pdf.combined.js 1.4 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513
  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.1080';
  24. PDFJS.build = 'f6ad15d';
  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. case 'tel':
  319. return true;
  320. default:
  321. return false;
  322. }
  323. }
  324. PDFJS.isValidUrl = isValidUrl;
  325. function shadow(obj, prop, value) {
  326. Object.defineProperty(obj, prop, { value: value,
  327. enumerable: true,
  328. configurable: true,
  329. writable: false });
  330. return value;
  331. }
  332. var PasswordResponses = PDFJS.PasswordResponses = {
  333. NEED_PASSWORD: 1,
  334. INCORRECT_PASSWORD: 2
  335. };
  336. var PasswordException = (function PasswordExceptionClosure() {
  337. function PasswordException(msg, code) {
  338. this.name = 'PasswordException';
  339. this.message = msg;
  340. this.code = code;
  341. }
  342. PasswordException.prototype = new Error();
  343. PasswordException.constructor = PasswordException;
  344. return PasswordException;
  345. })();
  346. PDFJS.PasswordException = PasswordException;
  347. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  348. function UnknownErrorException(msg, details) {
  349. this.name = 'UnknownErrorException';
  350. this.message = msg;
  351. this.details = details;
  352. }
  353. UnknownErrorException.prototype = new Error();
  354. UnknownErrorException.constructor = UnknownErrorException;
  355. return UnknownErrorException;
  356. })();
  357. PDFJS.UnknownErrorException = UnknownErrorException;
  358. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  359. function InvalidPDFException(msg) {
  360. this.name = 'InvalidPDFException';
  361. this.message = msg;
  362. }
  363. InvalidPDFException.prototype = new Error();
  364. InvalidPDFException.constructor = InvalidPDFException;
  365. return InvalidPDFException;
  366. })();
  367. PDFJS.InvalidPDFException = InvalidPDFException;
  368. var MissingPDFException = (function MissingPDFExceptionClosure() {
  369. function MissingPDFException(msg) {
  370. this.name = 'MissingPDFException';
  371. this.message = msg;
  372. }
  373. MissingPDFException.prototype = new Error();
  374. MissingPDFException.constructor = MissingPDFException;
  375. return MissingPDFException;
  376. })();
  377. PDFJS.MissingPDFException = MissingPDFException;
  378. var UnexpectedResponseException =
  379. (function UnexpectedResponseExceptionClosure() {
  380. function UnexpectedResponseException(msg, status) {
  381. this.name = 'UnexpectedResponseException';
  382. this.message = msg;
  383. this.status = status;
  384. }
  385. UnexpectedResponseException.prototype = new Error();
  386. UnexpectedResponseException.constructor = UnexpectedResponseException;
  387. return UnexpectedResponseException;
  388. })();
  389. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  390. var NotImplementedException = (function NotImplementedExceptionClosure() {
  391. function NotImplementedException(msg) {
  392. this.message = msg;
  393. }
  394. NotImplementedException.prototype = new Error();
  395. NotImplementedException.prototype.name = 'NotImplementedException';
  396. NotImplementedException.constructor = NotImplementedException;
  397. return NotImplementedException;
  398. })();
  399. var MissingDataException = (function MissingDataExceptionClosure() {
  400. function MissingDataException(begin, end) {
  401. this.begin = begin;
  402. this.end = end;
  403. this.message = 'Missing data [' + begin + ', ' + end + ')';
  404. }
  405. MissingDataException.prototype = new Error();
  406. MissingDataException.prototype.name = 'MissingDataException';
  407. MissingDataException.constructor = MissingDataException;
  408. return MissingDataException;
  409. })();
  410. var XRefParseException = (function XRefParseExceptionClosure() {
  411. function XRefParseException(msg) {
  412. this.message = msg;
  413. }
  414. XRefParseException.prototype = new Error();
  415. XRefParseException.prototype.name = 'XRefParseException';
  416. XRefParseException.constructor = XRefParseException;
  417. return XRefParseException;
  418. })();
  419. function bytesToString(bytes) {
  420. assert(bytes !== null && typeof bytes === 'object' &&
  421. bytes.length !== undefined, 'Invalid argument for bytesToString');
  422. var length = bytes.length;
  423. var MAX_ARGUMENT_COUNT = 8192;
  424. if (length < MAX_ARGUMENT_COUNT) {
  425. return String.fromCharCode.apply(null, bytes);
  426. }
  427. var strBuf = [];
  428. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  429. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  430. var chunk = bytes.subarray(i, chunkEnd);
  431. strBuf.push(String.fromCharCode.apply(null, chunk));
  432. }
  433. return strBuf.join('');
  434. }
  435. function stringToBytes(str) {
  436. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  437. var length = str.length;
  438. var bytes = new Uint8Array(length);
  439. for (var i = 0; i < length; ++i) {
  440. bytes[i] = str.charCodeAt(i) & 0xFF;
  441. }
  442. return bytes;
  443. }
  444. function string32(value) {
  445. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  446. (value >> 8) & 0xff, value & 0xff);
  447. }
  448. function log2(x) {
  449. var n = 1, i = 0;
  450. while (x > n) {
  451. n <<= 1;
  452. i++;
  453. }
  454. return i;
  455. }
  456. function readInt8(data, start) {
  457. return (data[start] << 24) >> 24;
  458. }
  459. function readUint16(data, offset) {
  460. return (data[offset] << 8) | data[offset + 1];
  461. }
  462. function readUint32(data, offset) {
  463. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  464. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  465. }
  466. // Lazy test the endianness of the platform
  467. // NOTE: This will be 'true' for simulated TypedArrays
  468. function isLittleEndian() {
  469. var buffer8 = new Uint8Array(2);
  470. buffer8[0] = 1;
  471. var buffer16 = new Uint16Array(buffer8.buffer);
  472. return (buffer16[0] === 1);
  473. }
  474. Object.defineProperty(PDFJS, 'isLittleEndian', {
  475. configurable: true,
  476. get: function PDFJS_isLittleEndian() {
  477. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  478. }
  479. });
  480. // Lazy test if the userAgant support CanvasTypedArrays
  481. function hasCanvasTypedArrays() {
  482. var canvas = document.createElement('canvas');
  483. canvas.width = canvas.height = 1;
  484. var ctx = canvas.getContext('2d');
  485. var imageData = ctx.createImageData(1, 1);
  486. return (typeof imageData.data.buffer !== 'undefined');
  487. }
  488. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  489. configurable: true,
  490. get: function PDFJS_hasCanvasTypedArrays() {
  491. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  492. }
  493. });
  494. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  495. function Uint32ArrayView(buffer, length) {
  496. this.buffer = buffer;
  497. this.byteLength = buffer.length;
  498. this.length = length === undefined ? (this.byteLength >> 2) : length;
  499. ensureUint32ArrayViewProps(this.length);
  500. }
  501. Uint32ArrayView.prototype = Object.create(null);
  502. var uint32ArrayViewSetters = 0;
  503. function createUint32ArrayProp(index) {
  504. return {
  505. get: function () {
  506. var buffer = this.buffer, offset = index << 2;
  507. return (buffer[offset] | (buffer[offset + 1] << 8) |
  508. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  509. },
  510. set: function (value) {
  511. var buffer = this.buffer, offset = index << 2;
  512. buffer[offset] = value & 255;
  513. buffer[offset + 1] = (value >> 8) & 255;
  514. buffer[offset + 2] = (value >> 16) & 255;
  515. buffer[offset + 3] = (value >>> 24) & 255;
  516. }
  517. };
  518. }
  519. function ensureUint32ArrayViewProps(length) {
  520. while (uint32ArrayViewSetters < length) {
  521. Object.defineProperty(Uint32ArrayView.prototype,
  522. uint32ArrayViewSetters,
  523. createUint32ArrayProp(uint32ArrayViewSetters));
  524. uint32ArrayViewSetters++;
  525. }
  526. }
  527. return Uint32ArrayView;
  528. })();
  529. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  530. var Util = PDFJS.Util = (function UtilClosure() {
  531. function Util() {}
  532. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  533. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  534. // creating many intermediate strings.
  535. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  536. rgbBuf[1] = r;
  537. rgbBuf[3] = g;
  538. rgbBuf[5] = b;
  539. return rgbBuf.join('');
  540. };
  541. // Concatenates two transformation matrices together and returns the result.
  542. Util.transform = function Util_transform(m1, m2) {
  543. return [
  544. m1[0] * m2[0] + m1[2] * m2[1],
  545. m1[1] * m2[0] + m1[3] * m2[1],
  546. m1[0] * m2[2] + m1[2] * m2[3],
  547. m1[1] * m2[2] + m1[3] * m2[3],
  548. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  549. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  550. ];
  551. };
  552. // For 2d affine transforms
  553. Util.applyTransform = function Util_applyTransform(p, m) {
  554. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  555. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  556. return [xt, yt];
  557. };
  558. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  559. var d = m[0] * m[3] - m[1] * m[2];
  560. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  561. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  562. return [xt, yt];
  563. };
  564. // Applies the transform to the rectangle and finds the minimum axially
  565. // aligned bounding box.
  566. Util.getAxialAlignedBoundingBox =
  567. function Util_getAxialAlignedBoundingBox(r, m) {
  568. var p1 = Util.applyTransform(r, m);
  569. var p2 = Util.applyTransform(r.slice(2, 4), m);
  570. var p3 = Util.applyTransform([r[0], r[3]], m);
  571. var p4 = Util.applyTransform([r[2], r[1]], m);
  572. return [
  573. Math.min(p1[0], p2[0], p3[0], p4[0]),
  574. Math.min(p1[1], p2[1], p3[1], p4[1]),
  575. Math.max(p1[0], p2[0], p3[0], p4[0]),
  576. Math.max(p1[1], p2[1], p3[1], p4[1])
  577. ];
  578. };
  579. Util.inverseTransform = function Util_inverseTransform(m) {
  580. var d = m[0] * m[3] - m[1] * m[2];
  581. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  582. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  583. };
  584. // Apply a generic 3d matrix M on a 3-vector v:
  585. // | a b c | | X |
  586. // | d e f | x | Y |
  587. // | g h i | | Z |
  588. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  589. // with v as [X,Y,Z]
  590. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  591. return [
  592. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  593. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  594. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  595. ];
  596. };
  597. // This calculation uses Singular Value Decomposition.
  598. // The SVD can be represented with formula A = USV. We are interested in the
  599. // matrix S here because it represents the scale values.
  600. Util.singularValueDecompose2dScale =
  601. function Util_singularValueDecompose2dScale(m) {
  602. var transpose = [m[0], m[2], m[1], m[3]];
  603. // Multiply matrix m with its transpose.
  604. var a = m[0] * transpose[0] + m[1] * transpose[2];
  605. var b = m[0] * transpose[1] + m[1] * transpose[3];
  606. var c = m[2] * transpose[0] + m[3] * transpose[2];
  607. var d = m[2] * transpose[1] + m[3] * transpose[3];
  608. // Solve the second degree polynomial to get roots.
  609. var first = (a + d) / 2;
  610. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  611. var sx = first + second || 1;
  612. var sy = first - second || 1;
  613. // Scale values are the square roots of the eigenvalues.
  614. return [Math.sqrt(sx), Math.sqrt(sy)];
  615. };
  616. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  617. // For coordinate systems whose origin lies in the bottom-left, this
  618. // means normalization to (BL,TR) ordering. For systems with origin in the
  619. // top-left, this means (TL,BR) ordering.
  620. Util.normalizeRect = function Util_normalizeRect(rect) {
  621. var r = rect.slice(0); // clone rect
  622. if (rect[0] > rect[2]) {
  623. r[0] = rect[2];
  624. r[2] = rect[0];
  625. }
  626. if (rect[1] > rect[3]) {
  627. r[1] = rect[3];
  628. r[3] = rect[1];
  629. }
  630. return r;
  631. };
  632. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  633. // intersection of rect1 and rect2. If no intersection, returns 'false'
  634. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  635. Util.intersect = function Util_intersect(rect1, rect2) {
  636. function compare(a, b) {
  637. return a - b;
  638. }
  639. // Order points along the axes
  640. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  641. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  642. result = [];
  643. rect1 = Util.normalizeRect(rect1);
  644. rect2 = Util.normalizeRect(rect2);
  645. // X: first and second points belong to different rectangles?
  646. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  647. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  648. // Intersection must be between second and third points
  649. result[0] = orderedX[1];
  650. result[2] = orderedX[2];
  651. } else {
  652. return false;
  653. }
  654. // Y: first and second points belong to different rectangles?
  655. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  656. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  657. // Intersection must be between second and third points
  658. result[1] = orderedY[1];
  659. result[3] = orderedY[2];
  660. } else {
  661. return false;
  662. }
  663. return result;
  664. };
  665. Util.sign = function Util_sign(num) {
  666. return num < 0 ? -1 : 1;
  667. };
  668. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  669. Array.prototype.push.apply(arr1, arr2);
  670. };
  671. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  672. Array.prototype.unshift.apply(arr1, arr2);
  673. };
  674. Util.extendObj = function extendObj(obj1, obj2) {
  675. for (var key in obj2) {
  676. obj1[key] = obj2[key];
  677. }
  678. };
  679. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  680. name) {
  681. while (dict && !dict.has(name)) {
  682. dict = dict.get('Parent');
  683. }
  684. if (!dict) {
  685. return null;
  686. }
  687. return dict.get(name);
  688. };
  689. Util.inherit = function Util_inherit(sub, base, prototype) {
  690. sub.prototype = Object.create(base.prototype);
  691. sub.prototype.constructor = sub;
  692. for (var prop in prototype) {
  693. sub.prototype[prop] = prototype[prop];
  694. }
  695. };
  696. Util.loadScript = function Util_loadScript(src, callback) {
  697. var script = document.createElement('script');
  698. var loaded = false;
  699. script.setAttribute('src', src);
  700. if (callback) {
  701. script.onload = function() {
  702. if (!loaded) {
  703. callback();
  704. }
  705. loaded = true;
  706. };
  707. }
  708. document.getElementsByTagName('head')[0].appendChild(script);
  709. };
  710. return Util;
  711. })();
  712. /**
  713. * PDF page viewport created based on scale, rotation and offset.
  714. * @class
  715. * @alias PDFJS.PageViewport
  716. */
  717. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  718. /**
  719. * @constructor
  720. * @private
  721. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  722. * @param scale {number} scale of the viewport.
  723. * @param rotation {number} rotations of the viewport in degrees.
  724. * @param offsetX {number} offset X
  725. * @param offsetY {number} offset Y
  726. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  727. */
  728. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  729. this.viewBox = viewBox;
  730. this.scale = scale;
  731. this.rotation = rotation;
  732. this.offsetX = offsetX;
  733. this.offsetY = offsetY;
  734. // creating transform to convert pdf coordinate system to the normal
  735. // canvas like coordinates taking in account scale and rotation
  736. var centerX = (viewBox[2] + viewBox[0]) / 2;
  737. var centerY = (viewBox[3] + viewBox[1]) / 2;
  738. var rotateA, rotateB, rotateC, rotateD;
  739. rotation = rotation % 360;
  740. rotation = rotation < 0 ? rotation + 360 : rotation;
  741. switch (rotation) {
  742. case 180:
  743. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  744. break;
  745. case 90:
  746. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  747. break;
  748. case 270:
  749. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  750. break;
  751. //case 0:
  752. default:
  753. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  754. break;
  755. }
  756. if (dontFlip) {
  757. rotateC = -rotateC; rotateD = -rotateD;
  758. }
  759. var offsetCanvasX, offsetCanvasY;
  760. var width, height;
  761. if (rotateA === 0) {
  762. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  763. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  764. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  765. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  766. } else {
  767. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  768. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  769. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  770. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  771. }
  772. // creating transform for the following operations:
  773. // translate(-centerX, -centerY), rotate and flip vertically,
  774. // scale, and translate(offsetCanvasX, offsetCanvasY)
  775. this.transform = [
  776. rotateA * scale,
  777. rotateB * scale,
  778. rotateC * scale,
  779. rotateD * scale,
  780. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  781. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  782. ];
  783. this.width = width;
  784. this.height = height;
  785. this.fontScale = scale;
  786. }
  787. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  788. /**
  789. * Clones viewport with additional properties.
  790. * @param args {Object} (optional) If specified, may contain the 'scale' or
  791. * 'rotation' properties to override the corresponding properties in
  792. * the cloned viewport.
  793. * @returns {PDFJS.PageViewport} Cloned viewport.
  794. */
  795. clone: function PageViewPort_clone(args) {
  796. args = args || {};
  797. var scale = 'scale' in args ? args.scale : this.scale;
  798. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  799. return new PageViewport(this.viewBox.slice(), scale, rotation,
  800. this.offsetX, this.offsetY, args.dontFlip);
  801. },
  802. /**
  803. * Converts PDF point to the viewport coordinates. For examples, useful for
  804. * converting PDF location into canvas pixel coordinates.
  805. * @param x {number} X coordinate.
  806. * @param y {number} Y coordinate.
  807. * @returns {Object} Object that contains 'x' and 'y' properties of the
  808. * point in the viewport coordinate space.
  809. * @see {@link convertToPdfPoint}
  810. * @see {@link convertToViewportRectangle}
  811. */
  812. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  813. return Util.applyTransform([x, y], this.transform);
  814. },
  815. /**
  816. * Converts PDF rectangle to the viewport coordinates.
  817. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  818. * @returns {Array} Contains corresponding coordinates of the rectangle
  819. * in the viewport coordinate space.
  820. * @see {@link convertToViewportPoint}
  821. */
  822. convertToViewportRectangle:
  823. function PageViewport_convertToViewportRectangle(rect) {
  824. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  825. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  826. return [tl[0], tl[1], br[0], br[1]];
  827. },
  828. /**
  829. * Converts viewport coordinates to the PDF location. For examples, useful
  830. * for converting canvas pixel location into PDF one.
  831. * @param x {number} X coordinate.
  832. * @param y {number} Y coordinate.
  833. * @returns {Object} Object that contains 'x' and 'y' properties of the
  834. * point in the PDF coordinate space.
  835. * @see {@link convertToViewportPoint}
  836. */
  837. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  838. return Util.applyInverseTransform([x, y], this.transform);
  839. }
  840. };
  841. return PageViewport;
  842. })();
  843. var PDFStringTranslateTable = [
  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,
  845. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  846. 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,
  847. 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,
  848. 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,
  849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  850. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  851. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  852. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  853. ];
  854. function stringToPDFString(str) {
  855. var i, n = str.length, strBuf = [];
  856. if (str[0] === '\xFE' && str[1] === '\xFF') {
  857. // UTF16BE BOM
  858. for (i = 2; i < n; i += 2) {
  859. strBuf.push(String.fromCharCode(
  860. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  861. }
  862. } else {
  863. for (i = 0; i < n; ++i) {
  864. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  865. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  866. }
  867. }
  868. return strBuf.join('');
  869. }
  870. function stringToUTF8String(str) {
  871. return decodeURIComponent(escape(str));
  872. }
  873. function isEmptyObj(obj) {
  874. for (var key in obj) {
  875. return false;
  876. }
  877. return true;
  878. }
  879. function isBool(v) {
  880. return typeof v === 'boolean';
  881. }
  882. function isInt(v) {
  883. return typeof v === 'number' && ((v | 0) === v);
  884. }
  885. function isNum(v) {
  886. return typeof v === 'number';
  887. }
  888. function isString(v) {
  889. return typeof v === 'string';
  890. }
  891. function isNull(v) {
  892. return v === null;
  893. }
  894. function isName(v) {
  895. return v instanceof Name;
  896. }
  897. function isCmd(v, cmd) {
  898. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  899. }
  900. function isDict(v, type) {
  901. if (!(v instanceof Dict)) {
  902. return false;
  903. }
  904. if (!type) {
  905. return true;
  906. }
  907. var dictType = v.get('Type');
  908. return isName(dictType) && dictType.name === type;
  909. }
  910. function isArray(v) {
  911. return v instanceof Array;
  912. }
  913. function isStream(v) {
  914. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  915. }
  916. function isArrayBuffer(v) {
  917. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  918. }
  919. function isRef(v) {
  920. return v instanceof Ref;
  921. }
  922. /**
  923. * Promise Capability object.
  924. *
  925. * @typedef {Object} PromiseCapability
  926. * @property {Promise} promise - A promise object.
  927. * @property {function} resolve - Fullfills the promise.
  928. * @property {function} reject - Rejects the promise.
  929. */
  930. /**
  931. * Creates a promise capability object.
  932. * @alias PDFJS.createPromiseCapability
  933. *
  934. * @return {PromiseCapability} A capability object contains:
  935. * - a Promise, resolve and reject methods.
  936. */
  937. function createPromiseCapability() {
  938. var capability = {};
  939. capability.promise = new Promise(function (resolve, reject) {
  940. capability.resolve = resolve;
  941. capability.reject = reject;
  942. });
  943. return capability;
  944. }
  945. PDFJS.createPromiseCapability = createPromiseCapability;
  946. /**
  947. * Polyfill for Promises:
  948. * The following promise implementation tries to generally implement the
  949. * Promise/A+ spec. Some notable differences from other promise libaries are:
  950. * - There currently isn't a seperate deferred and promise object.
  951. * - Unhandled rejections eventually show an error if they aren't handled.
  952. *
  953. * Based off of the work in:
  954. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  955. */
  956. (function PromiseClosure() {
  957. if (globalScope.Promise) {
  958. // Promises existing in the DOM/Worker, checking presence of all/resolve
  959. if (typeof globalScope.Promise.all !== 'function') {
  960. globalScope.Promise.all = function (iterable) {
  961. var count = 0, results = [], resolve, reject;
  962. var promise = new globalScope.Promise(function (resolve_, reject_) {
  963. resolve = resolve_;
  964. reject = reject_;
  965. });
  966. iterable.forEach(function (p, i) {
  967. count++;
  968. p.then(function (result) {
  969. results[i] = result;
  970. count--;
  971. if (count === 0) {
  972. resolve(results);
  973. }
  974. }, reject);
  975. });
  976. if (count === 0) {
  977. resolve(results);
  978. }
  979. return promise;
  980. };
  981. }
  982. if (typeof globalScope.Promise.resolve !== 'function') {
  983. globalScope.Promise.resolve = function (value) {
  984. return new globalScope.Promise(function (resolve) { resolve(value); });
  985. };
  986. }
  987. if (typeof globalScope.Promise.reject !== 'function') {
  988. globalScope.Promise.reject = function (reason) {
  989. return new globalScope.Promise(function (resolve, reject) {
  990. reject(reason);
  991. });
  992. };
  993. }
  994. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  995. globalScope.Promise.prototype.catch = function (onReject) {
  996. return globalScope.Promise.prototype.then(undefined, onReject);
  997. };
  998. }
  999. return;
  1000. }
  1001. var STATUS_PENDING = 0;
  1002. var STATUS_RESOLVED = 1;
  1003. var STATUS_REJECTED = 2;
  1004. // In an attempt to avoid silent exceptions, unhandled rejections are
  1005. // tracked and if they aren't handled in a certain amount of time an
  1006. // error is logged.
  1007. var REJECTION_TIMEOUT = 500;
  1008. var HandlerManager = {
  1009. handlers: [],
  1010. running: false,
  1011. unhandledRejections: [],
  1012. pendingRejectionCheck: false,
  1013. scheduleHandlers: function scheduleHandlers(promise) {
  1014. if (promise._status === STATUS_PENDING) {
  1015. return;
  1016. }
  1017. this.handlers = this.handlers.concat(promise._handlers);
  1018. promise._handlers = [];
  1019. if (this.running) {
  1020. return;
  1021. }
  1022. this.running = true;
  1023. setTimeout(this.runHandlers.bind(this), 0);
  1024. },
  1025. runHandlers: function runHandlers() {
  1026. var RUN_TIMEOUT = 1; // ms
  1027. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1028. while (this.handlers.length > 0) {
  1029. var handler = this.handlers.shift();
  1030. var nextStatus = handler.thisPromise._status;
  1031. var nextValue = handler.thisPromise._value;
  1032. try {
  1033. if (nextStatus === STATUS_RESOLVED) {
  1034. if (typeof handler.onResolve === 'function') {
  1035. nextValue = handler.onResolve(nextValue);
  1036. }
  1037. } else if (typeof handler.onReject === 'function') {
  1038. nextValue = handler.onReject(nextValue);
  1039. nextStatus = STATUS_RESOLVED;
  1040. if (handler.thisPromise._unhandledRejection) {
  1041. this.removeUnhandeledRejection(handler.thisPromise);
  1042. }
  1043. }
  1044. } catch (ex) {
  1045. nextStatus = STATUS_REJECTED;
  1046. nextValue = ex;
  1047. }
  1048. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1049. if (Date.now() >= timeoutAt) {
  1050. break;
  1051. }
  1052. }
  1053. if (this.handlers.length > 0) {
  1054. setTimeout(this.runHandlers.bind(this), 0);
  1055. return;
  1056. }
  1057. this.running = false;
  1058. },
  1059. addUnhandledRejection: function addUnhandledRejection(promise) {
  1060. this.unhandledRejections.push({
  1061. promise: promise,
  1062. time: Date.now()
  1063. });
  1064. this.scheduleRejectionCheck();
  1065. },
  1066. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1067. promise._unhandledRejection = false;
  1068. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1069. if (this.unhandledRejections[i].promise === promise) {
  1070. this.unhandledRejections.splice(i);
  1071. i--;
  1072. }
  1073. }
  1074. },
  1075. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1076. if (this.pendingRejectionCheck) {
  1077. return;
  1078. }
  1079. this.pendingRejectionCheck = true;
  1080. setTimeout(function rejectionCheck() {
  1081. this.pendingRejectionCheck = false;
  1082. var now = Date.now();
  1083. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1084. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1085. var unhandled = this.unhandledRejections[i].promise._value;
  1086. var msg = 'Unhandled rejection: ' + unhandled;
  1087. if (unhandled.stack) {
  1088. msg += '\n' + unhandled.stack;
  1089. }
  1090. warn(msg);
  1091. this.unhandledRejections.splice(i);
  1092. i--;
  1093. }
  1094. }
  1095. if (this.unhandledRejections.length) {
  1096. this.scheduleRejectionCheck();
  1097. }
  1098. }.bind(this), REJECTION_TIMEOUT);
  1099. }
  1100. };
  1101. function Promise(resolver) {
  1102. this._status = STATUS_PENDING;
  1103. this._handlers = [];
  1104. try {
  1105. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1106. } catch (e) {
  1107. this._reject(e);
  1108. }
  1109. }
  1110. /**
  1111. * Builds a promise that is resolved when all the passed in promises are
  1112. * resolved.
  1113. * @param {array} array of data and/or promises to wait for.
  1114. * @return {Promise} New dependant promise.
  1115. */
  1116. Promise.all = function Promise_all(promises) {
  1117. var resolveAll, rejectAll;
  1118. var deferred = new Promise(function (resolve, reject) {
  1119. resolveAll = resolve;
  1120. rejectAll = reject;
  1121. });
  1122. var unresolved = promises.length;
  1123. var results = [];
  1124. if (unresolved === 0) {
  1125. resolveAll(results);
  1126. return deferred;
  1127. }
  1128. function reject(reason) {
  1129. if (deferred._status === STATUS_REJECTED) {
  1130. return;
  1131. }
  1132. results = [];
  1133. rejectAll(reason);
  1134. }
  1135. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1136. var promise = promises[i];
  1137. var resolve = (function(i) {
  1138. return function(value) {
  1139. if (deferred._status === STATUS_REJECTED) {
  1140. return;
  1141. }
  1142. results[i] = value;
  1143. unresolved--;
  1144. if (unresolved === 0) {
  1145. resolveAll(results);
  1146. }
  1147. };
  1148. })(i);
  1149. if (Promise.isPromise(promise)) {
  1150. promise.then(resolve, reject);
  1151. } else {
  1152. resolve(promise);
  1153. }
  1154. }
  1155. return deferred;
  1156. };
  1157. /**
  1158. * Checks if the value is likely a promise (has a 'then' function).
  1159. * @return {boolean} true if value is thenable
  1160. */
  1161. Promise.isPromise = function Promise_isPromise(value) {
  1162. return value && typeof value.then === 'function';
  1163. };
  1164. /**
  1165. * Creates resolved promise
  1166. * @param value resolve value
  1167. * @returns {Promise}
  1168. */
  1169. Promise.resolve = function Promise_resolve(value) {
  1170. return new Promise(function (resolve) { resolve(value); });
  1171. };
  1172. /**
  1173. * Creates rejected promise
  1174. * @param reason rejection value
  1175. * @returns {Promise}
  1176. */
  1177. Promise.reject = function Promise_reject(reason) {
  1178. return new Promise(function (resolve, reject) { reject(reason); });
  1179. };
  1180. Promise.prototype = {
  1181. _status: null,
  1182. _value: null,
  1183. _handlers: null,
  1184. _unhandledRejection: null,
  1185. _updateStatus: function Promise__updateStatus(status, value) {
  1186. if (this._status === STATUS_RESOLVED ||
  1187. this._status === STATUS_REJECTED) {
  1188. return;
  1189. }
  1190. if (status === STATUS_RESOLVED &&
  1191. Promise.isPromise(value)) {
  1192. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1193. this._updateStatus.bind(this, STATUS_REJECTED));
  1194. return;
  1195. }
  1196. this._status = status;
  1197. this._value = value;
  1198. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1199. this._unhandledRejection = true;
  1200. HandlerManager.addUnhandledRejection(this);
  1201. }
  1202. HandlerManager.scheduleHandlers(this);
  1203. },
  1204. _resolve: function Promise_resolve(value) {
  1205. this._updateStatus(STATUS_RESOLVED, value);
  1206. },
  1207. _reject: function Promise_reject(reason) {
  1208. this._updateStatus(STATUS_REJECTED, reason);
  1209. },
  1210. then: function Promise_then(onResolve, onReject) {
  1211. var nextPromise = new Promise(function (resolve, reject) {
  1212. this.resolve = resolve;
  1213. this.reject = reject;
  1214. });
  1215. this._handlers.push({
  1216. thisPromise: this,
  1217. onResolve: onResolve,
  1218. onReject: onReject,
  1219. nextPromise: nextPromise
  1220. });
  1221. HandlerManager.scheduleHandlers(this);
  1222. return nextPromise;
  1223. },
  1224. catch: function Promise_catch(onReject) {
  1225. return this.then(undefined, onReject);
  1226. }
  1227. };
  1228. globalScope.Promise = Promise;
  1229. })();
  1230. var StatTimer = (function StatTimerClosure() {
  1231. function rpad(str, pad, length) {
  1232. while (str.length < length) {
  1233. str += pad;
  1234. }
  1235. return str;
  1236. }
  1237. function StatTimer() {
  1238. this.started = {};
  1239. this.times = [];
  1240. this.enabled = true;
  1241. }
  1242. StatTimer.prototype = {
  1243. time: function StatTimer_time(name) {
  1244. if (!this.enabled) {
  1245. return;
  1246. }
  1247. if (name in this.started) {
  1248. warn('Timer is already running for ' + name);
  1249. }
  1250. this.started[name] = Date.now();
  1251. },
  1252. timeEnd: function StatTimer_timeEnd(name) {
  1253. if (!this.enabled) {
  1254. return;
  1255. }
  1256. if (!(name in this.started)) {
  1257. warn('Timer has not been started for ' + name);
  1258. }
  1259. this.times.push({
  1260. 'name': name,
  1261. 'start': this.started[name],
  1262. 'end': Date.now()
  1263. });
  1264. // Remove timer from started so it can be called again.
  1265. delete this.started[name];
  1266. },
  1267. toString: function StatTimer_toString() {
  1268. var i, ii;
  1269. var times = this.times;
  1270. var out = '';
  1271. // Find the longest name for padding purposes.
  1272. var longest = 0;
  1273. for (i = 0, ii = times.length; i < ii; ++i) {
  1274. var name = times[i]['name'];
  1275. if (name.length > longest) {
  1276. longest = name.length;
  1277. }
  1278. }
  1279. for (i = 0, ii = times.length; i < ii; ++i) {
  1280. var span = times[i];
  1281. var duration = span.end - span.start;
  1282. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1283. }
  1284. return out;
  1285. }
  1286. };
  1287. return StatTimer;
  1288. })();
  1289. PDFJS.createBlob = function createBlob(data, contentType) {
  1290. if (typeof Blob !== 'undefined') {
  1291. return new Blob([data], { type: contentType });
  1292. }
  1293. // Blob builder is deprecated in FF14 and removed in FF18.
  1294. var bb = new MozBlobBuilder();
  1295. bb.append(data);
  1296. return bb.getBlob(contentType);
  1297. };
  1298. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1299. // Blob/createObjectURL is not available, falling back to data schema.
  1300. var digits =
  1301. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1302. return function createObjectURL(data, contentType) {
  1303. if (!PDFJS.disableCreateObjectURL &&
  1304. typeof URL !== 'undefined' && URL.createObjectURL) {
  1305. var blob = PDFJS.createBlob(data, contentType);
  1306. return URL.createObjectURL(blob);
  1307. }
  1308. var buffer = 'data:' + contentType + ';base64,';
  1309. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1310. var b1 = data[i] & 0xFF;
  1311. var b2 = data[i + 1] & 0xFF;
  1312. var b3 = data[i + 2] & 0xFF;
  1313. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1314. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1315. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1316. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1317. }
  1318. return buffer;
  1319. };
  1320. })();
  1321. function MessageHandler(name, comObj) {
  1322. this.name = name;
  1323. this.comObj = comObj;
  1324. this.callbackIndex = 1;
  1325. this.postMessageTransfers = true;
  1326. var callbacksCapabilities = this.callbacksCapabilities = {};
  1327. var ah = this.actionHandler = {};
  1328. ah['console_log'] = [function ahConsoleLog(data) {
  1329. console.log.apply(console, data);
  1330. }];
  1331. ah['console_error'] = [function ahConsoleError(data) {
  1332. console.error.apply(console, data);
  1333. }];
  1334. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1335. UnsupportedManager.notify(data);
  1336. }];
  1337. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1338. var data = event.data;
  1339. if (data.isReply) {
  1340. var callbackId = data.callbackId;
  1341. if (data.callbackId in callbacksCapabilities) {
  1342. var callback = callbacksCapabilities[callbackId];
  1343. delete callbacksCapabilities[callbackId];
  1344. if ('error' in data) {
  1345. callback.reject(data.error);
  1346. } else {
  1347. callback.resolve(data.data);
  1348. }
  1349. } else {
  1350. error('Cannot resolve callback ' + callbackId);
  1351. }
  1352. } else if (data.action in ah) {
  1353. var action = ah[data.action];
  1354. if (data.callbackId) {
  1355. Promise.resolve().then(function () {
  1356. return action[0].call(action[1], data.data);
  1357. }).then(function (result) {
  1358. comObj.postMessage({
  1359. isReply: true,
  1360. callbackId: data.callbackId,
  1361. data: result
  1362. });
  1363. }, function (reason) {
  1364. comObj.postMessage({
  1365. isReply: true,
  1366. callbackId: data.callbackId,
  1367. error: reason
  1368. });
  1369. });
  1370. } else {
  1371. action[0].call(action[1], data.data);
  1372. }
  1373. } else {
  1374. error('Unknown action from worker: ' + data.action);
  1375. }
  1376. };
  1377. }
  1378. MessageHandler.prototype = {
  1379. on: function messageHandlerOn(actionName, handler, scope) {
  1380. var ah = this.actionHandler;
  1381. if (ah[actionName]) {
  1382. error('There is already an actionName called "' + actionName + '"');
  1383. }
  1384. ah[actionName] = [handler, scope];
  1385. },
  1386. /**
  1387. * Sends a message to the comObj to invoke the action with the supplied data.
  1388. * @param {String} actionName Action to call.
  1389. * @param {JSON} data JSON data to send.
  1390. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1391. */
  1392. send: function messageHandlerSend(actionName, data, transfers) {
  1393. var message = {
  1394. action: actionName,
  1395. data: data
  1396. };
  1397. this.postMessage(message, transfers);
  1398. },
  1399. /**
  1400. * Sends a message to the comObj to invoke the action with the supplied data.
  1401. * Expects that other side will callback with the response.
  1402. * @param {String} actionName Action to call.
  1403. * @param {JSON} data JSON data to send.
  1404. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1405. * @returns {Promise} Promise to be resolved with response data.
  1406. */
  1407. sendWithPromise:
  1408. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1409. var callbackId = this.callbackIndex++;
  1410. var message = {
  1411. action: actionName,
  1412. data: data,
  1413. callbackId: callbackId
  1414. };
  1415. var capability = createPromiseCapability();
  1416. this.callbacksCapabilities[callbackId] = capability;
  1417. try {
  1418. this.postMessage(message, transfers);
  1419. } catch (e) {
  1420. capability.reject(e);
  1421. }
  1422. return capability.promise;
  1423. },
  1424. /**
  1425. * Sends raw message to the comObj.
  1426. * @private
  1427. * @param message {Object} Raw message.
  1428. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1429. */
  1430. postMessage: function (message, transfers) {
  1431. if (transfers && this.postMessageTransfers) {
  1432. this.comObj.postMessage(message, transfers);
  1433. } else {
  1434. this.comObj.postMessage(message);
  1435. }
  1436. }
  1437. };
  1438. function loadJpegStream(id, imageUrl, objs) {
  1439. var img = new Image();
  1440. img.onload = (function loadJpegStream_onloadClosure() {
  1441. objs.resolve(id, img);
  1442. });
  1443. img.onerror = (function loadJpegStream_onerrorClosure() {
  1444. objs.resolve(id, null);
  1445. warn('Error during JPEG image loading');
  1446. });
  1447. img.src = imageUrl;
  1448. }
  1449. /**
  1450. * The maximum allowed image size in total pixels e.g. width * height. Images
  1451. * above this value will not be drawn. Use -1 for no limit.
  1452. * @var {number}
  1453. */
  1454. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1455. -1 : PDFJS.maxImageSize);
  1456. /**
  1457. * The url of where the predefined Adobe CMaps are located. Include trailing
  1458. * slash.
  1459. * @var {string}
  1460. */
  1461. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1462. /**
  1463. * Specifies if CMaps are binary packed.
  1464. * @var {boolean}
  1465. */
  1466. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1467. /*
  1468. * By default fonts are converted to OpenType fonts and loaded via font face
  1469. * rules. If disabled, the font will be rendered using a built in font renderer
  1470. * that constructs the glyphs with primitive path commands.
  1471. * @var {boolean}
  1472. */
  1473. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1474. false : PDFJS.disableFontFace);
  1475. /**
  1476. * Path for image resources, mainly for annotation icons. Include trailing
  1477. * slash.
  1478. * @var {string}
  1479. */
  1480. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1481. '' : PDFJS.imageResourcesPath);
  1482. /**
  1483. * Disable the web worker and run all code on the main thread. This will happen
  1484. * automatically if the browser doesn't support workers or sending typed arrays
  1485. * to workers.
  1486. * @var {boolean}
  1487. */
  1488. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1489. false : PDFJS.disableWorker);
  1490. /**
  1491. * Path and filename of the worker file. Required when the worker is enabled in
  1492. * development mode. If unspecified in the production build, the worker will be
  1493. * loaded based on the location of the pdf.js file.
  1494. * @var {string}
  1495. */
  1496. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1497. /**
  1498. * Disable range request loading of PDF files. When enabled and if the server
  1499. * supports partial content requests then the PDF will be fetched in chunks.
  1500. * Enabled (false) by default.
  1501. * @var {boolean}
  1502. */
  1503. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1504. false : PDFJS.disableRange);
  1505. /**
  1506. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  1507. * in chunks. This default behavior can be disabled.
  1508. * @var {boolean}
  1509. */
  1510. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  1511. false : PDFJS.disableStream);
  1512. /**
  1513. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1514. * will automatically keep fetching more data even if it isn't needed to display
  1515. * the current page. This default behavior can be disabled.
  1516. * @var {boolean}
  1517. */
  1518. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1519. false : PDFJS.disableAutoFetch);
  1520. /**
  1521. * Enables special hooks for debugging PDF.js.
  1522. * @var {boolean}
  1523. */
  1524. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1525. /**
  1526. * Enables transfer usage in postMessage for ArrayBuffers.
  1527. * @var {boolean}
  1528. */
  1529. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1530. true : PDFJS.postMessageTransfers);
  1531. /**
  1532. * Disables URL.createObjectURL usage.
  1533. * @var {boolean}
  1534. */
  1535. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1536. false : PDFJS.disableCreateObjectURL);
  1537. /**
  1538. * Disables WebGL usage.
  1539. * @var {boolean}
  1540. */
  1541. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1542. true : PDFJS.disableWebGL);
  1543. /**
  1544. * Enables CSS only zooming.
  1545. * @var {boolean}
  1546. */
  1547. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1548. false : PDFJS.useOnlyCssZoom);
  1549. /**
  1550. * Controls the logging level.
  1551. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1552. * - errors
  1553. * - warnings [default]
  1554. * - infos
  1555. * @var {number}
  1556. */
  1557. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1558. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1559. /**
  1560. * The maximum supported canvas size in total pixels e.g. width * height.
  1561. * The default value is 4096 * 4096. Use -1 for no limit.
  1562. * @var {number}
  1563. */
  1564. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1565. 16777216 : PDFJS.maxCanvasPixels);
  1566. /**
  1567. * Document initialization / loading parameters object.
  1568. *
  1569. * @typedef {Object} DocumentInitParameters
  1570. * @property {string} url - The URL of the PDF.
  1571. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  1572. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  1573. * use atob() to convert it to a binary string first.
  1574. * @property {Object} httpHeaders - Basic authentication headers.
  1575. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1576. * Access-Control requests should be made using credentials such as cookies
  1577. * or authorization headers. The default is false.
  1578. * @property {string} password - For decrypting password-protected PDFs.
  1579. * @property {TypedArray} initialData - A typed array with the first portion or
  1580. * all of the pdf data. Used by the extension since some data is already
  1581. * loaded before the switch to range requests.
  1582. * @property {number} length - The PDF file length. It's used for progress
  1583. * reports and range requests operations.
  1584. * @property {PDFDataRangeTransport} range
  1585. */
  1586. /**
  1587. * @typedef {Object} PDFDocumentStats
  1588. * @property {Array} streamTypes - Used stream types in the document (an item
  1589. * is set to true if specific stream ID was used in the document).
  1590. * @property {Array} fontTypes - Used font type in the document (an item is set
  1591. * to true if specific font ID was used in the document).
  1592. */
  1593. /**
  1594. * This is the main entry point for loading a PDF and interacting with it.
  1595. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1596. * is used, which means it must follow the same origin rules that any XHR does
  1597. * e.g. No cross domain requests without CORS.
  1598. *
  1599. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  1600. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  1601. * already populated with data or parameter object.
  1602. *
  1603. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  1604. * if you want to manually serve range requests for data in the PDF.
  1605. *
  1606. * @param {function} passwordCallback (deprecated) It is used to request a
  1607. * password if wrong or no password was provided. The callback receives two
  1608. * parameters: function that needs to be called with new password and reason
  1609. * (see {PasswordResponses}).
  1610. *
  1611. * @param {function} progressCallback (deprecated) It is used to be able to
  1612. * monitor the loading progress of the PDF file (necessary to implement e.g.
  1613. * a loading bar). The callback receives an {Object} with the properties:
  1614. * {number} loaded and {number} total.
  1615. *
  1616. * @return {PDFDocumentLoadingTask}
  1617. */
  1618. PDFJS.getDocument = function getDocument(src,
  1619. pdfDataRangeTransport,
  1620. passwordCallback,
  1621. progressCallback) {
  1622. var task = new PDFDocumentLoadingTask();
  1623. // Support of the obsolete arguments (for compatibility with API v1.0)
  1624. if (pdfDataRangeTransport) {
  1625. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  1626. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  1627. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  1628. pdfDataRangeTransport.length = src.length;
  1629. pdfDataRangeTransport.initialData = src.initialData;
  1630. }
  1631. src = Object.create(src);
  1632. src.range = pdfDataRangeTransport;
  1633. }
  1634. task.onPassword = passwordCallback || null;
  1635. task.onProgress = progressCallback || null;
  1636. var workerInitializedCapability, transport;
  1637. var source;
  1638. if (typeof src === 'string') {
  1639. source = { url: src };
  1640. } else if (isArrayBuffer(src)) {
  1641. source = { data: src };
  1642. } else if (src instanceof PDFDataRangeTransport) {
  1643. source = { range: src };
  1644. } else {
  1645. if (typeof src !== 'object') {
  1646. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1647. 'string or a parameter object');
  1648. }
  1649. if (!src.url && !src.data && !src.range) {
  1650. error('Invalid parameter object: need either .data, .range or .url');
  1651. }
  1652. source = src;
  1653. }
  1654. var params = {};
  1655. for (var key in source) {
  1656. if (key === 'url' && typeof window !== 'undefined') {
  1657. // The full path is required in the 'url' field.
  1658. params[key] = combineUrl(window.location.href, source[key]);
  1659. continue;
  1660. } else if (key === 'range') {
  1661. continue;
  1662. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  1663. // Converting string or array-like data to Uint8Array.
  1664. var pdfBytes = source[key];
  1665. if (typeof pdfBytes === 'string') {
  1666. params[key] = stringToBytes(pdfBytes);
  1667. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  1668. !isNaN(pdfBytes.length)) {
  1669. params[key] = new Uint8Array(pdfBytes);
  1670. } else {
  1671. error('Invalid PDF binary data: either typed array, string or ' +
  1672. 'array-like object is expected in the data property.');
  1673. }
  1674. continue;
  1675. }
  1676. params[key] = source[key];
  1677. }
  1678. workerInitializedCapability = createPromiseCapability();
  1679. transport = new WorkerTransport(workerInitializedCapability, source.range);
  1680. workerInitializedCapability.promise.then(function transportInitialized() {
  1681. transport.fetchDocument(task, params);
  1682. });
  1683. return task;
  1684. };
  1685. /**
  1686. * PDF document loading operation.
  1687. * @class
  1688. */
  1689. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  1690. /** @constructs PDFDocumentLoadingTask */
  1691. function PDFDocumentLoadingTask() {
  1692. this._capability = createPromiseCapability();
  1693. /**
  1694. * Callback to request a password if wrong or no password was provided.
  1695. * The callback receives two parameters: function that needs to be called
  1696. * with new password and reason (see {PasswordResponses}).
  1697. */
  1698. this.onPassword = null;
  1699. /**
  1700. * Callback to be able to monitor the loading progress of the PDF file
  1701. * (necessary to implement e.g. a loading bar). The callback receives
  1702. * an {Object} with the properties: {number} loaded and {number} total.
  1703. */
  1704. this.onProgress = null;
  1705. }
  1706. PDFDocumentLoadingTask.prototype =
  1707. /** @lends PDFDocumentLoadingTask.prototype */ {
  1708. /**
  1709. * @return {Promise}
  1710. */
  1711. get promise() {
  1712. return this._capability.promise;
  1713. },
  1714. // TODO add cancel or abort method
  1715. /**
  1716. * Registers callbacks to indicate the document loading completion.
  1717. *
  1718. * @param {function} onFulfilled The callback for the loading completion.
  1719. * @param {function} onRejected The callback for the loading failure.
  1720. * @return {Promise} A promise that is resolved after the onFulfilled or
  1721. * onRejected callback.
  1722. */
  1723. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  1724. return this.promise.then.apply(this.promise, arguments);
  1725. }
  1726. };
  1727. return PDFDocumentLoadingTask;
  1728. })();
  1729. /**
  1730. * Abstract class to support range requests file loading.
  1731. * @class
  1732. */
  1733. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  1734. /**
  1735. * @constructs PDFDataRangeTransport
  1736. * @param {number} length
  1737. * @param {Uint8Array} initialData
  1738. */
  1739. function PDFDataRangeTransport(length, initialData) {
  1740. this.length = length;
  1741. this.initialData = initialData;
  1742. this._rangeListeners = [];
  1743. this._progressListeners = [];
  1744. this._progressiveReadListeners = [];
  1745. this._readyCapability = createPromiseCapability();
  1746. }
  1747. PDFDataRangeTransport.prototype =
  1748. /** @lends PDFDataRangeTransport.prototype */ {
  1749. addRangeListener:
  1750. function PDFDataRangeTransport_addRangeListener(listener) {
  1751. this._rangeListeners.push(listener);
  1752. },
  1753. addProgressListener:
  1754. function PDFDataRangeTransport_addProgressListener(listener) {
  1755. this._progressListeners.push(listener);
  1756. },
  1757. addProgressiveReadListener:
  1758. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  1759. this._progressiveReadListeners.push(listener);
  1760. },
  1761. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  1762. var listeners = this._rangeListeners;
  1763. for (var i = 0, n = listeners.length; i < n; ++i) {
  1764. listeners[i](begin, chunk);
  1765. }
  1766. },
  1767. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  1768. this._readyCapability.promise.then(function () {
  1769. var listeners = this._progressListeners;
  1770. for (var i = 0, n = listeners.length; i < n; ++i) {
  1771. listeners[i](loaded);
  1772. }
  1773. }.bind(this));
  1774. },
  1775. onDataProgressiveRead:
  1776. function PDFDataRangeTransport_onDataProgress(chunk) {
  1777. this._readyCapability.promise.then(function () {
  1778. var listeners = this._progressiveReadListeners;
  1779. for (var i = 0, n = listeners.length; i < n; ++i) {
  1780. listeners[i](chunk);
  1781. }
  1782. }.bind(this));
  1783. },
  1784. transportReady: function PDFDataRangeTransport_transportReady() {
  1785. this._readyCapability.resolve();
  1786. },
  1787. requestDataRange:
  1788. function PDFDataRangeTransport_requestDataRange(begin, end) {
  1789. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  1790. }
  1791. };
  1792. return PDFDataRangeTransport;
  1793. })();
  1794. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  1795. /**
  1796. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1797. * properties that can be read synchronously.
  1798. * @class
  1799. */
  1800. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1801. function PDFDocumentProxy(pdfInfo, transport) {
  1802. this.pdfInfo = pdfInfo;
  1803. this.transport = transport;
  1804. }
  1805. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1806. /**
  1807. * @return {number} Total number of pages the PDF contains.
  1808. */
  1809. get numPages() {
  1810. return this.pdfInfo.numPages;
  1811. },
  1812. /**
  1813. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1814. * unique.
  1815. */
  1816. get fingerprint() {
  1817. return this.pdfInfo.fingerprint;
  1818. },
  1819. /**
  1820. * @param {number} pageNumber The page number to get. The first page is 1.
  1821. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1822. * object.
  1823. */
  1824. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1825. return this.transport.getPage(pageNumber);
  1826. },
  1827. /**
  1828. * @param {{num: number, gen: number}} ref The page reference. Must have
  1829. * the 'num' and 'gen' properties.
  1830. * @return {Promise} A promise that is resolved with the page index that is
  1831. * associated with the reference.
  1832. */
  1833. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1834. return this.transport.getPageIndex(ref);
  1835. },
  1836. /**
  1837. * @return {Promise} A promise that is resolved with a lookup table for
  1838. * mapping named destinations to reference numbers.
  1839. *
  1840. * This can be slow for large documents: use getDestination instead
  1841. */
  1842. getDestinations: function PDFDocumentProxy_getDestinations() {
  1843. return this.transport.getDestinations();
  1844. },
  1845. /**
  1846. * @param {string} id The named destination to get.
  1847. * @return {Promise} A promise that is resolved with all information
  1848. * of the given named destination.
  1849. */
  1850. getDestination: function PDFDocumentProxy_getDestination(id) {
  1851. return this.transport.getDestination(id);
  1852. },
  1853. /**
  1854. * @return {Promise} A promise that is resolved with a lookup table for
  1855. * mapping named attachments to their content.
  1856. */
  1857. getAttachments: function PDFDocumentProxy_getAttachments() {
  1858. return this.transport.getAttachments();
  1859. },
  1860. /**
  1861. * @return {Promise} A promise that is resolved with an array of all the
  1862. * JavaScript strings in the name tree.
  1863. */
  1864. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1865. return this.transport.getJavaScript();
  1866. },
  1867. /**
  1868. * @return {Promise} A promise that is resolved with an {Array} that is a
  1869. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1870. * [
  1871. * {
  1872. * title: string,
  1873. * bold: boolean,
  1874. * italic: boolean,
  1875. * color: rgb array,
  1876. * dest: dest obj,
  1877. * items: array of more items like this
  1878. * },
  1879. * ...
  1880. * ].
  1881. */
  1882. getOutline: function PDFDocumentProxy_getOutline() {
  1883. return this.transport.getOutline();
  1884. },
  1885. /**
  1886. * @return {Promise} A promise that is resolved with an {Object} that has
  1887. * info and metadata properties. Info is an {Object} filled with anything
  1888. * available in the information dictionary and similarly metadata is a
  1889. * {Metadata} object with information from the metadata section of the PDF.
  1890. */
  1891. getMetadata: function PDFDocumentProxy_getMetadata() {
  1892. return this.transport.getMetadata();
  1893. },
  1894. /**
  1895. * @return {Promise} A promise that is resolved with a TypedArray that has
  1896. * the raw data from the PDF.
  1897. */
  1898. getData: function PDFDocumentProxy_getData() {
  1899. return this.transport.getData();
  1900. },
  1901. /**
  1902. * @return {Promise} A promise that is resolved when the document's data
  1903. * is loaded. It is resolved with an {Object} that contains the length
  1904. * property that indicates size of the PDF data in bytes.
  1905. */
  1906. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1907. return this.transport.downloadInfoCapability.promise;
  1908. },
  1909. /**
  1910. * @return {Promise} A promise this is resolved with current stats about
  1911. * document structures (see {@link PDFDocumentStats}).
  1912. */
  1913. getStats: function PDFDocumentProxy_getStats() {
  1914. return this.transport.getStats();
  1915. },
  1916. /**
  1917. * Cleans up resources allocated by the document, e.g. created @font-face.
  1918. */
  1919. cleanup: function PDFDocumentProxy_cleanup() {
  1920. this.transport.startCleanup();
  1921. },
  1922. /**
  1923. * Destroys current document instance and terminates worker.
  1924. */
  1925. destroy: function PDFDocumentProxy_destroy() {
  1926. this.transport.destroy();
  1927. }
  1928. };
  1929. return PDFDocumentProxy;
  1930. })();
  1931. /**
  1932. * Page text content.
  1933. *
  1934. * @typedef {Object} TextContent
  1935. * @property {array} items - array of {@link TextItem}
  1936. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1937. * name.
  1938. */
  1939. /**
  1940. * Page text content part.
  1941. *
  1942. * @typedef {Object} TextItem
  1943. * @property {string} str - text content.
  1944. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1945. * @property {array} transform - transformation matrix.
  1946. * @property {number} width - width in device space.
  1947. * @property {number} height - height in device space.
  1948. * @property {string} fontName - font name used by pdf.js for converted font.
  1949. */
  1950. /**
  1951. * Text style.
  1952. *
  1953. * @typedef {Object} TextStyle
  1954. * @property {number} ascent - font ascent.
  1955. * @property {number} descent - font descent.
  1956. * @property {boolean} vertical - text is in vertical mode.
  1957. * @property {string} fontFamily - possible font family
  1958. */
  1959. /**
  1960. * Page render parameters.
  1961. *
  1962. * @typedef {Object} RenderParameters
  1963. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1964. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1965. * calling of PDFPage.getViewport method.
  1966. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1967. * (default value is 'display').
  1968. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1969. * endLayout and appendImage functions.
  1970. * @property {function} continueCallback - (deprecated) A function that will be
  1971. * called each time the rendering is paused. To continue
  1972. * rendering call the function that is the first argument
  1973. * to the callback.
  1974. */
  1975. /**
  1976. * PDF page operator list.
  1977. *
  1978. * @typedef {Object} PDFOperatorList
  1979. * @property {Array} fnArray - Array containing the operator functions.
  1980. * @property {Array} argsArray - Array containing the arguments of the
  1981. * functions.
  1982. */
  1983. /**
  1984. * Proxy to a PDFPage in the worker thread.
  1985. * @class
  1986. */
  1987. var PDFPageProxy = (function PDFPageProxyClosure() {
  1988. function PDFPageProxy(pageIndex, pageInfo, transport) {
  1989. this.pageIndex = pageIndex;
  1990. this.pageInfo = pageInfo;
  1991. this.transport = transport;
  1992. this.stats = new StatTimer();
  1993. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  1994. this.commonObjs = transport.commonObjs;
  1995. this.objs = new PDFObjects();
  1996. this.cleanupAfterRender = false;
  1997. this.pendingDestroy = false;
  1998. this.intentStates = {};
  1999. }
  2000. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  2001. /**
  2002. * @return {number} Page number of the page. First page is 1.
  2003. */
  2004. get pageNumber() {
  2005. return this.pageIndex + 1;
  2006. },
  2007. /**
  2008. * @return {number} The number of degrees the page is rotated clockwise.
  2009. */
  2010. get rotate() {
  2011. return this.pageInfo.rotate;
  2012. },
  2013. /**
  2014. * @return {Object} The reference that points to this page. It has 'num' and
  2015. * 'gen' properties.
  2016. */
  2017. get ref() {
  2018. return this.pageInfo.ref;
  2019. },
  2020. /**
  2021. * @return {Array} An array of the visible portion of the PDF page in the
  2022. * user space units - [x1, y1, x2, y2].
  2023. */
  2024. get view() {
  2025. return this.pageInfo.view;
  2026. },
  2027. /**
  2028. * @param {number} scale The desired scale of the viewport.
  2029. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  2030. * defaults to the page rotation.
  2031. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  2032. * along with transforms required for rendering.
  2033. */
  2034. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  2035. if (arguments.length < 2) {
  2036. rotate = this.rotate;
  2037. }
  2038. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  2039. },
  2040. /**
  2041. * @return {Promise} A promise that is resolved with an {Array} of the
  2042. * annotation objects.
  2043. */
  2044. getAnnotations: function PDFPageProxy_getAnnotations() {
  2045. if (this.annotationsPromise) {
  2046. return this.annotationsPromise;
  2047. }
  2048. var promise = this.transport.getAnnotations(this.pageIndex);
  2049. this.annotationsPromise = promise;
  2050. return promise;
  2051. },
  2052. /**
  2053. * Begins the process of rendering a page to the desired context.
  2054. * @param {RenderParameters} params Page render parameters.
  2055. * @return {RenderTask} An object that contains the promise, which
  2056. * is resolved when the page finishes rendering.
  2057. */
  2058. render: function PDFPageProxy_render(params) {
  2059. var stats = this.stats;
  2060. stats.time('Overall');
  2061. // If there was a pending destroy cancel it so no cleanup happens during
  2062. // this call to render.
  2063. this.pendingDestroy = false;
  2064. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  2065. if (!this.intentStates[renderingIntent]) {
  2066. this.intentStates[renderingIntent] = {};
  2067. }
  2068. var intentState = this.intentStates[renderingIntent];
  2069. // If there's no displayReadyCapability yet, then the operatorList
  2070. // was never requested before. Make the request and create the promise.
  2071. if (!intentState.displayReadyCapability) {
  2072. intentState.receivingOperatorList = true;
  2073. intentState.displayReadyCapability = createPromiseCapability();
  2074. intentState.operatorList = {
  2075. fnArray: [],
  2076. argsArray: [],
  2077. lastChunk: false
  2078. };
  2079. this.stats.time('Page Request');
  2080. this.transport.messageHandler.send('RenderPageRequest', {
  2081. pageIndex: this.pageNumber - 1,
  2082. intent: renderingIntent
  2083. });
  2084. }
  2085. var internalRenderTask = new InternalRenderTask(complete, params,
  2086. this.objs,
  2087. this.commonObjs,
  2088. intentState.operatorList,
  2089. this.pageNumber);
  2090. if (!intentState.renderTasks) {
  2091. intentState.renderTasks = [];
  2092. }
  2093. intentState.renderTasks.push(internalRenderTask);
  2094. var renderTask = internalRenderTask.task;
  2095. // Obsolete parameter support
  2096. if (params.continueCallback) {
  2097. renderTask.onContinue = params.continueCallback;
  2098. }
  2099. var self = this;
  2100. intentState.displayReadyCapability.promise.then(
  2101. function pageDisplayReadyPromise(transparency) {
  2102. if (self.pendingDestroy) {
  2103. complete();
  2104. return;
  2105. }
  2106. stats.time('Rendering');
  2107. internalRenderTask.initalizeGraphics(transparency);
  2108. internalRenderTask.operatorListChanged();
  2109. },
  2110. function pageDisplayReadPromiseError(reason) {
  2111. complete(reason);
  2112. }
  2113. );
  2114. function complete(error) {
  2115. var i = intentState.renderTasks.indexOf(internalRenderTask);
  2116. if (i >= 0) {
  2117. intentState.renderTasks.splice(i, 1);
  2118. }
  2119. if (self.cleanupAfterRender) {
  2120. self.pendingDestroy = true;
  2121. }
  2122. self._tryDestroy();
  2123. if (error) {
  2124. internalRenderTask.capability.reject(error);
  2125. } else {
  2126. internalRenderTask.capability.resolve();
  2127. }
  2128. stats.timeEnd('Rendering');
  2129. stats.timeEnd('Overall');
  2130. }
  2131. return renderTask;
  2132. },
  2133. /**
  2134. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  2135. * object that represents page's operator list.
  2136. */
  2137. getOperatorList: function PDFPageProxy_getOperatorList() {
  2138. function operatorListChanged() {
  2139. if (intentState.operatorList.lastChunk) {
  2140. intentState.opListReadCapability.resolve(intentState.operatorList);
  2141. }
  2142. }
  2143. var renderingIntent = 'oplist';
  2144. if (!this.intentStates[renderingIntent]) {
  2145. this.intentStates[renderingIntent] = {};
  2146. }
  2147. var intentState = this.intentStates[renderingIntent];
  2148. if (!intentState.opListReadCapability) {
  2149. var opListTask = {};
  2150. opListTask.operatorListChanged = operatorListChanged;
  2151. intentState.receivingOperatorList = true;
  2152. intentState.opListReadCapability = createPromiseCapability();
  2153. intentState.renderTasks = [];
  2154. intentState.renderTasks.push(opListTask);
  2155. intentState.operatorList = {
  2156. fnArray: [],
  2157. argsArray: [],
  2158. lastChunk: false
  2159. };
  2160. this.transport.messageHandler.send('RenderPageRequest', {
  2161. pageIndex: this.pageIndex,
  2162. intent: renderingIntent
  2163. });
  2164. }
  2165. return intentState.opListReadCapability.promise;
  2166. },
  2167. /**
  2168. * @return {Promise} That is resolved a {@link TextContent}
  2169. * object that represent the page text content.
  2170. */
  2171. getTextContent: function PDFPageProxy_getTextContent() {
  2172. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  2173. pageIndex: this.pageNumber - 1
  2174. });
  2175. },
  2176. /**
  2177. * Destroys resources allocated by the page.
  2178. */
  2179. destroy: function PDFPageProxy_destroy() {
  2180. this.pendingDestroy = true;
  2181. this._tryDestroy();
  2182. },
  2183. /**
  2184. * For internal use only. Attempts to clean up if rendering is in a state
  2185. * where that's possible.
  2186. * @ignore
  2187. */
  2188. _tryDestroy: function PDFPageProxy__destroy() {
  2189. if (!this.pendingDestroy ||
  2190. Object.keys(this.intentStates).some(function(intent) {
  2191. var intentState = this.intentStates[intent];
  2192. return (intentState.renderTasks.length !== 0 ||
  2193. intentState.receivingOperatorList);
  2194. }, this)) {
  2195. return;
  2196. }
  2197. Object.keys(this.intentStates).forEach(function(intent) {
  2198. delete this.intentStates[intent];
  2199. }, this);
  2200. this.objs.clear();
  2201. this.annotationsPromise = null;
  2202. this.pendingDestroy = false;
  2203. },
  2204. /**
  2205. * For internal use only.
  2206. * @ignore
  2207. */
  2208. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2209. intent) {
  2210. var intentState = this.intentStates[intent];
  2211. // TODO Refactor RenderPageRequest to separate rendering
  2212. // and operator list logic
  2213. if (intentState.displayReadyCapability) {
  2214. intentState.displayReadyCapability.resolve(transparency);
  2215. }
  2216. },
  2217. /**
  2218. * For internal use only.
  2219. * @ignore
  2220. */
  2221. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2222. intent) {
  2223. var intentState = this.intentStates[intent];
  2224. var i, ii;
  2225. // Add the new chunk to the current operator list.
  2226. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2227. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2228. intentState.operatorList.argsArray.push(
  2229. operatorListChunk.argsArray[i]);
  2230. }
  2231. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2232. // Notify all the rendering tasks there are more operators to be consumed.
  2233. for (i = 0; i < intentState.renderTasks.length; i++) {
  2234. intentState.renderTasks[i].operatorListChanged();
  2235. }
  2236. if (operatorListChunk.lastChunk) {
  2237. intentState.receivingOperatorList = false;
  2238. this._tryDestroy();
  2239. }
  2240. }
  2241. };
  2242. return PDFPageProxy;
  2243. })();
  2244. /**
  2245. * For internal use only.
  2246. * @ignore
  2247. */
  2248. var WorkerTransport = (function WorkerTransportClosure() {
  2249. function WorkerTransport(workerInitializedCapability, pdfDataRangeTransport) {
  2250. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2251. this.workerInitializedCapability = workerInitializedCapability;
  2252. this.commonObjs = new PDFObjects();
  2253. this.loadingTask = null;
  2254. this.pageCache = [];
  2255. this.pagePromises = [];
  2256. this.downloadInfoCapability = createPromiseCapability();
  2257. // If worker support isn't disabled explicit and the browser has worker
  2258. // support, create a new web worker and test if it/the browser fullfills
  2259. // all requirements to run parts of pdf.js in a web worker.
  2260. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2261. // as it arrives on the worker. Chrome added this with version 15.
  2262. // Either workers are disabled, not supported or have thrown an exception.
  2263. // Thus, we fallback to a faked worker.
  2264. this.setupFakeWorker();
  2265. }
  2266. WorkerTransport.prototype = {
  2267. destroy: function WorkerTransport_destroy() {
  2268. this.pageCache = [];
  2269. this.pagePromises = [];
  2270. var self = this;
  2271. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2272. FontLoader.clear();
  2273. if (self.worker) {
  2274. self.worker.terminate();
  2275. }
  2276. });
  2277. },
  2278. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2279. globalScope.PDFJS.disableWorker = true;
  2280. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2281. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2282. // In the developer build load worker_loader which in turn loads all the
  2283. // other files and resolves the promise. In production only the
  2284. // pdf.worker.js file is needed.
  2285. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2286. }
  2287. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2288. warn('Setting up fake worker.');
  2289. // If we don't use a worker, just post/sendMessage to the main thread.
  2290. var fakeWorker = {
  2291. postMessage: function WorkerTransport_postMessage(obj) {
  2292. fakeWorker.onmessage({data: obj});
  2293. },
  2294. terminate: function WorkerTransport_terminate() {}
  2295. };
  2296. var messageHandler = new MessageHandler('main', fakeWorker);
  2297. this.setupMessageHandler(messageHandler);
  2298. // If the main thread is our worker, setup the handling for the messages
  2299. // the main thread sends to it self.
  2300. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2301. this.workerInitializedCapability.resolve();
  2302. }.bind(this));
  2303. },
  2304. setupMessageHandler:
  2305. function WorkerTransport_setupMessageHandler(messageHandler) {
  2306. this.messageHandler = messageHandler;
  2307. function updatePassword(password) {
  2308. messageHandler.send('UpdatePassword', password);
  2309. }
  2310. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2311. if (pdfDataRangeTransport) {
  2312. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2313. messageHandler.send('OnDataRange', {
  2314. begin: begin,
  2315. chunk: chunk
  2316. });
  2317. });
  2318. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2319. messageHandler.send('OnDataProgress', {
  2320. loaded: loaded
  2321. });
  2322. });
  2323. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  2324. messageHandler.send('OnDataRange', {
  2325. chunk: chunk
  2326. });
  2327. });
  2328. messageHandler.on('RequestDataRange',
  2329. function transportDataRange(data) {
  2330. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2331. }, this);
  2332. }
  2333. messageHandler.on('GetDoc', function transportDoc(data) {
  2334. var pdfInfo = data.pdfInfo;
  2335. this.numPages = data.pdfInfo.numPages;
  2336. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2337. this.pdfDocument = pdfDocument;
  2338. this.loadingTask._capability.resolve(pdfDocument);
  2339. }, this);
  2340. messageHandler.on('NeedPassword',
  2341. function transportNeedPassword(exception) {
  2342. var loadingTask = this.loadingTask;
  2343. if (loadingTask.onPassword) {
  2344. return loadingTask.onPassword(updatePassword,
  2345. PasswordResponses.NEED_PASSWORD);
  2346. }
  2347. loadingTask._capability.reject(
  2348. new PasswordException(exception.message, exception.code));
  2349. }, this);
  2350. messageHandler.on('IncorrectPassword',
  2351. function transportIncorrectPassword(exception) {
  2352. var loadingTask = this.loadingTask;
  2353. if (loadingTask.onPassword) {
  2354. return loadingTask.onPassword(updatePassword,
  2355. PasswordResponses.INCORRECT_PASSWORD);
  2356. }
  2357. loadingTask._capability.reject(
  2358. new PasswordException(exception.message, exception.code));
  2359. }, this);
  2360. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2361. this.loadingTask._capability.reject(
  2362. new InvalidPDFException(exception.message));
  2363. }, this);
  2364. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2365. this.loadingTask._capability.reject(
  2366. new MissingPDFException(exception.message));
  2367. }, this);
  2368. messageHandler.on('UnexpectedResponse',
  2369. function transportUnexpectedResponse(exception) {
  2370. this.loadingTask._capability.reject(
  2371. new UnexpectedResponseException(exception.message, exception.status));
  2372. }, this);
  2373. messageHandler.on('UnknownError',
  2374. function transportUnknownError(exception) {
  2375. this.loadingTask._capability.reject(
  2376. new UnknownErrorException(exception.message, exception.details));
  2377. }, this);
  2378. messageHandler.on('DataLoaded', function transportPage(data) {
  2379. this.downloadInfoCapability.resolve(data);
  2380. }, this);
  2381. messageHandler.on('PDFManagerReady', function transportPage(data) {
  2382. if (this.pdfDataRangeTransport) {
  2383. this.pdfDataRangeTransport.transportReady();
  2384. }
  2385. }, this);
  2386. messageHandler.on('StartRenderPage', function transportRender(data) {
  2387. var page = this.pageCache[data.pageIndex];
  2388. page.stats.timeEnd('Page Request');
  2389. page._startRenderPage(data.transparency, data.intent);
  2390. }, this);
  2391. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2392. var page = this.pageCache[data.pageIndex];
  2393. page._renderPageChunk(data.operatorList, data.intent);
  2394. }, this);
  2395. messageHandler.on('commonobj', function transportObj(data) {
  2396. var id = data[0];
  2397. var type = data[1];
  2398. if (this.commonObjs.hasData(id)) {
  2399. return;
  2400. }
  2401. switch (type) {
  2402. case 'Font':
  2403. var exportedData = data[2];
  2404. var font;
  2405. if ('error' in exportedData) {
  2406. var error = exportedData.error;
  2407. warn('Error during font loading: ' + error);
  2408. this.commonObjs.resolve(id, error);
  2409. break;
  2410. } else {
  2411. font = new FontFaceObject(exportedData);
  2412. }
  2413. FontLoader.bind(
  2414. [font],
  2415. function fontReady(fontObjs) {
  2416. this.commonObjs.resolve(id, font);
  2417. }.bind(this)
  2418. );
  2419. break;
  2420. case 'FontPath':
  2421. this.commonObjs.resolve(id, data[2]);
  2422. break;
  2423. default:
  2424. error('Got unknown common object type ' + type);
  2425. }
  2426. }, this);
  2427. messageHandler.on('obj', function transportObj(data) {
  2428. var id = data[0];
  2429. var pageIndex = data[1];
  2430. var type = data[2];
  2431. var pageProxy = this.pageCache[pageIndex];
  2432. var imageData;
  2433. if (pageProxy.objs.hasData(id)) {
  2434. return;
  2435. }
  2436. switch (type) {
  2437. case 'JpegStream':
  2438. imageData = data[3];
  2439. loadJpegStream(id, imageData, pageProxy.objs);
  2440. break;
  2441. case 'Image':
  2442. imageData = data[3];
  2443. pageProxy.objs.resolve(id, imageData);
  2444. // heuristics that will allow not to store large data
  2445. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2446. if (imageData && 'data' in imageData &&
  2447. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2448. pageProxy.cleanupAfterRender = true;
  2449. }
  2450. break;
  2451. default:
  2452. error('Got unknown object type ' + type);
  2453. }
  2454. }, this);
  2455. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2456. var loadingTask = this.loadingTask;
  2457. if (loadingTask.onProgress) {
  2458. loadingTask.onProgress({
  2459. loaded: data.loaded,
  2460. total: data.total
  2461. });
  2462. }
  2463. }, this);
  2464. messageHandler.on('PageError', function transportError(data) {
  2465. var page = this.pageCache[data.pageNum - 1];
  2466. var intentState = page.intentStates[data.intent];
  2467. if (intentState.displayReadyCapability) {
  2468. intentState.displayReadyCapability.reject(data.error);
  2469. } else {
  2470. error(data.error);
  2471. }
  2472. }, this);
  2473. messageHandler.on('JpegDecode', function(data) {
  2474. var imageUrl = data[0];
  2475. var components = data[1];
  2476. if (components !== 3 && components !== 1) {
  2477. return Promise.reject(
  2478. new Error('Only 3 components or 1 component can be returned'));
  2479. }
  2480. return new Promise(function (resolve, reject) {
  2481. var img = new Image();
  2482. img.onload = function () {
  2483. var width = img.width;
  2484. var height = img.height;
  2485. var size = width * height;
  2486. var rgbaLength = size * 4;
  2487. var buf = new Uint8Array(size * components);
  2488. var tmpCanvas = createScratchCanvas(width, height);
  2489. var tmpCtx = tmpCanvas.getContext('2d');
  2490. tmpCtx.drawImage(img, 0, 0);
  2491. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2492. var i, j;
  2493. if (components === 3) {
  2494. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2495. buf[j] = data[i];
  2496. buf[j + 1] = data[i + 1];
  2497. buf[j + 2] = data[i + 2];
  2498. }
  2499. } else if (components === 1) {
  2500. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2501. buf[j] = data[i];
  2502. }
  2503. }
  2504. resolve({ data: buf, width: width, height: height});
  2505. };
  2506. img.onerror = function () {
  2507. reject(new Error('JpegDecode failed to load image'));
  2508. };
  2509. img.src = imageUrl;
  2510. });
  2511. });
  2512. },
  2513. fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
  2514. this.loadingTask = loadingTask;
  2515. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2516. source.disableStream = PDFJS.disableStream;
  2517. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2518. if (this.pdfDataRangeTransport) {
  2519. source.length = this.pdfDataRangeTransport.length;
  2520. source.initialData = this.pdfDataRangeTransport.initialData;
  2521. }
  2522. this.messageHandler.send('GetDocRequest', {
  2523. source: source,
  2524. disableRange: PDFJS.disableRange,
  2525. maxImageSize: PDFJS.maxImageSize,
  2526. cMapUrl: PDFJS.cMapUrl,
  2527. cMapPacked: PDFJS.cMapPacked,
  2528. disableFontFace: PDFJS.disableFontFace,
  2529. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2530. verbosity: PDFJS.verbosity
  2531. });
  2532. },
  2533. getData: function WorkerTransport_getData() {
  2534. return this.messageHandler.sendWithPromise('GetData', null);
  2535. },
  2536. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2537. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2538. (pageNumber|0) !== pageNumber) {
  2539. return Promise.reject(new Error('Invalid page request'));
  2540. }
  2541. var pageIndex = pageNumber - 1;
  2542. if (pageIndex in this.pagePromises) {
  2543. return this.pagePromises[pageIndex];
  2544. }
  2545. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2546. pageIndex: pageIndex
  2547. }).then(function (pageInfo) {
  2548. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2549. this.pageCache[pageIndex] = page;
  2550. return page;
  2551. }.bind(this));
  2552. this.pagePromises[pageIndex] = promise;
  2553. return promise;
  2554. },
  2555. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2556. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2557. },
  2558. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2559. return this.messageHandler.sendWithPromise('GetAnnotations',
  2560. { pageIndex: pageIndex });
  2561. },
  2562. getDestinations: function WorkerTransport_getDestinations() {
  2563. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2564. },
  2565. getDestination: function WorkerTransport_getDestination(id) {
  2566. return this.messageHandler.sendWithPromise('GetDestination', { id: id } );
  2567. },
  2568. getAttachments: function WorkerTransport_getAttachments() {
  2569. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2570. },
  2571. getJavaScript: function WorkerTransport_getJavaScript() {
  2572. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2573. },
  2574. getOutline: function WorkerTransport_getOutline() {
  2575. return this.messageHandler.sendWithPromise('GetOutline', null);
  2576. },
  2577. getMetadata: function WorkerTransport_getMetadata() {
  2578. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2579. then(function transportMetadata(results) {
  2580. return {
  2581. info: results[0],
  2582. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2583. };
  2584. });
  2585. },
  2586. getStats: function WorkerTransport_getStats() {
  2587. return this.messageHandler.sendWithPromise('GetStats', null);
  2588. },
  2589. startCleanup: function WorkerTransport_startCleanup() {
  2590. this.messageHandler.sendWithPromise('Cleanup', null).
  2591. then(function endCleanup() {
  2592. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2593. var page = this.pageCache[i];
  2594. if (page) {
  2595. page.destroy();
  2596. }
  2597. }
  2598. this.commonObjs.clear();
  2599. FontLoader.clear();
  2600. }.bind(this));
  2601. }
  2602. };
  2603. return WorkerTransport;
  2604. })();
  2605. /**
  2606. * A PDF document and page is built of many objects. E.g. there are objects
  2607. * for fonts, images, rendering code and such. These objects might get processed
  2608. * inside of a worker. The `PDFObjects` implements some basic functions to
  2609. * manage these objects.
  2610. * @ignore
  2611. */
  2612. var PDFObjects = (function PDFObjectsClosure() {
  2613. function PDFObjects() {
  2614. this.objs = {};
  2615. }
  2616. PDFObjects.prototype = {
  2617. /**
  2618. * Internal function.
  2619. * Ensures there is an object defined for `objId`.
  2620. */
  2621. ensureObj: function PDFObjects_ensureObj(objId) {
  2622. if (this.objs[objId]) {
  2623. return this.objs[objId];
  2624. }
  2625. var obj = {
  2626. capability: createPromiseCapability(),
  2627. data: null,
  2628. resolved: false
  2629. };
  2630. this.objs[objId] = obj;
  2631. return obj;
  2632. },
  2633. /**
  2634. * If called *without* callback, this returns the data of `objId` but the
  2635. * object needs to be resolved. If it isn't, this function throws.
  2636. *
  2637. * If called *with* a callback, the callback is called with the data of the
  2638. * object once the object is resolved. That means, if you call this
  2639. * function and the object is already resolved, the callback gets called
  2640. * right away.
  2641. */
  2642. get: function PDFObjects_get(objId, callback) {
  2643. // If there is a callback, then the get can be async and the object is
  2644. // not required to be resolved right now
  2645. if (callback) {
  2646. this.ensureObj(objId).capability.promise.then(callback);
  2647. return null;
  2648. }
  2649. // If there isn't a callback, the user expects to get the resolved data
  2650. // directly.
  2651. var obj = this.objs[objId];
  2652. // If there isn't an object yet or the object isn't resolved, then the
  2653. // data isn't ready yet!
  2654. if (!obj || !obj.resolved) {
  2655. error('Requesting object that isn\'t resolved yet ' + objId);
  2656. }
  2657. return obj.data;
  2658. },
  2659. /**
  2660. * Resolves the object `objId` with optional `data`.
  2661. */
  2662. resolve: function PDFObjects_resolve(objId, data) {
  2663. var obj = this.ensureObj(objId);
  2664. obj.resolved = true;
  2665. obj.data = data;
  2666. obj.capability.resolve(data);
  2667. },
  2668. isResolved: function PDFObjects_isResolved(objId) {
  2669. var objs = this.objs;
  2670. if (!objs[objId]) {
  2671. return false;
  2672. } else {
  2673. return objs[objId].resolved;
  2674. }
  2675. },
  2676. hasData: function PDFObjects_hasData(objId) {
  2677. return this.isResolved(objId);
  2678. },
  2679. /**
  2680. * Returns the data of `objId` if object exists, null otherwise.
  2681. */
  2682. getData: function PDFObjects_getData(objId) {
  2683. var objs = this.objs;
  2684. if (!objs[objId] || !objs[objId].resolved) {
  2685. return null;
  2686. } else {
  2687. return objs[objId].data;
  2688. }
  2689. },
  2690. clear: function PDFObjects_clear() {
  2691. this.objs = {};
  2692. }
  2693. };
  2694. return PDFObjects;
  2695. })();
  2696. /**
  2697. * Allows controlling of the rendering tasks.
  2698. * @class
  2699. */
  2700. var RenderTask = (function RenderTaskClosure() {
  2701. function RenderTask(internalRenderTask) {
  2702. this._internalRenderTask = internalRenderTask;
  2703. /**
  2704. * Callback for incremental rendering -- a function that will be called
  2705. * each time the rendering is paused. To continue rendering call the
  2706. * function that is the first argument to the callback.
  2707. * @type {function}
  2708. */
  2709. this.onContinue = null;
  2710. }
  2711. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2712. /**
  2713. * Promise for rendering task completion.
  2714. * @return {Promise}
  2715. */
  2716. get promise() {
  2717. return this._internalRenderTask.capability.promise;
  2718. },
  2719. /**
  2720. * Cancels the rendering task. If the task is currently rendering it will
  2721. * not be cancelled until graphics pauses with a timeout. The promise that
  2722. * this object extends will resolved when cancelled.
  2723. */
  2724. cancel: function RenderTask_cancel() {
  2725. this._internalRenderTask.cancel();
  2726. },
  2727. /**
  2728. * Registers callbacks to indicate the rendering task completion.
  2729. *
  2730. * @param {function} onFulfilled The callback for the rendering completion.
  2731. * @param {function} onRejected The callback for the rendering failure.
  2732. * @return {Promise} A promise that is resolved after the onFulfilled or
  2733. * onRejected callback.
  2734. */
  2735. then: function RenderTask_then(onFulfilled, onRejected) {
  2736. return this.promise.then.apply(this.promise, arguments);
  2737. }
  2738. };
  2739. return RenderTask;
  2740. })();
  2741. /**
  2742. * For internal use only.
  2743. * @ignore
  2744. */
  2745. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2746. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2747. pageNumber) {
  2748. this.callback = callback;
  2749. this.params = params;
  2750. this.objs = objs;
  2751. this.commonObjs = commonObjs;
  2752. this.operatorListIdx = null;
  2753. this.operatorList = operatorList;
  2754. this.pageNumber = pageNumber;
  2755. this.running = false;
  2756. this.graphicsReadyCallback = null;
  2757. this.graphicsReady = false;
  2758. this.cancelled = false;
  2759. this.capability = createPromiseCapability();
  2760. this.task = new RenderTask(this);
  2761. // caching this-bound methods
  2762. this._continueBound = this._continue.bind(this);
  2763. this._scheduleNextBound = this._scheduleNext.bind(this);
  2764. this._nextBound = this._next.bind(this);
  2765. }
  2766. InternalRenderTask.prototype = {
  2767. initalizeGraphics:
  2768. function InternalRenderTask_initalizeGraphics(transparency) {
  2769. if (this.cancelled) {
  2770. return;
  2771. }
  2772. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2773. globalScope.StepperManager.enabled) {
  2774. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2775. this.stepper.init(this.operatorList);
  2776. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2777. }
  2778. var params = this.params;
  2779. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2780. this.objs, params.imageLayer);
  2781. this.gfx.beginDrawing(params.viewport, transparency);
  2782. this.operatorListIdx = 0;
  2783. this.graphicsReady = true;
  2784. if (this.graphicsReadyCallback) {
  2785. this.graphicsReadyCallback();
  2786. }
  2787. },
  2788. cancel: function InternalRenderTask_cancel() {
  2789. this.running = false;
  2790. this.cancelled = true;
  2791. this.callback('cancelled');
  2792. },
  2793. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2794. if (!this.graphicsReady) {
  2795. if (!this.graphicsReadyCallback) {
  2796. this.graphicsReadyCallback = this._continueBound;
  2797. }
  2798. return;
  2799. }
  2800. if (this.stepper) {
  2801. this.stepper.updateOperatorList(this.operatorList);
  2802. }
  2803. if (this.running) {
  2804. return;
  2805. }
  2806. this._continue();
  2807. },
  2808. _continue: function InternalRenderTask__continue() {
  2809. this.running = true;
  2810. if (this.cancelled) {
  2811. return;
  2812. }
  2813. if (this.task.onContinue) {
  2814. this.task.onContinue.call(this.task, this._scheduleNextBound);
  2815. } else {
  2816. this._scheduleNext();
  2817. }
  2818. },
  2819. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2820. window.requestAnimationFrame(this._nextBound);
  2821. },
  2822. _next: function InternalRenderTask__next() {
  2823. if (this.cancelled) {
  2824. return;
  2825. }
  2826. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2827. this.operatorListIdx,
  2828. this._continueBound,
  2829. this.stepper);
  2830. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2831. this.running = false;
  2832. if (this.operatorList.lastChunk) {
  2833. this.gfx.endDrawing();
  2834. this.callback();
  2835. }
  2836. }
  2837. }
  2838. };
  2839. return InternalRenderTask;
  2840. })();
  2841. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2842. function fixMetadata(meta) {
  2843. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2844. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2845. function(code, d1, d2, d3) {
  2846. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2847. });
  2848. var chars = '';
  2849. for (var i = 0; i < bytes.length; i += 2) {
  2850. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2851. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2852. code !== 38 && false ? String.fromCharCode(code) :
  2853. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2854. }
  2855. return '>' + chars;
  2856. });
  2857. }
  2858. function Metadata(meta) {
  2859. if (typeof meta === 'string') {
  2860. // Ghostscript produces invalid metadata
  2861. meta = fixMetadata(meta);
  2862. var parser = new DOMParser();
  2863. meta = parser.parseFromString(meta, 'application/xml');
  2864. } else if (!(meta instanceof Document)) {
  2865. error('Metadata: Invalid metadata object');
  2866. }
  2867. this.metaDocument = meta;
  2868. this.metadata = {};
  2869. this.parse();
  2870. }
  2871. Metadata.prototype = {
  2872. parse: function Metadata_parse() {
  2873. var doc = this.metaDocument;
  2874. var rdf = doc.documentElement;
  2875. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2876. rdf = rdf.firstChild;
  2877. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2878. rdf = rdf.nextSibling;
  2879. }
  2880. }
  2881. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2882. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2883. return;
  2884. }
  2885. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2886. for (i = 0, length = children.length; i < length; i++) {
  2887. desc = children[i];
  2888. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2889. continue;
  2890. }
  2891. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2892. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2893. entry = desc.childNodes[ii];
  2894. name = entry.nodeName.toLowerCase();
  2895. this.metadata[name] = entry.textContent.trim();
  2896. }
  2897. }
  2898. }
  2899. },
  2900. get: function Metadata_get(name) {
  2901. return this.metadata[name] || null;
  2902. },
  2903. has: function Metadata_has(name) {
  2904. return typeof this.metadata[name] !== 'undefined';
  2905. }
  2906. };
  2907. return Metadata;
  2908. })();
  2909. // <canvas> contexts store most of the state we need natively.
  2910. // However, PDF needs a bit more state, which we store here.
  2911. // Minimal font size that would be used during canvas fillText operations.
  2912. var MIN_FONT_SIZE = 16;
  2913. // Maximum font size that would be used during canvas fillText operations.
  2914. var MAX_FONT_SIZE = 100;
  2915. var MAX_GROUP_SIZE = 4096;
  2916. // Heuristic value used when enforcing minimum line widths.
  2917. var MIN_WIDTH_FACTOR = 0.65;
  2918. var COMPILE_TYPE3_GLYPHS = true;
  2919. var MAX_SIZE_TO_COMPILE = 1000;
  2920. var FULL_CHUNK_HEIGHT = 16;
  2921. function createScratchCanvas(width, height) {
  2922. var canvas = document.createElement('canvas');
  2923. canvas.width = width;
  2924. canvas.height = height;
  2925. return canvas;
  2926. }
  2927. function addContextCurrentTransform(ctx) {
  2928. // If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
  2929. if (!ctx.mozCurrentTransform) {
  2930. // Store the original context
  2931. ctx._scaleX = ctx._scaleX || 1.0;
  2932. ctx._scaleY = ctx._scaleY || 1.0;
  2933. ctx._originalSave = ctx.save;
  2934. ctx._originalRestore = ctx.restore;
  2935. ctx._originalRotate = ctx.rotate;
  2936. ctx._originalScale = ctx.scale;
  2937. ctx._originalTranslate = ctx.translate;
  2938. ctx._originalTransform = ctx.transform;
  2939. ctx._originalSetTransform = ctx.setTransform;
  2940. ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
  2941. ctx._transformStack = [];
  2942. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2943. get: function getCurrentTransform() {
  2944. return this._transformMatrix;
  2945. }
  2946. });
  2947. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2948. get: function getCurrentTransformInverse() {
  2949. // Calculation done using WolframAlpha:
  2950. // http://www.wolframalpha.com/input/?
  2951. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2952. var m = this._transformMatrix;
  2953. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2954. var ad_bc = a * d - b * c;
  2955. var bc_ad = b * c - a * d;
  2956. return [
  2957. d / ad_bc,
  2958. b / bc_ad,
  2959. c / bc_ad,
  2960. a / ad_bc,
  2961. (d * e - c * f) / bc_ad,
  2962. (b * e - a * f) / ad_bc
  2963. ];
  2964. }
  2965. });
  2966. ctx.save = function ctxSave() {
  2967. var old = this._transformMatrix;
  2968. this._transformStack.push(old);
  2969. this._transformMatrix = old.slice(0, 6);
  2970. this._originalSave();
  2971. };
  2972. ctx.restore = function ctxRestore() {
  2973. var prev = this._transformStack.pop();
  2974. if (prev) {
  2975. this._transformMatrix = prev;
  2976. this._originalRestore();
  2977. }
  2978. };
  2979. ctx.translate = function ctxTranslate(x, y) {
  2980. var m = this._transformMatrix;
  2981. m[4] = m[0] * x + m[2] * y + m[4];
  2982. m[5] = m[1] * x + m[3] * y + m[5];
  2983. this._originalTranslate(x, y);
  2984. };
  2985. ctx.scale = function ctxScale(x, y) {
  2986. var m = this._transformMatrix;
  2987. m[0] = m[0] * x;
  2988. m[1] = m[1] * x;
  2989. m[2] = m[2] * y;
  2990. m[3] = m[3] * y;
  2991. this._originalScale(x, y);
  2992. };
  2993. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  2994. var m = this._transformMatrix;
  2995. this._transformMatrix = [
  2996. m[0] * a + m[2] * b,
  2997. m[1] * a + m[3] * b,
  2998. m[0] * c + m[2] * d,
  2999. m[1] * c + m[3] * d,
  3000. m[0] * e + m[2] * f + m[4],
  3001. m[1] * e + m[3] * f + m[5]
  3002. ];
  3003. ctx._originalTransform(a, b, c, d, e, f);
  3004. };
  3005. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3006. this._transformMatrix = [a, b, c, d, e, f];
  3007. ctx._originalSetTransform(a, b, c, d, e, f);
  3008. };
  3009. ctx.rotate = function ctxRotate(angle) {
  3010. var cosValue = Math.cos(angle);
  3011. var sinValue = Math.sin(angle);
  3012. var m = this._transformMatrix;
  3013. this._transformMatrix = [
  3014. m[0] * cosValue + m[2] * sinValue,
  3015. m[1] * cosValue + m[3] * sinValue,
  3016. m[0] * (-sinValue) + m[2] * cosValue,
  3017. m[1] * (-sinValue) + m[3] * cosValue,
  3018. m[4],
  3019. m[5]
  3020. ];
  3021. this._originalRotate(angle);
  3022. };
  3023. }
  3024. }
  3025. var CachedCanvases = (function CachedCanvasesClosure() {
  3026. var cache = {};
  3027. return {
  3028. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3029. trackTransform) {
  3030. var canvasEntry;
  3031. if (cache[id] !== undefined) {
  3032. canvasEntry = cache[id];
  3033. canvasEntry.canvas.width = width;
  3034. canvasEntry.canvas.height = height;
  3035. // reset canvas transform for emulated mozCurrentTransform, if needed
  3036. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3037. } else {
  3038. var canvas = createScratchCanvas(width, height);
  3039. var ctx = canvas.getContext('2d');
  3040. if (trackTransform) {
  3041. addContextCurrentTransform(ctx);
  3042. }
  3043. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3044. }
  3045. return canvasEntry;
  3046. },
  3047. clear: function () {
  3048. for (var id in cache) {
  3049. var canvasEntry = cache[id];
  3050. // Zeroing the width and height causes Firefox to release graphics
  3051. // resources immediately, which can greatly reduce memory consumption.
  3052. canvasEntry.canvas.width = 0;
  3053. canvasEntry.canvas.height = 0;
  3054. delete cache[id];
  3055. }
  3056. }
  3057. };
  3058. })();
  3059. function compileType3Glyph(imgData) {
  3060. var POINT_TO_PROCESS_LIMIT = 1000;
  3061. var width = imgData.width, height = imgData.height;
  3062. var i, j, j0, width1 = width + 1;
  3063. var points = new Uint8Array(width1 * (height + 1));
  3064. var POINT_TYPES =
  3065. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3066. // decodes bit-packed mask data
  3067. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3068. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3069. for (i = 0, ii = data0.length; i < ii; i++) {
  3070. var mask = 128, elem = data0[i];
  3071. while (mask > 0) {
  3072. data[pos++] = (elem & mask) ? 0 : 255;
  3073. mask >>= 1;
  3074. }
  3075. }
  3076. // finding iteresting points: every point is located between mask pixels,
  3077. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3078. // will have flags assigned based on neighboring mask pixels:
  3079. // 4 | 8
  3080. // --P--
  3081. // 2 | 1
  3082. // We are interested only in points with the flags:
  3083. // - outside corners: 1, 2, 4, 8;
  3084. // - inside corners: 7, 11, 13, 14;
  3085. // - and, intersections: 5, 10.
  3086. var count = 0;
  3087. pos = 0;
  3088. if (data[pos] !== 0) {
  3089. points[0] = 1;
  3090. ++count;
  3091. }
  3092. for (j = 1; j < width; j++) {
  3093. if (data[pos] !== data[pos + 1]) {
  3094. points[j] = data[pos] ? 2 : 1;
  3095. ++count;
  3096. }
  3097. pos++;
  3098. }
  3099. if (data[pos] !== 0) {
  3100. points[j] = 2;
  3101. ++count;
  3102. }
  3103. for (i = 1; i < height; i++) {
  3104. pos = i * lineSize;
  3105. j0 = i * width1;
  3106. if (data[pos - lineSize] !== data[pos]) {
  3107. points[j0] = data[pos] ? 1 : 8;
  3108. ++count;
  3109. }
  3110. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3111. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3112. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3113. for (j = 1; j < width; j++) {
  3114. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3115. (data[pos - lineSize + 1] ? 8 : 0);
  3116. if (POINT_TYPES[sum]) {
  3117. points[j0 + j] = POINT_TYPES[sum];
  3118. ++count;
  3119. }
  3120. pos++;
  3121. }
  3122. if (data[pos - lineSize] !== data[pos]) {
  3123. points[j0 + j] = data[pos] ? 2 : 4;
  3124. ++count;
  3125. }
  3126. if (count > POINT_TO_PROCESS_LIMIT) {
  3127. return null;
  3128. }
  3129. }
  3130. pos = lineSize * (height - 1);
  3131. j0 = i * width1;
  3132. if (data[pos] !== 0) {
  3133. points[j0] = 8;
  3134. ++count;
  3135. }
  3136. for (j = 1; j < width; j++) {
  3137. if (data[pos] !== data[pos + 1]) {
  3138. points[j0 + j] = data[pos] ? 4 : 8;
  3139. ++count;
  3140. }
  3141. pos++;
  3142. }
  3143. if (data[pos] !== 0) {
  3144. points[j0 + j] = 4;
  3145. ++count;
  3146. }
  3147. if (count > POINT_TO_PROCESS_LIMIT) {
  3148. return null;
  3149. }
  3150. // building outlines
  3151. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3152. var outlines = [];
  3153. for (i = 0; count && i <= height; i++) {
  3154. var p = i * width1;
  3155. var end = p + width;
  3156. while (p < end && !points[p]) {
  3157. p++;
  3158. }
  3159. if (p === end) {
  3160. continue;
  3161. }
  3162. var coords = [p % width1, i];
  3163. var type = points[p], p0 = p, pp;
  3164. do {
  3165. var step = steps[type];
  3166. do {
  3167. p += step;
  3168. } while (!points[p]);
  3169. pp = points[p];
  3170. if (pp !== 5 && pp !== 10) {
  3171. // set new direction
  3172. type = pp;
  3173. // delete mark
  3174. points[p] = 0;
  3175. } else { // type is 5 or 10, ie, a crossing
  3176. // set new direction
  3177. type = pp & ((0x33 * type) >> 4);
  3178. // set new type for "future hit"
  3179. points[p] &= (type >> 2 | type << 2);
  3180. }
  3181. coords.push(p % width1);
  3182. coords.push((p / width1) | 0);
  3183. --count;
  3184. } while (p0 !== p);
  3185. outlines.push(coords);
  3186. --i;
  3187. }
  3188. var drawOutline = function(c) {
  3189. c.save();
  3190. // the path shall be painted in [0..1]x[0..1] space
  3191. c.scale(1 / width, -1 / height);
  3192. c.translate(0, -height);
  3193. c.beginPath();
  3194. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3195. var o = outlines[i];
  3196. c.moveTo(o[0], o[1]);
  3197. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3198. c.lineTo(o[j], o[j+1]);
  3199. }
  3200. }
  3201. c.fill();
  3202. c.beginPath();
  3203. c.restore();
  3204. };
  3205. return drawOutline;
  3206. }
  3207. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3208. function CanvasExtraState(old) {
  3209. // Are soft masks and alpha values shapes or opacities?
  3210. this.alphaIsShape = false;
  3211. this.fontSize = 0;
  3212. this.fontSizeScale = 1;
  3213. this.textMatrix = IDENTITY_MATRIX;
  3214. this.textMatrixScale = 1;
  3215. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3216. this.leading = 0;
  3217. // Current point (in user coordinates)
  3218. this.x = 0;
  3219. this.y = 0;
  3220. // Start of text line (in text coordinates)
  3221. this.lineX = 0;
  3222. this.lineY = 0;
  3223. // Character and word spacing
  3224. this.charSpacing = 0;
  3225. this.wordSpacing = 0;
  3226. this.textHScale = 1;
  3227. this.textRenderingMode = TextRenderingMode.FILL;
  3228. this.textRise = 0;
  3229. // Default fore and background colors
  3230. this.fillColor = '#000000';
  3231. this.strokeColor = '#000000';
  3232. this.patternFill = false;
  3233. // Note: fill alpha applies to all non-stroking operations
  3234. this.fillAlpha = 1;
  3235. this.strokeAlpha = 1;
  3236. this.lineWidth = 1;
  3237. this.activeSMask = null; // nonclonable field (see the save method below)
  3238. this.old = old;
  3239. }
  3240. CanvasExtraState.prototype = {
  3241. clone: function CanvasExtraState_clone() {
  3242. return Object.create(this);
  3243. },
  3244. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3245. this.x = x;
  3246. this.y = y;
  3247. }
  3248. };
  3249. return CanvasExtraState;
  3250. })();
  3251. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3252. // Defines the time the executeOperatorList is going to be executing
  3253. // before it stops and shedules a continue of execution.
  3254. var EXECUTION_TIME = 15;
  3255. // Defines the number of steps before checking the execution time
  3256. var EXECUTION_STEPS = 10;
  3257. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3258. this.ctx = canvasCtx;
  3259. this.current = new CanvasExtraState();
  3260. this.stateStack = [];
  3261. this.pendingClip = null;
  3262. this.pendingEOFill = false;
  3263. this.res = null;
  3264. this.xobjs = null;
  3265. this.commonObjs = commonObjs;
  3266. this.objs = objs;
  3267. this.imageLayer = imageLayer;
  3268. this.groupStack = [];
  3269. this.processingType3 = null;
  3270. // Patterns are painted relative to the initial page/form transform, see pdf
  3271. // spec 8.7.2 NOTE 1.
  3272. this.baseTransform = null;
  3273. this.baseTransformStack = [];
  3274. this.groupLevel = 0;
  3275. this.smaskStack = [];
  3276. this.smaskCounter = 0;
  3277. this.tempSMask = null;
  3278. if (canvasCtx) {
  3279. addContextCurrentTransform(canvasCtx);
  3280. }
  3281. this.cachedGetSinglePixelWidth = null;
  3282. }
  3283. function putBinaryImageData(ctx, imgData) {
  3284. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3285. ctx.putImageData(imgData, 0, 0);
  3286. return;
  3287. }
  3288. // Put the image data to the canvas in chunks, rather than putting the
  3289. // whole image at once. This saves JS memory, because the ImageData object
  3290. // is smaller. It also possibly saves C++ memory within the implementation
  3291. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3292. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3293. // because too many putImageData() calls will slow things down.
  3294. //
  3295. // Note: as written, if the last chunk is partial, the putImageData() call
  3296. // will (conceptually) put pixels past the bounds of the canvas. But
  3297. // that's ok; any such pixels are ignored.
  3298. var height = imgData.height, width = imgData.width;
  3299. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3300. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3301. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3302. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3303. var srcPos = 0, destPos;
  3304. var src = imgData.data;
  3305. var dest = chunkImgData.data;
  3306. var i, j, thisChunkHeight, elemsInThisChunk;
  3307. // There are multiple forms in which the pixel data can be passed, and
  3308. // imgData.kind tells us which one this is.
  3309. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3310. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3311. var srcLength = src.byteLength;
  3312. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3313. new Uint32ArrayView(dest);
  3314. var dest32DataLength = dest32.length;
  3315. var fullSrcDiff = (width + 7) >> 3;
  3316. var white = 0xFFFFFFFF;
  3317. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3318. 0xFF000000 : 0x000000FF;
  3319. for (i = 0; i < totalChunks; i++) {
  3320. thisChunkHeight =
  3321. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3322. destPos = 0;
  3323. for (j = 0; j < thisChunkHeight; j++) {
  3324. var srcDiff = srcLength - srcPos;
  3325. var k = 0;
  3326. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3327. var kEndUnrolled = kEnd & ~7;
  3328. var mask = 0;
  3329. var srcByte = 0;
  3330. for (; k < kEndUnrolled; k += 8) {
  3331. srcByte = src[srcPos++];
  3332. dest32[destPos++] = (srcByte & 128) ? white : black;
  3333. dest32[destPos++] = (srcByte & 64) ? white : black;
  3334. dest32[destPos++] = (srcByte & 32) ? white : black;
  3335. dest32[destPos++] = (srcByte & 16) ? white : black;
  3336. dest32[destPos++] = (srcByte & 8) ? white : black;
  3337. dest32[destPos++] = (srcByte & 4) ? white : black;
  3338. dest32[destPos++] = (srcByte & 2) ? white : black;
  3339. dest32[destPos++] = (srcByte & 1) ? white : black;
  3340. }
  3341. for (; k < kEnd; k++) {
  3342. if (mask === 0) {
  3343. srcByte = src[srcPos++];
  3344. mask = 128;
  3345. }
  3346. dest32[destPos++] = (srcByte & mask) ? white : black;
  3347. mask >>= 1;
  3348. }
  3349. }
  3350. // We ran out of input. Make all remaining pixels transparent.
  3351. while (destPos < dest32DataLength) {
  3352. dest32[destPos++] = 0;
  3353. }
  3354. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3355. }
  3356. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3357. // RGBA, 32-bits per pixel.
  3358. j = 0;
  3359. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  3360. for (i = 0; i < fullChunks; i++) {
  3361. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3362. srcPos += elemsInThisChunk;
  3363. ctx.putImageData(chunkImgData, 0, j);
  3364. j += FULL_CHUNK_HEIGHT;
  3365. }
  3366. if (i < totalChunks) {
  3367. elemsInThisChunk = width * partialChunkHeight * 4;
  3368. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3369. ctx.putImageData(chunkImgData, 0, j);
  3370. }
  3371. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3372. // RGB, 24-bits per pixel.
  3373. thisChunkHeight = FULL_CHUNK_HEIGHT;
  3374. elemsInThisChunk = width * thisChunkHeight;
  3375. for (i = 0; i < totalChunks; i++) {
  3376. if (i >= fullChunks) {
  3377. thisChunkHeight = partialChunkHeight;
  3378. elemsInThisChunk = width * thisChunkHeight;
  3379. }
  3380. destPos = 0;
  3381. for (j = elemsInThisChunk; j--;) {
  3382. dest[destPos++] = src[srcPos++];
  3383. dest[destPos++] = src[srcPos++];
  3384. dest[destPos++] = src[srcPos++];
  3385. dest[destPos++] = 255;
  3386. }
  3387. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3388. }
  3389. } else {
  3390. error('bad image kind: ' + imgData.kind);
  3391. }
  3392. }
  3393. function putBinaryImageMask(ctx, imgData) {
  3394. var height = imgData.height, width = imgData.width;
  3395. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3396. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3397. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3398. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3399. var srcPos = 0;
  3400. var src = imgData.data;
  3401. var dest = chunkImgData.data;
  3402. for (var i = 0; i < totalChunks; i++) {
  3403. var thisChunkHeight =
  3404. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3405. // Expand the mask so it can be used by the canvas. Any required
  3406. // inversion has already been handled.
  3407. var destPos = 3; // alpha component offset
  3408. for (var j = 0; j < thisChunkHeight; j++) {
  3409. var mask = 0;
  3410. for (var k = 0; k < width; k++) {
  3411. if (!mask) {
  3412. var elem = src[srcPos++];
  3413. mask = 128;
  3414. }
  3415. dest[destPos] = (elem & mask) ? 0 : 255;
  3416. destPos += 4;
  3417. mask >>= 1;
  3418. }
  3419. }
  3420. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3421. }
  3422. }
  3423. function copyCtxState(sourceCtx, destCtx) {
  3424. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3425. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3426. 'globalCompositeOperation', 'font'];
  3427. for (var i = 0, ii = properties.length; i < ii; i++) {
  3428. var property = properties[i];
  3429. if (sourceCtx[property] !== undefined) {
  3430. destCtx[property] = sourceCtx[property];
  3431. }
  3432. }
  3433. if (sourceCtx.setLineDash !== undefined) {
  3434. destCtx.setLineDash(sourceCtx.getLineDash());
  3435. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3436. } else if (sourceCtx.mozDashOffset !== undefined) {
  3437. destCtx.mozDash = sourceCtx.mozDash;
  3438. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3439. }
  3440. }
  3441. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3442. var length = bytes.length;
  3443. for (var i = 3; i < length; i += 4) {
  3444. var alpha = bytes[i];
  3445. if (alpha === 0) {
  3446. bytes[i - 3] = r0;
  3447. bytes[i - 2] = g0;
  3448. bytes[i - 1] = b0;
  3449. } else if (alpha < 255) {
  3450. var alpha_ = 255 - alpha;
  3451. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3452. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3453. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3454. }
  3455. }
  3456. }
  3457. function composeSMaskAlpha(maskData, layerData) {
  3458. var length = maskData.length;
  3459. var scale = 1 / 255;
  3460. for (var i = 3; i < length; i += 4) {
  3461. var alpha = maskData[i];
  3462. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3463. }
  3464. }
  3465. function composeSMaskLuminosity(maskData, layerData) {
  3466. var length = maskData.length;
  3467. for (var i = 3; i < length; i += 4) {
  3468. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3469. (maskData[i - 2] * 152) + // * 0.59 ....
  3470. (maskData[i - 1] * 28); // * 0.11 ....
  3471. layerData[i] = (layerData[i] * y) >> 16;
  3472. }
  3473. }
  3474. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3475. subtype, backdrop) {
  3476. var hasBackdrop = !!backdrop;
  3477. var r0 = hasBackdrop ? backdrop[0] : 0;
  3478. var g0 = hasBackdrop ? backdrop[1] : 0;
  3479. var b0 = hasBackdrop ? backdrop[2] : 0;
  3480. var composeFn;
  3481. if (subtype === 'Luminosity') {
  3482. composeFn = composeSMaskLuminosity;
  3483. } else {
  3484. composeFn = composeSMaskAlpha;
  3485. }
  3486. // processing image in chunks to save memory
  3487. var PIXELS_TO_PROCESS = 1048576;
  3488. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3489. for (var row = 0; row < height; row += chunkSize) {
  3490. var chunkHeight = Math.min(chunkSize, height - row);
  3491. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3492. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3493. if (hasBackdrop) {
  3494. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3495. }
  3496. composeFn(maskData.data, layerData.data);
  3497. maskCtx.putImageData(layerData, 0, row);
  3498. }
  3499. }
  3500. function composeSMask(ctx, smask, layerCtx) {
  3501. var mask = smask.canvas;
  3502. var maskCtx = smask.context;
  3503. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3504. smask.offsetX, smask.offsetY);
  3505. var backdrop = smask.backdrop || null;
  3506. if (WebGLUtils.isEnabled) {
  3507. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3508. {subtype: smask.subtype, backdrop: backdrop});
  3509. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3510. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3511. return;
  3512. }
  3513. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3514. smask.subtype, backdrop);
  3515. ctx.drawImage(mask, 0, 0);
  3516. }
  3517. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3518. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3519. var NORMAL_CLIP = {};
  3520. var EO_CLIP = {};
  3521. CanvasGraphics.prototype = {
  3522. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3523. // For pdfs that use blend modes we have to clear the canvas else certain
  3524. // blend modes can look wrong since we'd be blending with a white
  3525. // backdrop. The problem with a transparent backdrop though is we then
  3526. // don't get sub pixel anti aliasing on text, so we fill with white if
  3527. // we can.
  3528. var width = this.ctx.canvas.width;
  3529. var height = this.ctx.canvas.height;
  3530. if (transparency) {
  3531. this.ctx.clearRect(0, 0, width, height);
  3532. } else {
  3533. this.ctx.mozOpaque = true;
  3534. this.ctx.save();
  3535. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3536. this.ctx.fillRect(0, 0, width, height);
  3537. this.ctx.restore();
  3538. }
  3539. var transform = viewport.transform;
  3540. this.ctx.save();
  3541. this.ctx.transform.apply(this.ctx, transform);
  3542. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3543. if (this.imageLayer) {
  3544. this.imageLayer.beginLayout();
  3545. }
  3546. },
  3547. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3548. operatorList,
  3549. executionStartIdx, continueCallback,
  3550. stepper) {
  3551. var argsArray = operatorList.argsArray;
  3552. var fnArray = operatorList.fnArray;
  3553. var i = executionStartIdx || 0;
  3554. var argsArrayLen = argsArray.length;
  3555. // Sometimes the OperatorList to execute is empty.
  3556. if (argsArrayLen === i) {
  3557. return i;
  3558. }
  3559. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3560. typeof continueCallback === 'function');
  3561. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3562. var steps = 0;
  3563. var commonObjs = this.commonObjs;
  3564. var objs = this.objs;
  3565. var fnId;
  3566. while (true) {
  3567. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3568. stepper.breakIt(i, continueCallback);
  3569. return i;
  3570. }
  3571. fnId = fnArray[i];
  3572. if (fnId !== OPS.dependency) {
  3573. this[fnId].apply(this, argsArray[i]);
  3574. } else {
  3575. var deps = argsArray[i];
  3576. for (var n = 0, nn = deps.length; n < nn; n++) {
  3577. var depObjId = deps[n];
  3578. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3579. var objsPool = common ? commonObjs : objs;
  3580. // If the promise isn't resolved yet, add the continueCallback
  3581. // to the promise and bail out.
  3582. if (!objsPool.isResolved(depObjId)) {
  3583. objsPool.get(depObjId, continueCallback);
  3584. return i;
  3585. }
  3586. }
  3587. }
  3588. i++;
  3589. // If the entire operatorList was executed, stop as were done.
  3590. if (i === argsArrayLen) {
  3591. return i;
  3592. }
  3593. // If the execution took longer then a certain amount of time and
  3594. // `continueCallback` is specified, interrupt the execution.
  3595. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3596. if (Date.now() > endTime) {
  3597. continueCallback();
  3598. return i;
  3599. }
  3600. steps = 0;
  3601. }
  3602. // If the operatorList isn't executed completely yet OR the execution
  3603. // time was short enough, do another execution round.
  3604. }
  3605. },
  3606. endDrawing: function CanvasGraphics_endDrawing() {
  3607. this.ctx.restore();
  3608. CachedCanvases.clear();
  3609. WebGLUtils.clear();
  3610. if (this.imageLayer) {
  3611. this.imageLayer.endLayout();
  3612. }
  3613. },
  3614. // Graphics state
  3615. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3616. this.current.lineWidth = width;
  3617. this.ctx.lineWidth = width;
  3618. },
  3619. setLineCap: function CanvasGraphics_setLineCap(style) {
  3620. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3621. },
  3622. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3623. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3624. },
  3625. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3626. this.ctx.miterLimit = limit;
  3627. },
  3628. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3629. var ctx = this.ctx;
  3630. if (ctx.setLineDash !== undefined) {
  3631. ctx.setLineDash(dashArray);
  3632. ctx.lineDashOffset = dashPhase;
  3633. } else {
  3634. ctx.mozDash = dashArray;
  3635. ctx.mozDashOffset = dashPhase;
  3636. }
  3637. },
  3638. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3639. // Maybe if we one day fully support color spaces this will be important
  3640. // for now we can ignore.
  3641. // TODO set rendering intent?
  3642. },
  3643. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3644. // There's no way to control this with canvas, but we can safely ignore.
  3645. // TODO set flatness?
  3646. },
  3647. setGState: function CanvasGraphics_setGState(states) {
  3648. for (var i = 0, ii = states.length; i < ii; i++) {
  3649. var state = states[i];
  3650. var key = state[0];
  3651. var value = state[1];
  3652. switch (key) {
  3653. case 'LW':
  3654. this.setLineWidth(value);
  3655. break;
  3656. case 'LC':
  3657. this.setLineCap(value);
  3658. break;
  3659. case 'LJ':
  3660. this.setLineJoin(value);
  3661. break;
  3662. case 'ML':
  3663. this.setMiterLimit(value);
  3664. break;
  3665. case 'D':
  3666. this.setDash(value[0], value[1]);
  3667. break;
  3668. case 'RI':
  3669. this.setRenderingIntent(value);
  3670. break;
  3671. case 'FL':
  3672. this.setFlatness(value);
  3673. break;
  3674. case 'Font':
  3675. this.setFont(value[0], value[1]);
  3676. break;
  3677. case 'CA':
  3678. this.current.strokeAlpha = state[1];
  3679. break;
  3680. case 'ca':
  3681. this.current.fillAlpha = state[1];
  3682. this.ctx.globalAlpha = state[1];
  3683. break;
  3684. case 'BM':
  3685. if (value && value.name && (value.name !== 'Normal')) {
  3686. var mode = value.name.replace(/([A-Z])/g,
  3687. function(c) {
  3688. return '-' + c.toLowerCase();
  3689. }
  3690. ).substring(1);
  3691. this.ctx.globalCompositeOperation = mode;
  3692. if (this.ctx.globalCompositeOperation !== mode) {
  3693. warn('globalCompositeOperation "' + mode +
  3694. '" is not supported');
  3695. }
  3696. } else {
  3697. this.ctx.globalCompositeOperation = 'source-over';
  3698. }
  3699. break;
  3700. case 'SMask':
  3701. if (this.current.activeSMask) {
  3702. this.endSMaskGroup();
  3703. }
  3704. this.current.activeSMask = value ? this.tempSMask : null;
  3705. if (this.current.activeSMask) {
  3706. this.beginSMaskGroup();
  3707. }
  3708. this.tempSMask = null;
  3709. break;
  3710. }
  3711. }
  3712. },
  3713. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3714. var activeSMask = this.current.activeSMask;
  3715. var drawnWidth = activeSMask.canvas.width;
  3716. var drawnHeight = activeSMask.canvas.height;
  3717. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3718. var scratchCanvas = CachedCanvases.getCanvas(
  3719. cacheId, drawnWidth, drawnHeight, true);
  3720. var currentCtx = this.ctx;
  3721. var currentTransform = currentCtx.mozCurrentTransform;
  3722. this.ctx.save();
  3723. var groupCtx = scratchCanvas.context;
  3724. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3725. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3726. groupCtx.transform.apply(groupCtx, currentTransform);
  3727. copyCtxState(currentCtx, groupCtx);
  3728. this.ctx = groupCtx;
  3729. this.setGState([
  3730. ['BM', 'Normal'],
  3731. ['ca', 1],
  3732. ['CA', 1]
  3733. ]);
  3734. this.groupStack.push(currentCtx);
  3735. this.groupLevel++;
  3736. },
  3737. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3738. var groupCtx = this.ctx;
  3739. this.groupLevel--;
  3740. this.ctx = this.groupStack.pop();
  3741. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3742. this.ctx.restore();
  3743. },
  3744. save: function CanvasGraphics_save() {
  3745. this.ctx.save();
  3746. var old = this.current;
  3747. this.stateStack.push(old);
  3748. this.current = old.clone();
  3749. this.current.activeSMask = null;
  3750. },
  3751. restore: function CanvasGraphics_restore() {
  3752. if (this.stateStack.length !== 0) {
  3753. if (this.current.activeSMask !== null) {
  3754. this.endSMaskGroup();
  3755. }
  3756. this.current = this.stateStack.pop();
  3757. this.ctx.restore();
  3758. this.cachedGetSinglePixelWidth = null;
  3759. }
  3760. },
  3761. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3762. this.ctx.transform(a, b, c, d, e, f);
  3763. this.cachedGetSinglePixelWidth = null;
  3764. },
  3765. // Path
  3766. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3767. var ctx = this.ctx;
  3768. var current = this.current;
  3769. var x = current.x, y = current.y;
  3770. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3771. switch (ops[i] | 0) {
  3772. case OPS.rectangle:
  3773. x = args[j++];
  3774. y = args[j++];
  3775. var width = args[j++];
  3776. var height = args[j++];
  3777. if (width === 0) {
  3778. width = this.getSinglePixelWidth();
  3779. }
  3780. if (height === 0) {
  3781. height = this.getSinglePixelWidth();
  3782. }
  3783. var xw = x + width;
  3784. var yh = y + height;
  3785. this.ctx.moveTo(x, y);
  3786. this.ctx.lineTo(xw, y);
  3787. this.ctx.lineTo(xw, yh);
  3788. this.ctx.lineTo(x, yh);
  3789. this.ctx.lineTo(x, y);
  3790. this.ctx.closePath();
  3791. break;
  3792. case OPS.moveTo:
  3793. x = args[j++];
  3794. y = args[j++];
  3795. ctx.moveTo(x, y);
  3796. break;
  3797. case OPS.lineTo:
  3798. x = args[j++];
  3799. y = args[j++];
  3800. ctx.lineTo(x, y);
  3801. break;
  3802. case OPS.curveTo:
  3803. x = args[j + 4];
  3804. y = args[j + 5];
  3805. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3806. x, y);
  3807. j += 6;
  3808. break;
  3809. case OPS.curveTo2:
  3810. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3811. args[j + 2], args[j + 3]);
  3812. x = args[j + 2];
  3813. y = args[j + 3];
  3814. j += 4;
  3815. break;
  3816. case OPS.curveTo3:
  3817. x = args[j + 2];
  3818. y = args[j + 3];
  3819. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3820. j += 4;
  3821. break;
  3822. case OPS.closePath:
  3823. ctx.closePath();
  3824. break;
  3825. }
  3826. }
  3827. current.setCurrentPoint(x, y);
  3828. },
  3829. closePath: function CanvasGraphics_closePath() {
  3830. this.ctx.closePath();
  3831. },
  3832. stroke: function CanvasGraphics_stroke(consumePath) {
  3833. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3834. var ctx = this.ctx;
  3835. var strokeColor = this.current.strokeColor;
  3836. // Prevent drawing too thin lines by enforcing a minimum line width.
  3837. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  3838. this.current.lineWidth);
  3839. // For stroke we want to temporarily change the global alpha to the
  3840. // stroking alpha.
  3841. ctx.globalAlpha = this.current.strokeAlpha;
  3842. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3843. strokeColor.type === 'Pattern') {
  3844. // for patterns, we transform to pattern space, calculate
  3845. // the pattern, call stroke, and restore to user space
  3846. ctx.save();
  3847. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3848. ctx.stroke();
  3849. ctx.restore();
  3850. } else {
  3851. ctx.stroke();
  3852. }
  3853. if (consumePath) {
  3854. this.consumePath();
  3855. }
  3856. // Restore the global alpha to the fill alpha
  3857. ctx.globalAlpha = this.current.fillAlpha;
  3858. },
  3859. closeStroke: function CanvasGraphics_closeStroke() {
  3860. this.closePath();
  3861. this.stroke();
  3862. },
  3863. fill: function CanvasGraphics_fill(consumePath) {
  3864. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3865. var ctx = this.ctx;
  3866. var fillColor = this.current.fillColor;
  3867. var isPatternFill = this.current.patternFill;
  3868. var needRestore = false;
  3869. if (isPatternFill) {
  3870. ctx.save();
  3871. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3872. needRestore = true;
  3873. }
  3874. if (this.pendingEOFill) {
  3875. if (ctx.mozFillRule !== undefined) {
  3876. ctx.mozFillRule = 'evenodd';
  3877. ctx.fill();
  3878. ctx.mozFillRule = 'nonzero';
  3879. } else {
  3880. try {
  3881. ctx.fill('evenodd');
  3882. } catch (ex) {
  3883. // shouldn't really happen, but browsers might think differently
  3884. ctx.fill();
  3885. }
  3886. }
  3887. this.pendingEOFill = false;
  3888. } else {
  3889. ctx.fill();
  3890. }
  3891. if (needRestore) {
  3892. ctx.restore();
  3893. }
  3894. if (consumePath) {
  3895. this.consumePath();
  3896. }
  3897. },
  3898. eoFill: function CanvasGraphics_eoFill() {
  3899. this.pendingEOFill = true;
  3900. this.fill();
  3901. },
  3902. fillStroke: function CanvasGraphics_fillStroke() {
  3903. this.fill(false);
  3904. this.stroke(false);
  3905. this.consumePath();
  3906. },
  3907. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3908. this.pendingEOFill = true;
  3909. this.fillStroke();
  3910. },
  3911. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3912. this.closePath();
  3913. this.fillStroke();
  3914. },
  3915. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3916. this.pendingEOFill = true;
  3917. this.closePath();
  3918. this.fillStroke();
  3919. },
  3920. endPath: function CanvasGraphics_endPath() {
  3921. this.consumePath();
  3922. },
  3923. // Clipping
  3924. clip: function CanvasGraphics_clip() {
  3925. this.pendingClip = NORMAL_CLIP;
  3926. },
  3927. eoClip: function CanvasGraphics_eoClip() {
  3928. this.pendingClip = EO_CLIP;
  3929. },
  3930. // Text
  3931. beginText: function CanvasGraphics_beginText() {
  3932. this.current.textMatrix = IDENTITY_MATRIX;
  3933. this.current.textMatrixScale = 1;
  3934. this.current.x = this.current.lineX = 0;
  3935. this.current.y = this.current.lineY = 0;
  3936. },
  3937. endText: function CanvasGraphics_endText() {
  3938. var paths = this.pendingTextPaths;
  3939. var ctx = this.ctx;
  3940. if (paths === undefined) {
  3941. ctx.beginPath();
  3942. return;
  3943. }
  3944. ctx.save();
  3945. ctx.beginPath();
  3946. for (var i = 0; i < paths.length; i++) {
  3947. var path = paths[i];
  3948. ctx.setTransform.apply(ctx, path.transform);
  3949. ctx.translate(path.x, path.y);
  3950. path.addToPath(ctx, path.fontSize);
  3951. }
  3952. ctx.restore();
  3953. ctx.clip();
  3954. ctx.beginPath();
  3955. delete this.pendingTextPaths;
  3956. },
  3957. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3958. this.current.charSpacing = spacing;
  3959. },
  3960. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3961. this.current.wordSpacing = spacing;
  3962. },
  3963. setHScale: function CanvasGraphics_setHScale(scale) {
  3964. this.current.textHScale = scale / 100;
  3965. },
  3966. setLeading: function CanvasGraphics_setLeading(leading) {
  3967. this.current.leading = -leading;
  3968. },
  3969. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3970. var fontObj = this.commonObjs.get(fontRefName);
  3971. var current = this.current;
  3972. if (!fontObj) {
  3973. error('Can\'t find font for ' + fontRefName);
  3974. }
  3975. current.fontMatrix = (fontObj.fontMatrix ?
  3976. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3977. // A valid matrix needs all main diagonal elements to be non-zero
  3978. // This also ensures we bypass FF bugzilla bug #719844.
  3979. if (current.fontMatrix[0] === 0 ||
  3980. current.fontMatrix[3] === 0) {
  3981. warn('Invalid font matrix for font ' + fontRefName);
  3982. }
  3983. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  3984. // and in some docs this can be negative (inverted x-y axes).
  3985. if (size < 0) {
  3986. size = -size;
  3987. current.fontDirection = -1;
  3988. } else {
  3989. current.fontDirection = 1;
  3990. }
  3991. this.current.font = fontObj;
  3992. this.current.fontSize = size;
  3993. if (fontObj.isType3Font) {
  3994. return; // we don't need ctx.font for Type3 fonts
  3995. }
  3996. var name = fontObj.loadedName || 'sans-serif';
  3997. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  3998. (fontObj.bold ? 'bold' : 'normal');
  3999. var italic = fontObj.italic ? 'italic' : 'normal';
  4000. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4001. // Some font backends cannot handle fonts below certain size.
  4002. // Keeping the font at minimal size and using the fontSizeScale to change
  4003. // the current transformation matrix before the fillText/strokeText.
  4004. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4005. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4006. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4007. this.current.fontSizeScale = size / browserFontSize;
  4008. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4009. this.ctx.font = rule;
  4010. },
  4011. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4012. this.current.textRenderingMode = mode;
  4013. },
  4014. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4015. this.current.textRise = rise;
  4016. },
  4017. moveText: function CanvasGraphics_moveText(x, y) {
  4018. this.current.x = this.current.lineX += x;
  4019. this.current.y = this.current.lineY += y;
  4020. },
  4021. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4022. this.setLeading(-y);
  4023. this.moveText(x, y);
  4024. },
  4025. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4026. this.current.textMatrix = [a, b, c, d, e, f];
  4027. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4028. this.current.x = this.current.lineX = 0;
  4029. this.current.y = this.current.lineY = 0;
  4030. },
  4031. nextLine: function CanvasGraphics_nextLine() {
  4032. this.moveText(0, this.current.leading);
  4033. },
  4034. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4035. var ctx = this.ctx;
  4036. var current = this.current;
  4037. var font = current.font;
  4038. var textRenderingMode = current.textRenderingMode;
  4039. var fontSize = current.fontSize / current.fontSizeScale;
  4040. var fillStrokeMode = textRenderingMode &
  4041. TextRenderingMode.FILL_STROKE_MASK;
  4042. var isAddToPathSet = !!(textRenderingMode &
  4043. TextRenderingMode.ADD_TO_PATH_FLAG);
  4044. var addToPath;
  4045. if (font.disableFontFace || isAddToPathSet) {
  4046. addToPath = font.getPathGenerator(this.commonObjs, character);
  4047. }
  4048. if (font.disableFontFace) {
  4049. ctx.save();
  4050. ctx.translate(x, y);
  4051. ctx.beginPath();
  4052. addToPath(ctx, fontSize);
  4053. if (fillStrokeMode === TextRenderingMode.FILL ||
  4054. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4055. ctx.fill();
  4056. }
  4057. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4058. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4059. ctx.stroke();
  4060. }
  4061. ctx.restore();
  4062. } else {
  4063. if (fillStrokeMode === TextRenderingMode.FILL ||
  4064. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4065. ctx.fillText(character, x, y);
  4066. }
  4067. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4068. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4069. ctx.strokeText(character, x, y);
  4070. }
  4071. }
  4072. if (isAddToPathSet) {
  4073. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4074. paths.push({
  4075. transform: ctx.mozCurrentTransform,
  4076. x: x,
  4077. y: y,
  4078. fontSize: fontSize,
  4079. addToPath: addToPath
  4080. });
  4081. }
  4082. },
  4083. get isFontSubpixelAAEnabled() {
  4084. // Checks if anti-aliasing is enabled when scaled text is painted.
  4085. // On Windows GDI scaled fonts looks bad.
  4086. var ctx = document.createElement('canvas').getContext('2d');
  4087. ctx.scale(1.5, 1);
  4088. ctx.fillText('I', 0, 10);
  4089. var data = ctx.getImageData(0, 0, 10, 10).data;
  4090. var enabled = false;
  4091. for (var i = 3; i < data.length; i += 4) {
  4092. if (data[i] > 0 && data[i] < 255) {
  4093. enabled = true;
  4094. break;
  4095. }
  4096. }
  4097. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4098. },
  4099. showText: function CanvasGraphics_showText(glyphs) {
  4100. var current = this.current;
  4101. var font = current.font;
  4102. if (font.isType3Font) {
  4103. return this.showType3Text(glyphs);
  4104. }
  4105. var fontSize = current.fontSize;
  4106. if (fontSize === 0) {
  4107. return;
  4108. }
  4109. var ctx = this.ctx;
  4110. var fontSizeScale = current.fontSizeScale;
  4111. var charSpacing = current.charSpacing;
  4112. var wordSpacing = current.wordSpacing;
  4113. var fontDirection = current.fontDirection;
  4114. var textHScale = current.textHScale * fontDirection;
  4115. var glyphsLength = glyphs.length;
  4116. var vertical = font.vertical;
  4117. var defaultVMetrics = font.defaultVMetrics;
  4118. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4119. var simpleFillText =
  4120. current.textRenderingMode === TextRenderingMode.FILL &&
  4121. !font.disableFontFace;
  4122. ctx.save();
  4123. ctx.transform.apply(ctx, current.textMatrix);
  4124. ctx.translate(current.x, current.y + current.textRise);
  4125. if (fontDirection > 0) {
  4126. ctx.scale(textHScale, -1);
  4127. } else {
  4128. ctx.scale(textHScale, 1);
  4129. }
  4130. var lineWidth = current.lineWidth;
  4131. var scale = current.textMatrixScale;
  4132. if (scale === 0 || lineWidth === 0) {
  4133. var fillStrokeMode = current.textRenderingMode &
  4134. TextRenderingMode.FILL_STROKE_MASK;
  4135. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4136. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4137. this.cachedGetSinglePixelWidth = null;
  4138. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4139. }
  4140. } else {
  4141. lineWidth /= scale;
  4142. }
  4143. if (fontSizeScale !== 1.0) {
  4144. ctx.scale(fontSizeScale, fontSizeScale);
  4145. lineWidth /= fontSizeScale;
  4146. }
  4147. ctx.lineWidth = lineWidth;
  4148. var x = 0, i;
  4149. for (i = 0; i < glyphsLength; ++i) {
  4150. var glyph = glyphs[i];
  4151. if (glyph === null) {
  4152. // word break
  4153. x += fontDirection * wordSpacing;
  4154. continue;
  4155. } else if (isNum(glyph)) {
  4156. x += -glyph * fontSize * 0.001;
  4157. continue;
  4158. }
  4159. var restoreNeeded = false;
  4160. var character = glyph.fontChar;
  4161. var accent = glyph.accent;
  4162. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4163. var width = glyph.width;
  4164. if (vertical) {
  4165. var vmetric, vx, vy;
  4166. vmetric = glyph.vmetric || defaultVMetrics;
  4167. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4168. vx = -vx * widthAdvanceScale;
  4169. vy = vmetric[2] * widthAdvanceScale;
  4170. width = vmetric ? -vmetric[0] : width;
  4171. scaledX = vx / fontSizeScale;
  4172. scaledY = (x + vy) / fontSizeScale;
  4173. } else {
  4174. scaledX = x / fontSizeScale;
  4175. scaledY = 0;
  4176. }
  4177. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  4178. // some standard fonts may not have the exact width, trying to
  4179. // rescale per character
  4180. var measuredWidth = ctx.measureText(character).width * 1000 /
  4181. fontSize * fontSizeScale;
  4182. var characterScaleX = width / measuredWidth;
  4183. restoreNeeded = true;
  4184. ctx.save();
  4185. ctx.scale(characterScaleX, 1);
  4186. scaledX /= characterScaleX;
  4187. }
  4188. if (simpleFillText && !accent) {
  4189. // common case
  4190. ctx.fillText(character, scaledX, scaledY);
  4191. } else {
  4192. this.paintChar(character, scaledX, scaledY);
  4193. if (accent) {
  4194. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4195. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4196. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4197. }
  4198. }
  4199. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  4200. x += charWidth;
  4201. if (restoreNeeded) {
  4202. ctx.restore();
  4203. }
  4204. }
  4205. if (vertical) {
  4206. current.y -= x * textHScale;
  4207. } else {
  4208. current.x += x * textHScale;
  4209. }
  4210. ctx.restore();
  4211. },
  4212. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4213. // Type3 fonts - each glyph is a "mini-PDF"
  4214. var ctx = this.ctx;
  4215. var current = this.current;
  4216. var font = current.font;
  4217. var fontSize = current.fontSize;
  4218. var fontDirection = current.fontDirection;
  4219. var charSpacing = current.charSpacing;
  4220. var wordSpacing = current.wordSpacing;
  4221. var textHScale = current.textHScale * fontDirection;
  4222. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4223. var glyphsLength = glyphs.length;
  4224. var isTextInvisible =
  4225. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4226. var i, glyph, width;
  4227. if (isTextInvisible || fontSize === 0) {
  4228. return;
  4229. }
  4230. ctx.save();
  4231. ctx.transform.apply(ctx, current.textMatrix);
  4232. ctx.translate(current.x, current.y);
  4233. ctx.scale(textHScale, fontDirection);
  4234. for (i = 0; i < glyphsLength; ++i) {
  4235. glyph = glyphs[i];
  4236. if (glyph === null) {
  4237. // word break
  4238. this.ctx.translate(wordSpacing, 0);
  4239. current.x += wordSpacing * textHScale;
  4240. continue;
  4241. } else if (isNum(glyph)) {
  4242. var spacingLength = -glyph * 0.001 * fontSize;
  4243. this.ctx.translate(spacingLength, 0);
  4244. current.x += spacingLength * textHScale;
  4245. continue;
  4246. }
  4247. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4248. if (!operatorList) {
  4249. warn('Type3 character \"' + glyph.operatorListId +
  4250. '\" is not available');
  4251. continue;
  4252. }
  4253. this.processingType3 = glyph;
  4254. this.save();
  4255. ctx.scale(fontSize, fontSize);
  4256. ctx.transform.apply(ctx, fontMatrix);
  4257. this.executeOperatorList(operatorList);
  4258. this.restore();
  4259. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4260. width = transformed[0] * fontSize + charSpacing;
  4261. ctx.translate(width, 0);
  4262. current.x += width * textHScale;
  4263. }
  4264. ctx.restore();
  4265. this.processingType3 = null;
  4266. },
  4267. // Type3 fonts
  4268. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4269. // We can safely ignore this since the width should be the same
  4270. // as the width in the Widths array.
  4271. },
  4272. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4273. yWidth,
  4274. llx,
  4275. lly,
  4276. urx,
  4277. ury) {
  4278. // TODO According to the spec we're also suppose to ignore any operators
  4279. // that set color or include images while processing this type3 font.
  4280. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4281. this.clip();
  4282. this.endPath();
  4283. },
  4284. // Color
  4285. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4286. var pattern;
  4287. if (IR[0] === 'TilingPattern') {
  4288. var color = IR[1];
  4289. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4290. this.commonObjs, this.baseTransform);
  4291. } else {
  4292. pattern = getShadingPatternFromIR(IR);
  4293. }
  4294. return pattern;
  4295. },
  4296. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4297. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4298. },
  4299. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4300. this.current.fillColor = this.getColorN_Pattern(arguments);
  4301. this.current.patternFill = true;
  4302. },
  4303. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4304. var color = Util.makeCssRgb(r, g, b);
  4305. this.ctx.strokeStyle = color;
  4306. this.current.strokeColor = color;
  4307. },
  4308. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4309. var color = Util.makeCssRgb(r, g, b);
  4310. this.ctx.fillStyle = color;
  4311. this.current.fillColor = color;
  4312. this.current.patternFill = false;
  4313. },
  4314. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4315. var ctx = this.ctx;
  4316. this.save();
  4317. var pattern = getShadingPatternFromIR(patternIR);
  4318. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4319. var inv = ctx.mozCurrentTransformInverse;
  4320. if (inv) {
  4321. var canvas = ctx.canvas;
  4322. var width = canvas.width;
  4323. var height = canvas.height;
  4324. var bl = Util.applyTransform([0, 0], inv);
  4325. var br = Util.applyTransform([0, height], inv);
  4326. var ul = Util.applyTransform([width, 0], inv);
  4327. var ur = Util.applyTransform([width, height], inv);
  4328. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4329. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4330. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4331. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4332. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4333. } else {
  4334. // HACK to draw the gradient onto an infinite rectangle.
  4335. // PDF gradients are drawn across the entire image while
  4336. // Canvas only allows gradients to be drawn in a rectangle
  4337. // The following bug should allow us to remove this.
  4338. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4339. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4340. }
  4341. this.restore();
  4342. },
  4343. // Images
  4344. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4345. error('Should not call beginInlineImage');
  4346. },
  4347. beginImageData: function CanvasGraphics_beginImageData() {
  4348. error('Should not call beginImageData');
  4349. },
  4350. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4351. bbox) {
  4352. this.save();
  4353. this.baseTransformStack.push(this.baseTransform);
  4354. if (isArray(matrix) && 6 === matrix.length) {
  4355. this.transform.apply(this, matrix);
  4356. }
  4357. this.baseTransform = this.ctx.mozCurrentTransform;
  4358. if (isArray(bbox) && 4 === bbox.length) {
  4359. var width = bbox[2] - bbox[0];
  4360. var height = bbox[3] - bbox[1];
  4361. this.ctx.rect(bbox[0], bbox[1], width, height);
  4362. this.clip();
  4363. this.endPath();
  4364. }
  4365. },
  4366. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4367. this.restore();
  4368. this.baseTransform = this.baseTransformStack.pop();
  4369. },
  4370. beginGroup: function CanvasGraphics_beginGroup(group) {
  4371. this.save();
  4372. var currentCtx = this.ctx;
  4373. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4374. // group results aren't usually that different and they even have tools
  4375. // that ignore this setting. Notes from Rik on implmenting:
  4376. // - When you encounter an transparency group, create a new canvas with
  4377. // the dimensions of the bbox
  4378. // - copy the content from the previous canvas to the new canvas
  4379. // - draw as usual
  4380. // - remove the backdrop alpha:
  4381. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4382. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4383. // backdrop
  4384. // - remove background color:
  4385. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4386. if (!group.isolated) {
  4387. info('TODO: Support non-isolated groups.');
  4388. }
  4389. // TODO knockout - supposedly possible with the clever use of compositing
  4390. // modes.
  4391. if (group.knockout) {
  4392. warn('Knockout groups not supported.');
  4393. }
  4394. var currentTransform = currentCtx.mozCurrentTransform;
  4395. if (group.matrix) {
  4396. currentCtx.transform.apply(currentCtx, group.matrix);
  4397. }
  4398. assert(group.bbox, 'Bounding box is required.');
  4399. // Based on the current transform figure out how big the bounding box
  4400. // will actually be.
  4401. var bounds = Util.getAxialAlignedBoundingBox(
  4402. group.bbox,
  4403. currentCtx.mozCurrentTransform);
  4404. // Clip the bounding box to the current canvas.
  4405. var canvasBounds = [0,
  4406. 0,
  4407. currentCtx.canvas.width,
  4408. currentCtx.canvas.height];
  4409. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4410. // Use ceil in case we're between sizes so we don't create canvas that is
  4411. // too small and make the canvas at least 1x1 pixels.
  4412. var offsetX = Math.floor(bounds[0]);
  4413. var offsetY = Math.floor(bounds[1]);
  4414. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4415. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4416. var scaleX = 1, scaleY = 1;
  4417. if (drawnWidth > MAX_GROUP_SIZE) {
  4418. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4419. drawnWidth = MAX_GROUP_SIZE;
  4420. }
  4421. if (drawnHeight > MAX_GROUP_SIZE) {
  4422. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4423. drawnHeight = MAX_GROUP_SIZE;
  4424. }
  4425. var cacheId = 'groupAt' + this.groupLevel;
  4426. if (group.smask) {
  4427. // Using two cache entries is case if masks are used one after another.
  4428. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4429. }
  4430. var scratchCanvas = CachedCanvases.getCanvas(
  4431. cacheId, drawnWidth, drawnHeight, true);
  4432. var groupCtx = scratchCanvas.context;
  4433. // Since we created a new canvas that is just the size of the bounding box
  4434. // we have to translate the group ctx.
  4435. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4436. groupCtx.translate(-offsetX, -offsetY);
  4437. groupCtx.transform.apply(groupCtx, currentTransform);
  4438. if (group.smask) {
  4439. // Saving state and cached mask to be used in setGState.
  4440. this.smaskStack.push({
  4441. canvas: scratchCanvas.canvas,
  4442. context: groupCtx,
  4443. offsetX: offsetX,
  4444. offsetY: offsetY,
  4445. scaleX: scaleX,
  4446. scaleY: scaleY,
  4447. subtype: group.smask.subtype,
  4448. backdrop: group.smask.backdrop
  4449. });
  4450. } else {
  4451. // Setup the current ctx so when the group is popped we draw it at the
  4452. // right location.
  4453. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4454. currentCtx.translate(offsetX, offsetY);
  4455. currentCtx.scale(scaleX, scaleY);
  4456. }
  4457. // The transparency group inherits all off the current graphics state
  4458. // except the blend mode, soft mask, and alpha constants.
  4459. copyCtxState(currentCtx, groupCtx);
  4460. this.ctx = groupCtx;
  4461. this.setGState([
  4462. ['BM', 'Normal'],
  4463. ['ca', 1],
  4464. ['CA', 1]
  4465. ]);
  4466. this.groupStack.push(currentCtx);
  4467. this.groupLevel++;
  4468. },
  4469. endGroup: function CanvasGraphics_endGroup(group) {
  4470. this.groupLevel--;
  4471. var groupCtx = this.ctx;
  4472. this.ctx = this.groupStack.pop();
  4473. // Turn off image smoothing to avoid sub pixel interpolation which can
  4474. // look kind of blurry for some pdfs.
  4475. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4476. this.ctx.imageSmoothingEnabled = false;
  4477. } else {
  4478. this.ctx.mozImageSmoothingEnabled = false;
  4479. }
  4480. if (group.smask) {
  4481. this.tempSMask = this.smaskStack.pop();
  4482. } else {
  4483. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4484. }
  4485. this.restore();
  4486. },
  4487. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4488. this.save();
  4489. this.current = new CanvasExtraState();
  4490. },
  4491. endAnnotations: function CanvasGraphics_endAnnotations() {
  4492. this.restore();
  4493. },
  4494. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4495. matrix) {
  4496. this.save();
  4497. if (isArray(rect) && 4 === rect.length) {
  4498. var width = rect[2] - rect[0];
  4499. var height = rect[3] - rect[1];
  4500. this.ctx.rect(rect[0], rect[1], width, height);
  4501. this.clip();
  4502. this.endPath();
  4503. }
  4504. this.transform.apply(this, transform);
  4505. this.transform.apply(this, matrix);
  4506. },
  4507. endAnnotation: function CanvasGraphics_endAnnotation() {
  4508. this.restore();
  4509. },
  4510. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4511. var domImage = this.objs.get(objId);
  4512. if (!domImage) {
  4513. warn('Dependent image isn\'t ready yet');
  4514. return;
  4515. }
  4516. this.save();
  4517. var ctx = this.ctx;
  4518. // scale the image to the unit square
  4519. ctx.scale(1 / w, -1 / h);
  4520. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4521. 0, -h, w, h);
  4522. if (this.imageLayer) {
  4523. var currentTransform = ctx.mozCurrentTransformInverse;
  4524. var position = this.getCanvasPosition(0, 0);
  4525. this.imageLayer.appendImage({
  4526. objId: objId,
  4527. left: position[0],
  4528. top: position[1],
  4529. width: w / currentTransform[0],
  4530. height: h / currentTransform[3]
  4531. });
  4532. }
  4533. this.restore();
  4534. },
  4535. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4536. var ctx = this.ctx;
  4537. var width = img.width, height = img.height;
  4538. var fillColor = this.current.fillColor;
  4539. var isPatternFill = this.current.patternFill;
  4540. var glyph = this.processingType3;
  4541. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  4542. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4543. glyph.compiled =
  4544. compileType3Glyph({data: img.data, width: width, height: height});
  4545. } else {
  4546. glyph.compiled = null;
  4547. }
  4548. }
  4549. if (glyph && glyph.compiled) {
  4550. glyph.compiled(ctx);
  4551. return;
  4552. }
  4553. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4554. var maskCtx = maskCanvas.context;
  4555. maskCtx.save();
  4556. putBinaryImageMask(maskCtx, img);
  4557. maskCtx.globalCompositeOperation = 'source-in';
  4558. maskCtx.fillStyle = isPatternFill ?
  4559. fillColor.getPattern(maskCtx, this) : fillColor;
  4560. maskCtx.fillRect(0, 0, width, height);
  4561. maskCtx.restore();
  4562. this.paintInlineImageXObject(maskCanvas.canvas);
  4563. },
  4564. paintImageMaskXObjectRepeat:
  4565. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4566. scaleY, positions) {
  4567. var width = imgData.width;
  4568. var height = imgData.height;
  4569. var fillColor = this.current.fillColor;
  4570. var isPatternFill = this.current.patternFill;
  4571. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4572. var maskCtx = maskCanvas.context;
  4573. maskCtx.save();
  4574. putBinaryImageMask(maskCtx, imgData);
  4575. maskCtx.globalCompositeOperation = 'source-in';
  4576. maskCtx.fillStyle = isPatternFill ?
  4577. fillColor.getPattern(maskCtx, this) : fillColor;
  4578. maskCtx.fillRect(0, 0, width, height);
  4579. maskCtx.restore();
  4580. var ctx = this.ctx;
  4581. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4582. ctx.save();
  4583. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4584. ctx.scale(1, -1);
  4585. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4586. 0, -1, 1, 1);
  4587. ctx.restore();
  4588. }
  4589. },
  4590. paintImageMaskXObjectGroup:
  4591. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4592. var ctx = this.ctx;
  4593. var fillColor = this.current.fillColor;
  4594. var isPatternFill = this.current.patternFill;
  4595. for (var i = 0, ii = images.length; i < ii; i++) {
  4596. var image = images[i];
  4597. var width = image.width, height = image.height;
  4598. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4599. var maskCtx = maskCanvas.context;
  4600. maskCtx.save();
  4601. putBinaryImageMask(maskCtx, image);
  4602. maskCtx.globalCompositeOperation = 'source-in';
  4603. maskCtx.fillStyle = isPatternFill ?
  4604. fillColor.getPattern(maskCtx, this) : fillColor;
  4605. maskCtx.fillRect(0, 0, width, height);
  4606. maskCtx.restore();
  4607. ctx.save();
  4608. ctx.transform.apply(ctx, image.transform);
  4609. ctx.scale(1, -1);
  4610. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4611. 0, -1, 1, 1);
  4612. ctx.restore();
  4613. }
  4614. },
  4615. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4616. var imgData = this.objs.get(objId);
  4617. if (!imgData) {
  4618. warn('Dependent image isn\'t ready yet');
  4619. return;
  4620. }
  4621. this.paintInlineImageXObject(imgData);
  4622. },
  4623. paintImageXObjectRepeat:
  4624. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4625. positions) {
  4626. var imgData = this.objs.get(objId);
  4627. if (!imgData) {
  4628. warn('Dependent image isn\'t ready yet');
  4629. return;
  4630. }
  4631. var width = imgData.width;
  4632. var height = imgData.height;
  4633. var map = [];
  4634. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4635. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4636. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4637. }
  4638. this.paintInlineImageXObjectGroup(imgData, map);
  4639. },
  4640. paintInlineImageXObject:
  4641. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4642. var width = imgData.width;
  4643. var height = imgData.height;
  4644. var ctx = this.ctx;
  4645. this.save();
  4646. // scale the image to the unit square
  4647. ctx.scale(1 / width, -1 / height);
  4648. var currentTransform = ctx.mozCurrentTransformInverse;
  4649. var a = currentTransform[0], b = currentTransform[1];
  4650. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4651. var c = currentTransform[2], d = currentTransform[3];
  4652. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4653. var imgToPaint, tmpCanvas;
  4654. // instanceof HTMLElement does not work in jsdom node.js module
  4655. if (imgData instanceof HTMLElement || !imgData.data) {
  4656. imgToPaint = imgData;
  4657. } else {
  4658. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4659. var tmpCtx = tmpCanvas.context;
  4660. putBinaryImageData(tmpCtx, imgData);
  4661. imgToPaint = tmpCanvas.canvas;
  4662. }
  4663. var paintWidth = width, paintHeight = height;
  4664. var tmpCanvasId = 'prescale1';
  4665. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4666. // pixels during drawImage operation, painting on the temporary canvas(es)
  4667. // that are twice smaller in size
  4668. while ((widthScale > 2 && paintWidth > 1) ||
  4669. (heightScale > 2 && paintHeight > 1)) {
  4670. var newWidth = paintWidth, newHeight = paintHeight;
  4671. if (widthScale > 2 && paintWidth > 1) {
  4672. newWidth = Math.ceil(paintWidth / 2);
  4673. widthScale /= paintWidth / newWidth;
  4674. }
  4675. if (heightScale > 2 && paintHeight > 1) {
  4676. newHeight = Math.ceil(paintHeight / 2);
  4677. heightScale /= paintHeight / newHeight;
  4678. }
  4679. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4680. tmpCtx = tmpCanvas.context;
  4681. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4682. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4683. 0, 0, newWidth, newHeight);
  4684. imgToPaint = tmpCanvas.canvas;
  4685. paintWidth = newWidth;
  4686. paintHeight = newHeight;
  4687. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4688. }
  4689. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4690. 0, -height, width, height);
  4691. if (this.imageLayer) {
  4692. var position = this.getCanvasPosition(0, -height);
  4693. this.imageLayer.appendImage({
  4694. imgData: imgData,
  4695. left: position[0],
  4696. top: position[1],
  4697. width: width / currentTransform[0],
  4698. height: height / currentTransform[3]
  4699. });
  4700. }
  4701. this.restore();
  4702. },
  4703. paintInlineImageXObjectGroup:
  4704. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4705. var ctx = this.ctx;
  4706. var w = imgData.width;
  4707. var h = imgData.height;
  4708. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4709. var tmpCtx = tmpCanvas.context;
  4710. putBinaryImageData(tmpCtx, imgData);
  4711. for (var i = 0, ii = map.length; i < ii; i++) {
  4712. var entry = map[i];
  4713. ctx.save();
  4714. ctx.transform.apply(ctx, entry.transform);
  4715. ctx.scale(1, -1);
  4716. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4717. 0, -1, 1, 1);
  4718. if (this.imageLayer) {
  4719. var position = this.getCanvasPosition(entry.x, entry.y);
  4720. this.imageLayer.appendImage({
  4721. imgData: imgData,
  4722. left: position[0],
  4723. top: position[1],
  4724. width: w,
  4725. height: h
  4726. });
  4727. }
  4728. ctx.restore();
  4729. }
  4730. },
  4731. paintSolidColorImageMask:
  4732. function CanvasGraphics_paintSolidColorImageMask() {
  4733. this.ctx.fillRect(0, 0, 1, 1);
  4734. },
  4735. // Marked content
  4736. markPoint: function CanvasGraphics_markPoint(tag) {
  4737. // TODO Marked content.
  4738. },
  4739. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4740. // TODO Marked content.
  4741. },
  4742. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4743. // TODO Marked content.
  4744. },
  4745. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4746. tag, properties) {
  4747. // TODO Marked content.
  4748. },
  4749. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4750. // TODO Marked content.
  4751. },
  4752. // Compatibility
  4753. beginCompat: function CanvasGraphics_beginCompat() {
  4754. // TODO ignore undefined operators (should we do that anyway?)
  4755. },
  4756. endCompat: function CanvasGraphics_endCompat() {
  4757. // TODO stop ignoring undefined operators
  4758. },
  4759. // Helper functions
  4760. consumePath: function CanvasGraphics_consumePath() {
  4761. var ctx = this.ctx;
  4762. if (this.pendingClip) {
  4763. if (this.pendingClip === EO_CLIP) {
  4764. if (ctx.mozFillRule !== undefined) {
  4765. ctx.mozFillRule = 'evenodd';
  4766. ctx.clip();
  4767. ctx.mozFillRule = 'nonzero';
  4768. } else {
  4769. try {
  4770. ctx.clip('evenodd');
  4771. } catch (ex) {
  4772. // shouldn't really happen, but browsers might think differently
  4773. ctx.clip();
  4774. }
  4775. }
  4776. } else {
  4777. ctx.clip();
  4778. }
  4779. this.pendingClip = null;
  4780. }
  4781. ctx.beginPath();
  4782. },
  4783. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4784. if (this.cachedGetSinglePixelWidth === null) {
  4785. var inverse = this.ctx.mozCurrentTransformInverse;
  4786. // max of the current horizontal and vertical scale
  4787. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  4788. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4789. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4790. }
  4791. return this.cachedGetSinglePixelWidth;
  4792. },
  4793. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4794. var transform = this.ctx.mozCurrentTransform;
  4795. return [
  4796. transform[0] * x + transform[2] * y + transform[4],
  4797. transform[1] * x + transform[3] * y + transform[5]
  4798. ];
  4799. }
  4800. };
  4801. for (var op in OPS) {
  4802. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4803. }
  4804. return CanvasGraphics;
  4805. })();
  4806. var WebGLUtils = (function WebGLUtilsClosure() {
  4807. function loadShader(gl, code, shaderType) {
  4808. var shader = gl.createShader(shaderType);
  4809. gl.shaderSource(shader, code);
  4810. gl.compileShader(shader);
  4811. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4812. if (!compiled) {
  4813. var errorMsg = gl.getShaderInfoLog(shader);
  4814. throw new Error('Error during shader compilation: ' + errorMsg);
  4815. }
  4816. return shader;
  4817. }
  4818. function createVertexShader(gl, code) {
  4819. return loadShader(gl, code, gl.VERTEX_SHADER);
  4820. }
  4821. function createFragmentShader(gl, code) {
  4822. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4823. }
  4824. function createProgram(gl, shaders) {
  4825. var program = gl.createProgram();
  4826. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4827. gl.attachShader(program, shaders[i]);
  4828. }
  4829. gl.linkProgram(program);
  4830. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4831. if (!linked) {
  4832. var errorMsg = gl.getProgramInfoLog(program);
  4833. throw new Error('Error during program linking: ' + errorMsg);
  4834. }
  4835. return program;
  4836. }
  4837. function createTexture(gl, image, textureId) {
  4838. gl.activeTexture(textureId);
  4839. var texture = gl.createTexture();
  4840. gl.bindTexture(gl.TEXTURE_2D, texture);
  4841. // Set the parameters so we can render any size image.
  4842. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4843. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4844. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4845. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4846. // Upload the image into the texture.
  4847. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4848. return texture;
  4849. }
  4850. var currentGL, currentCanvas;
  4851. function generateGL() {
  4852. if (currentGL) {
  4853. return;
  4854. }
  4855. currentCanvas = document.createElement('canvas');
  4856. currentGL = currentCanvas.getContext('webgl',
  4857. { premultipliedalpha: false });
  4858. }
  4859. var smaskVertexShaderCode = '\
  4860. attribute vec2 a_position; \
  4861. attribute vec2 a_texCoord; \
  4862. \
  4863. uniform vec2 u_resolution; \
  4864. \
  4865. varying vec2 v_texCoord; \
  4866. \
  4867. void main() { \
  4868. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4869. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4870. \
  4871. v_texCoord = a_texCoord; \
  4872. } ';
  4873. var smaskFragmentShaderCode = '\
  4874. precision mediump float; \
  4875. \
  4876. uniform vec4 u_backdrop; \
  4877. uniform int u_subtype; \
  4878. uniform sampler2D u_image; \
  4879. uniform sampler2D u_mask; \
  4880. \
  4881. varying vec2 v_texCoord; \
  4882. \
  4883. void main() { \
  4884. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4885. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4886. if (u_backdrop.a > 0.0) { \
  4887. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4888. u_backdrop.rgb * (1.0 - maskColor.a); \
  4889. } \
  4890. float lum; \
  4891. if (u_subtype == 0) { \
  4892. lum = maskColor.a; \
  4893. } else { \
  4894. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4895. maskColor.b * 0.11; \
  4896. } \
  4897. imageColor.a *= lum; \
  4898. imageColor.rgb *= imageColor.a; \
  4899. gl_FragColor = imageColor; \
  4900. } ';
  4901. var smaskCache = null;
  4902. function initSmaskGL() {
  4903. var canvas, gl;
  4904. generateGL();
  4905. canvas = currentCanvas;
  4906. currentCanvas = null;
  4907. gl = currentGL;
  4908. currentGL = null;
  4909. // setup a GLSL program
  4910. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4911. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4912. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4913. gl.useProgram(program);
  4914. var cache = {};
  4915. cache.gl = gl;
  4916. cache.canvas = canvas;
  4917. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4918. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4919. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4920. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4921. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4922. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4923. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4924. // provide texture coordinates for the rectangle.
  4925. var texCoordBuffer = gl.createBuffer();
  4926. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4927. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4928. 0.0, 0.0,
  4929. 1.0, 0.0,
  4930. 0.0, 1.0,
  4931. 0.0, 1.0,
  4932. 1.0, 0.0,
  4933. 1.0, 1.0]), gl.STATIC_DRAW);
  4934. gl.enableVertexAttribArray(texCoordLocation);
  4935. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4936. gl.uniform1i(texLayerLocation, 0);
  4937. gl.uniform1i(texMaskLocation, 1);
  4938. smaskCache = cache;
  4939. }
  4940. function composeSMask(layer, mask, properties) {
  4941. var width = layer.width, height = layer.height;
  4942. if (!smaskCache) {
  4943. initSmaskGL();
  4944. }
  4945. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4946. canvas.width = width;
  4947. canvas.height = height;
  4948. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4949. gl.uniform2f(cache.resolutionLocation, width, height);
  4950. if (properties.backdrop) {
  4951. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4952. properties.backdrop[1], properties.backdrop[2], 1);
  4953. } else {
  4954. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4955. }
  4956. gl.uniform1i(cache.subtypeLocation,
  4957. properties.subtype === 'Luminosity' ? 1 : 0);
  4958. // Create a textures
  4959. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4960. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4961. // Create a buffer and put a single clipspace rectangle in
  4962. // it (2 triangles)
  4963. var buffer = gl.createBuffer();
  4964. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4965. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4966. 0, 0,
  4967. width, 0,
  4968. 0, height,
  4969. 0, height,
  4970. width, 0,
  4971. width, height]), gl.STATIC_DRAW);
  4972. gl.enableVertexAttribArray(cache.positionLocation);
  4973. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4974. // draw
  4975. gl.clearColor(0, 0, 0, 0);
  4976. gl.enable(gl.BLEND);
  4977. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4978. gl.clear(gl.COLOR_BUFFER_BIT);
  4979. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4980. gl.flush();
  4981. gl.deleteTexture(texture);
  4982. gl.deleteTexture(maskTexture);
  4983. gl.deleteBuffer(buffer);
  4984. return canvas;
  4985. }
  4986. var figuresVertexShaderCode = '\
  4987. attribute vec2 a_position; \
  4988. attribute vec3 a_color; \
  4989. \
  4990. uniform vec2 u_resolution; \
  4991. uniform vec2 u_scale; \
  4992. uniform vec2 u_offset; \
  4993. \
  4994. varying vec4 v_color; \
  4995. \
  4996. void main() { \
  4997. vec2 position = (a_position + u_offset) * u_scale; \
  4998. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  4999. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5000. \
  5001. v_color = vec4(a_color / 255.0, 1.0); \
  5002. } ';
  5003. var figuresFragmentShaderCode = '\
  5004. precision mediump float; \
  5005. \
  5006. varying vec4 v_color; \
  5007. \
  5008. void main() { \
  5009. gl_FragColor = v_color; \
  5010. } ';
  5011. var figuresCache = null;
  5012. function initFiguresGL() {
  5013. var canvas, gl;
  5014. generateGL();
  5015. canvas = currentCanvas;
  5016. currentCanvas = null;
  5017. gl = currentGL;
  5018. currentGL = null;
  5019. // setup a GLSL program
  5020. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  5021. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  5022. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5023. gl.useProgram(program);
  5024. var cache = {};
  5025. cache.gl = gl;
  5026. cache.canvas = canvas;
  5027. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5028. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  5029. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  5030. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5031. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  5032. figuresCache = cache;
  5033. }
  5034. function drawFigures(width, height, backgroundColor, figures, context) {
  5035. if (!figuresCache) {
  5036. initFiguresGL();
  5037. }
  5038. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  5039. canvas.width = width;
  5040. canvas.height = height;
  5041. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5042. gl.uniform2f(cache.resolutionLocation, width, height);
  5043. // count triangle points
  5044. var count = 0;
  5045. var i, ii, rows;
  5046. for (i = 0, ii = figures.length; i < ii; i++) {
  5047. switch (figures[i].type) {
  5048. case 'lattice':
  5049. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  5050. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  5051. break;
  5052. case 'triangles':
  5053. count += figures[i].coords.length;
  5054. break;
  5055. }
  5056. }
  5057. // transfer data
  5058. var coords = new Float32Array(count * 2);
  5059. var colors = new Uint8Array(count * 3);
  5060. var coordsMap = context.coords, colorsMap = context.colors;
  5061. var pIndex = 0, cIndex = 0;
  5062. for (i = 0, ii = figures.length; i < ii; i++) {
  5063. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  5064. switch (figure.type) {
  5065. case 'lattice':
  5066. var cols = figure.verticesPerRow;
  5067. rows = (ps.length / cols) | 0;
  5068. for (var row = 1; row < rows; row++) {
  5069. var offset = row * cols + 1;
  5070. for (var col = 1; col < cols; col++, offset++) {
  5071. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  5072. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  5073. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  5074. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  5075. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  5076. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  5077. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  5078. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  5079. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  5080. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  5081. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  5082. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  5083. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  5084. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  5085. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  5086. coords[pIndex + 6] = coords[pIndex + 2];
  5087. coords[pIndex + 7] = coords[pIndex + 3];
  5088. coords[pIndex + 8] = coords[pIndex + 4];
  5089. coords[pIndex + 9] = coords[pIndex + 5];
  5090. coords[pIndex + 10] = coordsMap[ps[offset]];
  5091. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  5092. colors[cIndex + 9] = colors[cIndex + 3];
  5093. colors[cIndex + 10] = colors[cIndex + 4];
  5094. colors[cIndex + 11] = colors[cIndex + 5];
  5095. colors[cIndex + 12] = colors[cIndex + 6];
  5096. colors[cIndex + 13] = colors[cIndex + 7];
  5097. colors[cIndex + 14] = colors[cIndex + 8];
  5098. colors[cIndex + 15] = colorsMap[cs[offset]];
  5099. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  5100. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  5101. pIndex += 12;
  5102. cIndex += 18;
  5103. }
  5104. }
  5105. break;
  5106. case 'triangles':
  5107. for (var j = 0, jj = ps.length; j < jj; j++) {
  5108. coords[pIndex] = coordsMap[ps[j]];
  5109. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  5110. colors[cIndex] = colorsMap[cs[i]];
  5111. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  5112. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  5113. pIndex += 2;
  5114. cIndex += 3;
  5115. }
  5116. break;
  5117. }
  5118. }
  5119. // draw
  5120. if (backgroundColor) {
  5121. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  5122. backgroundColor[2] / 255, 1.0);
  5123. } else {
  5124. gl.clearColor(0, 0, 0, 0);
  5125. }
  5126. gl.clear(gl.COLOR_BUFFER_BIT);
  5127. var coordsBuffer = gl.createBuffer();
  5128. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  5129. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  5130. gl.enableVertexAttribArray(cache.positionLocation);
  5131. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5132. var colorsBuffer = gl.createBuffer();
  5133. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  5134. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  5135. gl.enableVertexAttribArray(cache.colorLocation);
  5136. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  5137. 0, 0);
  5138. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  5139. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  5140. gl.drawArrays(gl.TRIANGLES, 0, count);
  5141. gl.flush();
  5142. gl.deleteBuffer(coordsBuffer);
  5143. gl.deleteBuffer(colorsBuffer);
  5144. return canvas;
  5145. }
  5146. function cleanup() {
  5147. if (smaskCache && smaskCache.canvas) {
  5148. smaskCache.canvas.width = 0;
  5149. smaskCache.canvas.height = 0;
  5150. }
  5151. if (figuresCache && figuresCache.canvas) {
  5152. figuresCache.canvas.width = 0;
  5153. figuresCache.canvas.height = 0;
  5154. }
  5155. smaskCache = null;
  5156. figuresCache = null;
  5157. }
  5158. return {
  5159. get isEnabled() {
  5160. if (PDFJS.disableWebGL) {
  5161. return false;
  5162. }
  5163. var enabled = false;
  5164. try {
  5165. generateGL();
  5166. enabled = !!currentGL;
  5167. } catch (e) { }
  5168. return shadow(this, 'isEnabled', enabled);
  5169. },
  5170. composeSMask: composeSMask,
  5171. drawFigures: drawFigures,
  5172. clear: cleanup
  5173. };
  5174. })();
  5175. var ShadingIRs = {};
  5176. ShadingIRs.RadialAxial = {
  5177. fromIR: function RadialAxial_fromIR(raw) {
  5178. var type = raw[1];
  5179. var colorStops = raw[2];
  5180. var p0 = raw[3];
  5181. var p1 = raw[4];
  5182. var r0 = raw[5];
  5183. var r1 = raw[6];
  5184. return {
  5185. type: 'Pattern',
  5186. getPattern: function RadialAxial_getPattern(ctx) {
  5187. var grad;
  5188. if (type === 'axial') {
  5189. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5190. } else if (type === 'radial') {
  5191. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5192. }
  5193. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5194. var c = colorStops[i];
  5195. grad.addColorStop(c[0], c[1]);
  5196. }
  5197. return grad;
  5198. }
  5199. };
  5200. }
  5201. };
  5202. var createMeshCanvas = (function createMeshCanvasClosure() {
  5203. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5204. // Very basic Gouraud-shaded triangle rasterization algorithm.
  5205. var coords = context.coords, colors = context.colors;
  5206. var bytes = data.data, rowSize = data.width * 4;
  5207. var tmp;
  5208. if (coords[p1 + 1] > coords[p2 + 1]) {
  5209. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5210. }
  5211. if (coords[p2 + 1] > coords[p3 + 1]) {
  5212. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  5213. }
  5214. if (coords[p1 + 1] > coords[p2 + 1]) {
  5215. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5216. }
  5217. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5218. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5219. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5220. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5221. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5222. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5223. if (y1 >= y3) {
  5224. return;
  5225. }
  5226. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5227. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5228. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5229. var minY = Math.round(y1), maxY = Math.round(y3);
  5230. var xa, car, cag, cab;
  5231. var xb, cbr, cbg, cbb;
  5232. var k;
  5233. for (var y = minY; y <= maxY; y++) {
  5234. if (y < y2) {
  5235. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5236. xa = x1 - (x1 - x2) * k;
  5237. car = c1r - (c1r - c2r) * k;
  5238. cag = c1g - (c1g - c2g) * k;
  5239. cab = c1b - (c1b - c2b) * k;
  5240. } else {
  5241. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5242. xa = x2 - (x2 - x3) * k;
  5243. car = c2r - (c2r - c3r) * k;
  5244. cag = c2g - (c2g - c3g) * k;
  5245. cab = c2b - (c2b - c3b) * k;
  5246. }
  5247. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5248. xb = x1 - (x1 - x3) * k;
  5249. cbr = c1r - (c1r - c3r) * k;
  5250. cbg = c1g - (c1g - c3g) * k;
  5251. cbb = c1b - (c1b - c3b) * k;
  5252. var x1_ = Math.round(Math.min(xa, xb));
  5253. var x2_ = Math.round(Math.max(xa, xb));
  5254. var j = rowSize * y + x1_ * 4;
  5255. for (var x = x1_; x <= x2_; x++) {
  5256. k = (xa - x) / (xa - xb);
  5257. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5258. bytes[j++] = (car - (car - cbr) * k) | 0;
  5259. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5260. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5261. bytes[j++] = 255;
  5262. }
  5263. }
  5264. }
  5265. function drawFigure(data, figure, context) {
  5266. var ps = figure.coords;
  5267. var cs = figure.colors;
  5268. var i, ii;
  5269. switch (figure.type) {
  5270. case 'lattice':
  5271. var verticesPerRow = figure.verticesPerRow;
  5272. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5273. var cols = verticesPerRow - 1;
  5274. for (i = 0; i < rows; i++) {
  5275. var q = i * verticesPerRow;
  5276. for (var j = 0; j < cols; j++, q++) {
  5277. drawTriangle(data, context,
  5278. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5279. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5280. drawTriangle(data, context,
  5281. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5282. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5283. }
  5284. }
  5285. break;
  5286. case 'triangles':
  5287. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5288. drawTriangle(data, context,
  5289. ps[i], ps[i + 1], ps[i + 2],
  5290. cs[i], cs[i + 1], cs[i + 2]);
  5291. }
  5292. break;
  5293. default:
  5294. error('illigal figure');
  5295. break;
  5296. }
  5297. }
  5298. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5299. backgroundColor) {
  5300. // we will increase scale on some weird factor to let antialiasing take
  5301. // care of "rough" edges
  5302. var EXPECTED_SCALE = 1.1;
  5303. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5304. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5305. var offsetX = Math.floor(bounds[0]);
  5306. var offsetY = Math.floor(bounds[1]);
  5307. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5308. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5309. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5310. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5311. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5312. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5313. var scaleX = boundsWidth / width;
  5314. var scaleY = boundsHeight / height;
  5315. var context = {
  5316. coords: coords,
  5317. colors: colors,
  5318. offsetX: -offsetX,
  5319. offsetY: -offsetY,
  5320. scaleX: 1 / scaleX,
  5321. scaleY: 1 / scaleY
  5322. };
  5323. var canvas, tmpCanvas, i, ii;
  5324. if (WebGLUtils.isEnabled) {
  5325. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5326. figures, context);
  5327. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5328. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5329. tmpCanvas.context.drawImage(canvas, 0, 0);
  5330. canvas = tmpCanvas.canvas;
  5331. } else {
  5332. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5333. var tmpCtx = tmpCanvas.context;
  5334. var data = tmpCtx.createImageData(width, height);
  5335. if (backgroundColor) {
  5336. var bytes = data.data;
  5337. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5338. bytes[i] = backgroundColor[0];
  5339. bytes[i + 1] = backgroundColor[1];
  5340. bytes[i + 2] = backgroundColor[2];
  5341. bytes[i + 3] = 255;
  5342. }
  5343. }
  5344. for (i = 0; i < figures.length; i++) {
  5345. drawFigure(data, figures[i], context);
  5346. }
  5347. tmpCtx.putImageData(data, 0, 0);
  5348. canvas = tmpCanvas.canvas;
  5349. }
  5350. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5351. scaleX: scaleX, scaleY: scaleY};
  5352. }
  5353. return createMeshCanvas;
  5354. })();
  5355. ShadingIRs.Mesh = {
  5356. fromIR: function Mesh_fromIR(raw) {
  5357. //var type = raw[1];
  5358. var coords = raw[2];
  5359. var colors = raw[3];
  5360. var figures = raw[4];
  5361. var bounds = raw[5];
  5362. var matrix = raw[6];
  5363. //var bbox = raw[7];
  5364. var background = raw[8];
  5365. return {
  5366. type: 'Pattern',
  5367. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5368. var scale;
  5369. if (shadingFill) {
  5370. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5371. } else {
  5372. // Obtain scale from matrix and current transformation matrix.
  5373. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5374. if (matrix) {
  5375. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5376. scale = [scale[0] * matrixScale[0],
  5377. scale[1] * matrixScale[1]];
  5378. }
  5379. }
  5380. // Rasterizing on the main thread since sending/queue large canvases
  5381. // might cause OOM.
  5382. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5383. colors, figures, shadingFill ? null : background);
  5384. if (!shadingFill) {
  5385. ctx.setTransform.apply(ctx, owner.baseTransform);
  5386. if (matrix) {
  5387. ctx.transform.apply(ctx, matrix);
  5388. }
  5389. }
  5390. ctx.translate(temporaryPatternCanvas.offsetX,
  5391. temporaryPatternCanvas.offsetY);
  5392. ctx.scale(temporaryPatternCanvas.scaleX,
  5393. temporaryPatternCanvas.scaleY);
  5394. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5395. }
  5396. };
  5397. }
  5398. };
  5399. ShadingIRs.Dummy = {
  5400. fromIR: function Dummy_fromIR() {
  5401. return {
  5402. type: 'Pattern',
  5403. getPattern: function Dummy_fromIR_getPattern() {
  5404. return 'hotpink';
  5405. }
  5406. };
  5407. }
  5408. };
  5409. function getShadingPatternFromIR(raw) {
  5410. var shadingIR = ShadingIRs[raw[0]];
  5411. if (!shadingIR) {
  5412. error('Unknown IR type: ' + raw[0]);
  5413. }
  5414. return shadingIR.fromIR(raw);
  5415. }
  5416. var TilingPattern = (function TilingPatternClosure() {
  5417. var PaintType = {
  5418. COLORED: 1,
  5419. UNCOLORED: 2
  5420. };
  5421. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5422. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5423. this.operatorList = IR[2];
  5424. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5425. this.bbox = IR[4];
  5426. this.xstep = IR[5];
  5427. this.ystep = IR[6];
  5428. this.paintType = IR[7];
  5429. this.tilingType = IR[8];
  5430. this.color = color;
  5431. this.objs = objs;
  5432. this.commonObjs = commonObjs;
  5433. this.baseTransform = baseTransform;
  5434. this.type = 'Pattern';
  5435. this.ctx = ctx;
  5436. }
  5437. TilingPattern.prototype = {
  5438. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5439. var operatorList = this.operatorList;
  5440. var bbox = this.bbox;
  5441. var xstep = this.xstep;
  5442. var ystep = this.ystep;
  5443. var paintType = this.paintType;
  5444. var tilingType = this.tilingType;
  5445. var color = this.color;
  5446. var objs = this.objs;
  5447. var commonObjs = this.commonObjs;
  5448. info('TilingType: ' + tilingType);
  5449. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5450. var topLeft = [x0, y0];
  5451. // we want the canvas to be as large as the step size
  5452. var botRight = [x0 + xstep, y0 + ystep];
  5453. var width = botRight[0] - topLeft[0];
  5454. var height = botRight[1] - topLeft[1];
  5455. // Obtain scale from matrix and current transformation matrix.
  5456. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5457. var curMatrixScale = Util.singularValueDecompose2dScale(
  5458. this.baseTransform);
  5459. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5460. matrixScale[1] * curMatrixScale[1]];
  5461. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5462. // Use width and height values that are as close as possible to the end
  5463. // result when the pattern is used. Too low value makes the pattern look
  5464. // blurry. Too large value makes it look too crispy.
  5465. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5466. MAX_PATTERN_SIZE);
  5467. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5468. MAX_PATTERN_SIZE);
  5469. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5470. var tmpCtx = tmpCanvas.context;
  5471. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5472. graphics.groupLevel = owner.groupLevel;
  5473. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5474. this.setScale(width, height, xstep, ystep);
  5475. this.transformToScale(graphics);
  5476. // transform coordinates to pattern space
  5477. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5478. graphics.transform.apply(graphics, tmpTranslate);
  5479. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5480. graphics.executeOperatorList(operatorList);
  5481. return tmpCanvas.canvas;
  5482. },
  5483. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5484. this.scale = [width / xstep, height / ystep];
  5485. },
  5486. transformToScale: function TilingPattern_transformToScale(graphics) {
  5487. var scale = this.scale;
  5488. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5489. graphics.transform.apply(graphics, tmpScale);
  5490. },
  5491. scaleToContext: function TilingPattern_scaleToContext() {
  5492. var scale = this.scale;
  5493. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5494. },
  5495. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5496. if (bbox && isArray(bbox) && bbox.length === 4) {
  5497. var bboxWidth = x1 - x0;
  5498. var bboxHeight = y1 - y0;
  5499. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5500. graphics.clip();
  5501. graphics.endPath();
  5502. }
  5503. },
  5504. setFillAndStrokeStyleToContext:
  5505. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5506. switch (paintType) {
  5507. case PaintType.COLORED:
  5508. var ctx = this.ctx;
  5509. context.fillStyle = ctx.fillStyle;
  5510. context.strokeStyle = ctx.strokeStyle;
  5511. break;
  5512. case PaintType.UNCOLORED:
  5513. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  5514. context.fillStyle = cssColor;
  5515. context.strokeStyle = cssColor;
  5516. break;
  5517. default:
  5518. error('Unsupported paint type: ' + paintType);
  5519. }
  5520. },
  5521. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5522. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5523. ctx = this.ctx;
  5524. ctx.setTransform.apply(ctx, this.baseTransform);
  5525. ctx.transform.apply(ctx, this.matrix);
  5526. this.scaleToContext();
  5527. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5528. }
  5529. };
  5530. return TilingPattern;
  5531. })();
  5532. PDFJS.disableFontFace = false;
  5533. var FontLoader = {
  5534. insertRule: function fontLoaderInsertRule(rule) {
  5535. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5536. if (!styleElement) {
  5537. styleElement = document.createElement('style');
  5538. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5539. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5540. styleElement);
  5541. }
  5542. var styleSheet = styleElement.sheet;
  5543. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5544. },
  5545. clear: function fontLoaderClear() {
  5546. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5547. if (styleElement) {
  5548. styleElement.parentNode.removeChild(styleElement);
  5549. }
  5550. this.nativeFontFaces.forEach(function(nativeFontFace) {
  5551. document.fonts.delete(nativeFontFace);
  5552. });
  5553. this.nativeFontFaces.length = 0;
  5554. },
  5555. get loadTestFont() {
  5556. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5557. // height.
  5558. return shadow(this, 'loadTestFont', atob(
  5559. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5560. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5561. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5562. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5563. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5564. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5565. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5566. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5567. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5568. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5569. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5570. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5571. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5572. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5573. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5574. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5575. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5576. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5577. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5578. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5579. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5580. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5581. ));
  5582. },
  5583. loadTestFontId: 0,
  5584. loadingContext: {
  5585. requests: [],
  5586. nextRequestId: 0
  5587. },
  5588. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5589. if (isWorker) {
  5590. return false;
  5591. }
  5592. // User agent string sniffing is bad, but there is no reliable way to tell
  5593. // if font is fully loaded and ready to be used with canvas.
  5594. var userAgent = window.navigator.userAgent;
  5595. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5596. if (m && m[1] >= 14) {
  5597. return true;
  5598. }
  5599. // TODO other browsers
  5600. if (userAgent === 'node') {
  5601. return true;
  5602. }
  5603. return false;
  5604. })(),
  5605. nativeFontFaces: [],
  5606. isFontLoadingAPISupported: !isWorker && !!document.fonts,
  5607. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  5608. this.nativeFontFaces.push(nativeFontFace);
  5609. document.fonts.add(nativeFontFace);
  5610. },
  5611. bind: function fontLoaderBind(fonts, callback) {
  5612. assert(!isWorker, 'bind() shall be called from main thread');
  5613. var rules = [];
  5614. var fontsToLoad = [];
  5615. var fontLoadPromises = [];
  5616. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5617. var font = fonts[i];
  5618. // Add the font to the DOM only once or skip if the font
  5619. // is already loaded.
  5620. if (font.attached || font.loading === false) {
  5621. continue;
  5622. }
  5623. font.attached = true;
  5624. if (this.isFontLoadingAPISupported) {
  5625. var nativeFontFace = font.createNativeFontFace();
  5626. if (nativeFontFace) {
  5627. fontLoadPromises.push(nativeFontFace.loaded);
  5628. }
  5629. } else {
  5630. var rule = font.bindDOM();
  5631. if (rule) {
  5632. rules.push(rule);
  5633. fontsToLoad.push(font);
  5634. }
  5635. }
  5636. }
  5637. var request = FontLoader.queueLoadingCallback(callback);
  5638. if (this.isFontLoadingAPISupported) {
  5639. Promise.all(fontsToLoad).then(function() {
  5640. request.complete();
  5641. });
  5642. } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5643. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5644. } else {
  5645. request.complete();
  5646. }
  5647. },
  5648. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5649. function LoadLoader_completeRequest() {
  5650. assert(!request.end, 'completeRequest() cannot be called twice');
  5651. request.end = Date.now();
  5652. // sending all completed requests in order how they were queued
  5653. while (context.requests.length > 0 && context.requests[0].end) {
  5654. var otherRequest = context.requests.shift();
  5655. setTimeout(otherRequest.callback, 0);
  5656. }
  5657. }
  5658. var context = FontLoader.loadingContext;
  5659. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5660. var request = {
  5661. id: requestId,
  5662. complete: LoadLoader_completeRequest,
  5663. callback: callback,
  5664. started: Date.now()
  5665. };
  5666. context.requests.push(request);
  5667. return request;
  5668. },
  5669. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5670. fonts,
  5671. request) {
  5672. /** Hack begin */
  5673. // There's currently no event when a font has finished downloading so the
  5674. // following code is a dirty hack to 'guess' when a font is
  5675. // ready. It's assumed fonts are loaded in order, so add a known test
  5676. // font after the desired fonts and then test for the loading of that
  5677. // test font.
  5678. function int32(data, offset) {
  5679. return (data.charCodeAt(offset) << 24) |
  5680. (data.charCodeAt(offset + 1) << 16) |
  5681. (data.charCodeAt(offset + 2) << 8) |
  5682. (data.charCodeAt(offset + 3) & 0xff);
  5683. }
  5684. function spliceString(s, offset, remove, insert) {
  5685. var chunk1 = s.substr(0, offset);
  5686. var chunk2 = s.substr(offset + remove);
  5687. return chunk1 + insert + chunk2;
  5688. }
  5689. var i, ii;
  5690. var canvas = document.createElement('canvas');
  5691. canvas.width = 1;
  5692. canvas.height = 1;
  5693. var ctx = canvas.getContext('2d');
  5694. var called = 0;
  5695. function isFontReady(name, callback) {
  5696. called++;
  5697. // With setTimeout clamping this gives the font ~100ms to load.
  5698. if(called > 30) {
  5699. warn('Load test font never loaded.');
  5700. callback();
  5701. return;
  5702. }
  5703. ctx.font = '30px ' + name;
  5704. ctx.fillText('.', 0, 20);
  5705. var imageData = ctx.getImageData(0, 0, 1, 1);
  5706. if (imageData.data[3] > 0) {
  5707. callback();
  5708. return;
  5709. }
  5710. setTimeout(isFontReady.bind(null, name, callback));
  5711. }
  5712. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5713. // Chromium seems to cache fonts based on a hash of the actual font data,
  5714. // so the font must be modified for each load test else it will appear to
  5715. // be loaded already.
  5716. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5717. // font by splitting it in chunks before hand and padding the font id.
  5718. var data = this.loadTestFont;
  5719. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5720. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5721. loadTestFontId);
  5722. // CFF checksum is important for IE, adjusting it
  5723. var CFF_CHECKSUM_OFFSET = 16;
  5724. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5725. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5726. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5727. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5728. }
  5729. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5730. checksum = (checksum - XXXX_VALUE +
  5731. int32(loadTestFontId + 'XXX', i)) | 0;
  5732. }
  5733. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5734. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5735. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5736. url + '}';
  5737. FontLoader.insertRule(rule);
  5738. var names = [];
  5739. for (i = 0, ii = fonts.length; i < ii; i++) {
  5740. names.push(fonts[i].loadedName);
  5741. }
  5742. names.push(loadTestFontId);
  5743. var div = document.createElement('div');
  5744. div.setAttribute('style',
  5745. 'visibility: hidden;' +
  5746. 'width: 10px; height: 10px;' +
  5747. 'position: absolute; top: 0px; left: 0px;');
  5748. for (i = 0, ii = names.length; i < ii; ++i) {
  5749. var span = document.createElement('span');
  5750. span.textContent = 'Hi';
  5751. span.style.fontFamily = names[i];
  5752. div.appendChild(span);
  5753. }
  5754. document.body.appendChild(div);
  5755. isFontReady(loadTestFontId, function() {
  5756. document.body.removeChild(div);
  5757. request.complete();
  5758. });
  5759. /** Hack end */
  5760. }
  5761. };
  5762. var FontFaceObject = (function FontFaceObjectClosure() {
  5763. function FontFaceObject(name, file, properties) {
  5764. this.compiledGlyphs = {};
  5765. if (arguments.length === 1) {
  5766. // importing translated data
  5767. var data = arguments[0];
  5768. for (var i in data) {
  5769. this[i] = data[i];
  5770. }
  5771. return;
  5772. }
  5773. }
  5774. FontFaceObject.prototype = {
  5775. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  5776. if (!this.data) {
  5777. return null;
  5778. }
  5779. if (PDFJS.disableFontFace) {
  5780. this.disableFontFace = true;
  5781. return null;
  5782. }
  5783. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  5784. FontLoader.addNativeFontFace(nativeFontFace);
  5785. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5786. globalScope['FontInspector'].enabled) {
  5787. globalScope['FontInspector'].fontAdded(this);
  5788. }
  5789. return nativeFontFace;
  5790. },
  5791. bindDOM: function FontFaceObject_bindDOM() {
  5792. if (!this.data) {
  5793. return null;
  5794. }
  5795. if (PDFJS.disableFontFace) {
  5796. this.disableFontFace = true;
  5797. return null;
  5798. }
  5799. var data = bytesToString(new Uint8Array(this.data));
  5800. var fontName = this.loadedName;
  5801. // Add the font-face rule to the document
  5802. var url = ('url(data:' + this.mimetype + ';base64,' +
  5803. window.btoa(data) + ');');
  5804. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5805. FontLoader.insertRule(rule);
  5806. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5807. globalScope['FontInspector'].enabled) {
  5808. globalScope['FontInspector'].fontAdded(this, url);
  5809. }
  5810. return rule;
  5811. },
  5812. getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
  5813. if (!(character in this.compiledGlyphs)) {
  5814. var js = objs.get(this.loadedName + '_path_' + character);
  5815. /*jshint -W054 */
  5816. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5817. }
  5818. return this.compiledGlyphs[character];
  5819. }
  5820. };
  5821. return FontFaceObject;
  5822. })();
  5823. var ANNOT_MIN_SIZE = 10; // px
  5824. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5825. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5826. function setTextStyles(element, item, fontObj) {
  5827. var style = element.style;
  5828. style.fontSize = item.fontSize + 'px';
  5829. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5830. if (!fontObj) {
  5831. return;
  5832. }
  5833. style.fontWeight = fontObj.black ?
  5834. (fontObj.bold ? 'bolder' : 'bold') :
  5835. (fontObj.bold ? 'bold' : 'normal');
  5836. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5837. var fontName = fontObj.loadedName;
  5838. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5839. // Use a reasonable default font if the font doesn't specify a fallback
  5840. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5841. style.fontFamily = fontFamily + fallbackName;
  5842. }
  5843. function initContainer(item, drawBorder) {
  5844. var container = document.createElement('section');
  5845. var cstyle = container.style;
  5846. var width = item.rect[2] - item.rect[0];
  5847. var height = item.rect[3] - item.rect[1];
  5848. var bWidth = item.borderWidth || 0;
  5849. if (bWidth) {
  5850. width = width - 2 * bWidth;
  5851. height = height - 2 * bWidth;
  5852. cstyle.borderWidth = bWidth + 'px';
  5853. var color = item.color;
  5854. if (drawBorder && color) {
  5855. cstyle.borderStyle = 'solid';
  5856. cstyle.borderColor = Util.makeCssRgb(Math.round(color[0] * 255),
  5857. Math.round(color[1] * 255),
  5858. Math.round(color[2] * 255));
  5859. }
  5860. }
  5861. cstyle.width = width + 'px';
  5862. cstyle.height = height + 'px';
  5863. return container;
  5864. }
  5865. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5866. var element = document.createElement('div');
  5867. var width = item.rect[2] - item.rect[0];
  5868. var height = item.rect[3] - item.rect[1];
  5869. element.style.width = width + 'px';
  5870. element.style.height = height + 'px';
  5871. element.style.display = 'table';
  5872. var content = document.createElement('div');
  5873. content.textContent = item.fieldValue;
  5874. var textAlignment = item.textAlignment;
  5875. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5876. content.style.verticalAlign = 'middle';
  5877. content.style.display = 'table-cell';
  5878. var fontObj = item.fontRefName ?
  5879. commonObjs.getData(item.fontRefName) : null;
  5880. setTextStyles(content, item, fontObj);
  5881. element.appendChild(content);
  5882. return element;
  5883. }
  5884. function getHtmlElementForTextAnnotation(item) {
  5885. var rect = item.rect;
  5886. // sanity check because of OOo-generated PDFs
  5887. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5888. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5889. }
  5890. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5891. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5892. }
  5893. var container = initContainer(item, false);
  5894. container.className = 'annotText';
  5895. var image = document.createElement('img');
  5896. image.style.height = container.style.height;
  5897. image.style.width = container.style.width;
  5898. var iconName = item.name;
  5899. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5900. iconName.toLowerCase() + '.svg';
  5901. image.alt = '[{{type}} Annotation]';
  5902. image.dataset.l10nId = 'text_annotation_type';
  5903. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5904. var contentWrapper = document.createElement('div');
  5905. contentWrapper.className = 'annotTextContentWrapper';
  5906. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5907. contentWrapper.style.top = '-10px';
  5908. var content = document.createElement('div');
  5909. content.className = 'annotTextContent';
  5910. content.setAttribute('hidden', true);
  5911. var i, ii;
  5912. if (item.hasBgColor) {
  5913. var color = item.color;
  5914. // Enlighten the color (70%)
  5915. var BACKGROUND_ENLIGHT = 0.7;
  5916. var r = BACKGROUND_ENLIGHT * (1.0 - color[0]) + color[0];
  5917. var g = BACKGROUND_ENLIGHT * (1.0 - color[1]) + color[1];
  5918. var b = BACKGROUND_ENLIGHT * (1.0 - color[2]) + color[2];
  5919. content.style.backgroundColor = Util.makeCssRgb((r * 255) | 0,
  5920. (g * 255) | 0,
  5921. (b * 255) | 0);
  5922. }
  5923. var title = document.createElement('h1');
  5924. var text = document.createElement('p');
  5925. title.textContent = item.title;
  5926. if (!item.content && !item.title) {
  5927. content.setAttribute('hidden', true);
  5928. } else {
  5929. var e = document.createElement('span');
  5930. var lines = item.content.split(/(?:\r\n?|\n)/);
  5931. for (i = 0, ii = lines.length; i < ii; ++i) {
  5932. var line = lines[i];
  5933. e.appendChild(document.createTextNode(line));
  5934. if (i < (ii - 1)) {
  5935. e.appendChild(document.createElement('br'));
  5936. }
  5937. }
  5938. text.appendChild(e);
  5939. var pinned = false;
  5940. var showAnnotation = function showAnnotation(pin) {
  5941. if (pin) {
  5942. pinned = true;
  5943. }
  5944. if (content.hasAttribute('hidden')) {
  5945. container.style.zIndex += 1;
  5946. content.removeAttribute('hidden');
  5947. }
  5948. };
  5949. var hideAnnotation = function hideAnnotation(unpin) {
  5950. if (unpin) {
  5951. pinned = false;
  5952. }
  5953. if (!content.hasAttribute('hidden') && !pinned) {
  5954. container.style.zIndex -= 1;
  5955. content.setAttribute('hidden', true);
  5956. }
  5957. };
  5958. var toggleAnnotation = function toggleAnnotation() {
  5959. if (pinned) {
  5960. hideAnnotation(true);
  5961. } else {
  5962. showAnnotation(true);
  5963. }
  5964. };
  5965. image.addEventListener('click', function image_clickHandler() {
  5966. toggleAnnotation();
  5967. }, false);
  5968. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5969. showAnnotation();
  5970. }, false);
  5971. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5972. hideAnnotation();
  5973. }, false);
  5974. content.addEventListener('click', function content_clickHandler() {
  5975. hideAnnotation(true);
  5976. }, false);
  5977. }
  5978. content.appendChild(title);
  5979. content.appendChild(text);
  5980. contentWrapper.appendChild(content);
  5981. container.appendChild(image);
  5982. container.appendChild(contentWrapper);
  5983. return container;
  5984. }
  5985. function getHtmlElementForLinkAnnotation(item) {
  5986. var container = initContainer(item, true);
  5987. container.className = 'annotLink';
  5988. var link = document.createElement('a');
  5989. link.href = link.title = item.url || '';
  5990. container.appendChild(link);
  5991. return container;
  5992. }
  5993. function getHtmlElement(data, objs) {
  5994. switch (data.annotationType) {
  5995. case AnnotationType.WIDGET:
  5996. return getHtmlElementForTextWidgetAnnotation(data, objs);
  5997. case AnnotationType.TEXT:
  5998. return getHtmlElementForTextAnnotation(data);
  5999. case AnnotationType.LINK:
  6000. return getHtmlElementForLinkAnnotation(data);
  6001. default:
  6002. throw new Error('Unsupported annotationType: ' + data.annotationType);
  6003. }
  6004. }
  6005. return {
  6006. getHtmlElement: getHtmlElement
  6007. };
  6008. })();
  6009. PDFJS.AnnotationUtils = AnnotationUtils;
  6010. var SVG_DEFAULTS = {
  6011. fontStyle: 'normal',
  6012. fontWeight: 'normal',
  6013. fillColor: '#000000'
  6014. };
  6015. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  6016. var PNG_HEADER =
  6017. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  6018. var CHUNK_WRAPPER_SIZE = 12;
  6019. var crcTable = new Int32Array(256);
  6020. for (var i = 0; i < 256; i++) {
  6021. var c = i;
  6022. for (var h = 0; h < 8; h++) {
  6023. if (c & 1) {
  6024. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  6025. } else {
  6026. c = (c >> 1) & 0x7fffffff;
  6027. }
  6028. }
  6029. crcTable[i] = c;
  6030. }
  6031. function crc32(data, start, end) {
  6032. var crc = -1;
  6033. for (var i = start; i < end; i++) {
  6034. var a = (crc ^ data[i]) & 0xff;
  6035. var b = crcTable[a];
  6036. crc = (crc >>> 8) ^ b;
  6037. }
  6038. return crc ^ -1;
  6039. }
  6040. function writePngChunk(type, body, data, offset) {
  6041. var p = offset;
  6042. var len = body.length;
  6043. data[p] = len >> 24 & 0xff;
  6044. data[p + 1] = len >> 16 & 0xff;
  6045. data[p + 2] = len >> 8 & 0xff;
  6046. data[p + 3] = len & 0xff;
  6047. p += 4;
  6048. data[p] = type.charCodeAt(0) & 0xff;
  6049. data[p + 1] = type.charCodeAt(1) & 0xff;
  6050. data[p + 2] = type.charCodeAt(2) & 0xff;
  6051. data[p + 3] = type.charCodeAt(3) & 0xff;
  6052. p += 4;
  6053. data.set(body, p);
  6054. p += body.length;
  6055. var crc = crc32(data, offset + 4, p);
  6056. data[p] = crc >> 24 & 0xff;
  6057. data[p + 1] = crc >> 16 & 0xff;
  6058. data[p + 2] = crc >> 8 & 0xff;
  6059. data[p + 3] = crc & 0xff;
  6060. }
  6061. function adler32(data, start, end) {
  6062. var a = 1;
  6063. var b = 0;
  6064. for (var i = start; i < end; ++i) {
  6065. a = (a + (data[i] & 0xff)) % 65521;
  6066. b = (b + a) % 65521;
  6067. }
  6068. return (b << 16) | a;
  6069. }
  6070. function encode(imgData, kind) {
  6071. var width = imgData.width;
  6072. var height = imgData.height;
  6073. var bitDepth, colorType, lineSize;
  6074. var bytes = imgData.data;
  6075. switch (kind) {
  6076. case ImageKind.GRAYSCALE_1BPP:
  6077. colorType = 0;
  6078. bitDepth = 1;
  6079. lineSize = (width + 7) >> 3;
  6080. break;
  6081. case ImageKind.RGB_24BPP:
  6082. colorType = 2;
  6083. bitDepth = 8;
  6084. lineSize = width * 3;
  6085. break;
  6086. case ImageKind.RGBA_32BPP:
  6087. colorType = 6;
  6088. bitDepth = 8;
  6089. lineSize = width * 4;
  6090. break;
  6091. default:
  6092. throw new Error('invalid format');
  6093. }
  6094. // prefix every row with predictor 0
  6095. var literals = new Uint8Array((1 + lineSize) * height);
  6096. var offsetLiterals = 0, offsetBytes = 0;
  6097. var y, i;
  6098. for (y = 0; y < height; ++y) {
  6099. literals[offsetLiterals++] = 0; // no prediction
  6100. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  6101. offsetLiterals);
  6102. offsetBytes += lineSize;
  6103. offsetLiterals += lineSize;
  6104. }
  6105. if (kind === ImageKind.GRAYSCALE_1BPP) {
  6106. // inverting for B/W
  6107. offsetLiterals = 0;
  6108. for (y = 0; y < height; y++) {
  6109. offsetLiterals++; // skipping predictor
  6110. for (i = 0; i < lineSize; i++) {
  6111. literals[offsetLiterals++] ^= 0xFF;
  6112. }
  6113. }
  6114. }
  6115. var ihdr = new Uint8Array([
  6116. width >> 24 & 0xff,
  6117. width >> 16 & 0xff,
  6118. width >> 8 & 0xff,
  6119. width & 0xff,
  6120. height >> 24 & 0xff,
  6121. height >> 16 & 0xff,
  6122. height >> 8 & 0xff,
  6123. height & 0xff,
  6124. bitDepth, // bit depth
  6125. colorType, // color type
  6126. 0x00, // compression method
  6127. 0x00, // filter method
  6128. 0x00 // interlace method
  6129. ]);
  6130. var len = literals.length;
  6131. var maxBlockLength = 0xFFFF;
  6132. var deflateBlocks = Math.ceil(len / maxBlockLength);
  6133. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  6134. var pi = 0;
  6135. idat[pi++] = 0x78; // compression method and flags
  6136. idat[pi++] = 0x9c; // flags
  6137. var pos = 0;
  6138. while (len > maxBlockLength) {
  6139. // writing non-final DEFLATE blocks type 0 and length of 65535
  6140. idat[pi++] = 0x00;
  6141. idat[pi++] = 0xff;
  6142. idat[pi++] = 0xff;
  6143. idat[pi++] = 0x00;
  6144. idat[pi++] = 0x00;
  6145. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  6146. pi += maxBlockLength;
  6147. pos += maxBlockLength;
  6148. len -= maxBlockLength;
  6149. }
  6150. // writing non-final DEFLATE blocks type 0
  6151. idat[pi++] = 0x01;
  6152. idat[pi++] = len & 0xff;
  6153. idat[pi++] = len >> 8 & 0xff;
  6154. idat[pi++] = (~len & 0xffff) & 0xff;
  6155. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  6156. idat.set(literals.subarray(pos), pi);
  6157. pi += literals.length - pos;
  6158. var adler = adler32(literals, 0, literals.length); // checksum
  6159. idat[pi++] = adler >> 24 & 0xff;
  6160. idat[pi++] = adler >> 16 & 0xff;
  6161. idat[pi++] = adler >> 8 & 0xff;
  6162. idat[pi++] = adler & 0xff;
  6163. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  6164. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  6165. ihdr.length + idat.length;
  6166. var data = new Uint8Array(pngLength);
  6167. var offset = 0;
  6168. data.set(PNG_HEADER, offset);
  6169. offset += PNG_HEADER.length;
  6170. writePngChunk('IHDR', ihdr, data, offset);
  6171. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  6172. writePngChunk('IDATA', idat, data, offset);
  6173. offset += CHUNK_WRAPPER_SIZE + idat.length;
  6174. writePngChunk('IEND', new Uint8Array(0), data, offset);
  6175. return PDFJS.createObjectURL(data, 'image/png');
  6176. }
  6177. return function convertImgDataToPng(imgData) {
  6178. var kind = (imgData.kind === undefined ?
  6179. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  6180. return encode(imgData, kind);
  6181. };
  6182. })();
  6183. var SVGExtraState = (function SVGExtraStateClosure() {
  6184. function SVGExtraState() {
  6185. this.fontSizeScale = 1;
  6186. this.fontWeight = SVG_DEFAULTS.fontWeight;
  6187. this.fontSize = 0;
  6188. this.textMatrix = IDENTITY_MATRIX;
  6189. this.fontMatrix = FONT_IDENTITY_MATRIX;
  6190. this.leading = 0;
  6191. // Current point (in user coordinates)
  6192. this.x = 0;
  6193. this.y = 0;
  6194. // Start of text line (in text coordinates)
  6195. this.lineX = 0;
  6196. this.lineY = 0;
  6197. // Character and word spacing
  6198. this.charSpacing = 0;
  6199. this.wordSpacing = 0;
  6200. this.textHScale = 1;
  6201. this.textRise = 0;
  6202. // Default foreground and background colors
  6203. this.fillColor = SVG_DEFAULTS.fillColor;
  6204. this.strokeColor = '#000000';
  6205. this.fillAlpha = 1;
  6206. this.strokeAlpha = 1;
  6207. this.lineWidth = 1;
  6208. this.lineJoin = '';
  6209. this.lineCap = '';
  6210. this.miterLimit = 0;
  6211. this.dashArray = [];
  6212. this.dashPhase = 0;
  6213. this.dependencies = [];
  6214. // Clipping
  6215. this.clipId = '';
  6216. this.pendingClip = false;
  6217. this.maskId = '';
  6218. }
  6219. SVGExtraState.prototype = {
  6220. clone: function SVGExtraState_clone() {
  6221. return Object.create(this);
  6222. },
  6223. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  6224. this.x = x;
  6225. this.y = y;
  6226. }
  6227. };
  6228. return SVGExtraState;
  6229. })();
  6230. var SVGGraphics = (function SVGGraphicsClosure() {
  6231. function createScratchSVG(width, height) {
  6232. var NS = 'http://www.w3.org/2000/svg';
  6233. var svg = document.createElementNS(NS, 'svg:svg');
  6234. svg.setAttributeNS(null, 'version', '1.1');
  6235. svg.setAttributeNS(null, 'width', width + 'px');
  6236. svg.setAttributeNS(null, 'height', height + 'px');
  6237. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  6238. return svg;
  6239. }
  6240. function opListToTree(opList) {
  6241. var opTree = [];
  6242. var tmp = [];
  6243. var opListLen = opList.length;
  6244. for (var x = 0; x < opListLen; x++) {
  6245. if (opList[x].fn === 'save') {
  6246. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  6247. tmp.push(opTree);
  6248. opTree = opTree[opTree.length - 1].items;
  6249. continue;
  6250. }
  6251. if(opList[x].fn === 'restore') {
  6252. opTree = tmp.pop();
  6253. } else {
  6254. opTree.push(opList[x]);
  6255. }
  6256. }
  6257. return opTree;
  6258. }
  6259. /**
  6260. * Formats float number.
  6261. * @param value {number} number to format.
  6262. * @returns {string}
  6263. */
  6264. function pf(value) {
  6265. if (value === (value | 0)) { // integer number
  6266. return value.toString();
  6267. }
  6268. var s = value.toFixed(10);
  6269. var i = s.length - 1;
  6270. if (s[i] !== '0') {
  6271. return s;
  6272. }
  6273. // removing trailing zeros
  6274. do {
  6275. i--;
  6276. } while (s[i] === '0');
  6277. return s.substr(0, s[i] === '.' ? i : i + 1);
  6278. }
  6279. /**
  6280. * Formats transform matrix. The standard rotation, scale and translate
  6281. * matrices are replaced by their shorter forms, and for identity matrix
  6282. * returns empty string to save the memory.
  6283. * @param m {Array} matrix to format.
  6284. * @returns {string}
  6285. */
  6286. function pm(m) {
  6287. if (m[4] === 0 && m[5] === 0) {
  6288. if (m[1] === 0 && m[2] === 0) {
  6289. if (m[0] === 1 && m[3] === 1) {
  6290. return '';
  6291. }
  6292. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6293. }
  6294. if (m[0] === m[3] && m[1] === -m[2]) {
  6295. var a = Math.acos(m[0]) * 180 / Math.PI;
  6296. return 'rotate(' + pf(a) + ')';
  6297. }
  6298. } else {
  6299. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6300. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6301. }
  6302. }
  6303. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6304. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6305. }
  6306. function SVGGraphics(commonObjs, objs) {
  6307. this.current = new SVGExtraState();
  6308. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6309. this.transformStack = [];
  6310. this.extraStack = [];
  6311. this.commonObjs = commonObjs;
  6312. this.objs = objs;
  6313. this.pendingEOFill = false;
  6314. this.embedFonts = false;
  6315. this.embeddedFonts = {};
  6316. this.cssStyle = null;
  6317. }
  6318. var NS = 'http://www.w3.org/2000/svg';
  6319. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6320. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6321. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6322. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6323. var clipCount = 0;
  6324. var maskCount = 0;
  6325. SVGGraphics.prototype = {
  6326. save: function SVGGraphics_save() {
  6327. this.transformStack.push(this.transformMatrix);
  6328. var old = this.current;
  6329. this.extraStack.push(old);
  6330. this.current = old.clone();
  6331. },
  6332. restore: function SVGGraphics_restore() {
  6333. this.transformMatrix = this.transformStack.pop();
  6334. this.current = this.extraStack.pop();
  6335. this.tgrp = document.createElementNS(NS, 'svg:g');
  6336. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6337. this.pgrp.appendChild(this.tgrp);
  6338. },
  6339. group: function SVGGraphics_group(items) {
  6340. this.save();
  6341. this.executeOpTree(items);
  6342. this.restore();
  6343. },
  6344. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6345. var fnArray = operatorList.fnArray;
  6346. var fnArrayLen = fnArray.length;
  6347. var argsArray = operatorList.argsArray;
  6348. var self = this;
  6349. for (var i = 0; i < fnArrayLen; i++) {
  6350. if (OPS.dependency === fnArray[i]) {
  6351. var deps = argsArray[i];
  6352. for (var n = 0, nn = deps.length; n < nn; n++) {
  6353. var obj = deps[n];
  6354. var common = obj.substring(0, 2) === 'g_';
  6355. var promise;
  6356. if (common) {
  6357. promise = new Promise(function(resolve) {
  6358. self.commonObjs.get(obj, resolve);
  6359. });
  6360. } else {
  6361. promise = new Promise(function(resolve) {
  6362. self.objs.get(obj, resolve);
  6363. });
  6364. }
  6365. this.current.dependencies.push(promise);
  6366. }
  6367. }
  6368. }
  6369. return Promise.all(this.current.dependencies);
  6370. },
  6371. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6372. var transformMatrix = [a, b, c, d, e, f];
  6373. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6374. transformMatrix);
  6375. this.tgrp = document.createElementNS(NS, 'svg:g');
  6376. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6377. },
  6378. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6379. this.svg = createScratchSVG(viewport.width, viewport.height);
  6380. this.viewport = viewport;
  6381. return this.loadDependencies(operatorList).then(function () {
  6382. this.transformMatrix = IDENTITY_MATRIX;
  6383. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6384. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6385. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6386. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6387. this.defs = document.createElementNS(NS, 'svg:defs');
  6388. this.pgrp.appendChild(this.defs);
  6389. this.pgrp.appendChild(this.tgrp);
  6390. this.svg.appendChild(this.pgrp);
  6391. var opTree = this.convertOpList(operatorList);
  6392. this.executeOpTree(opTree);
  6393. return this.svg;
  6394. }.bind(this));
  6395. },
  6396. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6397. var argsArray = operatorList.argsArray;
  6398. var fnArray = operatorList.fnArray;
  6399. var fnArrayLen = fnArray.length;
  6400. var REVOPS = [];
  6401. var opList = [];
  6402. for (var op in OPS) {
  6403. REVOPS[OPS[op]] = op;
  6404. }
  6405. for (var x = 0; x < fnArrayLen; x++) {
  6406. var fnId = fnArray[x];
  6407. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6408. }
  6409. return opListToTree(opList);
  6410. },
  6411. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6412. var opTreeLen = opTree.length;
  6413. for(var x = 0; x < opTreeLen; x++) {
  6414. var fn = opTree[x].fn;
  6415. var fnId = opTree[x].fnId;
  6416. var args = opTree[x].args;
  6417. switch (fnId | 0) {
  6418. case OPS.beginText:
  6419. this.beginText();
  6420. break;
  6421. case OPS.setLeading:
  6422. this.setLeading(args);
  6423. break;
  6424. case OPS.setLeadingMoveText:
  6425. this.setLeadingMoveText(args[0], args[1]);
  6426. break;
  6427. case OPS.setFont:
  6428. this.setFont(args);
  6429. break;
  6430. case OPS.showText:
  6431. this.showText(args[0]);
  6432. break;
  6433. case OPS.showSpacedText:
  6434. this.showText(args[0]);
  6435. break;
  6436. case OPS.endText:
  6437. this.endText();
  6438. break;
  6439. case OPS.moveText:
  6440. this.moveText(args[0], args[1]);
  6441. break;
  6442. case OPS.setCharSpacing:
  6443. this.setCharSpacing(args[0]);
  6444. break;
  6445. case OPS.setWordSpacing:
  6446. this.setWordSpacing(args[0]);
  6447. break;
  6448. case OPS.setTextMatrix:
  6449. this.setTextMatrix(args[0], args[1], args[2],
  6450. args[3], args[4], args[5]);
  6451. break;
  6452. case OPS.setLineWidth:
  6453. this.setLineWidth(args[0]);
  6454. break;
  6455. case OPS.setLineJoin:
  6456. this.setLineJoin(args[0]);
  6457. break;
  6458. case OPS.setLineCap:
  6459. this.setLineCap(args[0]);
  6460. break;
  6461. case OPS.setMiterLimit:
  6462. this.setMiterLimit(args[0]);
  6463. break;
  6464. case OPS.setFillRGBColor:
  6465. this.setFillRGBColor(args[0], args[1], args[2]);
  6466. break;
  6467. case OPS.setStrokeRGBColor:
  6468. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6469. break;
  6470. case OPS.setDash:
  6471. this.setDash(args[0], args[1]);
  6472. break;
  6473. case OPS.setGState:
  6474. this.setGState(args[0]);
  6475. break;
  6476. case OPS.fill:
  6477. this.fill();
  6478. break;
  6479. case OPS.eoFill:
  6480. this.eoFill();
  6481. break;
  6482. case OPS.stroke:
  6483. this.stroke();
  6484. break;
  6485. case OPS.fillStroke:
  6486. this.fillStroke();
  6487. break;
  6488. case OPS.eoFillStroke:
  6489. this.eoFillStroke();
  6490. break;
  6491. case OPS.clip:
  6492. this.clip('nonzero');
  6493. break;
  6494. case OPS.eoClip:
  6495. this.clip('evenodd');
  6496. break;
  6497. case OPS.paintSolidColorImageMask:
  6498. this.paintSolidColorImageMask();
  6499. break;
  6500. case OPS.paintJpegXObject:
  6501. this.paintJpegXObject(args[0], args[1], args[2]);
  6502. break;
  6503. case OPS.paintImageXObject:
  6504. this.paintImageXObject(args[0]);
  6505. break;
  6506. case OPS.paintInlineImageXObject:
  6507. this.paintInlineImageXObject(args[0]);
  6508. break;
  6509. case OPS.paintImageMaskXObject:
  6510. this.paintImageMaskXObject(args[0]);
  6511. break;
  6512. case OPS.paintFormXObjectBegin:
  6513. this.paintFormXObjectBegin(args[0], args[1]);
  6514. break;
  6515. case OPS.paintFormXObjectEnd:
  6516. this.paintFormXObjectEnd();
  6517. break;
  6518. case OPS.closePath:
  6519. this.closePath();
  6520. break;
  6521. case OPS.closeStroke:
  6522. this.closeStroke();
  6523. break;
  6524. case OPS.closeFillStroke:
  6525. this.closeFillStroke();
  6526. break;
  6527. case OPS.nextLine:
  6528. this.nextLine();
  6529. break;
  6530. case OPS.transform:
  6531. this.transform(args[0], args[1], args[2], args[3],
  6532. args[4], args[5]);
  6533. break;
  6534. case OPS.constructPath:
  6535. this.constructPath(args[0], args[1]);
  6536. break;
  6537. case OPS.endPath:
  6538. this.endPath();
  6539. break;
  6540. case 92:
  6541. this.group(opTree[x].items);
  6542. break;
  6543. default:
  6544. warn('Unimplemented method '+ fn);
  6545. break;
  6546. }
  6547. }
  6548. },
  6549. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  6550. this.current.wordSpacing = wordSpacing;
  6551. },
  6552. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  6553. this.current.charSpacing = charSpacing;
  6554. },
  6555. nextLine: function SVGGraphics_nextLine() {
  6556. this.moveText(0, this.current.leading);
  6557. },
  6558. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  6559. var current = this.current;
  6560. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  6561. this.current.x = this.current.lineX = 0;
  6562. this.current.y = this.current.lineY = 0;
  6563. current.xcoords = [];
  6564. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6565. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6566. current.tspan.setAttributeNS(null, 'font-size',
  6567. pf(current.fontSize) + 'px');
  6568. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6569. current.txtElement = document.createElementNS(NS, 'svg:text');
  6570. current.txtElement.appendChild(current.tspan);
  6571. },
  6572. beginText: function SVGGraphics_beginText() {
  6573. this.current.x = this.current.lineX = 0;
  6574. this.current.y = this.current.lineY = 0;
  6575. this.current.textMatrix = IDENTITY_MATRIX;
  6576. this.current.lineMatrix = IDENTITY_MATRIX;
  6577. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6578. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  6579. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  6580. this.current.xcoords = [];
  6581. },
  6582. moveText: function SVGGraphics_moveText(x, y) {
  6583. var current = this.current;
  6584. this.current.x = this.current.lineX += x;
  6585. this.current.y = this.current.lineY += y;
  6586. current.xcoords = [];
  6587. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6588. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6589. current.tspan.setAttributeNS(null, 'font-size',
  6590. pf(current.fontSize) + 'px');
  6591. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6592. },
  6593. showText: function SVGGraphics_showText(glyphs) {
  6594. var current = this.current;
  6595. var font = current.font;
  6596. var fontSize = current.fontSize;
  6597. if (fontSize === 0) {
  6598. return;
  6599. }
  6600. var charSpacing = current.charSpacing;
  6601. var wordSpacing = current.wordSpacing;
  6602. var fontDirection = current.fontDirection;
  6603. var textHScale = current.textHScale * fontDirection;
  6604. var glyphsLength = glyphs.length;
  6605. var vertical = font.vertical;
  6606. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  6607. var x = 0, i;
  6608. for (i = 0; i < glyphsLength; ++i) {
  6609. var glyph = glyphs[i];
  6610. if (glyph === null) {
  6611. // word break
  6612. x += fontDirection * wordSpacing;
  6613. continue;
  6614. } else if (isNum(glyph)) {
  6615. x += -glyph * fontSize * 0.001;
  6616. continue;
  6617. }
  6618. current.xcoords.push(current.x + x * textHScale);
  6619. var width = glyph.width;
  6620. var character = glyph.fontChar;
  6621. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  6622. x += charWidth;
  6623. current.tspan.textContent += character;
  6624. }
  6625. if (vertical) {
  6626. current.y -= x * textHScale;
  6627. } else {
  6628. current.x += x * textHScale;
  6629. }
  6630. current.tspan.setAttributeNS(null, 'x',
  6631. current.xcoords.map(pf).join(' '));
  6632. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6633. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6634. current.tspan.setAttributeNS(null, 'font-size',
  6635. pf(current.fontSize) + 'px');
  6636. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  6637. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  6638. }
  6639. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  6640. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  6641. }
  6642. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  6643. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  6644. }
  6645. current.txtElement.setAttributeNS(null, 'transform',
  6646. pm(current.textMatrix) +
  6647. ' scale(1, -1)' );
  6648. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  6649. current.txtElement.appendChild(current.tspan);
  6650. current.txtgrp.appendChild(current.txtElement);
  6651. this.tgrp.appendChild(current.txtElement);
  6652. },
  6653. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  6654. this.setLeading(-y);
  6655. this.moveText(x, y);
  6656. },
  6657. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  6658. if (!this.cssStyle) {
  6659. this.cssStyle = document.createElementNS(NS, 'svg:style');
  6660. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  6661. this.defs.appendChild(this.cssStyle);
  6662. }
  6663. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  6664. this.cssStyle.textContent +=
  6665. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  6666. ' src: url(' + url + '); }\n';
  6667. },
  6668. setFont: function SVGGraphics_setFont(details) {
  6669. var current = this.current;
  6670. var fontObj = this.commonObjs.get(details[0]);
  6671. var size = details[1];
  6672. this.current.font = fontObj;
  6673. if (this.embedFonts && fontObj.data &&
  6674. !this.embeddedFonts[fontObj.loadedName]) {
  6675. this.addFontStyle(fontObj);
  6676. this.embeddedFonts[fontObj.loadedName] = fontObj;
  6677. }
  6678. current.fontMatrix = (fontObj.fontMatrix ?
  6679. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  6680. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  6681. (fontObj.bold ? 'bold' : 'normal');
  6682. var italic = fontObj.italic ? 'italic' : 'normal';
  6683. if (size < 0) {
  6684. size = -size;
  6685. current.fontDirection = -1;
  6686. } else {
  6687. current.fontDirection = 1;
  6688. }
  6689. current.fontSize = size;
  6690. current.fontFamily = fontObj.loadedName;
  6691. current.fontWeight = bold;
  6692. current.fontStyle = italic;
  6693. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6694. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6695. current.xcoords = [];
  6696. },
  6697. endText: function SVGGraphics_endText() {
  6698. if (this.current.pendingClip) {
  6699. this.cgrp.appendChild(this.tgrp);
  6700. this.pgrp.appendChild(this.cgrp);
  6701. } else {
  6702. this.pgrp.appendChild(this.tgrp);
  6703. }
  6704. this.tgrp = document.createElementNS(NS, 'svg:g');
  6705. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6706. },
  6707. // Path properties
  6708. setLineWidth: function SVGGraphics_setLineWidth(width) {
  6709. this.current.lineWidth = width;
  6710. },
  6711. setLineCap: function SVGGraphics_setLineCap(style) {
  6712. this.current.lineCap = LINE_CAP_STYLES[style];
  6713. },
  6714. setLineJoin: function SVGGraphics_setLineJoin(style) {
  6715. this.current.lineJoin = LINE_JOIN_STYLES[style];
  6716. },
  6717. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  6718. this.current.miterLimit = limit;
  6719. },
  6720. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  6721. var color = Util.makeCssRgb(r, g, b);
  6722. this.current.strokeColor = color;
  6723. },
  6724. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  6725. var color = Util.makeCssRgb(r, g, b);
  6726. this.current.fillColor = color;
  6727. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6728. this.current.xcoords = [];
  6729. },
  6730. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  6731. this.current.dashArray = dashArray;
  6732. this.current.dashPhase = dashPhase;
  6733. },
  6734. constructPath: function SVGGraphics_constructPath(ops, args) {
  6735. var current = this.current;
  6736. var x = current.x, y = current.y;
  6737. current.path = document.createElementNS(NS, 'svg:path');
  6738. var d = [];
  6739. var opLength = ops.length;
  6740. for (var i = 0, j = 0; i < opLength; i++) {
  6741. switch (ops[i] | 0) {
  6742. case OPS.rectangle:
  6743. x = args[j++];
  6744. y = args[j++];
  6745. var width = args[j++];
  6746. var height = args[j++];
  6747. var xw = x + width;
  6748. var yh = y + height;
  6749. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  6750. 'L', pf(x), pf(yh), 'Z');
  6751. break;
  6752. case OPS.moveTo:
  6753. x = args[j++];
  6754. y = args[j++];
  6755. d.push('M', pf(x), pf(y));
  6756. break;
  6757. case OPS.lineTo:
  6758. x = args[j++];
  6759. y = args[j++];
  6760. d.push('L', pf(x) , pf(y));
  6761. break;
  6762. case OPS.curveTo:
  6763. x = args[j + 4];
  6764. y = args[j + 5];
  6765. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  6766. pf(args[j + 3]), pf(x), pf(y));
  6767. j += 6;
  6768. break;
  6769. case OPS.curveTo2:
  6770. x = args[j + 2];
  6771. y = args[j + 3];
  6772. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  6773. pf(args[j + 2]), pf(args[j + 3]));
  6774. j += 4;
  6775. break;
  6776. case OPS.curveTo3:
  6777. x = args[j + 2];
  6778. y = args[j + 3];
  6779. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  6780. pf(x), pf(y));
  6781. j += 4;
  6782. break;
  6783. case OPS.closePath:
  6784. d.push('Z');
  6785. break;
  6786. }
  6787. }
  6788. current.path.setAttributeNS(null, 'd', d.join(' '));
  6789. current.path.setAttributeNS(null, 'stroke-miterlimit',
  6790. pf(current.miterLimit));
  6791. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  6792. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  6793. current.path.setAttributeNS(null, 'stroke-width',
  6794. pf(current.lineWidth) + 'px');
  6795. current.path.setAttributeNS(null, 'stroke-dasharray',
  6796. current.dashArray.map(pf).join(' '));
  6797. current.path.setAttributeNS(null, 'stroke-dashoffset',
  6798. pf(current.dashPhase) + 'px');
  6799. current.path.setAttributeNS(null, 'fill', 'none');
  6800. this.tgrp.appendChild(current.path);
  6801. if (current.pendingClip) {
  6802. this.cgrp.appendChild(this.tgrp);
  6803. this.pgrp.appendChild(this.cgrp);
  6804. } else {
  6805. this.pgrp.appendChild(this.tgrp);
  6806. }
  6807. // Saving a reference in current.element so that it can be addressed
  6808. // in 'fill' and 'stroke'
  6809. current.element = current.path;
  6810. current.setCurrentPoint(x, y);
  6811. },
  6812. endPath: function SVGGraphics_endPath() {
  6813. var current = this.current;
  6814. if (current.pendingClip) {
  6815. this.cgrp.appendChild(this.tgrp);
  6816. this.pgrp.appendChild(this.cgrp);
  6817. } else {
  6818. this.pgrp.appendChild(this.tgrp);
  6819. }
  6820. this.tgrp = document.createElementNS(NS, 'svg:g');
  6821. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6822. },
  6823. clip: function SVGGraphics_clip(type) {
  6824. var current = this.current;
  6825. // Add current path to clipping path
  6826. current.clipId = 'clippath' + clipCount;
  6827. clipCount++;
  6828. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  6829. this.clippath.setAttributeNS(null, 'id', current.clipId);
  6830. var clipElement = current.element.cloneNode();
  6831. if (type === 'evenodd') {
  6832. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  6833. } else {
  6834. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  6835. }
  6836. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6837. this.clippath.appendChild(clipElement);
  6838. this.defs.appendChild(this.clippath);
  6839. // Create a new group with that attribute
  6840. current.pendingClip = true;
  6841. this.cgrp = document.createElementNS(NS, 'svg:g');
  6842. this.cgrp.setAttributeNS(null, 'clip-path',
  6843. 'url(#' + current.clipId + ')');
  6844. this.pgrp.appendChild(this.cgrp);
  6845. },
  6846. closePath: function SVGGraphics_closePath() {
  6847. var current = this.current;
  6848. var d = current.path.getAttributeNS(null, 'd');
  6849. d += 'Z';
  6850. current.path.setAttributeNS(null, 'd', d);
  6851. },
  6852. setLeading: function SVGGraphics_setLeading(leading) {
  6853. this.current.leading = -leading;
  6854. },
  6855. setTextRise: function SVGGraphics_setTextRise(textRise) {
  6856. this.current.textRise = textRise;
  6857. },
  6858. setHScale: function SVGGraphics_setHScale(scale) {
  6859. this.current.textHScale = scale / 100;
  6860. },
  6861. setGState: function SVGGraphics_setGState(states) {
  6862. for (var i = 0, ii = states.length; i < ii; i++) {
  6863. var state = states[i];
  6864. var key = state[0];
  6865. var value = state[1];
  6866. switch (key) {
  6867. case 'LW':
  6868. this.setLineWidth(value);
  6869. break;
  6870. case 'LC':
  6871. this.setLineCap(value);
  6872. break;
  6873. case 'LJ':
  6874. this.setLineJoin(value);
  6875. break;
  6876. case 'ML':
  6877. this.setMiterLimit(value);
  6878. break;
  6879. case 'D':
  6880. this.setDash(value[0], value[1]);
  6881. break;
  6882. case 'RI':
  6883. break;
  6884. case 'FL':
  6885. break;
  6886. case 'Font':
  6887. this.setFont(value);
  6888. break;
  6889. case 'CA':
  6890. break;
  6891. case 'ca':
  6892. break;
  6893. case 'BM':
  6894. break;
  6895. case 'SMask':
  6896. break;
  6897. }
  6898. }
  6899. },
  6900. fill: function SVGGraphics_fill() {
  6901. var current = this.current;
  6902. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6903. },
  6904. stroke: function SVGGraphics_stroke() {
  6905. var current = this.current;
  6906. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  6907. current.element.setAttributeNS(null, 'fill', 'none');
  6908. },
  6909. eoFill: function SVGGraphics_eoFill() {
  6910. var current = this.current;
  6911. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6912. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6913. },
  6914. fillStroke: function SVGGraphics_fillStroke() {
  6915. // Order is important since stroke wants fill to be none.
  6916. // First stroke, then if fill needed, it will be overwritten.
  6917. this.stroke();
  6918. this.fill();
  6919. },
  6920. eoFillStroke: function SVGGraphics_eoFillStroke() {
  6921. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6922. this.fillStroke();
  6923. },
  6924. closeStroke: function SVGGraphics_closeStroke() {
  6925. this.closePath();
  6926. this.stroke();
  6927. },
  6928. closeFillStroke: function SVGGraphics_closeFillStroke() {
  6929. this.closePath();
  6930. this.fillStroke();
  6931. },
  6932. paintSolidColorImageMask:
  6933. function SVGGraphics_paintSolidColorImageMask() {
  6934. var current = this.current;
  6935. var rect = document.createElementNS(NS, 'svg:rect');
  6936. rect.setAttributeNS(null, 'x', '0');
  6937. rect.setAttributeNS(null, 'y', '0');
  6938. rect.setAttributeNS(null, 'width', '1px');
  6939. rect.setAttributeNS(null, 'height', '1px');
  6940. rect.setAttributeNS(null, 'fill', current.fillColor);
  6941. this.tgrp.appendChild(rect);
  6942. },
  6943. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  6944. var current = this.current;
  6945. var imgObj = this.objs.get(objId);
  6946. var imgEl = document.createElementNS(NS, 'svg:image');
  6947. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  6948. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  6949. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  6950. imgEl.setAttributeNS(null, 'x', '0');
  6951. imgEl.setAttributeNS(null, 'y', pf(-h));
  6952. imgEl.setAttributeNS(null, 'transform',
  6953. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  6954. this.tgrp.appendChild(imgEl);
  6955. if (current.pendingClip) {
  6956. this.cgrp.appendChild(this.tgrp);
  6957. this.pgrp.appendChild(this.cgrp);
  6958. } else {
  6959. this.pgrp.appendChild(this.tgrp);
  6960. }
  6961. },
  6962. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  6963. var imgData = this.objs.get(objId);
  6964. if (!imgData) {
  6965. warn('Dependent image isn\'t ready yet');
  6966. return;
  6967. }
  6968. this.paintInlineImageXObject(imgData);
  6969. },
  6970. paintInlineImageXObject:
  6971. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  6972. var current = this.current;
  6973. var width = imgData.width;
  6974. var height = imgData.height;
  6975. var imgSrc = convertImgDataToPng(imgData);
  6976. var cliprect = document.createElementNS(NS, 'svg:rect');
  6977. cliprect.setAttributeNS(null, 'x', '0');
  6978. cliprect.setAttributeNS(null, 'y', '0');
  6979. cliprect.setAttributeNS(null, 'width', pf(width));
  6980. cliprect.setAttributeNS(null, 'height', pf(height));
  6981. current.element = cliprect;
  6982. this.clip('nonzero');
  6983. var imgEl = document.createElementNS(NS, 'svg:image');
  6984. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  6985. imgEl.setAttributeNS(null, 'x', '0');
  6986. imgEl.setAttributeNS(null, 'y', pf(-height));
  6987. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  6988. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  6989. imgEl.setAttributeNS(null, 'transform',
  6990. 'scale(' + pf(1 / width) + ' ' +
  6991. pf(-1 / height) + ')');
  6992. if (mask) {
  6993. mask.appendChild(imgEl);
  6994. } else {
  6995. this.tgrp.appendChild(imgEl);
  6996. }
  6997. if (current.pendingClip) {
  6998. this.cgrp.appendChild(this.tgrp);
  6999. this.pgrp.appendChild(this.cgrp);
  7000. } else {
  7001. this.pgrp.appendChild(this.tgrp);
  7002. }
  7003. },
  7004. paintImageMaskXObject:
  7005. function SVGGraphics_paintImageMaskXObject(imgData) {
  7006. var current = this.current;
  7007. var width = imgData.width;
  7008. var height = imgData.height;
  7009. var fillColor = current.fillColor;
  7010. current.maskId = 'mask' + maskCount++;
  7011. var mask = document.createElementNS(NS, 'svg:mask');
  7012. mask.setAttributeNS(null, 'id', current.maskId);
  7013. var rect = document.createElementNS(NS, 'svg:rect');
  7014. rect.setAttributeNS(null, 'x', '0');
  7015. rect.setAttributeNS(null, 'y', '0');
  7016. rect.setAttributeNS(null, 'width', pf(width));
  7017. rect.setAttributeNS(null, 'height', pf(height));
  7018. rect.setAttributeNS(null, 'fill', fillColor);
  7019. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  7020. this.defs.appendChild(mask);
  7021. this.tgrp.appendChild(rect);
  7022. this.paintInlineImageXObject(imgData, mask);
  7023. },
  7024. paintFormXObjectBegin:
  7025. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  7026. this.save();
  7027. if (isArray(matrix) && matrix.length === 6) {
  7028. this.transform(matrix[0], matrix[1], matrix[2],
  7029. matrix[3], matrix[4], matrix[5]);
  7030. }
  7031. if (isArray(bbox) && bbox.length === 4) {
  7032. var width = bbox[2] - bbox[0];
  7033. var height = bbox[3] - bbox[1];
  7034. var cliprect = document.createElementNS(NS, 'svg:rect');
  7035. cliprect.setAttributeNS(null, 'x', bbox[0]);
  7036. cliprect.setAttributeNS(null, 'y', bbox[1]);
  7037. cliprect.setAttributeNS(null, 'width', pf(width));
  7038. cliprect.setAttributeNS(null, 'height', pf(height));
  7039. this.current.element = cliprect;
  7040. this.clip('nonzero');
  7041. this.endPath();
  7042. }
  7043. },
  7044. paintFormXObjectEnd:
  7045. function SVGGraphics_paintFormXObjectEnd() {
  7046. this.restore();
  7047. }
  7048. };
  7049. return SVGGraphics;
  7050. })();
  7051. PDFJS.SVGGraphics = SVGGraphics;
  7052. var NetworkManager = (function NetworkManagerClosure() {
  7053. var OK_RESPONSE = 200;
  7054. var PARTIAL_CONTENT_RESPONSE = 206;
  7055. function NetworkManager(url, args) {
  7056. this.url = url;
  7057. args = args || {};
  7058. this.isHttp = /^https?:/i.test(url);
  7059. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  7060. this.withCredentials = args.withCredentials || false;
  7061. this.getXhr = args.getXhr ||
  7062. function NetworkManager_getXhr() {
  7063. return new XMLHttpRequest();
  7064. };
  7065. this.currXhrId = 0;
  7066. this.pendingRequests = {};
  7067. this.loadedRequests = {};
  7068. }
  7069. function getArrayBuffer(xhr) {
  7070. var data = xhr.response;
  7071. if (typeof data !== 'string') {
  7072. return data;
  7073. }
  7074. var length = data.length;
  7075. var array = new Uint8Array(length);
  7076. for (var i = 0; i < length; i++) {
  7077. array[i] = data.charCodeAt(i) & 0xFF;
  7078. }
  7079. return array.buffer;
  7080. }
  7081. NetworkManager.prototype = {
  7082. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  7083. var args = {
  7084. begin: begin,
  7085. end: end
  7086. };
  7087. for (var prop in listeners) {
  7088. args[prop] = listeners[prop];
  7089. }
  7090. return this.request(args);
  7091. },
  7092. requestFull: function NetworkManager_requestFull(listeners) {
  7093. return this.request(listeners);
  7094. },
  7095. request: function NetworkManager_request(args) {
  7096. var xhr = this.getXhr();
  7097. var xhrId = this.currXhrId++;
  7098. var pendingRequest = this.pendingRequests[xhrId] = {
  7099. xhr: xhr
  7100. };
  7101. xhr.open('GET', this.url);
  7102. xhr.withCredentials = this.withCredentials;
  7103. for (var property in this.httpHeaders) {
  7104. var value = this.httpHeaders[property];
  7105. if (typeof value === 'undefined') {
  7106. continue;
  7107. }
  7108. xhr.setRequestHeader(property, value);
  7109. }
  7110. if (this.isHttp && 'begin' in args && 'end' in args) {
  7111. var rangeStr = args.begin + '-' + (args.end - 1);
  7112. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  7113. pendingRequest.expectedStatus = 206;
  7114. } else {
  7115. pendingRequest.expectedStatus = 200;
  7116. }
  7117. if (args.onProgressiveData) {
  7118. // Some legacy browsers might throw an exception.
  7119. try {
  7120. xhr.responseType = 'moz-chunked-arraybuffer';
  7121. } catch(e) {}
  7122. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  7123. pendingRequest.onProgressiveData = args.onProgressiveData;
  7124. pendingRequest.mozChunked = true;
  7125. } else {
  7126. xhr.responseType = 'arraybuffer';
  7127. }
  7128. } else {
  7129. xhr.responseType = 'arraybuffer';
  7130. }
  7131. if (args.onError) {
  7132. xhr.onerror = function(evt) {
  7133. args.onError(xhr.status);
  7134. };
  7135. }
  7136. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  7137. xhr.onprogress = this.onProgress.bind(this, xhrId);
  7138. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  7139. pendingRequest.onDone = args.onDone;
  7140. pendingRequest.onError = args.onError;
  7141. pendingRequest.onProgress = args.onProgress;
  7142. xhr.send(null);
  7143. return xhrId;
  7144. },
  7145. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  7146. var pendingRequest = this.pendingRequests[xhrId];
  7147. if (!pendingRequest) {
  7148. // Maybe abortRequest was called...
  7149. return;
  7150. }
  7151. if (pendingRequest.mozChunked) {
  7152. var chunk = getArrayBuffer(pendingRequest.xhr);
  7153. pendingRequest.onProgressiveData(chunk);
  7154. }
  7155. var onProgress = pendingRequest.onProgress;
  7156. if (onProgress) {
  7157. onProgress(evt);
  7158. }
  7159. },
  7160. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  7161. var pendingRequest = this.pendingRequests[xhrId];
  7162. if (!pendingRequest) {
  7163. // Maybe abortRequest was called...
  7164. return;
  7165. }
  7166. var xhr = pendingRequest.xhr;
  7167. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  7168. pendingRequest.onHeadersReceived();
  7169. delete pendingRequest.onHeadersReceived;
  7170. }
  7171. if (xhr.readyState !== 4) {
  7172. return;
  7173. }
  7174. if (!(xhrId in this.pendingRequests)) {
  7175. // The XHR request might have been aborted in onHeadersReceived()
  7176. // callback, in which case we should abort request
  7177. return;
  7178. }
  7179. delete this.pendingRequests[xhrId];
  7180. // success status == 0 can be on ftp, file and other protocols
  7181. if (xhr.status === 0 && this.isHttp) {
  7182. if (pendingRequest.onError) {
  7183. pendingRequest.onError(xhr.status);
  7184. }
  7185. return;
  7186. }
  7187. var xhrStatus = xhr.status || OK_RESPONSE;
  7188. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  7189. // "A server MAY ignore the Range header". This means it's possible to
  7190. // get a 200 rather than a 206 response from a range request.
  7191. var ok_response_on_range_request =
  7192. xhrStatus === OK_RESPONSE &&
  7193. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  7194. if (!ok_response_on_range_request &&
  7195. xhrStatus !== pendingRequest.expectedStatus) {
  7196. if (pendingRequest.onError) {
  7197. pendingRequest.onError(xhr.status);
  7198. }
  7199. return;
  7200. }
  7201. this.loadedRequests[xhrId] = true;
  7202. var chunk = getArrayBuffer(xhr);
  7203. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  7204. var rangeHeader = xhr.getResponseHeader('Content-Range');
  7205. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  7206. var begin = parseInt(matches[1], 10);
  7207. pendingRequest.onDone({
  7208. begin: begin,
  7209. chunk: chunk
  7210. });
  7211. } else if (pendingRequest.onProgressiveData) {
  7212. pendingRequest.onDone(null);
  7213. } else {
  7214. pendingRequest.onDone({
  7215. begin: 0,
  7216. chunk: chunk
  7217. });
  7218. }
  7219. },
  7220. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  7221. for (var xhrId in this.pendingRequests) {
  7222. return true;
  7223. }
  7224. return false;
  7225. },
  7226. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  7227. return this.pendingRequests[xhrId].xhr;
  7228. },
  7229. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  7230. return !!(this.pendingRequests[xhrId].onProgressiveData);
  7231. },
  7232. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  7233. return xhrId in this.pendingRequests;
  7234. },
  7235. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  7236. return xhrId in this.loadedRequests;
  7237. },
  7238. abortAllRequests: function NetworkManager_abortAllRequests() {
  7239. for (var xhrId in this.pendingRequests) {
  7240. this.abortRequest(xhrId | 0);
  7241. }
  7242. },
  7243. abortRequest: function NetworkManager_abortRequest(xhrId) {
  7244. var xhr = this.pendingRequests[xhrId].xhr;
  7245. delete this.pendingRequests[xhrId];
  7246. xhr.abort();
  7247. }
  7248. };
  7249. return NetworkManager;
  7250. })();
  7251. var ChunkedStream = (function ChunkedStreamClosure() {
  7252. function ChunkedStream(length, chunkSize, manager) {
  7253. this.bytes = new Uint8Array(length);
  7254. this.start = 0;
  7255. this.pos = 0;
  7256. this.end = length;
  7257. this.chunkSize = chunkSize;
  7258. this.loadedChunks = [];
  7259. this.numChunksLoaded = 0;
  7260. this.numChunks = Math.ceil(length / chunkSize);
  7261. this.manager = manager;
  7262. this.progressiveDataLength = 0;
  7263. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  7264. }
  7265. // required methods for a stream. if a particular stream does not
  7266. // implement these, an error should be thrown
  7267. ChunkedStream.prototype = {
  7268. getMissingChunks: function ChunkedStream_getMissingChunks() {
  7269. var chunks = [];
  7270. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  7271. if (!this.loadedChunks[chunk]) {
  7272. chunks.push(chunk);
  7273. }
  7274. }
  7275. return chunks;
  7276. },
  7277. getBaseStreams: function ChunkedStream_getBaseStreams() {
  7278. return [this];
  7279. },
  7280. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  7281. return this.numChunksLoaded === this.numChunks;
  7282. },
  7283. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  7284. var end = begin + chunk.byteLength;
  7285. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  7286. // Using this.length is inaccurate here since this.start can be moved
  7287. // See ChunkedStream.moveStart()
  7288. var length = this.bytes.length;
  7289. assert(end % this.chunkSize === 0 || end === length,
  7290. 'Bad end offset: ' + end);
  7291. this.bytes.set(new Uint8Array(chunk), begin);
  7292. var chunkSize = this.chunkSize;
  7293. var beginChunk = Math.floor(begin / chunkSize);
  7294. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7295. var curChunk;
  7296. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7297. if (!this.loadedChunks[curChunk]) {
  7298. this.loadedChunks[curChunk] = true;
  7299. ++this.numChunksLoaded;
  7300. }
  7301. }
  7302. },
  7303. onReceiveProgressiveData:
  7304. function ChunkedStream_onReceiveProgressiveData(data) {
  7305. var position = this.progressiveDataLength;
  7306. var beginChunk = Math.floor(position / this.chunkSize);
  7307. this.bytes.set(new Uint8Array(data), position);
  7308. position += data.byteLength;
  7309. this.progressiveDataLength = position;
  7310. var endChunk = position >= this.end ? this.numChunks :
  7311. Math.floor(position / this.chunkSize);
  7312. var curChunk;
  7313. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7314. if (!this.loadedChunks[curChunk]) {
  7315. this.loadedChunks[curChunk] = true;
  7316. ++this.numChunksLoaded;
  7317. }
  7318. }
  7319. },
  7320. ensureByte: function ChunkedStream_ensureByte(pos) {
  7321. var chunk = Math.floor(pos / this.chunkSize);
  7322. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  7323. return;
  7324. }
  7325. if (!this.loadedChunks[chunk]) {
  7326. throw new MissingDataException(pos, pos + 1);
  7327. }
  7328. this.lastSuccessfulEnsureByteChunk = chunk;
  7329. },
  7330. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  7331. if (begin >= end) {
  7332. return;
  7333. }
  7334. if (end <= this.progressiveDataLength) {
  7335. return;
  7336. }
  7337. var chunkSize = this.chunkSize;
  7338. var beginChunk = Math.floor(begin / chunkSize);
  7339. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7340. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7341. if (!this.loadedChunks[chunk]) {
  7342. throw new MissingDataException(begin, end);
  7343. }
  7344. }
  7345. },
  7346. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  7347. var chunk, n;
  7348. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  7349. if (!this.loadedChunks[chunk]) {
  7350. return chunk;
  7351. }
  7352. }
  7353. // Wrap around to beginning
  7354. for (chunk = 0; chunk < beginChunk; ++chunk) {
  7355. if (!this.loadedChunks[chunk]) {
  7356. return chunk;
  7357. }
  7358. }
  7359. return null;
  7360. },
  7361. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7362. return !!this.loadedChunks[chunk];
  7363. },
  7364. get length() {
  7365. return this.end - this.start;
  7366. },
  7367. get isEmpty() {
  7368. return this.length === 0;
  7369. },
  7370. getByte: function ChunkedStream_getByte() {
  7371. var pos = this.pos;
  7372. if (pos >= this.end) {
  7373. return -1;
  7374. }
  7375. this.ensureByte(pos);
  7376. return this.bytes[this.pos++];
  7377. },
  7378. getUint16: function ChunkedStream_getUint16() {
  7379. var b0 = this.getByte();
  7380. var b1 = this.getByte();
  7381. if (b0 === -1 || b1 === -1) {
  7382. return -1;
  7383. }
  7384. return (b0 << 8) + b1;
  7385. },
  7386. getInt32: function ChunkedStream_getInt32() {
  7387. var b0 = this.getByte();
  7388. var b1 = this.getByte();
  7389. var b2 = this.getByte();
  7390. var b3 = this.getByte();
  7391. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7392. },
  7393. // returns subarray of original buffer
  7394. // should only be read
  7395. getBytes: function ChunkedStream_getBytes(length) {
  7396. var bytes = this.bytes;
  7397. var pos = this.pos;
  7398. var strEnd = this.end;
  7399. if (!length) {
  7400. this.ensureRange(pos, strEnd);
  7401. return bytes.subarray(pos, strEnd);
  7402. }
  7403. var end = pos + length;
  7404. if (end > strEnd) {
  7405. end = strEnd;
  7406. }
  7407. this.ensureRange(pos, end);
  7408. this.pos = end;
  7409. return bytes.subarray(pos, end);
  7410. },
  7411. peekByte: function ChunkedStream_peekByte() {
  7412. var peekedByte = this.getByte();
  7413. this.pos--;
  7414. return peekedByte;
  7415. },
  7416. peekBytes: function ChunkedStream_peekBytes(length) {
  7417. var bytes = this.getBytes(length);
  7418. this.pos -= bytes.length;
  7419. return bytes;
  7420. },
  7421. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7422. this.ensureRange(begin, end);
  7423. return this.bytes.subarray(begin, end);
  7424. },
  7425. skip: function ChunkedStream_skip(n) {
  7426. if (!n) {
  7427. n = 1;
  7428. }
  7429. this.pos += n;
  7430. },
  7431. reset: function ChunkedStream_reset() {
  7432. this.pos = this.start;
  7433. },
  7434. moveStart: function ChunkedStream_moveStart() {
  7435. this.start = this.pos;
  7436. },
  7437. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7438. this.ensureRange(start, start + length);
  7439. function ChunkedStreamSubstream() {}
  7440. ChunkedStreamSubstream.prototype = Object.create(this);
  7441. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7442. var chunkSize = this.chunkSize;
  7443. var beginChunk = Math.floor(this.start / chunkSize);
  7444. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7445. var missingChunks = [];
  7446. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7447. if (!this.loadedChunks[chunk]) {
  7448. missingChunks.push(chunk);
  7449. }
  7450. }
  7451. return missingChunks;
  7452. };
  7453. var subStream = new ChunkedStreamSubstream();
  7454. subStream.pos = subStream.start = start;
  7455. subStream.end = start + length || this.end;
  7456. subStream.dict = dict;
  7457. return subStream;
  7458. },
  7459. isStream: true
  7460. };
  7461. return ChunkedStream;
  7462. })();
  7463. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7464. function ChunkedStreamManager(length, chunkSize, url, args) {
  7465. this.stream = new ChunkedStream(length, chunkSize, this);
  7466. this.length = length;
  7467. this.chunkSize = chunkSize;
  7468. this.url = url;
  7469. this.disableAutoFetch = args.disableAutoFetch;
  7470. var msgHandler = this.msgHandler = args.msgHandler;
  7471. if (args.chunkedViewerLoading) {
  7472. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7473. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  7474. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7475. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  7476. };
  7477. } else {
  7478. var getXhr = function getXhr() {
  7479. return new XMLHttpRequest();
  7480. };
  7481. this.networkManager = new NetworkManager(this.url, {
  7482. getXhr: getXhr,
  7483. httpHeaders: args.httpHeaders,
  7484. withCredentials: args.withCredentials
  7485. });
  7486. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7487. this.networkManager.requestRange(begin, end, {
  7488. onDone: this.onReceiveData.bind(this),
  7489. onProgress: this.onProgress.bind(this)
  7490. });
  7491. };
  7492. }
  7493. this.currRequestId = 0;
  7494. this.chunksNeededByRequest = {};
  7495. this.requestsByChunk = {};
  7496. this.callbacksByRequest = {};
  7497. this.progressiveDataLength = 0;
  7498. this._loadedStreamCapability = createPromiseCapability();
  7499. if (args.initialData) {
  7500. this.onReceiveData({chunk: args.initialData});
  7501. }
  7502. }
  7503. ChunkedStreamManager.prototype = {
  7504. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  7505. return this._loadedStreamCapability.promise;
  7506. },
  7507. // Get all the chunks that are not yet loaded and groups them into
  7508. // contiguous ranges to load in as few requests as possible
  7509. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  7510. var missingChunks = this.stream.getMissingChunks();
  7511. this.requestChunks(missingChunks);
  7512. return this._loadedStreamCapability.promise;
  7513. },
  7514. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  7515. callback) {
  7516. var requestId = this.currRequestId++;
  7517. var chunksNeeded;
  7518. var i, ii;
  7519. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  7520. for (i = 0, ii = chunks.length; i < ii; i++) {
  7521. if (!this.stream.hasChunk(chunks[i])) {
  7522. chunksNeeded[chunks[i]] = true;
  7523. }
  7524. }
  7525. if (isEmptyObj(chunksNeeded)) {
  7526. if (callback) {
  7527. callback();
  7528. }
  7529. return;
  7530. }
  7531. this.callbacksByRequest[requestId] = callback;
  7532. var chunksToRequest = [];
  7533. for (var chunk in chunksNeeded) {
  7534. chunk = chunk | 0;
  7535. if (!(chunk in this.requestsByChunk)) {
  7536. this.requestsByChunk[chunk] = [];
  7537. chunksToRequest.push(chunk);
  7538. }
  7539. this.requestsByChunk[chunk].push(requestId);
  7540. }
  7541. if (!chunksToRequest.length) {
  7542. return;
  7543. }
  7544. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  7545. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  7546. var groupedChunk = groupedChunksToRequest[i];
  7547. var begin = groupedChunk.beginChunk * this.chunkSize;
  7548. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  7549. this.sendRequest(begin, end);
  7550. }
  7551. },
  7552. getStream: function ChunkedStreamManager_getStream() {
  7553. return this.stream;
  7554. },
  7555. // Loads any chunks in the requested range that are not yet loaded
  7556. requestRange: function ChunkedStreamManager_requestRange(
  7557. begin, end, callback) {
  7558. end = Math.min(end, this.length);
  7559. var beginChunk = this.getBeginChunk(begin);
  7560. var endChunk = this.getEndChunk(end);
  7561. var chunks = [];
  7562. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7563. chunks.push(chunk);
  7564. }
  7565. this.requestChunks(chunks, callback);
  7566. },
  7567. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  7568. callback) {
  7569. ranges = ranges || [];
  7570. var chunksToRequest = [];
  7571. for (var i = 0; i < ranges.length; i++) {
  7572. var beginChunk = this.getBeginChunk(ranges[i].begin);
  7573. var endChunk = this.getEndChunk(ranges[i].end);
  7574. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7575. if (chunksToRequest.indexOf(chunk) < 0) {
  7576. chunksToRequest.push(chunk);
  7577. }
  7578. }
  7579. }
  7580. chunksToRequest.sort(function(a, b) { return a - b; });
  7581. this.requestChunks(chunksToRequest, callback);
  7582. },
  7583. // Groups a sorted array of chunks into as few continguous larger
  7584. // chunks as possible
  7585. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  7586. var groupedChunks = [];
  7587. var beginChunk = -1;
  7588. var prevChunk = -1;
  7589. for (var i = 0; i < chunks.length; ++i) {
  7590. var chunk = chunks[i];
  7591. if (beginChunk < 0) {
  7592. beginChunk = chunk;
  7593. }
  7594. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  7595. groupedChunks.push({ beginChunk: beginChunk,
  7596. endChunk: prevChunk + 1 });
  7597. beginChunk = chunk;
  7598. }
  7599. if (i + 1 === chunks.length) {
  7600. groupedChunks.push({ beginChunk: beginChunk,
  7601. endChunk: chunk + 1 });
  7602. }
  7603. prevChunk = chunk;
  7604. }
  7605. return groupedChunks;
  7606. },
  7607. onProgress: function ChunkedStreamManager_onProgress(args) {
  7608. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  7609. args.loaded);
  7610. this.msgHandler.send('DocProgress', {
  7611. loaded: bytesLoaded,
  7612. total: this.length
  7613. });
  7614. },
  7615. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  7616. var chunk = args.chunk;
  7617. var isProgressive = args.begin === undefined;
  7618. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  7619. var end = begin + chunk.byteLength;
  7620. var beginChunk = Math.floor(begin / this.chunkSize);
  7621. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  7622. Math.ceil(end / this.chunkSize);
  7623. if (isProgressive) {
  7624. this.stream.onReceiveProgressiveData(chunk);
  7625. this.progressiveDataLength = end;
  7626. } else {
  7627. this.stream.onReceiveData(begin, chunk);
  7628. }
  7629. if (this.stream.allChunksLoaded()) {
  7630. this._loadedStreamCapability.resolve(this.stream);
  7631. }
  7632. var loadedRequests = [];
  7633. var i, requestId;
  7634. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  7635. // The server might return more chunks than requested
  7636. var requestIds = this.requestsByChunk[chunk] || [];
  7637. delete this.requestsByChunk[chunk];
  7638. for (i = 0; i < requestIds.length; ++i) {
  7639. requestId = requestIds[i];
  7640. var chunksNeeded = this.chunksNeededByRequest[requestId];
  7641. if (chunk in chunksNeeded) {
  7642. delete chunksNeeded[chunk];
  7643. }
  7644. if (!isEmptyObj(chunksNeeded)) {
  7645. continue;
  7646. }
  7647. loadedRequests.push(requestId);
  7648. }
  7649. }
  7650. // If there are no pending requests, automatically fetch the next
  7651. // unfetched chunk of the PDF
  7652. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  7653. var nextEmptyChunk;
  7654. if (this.stream.numChunksLoaded === 1) {
  7655. // This is a special optimization so that after fetching the first
  7656. // chunk, rather than fetching the second chunk, we fetch the last
  7657. // chunk.
  7658. var lastChunk = this.stream.numChunks - 1;
  7659. if (!this.stream.hasChunk(lastChunk)) {
  7660. nextEmptyChunk = lastChunk;
  7661. }
  7662. } else {
  7663. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  7664. }
  7665. if (isInt(nextEmptyChunk)) {
  7666. this.requestChunks([nextEmptyChunk]);
  7667. }
  7668. }
  7669. for (i = 0; i < loadedRequests.length; ++i) {
  7670. requestId = loadedRequests[i];
  7671. var callback = this.callbacksByRequest[requestId];
  7672. delete this.callbacksByRequest[requestId];
  7673. if (callback) {
  7674. callback();
  7675. }
  7676. }
  7677. this.msgHandler.send('DocProgress', {
  7678. loaded: this.stream.numChunksLoaded * this.chunkSize,
  7679. total: this.length
  7680. });
  7681. },
  7682. onError: function ChunkedStreamManager_onError(err) {
  7683. this._loadedStreamCapability.reject(err);
  7684. },
  7685. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  7686. var chunk = Math.floor(begin / this.chunkSize);
  7687. return chunk;
  7688. },
  7689. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  7690. if (end % this.chunkSize === 0) {
  7691. return end / this.chunkSize;
  7692. }
  7693. // 0 -> 0
  7694. // 1 -> 1
  7695. // 99 -> 1
  7696. // 100 -> 1
  7697. // 101 -> 2
  7698. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  7699. return chunk;
  7700. }
  7701. };
  7702. return ChunkedStreamManager;
  7703. })();
  7704. // The maximum number of bytes fetched per range request
  7705. var RANGE_CHUNK_SIZE = 65536;
  7706. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  7707. var BasePdfManager = (function BasePdfManagerClosure() {
  7708. function BasePdfManager() {
  7709. throw new Error('Cannot initialize BaseManagerManager');
  7710. }
  7711. BasePdfManager.prototype = {
  7712. onLoadedStream: function BasePdfManager_onLoadedStream() {
  7713. throw new NotImplementedException();
  7714. },
  7715. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  7716. return this.ensure(this.pdfDocument, prop, args);
  7717. },
  7718. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  7719. return this.ensure(this.pdfDocument.xref, prop, args);
  7720. },
  7721. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  7722. return this.ensure(this.pdfDocument.catalog, prop, args);
  7723. },
  7724. getPage: function BasePdfManager_pagePage(pageIndex) {
  7725. return this.pdfDocument.getPage(pageIndex);
  7726. },
  7727. cleanup: function BasePdfManager_cleanup() {
  7728. return this.pdfDocument.cleanup();
  7729. },
  7730. ensure: function BasePdfManager_ensure(obj, prop, args) {
  7731. return new NotImplementedException();
  7732. },
  7733. requestRange: function BasePdfManager_ensure(begin, end) {
  7734. return new NotImplementedException();
  7735. },
  7736. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  7737. return new NotImplementedException();
  7738. },
  7739. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  7740. return new NotImplementedException();
  7741. },
  7742. updatePassword: function BasePdfManager_updatePassword(password) {
  7743. this.pdfDocument.xref.password = this.password = password;
  7744. if (this._passwordChangedCapability) {
  7745. this._passwordChangedCapability.resolve();
  7746. }
  7747. },
  7748. passwordChanged: function BasePdfManager_passwordChanged() {
  7749. this._passwordChangedCapability = createPromiseCapability();
  7750. return this._passwordChangedCapability.promise;
  7751. },
  7752. terminate: function BasePdfManager_terminate() {
  7753. return new NotImplementedException();
  7754. }
  7755. };
  7756. return BasePdfManager;
  7757. })();
  7758. var LocalPdfManager = (function LocalPdfManagerClosure() {
  7759. function LocalPdfManager(data, password) {
  7760. var stream = new Stream(data);
  7761. this.pdfDocument = new PDFDocument(this, stream, password);
  7762. this._loadedStreamCapability = createPromiseCapability();
  7763. this._loadedStreamCapability.resolve(stream);
  7764. }
  7765. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7766. LocalPdfManager.prototype.constructor = LocalPdfManager;
  7767. LocalPdfManager.prototype.ensure =
  7768. function LocalPdfManager_ensure(obj, prop, args) {
  7769. return new Promise(function (resolve, reject) {
  7770. try {
  7771. var value = obj[prop];
  7772. var result;
  7773. if (typeof value === 'function') {
  7774. result = value.apply(obj, args);
  7775. } else {
  7776. result = value;
  7777. }
  7778. resolve(result);
  7779. } catch (e) {
  7780. reject(e);
  7781. }
  7782. });
  7783. };
  7784. LocalPdfManager.prototype.requestRange =
  7785. function LocalPdfManager_requestRange(begin, end) {
  7786. return Promise.resolve();
  7787. };
  7788. LocalPdfManager.prototype.requestLoadedStream =
  7789. function LocalPdfManager_requestLoadedStream() {
  7790. };
  7791. LocalPdfManager.prototype.onLoadedStream =
  7792. function LocalPdfManager_getLoadedStream() {
  7793. return this._loadedStreamCapability.promise;
  7794. };
  7795. LocalPdfManager.prototype.terminate =
  7796. function LocalPdfManager_terminate() {
  7797. return;
  7798. };
  7799. return LocalPdfManager;
  7800. })();
  7801. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  7802. function NetworkPdfManager(args, msgHandler) {
  7803. this.msgHandler = msgHandler;
  7804. var params = {
  7805. msgHandler: msgHandler,
  7806. httpHeaders: args.httpHeaders,
  7807. withCredentials: args.withCredentials,
  7808. chunkedViewerLoading: args.chunkedViewerLoading,
  7809. disableAutoFetch: args.disableAutoFetch,
  7810. initialData: args.initialData
  7811. };
  7812. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  7813. args.url, params);
  7814. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  7815. args.password);
  7816. }
  7817. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7818. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  7819. NetworkPdfManager.prototype.ensure =
  7820. function NetworkPdfManager_ensure(obj, prop, args) {
  7821. var pdfManager = this;
  7822. return new Promise(function (resolve, reject) {
  7823. function ensureHelper() {
  7824. try {
  7825. var result;
  7826. var value = obj[prop];
  7827. if (typeof value === 'function') {
  7828. result = value.apply(obj, args);
  7829. } else {
  7830. result = value;
  7831. }
  7832. resolve(result);
  7833. } catch(e) {
  7834. if (!(e instanceof MissingDataException)) {
  7835. reject(e);
  7836. return;
  7837. }
  7838. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  7839. }
  7840. }
  7841. ensureHelper();
  7842. });
  7843. };
  7844. NetworkPdfManager.prototype.requestRange =
  7845. function NetworkPdfManager_requestRange(begin, end) {
  7846. return new Promise(function (resolve) {
  7847. this.streamManager.requestRange(begin, end, function() {
  7848. resolve();
  7849. });
  7850. }.bind(this));
  7851. };
  7852. NetworkPdfManager.prototype.requestLoadedStream =
  7853. function NetworkPdfManager_requestLoadedStream() {
  7854. this.streamManager.requestAllChunks();
  7855. };
  7856. NetworkPdfManager.prototype.sendProgressiveData =
  7857. function NetworkPdfManager_sendProgressiveData(chunk) {
  7858. this.streamManager.onReceiveData({ chunk: chunk });
  7859. };
  7860. NetworkPdfManager.prototype.onLoadedStream =
  7861. function NetworkPdfManager_getLoadedStream() {
  7862. return this.streamManager.onLoadedStream();
  7863. };
  7864. NetworkPdfManager.prototype.terminate =
  7865. function NetworkPdfManager_terminate() {
  7866. this.streamManager.networkManager.abortAllRequests();
  7867. };
  7868. return NetworkPdfManager;
  7869. })();
  7870. var Page = (function PageClosure() {
  7871. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  7872. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  7873. this.pdfManager = pdfManager;
  7874. this.pageIndex = pageIndex;
  7875. this.pageDict = pageDict;
  7876. this.xref = xref;
  7877. this.ref = ref;
  7878. this.fontCache = fontCache;
  7879. this.idCounters = {
  7880. obj: 0
  7881. };
  7882. this.resourcesPromise = null;
  7883. }
  7884. Page.prototype = {
  7885. getPageProp: function Page_getPageProp(key) {
  7886. return this.pageDict.get(key);
  7887. },
  7888. getInheritedPageProp: function Page_inheritPageProp(key) {
  7889. var dict = this.pageDict;
  7890. var value = dict.get(key);
  7891. while (value === undefined) {
  7892. dict = dict.get('Parent');
  7893. if (!dict) {
  7894. break;
  7895. }
  7896. value = dict.get(key);
  7897. }
  7898. return value;
  7899. },
  7900. get content() {
  7901. return this.getPageProp('Contents');
  7902. },
  7903. get resources() {
  7904. var value = this.getInheritedPageProp('Resources');
  7905. // For robustness: The spec states that a \Resources entry has to be
  7906. // present, but can be empty. Some document omit it still. In this case
  7907. // return an empty dictionary:
  7908. if (value === undefined) {
  7909. value = Dict.empty;
  7910. }
  7911. return shadow(this, 'resources', value);
  7912. },
  7913. get mediaBox() {
  7914. var obj = this.getInheritedPageProp('MediaBox');
  7915. // Reset invalid media box to letter size.
  7916. if (!isArray(obj) || obj.length !== 4) {
  7917. obj = LETTER_SIZE_MEDIABOX;
  7918. }
  7919. return shadow(this, 'mediaBox', obj);
  7920. },
  7921. get view() {
  7922. var mediaBox = this.mediaBox;
  7923. var cropBox = this.getInheritedPageProp('CropBox');
  7924. if (!isArray(cropBox) || cropBox.length !== 4) {
  7925. return shadow(this, 'view', mediaBox);
  7926. }
  7927. // From the spec, 6th ed., p.963:
  7928. // "The crop, bleed, trim, and art boxes should not ordinarily
  7929. // extend beyond the boundaries of the media box. If they do, they are
  7930. // effectively reduced to their intersection with the media box."
  7931. cropBox = Util.intersect(cropBox, mediaBox);
  7932. if (!cropBox) {
  7933. return shadow(this, 'view', mediaBox);
  7934. }
  7935. return shadow(this, 'view', cropBox);
  7936. },
  7937. get annotationRefs() {
  7938. return shadow(this, 'annotationRefs',
  7939. this.getInheritedPageProp('Annots'));
  7940. },
  7941. get rotate() {
  7942. var rotate = this.getInheritedPageProp('Rotate') || 0;
  7943. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  7944. if (rotate % 90 !== 0) {
  7945. rotate = 0;
  7946. } else if (rotate >= 360) {
  7947. rotate = rotate % 360;
  7948. } else if (rotate < 0) {
  7949. // The spec doesn't cover negatives, assume its counterclockwise
  7950. // rotation. The following is the other implementation of modulo.
  7951. rotate = ((rotate % 360) + 360) % 360;
  7952. }
  7953. return shadow(this, 'rotate', rotate);
  7954. },
  7955. getContentStream: function Page_getContentStream() {
  7956. var content = this.content;
  7957. var stream;
  7958. if (isArray(content)) {
  7959. // fetching items
  7960. var xref = this.xref;
  7961. var i, n = content.length;
  7962. var streams = [];
  7963. for (i = 0; i < n; ++i) {
  7964. streams.push(xref.fetchIfRef(content[i]));
  7965. }
  7966. stream = new StreamsSequenceStream(streams);
  7967. } else if (isStream(content)) {
  7968. stream = content;
  7969. } else {
  7970. // replacing non-existent page content with empty one
  7971. stream = new NullStream();
  7972. }
  7973. return stream;
  7974. },
  7975. loadResources: function Page_loadResources(keys) {
  7976. if (!this.resourcesPromise) {
  7977. // TODO: add async getInheritedPageProp and remove this.
  7978. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  7979. }
  7980. return this.resourcesPromise.then(function resourceSuccess() {
  7981. var objectLoader = new ObjectLoader(this.resources.map,
  7982. keys,
  7983. this.xref);
  7984. return objectLoader.load();
  7985. }.bind(this));
  7986. },
  7987. getOperatorList: function Page_getOperatorList(handler, intent) {
  7988. var self = this;
  7989. var pdfManager = this.pdfManager;
  7990. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  7991. []);
  7992. var resourcesPromise = this.loadResources([
  7993. 'ExtGState',
  7994. 'ColorSpace',
  7995. 'Pattern',
  7996. 'Shading',
  7997. 'XObject',
  7998. 'Font'
  7999. // ProcSet
  8000. // Properties
  8001. ]);
  8002. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  8003. handler, this.pageIndex,
  8004. 'p' + this.pageIndex + '_',
  8005. this.idCounters,
  8006. this.fontCache);
  8007. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  8008. var pageListPromise = dataPromises.then(function(data) {
  8009. var contentStream = data[0];
  8010. var opList = new OperatorList(intent, handler, self.pageIndex);
  8011. handler.send('StartRenderPage', {
  8012. transparency: partialEvaluator.hasBlendModes(self.resources),
  8013. pageIndex: self.pageIndex,
  8014. intent: intent
  8015. });
  8016. return partialEvaluator.getOperatorList(contentStream, self.resources,
  8017. opList).then(function () {
  8018. return opList;
  8019. });
  8020. });
  8021. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  8022. return Promise.all([pageListPromise, annotationsPromise]).then(
  8023. function(datas) {
  8024. var pageOpList = datas[0];
  8025. var annotations = datas[1];
  8026. if (annotations.length === 0) {
  8027. pageOpList.flush(true);
  8028. return pageOpList;
  8029. }
  8030. var annotationsReadyPromise = Annotation.appendToOperatorList(
  8031. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  8032. return annotationsReadyPromise.then(function () {
  8033. pageOpList.flush(true);
  8034. return pageOpList;
  8035. });
  8036. });
  8037. },
  8038. extractTextContent: function Page_extractTextContent() {
  8039. var handler = {
  8040. on: function nullHandlerOn() {},
  8041. send: function nullHandlerSend() {}
  8042. };
  8043. var self = this;
  8044. var pdfManager = this.pdfManager;
  8045. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8046. []);
  8047. var resourcesPromise = this.loadResources([
  8048. 'ExtGState',
  8049. 'XObject',
  8050. 'Font'
  8051. ]);
  8052. var dataPromises = Promise.all([contentStreamPromise,
  8053. resourcesPromise]);
  8054. return dataPromises.then(function(data) {
  8055. var contentStream = data[0];
  8056. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  8057. handler, self.pageIndex,
  8058. 'p' + self.pageIndex + '_',
  8059. self.idCounters,
  8060. self.fontCache);
  8061. return partialEvaluator.getTextContent(contentStream,
  8062. self.resources);
  8063. });
  8064. },
  8065. getAnnotationsData: function Page_getAnnotationsData() {
  8066. var annotations = this.annotations;
  8067. var annotationsData = [];
  8068. for (var i = 0, n = annotations.length; i < n; ++i) {
  8069. annotationsData.push(annotations[i].getData());
  8070. }
  8071. return annotationsData;
  8072. },
  8073. get annotations() {
  8074. var annotations = [];
  8075. var annotationRefs = (this.annotationRefs || []);
  8076. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  8077. var annotationRef = annotationRefs[i];
  8078. var annotation = Annotation.fromRef(this.xref, annotationRef);
  8079. if (annotation) {
  8080. annotations.push(annotation);
  8081. }
  8082. }
  8083. return shadow(this, 'annotations', annotations);
  8084. }
  8085. };
  8086. return Page;
  8087. })();
  8088. /**
  8089. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  8090. * `PDFDoc`, this one doesn't have any job management code.
  8091. * Right now there exists one PDFDocument on the main thread + one object
  8092. * for each worker. If there is no worker support enabled, there are two
  8093. * `PDFDocument` objects on the main thread created.
  8094. */
  8095. var PDFDocument = (function PDFDocumentClosure() {
  8096. var FINGERPRINT_FIRST_BYTES = 1024;
  8097. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  8098. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  8099. function PDFDocument(pdfManager, arg, password) {
  8100. if (isStream(arg)) {
  8101. init.call(this, pdfManager, arg, password);
  8102. } else if (isArrayBuffer(arg)) {
  8103. init.call(this, pdfManager, new Stream(arg), password);
  8104. } else {
  8105. error('PDFDocument: Unknown argument type');
  8106. }
  8107. }
  8108. function init(pdfManager, stream, password) {
  8109. assert(stream.length > 0, 'stream must have data');
  8110. this.pdfManager = pdfManager;
  8111. this.stream = stream;
  8112. var xref = new XRef(this.stream, password, pdfManager);
  8113. this.xref = xref;
  8114. }
  8115. function find(stream, needle, limit, backwards) {
  8116. var pos = stream.pos;
  8117. var end = stream.end;
  8118. var strBuf = [];
  8119. if (pos + limit > end) {
  8120. limit = end - pos;
  8121. }
  8122. for (var n = 0; n < limit; ++n) {
  8123. strBuf.push(String.fromCharCode(stream.getByte()));
  8124. }
  8125. var str = strBuf.join('');
  8126. stream.pos = pos;
  8127. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  8128. if (index === -1) {
  8129. return false; /* not found */
  8130. }
  8131. stream.pos += index;
  8132. return true; /* found */
  8133. }
  8134. var DocumentInfoValidators = {
  8135. get entries() {
  8136. // Lazily build this since all the validation functions below are not
  8137. // defined until after this file loads.
  8138. return shadow(this, 'entries', {
  8139. Title: isString,
  8140. Author: isString,
  8141. Subject: isString,
  8142. Keywords: isString,
  8143. Creator: isString,
  8144. Producer: isString,
  8145. CreationDate: isString,
  8146. ModDate: isString,
  8147. Trapped: isName
  8148. });
  8149. }
  8150. };
  8151. PDFDocument.prototype = {
  8152. parse: function PDFDocument_parse(recoveryMode) {
  8153. this.setup(recoveryMode);
  8154. try {
  8155. // checking if AcroForm is present
  8156. this.acroForm = this.catalog.catDict.get('AcroForm');
  8157. if (this.acroForm) {
  8158. this.xfa = this.acroForm.get('XFA');
  8159. var fields = this.acroForm.get('Fields');
  8160. if ((!fields || !isArray(fields) || fields.length === 0) &&
  8161. !this.xfa) {
  8162. // no fields and no XFA -- not a form (?)
  8163. this.acroForm = null;
  8164. }
  8165. }
  8166. } catch (ex) {
  8167. info('Something wrong with AcroForm entry');
  8168. this.acroForm = null;
  8169. }
  8170. },
  8171. get linearization() {
  8172. var linearization = null;
  8173. if (this.stream.length) {
  8174. try {
  8175. linearization = Linearization.create(this.stream);
  8176. } catch (err) {
  8177. if (err instanceof MissingDataException) {
  8178. throw err;
  8179. }
  8180. info(err);
  8181. }
  8182. }
  8183. // shadow the prototype getter with a data property
  8184. return shadow(this, 'linearization', linearization);
  8185. },
  8186. get startXRef() {
  8187. var stream = this.stream;
  8188. var startXRef = 0;
  8189. var linearization = this.linearization;
  8190. if (linearization) {
  8191. // Find end of first obj.
  8192. stream.reset();
  8193. if (find(stream, 'endobj', 1024)) {
  8194. startXRef = stream.pos + 6;
  8195. }
  8196. } else {
  8197. // Find startxref by jumping backward from the end of the file.
  8198. var step = 1024;
  8199. var found = false, pos = stream.end;
  8200. while (!found && pos > 0) {
  8201. pos -= step - 'startxref'.length;
  8202. if (pos < 0) {
  8203. pos = 0;
  8204. }
  8205. stream.pos = pos;
  8206. found = find(stream, 'startxref', step, true);
  8207. }
  8208. if (found) {
  8209. stream.skip(9);
  8210. var ch;
  8211. do {
  8212. ch = stream.getByte();
  8213. } while (Lexer.isSpace(ch));
  8214. var str = '';
  8215. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  8216. str += String.fromCharCode(ch);
  8217. ch = stream.getByte();
  8218. }
  8219. startXRef = parseInt(str, 10);
  8220. if (isNaN(startXRef)) {
  8221. startXRef = 0;
  8222. }
  8223. }
  8224. }
  8225. // shadow the prototype getter with a data property
  8226. return shadow(this, 'startXRef', startXRef);
  8227. },
  8228. get mainXRefEntriesOffset() {
  8229. var mainXRefEntriesOffset = 0;
  8230. var linearization = this.linearization;
  8231. if (linearization) {
  8232. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  8233. }
  8234. // shadow the prototype getter with a data property
  8235. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  8236. },
  8237. // Find the header, remove leading garbage and setup the stream
  8238. // starting from the header.
  8239. checkHeader: function PDFDocument_checkHeader() {
  8240. var stream = this.stream;
  8241. stream.reset();
  8242. if (find(stream, '%PDF-', 1024)) {
  8243. // Found the header, trim off any garbage before it.
  8244. stream.moveStart();
  8245. // Reading file format version
  8246. var MAX_VERSION_LENGTH = 12;
  8247. var version = '', ch;
  8248. while ((ch = stream.getByte()) > 0x20) { // SPACE
  8249. if (version.length >= MAX_VERSION_LENGTH) {
  8250. break;
  8251. }
  8252. version += String.fromCharCode(ch);
  8253. }
  8254. // removing "%PDF-"-prefix
  8255. this.pdfFormatVersion = version.substring(5);
  8256. return;
  8257. }
  8258. // May not be a PDF file, continue anyway.
  8259. },
  8260. parseStartXRef: function PDFDocument_parseStartXRef() {
  8261. var startXRef = this.startXRef;
  8262. this.xref.setStartXRef(startXRef);
  8263. },
  8264. setup: function PDFDocument_setup(recoveryMode) {
  8265. this.xref.parse(recoveryMode);
  8266. this.catalog = new Catalog(this.pdfManager, this.xref);
  8267. },
  8268. get numPages() {
  8269. var linearization = this.linearization;
  8270. var num = linearization ? linearization.numPages : this.catalog.numPages;
  8271. // shadow the prototype getter
  8272. return shadow(this, 'numPages', num);
  8273. },
  8274. get documentInfo() {
  8275. var docInfo = {
  8276. PDFFormatVersion: this.pdfFormatVersion,
  8277. IsAcroFormPresent: !!this.acroForm,
  8278. IsXFAPresent: !!this.xfa
  8279. };
  8280. var infoDict;
  8281. try {
  8282. infoDict = this.xref.trailer.get('Info');
  8283. } catch (err) {
  8284. info('The document information dictionary is invalid.');
  8285. }
  8286. if (infoDict) {
  8287. var validEntries = DocumentInfoValidators.entries;
  8288. // Only fill the document info with valid entries from the spec.
  8289. for (var key in validEntries) {
  8290. if (infoDict.has(key)) {
  8291. var value = infoDict.get(key);
  8292. // Make sure the value conforms to the spec.
  8293. if (validEntries[key](value)) {
  8294. docInfo[key] = (typeof value !== 'string' ?
  8295. value : stringToPDFString(value));
  8296. } else {
  8297. info('Bad value in document info for "' + key + '"');
  8298. }
  8299. }
  8300. }
  8301. }
  8302. return shadow(this, 'documentInfo', docInfo);
  8303. },
  8304. get fingerprint() {
  8305. var xref = this.xref, idArray, hash, fileID = '';
  8306. if (xref.trailer.has('ID')) {
  8307. idArray = xref.trailer.get('ID');
  8308. }
  8309. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  8310. hash = stringToBytes(idArray[0]);
  8311. } else {
  8312. if (this.stream.ensureRange) {
  8313. this.stream.ensureRange(0,
  8314. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  8315. }
  8316. hash = calculateMD5(this.stream.bytes.subarray(0,
  8317. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  8318. }
  8319. for (var i = 0, n = hash.length; i < n; i++) {
  8320. var hex = hash[i].toString(16);
  8321. fileID += hex.length === 1 ? '0' + hex : hex;
  8322. }
  8323. return shadow(this, 'fingerprint', fileID);
  8324. },
  8325. getPage: function PDFDocument_getPage(pageIndex) {
  8326. return this.catalog.getPage(pageIndex);
  8327. },
  8328. cleanup: function PDFDocument_cleanup() {
  8329. return this.catalog.cleanup();
  8330. }
  8331. };
  8332. return PDFDocument;
  8333. })();
  8334. var Name = (function NameClosure() {
  8335. function Name(name) {
  8336. this.name = name;
  8337. }
  8338. Name.prototype = {};
  8339. var nameCache = {};
  8340. Name.get = function Name_get(name) {
  8341. var nameValue = nameCache[name];
  8342. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  8343. };
  8344. return Name;
  8345. })();
  8346. var Cmd = (function CmdClosure() {
  8347. function Cmd(cmd) {
  8348. this.cmd = cmd;
  8349. }
  8350. Cmd.prototype = {};
  8351. var cmdCache = {};
  8352. Cmd.get = function Cmd_get(cmd) {
  8353. var cmdValue = cmdCache[cmd];
  8354. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  8355. };
  8356. return Cmd;
  8357. })();
  8358. var Dict = (function DictClosure() {
  8359. var nonSerializable = function nonSerializableClosure() {
  8360. return nonSerializable; // creating closure on some variable
  8361. };
  8362. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  8363. 'Background': true,
  8364. 'ExtGState': true,
  8365. 'Halftone': true,
  8366. 'Layout': true,
  8367. 'Mask': true,
  8368. 'Pagination': true,
  8369. 'Printing': true
  8370. };
  8371. function isRecursionAllowedFor(dict) {
  8372. if (!isName(dict.Type)) {
  8373. return true;
  8374. }
  8375. var dictType = dict.Type.name;
  8376. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  8377. }
  8378. // xref is optional
  8379. function Dict(xref) {
  8380. // Map should only be used internally, use functions below to access.
  8381. this.map = Object.create(null);
  8382. this.xref = xref;
  8383. this.objId = null;
  8384. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8385. }
  8386. Dict.prototype = {
  8387. assignXref: function Dict_assignXref(newXref) {
  8388. this.xref = newXref;
  8389. },
  8390. // automatically dereferences Ref objects
  8391. get: function Dict_get(key1, key2, key3) {
  8392. var value;
  8393. var xref = this.xref;
  8394. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8395. typeof key2 === 'undefined') {
  8396. return xref ? xref.fetchIfRef(value) : value;
  8397. }
  8398. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8399. typeof key3 === 'undefined') {
  8400. return xref ? xref.fetchIfRef(value) : value;
  8401. }
  8402. value = this.map[key3] || null;
  8403. return xref ? xref.fetchIfRef(value) : value;
  8404. },
  8405. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8406. getAsync: function Dict_getAsync(key1, key2, key3) {
  8407. var value;
  8408. var xref = this.xref;
  8409. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8410. typeof key2 === 'undefined') {
  8411. if (xref) {
  8412. return xref.fetchIfRefAsync(value);
  8413. }
  8414. return Promise.resolve(value);
  8415. }
  8416. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8417. typeof key3 === 'undefined') {
  8418. if (xref) {
  8419. return xref.fetchIfRefAsync(value);
  8420. }
  8421. return Promise.resolve(value);
  8422. }
  8423. value = this.map[key3] || null;
  8424. if (xref) {
  8425. return xref.fetchIfRefAsync(value);
  8426. }
  8427. return Promise.resolve(value);
  8428. },
  8429. // no dereferencing
  8430. getRaw: function Dict_getRaw(key) {
  8431. return this.map[key];
  8432. },
  8433. // creates new map and dereferences all Refs
  8434. getAll: function Dict_getAll() {
  8435. var all = Object.create(null);
  8436. var queue = null;
  8437. var key, obj;
  8438. for (key in this.map) {
  8439. obj = this.get(key);
  8440. if (obj instanceof Dict) {
  8441. if (isRecursionAllowedFor(obj)) {
  8442. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8443. } else {
  8444. all[key] = this.getRaw(key);
  8445. }
  8446. } else {
  8447. all[key] = obj;
  8448. }
  8449. }
  8450. if (!queue) {
  8451. return all;
  8452. }
  8453. // trying to take cyclic references into the account
  8454. var processed = Object.create(null);
  8455. while (queue.length > 0) {
  8456. var item = queue.shift();
  8457. var itemObj = item.obj;
  8458. var objId = itemObj.objId;
  8459. if (objId && objId in processed) {
  8460. item.target[item.key] = processed[objId];
  8461. continue;
  8462. }
  8463. var dereferenced = Object.create(null);
  8464. for (key in itemObj.map) {
  8465. obj = itemObj.get(key);
  8466. if (obj instanceof Dict) {
  8467. if (isRecursionAllowedFor(obj)) {
  8468. queue.push({target: dereferenced, key: key, obj: obj});
  8469. } else {
  8470. dereferenced[key] = itemObj.getRaw(key);
  8471. }
  8472. } else {
  8473. dereferenced[key] = obj;
  8474. }
  8475. }
  8476. if (objId) {
  8477. processed[objId] = dereferenced;
  8478. }
  8479. item.target[item.key] = dereferenced;
  8480. }
  8481. return all;
  8482. },
  8483. set: function Dict_set(key, value) {
  8484. this.map[key] = value;
  8485. },
  8486. has: function Dict_has(key) {
  8487. return key in this.map;
  8488. },
  8489. forEach: function Dict_forEach(callback) {
  8490. for (var key in this.map) {
  8491. callback(key, this.get(key));
  8492. }
  8493. }
  8494. };
  8495. Dict.empty = new Dict(null);
  8496. return Dict;
  8497. })();
  8498. var Ref = (function RefClosure() {
  8499. function Ref(num, gen) {
  8500. this.num = num;
  8501. this.gen = gen;
  8502. }
  8503. Ref.prototype = {
  8504. toString: function Ref_toString() {
  8505. // This function is hot, so we make the string as compact as possible.
  8506. // |this.gen| is almost always zero, so we treat that case specially.
  8507. var str = this.num + 'R';
  8508. if (this.gen !== 0) {
  8509. str += this.gen;
  8510. }
  8511. return str;
  8512. }
  8513. };
  8514. return Ref;
  8515. })();
  8516. // The reference is identified by number and generation.
  8517. // This structure stores only one instance of the reference.
  8518. var RefSet = (function RefSetClosure() {
  8519. function RefSet() {
  8520. this.dict = {};
  8521. }
  8522. RefSet.prototype = {
  8523. has: function RefSet_has(ref) {
  8524. return ref.toString() in this.dict;
  8525. },
  8526. put: function RefSet_put(ref) {
  8527. this.dict[ref.toString()] = true;
  8528. },
  8529. remove: function RefSet_remove(ref) {
  8530. delete this.dict[ref.toString()];
  8531. }
  8532. };
  8533. return RefSet;
  8534. })();
  8535. var RefSetCache = (function RefSetCacheClosure() {
  8536. function RefSetCache() {
  8537. this.dict = Object.create(null);
  8538. }
  8539. RefSetCache.prototype = {
  8540. get: function RefSetCache_get(ref) {
  8541. return this.dict[ref.toString()];
  8542. },
  8543. has: function RefSetCache_has(ref) {
  8544. return ref.toString() in this.dict;
  8545. },
  8546. put: function RefSetCache_put(ref, obj) {
  8547. this.dict[ref.toString()] = obj;
  8548. },
  8549. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  8550. this.dict[ref.toString()] = this.get(aliasRef);
  8551. },
  8552. forEach: function RefSetCache_forEach(fn, thisArg) {
  8553. for (var i in this.dict) {
  8554. fn.call(thisArg, this.dict[i]);
  8555. }
  8556. },
  8557. clear: function RefSetCache_clear() {
  8558. this.dict = Object.create(null);
  8559. }
  8560. };
  8561. return RefSetCache;
  8562. })();
  8563. var Catalog = (function CatalogClosure() {
  8564. function Catalog(pdfManager, xref) {
  8565. this.pdfManager = pdfManager;
  8566. this.xref = xref;
  8567. this.catDict = xref.getCatalogObj();
  8568. this.fontCache = new RefSetCache();
  8569. assert(isDict(this.catDict),
  8570. 'catalog object is not a dictionary');
  8571. this.pagePromises = [];
  8572. }
  8573. Catalog.prototype = {
  8574. get metadata() {
  8575. var streamRef = this.catDict.getRaw('Metadata');
  8576. if (!isRef(streamRef)) {
  8577. return shadow(this, 'metadata', null);
  8578. }
  8579. var encryptMetadata = (!this.xref.encrypt ? false :
  8580. this.xref.encrypt.encryptMetadata);
  8581. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  8582. var metadata;
  8583. if (stream && isDict(stream.dict)) {
  8584. var type = stream.dict.get('Type');
  8585. var subtype = stream.dict.get('Subtype');
  8586. if (isName(type) && isName(subtype) &&
  8587. type.name === 'Metadata' && subtype.name === 'XML') {
  8588. // XXX: This should examine the charset the XML document defines,
  8589. // however since there are currently no real means to decode
  8590. // arbitrary charsets, let's just hope that the author of the PDF
  8591. // was reasonable enough to stick with the XML default charset,
  8592. // which is UTF-8.
  8593. try {
  8594. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  8595. } catch (e) {
  8596. info('Skipping invalid metadata.');
  8597. }
  8598. }
  8599. }
  8600. return shadow(this, 'metadata', metadata);
  8601. },
  8602. get toplevelPagesDict() {
  8603. var pagesObj = this.catDict.get('Pages');
  8604. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  8605. // shadow the prototype getter
  8606. return shadow(this, 'toplevelPagesDict', pagesObj);
  8607. },
  8608. get documentOutline() {
  8609. var obj = null;
  8610. try {
  8611. obj = this.readDocumentOutline();
  8612. } catch (ex) {
  8613. if (ex instanceof MissingDataException) {
  8614. throw ex;
  8615. }
  8616. warn('Unable to read document outline');
  8617. }
  8618. return shadow(this, 'documentOutline', obj);
  8619. },
  8620. readDocumentOutline: function Catalog_readDocumentOutline() {
  8621. var xref = this.xref;
  8622. var obj = this.catDict.get('Outlines');
  8623. var root = { items: [] };
  8624. if (isDict(obj)) {
  8625. obj = obj.getRaw('First');
  8626. var processed = new RefSet();
  8627. if (isRef(obj)) {
  8628. var queue = [{obj: obj, parent: root}];
  8629. // to avoid recursion keeping track of the items
  8630. // in the processed dictionary
  8631. processed.put(obj);
  8632. while (queue.length > 0) {
  8633. var i = queue.shift();
  8634. var outlineDict = xref.fetchIfRef(i.obj);
  8635. if (outlineDict === null) {
  8636. continue;
  8637. }
  8638. if (!outlineDict.has('Title')) {
  8639. error('Invalid outline item');
  8640. }
  8641. var dest = outlineDict.get('A');
  8642. if (dest) {
  8643. dest = dest.get('D');
  8644. } else if (outlineDict.has('Dest')) {
  8645. dest = outlineDict.getRaw('Dest');
  8646. if (isName(dest)) {
  8647. dest = dest.name;
  8648. }
  8649. }
  8650. var title = outlineDict.get('Title');
  8651. var outlineItem = {
  8652. dest: dest,
  8653. title: stringToPDFString(title),
  8654. color: outlineDict.get('C') || [0, 0, 0],
  8655. count: outlineDict.get('Count'),
  8656. bold: !!(outlineDict.get('F') & 2),
  8657. italic: !!(outlineDict.get('F') & 1),
  8658. items: []
  8659. };
  8660. i.parent.items.push(outlineItem);
  8661. obj = outlineDict.getRaw('First');
  8662. if (isRef(obj) && !processed.has(obj)) {
  8663. queue.push({obj: obj, parent: outlineItem});
  8664. processed.put(obj);
  8665. }
  8666. obj = outlineDict.getRaw('Next');
  8667. if (isRef(obj) && !processed.has(obj)) {
  8668. queue.push({obj: obj, parent: i.parent});
  8669. processed.put(obj);
  8670. }
  8671. }
  8672. }
  8673. }
  8674. return (root.items.length > 0 ? root.items : null);
  8675. },
  8676. get numPages() {
  8677. var obj = this.toplevelPagesDict.get('Count');
  8678. assert(
  8679. isInt(obj),
  8680. 'page count in top level pages object is not an integer'
  8681. );
  8682. // shadow the prototype getter
  8683. return shadow(this, 'num', obj);
  8684. },
  8685. get destinations() {
  8686. function fetchDestination(dest) {
  8687. return isDict(dest) ? dest.get('D') : dest;
  8688. }
  8689. var xref = this.xref;
  8690. var dests = {}, nameTreeRef, nameDictionaryRef;
  8691. var obj = this.catDict.get('Names');
  8692. if (obj && obj.has('Dests')) {
  8693. nameTreeRef = obj.getRaw('Dests');
  8694. } else if (this.catDict.has('Dests')) {
  8695. nameDictionaryRef = this.catDict.get('Dests');
  8696. }
  8697. if (nameDictionaryRef) {
  8698. // reading simple destination dictionary
  8699. obj = nameDictionaryRef;
  8700. obj.forEach(function catalogForEach(key, value) {
  8701. if (!value) {
  8702. return;
  8703. }
  8704. dests[key] = fetchDestination(value);
  8705. });
  8706. }
  8707. if (nameTreeRef) {
  8708. var nameTree = new NameTree(nameTreeRef, xref);
  8709. var names = nameTree.getAll();
  8710. for (var name in names) {
  8711. if (!names.hasOwnProperty(name)) {
  8712. continue;
  8713. }
  8714. dests[name] = fetchDestination(names[name]);
  8715. }
  8716. }
  8717. return shadow(this, 'destinations', dests);
  8718. },
  8719. getDestination: function Catalog_getDestination(destinationId) {
  8720. function fetchDestination(dest) {
  8721. return isDict(dest) ? dest.get('D') : dest;
  8722. }
  8723. var xref = this.xref;
  8724. var dest, nameTreeRef, nameDictionaryRef;
  8725. var obj = this.catDict.get('Names');
  8726. if (obj && obj.has('Dests')) {
  8727. nameTreeRef = obj.getRaw('Dests');
  8728. } else if (this.catDict.has('Dests')) {
  8729. nameDictionaryRef = this.catDict.get('Dests');
  8730. }
  8731. if (nameDictionaryRef) {
  8732. // reading simple destination dictionary
  8733. obj = nameDictionaryRef;
  8734. obj.forEach(function catalogForEach(key, value) {
  8735. if (!value) {
  8736. return;
  8737. }
  8738. if (key === destinationId) {
  8739. dest = fetchDestination(value);
  8740. }
  8741. });
  8742. }
  8743. if (nameTreeRef) {
  8744. var nameTree = new NameTree(nameTreeRef, xref);
  8745. dest = fetchDestination(nameTree.get(destinationId));
  8746. }
  8747. return dest;
  8748. },
  8749. get attachments() {
  8750. var xref = this.xref;
  8751. var attachments = null, nameTreeRef;
  8752. var obj = this.catDict.get('Names');
  8753. if (obj) {
  8754. nameTreeRef = obj.getRaw('EmbeddedFiles');
  8755. }
  8756. if (nameTreeRef) {
  8757. var nameTree = new NameTree(nameTreeRef, xref);
  8758. var names = nameTree.getAll();
  8759. for (var name in names) {
  8760. if (!names.hasOwnProperty(name)) {
  8761. continue;
  8762. }
  8763. var fs = new FileSpec(names[name], xref);
  8764. if (!attachments) {
  8765. attachments = {};
  8766. }
  8767. attachments[stringToPDFString(name)] = fs.serializable;
  8768. }
  8769. }
  8770. return shadow(this, 'attachments', attachments);
  8771. },
  8772. get javaScript() {
  8773. var xref = this.xref;
  8774. var obj = this.catDict.get('Names');
  8775. var javaScript = [];
  8776. if (obj && obj.has('JavaScript')) {
  8777. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  8778. var names = nameTree.getAll();
  8779. for (var name in names) {
  8780. if (!names.hasOwnProperty(name)) {
  8781. continue;
  8782. }
  8783. // We don't really use the JavaScript right now. This code is
  8784. // defensive so we don't cause errors on document load.
  8785. var jsDict = names[name];
  8786. if (!isDict(jsDict)) {
  8787. continue;
  8788. }
  8789. var type = jsDict.get('S');
  8790. if (!isName(type) || type.name !== 'JavaScript') {
  8791. continue;
  8792. }
  8793. var js = jsDict.get('JS');
  8794. if (!isString(js) && !isStream(js)) {
  8795. continue;
  8796. }
  8797. if (isStream(js)) {
  8798. js = bytesToString(js.getBytes());
  8799. }
  8800. javaScript.push(stringToPDFString(js));
  8801. }
  8802. }
  8803. // Append OpenAction actions to javaScript array
  8804. var openactionDict = this.catDict.get('OpenAction');
  8805. if (isDict(openactionDict)) {
  8806. var objType = openactionDict.get('Type');
  8807. var actionType = openactionDict.get('S');
  8808. var action = openactionDict.get('N');
  8809. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  8810. isName(actionType) && actionType.name === 'Named' &&
  8811. isName(action) && action.name === 'Print');
  8812. if (isPrintAction) {
  8813. javaScript.push('print(true);');
  8814. }
  8815. }
  8816. return shadow(this, 'javaScript', javaScript);
  8817. },
  8818. cleanup: function Catalog_cleanup() {
  8819. var promises = [];
  8820. this.fontCache.forEach(function (promise) {
  8821. promises.push(promise);
  8822. });
  8823. return Promise.all(promises).then(function (translatedFonts) {
  8824. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  8825. var font = translatedFonts[i].dict;
  8826. delete font.translated;
  8827. }
  8828. this.fontCache.clear();
  8829. }.bind(this));
  8830. },
  8831. getPage: function Catalog_getPage(pageIndex) {
  8832. if (!(pageIndex in this.pagePromises)) {
  8833. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  8834. function (a) {
  8835. var dict = a[0];
  8836. var ref = a[1];
  8837. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  8838. this.fontCache);
  8839. }.bind(this)
  8840. );
  8841. }
  8842. return this.pagePromises[pageIndex];
  8843. },
  8844. getPageDict: function Catalog_getPageDict(pageIndex) {
  8845. var capability = createPromiseCapability();
  8846. var nodesToVisit = [this.catDict.getRaw('Pages')];
  8847. var currentPageIndex = 0;
  8848. var xref = this.xref;
  8849. function next() {
  8850. while (nodesToVisit.length) {
  8851. var currentNode = nodesToVisit.pop();
  8852. if (isRef(currentNode)) {
  8853. xref.fetchAsync(currentNode).then(function (obj) {
  8854. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  8855. if (pageIndex === currentPageIndex) {
  8856. capability.resolve([obj, currentNode]);
  8857. } else {
  8858. currentPageIndex++;
  8859. next();
  8860. }
  8861. return;
  8862. }
  8863. nodesToVisit.push(obj);
  8864. next();
  8865. }, capability.reject);
  8866. return;
  8867. }
  8868. // must be a child page dictionary
  8869. assert(
  8870. isDict(currentNode),
  8871. 'page dictionary kid reference points to wrong type of object'
  8872. );
  8873. var count = currentNode.get('Count');
  8874. // Skip nodes where the page can't be.
  8875. if (currentPageIndex + count <= pageIndex) {
  8876. currentPageIndex += count;
  8877. continue;
  8878. }
  8879. var kids = currentNode.get('Kids');
  8880. assert(isArray(kids), 'page dictionary kids object is not an array');
  8881. if (count === kids.length) {
  8882. // Nodes that don't have the page have been skipped and this is the
  8883. // bottom of the tree which means the page requested must be a
  8884. // descendant of this pages node. Ideally we would just resolve the
  8885. // promise with the page ref here, but there is the case where more
  8886. // pages nodes could link to single a page (see issue 3666 pdf). To
  8887. // handle this push it back on the queue so if it is a pages node it
  8888. // will be descended into.
  8889. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  8890. currentPageIndex = pageIndex;
  8891. continue;
  8892. } else {
  8893. for (var last = kids.length - 1; last >= 0; last--) {
  8894. nodesToVisit.push(kids[last]);
  8895. }
  8896. }
  8897. }
  8898. capability.reject('Page index ' + pageIndex + ' not found.');
  8899. }
  8900. next();
  8901. return capability.promise;
  8902. },
  8903. getPageIndex: function Catalog_getPageIndex(ref) {
  8904. // The page tree nodes have the count of all the leaves below them. To get
  8905. // how many pages are before we just have to walk up the tree and keep
  8906. // adding the count of siblings to the left of the node.
  8907. var xref = this.xref;
  8908. function pagesBeforeRef(kidRef) {
  8909. var total = 0;
  8910. var parentRef;
  8911. return xref.fetchAsync(kidRef).then(function (node) {
  8912. if (!node) {
  8913. return null;
  8914. }
  8915. parentRef = node.getRaw('Parent');
  8916. return node.getAsync('Parent');
  8917. }).then(function (parent) {
  8918. if (!parent) {
  8919. return null;
  8920. }
  8921. return parent.getAsync('Kids');
  8922. }).then(function (kids) {
  8923. if (!kids) {
  8924. return null;
  8925. }
  8926. var kidPromises = [];
  8927. var found = false;
  8928. for (var i = 0; i < kids.length; i++) {
  8929. var kid = kids[i];
  8930. assert(isRef(kid), 'kids must be a ref');
  8931. if (kid.num === kidRef.num) {
  8932. found = true;
  8933. break;
  8934. }
  8935. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  8936. if (kid.has('Count')) {
  8937. var count = kid.get('Count');
  8938. total += count;
  8939. } else { // page leaf node
  8940. total++;
  8941. }
  8942. }));
  8943. }
  8944. if (!found) {
  8945. error('kid ref not found in parents kids');
  8946. }
  8947. return Promise.all(kidPromises).then(function () {
  8948. return [total, parentRef];
  8949. });
  8950. });
  8951. }
  8952. var total = 0;
  8953. function next(ref) {
  8954. return pagesBeforeRef(ref).then(function (args) {
  8955. if (!args) {
  8956. return total;
  8957. }
  8958. var count = args[0];
  8959. var parentRef = args[1];
  8960. total += count;
  8961. return next(parentRef);
  8962. });
  8963. }
  8964. return next(ref);
  8965. }
  8966. };
  8967. return Catalog;
  8968. })();
  8969. var XRef = (function XRefClosure() {
  8970. function XRef(stream, password) {
  8971. this.stream = stream;
  8972. this.entries = [];
  8973. this.xrefstms = {};
  8974. // prepare the XRef cache
  8975. this.cache = [];
  8976. this.password = password;
  8977. this.stats = {
  8978. streamTypes: [],
  8979. fontTypes: []
  8980. };
  8981. }
  8982. XRef.prototype = {
  8983. setStartXRef: function XRef_setStartXRef(startXRef) {
  8984. // Store the starting positions of xref tables as we process them
  8985. // so we can recover from missing data errors
  8986. this.startXRefQueue = [startXRef];
  8987. },
  8988. parse: function XRef_parse(recoveryMode) {
  8989. var trailerDict;
  8990. if (!recoveryMode) {
  8991. trailerDict = this.readXRef();
  8992. } else {
  8993. warn('Indexing all PDF objects');
  8994. trailerDict = this.indexObjects();
  8995. }
  8996. trailerDict.assignXref(this);
  8997. this.trailer = trailerDict;
  8998. var encrypt = trailerDict.get('Encrypt');
  8999. if (encrypt) {
  9000. var ids = trailerDict.get('ID');
  9001. var fileId = (ids && ids.length) ? ids[0] : '';
  9002. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  9003. this.password);
  9004. }
  9005. // get the root dictionary (catalog) object
  9006. if (!(this.root = trailerDict.get('Root'))) {
  9007. error('Invalid root reference');
  9008. }
  9009. },
  9010. processXRefTable: function XRef_processXRefTable(parser) {
  9011. if (!('tableState' in this)) {
  9012. // Stores state of the table as we process it so we can resume
  9013. // from middle of table in case of missing data error
  9014. this.tableState = {
  9015. entryNum: 0,
  9016. streamPos: parser.lexer.stream.pos,
  9017. parserBuf1: parser.buf1,
  9018. parserBuf2: parser.buf2
  9019. };
  9020. }
  9021. var obj = this.readXRefTable(parser);
  9022. // Sanity check
  9023. if (!isCmd(obj, 'trailer')) {
  9024. error('Invalid XRef table: could not find trailer dictionary');
  9025. }
  9026. // Read trailer dictionary, e.g.
  9027. // trailer
  9028. // << /Size 22
  9029. // /Root 20R
  9030. // /Info 10R
  9031. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  9032. // >>
  9033. // The parser goes through the entire stream << ... >> and provides
  9034. // a getter interface for the key-value table
  9035. var dict = parser.getObj();
  9036. // The pdflib PDF generator can generate a nested trailer dictionary
  9037. if (!isDict(dict) && dict.dict) {
  9038. dict = dict.dict;
  9039. }
  9040. if (!isDict(dict)) {
  9041. error('Invalid XRef table: could not parse trailer dictionary');
  9042. }
  9043. delete this.tableState;
  9044. return dict;
  9045. },
  9046. readXRefTable: function XRef_readXRefTable(parser) {
  9047. // Example of cross-reference table:
  9048. // xref
  9049. // 0 1 <-- subsection header (first obj #, obj count)
  9050. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  9051. // 23 2 <-- subsection header ... and so on ...
  9052. // 0000025518 00002 n
  9053. // 0000025635 00000 n
  9054. // trailer
  9055. // ...
  9056. var stream = parser.lexer.stream;
  9057. var tableState = this.tableState;
  9058. stream.pos = tableState.streamPos;
  9059. parser.buf1 = tableState.parserBuf1;
  9060. parser.buf2 = tableState.parserBuf2;
  9061. // Outer loop is over subsection headers
  9062. var obj;
  9063. while (true) {
  9064. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  9065. if (isCmd(obj = parser.getObj(), 'trailer')) {
  9066. break;
  9067. }
  9068. tableState.firstEntryNum = obj;
  9069. tableState.entryCount = parser.getObj();
  9070. }
  9071. var first = tableState.firstEntryNum;
  9072. var count = tableState.entryCount;
  9073. if (!isInt(first) || !isInt(count)) {
  9074. error('Invalid XRef table: wrong types in subsection header');
  9075. }
  9076. // Inner loop is over objects themselves
  9077. for (var i = tableState.entryNum; i < count; i++) {
  9078. tableState.streamPos = stream.pos;
  9079. tableState.entryNum = i;
  9080. tableState.parserBuf1 = parser.buf1;
  9081. tableState.parserBuf2 = parser.buf2;
  9082. var entry = {};
  9083. entry.offset = parser.getObj();
  9084. entry.gen = parser.getObj();
  9085. var type = parser.getObj();
  9086. if (isCmd(type, 'f')) {
  9087. entry.free = true;
  9088. } else if (isCmd(type, 'n')) {
  9089. entry.uncompressed = true;
  9090. }
  9091. // Validate entry obj
  9092. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  9093. !(entry.free || entry.uncompressed)) {
  9094. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  9095. }
  9096. if (!this.entries[i + first]) {
  9097. this.entries[i + first] = entry;
  9098. }
  9099. }
  9100. tableState.entryNum = 0;
  9101. tableState.streamPos = stream.pos;
  9102. tableState.parserBuf1 = parser.buf1;
  9103. tableState.parserBuf2 = parser.buf2;
  9104. delete tableState.firstEntryNum;
  9105. delete tableState.entryCount;
  9106. }
  9107. // Per issue 3248: hp scanners generate bad XRef
  9108. if (first === 1 && this.entries[1] && this.entries[1].free) {
  9109. // shifting the entries
  9110. this.entries.shift();
  9111. }
  9112. // Sanity check: as per spec, first object must be free
  9113. if (this.entries[0] && !this.entries[0].free) {
  9114. error('Invalid XRef table: unexpected first object');
  9115. }
  9116. return obj;
  9117. },
  9118. processXRefStream: function XRef_processXRefStream(stream) {
  9119. if (!('streamState' in this)) {
  9120. // Stores state of the stream as we process it so we can resume
  9121. // from middle of stream in case of missing data error
  9122. var streamParameters = stream.dict;
  9123. var byteWidths = streamParameters.get('W');
  9124. var range = streamParameters.get('Index');
  9125. if (!range) {
  9126. range = [0, streamParameters.get('Size')];
  9127. }
  9128. this.streamState = {
  9129. entryRanges: range,
  9130. byteWidths: byteWidths,
  9131. entryNum: 0,
  9132. streamPos: stream.pos
  9133. };
  9134. }
  9135. this.readXRefStream(stream);
  9136. delete this.streamState;
  9137. return stream.dict;
  9138. },
  9139. readXRefStream: function XRef_readXRefStream(stream) {
  9140. var i, j;
  9141. var streamState = this.streamState;
  9142. stream.pos = streamState.streamPos;
  9143. var byteWidths = streamState.byteWidths;
  9144. var typeFieldWidth = byteWidths[0];
  9145. var offsetFieldWidth = byteWidths[1];
  9146. var generationFieldWidth = byteWidths[2];
  9147. var entryRanges = streamState.entryRanges;
  9148. while (entryRanges.length > 0) {
  9149. var first = entryRanges[0];
  9150. var n = entryRanges[1];
  9151. if (!isInt(first) || !isInt(n)) {
  9152. error('Invalid XRef range fields: ' + first + ', ' + n);
  9153. }
  9154. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  9155. !isInt(generationFieldWidth)) {
  9156. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  9157. }
  9158. for (i = streamState.entryNum; i < n; ++i) {
  9159. streamState.entryNum = i;
  9160. streamState.streamPos = stream.pos;
  9161. var type = 0, offset = 0, generation = 0;
  9162. for (j = 0; j < typeFieldWidth; ++j) {
  9163. type = (type << 8) | stream.getByte();
  9164. }
  9165. // if type field is absent, its default value is 1
  9166. if (typeFieldWidth === 0) {
  9167. type = 1;
  9168. }
  9169. for (j = 0; j < offsetFieldWidth; ++j) {
  9170. offset = (offset << 8) | stream.getByte();
  9171. }
  9172. for (j = 0; j < generationFieldWidth; ++j) {
  9173. generation = (generation << 8) | stream.getByte();
  9174. }
  9175. var entry = {};
  9176. entry.offset = offset;
  9177. entry.gen = generation;
  9178. switch (type) {
  9179. case 0:
  9180. entry.free = true;
  9181. break;
  9182. case 1:
  9183. entry.uncompressed = true;
  9184. break;
  9185. case 2:
  9186. break;
  9187. default:
  9188. error('Invalid XRef entry type: ' + type);
  9189. }
  9190. if (!this.entries[first + i]) {
  9191. this.entries[first + i] = entry;
  9192. }
  9193. }
  9194. streamState.entryNum = 0;
  9195. streamState.streamPos = stream.pos;
  9196. entryRanges.splice(0, 2);
  9197. }
  9198. },
  9199. indexObjects: function XRef_indexObjects() {
  9200. // Simple scan through the PDF content to find objects,
  9201. // trailers and XRef streams.
  9202. function readToken(data, offset) {
  9203. var token = '', ch = data[offset];
  9204. while (ch !== 13 && ch !== 10) {
  9205. if (++offset >= data.length) {
  9206. break;
  9207. }
  9208. token += String.fromCharCode(ch);
  9209. ch = data[offset];
  9210. }
  9211. return token;
  9212. }
  9213. function skipUntil(data, offset, what) {
  9214. var length = what.length, dataLength = data.length;
  9215. var skipped = 0;
  9216. // finding byte sequence
  9217. while (offset < dataLength) {
  9218. var i = 0;
  9219. while (i < length && data[offset + i] === what[i]) {
  9220. ++i;
  9221. }
  9222. if (i >= length) {
  9223. break; // sequence found
  9224. }
  9225. offset++;
  9226. skipped++;
  9227. }
  9228. return skipped;
  9229. }
  9230. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  9231. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  9232. 101, 102]);
  9233. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  9234. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  9235. var stream = this.stream;
  9236. stream.pos = 0;
  9237. var buffer = stream.getBytes();
  9238. var position = stream.start, length = buffer.length;
  9239. var trailers = [], xrefStms = [];
  9240. while (position < length) {
  9241. var ch = buffer[position];
  9242. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  9243. ++position;
  9244. continue;
  9245. }
  9246. if (ch === 37) { // %-comment
  9247. do {
  9248. ++position;
  9249. if (position >= length) {
  9250. break;
  9251. }
  9252. ch = buffer[position];
  9253. } while (ch !== 13 && ch !== 10);
  9254. continue;
  9255. }
  9256. var token = readToken(buffer, position);
  9257. var m;
  9258. if (token === 'xref') {
  9259. position += skipUntil(buffer, position, trailerBytes);
  9260. trailers.push(position);
  9261. position += skipUntil(buffer, position, startxrefBytes);
  9262. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  9263. this.entries[m[1]] = {
  9264. offset: position,
  9265. gen: m[2] | 0,
  9266. uncompressed: true
  9267. };
  9268. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  9269. var content = buffer.subarray(position, position + contentLength);
  9270. // checking XRef stream suspect
  9271. // (it shall have '/XRef' and next char is not a letter)
  9272. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  9273. if (xrefTagOffset < contentLength &&
  9274. content[xrefTagOffset + 5] < 64) {
  9275. xrefStms.push(position);
  9276. this.xrefstms[position] = 1; // don't read it recursively
  9277. }
  9278. position += contentLength;
  9279. } else {
  9280. position += token.length + 1;
  9281. }
  9282. }
  9283. // reading XRef streams
  9284. var i, ii;
  9285. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  9286. this.startXRefQueue.push(xrefStms[i]);
  9287. this.readXRef(/* recoveryMode */ true);
  9288. }
  9289. // finding main trailer
  9290. var dict;
  9291. for (i = 0, ii = trailers.length; i < ii; ++i) {
  9292. stream.pos = trailers[i];
  9293. var parser = new Parser(new Lexer(stream), true, this);
  9294. var obj = parser.getObj();
  9295. if (!isCmd(obj, 'trailer')) {
  9296. continue;
  9297. }
  9298. // read the trailer dictionary
  9299. if (!isDict(dict = parser.getObj())) {
  9300. continue;
  9301. }
  9302. // taking the first one with 'ID'
  9303. if (dict.has('ID')) {
  9304. return dict;
  9305. }
  9306. }
  9307. // no tailer with 'ID', taking last one (if exists)
  9308. if (dict) {
  9309. return dict;
  9310. }
  9311. // nothing helps
  9312. // calling error() would reject worker with an UnknownErrorException.
  9313. throw new InvalidPDFException('Invalid PDF structure');
  9314. },
  9315. readXRef: function XRef_readXRef(recoveryMode) {
  9316. var stream = this.stream;
  9317. try {
  9318. while (this.startXRefQueue.length) {
  9319. var startXRef = this.startXRefQueue[0];
  9320. stream.pos = startXRef + stream.start;
  9321. var parser = new Parser(new Lexer(stream), true, this);
  9322. var obj = parser.getObj();
  9323. var dict;
  9324. // Get dictionary
  9325. if (isCmd(obj, 'xref')) {
  9326. // Parse end-of-file XRef
  9327. dict = this.processXRefTable(parser);
  9328. if (!this.topDict) {
  9329. this.topDict = dict;
  9330. }
  9331. // Recursively get other XRefs 'XRefStm', if any
  9332. obj = dict.get('XRefStm');
  9333. if (isInt(obj)) {
  9334. var pos = obj;
  9335. // ignore previously loaded xref streams
  9336. // (possible infinite recursion)
  9337. if (!(pos in this.xrefstms)) {
  9338. this.xrefstms[pos] = 1;
  9339. this.startXRefQueue.push(pos);
  9340. }
  9341. }
  9342. } else if (isInt(obj)) {
  9343. // Parse in-stream XRef
  9344. if (!isInt(parser.getObj()) ||
  9345. !isCmd(parser.getObj(), 'obj') ||
  9346. !isStream(obj = parser.getObj())) {
  9347. error('Invalid XRef stream');
  9348. }
  9349. dict = this.processXRefStream(obj);
  9350. if (!this.topDict) {
  9351. this.topDict = dict;
  9352. }
  9353. if (!dict) {
  9354. error('Failed to read XRef stream');
  9355. }
  9356. } else {
  9357. error('Invalid XRef stream header');
  9358. }
  9359. // Recursively get previous dictionary, if any
  9360. obj = dict.get('Prev');
  9361. if (isInt(obj)) {
  9362. this.startXRefQueue.push(obj);
  9363. } else if (isRef(obj)) {
  9364. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  9365. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  9366. this.startXRefQueue.push(obj.num);
  9367. }
  9368. this.startXRefQueue.shift();
  9369. }
  9370. return this.topDict;
  9371. } catch (e) {
  9372. if (e instanceof MissingDataException) {
  9373. throw e;
  9374. }
  9375. info('(while reading XRef): ' + e);
  9376. }
  9377. if (recoveryMode) {
  9378. return;
  9379. }
  9380. throw new XRefParseException();
  9381. },
  9382. getEntry: function XRef_getEntry(i) {
  9383. var xrefEntry = this.entries[i];
  9384. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  9385. return xrefEntry;
  9386. }
  9387. return null;
  9388. },
  9389. fetchIfRef: function XRef_fetchIfRef(obj) {
  9390. if (!isRef(obj)) {
  9391. return obj;
  9392. }
  9393. return this.fetch(obj);
  9394. },
  9395. fetch: function XRef_fetch(ref, suppressEncryption) {
  9396. assert(isRef(ref), 'ref object is not a reference');
  9397. var num = ref.num;
  9398. if (num in this.cache) {
  9399. var cacheEntry = this.cache[num];
  9400. return cacheEntry;
  9401. }
  9402. var xrefEntry = this.getEntry(num);
  9403. // the referenced entry can be free
  9404. if (xrefEntry === null) {
  9405. return (this.cache[num] = null);
  9406. }
  9407. if (xrefEntry.uncompressed) {
  9408. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  9409. } else {
  9410. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9411. }
  9412. if (isDict(xrefEntry)){
  9413. xrefEntry.objId = ref.toString();
  9414. } else if (isStream(xrefEntry)) {
  9415. xrefEntry.dict.objId = ref.toString();
  9416. }
  9417. return xrefEntry;
  9418. },
  9419. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  9420. suppressEncryption) {
  9421. var gen = ref.gen;
  9422. var num = ref.num;
  9423. if (xrefEntry.gen !== gen) {
  9424. error('inconsistent generation in XRef');
  9425. }
  9426. var stream = this.stream.makeSubStream(xrefEntry.offset +
  9427. this.stream.start);
  9428. var parser = new Parser(new Lexer(stream), true, this);
  9429. var obj1 = parser.getObj();
  9430. var obj2 = parser.getObj();
  9431. var obj3 = parser.getObj();
  9432. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  9433. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  9434. !isCmd(obj3)) {
  9435. error('bad XRef entry');
  9436. }
  9437. if (!isCmd(obj3, 'obj')) {
  9438. // some bad PDFs use "obj1234" and really mean 1234
  9439. if (obj3.cmd.indexOf('obj') === 0) {
  9440. num = parseInt(obj3.cmd.substring(3), 10);
  9441. if (!isNaN(num)) {
  9442. return num;
  9443. }
  9444. }
  9445. error('bad XRef entry');
  9446. }
  9447. if (this.encrypt && !suppressEncryption) {
  9448. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  9449. } else {
  9450. xrefEntry = parser.getObj();
  9451. }
  9452. if (!isStream(xrefEntry)) {
  9453. this.cache[num] = xrefEntry;
  9454. }
  9455. return xrefEntry;
  9456. },
  9457. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  9458. suppressEncryption) {
  9459. var tableOffset = xrefEntry.offset;
  9460. var stream = this.fetch(new Ref(tableOffset, 0));
  9461. if (!isStream(stream)) {
  9462. error('bad ObjStm stream');
  9463. }
  9464. var first = stream.dict.get('First');
  9465. var n = stream.dict.get('N');
  9466. if (!isInt(first) || !isInt(n)) {
  9467. error('invalid first and n parameters for ObjStm stream');
  9468. }
  9469. var parser = new Parser(new Lexer(stream), false, this);
  9470. parser.allowStreams = true;
  9471. var i, entries = [], num, nums = [];
  9472. // read the object numbers to populate cache
  9473. for (i = 0; i < n; ++i) {
  9474. num = parser.getObj();
  9475. if (!isInt(num)) {
  9476. error('invalid object number in the ObjStm stream: ' + num);
  9477. }
  9478. nums.push(num);
  9479. var offset = parser.getObj();
  9480. if (!isInt(offset)) {
  9481. error('invalid object offset in the ObjStm stream: ' + offset);
  9482. }
  9483. }
  9484. // read stream objects for cache
  9485. for (i = 0; i < n; ++i) {
  9486. entries.push(parser.getObj());
  9487. num = nums[i];
  9488. var entry = this.entries[num];
  9489. if (entry && entry.offset === tableOffset && entry.gen === i) {
  9490. this.cache[num] = entries[i];
  9491. }
  9492. }
  9493. xrefEntry = entries[xrefEntry.gen];
  9494. if (xrefEntry === undefined) {
  9495. error('bad XRef entry for compressed object');
  9496. }
  9497. return xrefEntry;
  9498. },
  9499. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  9500. if (!isRef(obj)) {
  9501. return Promise.resolve(obj);
  9502. }
  9503. return this.fetchAsync(obj);
  9504. },
  9505. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  9506. var streamManager = this.stream.manager;
  9507. var xref = this;
  9508. return new Promise(function tryFetch(resolve, reject) {
  9509. try {
  9510. resolve(xref.fetch(ref, suppressEncryption));
  9511. } catch (e) {
  9512. if (e instanceof MissingDataException) {
  9513. streamManager.requestRange(e.begin, e.end, function () {
  9514. tryFetch(resolve, reject);
  9515. });
  9516. return;
  9517. }
  9518. reject(e);
  9519. }
  9520. });
  9521. },
  9522. getCatalogObj: function XRef_getCatalogObj() {
  9523. return this.root;
  9524. }
  9525. };
  9526. return XRef;
  9527. })();
  9528. /**
  9529. * A NameTree is like a Dict but has some advantageous properties, see the
  9530. * spec (7.9.6) for more details.
  9531. * TODO: implement all the Dict functions and make this more efficent.
  9532. */
  9533. var NameTree = (function NameTreeClosure() {
  9534. function NameTree(root, xref) {
  9535. this.root = root;
  9536. this.xref = xref;
  9537. }
  9538. NameTree.prototype = {
  9539. getAll: function NameTree_getAll() {
  9540. var dict = {};
  9541. if (!this.root) {
  9542. return dict;
  9543. }
  9544. var xref = this.xref;
  9545. // reading name tree
  9546. var processed = new RefSet();
  9547. processed.put(this.root);
  9548. var queue = [this.root];
  9549. while (queue.length > 0) {
  9550. var i, n;
  9551. var obj = xref.fetchIfRef(queue.shift());
  9552. if (!isDict(obj)) {
  9553. continue;
  9554. }
  9555. if (obj.has('Kids')) {
  9556. var kids = obj.get('Kids');
  9557. for (i = 0, n = kids.length; i < n; i++) {
  9558. var kid = kids[i];
  9559. if (processed.has(kid)) {
  9560. error('invalid destinations');
  9561. }
  9562. queue.push(kid);
  9563. processed.put(kid);
  9564. }
  9565. continue;
  9566. }
  9567. var names = obj.get('Names');
  9568. if (names) {
  9569. for (i = 0, n = names.length; i < n; i += 2) {
  9570. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  9571. }
  9572. }
  9573. }
  9574. return dict;
  9575. },
  9576. get: function NameTree_get(destinationId) {
  9577. if (!this.root) {
  9578. return null;
  9579. }
  9580. var xref = this.xref;
  9581. var kidsOrNames = xref.fetchIfRef(this.root);
  9582. var loopCount = 0;
  9583. var MAX_NAMES_LEVELS = 10;
  9584. var l, r, m;
  9585. // Perform a binary search to quickly find the entry that
  9586. // contains the named destination we are looking for.
  9587. while (kidsOrNames.has('Kids')) {
  9588. loopCount++;
  9589. if (loopCount > MAX_NAMES_LEVELS) {
  9590. warn('Search depth limit for named destionations has been reached.');
  9591. return null;
  9592. }
  9593. var kids = kidsOrNames.get('Kids');
  9594. if (!isArray(kids)) {
  9595. return null;
  9596. }
  9597. l = 0;
  9598. r = kids.length - 1;
  9599. while (l <= r) {
  9600. m = (l + r) >> 1;
  9601. var kid = xref.fetchIfRef(kids[m]);
  9602. var limits = kid.get('Limits');
  9603. if (destinationId < limits[0]) {
  9604. r = m - 1;
  9605. } else if (destinationId > limits[1]) {
  9606. l = m + 1;
  9607. } else {
  9608. kidsOrNames = xref.fetchIfRef(kids[m]);
  9609. break;
  9610. }
  9611. }
  9612. if (l > r) {
  9613. return null;
  9614. }
  9615. }
  9616. // If we get here, then we have found the right entry. Now
  9617. // go through the named destinations in the Named dictionary
  9618. // until we find the exact destination we're looking for.
  9619. var names = kidsOrNames.get('Names');
  9620. if (isArray(names)) {
  9621. // Perform a binary search to reduce the lookup time.
  9622. l = 0;
  9623. r = names.length - 2;
  9624. while (l <= r) {
  9625. // Check only even indices (0, 2, 4, ...) because the
  9626. // odd indices contain the actual D array.
  9627. m = (l + r) & ~1;
  9628. if (destinationId < names[m]) {
  9629. r = m - 2;
  9630. } else if (destinationId > names[m]) {
  9631. l = m + 2;
  9632. } else {
  9633. return xref.fetchIfRef(names[m + 1]);
  9634. }
  9635. }
  9636. }
  9637. return null;
  9638. }
  9639. };
  9640. return NameTree;
  9641. })();
  9642. /**
  9643. * "A PDF file can refer to the contents of another file by using a File
  9644. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  9645. * NOTE: Only embedded files are supported (as part of the attachments support)
  9646. * TODO: support the 'URL' file system (with caching if !/V), portable
  9647. * collections attributes and related files (/RF)
  9648. */
  9649. var FileSpec = (function FileSpecClosure() {
  9650. function FileSpec(root, xref) {
  9651. if (!root || !isDict(root)) {
  9652. return;
  9653. }
  9654. this.xref = xref;
  9655. this.root = root;
  9656. if (root.has('FS')) {
  9657. this.fs = root.get('FS');
  9658. }
  9659. this.description = root.has('Desc') ?
  9660. stringToPDFString(root.get('Desc')) :
  9661. '';
  9662. if (root.has('RF')) {
  9663. warn('Related file specifications are not supported');
  9664. }
  9665. this.contentAvailable = true;
  9666. if (!root.has('EF')) {
  9667. this.contentAvailable = false;
  9668. warn('Non-embedded file specifications are not supported');
  9669. }
  9670. }
  9671. function pickPlatformItem(dict) {
  9672. // Look for the filename in this order:
  9673. // UF, F, Unix, Mac, DOS
  9674. if (dict.has('UF')) {
  9675. return dict.get('UF');
  9676. } else if (dict.has('F')) {
  9677. return dict.get('F');
  9678. } else if (dict.has('Unix')) {
  9679. return dict.get('Unix');
  9680. } else if (dict.has('Mac')) {
  9681. return dict.get('Mac');
  9682. } else if (dict.has('DOS')) {
  9683. return dict.get('DOS');
  9684. } else {
  9685. return null;
  9686. }
  9687. }
  9688. FileSpec.prototype = {
  9689. get filename() {
  9690. if (!this._filename && this.root) {
  9691. var filename = pickPlatformItem(this.root) || 'unnamed';
  9692. this._filename = stringToPDFString(filename).
  9693. replace(/\\\\/g, '\\').
  9694. replace(/\\\//g, '/').
  9695. replace(/\\/g, '/');
  9696. }
  9697. return this._filename;
  9698. },
  9699. get content() {
  9700. if (!this.contentAvailable) {
  9701. return null;
  9702. }
  9703. if (!this.contentRef && this.root) {
  9704. this.contentRef = pickPlatformItem(this.root.get('EF'));
  9705. }
  9706. var content = null;
  9707. if (this.contentRef) {
  9708. var xref = this.xref;
  9709. var fileObj = xref.fetchIfRef(this.contentRef);
  9710. if (fileObj && isStream(fileObj)) {
  9711. content = fileObj.getBytes();
  9712. } else {
  9713. warn('Embedded file specification points to non-existing/invalid ' +
  9714. 'content');
  9715. }
  9716. } else {
  9717. warn('Embedded file specification does not have a content');
  9718. }
  9719. return content;
  9720. },
  9721. get serializable() {
  9722. return {
  9723. filename: this.filename,
  9724. content: this.content
  9725. };
  9726. }
  9727. };
  9728. return FileSpec;
  9729. })();
  9730. /**
  9731. * A helper for loading missing data in object graphs. It traverses the graph
  9732. * depth first and queues up any objects that have missing data. Once it has
  9733. * has traversed as many objects that are available it attempts to bundle the
  9734. * missing data requests and then resume from the nodes that weren't ready.
  9735. *
  9736. * NOTE: It provides protection from circular references by keeping track of
  9737. * of loaded references. However, you must be careful not to load any graphs
  9738. * that have references to the catalog or other pages since that will cause the
  9739. * entire PDF document object graph to be traversed.
  9740. */
  9741. var ObjectLoader = (function() {
  9742. function mayHaveChildren(value) {
  9743. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  9744. }
  9745. function addChildren(node, nodesToVisit) {
  9746. var value;
  9747. if (isDict(node) || isStream(node)) {
  9748. var map;
  9749. if (isDict(node)) {
  9750. map = node.map;
  9751. } else {
  9752. map = node.dict.map;
  9753. }
  9754. for (var key in map) {
  9755. value = map[key];
  9756. if (mayHaveChildren(value)) {
  9757. nodesToVisit.push(value);
  9758. }
  9759. }
  9760. } else if (isArray(node)) {
  9761. for (var i = 0, ii = node.length; i < ii; i++) {
  9762. value = node[i];
  9763. if (mayHaveChildren(value)) {
  9764. nodesToVisit.push(value);
  9765. }
  9766. }
  9767. }
  9768. }
  9769. function ObjectLoader(obj, keys, xref) {
  9770. this.obj = obj;
  9771. this.keys = keys;
  9772. this.xref = xref;
  9773. this.refSet = null;
  9774. }
  9775. ObjectLoader.prototype = {
  9776. load: function ObjectLoader_load() {
  9777. var keys = this.keys;
  9778. this.capability = createPromiseCapability();
  9779. // Don't walk the graph if all the data is already loaded.
  9780. if (!(this.xref.stream instanceof ChunkedStream) ||
  9781. this.xref.stream.getMissingChunks().length === 0) {
  9782. this.capability.resolve();
  9783. return this.capability.promise;
  9784. }
  9785. this.refSet = new RefSet();
  9786. // Setup the initial nodes to visit.
  9787. var nodesToVisit = [];
  9788. for (var i = 0; i < keys.length; i++) {
  9789. nodesToVisit.push(this.obj[keys[i]]);
  9790. }
  9791. this.walk(nodesToVisit);
  9792. return this.capability.promise;
  9793. },
  9794. walk: function ObjectLoader_walk(nodesToVisit) {
  9795. var nodesToRevisit = [];
  9796. var pendingRequests = [];
  9797. // DFS walk of the object graph.
  9798. while (nodesToVisit.length) {
  9799. var currentNode = nodesToVisit.pop();
  9800. // Only references or chunked streams can cause missing data exceptions.
  9801. if (isRef(currentNode)) {
  9802. // Skip nodes that have already been visited.
  9803. if (this.refSet.has(currentNode)) {
  9804. continue;
  9805. }
  9806. try {
  9807. var ref = currentNode;
  9808. this.refSet.put(ref);
  9809. currentNode = this.xref.fetch(currentNode);
  9810. } catch (e) {
  9811. if (!(e instanceof MissingDataException)) {
  9812. throw e;
  9813. }
  9814. nodesToRevisit.push(currentNode);
  9815. pendingRequests.push({ begin: e.begin, end: e.end });
  9816. }
  9817. }
  9818. if (currentNode && currentNode.getBaseStreams) {
  9819. var baseStreams = currentNode.getBaseStreams();
  9820. var foundMissingData = false;
  9821. for (var i = 0; i < baseStreams.length; i++) {
  9822. var stream = baseStreams[i];
  9823. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  9824. foundMissingData = true;
  9825. pendingRequests.push({
  9826. begin: stream.start,
  9827. end: stream.end
  9828. });
  9829. }
  9830. }
  9831. if (foundMissingData) {
  9832. nodesToRevisit.push(currentNode);
  9833. }
  9834. }
  9835. addChildren(currentNode, nodesToVisit);
  9836. }
  9837. if (pendingRequests.length) {
  9838. this.xref.stream.manager.requestRanges(pendingRequests,
  9839. function pendingRequestCallback() {
  9840. nodesToVisit = nodesToRevisit;
  9841. for (var i = 0; i < nodesToRevisit.length; i++) {
  9842. var node = nodesToRevisit[i];
  9843. // Remove any reference nodes from the currrent refset so they
  9844. // aren't skipped when we revist them.
  9845. if (isRef(node)) {
  9846. this.refSet.remove(node);
  9847. }
  9848. }
  9849. this.walk(nodesToVisit);
  9850. }.bind(this));
  9851. return;
  9852. }
  9853. // Everything is loaded.
  9854. this.refSet = null;
  9855. this.capability.resolve();
  9856. }
  9857. };
  9858. return ObjectLoader;
  9859. })();
  9860. var ISOAdobeCharset = [
  9861. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  9862. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  9863. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  9864. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  9865. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  9866. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  9867. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  9868. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  9869. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  9870. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  9871. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  9872. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  9873. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  9874. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  9875. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  9876. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  9877. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  9878. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  9879. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  9880. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  9881. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  9882. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  9883. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  9884. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  9885. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  9886. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  9887. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  9888. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  9889. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  9890. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  9891. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  9892. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  9893. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  9894. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  9895. ];
  9896. var ExpertCharset = [
  9897. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  9898. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  9899. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  9900. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  9901. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  9902. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  9903. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  9904. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  9905. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9906. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9907. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9908. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  9909. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  9910. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  9911. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  9912. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  9913. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  9914. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  9915. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  9916. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  9917. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  9918. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  9919. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9920. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9921. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9922. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9923. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9924. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9925. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  9926. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  9927. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  9928. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  9929. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  9930. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  9931. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  9932. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  9933. 'Ydieresissmall'
  9934. ];
  9935. var ExpertSubsetCharset = [
  9936. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  9937. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  9938. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  9939. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  9940. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  9941. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  9942. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  9943. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9944. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9945. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9946. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  9947. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  9948. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  9949. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9950. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9951. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9952. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9953. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9954. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9955. 'periodinferior', 'commainferior'
  9956. ];
  9957. var DEFAULT_ICON_SIZE = 22; // px
  9958. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  9959. var Annotation = (function AnnotationClosure() {
  9960. // 12.5.5: Algorithm: Appearance streams
  9961. function getTransformMatrix(rect, bbox, matrix) {
  9962. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  9963. var minX = bounds[0];
  9964. var minY = bounds[1];
  9965. var maxX = bounds[2];
  9966. var maxY = bounds[3];
  9967. if (minX === maxX || minY === maxY) {
  9968. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  9969. // just apply the transform for rect
  9970. return [1, 0, 0, 1, rect[0], rect[1]];
  9971. }
  9972. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  9973. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  9974. return [
  9975. xRatio,
  9976. 0,
  9977. 0,
  9978. yRatio,
  9979. rect[0] - minX * xRatio,
  9980. rect[1] - minY * yRatio
  9981. ];
  9982. }
  9983. function getDefaultAppearance(dict) {
  9984. var appearanceState = dict.get('AP');
  9985. if (!isDict(appearanceState)) {
  9986. return;
  9987. }
  9988. var appearance;
  9989. var appearances = appearanceState.get('N');
  9990. if (isDict(appearances)) {
  9991. var as = dict.get('AS');
  9992. if (as && appearances.has(as.name)) {
  9993. appearance = appearances.get(as.name);
  9994. }
  9995. } else {
  9996. appearance = appearances;
  9997. }
  9998. return appearance;
  9999. }
  10000. function Annotation(params) {
  10001. var dict = params.dict;
  10002. var data = this.data = {};
  10003. data.subtype = dict.get('Subtype').name;
  10004. var rect = dict.get('Rect') || [0, 0, 0, 0];
  10005. data.rect = Util.normalizeRect(rect);
  10006. data.annotationFlags = dict.get('F');
  10007. var color = dict.get('C');
  10008. if (!color) {
  10009. // The PDF spec does not mention how a missing color array is interpreted.
  10010. // Adobe Reader seems to default to black in this case.
  10011. data.color = [0, 0, 0];
  10012. } else if (isArray(color)) {
  10013. switch (color.length) {
  10014. case 0:
  10015. // Empty array denotes transparent border.
  10016. data.color = null;
  10017. break;
  10018. case 1:
  10019. // TODO: implement DeviceGray
  10020. break;
  10021. case 3:
  10022. data.color = color;
  10023. break;
  10024. case 4:
  10025. // TODO: implement DeviceCMYK
  10026. break;
  10027. }
  10028. }
  10029. // Some types of annotations have border style dict which has more
  10030. // info than the border array
  10031. if (dict.has('BS')) {
  10032. var borderStyle = dict.get('BS');
  10033. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  10034. } else {
  10035. var borderArray = dict.get('Border') || [0, 0, 1];
  10036. data.borderWidth = borderArray[2] || 0;
  10037. // TODO: implement proper support for annotations with line dash patterns.
  10038. var dashArray = borderArray[3];
  10039. if (data.borderWidth > 0 && dashArray) {
  10040. if (!isArray(dashArray)) {
  10041. // Ignore the border if dashArray is not actually an array,
  10042. // this is consistent with the behaviour in Adobe Reader.
  10043. data.borderWidth = 0;
  10044. } else {
  10045. var dashArrayLength = dashArray.length;
  10046. if (dashArrayLength > 0) {
  10047. // According to the PDF specification: the elements in a dashArray
  10048. // shall be numbers that are nonnegative and not all equal to zero.
  10049. var isInvalid = false;
  10050. var numPositive = 0;
  10051. for (var i = 0; i < dashArrayLength; i++) {
  10052. var validNumber = (+dashArray[i] >= 0);
  10053. if (!validNumber) {
  10054. isInvalid = true;
  10055. break;
  10056. } else if (dashArray[i] > 0) {
  10057. numPositive++;
  10058. }
  10059. }
  10060. if (isInvalid || numPositive === 0) {
  10061. data.borderWidth = 0;
  10062. }
  10063. }
  10064. }
  10065. }
  10066. }
  10067. this.appearance = getDefaultAppearance(dict);
  10068. data.hasAppearance = !!this.appearance;
  10069. data.id = params.ref.num;
  10070. }
  10071. Annotation.prototype = {
  10072. getData: function Annotation_getData() {
  10073. return this.data;
  10074. },
  10075. isInvisible: function Annotation_isInvisible() {
  10076. var data = this.data;
  10077. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  10078. return false;
  10079. } else {
  10080. return !!(data &&
  10081. data.annotationFlags && // Default: not invisible
  10082. data.annotationFlags & 0x1); // Invisible
  10083. }
  10084. },
  10085. isViewable: function Annotation_isViewable() {
  10086. var data = this.data;
  10087. return !!(!this.isInvisible() &&
  10088. data &&
  10089. (!data.annotationFlags ||
  10090. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  10091. data.rect); // rectangle is necessary
  10092. },
  10093. isPrintable: function Annotation_isPrintable() {
  10094. var data = this.data;
  10095. return !!(!this.isInvisible() &&
  10096. data &&
  10097. data.annotationFlags && // Default: not printable
  10098. data.annotationFlags & 0x4 && // Print
  10099. !(data.annotationFlags & 0x2) && // Hidden
  10100. data.rect); // rectangle is necessary
  10101. },
  10102. loadResources: function Annotation_loadResources(keys) {
  10103. return new Promise(function (resolve, reject) {
  10104. this.appearance.dict.getAsync('Resources').then(function (resources) {
  10105. if (!resources) {
  10106. resolve();
  10107. return;
  10108. }
  10109. var objectLoader = new ObjectLoader(resources.map,
  10110. keys,
  10111. resources.xref);
  10112. objectLoader.load().then(function() {
  10113. resolve(resources);
  10114. }, reject);
  10115. }, reject);
  10116. }.bind(this));
  10117. },
  10118. getOperatorList: function Annotation_getOperatorList(evaluator) {
  10119. if (!this.appearance) {
  10120. return Promise.resolve(new OperatorList());
  10121. }
  10122. var data = this.data;
  10123. var appearanceDict = this.appearance.dict;
  10124. var resourcesPromise = this.loadResources([
  10125. 'ExtGState',
  10126. 'ColorSpace',
  10127. 'Pattern',
  10128. 'Shading',
  10129. 'XObject',
  10130. 'Font'
  10131. // ProcSet
  10132. // Properties
  10133. ]);
  10134. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  10135. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  10136. var transform = getTransformMatrix(data.rect, bbox, matrix);
  10137. var self = this;
  10138. return resourcesPromise.then(function(resources) {
  10139. var opList = new OperatorList();
  10140. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  10141. return evaluator.getOperatorList(self.appearance, resources, opList).
  10142. then(function () {
  10143. opList.addOp(OPS.endAnnotation, []);
  10144. self.appearance.reset();
  10145. return opList;
  10146. });
  10147. });
  10148. }
  10149. };
  10150. Annotation.getConstructor =
  10151. function Annotation_getConstructor(subtype, fieldType) {
  10152. if (!subtype) {
  10153. return;
  10154. }
  10155. // TODO(mack): Implement FreeText annotations
  10156. if (subtype === 'Link') {
  10157. return LinkAnnotation;
  10158. } else if (subtype === 'Text') {
  10159. return TextAnnotation;
  10160. } else if (subtype === 'Widget') {
  10161. if (!fieldType) {
  10162. return;
  10163. }
  10164. if (fieldType === 'Tx') {
  10165. return TextWidgetAnnotation;
  10166. } else {
  10167. return WidgetAnnotation;
  10168. }
  10169. } else {
  10170. return Annotation;
  10171. }
  10172. };
  10173. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  10174. var dict = xref.fetchIfRef(ref);
  10175. if (!isDict(dict)) {
  10176. return;
  10177. }
  10178. var subtype = dict.get('Subtype');
  10179. subtype = isName(subtype) ? subtype.name : '';
  10180. if (!subtype) {
  10181. return;
  10182. }
  10183. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10184. fieldType = isName(fieldType) ? fieldType.name : '';
  10185. var Constructor = Annotation.getConstructor(subtype, fieldType);
  10186. if (!Constructor) {
  10187. return;
  10188. }
  10189. var params = {
  10190. dict: dict,
  10191. ref: ref,
  10192. };
  10193. var annotation = new Constructor(params);
  10194. if (annotation.isViewable() || annotation.isPrintable()) {
  10195. return annotation;
  10196. } else {
  10197. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  10198. warn('unimplemented annotation type: ' + subtype);
  10199. }
  10200. }
  10201. };
  10202. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  10203. annotations, opList, pdfManager, partialEvaluator, intent) {
  10204. function reject(e) {
  10205. annotationsReadyCapability.reject(e);
  10206. }
  10207. var annotationsReadyCapability = createPromiseCapability();
  10208. var annotationPromises = [];
  10209. for (var i = 0, n = annotations.length; i < n; ++i) {
  10210. if (intent === 'display' && annotations[i].isViewable() ||
  10211. intent === 'print' && annotations[i].isPrintable()) {
  10212. annotationPromises.push(
  10213. annotations[i].getOperatorList(partialEvaluator));
  10214. }
  10215. }
  10216. Promise.all(annotationPromises).then(function(datas) {
  10217. opList.addOp(OPS.beginAnnotations, []);
  10218. for (var i = 0, n = datas.length; i < n; ++i) {
  10219. var annotOpList = datas[i];
  10220. opList.addOpList(annotOpList);
  10221. }
  10222. opList.addOp(OPS.endAnnotations, []);
  10223. annotationsReadyCapability.resolve();
  10224. }, reject);
  10225. return annotationsReadyCapability.promise;
  10226. };
  10227. return Annotation;
  10228. })();
  10229. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  10230. function WidgetAnnotation(params) {
  10231. Annotation.call(this, params);
  10232. var dict = params.dict;
  10233. var data = this.data;
  10234. data.fieldValue = stringToPDFString(
  10235. Util.getInheritableProperty(dict, 'V') || '');
  10236. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  10237. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  10238. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10239. data.fieldType = isName(fieldType) ? fieldType.name : '';
  10240. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  10241. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  10242. // Building the full field name by collecting the field and
  10243. // its ancestors 'T' data and joining them using '.'.
  10244. var fieldName = [];
  10245. var namedItem = dict;
  10246. var ref = params.ref;
  10247. while (namedItem) {
  10248. var parent = namedItem.get('Parent');
  10249. var parentRef = namedItem.getRaw('Parent');
  10250. var name = namedItem.get('T');
  10251. if (name) {
  10252. fieldName.unshift(stringToPDFString(name));
  10253. } else if (parent && ref) {
  10254. // The field name is absent, that means more than one field
  10255. // with the same name may exist. Replacing the empty name
  10256. // with the '`' plus index in the parent's 'Kids' array.
  10257. // This is not in the PDF spec but necessary to id the
  10258. // the input controls.
  10259. var kids = parent.get('Kids');
  10260. var j, jj;
  10261. for (j = 0, jj = kids.length; j < jj; j++) {
  10262. var kidRef = kids[j];
  10263. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  10264. break;
  10265. }
  10266. }
  10267. fieldName.unshift('`' + j);
  10268. }
  10269. namedItem = parent;
  10270. ref = parentRef;
  10271. }
  10272. data.fullName = fieldName.join('.');
  10273. }
  10274. var parent = Annotation.prototype;
  10275. Util.inherit(WidgetAnnotation, Annotation, {
  10276. isViewable: function WidgetAnnotation_isViewable() {
  10277. if (this.data.fieldType === 'Sig') {
  10278. warn('unimplemented annotation type: Widget signature');
  10279. return false;
  10280. }
  10281. return parent.isViewable.call(this);
  10282. }
  10283. });
  10284. return WidgetAnnotation;
  10285. })();
  10286. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  10287. function TextWidgetAnnotation(params) {
  10288. WidgetAnnotation.call(this, params);
  10289. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  10290. this.data.annotationType = AnnotationType.WIDGET;
  10291. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  10292. }
  10293. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  10294. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  10295. if (this.appearance) {
  10296. return Annotation.prototype.getOperatorList.call(this, evaluator);
  10297. }
  10298. var opList = new OperatorList();
  10299. var data = this.data;
  10300. // Even if there is an appearance stream, ignore it. This is the
  10301. // behaviour used by Adobe Reader.
  10302. if (!data.defaultAppearance) {
  10303. return Promise.resolve(opList);
  10304. }
  10305. var stream = new Stream(stringToBytes(data.defaultAppearance));
  10306. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  10307. then(function () {
  10308. return opList;
  10309. });
  10310. }
  10311. });
  10312. return TextWidgetAnnotation;
  10313. })();
  10314. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  10315. function InteractiveAnnotation(params) {
  10316. Annotation.call(this, params);
  10317. this.data.hasHtml = true;
  10318. }
  10319. Util.inherit(InteractiveAnnotation, Annotation, { });
  10320. return InteractiveAnnotation;
  10321. })();
  10322. var TextAnnotation = (function TextAnnotationClosure() {
  10323. function TextAnnotation(params) {
  10324. InteractiveAnnotation.call(this, params);
  10325. var dict = params.dict;
  10326. var data = this.data;
  10327. var content = dict.get('Contents');
  10328. var title = dict.get('T');
  10329. data.annotationType = AnnotationType.TEXT;
  10330. data.content = stringToPDFString(content || '');
  10331. data.title = stringToPDFString(title || '');
  10332. if (data.hasAppearance) {
  10333. data.name = 'NoIcon';
  10334. } else {
  10335. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  10336. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  10337. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  10338. }
  10339. if (dict.has('C')) {
  10340. data.hasBgColor = true;
  10341. }
  10342. }
  10343. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  10344. return TextAnnotation;
  10345. })();
  10346. var LinkAnnotation = (function LinkAnnotationClosure() {
  10347. function LinkAnnotation(params) {
  10348. InteractiveAnnotation.call(this, params);
  10349. var dict = params.dict;
  10350. var data = this.data;
  10351. data.annotationType = AnnotationType.LINK;
  10352. var action = dict.get('A');
  10353. if (action) {
  10354. var linkType = action.get('S').name;
  10355. if (linkType === 'URI') {
  10356. var url = action.get('URI');
  10357. if (isName(url)) {
  10358. // Some bad PDFs do not put parentheses around relative URLs.
  10359. url = '/' + url.name;
  10360. } else if (url) {
  10361. url = addDefaultProtocolToUrl(url);
  10362. }
  10363. // TODO: pdf spec mentions urls can be relative to a Base
  10364. // entry in the dictionary.
  10365. if (!isValidUrl(url, false)) {
  10366. url = '';
  10367. }
  10368. data.url = url;
  10369. } else if (linkType === 'GoTo') {
  10370. data.dest = action.get('D');
  10371. } else if (linkType === 'GoToR') {
  10372. var urlDict = action.get('F');
  10373. if (isDict(urlDict)) {
  10374. // We assume that the 'url' is a Filspec dictionary
  10375. // and fetch the url without checking any further
  10376. url = urlDict.get('F') || '';
  10377. }
  10378. // TODO: pdf reference says that GoToR
  10379. // can also have 'NewWindow' attribute
  10380. if (!isValidUrl(url, false)) {
  10381. url = '';
  10382. }
  10383. data.url = url;
  10384. data.dest = action.get('D');
  10385. } else if (linkType === 'Named') {
  10386. data.action = action.get('N').name;
  10387. } else {
  10388. warn('unrecognized link type: ' + linkType);
  10389. }
  10390. } else if (dict.has('Dest')) {
  10391. // simple destination link
  10392. var dest = dict.get('Dest');
  10393. data.dest = isName(dest) ? dest.name : dest;
  10394. }
  10395. }
  10396. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  10397. function addDefaultProtocolToUrl(url) {
  10398. if (url && url.indexOf('www.') === 0) {
  10399. return ('http://' + url);
  10400. }
  10401. return url;
  10402. }
  10403. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  10404. return LinkAnnotation;
  10405. })();
  10406. var PDFFunction = (function PDFFunctionClosure() {
  10407. var CONSTRUCT_SAMPLED = 0;
  10408. var CONSTRUCT_INTERPOLATED = 2;
  10409. var CONSTRUCT_STICHED = 3;
  10410. var CONSTRUCT_POSTSCRIPT = 4;
  10411. return {
  10412. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  10413. str) {
  10414. var i, ii;
  10415. var length = 1;
  10416. for (i = 0, ii = size.length; i < ii; i++) {
  10417. length *= size[i];
  10418. }
  10419. length *= outputSize;
  10420. var array = new Array(length);
  10421. var codeSize = 0;
  10422. var codeBuf = 0;
  10423. // 32 is a valid bps so shifting won't work
  10424. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  10425. var strBytes = str.getBytes((length * bps + 7) / 8);
  10426. var strIdx = 0;
  10427. for (i = 0; i < length; i++) {
  10428. while (codeSize < bps) {
  10429. codeBuf <<= 8;
  10430. codeBuf |= strBytes[strIdx++];
  10431. codeSize += 8;
  10432. }
  10433. codeSize -= bps;
  10434. array[i] = (codeBuf >> codeSize) * sampleMul;
  10435. codeBuf &= (1 << codeSize) - 1;
  10436. }
  10437. return array;
  10438. },
  10439. getIR: function PDFFunction_getIR(xref, fn) {
  10440. var dict = fn.dict;
  10441. if (!dict) {
  10442. dict = fn;
  10443. }
  10444. var types = [this.constructSampled,
  10445. null,
  10446. this.constructInterpolated,
  10447. this.constructStiched,
  10448. this.constructPostScript];
  10449. var typeNum = dict.get('FunctionType');
  10450. var typeFn = types[typeNum];
  10451. if (!typeFn) {
  10452. error('Unknown type of function');
  10453. }
  10454. return typeFn.call(this, fn, dict, xref);
  10455. },
  10456. fromIR: function PDFFunction_fromIR(IR) {
  10457. var type = IR[0];
  10458. switch (type) {
  10459. case CONSTRUCT_SAMPLED:
  10460. return this.constructSampledFromIR(IR);
  10461. case CONSTRUCT_INTERPOLATED:
  10462. return this.constructInterpolatedFromIR(IR);
  10463. case CONSTRUCT_STICHED:
  10464. return this.constructStichedFromIR(IR);
  10465. //case CONSTRUCT_POSTSCRIPT:
  10466. default:
  10467. return this.constructPostScriptFromIR(IR);
  10468. }
  10469. },
  10470. parse: function PDFFunction_parse(xref, fn) {
  10471. var IR = this.getIR(xref, fn);
  10472. return this.fromIR(IR);
  10473. },
  10474. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  10475. if (!isArray(fnObj)) {
  10476. // not an array -- parsing as regular function
  10477. return this.parse(xref, fnObj);
  10478. }
  10479. var fnArray = [];
  10480. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  10481. var obj = xref.fetchIfRef(fnObj[j]);
  10482. fnArray.push(PDFFunction.parse(xref, obj));
  10483. }
  10484. return function (src, srcOffset, dest, destOffset) {
  10485. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  10486. fnArray[i](src, srcOffset, dest, destOffset + i);
  10487. }
  10488. };
  10489. },
  10490. constructSampled: function PDFFunction_constructSampled(str, dict) {
  10491. function toMultiArray(arr) {
  10492. var inputLength = arr.length;
  10493. var out = [];
  10494. var index = 0;
  10495. for (var i = 0; i < inputLength; i += 2) {
  10496. out[index] = [arr[i], arr[i + 1]];
  10497. ++index;
  10498. }
  10499. return out;
  10500. }
  10501. var domain = dict.get('Domain');
  10502. var range = dict.get('Range');
  10503. if (!domain || !range) {
  10504. error('No domain or range');
  10505. }
  10506. var inputSize = domain.length / 2;
  10507. var outputSize = range.length / 2;
  10508. domain = toMultiArray(domain);
  10509. range = toMultiArray(range);
  10510. var size = dict.get('Size');
  10511. var bps = dict.get('BitsPerSample');
  10512. var order = dict.get('Order') || 1;
  10513. if (order !== 1) {
  10514. // No description how cubic spline interpolation works in PDF32000:2008
  10515. // As in poppler, ignoring order, linear interpolation may work as good
  10516. info('No support for cubic spline interpolation: ' + order);
  10517. }
  10518. var encode = dict.get('Encode');
  10519. if (!encode) {
  10520. encode = [];
  10521. for (var i = 0; i < inputSize; ++i) {
  10522. encode.push(0);
  10523. encode.push(size[i] - 1);
  10524. }
  10525. }
  10526. encode = toMultiArray(encode);
  10527. var decode = dict.get('Decode');
  10528. if (!decode) {
  10529. decode = range;
  10530. } else {
  10531. decode = toMultiArray(decode);
  10532. }
  10533. var samples = this.getSampleArray(size, outputSize, bps, str);
  10534. return [
  10535. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  10536. outputSize, Math.pow(2, bps) - 1, range
  10537. ];
  10538. },
  10539. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  10540. // See chapter 3, page 109 of the PDF reference
  10541. function interpolate(x, xmin, xmax, ymin, ymax) {
  10542. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  10543. }
  10544. return function constructSampledFromIRResult(src, srcOffset,
  10545. dest, destOffset) {
  10546. // See chapter 3, page 110 of the PDF reference.
  10547. var m = IR[1];
  10548. var domain = IR[2];
  10549. var encode = IR[3];
  10550. var decode = IR[4];
  10551. var samples = IR[5];
  10552. var size = IR[6];
  10553. var n = IR[7];
  10554. //var mask = IR[8];
  10555. var range = IR[9];
  10556. // Building the cube vertices: its part and sample index
  10557. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  10558. var cubeVertices = 1 << m;
  10559. var cubeN = new Float64Array(cubeVertices);
  10560. var cubeVertex = new Uint32Array(cubeVertices);
  10561. var i, j;
  10562. for (j = 0; j < cubeVertices; j++) {
  10563. cubeN[j] = 1;
  10564. }
  10565. var k = n, pos = 1;
  10566. // Map x_i to y_j for 0 <= i < m using the sampled function.
  10567. for (i = 0; i < m; ++i) {
  10568. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  10569. var domain_2i = domain[i][0];
  10570. var domain_2i_1 = domain[i][1];
  10571. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  10572. domain_2i_1);
  10573. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  10574. // Encode_2i, Encode_2i+1)
  10575. var e = interpolate(xi, domain_2i, domain_2i_1,
  10576. encode[i][0], encode[i][1]);
  10577. // e_i' = min(max(e_i, 0), Size_i - 1)
  10578. var size_i = size[i];
  10579. e = Math.min(Math.max(e, 0), size_i - 1);
  10580. // Adjusting the cube: N and vertex sample index
  10581. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  10582. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  10583. var n1 = e - e0; // (e - e0) / (e1 - e0);
  10584. var offset0 = e0 * k;
  10585. var offset1 = offset0 + k; // e1 * k
  10586. for (j = 0; j < cubeVertices; j++) {
  10587. if (j & pos) {
  10588. cubeN[j] *= n1;
  10589. cubeVertex[j] += offset1;
  10590. } else {
  10591. cubeN[j] *= n0;
  10592. cubeVertex[j] += offset0;
  10593. }
  10594. }
  10595. k *= size_i;
  10596. pos <<= 1;
  10597. }
  10598. for (j = 0; j < n; ++j) {
  10599. // Sum all cube vertices' samples portions
  10600. var rj = 0;
  10601. for (i = 0; i < cubeVertices; i++) {
  10602. rj += samples[cubeVertex[i] + j] * cubeN[i];
  10603. }
  10604. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  10605. // Decode_2j, Decode_2j+1)
  10606. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  10607. // y_j = min(max(r_j, range_2j), range_2j+1)
  10608. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  10609. range[j][1]);
  10610. }
  10611. };
  10612. },
  10613. constructInterpolated: function PDFFunction_constructInterpolated(str,
  10614. dict) {
  10615. var c0 = dict.get('C0') || [0];
  10616. var c1 = dict.get('C1') || [1];
  10617. var n = dict.get('N');
  10618. if (!isArray(c0) || !isArray(c1)) {
  10619. error('Illegal dictionary for interpolated function');
  10620. }
  10621. var length = c0.length;
  10622. var diff = [];
  10623. for (var i = 0; i < length; ++i) {
  10624. diff.push(c1[i] - c0[i]);
  10625. }
  10626. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  10627. },
  10628. constructInterpolatedFromIR:
  10629. function PDFFunction_constructInterpolatedFromIR(IR) {
  10630. var c0 = IR[1];
  10631. var diff = IR[2];
  10632. var n = IR[3];
  10633. var length = diff.length;
  10634. return function constructInterpolatedFromIRResult(src, srcOffset,
  10635. dest, destOffset) {
  10636. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  10637. for (var j = 0; j < length; ++j) {
  10638. dest[destOffset + j] = c0[j] + (x * diff[j]);
  10639. }
  10640. };
  10641. },
  10642. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  10643. var domain = dict.get('Domain');
  10644. if (!domain) {
  10645. error('No domain');
  10646. }
  10647. var inputSize = domain.length / 2;
  10648. if (inputSize !== 1) {
  10649. error('Bad domain for stiched function');
  10650. }
  10651. var fnRefs = dict.get('Functions');
  10652. var fns = [];
  10653. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  10654. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  10655. }
  10656. var bounds = dict.get('Bounds');
  10657. var encode = dict.get('Encode');
  10658. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  10659. },
  10660. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  10661. var domain = IR[1];
  10662. var bounds = IR[2];
  10663. var encode = IR[3];
  10664. var fnsIR = IR[4];
  10665. var fns = [];
  10666. var tmpBuf = new Float32Array(1);
  10667. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  10668. fns.push(PDFFunction.fromIR(fnsIR[i]));
  10669. }
  10670. return function constructStichedFromIRResult(src, srcOffset,
  10671. dest, destOffset) {
  10672. var clip = function constructStichedFromIRClip(v, min, max) {
  10673. if (v > max) {
  10674. v = max;
  10675. } else if (v < min) {
  10676. v = min;
  10677. }
  10678. return v;
  10679. };
  10680. // clip to domain
  10681. var v = clip(src[srcOffset], domain[0], domain[1]);
  10682. // calulate which bound the value is in
  10683. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  10684. if (v < bounds[i]) {
  10685. break;
  10686. }
  10687. }
  10688. // encode value into domain of function
  10689. var dmin = domain[0];
  10690. if (i > 0) {
  10691. dmin = bounds[i - 1];
  10692. }
  10693. var dmax = domain[1];
  10694. if (i < bounds.length) {
  10695. dmax = bounds[i];
  10696. }
  10697. var rmin = encode[2 * i];
  10698. var rmax = encode[2 * i + 1];
  10699. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  10700. // call the appropriate function
  10701. fns[i](tmpBuf, 0, dest, destOffset);
  10702. };
  10703. },
  10704. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  10705. xref) {
  10706. var domain = dict.get('Domain');
  10707. var range = dict.get('Range');
  10708. if (!domain) {
  10709. error('No domain.');
  10710. }
  10711. if (!range) {
  10712. error('No range.');
  10713. }
  10714. var lexer = new PostScriptLexer(fn);
  10715. var parser = new PostScriptParser(lexer);
  10716. var code = parser.parse();
  10717. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  10718. },
  10719. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  10720. IR) {
  10721. var domain = IR[1];
  10722. var range = IR[2];
  10723. var code = IR[3];
  10724. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  10725. if (compiled) {
  10726. // Compiled function consists of simple expressions such as addition,
  10727. // subtraction, Math.max, and also contains 'var' and 'return'
  10728. // statements. See the generation in the PostScriptCompiler below.
  10729. /*jshint -W054 */
  10730. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  10731. }
  10732. info('Unable to compile PS function');
  10733. var numOutputs = range.length >> 1;
  10734. var numInputs = domain.length >> 1;
  10735. var evaluator = new PostScriptEvaluator(code);
  10736. // Cache the values for a big speed up, the cache size is limited though
  10737. // since the number of possible values can be huge from a PS function.
  10738. var cache = {};
  10739. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  10740. // seen in our tests.
  10741. var MAX_CACHE_SIZE = 2048 * 4;
  10742. var cache_available = MAX_CACHE_SIZE;
  10743. var tmpBuf = new Float32Array(numInputs);
  10744. return function constructPostScriptFromIRResult(src, srcOffset,
  10745. dest, destOffset) {
  10746. var i, value;
  10747. var key = '';
  10748. var input = tmpBuf;
  10749. for (i = 0; i < numInputs; i++) {
  10750. value = src[srcOffset + i];
  10751. input[i] = value;
  10752. key += value + '_';
  10753. }
  10754. var cachedValue = cache[key];
  10755. if (cachedValue !== undefined) {
  10756. dest.set(cachedValue, destOffset);
  10757. return;
  10758. }
  10759. var output = new Float32Array(numOutputs);
  10760. var stack = evaluator.execute(input);
  10761. var stackIndex = stack.length - numOutputs;
  10762. for (i = 0; i < numOutputs; i++) {
  10763. value = stack[stackIndex + i];
  10764. var bound = range[i * 2];
  10765. if (value < bound) {
  10766. value = bound;
  10767. } else {
  10768. bound = range[i * 2 +1];
  10769. if (value > bound) {
  10770. value = bound;
  10771. }
  10772. }
  10773. output[i] = value;
  10774. }
  10775. if (cache_available > 0) {
  10776. cache_available--;
  10777. cache[key] = output;
  10778. }
  10779. dest.set(output, destOffset);
  10780. };
  10781. }
  10782. };
  10783. })();
  10784. function isPDFFunction(v) {
  10785. var fnDict;
  10786. if (typeof v !== 'object') {
  10787. return false;
  10788. } else if (isDict(v)) {
  10789. fnDict = v;
  10790. } else if (isStream(v)) {
  10791. fnDict = v.dict;
  10792. } else {
  10793. return false;
  10794. }
  10795. return fnDict.has('FunctionType');
  10796. }
  10797. var PostScriptStack = (function PostScriptStackClosure() {
  10798. var MAX_STACK_SIZE = 100;
  10799. function PostScriptStack(initialStack) {
  10800. this.stack = !initialStack ? [] :
  10801. Array.prototype.slice.call(initialStack, 0);
  10802. }
  10803. PostScriptStack.prototype = {
  10804. push: function PostScriptStack_push(value) {
  10805. if (this.stack.length >= MAX_STACK_SIZE) {
  10806. error('PostScript function stack overflow.');
  10807. }
  10808. this.stack.push(value);
  10809. },
  10810. pop: function PostScriptStack_pop() {
  10811. if (this.stack.length <= 0) {
  10812. error('PostScript function stack underflow.');
  10813. }
  10814. return this.stack.pop();
  10815. },
  10816. copy: function PostScriptStack_copy(n) {
  10817. if (this.stack.length + n >= MAX_STACK_SIZE) {
  10818. error('PostScript function stack overflow.');
  10819. }
  10820. var stack = this.stack;
  10821. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  10822. stack.push(stack[i]);
  10823. }
  10824. },
  10825. index: function PostScriptStack_index(n) {
  10826. this.push(this.stack[this.stack.length - n - 1]);
  10827. },
  10828. // rotate the last n stack elements p times
  10829. roll: function PostScriptStack_roll(n, p) {
  10830. var stack = this.stack;
  10831. var l = stack.length - n;
  10832. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  10833. for (i = l, j = r; i < j; i++, j--) {
  10834. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10835. }
  10836. for (i = l, j = c - 1; i < j; i++, j--) {
  10837. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10838. }
  10839. for (i = c, j = r; i < j; i++, j--) {
  10840. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10841. }
  10842. }
  10843. };
  10844. return PostScriptStack;
  10845. })();
  10846. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  10847. function PostScriptEvaluator(operators) {
  10848. this.operators = operators;
  10849. }
  10850. PostScriptEvaluator.prototype = {
  10851. execute: function PostScriptEvaluator_execute(initialStack) {
  10852. var stack = new PostScriptStack(initialStack);
  10853. var counter = 0;
  10854. var operators = this.operators;
  10855. var length = operators.length;
  10856. var operator, a, b;
  10857. while (counter < length) {
  10858. operator = operators[counter++];
  10859. if (typeof operator === 'number') {
  10860. // Operator is really an operand and should be pushed to the stack.
  10861. stack.push(operator);
  10862. continue;
  10863. }
  10864. switch (operator) {
  10865. // non standard ps operators
  10866. case 'jz': // jump if false
  10867. b = stack.pop();
  10868. a = stack.pop();
  10869. if (!a) {
  10870. counter = b;
  10871. }
  10872. break;
  10873. case 'j': // jump
  10874. a = stack.pop();
  10875. counter = a;
  10876. break;
  10877. // all ps operators in alphabetical order (excluding if/ifelse)
  10878. case 'abs':
  10879. a = stack.pop();
  10880. stack.push(Math.abs(a));
  10881. break;
  10882. case 'add':
  10883. b = stack.pop();
  10884. a = stack.pop();
  10885. stack.push(a + b);
  10886. break;
  10887. case 'and':
  10888. b = stack.pop();
  10889. a = stack.pop();
  10890. if (isBool(a) && isBool(b)) {
  10891. stack.push(a && b);
  10892. } else {
  10893. stack.push(a & b);
  10894. }
  10895. break;
  10896. case 'atan':
  10897. a = stack.pop();
  10898. stack.push(Math.atan(a));
  10899. break;
  10900. case 'bitshift':
  10901. b = stack.pop();
  10902. a = stack.pop();
  10903. if (a > 0) {
  10904. stack.push(a << b);
  10905. } else {
  10906. stack.push(a >> b);
  10907. }
  10908. break;
  10909. case 'ceiling':
  10910. a = stack.pop();
  10911. stack.push(Math.ceil(a));
  10912. break;
  10913. case 'copy':
  10914. a = stack.pop();
  10915. stack.copy(a);
  10916. break;
  10917. case 'cos':
  10918. a = stack.pop();
  10919. stack.push(Math.cos(a));
  10920. break;
  10921. case 'cvi':
  10922. a = stack.pop() | 0;
  10923. stack.push(a);
  10924. break;
  10925. case 'cvr':
  10926. // noop
  10927. break;
  10928. case 'div':
  10929. b = stack.pop();
  10930. a = stack.pop();
  10931. stack.push(a / b);
  10932. break;
  10933. case 'dup':
  10934. stack.copy(1);
  10935. break;
  10936. case 'eq':
  10937. b = stack.pop();
  10938. a = stack.pop();
  10939. stack.push(a === b);
  10940. break;
  10941. case 'exch':
  10942. stack.roll(2, 1);
  10943. break;
  10944. case 'exp':
  10945. b = stack.pop();
  10946. a = stack.pop();
  10947. stack.push(Math.pow(a, b));
  10948. break;
  10949. case 'false':
  10950. stack.push(false);
  10951. break;
  10952. case 'floor':
  10953. a = stack.pop();
  10954. stack.push(Math.floor(a));
  10955. break;
  10956. case 'ge':
  10957. b = stack.pop();
  10958. a = stack.pop();
  10959. stack.push(a >= b);
  10960. break;
  10961. case 'gt':
  10962. b = stack.pop();
  10963. a = stack.pop();
  10964. stack.push(a > b);
  10965. break;
  10966. case 'idiv':
  10967. b = stack.pop();
  10968. a = stack.pop();
  10969. stack.push((a / b) | 0);
  10970. break;
  10971. case 'index':
  10972. a = stack.pop();
  10973. stack.index(a);
  10974. break;
  10975. case 'le':
  10976. b = stack.pop();
  10977. a = stack.pop();
  10978. stack.push(a <= b);
  10979. break;
  10980. case 'ln':
  10981. a = stack.pop();
  10982. stack.push(Math.log(a));
  10983. break;
  10984. case 'log':
  10985. a = stack.pop();
  10986. stack.push(Math.log(a) / Math.LN10);
  10987. break;
  10988. case 'lt':
  10989. b = stack.pop();
  10990. a = stack.pop();
  10991. stack.push(a < b);
  10992. break;
  10993. case 'mod':
  10994. b = stack.pop();
  10995. a = stack.pop();
  10996. stack.push(a % b);
  10997. break;
  10998. case 'mul':
  10999. b = stack.pop();
  11000. a = stack.pop();
  11001. stack.push(a * b);
  11002. break;
  11003. case 'ne':
  11004. b = stack.pop();
  11005. a = stack.pop();
  11006. stack.push(a !== b);
  11007. break;
  11008. case 'neg':
  11009. a = stack.pop();
  11010. stack.push(-a);
  11011. break;
  11012. case 'not':
  11013. a = stack.pop();
  11014. if (isBool(a)) {
  11015. stack.push(!a);
  11016. } else {
  11017. stack.push(~a);
  11018. }
  11019. break;
  11020. case 'or':
  11021. b = stack.pop();
  11022. a = stack.pop();
  11023. if (isBool(a) && isBool(b)) {
  11024. stack.push(a || b);
  11025. } else {
  11026. stack.push(a | b);
  11027. }
  11028. break;
  11029. case 'pop':
  11030. stack.pop();
  11031. break;
  11032. case 'roll':
  11033. b = stack.pop();
  11034. a = stack.pop();
  11035. stack.roll(a, b);
  11036. break;
  11037. case 'round':
  11038. a = stack.pop();
  11039. stack.push(Math.round(a));
  11040. break;
  11041. case 'sin':
  11042. a = stack.pop();
  11043. stack.push(Math.sin(a));
  11044. break;
  11045. case 'sqrt':
  11046. a = stack.pop();
  11047. stack.push(Math.sqrt(a));
  11048. break;
  11049. case 'sub':
  11050. b = stack.pop();
  11051. a = stack.pop();
  11052. stack.push(a - b);
  11053. break;
  11054. case 'true':
  11055. stack.push(true);
  11056. break;
  11057. case 'truncate':
  11058. a = stack.pop();
  11059. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  11060. stack.push(a);
  11061. break;
  11062. case 'xor':
  11063. b = stack.pop();
  11064. a = stack.pop();
  11065. if (isBool(a) && isBool(b)) {
  11066. stack.push(a !== b);
  11067. } else {
  11068. stack.push(a ^ b);
  11069. }
  11070. break;
  11071. default:
  11072. error('Unknown operator ' + operator);
  11073. break;
  11074. }
  11075. }
  11076. return stack.stack;
  11077. }
  11078. };
  11079. return PostScriptEvaluator;
  11080. })();
  11081. // Most of the PDFs functions consist of simple operations such as:
  11082. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  11083. //
  11084. // We can compile most of such programs, and at the same moment, we can
  11085. // optimize some expressions using basic math properties. Keeping track of
  11086. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  11087. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  11088. function AstNode(type) {
  11089. this.type = type;
  11090. }
  11091. AstNode.prototype.visit = function (visitor) {
  11092. throw new Error('abstract method');
  11093. };
  11094. function AstArgument(index, min, max) {
  11095. AstNode.call(this, 'args');
  11096. this.index = index;
  11097. this.min = min;
  11098. this.max = max;
  11099. }
  11100. AstArgument.prototype = Object.create(AstNode.prototype);
  11101. AstArgument.prototype.visit = function (visitor) {
  11102. visitor.visitArgument(this);
  11103. };
  11104. function AstLiteral(number) {
  11105. AstNode.call(this, 'literal');
  11106. this.number = number;
  11107. this.min = number;
  11108. this.max = number;
  11109. }
  11110. AstLiteral.prototype = Object.create(AstNode.prototype);
  11111. AstLiteral.prototype.visit = function (visitor) {
  11112. visitor.visitLiteral(this);
  11113. };
  11114. function AstBinaryOperation(op, arg1, arg2, min, max) {
  11115. AstNode.call(this, 'binary');
  11116. this.op = op;
  11117. this.arg1 = arg1;
  11118. this.arg2 = arg2;
  11119. this.min = min;
  11120. this.max = max;
  11121. }
  11122. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  11123. AstBinaryOperation.prototype.visit = function (visitor) {
  11124. visitor.visitBinaryOperation(this);
  11125. };
  11126. function AstMin(arg, max) {
  11127. AstNode.call(this, 'max');
  11128. this.arg = arg;
  11129. this.min = arg.min;
  11130. this.max = max;
  11131. }
  11132. AstMin.prototype = Object.create(AstNode.prototype);
  11133. AstMin.prototype.visit = function (visitor) {
  11134. visitor.visitMin(this);
  11135. };
  11136. function AstVariable(index, min, max) {
  11137. AstNode.call(this, 'var');
  11138. this.index = index;
  11139. this.min = min;
  11140. this.max = max;
  11141. }
  11142. AstVariable.prototype = Object.create(AstNode.prototype);
  11143. AstVariable.prototype.visit = function (visitor) {
  11144. visitor.visitVariable(this);
  11145. };
  11146. function AstVariableDefinition(variable, arg) {
  11147. AstNode.call(this, 'definition');
  11148. this.variable = variable;
  11149. this.arg = arg;
  11150. }
  11151. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  11152. AstVariableDefinition.prototype.visit = function (visitor) {
  11153. visitor.visitVariableDefinition(this);
  11154. };
  11155. function ExpressionBuilderVisitor() {
  11156. this.parts = [];
  11157. }
  11158. ExpressionBuilderVisitor.prototype = {
  11159. visitArgument: function (arg) {
  11160. this.parts.push('Math.max(', arg.min, ', Math.min(',
  11161. arg.max, ', src[srcOffset + ', arg.index, ']))');
  11162. },
  11163. visitVariable: function (variable) {
  11164. this.parts.push('v', variable.index);
  11165. },
  11166. visitLiteral: function (literal) {
  11167. this.parts.push(literal.number);
  11168. },
  11169. visitBinaryOperation: function (operation) {
  11170. this.parts.push('(');
  11171. operation.arg1.visit(this);
  11172. this.parts.push(' ', operation.op, ' ');
  11173. operation.arg2.visit(this);
  11174. this.parts.push(')');
  11175. },
  11176. visitVariableDefinition: function (definition) {
  11177. this.parts.push('var ');
  11178. definition.variable.visit(this);
  11179. this.parts.push(' = ');
  11180. definition.arg.visit(this);
  11181. this.parts.push(';');
  11182. },
  11183. visitMin: function (max) {
  11184. this.parts.push('Math.min(');
  11185. max.arg.visit(this);
  11186. this.parts.push(', ', max.max, ')');
  11187. },
  11188. toString: function () {
  11189. return this.parts.join('');
  11190. }
  11191. };
  11192. function buildAddOperation(num1, num2) {
  11193. if (num2.type === 'literal' && num2.number === 0) {
  11194. // optimization: second operand is 0
  11195. return num1;
  11196. }
  11197. if (num1.type === 'literal' && num1.number === 0) {
  11198. // optimization: first operand is 0
  11199. return num2;
  11200. }
  11201. if (num2.type === 'literal' && num1.type === 'literal') {
  11202. // optimization: operands operand are literals
  11203. return new AstLiteral(num1.number + num2.number);
  11204. }
  11205. return new AstBinaryOperation('+', num1, num2,
  11206. num1.min + num2.min, num1.max + num2.max);
  11207. }
  11208. function buildMulOperation(num1, num2) {
  11209. if (num2.type === 'literal') {
  11210. // optimization: second operands is a literal...
  11211. if (num2.number === 0) {
  11212. return new AstLiteral(0); // and it's 0
  11213. } else if (num2.number === 1) {
  11214. return num1; // and it's 1
  11215. } else if (num1.type === 'literal') {
  11216. // ... and first operands is a literal too
  11217. return new AstLiteral(num1.number * num2.number);
  11218. }
  11219. }
  11220. if (num1.type === 'literal') {
  11221. // optimization: first operands is a literal...
  11222. if (num1.number === 0) {
  11223. return new AstLiteral(0); // and it's 0
  11224. } else if (num1.number === 1) {
  11225. return num2; // and it's 1
  11226. }
  11227. }
  11228. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  11229. num1.max * num2.min, num1.max * num2.max);
  11230. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  11231. num1.max * num2.min, num1.max * num2.max);
  11232. return new AstBinaryOperation('*', num1, num2, min, max);
  11233. }
  11234. function buildSubOperation(num1, num2) {
  11235. if (num2.type === 'literal') {
  11236. // optimization: second operands is a literal...
  11237. if (num2.number === 0) {
  11238. return num1; // ... and it's 0
  11239. } else if (num1.type === 'literal') {
  11240. // ... and first operands is a literal too
  11241. return new AstLiteral(num1.number - num2.number);
  11242. }
  11243. }
  11244. if (num2.type === 'binary' && num2.op === '-' &&
  11245. num1.type === 'literal' && num1.number === 1 &&
  11246. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  11247. // optimization for case: 1 - (1 - x)
  11248. return num2.arg2;
  11249. }
  11250. return new AstBinaryOperation('-', num1, num2,
  11251. num1.min - num2.max, num1.max - num2.min);
  11252. }
  11253. function buildMinOperation(num1, max) {
  11254. if (num1.min >= max) {
  11255. // optimization: num1 min value is not less than required max
  11256. return new AstLiteral(max); // just returning max
  11257. } else if (num1.max <= max) {
  11258. // optimization: num1 max value is not greater than required max
  11259. return num1; // just returning an argument
  11260. }
  11261. return new AstMin(num1, max);
  11262. }
  11263. function PostScriptCompiler() {}
  11264. PostScriptCompiler.prototype = {
  11265. compile: function PostScriptCompiler_compile(code, domain, range) {
  11266. var stack = [];
  11267. var i, ii;
  11268. var instructions = [];
  11269. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  11270. var lastRegister = 0;
  11271. var n, j, min, max;
  11272. var num1, num2, ast1, ast2, tmpVar, item;
  11273. for (i = 0; i < inputSize; i++) {
  11274. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  11275. }
  11276. for (i = 0, ii = code.length; i < ii; i++) {
  11277. item = code[i];
  11278. if (typeof item === 'number') {
  11279. stack.push(new AstLiteral(item));
  11280. continue;
  11281. }
  11282. switch (item) {
  11283. case 'add':
  11284. if (stack.length < 2) {
  11285. return null;
  11286. }
  11287. num2 = stack.pop();
  11288. num1 = stack.pop();
  11289. stack.push(buildAddOperation(num1, num2));
  11290. break;
  11291. case 'cvr':
  11292. if (stack.length < 1) {
  11293. return null;
  11294. }
  11295. break;
  11296. case 'mul':
  11297. if (stack.length < 2) {
  11298. return null;
  11299. }
  11300. num2 = stack.pop();
  11301. num1 = stack.pop();
  11302. stack.push(buildMulOperation(num1, num2));
  11303. break;
  11304. case 'sub':
  11305. if (stack.length < 2) {
  11306. return null;
  11307. }
  11308. num2 = stack.pop();
  11309. num1 = stack.pop();
  11310. stack.push(buildSubOperation(num1, num2));
  11311. break;
  11312. case 'exch':
  11313. if (stack.length < 2) {
  11314. return null;
  11315. }
  11316. ast1 = stack.pop(); ast2 = stack.pop();
  11317. stack.push(ast1, ast2);
  11318. break;
  11319. case 'pop':
  11320. if (stack.length < 1) {
  11321. return null;
  11322. }
  11323. stack.pop();
  11324. break;
  11325. case 'index':
  11326. if (stack.length < 1) {
  11327. return null;
  11328. }
  11329. num1 = stack.pop();
  11330. if (num1.type !== 'literal') {
  11331. return null;
  11332. }
  11333. n = num1.number;
  11334. if (n < 0 || (n|0) !== n || stack.length < n) {
  11335. return null;
  11336. }
  11337. ast1 = stack[stack.length - n - 1];
  11338. if (ast1.type === 'literal' || ast1.type === 'var') {
  11339. stack.push(ast1);
  11340. break;
  11341. }
  11342. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11343. stack[stack.length - n - 1] = tmpVar;
  11344. stack.push(tmpVar);
  11345. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11346. break;
  11347. case 'dup':
  11348. if (stack.length < 1) {
  11349. return null;
  11350. }
  11351. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  11352. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  11353. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  11354. // special case of the commands sequence for the min operation
  11355. num1 = stack.pop();
  11356. stack.push(buildMinOperation(num1, code[i + 1]));
  11357. i += 6;
  11358. break;
  11359. }
  11360. ast1 = stack[stack.length - 1];
  11361. if (ast1.type === 'literal' || ast1.type === 'var') {
  11362. // we don't have to save into intermediate variable a literal or
  11363. // variable.
  11364. stack.push(ast1);
  11365. break;
  11366. }
  11367. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11368. stack[stack.length - 1] = tmpVar;
  11369. stack.push(tmpVar);
  11370. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11371. break;
  11372. case 'roll':
  11373. if (stack.length < 2) {
  11374. return null;
  11375. }
  11376. num2 = stack.pop();
  11377. num1 = stack.pop();
  11378. if (num2.type !== 'literal' || num1.type !== 'literal') {
  11379. // both roll operands must be numbers
  11380. return null;
  11381. }
  11382. j = num2.number;
  11383. n = num1.number;
  11384. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  11385. // ... and integers
  11386. return null;
  11387. }
  11388. j = ((j % n) + n) % n;
  11389. if (j === 0) {
  11390. break; // just skipping -- there are nothing to rotate
  11391. }
  11392. Array.prototype.push.apply(stack,
  11393. stack.splice(stack.length - n, n - j));
  11394. break;
  11395. default:
  11396. return null; // unsupported operator
  11397. }
  11398. }
  11399. if (stack.length !== outputSize) {
  11400. return null;
  11401. }
  11402. var result = [];
  11403. instructions.forEach(function (instruction) {
  11404. var statementBuilder = new ExpressionBuilderVisitor();
  11405. instruction.visit(statementBuilder);
  11406. result.push(statementBuilder.toString());
  11407. });
  11408. stack.forEach(function (expr, i) {
  11409. var statementBuilder = new ExpressionBuilderVisitor();
  11410. expr.visit(statementBuilder);
  11411. var min = range[i * 2], max = range[i * 2 + 1];
  11412. var out = [statementBuilder.toString()];
  11413. if (min > expr.min) {
  11414. out.unshift('Math.max(', min, ', ');
  11415. out.push(')');
  11416. }
  11417. if (max < expr.max) {
  11418. out.unshift('Math.min(', max, ', ');
  11419. out.push(')');
  11420. }
  11421. out.unshift('dest[destOffset + ', i, '] = ');
  11422. out.push(';');
  11423. result.push(out.join(''));
  11424. });
  11425. return result.join('\n');
  11426. }
  11427. };
  11428. return PostScriptCompiler;
  11429. })();
  11430. var ColorSpace = (function ColorSpaceClosure() {
  11431. // Constructor should define this.numComps, this.defaultColor, this.name
  11432. function ColorSpace() {
  11433. error('should not call ColorSpace constructor');
  11434. }
  11435. ColorSpace.prototype = {
  11436. /**
  11437. * Converts the color value to the RGB color. The color components are
  11438. * located in the src array starting from the srcOffset. Returns the array
  11439. * of the rgb components, each value ranging from [0,255].
  11440. */
  11441. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  11442. var rgb = new Uint8Array(3);
  11443. this.getRgbItem(src, srcOffset, rgb, 0);
  11444. return rgb;
  11445. },
  11446. /**
  11447. * Converts the color value to the RGB color, similar to the getRgb method.
  11448. * The result placed into the dest array starting from the destOffset.
  11449. */
  11450. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  11451. dest, destOffset) {
  11452. error('Should not call ColorSpace.getRgbItem');
  11453. },
  11454. /**
  11455. * Converts the specified number of the color values to the RGB colors.
  11456. * The colors are located in the src array starting from the srcOffset.
  11457. * The result is placed into the dest array starting from the destOffset.
  11458. * The src array items shall be in [0,2^bits) range, the dest array items
  11459. * will be in [0,255] range. alpha01 indicates how many alpha components
  11460. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  11461. * array).
  11462. */
  11463. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  11464. dest, destOffset, bits,
  11465. alpha01) {
  11466. error('Should not call ColorSpace.getRgbBuffer');
  11467. },
  11468. /**
  11469. * Determines the number of bytes required to store the result of the
  11470. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  11471. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  11472. */
  11473. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  11474. alpha01) {
  11475. error('Should not call ColorSpace.getOutputLength');
  11476. },
  11477. /**
  11478. * Returns true if source data will be equal the result/output data.
  11479. */
  11480. isPassthrough: function ColorSpace_isPassthrough(bits) {
  11481. return false;
  11482. },
  11483. /**
  11484. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  11485. * how many alpha components there are in the dest array; it will be either
  11486. * 0 (RGB array) or 1 (RGBA array).
  11487. */
  11488. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  11489. originalHeight, width, height,
  11490. actualHeight, bpc, comps, alpha01) {
  11491. var count = originalWidth * originalHeight;
  11492. var rgbBuf = null;
  11493. var numComponentColors = 1 << bpc;
  11494. var needsResizing = originalHeight !== height || originalWidth !== width;
  11495. var i, ii;
  11496. if (this.isPassthrough(bpc)) {
  11497. rgbBuf = comps;
  11498. } else if (this.numComps === 1 && count > numComponentColors &&
  11499. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  11500. // Optimization: create a color map when there is just one component and
  11501. // we are converting more colors than the size of the color map. We
  11502. // don't build the map if the colorspace is gray or rgb since those
  11503. // methods are faster than building a map. This mainly offers big speed
  11504. // ups for indexed and alternate colorspaces.
  11505. //
  11506. // TODO it may be worth while to cache the color map. While running
  11507. // testing I never hit a cache so I will leave that out for now (perhaps
  11508. // we are reparsing colorspaces too much?).
  11509. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  11510. new Uint16Array(numComponentColors);
  11511. var key;
  11512. for (i = 0; i < numComponentColors; i++) {
  11513. allColors[i] = i;
  11514. }
  11515. var colorMap = new Uint8Array(numComponentColors * 3);
  11516. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  11517. /* alpha01 = */ 0);
  11518. var destPos, rgbPos;
  11519. if (!needsResizing) {
  11520. // Fill in the RGB values directly into |dest|.
  11521. destPos = 0;
  11522. for (i = 0; i < count; ++i) {
  11523. key = comps[i] * 3;
  11524. dest[destPos++] = colorMap[key];
  11525. dest[destPos++] = colorMap[key + 1];
  11526. dest[destPos++] = colorMap[key + 2];
  11527. destPos += alpha01;
  11528. }
  11529. } else {
  11530. rgbBuf = new Uint8Array(count * 3);
  11531. rgbPos = 0;
  11532. for (i = 0; i < count; ++i) {
  11533. key = comps[i] * 3;
  11534. rgbBuf[rgbPos++] = colorMap[key];
  11535. rgbBuf[rgbPos++] = colorMap[key + 1];
  11536. rgbBuf[rgbPos++] = colorMap[key + 2];
  11537. }
  11538. }
  11539. } else {
  11540. if (!needsResizing) {
  11541. // Fill in the RGB values directly into |dest|.
  11542. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  11543. alpha01);
  11544. } else {
  11545. rgbBuf = new Uint8Array(count * 3);
  11546. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  11547. /* alpha01 = */ 0);
  11548. }
  11549. }
  11550. if (rgbBuf) {
  11551. if (needsResizing) {
  11552. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  11553. height, dest, alpha01);
  11554. } else {
  11555. rgbPos = 0;
  11556. destPos = 0;
  11557. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  11558. dest[destPos++] = rgbBuf[rgbPos++];
  11559. dest[destPos++] = rgbBuf[rgbPos++];
  11560. dest[destPos++] = rgbBuf[rgbPos++];
  11561. destPos += alpha01;
  11562. }
  11563. }
  11564. }
  11565. },
  11566. /**
  11567. * True if the colorspace has components in the default range of [0, 1].
  11568. * This should be true for all colorspaces except for lab color spaces
  11569. * which are [0,100], [-128, 127], [-128, 127].
  11570. */
  11571. usesZeroToOneRange: true
  11572. };
  11573. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  11574. var IR = ColorSpace.parseToIR(cs, xref, res);
  11575. if (IR instanceof AlternateCS) {
  11576. return IR;
  11577. }
  11578. return ColorSpace.fromIR(IR);
  11579. };
  11580. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  11581. var name = isArray(IR) ? IR[0] : IR;
  11582. var whitePoint, blackPoint, gamma;
  11583. switch (name) {
  11584. case 'DeviceGrayCS':
  11585. return this.singletons.gray;
  11586. case 'DeviceRgbCS':
  11587. return this.singletons.rgb;
  11588. case 'DeviceCmykCS':
  11589. return this.singletons.cmyk;
  11590. case 'CalGrayCS':
  11591. whitePoint = IR[1].WhitePoint;
  11592. blackPoint = IR[1].BlackPoint;
  11593. gamma = IR[1].Gamma;
  11594. return new CalGrayCS(whitePoint, blackPoint, gamma);
  11595. case 'CalRGBCS':
  11596. whitePoint = IR[1].WhitePoint;
  11597. blackPoint = IR[1].BlackPoint;
  11598. gamma = IR[1].Gamma;
  11599. var matrix = IR[1].Matrix;
  11600. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  11601. case 'PatternCS':
  11602. var basePatternCS = IR[1];
  11603. if (basePatternCS) {
  11604. basePatternCS = ColorSpace.fromIR(basePatternCS);
  11605. }
  11606. return new PatternCS(basePatternCS);
  11607. case 'IndexedCS':
  11608. var baseIndexedCS = IR[1];
  11609. var hiVal = IR[2];
  11610. var lookup = IR[3];
  11611. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  11612. case 'AlternateCS':
  11613. var numComps = IR[1];
  11614. var alt = IR[2];
  11615. var tintFnIR = IR[3];
  11616. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  11617. PDFFunction.fromIR(tintFnIR));
  11618. case 'LabCS':
  11619. whitePoint = IR[1].WhitePoint;
  11620. blackPoint = IR[1].BlackPoint;
  11621. var range = IR[1].Range;
  11622. return new LabCS(whitePoint, blackPoint, range);
  11623. default:
  11624. error('Unknown name ' + name);
  11625. }
  11626. return null;
  11627. };
  11628. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  11629. if (isName(cs)) {
  11630. var colorSpaces = res.get('ColorSpace');
  11631. if (isDict(colorSpaces)) {
  11632. var refcs = colorSpaces.get(cs.name);
  11633. if (refcs) {
  11634. cs = refcs;
  11635. }
  11636. }
  11637. }
  11638. cs = xref.fetchIfRef(cs);
  11639. var mode;
  11640. if (isName(cs)) {
  11641. mode = cs.name;
  11642. this.mode = mode;
  11643. switch (mode) {
  11644. case 'DeviceGray':
  11645. case 'G':
  11646. return 'DeviceGrayCS';
  11647. case 'DeviceRGB':
  11648. case 'RGB':
  11649. return 'DeviceRgbCS';
  11650. case 'DeviceCMYK':
  11651. case 'CMYK':
  11652. return 'DeviceCmykCS';
  11653. case 'Pattern':
  11654. return ['PatternCS', null];
  11655. default:
  11656. error('unrecognized colorspace ' + mode);
  11657. }
  11658. } else if (isArray(cs)) {
  11659. mode = cs[0].name;
  11660. this.mode = mode;
  11661. var numComps, params;
  11662. switch (mode) {
  11663. case 'DeviceGray':
  11664. case 'G':
  11665. return 'DeviceGrayCS';
  11666. case 'DeviceRGB':
  11667. case 'RGB':
  11668. return 'DeviceRgbCS';
  11669. case 'DeviceCMYK':
  11670. case 'CMYK':
  11671. return 'DeviceCmykCS';
  11672. case 'CalGray':
  11673. params = cs[1].getAll();
  11674. return ['CalGrayCS', params];
  11675. case 'CalRGB':
  11676. params = cs[1].getAll();
  11677. return ['CalRGBCS', params];
  11678. case 'ICCBased':
  11679. var stream = xref.fetchIfRef(cs[1]);
  11680. var dict = stream.dict;
  11681. numComps = dict.get('N');
  11682. if (numComps === 1) {
  11683. return 'DeviceGrayCS';
  11684. } else if (numComps === 3) {
  11685. return 'DeviceRgbCS';
  11686. } else if (numComps === 4) {
  11687. return 'DeviceCmykCS';
  11688. }
  11689. break;
  11690. case 'Pattern':
  11691. var basePatternCS = cs[1];
  11692. if (basePatternCS) {
  11693. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  11694. }
  11695. return ['PatternCS', basePatternCS];
  11696. case 'Indexed':
  11697. case 'I':
  11698. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  11699. var hiVal = cs[2] + 1;
  11700. var lookup = xref.fetchIfRef(cs[3]);
  11701. if (isStream(lookup)) {
  11702. lookup = lookup.getBytes();
  11703. }
  11704. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  11705. case 'Separation':
  11706. case 'DeviceN':
  11707. var name = cs[1];
  11708. numComps = 1;
  11709. if (isName(name)) {
  11710. numComps = 1;
  11711. } else if (isArray(name)) {
  11712. numComps = name.length;
  11713. }
  11714. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  11715. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  11716. return ['AlternateCS', numComps, alt, tintFnIR];
  11717. case 'Lab':
  11718. params = cs[1].getAll();
  11719. return ['LabCS', params];
  11720. default:
  11721. error('unimplemented color space object "' + mode + '"');
  11722. }
  11723. } else {
  11724. error('unrecognized color space object: "' + cs + '"');
  11725. }
  11726. return null;
  11727. };
  11728. /**
  11729. * Checks if a decode map matches the default decode map for a color space.
  11730. * This handles the general decode maps where there are two values per
  11731. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  11732. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  11733. * slightly different.
  11734. * @param {Array} decode Decode map (usually from an image).
  11735. * @param {Number} n Number of components the color space has.
  11736. */
  11737. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  11738. if (!decode) {
  11739. return true;
  11740. }
  11741. if (n * 2 !== decode.length) {
  11742. warn('The decode map is not the correct length');
  11743. return true;
  11744. }
  11745. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  11746. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  11747. return false;
  11748. }
  11749. }
  11750. return true;
  11751. };
  11752. ColorSpace.singletons = {
  11753. get gray() {
  11754. return shadow(this, 'gray', new DeviceGrayCS());
  11755. },
  11756. get rgb() {
  11757. return shadow(this, 'rgb', new DeviceRgbCS());
  11758. },
  11759. get cmyk() {
  11760. return shadow(this, 'cmyk', new DeviceCmykCS());
  11761. }
  11762. };
  11763. return ColorSpace;
  11764. })();
  11765. /**
  11766. * Alternate color space handles both Separation and DeviceN color spaces. A
  11767. * Separation color space is actually just a DeviceN with one color component.
  11768. * Both color spaces use a tinting function to convert colors to a base color
  11769. * space.
  11770. */
  11771. var AlternateCS = (function AlternateCSClosure() {
  11772. function AlternateCS(numComps, base, tintFn) {
  11773. this.name = 'Alternate';
  11774. this.numComps = numComps;
  11775. this.defaultColor = new Float32Array(numComps);
  11776. for (var i = 0; i < numComps; ++i) {
  11777. this.defaultColor[i] = 1;
  11778. }
  11779. this.base = base;
  11780. this.tintFn = tintFn;
  11781. this.tmpBuf = new Float32Array(base.numComps);
  11782. }
  11783. AlternateCS.prototype = {
  11784. getRgb: ColorSpace.prototype.getRgb,
  11785. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  11786. dest, destOffset) {
  11787. var tmpBuf = this.tmpBuf;
  11788. this.tintFn(src, srcOffset, tmpBuf, 0);
  11789. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  11790. },
  11791. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  11792. dest, destOffset, bits,
  11793. alpha01) {
  11794. var tintFn = this.tintFn;
  11795. var base = this.base;
  11796. var scale = 1 / ((1 << bits) - 1);
  11797. var baseNumComps = base.numComps;
  11798. var usesZeroToOneRange = base.usesZeroToOneRange;
  11799. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  11800. alpha01 === 0;
  11801. var pos = isPassthrough ? destOffset : 0;
  11802. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  11803. var numComps = this.numComps;
  11804. var scaled = new Float32Array(numComps);
  11805. var tinted = new Float32Array(baseNumComps);
  11806. var i, j;
  11807. if (usesZeroToOneRange) {
  11808. for (i = 0; i < count; i++) {
  11809. for (j = 0; j < numComps; j++) {
  11810. scaled[j] = src[srcOffset++] * scale;
  11811. }
  11812. tintFn(scaled, 0, tinted, 0);
  11813. for (j = 0; j < baseNumComps; j++) {
  11814. baseBuf[pos++] = tinted[j] * 255;
  11815. }
  11816. }
  11817. } else {
  11818. for (i = 0; i < count; i++) {
  11819. for (j = 0; j < numComps; j++) {
  11820. scaled[j] = src[srcOffset++] * scale;
  11821. }
  11822. tintFn(scaled, 0, tinted, 0);
  11823. base.getRgbItem(tinted, 0, baseBuf, pos);
  11824. pos += baseNumComps;
  11825. }
  11826. }
  11827. if (!isPassthrough) {
  11828. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  11829. }
  11830. },
  11831. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  11832. alpha01) {
  11833. return this.base.getOutputLength(inputLength *
  11834. this.base.numComps / this.numComps,
  11835. alpha01);
  11836. },
  11837. isPassthrough: ColorSpace.prototype.isPassthrough,
  11838. fillRgb: ColorSpace.prototype.fillRgb,
  11839. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  11840. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11841. },
  11842. usesZeroToOneRange: true
  11843. };
  11844. return AlternateCS;
  11845. })();
  11846. var PatternCS = (function PatternCSClosure() {
  11847. function PatternCS(baseCS) {
  11848. this.name = 'Pattern';
  11849. this.base = baseCS;
  11850. }
  11851. PatternCS.prototype = {};
  11852. return PatternCS;
  11853. })();
  11854. var IndexedCS = (function IndexedCSClosure() {
  11855. function IndexedCS(base, highVal, lookup) {
  11856. this.name = 'Indexed';
  11857. this.numComps = 1;
  11858. this.defaultColor = new Uint8Array([0]);
  11859. this.base = base;
  11860. this.highVal = highVal;
  11861. var baseNumComps = base.numComps;
  11862. var length = baseNumComps * highVal;
  11863. var lookupArray;
  11864. if (isStream(lookup)) {
  11865. lookupArray = new Uint8Array(length);
  11866. var bytes = lookup.getBytes(length);
  11867. lookupArray.set(bytes);
  11868. } else if (isString(lookup)) {
  11869. lookupArray = new Uint8Array(length);
  11870. for (var i = 0; i < length; ++i) {
  11871. lookupArray[i] = lookup.charCodeAt(i);
  11872. }
  11873. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  11874. lookupArray = lookup;
  11875. } else {
  11876. error('Unrecognized lookup table: ' + lookup);
  11877. }
  11878. this.lookup = lookupArray;
  11879. }
  11880. IndexedCS.prototype = {
  11881. getRgb: ColorSpace.prototype.getRgb,
  11882. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  11883. dest, destOffset) {
  11884. var numComps = this.base.numComps;
  11885. var start = src[srcOffset] * numComps;
  11886. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  11887. },
  11888. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  11889. dest, destOffset, bits,
  11890. alpha01) {
  11891. var base = this.base;
  11892. var numComps = base.numComps;
  11893. var outputDelta = base.getOutputLength(numComps, alpha01);
  11894. var lookup = this.lookup;
  11895. for (var i = 0; i < count; ++i) {
  11896. var lookupPos = src[srcOffset++] * numComps;
  11897. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  11898. destOffset += outputDelta;
  11899. }
  11900. },
  11901. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  11902. return this.base.getOutputLength(inputLength * this.base.numComps,
  11903. alpha01);
  11904. },
  11905. isPassthrough: ColorSpace.prototype.isPassthrough,
  11906. fillRgb: ColorSpace.prototype.fillRgb,
  11907. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  11908. // indexed color maps shouldn't be changed
  11909. return true;
  11910. },
  11911. usesZeroToOneRange: true
  11912. };
  11913. return IndexedCS;
  11914. })();
  11915. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  11916. function DeviceGrayCS() {
  11917. this.name = 'DeviceGray';
  11918. this.numComps = 1;
  11919. this.defaultColor = new Float32Array([0]);
  11920. }
  11921. DeviceGrayCS.prototype = {
  11922. getRgb: ColorSpace.prototype.getRgb,
  11923. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  11924. dest, destOffset) {
  11925. var c = (src[srcOffset] * 255) | 0;
  11926. c = c < 0 ? 0 : c > 255 ? 255 : c;
  11927. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  11928. },
  11929. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  11930. dest, destOffset, bits,
  11931. alpha01) {
  11932. var scale = 255 / ((1 << bits) - 1);
  11933. var j = srcOffset, q = destOffset;
  11934. for (var i = 0; i < count; ++i) {
  11935. var c = (scale * src[j++]) | 0;
  11936. dest[q++] = c;
  11937. dest[q++] = c;
  11938. dest[q++] = c;
  11939. q += alpha01;
  11940. }
  11941. },
  11942. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  11943. alpha01) {
  11944. return inputLength * (3 + alpha01);
  11945. },
  11946. isPassthrough: ColorSpace.prototype.isPassthrough,
  11947. fillRgb: ColorSpace.prototype.fillRgb,
  11948. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  11949. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11950. },
  11951. usesZeroToOneRange: true
  11952. };
  11953. return DeviceGrayCS;
  11954. })();
  11955. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  11956. function DeviceRgbCS() {
  11957. this.name = 'DeviceRGB';
  11958. this.numComps = 3;
  11959. this.defaultColor = new Float32Array([0, 0, 0]);
  11960. }
  11961. DeviceRgbCS.prototype = {
  11962. getRgb: ColorSpace.prototype.getRgb,
  11963. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  11964. dest, destOffset) {
  11965. var r = (src[srcOffset] * 255) | 0;
  11966. var g = (src[srcOffset + 1] * 255) | 0;
  11967. var b = (src[srcOffset + 2] * 255) | 0;
  11968. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  11969. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  11970. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  11971. },
  11972. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  11973. dest, destOffset, bits,
  11974. alpha01) {
  11975. if (bits === 8 && alpha01 === 0) {
  11976. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  11977. return;
  11978. }
  11979. var scale = 255 / ((1 << bits) - 1);
  11980. var j = srcOffset, q = destOffset;
  11981. for (var i = 0; i < count; ++i) {
  11982. dest[q++] = (scale * src[j++]) | 0;
  11983. dest[q++] = (scale * src[j++]) | 0;
  11984. dest[q++] = (scale * src[j++]) | 0;
  11985. q += alpha01;
  11986. }
  11987. },
  11988. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  11989. alpha01) {
  11990. return (inputLength * (3 + alpha01) / 3) | 0;
  11991. },
  11992. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  11993. return bits === 8;
  11994. },
  11995. fillRgb: ColorSpace.prototype.fillRgb,
  11996. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  11997. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11998. },
  11999. usesZeroToOneRange: true
  12000. };
  12001. return DeviceRgbCS;
  12002. })();
  12003. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  12004. // The coefficients below was found using numerical analysis: the method of
  12005. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  12006. // where color_value is the tabular value from the table of sampled RGB colors
  12007. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  12008. // CMYK color conversion using the estimation below:
  12009. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  12010. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  12011. var c = src[srcOffset + 0] * srcScale;
  12012. var m = src[srcOffset + 1] * srcScale;
  12013. var y = src[srcOffset + 2] * srcScale;
  12014. var k = src[srcOffset + 3] * srcScale;
  12015. var r =
  12016. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  12017. 18.82290502165302 * y + 212.25662451639585 * k +
  12018. -285.2331026137004) +
  12019. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  12020. -17.873870861415444 * k - 5.497006427196366) +
  12021. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  12022. 17.5119270841813) +
  12023. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  12024. var g =
  12025. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  12026. 6.871425592049007 * y + 31.159100130055922 * k +
  12027. -79.2970844816548) +
  12028. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  12029. 131.35250912493976 * k - 190.9453302588951) +
  12030. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  12031. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  12032. var b =
  12033. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  12034. 30.89978309703729 * y - 0.23883238689178934 * k +
  12035. -14.183576799673286) +
  12036. m * (10.49593273432072 * m + 63.02378494754052 * y +
  12037. 50.606957656360734 * k - 112.23884253719248) +
  12038. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  12039. -193.58209356861505) +
  12040. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  12041. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  12042. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  12043. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  12044. }
  12045. function DeviceCmykCS() {
  12046. this.name = 'DeviceCMYK';
  12047. this.numComps = 4;
  12048. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  12049. }
  12050. DeviceCmykCS.prototype = {
  12051. getRgb: ColorSpace.prototype.getRgb,
  12052. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  12053. dest, destOffset) {
  12054. convertToRgb(src, srcOffset, 1, dest, destOffset);
  12055. },
  12056. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  12057. dest, destOffset, bits,
  12058. alpha01) {
  12059. var scale = 1 / ((1 << bits) - 1);
  12060. for (var i = 0; i < count; i++) {
  12061. convertToRgb(src, srcOffset, scale, dest, destOffset);
  12062. srcOffset += 4;
  12063. destOffset += 3 + alpha01;
  12064. }
  12065. },
  12066. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  12067. alpha01) {
  12068. return (inputLength / 4 * (3 + alpha01)) | 0;
  12069. },
  12070. isPassthrough: ColorSpace.prototype.isPassthrough,
  12071. fillRgb: ColorSpace.prototype.fillRgb,
  12072. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  12073. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12074. },
  12075. usesZeroToOneRange: true
  12076. };
  12077. return DeviceCmykCS;
  12078. })();
  12079. //
  12080. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  12081. //
  12082. var CalGrayCS = (function CalGrayCSClosure() {
  12083. function CalGrayCS(whitePoint, blackPoint, gamma) {
  12084. this.name = 'CalGray';
  12085. this.numComps = 1;
  12086. this.defaultColor = new Float32Array([0]);
  12087. if (!whitePoint) {
  12088. error('WhitePoint missing - required for color space CalGray');
  12089. }
  12090. blackPoint = blackPoint || [0, 0, 0];
  12091. gamma = gamma || 1;
  12092. // Translate arguments to spec variables.
  12093. this.XW = whitePoint[0];
  12094. this.YW = whitePoint[1];
  12095. this.ZW = whitePoint[2];
  12096. this.XB = blackPoint[0];
  12097. this.YB = blackPoint[1];
  12098. this.ZB = blackPoint[2];
  12099. this.G = gamma;
  12100. // Validate variables as per spec.
  12101. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12102. error('Invalid WhitePoint components for ' + this.name +
  12103. ', no fallback available');
  12104. }
  12105. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12106. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  12107. this.XB = this.YB = this.ZB = 0;
  12108. }
  12109. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  12110. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  12111. ', ZB: ' + this.ZB + ', only default values are supported.');
  12112. }
  12113. if (this.G < 1) {
  12114. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  12115. ', falling back to default');
  12116. this.G = 1;
  12117. }
  12118. }
  12119. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12120. // A represents a gray component of a calibrated gray space.
  12121. // A <---> AG in the spec
  12122. var A = src[srcOffset] * scale;
  12123. var AG = Math.pow(A, cs.G);
  12124. // Computes L as per spec. ( = cs.YW * AG )
  12125. // Except if other than default BlackPoint values are used.
  12126. var L = cs.YW * AG;
  12127. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  12128. // Convert values to rgb range [0, 255].
  12129. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  12130. dest[destOffset] = val;
  12131. dest[destOffset + 1] = val;
  12132. dest[destOffset + 2] = val;
  12133. }
  12134. CalGrayCS.prototype = {
  12135. getRgb: ColorSpace.prototype.getRgb,
  12136. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  12137. dest, destOffset) {
  12138. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12139. },
  12140. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  12141. dest, destOffset, bits,
  12142. alpha01) {
  12143. var scale = 1 / ((1 << bits) - 1);
  12144. for (var i = 0; i < count; ++i) {
  12145. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12146. srcOffset += 1;
  12147. destOffset += 3 + alpha01;
  12148. }
  12149. },
  12150. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  12151. return inputLength * (3 + alpha01);
  12152. },
  12153. isPassthrough: ColorSpace.prototype.isPassthrough,
  12154. fillRgb: ColorSpace.prototype.fillRgb,
  12155. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  12156. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12157. },
  12158. usesZeroToOneRange: true
  12159. };
  12160. return CalGrayCS;
  12161. })();
  12162. //
  12163. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  12164. //
  12165. var CalRGBCS = (function CalRGBCSClosure() {
  12166. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  12167. // matrices.
  12168. var BRADFORD_SCALE_MATRIX = new Float32Array([
  12169. 0.8951, 0.2664, -0.1614,
  12170. -0.7502, 1.7135, 0.0367,
  12171. 0.0389, -0.0685, 1.0296]);
  12172. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  12173. 0.9869929, -0.1470543, 0.1599627,
  12174. 0.4323053, 0.5183603, 0.0492912,
  12175. -0.0085287, 0.0400428, 0.9684867]);
  12176. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  12177. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  12178. 3.2404542, -1.5371385, -0.4985314,
  12179. -0.9692660, 1.8760108, 0.0415560,
  12180. 0.0556434, -0.2040259, 1.0572252]);
  12181. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  12182. var tempNormalizeMatrix = new Float32Array(3);
  12183. var tempConvertMatrix1 = new Float32Array(3);
  12184. var tempConvertMatrix2 = new Float32Array(3);
  12185. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  12186. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  12187. this.name = 'CalRGB';
  12188. this.numComps = 3;
  12189. this.defaultColor = new Float32Array(3);
  12190. if (!whitePoint) {
  12191. error('WhitePoint missing - required for color space CalRGB');
  12192. }
  12193. blackPoint = blackPoint || new Float32Array(3);
  12194. gamma = gamma || new Float32Array([1, 1, 1]);
  12195. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  12196. // Translate arguments to spec variables.
  12197. var XW = whitePoint[0];
  12198. var YW = whitePoint[1];
  12199. var ZW = whitePoint[2];
  12200. this.whitePoint = whitePoint;
  12201. var XB = blackPoint[0];
  12202. var YB = blackPoint[1];
  12203. var ZB = blackPoint[2];
  12204. this.blackPoint = blackPoint;
  12205. this.GR = gamma[0];
  12206. this.GG = gamma[1];
  12207. this.GB = gamma[2];
  12208. this.MXA = matrix[0];
  12209. this.MYA = matrix[1];
  12210. this.MZA = matrix[2];
  12211. this.MXB = matrix[3];
  12212. this.MYB = matrix[4];
  12213. this.MZB = matrix[5];
  12214. this.MXC = matrix[6];
  12215. this.MYC = matrix[7];
  12216. this.MZC = matrix[8];
  12217. // Validate variables as per spec.
  12218. if (XW < 0 || ZW < 0 || YW !== 1) {
  12219. error('Invalid WhitePoint components for ' + this.name +
  12220. ', no fallback available');
  12221. }
  12222. if (XB < 0 || YB < 0 || ZB < 0) {
  12223. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  12224. ', ' + ZB + '], falling back to default');
  12225. this.blackPoint = new Float32Array(3);
  12226. }
  12227. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  12228. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  12229. '] for ' + this.name + ', falling back to default');
  12230. this.GR = this.GG = this.GB = 1;
  12231. }
  12232. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  12233. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  12234. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  12235. info('Invalid Matrix for ' + this.name + ' [' +
  12236. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  12237. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  12238. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  12239. '], falling back to default');
  12240. this.MXA = this.MYB = this.MZC = 1;
  12241. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  12242. }
  12243. }
  12244. function matrixProduct(a, b, result) {
  12245. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  12246. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  12247. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  12248. }
  12249. function convertToFlat(sourceWhitePoint, LMS, result) {
  12250. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  12251. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  12252. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  12253. }
  12254. function convertToD65(sourceWhitePoint, LMS, result) {
  12255. var D65X = 0.95047;
  12256. var D65Y = 1;
  12257. var D65Z = 1.08883;
  12258. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  12259. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  12260. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  12261. }
  12262. function sRGBTransferFunction(color) {
  12263. // See http://en.wikipedia.org/wiki/SRGB.
  12264. if (color <= 0.0031308){
  12265. return adjustToRange(0, 1, 12.92 * color);
  12266. }
  12267. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  12268. }
  12269. function adjustToRange(min, max, value) {
  12270. return Math.max(min, Math.min(max, value));
  12271. }
  12272. function decodeL(L) {
  12273. if (L < 0) {
  12274. return -decodeL(-L);
  12275. }
  12276. if (L > 8.0) {
  12277. return Math.pow(((L + 16) / 116), 3);
  12278. }
  12279. return L * DECODE_L_CONSTANT;
  12280. }
  12281. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  12282. // In case the blackPoint is already the default blackPoint then there is
  12283. // no need to do compensation.
  12284. if (sourceBlackPoint[0] === 0 &&
  12285. sourceBlackPoint[1] === 0 &&
  12286. sourceBlackPoint[2] === 0) {
  12287. result[0] = XYZ_Flat[0];
  12288. result[1] = XYZ_Flat[1];
  12289. result[2] = XYZ_Flat[2];
  12290. return;
  12291. }
  12292. // For the blackPoint calculation details, please see
  12293. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12294. // AdobeBPC.pdf.
  12295. // The destination blackPoint is the default blackPoint [0, 0, 0].
  12296. var zeroDecodeL = decodeL(0);
  12297. var X_DST = zeroDecodeL;
  12298. var X_SRC = decodeL(sourceBlackPoint[0]);
  12299. var Y_DST = zeroDecodeL;
  12300. var Y_SRC = decodeL(sourceBlackPoint[1]);
  12301. var Z_DST = zeroDecodeL;
  12302. var Z_SRC = decodeL(sourceBlackPoint[2]);
  12303. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  12304. var X_Offset = 1 - X_Scale;
  12305. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  12306. var Y_Offset = 1 - Y_Scale;
  12307. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  12308. var Z_Offset = 1 - Z_Scale;
  12309. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  12310. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  12311. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  12312. }
  12313. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  12314. // In case the whitePoint is already flat then there is no need to do
  12315. // normalization.
  12316. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  12317. result[0] = XYZ_In[0];
  12318. result[1] = XYZ_In[1];
  12319. result[2] = XYZ_In[2];
  12320. return;
  12321. }
  12322. var LMS = result;
  12323. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12324. var LMS_Flat = tempNormalizeMatrix;
  12325. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  12326. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  12327. }
  12328. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  12329. var LMS = result;
  12330. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12331. var LMS_D65 = tempNormalizeMatrix;
  12332. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  12333. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  12334. }
  12335. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12336. // A, B and C represent a red, green and blue components of a calibrated
  12337. // rgb space.
  12338. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  12339. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  12340. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  12341. // A <---> AGR in the spec
  12342. // B <---> BGG in the spec
  12343. // C <---> CGB in the spec
  12344. var AGR = Math.pow(A, cs.GR);
  12345. var BGG = Math.pow(B, cs.GG);
  12346. var CGB = Math.pow(C, cs.GB);
  12347. // Computes intermediate variables L, M, N as per spec.
  12348. // To decode X, Y, Z values map L, M, N directly to them.
  12349. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  12350. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  12351. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  12352. // The following calculations are based on this document:
  12353. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12354. // AdobeBPC.pdf.
  12355. var XYZ = tempConvertMatrix1;
  12356. XYZ[0] = X;
  12357. XYZ[1] = Y;
  12358. XYZ[2] = Z;
  12359. var XYZ_Flat = tempConvertMatrix2;
  12360. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  12361. var XYZ_Black = tempConvertMatrix1;
  12362. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  12363. var XYZ_D65 = tempConvertMatrix2;
  12364. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  12365. var SRGB = tempConvertMatrix1;
  12366. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  12367. var sR = sRGBTransferFunction(SRGB[0]);
  12368. var sG = sRGBTransferFunction(SRGB[1]);
  12369. var sB = sRGBTransferFunction(SRGB[2]);
  12370. // Convert the values to rgb range [0, 255].
  12371. dest[destOffset] = Math.round(sR * 255);
  12372. dest[destOffset + 1] = Math.round(sG * 255);
  12373. dest[destOffset + 2] = Math.round(sB * 255);
  12374. }
  12375. CalRGBCS.prototype = {
  12376. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  12377. var rgb = new Uint8Array(3);
  12378. this.getRgbItem(src, srcOffset, rgb, 0);
  12379. return rgb;
  12380. },
  12381. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  12382. dest, destOffset) {
  12383. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12384. },
  12385. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  12386. dest, destOffset, bits,
  12387. alpha01) {
  12388. var scale = 1 / ((1 << bits) - 1);
  12389. for (var i = 0; i < count; ++i) {
  12390. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12391. srcOffset += 3;
  12392. destOffset += 3 + alpha01;
  12393. }
  12394. },
  12395. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  12396. return (inputLength * (3 + alpha01) / 3) | 0;
  12397. },
  12398. isPassthrough: ColorSpace.prototype.isPassthrough,
  12399. fillRgb: ColorSpace.prototype.fillRgb,
  12400. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  12401. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12402. },
  12403. usesZeroToOneRange: true
  12404. };
  12405. return CalRGBCS;
  12406. })();
  12407. //
  12408. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  12409. //
  12410. var LabCS = (function LabCSClosure() {
  12411. function LabCS(whitePoint, blackPoint, range) {
  12412. this.name = 'Lab';
  12413. this.numComps = 3;
  12414. this.defaultColor = new Float32Array([0, 0, 0]);
  12415. if (!whitePoint) {
  12416. error('WhitePoint missing - required for color space Lab');
  12417. }
  12418. blackPoint = blackPoint || [0, 0, 0];
  12419. range = range || [-100, 100, -100, 100];
  12420. // Translate args to spec variables
  12421. this.XW = whitePoint[0];
  12422. this.YW = whitePoint[1];
  12423. this.ZW = whitePoint[2];
  12424. this.amin = range[0];
  12425. this.amax = range[1];
  12426. this.bmin = range[2];
  12427. this.bmax = range[3];
  12428. // These are here just for completeness - the spec doesn't offer any
  12429. // formulas that use BlackPoint in Lab
  12430. this.XB = blackPoint[0];
  12431. this.YB = blackPoint[1];
  12432. this.ZB = blackPoint[2];
  12433. // Validate vars as per spec
  12434. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12435. error('Invalid WhitePoint components, no fallback available');
  12436. }
  12437. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12438. info('Invalid BlackPoint, falling back to default');
  12439. this.XB = this.YB = this.ZB = 0;
  12440. }
  12441. if (this.amin > this.amax || this.bmin > this.bmax) {
  12442. info('Invalid Range, falling back to defaults');
  12443. this.amin = -100;
  12444. this.amax = 100;
  12445. this.bmin = -100;
  12446. this.bmax = 100;
  12447. }
  12448. }
  12449. // Function g(x) from spec
  12450. function fn_g(x) {
  12451. if (x >= 6 / 29) {
  12452. return x * x * x;
  12453. } else {
  12454. return (108 / 841) * (x - 4 / 29);
  12455. }
  12456. }
  12457. function decode(value, high1, low2, high2) {
  12458. return low2 + (value) * (high2 - low2) / (high1);
  12459. }
  12460. // If decoding is needed maxVal should be 2^bits per component - 1.
  12461. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  12462. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  12463. // not the usual [0, 1]. If a command like setFillColor is used the src
  12464. // values will already be within the correct range. However, if we are
  12465. // converting an image we have to map the values to the correct range given
  12466. // above.
  12467. // Ls,as,bs <---> L*,a*,b* in the spec
  12468. var Ls = src[srcOffset];
  12469. var as = src[srcOffset + 1];
  12470. var bs = src[srcOffset + 2];
  12471. if (maxVal !== false) {
  12472. Ls = decode(Ls, maxVal, 0, 100);
  12473. as = decode(as, maxVal, cs.amin, cs.amax);
  12474. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  12475. }
  12476. // Adjust limits of 'as' and 'bs'
  12477. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  12478. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  12479. // Computes intermediate variables X,Y,Z as per spec
  12480. var M = (Ls + 16) / 116;
  12481. var L = M + (as / 500);
  12482. var N = M - (bs / 200);
  12483. var X = cs.XW * fn_g(L);
  12484. var Y = cs.YW * fn_g(M);
  12485. var Z = cs.ZW * fn_g(N);
  12486. var r, g, b;
  12487. // Using different conversions for D50 and D65 white points,
  12488. // per http://www.color.org/srgb.pdf
  12489. if (cs.ZW < 1) {
  12490. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  12491. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  12492. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  12493. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  12494. } else {
  12495. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  12496. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  12497. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  12498. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  12499. }
  12500. // clamp color values to [0,1] range then convert to [0,255] range.
  12501. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  12502. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  12503. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  12504. }
  12505. LabCS.prototype = {
  12506. getRgb: ColorSpace.prototype.getRgb,
  12507. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  12508. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  12509. },
  12510. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  12511. dest, destOffset, bits,
  12512. alpha01) {
  12513. var maxVal = (1 << bits) - 1;
  12514. for (var i = 0; i < count; i++) {
  12515. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  12516. srcOffset += 3;
  12517. destOffset += 3 + alpha01;
  12518. }
  12519. },
  12520. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  12521. return (inputLength * (3 + alpha01) / 3) | 0;
  12522. },
  12523. isPassthrough: ColorSpace.prototype.isPassthrough,
  12524. fillRgb: ColorSpace.prototype.fillRgb,
  12525. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  12526. // XXX: Decoding is handled with the lab conversion because of the strange
  12527. // ranges that are used.
  12528. return true;
  12529. },
  12530. usesZeroToOneRange: false
  12531. };
  12532. return LabCS;
  12533. })();
  12534. var ARCFourCipher = (function ARCFourCipherClosure() {
  12535. function ARCFourCipher(key) {
  12536. this.a = 0;
  12537. this.b = 0;
  12538. var s = new Uint8Array(256);
  12539. var i, j = 0, tmp, keyLength = key.length;
  12540. for (i = 0; i < 256; ++i) {
  12541. s[i] = i;
  12542. }
  12543. for (i = 0; i < 256; ++i) {
  12544. tmp = s[i];
  12545. j = (j + tmp + key[i % keyLength]) & 0xFF;
  12546. s[i] = s[j];
  12547. s[j] = tmp;
  12548. }
  12549. this.s = s;
  12550. }
  12551. ARCFourCipher.prototype = {
  12552. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  12553. var i, n = data.length, tmp, tmp2;
  12554. var a = this.a, b = this.b, s = this.s;
  12555. var output = new Uint8Array(n);
  12556. for (i = 0; i < n; ++i) {
  12557. a = (a + 1) & 0xFF;
  12558. tmp = s[a];
  12559. b = (b + tmp) & 0xFF;
  12560. tmp2 = s[b];
  12561. s[a] = tmp2;
  12562. s[b] = tmp;
  12563. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  12564. }
  12565. this.a = a;
  12566. this.b = b;
  12567. return output;
  12568. }
  12569. };
  12570. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  12571. return ARCFourCipher;
  12572. })();
  12573. var calculateMD5 = (function calculateMD5Closure() {
  12574. var r = new Uint8Array([
  12575. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  12576. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  12577. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  12578. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  12579. var k = new Int32Array([
  12580. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  12581. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  12582. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  12583. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  12584. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  12585. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  12586. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  12587. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  12588. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  12589. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  12590. -145523070, -1120210379, 718787259, -343485551]);
  12591. function hash(data, offset, length) {
  12592. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  12593. // pre-processing
  12594. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  12595. var padded = new Uint8Array(paddedLength);
  12596. var i, j, n;
  12597. for (i = 0; i < length; ++i) {
  12598. padded[i] = data[offset++];
  12599. }
  12600. padded[i++] = 0x80;
  12601. n = paddedLength - 8;
  12602. while (i < n) {
  12603. padded[i++] = 0;
  12604. }
  12605. padded[i++] = (length << 3) & 0xFF;
  12606. padded[i++] = (length >> 5) & 0xFF;
  12607. padded[i++] = (length >> 13) & 0xFF;
  12608. padded[i++] = (length >> 21) & 0xFF;
  12609. padded[i++] = (length >>> 29) & 0xFF;
  12610. padded[i++] = 0;
  12611. padded[i++] = 0;
  12612. padded[i++] = 0;
  12613. var w = new Int32Array(16);
  12614. for (i = 0; i < paddedLength;) {
  12615. for (j = 0; j < 16; ++j, i += 4) {
  12616. w[j] = (padded[i] | (padded[i + 1] << 8) |
  12617. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  12618. }
  12619. var a = h0, b = h1, c = h2, d = h3, f, g;
  12620. for (j = 0; j < 64; ++j) {
  12621. if (j < 16) {
  12622. f = (b & c) | ((~b) & d);
  12623. g = j;
  12624. } else if (j < 32) {
  12625. f = (d & b) | ((~d) & c);
  12626. g = (5 * j + 1) & 15;
  12627. } else if (j < 48) {
  12628. f = b ^ c ^ d;
  12629. g = (3 * j + 5) & 15;
  12630. } else {
  12631. f = c ^ (b | (~d));
  12632. g = (7 * j) & 15;
  12633. }
  12634. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  12635. d = c;
  12636. c = b;
  12637. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  12638. a = tmp;
  12639. }
  12640. h0 = (h0 + a) | 0;
  12641. h1 = (h1 + b) | 0;
  12642. h2 = (h2 + c) | 0;
  12643. h3 = (h3 + d) | 0;
  12644. }
  12645. return new Uint8Array([
  12646. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  12647. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  12648. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  12649. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  12650. ]);
  12651. }
  12652. return hash;
  12653. })();
  12654. var Word64 = (function Word64Closure() {
  12655. function Word64(highInteger, lowInteger) {
  12656. this.high = highInteger | 0;
  12657. this.low = lowInteger | 0;
  12658. }
  12659. Word64.prototype = {
  12660. and: function Word64_and(word) {
  12661. this.high &= word.high;
  12662. this.low &= word.low;
  12663. },
  12664. xor: function Word64_xor(word) {
  12665. this.high ^= word.high;
  12666. this.low ^= word.low;
  12667. },
  12668. or: function Word64_or(word) {
  12669. this.high |= word.high;
  12670. this.low |= word.low;
  12671. },
  12672. shiftRight: function Word64_shiftRight(places) {
  12673. if (places >= 32) {
  12674. this.low = (this.high >>> (places - 32)) | 0;
  12675. this.high = 0;
  12676. } else {
  12677. this.low = (this.low >>> places) | (this.high << (32 - places));
  12678. this.high = (this.high >>> places) | 0;
  12679. }
  12680. },
  12681. shiftLeft: function Word64_shiftLeft(places) {
  12682. if (places >= 32) {
  12683. this.high = this.low << (places - 32);
  12684. this.low = 0;
  12685. } else {
  12686. this.high = (this.high << places) | (this.low >>> (32 - places));
  12687. this.low = this.low << places;
  12688. }
  12689. },
  12690. rotateRight: function Word64_rotateRight(places) {
  12691. var low, high;
  12692. if (places & 32) {
  12693. high = this.low;
  12694. low = this.high;
  12695. } else {
  12696. low = this.low;
  12697. high = this.high;
  12698. }
  12699. places &= 31;
  12700. this.low = (low >>> places) | (high << (32 - places));
  12701. this.high = (high >>> places) | (low << (32 - places));
  12702. },
  12703. not: function Word64_not() {
  12704. this.high = ~this.high;
  12705. this.low = ~this.low;
  12706. },
  12707. add: function Word64_add(word) {
  12708. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  12709. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  12710. if (lowAdd > 0xFFFFFFFF) {
  12711. highAdd += 1;
  12712. }
  12713. this.low = lowAdd | 0;
  12714. this.high = highAdd | 0;
  12715. },
  12716. copyTo: function Word64_copyTo(bytes, offset) {
  12717. bytes[offset] = (this.high >>> 24) & 0xFF;
  12718. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  12719. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  12720. bytes[offset + 3] = this.high & 0xFF;
  12721. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  12722. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  12723. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  12724. bytes[offset + 7] = this.low & 0xFF;
  12725. },
  12726. assign: function Word64_assign(word) {
  12727. this.high = word.high;
  12728. this.low = word.low;
  12729. }
  12730. };
  12731. return Word64;
  12732. })();
  12733. var calculateSHA256 = (function calculateSHA256Closure() {
  12734. function rotr(x, n) {
  12735. return (x >>> n) | (x << 32 - n);
  12736. }
  12737. function ch(x, y, z) {
  12738. return (x & y) ^ (~x & z);
  12739. }
  12740. function maj(x, y, z) {
  12741. return (x & y) ^ (x & z) ^ (y & z);
  12742. }
  12743. function sigma(x) {
  12744. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  12745. }
  12746. function sigmaPrime(x) {
  12747. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  12748. }
  12749. function littleSigma(x) {
  12750. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  12751. }
  12752. function littleSigmaPrime(x) {
  12753. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  12754. }
  12755. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  12756. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  12757. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  12758. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  12759. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  12760. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  12761. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  12762. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  12763. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  12764. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  12765. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  12766. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  12767. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  12768. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  12769. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  12770. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  12771. function hash(data, offset, length) {
  12772. // initial hash values
  12773. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  12774. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  12775. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  12776. // pre-processing
  12777. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  12778. var padded = new Uint8Array(paddedLength);
  12779. var i, j, n;
  12780. for (i = 0; i < length; ++i) {
  12781. padded[i] = data[offset++];
  12782. }
  12783. padded[i++] = 0x80;
  12784. n = paddedLength - 8;
  12785. while (i < n) {
  12786. padded[i++] = 0;
  12787. }
  12788. padded[i++] = 0;
  12789. padded[i++] = 0;
  12790. padded[i++] = 0;
  12791. padded[i++] = (length >>> 29) & 0xFF;
  12792. padded[i++] = (length >> 21) & 0xFF;
  12793. padded[i++] = (length >> 13) & 0xFF;
  12794. padded[i++] = (length >> 5) & 0xFF;
  12795. padded[i++] = (length << 3) & 0xFF;
  12796. var w = new Uint32Array(64);
  12797. // for each 512 bit block
  12798. for (i = 0; i < paddedLength;) {
  12799. for (j = 0; j < 16; ++j) {
  12800. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  12801. (padded[i + 2] << 8) | (padded[i + 3]));
  12802. i += 4;
  12803. }
  12804. for (j = 16; j < 64; ++j) {
  12805. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  12806. littleSigma(w[j - 15]) + w[j - 16] | 0;
  12807. }
  12808. var a = h0, b = h1, c = h2, d = h3, e = h4,
  12809. f = h5, g = h6, h = h7, t1, t2;
  12810. for (j = 0; j < 64; ++j) {
  12811. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  12812. t2 = sigma(a) + maj(a, b, c);
  12813. h = g;
  12814. g = f;
  12815. f = e;
  12816. e = (d + t1) | 0;
  12817. d = c;
  12818. c = b;
  12819. b = a;
  12820. a = (t1 + t2) | 0;
  12821. }
  12822. h0 = (h0 + a) | 0;
  12823. h1 = (h1 + b) | 0;
  12824. h2 = (h2 + c) | 0;
  12825. h3 = (h3 + d) | 0;
  12826. h4 = (h4 + e) | 0;
  12827. h5 = (h5 + f) | 0;
  12828. h6 = (h6 + g) | 0;
  12829. h7 = (h7 + h) | 0;
  12830. }
  12831. return new Uint8Array([
  12832. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  12833. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  12834. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  12835. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  12836. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  12837. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  12838. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  12839. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  12840. ]);
  12841. }
  12842. return hash;
  12843. })();
  12844. var calculateSHA512 = (function calculateSHA512Closure() {
  12845. function ch(result, x, y, z, tmp) {
  12846. result.assign(x);
  12847. result.and(y);
  12848. tmp.assign(x);
  12849. tmp.not();
  12850. tmp.and(z);
  12851. result.xor(tmp);
  12852. }
  12853. function maj(result, x, y, z, tmp) {
  12854. result.assign(x);
  12855. result.and(y);
  12856. tmp.assign(x);
  12857. tmp.and(z);
  12858. result.xor(tmp);
  12859. tmp.assign(y);
  12860. tmp.and(z);
  12861. result.xor(tmp);
  12862. }
  12863. function sigma(result, x, tmp) {
  12864. result.assign(x);
  12865. result.rotateRight(28);
  12866. tmp.assign(x);
  12867. tmp.rotateRight(34);
  12868. result.xor(tmp);
  12869. tmp.assign(x);
  12870. tmp.rotateRight(39);
  12871. result.xor(tmp);
  12872. }
  12873. function sigmaPrime(result, x, tmp) {
  12874. result.assign(x);
  12875. result.rotateRight(14);
  12876. tmp.assign(x);
  12877. tmp.rotateRight(18);
  12878. result.xor(tmp);
  12879. tmp.assign(x);
  12880. tmp.rotateRight(41);
  12881. result.xor(tmp);
  12882. }
  12883. function littleSigma(result, x, tmp) {
  12884. result.assign(x);
  12885. result.rotateRight(1);
  12886. tmp.assign(x);
  12887. tmp.rotateRight(8);
  12888. result.xor(tmp);
  12889. tmp.assign(x);
  12890. tmp.shiftRight(7);
  12891. result.xor(tmp);
  12892. }
  12893. function littleSigmaPrime(result, x, tmp) {
  12894. result.assign(x);
  12895. result.rotateRight(19);
  12896. tmp.assign(x);
  12897. tmp.rotateRight(61);
  12898. result.xor(tmp);
  12899. tmp.assign(x);
  12900. tmp.shiftRight(6);
  12901. result.xor(tmp);
  12902. }
  12903. var k = [
  12904. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  12905. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  12906. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  12907. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  12908. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  12909. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  12910. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  12911. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  12912. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  12913. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  12914. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  12915. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  12916. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  12917. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  12918. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  12919. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  12920. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  12921. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  12922. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  12923. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  12924. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  12925. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  12926. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  12927. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  12928. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  12929. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  12930. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  12931. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  12932. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  12933. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  12934. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  12935. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  12936. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  12937. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  12938. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  12939. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  12940. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  12941. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  12942. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  12943. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  12944. function hash(data, offset, length, mode384) {
  12945. mode384 = !!mode384;
  12946. // initial hash values
  12947. var h0, h1, h2, h3, h4, h5, h6, h7;
  12948. if (!mode384) {
  12949. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  12950. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  12951. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  12952. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  12953. h4 = new Word64(0x510e527f, 0xade682d1);
  12954. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  12955. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  12956. h7 = new Word64(0x5be0cd19, 0x137e2179);
  12957. }
  12958. else {
  12959. // SHA384 is exactly the same
  12960. // except with different starting values and a trimmed result
  12961. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  12962. h1 = new Word64(0x629a292a, 0x367cd507);
  12963. h2 = new Word64(0x9159015a, 0x3070dd17);
  12964. h3 = new Word64(0x152fecd8, 0xf70e5939);
  12965. h4 = new Word64(0x67332667, 0xffc00b31);
  12966. h5 = new Word64(0x8eb44a87, 0x68581511);
  12967. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  12968. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  12969. }
  12970. // pre-processing
  12971. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  12972. var padded = new Uint8Array(paddedLength);
  12973. var i, j, n;
  12974. for (i = 0; i < length; ++i) {
  12975. padded[i] = data[offset++];
  12976. }
  12977. padded[i++] = 0x80;
  12978. n = paddedLength - 16;
  12979. while (i < n) {
  12980. padded[i++] = 0;
  12981. }
  12982. padded[i++] = 0;
  12983. padded[i++] = 0;
  12984. padded[i++] = 0;
  12985. padded[i++] = 0;
  12986. padded[i++] = 0;
  12987. padded[i++] = 0;
  12988. padded[i++] = 0;
  12989. padded[i++] = 0;
  12990. padded[i++] = 0;
  12991. padded[i++] = 0;
  12992. padded[i++] = 0;
  12993. padded[i++] = (length >>> 29) & 0xFF;
  12994. padded[i++] = (length >> 21) & 0xFF;
  12995. padded[i++] = (length >> 13) & 0xFF;
  12996. padded[i++] = (length >> 5) & 0xFF;
  12997. padded[i++] = (length << 3) & 0xFF;
  12998. var w = new Array(80);
  12999. for (i = 0; i < 80; i++) {
  13000. w[i] = new Word64(0, 0);
  13001. }
  13002. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  13003. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  13004. var g = new Word64(0, 0), h = new Word64(0, 0);
  13005. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  13006. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  13007. // for each 1024 bit block
  13008. for (i = 0; i < paddedLength;) {
  13009. for (j = 0; j < 16; ++j) {
  13010. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  13011. (padded[i + 2] << 8) | (padded[i + 3]);
  13012. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  13013. (padded[i + 6]) << 8 | (padded[i + 7]);
  13014. i += 8;
  13015. }
  13016. for (j = 16; j < 80; ++j) {
  13017. tmp3 = w[j];
  13018. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  13019. tmp3.add(w[j - 7]);
  13020. littleSigma(tmp1, w[j - 15], tmp2);
  13021. tmp3.add(tmp1);
  13022. tmp3.add(w[j - 16]);
  13023. }
  13024. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  13025. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  13026. for (j = 0; j < 80; ++j) {
  13027. t1.assign(h);
  13028. sigmaPrime(tmp1, e, tmp2);
  13029. t1.add(tmp1);
  13030. ch(tmp1, e, f, g, tmp2);
  13031. t1.add(tmp1);
  13032. t1.add(k[j]);
  13033. t1.add(w[j]);
  13034. sigma(t2, a, tmp2);
  13035. maj(tmp1, a, b, c, tmp2);
  13036. t2.add(tmp1);
  13037. tmp3 = h;
  13038. h = g;
  13039. g = f;
  13040. f = e;
  13041. d.add(t1);
  13042. e = d;
  13043. d = c;
  13044. c = b;
  13045. b = a;
  13046. tmp3.assign(t1);
  13047. tmp3.add(t2);
  13048. a = tmp3;
  13049. }
  13050. h0.add(a);
  13051. h1.add(b);
  13052. h2.add(c);
  13053. h3.add(d);
  13054. h4.add(e);
  13055. h5.add(f);
  13056. h6.add(g);
  13057. h7.add(h);
  13058. }
  13059. var result;
  13060. if (!mode384) {
  13061. result = new Uint8Array(64);
  13062. h0.copyTo(result,0);
  13063. h1.copyTo(result,8);
  13064. h2.copyTo(result,16);
  13065. h3.copyTo(result,24);
  13066. h4.copyTo(result,32);
  13067. h5.copyTo(result,40);
  13068. h6.copyTo(result,48);
  13069. h7.copyTo(result,56);
  13070. }
  13071. else {
  13072. result = new Uint8Array(48);
  13073. h0.copyTo(result,0);
  13074. h1.copyTo(result,8);
  13075. h2.copyTo(result,16);
  13076. h3.copyTo(result,24);
  13077. h4.copyTo(result,32);
  13078. h5.copyTo(result,40);
  13079. }
  13080. return result;
  13081. }
  13082. return hash;
  13083. })();
  13084. var calculateSHA384 = (function calculateSHA384Closure() {
  13085. function hash(data, offset, length) {
  13086. return calculateSHA512(data, offset, length, true);
  13087. }
  13088. return hash;
  13089. })();
  13090. var NullCipher = (function NullCipherClosure() {
  13091. function NullCipher() {
  13092. }
  13093. NullCipher.prototype = {
  13094. decryptBlock: function NullCipher_decryptBlock(data) {
  13095. return data;
  13096. }
  13097. };
  13098. return NullCipher;
  13099. })();
  13100. var AES128Cipher = (function AES128CipherClosure() {
  13101. var rcon = new Uint8Array([
  13102. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13103. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13104. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13105. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13106. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13107. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13108. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13109. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13110. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13111. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13112. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13113. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13114. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13115. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13116. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13117. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13118. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13119. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13120. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13121. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13122. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13123. 0x74, 0xe8, 0xcb, 0x8d]);
  13124. var s = new Uint8Array([
  13125. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13126. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13127. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13128. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13129. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13130. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13131. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13132. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13133. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13134. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13135. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13136. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13137. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13138. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13139. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13140. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13141. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13142. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13143. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13144. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13145. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13146. 0xb0, 0x54, 0xbb, 0x16]);
  13147. var inv_s = new Uint8Array([
  13148. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13149. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13150. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13151. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13152. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13153. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13154. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13155. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13156. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13157. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13158. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13159. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13160. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13161. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13162. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13163. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13164. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13165. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13166. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13167. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13168. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13169. 0x55, 0x21, 0x0c, 0x7d]);
  13170. var mixCol = new Uint8Array(256);
  13171. for (var i = 0; i < 256; i++) {
  13172. if (i < 128) {
  13173. mixCol[i] = i << 1;
  13174. } else {
  13175. mixCol[i] = (i << 1) ^ 0x1b;
  13176. }
  13177. }
  13178. var mix = new Uint32Array([
  13179. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13180. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13181. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13182. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13183. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13184. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13185. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13186. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13187. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13188. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13189. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13190. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13191. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13192. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13193. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13194. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13195. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13196. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13197. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13198. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13199. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13200. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13201. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13202. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13203. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13204. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13205. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13206. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13207. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13208. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13209. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13210. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13211. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13212. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13213. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13214. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13215. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13216. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13217. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13218. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13219. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13220. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13221. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13222. function expandKey128(cipherKey) {
  13223. var b = 176, result = new Uint8Array(b);
  13224. result.set(cipherKey);
  13225. for (var j = 16, i = 1; j < b; ++i) {
  13226. // RotWord
  13227. var t1 = result[j - 3], t2 = result[j - 2],
  13228. t3 = result[j - 1], t4 = result[j - 4];
  13229. // SubWord
  13230. t1 = s[t1];
  13231. t2 = s[t2];
  13232. t3 = s[t3];
  13233. t4 = s[t4];
  13234. // Rcon
  13235. t1 = t1 ^ rcon[i];
  13236. for (var n = 0; n < 4; ++n) {
  13237. result[j] = (t1 ^= result[j - 16]);
  13238. j++;
  13239. result[j] = (t2 ^= result[j - 16]);
  13240. j++;
  13241. result[j] = (t3 ^= result[j - 16]);
  13242. j++;
  13243. result[j] = (t4 ^= result[j - 16]);
  13244. j++;
  13245. }
  13246. }
  13247. return result;
  13248. }
  13249. function decrypt128(input, key) {
  13250. var state = new Uint8Array(16);
  13251. state.set(input);
  13252. var i, j, k;
  13253. var t, u, v;
  13254. // AddRoundKey
  13255. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13256. state[j] ^= key[k];
  13257. }
  13258. for (i = 9; i >= 1; --i) {
  13259. // InvShiftRows
  13260. t = state[13];
  13261. state[13] = state[9];
  13262. state[9] = state[5];
  13263. state[5] = state[1];
  13264. state[1] = t;
  13265. t = state[14];
  13266. u = state[10];
  13267. state[14] = state[6];
  13268. state[10] = state[2];
  13269. state[6] = t;
  13270. state[2] = u;
  13271. t = state[15];
  13272. u = state[11];
  13273. v = state[7];
  13274. state[15] = state[3];
  13275. state[11] = t;
  13276. state[7] = u;
  13277. state[3] = v;
  13278. // InvSubBytes
  13279. for (j = 0; j < 16; ++j) {
  13280. state[j] = inv_s[state[j]];
  13281. }
  13282. // AddRoundKey
  13283. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13284. state[j] ^= key[k];
  13285. }
  13286. // InvMixColumns
  13287. for (j = 0; j < 16; j += 4) {
  13288. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13289. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13290. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13291. (s3 >>> 24) ^ (s3 << 8));
  13292. state[j] = (t >>> 24) & 0xFF;
  13293. state[j + 1] = (t >> 16) & 0xFF;
  13294. state[j + 2] = (t >> 8) & 0xFF;
  13295. state[j + 3] = t & 0xFF;
  13296. }
  13297. }
  13298. // InvShiftRows
  13299. t = state[13];
  13300. state[13] = state[9];
  13301. state[9] = state[5];
  13302. state[5] = state[1];
  13303. state[1] = t;
  13304. t = state[14];
  13305. u = state[10];
  13306. state[14] = state[6];
  13307. state[10] = state[2];
  13308. state[6] = t;
  13309. state[2] = u;
  13310. t = state[15];
  13311. u = state[11];
  13312. v = state[7];
  13313. state[15] = state[3];
  13314. state[11] = t;
  13315. state[7] = u;
  13316. state[3] = v;
  13317. for (j = 0; j < 16; ++j) {
  13318. // InvSubBytes
  13319. state[j] = inv_s[state[j]];
  13320. // AddRoundKey
  13321. state[j] ^= key[j];
  13322. }
  13323. return state;
  13324. }
  13325. function encrypt128(input, key) {
  13326. var t, u, v, k;
  13327. var state = new Uint8Array(16);
  13328. state.set(input);
  13329. for (j = 0; j < 16; ++j) {
  13330. // AddRoundKey
  13331. state[j] ^= key[j];
  13332. }
  13333. for (i = 1; i < 10; i++) {
  13334. //SubBytes
  13335. for (j = 0; j < 16; ++j) {
  13336. state[j] = s[state[j]];
  13337. }
  13338. //ShiftRows
  13339. v = state[1];
  13340. state[1] = state[5];
  13341. state[5] = state[9];
  13342. state[9] = state[13];
  13343. state[13] = v;
  13344. v = state[2];
  13345. u = state[6];
  13346. state[2] = state[10];
  13347. state[6] = state[14];
  13348. state[10] = v;
  13349. state[14] = u;
  13350. v = state[3];
  13351. u = state[7];
  13352. t = state[11];
  13353. state[3] = state[15];
  13354. state[7] = v;
  13355. state[11] = u;
  13356. state[15] = t;
  13357. //MixColumns
  13358. for (var j = 0; j < 16; j += 4) {
  13359. var s0 = state[j + 0], s1 = state[j + 1];
  13360. var s2 = state[j + 2], s3 = state[j + 3];
  13361. t = s0 ^ s1 ^ s2 ^ s3;
  13362. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13363. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13364. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13365. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13366. }
  13367. //AddRoundKey
  13368. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13369. state[j] ^= key[k];
  13370. }
  13371. }
  13372. //SubBytes
  13373. for (j = 0; j < 16; ++j) {
  13374. state[j] = s[state[j]];
  13375. }
  13376. //ShiftRows
  13377. v = state[1];
  13378. state[1] = state[5];
  13379. state[5] = state[9];
  13380. state[9] = state[13];
  13381. state[13] = v;
  13382. v = state[2];
  13383. u = state[6];
  13384. state[2] = state[10];
  13385. state[6] = state[14];
  13386. state[10] = v;
  13387. state[14] = u;
  13388. v = state[3];
  13389. u = state[7];
  13390. t = state[11];
  13391. state[3] = state[15];
  13392. state[7] = v;
  13393. state[11] = u;
  13394. state[15] = t;
  13395. //AddRoundKey
  13396. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13397. state[j] ^= key[k];
  13398. }
  13399. return state;
  13400. }
  13401. function AES128Cipher(key) {
  13402. this.key = expandKey128(key);
  13403. this.buffer = new Uint8Array(16);
  13404. this.bufferPosition = 0;
  13405. }
  13406. function decryptBlock2(data, finalize) {
  13407. var i, j, ii, sourceLength = data.length,
  13408. buffer = this.buffer, bufferLength = this.bufferPosition,
  13409. result = [], iv = this.iv;
  13410. for (i = 0; i < sourceLength; ++i) {
  13411. buffer[bufferLength] = data[i];
  13412. ++bufferLength;
  13413. if (bufferLength < 16) {
  13414. continue;
  13415. }
  13416. // buffer is full, decrypting
  13417. var plain = decrypt128(buffer, this.key);
  13418. // xor-ing the IV vector to get plain text
  13419. for (j = 0; j < 16; ++j) {
  13420. plain[j] ^= iv[j];
  13421. }
  13422. iv = buffer;
  13423. result.push(plain);
  13424. buffer = new Uint8Array(16);
  13425. bufferLength = 0;
  13426. }
  13427. // saving incomplete buffer
  13428. this.buffer = buffer;
  13429. this.bufferLength = bufferLength;
  13430. this.iv = iv;
  13431. if (result.length === 0) {
  13432. return new Uint8Array([]);
  13433. }
  13434. // combining plain text blocks into one
  13435. var outputLength = 16 * result.length;
  13436. if (finalize) {
  13437. // undo a padding that is described in RFC 2898
  13438. var lastBlock = result[result.length - 1];
  13439. var psLen = lastBlock[15];
  13440. if (psLen <= 16) {
  13441. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13442. if (lastBlock[i] !== psLen) {
  13443. // Invalid padding, assume that the block has no padding.
  13444. psLen = 0;
  13445. break;
  13446. }
  13447. }
  13448. outputLength -= psLen;
  13449. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13450. }
  13451. }
  13452. var output = new Uint8Array(outputLength);
  13453. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13454. output.set(result[i], j);
  13455. }
  13456. return output;
  13457. }
  13458. AES128Cipher.prototype = {
  13459. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  13460. var i, sourceLength = data.length;
  13461. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13462. // waiting for IV values -- they are at the start of the stream
  13463. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  13464. buffer[bufferLength] = data[i];
  13465. }
  13466. if (bufferLength < 16) {
  13467. // need more data
  13468. this.bufferLength = bufferLength;
  13469. return new Uint8Array([]);
  13470. }
  13471. this.iv = buffer;
  13472. this.buffer = new Uint8Array(16);
  13473. this.bufferLength = 0;
  13474. // starting decryption
  13475. this.decryptBlock = decryptBlock2;
  13476. return this.decryptBlock(data.subarray(16), finalize);
  13477. },
  13478. encrypt: function AES128Cipher_encrypt(data, iv) {
  13479. var i, j, ii, sourceLength = data.length,
  13480. buffer = this.buffer, bufferLength = this.bufferPosition,
  13481. result = [];
  13482. if (!iv) {
  13483. iv = new Uint8Array(16);
  13484. }
  13485. for (i = 0; i < sourceLength; ++i) {
  13486. buffer[bufferLength] = data[i];
  13487. ++bufferLength;
  13488. if (bufferLength < 16) {
  13489. continue;
  13490. }
  13491. for (j = 0; j < 16; ++j) {
  13492. buffer[j] ^= iv[j];
  13493. }
  13494. // buffer is full, encrypting
  13495. var cipher = encrypt128(buffer, this.key);
  13496. iv = cipher;
  13497. result.push(cipher);
  13498. buffer = new Uint8Array(16);
  13499. bufferLength = 0;
  13500. }
  13501. // saving incomplete buffer
  13502. this.buffer = buffer;
  13503. this.bufferLength = bufferLength;
  13504. this.iv = iv;
  13505. if (result.length === 0) {
  13506. return new Uint8Array([]);
  13507. }
  13508. // combining plain text blocks into one
  13509. var outputLength = 16 * result.length;
  13510. var output = new Uint8Array(outputLength);
  13511. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13512. output.set(result[i], j);
  13513. }
  13514. return output;
  13515. }
  13516. };
  13517. return AES128Cipher;
  13518. })();
  13519. var AES256Cipher = (function AES256CipherClosure() {
  13520. var rcon = new Uint8Array([
  13521. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13522. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13523. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13524. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13525. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13526. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13527. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13528. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13529. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13530. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13531. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13532. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13533. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13534. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13535. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13536. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13537. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13538. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13539. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13540. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13541. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13542. 0x74, 0xe8, 0xcb, 0x8d]);
  13543. var s = new Uint8Array([
  13544. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13545. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13546. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13547. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13548. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13549. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13550. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13551. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13552. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13553. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13554. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13555. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13556. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13557. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13558. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13559. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13560. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13561. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13562. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13563. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13564. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13565. 0xb0, 0x54, 0xbb, 0x16]);
  13566. var inv_s = new Uint8Array([
  13567. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13568. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13569. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13570. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13571. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13572. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13573. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13574. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13575. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13576. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13577. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13578. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13579. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13580. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13581. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13582. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13583. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13584. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13585. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13586. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13587. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13588. 0x55, 0x21, 0x0c, 0x7d]);
  13589. var mixCol = new Uint8Array(256);
  13590. for (var i = 0; i < 256; i++) {
  13591. if (i < 128) {
  13592. mixCol[i] = i << 1;
  13593. } else {
  13594. mixCol[i] = (i << 1) ^ 0x1b;
  13595. }
  13596. }
  13597. var mix = new Uint32Array([
  13598. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13599. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13600. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13601. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13602. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13603. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13604. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13605. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13606. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13607. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13608. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13609. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13610. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13611. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13612. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13613. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13614. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13615. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13616. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13617. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13618. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13619. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13620. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13621. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13622. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13623. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13624. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13625. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13626. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13627. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13628. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13629. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13630. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13631. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13632. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13633. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13634. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13635. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13636. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13637. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13638. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13639. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13640. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13641. function expandKey256(cipherKey) {
  13642. var b = 240, result = new Uint8Array(b);
  13643. var r = 1;
  13644. result.set(cipherKey);
  13645. for (var j = 32, i = 1; j < b; ++i) {
  13646. if (j % 32 === 16) {
  13647. t1 = s[t1];
  13648. t2 = s[t2];
  13649. t3 = s[t3];
  13650. t4 = s[t4];
  13651. } else if (j % 32 === 0) {
  13652. // RotWord
  13653. var t1 = result[j - 3], t2 = result[j - 2],
  13654. t3 = result[j - 1], t4 = result[j - 4];
  13655. // SubWord
  13656. t1 = s[t1];
  13657. t2 = s[t2];
  13658. t3 = s[t3];
  13659. t4 = s[t4];
  13660. // Rcon
  13661. t1 = t1 ^ r;
  13662. if ((r <<= 1) >= 256) {
  13663. r = (r ^ 0x1b) & 0xFF;
  13664. }
  13665. }
  13666. for (var n = 0; n < 4; ++n) {
  13667. result[j] = (t1 ^= result[j - 32]);
  13668. j++;
  13669. result[j] = (t2 ^= result[j - 32]);
  13670. j++;
  13671. result[j] = (t3 ^= result[j - 32]);
  13672. j++;
  13673. result[j] = (t4 ^= result[j - 32]);
  13674. j++;
  13675. }
  13676. }
  13677. return result;
  13678. }
  13679. function decrypt256(input, key) {
  13680. var state = new Uint8Array(16);
  13681. state.set(input);
  13682. var i, j, k;
  13683. var t, u, v;
  13684. // AddRoundKey
  13685. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13686. state[j] ^= key[k];
  13687. }
  13688. for (i = 13; i >= 1; --i) {
  13689. // InvShiftRows
  13690. t = state[13];
  13691. state[13] = state[9];
  13692. state[9] = state[5];
  13693. state[5] = state[1];
  13694. state[1] = t;
  13695. t = state[14];
  13696. u = state[10];
  13697. state[14] = state[6];
  13698. state[10] = state[2];
  13699. state[6] = t;
  13700. state[2] = u;
  13701. t = state[15];
  13702. u = state[11];
  13703. v = state[7];
  13704. state[15] = state[3];
  13705. state[11] = t;
  13706. state[7] = u;
  13707. state[3] = v;
  13708. // InvSubBytes
  13709. for (j = 0; j < 16; ++j) {
  13710. state[j] = inv_s[state[j]];
  13711. }
  13712. // AddRoundKey
  13713. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13714. state[j] ^= key[k];
  13715. }
  13716. // InvMixColumns
  13717. for (j = 0; j < 16; j += 4) {
  13718. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13719. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13720. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13721. (s3 >>> 24) ^ (s3 << 8));
  13722. state[j] = (t >>> 24) & 0xFF;
  13723. state[j + 1] = (t >> 16) & 0xFF;
  13724. state[j + 2] = (t >> 8) & 0xFF;
  13725. state[j + 3] = t & 0xFF;
  13726. }
  13727. }
  13728. // InvShiftRows
  13729. t = state[13];
  13730. state[13] = state[9];
  13731. state[9] = state[5];
  13732. state[5] = state[1];
  13733. state[1] = t;
  13734. t = state[14];
  13735. u = state[10];
  13736. state[14] = state[6];
  13737. state[10] = state[2];
  13738. state[6] = t;
  13739. state[2] = u;
  13740. t = state[15];
  13741. u = state[11];
  13742. v = state[7];
  13743. state[15] = state[3];
  13744. state[11] = t;
  13745. state[7] = u;
  13746. state[3] = v;
  13747. for (j = 0; j < 16; ++j) {
  13748. // InvSubBytes
  13749. state[j] = inv_s[state[j]];
  13750. // AddRoundKey
  13751. state[j] ^= key[j];
  13752. }
  13753. return state;
  13754. }
  13755. function encrypt256(input, key) {
  13756. var t, u, v, k;
  13757. var state = new Uint8Array(16);
  13758. state.set(input);
  13759. for (j = 0; j < 16; ++j) {
  13760. // AddRoundKey
  13761. state[j] ^= key[j];
  13762. }
  13763. for (i = 1; i < 14; i++) {
  13764. //SubBytes
  13765. for (j = 0; j < 16; ++j) {
  13766. state[j] = s[state[j]];
  13767. }
  13768. //ShiftRows
  13769. v = state[1];
  13770. state[1] = state[5];
  13771. state[5] = state[9];
  13772. state[9] = state[13];
  13773. state[13] = v;
  13774. v = state[2];
  13775. u = state[6];
  13776. state[2] = state[10];
  13777. state[6] = state[14];
  13778. state[10] = v;
  13779. state[14] = u;
  13780. v = state[3];
  13781. u = state[7];
  13782. t = state[11];
  13783. state[3] = state[15];
  13784. state[7] = v;
  13785. state[11] = u;
  13786. state[15] = t;
  13787. //MixColumns
  13788. for (var j = 0; j < 16; j += 4) {
  13789. var s0 = state[j + 0], s1 = state[j + 1];
  13790. var s2 = state[j + 2], s3 = state[j + 3];
  13791. t = s0 ^ s1 ^ s2 ^ s3;
  13792. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13793. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13794. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13795. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13796. }
  13797. //AddRoundKey
  13798. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13799. state[j] ^= key[k];
  13800. }
  13801. }
  13802. //SubBytes
  13803. for (j = 0; j < 16; ++j) {
  13804. state[j] = s[state[j]];
  13805. }
  13806. //ShiftRows
  13807. v = state[1];
  13808. state[1] = state[5];
  13809. state[5] = state[9];
  13810. state[9] = state[13];
  13811. state[13] = v;
  13812. v = state[2];
  13813. u = state[6];
  13814. state[2] = state[10];
  13815. state[6] = state[14];
  13816. state[10] = v;
  13817. state[14] = u;
  13818. v = state[3];
  13819. u = state[7];
  13820. t = state[11];
  13821. state[3] = state[15];
  13822. state[7] = v;
  13823. state[11] = u;
  13824. state[15] = t;
  13825. //AddRoundKey
  13826. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13827. state[j] ^= key[k];
  13828. }
  13829. return state;
  13830. }
  13831. function AES256Cipher(key) {
  13832. this.key = expandKey256(key);
  13833. this.buffer = new Uint8Array(16);
  13834. this.bufferPosition = 0;
  13835. }
  13836. function decryptBlock2(data, finalize) {
  13837. var i, j, ii, sourceLength = data.length,
  13838. buffer = this.buffer, bufferLength = this.bufferPosition,
  13839. result = [], iv = this.iv;
  13840. for (i = 0; i < sourceLength; ++i) {
  13841. buffer[bufferLength] = data[i];
  13842. ++bufferLength;
  13843. if (bufferLength < 16) {
  13844. continue;
  13845. }
  13846. // buffer is full, decrypting
  13847. var plain = decrypt256(buffer, this.key);
  13848. // xor-ing the IV vector to get plain text
  13849. for (j = 0; j < 16; ++j) {
  13850. plain[j] ^= iv[j];
  13851. }
  13852. iv = buffer;
  13853. result.push(plain);
  13854. buffer = new Uint8Array(16);
  13855. bufferLength = 0;
  13856. }
  13857. // saving incomplete buffer
  13858. this.buffer = buffer;
  13859. this.bufferLength = bufferLength;
  13860. this.iv = iv;
  13861. if (result.length === 0) {
  13862. return new Uint8Array([]);
  13863. }
  13864. // combining plain text blocks into one
  13865. var outputLength = 16 * result.length;
  13866. if (finalize) {
  13867. // undo a padding that is described in RFC 2898
  13868. var lastBlock = result[result.length - 1];
  13869. var psLen = lastBlock[15];
  13870. if (psLen <= 16) {
  13871. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13872. if (lastBlock[i] !== psLen) {
  13873. // Invalid padding, assume that the block has no padding.
  13874. psLen = 0;
  13875. break;
  13876. }
  13877. }
  13878. outputLength -= psLen;
  13879. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13880. }
  13881. }
  13882. var output = new Uint8Array(outputLength);
  13883. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13884. output.set(result[i], j);
  13885. }
  13886. return output;
  13887. }
  13888. AES256Cipher.prototype = {
  13889. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  13890. var i, sourceLength = data.length;
  13891. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13892. // if not supplied an IV wait for IV values
  13893. // they are at the start of the stream
  13894. if (iv) {
  13895. this.iv = iv;
  13896. } else {
  13897. for (i = 0; bufferLength < 16 &&
  13898. i < sourceLength; ++i, ++bufferLength) {
  13899. buffer[bufferLength] = data[i];
  13900. }
  13901. if (bufferLength < 16) {
  13902. //need more data
  13903. this.bufferLength = bufferLength;
  13904. return new Uint8Array([]);
  13905. }
  13906. this.iv = buffer;
  13907. data = data.subarray(16);
  13908. }
  13909. this.buffer = new Uint8Array(16);
  13910. this.bufferLength = 0;
  13911. // starting decryption
  13912. this.decryptBlock = decryptBlock2;
  13913. return this.decryptBlock(data, finalize);
  13914. },
  13915. encrypt: function AES256Cipher_encrypt(data, iv) {
  13916. var i, j, ii, sourceLength = data.length,
  13917. buffer = this.buffer, bufferLength = this.bufferPosition,
  13918. result = [];
  13919. if (!iv) {
  13920. iv = new Uint8Array(16);
  13921. }
  13922. for (i = 0; i < sourceLength; ++i) {
  13923. buffer[bufferLength] = data[i];
  13924. ++bufferLength;
  13925. if (bufferLength < 16) {
  13926. continue;
  13927. }
  13928. for (j = 0; j < 16; ++j) {
  13929. buffer[j] ^= iv[j];
  13930. }
  13931. // buffer is full, encrypting
  13932. var cipher = encrypt256(buffer, this.key);
  13933. this.iv = cipher;
  13934. result.push(cipher);
  13935. buffer = new Uint8Array(16);
  13936. bufferLength = 0;
  13937. }
  13938. // saving incomplete buffer
  13939. this.buffer = buffer;
  13940. this.bufferLength = bufferLength;
  13941. this.iv = iv;
  13942. if (result.length === 0) {
  13943. return new Uint8Array([]);
  13944. }
  13945. // combining plain text blocks into one
  13946. var outputLength = 16 * result.length;
  13947. var output = new Uint8Array(outputLength);
  13948. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13949. output.set(result[i], j);
  13950. }
  13951. return output;
  13952. }
  13953. };
  13954. return AES256Cipher;
  13955. })();
  13956. var PDF17 = (function PDF17Closure() {
  13957. function compareByteArrays(array1, array2) {
  13958. if (array1.length !== array2.length) {
  13959. return false;
  13960. }
  13961. for (var i = 0; i < array1.length; i++) {
  13962. if (array1[i] !== array2[i]) {
  13963. return false;
  13964. }
  13965. }
  13966. return true;
  13967. }
  13968. function PDF17() {
  13969. }
  13970. PDF17.prototype = {
  13971. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  13972. ownerValidationSalt,
  13973. userBytes,
  13974. ownerPassword) {
  13975. var hashData = new Uint8Array(password.length + 56);
  13976. hashData.set(password, 0);
  13977. hashData.set(ownerValidationSalt, password.length);
  13978. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  13979. var result = calculateSHA256(hashData, 0, hashData.length);
  13980. return compareByteArrays(result, ownerPassword);
  13981. },
  13982. checkUserPassword: function PDF17_checkUserPassword(password,
  13983. userValidationSalt,
  13984. userPassword) {
  13985. var hashData = new Uint8Array(password.length + 8);
  13986. hashData.set(password, 0);
  13987. hashData.set(userValidationSalt, password.length);
  13988. var result = calculateSHA256(hashData, 0, hashData.length);
  13989. return compareByteArrays(result, userPassword);
  13990. },
  13991. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  13992. ownerEncryption) {
  13993. var hashData = new Uint8Array(password.length + 56);
  13994. hashData.set(password, 0);
  13995. hashData.set(ownerKeySalt, password.length);
  13996. hashData.set(userBytes, password.length + ownerKeySalt.length);
  13997. var key = calculateSHA256(hashData, 0, hashData.length);
  13998. var cipher = new AES256Cipher(key);
  13999. return cipher.decryptBlock(ownerEncryption,
  14000. false,
  14001. new Uint8Array(16));
  14002. },
  14003. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  14004. userEncryption) {
  14005. var hashData = new Uint8Array(password.length + 8);
  14006. hashData.set(password, 0);
  14007. hashData.set(userKeySalt, password.length);
  14008. //key is the decryption key for the UE string
  14009. var key = calculateSHA256(hashData, 0, hashData.length);
  14010. var cipher = new AES256Cipher(key);
  14011. return cipher.decryptBlock(userEncryption,
  14012. false,
  14013. new Uint8Array(16));
  14014. }
  14015. };
  14016. return PDF17;
  14017. })();
  14018. var PDF20 = (function PDF20Closure() {
  14019. function concatArrays(array1, array2) {
  14020. var t = new Uint8Array(array1.length + array2.length);
  14021. t.set(array1, 0);
  14022. t.set(array2, array1.length);
  14023. return t;
  14024. }
  14025. function calculatePDF20Hash(password, input, userBytes) {
  14026. //This refers to Algorithm 2.B as defined in ISO 32000-2
  14027. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  14028. var e = [0];
  14029. var i = 0;
  14030. while (i < 64 || e[e.length - 1] > i - 32) {
  14031. var arrayLength = password.length + k.length + userBytes.length;
  14032. var k1 = new Uint8Array(arrayLength * 64);
  14033. var array = concatArrays(password, k);
  14034. array = concatArrays(array, userBytes);
  14035. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  14036. k1.set(array, pos);
  14037. }
  14038. //AES128 CBC NO PADDING with
  14039. //first 16 bytes of k as the key and the second 16 as the iv.
  14040. var cipher = new AES128Cipher(k.subarray(0, 16));
  14041. e = cipher.encrypt(k1, k.subarray(16, 32));
  14042. //Now we have to take the first 16 bytes of an unsigned
  14043. //big endian integer... and compute the remainder
  14044. //modulo 3.... That is a fairly large number and
  14045. //JavaScript isn't going to handle that well...
  14046. //So we're using a trick that allows us to perform
  14047. //modulo math byte by byte
  14048. var remainder = 0;
  14049. for (var z = 0; z < 16; z++) {
  14050. remainder *= (256 % 3);
  14051. remainder %= 3;
  14052. remainder += ((e[z] >>> 0) % 3);
  14053. remainder %= 3;
  14054. }
  14055. if (remainder === 0) {
  14056. k = calculateSHA256(e, 0, e.length);
  14057. }
  14058. else if (remainder === 1) {
  14059. k = calculateSHA384(e, 0, e.length);
  14060. }
  14061. else if (remainder === 2) {
  14062. k = calculateSHA512(e, 0, e.length);
  14063. }
  14064. i++;
  14065. }
  14066. return k.subarray(0, 32);
  14067. }
  14068. function PDF20() {
  14069. }
  14070. function compareByteArrays(array1, array2) {
  14071. if (array1.length !== array2.length) {
  14072. return false;
  14073. }
  14074. for (var i = 0; i < array1.length; i++) {
  14075. if (array1[i] !== array2[i]) {
  14076. return false;
  14077. }
  14078. }
  14079. return true;
  14080. }
  14081. PDF20.prototype = {
  14082. hash: function PDF20_hash(password, concatBytes, userBytes) {
  14083. return calculatePDF20Hash(password, concatBytes, userBytes);
  14084. },
  14085. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  14086. ownerValidationSalt,
  14087. userBytes,
  14088. ownerPassword) {
  14089. var hashData = new Uint8Array(password.length + 56);
  14090. hashData.set(password, 0);
  14091. hashData.set(ownerValidationSalt, password.length);
  14092. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14093. var result = calculatePDF20Hash(password, hashData, userBytes);
  14094. return compareByteArrays(result, ownerPassword);
  14095. },
  14096. checkUserPassword: function PDF20_checkUserPassword(password,
  14097. userValidationSalt,
  14098. userPassword) {
  14099. var hashData = new Uint8Array(password.length + 8);
  14100. hashData.set(password, 0);
  14101. hashData.set(userValidationSalt, password.length);
  14102. var result = calculatePDF20Hash(password, hashData, []);
  14103. return compareByteArrays(result, userPassword);
  14104. },
  14105. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  14106. ownerEncryption) {
  14107. var hashData = new Uint8Array(password.length + 56);
  14108. hashData.set(password, 0);
  14109. hashData.set(ownerKeySalt, password.length);
  14110. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14111. var key = calculatePDF20Hash(password, hashData, userBytes);
  14112. var cipher = new AES256Cipher(key);
  14113. return cipher.decryptBlock(ownerEncryption,
  14114. false,
  14115. new Uint8Array(16));
  14116. },
  14117. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  14118. userEncryption) {
  14119. var hashData = new Uint8Array(password.length + 8);
  14120. hashData.set(password, 0);
  14121. hashData.set(userKeySalt, password.length);
  14122. //key is the decryption key for the UE string
  14123. var key = calculatePDF20Hash(password, hashData, []);
  14124. var cipher = new AES256Cipher(key);
  14125. return cipher.decryptBlock(userEncryption,
  14126. false,
  14127. new Uint8Array(16));
  14128. }
  14129. };
  14130. return PDF20;
  14131. })();
  14132. var CipherTransform = (function CipherTransformClosure() {
  14133. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  14134. this.stringCipherConstructor = stringCipherConstructor;
  14135. this.streamCipherConstructor = streamCipherConstructor;
  14136. }
  14137. CipherTransform.prototype = {
  14138. createStream: function CipherTransform_createStream(stream, length) {
  14139. var cipher = new this.streamCipherConstructor();
  14140. return new DecryptStream(stream, length,
  14141. function cipherTransformDecryptStream(data, finalize) {
  14142. return cipher.decryptBlock(data, finalize);
  14143. }
  14144. );
  14145. },
  14146. decryptString: function CipherTransform_decryptString(s) {
  14147. var cipher = new this.stringCipherConstructor();
  14148. var data = stringToBytes(s);
  14149. data = cipher.decryptBlock(data, true);
  14150. return bytesToString(data);
  14151. }
  14152. };
  14153. return CipherTransform;
  14154. })();
  14155. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  14156. var defaultPasswordBytes = new Uint8Array([
  14157. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  14158. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  14159. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  14160. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  14161. function createEncryptionKey20(revision, password, ownerPassword,
  14162. ownerValidationSalt, ownerKeySalt, uBytes,
  14163. userPassword, userValidationSalt, userKeySalt,
  14164. ownerEncryption, userEncryption, perms) {
  14165. if (password) {
  14166. var passwordLength = Math.min(127, password.length);
  14167. password = password.subarray(0, passwordLength);
  14168. } else {
  14169. password = [];
  14170. }
  14171. var pdfAlgorithm;
  14172. if (revision === 6) {
  14173. pdfAlgorithm = new PDF20();
  14174. } else {
  14175. pdfAlgorithm = new PDF17();
  14176. }
  14177. if (pdfAlgorithm) {
  14178. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  14179. userPassword)) {
  14180. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  14181. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  14182. uBytes,
  14183. ownerPassword)) {
  14184. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  14185. ownerEncryption);
  14186. }
  14187. }
  14188. return null;
  14189. }
  14190. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  14191. flags, revision, keyLength, encryptMetadata) {
  14192. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  14193. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  14194. if (password) {
  14195. n = Math.min(32, password.length);
  14196. for (; i < n; ++i) {
  14197. hashData[i] = password[i];
  14198. }
  14199. }
  14200. j = 0;
  14201. while (i < 32) {
  14202. hashData[i++] = defaultPasswordBytes[j++];
  14203. }
  14204. // as now the padded password in the hashData[0..i]
  14205. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  14206. hashData[i++] = ownerPassword[j];
  14207. }
  14208. hashData[i++] = flags & 0xFF;
  14209. hashData[i++] = (flags >> 8) & 0xFF;
  14210. hashData[i++] = (flags >> 16) & 0xFF;
  14211. hashData[i++] = (flags >>> 24) & 0xFF;
  14212. for (j = 0, n = fileId.length; j < n; ++j) {
  14213. hashData[i++] = fileId[j];
  14214. }
  14215. if (revision >= 4 && !encryptMetadata) {
  14216. hashData[i++] = 0xFF;
  14217. hashData[i++] = 0xFF;
  14218. hashData[i++] = 0xFF;
  14219. hashData[i++] = 0xFF;
  14220. }
  14221. var hash = calculateMD5(hashData, 0, i);
  14222. var keyLengthInBytes = keyLength >> 3;
  14223. if (revision >= 3) {
  14224. for (j = 0; j < 50; ++j) {
  14225. hash = calculateMD5(hash, 0, keyLengthInBytes);
  14226. }
  14227. }
  14228. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  14229. var cipher, checkData;
  14230. if (revision >= 3) {
  14231. for (i = 0; i < 32; ++i) {
  14232. hashData[i] = defaultPasswordBytes[i];
  14233. }
  14234. for (j = 0, n = fileId.length; j < n; ++j) {
  14235. hashData[i++] = fileId[j];
  14236. }
  14237. cipher = new ARCFourCipher(encryptionKey);
  14238. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  14239. n = encryptionKey.length;
  14240. var derivedKey = new Uint8Array(n), k;
  14241. for (j = 1; j <= 19; ++j) {
  14242. for (k = 0; k < n; ++k) {
  14243. derivedKey[k] = encryptionKey[k] ^ j;
  14244. }
  14245. cipher = new ARCFourCipher(derivedKey);
  14246. checkData = cipher.encryptBlock(checkData);
  14247. }
  14248. for (j = 0, n = checkData.length; j < n; ++j) {
  14249. if (userPassword[j] !== checkData[j]) {
  14250. return null;
  14251. }
  14252. }
  14253. } else {
  14254. cipher = new ARCFourCipher(encryptionKey);
  14255. checkData = cipher.encryptBlock(defaultPasswordBytes);
  14256. for (j = 0, n = checkData.length; j < n; ++j) {
  14257. if (userPassword[j] !== checkData[j]) {
  14258. return null;
  14259. }
  14260. }
  14261. }
  14262. return encryptionKey;
  14263. }
  14264. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  14265. var hashData = new Uint8Array(32), i = 0, j, n;
  14266. n = Math.min(32, password.length);
  14267. for (; i < n; ++i) {
  14268. hashData[i] = password[i];
  14269. }
  14270. j = 0;
  14271. while (i < 32) {
  14272. hashData[i++] = defaultPasswordBytes[j++];
  14273. }
  14274. var hash = calculateMD5(hashData, 0, i);
  14275. var keyLengthInBytes = keyLength >> 3;
  14276. if (revision >= 3) {
  14277. for (j = 0; j < 50; ++j) {
  14278. hash = calculateMD5(hash, 0, hash.length);
  14279. }
  14280. }
  14281. var cipher, userPassword;
  14282. if (revision >= 3) {
  14283. userPassword = ownerPassword;
  14284. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  14285. for (j = 19; j >= 0; j--) {
  14286. for (k = 0; k < keyLengthInBytes; ++k) {
  14287. derivedKey[k] = hash[k] ^ j;
  14288. }
  14289. cipher = new ARCFourCipher(derivedKey);
  14290. userPassword = cipher.encryptBlock(userPassword);
  14291. }
  14292. } else {
  14293. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  14294. userPassword = cipher.encryptBlock(ownerPassword);
  14295. }
  14296. return userPassword;
  14297. }
  14298. var identityName = Name.get('Identity');
  14299. function CipherTransformFactory(dict, fileId, password) {
  14300. var filter = dict.get('Filter');
  14301. if (!isName(filter) || filter.name !== 'Standard') {
  14302. error('unknown encryption method');
  14303. }
  14304. this.dict = dict;
  14305. var algorithm = dict.get('V');
  14306. if (!isInt(algorithm) ||
  14307. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  14308. algorithm !== 5)) {
  14309. error('unsupported encryption algorithm');
  14310. }
  14311. this.algorithm = algorithm;
  14312. var keyLength = dict.get('Length') || 40;
  14313. if (!isInt(keyLength) ||
  14314. keyLength < 40 || (keyLength % 8) !== 0) {
  14315. error('invalid key length');
  14316. }
  14317. // prepare keys
  14318. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  14319. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  14320. var flags = dict.get('P');
  14321. var revision = dict.get('R');
  14322. // meaningful when V is 4 or 5
  14323. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  14324. dict.get('EncryptMetadata') !== false);
  14325. this.encryptMetadata = encryptMetadata;
  14326. var fileIdBytes = stringToBytes(fileId);
  14327. var passwordBytes;
  14328. if (password) {
  14329. passwordBytes = stringToBytes(password);
  14330. }
  14331. var encryptionKey;
  14332. if (algorithm !== 5) {
  14333. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  14334. ownerPassword, userPassword, flags,
  14335. revision, keyLength, encryptMetadata);
  14336. }
  14337. else {
  14338. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  14339. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  14340. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  14341. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  14342. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  14343. var ownerEncryption = stringToBytes(dict.get('OE'));
  14344. var userEncryption = stringToBytes(dict.get('UE'));
  14345. var perms = stringToBytes(dict.get('Perms'));
  14346. encryptionKey =
  14347. createEncryptionKey20(revision, passwordBytes,
  14348. ownerPassword, ownerValidationSalt,
  14349. ownerKeySalt, uBytes,
  14350. userPassword, userValidationSalt,
  14351. userKeySalt, ownerEncryption,
  14352. userEncryption, perms);
  14353. }
  14354. if (!encryptionKey && !password) {
  14355. throw new PasswordException('No password given',
  14356. PasswordResponses.NEED_PASSWORD);
  14357. } else if (!encryptionKey && password) {
  14358. // Attempting use the password as an owner password
  14359. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  14360. revision, keyLength);
  14361. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  14362. ownerPassword, userPassword, flags,
  14363. revision, keyLength, encryptMetadata);
  14364. }
  14365. if (!encryptionKey) {
  14366. throw new PasswordException('Incorrect Password',
  14367. PasswordResponses.INCORRECT_PASSWORD);
  14368. }
  14369. this.encryptionKey = encryptionKey;
  14370. if (algorithm >= 4) {
  14371. this.cf = dict.get('CF');
  14372. this.stmf = dict.get('StmF') || identityName;
  14373. this.strf = dict.get('StrF') || identityName;
  14374. this.eff = dict.get('EFF') || this.strf;
  14375. }
  14376. }
  14377. function buildObjectKey(num, gen, encryptionKey, isAes) {
  14378. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  14379. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  14380. key[i] = encryptionKey[i];
  14381. }
  14382. key[i++] = num & 0xFF;
  14383. key[i++] = (num >> 8) & 0xFF;
  14384. key[i++] = (num >> 16) & 0xFF;
  14385. key[i++] = gen & 0xFF;
  14386. key[i++] = (gen >> 8) & 0xFF;
  14387. if (isAes) {
  14388. key[i++] = 0x73;
  14389. key[i++] = 0x41;
  14390. key[i++] = 0x6C;
  14391. key[i++] = 0x54;
  14392. }
  14393. var hash = calculateMD5(key, 0, i);
  14394. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  14395. }
  14396. function buildCipherConstructor(cf, name, num, gen, key) {
  14397. var cryptFilter = cf.get(name.name);
  14398. var cfm;
  14399. if (cryptFilter !== null && cryptFilter !== undefined) {
  14400. cfm = cryptFilter.get('CFM');
  14401. }
  14402. if (!cfm || cfm.name === 'None') {
  14403. return function cipherTransformFactoryBuildCipherConstructorNone() {
  14404. return new NullCipher();
  14405. };
  14406. }
  14407. if ('V2' === cfm.name) {
  14408. return function cipherTransformFactoryBuildCipherConstructorV2() {
  14409. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  14410. };
  14411. }
  14412. if ('AESV2' === cfm.name) {
  14413. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  14414. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  14415. };
  14416. }
  14417. if ('AESV3' === cfm.name) {
  14418. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  14419. return new AES256Cipher(key);
  14420. };
  14421. }
  14422. error('Unknown crypto method');
  14423. }
  14424. CipherTransformFactory.prototype = {
  14425. createCipherTransform:
  14426. function CipherTransformFactory_createCipherTransform(num, gen) {
  14427. if (this.algorithm === 4 || this.algorithm === 5) {
  14428. return new CipherTransform(
  14429. buildCipherConstructor(this.cf, this.stmf,
  14430. num, gen, this.encryptionKey),
  14431. buildCipherConstructor(this.cf, this.strf,
  14432. num, gen, this.encryptionKey));
  14433. }
  14434. // algorithms 1 and 2
  14435. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  14436. var cipherConstructor = function buildCipherCipherConstructor() {
  14437. return new ARCFourCipher(key);
  14438. };
  14439. return new CipherTransform(cipherConstructor, cipherConstructor);
  14440. }
  14441. };
  14442. return CipherTransformFactory;
  14443. })();
  14444. var PatternType = {
  14445. FUNCTION_BASED: 1,
  14446. AXIAL: 2,
  14447. RADIAL: 3,
  14448. FREE_FORM_MESH: 4,
  14449. LATTICE_FORM_MESH: 5,
  14450. COONS_PATCH_MESH: 6,
  14451. TENSOR_PATCH_MESH: 7
  14452. };
  14453. var Pattern = (function PatternClosure() {
  14454. // Constructor should define this.getPattern
  14455. function Pattern() {
  14456. error('should not call Pattern constructor');
  14457. }
  14458. Pattern.prototype = {
  14459. // Input: current Canvas context
  14460. // Output: the appropriate fillStyle or strokeStyle
  14461. getPattern: function Pattern_getPattern(ctx) {
  14462. error('Should not call Pattern.getStyle: ' + ctx);
  14463. }
  14464. };
  14465. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  14466. res) {
  14467. var dict = isStream(shading) ? shading.dict : shading;
  14468. var type = dict.get('ShadingType');
  14469. try {
  14470. switch (type) {
  14471. case PatternType.AXIAL:
  14472. case PatternType.RADIAL:
  14473. // Both radial and axial shadings are handled by RadialAxial shading.
  14474. return new Shadings.RadialAxial(dict, matrix, xref, res);
  14475. case PatternType.FREE_FORM_MESH:
  14476. case PatternType.LATTICE_FORM_MESH:
  14477. case PatternType.COONS_PATCH_MESH:
  14478. case PatternType.TENSOR_PATCH_MESH:
  14479. return new Shadings.Mesh(shading, matrix, xref, res);
  14480. default:
  14481. throw new Error('Unknown PatternType: ' + type);
  14482. }
  14483. } catch (ex) {
  14484. if (ex instanceof MissingDataException) {
  14485. throw ex;
  14486. }
  14487. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  14488. warn(ex);
  14489. return new Shadings.Dummy();
  14490. }
  14491. };
  14492. return Pattern;
  14493. })();
  14494. var Shadings = {};
  14495. // A small number to offset the first/last color stops so we can insert ones to
  14496. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  14497. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  14498. // internally so we have to go bigger.
  14499. Shadings.SMALL_NUMBER = 1e-2;
  14500. // Radial and axial shading have very similar implementations
  14501. // If needed, the implementations can be broken into two classes
  14502. Shadings.RadialAxial = (function RadialAxialClosure() {
  14503. function RadialAxial(dict, matrix, xref, res) {
  14504. this.matrix = matrix;
  14505. this.coordsArr = dict.get('Coords');
  14506. this.shadingType = dict.get('ShadingType');
  14507. this.type = 'Pattern';
  14508. var cs = dict.get('ColorSpace', 'CS');
  14509. cs = ColorSpace.parse(cs, xref, res);
  14510. this.cs = cs;
  14511. var t0 = 0.0, t1 = 1.0;
  14512. if (dict.has('Domain')) {
  14513. var domainArr = dict.get('Domain');
  14514. t0 = domainArr[0];
  14515. t1 = domainArr[1];
  14516. }
  14517. var extendStart = false, extendEnd = false;
  14518. if (dict.has('Extend')) {
  14519. var extendArr = dict.get('Extend');
  14520. extendStart = extendArr[0];
  14521. extendEnd = extendArr[1];
  14522. }
  14523. if (this.shadingType === PatternType.RADIAL &&
  14524. (!extendStart || !extendEnd)) {
  14525. // Radial gradient only currently works if either circle is fully within
  14526. // the other circle.
  14527. var x1 = this.coordsArr[0];
  14528. var y1 = this.coordsArr[1];
  14529. var r1 = this.coordsArr[2];
  14530. var x2 = this.coordsArr[3];
  14531. var y2 = this.coordsArr[4];
  14532. var r2 = this.coordsArr[5];
  14533. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  14534. if (r1 <= r2 + distance &&
  14535. r2 <= r1 + distance) {
  14536. warn('Unsupported radial gradient.');
  14537. }
  14538. }
  14539. this.extendStart = extendStart;
  14540. this.extendEnd = extendEnd;
  14541. var fnObj = dict.get('Function');
  14542. var fn = PDFFunction.parseArray(xref, fnObj);
  14543. // 10 samples seems good enough for now, but probably won't work
  14544. // if there are sharp color changes. Ideally, we would implement
  14545. // the spec faithfully and add lossless optimizations.
  14546. var diff = t1 - t0;
  14547. var step = diff / 10;
  14548. var colorStops = this.colorStops = [];
  14549. // Protect against bad domains so we don't end up in an infinte loop below.
  14550. if (t0 >= t1 || step <= 0) {
  14551. // Acrobat doesn't seem to handle these cases so we'll ignore for
  14552. // now.
  14553. info('Bad shading domain.');
  14554. return;
  14555. }
  14556. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  14557. var rgbColor;
  14558. for (var i = t0; i <= t1; i += step) {
  14559. ratio[0] = i;
  14560. fn(ratio, 0, color, 0);
  14561. rgbColor = cs.getRgb(color, 0);
  14562. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14563. colorStops.push([(i - t0) / diff, cssColor]);
  14564. }
  14565. var background = 'transparent';
  14566. if (dict.has('Background')) {
  14567. rgbColor = cs.getRgb(dict.get('Background'), 0);
  14568. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14569. }
  14570. if (!extendStart) {
  14571. // Insert a color stop at the front and offset the first real color stop
  14572. // so it doesn't conflict with the one we insert.
  14573. colorStops.unshift([0, background]);
  14574. colorStops[1][0] += Shadings.SMALL_NUMBER;
  14575. }
  14576. if (!extendEnd) {
  14577. // Same idea as above in extendStart but for the end.
  14578. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  14579. colorStops.push([1, background]);
  14580. }
  14581. this.colorStops = colorStops;
  14582. }
  14583. RadialAxial.prototype = {
  14584. getIR: function RadialAxial_getIR() {
  14585. var coordsArr = this.coordsArr;
  14586. var shadingType = this.shadingType;
  14587. var type, p0, p1, r0, r1;
  14588. if (shadingType === PatternType.AXIAL) {
  14589. p0 = [coordsArr[0], coordsArr[1]];
  14590. p1 = [coordsArr[2], coordsArr[3]];
  14591. r0 = null;
  14592. r1 = null;
  14593. type = 'axial';
  14594. } else if (shadingType === PatternType.RADIAL) {
  14595. p0 = [coordsArr[0], coordsArr[1]];
  14596. p1 = [coordsArr[3], coordsArr[4]];
  14597. r0 = coordsArr[2];
  14598. r1 = coordsArr[5];
  14599. type = 'radial';
  14600. } else {
  14601. error('getPattern type unknown: ' + shadingType);
  14602. }
  14603. var matrix = this.matrix;
  14604. if (matrix) {
  14605. p0 = Util.applyTransform(p0, matrix);
  14606. p1 = Util.applyTransform(p1, matrix);
  14607. }
  14608. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  14609. }
  14610. };
  14611. return RadialAxial;
  14612. })();
  14613. // All mesh shading. For now, they will be presented as set of the triangles
  14614. // to be drawn on the canvas and rgb color for each vertex.
  14615. Shadings.Mesh = (function MeshClosure() {
  14616. function MeshStreamReader(stream, context) {
  14617. this.stream = stream;
  14618. this.context = context;
  14619. this.buffer = 0;
  14620. this.bufferLength = 0;
  14621. var numComps = context.numComps;
  14622. this.tmpCompsBuf = new Float32Array(numComps);
  14623. var csNumComps = context.colorSpace;
  14624. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  14625. this.tmpCompsBuf;
  14626. }
  14627. MeshStreamReader.prototype = {
  14628. get hasData() {
  14629. if (this.stream.end) {
  14630. return this.stream.pos < this.stream.end;
  14631. }
  14632. if (this.bufferLength > 0) {
  14633. return true;
  14634. }
  14635. var nextByte = this.stream.getByte();
  14636. if (nextByte < 0) {
  14637. return false;
  14638. }
  14639. this.buffer = nextByte;
  14640. this.bufferLength = 8;
  14641. return true;
  14642. },
  14643. readBits: function MeshStreamReader_readBits(n) {
  14644. var buffer = this.buffer;
  14645. var bufferLength = this.bufferLength;
  14646. if (n === 32) {
  14647. if (bufferLength === 0) {
  14648. return ((this.stream.getByte() << 24) |
  14649. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  14650. this.stream.getByte()) >>> 0;
  14651. }
  14652. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  14653. (this.stream.getByte() << 8) | this.stream.getByte();
  14654. var nextByte = this.stream.getByte();
  14655. this.buffer = nextByte & ((1 << bufferLength) - 1);
  14656. return ((buffer << (8 - bufferLength)) |
  14657. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  14658. }
  14659. if (n === 8 && bufferLength === 0) {
  14660. return this.stream.getByte();
  14661. }
  14662. while (bufferLength < n) {
  14663. buffer = (buffer << 8) | this.stream.getByte();
  14664. bufferLength += 8;
  14665. }
  14666. bufferLength -= n;
  14667. this.bufferLength = bufferLength;
  14668. this.buffer = buffer & ((1 << bufferLength) - 1);
  14669. return buffer >> bufferLength;
  14670. },
  14671. align: function MeshStreamReader_align() {
  14672. this.buffer = 0;
  14673. this.bufferLength = 0;
  14674. },
  14675. readFlag: function MeshStreamReader_readFlag() {
  14676. return this.readBits(this.context.bitsPerFlag);
  14677. },
  14678. readCoordinate: function MeshStreamReader_readCoordinate() {
  14679. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  14680. var xi = this.readBits(bitsPerCoordinate);
  14681. var yi = this.readBits(bitsPerCoordinate);
  14682. var decode = this.context.decode;
  14683. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  14684. 2.3283064365386963e-10; // 2 ^ -32
  14685. return [
  14686. xi * scale * (decode[1] - decode[0]) + decode[0],
  14687. yi * scale * (decode[3] - decode[2]) + decode[2]
  14688. ];
  14689. },
  14690. readComponents: function MeshStreamReader_readComponents() {
  14691. var numComps = this.context.numComps;
  14692. var bitsPerComponent = this.context.bitsPerComponent;
  14693. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  14694. 2.3283064365386963e-10; // 2 ^ -32
  14695. var decode = this.context.decode;
  14696. var components = this.tmpCompsBuf;
  14697. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  14698. var ci = this.readBits(bitsPerComponent);
  14699. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  14700. }
  14701. var color = this.tmpCsCompsBuf;
  14702. if (this.context.colorFn) {
  14703. this.context.colorFn(components, 0, color, 0);
  14704. }
  14705. return this.context.colorSpace.getRgb(color, 0);
  14706. }
  14707. };
  14708. function decodeType4Shading(mesh, reader) {
  14709. var coords = mesh.coords;
  14710. var colors = mesh.colors;
  14711. var operators = [];
  14712. var ps = []; // not maintaining cs since that will match ps
  14713. var verticesLeft = 0; // assuming we have all data to start a new triangle
  14714. while (reader.hasData) {
  14715. var f = reader.readFlag();
  14716. var coord = reader.readCoordinate();
  14717. var color = reader.readComponents();
  14718. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  14719. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  14720. switch (f) {
  14721. case 0:
  14722. verticesLeft = 3;
  14723. break;
  14724. case 1:
  14725. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  14726. verticesLeft = 1;
  14727. break;
  14728. case 2:
  14729. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  14730. verticesLeft = 1;
  14731. break;
  14732. }
  14733. operators.push(f);
  14734. }
  14735. ps.push(coords.length);
  14736. coords.push(coord);
  14737. colors.push(color);
  14738. verticesLeft--;
  14739. reader.align();
  14740. }
  14741. var psPacked = new Int32Array(ps);
  14742. mesh.figures.push({
  14743. type: 'triangles',
  14744. coords: psPacked,
  14745. colors: psPacked
  14746. });
  14747. }
  14748. function decodeType5Shading(mesh, reader, verticesPerRow) {
  14749. var coords = mesh.coords;
  14750. var colors = mesh.colors;
  14751. var ps = []; // not maintaining cs since that will match ps
  14752. while (reader.hasData) {
  14753. var coord = reader.readCoordinate();
  14754. var color = reader.readComponents();
  14755. ps.push(coords.length);
  14756. coords.push(coord);
  14757. colors.push(color);
  14758. }
  14759. var psPacked = new Int32Array(ps);
  14760. mesh.figures.push({
  14761. type: 'lattice',
  14762. coords: psPacked,
  14763. colors: psPacked,
  14764. verticesPerRow: verticesPerRow
  14765. });
  14766. }
  14767. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  14768. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  14769. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  14770. var getB = (function getBClosure() {
  14771. function buildB(count) {
  14772. var lut = [];
  14773. for (var i = 0; i <= count; i++) {
  14774. var t = i / count, t_ = 1 - t;
  14775. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  14776. 3 * t * t * t_, t * t * t]));
  14777. }
  14778. return lut;
  14779. }
  14780. var cache = [];
  14781. return function getB(count) {
  14782. if (!cache[count]) {
  14783. cache[count] = buildB(count);
  14784. }
  14785. return cache[count];
  14786. };
  14787. })();
  14788. function buildFigureFromPatch(mesh, index) {
  14789. var figure = mesh.figures[index];
  14790. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  14791. var coords = mesh.coords, colors = mesh.colors;
  14792. var pi = figure.coords;
  14793. var ci = figure.colors;
  14794. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  14795. coords[pi[12]][0], coords[pi[15]][0]);
  14796. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  14797. coords[pi[12]][1], coords[pi[15]][1]);
  14798. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  14799. coords[pi[12]][0], coords[pi[15]][0]);
  14800. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  14801. coords[pi[12]][1], coords[pi[15]][1]);
  14802. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  14803. (mesh.bounds[2] - mesh.bounds[0]));
  14804. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14805. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  14806. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  14807. (mesh.bounds[3] - mesh.bounds[1]));
  14808. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14809. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  14810. var verticesPerRow = splitXBy + 1;
  14811. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  14812. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  14813. var k = 0;
  14814. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  14815. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  14816. c2 = colors[ci[2]], c3 = colors[ci[3]];
  14817. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  14818. for (var row = 0; row <= splitYBy; row++) {
  14819. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  14820. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  14821. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  14822. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  14823. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  14824. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  14825. for (var col = 0; col <= splitXBy; col++, k++) {
  14826. if ((row === 0 || row === splitYBy) &&
  14827. (col === 0 || col === splitXBy)) {
  14828. continue;
  14829. }
  14830. var x = 0, y = 0;
  14831. var q = 0;
  14832. for (var i = 0; i <= 3; i++) {
  14833. for (var j = 0; j <= 3; j++, q++) {
  14834. var m = bRow[row][i] * bCol[col][j];
  14835. x += coords[pi[q]][0] * m;
  14836. y += coords[pi[q]][1] * m;
  14837. }
  14838. }
  14839. figureCoords[k] = coords.length;
  14840. coords.push([x, y]);
  14841. figureColors[k] = colors.length;
  14842. var newColor = new Uint8Array(3);
  14843. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  14844. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  14845. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  14846. colors.push(newColor);
  14847. }
  14848. }
  14849. figureCoords[0] = pi[0];
  14850. figureColors[0] = ci[0];
  14851. figureCoords[splitXBy] = pi[3];
  14852. figureColors[splitXBy] = ci[1];
  14853. figureCoords[verticesPerRow * splitYBy] = pi[12];
  14854. figureColors[verticesPerRow * splitYBy] = ci[2];
  14855. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  14856. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  14857. mesh.figures[index] = {
  14858. type: 'lattice',
  14859. coords: figureCoords,
  14860. colors: figureColors,
  14861. verticesPerRow: verticesPerRow
  14862. };
  14863. }
  14864. function decodeType6Shading(mesh, reader) {
  14865. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  14866. var coords = mesh.coords;
  14867. var colors = mesh.colors;
  14868. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14869. var cs = new Int32Array(4); // c00, c30, c03, c33
  14870. while (reader.hasData) {
  14871. var f = reader.readFlag();
  14872. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  14873. var i, ii;
  14874. var pi = coords.length;
  14875. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  14876. coords.push(reader.readCoordinate());
  14877. }
  14878. var ci = colors.length;
  14879. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14880. colors.push(reader.readComponents());
  14881. }
  14882. var tmp1, tmp2, tmp3, tmp4;
  14883. switch (f) {
  14884. case 0:
  14885. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14886. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14887. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  14888. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14889. cs[2] = ci + 1; cs[3] = ci + 2;
  14890. cs[0] = ci; cs[1] = ci + 3;
  14891. break;
  14892. case 1:
  14893. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14894. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14895. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  14896. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  14897. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14898. tmp1 = cs[2]; tmp2 = cs[3];
  14899. cs[2] = ci + 1; cs[3] = ci;
  14900. cs[0] = tmp1; cs[1] = tmp2;
  14901. break;
  14902. case 2:
  14903. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14904. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  14905. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  14906. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14907. cs[2] = cs[3]; cs[3] = ci + 1;
  14908. cs[0] = cs[1]; cs[1] = ci;
  14909. break;
  14910. case 3:
  14911. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14912. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14913. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  14914. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14915. cs[2] = cs[0]; cs[3] = cs[1];
  14916. cs[0] = ci; cs[1] = ci + 1;
  14917. break;
  14918. }
  14919. // set p11, p12, p21, p22
  14920. ps[5] = coords.length;
  14921. coords.push([
  14922. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  14923. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  14924. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14925. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  14926. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  14927. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  14928. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14929. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  14930. ]);
  14931. ps[6] = coords.length;
  14932. coords.push([
  14933. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  14934. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  14935. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14936. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  14937. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  14938. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  14939. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14940. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  14941. ]);
  14942. ps[9] = coords.length;
  14943. coords.push([
  14944. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  14945. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  14946. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14947. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  14948. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  14949. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  14950. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14951. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  14952. ]);
  14953. ps[10] = coords.length;
  14954. coords.push([
  14955. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  14956. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  14957. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14958. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  14959. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  14960. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  14961. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14962. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  14963. ]);
  14964. mesh.figures.push({
  14965. type: 'patch',
  14966. coords: new Int32Array(ps), // making copies of ps and cs
  14967. colors: new Int32Array(cs)
  14968. });
  14969. }
  14970. }
  14971. function decodeType7Shading(mesh, reader) {
  14972. var coords = mesh.coords;
  14973. var colors = mesh.colors;
  14974. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14975. var cs = new Int32Array(4); // c00, c30, c03, c33
  14976. while (reader.hasData) {
  14977. var f = reader.readFlag();
  14978. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  14979. var i, ii;
  14980. var pi = coords.length;
  14981. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  14982. coords.push(reader.readCoordinate());
  14983. }
  14984. var ci = colors.length;
  14985. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14986. colors.push(reader.readComponents());
  14987. }
  14988. var tmp1, tmp2, tmp3, tmp4;
  14989. switch (f) {
  14990. case 0:
  14991. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14992. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  14993. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  14994. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14995. cs[2] = ci + 1; cs[3] = ci + 2;
  14996. cs[0] = ci; cs[1] = ci + 3;
  14997. break;
  14998. case 1:
  14999. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  15000. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  15001. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  15002. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  15003. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  15004. tmp1 = cs[2]; tmp2 = cs[3];
  15005. cs[2] = ci + 1; cs[3] = ci;
  15006. cs[0] = tmp1; cs[1] = tmp2;
  15007. break;
  15008. case 2:
  15009. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  15010. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  15011. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  15012. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  15013. cs[2] = cs[3]; cs[3] = ci + 1;
  15014. cs[0] = cs[1]; cs[1] = ci;
  15015. break;
  15016. case 3:
  15017. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  15018. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  15019. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  15020. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  15021. cs[2] = cs[0]; cs[3] = cs[1];
  15022. cs[0] = ci; cs[1] = ci + 1;
  15023. break;
  15024. }
  15025. mesh.figures.push({
  15026. type: 'patch',
  15027. coords: new Int32Array(ps), // making copies of ps and cs
  15028. colors: new Int32Array(cs)
  15029. });
  15030. }
  15031. }
  15032. function updateBounds(mesh) {
  15033. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  15034. maxX = minX, maxY = minY;
  15035. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  15036. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  15037. minX = minX > x ? x : minX;
  15038. minY = minY > y ? y : minY;
  15039. maxX = maxX < x ? x : maxX;
  15040. maxY = maxY < y ? y : maxY;
  15041. }
  15042. mesh.bounds = [minX, minY, maxX, maxY];
  15043. }
  15044. function packData(mesh) {
  15045. var i, ii, j, jj;
  15046. var coords = mesh.coords;
  15047. var coordsPacked = new Float32Array(coords.length * 2);
  15048. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  15049. var xy = coords[i];
  15050. coordsPacked[j++] = xy[0];
  15051. coordsPacked[j++] = xy[1];
  15052. }
  15053. mesh.coords = coordsPacked;
  15054. var colors = mesh.colors;
  15055. var colorsPacked = new Uint8Array(colors.length * 3);
  15056. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  15057. var c = colors[i];
  15058. colorsPacked[j++] = c[0];
  15059. colorsPacked[j++] = c[1];
  15060. colorsPacked[j++] = c[2];
  15061. }
  15062. mesh.colors = colorsPacked;
  15063. var figures = mesh.figures;
  15064. for (i = 0, ii = figures.length; i < ii; i++) {
  15065. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  15066. for (j = 0, jj = ps.length; j < jj; j++) {
  15067. ps[j] *= 2;
  15068. cs[j] *= 3;
  15069. }
  15070. }
  15071. }
  15072. function Mesh(stream, matrix, xref, res) {
  15073. assert(isStream(stream), 'Mesh data is not a stream');
  15074. var dict = stream.dict;
  15075. this.matrix = matrix;
  15076. this.shadingType = dict.get('ShadingType');
  15077. this.type = 'Pattern';
  15078. this.bbox = dict.get('BBox');
  15079. var cs = dict.get('ColorSpace', 'CS');
  15080. cs = ColorSpace.parse(cs, xref, res);
  15081. this.cs = cs;
  15082. this.background = dict.has('Background') ?
  15083. cs.getRgb(dict.get('Background'), 0) : null;
  15084. var fnObj = dict.get('Function');
  15085. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  15086. this.coords = [];
  15087. this.colors = [];
  15088. this.figures = [];
  15089. var decodeContext = {
  15090. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  15091. bitsPerComponent: dict.get('BitsPerComponent'),
  15092. bitsPerFlag: dict.get('BitsPerFlag'),
  15093. decode: dict.get('Decode'),
  15094. colorFn: fn,
  15095. colorSpace: cs,
  15096. numComps: fn ? 1 : cs.numComps
  15097. };
  15098. var reader = new MeshStreamReader(stream, decodeContext);
  15099. var patchMesh = false;
  15100. switch (this.shadingType) {
  15101. case PatternType.FREE_FORM_MESH:
  15102. decodeType4Shading(this, reader);
  15103. break;
  15104. case PatternType.LATTICE_FORM_MESH:
  15105. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  15106. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  15107. decodeType5Shading(this, reader, verticesPerRow);
  15108. break;
  15109. case PatternType.COONS_PATCH_MESH:
  15110. decodeType6Shading(this, reader);
  15111. patchMesh = true;
  15112. break;
  15113. case PatternType.TENSOR_PATCH_MESH:
  15114. decodeType7Shading(this, reader);
  15115. patchMesh = true;
  15116. break;
  15117. default:
  15118. error('Unsupported mesh type.');
  15119. break;
  15120. }
  15121. if (patchMesh) {
  15122. // dirty bounds calculation for determining, how dense shall be triangles
  15123. updateBounds(this);
  15124. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  15125. buildFigureFromPatch(this, i);
  15126. }
  15127. }
  15128. // calculate bounds
  15129. updateBounds(this);
  15130. packData(this);
  15131. }
  15132. Mesh.prototype = {
  15133. getIR: function Mesh_getIR() {
  15134. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  15135. this.bounds, this.matrix, this.bbox, this.background];
  15136. }
  15137. };
  15138. return Mesh;
  15139. })();
  15140. Shadings.Dummy = (function DummyClosure() {
  15141. function Dummy() {
  15142. this.type = 'Pattern';
  15143. }
  15144. Dummy.prototype = {
  15145. getIR: function Dummy_getIR() {
  15146. return ['Dummy'];
  15147. }
  15148. };
  15149. return Dummy;
  15150. })();
  15151. function getTilingPatternIR(operatorList, dict, args) {
  15152. var matrix = dict.get('Matrix');
  15153. var bbox = dict.get('BBox');
  15154. var xstep = dict.get('XStep');
  15155. var ystep = dict.get('YStep');
  15156. var paintType = dict.get('PaintType');
  15157. var tilingType = dict.get('TilingType');
  15158. return [
  15159. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  15160. paintType, tilingType
  15161. ];
  15162. }
  15163. var PartialEvaluator = (function PartialEvaluatorClosure() {
  15164. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  15165. uniquePrefix, idCounters, fontCache) {
  15166. this.pdfManager = pdfManager;
  15167. this.xref = xref;
  15168. this.handler = handler;
  15169. this.pageIndex = pageIndex;
  15170. this.uniquePrefix = uniquePrefix;
  15171. this.idCounters = idCounters;
  15172. this.fontCache = fontCache;
  15173. }
  15174. // Trying to minimize Date.now() usage and check every 100 time
  15175. var TIME_SLOT_DURATION_MS = 20;
  15176. var CHECK_TIME_EVERY = 100;
  15177. function TimeSlotManager() {
  15178. this.reset();
  15179. }
  15180. TimeSlotManager.prototype = {
  15181. check: function TimeSlotManager_check() {
  15182. if (++this.checked < CHECK_TIME_EVERY) {
  15183. return false;
  15184. }
  15185. this.checked = 0;
  15186. return this.endTime <= Date.now();
  15187. },
  15188. reset: function TimeSlotManager_reset() {
  15189. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  15190. this.checked = 0;
  15191. }
  15192. };
  15193. var deferred = Promise.resolve();
  15194. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  15195. PartialEvaluator.prototype = {
  15196. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  15197. if (!isDict(resources)) {
  15198. return false;
  15199. }
  15200. var processed = Object.create(null);
  15201. if (resources.objId) {
  15202. processed[resources.objId] = true;
  15203. }
  15204. var nodes = [resources];
  15205. while (nodes.length) {
  15206. var key;
  15207. var node = nodes.shift();
  15208. // First check the current resources for blend modes.
  15209. var graphicStates = node.get('ExtGState');
  15210. if (isDict(graphicStates)) {
  15211. graphicStates = graphicStates.getAll();
  15212. for (key in graphicStates) {
  15213. var graphicState = graphicStates[key];
  15214. var bm = graphicState['BM'];
  15215. if (isName(bm) && bm.name !== 'Normal') {
  15216. return true;
  15217. }
  15218. }
  15219. }
  15220. // Descend into the XObjects to look for more resources and blend modes.
  15221. var xObjects = node.get('XObject');
  15222. if (!isDict(xObjects)) {
  15223. continue;
  15224. }
  15225. xObjects = xObjects.getAll();
  15226. for (key in xObjects) {
  15227. var xObject = xObjects[key];
  15228. if (!isStream(xObject)) {
  15229. continue;
  15230. }
  15231. if (xObject.dict.objId) {
  15232. if (processed[xObject.dict.objId]) {
  15233. // stream has objId and is processed already
  15234. continue;
  15235. }
  15236. processed[xObject.dict.objId] = true;
  15237. }
  15238. var xResources = xObject.dict.get('Resources');
  15239. // Checking objId to detect an infinite loop.
  15240. if (isDict(xResources) &&
  15241. (!xResources.objId || !processed[xResources.objId])) {
  15242. nodes.push(xResources);
  15243. if (xResources.objId) {
  15244. processed[xResources.objId] = true;
  15245. }
  15246. }
  15247. }
  15248. }
  15249. return false;
  15250. },
  15251. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  15252. xobj, smask,
  15253. operatorList,
  15254. initialState) {
  15255. var matrix = xobj.dict.get('Matrix');
  15256. var bbox = xobj.dict.get('BBox');
  15257. var group = xobj.dict.get('Group');
  15258. if (group) {
  15259. var groupOptions = {
  15260. matrix: matrix,
  15261. bbox: bbox,
  15262. smask: smask,
  15263. isolated: false,
  15264. knockout: false
  15265. };
  15266. var groupSubtype = group.get('S');
  15267. var colorSpace;
  15268. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  15269. groupOptions.isolated = (group.get('I') || false);
  15270. groupOptions.knockout = (group.get('K') || false);
  15271. colorSpace = (group.has('CS') ?
  15272. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  15273. }
  15274. if (smask && smask.backdrop) {
  15275. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  15276. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  15277. }
  15278. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  15279. }
  15280. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  15281. return this.getOperatorList(xobj,
  15282. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  15283. then(function () {
  15284. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  15285. if (group) {
  15286. operatorList.addOp(OPS.endGroup, [groupOptions]);
  15287. }
  15288. });
  15289. },
  15290. buildPaintImageXObject:
  15291. function PartialEvaluator_buildPaintImageXObject(resources, image,
  15292. inline, operatorList,
  15293. cacheKey, imageCache) {
  15294. var self = this;
  15295. var dict = image.dict;
  15296. var w = dict.get('Width', 'W');
  15297. var h = dict.get('Height', 'H');
  15298. if (!(w && isNum(w)) || !(h && isNum(h))) {
  15299. warn('Image dimensions are missing, or not numbers.');
  15300. return;
  15301. }
  15302. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  15303. warn('Image exceeded maximum allowed size and was removed.');
  15304. return;
  15305. }
  15306. var imageMask = (dict.get('ImageMask', 'IM') || false);
  15307. var imgData, args;
  15308. if (imageMask) {
  15309. // This depends on a tmpCanvas being filled with the
  15310. // current fillStyle, such that processing the pixel
  15311. // data can't be done here. Instead of creating a
  15312. // complete PDFImage, only read the information needed
  15313. // for later.
  15314. var width = dict.get('Width', 'W');
  15315. var height = dict.get('Height', 'H');
  15316. var bitStrideLength = (width + 7) >> 3;
  15317. var imgArray = image.getBytes(bitStrideLength * height);
  15318. var decode = dict.get('Decode', 'D');
  15319. var inverseDecode = (!!decode && decode[0] > 0);
  15320. imgData = PDFImage.createMask(imgArray, width, height,
  15321. image instanceof DecodeStream,
  15322. inverseDecode);
  15323. imgData.cached = true;
  15324. args = [imgData];
  15325. operatorList.addOp(OPS.paintImageMaskXObject, args);
  15326. if (cacheKey) {
  15327. imageCache[cacheKey] = {
  15328. fn: OPS.paintImageMaskXObject,
  15329. args: args
  15330. };
  15331. }
  15332. return;
  15333. }
  15334. var softMask = (dict.get('SMask', 'SM') || false);
  15335. var mask = (dict.get('Mask') || false);
  15336. var SMALL_IMAGE_DIMENSIONS = 200;
  15337. // Inlining small images into the queue as RGB data
  15338. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  15339. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  15340. var imageObj = new PDFImage(this.xref, resources, image,
  15341. inline, null, null);
  15342. // We force the use of RGBA_32BPP images here, because we can't handle
  15343. // any other kind.
  15344. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  15345. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  15346. return;
  15347. }
  15348. // If there is no imageMask, create the PDFImage and a lot
  15349. // of image processing can be done here.
  15350. var uniquePrefix = (this.uniquePrefix || '');
  15351. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  15352. operatorList.addDependency(objId);
  15353. args = [objId, w, h];
  15354. if (!softMask && !mask && image instanceof JpegStream &&
  15355. image.isNativelySupported(this.xref, resources)) {
  15356. // These JPEGs don't need any more processing so we can just send it.
  15357. operatorList.addOp(OPS.paintJpegXObject, args);
  15358. this.handler.send('obj',
  15359. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  15360. return;
  15361. }
  15362. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  15363. then(function(imageObj) {
  15364. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  15365. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  15366. [imgData.data.buffer]);
  15367. }).then(undefined, function (reason) {
  15368. warn('Unable to decode image: ' + reason);
  15369. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  15370. });
  15371. operatorList.addOp(OPS.paintImageXObject, args);
  15372. if (cacheKey) {
  15373. imageCache[cacheKey] = {
  15374. fn: OPS.paintImageXObject,
  15375. args: args
  15376. };
  15377. }
  15378. },
  15379. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  15380. operatorList,
  15381. stateManager) {
  15382. var smaskContent = smask.get('G');
  15383. var smaskOptions = {
  15384. subtype: smask.get('S').name,
  15385. backdrop: smask.get('BC')
  15386. };
  15387. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  15388. operatorList, stateManager.state.clone());
  15389. },
  15390. handleTilingType:
  15391. function PartialEvaluator_handleTilingType(fn, args, resources,
  15392. pattern, patternDict,
  15393. operatorList) {
  15394. // Create an IR of the pattern code.
  15395. var tilingOpList = new OperatorList();
  15396. return this.getOperatorList(pattern,
  15397. (patternDict.get('Resources') || resources), tilingOpList).
  15398. then(function () {
  15399. // Add the dependencies to the parent operator list so they are
  15400. // resolved before sub operator list is executed synchronously.
  15401. operatorList.addDependencies(tilingOpList.dependencies);
  15402. operatorList.addOp(fn, getTilingPatternIR({
  15403. fnArray: tilingOpList.fnArray,
  15404. argsArray: tilingOpList.argsArray
  15405. }, patternDict, args));
  15406. });
  15407. },
  15408. handleSetFont:
  15409. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  15410. operatorList, state) {
  15411. // TODO(mack): Not needed?
  15412. var fontName;
  15413. if (fontArgs) {
  15414. fontArgs = fontArgs.slice();
  15415. fontName = fontArgs[0].name;
  15416. }
  15417. var self = this;
  15418. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  15419. function (translated) {
  15420. if (!translated.font.isType3Font) {
  15421. return translated;
  15422. }
  15423. return translated.loadType3Data(self, resources, operatorList).then(
  15424. function () {
  15425. return translated;
  15426. });
  15427. }).then(function (translated) {
  15428. state.font = translated.font;
  15429. translated.send(self.handler);
  15430. return translated.loadedName;
  15431. });
  15432. },
  15433. handleText: function PartialEvaluator_handleText(chars, state) {
  15434. var font = state.font;
  15435. var glyphs = font.charsToGlyphs(chars);
  15436. var isAddToPathSet = !!(state.textRenderingMode &
  15437. TextRenderingMode.ADD_TO_PATH_FLAG);
  15438. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  15439. var buildPath = function (fontChar) {
  15440. if (!font.renderer.hasBuiltPath(fontChar)) {
  15441. var path = font.renderer.getPathJs(fontChar);
  15442. this.handler.send('commonobj', [
  15443. font.loadedName + '_path_' + fontChar,
  15444. 'FontPath',
  15445. path
  15446. ]);
  15447. }
  15448. }.bind(this);
  15449. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  15450. var glyph = glyphs[i];
  15451. if (glyph === null) {
  15452. continue;
  15453. }
  15454. buildPath(glyph.fontChar);
  15455. // If the glyph has an accent we need to build a path for its
  15456. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  15457. var accent = glyph.accent;
  15458. if (accent && accent.fontChar) {
  15459. buildPath(accent.fontChar);
  15460. }
  15461. }
  15462. }
  15463. return glyphs;
  15464. },
  15465. setGState: function PartialEvaluator_setGState(resources, gState,
  15466. operatorList, xref,
  15467. stateManager) {
  15468. // This array holds the converted/processed state data.
  15469. var gStateObj = [];
  15470. var gStateMap = gState.map;
  15471. var self = this;
  15472. var promise = Promise.resolve();
  15473. for (var key in gStateMap) {
  15474. var value = gStateMap[key];
  15475. switch (key) {
  15476. case 'Type':
  15477. break;
  15478. case 'LW':
  15479. case 'LC':
  15480. case 'LJ':
  15481. case 'ML':
  15482. case 'D':
  15483. case 'RI':
  15484. case 'FL':
  15485. case 'CA':
  15486. case 'ca':
  15487. gStateObj.push([key, value]);
  15488. break;
  15489. case 'Font':
  15490. promise = promise.then(function () {
  15491. return self.handleSetFont(resources, null, value[0],
  15492. operatorList, stateManager.state).
  15493. then(function (loadedName) {
  15494. operatorList.addDependency(loadedName);
  15495. gStateObj.push([key, [loadedName, value[1]]]);
  15496. });
  15497. });
  15498. break;
  15499. case 'BM':
  15500. gStateObj.push([key, value]);
  15501. break;
  15502. case 'SMask':
  15503. if (isName(value) && value.name === 'None') {
  15504. gStateObj.push([key, false]);
  15505. break;
  15506. }
  15507. var dict = xref.fetchIfRef(value);
  15508. if (isDict(dict)) {
  15509. promise = promise.then(function () {
  15510. return self.handleSMask(dict, resources, operatorList,
  15511. stateManager);
  15512. });
  15513. gStateObj.push([key, true]);
  15514. } else {
  15515. warn('Unsupported SMask type');
  15516. }
  15517. break;
  15518. // Only generate info log messages for the following since
  15519. // they are unlikely to have a big impact on the rendering.
  15520. case 'OP':
  15521. case 'op':
  15522. case 'OPM':
  15523. case 'BG':
  15524. case 'BG2':
  15525. case 'UCR':
  15526. case 'UCR2':
  15527. case 'TR':
  15528. case 'TR2':
  15529. case 'HT':
  15530. case 'SM':
  15531. case 'SA':
  15532. case 'AIS':
  15533. case 'TK':
  15534. // TODO implement these operators.
  15535. info('graphic state operator ' + key);
  15536. break;
  15537. default:
  15538. info('Unknown graphic state operator ' + key);
  15539. break;
  15540. }
  15541. }
  15542. return promise.then(function () {
  15543. if (gStateObj.length >= 0) {
  15544. operatorList.addOp(OPS.setGState, [gStateObj]);
  15545. }
  15546. });
  15547. },
  15548. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  15549. resources) {
  15550. function errorFont() {
  15551. return Promise.resolve(new TranslatedFont('g_font_error',
  15552. new ErrorFont('Font ' + fontName + ' is not available'), font));
  15553. }
  15554. var fontRef;
  15555. if (font) { // Loading by ref.
  15556. assert(isRef(font));
  15557. fontRef = font;
  15558. } else { // Loading by name.
  15559. var fontRes = resources.get('Font');
  15560. if (fontRes) {
  15561. fontRef = fontRes.getRaw(fontName);
  15562. } else {
  15563. warn('fontRes not available');
  15564. return errorFont();
  15565. }
  15566. }
  15567. if (!fontRef) {
  15568. warn('fontRef not available');
  15569. return errorFont();
  15570. }
  15571. if (this.fontCache.has(fontRef)) {
  15572. return this.fontCache.get(fontRef);
  15573. }
  15574. font = xref.fetchIfRef(fontRef);
  15575. if (!isDict(font)) {
  15576. return errorFont();
  15577. }
  15578. // We are holding font.translated references just for fontRef that are not
  15579. // dictionaries (Dict). See explanation below.
  15580. if (font.translated) {
  15581. return font.translated;
  15582. }
  15583. var fontCapability = createPromiseCapability();
  15584. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  15585. var descriptor = preEvaluatedFont.descriptor;
  15586. var fontID = fontRef.num + '_' + fontRef.gen;
  15587. if (isDict(descriptor)) {
  15588. if (!descriptor.fontAliases) {
  15589. descriptor.fontAliases = Object.create(null);
  15590. }
  15591. var fontAliases = descriptor.fontAliases;
  15592. var hash = preEvaluatedFont.hash;
  15593. if (fontAliases[hash]) {
  15594. var aliasFontRef = fontAliases[hash].aliasRef;
  15595. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  15596. this.fontCache.putAlias(fontRef, aliasFontRef);
  15597. return this.fontCache.get(fontRef);
  15598. }
  15599. }
  15600. if (!fontAliases[hash]) {
  15601. fontAliases[hash] = {
  15602. fontID: Font.getFontID()
  15603. };
  15604. }
  15605. fontAliases[hash].aliasRef = fontRef;
  15606. fontID = fontAliases[hash].fontID;
  15607. }
  15608. // Workaround for bad PDF generators that don't reference fonts
  15609. // properly, i.e. by not using an object identifier.
  15610. // Check if the fontRef is a Dict (as opposed to a standard object),
  15611. // in which case we don't cache the font and instead reference it by
  15612. // fontName in font.loadedName below.
  15613. var fontRefIsDict = isDict(fontRef);
  15614. if (!fontRefIsDict) {
  15615. this.fontCache.put(fontRef, fontCapability.promise);
  15616. }
  15617. // Keep track of each font we translated so the caller can
  15618. // load them asynchronously before calling display on a page.
  15619. font.loadedName = 'g_font_' + (fontRefIsDict ?
  15620. fontName.replace(/\W/g, '') : fontID);
  15621. font.translated = fontCapability.promise;
  15622. // TODO move promises into translate font
  15623. var translatedPromise;
  15624. try {
  15625. translatedPromise = Promise.resolve(
  15626. this.translateFont(preEvaluatedFont, xref));
  15627. } catch (e) {
  15628. translatedPromise = Promise.reject(e);
  15629. }
  15630. translatedPromise.then(function (translatedFont) {
  15631. if (translatedFont.fontType !== undefined) {
  15632. var xrefFontStats = xref.stats.fontTypes;
  15633. xrefFontStats[translatedFont.fontType] = true;
  15634. }
  15635. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15636. translatedFont, font));
  15637. }, function (reason) {
  15638. // TODO fontCapability.reject?
  15639. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  15640. try {
  15641. // error, but it's still nice to have font type reported
  15642. var descriptor = preEvaluatedFont.descriptor;
  15643. var fontFile3 = descriptor && descriptor.get('FontFile3');
  15644. var subtype = fontFile3 && fontFile3.get('Subtype');
  15645. var fontType = getFontType(preEvaluatedFont.type,
  15646. subtype && subtype.name);
  15647. var xrefFontStats = xref.stats.fontTypes;
  15648. xrefFontStats[fontType] = true;
  15649. } catch (ex) { }
  15650. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15651. new ErrorFont(reason instanceof Error ? reason.message : reason),
  15652. font));
  15653. });
  15654. return fontCapability.promise;
  15655. },
  15656. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  15657. var lastIndex = operatorList.length - 1;
  15658. if (!args) {
  15659. args = [];
  15660. }
  15661. if (lastIndex < 0 ||
  15662. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  15663. operatorList.addOp(OPS.constructPath, [[fn], args]);
  15664. } else {
  15665. var opArgs = operatorList.argsArray[lastIndex];
  15666. opArgs[0].push(fn);
  15667. Array.prototype.push.apply(opArgs[1], args);
  15668. }
  15669. },
  15670. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  15671. cs, patterns, resources, xref) {
  15672. // compile tiling patterns
  15673. var patternName = args[args.length - 1];
  15674. // SCN/scn applies patterns along with normal colors
  15675. var pattern;
  15676. if (isName(patternName) &&
  15677. (pattern = patterns.get(patternName.name))) {
  15678. var dict = (isStream(pattern) ? pattern.dict : pattern);
  15679. var typeNum = dict.get('PatternType');
  15680. if (typeNum === TILING_PATTERN) {
  15681. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  15682. return this.handleTilingType(fn, color, resources, pattern,
  15683. dict, operatorList);
  15684. } else if (typeNum === SHADING_PATTERN) {
  15685. var shading = dict.get('Shading');
  15686. var matrix = dict.get('Matrix');
  15687. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  15688. operatorList.addOp(fn, pattern.getIR());
  15689. return Promise.resolve();
  15690. } else {
  15691. return Promise.reject('Unknown PatternType: ' + typeNum);
  15692. }
  15693. }
  15694. // TODO shall we fail here?
  15695. operatorList.addOp(fn, args);
  15696. return Promise.resolve();
  15697. },
  15698. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  15699. resources,
  15700. operatorList,
  15701. initialState) {
  15702. var self = this;
  15703. var xref = this.xref;
  15704. var imageCache = {};
  15705. assert(operatorList);
  15706. resources = (resources || Dict.empty);
  15707. var xobjs = (resources.get('XObject') || Dict.empty);
  15708. var patterns = (resources.get('Pattern') || Dict.empty);
  15709. var stateManager = new StateManager(initialState || new EvalState());
  15710. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15711. var timeSlotManager = new TimeSlotManager();
  15712. return new Promise(function next(resolve, reject) {
  15713. timeSlotManager.reset();
  15714. var stop, operation = {}, i, ii, cs;
  15715. while (!(stop = timeSlotManager.check())) {
  15716. // The arguments parsed by read() are used beyond this loop, so we
  15717. // cannot reuse the same array on each iteration. Therefore we pass
  15718. // in |null| as the initial value (see the comment on
  15719. // EvaluatorPreprocessor_read() for why).
  15720. operation.args = null;
  15721. if (!(preprocessor.read(operation))) {
  15722. break;
  15723. }
  15724. var args = operation.args;
  15725. var fn = operation.fn;
  15726. switch (fn | 0) {
  15727. case OPS.paintXObject:
  15728. if (args[0].code) {
  15729. break;
  15730. }
  15731. // eagerly compile XForm objects
  15732. var name = args[0].name;
  15733. if (imageCache[name] !== undefined) {
  15734. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  15735. args = null;
  15736. continue;
  15737. }
  15738. var xobj = xobjs.get(name);
  15739. if (xobj) {
  15740. assert(isStream(xobj), 'XObject should be a stream');
  15741. var type = xobj.dict.get('Subtype');
  15742. assert(isName(type),
  15743. 'XObject should have a Name subtype');
  15744. if (type.name === 'Form') {
  15745. stateManager.save();
  15746. return self.buildFormXObject(resources, xobj, null,
  15747. operatorList,
  15748. stateManager.state.clone()).
  15749. then(function () {
  15750. stateManager.restore();
  15751. next(resolve, reject);
  15752. }, reject);
  15753. } else if (type.name === 'Image') {
  15754. self.buildPaintImageXObject(resources, xobj, false,
  15755. operatorList, name, imageCache);
  15756. args = null;
  15757. continue;
  15758. } else if (type.name === 'PS') {
  15759. // PostScript XObjects are unused when viewing documents.
  15760. // See section 4.7.1 of Adobe's PDF reference.
  15761. info('Ignored XObject subtype PS');
  15762. continue;
  15763. } else {
  15764. error('Unhandled XObject subtype ' + type.name);
  15765. }
  15766. }
  15767. break;
  15768. case OPS.setFont:
  15769. var fontSize = args[1];
  15770. // eagerly collect all fonts
  15771. return self.handleSetFont(resources, args, null,
  15772. operatorList, stateManager.state).
  15773. then(function (loadedName) {
  15774. operatorList.addDependency(loadedName);
  15775. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  15776. next(resolve, reject);
  15777. }, reject);
  15778. case OPS.endInlineImage:
  15779. var cacheKey = args[0].cacheKey;
  15780. if (cacheKey) {
  15781. var cacheEntry = imageCache[cacheKey];
  15782. if (cacheEntry !== undefined) {
  15783. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  15784. args = null;
  15785. continue;
  15786. }
  15787. }
  15788. self.buildPaintImageXObject(resources, args[0], true,
  15789. operatorList, cacheKey, imageCache);
  15790. args = null;
  15791. continue;
  15792. case OPS.showText:
  15793. args[0] = self.handleText(args[0], stateManager.state);
  15794. break;
  15795. case OPS.showSpacedText:
  15796. var arr = args[0];
  15797. var combinedGlyphs = [];
  15798. var arrLength = arr.length;
  15799. for (i = 0; i < arrLength; ++i) {
  15800. var arrItem = arr[i];
  15801. if (isString(arrItem)) {
  15802. Array.prototype.push.apply(combinedGlyphs,
  15803. self.handleText(arrItem, stateManager.state));
  15804. } else if (isNum(arrItem)) {
  15805. combinedGlyphs.push(arrItem);
  15806. }
  15807. }
  15808. args[0] = combinedGlyphs;
  15809. fn = OPS.showText;
  15810. break;
  15811. case OPS.nextLineShowText:
  15812. operatorList.addOp(OPS.nextLine);
  15813. args[0] = self.handleText(args[0], stateManager.state);
  15814. fn = OPS.showText;
  15815. break;
  15816. case OPS.nextLineSetSpacingShowText:
  15817. operatorList.addOp(OPS.nextLine);
  15818. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  15819. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  15820. args[0] = self.handleText(args[0], stateManager.state);
  15821. fn = OPS.showText;
  15822. break;
  15823. case OPS.setTextRenderingMode:
  15824. stateManager.state.textRenderingMode = args[0];
  15825. break;
  15826. case OPS.setFillColorSpace:
  15827. stateManager.state.fillColorSpace =
  15828. ColorSpace.parse(args[0], xref, resources);
  15829. continue;
  15830. case OPS.setStrokeColorSpace:
  15831. stateManager.state.strokeColorSpace =
  15832. ColorSpace.parse(args[0], xref, resources);
  15833. continue;
  15834. case OPS.setFillColor:
  15835. cs = stateManager.state.fillColorSpace;
  15836. args = cs.getRgb(args, 0);
  15837. fn = OPS.setFillRGBColor;
  15838. break;
  15839. case OPS.setStrokeColor:
  15840. cs = stateManager.state.strokeColorSpace;
  15841. args = cs.getRgb(args, 0);
  15842. fn = OPS.setStrokeRGBColor;
  15843. break;
  15844. case OPS.setFillGray:
  15845. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  15846. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15847. fn = OPS.setFillRGBColor;
  15848. break;
  15849. case OPS.setStrokeGray:
  15850. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  15851. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15852. fn = OPS.setStrokeRGBColor;
  15853. break;
  15854. case OPS.setFillCMYKColor:
  15855. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  15856. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15857. fn = OPS.setFillRGBColor;
  15858. break;
  15859. case OPS.setStrokeCMYKColor:
  15860. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  15861. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15862. fn = OPS.setStrokeRGBColor;
  15863. break;
  15864. case OPS.setFillRGBColor:
  15865. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  15866. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15867. break;
  15868. case OPS.setStrokeRGBColor:
  15869. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  15870. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15871. break;
  15872. case OPS.setFillColorN:
  15873. cs = stateManager.state.fillColorSpace;
  15874. if (cs.name === 'Pattern') {
  15875. return self.handleColorN(operatorList, OPS.setFillColorN,
  15876. args, cs, patterns, resources, xref).then(function() {
  15877. next(resolve, reject);
  15878. }, reject);
  15879. }
  15880. args = cs.getRgb(args, 0);
  15881. fn = OPS.setFillRGBColor;
  15882. break;
  15883. case OPS.setStrokeColorN:
  15884. cs = stateManager.state.strokeColorSpace;
  15885. if (cs.name === 'Pattern') {
  15886. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  15887. args, cs, patterns, resources, xref).then(function() {
  15888. next(resolve, reject);
  15889. }, reject);
  15890. }
  15891. args = cs.getRgb(args, 0);
  15892. fn = OPS.setStrokeRGBColor;
  15893. break;
  15894. case OPS.shadingFill:
  15895. var shadingRes = resources.get('Shading');
  15896. if (!shadingRes) {
  15897. error('No shading resource found');
  15898. }
  15899. var shading = shadingRes.get(args[0].name);
  15900. if (!shading) {
  15901. error('No shading object found');
  15902. }
  15903. var shadingFill = Pattern.parseShading(shading, null, xref,
  15904. resources);
  15905. var patternIR = shadingFill.getIR();
  15906. args = [patternIR];
  15907. fn = OPS.shadingFill;
  15908. break;
  15909. case OPS.setGState:
  15910. var dictName = args[0];
  15911. var extGState = resources.get('ExtGState');
  15912. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15913. break;
  15914. }
  15915. var gState = extGState.get(dictName.name);
  15916. return self.setGState(resources, gState, operatorList, xref,
  15917. stateManager).then(function() {
  15918. next(resolve, reject);
  15919. }, reject);
  15920. case OPS.moveTo:
  15921. case OPS.lineTo:
  15922. case OPS.curveTo:
  15923. case OPS.curveTo2:
  15924. case OPS.curveTo3:
  15925. case OPS.closePath:
  15926. self.buildPath(operatorList, fn, args);
  15927. continue;
  15928. case OPS.rectangle:
  15929. self.buildPath(operatorList, fn, args);
  15930. continue;
  15931. }
  15932. operatorList.addOp(fn, args);
  15933. }
  15934. if (stop) {
  15935. deferred.then(function () {
  15936. next(resolve, reject);
  15937. });
  15938. return;
  15939. }
  15940. // Some PDFs don't close all restores inside object/form.
  15941. // Closing those for them.
  15942. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  15943. operatorList.addOp(OPS.restore, []);
  15944. }
  15945. resolve();
  15946. });
  15947. },
  15948. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  15949. stateManager) {
  15950. stateManager = (stateManager || new StateManager(new TextState()));
  15951. var textContent = {
  15952. items: [],
  15953. styles: Object.create(null)
  15954. };
  15955. var bidiTexts = textContent.items;
  15956. var SPACE_FACTOR = 0.35;
  15957. var MULTI_SPACE_FACTOR = 1.5;
  15958. var self = this;
  15959. var xref = this.xref;
  15960. resources = (xref.fetchIfRef(resources) || Dict.empty);
  15961. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  15962. var xobjs = null;
  15963. var xobjsCache = {};
  15964. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15965. var textState;
  15966. function newTextChunk() {
  15967. var font = textState.font;
  15968. if (!(font.loadedName in textContent.styles)) {
  15969. textContent.styles[font.loadedName] = {
  15970. fontFamily: font.fallbackName,
  15971. ascent: font.ascent,
  15972. descent: font.descent,
  15973. vertical: font.vertical
  15974. };
  15975. }
  15976. return {
  15977. // |str| is initially an array which we push individual chars to, and
  15978. // then runBidi() overwrites it with the final string.
  15979. str: [],
  15980. dir: null,
  15981. width: 0,
  15982. height: 0,
  15983. transform: null,
  15984. fontName: font.loadedName
  15985. };
  15986. }
  15987. function runBidi(textChunk) {
  15988. var str = textChunk.str.join('');
  15989. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  15990. textChunk.str = bidiResult.str;
  15991. textChunk.dir = bidiResult.dir;
  15992. return textChunk;
  15993. }
  15994. function handleSetFont(fontName, fontRef) {
  15995. return self.loadFont(fontName, fontRef, xref, resources).
  15996. then(function (translated) {
  15997. textState.font = translated.font;
  15998. textState.fontMatrix = translated.font.fontMatrix ||
  15999. FONT_IDENTITY_MATRIX;
  16000. });
  16001. }
  16002. function buildTextGeometry(chars, textChunk) {
  16003. var font = textState.font;
  16004. textChunk = textChunk || newTextChunk();
  16005. if (!textChunk.transform) {
  16006. // 9.4.4 Text Space Details
  16007. var tsm = [textState.fontSize * textState.textHScale, 0,
  16008. 0, textState.fontSize,
  16009. 0, textState.textRise];
  16010. var trm = textChunk.transform = Util.transform(textState.ctm,
  16011. Util.transform(textState.textMatrix, tsm));
  16012. if (!font.vertical) {
  16013. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  16014. } else {
  16015. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  16016. }
  16017. }
  16018. var width = 0;
  16019. var height = 0;
  16020. var glyphs = font.charsToGlyphs(chars);
  16021. var defaultVMetrics = font.defaultVMetrics;
  16022. for (var i = 0; i < glyphs.length; i++) {
  16023. var glyph = glyphs[i];
  16024. if (!glyph) { // Previous glyph was a space.
  16025. width += textState.wordSpacing * textState.textHScale;
  16026. continue;
  16027. }
  16028. var vMetricX = null;
  16029. var vMetricY = null;
  16030. var glyphWidth = null;
  16031. if (font.vertical) {
  16032. if (glyph.vmetric) {
  16033. glyphWidth = glyph.vmetric[0];
  16034. vMetricX = glyph.vmetric[1];
  16035. vMetricY = glyph.vmetric[2];
  16036. } else {
  16037. glyphWidth = glyph.width;
  16038. vMetricX = glyph.width * 0.5;
  16039. vMetricY = defaultVMetrics[2];
  16040. }
  16041. } else {
  16042. glyphWidth = glyph.width;
  16043. }
  16044. var glyphUnicode = glyph.unicode;
  16045. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  16046. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  16047. }
  16048. glyphUnicode = reverseIfRtl(glyphUnicode);
  16049. // The following will calculate the x and y of the individual glyphs.
  16050. // if (font.vertical) {
  16051. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  16052. // textState.fontMatrix[0];
  16053. // tsm[5] -= vMetricY * textState.fontSize *
  16054. // textState.fontMatrix[0];
  16055. // }
  16056. // var trm = Util.transform(textState.textMatrix, tsm);
  16057. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  16058. // var x = pt[0];
  16059. // var y = pt[1];
  16060. var tx = 0;
  16061. var ty = 0;
  16062. if (!font.vertical) {
  16063. var w0 = glyphWidth * textState.fontMatrix[0];
  16064. tx = (w0 * textState.fontSize + textState.charSpacing) *
  16065. textState.textHScale;
  16066. width += tx;
  16067. } else {
  16068. var w1 = glyphWidth * textState.fontMatrix[0];
  16069. ty = w1 * textState.fontSize + textState.charSpacing;
  16070. height += ty;
  16071. }
  16072. textState.translateTextMatrix(tx, ty);
  16073. textChunk.str.push(glyphUnicode);
  16074. }
  16075. var a = textState.textLineMatrix[0];
  16076. var b = textState.textLineMatrix[1];
  16077. var scaleLineX = Math.sqrt(a * a + b * b);
  16078. a = textState.ctm[0];
  16079. b = textState.ctm[1];
  16080. var scaleCtmX = Math.sqrt(a * a + b * b);
  16081. if (!font.vertical) {
  16082. textChunk.width += width * scaleCtmX * scaleLineX;
  16083. } else {
  16084. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  16085. }
  16086. return textChunk;
  16087. }
  16088. var timeSlotManager = new TimeSlotManager();
  16089. return new Promise(function next(resolve, reject) {
  16090. timeSlotManager.reset();
  16091. var stop, operation = {}, args = [];
  16092. while (!(stop = timeSlotManager.check())) {
  16093. // The arguments parsed by read() are not used beyond this loop, so
  16094. // we can reuse the same array on every iteration, thus avoiding
  16095. // unnecessary allocations.
  16096. args.length = 0;
  16097. operation.args = args;
  16098. if (!(preprocessor.read(operation))) {
  16099. break;
  16100. }
  16101. textState = stateManager.state;
  16102. var fn = operation.fn;
  16103. args = operation.args;
  16104. switch (fn | 0) {
  16105. case OPS.setFont:
  16106. textState.fontSize = args[1];
  16107. return handleSetFont(args[0].name).then(function() {
  16108. next(resolve, reject);
  16109. }, reject);
  16110. case OPS.setTextRise:
  16111. textState.textRise = args[0];
  16112. break;
  16113. case OPS.setHScale:
  16114. textState.textHScale = args[0] / 100;
  16115. break;
  16116. case OPS.setLeading:
  16117. textState.leading = args[0];
  16118. break;
  16119. case OPS.moveText:
  16120. textState.translateTextLineMatrix(args[0], args[1]);
  16121. textState.textMatrix = textState.textLineMatrix.slice();
  16122. break;
  16123. case OPS.setLeadingMoveText:
  16124. textState.leading = -args[1];
  16125. textState.translateTextLineMatrix(args[0], args[1]);
  16126. textState.textMatrix = textState.textLineMatrix.slice();
  16127. break;
  16128. case OPS.nextLine:
  16129. textState.carriageReturn();
  16130. break;
  16131. case OPS.setTextMatrix:
  16132. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  16133. args[4], args[5]);
  16134. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  16135. args[4], args[5]);
  16136. break;
  16137. case OPS.setCharSpacing:
  16138. textState.charSpacing = args[0];
  16139. break;
  16140. case OPS.setWordSpacing:
  16141. textState.wordSpacing = args[0];
  16142. break;
  16143. case OPS.beginText:
  16144. textState.textMatrix = IDENTITY_MATRIX.slice();
  16145. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  16146. break;
  16147. case OPS.showSpacedText:
  16148. var items = args[0];
  16149. var textChunk = newTextChunk();
  16150. var offset;
  16151. for (var j = 0, jj = items.length; j < jj; j++) {
  16152. if (typeof items[j] === 'string') {
  16153. buildTextGeometry(items[j], textChunk);
  16154. } else {
  16155. var val = items[j] / 1000;
  16156. if (!textState.font.vertical) {
  16157. offset = -val * textState.fontSize * textState.textHScale *
  16158. textState.textMatrix[0];
  16159. textState.translateTextMatrix(offset, 0);
  16160. textChunk.width += offset;
  16161. } else {
  16162. offset = -val * textState.fontSize *
  16163. textState.textMatrix[3];
  16164. textState.translateTextMatrix(0, offset);
  16165. textChunk.height += offset;
  16166. }
  16167. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  16168. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  16169. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  16170. fakeSpaces = Math.round(fakeSpaces);
  16171. while (fakeSpaces--) {
  16172. textChunk.str.push(' ');
  16173. }
  16174. } else if (fakeSpaces > SPACE_FACTOR) {
  16175. textChunk.str.push(' ');
  16176. }
  16177. }
  16178. }
  16179. }
  16180. bidiTexts.push(runBidi(textChunk));
  16181. break;
  16182. case OPS.showText:
  16183. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16184. break;
  16185. case OPS.nextLineShowText:
  16186. textState.carriageReturn();
  16187. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16188. break;
  16189. case OPS.nextLineSetSpacingShowText:
  16190. textState.wordSpacing = args[0];
  16191. textState.charSpacing = args[1];
  16192. textState.carriageReturn();
  16193. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  16194. break;
  16195. case OPS.paintXObject:
  16196. if (args[0].code) {
  16197. break;
  16198. }
  16199. if (!xobjs) {
  16200. xobjs = (resources.get('XObject') || Dict.empty);
  16201. }
  16202. var name = args[0].name;
  16203. if (xobjsCache.key === name) {
  16204. if (xobjsCache.texts) {
  16205. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  16206. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  16207. }
  16208. break;
  16209. }
  16210. var xobj = xobjs.get(name);
  16211. if (!xobj) {
  16212. break;
  16213. }
  16214. assert(isStream(xobj), 'XObject should be a stream');
  16215. var type = xobj.dict.get('Subtype');
  16216. assert(isName(type),
  16217. 'XObject should have a Name subtype');
  16218. if ('Form' !== type.name) {
  16219. xobjsCache.key = name;
  16220. xobjsCache.texts = null;
  16221. break;
  16222. }
  16223. stateManager.save();
  16224. var matrix = xobj.dict.get('Matrix');
  16225. if (isArray(matrix) && matrix.length === 6) {
  16226. stateManager.transform(matrix);
  16227. }
  16228. return self.getTextContent(xobj,
  16229. xobj.dict.get('Resources') || resources, stateManager).
  16230. then(function (formTextContent) {
  16231. Util.appendToArray(bidiTexts, formTextContent.items);
  16232. Util.extendObj(textContent.styles, formTextContent.styles);
  16233. stateManager.restore();
  16234. xobjsCache.key = name;
  16235. xobjsCache.texts = formTextContent;
  16236. next(resolve, reject);
  16237. }, reject);
  16238. case OPS.setGState:
  16239. var dictName = args[0];
  16240. var extGState = resources.get('ExtGState');
  16241. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  16242. break;
  16243. }
  16244. var gsStateMap = extGState.get(dictName.name);
  16245. var gsStateFont = null;
  16246. for (var key in gsStateMap) {
  16247. if (key === 'Font') {
  16248. assert(!gsStateFont);
  16249. gsStateFont = gsStateMap[key];
  16250. }
  16251. }
  16252. if (gsStateFont) {
  16253. textState.fontSize = gsStateFont[1];
  16254. return handleSetFont(gsStateFont[0]).then(function() {
  16255. next(resolve, reject);
  16256. }, reject);
  16257. }
  16258. break;
  16259. } // switch
  16260. } // while
  16261. if (stop) {
  16262. deferred.then(function () {
  16263. next(resolve, reject);
  16264. });
  16265. return;
  16266. }
  16267. resolve(textContent);
  16268. });
  16269. },
  16270. extractDataStructures: function
  16271. partialEvaluatorExtractDataStructures(dict, baseDict,
  16272. xref, properties) {
  16273. // 9.10.2
  16274. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  16275. if (toUnicode) {
  16276. properties.toUnicode = this.readToUnicode(toUnicode);
  16277. }
  16278. if (properties.composite) {
  16279. // CIDSystemInfo helps to match CID to glyphs
  16280. var cidSystemInfo = dict.get('CIDSystemInfo');
  16281. if (isDict(cidSystemInfo)) {
  16282. properties.cidSystemInfo = {
  16283. registry: cidSystemInfo.get('Registry'),
  16284. ordering: cidSystemInfo.get('Ordering'),
  16285. supplement: cidSystemInfo.get('Supplement')
  16286. };
  16287. }
  16288. var cidToGidMap = dict.get('CIDToGIDMap');
  16289. if (isStream(cidToGidMap)) {
  16290. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  16291. }
  16292. }
  16293. // Based on 9.6.6 of the spec the encoding can come from multiple places
  16294. // and depends on the font type. The base encoding and differences are
  16295. // read here, but the encoding that is actually used is chosen during
  16296. // glyph mapping in the font.
  16297. // TODO: Loading the built in encoding in the font would allow the
  16298. // differences to be merged in here not require us to hold on to it.
  16299. var differences = [];
  16300. var baseEncodingName = null;
  16301. var encoding;
  16302. if (dict.has('Encoding')) {
  16303. encoding = dict.get('Encoding');
  16304. if (isDict(encoding)) {
  16305. baseEncodingName = encoding.get('BaseEncoding');
  16306. baseEncodingName = (isName(baseEncodingName) ?
  16307. baseEncodingName.name : null);
  16308. // Load the differences between the base and original
  16309. if (encoding.has('Differences')) {
  16310. var diffEncoding = encoding.get('Differences');
  16311. var index = 0;
  16312. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  16313. var data = diffEncoding[j];
  16314. if (isNum(data)) {
  16315. index = data;
  16316. } else {
  16317. differences[index++] = data.name;
  16318. }
  16319. }
  16320. }
  16321. } else if (isName(encoding)) {
  16322. baseEncodingName = encoding.name;
  16323. } else {
  16324. error('Encoding is not a Name nor a Dict');
  16325. }
  16326. // According to table 114 if the encoding is a named encoding it must be
  16327. // one of these predefined encodings.
  16328. if ((baseEncodingName !== 'MacRomanEncoding' &&
  16329. baseEncodingName !== 'MacExpertEncoding' &&
  16330. baseEncodingName !== 'WinAnsiEncoding')) {
  16331. baseEncodingName = null;
  16332. }
  16333. }
  16334. if (baseEncodingName) {
  16335. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  16336. } else {
  16337. encoding = (properties.type === 'TrueType' ?
  16338. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  16339. // The Symbolic attribute can be misused for regular fonts
  16340. // Heuristic: we have to check if the font is a standard one also
  16341. if (!!(properties.flags & FontFlags.Symbolic)) {
  16342. encoding = Encodings.MacRomanEncoding;
  16343. if (!properties.file) {
  16344. if (/Symbol/i.test(properties.name)) {
  16345. encoding = Encodings.SymbolSetEncoding;
  16346. } else if (/Dingbats/i.test(properties.name)) {
  16347. encoding = Encodings.ZapfDingbatsEncoding;
  16348. }
  16349. }
  16350. }
  16351. properties.defaultEncoding = encoding;
  16352. }
  16353. properties.differences = differences;
  16354. properties.baseEncodingName = baseEncodingName;
  16355. properties.dict = dict;
  16356. },
  16357. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  16358. var cmap, cmapObj = toUnicode;
  16359. if (isName(cmapObj)) {
  16360. cmap = CMapFactory.create(cmapObj,
  16361. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16362. return new ToUnicodeMap(cmap);
  16363. } else if (isStream(cmapObj)) {
  16364. cmap = CMapFactory.create(cmapObj,
  16365. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16366. // Convert UTF-16BE
  16367. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  16368. // to iterate over all keys.
  16369. cmap.forEach(function(token, i) {
  16370. var str = [];
  16371. for (var k = 0; k < token.length; k += 2) {
  16372. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16373. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  16374. str.push(w1);
  16375. continue;
  16376. }
  16377. k += 2;
  16378. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16379. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  16380. }
  16381. cmap[i] = String.fromCharCode.apply(String, str);
  16382. });
  16383. return new ToUnicodeMap(cmap);
  16384. }
  16385. return null;
  16386. },
  16387. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  16388. // Extract the encoding from the CIDToGIDMap
  16389. var glyphsData = cidToGidStream.getBytes();
  16390. // Set encoding 0 to later verify the font has an encoding
  16391. var result = [];
  16392. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  16393. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  16394. if (glyphID === 0) {
  16395. continue;
  16396. }
  16397. var code = j >> 1;
  16398. result[code] = glyphID;
  16399. }
  16400. return result;
  16401. },
  16402. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  16403. descriptor,
  16404. properties) {
  16405. var glyphsWidths = [];
  16406. var defaultWidth = 0;
  16407. var glyphsVMetrics = [];
  16408. var defaultVMetrics;
  16409. var i, ii, j, jj, start, code, widths;
  16410. if (properties.composite) {
  16411. defaultWidth = dict.get('DW') || 1000;
  16412. widths = dict.get('W');
  16413. if (widths) {
  16414. for (i = 0, ii = widths.length; i < ii; i++) {
  16415. start = widths[i++];
  16416. code = xref.fetchIfRef(widths[i]);
  16417. if (isArray(code)) {
  16418. for (j = 0, jj = code.length; j < jj; j++) {
  16419. glyphsWidths[start++] = code[j];
  16420. }
  16421. } else {
  16422. var width = widths[++i];
  16423. for (j = start; j <= code; j++) {
  16424. glyphsWidths[j] = width;
  16425. }
  16426. }
  16427. }
  16428. }
  16429. if (properties.vertical) {
  16430. var vmetrics = (dict.get('DW2') || [880, -1000]);
  16431. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  16432. vmetrics = dict.get('W2');
  16433. if (vmetrics) {
  16434. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  16435. start = vmetrics[i++];
  16436. code = xref.fetchIfRef(vmetrics[i]);
  16437. if (isArray(code)) {
  16438. for (j = 0, jj = code.length; j < jj; j++) {
  16439. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  16440. }
  16441. } else {
  16442. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  16443. for (j = start; j <= code; j++) {
  16444. glyphsVMetrics[j] = vmetric;
  16445. }
  16446. }
  16447. }
  16448. }
  16449. }
  16450. } else {
  16451. var firstChar = properties.firstChar;
  16452. widths = dict.get('Widths');
  16453. if (widths) {
  16454. j = firstChar;
  16455. for (i = 0, ii = widths.length; i < ii; i++) {
  16456. glyphsWidths[j++] = widths[i];
  16457. }
  16458. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  16459. } else {
  16460. // Trying get the BaseFont metrics (see comment above).
  16461. var baseFontName = dict.get('BaseFont');
  16462. if (isName(baseFontName)) {
  16463. var metrics = this.getBaseFontMetrics(baseFontName.name);
  16464. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  16465. properties);
  16466. defaultWidth = metrics.defaultWidth;
  16467. }
  16468. }
  16469. }
  16470. // Heuristic: detection of monospace font by checking all non-zero widths
  16471. var isMonospace = true;
  16472. var firstWidth = defaultWidth;
  16473. for (var glyph in glyphsWidths) {
  16474. var glyphWidth = glyphsWidths[glyph];
  16475. if (!glyphWidth) {
  16476. continue;
  16477. }
  16478. if (!firstWidth) {
  16479. firstWidth = glyphWidth;
  16480. continue;
  16481. }
  16482. if (firstWidth !== glyphWidth) {
  16483. isMonospace = false;
  16484. break;
  16485. }
  16486. }
  16487. if (isMonospace) {
  16488. properties.flags |= FontFlags.FixedPitch;
  16489. }
  16490. properties.defaultWidth = defaultWidth;
  16491. properties.widths = glyphsWidths;
  16492. properties.defaultVMetrics = defaultVMetrics;
  16493. properties.vmetrics = glyphsVMetrics;
  16494. },
  16495. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  16496. // Simulating descriptor flags attribute
  16497. var fontNameWoStyle = baseFontName.split('-')[0];
  16498. return (fontNameWoStyle in serifFonts) ||
  16499. (fontNameWoStyle.search(/serif/gi) !== -1);
  16500. },
  16501. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  16502. var defaultWidth = 0;
  16503. var widths = [];
  16504. var monospace = false;
  16505. var lookupName = (stdFontMap[name] || name);
  16506. if (!(lookupName in Metrics)) {
  16507. // Use default fonts for looking up font metrics if the passed
  16508. // font is not a base font
  16509. if (this.isSerifFont(name)) {
  16510. lookupName = 'Times-Roman';
  16511. } else {
  16512. lookupName = 'Helvetica';
  16513. }
  16514. }
  16515. var glyphWidths = Metrics[lookupName];
  16516. if (isNum(glyphWidths)) {
  16517. defaultWidth = glyphWidths;
  16518. monospace = true;
  16519. } else {
  16520. widths = glyphWidths;
  16521. }
  16522. return {
  16523. defaultWidth: defaultWidth,
  16524. monospace: monospace,
  16525. widths: widths
  16526. };
  16527. },
  16528. buildCharCodeToWidth:
  16529. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  16530. properties) {
  16531. var widths = Object.create(null);
  16532. var differences = properties.differences;
  16533. var encoding = properties.defaultEncoding;
  16534. for (var charCode = 0; charCode < 256; charCode++) {
  16535. if (charCode in differences &&
  16536. widthsByGlyphName[differences[charCode]]) {
  16537. widths[charCode] = widthsByGlyphName[differences[charCode]];
  16538. continue;
  16539. }
  16540. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  16541. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  16542. continue;
  16543. }
  16544. }
  16545. return widths;
  16546. },
  16547. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  16548. var baseDict = dict;
  16549. var type = dict.get('Subtype');
  16550. assert(isName(type), 'invalid font Subtype');
  16551. var composite = false;
  16552. var uint8array;
  16553. if (type.name === 'Type0') {
  16554. // If font is a composite
  16555. // - get the descendant font
  16556. // - set the type according to the descendant font
  16557. // - get the FontDescriptor from the descendant font
  16558. var df = dict.get('DescendantFonts');
  16559. if (!df) {
  16560. error('Descendant fonts are not specified');
  16561. }
  16562. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  16563. type = dict.get('Subtype');
  16564. assert(isName(type), 'invalid font Subtype');
  16565. composite = true;
  16566. }
  16567. var descriptor = dict.get('FontDescriptor');
  16568. if (descriptor) {
  16569. var hash = new MurmurHash3_64();
  16570. var encoding = baseDict.getRaw('Encoding');
  16571. if (isName(encoding)) {
  16572. hash.update(encoding.name);
  16573. } else if (isRef(encoding)) {
  16574. hash.update(encoding.num + '_' + encoding.gen);
  16575. }
  16576. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  16577. if (isStream(toUnicode)) {
  16578. var stream = toUnicode.str || toUnicode;
  16579. uint8array = stream.buffer ?
  16580. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  16581. new Uint8Array(stream.bytes.buffer,
  16582. stream.start, stream.end - stream.start);
  16583. hash.update(uint8array);
  16584. } else if (isName(toUnicode)) {
  16585. hash.update(toUnicode.name);
  16586. }
  16587. var widths = dict.get('Widths') || baseDict.get('Widths');
  16588. if (widths) {
  16589. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  16590. hash.update(uint8array);
  16591. }
  16592. }
  16593. return {
  16594. descriptor: descriptor,
  16595. dict: dict,
  16596. baseDict: baseDict,
  16597. composite: composite,
  16598. type: type.name,
  16599. hash: hash ? hash.hexdigest() : ''
  16600. };
  16601. },
  16602. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  16603. xref) {
  16604. var baseDict = preEvaluatedFont.baseDict;
  16605. var dict = preEvaluatedFont.dict;
  16606. var composite = preEvaluatedFont.composite;
  16607. var descriptor = preEvaluatedFont.descriptor;
  16608. var type = preEvaluatedFont.type;
  16609. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  16610. var properties;
  16611. if (!descriptor) {
  16612. if (type === 'Type3') {
  16613. // FontDescriptor is only required for Type3 fonts when the document
  16614. // is a tagged pdf. Create a barbebones one to get by.
  16615. descriptor = new Dict(null);
  16616. descriptor.set('FontName', Name.get(type));
  16617. } else {
  16618. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  16619. // FontDescriptor was not required.
  16620. // This case is here for compatibility.
  16621. var baseFontName = dict.get('BaseFont');
  16622. if (!isName(baseFontName)) {
  16623. error('Base font is not specified');
  16624. }
  16625. // Using base font name as a font name.
  16626. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  16627. var metrics = this.getBaseFontMetrics(baseFontName);
  16628. // Simulating descriptor flags attribute
  16629. var fontNameWoStyle = baseFontName.split('-')[0];
  16630. var flags =
  16631. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  16632. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  16633. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  16634. FontFlags.Nonsymbolic);
  16635. properties = {
  16636. type: type,
  16637. name: baseFontName,
  16638. widths: metrics.widths,
  16639. defaultWidth: metrics.defaultWidth,
  16640. flags: flags,
  16641. firstChar: 0,
  16642. lastChar: maxCharIndex
  16643. };
  16644. this.extractDataStructures(dict, dict, xref, properties);
  16645. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  16646. properties);
  16647. return new Font(baseFontName, null, properties);
  16648. }
  16649. }
  16650. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  16651. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  16652. // to ignore this rule when a variant of a standart font is used.
  16653. // TODO Fill the width array depending on which of the base font this is
  16654. // a variant.
  16655. var firstChar = (dict.get('FirstChar') || 0);
  16656. var lastChar = (dict.get('LastChar') || maxCharIndex);
  16657. var fontName = descriptor.get('FontName');
  16658. var baseFont = dict.get('BaseFont');
  16659. // Some bad PDFs have a string as the font name.
  16660. if (isString(fontName)) {
  16661. fontName = Name.get(fontName);
  16662. }
  16663. if (isString(baseFont)) {
  16664. baseFont = Name.get(baseFont);
  16665. }
  16666. if (type !== 'Type3') {
  16667. var fontNameStr = fontName && fontName.name;
  16668. var baseFontStr = baseFont && baseFont.name;
  16669. if (fontNameStr !== baseFontStr) {
  16670. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  16671. '" but should be the same as the Font\'s BaseFont "' +
  16672. baseFontStr + '"');
  16673. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  16674. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  16675. if (fontNameStr && baseFontStr &&
  16676. baseFontStr.indexOf(fontNameStr) === 0) {
  16677. fontName = baseFont;
  16678. }
  16679. }
  16680. }
  16681. fontName = (fontName || baseFont);
  16682. assert(isName(fontName), 'invalid font name');
  16683. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  16684. if (fontFile) {
  16685. if (fontFile.dict) {
  16686. var subtype = fontFile.dict.get('Subtype');
  16687. if (subtype) {
  16688. subtype = subtype.name;
  16689. }
  16690. var length1 = fontFile.dict.get('Length1');
  16691. var length2 = fontFile.dict.get('Length2');
  16692. }
  16693. }
  16694. properties = {
  16695. type: type,
  16696. name: fontName.name,
  16697. subtype: subtype,
  16698. file: fontFile,
  16699. length1: length1,
  16700. length2: length2,
  16701. loadedName: baseDict.loadedName,
  16702. composite: composite,
  16703. wideChars: composite,
  16704. fixedPitch: false,
  16705. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  16706. firstChar: firstChar || 0,
  16707. lastChar: (lastChar || maxCharIndex),
  16708. bbox: descriptor.get('FontBBox'),
  16709. ascent: descriptor.get('Ascent'),
  16710. descent: descriptor.get('Descent'),
  16711. xHeight: descriptor.get('XHeight'),
  16712. capHeight: descriptor.get('CapHeight'),
  16713. flags: descriptor.get('Flags'),
  16714. italicAngle: descriptor.get('ItalicAngle'),
  16715. coded: false
  16716. };
  16717. if (composite) {
  16718. var cidEncoding = baseDict.get('Encoding');
  16719. if (isName(cidEncoding)) {
  16720. properties.cidEncoding = cidEncoding.name;
  16721. }
  16722. properties.cMap = CMapFactory.create(cidEncoding,
  16723. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16724. properties.vertical = properties.cMap.vertical;
  16725. }
  16726. this.extractDataStructures(dict, baseDict, xref, properties);
  16727. this.extractWidths(dict, xref, descriptor, properties);
  16728. if (type === 'Type3') {
  16729. properties.isType3Font = true;
  16730. }
  16731. return new Font(fontName.name, fontFile, properties);
  16732. }
  16733. };
  16734. return PartialEvaluator;
  16735. })();
  16736. var TranslatedFont = (function TranslatedFontClosure() {
  16737. function TranslatedFont(loadedName, font, dict) {
  16738. this.loadedName = loadedName;
  16739. this.font = font;
  16740. this.dict = dict;
  16741. this.type3Loaded = null;
  16742. this.sent = false;
  16743. }
  16744. TranslatedFont.prototype = {
  16745. send: function (handler) {
  16746. if (this.sent) {
  16747. return;
  16748. }
  16749. var fontData = this.font.exportData();
  16750. handler.send('commonobj', [
  16751. this.loadedName,
  16752. 'Font',
  16753. fontData
  16754. ]);
  16755. this.sent = true;
  16756. },
  16757. loadType3Data: function (evaluator, resources, parentOperatorList) {
  16758. assert(this.font.isType3Font);
  16759. if (this.type3Loaded) {
  16760. return this.type3Loaded;
  16761. }
  16762. var translatedFont = this.font;
  16763. var loadCharProcsPromise = Promise.resolve();
  16764. var charProcs = this.dict.get('CharProcs').getAll();
  16765. var fontResources = this.dict.get('Resources') || resources;
  16766. var charProcKeys = Object.keys(charProcs);
  16767. var charProcOperatorList = {};
  16768. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  16769. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  16770. var glyphStream = charProcs[key];
  16771. var operatorList = new OperatorList();
  16772. return evaluator.getOperatorList(glyphStream, fontResources,
  16773. operatorList).then(function () {
  16774. charProcOperatorList[key] = operatorList.getIR();
  16775. // Add the dependencies to the parent operator list so they are
  16776. // resolved before sub operator list is executed synchronously.
  16777. parentOperatorList.addDependencies(operatorList.dependencies);
  16778. }, function (reason) {
  16779. warn('Type3 font resource \"' + key + '\" is not available');
  16780. var operatorList = new OperatorList();
  16781. charProcOperatorList[key] = operatorList.getIR();
  16782. });
  16783. }.bind(this, charProcKeys[i]));
  16784. }
  16785. this.type3Loaded = loadCharProcsPromise.then(function () {
  16786. translatedFont.charProcOperatorList = charProcOperatorList;
  16787. });
  16788. return this.type3Loaded;
  16789. }
  16790. };
  16791. return TranslatedFont;
  16792. })();
  16793. var OperatorList = (function OperatorListClosure() {
  16794. var CHUNK_SIZE = 1000;
  16795. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  16796. function getTransfers(queue) {
  16797. var transfers = [];
  16798. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  16799. for (var i = 0, ii = queue.length; i < ii; i++) {
  16800. switch (fnArray[i]) {
  16801. case OPS.paintInlineImageXObject:
  16802. case OPS.paintInlineImageXObjectGroup:
  16803. case OPS.paintImageMaskXObject:
  16804. var arg = argsArray[i][0]; // first param in imgData
  16805. if (!arg.cached) {
  16806. transfers.push(arg.data.buffer);
  16807. }
  16808. break;
  16809. }
  16810. }
  16811. return transfers;
  16812. }
  16813. function OperatorList(intent, messageHandler, pageIndex) {
  16814. this.messageHandler = messageHandler;
  16815. this.fnArray = [];
  16816. this.argsArray = [];
  16817. this.dependencies = {};
  16818. this.pageIndex = pageIndex;
  16819. this.intent = intent;
  16820. }
  16821. OperatorList.prototype = {
  16822. get length() {
  16823. return this.argsArray.length;
  16824. },
  16825. addOp: function(fn, args) {
  16826. this.fnArray.push(fn);
  16827. this.argsArray.push(args);
  16828. if (this.messageHandler) {
  16829. if (this.fnArray.length >= CHUNK_SIZE) {
  16830. this.flush();
  16831. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  16832. (fn === OPS.restore || fn === OPS.endText)) {
  16833. // heuristic to flush on boundary of restore or endText
  16834. this.flush();
  16835. }
  16836. }
  16837. },
  16838. addDependency: function(dependency) {
  16839. if (dependency in this.dependencies) {
  16840. return;
  16841. }
  16842. this.dependencies[dependency] = true;
  16843. this.addOp(OPS.dependency, [dependency]);
  16844. },
  16845. addDependencies: function(dependencies) {
  16846. for (var key in dependencies) {
  16847. this.addDependency(key);
  16848. }
  16849. },
  16850. addOpList: function(opList) {
  16851. Util.extendObj(this.dependencies, opList.dependencies);
  16852. for (var i = 0, ii = opList.length; i < ii; i++) {
  16853. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  16854. }
  16855. },
  16856. getIR: function() {
  16857. return {
  16858. fnArray: this.fnArray,
  16859. argsArray: this.argsArray,
  16860. length: this.length
  16861. };
  16862. },
  16863. flush: function(lastChunk) {
  16864. if (this.intent !== 'oplist') {
  16865. new QueueOptimizer().optimize(this);
  16866. }
  16867. var transfers = getTransfers(this);
  16868. this.messageHandler.send('RenderPageChunk', {
  16869. operatorList: {
  16870. fnArray: this.fnArray,
  16871. argsArray: this.argsArray,
  16872. lastChunk: lastChunk,
  16873. length: this.length
  16874. },
  16875. pageIndex: this.pageIndex,
  16876. intent: this.intent
  16877. }, transfers);
  16878. this.dependencies = {};
  16879. this.fnArray.length = 0;
  16880. this.argsArray.length = 0;
  16881. }
  16882. };
  16883. return OperatorList;
  16884. })();
  16885. var StateManager = (function StateManagerClosure() {
  16886. function StateManager(initialState) {
  16887. this.state = initialState;
  16888. this.stateStack = [];
  16889. }
  16890. StateManager.prototype = {
  16891. save: function () {
  16892. var old = this.state;
  16893. this.stateStack.push(this.state);
  16894. this.state = old.clone();
  16895. },
  16896. restore: function () {
  16897. var prev = this.stateStack.pop();
  16898. if (prev) {
  16899. this.state = prev;
  16900. }
  16901. },
  16902. transform: function (args) {
  16903. this.state.ctm = Util.transform(this.state.ctm, args);
  16904. }
  16905. };
  16906. return StateManager;
  16907. })();
  16908. var TextState = (function TextStateClosure() {
  16909. function TextState() {
  16910. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16911. this.fontSize = 0;
  16912. this.font = null;
  16913. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16914. this.textMatrix = IDENTITY_MATRIX.slice();
  16915. this.textLineMatrix = IDENTITY_MATRIX.slice();
  16916. this.charSpacing = 0;
  16917. this.wordSpacing = 0;
  16918. this.leading = 0;
  16919. this.textHScale = 1;
  16920. this.textRise = 0;
  16921. }
  16922. TextState.prototype = {
  16923. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16924. var m = this.textMatrix;
  16925. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16926. },
  16927. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16928. var m = this.textLineMatrix;
  16929. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16930. },
  16931. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  16932. var m = this.textMatrix;
  16933. m[4] = m[0] * x + m[2] * y + m[4];
  16934. m[5] = m[1] * x + m[3] * y + m[5];
  16935. },
  16936. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  16937. var m = this.textLineMatrix;
  16938. m[4] = m[0] * x + m[2] * y + m[4];
  16939. m[5] = m[1] * x + m[3] * y + m[5];
  16940. },
  16941. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  16942. // 9.4.4 Text Space Details
  16943. var tsm = [this.fontSize * this.textHScale, 0,
  16944. 0, this.fontSize,
  16945. 0, this.textRise];
  16946. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  16947. },
  16948. carriageReturn: function TextState_carriageReturn() {
  16949. this.translateTextLineMatrix(0, -this.leading);
  16950. this.textMatrix = this.textLineMatrix.slice();
  16951. },
  16952. clone: function TextState_clone() {
  16953. var clone = Object.create(this);
  16954. clone.textMatrix = this.textMatrix.slice();
  16955. clone.textLineMatrix = this.textLineMatrix.slice();
  16956. clone.fontMatrix = this.fontMatrix.slice();
  16957. return clone;
  16958. }
  16959. };
  16960. return TextState;
  16961. })();
  16962. var EvalState = (function EvalStateClosure() {
  16963. function EvalState() {
  16964. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16965. this.font = null;
  16966. this.textRenderingMode = TextRenderingMode.FILL;
  16967. this.fillColorSpace = ColorSpace.singletons.gray;
  16968. this.strokeColorSpace = ColorSpace.singletons.gray;
  16969. }
  16970. EvalState.prototype = {
  16971. clone: function CanvasExtraState_clone() {
  16972. return Object.create(this);
  16973. },
  16974. };
  16975. return EvalState;
  16976. })();
  16977. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  16978. // Specifies properties for each command
  16979. //
  16980. // If variableArgs === true: [0, `numArgs`] expected
  16981. // If variableArgs === false: exactly `numArgs` expected
  16982. var OP_MAP = {
  16983. // Graphic state
  16984. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  16985. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  16986. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  16987. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  16988. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  16989. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  16990. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  16991. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  16992. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  16993. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  16994. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  16995. // Path
  16996. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  16997. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  16998. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  16999. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  17000. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  17001. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  17002. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  17003. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  17004. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  17005. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17006. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17007. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  17008. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  17009. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  17010. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  17011. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  17012. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  17013. // Clipping
  17014. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  17015. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  17016. // Text
  17017. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  17018. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  17019. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  17020. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  17021. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  17022. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  17023. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  17024. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  17025. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  17026. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  17027. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  17028. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  17029. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  17030. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  17031. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  17032. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  17033. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  17034. variableArgs: false },
  17035. // Type3 fonts
  17036. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  17037. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  17038. // Color
  17039. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  17040. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  17041. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  17042. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  17043. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  17044. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  17045. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  17046. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  17047. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  17048. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  17049. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  17050. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  17051. // Shading
  17052. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  17053. // Images
  17054. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  17055. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  17056. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  17057. // XObjects
  17058. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  17059. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  17060. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  17061. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  17062. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  17063. variableArgs: false },
  17064. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  17065. // Compatibility
  17066. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  17067. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  17068. // (reserved partial commands for the lexer)
  17069. BM: null,
  17070. BD: null,
  17071. 'true': null,
  17072. fa: null,
  17073. fal: null,
  17074. fals: null,
  17075. 'false': null,
  17076. nu: null,
  17077. nul: null,
  17078. 'null': null
  17079. };
  17080. function EvaluatorPreprocessor(stream, xref, stateManager) {
  17081. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  17082. // dictionary
  17083. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  17084. this.stateManager = stateManager;
  17085. this.nonProcessedArgs = [];
  17086. }
  17087. EvaluatorPreprocessor.prototype = {
  17088. get savedStatesDepth() {
  17089. return this.stateManager.stateStack.length;
  17090. },
  17091. // |operation| is an object with two fields:
  17092. //
  17093. // - |fn| is an out param.
  17094. //
  17095. // - |args| is an inout param. On entry, it should have one of two values.
  17096. //
  17097. // - An empty array. This indicates that the caller is providing the
  17098. // array in which the args will be stored in. The caller should use
  17099. // this value if it can reuse a single array for each call to read().
  17100. //
  17101. // - |null|. This indicates that the caller needs this function to create
  17102. // the array in which any args are stored in. If there are zero args,
  17103. // this function will leave |operation.args| as |null| (thus avoiding
  17104. // allocations that would occur if we used an empty array to represent
  17105. // zero arguments). Otherwise, it will replace |null| with a new array
  17106. // containing the arguments. The caller should use this value if it
  17107. // cannot reuse an array for each call to read().
  17108. //
  17109. // These two modes are present because this function is very hot and so
  17110. // avoiding allocations where possible is worthwhile.
  17111. //
  17112. read: function EvaluatorPreprocessor_read(operation) {
  17113. var args = operation.args;
  17114. while (true) {
  17115. var obj = this.parser.getObj();
  17116. if (isCmd(obj)) {
  17117. var cmd = obj.cmd;
  17118. // Check that the command is valid
  17119. var opSpec = OP_MAP[cmd];
  17120. if (!opSpec) {
  17121. warn('Unknown command "' + cmd + '"');
  17122. continue;
  17123. }
  17124. var fn = opSpec.id;
  17125. var numArgs = opSpec.numArgs;
  17126. var argsLength = args !== null ? args.length : 0;
  17127. if (!opSpec.variableArgs) {
  17128. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  17129. if (argsLength !== numArgs) {
  17130. var nonProcessedArgs = this.nonProcessedArgs;
  17131. while (argsLength > numArgs) {
  17132. nonProcessedArgs.push(args.shift());
  17133. argsLength--;
  17134. }
  17135. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  17136. if (!args) {
  17137. args = [];
  17138. }
  17139. args.unshift(nonProcessedArgs.pop());
  17140. argsLength++;
  17141. }
  17142. }
  17143. if (argsLength < numArgs) {
  17144. // If we receive too few args, it's not possible to possible
  17145. // to execute the command, so skip the command
  17146. info('Command ' + fn + ': because expected ' +
  17147. numArgs + ' args, but received ' + argsLength +
  17148. ' args; skipping');
  17149. args = null;
  17150. continue;
  17151. }
  17152. } else if (argsLength > numArgs) {
  17153. info('Command ' + fn + ': expected [0,' + numArgs +
  17154. '] args, but received ' + argsLength + ' args');
  17155. }
  17156. // TODO figure out how to type-check vararg functions
  17157. this.preprocessCommand(fn, args);
  17158. operation.fn = fn;
  17159. operation.args = args;
  17160. return true;
  17161. } else {
  17162. if (isEOF(obj)) {
  17163. return false; // no more commands
  17164. }
  17165. // argument
  17166. if (obj !== null) {
  17167. if (!args) {
  17168. args = [];
  17169. }
  17170. args.push((obj instanceof Dict ? obj.getAll() : obj));
  17171. assert(args.length <= 33, 'Too many arguments');
  17172. }
  17173. }
  17174. }
  17175. },
  17176. preprocessCommand:
  17177. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  17178. switch (fn | 0) {
  17179. case OPS.save:
  17180. this.stateManager.save();
  17181. break;
  17182. case OPS.restore:
  17183. this.stateManager.restore();
  17184. break;
  17185. case OPS.transform:
  17186. this.stateManager.transform(args);
  17187. break;
  17188. }
  17189. }
  17190. };
  17191. return EvaluatorPreprocessor;
  17192. })();
  17193. var QueueOptimizer = (function QueueOptimizerClosure() {
  17194. function addState(parentState, pattern, fn) {
  17195. var state = parentState;
  17196. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  17197. var item = pattern[i];
  17198. state = (state[item] || (state[item] = []));
  17199. }
  17200. state[pattern[pattern.length - 1]] = fn;
  17201. }
  17202. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17203. argsArray) {
  17204. // Handles special case of mainly LaTeX documents which use image masks to
  17205. // draw lines with the current fill style.
  17206. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  17207. // have been found at iFirstSave.
  17208. var iFirstPIMXO = iFirstSave + 2;
  17209. for (var i = 0; i < count; i++) {
  17210. var arg = argsArray[iFirstPIMXO + 4 * i];
  17211. var imageMask = arg.length === 1 && arg[0];
  17212. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  17213. (!imageMask.data.length ||
  17214. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  17215. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  17216. continue;
  17217. }
  17218. break;
  17219. }
  17220. return count - i;
  17221. }
  17222. var InitialState = [];
  17223. // This replaces (save, transform, paintInlineImageXObject, restore)+
  17224. // sequences with one |paintInlineImageXObjectGroup| operation.
  17225. addState(InitialState,
  17226. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  17227. function foundInlineImageGroup(context) {
  17228. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  17229. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  17230. var MAX_WIDTH = 1000;
  17231. var IMAGE_PADDING = 1;
  17232. var fnArray = context.fnArray, argsArray = context.argsArray;
  17233. var curr = context.iCurr;
  17234. var iFirstSave = curr - 3;
  17235. var iFirstTransform = curr - 2;
  17236. var iFirstPIIXO = curr - 1;
  17237. // Look for the quartets.
  17238. var i = iFirstSave + 4;
  17239. var ii = fnArray.length;
  17240. while (i + 3 < ii) {
  17241. if (fnArray[i] !== OPS.save ||
  17242. fnArray[i + 1] !== OPS.transform ||
  17243. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  17244. fnArray[i + 3] !== OPS.restore) {
  17245. break; // ops don't match
  17246. }
  17247. i += 4;
  17248. }
  17249. // At this point, i is the index of the first op past the last valid
  17250. // quartet.
  17251. var count = Math.min((i - iFirstSave) / 4,
  17252. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  17253. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  17254. return i;
  17255. }
  17256. // assuming that heights of those image is too small (~1 pixel)
  17257. // packing as much as possible by lines
  17258. var maxX = 0;
  17259. var map = [], maxLineHeight = 0;
  17260. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  17261. var q;
  17262. for (q = 0; q < count; q++) {
  17263. var transform = argsArray[iFirstTransform + (q << 2)];
  17264. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  17265. if (currentX + img.width > MAX_WIDTH) {
  17266. // starting new line
  17267. maxX = Math.max(maxX, currentX);
  17268. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  17269. currentX = 0;
  17270. maxLineHeight = 0;
  17271. }
  17272. map.push({
  17273. transform: transform,
  17274. x: currentX, y: currentY,
  17275. w: img.width, h: img.height
  17276. });
  17277. currentX += img.width + 2 * IMAGE_PADDING;
  17278. maxLineHeight = Math.max(maxLineHeight, img.height);
  17279. }
  17280. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  17281. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  17282. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  17283. var imgRowSize = imgWidth << 2;
  17284. for (q = 0; q < count; q++) {
  17285. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  17286. // Copy image by lines and extends pixels into padding.
  17287. var rowSize = map[q].w << 2;
  17288. var dataOffset = 0;
  17289. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  17290. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  17291. for (var k = 0, kk = map[q].h; k < kk; k++) {
  17292. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  17293. dataOffset += rowSize;
  17294. offset += imgRowSize;
  17295. }
  17296. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  17297. while (offset >= 0) {
  17298. data[offset - 4] = data[offset];
  17299. data[offset - 3] = data[offset + 1];
  17300. data[offset - 2] = data[offset + 2];
  17301. data[offset - 1] = data[offset + 3];
  17302. data[offset + rowSize] = data[offset + rowSize - 4];
  17303. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  17304. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  17305. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  17306. offset -= imgRowSize;
  17307. }
  17308. }
  17309. // Replace queue items.
  17310. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  17311. argsArray.splice(iFirstSave, count * 4,
  17312. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  17313. data: imgData }, map]);
  17314. return iFirstSave + 1;
  17315. });
  17316. // This replaces (save, transform, paintImageMaskXObject, restore)+
  17317. // sequences with one |paintImageMaskXObjectGroup| or one
  17318. // |paintImageMaskXObjectRepeat| operation.
  17319. addState(InitialState,
  17320. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  17321. function foundImageMaskGroup(context) {
  17322. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  17323. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  17324. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  17325. var fnArray = context.fnArray, argsArray = context.argsArray;
  17326. var curr = context.iCurr;
  17327. var iFirstSave = curr - 3;
  17328. var iFirstTransform = curr - 2;
  17329. var iFirstPIMXO = curr - 1;
  17330. // Look for the quartets.
  17331. var i = iFirstSave + 4;
  17332. var ii = fnArray.length;
  17333. while (i + 3 < ii) {
  17334. if (fnArray[i] !== OPS.save ||
  17335. fnArray[i + 1] !== OPS.transform ||
  17336. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  17337. fnArray[i + 3] !== OPS.restore) {
  17338. break; // ops don't match
  17339. }
  17340. i += 4;
  17341. }
  17342. // At this point, i is the index of the first op past the last valid
  17343. // quartet.
  17344. var count = (i - iFirstSave) / 4;
  17345. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17346. argsArray);
  17347. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  17348. return i;
  17349. }
  17350. var q;
  17351. var isSameImage = false;
  17352. var iTransform, transformArgs;
  17353. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  17354. if (argsArray[iFirstTransform][1] === 0 &&
  17355. argsArray[iFirstTransform][2] === 0) {
  17356. isSameImage = true;
  17357. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17358. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17359. iTransform = iFirstTransform + 4;
  17360. var iPIMXO = iFirstPIMXO + 4;
  17361. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  17362. transformArgs = argsArray[iTransform];
  17363. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  17364. transformArgs[0] !== firstTransformArg0 ||
  17365. transformArgs[1] !== 0 ||
  17366. transformArgs[2] !== 0 ||
  17367. transformArgs[3] !== firstTransformArg3) {
  17368. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  17369. isSameImage = false;
  17370. } else {
  17371. count = q;
  17372. }
  17373. break; // different image or transform
  17374. }
  17375. }
  17376. }
  17377. if (isSameImage) {
  17378. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  17379. var positions = new Float32Array(count * 2);
  17380. iTransform = iFirstTransform;
  17381. for (q = 0; q < count; q++, iTransform += 4) {
  17382. transformArgs = argsArray[iTransform];
  17383. positions[(q << 1)] = transformArgs[4];
  17384. positions[(q << 1) + 1] = transformArgs[5];
  17385. }
  17386. // Replace queue items.
  17387. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  17388. argsArray.splice(iFirstSave, count * 4,
  17389. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  17390. } else {
  17391. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  17392. var images = [];
  17393. for (q = 0; q < count; q++) {
  17394. transformArgs = argsArray[iFirstTransform + (q << 2)];
  17395. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  17396. images.push({ data: maskParams.data, width: maskParams.width,
  17397. height: maskParams.height,
  17398. transform: transformArgs });
  17399. }
  17400. // Replace queue items.
  17401. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  17402. argsArray.splice(iFirstSave, count * 4, [images]);
  17403. }
  17404. return iFirstSave + 1;
  17405. });
  17406. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  17407. // with one paintImageXObjectRepeat operation, if the |transform| and
  17408. // |paintImageXObjectRepeat| ops are appropriate.
  17409. addState(InitialState,
  17410. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  17411. function (context) {
  17412. var MIN_IMAGES_IN_BLOCK = 3;
  17413. var MAX_IMAGES_IN_BLOCK = 1000;
  17414. var fnArray = context.fnArray, argsArray = context.argsArray;
  17415. var curr = context.iCurr;
  17416. var iFirstSave = curr - 3;
  17417. var iFirstTransform = curr - 2;
  17418. var iFirstPIXO = curr - 1;
  17419. var iFirstRestore = curr;
  17420. if (argsArray[iFirstTransform][1] !== 0 ||
  17421. argsArray[iFirstTransform][2] !== 0) {
  17422. return iFirstRestore + 1; // transform has the wrong form
  17423. }
  17424. // Look for the quartets.
  17425. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  17426. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17427. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17428. var i = iFirstSave + 4;
  17429. var ii = fnArray.length;
  17430. while (i + 3 < ii) {
  17431. if (fnArray[i] !== OPS.save ||
  17432. fnArray[i + 1] !== OPS.transform ||
  17433. fnArray[i + 2] !== OPS.paintImageXObject ||
  17434. fnArray[i + 3] !== OPS.restore) {
  17435. break; // ops don't match
  17436. }
  17437. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  17438. argsArray[i + 1][1] !== 0 ||
  17439. argsArray[i + 1][2] !== 0 ||
  17440. argsArray[i + 1][3] !== firstTransformArg3) {
  17441. break; // transforms don't match
  17442. }
  17443. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  17444. break; // images don't match
  17445. }
  17446. i += 4;
  17447. }
  17448. // At this point, i is the index of the first op past the last valid
  17449. // quartet.
  17450. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  17451. if (count < MIN_IMAGES_IN_BLOCK) {
  17452. return i;
  17453. }
  17454. // Extract the (x,y) positions from all of the matching transforms.
  17455. var positions = new Float32Array(count * 2);
  17456. var iTransform = iFirstTransform;
  17457. for (var q = 0; q < count; q++, iTransform += 4) {
  17458. var transformArgs = argsArray[iTransform];
  17459. positions[(q << 1)] = transformArgs[4];
  17460. positions[(q << 1) + 1] = transformArgs[5];
  17461. }
  17462. // Replace queue items.
  17463. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  17464. positions];
  17465. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  17466. argsArray.splice(iFirstSave, count * 4, args);
  17467. return iFirstSave + 1;
  17468. });
  17469. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  17470. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  17471. // sequences, if the font for each one is the same.
  17472. addState(InitialState,
  17473. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  17474. function (context) {
  17475. var MIN_CHARS_IN_BLOCK = 3;
  17476. var MAX_CHARS_IN_BLOCK = 1000;
  17477. var fnArray = context.fnArray, argsArray = context.argsArray;
  17478. var curr = context.iCurr;
  17479. var iFirstBeginText = curr - 4;
  17480. var iFirstSetFont = curr - 3;
  17481. var iFirstSetTextMatrix = curr - 2;
  17482. var iFirstShowText = curr - 1;
  17483. var iFirstEndText = curr;
  17484. // Look for the quintets.
  17485. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  17486. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  17487. var i = iFirstBeginText + 5;
  17488. var ii = fnArray.length;
  17489. while (i + 4 < ii) {
  17490. if (fnArray[i] !== OPS.beginText ||
  17491. fnArray[i + 1] !== OPS.setFont ||
  17492. fnArray[i + 2] !== OPS.setTextMatrix ||
  17493. fnArray[i + 3] !== OPS.showText ||
  17494. fnArray[i + 4] !== OPS.endText) {
  17495. break; // ops don't match
  17496. }
  17497. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  17498. argsArray[i + 1][1] !== firstSetFontArg1) {
  17499. break; // fonts don't match
  17500. }
  17501. i += 5;
  17502. }
  17503. // At this point, i is the index of the first op past the last valid
  17504. // quintet.
  17505. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  17506. if (count < MIN_CHARS_IN_BLOCK) {
  17507. return i;
  17508. }
  17509. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  17510. // showText, endText), include that as well. (E.g. <something> might be
  17511. // |dependency|.)
  17512. var iFirst = iFirstBeginText;
  17513. if (iFirstBeginText >= 4 &&
  17514. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  17515. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  17516. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  17517. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  17518. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  17519. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  17520. count++;
  17521. iFirst -= 5;
  17522. }
  17523. // Remove (endText, beginText, setFont) trios.
  17524. var iEndText = iFirst + 4;
  17525. for (var q = 1; q < count; q++) {
  17526. fnArray.splice(iEndText, 3);
  17527. argsArray.splice(iEndText, 3);
  17528. iEndText += 2;
  17529. }
  17530. return iEndText + 1;
  17531. });
  17532. function QueueOptimizer() {}
  17533. QueueOptimizer.prototype = {
  17534. optimize: function QueueOptimizer_optimize(queue) {
  17535. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17536. var context = {
  17537. iCurr: 0,
  17538. fnArray: fnArray,
  17539. argsArray: argsArray
  17540. };
  17541. var state;
  17542. var i = 0, ii = fnArray.length;
  17543. while (i < ii) {
  17544. state = (state || InitialState)[fnArray[i]];
  17545. if (typeof state === 'function') { // we found some handler
  17546. context.iCurr = i;
  17547. // state() returns the index of the first non-matching op (if we
  17548. // didn't match) or the first op past the modified ops (if we did
  17549. // match and replace).
  17550. i = state(context);
  17551. state = undefined; // reset the state machine
  17552. ii = context.fnArray.length;
  17553. } else {
  17554. i++;
  17555. }
  17556. }
  17557. }
  17558. };
  17559. return QueueOptimizer;
  17560. })();
  17561. var BUILT_IN_CMAPS = [
  17562. // << Start unicode maps.
  17563. 'Adobe-GB1-UCS2',
  17564. 'Adobe-CNS1-UCS2',
  17565. 'Adobe-Japan1-UCS2',
  17566. 'Adobe-Korea1-UCS2',
  17567. // >> End unicode maps.
  17568. '78-EUC-H',
  17569. '78-EUC-V',
  17570. '78-H',
  17571. '78-RKSJ-H',
  17572. '78-RKSJ-V',
  17573. '78-V',
  17574. '78ms-RKSJ-H',
  17575. '78ms-RKSJ-V',
  17576. '83pv-RKSJ-H',
  17577. '90ms-RKSJ-H',
  17578. '90ms-RKSJ-V',
  17579. '90msp-RKSJ-H',
  17580. '90msp-RKSJ-V',
  17581. '90pv-RKSJ-H',
  17582. '90pv-RKSJ-V',
  17583. 'Add-H',
  17584. 'Add-RKSJ-H',
  17585. 'Add-RKSJ-V',
  17586. 'Add-V',
  17587. 'Adobe-CNS1-0',
  17588. 'Adobe-CNS1-1',
  17589. 'Adobe-CNS1-2',
  17590. 'Adobe-CNS1-3',
  17591. 'Adobe-CNS1-4',
  17592. 'Adobe-CNS1-5',
  17593. 'Adobe-CNS1-6',
  17594. 'Adobe-GB1-0',
  17595. 'Adobe-GB1-1',
  17596. 'Adobe-GB1-2',
  17597. 'Adobe-GB1-3',
  17598. 'Adobe-GB1-4',
  17599. 'Adobe-GB1-5',
  17600. 'Adobe-Japan1-0',
  17601. 'Adobe-Japan1-1',
  17602. 'Adobe-Japan1-2',
  17603. 'Adobe-Japan1-3',
  17604. 'Adobe-Japan1-4',
  17605. 'Adobe-Japan1-5',
  17606. 'Adobe-Japan1-6',
  17607. 'Adobe-Korea1-0',
  17608. 'Adobe-Korea1-1',
  17609. 'Adobe-Korea1-2',
  17610. 'B5-H',
  17611. 'B5-V',
  17612. 'B5pc-H',
  17613. 'B5pc-V',
  17614. 'CNS-EUC-H',
  17615. 'CNS-EUC-V',
  17616. 'CNS1-H',
  17617. 'CNS1-V',
  17618. 'CNS2-H',
  17619. 'CNS2-V',
  17620. 'ETHK-B5-H',
  17621. 'ETHK-B5-V',
  17622. 'ETen-B5-H',
  17623. 'ETen-B5-V',
  17624. 'ETenms-B5-H',
  17625. 'ETenms-B5-V',
  17626. 'EUC-H',
  17627. 'EUC-V',
  17628. 'Ext-H',
  17629. 'Ext-RKSJ-H',
  17630. 'Ext-RKSJ-V',
  17631. 'Ext-V',
  17632. 'GB-EUC-H',
  17633. 'GB-EUC-V',
  17634. 'GB-H',
  17635. 'GB-V',
  17636. 'GBK-EUC-H',
  17637. 'GBK-EUC-V',
  17638. 'GBK2K-H',
  17639. 'GBK2K-V',
  17640. 'GBKp-EUC-H',
  17641. 'GBKp-EUC-V',
  17642. 'GBT-EUC-H',
  17643. 'GBT-EUC-V',
  17644. 'GBT-H',
  17645. 'GBT-V',
  17646. 'GBTpc-EUC-H',
  17647. 'GBTpc-EUC-V',
  17648. 'GBpc-EUC-H',
  17649. 'GBpc-EUC-V',
  17650. 'H',
  17651. 'HKdla-B5-H',
  17652. 'HKdla-B5-V',
  17653. 'HKdlb-B5-H',
  17654. 'HKdlb-B5-V',
  17655. 'HKgccs-B5-H',
  17656. 'HKgccs-B5-V',
  17657. 'HKm314-B5-H',
  17658. 'HKm314-B5-V',
  17659. 'HKm471-B5-H',
  17660. 'HKm471-B5-V',
  17661. 'HKscs-B5-H',
  17662. 'HKscs-B5-V',
  17663. 'Hankaku',
  17664. 'Hiragana',
  17665. 'KSC-EUC-H',
  17666. 'KSC-EUC-V',
  17667. 'KSC-H',
  17668. 'KSC-Johab-H',
  17669. 'KSC-Johab-V',
  17670. 'KSC-V',
  17671. 'KSCms-UHC-H',
  17672. 'KSCms-UHC-HW-H',
  17673. 'KSCms-UHC-HW-V',
  17674. 'KSCms-UHC-V',
  17675. 'KSCpc-EUC-H',
  17676. 'KSCpc-EUC-V',
  17677. 'Katakana',
  17678. 'NWP-H',
  17679. 'NWP-V',
  17680. 'RKSJ-H',
  17681. 'RKSJ-V',
  17682. 'Roman',
  17683. 'UniCNS-UCS2-H',
  17684. 'UniCNS-UCS2-V',
  17685. 'UniCNS-UTF16-H',
  17686. 'UniCNS-UTF16-V',
  17687. 'UniCNS-UTF32-H',
  17688. 'UniCNS-UTF32-V',
  17689. 'UniCNS-UTF8-H',
  17690. 'UniCNS-UTF8-V',
  17691. 'UniGB-UCS2-H',
  17692. 'UniGB-UCS2-V',
  17693. 'UniGB-UTF16-H',
  17694. 'UniGB-UTF16-V',
  17695. 'UniGB-UTF32-H',
  17696. 'UniGB-UTF32-V',
  17697. 'UniGB-UTF8-H',
  17698. 'UniGB-UTF8-V',
  17699. 'UniJIS-UCS2-H',
  17700. 'UniJIS-UCS2-HW-H',
  17701. 'UniJIS-UCS2-HW-V',
  17702. 'UniJIS-UCS2-V',
  17703. 'UniJIS-UTF16-H',
  17704. 'UniJIS-UTF16-V',
  17705. 'UniJIS-UTF32-H',
  17706. 'UniJIS-UTF32-V',
  17707. 'UniJIS-UTF8-H',
  17708. 'UniJIS-UTF8-V',
  17709. 'UniJIS2004-UTF16-H',
  17710. 'UniJIS2004-UTF16-V',
  17711. 'UniJIS2004-UTF32-H',
  17712. 'UniJIS2004-UTF32-V',
  17713. 'UniJIS2004-UTF8-H',
  17714. 'UniJIS2004-UTF8-V',
  17715. 'UniJISPro-UCS2-HW-V',
  17716. 'UniJISPro-UCS2-V',
  17717. 'UniJISPro-UTF8-V',
  17718. 'UniJISX0213-UTF32-H',
  17719. 'UniJISX0213-UTF32-V',
  17720. 'UniJISX02132004-UTF32-H',
  17721. 'UniJISX02132004-UTF32-V',
  17722. 'UniKS-UCS2-H',
  17723. 'UniKS-UCS2-V',
  17724. 'UniKS-UTF16-H',
  17725. 'UniKS-UTF16-V',
  17726. 'UniKS-UTF32-H',
  17727. 'UniKS-UTF32-V',
  17728. 'UniKS-UTF8-H',
  17729. 'UniKS-UTF8-V',
  17730. 'V',
  17731. 'WP-Symbol'];
  17732. // CMap, not to be confused with TrueType's cmap.
  17733. var CMap = (function CMapClosure() {
  17734. function CMap(builtInCMap) {
  17735. // Codespace ranges are stored as follows:
  17736. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  17737. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  17738. this.codespaceRanges = [[], [], [], []];
  17739. this.numCodespaceRanges = 0;
  17740. // Map entries have one of two forms.
  17741. // - cid chars are 16-bit unsigned integers, stored as integers.
  17742. // - bf chars are variable-length byte sequences, stored as strings, with
  17743. // one byte per character.
  17744. this._map = [];
  17745. this.vertical = false;
  17746. this.useCMap = null;
  17747. this.builtInCMap = builtInCMap;
  17748. }
  17749. CMap.prototype = {
  17750. addCodespaceRange: function(n, low, high) {
  17751. this.codespaceRanges[n - 1].push(low, high);
  17752. this.numCodespaceRanges++;
  17753. },
  17754. mapCidRange: function(low, high, dstLow) {
  17755. while (low <= high) {
  17756. this._map[low++] = dstLow++;
  17757. }
  17758. },
  17759. mapBfRange: function(low, high, dstLow) {
  17760. var lastByte = dstLow.length - 1;
  17761. while (low <= high) {
  17762. this._map[low++] = dstLow;
  17763. // Only the last byte has to be incremented.
  17764. dstLow = dstLow.substr(0, lastByte) +
  17765. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  17766. }
  17767. },
  17768. mapBfRangeToArray: function(low, high, array) {
  17769. var i = 0, ii = array.length;
  17770. while (low <= high && i < ii) {
  17771. this._map[low] = array[i++];
  17772. ++low;
  17773. }
  17774. },
  17775. // This is used for both bf and cid chars.
  17776. mapOne: function(src, dst) {
  17777. this._map[src] = dst;
  17778. },
  17779. lookup: function(code) {
  17780. return this._map[code];
  17781. },
  17782. contains: function(code) {
  17783. return this._map[code] !== undefined;
  17784. },
  17785. forEach: function(callback) {
  17786. // Most maps have fewer than 65536 entries, and for those we use normal
  17787. // array iteration. But really sparse tables are possible -- e.g. with
  17788. // indices in the *billions*. For such tables we use for..in, which isn't
  17789. // ideal because it stringifies the indices for all present elements, but
  17790. // it does avoid iterating over every undefined entry.
  17791. var map = this._map;
  17792. var length = map.length;
  17793. var i;
  17794. if (length <= 0x10000) {
  17795. for (i = 0; i < length; i++) {
  17796. if (map[i] !== undefined) {
  17797. callback(i, map[i]);
  17798. }
  17799. }
  17800. } else {
  17801. for (i in this._map) {
  17802. callback(i, map[i]);
  17803. }
  17804. }
  17805. },
  17806. charCodeOf: function(value) {
  17807. return this._map.indexOf(value);
  17808. },
  17809. getMap: function() {
  17810. return this._map;
  17811. },
  17812. readCharCode: function(str, offset, out) {
  17813. var c = 0;
  17814. var codespaceRanges = this.codespaceRanges;
  17815. var codespaceRangesLen = this.codespaceRanges.length;
  17816. // 9.7.6.2 CMap Mapping
  17817. // The code length is at most 4.
  17818. for (var n = 0; n < codespaceRangesLen; n++) {
  17819. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  17820. // Check each codespace range to see if it falls within.
  17821. var codespaceRange = codespaceRanges[n];
  17822. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  17823. var low = codespaceRange[k++];
  17824. var high = codespaceRange[k++];
  17825. if (c >= low && c <= high) {
  17826. out.charcode = c;
  17827. out.length = n + 1;
  17828. return;
  17829. }
  17830. }
  17831. }
  17832. out.charcode = 0;
  17833. out.length = 1;
  17834. }
  17835. };
  17836. return CMap;
  17837. })();
  17838. // A special case of CMap, where the _map array implicitly has a length of
  17839. // 65535 and each element is equal to its index.
  17840. var IdentityCMap = (function IdentityCMapClosure() {
  17841. function IdentityCMap(vertical, n) {
  17842. CMap.call(this);
  17843. this.vertical = vertical;
  17844. this.addCodespaceRange(n, 0, 0xffff);
  17845. }
  17846. Util.inherit(IdentityCMap, CMap, {});
  17847. IdentityCMap.prototype = {
  17848. addCodespaceRange: CMap.prototype.addCodespaceRange,
  17849. mapCidRange: function(low, high, dstLow) {
  17850. error('should not call mapCidRange');
  17851. },
  17852. mapBfRange: function(low, high, dstLow) {
  17853. error('should not call mapBfRange');
  17854. },
  17855. mapBfRangeToArray: function(low, high, array) {
  17856. error('should not call mapBfRangeToArray');
  17857. },
  17858. mapOne: function(src, dst) {
  17859. error('should not call mapCidOne');
  17860. },
  17861. lookup: function(code) {
  17862. return (isInt(code) && code <= 0xffff) ? code : undefined;
  17863. },
  17864. contains: function(code) {
  17865. return isInt(code) && code <= 0xffff;
  17866. },
  17867. forEach: function(callback) {
  17868. for (var i = 0; i <= 0xffff; i++) {
  17869. callback(i, i);
  17870. }
  17871. },
  17872. charCodeOf: function(value) {
  17873. return (isInt(value) && value <= 0xffff) ? value : -1;
  17874. },
  17875. getMap: function() {
  17876. // Sometimes identity maps must be instantiated, but it's rare.
  17877. var map = new Array(0x10000);
  17878. for (var i = 0; i <= 0xffff; i++) {
  17879. map[i] = i;
  17880. }
  17881. return map;
  17882. },
  17883. readCharCode: CMap.prototype.readCharCode
  17884. };
  17885. return IdentityCMap;
  17886. })();
  17887. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  17888. function fetchBinaryData(url) {
  17889. var nonBinaryRequest = PDFJS.disableWorker;
  17890. var request = new XMLHttpRequest();
  17891. request.open('GET', url, false);
  17892. if (!nonBinaryRequest) {
  17893. try {
  17894. request.responseType = 'arraybuffer';
  17895. nonBinaryRequest = request.responseType !== 'arraybuffer';
  17896. } catch (e) {
  17897. nonBinaryRequest = true;
  17898. }
  17899. }
  17900. if (nonBinaryRequest && request.overrideMimeType) {
  17901. request.overrideMimeType('text/plain; charset=x-user-defined');
  17902. }
  17903. request.send(null);
  17904. if (nonBinaryRequest ? !request.responseText : !request.response) {
  17905. error('Unable to get binary cMap at: ' + url);
  17906. }
  17907. if (nonBinaryRequest) {
  17908. var data = Array.prototype.map.call(request.responseText, function (ch) {
  17909. return ch.charCodeAt(0) & 255;
  17910. });
  17911. return new Uint8Array(data);
  17912. }
  17913. return new Uint8Array(request.response);
  17914. }
  17915. function hexToInt(a, size) {
  17916. var n = 0;
  17917. for (var i = 0; i <= size; i++) {
  17918. n = (n << 8) | a[i];
  17919. }
  17920. return n >>> 0;
  17921. }
  17922. function hexToStr(a, size) {
  17923. // This code is hot. Special-case some common values to avoid creating an
  17924. // object with subarray().
  17925. if (size === 1) {
  17926. return String.fromCharCode(a[0], a[1]);
  17927. }
  17928. if (size === 3) {
  17929. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  17930. }
  17931. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  17932. }
  17933. function addHex(a, b, size) {
  17934. var c = 0;
  17935. for (var i = size; i >= 0; i--) {
  17936. c += a[i] + b[i];
  17937. a[i] = c & 255;
  17938. c >>= 8;
  17939. }
  17940. }
  17941. function incHex(a, size) {
  17942. var c = 1;
  17943. for (var i = size; i >= 0 && c > 0; i--) {
  17944. c += a[i];
  17945. a[i] = c & 255;
  17946. c >>= 8;
  17947. }
  17948. }
  17949. var MAX_NUM_SIZE = 16;
  17950. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  17951. function BinaryCMapStream(data) {
  17952. this.buffer = data;
  17953. this.pos = 0;
  17954. this.end = data.length;
  17955. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  17956. }
  17957. BinaryCMapStream.prototype = {
  17958. readByte: function () {
  17959. if (this.pos >= this.end) {
  17960. return -1;
  17961. }
  17962. return this.buffer[this.pos++];
  17963. },
  17964. readNumber: function () {
  17965. var n = 0;
  17966. var last;
  17967. do {
  17968. var b = this.readByte();
  17969. if (b < 0) {
  17970. error('unexpected EOF in bcmap');
  17971. }
  17972. last = !(b & 0x80);
  17973. n = (n << 7) | (b & 0x7F);
  17974. } while (!last);
  17975. return n;
  17976. },
  17977. readSigned: function () {
  17978. var n = this.readNumber();
  17979. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  17980. },
  17981. readHex: function (num, size) {
  17982. num.set(this.buffer.subarray(this.pos,
  17983. this.pos + size + 1));
  17984. this.pos += size + 1;
  17985. },
  17986. readHexNumber: function (num, size) {
  17987. var last;
  17988. var stack = this.tmpBuf, sp = 0;
  17989. do {
  17990. var b = this.readByte();
  17991. if (b < 0) {
  17992. error('unexpected EOF in bcmap');
  17993. }
  17994. last = !(b & 0x80);
  17995. stack[sp++] = b & 0x7F;
  17996. } while (!last);
  17997. var i = size, buffer = 0, bufferSize = 0;
  17998. while (i >= 0) {
  17999. while (bufferSize < 8 && stack.length > 0) {
  18000. buffer = (stack[--sp] << bufferSize) | buffer;
  18001. bufferSize += 7;
  18002. }
  18003. num[i] = buffer & 255;
  18004. i--;
  18005. buffer >>= 8;
  18006. bufferSize -= 8;
  18007. }
  18008. },
  18009. readHexSigned: function (num, size) {
  18010. this.readHexNumber(num, size);
  18011. var sign = num[size] & 1 ? 255 : 0;
  18012. var c = 0;
  18013. for (var i = 0; i <= size; i++) {
  18014. c = ((c & 1) << 8) | num[i];
  18015. num[i] = (c >> 1) ^ sign;
  18016. }
  18017. },
  18018. readString: function () {
  18019. var len = this.readNumber();
  18020. var s = '';
  18021. for (var i = 0; i < len; i++) {
  18022. s += String.fromCharCode(this.readNumber());
  18023. }
  18024. return s;
  18025. }
  18026. };
  18027. function processBinaryCMap(url, cMap, extend) {
  18028. var data = fetchBinaryData(url);
  18029. var stream = new BinaryCMapStream(data);
  18030. var header = stream.readByte();
  18031. cMap.vertical = !!(header & 1);
  18032. var useCMap = null;
  18033. var start = new Uint8Array(MAX_NUM_SIZE);
  18034. var end = new Uint8Array(MAX_NUM_SIZE);
  18035. var char = new Uint8Array(MAX_NUM_SIZE);
  18036. var charCode = new Uint8Array(MAX_NUM_SIZE);
  18037. var tmp = new Uint8Array(MAX_NUM_SIZE);
  18038. var code;
  18039. var b;
  18040. while ((b = stream.readByte()) >= 0) {
  18041. var type = b >> 5;
  18042. if (type === 7) { // metadata, e.g. comment or usecmap
  18043. switch (b & 0x1F) {
  18044. case 0:
  18045. stream.readString(); // skipping comment
  18046. break;
  18047. case 1:
  18048. useCMap = stream.readString();
  18049. break;
  18050. }
  18051. continue;
  18052. }
  18053. var sequence = !!(b & 0x10);
  18054. var dataSize = b & 15;
  18055. assert(dataSize + 1 <= MAX_NUM_SIZE);
  18056. var ucs2DataSize = 1;
  18057. var subitemsCount = stream.readNumber();
  18058. var i;
  18059. switch (type) {
  18060. case 0: // codespacerange
  18061. stream.readHex(start, dataSize);
  18062. stream.readHexNumber(end, dataSize);
  18063. addHex(end, start, dataSize);
  18064. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18065. hexToInt(end, dataSize));
  18066. for (i = 1; i < subitemsCount; i++) {
  18067. incHex(end, dataSize);
  18068. stream.readHexNumber(start, dataSize);
  18069. addHex(start, end, dataSize);
  18070. stream.readHexNumber(end, dataSize);
  18071. addHex(end, start, dataSize);
  18072. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18073. hexToInt(end, dataSize));
  18074. }
  18075. break;
  18076. case 1: // notdefrange
  18077. stream.readHex(start, dataSize);
  18078. stream.readHexNumber(end, dataSize);
  18079. addHex(end, start, dataSize);
  18080. code = stream.readNumber();
  18081. // undefined range, skipping
  18082. for (i = 1; i < subitemsCount; i++) {
  18083. incHex(end, dataSize);
  18084. stream.readHexNumber(start, dataSize);
  18085. addHex(start, end, dataSize);
  18086. stream.readHexNumber(end, dataSize);
  18087. addHex(end, start, dataSize);
  18088. code = stream.readNumber();
  18089. // nop
  18090. }
  18091. break;
  18092. case 2: // cidchar
  18093. stream.readHex(char, dataSize);
  18094. code = stream.readNumber();
  18095. cMap.mapOne(hexToInt(char, dataSize), code);
  18096. for (i = 1; i < subitemsCount; i++) {
  18097. incHex(char, dataSize);
  18098. if (!sequence) {
  18099. stream.readHexNumber(tmp, dataSize);
  18100. addHex(char, tmp, dataSize);
  18101. }
  18102. code = stream.readSigned() + (code + 1);
  18103. cMap.mapOne(hexToInt(char, dataSize), code);
  18104. }
  18105. break;
  18106. case 3: // cidrange
  18107. stream.readHex(start, dataSize);
  18108. stream.readHexNumber(end, dataSize);
  18109. addHex(end, start, dataSize);
  18110. code = stream.readNumber();
  18111. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18112. code);
  18113. for (i = 1; i < subitemsCount; i++) {
  18114. incHex(end, dataSize);
  18115. if (!sequence) {
  18116. stream.readHexNumber(start, dataSize);
  18117. addHex(start, end, dataSize);
  18118. } else {
  18119. start.set(end);
  18120. }
  18121. stream.readHexNumber(end, dataSize);
  18122. addHex(end, start, dataSize);
  18123. code = stream.readNumber();
  18124. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18125. code);
  18126. }
  18127. break;
  18128. case 4: // bfchar
  18129. stream.readHex(char, ucs2DataSize);
  18130. stream.readHex(charCode, dataSize);
  18131. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18132. hexToStr(charCode, dataSize));
  18133. for (i = 1; i < subitemsCount; i++) {
  18134. incHex(char, ucs2DataSize);
  18135. if (!sequence) {
  18136. stream.readHexNumber(tmp, ucs2DataSize);
  18137. addHex(char, tmp, ucs2DataSize);
  18138. }
  18139. incHex(charCode, dataSize);
  18140. stream.readHexSigned(tmp, dataSize);
  18141. addHex(charCode, tmp, dataSize);
  18142. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18143. hexToStr(charCode, dataSize));
  18144. }
  18145. break;
  18146. case 5: // bfrange
  18147. stream.readHex(start, ucs2DataSize);
  18148. stream.readHexNumber(end, ucs2DataSize);
  18149. addHex(end, start, ucs2DataSize);
  18150. stream.readHex(charCode, dataSize);
  18151. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18152. hexToInt(end, ucs2DataSize),
  18153. hexToStr(charCode, dataSize));
  18154. for (i = 1; i < subitemsCount; i++) {
  18155. incHex(end, ucs2DataSize);
  18156. if (!sequence) {
  18157. stream.readHexNumber(start, ucs2DataSize);
  18158. addHex(start, end, ucs2DataSize);
  18159. } else {
  18160. start.set(end);
  18161. }
  18162. stream.readHexNumber(end, ucs2DataSize);
  18163. addHex(end, start, ucs2DataSize);
  18164. stream.readHex(charCode, dataSize);
  18165. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18166. hexToInt(end, ucs2DataSize),
  18167. hexToStr(charCode, dataSize));
  18168. }
  18169. break;
  18170. default:
  18171. error('Unknown type: ' + type);
  18172. break;
  18173. }
  18174. }
  18175. if (useCMap) {
  18176. extend(useCMap);
  18177. }
  18178. return cMap;
  18179. }
  18180. function BinaryCMapReader() {}
  18181. BinaryCMapReader.prototype = {
  18182. read: processBinaryCMap
  18183. };
  18184. return BinaryCMapReader;
  18185. })();
  18186. var CMapFactory = (function CMapFactoryClosure() {
  18187. function strToInt(str) {
  18188. var a = 0;
  18189. for (var i = 0; i < str.length; i++) {
  18190. a = (a << 8) | str.charCodeAt(i);
  18191. }
  18192. return a >>> 0;
  18193. }
  18194. function expectString(obj) {
  18195. if (!isString(obj)) {
  18196. error('Malformed CMap: expected string.');
  18197. }
  18198. }
  18199. function expectInt(obj) {
  18200. if (!isInt(obj)) {
  18201. error('Malformed CMap: expected int.');
  18202. }
  18203. }
  18204. function parseBfChar(cMap, lexer) {
  18205. while (true) {
  18206. var obj = lexer.getObj();
  18207. if (isEOF(obj)) {
  18208. break;
  18209. }
  18210. if (isCmd(obj, 'endbfchar')) {
  18211. return;
  18212. }
  18213. expectString(obj);
  18214. var src = strToInt(obj);
  18215. obj = lexer.getObj();
  18216. // TODO are /dstName used?
  18217. expectString(obj);
  18218. var dst = obj;
  18219. cMap.mapOne(src, dst);
  18220. }
  18221. }
  18222. function parseBfRange(cMap, lexer) {
  18223. while (true) {
  18224. var obj = lexer.getObj();
  18225. if (isEOF(obj)) {
  18226. break;
  18227. }
  18228. if (isCmd(obj, 'endbfrange')) {
  18229. return;
  18230. }
  18231. expectString(obj);
  18232. var low = strToInt(obj);
  18233. obj = lexer.getObj();
  18234. expectString(obj);
  18235. var high = strToInt(obj);
  18236. obj = lexer.getObj();
  18237. if (isInt(obj) || isString(obj)) {
  18238. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  18239. cMap.mapBfRange(low, high, dstLow);
  18240. } else if (isCmd(obj, '[')) {
  18241. obj = lexer.getObj();
  18242. var array = [];
  18243. while (!isCmd(obj, ']') && !isEOF(obj)) {
  18244. array.push(obj);
  18245. obj = lexer.getObj();
  18246. }
  18247. cMap.mapBfRangeToArray(low, high, array);
  18248. } else {
  18249. break;
  18250. }
  18251. }
  18252. error('Invalid bf range.');
  18253. }
  18254. function parseCidChar(cMap, lexer) {
  18255. while (true) {
  18256. var obj = lexer.getObj();
  18257. if (isEOF(obj)) {
  18258. break;
  18259. }
  18260. if (isCmd(obj, 'endcidchar')) {
  18261. return;
  18262. }
  18263. expectString(obj);
  18264. var src = strToInt(obj);
  18265. obj = lexer.getObj();
  18266. expectInt(obj);
  18267. var dst = obj;
  18268. cMap.mapOne(src, dst);
  18269. }
  18270. }
  18271. function parseCidRange(cMap, lexer) {
  18272. while (true) {
  18273. var obj = lexer.getObj();
  18274. if (isEOF(obj)) {
  18275. break;
  18276. }
  18277. if (isCmd(obj, 'endcidrange')) {
  18278. return;
  18279. }
  18280. expectString(obj);
  18281. var low = strToInt(obj);
  18282. obj = lexer.getObj();
  18283. expectString(obj);
  18284. var high = strToInt(obj);
  18285. obj = lexer.getObj();
  18286. expectInt(obj);
  18287. var dstLow = obj;
  18288. cMap.mapCidRange(low, high, dstLow);
  18289. }
  18290. }
  18291. function parseCodespaceRange(cMap, lexer) {
  18292. while (true) {
  18293. var obj = lexer.getObj();
  18294. if (isEOF(obj)) {
  18295. break;
  18296. }
  18297. if (isCmd(obj, 'endcodespacerange')) {
  18298. return;
  18299. }
  18300. if (!isString(obj)) {
  18301. break;
  18302. }
  18303. var low = strToInt(obj);
  18304. obj = lexer.getObj();
  18305. if (!isString(obj)) {
  18306. break;
  18307. }
  18308. var high = strToInt(obj);
  18309. cMap.addCodespaceRange(obj.length, low, high);
  18310. }
  18311. error('Invalid codespace range.');
  18312. }
  18313. function parseWMode(cMap, lexer) {
  18314. var obj = lexer.getObj();
  18315. if (isInt(obj)) {
  18316. cMap.vertical = !!obj;
  18317. }
  18318. }
  18319. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  18320. var previous;
  18321. var embededUseCMap;
  18322. objLoop: while (true) {
  18323. var obj = lexer.getObj();
  18324. if (isEOF(obj)) {
  18325. break;
  18326. } else if (isName(obj)) {
  18327. if (obj.name === 'WMode') {
  18328. parseWMode(cMap, lexer);
  18329. }
  18330. previous = obj;
  18331. } else if (isCmd(obj)) {
  18332. switch (obj.cmd) {
  18333. case 'endcmap':
  18334. break objLoop;
  18335. case 'usecmap':
  18336. if (isName(previous)) {
  18337. embededUseCMap = previous.name;
  18338. }
  18339. break;
  18340. case 'begincodespacerange':
  18341. parseCodespaceRange(cMap, lexer);
  18342. break;
  18343. case 'beginbfchar':
  18344. parseBfChar(cMap, lexer);
  18345. break;
  18346. case 'begincidchar':
  18347. parseCidChar(cMap, lexer);
  18348. break;
  18349. case 'beginbfrange':
  18350. parseBfRange(cMap, lexer);
  18351. break;
  18352. case 'begincidrange':
  18353. parseCidRange(cMap, lexer);
  18354. break;
  18355. }
  18356. }
  18357. }
  18358. if (!useCMap && embededUseCMap) {
  18359. // Load the usecmap definition from the file only if there wasn't one
  18360. // specified.
  18361. useCMap = embededUseCMap;
  18362. }
  18363. if (useCMap) {
  18364. extendCMap(cMap, builtInCMapParams, useCMap);
  18365. }
  18366. }
  18367. function extendCMap(cMap, builtInCMapParams, useCMap) {
  18368. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  18369. // If there aren't any code space ranges defined clone all the parent ones
  18370. // into this cMap.
  18371. if (cMap.numCodespaceRanges === 0) {
  18372. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  18373. for (var i = 0; i < useCodespaceRanges.length; i++) {
  18374. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  18375. }
  18376. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  18377. }
  18378. // Merge the map into the current one, making sure not to override
  18379. // any previously defined entries.
  18380. cMap.useCMap.forEach(function(key, value) {
  18381. if (!cMap.contains(key)) {
  18382. cMap.mapOne(key, cMap.useCMap.lookup(key));
  18383. }
  18384. });
  18385. }
  18386. function parseBinaryCMap(name, builtInCMapParams) {
  18387. var url = builtInCMapParams.url + name + '.bcmap';
  18388. var cMap = new CMap(true);
  18389. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  18390. extendCMap(cMap, builtInCMapParams, useCMap);
  18391. });
  18392. return cMap;
  18393. }
  18394. function createBuiltInCMap(name, builtInCMapParams) {
  18395. if (name === 'Identity-H') {
  18396. return new IdentityCMap(false, 2);
  18397. } else if (name === 'Identity-V') {
  18398. return new IdentityCMap(true, 2);
  18399. }
  18400. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  18401. error('Unknown cMap name: ' + name);
  18402. }
  18403. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  18404. if (builtInCMapParams.packed) {
  18405. return parseBinaryCMap(name, builtInCMapParams);
  18406. }
  18407. var request = new XMLHttpRequest();
  18408. var url = builtInCMapParams.url + name;
  18409. request.open('GET', url, false);
  18410. request.send(null);
  18411. if (!request.responseText) {
  18412. error('Unable to get cMap at: ' + url);
  18413. }
  18414. var cMap = new CMap(true);
  18415. var lexer = new Lexer(new StringStream(request.responseText));
  18416. parseCMap(cMap, lexer, builtInCMapParams, null);
  18417. return cMap;
  18418. }
  18419. return {
  18420. create: function (encoding, builtInCMapParams, useCMap) {
  18421. if (isName(encoding)) {
  18422. return createBuiltInCMap(encoding.name, builtInCMapParams);
  18423. } else if (isStream(encoding)) {
  18424. var cMap = new CMap();
  18425. var lexer = new Lexer(encoding);
  18426. try {
  18427. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  18428. } catch (e) {
  18429. warn('Invalid CMap data. ' + e);
  18430. }
  18431. return cMap;
  18432. }
  18433. error('Encoding required.');
  18434. }
  18435. };
  18436. })();
  18437. // Unicode Private Use Area
  18438. var PRIVATE_USE_OFFSET_START = 0xE000;
  18439. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  18440. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  18441. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  18442. // except for Type 3 fonts
  18443. var PDF_GLYPH_SPACE_UNITS = 1000;
  18444. // Hinting is currently disabled due to unknown problems on windows
  18445. // in tracemonkey and various other pdfs with type1 fonts.
  18446. var HINTING_ENABLED = false;
  18447. // Accented charactars are not displayed properly on windows, using this flag
  18448. // to control analysis of seac charstrings.
  18449. var SEAC_ANALYSIS_ENABLED = false;
  18450. var FontFlags = {
  18451. FixedPitch: 1,
  18452. Serif: 2,
  18453. Symbolic: 4,
  18454. Script: 8,
  18455. Nonsymbolic: 32,
  18456. Italic: 64,
  18457. AllCap: 65536,
  18458. SmallCap: 131072,
  18459. ForceBold: 262144
  18460. };
  18461. var Encodings = {
  18462. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18463. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18464. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  18465. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  18466. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  18467. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  18468. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  18469. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  18470. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  18471. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  18472. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  18473. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  18474. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  18475. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  18476. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  18477. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  18478. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  18479. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  18480. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  18481. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18482. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18483. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  18484. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  18485. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  18486. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  18487. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  18488. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  18489. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  18490. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  18491. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  18492. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  18493. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  18494. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  18495. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  18496. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  18497. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  18498. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  18499. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  18500. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  18501. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  18502. 'Ydieresissmall'],
  18503. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18504. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18505. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  18506. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  18507. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18508. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  18509. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  18510. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  18511. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  18512. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  18513. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  18514. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  18515. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  18516. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  18517. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18518. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18519. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18520. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18521. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  18522. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  18523. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  18524. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  18525. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  18526. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  18527. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  18528. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  18529. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  18530. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  18531. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  18532. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  18533. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  18534. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  18535. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  18536. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  18537. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18538. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  18539. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  18540. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  18541. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  18542. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  18543. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18544. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18545. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18546. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18547. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18548. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18549. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18550. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18551. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18552. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18553. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18554. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  18555. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  18556. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  18557. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18558. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  18559. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  18560. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  18561. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  18562. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  18563. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  18564. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  18565. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  18566. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  18567. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  18568. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  18569. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  18570. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  18571. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  18572. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  18573. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  18574. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  18575. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  18576. 'ogonek', 'caron'],
  18577. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18578. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18579. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18580. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18581. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18582. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18583. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18584. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18585. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18586. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  18587. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  18588. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18589. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18590. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  18591. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18592. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18593. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  18594. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  18595. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  18596. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  18597. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  18598. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  18599. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  18600. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  18601. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  18602. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18603. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18604. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18605. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18606. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18607. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18608. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18609. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18610. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18611. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18612. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18613. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18614. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  18615. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  18616. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  18617. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  18618. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  18619. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  18620. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  18621. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  18622. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  18623. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  18624. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  18625. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  18626. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  18627. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  18628. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  18629. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  18630. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  18631. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  18632. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  18633. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  18634. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  18635. 'ydieresis'],
  18636. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18637. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18638. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  18639. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  18640. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18641. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18642. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  18643. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  18644. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  18645. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  18646. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  18647. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  18648. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  18649. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  18650. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  18651. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18652. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  18653. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  18654. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  18655. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  18656. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  18657. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  18658. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  18659. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  18660. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  18661. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  18662. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  18663. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  18664. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  18665. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  18666. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  18667. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  18668. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  18669. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  18670. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  18671. 'bracerightbt'],
  18672. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18673. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18674. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  18675. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  18676. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  18677. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  18678. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  18679. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  18680. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  18681. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  18682. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  18683. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  18684. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  18685. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  18686. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  18687. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  18688. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  18689. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  18690. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  18691. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  18692. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  18693. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  18694. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  18695. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  18696. };
  18697. /**
  18698. * Hold a map of decoded fonts and of the standard fourteen Type1
  18699. * fonts and their acronyms.
  18700. */
  18701. var stdFontMap = {
  18702. 'ArialNarrow': 'Helvetica',
  18703. 'ArialNarrow-Bold': 'Helvetica-Bold',
  18704. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  18705. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  18706. 'ArialBlack': 'Helvetica',
  18707. 'ArialBlack-Bold': 'Helvetica-Bold',
  18708. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  18709. 'ArialBlack-Italic': 'Helvetica-Oblique',
  18710. 'Arial': 'Helvetica',
  18711. 'Arial-Bold': 'Helvetica-Bold',
  18712. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  18713. 'Arial-Italic': 'Helvetica-Oblique',
  18714. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  18715. 'Arial-BoldMT': 'Helvetica-Bold',
  18716. 'Arial-ItalicMT': 'Helvetica-Oblique',
  18717. 'ArialMT': 'Helvetica',
  18718. 'Courier-Bold': 'Courier-Bold',
  18719. 'Courier-BoldItalic': 'Courier-BoldOblique',
  18720. 'Courier-Italic': 'Courier-Oblique',
  18721. 'CourierNew': 'Courier',
  18722. 'CourierNew-Bold': 'Courier-Bold',
  18723. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  18724. 'CourierNew-Italic': 'Courier-Oblique',
  18725. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  18726. 'CourierNewPS-BoldMT': 'Courier-Bold',
  18727. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  18728. 'CourierNewPSMT': 'Courier',
  18729. 'Helvetica': 'Helvetica',
  18730. 'Helvetica-Bold': 'Helvetica-Bold',
  18731. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  18732. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  18733. 'Helvetica-Italic': 'Helvetica-Oblique',
  18734. 'Helvetica-Oblique':'Helvetica-Oblique',
  18735. 'Symbol-Bold': 'Symbol',
  18736. 'Symbol-BoldItalic': 'Symbol',
  18737. 'Symbol-Italic': 'Symbol',
  18738. 'TimesNewRoman': 'Times-Roman',
  18739. 'TimesNewRoman-Bold': 'Times-Bold',
  18740. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  18741. 'TimesNewRoman-Italic': 'Times-Italic',
  18742. 'TimesNewRomanPS': 'Times-Roman',
  18743. 'TimesNewRomanPS-Bold': 'Times-Bold',
  18744. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  18745. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  18746. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  18747. 'TimesNewRomanPS-Italic': 'Times-Italic',
  18748. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  18749. 'TimesNewRomanPSMT': 'Times-Roman',
  18750. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  18751. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  18752. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  18753. };
  18754. /**
  18755. * Holds the map of the non-standard fonts that might be included as a standard
  18756. * fonts without glyph data.
  18757. */
  18758. var nonStdFontMap = {
  18759. 'CenturyGothic': 'Helvetica',
  18760. 'CenturyGothic-Bold': 'Helvetica-Bold',
  18761. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  18762. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  18763. 'ComicSansMS': 'Comic Sans MS',
  18764. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  18765. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  18766. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  18767. 'LucidaConsole': 'Courier',
  18768. 'LucidaConsole-Bold': 'Courier-Bold',
  18769. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  18770. 'LucidaConsole-Italic': 'Courier-Oblique',
  18771. 'MS-Gothic': 'MS Gothic',
  18772. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  18773. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  18774. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  18775. 'MS-Mincho': 'MS Mincho',
  18776. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  18777. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  18778. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  18779. 'MS-PGothic': 'MS PGothic',
  18780. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  18781. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  18782. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  18783. 'MS-PMincho': 'MS PMincho',
  18784. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  18785. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  18786. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  18787. 'Wingdings': 'ZapfDingbats'
  18788. };
  18789. var serifFonts = {
  18790. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  18791. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  18792. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  18793. 'Arno': true, 'Aster': true, 'Aurora': true,
  18794. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  18795. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  18796. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  18797. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  18798. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  18799. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  18800. 'Cartier': true, 'Caslon': true, 'Catull': true,
  18801. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  18802. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  18803. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  18804. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  18805. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  18806. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  18807. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  18808. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  18809. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  18810. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  18811. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  18812. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  18813. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  18814. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  18815. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  18816. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  18817. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  18818. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  18819. 'Miller': true, 'Minion': true, 'Modern': true,
  18820. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  18821. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  18822. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  18823. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  18824. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  18825. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  18826. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  18827. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  18828. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  18829. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  18830. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  18831. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  18832. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  18833. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  18834. };
  18835. var symbolsFonts = {
  18836. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  18837. };
  18838. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  18839. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  18840. // glyphs, but common for some set of the standard fonts.
  18841. var GlyphMapForStandardFonts = {
  18842. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  18843. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  18844. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  18845. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  18846. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  18847. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  18848. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  18849. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  18850. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  18851. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  18852. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  18853. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  18854. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  18855. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  18856. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  18857. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  18858. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  18859. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  18860. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  18861. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  18862. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  18863. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  18864. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  18865. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  18866. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  18867. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  18868. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  18869. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  18870. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  18871. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  18872. '298': 380, '305': 963,
  18873. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  18874. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  18875. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  18876. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  18877. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  18878. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  18879. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  18880. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  18881. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  18882. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  18883. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  18884. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  18885. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  18886. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  18887. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  18888. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  18889. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  18890. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  18891. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  18892. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  18893. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  18894. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  18895. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  18896. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  18897. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  18898. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  18899. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  18900. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  18901. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  18902. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  18903. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  18904. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  18905. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  18906. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  18907. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  18908. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  18909. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  18910. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  18911. };
  18912. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  18913. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  18914. // to the similar equivalents in the normal characters range.
  18915. var SpecialPUASymbols = {
  18916. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  18917. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  18918. '63720': 0x00AE, // registersans (0xF8E8) => registered
  18919. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  18920. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  18921. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  18922. '63729': 0x23A7, // bracelefttp (0xF8F1)
  18923. '63730': 0x23A8, // braceleftmid (0xF8F2)
  18924. '63731': 0x23A9, // braceleftbt (0xF8F3)
  18925. '63740': 0x23AB, // bracerighttp (0xF8FC)
  18926. '63741': 0x23AC, // bracerightmid (0xF8FD)
  18927. '63742': 0x23AD, // bracerightbt (0xF8FE)
  18928. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  18929. '63727': 0x23A2, // bracketleftex (0xF8EF)
  18930. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  18931. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  18932. '63738': 0x23A5, // bracketrightex (0xF8FA)
  18933. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  18934. '63723': 0x239B, // parenlefttp (0xF8EB)
  18935. '63724': 0x239C, // parenleftex (0xF8EC)
  18936. '63725': 0x239D, // parenleftbt (0xF8ED)
  18937. '63734': 0x239E, // parenrighttp (0xF8F6)
  18938. '63735': 0x239F, // parenrightex (0xF8F7)
  18939. '63736': 0x23A0, // parenrightbt (0xF8F8)
  18940. };
  18941. function mapSpecialUnicodeValues(code) {
  18942. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  18943. return 0;
  18944. } else if (code >= 0xF600 && code <= 0xF8FF) {
  18945. return (SpecialPUASymbols[code] || code);
  18946. }
  18947. return code;
  18948. }
  18949. var UnicodeRanges = [
  18950. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  18951. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  18952. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  18953. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  18954. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  18955. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  18956. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  18957. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  18958. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  18959. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  18960. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  18961. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  18962. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  18963. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  18964. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  18965. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  18966. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  18967. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  18968. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  18969. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  18970. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  18971. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  18972. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  18973. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  18974. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  18975. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  18976. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  18977. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  18978. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  18979. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  18980. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  18981. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  18982. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  18983. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  18984. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  18985. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  18986. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  18987. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  18988. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  18989. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  18990. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  18991. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  18992. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  18993. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  18994. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  18995. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  18996. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  18997. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  18998. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  18999. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  19000. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  19001. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  19002. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  19003. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  19004. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  19005. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  19006. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  19007. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  19008. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  19009. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  19010. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  19011. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  19012. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  19013. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  19014. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  19015. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  19016. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  19017. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  19018. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  19019. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  19020. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  19021. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  19022. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  19023. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  19024. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  19025. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  19026. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  19027. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  19028. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  19029. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  19030. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  19031. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  19032. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  19033. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  19034. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  19035. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  19036. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  19037. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  19038. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  19039. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  19040. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  19041. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  19042. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  19043. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  19044. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  19045. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  19046. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  19047. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  19048. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  19049. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  19050. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  19051. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  19052. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  19053. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  19054. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  19055. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  19056. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  19057. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  19058. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  19059. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  19060. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  19061. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  19062. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  19063. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  19064. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  19065. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  19066. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  19067. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  19068. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  19069. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  19070. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  19071. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  19072. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  19073. ];
  19074. var MacStandardGlyphOrdering = [
  19075. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  19076. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  19077. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  19078. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  19079. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  19080. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  19081. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  19082. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  19083. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  19084. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  19085. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  19086. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  19087. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  19088. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  19089. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  19090. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  19091. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  19092. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  19093. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  19094. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  19095. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  19096. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  19097. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  19098. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  19099. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  19100. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  19101. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  19102. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  19103. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  19104. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  19105. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  19106. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  19107. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  19108. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  19109. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  19110. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  19111. function getUnicodeRangeFor(value) {
  19112. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  19113. var range = UnicodeRanges[i];
  19114. if (value >= range.begin && value < range.end) {
  19115. return i;
  19116. }
  19117. }
  19118. return -1;
  19119. }
  19120. function isRTLRangeFor(value) {
  19121. var range = UnicodeRanges[13];
  19122. if (value >= range.begin && value < range.end) {
  19123. return true;
  19124. }
  19125. range = UnicodeRanges[11];
  19126. if (value >= range.begin && value < range.end) {
  19127. return true;
  19128. }
  19129. return false;
  19130. }
  19131. // The normalization table is obtained by filtering the Unicode characters
  19132. // database with <compat> entries.
  19133. var NormalizedUnicodes = {
  19134. '\u00A8': '\u0020\u0308',
  19135. '\u00AF': '\u0020\u0304',
  19136. '\u00B4': '\u0020\u0301',
  19137. '\u00B5': '\u03BC',
  19138. '\u00B8': '\u0020\u0327',
  19139. '\u0132': '\u0049\u004A',
  19140. '\u0133': '\u0069\u006A',
  19141. '\u013F': '\u004C\u00B7',
  19142. '\u0140': '\u006C\u00B7',
  19143. '\u0149': '\u02BC\u006E',
  19144. '\u017F': '\u0073',
  19145. '\u01C4': '\u0044\u017D',
  19146. '\u01C5': '\u0044\u017E',
  19147. '\u01C6': '\u0064\u017E',
  19148. '\u01C7': '\u004C\u004A',
  19149. '\u01C8': '\u004C\u006A',
  19150. '\u01C9': '\u006C\u006A',
  19151. '\u01CA': '\u004E\u004A',
  19152. '\u01CB': '\u004E\u006A',
  19153. '\u01CC': '\u006E\u006A',
  19154. '\u01F1': '\u0044\u005A',
  19155. '\u01F2': '\u0044\u007A',
  19156. '\u01F3': '\u0064\u007A',
  19157. '\u02D8': '\u0020\u0306',
  19158. '\u02D9': '\u0020\u0307',
  19159. '\u02DA': '\u0020\u030A',
  19160. '\u02DB': '\u0020\u0328',
  19161. '\u02DC': '\u0020\u0303',
  19162. '\u02DD': '\u0020\u030B',
  19163. '\u037A': '\u0020\u0345',
  19164. '\u0384': '\u0020\u0301',
  19165. '\u03D0': '\u03B2',
  19166. '\u03D1': '\u03B8',
  19167. '\u03D2': '\u03A5',
  19168. '\u03D5': '\u03C6',
  19169. '\u03D6': '\u03C0',
  19170. '\u03F0': '\u03BA',
  19171. '\u03F1': '\u03C1',
  19172. '\u03F2': '\u03C2',
  19173. '\u03F4': '\u0398',
  19174. '\u03F5': '\u03B5',
  19175. '\u03F9': '\u03A3',
  19176. '\u0587': '\u0565\u0582',
  19177. '\u0675': '\u0627\u0674',
  19178. '\u0676': '\u0648\u0674',
  19179. '\u0677': '\u06C7\u0674',
  19180. '\u0678': '\u064A\u0674',
  19181. '\u0E33': '\u0E4D\u0E32',
  19182. '\u0EB3': '\u0ECD\u0EB2',
  19183. '\u0EDC': '\u0EAB\u0E99',
  19184. '\u0EDD': '\u0EAB\u0EA1',
  19185. '\u0F77': '\u0FB2\u0F81',
  19186. '\u0F79': '\u0FB3\u0F81',
  19187. '\u1E9A': '\u0061\u02BE',
  19188. '\u1FBD': '\u0020\u0313',
  19189. '\u1FBF': '\u0020\u0313',
  19190. '\u1FC0': '\u0020\u0342',
  19191. '\u1FFE': '\u0020\u0314',
  19192. '\u2002': '\u0020',
  19193. '\u2003': '\u0020',
  19194. '\u2004': '\u0020',
  19195. '\u2005': '\u0020',
  19196. '\u2006': '\u0020',
  19197. '\u2008': '\u0020',
  19198. '\u2009': '\u0020',
  19199. '\u200A': '\u0020',
  19200. '\u2017': '\u0020\u0333',
  19201. '\u2024': '\u002E',
  19202. '\u2025': '\u002E\u002E',
  19203. '\u2026': '\u002E\u002E\u002E',
  19204. '\u2033': '\u2032\u2032',
  19205. '\u2034': '\u2032\u2032\u2032',
  19206. '\u2036': '\u2035\u2035',
  19207. '\u2037': '\u2035\u2035\u2035',
  19208. '\u203C': '\u0021\u0021',
  19209. '\u203E': '\u0020\u0305',
  19210. '\u2047': '\u003F\u003F',
  19211. '\u2048': '\u003F\u0021',
  19212. '\u2049': '\u0021\u003F',
  19213. '\u2057': '\u2032\u2032\u2032\u2032',
  19214. '\u205F': '\u0020',
  19215. '\u20A8': '\u0052\u0073',
  19216. '\u2100': '\u0061\u002F\u0063',
  19217. '\u2101': '\u0061\u002F\u0073',
  19218. '\u2103': '\u00B0\u0043',
  19219. '\u2105': '\u0063\u002F\u006F',
  19220. '\u2106': '\u0063\u002F\u0075',
  19221. '\u2107': '\u0190',
  19222. '\u2109': '\u00B0\u0046',
  19223. '\u2116': '\u004E\u006F',
  19224. '\u2121': '\u0054\u0045\u004C',
  19225. '\u2135': '\u05D0',
  19226. '\u2136': '\u05D1',
  19227. '\u2137': '\u05D2',
  19228. '\u2138': '\u05D3',
  19229. '\u213B': '\u0046\u0041\u0058',
  19230. '\u2160': '\u0049',
  19231. '\u2161': '\u0049\u0049',
  19232. '\u2162': '\u0049\u0049\u0049',
  19233. '\u2163': '\u0049\u0056',
  19234. '\u2164': '\u0056',
  19235. '\u2165': '\u0056\u0049',
  19236. '\u2166': '\u0056\u0049\u0049',
  19237. '\u2167': '\u0056\u0049\u0049\u0049',
  19238. '\u2168': '\u0049\u0058',
  19239. '\u2169': '\u0058',
  19240. '\u216A': '\u0058\u0049',
  19241. '\u216B': '\u0058\u0049\u0049',
  19242. '\u216C': '\u004C',
  19243. '\u216D': '\u0043',
  19244. '\u216E': '\u0044',
  19245. '\u216F': '\u004D',
  19246. '\u2170': '\u0069',
  19247. '\u2171': '\u0069\u0069',
  19248. '\u2172': '\u0069\u0069\u0069',
  19249. '\u2173': '\u0069\u0076',
  19250. '\u2174': '\u0076',
  19251. '\u2175': '\u0076\u0069',
  19252. '\u2176': '\u0076\u0069\u0069',
  19253. '\u2177': '\u0076\u0069\u0069\u0069',
  19254. '\u2178': '\u0069\u0078',
  19255. '\u2179': '\u0078',
  19256. '\u217A': '\u0078\u0069',
  19257. '\u217B': '\u0078\u0069\u0069',
  19258. '\u217C': '\u006C',
  19259. '\u217D': '\u0063',
  19260. '\u217E': '\u0064',
  19261. '\u217F': '\u006D',
  19262. '\u222C': '\u222B\u222B',
  19263. '\u222D': '\u222B\u222B\u222B',
  19264. '\u222F': '\u222E\u222E',
  19265. '\u2230': '\u222E\u222E\u222E',
  19266. '\u2474': '\u0028\u0031\u0029',
  19267. '\u2475': '\u0028\u0032\u0029',
  19268. '\u2476': '\u0028\u0033\u0029',
  19269. '\u2477': '\u0028\u0034\u0029',
  19270. '\u2478': '\u0028\u0035\u0029',
  19271. '\u2479': '\u0028\u0036\u0029',
  19272. '\u247A': '\u0028\u0037\u0029',
  19273. '\u247B': '\u0028\u0038\u0029',
  19274. '\u247C': '\u0028\u0039\u0029',
  19275. '\u247D': '\u0028\u0031\u0030\u0029',
  19276. '\u247E': '\u0028\u0031\u0031\u0029',
  19277. '\u247F': '\u0028\u0031\u0032\u0029',
  19278. '\u2480': '\u0028\u0031\u0033\u0029',
  19279. '\u2481': '\u0028\u0031\u0034\u0029',
  19280. '\u2482': '\u0028\u0031\u0035\u0029',
  19281. '\u2483': '\u0028\u0031\u0036\u0029',
  19282. '\u2484': '\u0028\u0031\u0037\u0029',
  19283. '\u2485': '\u0028\u0031\u0038\u0029',
  19284. '\u2486': '\u0028\u0031\u0039\u0029',
  19285. '\u2487': '\u0028\u0032\u0030\u0029',
  19286. '\u2488': '\u0031\u002E',
  19287. '\u2489': '\u0032\u002E',
  19288. '\u248A': '\u0033\u002E',
  19289. '\u248B': '\u0034\u002E',
  19290. '\u248C': '\u0035\u002E',
  19291. '\u248D': '\u0036\u002E',
  19292. '\u248E': '\u0037\u002E',
  19293. '\u248F': '\u0038\u002E',
  19294. '\u2490': '\u0039\u002E',
  19295. '\u2491': '\u0031\u0030\u002E',
  19296. '\u2492': '\u0031\u0031\u002E',
  19297. '\u2493': '\u0031\u0032\u002E',
  19298. '\u2494': '\u0031\u0033\u002E',
  19299. '\u2495': '\u0031\u0034\u002E',
  19300. '\u2496': '\u0031\u0035\u002E',
  19301. '\u2497': '\u0031\u0036\u002E',
  19302. '\u2498': '\u0031\u0037\u002E',
  19303. '\u2499': '\u0031\u0038\u002E',
  19304. '\u249A': '\u0031\u0039\u002E',
  19305. '\u249B': '\u0032\u0030\u002E',
  19306. '\u249C': '\u0028\u0061\u0029',
  19307. '\u249D': '\u0028\u0062\u0029',
  19308. '\u249E': '\u0028\u0063\u0029',
  19309. '\u249F': '\u0028\u0064\u0029',
  19310. '\u24A0': '\u0028\u0065\u0029',
  19311. '\u24A1': '\u0028\u0066\u0029',
  19312. '\u24A2': '\u0028\u0067\u0029',
  19313. '\u24A3': '\u0028\u0068\u0029',
  19314. '\u24A4': '\u0028\u0069\u0029',
  19315. '\u24A5': '\u0028\u006A\u0029',
  19316. '\u24A6': '\u0028\u006B\u0029',
  19317. '\u24A7': '\u0028\u006C\u0029',
  19318. '\u24A8': '\u0028\u006D\u0029',
  19319. '\u24A9': '\u0028\u006E\u0029',
  19320. '\u24AA': '\u0028\u006F\u0029',
  19321. '\u24AB': '\u0028\u0070\u0029',
  19322. '\u24AC': '\u0028\u0071\u0029',
  19323. '\u24AD': '\u0028\u0072\u0029',
  19324. '\u24AE': '\u0028\u0073\u0029',
  19325. '\u24AF': '\u0028\u0074\u0029',
  19326. '\u24B0': '\u0028\u0075\u0029',
  19327. '\u24B1': '\u0028\u0076\u0029',
  19328. '\u24B2': '\u0028\u0077\u0029',
  19329. '\u24B3': '\u0028\u0078\u0029',
  19330. '\u24B4': '\u0028\u0079\u0029',
  19331. '\u24B5': '\u0028\u007A\u0029',
  19332. '\u2A0C': '\u222B\u222B\u222B\u222B',
  19333. '\u2A74': '\u003A\u003A\u003D',
  19334. '\u2A75': '\u003D\u003D',
  19335. '\u2A76': '\u003D\u003D\u003D',
  19336. '\u2E9F': '\u6BCD',
  19337. '\u2EF3': '\u9F9F',
  19338. '\u2F00': '\u4E00',
  19339. '\u2F01': '\u4E28',
  19340. '\u2F02': '\u4E36',
  19341. '\u2F03': '\u4E3F',
  19342. '\u2F04': '\u4E59',
  19343. '\u2F05': '\u4E85',
  19344. '\u2F06': '\u4E8C',
  19345. '\u2F07': '\u4EA0',
  19346. '\u2F08': '\u4EBA',
  19347. '\u2F09': '\u513F',
  19348. '\u2F0A': '\u5165',
  19349. '\u2F0B': '\u516B',
  19350. '\u2F0C': '\u5182',
  19351. '\u2F0D': '\u5196',
  19352. '\u2F0E': '\u51AB',
  19353. '\u2F0F': '\u51E0',
  19354. '\u2F10': '\u51F5',
  19355. '\u2F11': '\u5200',
  19356. '\u2F12': '\u529B',
  19357. '\u2F13': '\u52F9',
  19358. '\u2F14': '\u5315',
  19359. '\u2F15': '\u531A',
  19360. '\u2F16': '\u5338',
  19361. '\u2F17': '\u5341',
  19362. '\u2F18': '\u535C',
  19363. '\u2F19': '\u5369',
  19364. '\u2F1A': '\u5382',
  19365. '\u2F1B': '\u53B6',
  19366. '\u2F1C': '\u53C8',
  19367. '\u2F1D': '\u53E3',
  19368. '\u2F1E': '\u56D7',
  19369. '\u2F1F': '\u571F',
  19370. '\u2F20': '\u58EB',
  19371. '\u2F21': '\u5902',
  19372. '\u2F22': '\u590A',
  19373. '\u2F23': '\u5915',
  19374. '\u2F24': '\u5927',
  19375. '\u2F25': '\u5973',
  19376. '\u2F26': '\u5B50',
  19377. '\u2F27': '\u5B80',
  19378. '\u2F28': '\u5BF8',
  19379. '\u2F29': '\u5C0F',
  19380. '\u2F2A': '\u5C22',
  19381. '\u2F2B': '\u5C38',
  19382. '\u2F2C': '\u5C6E',
  19383. '\u2F2D': '\u5C71',
  19384. '\u2F2E': '\u5DDB',
  19385. '\u2F2F': '\u5DE5',
  19386. '\u2F30': '\u5DF1',
  19387. '\u2F31': '\u5DFE',
  19388. '\u2F32': '\u5E72',
  19389. '\u2F33': '\u5E7A',
  19390. '\u2F34': '\u5E7F',
  19391. '\u2F35': '\u5EF4',
  19392. '\u2F36': '\u5EFE',
  19393. '\u2F37': '\u5F0B',
  19394. '\u2F38': '\u5F13',
  19395. '\u2F39': '\u5F50',
  19396. '\u2F3A': '\u5F61',
  19397. '\u2F3B': '\u5F73',
  19398. '\u2F3C': '\u5FC3',
  19399. '\u2F3D': '\u6208',
  19400. '\u2F3E': '\u6236',
  19401. '\u2F3F': '\u624B',
  19402. '\u2F40': '\u652F',
  19403. '\u2F41': '\u6534',
  19404. '\u2F42': '\u6587',
  19405. '\u2F43': '\u6597',
  19406. '\u2F44': '\u65A4',
  19407. '\u2F45': '\u65B9',
  19408. '\u2F46': '\u65E0',
  19409. '\u2F47': '\u65E5',
  19410. '\u2F48': '\u66F0',
  19411. '\u2F49': '\u6708',
  19412. '\u2F4A': '\u6728',
  19413. '\u2F4B': '\u6B20',
  19414. '\u2F4C': '\u6B62',
  19415. '\u2F4D': '\u6B79',
  19416. '\u2F4E': '\u6BB3',
  19417. '\u2F4F': '\u6BCB',
  19418. '\u2F50': '\u6BD4',
  19419. '\u2F51': '\u6BDB',
  19420. '\u2F52': '\u6C0F',
  19421. '\u2F53': '\u6C14',
  19422. '\u2F54': '\u6C34',
  19423. '\u2F55': '\u706B',
  19424. '\u2F56': '\u722A',
  19425. '\u2F57': '\u7236',
  19426. '\u2F58': '\u723B',
  19427. '\u2F59': '\u723F',
  19428. '\u2F5A': '\u7247',
  19429. '\u2F5B': '\u7259',
  19430. '\u2F5C': '\u725B',
  19431. '\u2F5D': '\u72AC',
  19432. '\u2F5E': '\u7384',
  19433. '\u2F5F': '\u7389',
  19434. '\u2F60': '\u74DC',
  19435. '\u2F61': '\u74E6',
  19436. '\u2F62': '\u7518',
  19437. '\u2F63': '\u751F',
  19438. '\u2F64': '\u7528',
  19439. '\u2F65': '\u7530',
  19440. '\u2F66': '\u758B',
  19441. '\u2F67': '\u7592',
  19442. '\u2F68': '\u7676',
  19443. '\u2F69': '\u767D',
  19444. '\u2F6A': '\u76AE',
  19445. '\u2F6B': '\u76BF',
  19446. '\u2F6C': '\u76EE',
  19447. '\u2F6D': '\u77DB',
  19448. '\u2F6E': '\u77E2',
  19449. '\u2F6F': '\u77F3',
  19450. '\u2F70': '\u793A',
  19451. '\u2F71': '\u79B8',
  19452. '\u2F72': '\u79BE',
  19453. '\u2F73': '\u7A74',
  19454. '\u2F74': '\u7ACB',
  19455. '\u2F75': '\u7AF9',
  19456. '\u2F76': '\u7C73',
  19457. '\u2F77': '\u7CF8',
  19458. '\u2F78': '\u7F36',
  19459. '\u2F79': '\u7F51',
  19460. '\u2F7A': '\u7F8A',
  19461. '\u2F7B': '\u7FBD',
  19462. '\u2F7C': '\u8001',
  19463. '\u2F7D': '\u800C',
  19464. '\u2F7E': '\u8012',
  19465. '\u2F7F': '\u8033',
  19466. '\u2F80': '\u807F',
  19467. '\u2F81': '\u8089',
  19468. '\u2F82': '\u81E3',
  19469. '\u2F83': '\u81EA',
  19470. '\u2F84': '\u81F3',
  19471. '\u2F85': '\u81FC',
  19472. '\u2F86': '\u820C',
  19473. '\u2F87': '\u821B',
  19474. '\u2F88': '\u821F',
  19475. '\u2F89': '\u826E',
  19476. '\u2F8A': '\u8272',
  19477. '\u2F8B': '\u8278',
  19478. '\u2F8C': '\u864D',
  19479. '\u2F8D': '\u866B',
  19480. '\u2F8E': '\u8840',
  19481. '\u2F8F': '\u884C',
  19482. '\u2F90': '\u8863',
  19483. '\u2F91': '\u897E',
  19484. '\u2F92': '\u898B',
  19485. '\u2F93': '\u89D2',
  19486. '\u2F94': '\u8A00',
  19487. '\u2F95': '\u8C37',
  19488. '\u2F96': '\u8C46',
  19489. '\u2F97': '\u8C55',
  19490. '\u2F98': '\u8C78',
  19491. '\u2F99': '\u8C9D',
  19492. '\u2F9A': '\u8D64',
  19493. '\u2F9B': '\u8D70',
  19494. '\u2F9C': '\u8DB3',
  19495. '\u2F9D': '\u8EAB',
  19496. '\u2F9E': '\u8ECA',
  19497. '\u2F9F': '\u8F9B',
  19498. '\u2FA0': '\u8FB0',
  19499. '\u2FA1': '\u8FB5',
  19500. '\u2FA2': '\u9091',
  19501. '\u2FA3': '\u9149',
  19502. '\u2FA4': '\u91C6',
  19503. '\u2FA5': '\u91CC',
  19504. '\u2FA6': '\u91D1',
  19505. '\u2FA7': '\u9577',
  19506. '\u2FA8': '\u9580',
  19507. '\u2FA9': '\u961C',
  19508. '\u2FAA': '\u96B6',
  19509. '\u2FAB': '\u96B9',
  19510. '\u2FAC': '\u96E8',
  19511. '\u2FAD': '\u9751',
  19512. '\u2FAE': '\u975E',
  19513. '\u2FAF': '\u9762',
  19514. '\u2FB0': '\u9769',
  19515. '\u2FB1': '\u97CB',
  19516. '\u2FB2': '\u97ED',
  19517. '\u2FB3': '\u97F3',
  19518. '\u2FB4': '\u9801',
  19519. '\u2FB5': '\u98A8',
  19520. '\u2FB6': '\u98DB',
  19521. '\u2FB7': '\u98DF',
  19522. '\u2FB8': '\u9996',
  19523. '\u2FB9': '\u9999',
  19524. '\u2FBA': '\u99AC',
  19525. '\u2FBB': '\u9AA8',
  19526. '\u2FBC': '\u9AD8',
  19527. '\u2FBD': '\u9ADF',
  19528. '\u2FBE': '\u9B25',
  19529. '\u2FBF': '\u9B2F',
  19530. '\u2FC0': '\u9B32',
  19531. '\u2FC1': '\u9B3C',
  19532. '\u2FC2': '\u9B5A',
  19533. '\u2FC3': '\u9CE5',
  19534. '\u2FC4': '\u9E75',
  19535. '\u2FC5': '\u9E7F',
  19536. '\u2FC6': '\u9EA5',
  19537. '\u2FC7': '\u9EBB',
  19538. '\u2FC8': '\u9EC3',
  19539. '\u2FC9': '\u9ECD',
  19540. '\u2FCA': '\u9ED1',
  19541. '\u2FCB': '\u9EF9',
  19542. '\u2FCC': '\u9EFD',
  19543. '\u2FCD': '\u9F0E',
  19544. '\u2FCE': '\u9F13',
  19545. '\u2FCF': '\u9F20',
  19546. '\u2FD0': '\u9F3B',
  19547. '\u2FD1': '\u9F4A',
  19548. '\u2FD2': '\u9F52',
  19549. '\u2FD3': '\u9F8D',
  19550. '\u2FD4': '\u9F9C',
  19551. '\u2FD5': '\u9FA0',
  19552. '\u3036': '\u3012',
  19553. '\u3038': '\u5341',
  19554. '\u3039': '\u5344',
  19555. '\u303A': '\u5345',
  19556. '\u309B': '\u0020\u3099',
  19557. '\u309C': '\u0020\u309A',
  19558. '\u3131': '\u1100',
  19559. '\u3132': '\u1101',
  19560. '\u3133': '\u11AA',
  19561. '\u3134': '\u1102',
  19562. '\u3135': '\u11AC',
  19563. '\u3136': '\u11AD',
  19564. '\u3137': '\u1103',
  19565. '\u3138': '\u1104',
  19566. '\u3139': '\u1105',
  19567. '\u313A': '\u11B0',
  19568. '\u313B': '\u11B1',
  19569. '\u313C': '\u11B2',
  19570. '\u313D': '\u11B3',
  19571. '\u313E': '\u11B4',
  19572. '\u313F': '\u11B5',
  19573. '\u3140': '\u111A',
  19574. '\u3141': '\u1106',
  19575. '\u3142': '\u1107',
  19576. '\u3143': '\u1108',
  19577. '\u3144': '\u1121',
  19578. '\u3145': '\u1109',
  19579. '\u3146': '\u110A',
  19580. '\u3147': '\u110B',
  19581. '\u3148': '\u110C',
  19582. '\u3149': '\u110D',
  19583. '\u314A': '\u110E',
  19584. '\u314B': '\u110F',
  19585. '\u314C': '\u1110',
  19586. '\u314D': '\u1111',
  19587. '\u314E': '\u1112',
  19588. '\u314F': '\u1161',
  19589. '\u3150': '\u1162',
  19590. '\u3151': '\u1163',
  19591. '\u3152': '\u1164',
  19592. '\u3153': '\u1165',
  19593. '\u3154': '\u1166',
  19594. '\u3155': '\u1167',
  19595. '\u3156': '\u1168',
  19596. '\u3157': '\u1169',
  19597. '\u3158': '\u116A',
  19598. '\u3159': '\u116B',
  19599. '\u315A': '\u116C',
  19600. '\u315B': '\u116D',
  19601. '\u315C': '\u116E',
  19602. '\u315D': '\u116F',
  19603. '\u315E': '\u1170',
  19604. '\u315F': '\u1171',
  19605. '\u3160': '\u1172',
  19606. '\u3161': '\u1173',
  19607. '\u3162': '\u1174',
  19608. '\u3163': '\u1175',
  19609. '\u3164': '\u1160',
  19610. '\u3165': '\u1114',
  19611. '\u3166': '\u1115',
  19612. '\u3167': '\u11C7',
  19613. '\u3168': '\u11C8',
  19614. '\u3169': '\u11CC',
  19615. '\u316A': '\u11CE',
  19616. '\u316B': '\u11D3',
  19617. '\u316C': '\u11D7',
  19618. '\u316D': '\u11D9',
  19619. '\u316E': '\u111C',
  19620. '\u316F': '\u11DD',
  19621. '\u3170': '\u11DF',
  19622. '\u3171': '\u111D',
  19623. '\u3172': '\u111E',
  19624. '\u3173': '\u1120',
  19625. '\u3174': '\u1122',
  19626. '\u3175': '\u1123',
  19627. '\u3176': '\u1127',
  19628. '\u3177': '\u1129',
  19629. '\u3178': '\u112B',
  19630. '\u3179': '\u112C',
  19631. '\u317A': '\u112D',
  19632. '\u317B': '\u112E',
  19633. '\u317C': '\u112F',
  19634. '\u317D': '\u1132',
  19635. '\u317E': '\u1136',
  19636. '\u317F': '\u1140',
  19637. '\u3180': '\u1147',
  19638. '\u3181': '\u114C',
  19639. '\u3182': '\u11F1',
  19640. '\u3183': '\u11F2',
  19641. '\u3184': '\u1157',
  19642. '\u3185': '\u1158',
  19643. '\u3186': '\u1159',
  19644. '\u3187': '\u1184',
  19645. '\u3188': '\u1185',
  19646. '\u3189': '\u1188',
  19647. '\u318A': '\u1191',
  19648. '\u318B': '\u1192',
  19649. '\u318C': '\u1194',
  19650. '\u318D': '\u119E',
  19651. '\u318E': '\u11A1',
  19652. '\u3200': '\u0028\u1100\u0029',
  19653. '\u3201': '\u0028\u1102\u0029',
  19654. '\u3202': '\u0028\u1103\u0029',
  19655. '\u3203': '\u0028\u1105\u0029',
  19656. '\u3204': '\u0028\u1106\u0029',
  19657. '\u3205': '\u0028\u1107\u0029',
  19658. '\u3206': '\u0028\u1109\u0029',
  19659. '\u3207': '\u0028\u110B\u0029',
  19660. '\u3208': '\u0028\u110C\u0029',
  19661. '\u3209': '\u0028\u110E\u0029',
  19662. '\u320A': '\u0028\u110F\u0029',
  19663. '\u320B': '\u0028\u1110\u0029',
  19664. '\u320C': '\u0028\u1111\u0029',
  19665. '\u320D': '\u0028\u1112\u0029',
  19666. '\u320E': '\u0028\u1100\u1161\u0029',
  19667. '\u320F': '\u0028\u1102\u1161\u0029',
  19668. '\u3210': '\u0028\u1103\u1161\u0029',
  19669. '\u3211': '\u0028\u1105\u1161\u0029',
  19670. '\u3212': '\u0028\u1106\u1161\u0029',
  19671. '\u3213': '\u0028\u1107\u1161\u0029',
  19672. '\u3214': '\u0028\u1109\u1161\u0029',
  19673. '\u3215': '\u0028\u110B\u1161\u0029',
  19674. '\u3216': '\u0028\u110C\u1161\u0029',
  19675. '\u3217': '\u0028\u110E\u1161\u0029',
  19676. '\u3218': '\u0028\u110F\u1161\u0029',
  19677. '\u3219': '\u0028\u1110\u1161\u0029',
  19678. '\u321A': '\u0028\u1111\u1161\u0029',
  19679. '\u321B': '\u0028\u1112\u1161\u0029',
  19680. '\u321C': '\u0028\u110C\u116E\u0029',
  19681. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  19682. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  19683. '\u3220': '\u0028\u4E00\u0029',
  19684. '\u3221': '\u0028\u4E8C\u0029',
  19685. '\u3222': '\u0028\u4E09\u0029',
  19686. '\u3223': '\u0028\u56DB\u0029',
  19687. '\u3224': '\u0028\u4E94\u0029',
  19688. '\u3225': '\u0028\u516D\u0029',
  19689. '\u3226': '\u0028\u4E03\u0029',
  19690. '\u3227': '\u0028\u516B\u0029',
  19691. '\u3228': '\u0028\u4E5D\u0029',
  19692. '\u3229': '\u0028\u5341\u0029',
  19693. '\u322A': '\u0028\u6708\u0029',
  19694. '\u322B': '\u0028\u706B\u0029',
  19695. '\u322C': '\u0028\u6C34\u0029',
  19696. '\u322D': '\u0028\u6728\u0029',
  19697. '\u322E': '\u0028\u91D1\u0029',
  19698. '\u322F': '\u0028\u571F\u0029',
  19699. '\u3230': '\u0028\u65E5\u0029',
  19700. '\u3231': '\u0028\u682A\u0029',
  19701. '\u3232': '\u0028\u6709\u0029',
  19702. '\u3233': '\u0028\u793E\u0029',
  19703. '\u3234': '\u0028\u540D\u0029',
  19704. '\u3235': '\u0028\u7279\u0029',
  19705. '\u3236': '\u0028\u8CA1\u0029',
  19706. '\u3237': '\u0028\u795D\u0029',
  19707. '\u3238': '\u0028\u52B4\u0029',
  19708. '\u3239': '\u0028\u4EE3\u0029',
  19709. '\u323A': '\u0028\u547C\u0029',
  19710. '\u323B': '\u0028\u5B66\u0029',
  19711. '\u323C': '\u0028\u76E3\u0029',
  19712. '\u323D': '\u0028\u4F01\u0029',
  19713. '\u323E': '\u0028\u8CC7\u0029',
  19714. '\u323F': '\u0028\u5354\u0029',
  19715. '\u3240': '\u0028\u796D\u0029',
  19716. '\u3241': '\u0028\u4F11\u0029',
  19717. '\u3242': '\u0028\u81EA\u0029',
  19718. '\u3243': '\u0028\u81F3\u0029',
  19719. '\u32C0': '\u0031\u6708',
  19720. '\u32C1': '\u0032\u6708',
  19721. '\u32C2': '\u0033\u6708',
  19722. '\u32C3': '\u0034\u6708',
  19723. '\u32C4': '\u0035\u6708',
  19724. '\u32C5': '\u0036\u6708',
  19725. '\u32C6': '\u0037\u6708',
  19726. '\u32C7': '\u0038\u6708',
  19727. '\u32C8': '\u0039\u6708',
  19728. '\u32C9': '\u0031\u0030\u6708',
  19729. '\u32CA': '\u0031\u0031\u6708',
  19730. '\u32CB': '\u0031\u0032\u6708',
  19731. '\u3358': '\u0030\u70B9',
  19732. '\u3359': '\u0031\u70B9',
  19733. '\u335A': '\u0032\u70B9',
  19734. '\u335B': '\u0033\u70B9',
  19735. '\u335C': '\u0034\u70B9',
  19736. '\u335D': '\u0035\u70B9',
  19737. '\u335E': '\u0036\u70B9',
  19738. '\u335F': '\u0037\u70B9',
  19739. '\u3360': '\u0038\u70B9',
  19740. '\u3361': '\u0039\u70B9',
  19741. '\u3362': '\u0031\u0030\u70B9',
  19742. '\u3363': '\u0031\u0031\u70B9',
  19743. '\u3364': '\u0031\u0032\u70B9',
  19744. '\u3365': '\u0031\u0033\u70B9',
  19745. '\u3366': '\u0031\u0034\u70B9',
  19746. '\u3367': '\u0031\u0035\u70B9',
  19747. '\u3368': '\u0031\u0036\u70B9',
  19748. '\u3369': '\u0031\u0037\u70B9',
  19749. '\u336A': '\u0031\u0038\u70B9',
  19750. '\u336B': '\u0031\u0039\u70B9',
  19751. '\u336C': '\u0032\u0030\u70B9',
  19752. '\u336D': '\u0032\u0031\u70B9',
  19753. '\u336E': '\u0032\u0032\u70B9',
  19754. '\u336F': '\u0032\u0033\u70B9',
  19755. '\u3370': '\u0032\u0034\u70B9',
  19756. '\u33E0': '\u0031\u65E5',
  19757. '\u33E1': '\u0032\u65E5',
  19758. '\u33E2': '\u0033\u65E5',
  19759. '\u33E3': '\u0034\u65E5',
  19760. '\u33E4': '\u0035\u65E5',
  19761. '\u33E5': '\u0036\u65E5',
  19762. '\u33E6': '\u0037\u65E5',
  19763. '\u33E7': '\u0038\u65E5',
  19764. '\u33E8': '\u0039\u65E5',
  19765. '\u33E9': '\u0031\u0030\u65E5',
  19766. '\u33EA': '\u0031\u0031\u65E5',
  19767. '\u33EB': '\u0031\u0032\u65E5',
  19768. '\u33EC': '\u0031\u0033\u65E5',
  19769. '\u33ED': '\u0031\u0034\u65E5',
  19770. '\u33EE': '\u0031\u0035\u65E5',
  19771. '\u33EF': '\u0031\u0036\u65E5',
  19772. '\u33F0': '\u0031\u0037\u65E5',
  19773. '\u33F1': '\u0031\u0038\u65E5',
  19774. '\u33F2': '\u0031\u0039\u65E5',
  19775. '\u33F3': '\u0032\u0030\u65E5',
  19776. '\u33F4': '\u0032\u0031\u65E5',
  19777. '\u33F5': '\u0032\u0032\u65E5',
  19778. '\u33F6': '\u0032\u0033\u65E5',
  19779. '\u33F7': '\u0032\u0034\u65E5',
  19780. '\u33F8': '\u0032\u0035\u65E5',
  19781. '\u33F9': '\u0032\u0036\u65E5',
  19782. '\u33FA': '\u0032\u0037\u65E5',
  19783. '\u33FB': '\u0032\u0038\u65E5',
  19784. '\u33FC': '\u0032\u0039\u65E5',
  19785. '\u33FD': '\u0033\u0030\u65E5',
  19786. '\u33FE': '\u0033\u0031\u65E5',
  19787. '\uFB00': '\u0066\u0066',
  19788. '\uFB01': '\u0066\u0069',
  19789. '\uFB02': '\u0066\u006C',
  19790. '\uFB03': '\u0066\u0066\u0069',
  19791. '\uFB04': '\u0066\u0066\u006C',
  19792. '\uFB05': '\u017F\u0074',
  19793. '\uFB06': '\u0073\u0074',
  19794. '\uFB13': '\u0574\u0576',
  19795. '\uFB14': '\u0574\u0565',
  19796. '\uFB15': '\u0574\u056B',
  19797. '\uFB16': '\u057E\u0576',
  19798. '\uFB17': '\u0574\u056D',
  19799. '\uFB4F': '\u05D0\u05DC',
  19800. '\uFB50': '\u0671',
  19801. '\uFB51': '\u0671',
  19802. '\uFB52': '\u067B',
  19803. '\uFB53': '\u067B',
  19804. '\uFB54': '\u067B',
  19805. '\uFB55': '\u067B',
  19806. '\uFB56': '\u067E',
  19807. '\uFB57': '\u067E',
  19808. '\uFB58': '\u067E',
  19809. '\uFB59': '\u067E',
  19810. '\uFB5A': '\u0680',
  19811. '\uFB5B': '\u0680',
  19812. '\uFB5C': '\u0680',
  19813. '\uFB5D': '\u0680',
  19814. '\uFB5E': '\u067A',
  19815. '\uFB5F': '\u067A',
  19816. '\uFB60': '\u067A',
  19817. '\uFB61': '\u067A',
  19818. '\uFB62': '\u067F',
  19819. '\uFB63': '\u067F',
  19820. '\uFB64': '\u067F',
  19821. '\uFB65': '\u067F',
  19822. '\uFB66': '\u0679',
  19823. '\uFB67': '\u0679',
  19824. '\uFB68': '\u0679',
  19825. '\uFB69': '\u0679',
  19826. '\uFB6A': '\u06A4',
  19827. '\uFB6B': '\u06A4',
  19828. '\uFB6C': '\u06A4',
  19829. '\uFB6D': '\u06A4',
  19830. '\uFB6E': '\u06A6',
  19831. '\uFB6F': '\u06A6',
  19832. '\uFB70': '\u06A6',
  19833. '\uFB71': '\u06A6',
  19834. '\uFB72': '\u0684',
  19835. '\uFB73': '\u0684',
  19836. '\uFB74': '\u0684',
  19837. '\uFB75': '\u0684',
  19838. '\uFB76': '\u0683',
  19839. '\uFB77': '\u0683',
  19840. '\uFB78': '\u0683',
  19841. '\uFB79': '\u0683',
  19842. '\uFB7A': '\u0686',
  19843. '\uFB7B': '\u0686',
  19844. '\uFB7C': '\u0686',
  19845. '\uFB7D': '\u0686',
  19846. '\uFB7E': '\u0687',
  19847. '\uFB7F': '\u0687',
  19848. '\uFB80': '\u0687',
  19849. '\uFB81': '\u0687',
  19850. '\uFB82': '\u068D',
  19851. '\uFB83': '\u068D',
  19852. '\uFB84': '\u068C',
  19853. '\uFB85': '\u068C',
  19854. '\uFB86': '\u068E',
  19855. '\uFB87': '\u068E',
  19856. '\uFB88': '\u0688',
  19857. '\uFB89': '\u0688',
  19858. '\uFB8A': '\u0698',
  19859. '\uFB8B': '\u0698',
  19860. '\uFB8C': '\u0691',
  19861. '\uFB8D': '\u0691',
  19862. '\uFB8E': '\u06A9',
  19863. '\uFB8F': '\u06A9',
  19864. '\uFB90': '\u06A9',
  19865. '\uFB91': '\u06A9',
  19866. '\uFB92': '\u06AF',
  19867. '\uFB93': '\u06AF',
  19868. '\uFB94': '\u06AF',
  19869. '\uFB95': '\u06AF',
  19870. '\uFB96': '\u06B3',
  19871. '\uFB97': '\u06B3',
  19872. '\uFB98': '\u06B3',
  19873. '\uFB99': '\u06B3',
  19874. '\uFB9A': '\u06B1',
  19875. '\uFB9B': '\u06B1',
  19876. '\uFB9C': '\u06B1',
  19877. '\uFB9D': '\u06B1',
  19878. '\uFB9E': '\u06BA',
  19879. '\uFB9F': '\u06BA',
  19880. '\uFBA0': '\u06BB',
  19881. '\uFBA1': '\u06BB',
  19882. '\uFBA2': '\u06BB',
  19883. '\uFBA3': '\u06BB',
  19884. '\uFBA4': '\u06C0',
  19885. '\uFBA5': '\u06C0',
  19886. '\uFBA6': '\u06C1',
  19887. '\uFBA7': '\u06C1',
  19888. '\uFBA8': '\u06C1',
  19889. '\uFBA9': '\u06C1',
  19890. '\uFBAA': '\u06BE',
  19891. '\uFBAB': '\u06BE',
  19892. '\uFBAC': '\u06BE',
  19893. '\uFBAD': '\u06BE',
  19894. '\uFBAE': '\u06D2',
  19895. '\uFBAF': '\u06D2',
  19896. '\uFBB0': '\u06D3',
  19897. '\uFBB1': '\u06D3',
  19898. '\uFBD3': '\u06AD',
  19899. '\uFBD4': '\u06AD',
  19900. '\uFBD5': '\u06AD',
  19901. '\uFBD6': '\u06AD',
  19902. '\uFBD7': '\u06C7',
  19903. '\uFBD8': '\u06C7',
  19904. '\uFBD9': '\u06C6',
  19905. '\uFBDA': '\u06C6',
  19906. '\uFBDB': '\u06C8',
  19907. '\uFBDC': '\u06C8',
  19908. '\uFBDD': '\u0677',
  19909. '\uFBDE': '\u06CB',
  19910. '\uFBDF': '\u06CB',
  19911. '\uFBE0': '\u06C5',
  19912. '\uFBE1': '\u06C5',
  19913. '\uFBE2': '\u06C9',
  19914. '\uFBE3': '\u06C9',
  19915. '\uFBE4': '\u06D0',
  19916. '\uFBE5': '\u06D0',
  19917. '\uFBE6': '\u06D0',
  19918. '\uFBE7': '\u06D0',
  19919. '\uFBE8': '\u0649',
  19920. '\uFBE9': '\u0649',
  19921. '\uFBEA': '\u0626\u0627',
  19922. '\uFBEB': '\u0626\u0627',
  19923. '\uFBEC': '\u0626\u06D5',
  19924. '\uFBED': '\u0626\u06D5',
  19925. '\uFBEE': '\u0626\u0648',
  19926. '\uFBEF': '\u0626\u0648',
  19927. '\uFBF0': '\u0626\u06C7',
  19928. '\uFBF1': '\u0626\u06C7',
  19929. '\uFBF2': '\u0626\u06C6',
  19930. '\uFBF3': '\u0626\u06C6',
  19931. '\uFBF4': '\u0626\u06C8',
  19932. '\uFBF5': '\u0626\u06C8',
  19933. '\uFBF6': '\u0626\u06D0',
  19934. '\uFBF7': '\u0626\u06D0',
  19935. '\uFBF8': '\u0626\u06D0',
  19936. '\uFBF9': '\u0626\u0649',
  19937. '\uFBFA': '\u0626\u0649',
  19938. '\uFBFB': '\u0626\u0649',
  19939. '\uFBFC': '\u06CC',
  19940. '\uFBFD': '\u06CC',
  19941. '\uFBFE': '\u06CC',
  19942. '\uFBFF': '\u06CC',
  19943. '\uFC00': '\u0626\u062C',
  19944. '\uFC01': '\u0626\u062D',
  19945. '\uFC02': '\u0626\u0645',
  19946. '\uFC03': '\u0626\u0649',
  19947. '\uFC04': '\u0626\u064A',
  19948. '\uFC05': '\u0628\u062C',
  19949. '\uFC06': '\u0628\u062D',
  19950. '\uFC07': '\u0628\u062E',
  19951. '\uFC08': '\u0628\u0645',
  19952. '\uFC09': '\u0628\u0649',
  19953. '\uFC0A': '\u0628\u064A',
  19954. '\uFC0B': '\u062A\u062C',
  19955. '\uFC0C': '\u062A\u062D',
  19956. '\uFC0D': '\u062A\u062E',
  19957. '\uFC0E': '\u062A\u0645',
  19958. '\uFC0F': '\u062A\u0649',
  19959. '\uFC10': '\u062A\u064A',
  19960. '\uFC11': '\u062B\u062C',
  19961. '\uFC12': '\u062B\u0645',
  19962. '\uFC13': '\u062B\u0649',
  19963. '\uFC14': '\u062B\u064A',
  19964. '\uFC15': '\u062C\u062D',
  19965. '\uFC16': '\u062C\u0645',
  19966. '\uFC17': '\u062D\u062C',
  19967. '\uFC18': '\u062D\u0645',
  19968. '\uFC19': '\u062E\u062C',
  19969. '\uFC1A': '\u062E\u062D',
  19970. '\uFC1B': '\u062E\u0645',
  19971. '\uFC1C': '\u0633\u062C',
  19972. '\uFC1D': '\u0633\u062D',
  19973. '\uFC1E': '\u0633\u062E',
  19974. '\uFC1F': '\u0633\u0645',
  19975. '\uFC20': '\u0635\u062D',
  19976. '\uFC21': '\u0635\u0645',
  19977. '\uFC22': '\u0636\u062C',
  19978. '\uFC23': '\u0636\u062D',
  19979. '\uFC24': '\u0636\u062E',
  19980. '\uFC25': '\u0636\u0645',
  19981. '\uFC26': '\u0637\u062D',
  19982. '\uFC27': '\u0637\u0645',
  19983. '\uFC28': '\u0638\u0645',
  19984. '\uFC29': '\u0639\u062C',
  19985. '\uFC2A': '\u0639\u0645',
  19986. '\uFC2B': '\u063A\u062C',
  19987. '\uFC2C': '\u063A\u0645',
  19988. '\uFC2D': '\u0641\u062C',
  19989. '\uFC2E': '\u0641\u062D',
  19990. '\uFC2F': '\u0641\u062E',
  19991. '\uFC30': '\u0641\u0645',
  19992. '\uFC31': '\u0641\u0649',
  19993. '\uFC32': '\u0641\u064A',
  19994. '\uFC33': '\u0642\u062D',
  19995. '\uFC34': '\u0642\u0645',
  19996. '\uFC35': '\u0642\u0649',
  19997. '\uFC36': '\u0642\u064A',
  19998. '\uFC37': '\u0643\u0627',
  19999. '\uFC38': '\u0643\u062C',
  20000. '\uFC39': '\u0643\u062D',
  20001. '\uFC3A': '\u0643\u062E',
  20002. '\uFC3B': '\u0643\u0644',
  20003. '\uFC3C': '\u0643\u0645',
  20004. '\uFC3D': '\u0643\u0649',
  20005. '\uFC3E': '\u0643\u064A',
  20006. '\uFC3F': '\u0644\u062C',
  20007. '\uFC40': '\u0644\u062D',
  20008. '\uFC41': '\u0644\u062E',
  20009. '\uFC42': '\u0644\u0645',
  20010. '\uFC43': '\u0644\u0649',
  20011. '\uFC44': '\u0644\u064A',
  20012. '\uFC45': '\u0645\u062C',
  20013. '\uFC46': '\u0645\u062D',
  20014. '\uFC47': '\u0645\u062E',
  20015. '\uFC48': '\u0645\u0645',
  20016. '\uFC49': '\u0645\u0649',
  20017. '\uFC4A': '\u0645\u064A',
  20018. '\uFC4B': '\u0646\u062C',
  20019. '\uFC4C': '\u0646\u062D',
  20020. '\uFC4D': '\u0646\u062E',
  20021. '\uFC4E': '\u0646\u0645',
  20022. '\uFC4F': '\u0646\u0649',
  20023. '\uFC50': '\u0646\u064A',
  20024. '\uFC51': '\u0647\u062C',
  20025. '\uFC52': '\u0647\u0645',
  20026. '\uFC53': '\u0647\u0649',
  20027. '\uFC54': '\u0647\u064A',
  20028. '\uFC55': '\u064A\u062C',
  20029. '\uFC56': '\u064A\u062D',
  20030. '\uFC57': '\u064A\u062E',
  20031. '\uFC58': '\u064A\u0645',
  20032. '\uFC59': '\u064A\u0649',
  20033. '\uFC5A': '\u064A\u064A',
  20034. '\uFC5B': '\u0630\u0670',
  20035. '\uFC5C': '\u0631\u0670',
  20036. '\uFC5D': '\u0649\u0670',
  20037. '\uFC5E': '\u0020\u064C\u0651',
  20038. '\uFC5F': '\u0020\u064D\u0651',
  20039. '\uFC60': '\u0020\u064E\u0651',
  20040. '\uFC61': '\u0020\u064F\u0651',
  20041. '\uFC62': '\u0020\u0650\u0651',
  20042. '\uFC63': '\u0020\u0651\u0670',
  20043. '\uFC64': '\u0626\u0631',
  20044. '\uFC65': '\u0626\u0632',
  20045. '\uFC66': '\u0626\u0645',
  20046. '\uFC67': '\u0626\u0646',
  20047. '\uFC68': '\u0626\u0649',
  20048. '\uFC69': '\u0626\u064A',
  20049. '\uFC6A': '\u0628\u0631',
  20050. '\uFC6B': '\u0628\u0632',
  20051. '\uFC6C': '\u0628\u0645',
  20052. '\uFC6D': '\u0628\u0646',
  20053. '\uFC6E': '\u0628\u0649',
  20054. '\uFC6F': '\u0628\u064A',
  20055. '\uFC70': '\u062A\u0631',
  20056. '\uFC71': '\u062A\u0632',
  20057. '\uFC72': '\u062A\u0645',
  20058. '\uFC73': '\u062A\u0646',
  20059. '\uFC74': '\u062A\u0649',
  20060. '\uFC75': '\u062A\u064A',
  20061. '\uFC76': '\u062B\u0631',
  20062. '\uFC77': '\u062B\u0632',
  20063. '\uFC78': '\u062B\u0645',
  20064. '\uFC79': '\u062B\u0646',
  20065. '\uFC7A': '\u062B\u0649',
  20066. '\uFC7B': '\u062B\u064A',
  20067. '\uFC7C': '\u0641\u0649',
  20068. '\uFC7D': '\u0641\u064A',
  20069. '\uFC7E': '\u0642\u0649',
  20070. '\uFC7F': '\u0642\u064A',
  20071. '\uFC80': '\u0643\u0627',
  20072. '\uFC81': '\u0643\u0644',
  20073. '\uFC82': '\u0643\u0645',
  20074. '\uFC83': '\u0643\u0649',
  20075. '\uFC84': '\u0643\u064A',
  20076. '\uFC85': '\u0644\u0645',
  20077. '\uFC86': '\u0644\u0649',
  20078. '\uFC87': '\u0644\u064A',
  20079. '\uFC88': '\u0645\u0627',
  20080. '\uFC89': '\u0645\u0645',
  20081. '\uFC8A': '\u0646\u0631',
  20082. '\uFC8B': '\u0646\u0632',
  20083. '\uFC8C': '\u0646\u0645',
  20084. '\uFC8D': '\u0646\u0646',
  20085. '\uFC8E': '\u0646\u0649',
  20086. '\uFC8F': '\u0646\u064A',
  20087. '\uFC90': '\u0649\u0670',
  20088. '\uFC91': '\u064A\u0631',
  20089. '\uFC92': '\u064A\u0632',
  20090. '\uFC93': '\u064A\u0645',
  20091. '\uFC94': '\u064A\u0646',
  20092. '\uFC95': '\u064A\u0649',
  20093. '\uFC96': '\u064A\u064A',
  20094. '\uFC97': '\u0626\u062C',
  20095. '\uFC98': '\u0626\u062D',
  20096. '\uFC99': '\u0626\u062E',
  20097. '\uFC9A': '\u0626\u0645',
  20098. '\uFC9B': '\u0626\u0647',
  20099. '\uFC9C': '\u0628\u062C',
  20100. '\uFC9D': '\u0628\u062D',
  20101. '\uFC9E': '\u0628\u062E',
  20102. '\uFC9F': '\u0628\u0645',
  20103. '\uFCA0': '\u0628\u0647',
  20104. '\uFCA1': '\u062A\u062C',
  20105. '\uFCA2': '\u062A\u062D',
  20106. '\uFCA3': '\u062A\u062E',
  20107. '\uFCA4': '\u062A\u0645',
  20108. '\uFCA5': '\u062A\u0647',
  20109. '\uFCA6': '\u062B\u0645',
  20110. '\uFCA7': '\u062C\u062D',
  20111. '\uFCA8': '\u062C\u0645',
  20112. '\uFCA9': '\u062D\u062C',
  20113. '\uFCAA': '\u062D\u0645',
  20114. '\uFCAB': '\u062E\u062C',
  20115. '\uFCAC': '\u062E\u0645',
  20116. '\uFCAD': '\u0633\u062C',
  20117. '\uFCAE': '\u0633\u062D',
  20118. '\uFCAF': '\u0633\u062E',
  20119. '\uFCB0': '\u0633\u0645',
  20120. '\uFCB1': '\u0635\u062D',
  20121. '\uFCB2': '\u0635\u062E',
  20122. '\uFCB3': '\u0635\u0645',
  20123. '\uFCB4': '\u0636\u062C',
  20124. '\uFCB5': '\u0636\u062D',
  20125. '\uFCB6': '\u0636\u062E',
  20126. '\uFCB7': '\u0636\u0645',
  20127. '\uFCB8': '\u0637\u062D',
  20128. '\uFCB9': '\u0638\u0645',
  20129. '\uFCBA': '\u0639\u062C',
  20130. '\uFCBB': '\u0639\u0645',
  20131. '\uFCBC': '\u063A\u062C',
  20132. '\uFCBD': '\u063A\u0645',
  20133. '\uFCBE': '\u0641\u062C',
  20134. '\uFCBF': '\u0641\u062D',
  20135. '\uFCC0': '\u0641\u062E',
  20136. '\uFCC1': '\u0641\u0645',
  20137. '\uFCC2': '\u0642\u062D',
  20138. '\uFCC3': '\u0642\u0645',
  20139. '\uFCC4': '\u0643\u062C',
  20140. '\uFCC5': '\u0643\u062D',
  20141. '\uFCC6': '\u0643\u062E',
  20142. '\uFCC7': '\u0643\u0644',
  20143. '\uFCC8': '\u0643\u0645',
  20144. '\uFCC9': '\u0644\u062C',
  20145. '\uFCCA': '\u0644\u062D',
  20146. '\uFCCB': '\u0644\u062E',
  20147. '\uFCCC': '\u0644\u0645',
  20148. '\uFCCD': '\u0644\u0647',
  20149. '\uFCCE': '\u0645\u062C',
  20150. '\uFCCF': '\u0645\u062D',
  20151. '\uFCD0': '\u0645\u062E',
  20152. '\uFCD1': '\u0645\u0645',
  20153. '\uFCD2': '\u0646\u062C',
  20154. '\uFCD3': '\u0646\u062D',
  20155. '\uFCD4': '\u0646\u062E',
  20156. '\uFCD5': '\u0646\u0645',
  20157. '\uFCD6': '\u0646\u0647',
  20158. '\uFCD7': '\u0647\u062C',
  20159. '\uFCD8': '\u0647\u0645',
  20160. '\uFCD9': '\u0647\u0670',
  20161. '\uFCDA': '\u064A\u062C',
  20162. '\uFCDB': '\u064A\u062D',
  20163. '\uFCDC': '\u064A\u062E',
  20164. '\uFCDD': '\u064A\u0645',
  20165. '\uFCDE': '\u064A\u0647',
  20166. '\uFCDF': '\u0626\u0645',
  20167. '\uFCE0': '\u0626\u0647',
  20168. '\uFCE1': '\u0628\u0645',
  20169. '\uFCE2': '\u0628\u0647',
  20170. '\uFCE3': '\u062A\u0645',
  20171. '\uFCE4': '\u062A\u0647',
  20172. '\uFCE5': '\u062B\u0645',
  20173. '\uFCE6': '\u062B\u0647',
  20174. '\uFCE7': '\u0633\u0645',
  20175. '\uFCE8': '\u0633\u0647',
  20176. '\uFCE9': '\u0634\u0645',
  20177. '\uFCEA': '\u0634\u0647',
  20178. '\uFCEB': '\u0643\u0644',
  20179. '\uFCEC': '\u0643\u0645',
  20180. '\uFCED': '\u0644\u0645',
  20181. '\uFCEE': '\u0646\u0645',
  20182. '\uFCEF': '\u0646\u0647',
  20183. '\uFCF0': '\u064A\u0645',
  20184. '\uFCF1': '\u064A\u0647',
  20185. '\uFCF2': '\u0640\u064E\u0651',
  20186. '\uFCF3': '\u0640\u064F\u0651',
  20187. '\uFCF4': '\u0640\u0650\u0651',
  20188. '\uFCF5': '\u0637\u0649',
  20189. '\uFCF6': '\u0637\u064A',
  20190. '\uFCF7': '\u0639\u0649',
  20191. '\uFCF8': '\u0639\u064A',
  20192. '\uFCF9': '\u063A\u0649',
  20193. '\uFCFA': '\u063A\u064A',
  20194. '\uFCFB': '\u0633\u0649',
  20195. '\uFCFC': '\u0633\u064A',
  20196. '\uFCFD': '\u0634\u0649',
  20197. '\uFCFE': '\u0634\u064A',
  20198. '\uFCFF': '\u062D\u0649',
  20199. '\uFD00': '\u062D\u064A',
  20200. '\uFD01': '\u062C\u0649',
  20201. '\uFD02': '\u062C\u064A',
  20202. '\uFD03': '\u062E\u0649',
  20203. '\uFD04': '\u062E\u064A',
  20204. '\uFD05': '\u0635\u0649',
  20205. '\uFD06': '\u0635\u064A',
  20206. '\uFD07': '\u0636\u0649',
  20207. '\uFD08': '\u0636\u064A',
  20208. '\uFD09': '\u0634\u062C',
  20209. '\uFD0A': '\u0634\u062D',
  20210. '\uFD0B': '\u0634\u062E',
  20211. '\uFD0C': '\u0634\u0645',
  20212. '\uFD0D': '\u0634\u0631',
  20213. '\uFD0E': '\u0633\u0631',
  20214. '\uFD0F': '\u0635\u0631',
  20215. '\uFD10': '\u0636\u0631',
  20216. '\uFD11': '\u0637\u0649',
  20217. '\uFD12': '\u0637\u064A',
  20218. '\uFD13': '\u0639\u0649',
  20219. '\uFD14': '\u0639\u064A',
  20220. '\uFD15': '\u063A\u0649',
  20221. '\uFD16': '\u063A\u064A',
  20222. '\uFD17': '\u0633\u0649',
  20223. '\uFD18': '\u0633\u064A',
  20224. '\uFD19': '\u0634\u0649',
  20225. '\uFD1A': '\u0634\u064A',
  20226. '\uFD1B': '\u062D\u0649',
  20227. '\uFD1C': '\u062D\u064A',
  20228. '\uFD1D': '\u062C\u0649',
  20229. '\uFD1E': '\u062C\u064A',
  20230. '\uFD1F': '\u062E\u0649',
  20231. '\uFD20': '\u062E\u064A',
  20232. '\uFD21': '\u0635\u0649',
  20233. '\uFD22': '\u0635\u064A',
  20234. '\uFD23': '\u0636\u0649',
  20235. '\uFD24': '\u0636\u064A',
  20236. '\uFD25': '\u0634\u062C',
  20237. '\uFD26': '\u0634\u062D',
  20238. '\uFD27': '\u0634\u062E',
  20239. '\uFD28': '\u0634\u0645',
  20240. '\uFD29': '\u0634\u0631',
  20241. '\uFD2A': '\u0633\u0631',
  20242. '\uFD2B': '\u0635\u0631',
  20243. '\uFD2C': '\u0636\u0631',
  20244. '\uFD2D': '\u0634\u062C',
  20245. '\uFD2E': '\u0634\u062D',
  20246. '\uFD2F': '\u0634\u062E',
  20247. '\uFD30': '\u0634\u0645',
  20248. '\uFD31': '\u0633\u0647',
  20249. '\uFD32': '\u0634\u0647',
  20250. '\uFD33': '\u0637\u0645',
  20251. '\uFD34': '\u0633\u062C',
  20252. '\uFD35': '\u0633\u062D',
  20253. '\uFD36': '\u0633\u062E',
  20254. '\uFD37': '\u0634\u062C',
  20255. '\uFD38': '\u0634\u062D',
  20256. '\uFD39': '\u0634\u062E',
  20257. '\uFD3A': '\u0637\u0645',
  20258. '\uFD3B': '\u0638\u0645',
  20259. '\uFD3C': '\u0627\u064B',
  20260. '\uFD3D': '\u0627\u064B',
  20261. '\uFD50': '\u062A\u062C\u0645',
  20262. '\uFD51': '\u062A\u062D\u062C',
  20263. '\uFD52': '\u062A\u062D\u062C',
  20264. '\uFD53': '\u062A\u062D\u0645',
  20265. '\uFD54': '\u062A\u062E\u0645',
  20266. '\uFD55': '\u062A\u0645\u062C',
  20267. '\uFD56': '\u062A\u0645\u062D',
  20268. '\uFD57': '\u062A\u0645\u062E',
  20269. '\uFD58': '\u062C\u0645\u062D',
  20270. '\uFD59': '\u062C\u0645\u062D',
  20271. '\uFD5A': '\u062D\u0645\u064A',
  20272. '\uFD5B': '\u062D\u0645\u0649',
  20273. '\uFD5C': '\u0633\u062D\u062C',
  20274. '\uFD5D': '\u0633\u062C\u062D',
  20275. '\uFD5E': '\u0633\u062C\u0649',
  20276. '\uFD5F': '\u0633\u0645\u062D',
  20277. '\uFD60': '\u0633\u0645\u062D',
  20278. '\uFD61': '\u0633\u0645\u062C',
  20279. '\uFD62': '\u0633\u0645\u0645',
  20280. '\uFD63': '\u0633\u0645\u0645',
  20281. '\uFD64': '\u0635\u062D\u062D',
  20282. '\uFD65': '\u0635\u062D\u062D',
  20283. '\uFD66': '\u0635\u0645\u0645',
  20284. '\uFD67': '\u0634\u062D\u0645',
  20285. '\uFD68': '\u0634\u062D\u0645',
  20286. '\uFD69': '\u0634\u062C\u064A',
  20287. '\uFD6A': '\u0634\u0645\u062E',
  20288. '\uFD6B': '\u0634\u0645\u062E',
  20289. '\uFD6C': '\u0634\u0645\u0645',
  20290. '\uFD6D': '\u0634\u0645\u0645',
  20291. '\uFD6E': '\u0636\u062D\u0649',
  20292. '\uFD6F': '\u0636\u062E\u0645',
  20293. '\uFD70': '\u0636\u062E\u0645',
  20294. '\uFD71': '\u0637\u0645\u062D',
  20295. '\uFD72': '\u0637\u0645\u062D',
  20296. '\uFD73': '\u0637\u0645\u0645',
  20297. '\uFD74': '\u0637\u0645\u064A',
  20298. '\uFD75': '\u0639\u062C\u0645',
  20299. '\uFD76': '\u0639\u0645\u0645',
  20300. '\uFD77': '\u0639\u0645\u0645',
  20301. '\uFD78': '\u0639\u0645\u0649',
  20302. '\uFD79': '\u063A\u0645\u0645',
  20303. '\uFD7A': '\u063A\u0645\u064A',
  20304. '\uFD7B': '\u063A\u0645\u0649',
  20305. '\uFD7C': '\u0641\u062E\u0645',
  20306. '\uFD7D': '\u0641\u062E\u0645',
  20307. '\uFD7E': '\u0642\u0645\u062D',
  20308. '\uFD7F': '\u0642\u0645\u0645',
  20309. '\uFD80': '\u0644\u062D\u0645',
  20310. '\uFD81': '\u0644\u062D\u064A',
  20311. '\uFD82': '\u0644\u062D\u0649',
  20312. '\uFD83': '\u0644\u062C\u062C',
  20313. '\uFD84': '\u0644\u062C\u062C',
  20314. '\uFD85': '\u0644\u062E\u0645',
  20315. '\uFD86': '\u0644\u062E\u0645',
  20316. '\uFD87': '\u0644\u0645\u062D',
  20317. '\uFD88': '\u0644\u0645\u062D',
  20318. '\uFD89': '\u0645\u062D\u062C',
  20319. '\uFD8A': '\u0645\u062D\u0645',
  20320. '\uFD8B': '\u0645\u062D\u064A',
  20321. '\uFD8C': '\u0645\u062C\u062D',
  20322. '\uFD8D': '\u0645\u062C\u0645',
  20323. '\uFD8E': '\u0645\u062E\u062C',
  20324. '\uFD8F': '\u0645\u062E\u0645',
  20325. '\uFD92': '\u0645\u062C\u062E',
  20326. '\uFD93': '\u0647\u0645\u062C',
  20327. '\uFD94': '\u0647\u0645\u0645',
  20328. '\uFD95': '\u0646\u062D\u0645',
  20329. '\uFD96': '\u0646\u062D\u0649',
  20330. '\uFD97': '\u0646\u062C\u0645',
  20331. '\uFD98': '\u0646\u062C\u0645',
  20332. '\uFD99': '\u0646\u062C\u0649',
  20333. '\uFD9A': '\u0646\u0645\u064A',
  20334. '\uFD9B': '\u0646\u0645\u0649',
  20335. '\uFD9C': '\u064A\u0645\u0645',
  20336. '\uFD9D': '\u064A\u0645\u0645',
  20337. '\uFD9E': '\u0628\u062E\u064A',
  20338. '\uFD9F': '\u062A\u062C\u064A',
  20339. '\uFDA0': '\u062A\u062C\u0649',
  20340. '\uFDA1': '\u062A\u062E\u064A',
  20341. '\uFDA2': '\u062A\u062E\u0649',
  20342. '\uFDA3': '\u062A\u0645\u064A',
  20343. '\uFDA4': '\u062A\u0645\u0649',
  20344. '\uFDA5': '\u062C\u0645\u064A',
  20345. '\uFDA6': '\u062C\u062D\u0649',
  20346. '\uFDA7': '\u062C\u0645\u0649',
  20347. '\uFDA8': '\u0633\u062E\u0649',
  20348. '\uFDA9': '\u0635\u062D\u064A',
  20349. '\uFDAA': '\u0634\u062D\u064A',
  20350. '\uFDAB': '\u0636\u062D\u064A',
  20351. '\uFDAC': '\u0644\u062C\u064A',
  20352. '\uFDAD': '\u0644\u0645\u064A',
  20353. '\uFDAE': '\u064A\u062D\u064A',
  20354. '\uFDAF': '\u064A\u062C\u064A',
  20355. '\uFDB0': '\u064A\u0645\u064A',
  20356. '\uFDB1': '\u0645\u0645\u064A',
  20357. '\uFDB2': '\u0642\u0645\u064A',
  20358. '\uFDB3': '\u0646\u062D\u064A',
  20359. '\uFDB4': '\u0642\u0645\u062D',
  20360. '\uFDB5': '\u0644\u062D\u0645',
  20361. '\uFDB6': '\u0639\u0645\u064A',
  20362. '\uFDB7': '\u0643\u0645\u064A',
  20363. '\uFDB8': '\u0646\u062C\u062D',
  20364. '\uFDB9': '\u0645\u062E\u064A',
  20365. '\uFDBA': '\u0644\u062C\u0645',
  20366. '\uFDBB': '\u0643\u0645\u0645',
  20367. '\uFDBC': '\u0644\u062C\u0645',
  20368. '\uFDBD': '\u0646\u062C\u062D',
  20369. '\uFDBE': '\u062C\u062D\u064A',
  20370. '\uFDBF': '\u062D\u062C\u064A',
  20371. '\uFDC0': '\u0645\u062C\u064A',
  20372. '\uFDC1': '\u0641\u0645\u064A',
  20373. '\uFDC2': '\u0628\u062D\u064A',
  20374. '\uFDC3': '\u0643\u0645\u0645',
  20375. '\uFDC4': '\u0639\u062C\u0645',
  20376. '\uFDC5': '\u0635\u0645\u0645',
  20377. '\uFDC6': '\u0633\u062E\u064A',
  20378. '\uFDC7': '\u0646\u062C\u064A',
  20379. '\uFE49': '\u203E',
  20380. '\uFE4A': '\u203E',
  20381. '\uFE4B': '\u203E',
  20382. '\uFE4C': '\u203E',
  20383. '\uFE4D': '\u005F',
  20384. '\uFE4E': '\u005F',
  20385. '\uFE4F': '\u005F',
  20386. '\uFE80': '\u0621',
  20387. '\uFE81': '\u0622',
  20388. '\uFE82': '\u0622',
  20389. '\uFE83': '\u0623',
  20390. '\uFE84': '\u0623',
  20391. '\uFE85': '\u0624',
  20392. '\uFE86': '\u0624',
  20393. '\uFE87': '\u0625',
  20394. '\uFE88': '\u0625',
  20395. '\uFE89': '\u0626',
  20396. '\uFE8A': '\u0626',
  20397. '\uFE8B': '\u0626',
  20398. '\uFE8C': '\u0626',
  20399. '\uFE8D': '\u0627',
  20400. '\uFE8E': '\u0627',
  20401. '\uFE8F': '\u0628',
  20402. '\uFE90': '\u0628',
  20403. '\uFE91': '\u0628',
  20404. '\uFE92': '\u0628',
  20405. '\uFE93': '\u0629',
  20406. '\uFE94': '\u0629',
  20407. '\uFE95': '\u062A',
  20408. '\uFE96': '\u062A',
  20409. '\uFE97': '\u062A',
  20410. '\uFE98': '\u062A',
  20411. '\uFE99': '\u062B',
  20412. '\uFE9A': '\u062B',
  20413. '\uFE9B': '\u062B',
  20414. '\uFE9C': '\u062B',
  20415. '\uFE9D': '\u062C',
  20416. '\uFE9E': '\u062C',
  20417. '\uFE9F': '\u062C',
  20418. '\uFEA0': '\u062C',
  20419. '\uFEA1': '\u062D',
  20420. '\uFEA2': '\u062D',
  20421. '\uFEA3': '\u062D',
  20422. '\uFEA4': '\u062D',
  20423. '\uFEA5': '\u062E',
  20424. '\uFEA6': '\u062E',
  20425. '\uFEA7': '\u062E',
  20426. '\uFEA8': '\u062E',
  20427. '\uFEA9': '\u062F',
  20428. '\uFEAA': '\u062F',
  20429. '\uFEAB': '\u0630',
  20430. '\uFEAC': '\u0630',
  20431. '\uFEAD': '\u0631',
  20432. '\uFEAE': '\u0631',
  20433. '\uFEAF': '\u0632',
  20434. '\uFEB0': '\u0632',
  20435. '\uFEB1': '\u0633',
  20436. '\uFEB2': '\u0633',
  20437. '\uFEB3': '\u0633',
  20438. '\uFEB4': '\u0633',
  20439. '\uFEB5': '\u0634',
  20440. '\uFEB6': '\u0634',
  20441. '\uFEB7': '\u0634',
  20442. '\uFEB8': '\u0634',
  20443. '\uFEB9': '\u0635',
  20444. '\uFEBA': '\u0635',
  20445. '\uFEBB': '\u0635',
  20446. '\uFEBC': '\u0635',
  20447. '\uFEBD': '\u0636',
  20448. '\uFEBE': '\u0636',
  20449. '\uFEBF': '\u0636',
  20450. '\uFEC0': '\u0636',
  20451. '\uFEC1': '\u0637',
  20452. '\uFEC2': '\u0637',
  20453. '\uFEC3': '\u0637',
  20454. '\uFEC4': '\u0637',
  20455. '\uFEC5': '\u0638',
  20456. '\uFEC6': '\u0638',
  20457. '\uFEC7': '\u0638',
  20458. '\uFEC8': '\u0638',
  20459. '\uFEC9': '\u0639',
  20460. '\uFECA': '\u0639',
  20461. '\uFECB': '\u0639',
  20462. '\uFECC': '\u0639',
  20463. '\uFECD': '\u063A',
  20464. '\uFECE': '\u063A',
  20465. '\uFECF': '\u063A',
  20466. '\uFED0': '\u063A',
  20467. '\uFED1': '\u0641',
  20468. '\uFED2': '\u0641',
  20469. '\uFED3': '\u0641',
  20470. '\uFED4': '\u0641',
  20471. '\uFED5': '\u0642',
  20472. '\uFED6': '\u0642',
  20473. '\uFED7': '\u0642',
  20474. '\uFED8': '\u0642',
  20475. '\uFED9': '\u0643',
  20476. '\uFEDA': '\u0643',
  20477. '\uFEDB': '\u0643',
  20478. '\uFEDC': '\u0643',
  20479. '\uFEDD': '\u0644',
  20480. '\uFEDE': '\u0644',
  20481. '\uFEDF': '\u0644',
  20482. '\uFEE0': '\u0644',
  20483. '\uFEE1': '\u0645',
  20484. '\uFEE2': '\u0645',
  20485. '\uFEE3': '\u0645',
  20486. '\uFEE4': '\u0645',
  20487. '\uFEE5': '\u0646',
  20488. '\uFEE6': '\u0646',
  20489. '\uFEE7': '\u0646',
  20490. '\uFEE8': '\u0646',
  20491. '\uFEE9': '\u0647',
  20492. '\uFEEA': '\u0647',
  20493. '\uFEEB': '\u0647',
  20494. '\uFEEC': '\u0647',
  20495. '\uFEED': '\u0648',
  20496. '\uFEEE': '\u0648',
  20497. '\uFEEF': '\u0649',
  20498. '\uFEF0': '\u0649',
  20499. '\uFEF1': '\u064A',
  20500. '\uFEF2': '\u064A',
  20501. '\uFEF3': '\u064A',
  20502. '\uFEF4': '\u064A',
  20503. '\uFEF5': '\u0644\u0622',
  20504. '\uFEF6': '\u0644\u0622',
  20505. '\uFEF7': '\u0644\u0623',
  20506. '\uFEF8': '\u0644\u0623',
  20507. '\uFEF9': '\u0644\u0625',
  20508. '\uFEFA': '\u0644\u0625',
  20509. '\uFEFB': '\u0644\u0627',
  20510. '\uFEFC': '\u0644\u0627'
  20511. };
  20512. function reverseIfRtl(chars) {
  20513. var charsLength = chars.length;
  20514. //reverse an arabic ligature
  20515. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  20516. return chars;
  20517. }
  20518. var s = '';
  20519. for (var ii = charsLength - 1; ii >= 0; ii--) {
  20520. s += chars[ii];
  20521. }
  20522. return s;
  20523. }
  20524. function adjustWidths(properties) {
  20525. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  20526. return;
  20527. }
  20528. // adjusting width to fontMatrix scale
  20529. var scale = 0.001 / properties.fontMatrix[0];
  20530. var glyphsWidths = properties.widths;
  20531. for (var glyph in glyphsWidths) {
  20532. glyphsWidths[glyph] *= scale;
  20533. }
  20534. properties.defaultWidth *= scale;
  20535. }
  20536. function getFontType(type, subtype) {
  20537. switch (type) {
  20538. case 'Type1':
  20539. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  20540. case 'CIDFontType0':
  20541. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  20542. FontType.CIDFONTTYPE0;
  20543. case 'OpenType':
  20544. return FontType.OPENTYPE;
  20545. case 'TrueType':
  20546. return FontType.TRUETYPE;
  20547. case 'CIDFontType2':
  20548. return FontType.CIDFONTTYPE2;
  20549. case 'MMType1':
  20550. return FontType.MMTYPE1;
  20551. case 'Type0':
  20552. return FontType.TYPE0;
  20553. default:
  20554. return FontType.UNKNOWN;
  20555. }
  20556. }
  20557. var Glyph = (function GlyphClosure() {
  20558. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20559. this.fontChar = fontChar;
  20560. this.unicode = unicode;
  20561. this.accent = accent;
  20562. this.width = width;
  20563. this.vmetric = vmetric;
  20564. this.operatorListId = operatorListId;
  20565. }
  20566. Glyph.prototype.matchesForCache =
  20567. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20568. return this.fontChar === fontChar &&
  20569. this.unicode === unicode &&
  20570. this.accent === accent &&
  20571. this.width === width &&
  20572. this.vmetric === vmetric &&
  20573. this.operatorListId === operatorListId;
  20574. };
  20575. return Glyph;
  20576. })();
  20577. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  20578. function ToUnicodeMap(cmap) {
  20579. // The elements of this._map can be integers or strings, depending on how
  20580. // |cmap| was created.
  20581. this._map = cmap;
  20582. }
  20583. ToUnicodeMap.prototype = {
  20584. get length() {
  20585. return this._map.length;
  20586. },
  20587. forEach: function(callback) {
  20588. for (var charCode in this._map) {
  20589. callback(charCode, this._map[charCode].charCodeAt(0));
  20590. }
  20591. },
  20592. get: function(i) {
  20593. return this._map[i];
  20594. },
  20595. charCodeOf: function(v) {
  20596. return this._map.indexOf(v);
  20597. }
  20598. };
  20599. return ToUnicodeMap;
  20600. })();
  20601. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  20602. function IdentityToUnicodeMap(firstChar, lastChar) {
  20603. this.firstChar = firstChar;
  20604. this.lastChar = lastChar;
  20605. }
  20606. IdentityToUnicodeMap.prototype = {
  20607. get length() {
  20608. error('should not access .length');
  20609. },
  20610. forEach: function (callback) {
  20611. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  20612. callback(i, i);
  20613. }
  20614. },
  20615. get: function (i) {
  20616. if (this.firstChar <= i && i <= this.lastChar) {
  20617. return String.fromCharCode(i);
  20618. }
  20619. return undefined;
  20620. },
  20621. charCodeOf: function (v) {
  20622. error('should not call .charCodeOf');
  20623. }
  20624. };
  20625. return IdentityToUnicodeMap;
  20626. })();
  20627. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  20628. function writeInt16(dest, offset, num) {
  20629. dest[offset] = (num >> 8) & 0xFF;
  20630. dest[offset + 1] = num & 0xFF;
  20631. }
  20632. function writeInt32(dest, offset, num) {
  20633. dest[offset] = (num >> 24) & 0xFF;
  20634. dest[offset + 1] = (num >> 16) & 0xFF;
  20635. dest[offset + 2] = (num >> 8) & 0xFF;
  20636. dest[offset + 3] = num & 0xFF;
  20637. }
  20638. function writeData(dest, offset, data) {
  20639. var i, ii;
  20640. if (data instanceof Uint8Array) {
  20641. dest.set(data, offset);
  20642. } else if (typeof data === 'string') {
  20643. for (i = 0, ii = data.length; i < ii; i++) {
  20644. dest[offset++] = data.charCodeAt(i) & 0xFF;
  20645. }
  20646. } else {
  20647. // treating everything else as array
  20648. for (i = 0, ii = data.length; i < ii; i++) {
  20649. dest[offset++] = data[i] & 0xFF;
  20650. }
  20651. }
  20652. }
  20653. function OpenTypeFileBuilder(sfnt) {
  20654. this.sfnt = sfnt;
  20655. this.tables = Object.create(null);
  20656. }
  20657. OpenTypeFileBuilder.getSearchParams =
  20658. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  20659. var maxPower2 = 1, log2 = 0;
  20660. while ((maxPower2 ^ entriesCount) > maxPower2) {
  20661. maxPower2 <<= 1;
  20662. log2++;
  20663. }
  20664. var searchRange = maxPower2 * entrySize;
  20665. return {
  20666. range: searchRange,
  20667. entry: log2,
  20668. rangeShift: entrySize * entriesCount - searchRange
  20669. };
  20670. };
  20671. var OTF_HEADER_SIZE = 12;
  20672. var OTF_TABLE_ENTRY_SIZE = 16;
  20673. OpenTypeFileBuilder.prototype = {
  20674. toArray: function OpenTypeFileBuilder_toArray() {
  20675. var sfnt = this.sfnt;
  20676. // Tables needs to be written by ascendant alphabetic order
  20677. var tables = this.tables;
  20678. var tablesNames = Object.keys(tables);
  20679. tablesNames.sort();
  20680. var numTables = tablesNames.length;
  20681. var i, j, jj, table, tableName;
  20682. // layout the tables data
  20683. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  20684. var tableOffsets = [offset];
  20685. for (i = 0; i < numTables; i++) {
  20686. table = tables[tablesNames[i]];
  20687. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  20688. offset += paddedLength;
  20689. tableOffsets.push(offset);
  20690. }
  20691. var file = new Uint8Array(offset);
  20692. // write the table data first (mostly for checksum)
  20693. for (i = 0; i < numTables; i++) {
  20694. table = tables[tablesNames[i]];
  20695. writeData(file, tableOffsets[i], table);
  20696. }
  20697. // sfnt version (4 bytes)
  20698. if (sfnt === 'true') {
  20699. // Windows hates the Mac TrueType sfnt version number
  20700. sfnt = string32(0x00010000);
  20701. }
  20702. file[0] = sfnt.charCodeAt(0) & 0xFF;
  20703. file[1] = sfnt.charCodeAt(1) & 0xFF;
  20704. file[2] = sfnt.charCodeAt(2) & 0xFF;
  20705. file[3] = sfnt.charCodeAt(3) & 0xFF;
  20706. // numTables (2 bytes)
  20707. writeInt16(file, 4, numTables);
  20708. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  20709. // searchRange (2 bytes)
  20710. writeInt16(file, 6, searchParams.range);
  20711. // entrySelector (2 bytes)
  20712. writeInt16(file, 8, searchParams.entry);
  20713. // rangeShift (2 bytes)
  20714. writeInt16(file, 10, searchParams.rangeShift);
  20715. offset = OTF_HEADER_SIZE;
  20716. // writing table entries
  20717. for (i = 0; i < numTables; i++) {
  20718. tableName = tablesNames[i];
  20719. file[offset] = tableName.charCodeAt(0) & 0xFF;
  20720. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  20721. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  20722. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  20723. // checksum
  20724. var checksum = 0;
  20725. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  20726. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  20727. (file[j + 2] << 8) + file[j + 3];
  20728. checksum = (checksum + quad) | 0;
  20729. }
  20730. writeInt32(file, offset + 4, checksum);
  20731. // offset
  20732. writeInt32(file, offset + 8, tableOffsets[i]);
  20733. // length
  20734. writeInt32(file, offset + 12, tables[tableName].length);
  20735. offset += OTF_TABLE_ENTRY_SIZE;
  20736. }
  20737. return file;
  20738. },
  20739. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  20740. if (tag in this.tables) {
  20741. throw new Error('Table ' + tag + ' already exists');
  20742. }
  20743. this.tables[tag] = data;
  20744. }
  20745. };
  20746. return OpenTypeFileBuilder;
  20747. })();
  20748. /**
  20749. * 'Font' is the class the outside world should use, it encapsulate all the font
  20750. * decoding logics whatever type it is (assuming the font type is supported).
  20751. *
  20752. * For example to read a Type1 font and to attach it to the document:
  20753. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  20754. * type1Font.bind();
  20755. */
  20756. var Font = (function FontClosure() {
  20757. function Font(name, file, properties) {
  20758. var charCode, glyphName, fontChar;
  20759. this.name = name;
  20760. this.loadedName = properties.loadedName;
  20761. this.isType3Font = properties.isType3Font;
  20762. this.sizes = [];
  20763. this.glyphCache = {};
  20764. var names = name.split('+');
  20765. names = names.length > 1 ? names[1] : names[0];
  20766. names = names.split(/[-,_]/g)[0];
  20767. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  20768. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  20769. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  20770. var type = properties.type;
  20771. var subtype = properties.subtype;
  20772. this.type = type;
  20773. this.fallbackName = (this.isMonospace ? 'monospace' :
  20774. (this.isSerifFont ? 'serif' : 'sans-serif'));
  20775. this.differences = properties.differences;
  20776. this.widths = properties.widths;
  20777. this.defaultWidth = properties.defaultWidth;
  20778. this.composite = properties.composite;
  20779. this.wideChars = properties.wideChars;
  20780. this.cMap = properties.cMap;
  20781. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  20782. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  20783. this.fontMatrix = properties.fontMatrix;
  20784. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  20785. this.toFontChar = [];
  20786. if (properties.type === 'Type3') {
  20787. for (charCode = 0; charCode < 256; charCode++) {
  20788. this.toFontChar[charCode] = (this.differences[charCode] ||
  20789. properties.defaultEncoding[charCode]);
  20790. }
  20791. this.fontType = FontType.TYPE3;
  20792. return;
  20793. }
  20794. this.cidEncoding = properties.cidEncoding;
  20795. this.vertical = properties.vertical;
  20796. if (this.vertical) {
  20797. this.vmetrics = properties.vmetrics;
  20798. this.defaultVMetrics = properties.defaultVMetrics;
  20799. }
  20800. if (!file || file.isEmpty) {
  20801. if (file) {
  20802. // Some bad PDF generators will include empty font files,
  20803. // attempting to recover by assuming that no file exists.
  20804. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  20805. }
  20806. this.missingFile = true;
  20807. // The file data is not specified. Trying to fix the font name
  20808. // to be used with the canvas.font.
  20809. var fontName = name.replace(/[,_]/g, '-');
  20810. var isStandardFont = !!stdFontMap[fontName] ||
  20811. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  20812. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  20813. this.bold = (fontName.search(/bold/gi) !== -1);
  20814. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  20815. (fontName.search(/italic/gi) !== -1));
  20816. // Use 'name' instead of 'fontName' here because the original
  20817. // name ArialBlack for example will be replaced by Helvetica.
  20818. this.black = (name.search(/Black/g) !== -1);
  20819. // if at least one width is present, remeasure all chars when exists
  20820. this.remeasure = Object.keys(this.widths).length > 0;
  20821. if (isStandardFont && type === 'CIDFontType2' &&
  20822. properties.cidEncoding.indexOf('Identity-') === 0) {
  20823. // Standard fonts might be embedded as CID font without glyph mapping.
  20824. // Building one based on GlyphMapForStandardFonts.
  20825. var map = [];
  20826. for (var code in GlyphMapForStandardFonts) {
  20827. map[+code] = GlyphMapForStandardFonts[code];
  20828. }
  20829. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  20830. if (!isIdentityUnicode) {
  20831. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20832. map[+charCode] = unicodeCharCode;
  20833. });
  20834. }
  20835. this.toFontChar = map;
  20836. this.toUnicode = new ToUnicodeMap(map);
  20837. } else if (/Symbol/i.test(fontName)) {
  20838. var symbols = Encodings.SymbolSetEncoding;
  20839. for (charCode in symbols) {
  20840. fontChar = GlyphsUnicode[symbols[charCode]];
  20841. if (!fontChar) {
  20842. continue;
  20843. }
  20844. this.toFontChar[charCode] = fontChar;
  20845. }
  20846. for (charCode in properties.differences) {
  20847. fontChar = GlyphsUnicode[properties.differences[charCode]];
  20848. if (!fontChar) {
  20849. continue;
  20850. }
  20851. this.toFontChar[charCode] = fontChar;
  20852. }
  20853. } else if (/Dingbats/i.test(fontName)) {
  20854. if (/Wingdings/i.test(name)) {
  20855. warn('Wingdings font without embedded font file, ' +
  20856. 'falling back to the ZapfDingbats encoding.');
  20857. }
  20858. var dingbats = Encodings.ZapfDingbatsEncoding;
  20859. for (charCode in dingbats) {
  20860. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  20861. if (!fontChar) {
  20862. continue;
  20863. }
  20864. this.toFontChar[charCode] = fontChar;
  20865. }
  20866. for (charCode in properties.differences) {
  20867. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  20868. if (!fontChar) {
  20869. continue;
  20870. }
  20871. this.toFontChar[charCode] = fontChar;
  20872. }
  20873. } else if (isStandardFont) {
  20874. this.toFontChar = [];
  20875. for (charCode in properties.defaultEncoding) {
  20876. glyphName = (properties.differences[charCode] ||
  20877. properties.defaultEncoding[charCode]);
  20878. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  20879. }
  20880. } else {
  20881. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  20882. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20883. if (notCidFont) {
  20884. glyphName = (properties.differences[charCode] ||
  20885. properties.defaultEncoding[charCode]);
  20886. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  20887. }
  20888. this.toFontChar[charCode] = unicodeCharCode;
  20889. }.bind(this));
  20890. }
  20891. this.loadedName = fontName.split('-')[0];
  20892. this.loading = false;
  20893. this.fontType = getFontType(type, subtype);
  20894. return;
  20895. }
  20896. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  20897. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  20898. // Some TrueType fonts by mistake claim Type1C
  20899. if (isTrueTypeFile(file)) {
  20900. subtype = 'TrueType';
  20901. } else {
  20902. type = 'Type1';
  20903. }
  20904. }
  20905. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  20906. type = 'CIDFontType0';
  20907. }
  20908. // XXX: Temporarily change the type for open type so we trigger a warning.
  20909. // This should be removed when we add support for open type.
  20910. if (subtype === 'OpenType') {
  20911. type = 'OpenType';
  20912. }
  20913. var data;
  20914. switch (type) {
  20915. case 'MMType1':
  20916. info('MMType1 font (' + name + '), falling back to Type1.');
  20917. /* falls through */
  20918. case 'Type1':
  20919. case 'CIDFontType0':
  20920. this.mimetype = 'font/opentype';
  20921. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  20922. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  20923. adjustWidths(properties);
  20924. // Wrap the CFF data inside an OTF font file
  20925. data = this.convert(name, cff, properties);
  20926. break;
  20927. case 'OpenType':
  20928. case 'TrueType':
  20929. case 'CIDFontType2':
  20930. this.mimetype = 'font/opentype';
  20931. // Repair the TrueType file. It is can be damaged in the point of
  20932. // view of the sanitizer
  20933. data = this.checkAndRepair(name, file, properties);
  20934. if (this.isOpenType) {
  20935. type = 'OpenType';
  20936. }
  20937. break;
  20938. default:
  20939. error('Font ' + type + ' is not supported');
  20940. break;
  20941. }
  20942. this.data = data;
  20943. this.fontType = getFontType(type, subtype);
  20944. // Transfer some properties again that could change during font conversion
  20945. this.fontMatrix = properties.fontMatrix;
  20946. this.widths = properties.widths;
  20947. this.defaultWidth = properties.defaultWidth;
  20948. this.encoding = properties.baseEncoding;
  20949. this.seacMap = properties.seacMap;
  20950. this.loading = true;
  20951. }
  20952. Font.getFontID = (function () {
  20953. var ID = 1;
  20954. return function Font_getFontID() {
  20955. return String(ID++);
  20956. };
  20957. })();
  20958. function int16(b0, b1) {
  20959. return (b0 << 8) + b1;
  20960. }
  20961. function int32(b0, b1, b2, b3) {
  20962. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20963. }
  20964. function string16(value) {
  20965. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20966. }
  20967. function safeString16(value) {
  20968. // clamp value to the 16-bit int range
  20969. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  20970. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20971. }
  20972. function isTrueTypeFile(file) {
  20973. var header = file.peekBytes(4);
  20974. return readUint32(header, 0) === 0x00010000;
  20975. }
  20976. /**
  20977. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  20978. * with their unicode value. It also moves char codes that are in known
  20979. * problematic locations.
  20980. * @return {Object} Two properties:
  20981. * 'toFontChar' - maps original char codes(the value that will be read
  20982. * from commands such as show text) to the char codes that will be used in the
  20983. * font that we build
  20984. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  20985. */
  20986. function adjustMapping(charCodeToGlyphId, properties) {
  20987. var toUnicode = properties.toUnicode;
  20988. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  20989. var isIdentityUnicode =
  20990. properties.toUnicode instanceof IdentityToUnicodeMap;
  20991. var isCidFontType2 = (properties.type === 'CIDFontType2');
  20992. var newMap = Object.create(null);
  20993. var toFontChar = [];
  20994. var usedFontCharCodes = [];
  20995. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  20996. for (var originalCharCode in charCodeToGlyphId) {
  20997. originalCharCode |= 0;
  20998. var glyphId = charCodeToGlyphId[originalCharCode];
  20999. var fontCharCode = originalCharCode;
  21000. // First try to map the value to a unicode position if a non identity map
  21001. // was created.
  21002. if (!isIdentityUnicode) {
  21003. if (toUnicode.get(originalCharCode) !== undefined) {
  21004. var unicode = toUnicode.get(fontCharCode);
  21005. // TODO: Try to map ligatures to the correct spot.
  21006. if (unicode.length === 1) {
  21007. fontCharCode = unicode.charCodeAt(0);
  21008. }
  21009. } else if (isCidFontType2) {
  21010. // For CIDFontType2, move characters not present in toUnicode
  21011. // to the private use area (fixes bug 1028735 and issue 4881).
  21012. fontCharCode = nextAvailableFontCharCode;
  21013. }
  21014. }
  21015. // Try to move control characters, special characters and already mapped
  21016. // characters to the private use area since they will not be drawn by
  21017. // canvas if left in their current position. Also, move characters if the
  21018. // font was symbolic and there is only an identity unicode map since the
  21019. // characters probably aren't in the correct position (fixes an issue
  21020. // with firefox and thuluthfont).
  21021. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  21022. fontCharCode <= 0x1f || // Control chars
  21023. fontCharCode === 0x7F || // Control char
  21024. fontCharCode === 0xAD || // Soft hyphen
  21025. fontCharCode === 0xA0 || // Non breaking space
  21026. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  21027. // Prevent drawing characters in the specials unicode block.
  21028. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  21029. (isSymbolic && isIdentityUnicode)) &&
  21030. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  21031. // Loop to try and find a free spot in the private use area.
  21032. do {
  21033. fontCharCode = nextAvailableFontCharCode++;
  21034. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  21035. fontCharCode = 0xF020;
  21036. nextAvailableFontCharCode = fontCharCode + 1;
  21037. }
  21038. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  21039. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  21040. }
  21041. newMap[fontCharCode] = glyphId;
  21042. toFontChar[originalCharCode] = fontCharCode;
  21043. usedFontCharCodes[fontCharCode] = true;
  21044. }
  21045. return {
  21046. toFontChar: toFontChar,
  21047. charCodeToGlyphId: newMap,
  21048. nextAvailableFontCharCode: nextAvailableFontCharCode
  21049. };
  21050. }
  21051. function getRanges(glyphs) {
  21052. // Array.sort() sorts by characters, not numerically, so convert to an
  21053. // array of characters.
  21054. var codes = [];
  21055. for (var charCode in glyphs) {
  21056. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  21057. }
  21058. codes.sort(function fontGetRangesSort(a, b) {
  21059. return a.fontCharCode - b.fontCharCode;
  21060. });
  21061. // Split the sorted codes into ranges.
  21062. var ranges = [];
  21063. var length = codes.length;
  21064. for (var n = 0; n < length; ) {
  21065. var start = codes[n].fontCharCode;
  21066. var codeIndices = [codes[n].glyphId];
  21067. ++n;
  21068. var end = start;
  21069. while (n < length && end + 1 === codes[n].fontCharCode) {
  21070. codeIndices.push(codes[n].glyphId);
  21071. ++end;
  21072. ++n;
  21073. if (end === 0xFFFF) {
  21074. break;
  21075. }
  21076. }
  21077. ranges.push([start, end, codeIndices]);
  21078. }
  21079. return ranges;
  21080. }
  21081. function createCmapTable(glyphs) {
  21082. var ranges = getRanges(glyphs);
  21083. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  21084. var cmap = '\x00\x00' + // version
  21085. string16(numTables) + // numTables
  21086. '\x00\x03' + // platformID
  21087. '\x00\x01' + // encodingID
  21088. string32(4 + numTables * 8); // start of the table record
  21089. var i, ii, j, jj;
  21090. for (i = ranges.length - 1; i >= 0; --i) {
  21091. if (ranges[i][0] <= 0xFFFF) { break; }
  21092. }
  21093. var bmpLength = i + 1;
  21094. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  21095. ranges[i][1] = 0xFFFE;
  21096. }
  21097. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  21098. var segCount = bmpLength + trailingRangesCount;
  21099. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  21100. // Fill up the 4 parallel arrays describing the segments.
  21101. var startCount = '';
  21102. var endCount = '';
  21103. var idDeltas = '';
  21104. var idRangeOffsets = '';
  21105. var glyphsIds = '';
  21106. var bias = 0;
  21107. var range, start, end, codes;
  21108. for (i = 0, ii = bmpLength; i < ii; i++) {
  21109. range = ranges[i];
  21110. start = range[0];
  21111. end = range[1];
  21112. startCount += string16(start);
  21113. endCount += string16(end);
  21114. codes = range[2];
  21115. var contiguous = true;
  21116. for (j = 1, jj = codes.length; j < jj; ++j) {
  21117. if (codes[j] !== codes[j - 1] + 1) {
  21118. contiguous = false;
  21119. break;
  21120. }
  21121. }
  21122. if (!contiguous) {
  21123. var offset = (segCount - i) * 2 + bias * 2;
  21124. bias += (end - start + 1);
  21125. idDeltas += string16(0);
  21126. idRangeOffsets += string16(offset);
  21127. for (j = 0, jj = codes.length; j < jj; ++j) {
  21128. glyphsIds += string16(codes[j]);
  21129. }
  21130. } else {
  21131. var startCode = codes[0];
  21132. idDeltas += string16((startCode - start) & 0xFFFF);
  21133. idRangeOffsets += string16(0);
  21134. }
  21135. }
  21136. if (trailingRangesCount > 0) {
  21137. endCount += '\xFF\xFF';
  21138. startCount += '\xFF\xFF';
  21139. idDeltas += '\x00\x01';
  21140. idRangeOffsets += '\x00\x00';
  21141. }
  21142. var format314 = '\x00\x00' + // language
  21143. string16(2 * segCount) +
  21144. string16(searchParams.range) +
  21145. string16(searchParams.entry) +
  21146. string16(searchParams.rangeShift) +
  21147. endCount + '\x00\x00' + startCount +
  21148. idDeltas + idRangeOffsets + glyphsIds;
  21149. var format31012 = '';
  21150. var header31012 = '';
  21151. if (numTables > 1) {
  21152. cmap += '\x00\x03' + // platformID
  21153. '\x00\x0A' + // encodingID
  21154. string32(4 + numTables * 8 +
  21155. 4 + format314.length); // start of the table record
  21156. format31012 = '';
  21157. for (i = 0, ii = ranges.length; i < ii; i++) {
  21158. range = ranges[i];
  21159. start = range[0];
  21160. codes = range[2];
  21161. var code = codes[0];
  21162. for (j = 1, jj = codes.length; j < jj; ++j) {
  21163. if (codes[j] !== codes[j - 1] + 1) {
  21164. end = range[0] + j - 1;
  21165. format31012 += string32(start) + // startCharCode
  21166. string32(end) + // endCharCode
  21167. string32(code); // startGlyphID
  21168. start = end + 1;
  21169. code = codes[j];
  21170. }
  21171. }
  21172. format31012 += string32(start) + // startCharCode
  21173. string32(range[1]) + // endCharCode
  21174. string32(code); // startGlyphID
  21175. }
  21176. header31012 = '\x00\x0C' + // format
  21177. '\x00\x00' + // reserved
  21178. string32(format31012.length + 16) + // length
  21179. '\x00\x00\x00\x00' + // language
  21180. string32(format31012.length / 12); // nGroups
  21181. }
  21182. return cmap + '\x00\x04' + // format
  21183. string16(format314.length + 4) + // length
  21184. format314 + header31012 + format31012;
  21185. }
  21186. function validateOS2Table(os2) {
  21187. var stream = new Stream(os2.data);
  21188. var version = stream.getUint16();
  21189. // TODO verify all OS/2 tables fields, but currently we validate only those
  21190. // that give us issues
  21191. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  21192. var selection = stream.getUint16();
  21193. if (version < 4 && (selection & 0x0300)) {
  21194. return false;
  21195. }
  21196. var firstChar = stream.getUint16();
  21197. var lastChar = stream.getUint16();
  21198. if (firstChar > lastChar) {
  21199. return false;
  21200. }
  21201. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  21202. var usWinAscent = stream.getUint16();
  21203. if (usWinAscent === 0) { // makes font unreadable by windows
  21204. return false;
  21205. }
  21206. // OS/2 appears to be valid, resetting some fields
  21207. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  21208. return true;
  21209. }
  21210. function createOS2Table(properties, charstrings, override) {
  21211. override = override || {
  21212. unitsPerEm: 0,
  21213. yMax: 0,
  21214. yMin: 0,
  21215. ascent: 0,
  21216. descent: 0
  21217. };
  21218. var ulUnicodeRange1 = 0;
  21219. var ulUnicodeRange2 = 0;
  21220. var ulUnicodeRange3 = 0;
  21221. var ulUnicodeRange4 = 0;
  21222. var firstCharIndex = null;
  21223. var lastCharIndex = 0;
  21224. if (charstrings) {
  21225. for (var code in charstrings) {
  21226. code |= 0;
  21227. if (firstCharIndex > code || !firstCharIndex) {
  21228. firstCharIndex = code;
  21229. }
  21230. if (lastCharIndex < code) {
  21231. lastCharIndex = code;
  21232. }
  21233. var position = getUnicodeRangeFor(code);
  21234. if (position < 32) {
  21235. ulUnicodeRange1 |= 1 << position;
  21236. } else if (position < 64) {
  21237. ulUnicodeRange2 |= 1 << position - 32;
  21238. } else if (position < 96) {
  21239. ulUnicodeRange3 |= 1 << position - 64;
  21240. } else if (position < 123) {
  21241. ulUnicodeRange4 |= 1 << position - 96;
  21242. } else {
  21243. error('Unicode ranges Bits > 123 are reserved for internal usage');
  21244. }
  21245. }
  21246. } else {
  21247. // TODO
  21248. firstCharIndex = 0;
  21249. lastCharIndex = 255;
  21250. }
  21251. var bbox = properties.bbox || [0, 0, 0, 0];
  21252. var unitsPerEm = (override.unitsPerEm ||
  21253. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  21254. // if the font units differ to the PDF glyph space units
  21255. // then scale up the values
  21256. var scale = (properties.ascentScaled ? 1.0 :
  21257. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  21258. var typoAscent = (override.ascent ||
  21259. Math.round(scale * (properties.ascent || bbox[3])));
  21260. var typoDescent = (override.descent ||
  21261. Math.round(scale * (properties.descent || bbox[1])));
  21262. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  21263. typoDescent = -typoDescent; // fixing incorrect descent
  21264. }
  21265. var winAscent = override.yMax || typoAscent;
  21266. var winDescent = -override.yMin || -typoDescent;
  21267. return '\x00\x03' + // version
  21268. '\x02\x24' + // xAvgCharWidth
  21269. '\x01\xF4' + // usWeightClass
  21270. '\x00\x05' + // usWidthClass
  21271. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  21272. '\x02\x8A' + // ySubscriptXSize
  21273. '\x02\xBB' + // ySubscriptYSize
  21274. '\x00\x00' + // ySubscriptXOffset
  21275. '\x00\x8C' + // ySubscriptYOffset
  21276. '\x02\x8A' + // ySuperScriptXSize
  21277. '\x02\xBB' + // ySuperScriptYSize
  21278. '\x00\x00' + // ySuperScriptXOffset
  21279. '\x01\xDF' + // ySuperScriptYOffset
  21280. '\x00\x31' + // yStrikeOutSize
  21281. '\x01\x02' + // yStrikeOutPosition
  21282. '\x00\x00' + // sFamilyClass
  21283. '\x00\x00\x06' +
  21284. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  21285. '\x00\x00\x00\x00\x00\x00' + // Panose
  21286. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  21287. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  21288. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  21289. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  21290. '\x2A\x32\x31\x2A' + // achVendID
  21291. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  21292. string16(firstCharIndex ||
  21293. properties.firstChar) + // usFirstCharIndex
  21294. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  21295. string16(typoAscent) + // sTypoAscender
  21296. string16(typoDescent) + // sTypoDescender
  21297. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  21298. string16(winAscent) + // usWinAscent
  21299. string16(winDescent) + // usWinDescent
  21300. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  21301. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  21302. string16(properties.xHeight) + // sxHeight
  21303. string16(properties.capHeight) + // sCapHeight
  21304. string16(0) + // usDefaultChar
  21305. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  21306. '\x00\x03'; // usMaxContext
  21307. }
  21308. function createPostTable(properties) {
  21309. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  21310. return ('\x00\x03\x00\x00' + // Version number
  21311. string32(angle) + // italicAngle
  21312. '\x00\x00' + // underlinePosition
  21313. '\x00\x00' + // underlineThickness
  21314. string32(properties.fixedPitch) + // isFixedPitch
  21315. '\x00\x00\x00\x00' + // minMemType42
  21316. '\x00\x00\x00\x00' + // maxMemType42
  21317. '\x00\x00\x00\x00' + // minMemType1
  21318. '\x00\x00\x00\x00'); // maxMemType1
  21319. }
  21320. function createNameTable(name, proto) {
  21321. if (!proto) {
  21322. proto = [[], []]; // no strings and unicode strings
  21323. }
  21324. var strings = [
  21325. proto[0][0] || 'Original licence', // 0.Copyright
  21326. proto[0][1] || name, // 1.Font family
  21327. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  21328. proto[0][3] || 'uniqueID', // 3.Unique ID
  21329. proto[0][4] || name, // 4.Full font name
  21330. proto[0][5] || 'Version 0.11', // 5.Version
  21331. proto[0][6] || '', // 6.Postscript name
  21332. proto[0][7] || 'Unknown', // 7.Trademark
  21333. proto[0][8] || 'Unknown', // 8.Manufacturer
  21334. proto[0][9] || 'Unknown' // 9.Designer
  21335. ];
  21336. // Mac want 1-byte per character strings while Windows want
  21337. // 2-bytes per character, so duplicate the names table
  21338. var stringsUnicode = [];
  21339. var i, ii, j, jj, str;
  21340. for (i = 0, ii = strings.length; i < ii; i++) {
  21341. str = proto[1][i] || strings[i];
  21342. var strBufUnicode = [];
  21343. for (j = 0, jj = str.length; j < jj; j++) {
  21344. strBufUnicode.push(string16(str.charCodeAt(j)));
  21345. }
  21346. stringsUnicode.push(strBufUnicode.join(''));
  21347. }
  21348. var names = [strings, stringsUnicode];
  21349. var platforms = ['\x00\x01', '\x00\x03'];
  21350. var encodings = ['\x00\x00', '\x00\x01'];
  21351. var languages = ['\x00\x00', '\x04\x09'];
  21352. var namesRecordCount = strings.length * platforms.length;
  21353. var nameTable =
  21354. '\x00\x00' + // format
  21355. string16(namesRecordCount) + // Number of names Record
  21356. string16(namesRecordCount * 12 + 6); // Storage
  21357. // Build the name records field
  21358. var strOffset = 0;
  21359. for (i = 0, ii = platforms.length; i < ii; i++) {
  21360. var strs = names[i];
  21361. for (j = 0, jj = strs.length; j < jj; j++) {
  21362. str = strs[j];
  21363. var nameRecord =
  21364. platforms[i] + // platform ID
  21365. encodings[i] + // encoding ID
  21366. languages[i] + // language ID
  21367. string16(j) + // name ID
  21368. string16(str.length) +
  21369. string16(strOffset);
  21370. nameTable += nameRecord;
  21371. strOffset += str.length;
  21372. }
  21373. }
  21374. nameTable += strings.join('') + stringsUnicode.join('');
  21375. return nameTable;
  21376. }
  21377. Font.prototype = {
  21378. name: null,
  21379. font: null,
  21380. mimetype: null,
  21381. encoding: null,
  21382. get renderer() {
  21383. var renderer = FontRendererFactory.create(this);
  21384. return shadow(this, 'renderer', renderer);
  21385. },
  21386. exportData: function Font_exportData() {
  21387. var data = {};
  21388. for (var i in this) {
  21389. if (this.hasOwnProperty(i)) {
  21390. data[i] = this[i];
  21391. }
  21392. }
  21393. return data;
  21394. },
  21395. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  21396. function readTableEntry(file) {
  21397. var tag = bytesToString(file.getBytes(4));
  21398. var checksum = file.getInt32();
  21399. var offset = file.getInt32() >>> 0;
  21400. var length = file.getInt32() >>> 0;
  21401. // Read the table associated data
  21402. var previousPosition = file.pos;
  21403. file.pos = file.start ? file.start : 0;
  21404. file.skip(offset);
  21405. var data = file.getBytes(length);
  21406. file.pos = previousPosition;
  21407. if (tag === 'head') {
  21408. // clearing checksum adjustment
  21409. data[8] = data[9] = data[10] = data[11] = 0;
  21410. data[17] |= 0x20; //Set font optimized for cleartype flag
  21411. }
  21412. return {
  21413. tag: tag,
  21414. checksum: checksum,
  21415. length: length,
  21416. offset: offset,
  21417. data: data
  21418. };
  21419. }
  21420. function readOpenTypeHeader(ttf) {
  21421. return {
  21422. version: bytesToString(ttf.getBytes(4)),
  21423. numTables: ttf.getUint16(),
  21424. searchRange: ttf.getUint16(),
  21425. entrySelector: ttf.getUint16(),
  21426. rangeShift: ttf.getUint16()
  21427. };
  21428. }
  21429. /**
  21430. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  21431. * PDF spec
  21432. */
  21433. function readCmapTable(cmap, font, isSymbolicFont) {
  21434. var segment;
  21435. var start = (font.start ? font.start : 0) + cmap.offset;
  21436. font.pos = start;
  21437. var version = font.getUint16();
  21438. var numTables = font.getUint16();
  21439. var potentialTable;
  21440. var canBreak = false;
  21441. // There's an order of preference in terms of which cmap subtable to
  21442. // use:
  21443. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  21444. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  21445. // The following takes advantage of the fact that the tables are sorted
  21446. // to work.
  21447. for (var i = 0; i < numTables; i++) {
  21448. var platformId = font.getUint16();
  21449. var encodingId = font.getUint16();
  21450. var offset = font.getInt32() >>> 0;
  21451. var useTable = false;
  21452. if (platformId === 1 && encodingId === 0) {
  21453. useTable = true;
  21454. // Continue the loop since there still may be a higher priority
  21455. // table.
  21456. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  21457. useTable = true;
  21458. canBreak = true;
  21459. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  21460. useTable = true;
  21461. canBreak = true;
  21462. }
  21463. if (useTable) {
  21464. potentialTable = {
  21465. platformId: platformId,
  21466. encodingId: encodingId,
  21467. offset: offset
  21468. };
  21469. }
  21470. if (canBreak) {
  21471. break;
  21472. }
  21473. }
  21474. if (!potentialTable) {
  21475. warn('Could not find a preferred cmap table.');
  21476. return {
  21477. platformId: -1,
  21478. encodingId: -1,
  21479. mappings: [],
  21480. hasShortCmap: false
  21481. };
  21482. }
  21483. font.pos = start + potentialTable.offset;
  21484. var format = font.getUint16();
  21485. var length = font.getUint16();
  21486. var language = font.getUint16();
  21487. var hasShortCmap = false;
  21488. var mappings = [];
  21489. var j, glyphId;
  21490. // TODO(mack): refactor this cmap subtable reading logic out
  21491. if (format === 0) {
  21492. for (j = 0; j < 256; j++) {
  21493. var index = font.getByte();
  21494. if (!index) {
  21495. continue;
  21496. }
  21497. mappings.push({
  21498. charCode: j,
  21499. glyphId: index
  21500. });
  21501. }
  21502. hasShortCmap = true;
  21503. } else if (format === 4) {
  21504. // re-creating the table in format 4 since the encoding
  21505. // might be changed
  21506. var segCount = (font.getUint16() >> 1);
  21507. font.getBytes(6); // skipping range fields
  21508. var segIndex, segments = [];
  21509. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21510. segments.push({ end: font.getUint16() });
  21511. }
  21512. font.getUint16();
  21513. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21514. segments[segIndex].start = font.getUint16();
  21515. }
  21516. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21517. segments[segIndex].delta = font.getUint16();
  21518. }
  21519. var offsetsCount = 0;
  21520. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21521. segment = segments[segIndex];
  21522. var rangeOffset = font.getUint16();
  21523. if (!rangeOffset) {
  21524. segment.offsetIndex = -1;
  21525. continue;
  21526. }
  21527. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  21528. segment.offsetIndex = offsetIndex;
  21529. offsetsCount = Math.max(offsetsCount, offsetIndex +
  21530. segment.end - segment.start + 1);
  21531. }
  21532. var offsets = [];
  21533. for (j = 0; j < offsetsCount; j++) {
  21534. offsets.push(font.getUint16());
  21535. }
  21536. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21537. segment = segments[segIndex];
  21538. start = segment.start;
  21539. var end = segment.end;
  21540. var delta = segment.delta;
  21541. offsetIndex = segment.offsetIndex;
  21542. for (j = start; j <= end; j++) {
  21543. if (j === 0xFFFF) {
  21544. continue;
  21545. }
  21546. glyphId = (offsetIndex < 0 ?
  21547. j : offsets[offsetIndex + j - start]);
  21548. glyphId = (glyphId + delta) & 0xFFFF;
  21549. if (glyphId === 0) {
  21550. continue;
  21551. }
  21552. mappings.push({
  21553. charCode: j,
  21554. glyphId: glyphId
  21555. });
  21556. }
  21557. }
  21558. } else if (format === 6) {
  21559. // Format 6 is a 2-bytes dense mapping, which means the font data
  21560. // lives glue together even if they are pretty far in the unicode
  21561. // table. (This looks weird, so I can have missed something), this
  21562. // works on Linux but seems to fails on Mac so let's rewrite the
  21563. // cmap table to a 3-1-4 style
  21564. var firstCode = font.getUint16();
  21565. var entryCount = font.getUint16();
  21566. for (j = 0; j < entryCount; j++) {
  21567. glyphId = font.getUint16();
  21568. var charCode = firstCode + j;
  21569. mappings.push({
  21570. charCode: charCode,
  21571. glyphId: glyphId
  21572. });
  21573. }
  21574. } else {
  21575. error('cmap table has unsupported format: ' + format);
  21576. }
  21577. // removing duplicate entries
  21578. mappings.sort(function (a, b) {
  21579. return a.charCode - b.charCode;
  21580. });
  21581. for (i = 1; i < mappings.length; i++) {
  21582. if (mappings[i - 1].charCode === mappings[i].charCode) {
  21583. mappings.splice(i, 1);
  21584. i--;
  21585. }
  21586. }
  21587. return {
  21588. platformId: potentialTable.platformId,
  21589. encodingId: potentialTable.encodingId,
  21590. mappings: mappings,
  21591. hasShortCmap: hasShortCmap
  21592. };
  21593. }
  21594. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  21595. if (!header) {
  21596. if (metrics) {
  21597. metrics.data = null;
  21598. }
  21599. return;
  21600. }
  21601. font.pos = (font.start ? font.start : 0) + header.offset;
  21602. font.pos += header.length - 2;
  21603. var numOfMetrics = font.getUint16();
  21604. if (numOfMetrics > numGlyphs) {
  21605. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  21606. 'greater than the numGlyphs (' + numGlyphs + ')');
  21607. // Reduce numOfMetrics if it is greater than numGlyphs
  21608. numOfMetrics = numGlyphs;
  21609. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  21610. header.data[35] = numOfMetrics & 0x00ff;
  21611. }
  21612. var numOfSidebearings = numGlyphs - numOfMetrics;
  21613. var numMissing = numOfSidebearings -
  21614. ((metrics.length - numOfMetrics * 4) >> 1);
  21615. if (numMissing > 0) {
  21616. // For each missing glyph, we set both the width and lsb to 0 (zero).
  21617. // Since we need to add two properties for each glyph, this explains
  21618. // the use of |numMissing * 2| when initializing the typed array.
  21619. var entries = new Uint8Array(metrics.length + numMissing * 2);
  21620. entries.set(metrics.data);
  21621. metrics.data = entries;
  21622. }
  21623. }
  21624. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  21625. hintsValid) {
  21626. if (sourceEnd - sourceStart <= 12) {
  21627. // glyph with data less than 12 is invalid one
  21628. return 0;
  21629. }
  21630. var glyf = source.subarray(sourceStart, sourceEnd);
  21631. var contoursCount = (glyf[0] << 8) | glyf[1];
  21632. if (contoursCount & 0x8000) {
  21633. // complex glyph, writing as is
  21634. dest.set(glyf, destStart);
  21635. return glyf.length;
  21636. }
  21637. var i, j = 10, flagsCount = 0;
  21638. for (i = 0; i < contoursCount; i++) {
  21639. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  21640. flagsCount = endPoint + 1;
  21641. j += 2;
  21642. }
  21643. // skipping instructions
  21644. var instructionsStart = j;
  21645. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  21646. j += 2 + instructionsLength;
  21647. var instructionsEnd = j;
  21648. // validating flags
  21649. var coordinatesLength = 0;
  21650. for (i = 0; i < flagsCount; i++) {
  21651. var flag = glyf[j++];
  21652. if (flag & 0xC0) {
  21653. // reserved flags must be zero, cleaning up
  21654. glyf[j - 1] = flag & 0x3F;
  21655. }
  21656. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  21657. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  21658. coordinatesLength += xyLength;
  21659. if (flag & 8) {
  21660. var repeat = glyf[j++];
  21661. i += repeat;
  21662. coordinatesLength += repeat * xyLength;
  21663. }
  21664. }
  21665. // glyph without coordinates will be rejected
  21666. if (coordinatesLength === 0) {
  21667. return 0;
  21668. }
  21669. var glyphDataLength = j + coordinatesLength;
  21670. if (glyphDataLength > glyf.length) {
  21671. // not enough data for coordinates
  21672. return 0;
  21673. }
  21674. if (!hintsValid && instructionsLength > 0) {
  21675. dest.set(glyf.subarray(0, instructionsStart), destStart);
  21676. dest.set([0, 0], destStart + instructionsStart);
  21677. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  21678. destStart + instructionsStart + 2);
  21679. glyphDataLength -= instructionsLength;
  21680. if (glyf.length - glyphDataLength > 3) {
  21681. glyphDataLength = (glyphDataLength + 3) & ~3;
  21682. }
  21683. return glyphDataLength;
  21684. }
  21685. if (glyf.length - glyphDataLength > 3) {
  21686. // truncating and aligning to 4 bytes the long glyph data
  21687. glyphDataLength = (glyphDataLength + 3) & ~3;
  21688. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  21689. return glyphDataLength;
  21690. }
  21691. // glyph data is fine
  21692. dest.set(glyf, destStart);
  21693. return glyf.length;
  21694. }
  21695. function sanitizeHead(head, numGlyphs, locaLength) {
  21696. var data = head.data;
  21697. // Validate version:
  21698. // Should always be 0x00010000
  21699. var version = int32(data[0], data[1], data[2], data[3]);
  21700. if (version >> 16 !== 1) {
  21701. info('Attempting to fix invalid version in head table: ' + version);
  21702. data[0] = 0;
  21703. data[1] = 1;
  21704. data[2] = 0;
  21705. data[3] = 0;
  21706. }
  21707. var indexToLocFormat = int16(data[50], data[51]);
  21708. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  21709. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  21710. indexToLocFormat);
  21711. // The value of indexToLocFormat should be 0 if the loca table
  21712. // consists of short offsets, and should be 1 if the loca table
  21713. // consists of long offsets.
  21714. //
  21715. // The number of entries in the loca table should be numGlyphs + 1.
  21716. //
  21717. // Using this information, we can work backwards to deduce if the
  21718. // size of each offset in the loca table, and thus figure out the
  21719. // appropriate value for indexToLocFormat.
  21720. var numGlyphsPlusOne = numGlyphs + 1;
  21721. if (locaLength === numGlyphsPlusOne << 1) {
  21722. // 0x0000 indicates the loca table consists of short offsets
  21723. data[50] = 0;
  21724. data[51] = 0;
  21725. } else if (locaLength === numGlyphsPlusOne << 2) {
  21726. // 0x0001 indicates the loca table consists of long offsets
  21727. data[50] = 0;
  21728. data[51] = 1;
  21729. } else {
  21730. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  21731. }
  21732. }
  21733. }
  21734. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  21735. isGlyphLocationsLong, hintsValid,
  21736. dupFirstEntry) {
  21737. var itemSize, itemDecode, itemEncode;
  21738. if (isGlyphLocationsLong) {
  21739. itemSize = 4;
  21740. itemDecode = function fontItemDecodeLong(data, offset) {
  21741. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21742. (data[offset + 2] << 8) | data[offset + 3];
  21743. };
  21744. itemEncode = function fontItemEncodeLong(data, offset, value) {
  21745. data[offset] = (value >>> 24) & 0xFF;
  21746. data[offset + 1] = (value >> 16) & 0xFF;
  21747. data[offset + 2] = (value >> 8) & 0xFF;
  21748. data[offset + 3] = value & 0xFF;
  21749. };
  21750. } else {
  21751. itemSize = 2;
  21752. itemDecode = function fontItemDecode(data, offset) {
  21753. return (data[offset] << 9) | (data[offset + 1] << 1);
  21754. };
  21755. itemEncode = function fontItemEncode(data, offset, value) {
  21756. data[offset] = (value >> 9) & 0xFF;
  21757. data[offset + 1] = (value >> 1) & 0xFF;
  21758. };
  21759. }
  21760. var locaData = loca.data;
  21761. var locaDataSize = itemSize * (1 + numGlyphs);
  21762. // is loca.data too short or long?
  21763. if (locaData.length !== locaDataSize) {
  21764. locaData = new Uint8Array(locaDataSize);
  21765. locaData.set(loca.data.subarray(0, locaDataSize));
  21766. loca.data = locaData;
  21767. }
  21768. // removing the invalid glyphs
  21769. var oldGlyfData = glyf.data;
  21770. var oldGlyfDataLength = oldGlyfData.length;
  21771. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  21772. var startOffset = itemDecode(locaData, 0);
  21773. var writeOffset = 0;
  21774. itemEncode(locaData, 0, writeOffset);
  21775. var i, j;
  21776. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21777. var endOffset = itemDecode(locaData, j);
  21778. if (endOffset > oldGlyfDataLength &&
  21779. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  21780. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  21781. // the glyf table size, which makes last glyph out of range.
  21782. endOffset = oldGlyfDataLength;
  21783. }
  21784. if (endOffset > oldGlyfDataLength) {
  21785. // glyph end offset points outside glyf data, rejecting the glyph
  21786. itemEncode(locaData, j, writeOffset);
  21787. startOffset = endOffset;
  21788. continue;
  21789. }
  21790. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  21791. newGlyfData, writeOffset, hintsValid);
  21792. writeOffset += newLength;
  21793. itemEncode(locaData, j, writeOffset);
  21794. startOffset = endOffset;
  21795. }
  21796. if (writeOffset === 0) {
  21797. // glyf table cannot be empty -- redoing the glyf and loca tables
  21798. // to have single glyph with one point
  21799. var simpleGlyph = new Uint8Array(
  21800. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  21801. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21802. itemEncode(locaData, j, simpleGlyph.length);
  21803. }
  21804. glyf.data = simpleGlyph;
  21805. return;
  21806. }
  21807. if (dupFirstEntry) {
  21808. var firstEntryLength = itemDecode(locaData, itemSize);
  21809. if (newGlyfData.length > firstEntryLength + writeOffset) {
  21810. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  21811. } else {
  21812. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  21813. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  21814. }
  21815. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  21816. itemEncode(loca.data, locaData.length - itemSize,
  21817. writeOffset + firstEntryLength);
  21818. } else {
  21819. glyf.data = newGlyfData.subarray(0, writeOffset);
  21820. }
  21821. }
  21822. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  21823. var start = (font.start ? font.start : 0) + post.offset;
  21824. font.pos = start;
  21825. var length = post.length, end = start + length;
  21826. var version = font.getInt32();
  21827. // skip rest to the tables
  21828. font.getBytes(28);
  21829. var glyphNames;
  21830. var valid = true;
  21831. var i;
  21832. switch (version) {
  21833. case 0x00010000:
  21834. glyphNames = MacStandardGlyphOrdering;
  21835. break;
  21836. case 0x00020000:
  21837. var numGlyphs = font.getUint16();
  21838. if (numGlyphs !== maxpNumGlyphs) {
  21839. valid = false;
  21840. break;
  21841. }
  21842. var glyphNameIndexes = [];
  21843. for (i = 0; i < numGlyphs; ++i) {
  21844. var index = font.getUint16();
  21845. if (index >= 32768) {
  21846. valid = false;
  21847. break;
  21848. }
  21849. glyphNameIndexes.push(index);
  21850. }
  21851. if (!valid) {
  21852. break;
  21853. }
  21854. var customNames = [];
  21855. var strBuf = [];
  21856. while (font.pos < end) {
  21857. var stringLength = font.getByte();
  21858. strBuf.length = stringLength;
  21859. for (i = 0; i < stringLength; ++i) {
  21860. strBuf[i] = String.fromCharCode(font.getByte());
  21861. }
  21862. customNames.push(strBuf.join(''));
  21863. }
  21864. glyphNames = [];
  21865. for (i = 0; i < numGlyphs; ++i) {
  21866. var j = glyphNameIndexes[i];
  21867. if (j < 258) {
  21868. glyphNames.push(MacStandardGlyphOrdering[j]);
  21869. continue;
  21870. }
  21871. glyphNames.push(customNames[j - 258]);
  21872. }
  21873. break;
  21874. case 0x00030000:
  21875. break;
  21876. default:
  21877. warn('Unknown/unsupported post table version ' + version);
  21878. valid = false;
  21879. break;
  21880. }
  21881. properties.glyphNames = glyphNames;
  21882. return valid;
  21883. }
  21884. function readNameTable(nameTable) {
  21885. var start = (font.start ? font.start : 0) + nameTable.offset;
  21886. font.pos = start;
  21887. var names = [[], []];
  21888. var length = nameTable.length, end = start + length;
  21889. var format = font.getUint16();
  21890. var FORMAT_0_HEADER_LENGTH = 6;
  21891. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  21892. // unsupported name table format or table "too" small
  21893. return names;
  21894. }
  21895. var numRecords = font.getUint16();
  21896. var stringsStart = font.getUint16();
  21897. var records = [];
  21898. var NAME_RECORD_LENGTH = 12;
  21899. var i, ii;
  21900. for (i = 0; i < numRecords &&
  21901. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  21902. var r = {
  21903. platform: font.getUint16(),
  21904. encoding: font.getUint16(),
  21905. language: font.getUint16(),
  21906. name: font.getUint16(),
  21907. length: font.getUint16(),
  21908. offset: font.getUint16()
  21909. };
  21910. // using only Macintosh and Windows platform/encoding names
  21911. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  21912. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  21913. records.push(r);
  21914. }
  21915. }
  21916. for (i = 0, ii = records.length; i < ii; i++) {
  21917. var record = records[i];
  21918. var pos = start + stringsStart + record.offset;
  21919. if (pos + record.length > end) {
  21920. continue; // outside of name table, ignoring
  21921. }
  21922. font.pos = pos;
  21923. var nameIndex = record.name;
  21924. if (record.encoding) {
  21925. // unicode
  21926. var str = '';
  21927. for (var j = 0, jj = record.length; j < jj; j += 2) {
  21928. str += String.fromCharCode(font.getUint16());
  21929. }
  21930. names[1][nameIndex] = str;
  21931. } else {
  21932. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  21933. }
  21934. }
  21935. return names;
  21936. }
  21937. var TTOpsStackDeltas = [
  21938. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  21939. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  21940. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  21941. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  21942. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  21943. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  21944. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  21945. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  21946. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  21947. // 0xC0-DF == -1 and 0xE0-FF == -2
  21948. function sanitizeTTProgram(table, ttContext) {
  21949. var data = table.data;
  21950. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  21951. var stack = [];
  21952. var callstack = [];
  21953. var functionsCalled = [];
  21954. var tooComplexToFollowFunctions =
  21955. ttContext.tooComplexToFollowFunctions;
  21956. var inFDEF = false, ifLevel = 0, inELSE = 0;
  21957. for (var ii = data.length; i < ii;) {
  21958. var op = data[i++];
  21959. // The TrueType instruction set docs can be found at
  21960. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  21961. if (op === 0x40) { // NPUSHB - pushes n bytes
  21962. n = data[i++];
  21963. if (inFDEF || inELSE) {
  21964. i += n;
  21965. } else {
  21966. for (j = 0; j < n; j++) {
  21967. stack.push(data[i++]);
  21968. }
  21969. }
  21970. } else if (op === 0x41) { // NPUSHW - pushes n words
  21971. n = data[i++];
  21972. if (inFDEF || inELSE) {
  21973. i += n * 2;
  21974. } else {
  21975. for (j = 0; j < n; j++) {
  21976. b = data[i++];
  21977. stack.push((b << 8) | data[i++]);
  21978. }
  21979. }
  21980. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  21981. n = op - 0xB0 + 1;
  21982. if (inFDEF || inELSE) {
  21983. i += n;
  21984. } else {
  21985. for (j = 0; j < n; j++) {
  21986. stack.push(data[i++]);
  21987. }
  21988. }
  21989. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  21990. n = op - 0xB8 + 1;
  21991. if (inFDEF || inELSE) {
  21992. i += n * 2;
  21993. } else {
  21994. for (j = 0; j < n; j++) {
  21995. b = data[i++];
  21996. stack.push((b << 8) | data[i++]);
  21997. }
  21998. }
  21999. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  22000. if (!inFDEF && !inELSE) {
  22001. // collecting inforamtion about which functions are used
  22002. funcId = stack[stack.length - 1];
  22003. ttContext.functionsUsed[funcId] = true;
  22004. if (funcId in ttContext.functionsStackDeltas) {
  22005. stack.length += ttContext.functionsStackDeltas[funcId];
  22006. } else if (funcId in ttContext.functionsDefined &&
  22007. functionsCalled.indexOf(funcId) < 0) {
  22008. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  22009. functionsCalled.push(funcId);
  22010. pc = ttContext.functionsDefined[funcId];
  22011. if (!pc) {
  22012. warn('TT: CALL non-existent function');
  22013. ttContext.hintsValid = false;
  22014. return;
  22015. }
  22016. data = pc.data;
  22017. i = pc.i;
  22018. }
  22019. }
  22020. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  22021. if (inFDEF || inELSE) {
  22022. warn('TT: nested FDEFs not allowed');
  22023. tooComplexToFollowFunctions = true;
  22024. }
  22025. inFDEF = true;
  22026. // collecting inforamtion about which functions are defined
  22027. lastDeff = i;
  22028. funcId = stack.pop();
  22029. ttContext.functionsDefined[funcId] = {data: data, i: i};
  22030. } else if (op === 0x2D) { // ENDF - end of function
  22031. if (inFDEF) {
  22032. inFDEF = false;
  22033. lastEndf = i;
  22034. } else {
  22035. pc = callstack.pop();
  22036. if (!pc) {
  22037. warn('TT: ENDF bad stack');
  22038. ttContext.hintsValid = false;
  22039. return;
  22040. }
  22041. funcId = functionsCalled.pop();
  22042. data = pc.data;
  22043. i = pc.i;
  22044. ttContext.functionsStackDeltas[funcId] =
  22045. stack.length - pc.stackTop;
  22046. }
  22047. } else if (op === 0x89) { // IDEF - instruction definition
  22048. if (inFDEF || inELSE) {
  22049. warn('TT: nested IDEFs not allowed');
  22050. tooComplexToFollowFunctions = true;
  22051. }
  22052. inFDEF = true;
  22053. // recording it as a function to track ENDF
  22054. lastDeff = i;
  22055. } else if (op === 0x58) { // IF
  22056. ++ifLevel;
  22057. } else if (op === 0x1B) { // ELSE
  22058. inELSE = ifLevel;
  22059. } else if (op === 0x59) { // EIF
  22060. if (inELSE === ifLevel) {
  22061. inELSE = 0;
  22062. }
  22063. --ifLevel;
  22064. } else if (op === 0x1C) { // JMPR
  22065. if (!inFDEF && !inELSE) {
  22066. var offset = stack[stack.length - 1];
  22067. // only jumping forward to prevent infinite loop
  22068. if (offset > 0) {
  22069. i += offset - 1;
  22070. }
  22071. }
  22072. }
  22073. // Adjusting stack not extactly, but just enough to get function id
  22074. if (!inFDEF && !inELSE) {
  22075. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  22076. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  22077. if (op >= 0x71 && op <= 0x75) {
  22078. n = stack.pop();
  22079. if (n === n) {
  22080. stackDelta = -n * 2;
  22081. }
  22082. }
  22083. while (stackDelta < 0 && stack.length > 0) {
  22084. stack.pop();
  22085. stackDelta++;
  22086. }
  22087. while (stackDelta > 0) {
  22088. stack.push(NaN); // pushing any number into stack
  22089. stackDelta--;
  22090. }
  22091. }
  22092. }
  22093. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  22094. var content = [data];
  22095. if (i > data.length) {
  22096. content.push(new Uint8Array(i - data.length));
  22097. }
  22098. if (lastDeff > lastEndf) {
  22099. warn('TT: complementing a missing function tail');
  22100. // new function definition started, but not finished
  22101. // complete function by [CLEAR, ENDF]
  22102. content.push(new Uint8Array([0x22, 0x2D]));
  22103. }
  22104. foldTTTable(table, content);
  22105. }
  22106. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  22107. if (ttContext.tooComplexToFollowFunctions) {
  22108. return;
  22109. }
  22110. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  22111. warn('TT: more functions defined than expected');
  22112. ttContext.hintsValid = false;
  22113. return;
  22114. }
  22115. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  22116. if (j > maxFunctionDefs) {
  22117. warn('TT: invalid function id: ' + j);
  22118. ttContext.hintsValid = false;
  22119. return;
  22120. }
  22121. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  22122. warn('TT: undefined function: ' + j);
  22123. ttContext.hintsValid = false;
  22124. return;
  22125. }
  22126. }
  22127. }
  22128. function foldTTTable(table, content) {
  22129. if (content.length > 1) {
  22130. // concatenating the content items
  22131. var newLength = 0;
  22132. var j, jj;
  22133. for (j = 0, jj = content.length; j < jj; j++) {
  22134. newLength += content[j].length;
  22135. }
  22136. newLength = (newLength + 3) & ~3;
  22137. var result = new Uint8Array(newLength);
  22138. var pos = 0;
  22139. for (j = 0, jj = content.length; j < jj; j++) {
  22140. result.set(content[j], pos);
  22141. pos += content[j].length;
  22142. }
  22143. table.data = result;
  22144. table.length = newLength;
  22145. }
  22146. }
  22147. function sanitizeTTPrograms(fpgm, prep, cvt) {
  22148. var ttContext = {
  22149. functionsDefined: [],
  22150. functionsUsed: [],
  22151. functionsStackDeltas: [],
  22152. tooComplexToFollowFunctions: false,
  22153. hintsValid: true
  22154. };
  22155. if (fpgm) {
  22156. sanitizeTTProgram(fpgm, ttContext);
  22157. }
  22158. if (prep) {
  22159. sanitizeTTProgram(prep, ttContext);
  22160. }
  22161. if (fpgm) {
  22162. checkInvalidFunctions(ttContext, maxFunctionDefs);
  22163. }
  22164. if (cvt && (cvt.length & 1)) {
  22165. var cvtData = new Uint8Array(cvt.length + 1);
  22166. cvtData.set(cvt.data);
  22167. cvt.data = cvtData;
  22168. }
  22169. return ttContext.hintsValid;
  22170. }
  22171. // The following steps modify the original font data, making copy
  22172. font = new Stream(new Uint8Array(font.getBytes()));
  22173. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  22174. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  22175. var header = readOpenTypeHeader(font);
  22176. var numTables = header.numTables;
  22177. var cff, cffFile;
  22178. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  22179. hmtx: null, maxp: null, name: null, post: null };
  22180. var table;
  22181. for (var i = 0; i < numTables; i++) {
  22182. table = readTableEntry(font);
  22183. if (VALID_TABLES.indexOf(table.tag) < 0) {
  22184. continue; // skipping table if it's not a required or optional table
  22185. }
  22186. if (table.length === 0) {
  22187. continue; // skipping empty tables
  22188. }
  22189. tables[table.tag] = table;
  22190. }
  22191. var isTrueType = !tables['CFF '];
  22192. if (!isTrueType) {
  22193. // OpenType font
  22194. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  22195. // no major tables: throwing everything at CFFFont
  22196. cffFile = new Stream(tables['CFF '].data);
  22197. cff = new CFFFont(cffFile, properties);
  22198. return this.convert(name, cff, properties);
  22199. }
  22200. delete tables.glyf;
  22201. delete tables.loca;
  22202. delete tables.fpgm;
  22203. delete tables.prep;
  22204. delete tables['cvt '];
  22205. this.isOpenType = true;
  22206. } else {
  22207. if (!tables.glyf || !tables.loca) {
  22208. error('Required "glyf" or "loca" tables are not found');
  22209. }
  22210. this.isOpenType = false;
  22211. }
  22212. if (!tables.maxp) {
  22213. error('Required "maxp" table is not found');
  22214. }
  22215. font.pos = (font.start || 0) + tables.maxp.offset;
  22216. var version = font.getInt32();
  22217. var numGlyphs = font.getUint16();
  22218. var maxFunctionDefs = 0;
  22219. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  22220. // maxZones can be invalid
  22221. font.pos += 8;
  22222. var maxZones = font.getUint16();
  22223. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  22224. tables.maxp.data[14] = 0;
  22225. tables.maxp.data[15] = 2;
  22226. }
  22227. font.pos += 4;
  22228. maxFunctionDefs = font.getUint16();
  22229. }
  22230. var dupFirstEntry = false;
  22231. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  22232. properties.toUnicode.get(0) > '\u0000') {
  22233. // oracle's defect (see 3427), duplicating first entry
  22234. dupFirstEntry = true;
  22235. numGlyphs++;
  22236. tables.maxp.data[4] = numGlyphs >> 8;
  22237. tables.maxp.data[5] = numGlyphs & 255;
  22238. }
  22239. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  22240. tables['cvt '], maxFunctionDefs);
  22241. if (!hintsValid) {
  22242. delete tables.fpgm;
  22243. delete tables.prep;
  22244. delete tables['cvt '];
  22245. }
  22246. // Ensure the hmtx table contains the advance width and
  22247. // sidebearings information for numGlyphs in the maxp table
  22248. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  22249. if (!tables.head) {
  22250. error('Required "head" table is not found');
  22251. }
  22252. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  22253. if (isTrueType) {
  22254. var isGlyphLocationsLong = int16(tables.head.data[50],
  22255. tables.head.data[51]);
  22256. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  22257. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  22258. }
  22259. if (!tables.hhea) {
  22260. error('Required "hhea" table is not found');
  22261. }
  22262. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  22263. // Sometimes it's 0. That needs to be fixed
  22264. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  22265. tables.hhea.data[10] = 0xFF;
  22266. tables.hhea.data[11] = 0xFF;
  22267. }
  22268. // The 'post' table has glyphs names.
  22269. if (tables.post) {
  22270. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  22271. if (!valid) {
  22272. tables.post = null;
  22273. }
  22274. }
  22275. var charCodeToGlyphId = [], charCode;
  22276. if (properties.type === 'CIDFontType2') {
  22277. var cidToGidMap = properties.cidToGidMap || [];
  22278. var cidToGidMapLength = cidToGidMap.length;
  22279. properties.cMap.forEach(function(charCode, cid) {
  22280. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22281. var glyphId = -1;
  22282. if (cidToGidMapLength === 0) {
  22283. glyphId = charCode;
  22284. } else if (cidToGidMap[cid] !== undefined) {
  22285. glyphId = cidToGidMap[cid];
  22286. }
  22287. if (glyphId >= 0 && glyphId < numGlyphs) {
  22288. charCodeToGlyphId[charCode] = glyphId;
  22289. }
  22290. });
  22291. if (dupFirstEntry) {
  22292. charCodeToGlyphId[0] = numGlyphs - 1;
  22293. }
  22294. } else {
  22295. // Most of the following logic in this code branch is based on the
  22296. // 9.6.6.4 of the PDF spec.
  22297. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  22298. var cmapPlatformId = cmapTable.platformId;
  22299. var cmapEncodingId = cmapTable.encodingId;
  22300. var cmapMappings = cmapTable.mappings;
  22301. var cmapMappingsLength = cmapMappings.length;
  22302. var hasEncoding = properties.differences.length ||
  22303. !!properties.baseEncodingName;
  22304. // The spec seems to imply that if the font is symbolic the encoding
  22305. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  22306. // where the the font is symbolic and it has an encoding.
  22307. if (hasEncoding &&
  22308. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  22309. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  22310. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  22311. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  22312. // When no preferred cmap table was found and |baseEncodingName| is
  22313. // one of the predefined encodings, we seem to obtain a better
  22314. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  22315. // TODO: Note that this is a hack which should be removed as soon as
  22316. // we have proper support for more exotic cmap tables.
  22317. var baseEncoding = [];
  22318. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  22319. properties.baseEncodingName === 'WinAnsiEncoding') {
  22320. baseEncoding = Encodings[properties.baseEncodingName];
  22321. }
  22322. for (charCode = 0; charCode < 256; charCode++) {
  22323. var glyphName;
  22324. if (this.differences && charCode in this.differences) {
  22325. glyphName = this.differences[charCode];
  22326. } else if (charCode in baseEncoding &&
  22327. baseEncoding[charCode] !== '') {
  22328. glyphName = baseEncoding[charCode];
  22329. } else {
  22330. glyphName = Encodings.StandardEncoding[charCode];
  22331. }
  22332. if (!glyphName) {
  22333. continue;
  22334. }
  22335. var unicodeOrCharCode;
  22336. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  22337. unicodeOrCharCode = GlyphsUnicode[glyphName];
  22338. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  22339. // TODO: the encoding needs to be updated with mac os table.
  22340. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  22341. }
  22342. var found = false;
  22343. for (i = 0; i < cmapMappingsLength; ++i) {
  22344. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  22345. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22346. found = true;
  22347. break;
  22348. }
  22349. }
  22350. if (!found && properties.glyphNames) {
  22351. // Try to map using the post table. There are currently no known
  22352. // pdfs that this fixes.
  22353. var glyphId = properties.glyphNames.indexOf(glyphName);
  22354. if (glyphId > 0) {
  22355. charCodeToGlyphId[charCode] = glyphId;
  22356. }
  22357. }
  22358. }
  22359. } else {
  22360. // For (3, 0) cmap tables:
  22361. // The charcode key being stored in charCodeToGlyphId is the lower
  22362. // byte of the two-byte charcodes of the cmap table since according to
  22363. // the spec: 'each byte from the string shall be prepended with the
  22364. // high byte of the range [of charcodes in the cmap table], to form
  22365. // a two-byte character, which shall be used to select the
  22366. // associated glyph description from the subtable'.
  22367. //
  22368. // For (1, 0) cmap tables:
  22369. // 'single bytes from the string shall be used to look up the
  22370. // associated glyph descriptions from the subtable'. This means
  22371. // charcodes in the cmap will be single bytes, so no-op since
  22372. // glyph.charCode & 0xFF === glyph.charCode
  22373. for (i = 0; i < cmapMappingsLength; ++i) {
  22374. charCode = cmapMappings[i].charCode & 0xFF;
  22375. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22376. }
  22377. }
  22378. }
  22379. if (charCodeToGlyphId.length === 0) {
  22380. // defines at least one glyph
  22381. charCodeToGlyphId[0] = 0;
  22382. }
  22383. // Converting glyphs and ids into font's cmap table
  22384. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  22385. this.toFontChar = newMapping.toFontChar;
  22386. tables.cmap = {
  22387. tag: 'cmap',
  22388. data: createCmapTable(newMapping.charCodeToGlyphId)
  22389. };
  22390. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  22391. // extract some more font properties from the OpenType head and
  22392. // hhea tables; yMin and descent value are always negative
  22393. var override = {
  22394. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  22395. yMax: int16(tables.head.data[42], tables.head.data[43]),
  22396. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  22397. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  22398. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  22399. };
  22400. tables['OS/2'] = {
  22401. tag: 'OS/2',
  22402. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  22403. override)
  22404. };
  22405. }
  22406. // Rewrite the 'post' table if needed
  22407. if (!tables.post) {
  22408. tables.post = {
  22409. tag: 'post',
  22410. data: createPostTable(properties)
  22411. };
  22412. }
  22413. if (!isTrueType) {
  22414. try {
  22415. // Trying to repair CFF file
  22416. cffFile = new Stream(tables['CFF '].data);
  22417. var parser = new CFFParser(cffFile, properties);
  22418. cff = parser.parse();
  22419. var compiler = new CFFCompiler(cff);
  22420. tables['CFF '].data = compiler.compile();
  22421. } catch (e) {
  22422. warn('Failed to compile font ' + properties.loadedName);
  22423. }
  22424. }
  22425. // Re-creating 'name' table
  22426. if (!tables.name) {
  22427. tables.name = {
  22428. tag: 'name',
  22429. data: createNameTable(this.name)
  22430. };
  22431. } else {
  22432. // ... using existing 'name' table as prototype
  22433. var namePrototype = readNameTable(tables.name);
  22434. tables.name.data = createNameTable(name, namePrototype);
  22435. }
  22436. var builder = new OpenTypeFileBuilder(header.version);
  22437. for (var tableTag in tables) {
  22438. builder.addTable(tableTag, tables[tableTag].data);
  22439. }
  22440. return builder.toArray();
  22441. },
  22442. convert: function Font_convert(fontName, font, properties) {
  22443. // TODO: Check the charstring widths to determine this.
  22444. properties.fixedPitch = false;
  22445. var mapping = font.getGlyphMapping(properties);
  22446. var newMapping = adjustMapping(mapping, properties);
  22447. this.toFontChar = newMapping.toFontChar;
  22448. var numGlyphs = font.numGlyphs;
  22449. function getCharCodes(charCodeToGlyphId, glyphId) {
  22450. var charCodes = null;
  22451. for (var charCode in charCodeToGlyphId) {
  22452. if (glyphId === charCodeToGlyphId[charCode]) {
  22453. if (!charCodes) {
  22454. charCodes = [];
  22455. }
  22456. charCodes.push(charCode | 0);
  22457. }
  22458. }
  22459. return charCodes;
  22460. }
  22461. function createCharCode(charCodeToGlyphId, glyphId) {
  22462. for (var charCode in charCodeToGlyphId) {
  22463. if (glyphId === charCodeToGlyphId[charCode]) {
  22464. return charCode | 0;
  22465. }
  22466. }
  22467. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  22468. glyphId;
  22469. return newMapping.nextAvailableFontCharCode++;
  22470. }
  22471. var seacs = font.seacs;
  22472. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  22473. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  22474. var charset = font.getCharset();
  22475. var seacMap = Object.create(null);
  22476. for (var glyphId in seacs) {
  22477. glyphId |= 0;
  22478. var seac = seacs[glyphId];
  22479. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  22480. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  22481. var baseGlyphId = charset.indexOf(baseGlyphName);
  22482. var accentGlyphId = charset.indexOf(accentGlyphName);
  22483. if (baseGlyphId < 0 || accentGlyphId < 0) {
  22484. continue;
  22485. }
  22486. var accentOffset = {
  22487. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  22488. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  22489. };
  22490. var charCodes = getCharCodes(mapping, glyphId);
  22491. if (!charCodes) {
  22492. // There's no point in mapping it if the char code was never mapped
  22493. // to begin with.
  22494. continue;
  22495. }
  22496. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  22497. var charCode = charCodes[i];
  22498. // Find a fontCharCode that maps to the base and accent glyphs.
  22499. // If one doesn't exists, create it.
  22500. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  22501. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  22502. baseGlyphId);
  22503. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  22504. accentGlyphId);
  22505. seacMap[charCode] = {
  22506. baseFontCharCode: baseFontCharCode,
  22507. accentFontCharCode: accentFontCharCode,
  22508. accentOffset: accentOffset
  22509. };
  22510. }
  22511. }
  22512. properties.seacMap = seacMap;
  22513. }
  22514. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  22515. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  22516. // PostScript Font Program
  22517. builder.addTable('CFF ', font.data);
  22518. // OS/2 and Windows Specific metrics
  22519. builder.addTable('OS/2', createOS2Table(properties,
  22520. newMapping.charCodeToGlyphId));
  22521. // Character to glyphs mapping
  22522. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  22523. // Font header
  22524. builder.addTable('head',
  22525. '\x00\x01\x00\x00' + // Version number
  22526. '\x00\x00\x10\x00' + // fontRevision
  22527. '\x00\x00\x00\x00' + // checksumAdjustement
  22528. '\x5F\x0F\x3C\xF5' + // magicNumber
  22529. '\x00\x00' + // Flags
  22530. safeString16(unitsPerEm) + // unitsPerEM
  22531. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  22532. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  22533. '\x00\x00' + // xMin
  22534. safeString16(properties.descent) + // yMin
  22535. '\x0F\xFF' + // xMax
  22536. safeString16(properties.ascent) + // yMax
  22537. string16(properties.italicAngle ? 2 : 0) + // macStyle
  22538. '\x00\x11' + // lowestRecPPEM
  22539. '\x00\x00' + // fontDirectionHint
  22540. '\x00\x00' + // indexToLocFormat
  22541. '\x00\x00'); // glyphDataFormat
  22542. // Horizontal header
  22543. builder.addTable('hhea',
  22544. '\x00\x01\x00\x00' + // Version number
  22545. safeString16(properties.ascent) + // Typographic Ascent
  22546. safeString16(properties.descent) + // Typographic Descent
  22547. '\x00\x00' + // Line Gap
  22548. '\xFF\xFF' + // advanceWidthMax
  22549. '\x00\x00' + // minLeftSidebearing
  22550. '\x00\x00' + // minRightSidebearing
  22551. '\x00\x00' + // xMaxExtent
  22552. safeString16(properties.capHeight) + // caretSlopeRise
  22553. safeString16(Math.tan(properties.italicAngle) *
  22554. properties.xHeight) + // caretSlopeRun
  22555. '\x00\x00' + // caretOffset
  22556. '\x00\x00' + // -reserved-
  22557. '\x00\x00' + // -reserved-
  22558. '\x00\x00' + // -reserved-
  22559. '\x00\x00' + // -reserved-
  22560. '\x00\x00' + // metricDataFormat
  22561. string16(numGlyphs)); // Number of HMetrics
  22562. // Horizontal metrics
  22563. builder.addTable('hmtx', (function fontFieldsHmtx() {
  22564. var charstrings = font.charstrings;
  22565. var cffWidths = font.cff ? font.cff.widths : null;
  22566. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  22567. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  22568. var width = 0;
  22569. if (charstrings) {
  22570. var charstring = charstrings[i - 1];
  22571. width = 'width' in charstring ? charstring.width : 0;
  22572. } else if (cffWidths) {
  22573. width = Math.ceil(cffWidths[i] || 0);
  22574. }
  22575. hmtx += string16(width) + string16(0);
  22576. }
  22577. return hmtx;
  22578. })());
  22579. // Maximum profile
  22580. builder.addTable('maxp',
  22581. '\x00\x00\x50\x00' + // Version number
  22582. string16(numGlyphs)); // Num of glyphs
  22583. // Naming tables
  22584. builder.addTable('name', createNameTable(fontName));
  22585. // PostScript informations
  22586. builder.addTable('post', createPostTable(properties));
  22587. return builder.toArray();
  22588. },
  22589. /**
  22590. * Builds a char code to unicode map based on section 9.10 of the spec.
  22591. * @param {Object} properties Font properties object.
  22592. * @return {Object} A ToUnicodeMap object.
  22593. */
  22594. buildToUnicode: function Font_buildToUnicode(properties) {
  22595. // Section 9.10.2 Mapping Character Codes to Unicode Values
  22596. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  22597. return properties.toUnicode;
  22598. }
  22599. // According to the spec if the font is a simple font we should only map
  22600. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  22601. // the differences array only contains adobe standard or symbol set names,
  22602. // in pratice it seems better to always try to create a toUnicode
  22603. // map based of the default encoding.
  22604. var toUnicode, charcode;
  22605. if (!properties.composite /* is simple font */) {
  22606. toUnicode = [];
  22607. var encoding = properties.defaultEncoding.slice();
  22608. var baseEncodingName = properties.baseEncodingName;
  22609. // Merge in the differences array.
  22610. var differences = properties.differences;
  22611. for (charcode in differences) {
  22612. encoding[charcode] = differences[charcode];
  22613. }
  22614. for (charcode in encoding) {
  22615. // a) Map the character code to a character name.
  22616. var glyphName = encoding[charcode];
  22617. // b) Look up the character name in the Adobe Glyph List (see the
  22618. // Bibliography) to obtain the corresponding Unicode value.
  22619. if (glyphName === '') {
  22620. continue;
  22621. } else if (GlyphsUnicode[glyphName] === undefined) {
  22622. // (undocumented) c) Few heuristics to recognize unknown glyphs
  22623. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  22624. var code = 0;
  22625. switch (glyphName[0]) {
  22626. case 'G': // Gxx glyph
  22627. if (glyphName.length === 3) {
  22628. code = parseInt(glyphName.substr(1), 16);
  22629. }
  22630. break;
  22631. case 'g': // g00xx glyph
  22632. if (glyphName.length === 5) {
  22633. code = parseInt(glyphName.substr(1), 16);
  22634. }
  22635. break;
  22636. case 'C': // Cddd glyph
  22637. case 'c': // cddd glyph
  22638. if (glyphName.length >= 3) {
  22639. code = +glyphName.substr(1);
  22640. }
  22641. break;
  22642. }
  22643. if (code) {
  22644. // If |baseEncodingName| is one the predefined encodings,
  22645. // and |code| equals |charcode|, using the glyph defined in the
  22646. // baseEncoding seems to yield a better |toUnicode| mapping
  22647. // (fixes issue 5070).
  22648. if (baseEncodingName && code === +charcode) {
  22649. var baseEncoding = Encodings[baseEncodingName];
  22650. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  22651. toUnicode[charcode] =
  22652. String.fromCharCode(GlyphsUnicode[glyphName]);
  22653. continue;
  22654. }
  22655. }
  22656. toUnicode[charcode] = String.fromCharCode(code);
  22657. }
  22658. continue;
  22659. }
  22660. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  22661. }
  22662. return new ToUnicodeMap(toUnicode);
  22663. }
  22664. // If the font is a composite font that uses one of the predefined CMaps
  22665. // listed in Table 118 (except Identity–H and Identity–V) or whose
  22666. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  22667. // Adobe-Korea1 character collection:
  22668. if (properties.composite && (
  22669. (properties.cMap.builtInCMap &&
  22670. !(properties.cMap instanceof IdentityCMap)) ||
  22671. (properties.cidSystemInfo.registry === 'Adobe' &&
  22672. (properties.cidSystemInfo.ordering === 'GB1' ||
  22673. properties.cidSystemInfo.ordering === 'CNS1' ||
  22674. properties.cidSystemInfo.ordering === 'Japan1' ||
  22675. properties.cidSystemInfo.ordering === 'Korea1')))) {
  22676. // Then:
  22677. // a) Map the character code to a character identifier (CID) according
  22678. // to the font’s CMap.
  22679. // b) Obtain the registry and ordering of the character collection used
  22680. // by the font’s CMap (for example, Adobe and Japan1) from its
  22681. // CIDSystemInfo dictionary.
  22682. var registry = properties.cidSystemInfo.registry;
  22683. var ordering = properties.cidSystemInfo.ordering;
  22684. // c) Construct a second CMap name by concatenating the registry and
  22685. // ordering obtained in step (b) in the format registry–ordering–UCS2
  22686. // (for example, Adobe–Japan1–UCS2).
  22687. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  22688. // d) Obtain the CMap with the name constructed in step (c) (available
  22689. // from the ASN Web site; see the Bibliography).
  22690. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  22691. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  22692. var cMap = properties.cMap;
  22693. toUnicode = [];
  22694. cMap.forEach(function(charcode, cid) {
  22695. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22696. // e) Map the CID obtained in step (a) according to the CMap obtained
  22697. // in step (d), producing a Unicode value.
  22698. var ucs2 = ucs2CMap.lookup(cid);
  22699. if (ucs2) {
  22700. toUnicode[charcode] =
  22701. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  22702. ucs2.charCodeAt(1));
  22703. }
  22704. });
  22705. return new ToUnicodeMap(toUnicode);
  22706. }
  22707. // The viewer's choice, just use an identity map.
  22708. return new IdentityToUnicodeMap(properties.firstChar,
  22709. properties.lastChar);
  22710. },
  22711. get spaceWidth() {
  22712. if ('_shadowWidth' in this) {
  22713. return this._shadowWidth;
  22714. }
  22715. // trying to estimate space character width
  22716. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  22717. var width;
  22718. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  22719. var glyphName = possibleSpaceReplacements[i];
  22720. // if possible, getting width by glyph name
  22721. if (glyphName in this.widths) {
  22722. width = this.widths[glyphName];
  22723. break;
  22724. }
  22725. var glyphUnicode = GlyphsUnicode[glyphName];
  22726. // finding the charcode via unicodeToCID map
  22727. var charcode = 0;
  22728. if (this.composite) {
  22729. if (this.cMap.contains(glyphUnicode)) {
  22730. charcode = this.cMap.lookup(glyphUnicode);
  22731. }
  22732. }
  22733. // ... via toUnicode map
  22734. if (!charcode && 'toUnicode' in this) {
  22735. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  22736. }
  22737. // setting it to unicode if negative or undefined
  22738. if (charcode <= 0) {
  22739. charcode = glyphUnicode;
  22740. }
  22741. // trying to get width via charcode
  22742. width = this.widths[charcode];
  22743. if (width) {
  22744. break; // the non-zero width found
  22745. }
  22746. }
  22747. width = width || this.defaultWidth;
  22748. // Do not shadow the property here. See discussion:
  22749. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  22750. this._shadowWidth = width;
  22751. return width;
  22752. },
  22753. charToGlyph: function Font_charToGlyph(charcode) {
  22754. var fontCharCode, width, operatorListId;
  22755. var widthCode = charcode;
  22756. if (this.cMap && this.cMap.contains(charcode)) {
  22757. widthCode = this.cMap.lookup(charcode);
  22758. }
  22759. width = this.widths[widthCode];
  22760. width = isNum(width) ? width : this.defaultWidth;
  22761. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  22762. var unicode = this.toUnicode.get(charcode) || charcode;
  22763. if (typeof unicode === 'number') {
  22764. unicode = String.fromCharCode(unicode);
  22765. }
  22766. // First try the toFontChar map, if it's not there then try falling
  22767. // back to the char code.
  22768. fontCharCode = this.toFontChar[charcode] || charcode;
  22769. if (this.missingFile) {
  22770. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  22771. }
  22772. if (this.isType3Font) {
  22773. // Font char code in this case is actually a glyph name.
  22774. operatorListId = fontCharCode;
  22775. }
  22776. var accent = null;
  22777. if (this.seacMap && this.seacMap[charcode]) {
  22778. var seac = this.seacMap[charcode];
  22779. fontCharCode = seac.baseFontCharCode;
  22780. accent = {
  22781. fontChar: String.fromCharCode(seac.accentFontCharCode),
  22782. offset: seac.accentOffset
  22783. };
  22784. }
  22785. var fontChar = String.fromCharCode(fontCharCode);
  22786. var glyph = this.glyphCache[charcode];
  22787. if (!glyph ||
  22788. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  22789. operatorListId)) {
  22790. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  22791. operatorListId);
  22792. this.glyphCache[charcode] = glyph;
  22793. }
  22794. return glyph;
  22795. },
  22796. charsToGlyphs: function Font_charsToGlyphs(chars) {
  22797. var charsCache = this.charsCache;
  22798. var glyphs, glyph, charcode;
  22799. // if we translated this string before, just grab it from the cache
  22800. if (charsCache) {
  22801. glyphs = charsCache[chars];
  22802. if (glyphs) {
  22803. return glyphs;
  22804. }
  22805. }
  22806. // lazily create the translation cache
  22807. if (!charsCache) {
  22808. charsCache = this.charsCache = Object.create(null);
  22809. }
  22810. glyphs = [];
  22811. var charsCacheKey = chars;
  22812. var i = 0, ii;
  22813. if (this.cMap) {
  22814. // composite fonts have multi-byte strings convert the string from
  22815. // single-byte to multi-byte
  22816. var c = {};
  22817. while (i < chars.length) {
  22818. this.cMap.readCharCode(chars, i, c);
  22819. charcode = c.charcode;
  22820. var length = c.length;
  22821. i += length;
  22822. glyph = this.charToGlyph(charcode);
  22823. glyphs.push(glyph);
  22824. // placing null after each word break charcode (ASCII SPACE)
  22825. // Ignore occurences of 0x20 in multiple-byte codes.
  22826. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  22827. glyphs.push(null);
  22828. }
  22829. }
  22830. } else {
  22831. for (i = 0, ii = chars.length; i < ii; ++i) {
  22832. charcode = chars.charCodeAt(i);
  22833. glyph = this.charToGlyph(charcode);
  22834. glyphs.push(glyph);
  22835. if (charcode === 0x20) {
  22836. glyphs.push(null);
  22837. }
  22838. }
  22839. }
  22840. // Enter the translated string into the cache
  22841. return (charsCache[charsCacheKey] = glyphs);
  22842. }
  22843. };
  22844. return Font;
  22845. })();
  22846. var ErrorFont = (function ErrorFontClosure() {
  22847. function ErrorFont(error) {
  22848. this.error = error;
  22849. this.loadedName = 'g_font_error';
  22850. this.loading = false;
  22851. }
  22852. ErrorFont.prototype = {
  22853. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  22854. return [];
  22855. },
  22856. exportData: function ErrorFont_exportData() {
  22857. return {error: this.error};
  22858. }
  22859. };
  22860. return ErrorFont;
  22861. })();
  22862. /**
  22863. * Shared logic for building a char code to glyph id mapping for Type1 and
  22864. * simple CFF fonts. See section 9.6.6.2 of the spec.
  22865. * @param {Object} properties Font properties object.
  22866. * @param {Object} builtInEncoding The encoding contained within the actual font
  22867. * data.
  22868. * @param {Array} Array of glyph names where the index is the glyph ID.
  22869. * @returns {Object} A char code to glyph ID map.
  22870. */
  22871. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  22872. var charCodeToGlyphId = Object.create(null);
  22873. var glyphId, charCode, baseEncoding;
  22874. if (properties.baseEncodingName) {
  22875. // If a valid base encoding name was used, the mapping is initialized with
  22876. // that.
  22877. baseEncoding = Encodings[properties.baseEncodingName];
  22878. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22879. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22880. if (glyphId >= 0) {
  22881. charCodeToGlyphId[charCode] = glyphId;
  22882. } else {
  22883. charCodeToGlyphId[charCode] = 0; // notdef
  22884. }
  22885. }
  22886. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  22887. // For a symbolic font the encoding should be the fonts built-in
  22888. // encoding.
  22889. for (charCode in builtInEncoding) {
  22890. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  22891. }
  22892. } else {
  22893. // For non-symbolic fonts that don't have a base encoding the standard
  22894. // encoding should be used.
  22895. baseEncoding = Encodings.StandardEncoding;
  22896. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22897. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22898. if (glyphId >= 0) {
  22899. charCodeToGlyphId[charCode] = glyphId;
  22900. } else {
  22901. charCodeToGlyphId[charCode] = 0; // notdef
  22902. }
  22903. }
  22904. }
  22905. // Lastly, merge in the differences.
  22906. var differences = properties.differences;
  22907. if (differences) {
  22908. for (charCode in differences) {
  22909. var glyphName = differences[charCode];
  22910. glyphId = glyphNames.indexOf(glyphName);
  22911. if (glyphId >= 0) {
  22912. charCodeToGlyphId[charCode] = glyphId;
  22913. } else {
  22914. charCodeToGlyphId[charCode] = 0; // notdef
  22915. }
  22916. }
  22917. }
  22918. return charCodeToGlyphId;
  22919. }
  22920. /*
  22921. * CharStrings are encoded following the the CharString Encoding sequence
  22922. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  22923. * The value in a byte indicates a command, a number, or subsequent bytes
  22924. * that are to be interpreted in a special way.
  22925. *
  22926. * CharString Number Encoding:
  22927. * A CharString byte containing the values from 32 through 255 inclusive
  22928. * indicate an integer. These values are decoded in four ranges.
  22929. *
  22930. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  22931. * indicate the integer v - 139. Thus, the integer values from -107 through
  22932. * 107 inclusive may be encoded in single byte.
  22933. *
  22934. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  22935. * indicates an integer involving the next byte, w, according to the formula:
  22936. * [(v - 247) x 256] + w + 108
  22937. *
  22938. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  22939. * indicates an integer involving the next byte, w, according to the formula:
  22940. * -[(v - 251) * 256] - w - 108
  22941. *
  22942. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  22943. * are a two complement signed integer. The first of these bytes contains the
  22944. * highest order bits, the second byte contains the next higher order bits
  22945. * and the fourth byte contain the lowest order bits.
  22946. *
  22947. *
  22948. * CharString Command Encoding:
  22949. * CharStrings commands are encoded in 1 or 2 bytes.
  22950. *
  22951. * Single byte commands are encoded in 1 byte that contains a value between
  22952. * 0 and 31 inclusive.
  22953. * If a command byte contains the value 12, then the value in the next byte
  22954. * indicates a command. This "escape" mechanism allows many extra commands
  22955. * to be encoded and this encoding technique helps to minimize the length of
  22956. * the charStrings.
  22957. */
  22958. var Type1CharString = (function Type1CharStringClosure() {
  22959. var COMMAND_MAP = {
  22960. 'hstem': [1],
  22961. 'vstem': [3],
  22962. 'vmoveto': [4],
  22963. 'rlineto': [5],
  22964. 'hlineto': [6],
  22965. 'vlineto': [7],
  22966. 'rrcurveto': [8],
  22967. 'callsubr': [10],
  22968. 'flex': [12, 35],
  22969. 'drop' : [12, 18],
  22970. 'endchar': [14],
  22971. 'rmoveto': [21],
  22972. 'hmoveto': [22],
  22973. 'vhcurveto': [30],
  22974. 'hvcurveto': [31]
  22975. };
  22976. function Type1CharString() {
  22977. this.width = 0;
  22978. this.lsb = 0;
  22979. this.flexing = false;
  22980. this.output = [];
  22981. this.stack = [];
  22982. }
  22983. Type1CharString.prototype = {
  22984. convert: function Type1CharString_convert(encoded, subrs) {
  22985. var count = encoded.length;
  22986. var error = false;
  22987. var wx, sbx, subrNumber;
  22988. for (var i = 0; i < count; i++) {
  22989. var value = encoded[i];
  22990. if (value < 32) {
  22991. if (value === 12) {
  22992. value = (value << 8) + encoded[++i];
  22993. }
  22994. switch (value) {
  22995. case 1: // hstem
  22996. if (!HINTING_ENABLED) {
  22997. this.stack = [];
  22998. break;
  22999. }
  23000. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23001. break;
  23002. case 3: // vstem
  23003. if (!HINTING_ENABLED) {
  23004. this.stack = [];
  23005. break;
  23006. }
  23007. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23008. break;
  23009. case 4: // vmoveto
  23010. if (this.flexing) {
  23011. if (this.stack.length < 1) {
  23012. error = true;
  23013. break;
  23014. }
  23015. // Add the dx for flex and but also swap the values so they are
  23016. // the right order.
  23017. var dy = this.stack.pop();
  23018. this.stack.push(0, dy);
  23019. break;
  23020. }
  23021. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  23022. break;
  23023. case 5: // rlineto
  23024. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  23025. break;
  23026. case 6: // hlineto
  23027. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  23028. break;
  23029. case 7: // vlineto
  23030. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  23031. break;
  23032. case 8: // rrcurveto
  23033. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  23034. break;
  23035. case 9: // closepath
  23036. // closepath is a Type1 command that does not take argument and is
  23037. // useless in Type2 and it can simply be ignored.
  23038. this.stack = [];
  23039. break;
  23040. case 10: // callsubr
  23041. if (this.stack.length < 1) {
  23042. error = true;
  23043. break;
  23044. }
  23045. subrNumber = this.stack.pop();
  23046. error = this.convert(subrs[subrNumber], subrs);
  23047. break;
  23048. case 11: // return
  23049. return error;
  23050. case 13: // hsbw
  23051. if (this.stack.length < 2) {
  23052. error = true;
  23053. break;
  23054. }
  23055. // To convert to type2 we have to move the width value to the
  23056. // first part of the charstring and then use hmoveto with lsb.
  23057. wx = this.stack.pop();
  23058. sbx = this.stack.pop();
  23059. this.lsb = sbx;
  23060. this.width = wx;
  23061. this.stack.push(wx, sbx);
  23062. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  23063. break;
  23064. case 14: // endchar
  23065. this.output.push(COMMAND_MAP.endchar[0]);
  23066. break;
  23067. case 21: // rmoveto
  23068. if (this.flexing) {
  23069. break;
  23070. }
  23071. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  23072. break;
  23073. case 22: // hmoveto
  23074. if (this.flexing) {
  23075. // Add the dy for flex.
  23076. this.stack.push(0);
  23077. break;
  23078. }
  23079. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  23080. break;
  23081. case 30: // vhcurveto
  23082. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  23083. break;
  23084. case 31: // hvcurveto
  23085. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  23086. break;
  23087. case (12 << 8) + 0: // dotsection
  23088. // dotsection is a Type1 command to specify some hinting feature
  23089. // for dots that do not take a parameter and it can safely be
  23090. // ignored for Type2.
  23091. this.stack = [];
  23092. break;
  23093. case (12 << 8) + 1: // vstem3
  23094. if (!HINTING_ENABLED) {
  23095. this.stack = [];
  23096. break;
  23097. }
  23098. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  23099. // multiple parameters, so instead of returning [vh]stem3 take a
  23100. // shortcut and return [vhstem] instead.
  23101. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23102. break;
  23103. case (12 << 8) + 2: // hstem3
  23104. if (!HINTING_ENABLED) {
  23105. this.stack = [];
  23106. break;
  23107. }
  23108. // See vstem3.
  23109. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23110. break;
  23111. case (12 << 8) + 6: // seac
  23112. // seac is like type 2's special endchar but it doesn't use the
  23113. // first argument asb, so remove it.
  23114. if (SEAC_ANALYSIS_ENABLED) {
  23115. this.seac = this.stack.splice(-4, 4);
  23116. error = this.executeCommand(0, COMMAND_MAP.endchar);
  23117. } else {
  23118. error = this.executeCommand(4, COMMAND_MAP.endchar);
  23119. }
  23120. break;
  23121. case (12 << 8) + 7: // sbw
  23122. if (this.stack.length < 4) {
  23123. error = true;
  23124. break;
  23125. }
  23126. // To convert to type2 we have to move the width value to the
  23127. // first part of the charstring and then use rmoveto with
  23128. // (dx, dy). The height argument will not be used for vmtx and
  23129. // vhea tables reconstruction -- ignoring it.
  23130. var wy = this.stack.pop();
  23131. wx = this.stack.pop();
  23132. var sby = this.stack.pop();
  23133. sbx = this.stack.pop();
  23134. this.lsb = sbx;
  23135. this.width = wx;
  23136. this.stack.push(wx, sbx, sby);
  23137. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  23138. break;
  23139. case (12 << 8) + 12: // div
  23140. if (this.stack.length < 2) {
  23141. error = true;
  23142. break;
  23143. }
  23144. var num2 = this.stack.pop();
  23145. var num1 = this.stack.pop();
  23146. this.stack.push(num1 / num2);
  23147. break;
  23148. case (12 << 8) + 16: // callothersubr
  23149. if (this.stack.length < 2) {
  23150. error = true;
  23151. break;
  23152. }
  23153. subrNumber = this.stack.pop();
  23154. var numArgs = this.stack.pop();
  23155. if (subrNumber === 0 && numArgs === 3) {
  23156. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  23157. this.stack.push(
  23158. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  23159. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  23160. flexArgs[4], // bcp2x
  23161. flexArgs[5], // bcp2y
  23162. flexArgs[6], // p2x
  23163. flexArgs[7], // p2y
  23164. flexArgs[8], // bcp3x
  23165. flexArgs[9], // bcp3y
  23166. flexArgs[10], // bcp4x
  23167. flexArgs[11], // bcp4y
  23168. flexArgs[12], // p3x
  23169. flexArgs[13], // p3y
  23170. flexArgs[14] // flexDepth
  23171. // 15 = finalx unused by flex
  23172. // 16 = finaly unused by flex
  23173. );
  23174. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  23175. this.flexing = false;
  23176. this.stack.push(flexArgs[15], flexArgs[16]);
  23177. } else if (subrNumber === 1 && numArgs === 0) {
  23178. this.flexing = true;
  23179. }
  23180. break;
  23181. case (12 << 8) + 17: // pop
  23182. // Ignore this since it is only used with othersubr.
  23183. break;
  23184. case (12 << 8) + 33: // setcurrentpoint
  23185. // Ignore for now.
  23186. this.stack = [];
  23187. break;
  23188. default:
  23189. warn('Unknown type 1 charstring command of "' + value + '"');
  23190. break;
  23191. }
  23192. if (error) {
  23193. break;
  23194. }
  23195. continue;
  23196. } else if (value <= 246) {
  23197. value = value - 139;
  23198. } else if (value <= 250) {
  23199. value = ((value - 247) * 256) + encoded[++i] + 108;
  23200. } else if (value <= 254) {
  23201. value = -((value - 251) * 256) - encoded[++i] - 108;
  23202. } else {
  23203. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  23204. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  23205. }
  23206. this.stack.push(value);
  23207. }
  23208. return error;
  23209. },
  23210. executeCommand: function(howManyArgs, command, keepStack) {
  23211. var stackLength = this.stack.length;
  23212. if (howManyArgs > stackLength) {
  23213. return true;
  23214. }
  23215. var start = stackLength - howManyArgs;
  23216. for (var i = start; i < stackLength; i++) {
  23217. var value = this.stack[i];
  23218. if (value === (value | 0)) { // int
  23219. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  23220. } else { // fixed point
  23221. value = (65536 * value) | 0;
  23222. this.output.push(255,
  23223. (value >> 24) & 0xFF,
  23224. (value >> 16) & 0xFF,
  23225. (value >> 8) & 0xFF,
  23226. value & 0xFF);
  23227. }
  23228. }
  23229. this.output.push.apply(this.output, command);
  23230. if (keepStack) {
  23231. this.stack.splice(start, howManyArgs);
  23232. } else {
  23233. this.stack.length = 0;
  23234. }
  23235. return false;
  23236. }
  23237. };
  23238. return Type1CharString;
  23239. })();
  23240. /*
  23241. * Type1Parser encapsulate the needed code for parsing a Type1 font
  23242. * program. Some of its logic depends on the Type2 charstrings
  23243. * structure.
  23244. * Note: this doesn't really parse the font since that would require evaluation
  23245. * of PostScript, but it is possible in most cases to extract what we need
  23246. * without a full parse.
  23247. */
  23248. var Type1Parser = (function Type1ParserClosure() {
  23249. /*
  23250. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  23251. * of Plaintext Bytes. The function took a key as a parameter which can be
  23252. * for decrypting the eexec block of for decoding charStrings.
  23253. */
  23254. var EEXEC_ENCRYPT_KEY = 55665;
  23255. var CHAR_STRS_ENCRYPT_KEY = 4330;
  23256. function isHexDigit(code) {
  23257. return code >= 48 && code <= 57 || // '0'-'9'
  23258. code >= 65 && code <= 70 || // 'A'-'F'
  23259. code >= 97 && code <= 102; // 'a'-'f'
  23260. }
  23261. function decrypt(data, key, discardNumber) {
  23262. var r = key | 0, c1 = 52845, c2 = 22719;
  23263. var count = data.length;
  23264. var decrypted = new Uint8Array(count);
  23265. for (var i = 0; i < count; i++) {
  23266. var value = data[i];
  23267. decrypted[i] = value ^ (r >> 8);
  23268. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23269. }
  23270. return Array.prototype.slice.call(decrypted, discardNumber);
  23271. }
  23272. function decryptAscii(data, key, discardNumber) {
  23273. var r = key | 0, c1 = 52845, c2 = 22719;
  23274. var count = data.length, maybeLength = count >>> 1;
  23275. var decrypted = new Uint8Array(maybeLength);
  23276. var i, j;
  23277. for (i = 0, j = 0; i < count; i++) {
  23278. var digit1 = data[i];
  23279. if (!isHexDigit(digit1)) {
  23280. continue;
  23281. }
  23282. i++;
  23283. var digit2;
  23284. while (i < count && !isHexDigit(digit2 = data[i])) {
  23285. i++;
  23286. }
  23287. if (i < count) {
  23288. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  23289. decrypted[j++] = value ^ (r >> 8);
  23290. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23291. }
  23292. }
  23293. return Array.prototype.slice.call(decrypted, discardNumber, j);
  23294. }
  23295. function isSpecial(c) {
  23296. return c === 0x2F || // '/'
  23297. c === 0x5B || c === 0x5D || // '[', ']'
  23298. c === 0x7B || c === 0x7D || // '{', '}'
  23299. c === 0x28 || c === 0x29; // '(', ')'
  23300. }
  23301. function Type1Parser(stream, encrypted) {
  23302. if (encrypted) {
  23303. var data = stream.getBytes();
  23304. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  23305. isHexDigit(data[2]) && isHexDigit(data[3]));
  23306. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  23307. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  23308. }
  23309. this.stream = stream;
  23310. this.nextChar();
  23311. }
  23312. Type1Parser.prototype = {
  23313. readNumberArray: function Type1Parser_readNumberArray() {
  23314. this.getToken(); // read '[' or '{' (arrays can start with either)
  23315. var array = [];
  23316. while (true) {
  23317. var token = this.getToken();
  23318. if (token === null || token === ']' || token === '}') {
  23319. break;
  23320. }
  23321. array.push(parseFloat(token || 0));
  23322. }
  23323. return array;
  23324. },
  23325. readNumber: function Type1Parser_readNumber() {
  23326. var token = this.getToken();
  23327. return parseFloat(token || 0);
  23328. },
  23329. readInt: function Type1Parser_readInt() {
  23330. // Use '| 0' to prevent setting a double into length such as the double
  23331. // does not flow into the loop variable.
  23332. var token = this.getToken();
  23333. return parseInt(token || 0, 10) | 0;
  23334. },
  23335. readBoolean: function Type1Parser_readBoolean() {
  23336. var token = this.getToken();
  23337. // Use 1 and 0 since that's what type2 charstrings use.
  23338. return token === 'true' ? 1 : 0;
  23339. },
  23340. nextChar : function Type1_nextChar() {
  23341. return (this.currentChar = this.stream.getByte());
  23342. },
  23343. getToken: function Type1Parser_getToken() {
  23344. // Eat whitespace and comments.
  23345. var comment = false;
  23346. var ch = this.currentChar;
  23347. while (true) {
  23348. if (ch === -1) {
  23349. return null;
  23350. }
  23351. if (comment) {
  23352. if (ch === 0x0A || ch === 0x0D) {
  23353. comment = false;
  23354. }
  23355. } else if (ch === 0x25) { // '%'
  23356. comment = true;
  23357. } else if (!Lexer.isSpace(ch)) {
  23358. break;
  23359. }
  23360. ch = this.nextChar();
  23361. }
  23362. if (isSpecial(ch)) {
  23363. this.nextChar();
  23364. return String.fromCharCode(ch);
  23365. }
  23366. var token = '';
  23367. do {
  23368. token += String.fromCharCode(ch);
  23369. ch = this.nextChar();
  23370. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  23371. return token;
  23372. },
  23373. /*
  23374. * Returns an object containing a Subrs array and a CharStrings
  23375. * array extracted from and eexec encrypted block of data
  23376. */
  23377. extractFontProgram: function Type1Parser_extractFontProgram() {
  23378. var stream = this.stream;
  23379. var subrs = [], charstrings = [];
  23380. var program = {
  23381. subrs: [],
  23382. charstrings: [],
  23383. properties: {
  23384. 'privateData': {
  23385. 'lenIV': 4
  23386. }
  23387. }
  23388. };
  23389. var token, length, data, lenIV, encoded;
  23390. while ((token = this.getToken()) !== null) {
  23391. if (token !== '/') {
  23392. continue;
  23393. }
  23394. token = this.getToken();
  23395. switch (token) {
  23396. case 'CharStrings':
  23397. // The number immediately following CharStrings must be greater or
  23398. // equal to the number of CharStrings.
  23399. this.getToken();
  23400. this.getToken(); // read in 'dict'
  23401. this.getToken(); // read in 'dup'
  23402. this.getToken(); // read in 'begin'
  23403. while(true) {
  23404. token = this.getToken();
  23405. if (token === null || token === 'end') {
  23406. break;
  23407. }
  23408. if (token !== '/') {
  23409. continue;
  23410. }
  23411. var glyph = this.getToken();
  23412. length = this.readInt();
  23413. this.getToken(); // read in 'RD' or '-|'
  23414. data = stream.makeSubStream(stream.pos, length);
  23415. lenIV = program.properties.privateData['lenIV'];
  23416. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23417. // Skip past the required space and binary data.
  23418. stream.skip(length);
  23419. this.nextChar();
  23420. token = this.getToken(); // read in 'ND' or '|-'
  23421. if (token === 'noaccess') {
  23422. this.getToken(); // read in 'def'
  23423. }
  23424. charstrings.push({
  23425. glyph: glyph,
  23426. encoded: encoded
  23427. });
  23428. }
  23429. break;
  23430. case 'Subrs':
  23431. var num = this.readInt();
  23432. this.getToken(); // read in 'array'
  23433. while ((token = this.getToken()) === 'dup') {
  23434. var index = this.readInt();
  23435. length = this.readInt();
  23436. this.getToken(); // read in 'RD' or '-|'
  23437. data = stream.makeSubStream(stream.pos, length);
  23438. lenIV = program.properties.privateData['lenIV'];
  23439. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23440. // Skip past the required space and binary data.
  23441. stream.skip(length);
  23442. this.nextChar();
  23443. token = this.getToken(); // read in 'NP' or '|'
  23444. if (token === 'noaccess') {
  23445. this.getToken(); // read in 'put'
  23446. }
  23447. subrs[index] = encoded;
  23448. }
  23449. break;
  23450. case 'BlueValues':
  23451. case 'OtherBlues':
  23452. case 'FamilyBlues':
  23453. case 'FamilyOtherBlues':
  23454. var blueArray = this.readNumberArray();
  23455. // *Blue* values may contain invalid data: disables reading of
  23456. // those values when hinting is disabled.
  23457. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  23458. HINTING_ENABLED) {
  23459. program.properties.privateData[token] = blueArray;
  23460. }
  23461. break;
  23462. case 'StemSnapH':
  23463. case 'StemSnapV':
  23464. program.properties.privateData[token] = this.readNumberArray();
  23465. break;
  23466. case 'StdHW':
  23467. case 'StdVW':
  23468. program.properties.privateData[token] =
  23469. this.readNumberArray()[0];
  23470. break;
  23471. case 'BlueShift':
  23472. case 'lenIV':
  23473. case 'BlueFuzz':
  23474. case 'BlueScale':
  23475. case 'LanguageGroup':
  23476. case 'ExpansionFactor':
  23477. program.properties.privateData[token] = this.readNumber();
  23478. break;
  23479. case 'ForceBold':
  23480. program.properties.privateData[token] = this.readBoolean();
  23481. break;
  23482. }
  23483. }
  23484. for (var i = 0; i < charstrings.length; i++) {
  23485. glyph = charstrings[i].glyph;
  23486. encoded = charstrings[i].encoded;
  23487. var charString = new Type1CharString();
  23488. var error = charString.convert(encoded, subrs);
  23489. var output = charString.output;
  23490. if (error) {
  23491. // It seems when FreeType encounters an error while evaluating a glyph
  23492. // that it completely ignores the glyph so we'll mimic that behaviour
  23493. // here and put an endchar to make the validator happy.
  23494. output = [14];
  23495. }
  23496. program.charstrings.push({
  23497. glyphName: glyph,
  23498. charstring: output,
  23499. width: charString.width,
  23500. lsb: charString.lsb,
  23501. seac: charString.seac
  23502. });
  23503. }
  23504. return program;
  23505. },
  23506. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  23507. var token;
  23508. while ((token = this.getToken()) !== null) {
  23509. if (token !== '/') {
  23510. continue;
  23511. }
  23512. token = this.getToken();
  23513. switch (token) {
  23514. case 'FontMatrix':
  23515. var matrix = this.readNumberArray();
  23516. properties.fontMatrix = matrix;
  23517. break;
  23518. case 'Encoding':
  23519. var encodingArg = this.getToken();
  23520. var encoding;
  23521. if (!/^\d+$/.test(encodingArg)) {
  23522. // encoding name is specified
  23523. encoding = Encodings[encodingArg];
  23524. } else {
  23525. encoding = [];
  23526. var size = parseInt(encodingArg, 10) | 0;
  23527. this.getToken(); // read in 'array'
  23528. for (var j = 0; j < size; j++) {
  23529. token = this.getToken();
  23530. // skipping till first dup or def (e.g. ignoring for statement)
  23531. while (token !== 'dup' && token !== 'def') {
  23532. token = this.getToken();
  23533. if (token === null) {
  23534. return; // invalid header
  23535. }
  23536. }
  23537. if (token === 'def') {
  23538. break; // read all array data
  23539. }
  23540. var index = this.readInt();
  23541. this.getToken(); // read in '/'
  23542. var glyph = this.getToken();
  23543. encoding[index] = glyph;
  23544. this.getToken(); // read the in 'put'
  23545. }
  23546. }
  23547. properties.builtInEncoding = encoding;
  23548. break;
  23549. case 'FontBBox':
  23550. var fontBBox = this.readNumberArray();
  23551. // adjusting ascent/descent
  23552. properties.ascent = fontBBox[3];
  23553. properties.descent = fontBBox[1];
  23554. properties.ascentScaled = true;
  23555. break;
  23556. }
  23557. }
  23558. }
  23559. };
  23560. return Type1Parser;
  23561. })();
  23562. /**
  23563. * The CFF class takes a Type1 file and wrap it into a
  23564. * 'Compact Font Format' which itself embed Type2 charstrings.
  23565. */
  23566. var CFFStandardStrings = [
  23567. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23568. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23569. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23570. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23571. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  23572. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  23573. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  23574. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  23575. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  23576. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  23577. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23578. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23579. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  23580. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  23581. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  23582. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  23583. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  23584. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  23585. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  23586. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  23587. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  23588. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  23589. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  23590. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  23591. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  23592. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  23593. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  23594. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  23595. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  23596. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  23597. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  23598. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  23599. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  23600. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23601. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  23602. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  23603. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  23604. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  23605. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  23606. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  23607. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  23608. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  23609. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23610. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23611. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23612. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23613. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23614. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  23615. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  23616. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  23617. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  23618. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23619. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  23620. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  23621. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  23622. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  23623. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  23624. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  23625. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  23626. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  23627. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  23628. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  23629. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  23630. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  23631. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  23632. ];
  23633. // Type1Font is also a CIDFontType0.
  23634. var Type1Font = function Type1Font(name, file, properties) {
  23635. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  23636. // Also, length1 and length2 might be off by 6 bytes as well.
  23637. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  23638. var PFB_HEADER_SIZE = 6;
  23639. var headerBlockLength = properties.length1;
  23640. var eexecBlockLength = properties.length2;
  23641. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  23642. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  23643. if (pfbHeaderPresent) {
  23644. file.skip(PFB_HEADER_SIZE);
  23645. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23646. (pfbHeader[3] << 8) | pfbHeader[2];
  23647. }
  23648. // Get the data block containing glyphs and subrs informations
  23649. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  23650. var headerBlockParser = new Type1Parser(headerBlock);
  23651. headerBlockParser.extractFontHeader(properties);
  23652. if (pfbHeaderPresent) {
  23653. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  23654. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23655. (pfbHeader[3] << 8) | pfbHeader[2];
  23656. }
  23657. // Decrypt the data blocks and retrieve it's content
  23658. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  23659. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  23660. var data = eexecBlockParser.extractFontProgram();
  23661. for (var info in data.properties) {
  23662. properties[info] = data.properties[info];
  23663. }
  23664. var charstrings = data.charstrings;
  23665. var type2Charstrings = this.getType2Charstrings(charstrings);
  23666. var subrs = this.getType2Subrs(data.subrs);
  23667. this.charstrings = charstrings;
  23668. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  23669. subrs, properties);
  23670. this.seacs = this.getSeacs(data.charstrings);
  23671. };
  23672. Type1Font.prototype = {
  23673. get numGlyphs() {
  23674. return this.charstrings.length + 1;
  23675. },
  23676. getCharset: function Type1Font_getCharset() {
  23677. var charset = ['.notdef'];
  23678. var charstrings = this.charstrings;
  23679. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23680. charset.push(charstrings[glyphId].glyphName);
  23681. }
  23682. return charset;
  23683. },
  23684. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  23685. var charstrings = this.charstrings;
  23686. var glyphNames = ['.notdef'], glyphId;
  23687. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23688. glyphNames.push(charstrings[glyphId].glyphName);
  23689. }
  23690. var encoding = properties.builtInEncoding;
  23691. if (encoding) {
  23692. var builtInEncoding = {};
  23693. for (var charCode in encoding) {
  23694. glyphId = glyphNames.indexOf(encoding[charCode]);
  23695. if (glyphId >= 0) {
  23696. builtInEncoding[charCode] = glyphId;
  23697. }
  23698. }
  23699. }
  23700. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  23701. },
  23702. getSeacs: function Type1Font_getSeacs(charstrings) {
  23703. var i, ii;
  23704. var seacMap = [];
  23705. for (i = 0, ii = charstrings.length; i < ii; i++) {
  23706. var charstring = charstrings[i];
  23707. if (charstring.seac) {
  23708. // Offset by 1 for .notdef
  23709. seacMap[i + 1] = charstring.seac;
  23710. }
  23711. }
  23712. return seacMap;
  23713. },
  23714. getType2Charstrings: function Type1Font_getType2Charstrings(
  23715. type1Charstrings) {
  23716. var type2Charstrings = [];
  23717. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  23718. type2Charstrings.push(type1Charstrings[i].charstring);
  23719. }
  23720. return type2Charstrings;
  23721. },
  23722. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  23723. var bias = 0;
  23724. var count = type1Subrs.length;
  23725. if (count < 1133) {
  23726. bias = 107;
  23727. } else if (count < 33769) {
  23728. bias = 1131;
  23729. } else {
  23730. bias = 32768;
  23731. }
  23732. // Add a bunch of empty subrs to deal with the Type2 bias
  23733. var type2Subrs = [];
  23734. var i;
  23735. for (i = 0; i < bias; i++) {
  23736. type2Subrs.push([0x0B]);
  23737. }
  23738. for (i = 0; i < count; i++) {
  23739. type2Subrs.push(type1Subrs[i]);
  23740. }
  23741. return type2Subrs;
  23742. },
  23743. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  23744. var cff = new CFF();
  23745. cff.header = new CFFHeader(1, 0, 4, 4);
  23746. cff.names = [name];
  23747. var topDict = new CFFTopDict();
  23748. // CFF strings IDs 0...390 are predefined names, so refering
  23749. // to entries in our own String INDEX starts at SID 391.
  23750. topDict.setByName('version', 391);
  23751. topDict.setByName('Notice', 392);
  23752. topDict.setByName('FullName', 393);
  23753. topDict.setByName('FamilyName', 394);
  23754. topDict.setByName('Weight', 395);
  23755. topDict.setByName('Encoding', null); // placeholder
  23756. topDict.setByName('FontMatrix', properties.fontMatrix);
  23757. topDict.setByName('FontBBox', properties.bbox);
  23758. topDict.setByName('charset', null); // placeholder
  23759. topDict.setByName('CharStrings', null); // placeholder
  23760. topDict.setByName('Private', null); // placeholder
  23761. cff.topDict = topDict;
  23762. var strings = new CFFStrings();
  23763. strings.add('Version 0.11'); // Version
  23764. strings.add('See original notice'); // Notice
  23765. strings.add(name); // FullName
  23766. strings.add(name); // FamilyName
  23767. strings.add('Medium'); // Weight
  23768. cff.strings = strings;
  23769. cff.globalSubrIndex = new CFFIndex();
  23770. var count = glyphs.length;
  23771. var charsetArray = [0];
  23772. var i, ii;
  23773. for (i = 0; i < count; i++) {
  23774. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  23775. // TODO: Insert the string and correctly map it. Previously it was
  23776. // thought mapping names that aren't in the standard strings to .notdef
  23777. // was fine, however in issue818 when mapping them all to .notdef the
  23778. // adieresis glyph no longer worked.
  23779. if (index === -1) {
  23780. index = 0;
  23781. }
  23782. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  23783. }
  23784. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  23785. var charStringsIndex = new CFFIndex();
  23786. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  23787. for (i = 0; i < count; i++) {
  23788. charStringsIndex.add(glyphs[i]);
  23789. }
  23790. cff.charStrings = charStringsIndex;
  23791. var privateDict = new CFFPrivateDict();
  23792. privateDict.setByName('Subrs', null); // placeholder
  23793. var fields = [
  23794. 'BlueValues',
  23795. 'OtherBlues',
  23796. 'FamilyBlues',
  23797. 'FamilyOtherBlues',
  23798. 'StemSnapH',
  23799. 'StemSnapV',
  23800. 'BlueShift',
  23801. 'BlueFuzz',
  23802. 'BlueScale',
  23803. 'LanguageGroup',
  23804. 'ExpansionFactor',
  23805. 'ForceBold',
  23806. 'StdHW',
  23807. 'StdVW'
  23808. ];
  23809. for (i = 0, ii = fields.length; i < ii; i++) {
  23810. var field = fields[i];
  23811. if (!properties.privateData.hasOwnProperty(field)) {
  23812. continue;
  23813. }
  23814. var value = properties.privateData[field];
  23815. if (isArray(value)) {
  23816. // All of the private dictionary array data in CFF must be stored as
  23817. // "delta-encoded" numbers.
  23818. for (var j = value.length - 1; j > 0; j--) {
  23819. value[j] -= value[j - 1]; // ... difference from previous value
  23820. }
  23821. }
  23822. privateDict.setByName(field, value);
  23823. }
  23824. cff.topDict.privateDict = privateDict;
  23825. var subrIndex = new CFFIndex();
  23826. for (i = 0, ii = subrs.length; i < ii; i++) {
  23827. subrIndex.add(subrs[i]);
  23828. }
  23829. privateDict.subrsIndex = subrIndex;
  23830. var compiler = new CFFCompiler(cff);
  23831. return compiler.compile();
  23832. }
  23833. };
  23834. var CFFFont = (function CFFFontClosure() {
  23835. function CFFFont(file, properties) {
  23836. this.properties = properties;
  23837. var parser = new CFFParser(file, properties);
  23838. this.cff = parser.parse();
  23839. var compiler = new CFFCompiler(this.cff);
  23840. this.seacs = this.cff.seacs;
  23841. try {
  23842. this.data = compiler.compile();
  23843. } catch (e) {
  23844. warn('Failed to compile font ' + properties.loadedName);
  23845. // There may have just been an issue with the compiler, set the data
  23846. // anyway and hope the font loaded.
  23847. this.data = file;
  23848. }
  23849. }
  23850. CFFFont.prototype = {
  23851. get numGlyphs() {
  23852. return this.cff.charStrings.count;
  23853. },
  23854. getCharset: function CFFFont_getCharset() {
  23855. return this.cff.charset.charset;
  23856. },
  23857. getGlyphMapping: function CFFFont_getGlyphMapping() {
  23858. var cff = this.cff;
  23859. var properties = this.properties;
  23860. var charsets = cff.charset.charset;
  23861. var charCodeToGlyphId;
  23862. var glyphId;
  23863. if (properties.composite) {
  23864. charCodeToGlyphId = Object.create(null);
  23865. if (cff.isCIDFont) {
  23866. // If the font is actually a CID font then we should use the charset
  23867. // to map CIDs to GIDs.
  23868. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  23869. var cid = charsets[glyphId];
  23870. var charCode = properties.cMap.charCodeOf(cid);
  23871. charCodeToGlyphId[charCode] = glyphId;
  23872. }
  23873. } else {
  23874. // If it is NOT actually a CID font then CIDs should be mapped
  23875. // directly to GIDs.
  23876. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  23877. charCodeToGlyphId[glyphId] = glyphId;
  23878. }
  23879. }
  23880. return charCodeToGlyphId;
  23881. }
  23882. var encoding = cff.encoding ? cff.encoding.encoding : null;
  23883. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  23884. return charCodeToGlyphId;
  23885. }
  23886. };
  23887. return CFFFont;
  23888. })();
  23889. var CFFParser = (function CFFParserClosure() {
  23890. var CharstringValidationData = [
  23891. null,
  23892. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  23893. null,
  23894. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  23895. { id: 'vmoveto', min: 1, stackClearing: true },
  23896. { id: 'rlineto', min: 2, resetStack: true },
  23897. { id: 'hlineto', min: 1, resetStack: true },
  23898. { id: 'vlineto', min: 1, resetStack: true },
  23899. { id: 'rrcurveto', min: 6, resetStack: true },
  23900. null,
  23901. { id: 'callsubr', min: 1, undefStack: true },
  23902. { id: 'return', min: 0, undefStack: true },
  23903. null, // 12
  23904. null,
  23905. { id: 'endchar', min: 0, stackClearing: true },
  23906. null,
  23907. null,
  23908. null,
  23909. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  23910. { id: 'hintmask', min: 0, stackClearing: true },
  23911. { id: 'cntrmask', min: 0, stackClearing: true },
  23912. { id: 'rmoveto', min: 2, stackClearing: true },
  23913. { id: 'hmoveto', min: 1, stackClearing: true },
  23914. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  23915. { id: 'rcurveline', min: 8, resetStack: true },
  23916. { id: 'rlinecurve', min: 8, resetStack: true },
  23917. { id: 'vvcurveto', min: 4, resetStack: true },
  23918. { id: 'hhcurveto', min: 4, resetStack: true },
  23919. null, // shortint
  23920. { id: 'callgsubr', min: 1, undefStack: true },
  23921. { id: 'vhcurveto', min: 4, resetStack: true },
  23922. { id: 'hvcurveto', min: 4, resetStack: true }
  23923. ];
  23924. var CharstringValidationData12 = [
  23925. null,
  23926. null,
  23927. null,
  23928. { id: 'and', min: 2, stackDelta: -1 },
  23929. { id: 'or', min: 2, stackDelta: -1 },
  23930. { id: 'not', min: 1, stackDelta: 0 },
  23931. null,
  23932. null,
  23933. null,
  23934. { id: 'abs', min: 1, stackDelta: 0 },
  23935. { id: 'add', min: 2, stackDelta: -1,
  23936. stackFn: function stack_div(stack, index) {
  23937. stack[index - 2] = stack[index - 2] + stack[index - 1];
  23938. }
  23939. },
  23940. { id: 'sub', min: 2, stackDelta: -1,
  23941. stackFn: function stack_div(stack, index) {
  23942. stack[index - 2] = stack[index - 2] - stack[index - 1];
  23943. }
  23944. },
  23945. { id: 'div', min: 2, stackDelta: -1,
  23946. stackFn: function stack_div(stack, index) {
  23947. stack[index - 2] = stack[index - 2] / stack[index - 1];
  23948. }
  23949. },
  23950. null,
  23951. { id: 'neg', min: 1, stackDelta: 0,
  23952. stackFn: function stack_div(stack, index) {
  23953. stack[index - 1] = -stack[index - 1];
  23954. }
  23955. },
  23956. { id: 'eq', min: 2, stackDelta: -1 },
  23957. null,
  23958. null,
  23959. { id: 'drop', min: 1, stackDelta: -1 },
  23960. null,
  23961. { id: 'put', min: 2, stackDelta: -2 },
  23962. { id: 'get', min: 1, stackDelta: 0 },
  23963. { id: 'ifelse', min: 4, stackDelta: -3 },
  23964. { id: 'random', min: 0, stackDelta: 1 },
  23965. { id: 'mul', min: 2, stackDelta: -1,
  23966. stackFn: function stack_div(stack, index) {
  23967. stack[index - 2] = stack[index - 2] * stack[index - 1];
  23968. }
  23969. },
  23970. null,
  23971. { id: 'sqrt', min: 1, stackDelta: 0 },
  23972. { id: 'dup', min: 1, stackDelta: 1 },
  23973. { id: 'exch', min: 2, stackDelta: 0 },
  23974. { id: 'index', min: 2, stackDelta: 0 },
  23975. { id: 'roll', min: 3, stackDelta: -2 },
  23976. null,
  23977. null,
  23978. null,
  23979. { id: 'hflex', min: 7, resetStack: true },
  23980. { id: 'flex', min: 13, resetStack: true },
  23981. { id: 'hflex1', min: 9, resetStack: true },
  23982. { id: 'flex1', min: 11, resetStack: true }
  23983. ];
  23984. function CFFParser(file, properties) {
  23985. this.bytes = file.getBytes();
  23986. this.properties = properties;
  23987. }
  23988. CFFParser.prototype = {
  23989. parse: function CFFParser_parse() {
  23990. var properties = this.properties;
  23991. var cff = new CFF();
  23992. this.cff = cff;
  23993. // The first five sections must be in order, all the others are reached
  23994. // via offsets contained in one of the below.
  23995. var header = this.parseHeader();
  23996. var nameIndex = this.parseIndex(header.endPos);
  23997. var topDictIndex = this.parseIndex(nameIndex.endPos);
  23998. var stringIndex = this.parseIndex(topDictIndex.endPos);
  23999. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  24000. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  24001. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  24002. cff.header = header.obj;
  24003. cff.names = this.parseNameIndex(nameIndex.obj);
  24004. cff.strings = this.parseStringIndex(stringIndex.obj);
  24005. cff.topDict = topDict;
  24006. cff.globalSubrIndex = globalSubrIndex.obj;
  24007. this.parsePrivateDict(cff.topDict);
  24008. cff.isCIDFont = topDict.hasName('ROS');
  24009. var charStringOffset = topDict.getByName('CharStrings');
  24010. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  24011. cff.charStrings = charStringsAndSeacs.charStrings;
  24012. cff.seacs = charStringsAndSeacs.seacs;
  24013. cff.widths = charStringsAndSeacs.widths;
  24014. var fontMatrix = topDict.getByName('FontMatrix');
  24015. if (fontMatrix) {
  24016. properties.fontMatrix = fontMatrix;
  24017. }
  24018. var fontBBox = topDict.getByName('FontBBox');
  24019. if (fontBBox) {
  24020. // adjusting ascent/descent
  24021. properties.ascent = fontBBox[3];
  24022. properties.descent = fontBBox[1];
  24023. properties.ascentScaled = true;
  24024. }
  24025. var charset, encoding;
  24026. if (cff.isCIDFont) {
  24027. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  24028. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  24029. var dictRaw = fdArrayIndex.get(i);
  24030. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  24031. cff.strings);
  24032. this.parsePrivateDict(fontDict);
  24033. cff.fdArray.push(fontDict);
  24034. }
  24035. // cid fonts don't have an encoding
  24036. encoding = null;
  24037. charset = this.parseCharsets(topDict.getByName('charset'),
  24038. cff.charStrings.count, cff.strings, true);
  24039. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  24040. cff.charStrings.count);
  24041. } else {
  24042. charset = this.parseCharsets(topDict.getByName('charset'),
  24043. cff.charStrings.count, cff.strings, false);
  24044. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  24045. properties,
  24046. cff.strings, charset.charset);
  24047. }
  24048. cff.charset = charset;
  24049. cff.encoding = encoding;
  24050. return cff;
  24051. },
  24052. parseHeader: function CFFParser_parseHeader() {
  24053. var bytes = this.bytes;
  24054. var bytesLength = bytes.length;
  24055. var offset = 0;
  24056. // Prevent an infinite loop, by checking that the offset is within the
  24057. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  24058. while (offset < bytesLength && bytes[offset] !== 1) {
  24059. ++offset;
  24060. }
  24061. if (offset >= bytesLength) {
  24062. error('Invalid CFF header');
  24063. } else if (offset !== 0) {
  24064. info('cff data is shifted');
  24065. bytes = bytes.subarray(offset);
  24066. this.bytes = bytes;
  24067. }
  24068. var major = bytes[0];
  24069. var minor = bytes[1];
  24070. var hdrSize = bytes[2];
  24071. var offSize = bytes[3];
  24072. var header = new CFFHeader(major, minor, hdrSize, offSize);
  24073. return { obj: header, endPos: hdrSize };
  24074. },
  24075. parseDict: function CFFParser_parseDict(dict) {
  24076. var pos = 0;
  24077. function parseOperand() {
  24078. var value = dict[pos++];
  24079. if (value === 30) {
  24080. return parseFloatOperand(pos);
  24081. } else if (value === 28) {
  24082. value = dict[pos++];
  24083. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  24084. return value;
  24085. } else if (value === 29) {
  24086. value = dict[pos++];
  24087. value = (value << 8) | dict[pos++];
  24088. value = (value << 8) | dict[pos++];
  24089. value = (value << 8) | dict[pos++];
  24090. return value;
  24091. } else if (value >= 32 && value <= 246) {
  24092. return value - 139;
  24093. } else if (value >= 247 && value <= 250) {
  24094. return ((value - 247) * 256) + dict[pos++] + 108;
  24095. } else if (value >= 251 && value <= 254) {
  24096. return -((value - 251) * 256) - dict[pos++] - 108;
  24097. } else {
  24098. error('255 is not a valid DICT command');
  24099. }
  24100. return -1;
  24101. }
  24102. function parseFloatOperand() {
  24103. var str = '';
  24104. var eof = 15;
  24105. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  24106. '9', '.', 'E', 'E-', null, '-'];
  24107. var length = dict.length;
  24108. while (pos < length) {
  24109. var b = dict[pos++];
  24110. var b1 = b >> 4;
  24111. var b2 = b & 15;
  24112. if (b1 === eof) {
  24113. break;
  24114. }
  24115. str += lookup[b1];
  24116. if (b2 === eof) {
  24117. break;
  24118. }
  24119. str += lookup[b2];
  24120. }
  24121. return parseFloat(str);
  24122. }
  24123. var operands = [];
  24124. var entries = [];
  24125. pos = 0;
  24126. var end = dict.length;
  24127. while (pos < end) {
  24128. var b = dict[pos];
  24129. if (b <= 21) {
  24130. if (b === 12) {
  24131. b = (b << 8) | dict[++pos];
  24132. }
  24133. entries.push([b, operands]);
  24134. operands = [];
  24135. ++pos;
  24136. } else {
  24137. operands.push(parseOperand());
  24138. }
  24139. }
  24140. return entries;
  24141. },
  24142. parseIndex: function CFFParser_parseIndex(pos) {
  24143. var cffIndex = new CFFIndex();
  24144. var bytes = this.bytes;
  24145. var count = (bytes[pos++] << 8) | bytes[pos++];
  24146. var offsets = [];
  24147. var end = pos;
  24148. var i, ii;
  24149. if (count !== 0) {
  24150. var offsetSize = bytes[pos++];
  24151. // add 1 for offset to determine size of last object
  24152. var startPos = pos + ((count + 1) * offsetSize) - 1;
  24153. for (i = 0, ii = count + 1; i < ii; ++i) {
  24154. var offset = 0;
  24155. for (var j = 0; j < offsetSize; ++j) {
  24156. offset <<= 8;
  24157. offset += bytes[pos++];
  24158. }
  24159. offsets.push(startPos + offset);
  24160. }
  24161. end = offsets[count];
  24162. }
  24163. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  24164. var offsetStart = offsets[i];
  24165. var offsetEnd = offsets[i + 1];
  24166. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  24167. }
  24168. return {obj: cffIndex, endPos: end};
  24169. },
  24170. parseNameIndex: function CFFParser_parseNameIndex(index) {
  24171. var names = [];
  24172. for (var i = 0, ii = index.count; i < ii; ++i) {
  24173. var name = index.get(i);
  24174. // OTS doesn't allow names to be over 127 characters.
  24175. var length = Math.min(name.length, 127);
  24176. var data = [];
  24177. // OTS also only permits certain characters in the name.
  24178. for (var j = 0; j < length; ++j) {
  24179. var c = name[j];
  24180. if (j === 0 && c === 0) {
  24181. data[j] = c;
  24182. continue;
  24183. }
  24184. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  24185. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  24186. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  24187. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  24188. data[j] = 95;
  24189. continue;
  24190. }
  24191. data[j] = c;
  24192. }
  24193. names.push(bytesToString(data));
  24194. }
  24195. return names;
  24196. },
  24197. parseStringIndex: function CFFParser_parseStringIndex(index) {
  24198. var strings = new CFFStrings();
  24199. for (var i = 0, ii = index.count; i < ii; ++i) {
  24200. var data = index.get(i);
  24201. strings.add(bytesToString(data));
  24202. }
  24203. return strings;
  24204. },
  24205. createDict: function CFFParser_createDict(Type, dict, strings) {
  24206. var cffDict = new Type(strings);
  24207. for (var i = 0, ii = dict.length; i < ii; ++i) {
  24208. var pair = dict[i];
  24209. var key = pair[0];
  24210. var value = pair[1];
  24211. cffDict.setByKey(key, value);
  24212. }
  24213. return cffDict;
  24214. },
  24215. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  24216. var charStrings = this.parseIndex(charStringOffset).obj;
  24217. var seacs = [];
  24218. var widths = [];
  24219. var count = charStrings.count;
  24220. for (var i = 0; i < count; i++) {
  24221. var charstring = charStrings.get(i);
  24222. var stackSize = 0;
  24223. var stack = [];
  24224. var undefStack = true;
  24225. var hints = 0;
  24226. var valid = true;
  24227. var data = charstring;
  24228. var length = data.length;
  24229. var firstStackClearing = true;
  24230. for (var j = 0; j < length;) {
  24231. var value = data[j++];
  24232. var validationCommand = null;
  24233. if (value === 12) {
  24234. var q = data[j++];
  24235. if (q === 0) {
  24236. // The CFF specification state that the 'dotsection' command
  24237. // (12, 0) is deprecated and treated as a no-op, but all Type2
  24238. // charstrings processors should support them. Unfortunately
  24239. // the font sanitizer don't. As a workaround the sequence (12, 0)
  24240. // is replaced by a useless (0, hmoveto).
  24241. data[j - 2] = 139;
  24242. data[j - 1] = 22;
  24243. stackSize = 0;
  24244. } else {
  24245. validationCommand = CharstringValidationData12[q];
  24246. }
  24247. } else if (value === 28) { // number (16 bit)
  24248. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  24249. j += 2;
  24250. stackSize++;
  24251. } else if (value === 14) {
  24252. if (stackSize >= 4) {
  24253. stackSize -= 4;
  24254. if (SEAC_ANALYSIS_ENABLED) {
  24255. seacs[i] = stack.slice(stackSize, stackSize + 4);
  24256. valid = false;
  24257. }
  24258. }
  24259. validationCommand = CharstringValidationData[value];
  24260. } else if (value >= 32 && value <= 246) { // number
  24261. stack[stackSize] = value - 139;
  24262. stackSize++;
  24263. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  24264. stack[stackSize] = (value < 251 ?
  24265. ((value - 247) << 8) + data[j] + 108 :
  24266. -((value - 251) << 8) - data[j] - 108);
  24267. j++;
  24268. stackSize++;
  24269. } else if (value === 255) { // number (32 bit)
  24270. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  24271. (data[j + 2] << 8) | data[j + 3]) / 65536;
  24272. j += 4;
  24273. stackSize++;
  24274. } else if (value === 19 || value === 20) {
  24275. hints += stackSize >> 1;
  24276. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  24277. stackSize %= 2;
  24278. validationCommand = CharstringValidationData[value];
  24279. } else {
  24280. validationCommand = CharstringValidationData[value];
  24281. }
  24282. if (validationCommand) {
  24283. if (validationCommand.stem) {
  24284. hints += stackSize >> 1;
  24285. }
  24286. if ('min' in validationCommand) {
  24287. if (!undefStack && stackSize < validationCommand.min) {
  24288. warn('Not enough parameters for ' + validationCommand.id +
  24289. '; actual: ' + stackSize +
  24290. ', expected: ' + validationCommand.min);
  24291. valid = false;
  24292. break;
  24293. }
  24294. }
  24295. if (firstStackClearing && validationCommand.stackClearing) {
  24296. firstStackClearing = false;
  24297. // the optional character width can be found before the first
  24298. // stack-clearing command arguments
  24299. stackSize -= validationCommand.min;
  24300. if (stackSize >= 2 && validationCommand.stem) {
  24301. // there are even amount of arguments for stem commands
  24302. stackSize %= 2;
  24303. } else if (stackSize > 1) {
  24304. warn('Found too many parameters for stack-clearing command');
  24305. }
  24306. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  24307. widths[i] = stack[stackSize - 1];
  24308. }
  24309. }
  24310. if ('stackDelta' in validationCommand) {
  24311. if ('stackFn' in validationCommand) {
  24312. validationCommand.stackFn(stack, stackSize);
  24313. }
  24314. stackSize += validationCommand.stackDelta;
  24315. } else if (validationCommand.stackClearing) {
  24316. stackSize = 0;
  24317. } else if (validationCommand.resetStack) {
  24318. stackSize = 0;
  24319. undefStack = false;
  24320. } else if (validationCommand.undefStack) {
  24321. stackSize = 0;
  24322. undefStack = true;
  24323. firstStackClearing = false;
  24324. }
  24325. }
  24326. }
  24327. if (!valid) {
  24328. // resetting invalid charstring to single 'endchar'
  24329. charStrings.set(i, new Uint8Array([14]));
  24330. }
  24331. }
  24332. return { charStrings: charStrings, seacs: seacs, widths: widths };
  24333. },
  24334. emptyPrivateDictionary:
  24335. function CFFParser_emptyPrivateDictionary(parentDict) {
  24336. var privateDict = this.createDict(CFFPrivateDict, [],
  24337. parentDict.strings);
  24338. parentDict.setByKey(18, [0, 0]);
  24339. parentDict.privateDict = privateDict;
  24340. },
  24341. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  24342. // no private dict, do nothing
  24343. if (!parentDict.hasName('Private')) {
  24344. this.emptyPrivateDictionary(parentDict);
  24345. return;
  24346. }
  24347. var privateOffset = parentDict.getByName('Private');
  24348. // make sure the params are formatted correctly
  24349. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  24350. parentDict.removeByName('Private');
  24351. return;
  24352. }
  24353. var size = privateOffset[0];
  24354. var offset = privateOffset[1];
  24355. // remove empty dicts or ones that refer to invalid location
  24356. if (size === 0 || offset >= this.bytes.length) {
  24357. this.emptyPrivateDictionary(parentDict);
  24358. return;
  24359. }
  24360. var privateDictEnd = offset + size;
  24361. var dictData = this.bytes.subarray(offset, privateDictEnd);
  24362. var dict = this.parseDict(dictData);
  24363. var privateDict = this.createDict(CFFPrivateDict, dict,
  24364. parentDict.strings);
  24365. parentDict.privateDict = privateDict;
  24366. // Parse the Subrs index also since it's relative to the private dict.
  24367. if (!privateDict.getByName('Subrs')) {
  24368. return;
  24369. }
  24370. var subrsOffset = privateDict.getByName('Subrs');
  24371. var relativeOffset = offset + subrsOffset;
  24372. // Validate the offset.
  24373. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  24374. this.emptyPrivateDictionary(parentDict);
  24375. return;
  24376. }
  24377. var subrsIndex = this.parseIndex(relativeOffset);
  24378. privateDict.subrsIndex = subrsIndex.obj;
  24379. },
  24380. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  24381. if (pos === 0) {
  24382. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  24383. ISOAdobeCharset);
  24384. } else if (pos === 1) {
  24385. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  24386. ExpertCharset);
  24387. } else if (pos === 2) {
  24388. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  24389. ExpertSubsetCharset);
  24390. }
  24391. var bytes = this.bytes;
  24392. var start = pos;
  24393. var format = bytes[pos++];
  24394. var charset = ['.notdef'];
  24395. var id, count, i;
  24396. // subtract 1 for the .notdef glyph
  24397. length -= 1;
  24398. switch (format) {
  24399. case 0:
  24400. for (i = 0; i < length; i++) {
  24401. id = (bytes[pos++] << 8) | bytes[pos++];
  24402. charset.push(cid ? id : strings.get(id));
  24403. }
  24404. break;
  24405. case 1:
  24406. while (charset.length <= length) {
  24407. id = (bytes[pos++] << 8) | bytes[pos++];
  24408. count = bytes[pos++];
  24409. for (i = 0; i <= count; i++) {
  24410. charset.push(cid ? id++ : strings.get(id++));
  24411. }
  24412. }
  24413. break;
  24414. case 2:
  24415. while (charset.length <= length) {
  24416. id = (bytes[pos++] << 8) | bytes[pos++];
  24417. count = (bytes[pos++] << 8) | bytes[pos++];
  24418. for (i = 0; i <= count; i++) {
  24419. charset.push(cid ? id++ : strings.get(id++));
  24420. }
  24421. }
  24422. break;
  24423. default:
  24424. error('Unknown charset format');
  24425. }
  24426. // Raw won't be needed if we actually compile the charset.
  24427. var end = pos;
  24428. var raw = bytes.subarray(start, end);
  24429. return new CFFCharset(false, format, charset, raw);
  24430. },
  24431. parseEncoding: function CFFParser_parseEncoding(pos,
  24432. properties,
  24433. strings,
  24434. charset) {
  24435. var encoding = {};
  24436. var bytes = this.bytes;
  24437. var predefined = false;
  24438. var hasSupplement = false;
  24439. var format, i, ii;
  24440. var raw = null;
  24441. function readSupplement() {
  24442. var supplementsCount = bytes[pos++];
  24443. for (i = 0; i < supplementsCount; i++) {
  24444. var code = bytes[pos++];
  24445. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  24446. encoding[code] = charset.indexOf(strings.get(sid));
  24447. }
  24448. }
  24449. if (pos === 0 || pos === 1) {
  24450. predefined = true;
  24451. format = pos;
  24452. var baseEncoding = pos ? Encodings.ExpertEncoding :
  24453. Encodings.StandardEncoding;
  24454. for (i = 0, ii = charset.length; i < ii; i++) {
  24455. var index = baseEncoding.indexOf(charset[i]);
  24456. if (index !== -1) {
  24457. encoding[index] = i;
  24458. }
  24459. }
  24460. } else {
  24461. var dataStart = pos;
  24462. format = bytes[pos++];
  24463. switch (format & 0x7f) {
  24464. case 0:
  24465. var glyphsCount = bytes[pos++];
  24466. for (i = 1; i <= glyphsCount; i++) {
  24467. encoding[bytes[pos++]] = i;
  24468. }
  24469. break;
  24470. case 1:
  24471. var rangesCount = bytes[pos++];
  24472. var gid = 1;
  24473. for (i = 0; i < rangesCount; i++) {
  24474. var start = bytes[pos++];
  24475. var left = bytes[pos++];
  24476. for (var j = start; j <= start + left; j++) {
  24477. encoding[j] = gid++;
  24478. }
  24479. }
  24480. break;
  24481. default:
  24482. error('Unknow encoding format: ' + format + ' in CFF');
  24483. break;
  24484. }
  24485. var dataEnd = pos;
  24486. if (format & 0x80) {
  24487. // The font sanitizer does not support CFF encoding with a
  24488. // supplement, since the encoding is not really used to map
  24489. // between gid to glyph, let's overwrite what is declared in
  24490. // the top dictionary to let the sanitizer think the font use
  24491. // StandardEncoding, that's a lie but that's ok.
  24492. bytes[dataStart] &= 0x7f;
  24493. readSupplement();
  24494. hasSupplement = true;
  24495. }
  24496. raw = bytes.subarray(dataStart, dataEnd);
  24497. }
  24498. format = format & 0x7f;
  24499. return new CFFEncoding(predefined, format, encoding, raw);
  24500. },
  24501. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  24502. var start = pos;
  24503. var bytes = this.bytes;
  24504. var format = bytes[pos++];
  24505. var fdSelect = [];
  24506. var i;
  24507. switch (format) {
  24508. case 0:
  24509. for (i = 0; i < length; ++i) {
  24510. var id = bytes[pos++];
  24511. fdSelect.push(id);
  24512. }
  24513. break;
  24514. case 3:
  24515. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  24516. for (i = 0; i < rangesCount; ++i) {
  24517. var first = (bytes[pos++] << 8) | bytes[pos++];
  24518. var fdIndex = bytes[pos++];
  24519. var next = (bytes[pos] << 8) | bytes[pos + 1];
  24520. for (var j = first; j < next; ++j) {
  24521. fdSelect.push(fdIndex);
  24522. }
  24523. }
  24524. // Advance past the sentinel(next).
  24525. pos += 2;
  24526. break;
  24527. default:
  24528. error('Unknown fdselect format ' + format);
  24529. break;
  24530. }
  24531. var end = pos;
  24532. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  24533. }
  24534. };
  24535. return CFFParser;
  24536. })();
  24537. // Compact Font Format
  24538. var CFF = (function CFFClosure() {
  24539. function CFF() {
  24540. this.header = null;
  24541. this.names = [];
  24542. this.topDict = null;
  24543. this.strings = new CFFStrings();
  24544. this.globalSubrIndex = null;
  24545. // The following could really be per font, but since we only have one font
  24546. // store them here.
  24547. this.encoding = null;
  24548. this.charset = null;
  24549. this.charStrings = null;
  24550. this.fdArray = [];
  24551. this.fdSelect = null;
  24552. this.isCIDFont = false;
  24553. }
  24554. return CFF;
  24555. })();
  24556. var CFFHeader = (function CFFHeaderClosure() {
  24557. function CFFHeader(major, minor, hdrSize, offSize) {
  24558. this.major = major;
  24559. this.minor = minor;
  24560. this.hdrSize = hdrSize;
  24561. this.offSize = offSize;
  24562. }
  24563. return CFFHeader;
  24564. })();
  24565. var CFFStrings = (function CFFStringsClosure() {
  24566. function CFFStrings() {
  24567. this.strings = [];
  24568. }
  24569. CFFStrings.prototype = {
  24570. get: function CFFStrings_get(index) {
  24571. if (index >= 0 && index <= 390) {
  24572. return CFFStandardStrings[index];
  24573. }
  24574. if (index - 391 <= this.strings.length) {
  24575. return this.strings[index - 391];
  24576. }
  24577. return CFFStandardStrings[0];
  24578. },
  24579. add: function CFFStrings_add(value) {
  24580. this.strings.push(value);
  24581. },
  24582. get count() {
  24583. return this.strings.length;
  24584. }
  24585. };
  24586. return CFFStrings;
  24587. })();
  24588. var CFFIndex = (function CFFIndexClosure() {
  24589. function CFFIndex() {
  24590. this.objects = [];
  24591. this.length = 0;
  24592. }
  24593. CFFIndex.prototype = {
  24594. add: function CFFIndex_add(data) {
  24595. this.length += data.length;
  24596. this.objects.push(data);
  24597. },
  24598. set: function CFFIndex_set(index, data) {
  24599. this.length += data.length - this.objects[index].length;
  24600. this.objects[index] = data;
  24601. },
  24602. get: function CFFIndex_get(index) {
  24603. return this.objects[index];
  24604. },
  24605. get count() {
  24606. return this.objects.length;
  24607. }
  24608. };
  24609. return CFFIndex;
  24610. })();
  24611. var CFFDict = (function CFFDictClosure() {
  24612. function CFFDict(tables, strings) {
  24613. this.keyToNameMap = tables.keyToNameMap;
  24614. this.nameToKeyMap = tables.nameToKeyMap;
  24615. this.defaults = tables.defaults;
  24616. this.types = tables.types;
  24617. this.opcodes = tables.opcodes;
  24618. this.order = tables.order;
  24619. this.strings = strings;
  24620. this.values = {};
  24621. }
  24622. CFFDict.prototype = {
  24623. // value should always be an array
  24624. setByKey: function CFFDict_setByKey(key, value) {
  24625. if (!(key in this.keyToNameMap)) {
  24626. return false;
  24627. }
  24628. // ignore empty values
  24629. if (value.length === 0) {
  24630. return true;
  24631. }
  24632. var type = this.types[key];
  24633. // remove the array wrapping these types of values
  24634. if (type === 'num' || type === 'sid' || type === 'offset') {
  24635. value = value[0];
  24636. }
  24637. this.values[key] = value;
  24638. return true;
  24639. },
  24640. setByName: function CFFDict_setByName(name, value) {
  24641. if (!(name in this.nameToKeyMap)) {
  24642. error('Invalid dictionary name "' + name + '"');
  24643. }
  24644. this.values[this.nameToKeyMap[name]] = value;
  24645. },
  24646. hasName: function CFFDict_hasName(name) {
  24647. return this.nameToKeyMap[name] in this.values;
  24648. },
  24649. getByName: function CFFDict_getByName(name) {
  24650. if (!(name in this.nameToKeyMap)) {
  24651. error('Invalid dictionary name "' + name + '"');
  24652. }
  24653. var key = this.nameToKeyMap[name];
  24654. if (!(key in this.values)) {
  24655. return this.defaults[key];
  24656. }
  24657. return this.values[key];
  24658. },
  24659. removeByName: function CFFDict_removeByName(name) {
  24660. delete this.values[this.nameToKeyMap[name]];
  24661. }
  24662. };
  24663. CFFDict.createTables = function CFFDict_createTables(layout) {
  24664. var tables = {
  24665. keyToNameMap: {},
  24666. nameToKeyMap: {},
  24667. defaults: {},
  24668. types: {},
  24669. opcodes: {},
  24670. order: []
  24671. };
  24672. for (var i = 0, ii = layout.length; i < ii; ++i) {
  24673. var entry = layout[i];
  24674. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  24675. tables.keyToNameMap[key] = entry[1];
  24676. tables.nameToKeyMap[entry[1]] = key;
  24677. tables.types[key] = entry[2];
  24678. tables.defaults[key] = entry[3];
  24679. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  24680. tables.order.push(key);
  24681. }
  24682. return tables;
  24683. };
  24684. return CFFDict;
  24685. })();
  24686. var CFFTopDict = (function CFFTopDictClosure() {
  24687. var layout = [
  24688. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  24689. [[12, 20], 'SyntheticBase', 'num', null],
  24690. [0, 'version', 'sid', null],
  24691. [1, 'Notice', 'sid', null],
  24692. [[12, 0], 'Copyright', 'sid', null],
  24693. [2, 'FullName', 'sid', null],
  24694. [3, 'FamilyName', 'sid', null],
  24695. [4, 'Weight', 'sid', null],
  24696. [[12, 1], 'isFixedPitch', 'num', 0],
  24697. [[12, 2], 'ItalicAngle', 'num', 0],
  24698. [[12, 3], 'UnderlinePosition', 'num', -100],
  24699. [[12, 4], 'UnderlineThickness', 'num', 50],
  24700. [[12, 5], 'PaintType', 'num', 0],
  24701. [[12, 6], 'CharstringType', 'num', 2],
  24702. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  24703. [0.001, 0, 0, 0.001, 0, 0]],
  24704. [13, 'UniqueID', 'num', null],
  24705. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  24706. [[12, 8], 'StrokeWidth', 'num', 0],
  24707. [14, 'XUID', 'array', null],
  24708. [15, 'charset', 'offset', 0],
  24709. [16, 'Encoding', 'offset', 0],
  24710. [17, 'CharStrings', 'offset', 0],
  24711. [18, 'Private', ['offset', 'offset'], null],
  24712. [[12, 21], 'PostScript', 'sid', null],
  24713. [[12, 22], 'BaseFontName', 'sid', null],
  24714. [[12, 23], 'BaseFontBlend', 'delta', null],
  24715. [[12, 31], 'CIDFontVersion', 'num', 0],
  24716. [[12, 32], 'CIDFontRevision', 'num', 0],
  24717. [[12, 33], 'CIDFontType', 'num', 0],
  24718. [[12, 34], 'CIDCount', 'num', 8720],
  24719. [[12, 35], 'UIDBase', 'num', null],
  24720. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  24721. // before FDArray.
  24722. [[12, 37], 'FDSelect', 'offset', null],
  24723. [[12, 36], 'FDArray', 'offset', null],
  24724. [[12, 38], 'FontName', 'sid', null]
  24725. ];
  24726. var tables = null;
  24727. function CFFTopDict(strings) {
  24728. if (tables === null) {
  24729. tables = CFFDict.createTables(layout);
  24730. }
  24731. CFFDict.call(this, tables, strings);
  24732. this.privateDict = null;
  24733. }
  24734. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  24735. return CFFTopDict;
  24736. })();
  24737. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  24738. var layout = [
  24739. [6, 'BlueValues', 'delta', null],
  24740. [7, 'OtherBlues', 'delta', null],
  24741. [8, 'FamilyBlues', 'delta', null],
  24742. [9, 'FamilyOtherBlues', 'delta', null],
  24743. [[12, 9], 'BlueScale', 'num', 0.039625],
  24744. [[12, 10], 'BlueShift', 'num', 7],
  24745. [[12, 11], 'BlueFuzz', 'num', 1],
  24746. [10, 'StdHW', 'num', null],
  24747. [11, 'StdVW', 'num', null],
  24748. [[12, 12], 'StemSnapH', 'delta', null],
  24749. [[12, 13], 'StemSnapV', 'delta', null],
  24750. [[12, 14], 'ForceBold', 'num', 0],
  24751. [[12, 17], 'LanguageGroup', 'num', 0],
  24752. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  24753. [[12, 19], 'initialRandomSeed', 'num', 0],
  24754. [20, 'defaultWidthX', 'num', 0],
  24755. [21, 'nominalWidthX', 'num', 0],
  24756. [19, 'Subrs', 'offset', null]
  24757. ];
  24758. var tables = null;
  24759. function CFFPrivateDict(strings) {
  24760. if (tables === null) {
  24761. tables = CFFDict.createTables(layout);
  24762. }
  24763. CFFDict.call(this, tables, strings);
  24764. this.subrsIndex = null;
  24765. }
  24766. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  24767. return CFFPrivateDict;
  24768. })();
  24769. var CFFCharsetPredefinedTypes = {
  24770. ISO_ADOBE: 0,
  24771. EXPERT: 1,
  24772. EXPERT_SUBSET: 2
  24773. };
  24774. var CFFCharset = (function CFFCharsetClosure() {
  24775. function CFFCharset(predefined, format, charset, raw) {
  24776. this.predefined = predefined;
  24777. this.format = format;
  24778. this.charset = charset;
  24779. this.raw = raw;
  24780. }
  24781. return CFFCharset;
  24782. })();
  24783. var CFFEncoding = (function CFFEncodingClosure() {
  24784. function CFFEncoding(predefined, format, encoding, raw) {
  24785. this.predefined = predefined;
  24786. this.format = format;
  24787. this.encoding = encoding;
  24788. this.raw = raw;
  24789. }
  24790. return CFFEncoding;
  24791. })();
  24792. var CFFFDSelect = (function CFFFDSelectClosure() {
  24793. function CFFFDSelect(fdSelect, raw) {
  24794. this.fdSelect = fdSelect;
  24795. this.raw = raw;
  24796. }
  24797. return CFFFDSelect;
  24798. })();
  24799. // Helper class to keep track of where an offset is within the data and helps
  24800. // filling in that offset once it's known.
  24801. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  24802. function CFFOffsetTracker() {
  24803. this.offsets = {};
  24804. }
  24805. CFFOffsetTracker.prototype = {
  24806. isTracking: function CFFOffsetTracker_isTracking(key) {
  24807. return key in this.offsets;
  24808. },
  24809. track: function CFFOffsetTracker_track(key, location) {
  24810. if (key in this.offsets) {
  24811. error('Already tracking location of ' + key);
  24812. }
  24813. this.offsets[key] = location;
  24814. },
  24815. offset: function CFFOffsetTracker_offset(value) {
  24816. for (var key in this.offsets) {
  24817. this.offsets[key] += value;
  24818. }
  24819. },
  24820. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  24821. values,
  24822. output) {
  24823. if (!(key in this.offsets)) {
  24824. error('Not tracking location of ' + key);
  24825. }
  24826. var data = output.data;
  24827. var dataOffset = this.offsets[key];
  24828. var size = 5;
  24829. for (var i = 0, ii = values.length; i < ii; ++i) {
  24830. var offset0 = i * size + dataOffset;
  24831. var offset1 = offset0 + 1;
  24832. var offset2 = offset0 + 2;
  24833. var offset3 = offset0 + 3;
  24834. var offset4 = offset0 + 4;
  24835. // It's easy to screw up offsets so perform this sanity check.
  24836. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  24837. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  24838. error('writing to an offset that is not empty');
  24839. }
  24840. var value = values[i];
  24841. data[offset0] = 0x1d;
  24842. data[offset1] = (value >> 24) & 0xFF;
  24843. data[offset2] = (value >> 16) & 0xFF;
  24844. data[offset3] = (value >> 8) & 0xFF;
  24845. data[offset4] = value & 0xFF;
  24846. }
  24847. }
  24848. };
  24849. return CFFOffsetTracker;
  24850. })();
  24851. // Takes a CFF and converts it to the binary representation.
  24852. var CFFCompiler = (function CFFCompilerClosure() {
  24853. function CFFCompiler(cff) {
  24854. this.cff = cff;
  24855. }
  24856. CFFCompiler.prototype = {
  24857. compile: function CFFCompiler_compile() {
  24858. var cff = this.cff;
  24859. var output = {
  24860. data: [],
  24861. length: 0,
  24862. add: function CFFCompiler_add(data) {
  24863. this.data = this.data.concat(data);
  24864. this.length = this.data.length;
  24865. }
  24866. };
  24867. // Compile the five entries that must be in order.
  24868. var header = this.compileHeader(cff.header);
  24869. output.add(header);
  24870. var nameIndex = this.compileNameIndex(cff.names);
  24871. output.add(nameIndex);
  24872. if (cff.isCIDFont) {
  24873. // The spec is unclear on how font matrices should relate to each other
  24874. // when there is one in the main top dict and the sub top dicts.
  24875. // Windows handles this differently than linux and osx so we have to
  24876. // normalize to work on all.
  24877. // Rules based off of some mailing list discussions:
  24878. // - If main font has a matrix and subfont doesn't, use the main matrix.
  24879. // - If no main font matrix and there is a subfont matrix, use the
  24880. // subfont matrix.
  24881. // - If both have matrices, concat together.
  24882. // - If neither have matrices, use default.
  24883. // To make this work on all platforms we move the top matrix into each
  24884. // sub top dict and concat if necessary.
  24885. if (cff.topDict.hasName('FontMatrix')) {
  24886. var base = cff.topDict.getByName('FontMatrix');
  24887. cff.topDict.removeByName('FontMatrix');
  24888. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  24889. var subDict = cff.fdArray[i];
  24890. var matrix = base.slice(0);
  24891. if (subDict.hasName('FontMatrix')) {
  24892. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  24893. }
  24894. subDict.setByName('FontMatrix', matrix);
  24895. }
  24896. }
  24897. }
  24898. var compiled = this.compileTopDicts([cff.topDict],
  24899. output.length,
  24900. cff.isCIDFont);
  24901. output.add(compiled.output);
  24902. var topDictTracker = compiled.trackers[0];
  24903. var stringIndex = this.compileStringIndex(cff.strings.strings);
  24904. output.add(stringIndex);
  24905. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  24906. output.add(globalSubrIndex);
  24907. // Now start on the other entries that have no specfic order.
  24908. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  24909. if (cff.encoding.predefined) {
  24910. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  24911. output);
  24912. } else {
  24913. var encoding = this.compileEncoding(cff.encoding);
  24914. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  24915. output.add(encoding);
  24916. }
  24917. }
  24918. if (cff.charset && cff.topDict.hasName('charset')) {
  24919. if (cff.charset.predefined) {
  24920. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  24921. output);
  24922. } else {
  24923. var charset = this.compileCharset(cff.charset);
  24924. topDictTracker.setEntryLocation('charset', [output.length], output);
  24925. output.add(charset);
  24926. }
  24927. }
  24928. var charStrings = this.compileCharStrings(cff.charStrings);
  24929. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  24930. output.add(charStrings);
  24931. if (cff.isCIDFont) {
  24932. // For some reason FDSelect must be in front of FDArray on windows. OSX
  24933. // and linux don't seem to care.
  24934. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  24935. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  24936. output.add(fdSelect);
  24937. // It is unclear if the sub font dictionary can have CID related
  24938. // dictionary keys, but the sanitizer doesn't like them so remove them.
  24939. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  24940. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  24941. output.add(compiled.output);
  24942. var fontDictTrackers = compiled.trackers;
  24943. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  24944. }
  24945. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  24946. // If the font data ends with INDEX whose object data is zero-length,
  24947. // the sanitizer will bail out. Add a dummy byte to avoid that.
  24948. output.add([0]);
  24949. return output.data;
  24950. },
  24951. encodeNumber: function CFFCompiler_encodeNumber(value) {
  24952. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  24953. return this.encodeInteger(value);
  24954. } else {
  24955. return this.encodeFloat(value);
  24956. }
  24957. },
  24958. encodeFloat: function CFFCompiler_encodeFloat(num) {
  24959. var value = num.toString();
  24960. // rounding inaccurate doubles
  24961. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  24962. if (m) {
  24963. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  24964. value = (Math.round(num * epsilon) / epsilon).toString();
  24965. }
  24966. var nibbles = '';
  24967. var i, ii;
  24968. for (i = 0, ii = value.length; i < ii; ++i) {
  24969. var a = value[i];
  24970. if (a === 'e') {
  24971. nibbles += value[++i] === '-' ? 'c' : 'b';
  24972. } else if (a === '.') {
  24973. nibbles += 'a';
  24974. } else if (a === '-') {
  24975. nibbles += 'e';
  24976. } else {
  24977. nibbles += a;
  24978. }
  24979. }
  24980. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  24981. var out = [30];
  24982. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  24983. out.push(parseInt(nibbles.substr(i, 2), 16));
  24984. }
  24985. return out;
  24986. },
  24987. encodeInteger: function CFFCompiler_encodeInteger(value) {
  24988. var code;
  24989. if (value >= -107 && value <= 107) {
  24990. code = [value + 139];
  24991. } else if (value >= 108 && value <= 1131) {
  24992. value = [value - 108];
  24993. code = [(value >> 8) + 247, value & 0xFF];
  24994. } else if (value >= -1131 && value <= -108) {
  24995. value = -value - 108;
  24996. code = [(value >> 8) + 251, value & 0xFF];
  24997. } else if (value >= -32768 && value <= 32767) {
  24998. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  24999. } else {
  25000. code = [0x1d,
  25001. (value >> 24) & 0xFF,
  25002. (value >> 16) & 0xFF,
  25003. (value >> 8) & 0xFF,
  25004. value & 0xFF];
  25005. }
  25006. return code;
  25007. },
  25008. compileHeader: function CFFCompiler_compileHeader(header) {
  25009. return [
  25010. header.major,
  25011. header.minor,
  25012. header.hdrSize,
  25013. header.offSize
  25014. ];
  25015. },
  25016. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  25017. var nameIndex = new CFFIndex();
  25018. for (var i = 0, ii = names.length; i < ii; ++i) {
  25019. nameIndex.add(stringToBytes(names[i]));
  25020. }
  25021. return this.compileIndex(nameIndex);
  25022. },
  25023. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  25024. length,
  25025. removeCidKeys) {
  25026. var fontDictTrackers = [];
  25027. var fdArrayIndex = new CFFIndex();
  25028. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25029. var fontDict = dicts[i];
  25030. if (removeCidKeys) {
  25031. fontDict.removeByName('CIDFontVersion');
  25032. fontDict.removeByName('CIDFontRevision');
  25033. fontDict.removeByName('CIDFontType');
  25034. fontDict.removeByName('CIDCount');
  25035. fontDict.removeByName('UIDBase');
  25036. }
  25037. var fontDictTracker = new CFFOffsetTracker();
  25038. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  25039. fontDictTrackers.push(fontDictTracker);
  25040. fdArrayIndex.add(fontDictData);
  25041. fontDictTracker.offset(length);
  25042. }
  25043. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  25044. return {
  25045. trackers: fontDictTrackers,
  25046. output: fdArrayIndex
  25047. };
  25048. },
  25049. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  25050. trackers,
  25051. output) {
  25052. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25053. var fontDict = dicts[i];
  25054. assert(fontDict.privateDict && fontDict.hasName('Private'),
  25055. 'There must be an private dictionary.');
  25056. var privateDict = fontDict.privateDict;
  25057. var privateDictTracker = new CFFOffsetTracker();
  25058. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  25059. var outputLength = output.length;
  25060. privateDictTracker.offset(outputLength);
  25061. if (!privateDictData.length) {
  25062. // The private dictionary was empty, set the output length to zero to
  25063. // ensure the offset length isn't out of bounds in the eyes of the
  25064. // sanitizer.
  25065. outputLength = 0;
  25066. }
  25067. trackers[i].setEntryLocation('Private',
  25068. [privateDictData.length, outputLength],
  25069. output);
  25070. output.add(privateDictData);
  25071. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  25072. var subrs = this.compileIndex(privateDict.subrsIndex);
  25073. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  25074. output);
  25075. output.add(subrs);
  25076. }
  25077. }
  25078. },
  25079. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  25080. var out = [];
  25081. // The dictionary keys must be in a certain order.
  25082. var order = dict.order;
  25083. for (var i = 0; i < order.length; ++i) {
  25084. var key = order[i];
  25085. if (!(key in dict.values)) {
  25086. continue;
  25087. }
  25088. var values = dict.values[key];
  25089. var types = dict.types[key];
  25090. if (!isArray(types)) {
  25091. types = [types];
  25092. }
  25093. if (!isArray(values)) {
  25094. values = [values];
  25095. }
  25096. // Remove any empty dict values.
  25097. if (values.length === 0) {
  25098. continue;
  25099. }
  25100. for (var j = 0, jj = types.length; j < jj; ++j) {
  25101. var type = types[j];
  25102. var value = values[j];
  25103. switch (type) {
  25104. case 'num':
  25105. case 'sid':
  25106. out = out.concat(this.encodeNumber(value));
  25107. break;
  25108. case 'offset':
  25109. // For offsets we just insert a 32bit integer so we don't have to
  25110. // deal with figuring out the length of the offset when it gets
  25111. // replaced later on by the compiler.
  25112. var name = dict.keyToNameMap[key];
  25113. // Some offsets have the offset and the length, so just record the
  25114. // position of the first one.
  25115. if (!offsetTracker.isTracking(name)) {
  25116. offsetTracker.track(name, out.length);
  25117. }
  25118. out = out.concat([0x1d, 0, 0, 0, 0]);
  25119. break;
  25120. case 'array':
  25121. case 'delta':
  25122. out = out.concat(this.encodeNumber(value));
  25123. for (var k = 1, kk = values.length; k < kk; ++k) {
  25124. out = out.concat(this.encodeNumber(values[k]));
  25125. }
  25126. break;
  25127. default:
  25128. error('Unknown data type of ' + type);
  25129. break;
  25130. }
  25131. }
  25132. out = out.concat(dict.opcodes[key]);
  25133. }
  25134. return out;
  25135. },
  25136. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  25137. var stringIndex = new CFFIndex();
  25138. for (var i = 0, ii = strings.length; i < ii; ++i) {
  25139. stringIndex.add(stringToBytes(strings[i]));
  25140. }
  25141. return this.compileIndex(stringIndex);
  25142. },
  25143. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  25144. var globalSubrIndex = this.cff.globalSubrIndex;
  25145. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  25146. },
  25147. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  25148. return this.compileIndex(charStrings);
  25149. },
  25150. compileCharset: function CFFCompiler_compileCharset(charset) {
  25151. return this.compileTypedArray(charset.raw);
  25152. },
  25153. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  25154. return this.compileTypedArray(encoding.raw);
  25155. },
  25156. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  25157. return this.compileTypedArray(fdSelect);
  25158. },
  25159. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  25160. var out = [];
  25161. for (var i = 0, ii = data.length; i < ii; ++i) {
  25162. out[i] = data[i];
  25163. }
  25164. return out;
  25165. },
  25166. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  25167. trackers = trackers || [];
  25168. var objects = index.objects;
  25169. // First 2 bytes contains the number of objects contained into this index
  25170. var count = objects.length;
  25171. // If there is no object, just create an index. This technically
  25172. // should just be [0, 0] but OTS has an issue with that.
  25173. if (count === 0) {
  25174. return [0, 0, 0];
  25175. }
  25176. var data = [(count >> 8) & 0xFF, count & 0xff];
  25177. var lastOffset = 1, i;
  25178. for (i = 0; i < count; ++i) {
  25179. lastOffset += objects[i].length;
  25180. }
  25181. var offsetSize;
  25182. if (lastOffset < 0x100) {
  25183. offsetSize = 1;
  25184. } else if (lastOffset < 0x10000) {
  25185. offsetSize = 2;
  25186. } else if (lastOffset < 0x1000000) {
  25187. offsetSize = 3;
  25188. } else {
  25189. offsetSize = 4;
  25190. }
  25191. // Next byte contains the offset size use to reference object in the file
  25192. data.push(offsetSize);
  25193. // Add another offset after this one because we need a new offset
  25194. var relativeOffset = 1;
  25195. for (i = 0; i < count + 1; i++) {
  25196. if (offsetSize === 1) {
  25197. data.push(relativeOffset & 0xFF);
  25198. } else if (offsetSize === 2) {
  25199. data.push((relativeOffset >> 8) & 0xFF,
  25200. relativeOffset & 0xFF);
  25201. } else if (offsetSize === 3) {
  25202. data.push((relativeOffset >> 16) & 0xFF,
  25203. (relativeOffset >> 8) & 0xFF,
  25204. relativeOffset & 0xFF);
  25205. } else {
  25206. data.push((relativeOffset >>> 24) & 0xFF,
  25207. (relativeOffset >> 16) & 0xFF,
  25208. (relativeOffset >> 8) & 0xFF,
  25209. relativeOffset & 0xFF);
  25210. }
  25211. if (objects[i]) {
  25212. relativeOffset += objects[i].length;
  25213. }
  25214. }
  25215. for (i = 0; i < count; i++) {
  25216. // Notify the tracker where the object will be offset in the data.
  25217. if (trackers[i]) {
  25218. trackers[i].offset(data.length);
  25219. }
  25220. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  25221. data.push(objects[i][j]);
  25222. }
  25223. }
  25224. return data;
  25225. }
  25226. };
  25227. return CFFCompiler;
  25228. })();
  25229. // Workaround for seac on Windows.
  25230. (function checkSeacSupport() {
  25231. if (/Windows/.test(navigator.userAgent)) {
  25232. SEAC_ANALYSIS_ENABLED = true;
  25233. }
  25234. })();
  25235. // Workaround for Private Use Area characters in Chrome on Windows
  25236. // http://code.google.com/p/chromium/issues/detail?id=122465
  25237. // https://github.com/mozilla/pdf.js/issues/1689
  25238. (function checkChromeWindows() {
  25239. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  25240. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  25241. }
  25242. })();
  25243. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25244. function getLong(data, offset) {
  25245. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25246. (data[offset + 2] << 8) | data[offset + 3];
  25247. }
  25248. function getUshort(data, offset) {
  25249. return (data[offset] << 8) | data[offset + 1];
  25250. }
  25251. function parseCmap(data, start, end) {
  25252. var offset = (getUshort(data, start + 2) === 1 ?
  25253. getLong(data, start + 8) : getLong(data, start + 16));
  25254. var format = getUshort(data, start + offset);
  25255. var length, ranges, p, i;
  25256. if (format === 4) {
  25257. length = getUshort(data, start + offset + 2);
  25258. var segCount = getUshort(data, start + offset + 6) >> 1;
  25259. p = start + offset + 14;
  25260. ranges = [];
  25261. for (i = 0; i < segCount; i++, p += 2) {
  25262. ranges[i] = {end: getUshort(data, p)};
  25263. }
  25264. p += 2;
  25265. for (i = 0; i < segCount; i++, p += 2) {
  25266. ranges[i].start = getUshort(data, p);
  25267. }
  25268. for (i = 0; i < segCount; i++, p += 2) {
  25269. ranges[i].idDelta = getUshort(data, p);
  25270. }
  25271. for (i = 0; i < segCount; i++, p += 2) {
  25272. var idOffset = getUshort(data, p);
  25273. if (idOffset === 0) {
  25274. continue;
  25275. }
  25276. ranges[i].ids = [];
  25277. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25278. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25279. idOffset += 2;
  25280. }
  25281. }
  25282. return ranges;
  25283. } else if (format === 12) {
  25284. length = getLong(data, start + offset + 4);
  25285. var groups = getLong(data, start + offset + 12);
  25286. p = start + offset + 16;
  25287. ranges = [];
  25288. for (i = 0; i < groups; i++) {
  25289. ranges.push({
  25290. start: getLong(data, p),
  25291. end: getLong(data, p + 4),
  25292. idDelta: getLong(data, p + 8) - getLong(data, p)
  25293. });
  25294. p += 12;
  25295. }
  25296. return ranges;
  25297. }
  25298. error('not supported cmap: ' + format);
  25299. }
  25300. function parseCff(data, start, end) {
  25301. var properties = {};
  25302. var parser = new CFFParser(new Stream(data, start, end - start),
  25303. properties);
  25304. var cff = parser.parse();
  25305. return {
  25306. glyphs: cff.charStrings.objects,
  25307. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25308. cff.topDict.privateDict.subrsIndex.objects),
  25309. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25310. };
  25311. }
  25312. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25313. var itemSize, itemDecode;
  25314. if (isGlyphLocationsLong) {
  25315. itemSize = 4;
  25316. itemDecode = function fontItemDecodeLong(data, offset) {
  25317. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25318. (data[offset + 2] << 8) | data[offset + 3];
  25319. };
  25320. } else {
  25321. itemSize = 2;
  25322. itemDecode = function fontItemDecode(data, offset) {
  25323. return (data[offset] << 9) | (data[offset + 1] << 1);
  25324. };
  25325. }
  25326. var glyphs = [];
  25327. var startOffset = itemDecode(loca, 0);
  25328. for (var j = itemSize; j < loca.length; j += itemSize) {
  25329. var endOffset = itemDecode(loca, j);
  25330. glyphs.push(glyf.subarray(startOffset, endOffset));
  25331. startOffset = endOffset;
  25332. }
  25333. return glyphs;
  25334. }
  25335. function lookupCmap(ranges, unicode) {
  25336. var code = unicode.charCodeAt(0);
  25337. var l = 0, r = ranges.length - 1;
  25338. while (l < r) {
  25339. var c = (l + r + 1) >> 1;
  25340. if (code < ranges[c].start) {
  25341. r = c - 1;
  25342. } else {
  25343. l = c;
  25344. }
  25345. }
  25346. if (ranges[l].start <= code && code <= ranges[l].end) {
  25347. return (ranges[l].idDelta + (ranges[l].ids ?
  25348. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25349. }
  25350. return 0;
  25351. }
  25352. function compileGlyf(code, js, font) {
  25353. function moveTo(x, y) {
  25354. js.push('c.moveTo(' + x + ',' + y + ');');
  25355. }
  25356. function lineTo(x, y) {
  25357. js.push('c.lineTo(' + x + ',' + y + ');');
  25358. }
  25359. function quadraticCurveTo(xa, ya, x, y) {
  25360. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  25361. x + ',' + y + ');');
  25362. }
  25363. var i = 0;
  25364. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25365. var flags;
  25366. var x = 0, y = 0;
  25367. i += 10;
  25368. if (numberOfContours < 0) {
  25369. // composite glyph
  25370. do {
  25371. flags = (code[i] << 8) | code[i + 1];
  25372. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25373. i += 4;
  25374. var arg1, arg2;
  25375. if ((flags & 0x01)) {
  25376. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25377. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25378. i += 4;
  25379. } else {
  25380. arg1 = code[i++]; arg2 = code[i++];
  25381. }
  25382. if ((flags & 0x02)) {
  25383. x = arg1;
  25384. y = arg2;
  25385. } else {
  25386. x = 0; y = 0; // TODO "they are points" ?
  25387. }
  25388. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25389. if ((flags & 0x08)) {
  25390. scaleX =
  25391. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25392. i += 2;
  25393. } else if ((flags & 0x40)) {
  25394. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25395. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25396. i += 4;
  25397. } else if ((flags & 0x80)) {
  25398. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25399. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25400. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25401. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25402. i += 8;
  25403. }
  25404. var subglyph = font.glyphs[glyphIndex];
  25405. if (subglyph) {
  25406. js.push('c.save();');
  25407. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  25408. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  25409. compileGlyf(subglyph, js, font);
  25410. js.push('c.restore();');
  25411. }
  25412. } while ((flags & 0x20));
  25413. } else {
  25414. // simple glyph
  25415. var endPtsOfContours = [];
  25416. var j, jj;
  25417. for (j = 0; j < numberOfContours; j++) {
  25418. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25419. i += 2;
  25420. }
  25421. var instructionLength = (code[i] << 8) | code[i + 1];
  25422. i += 2 + instructionLength; // skipping the instructions
  25423. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25424. var points = [];
  25425. while (points.length < numberOfPoints) {
  25426. flags = code[i++];
  25427. var repeat = 1;
  25428. if ((flags & 0x08)) {
  25429. repeat += code[i++];
  25430. }
  25431. while (repeat-- > 0) {
  25432. points.push({flags: flags});
  25433. }
  25434. }
  25435. for (j = 0; j < numberOfPoints; j++) {
  25436. switch (points[j].flags & 0x12) {
  25437. case 0x00:
  25438. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25439. i += 2;
  25440. break;
  25441. case 0x02:
  25442. x -= code[i++];
  25443. break;
  25444. case 0x12:
  25445. x += code[i++];
  25446. break;
  25447. }
  25448. points[j].x = x;
  25449. }
  25450. for (j = 0; j < numberOfPoints; j++) {
  25451. switch (points[j].flags & 0x24) {
  25452. case 0x00:
  25453. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25454. i += 2;
  25455. break;
  25456. case 0x04:
  25457. y -= code[i++];
  25458. break;
  25459. case 0x24:
  25460. y += code[i++];
  25461. break;
  25462. }
  25463. points[j].y = y;
  25464. }
  25465. var startPoint = 0;
  25466. for (i = 0; i < numberOfContours; i++) {
  25467. var endPoint = endPtsOfContours[i];
  25468. // contours might have implicit points, which is located in the middle
  25469. // between two neighboring off-curve points
  25470. var contour = points.slice(startPoint, endPoint + 1);
  25471. if ((contour[0].flags & 1)) {
  25472. contour.push(contour[0]); // using start point at the contour end
  25473. } else if ((contour[contour.length - 1].flags & 1)) {
  25474. // first is off-curve point, trying to use one from the end
  25475. contour.unshift(contour[contour.length - 1]);
  25476. } else {
  25477. // start and end are off-curve points, creating implicit one
  25478. var p = {
  25479. flags: 1,
  25480. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25481. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25482. };
  25483. contour.unshift(p);
  25484. contour.push(p);
  25485. }
  25486. moveTo(contour[0].x, contour[0].y);
  25487. for (j = 1, jj = contour.length; j < jj; j++) {
  25488. if ((contour[j].flags & 1)) {
  25489. lineTo(contour[j].x, contour[j].y);
  25490. } else if ((contour[j + 1].flags & 1)){
  25491. quadraticCurveTo(contour[j].x, contour[j].y,
  25492. contour[j + 1].x, contour[j + 1].y);
  25493. j++;
  25494. } else {
  25495. quadraticCurveTo(contour[j].x, contour[j].y,
  25496. (contour[j].x + contour[j + 1].x) / 2,
  25497. (contour[j].y + contour[j + 1].y) / 2);
  25498. }
  25499. }
  25500. startPoint = endPoint + 1;
  25501. }
  25502. }
  25503. }
  25504. function compileCharString(code, js, font) {
  25505. var stack = [];
  25506. var x = 0, y = 0;
  25507. var stems = 0;
  25508. function moveTo(x, y) {
  25509. js.push('c.moveTo(' + x + ',' + y + ');');
  25510. }
  25511. function lineTo(x, y) {
  25512. js.push('c.lineTo(' + x + ',' + y + ');');
  25513. }
  25514. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25515. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  25516. x + ',' + y + ');');
  25517. }
  25518. function parse(code) {
  25519. var i = 0;
  25520. while (i < code.length) {
  25521. var stackClean = false;
  25522. var v = code[i++];
  25523. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25524. switch (v) {
  25525. case 1: // hstem
  25526. stems += stack.length >> 1;
  25527. stackClean = true;
  25528. break;
  25529. case 3: // vstem
  25530. stems += stack.length >> 1;
  25531. stackClean = true;
  25532. break;
  25533. case 4: // vmoveto
  25534. y += stack.pop();
  25535. moveTo(x, y);
  25536. stackClean = true;
  25537. break;
  25538. case 5: // rlineto
  25539. while (stack.length > 0) {
  25540. x += stack.shift();
  25541. y += stack.shift();
  25542. lineTo(x, y);
  25543. }
  25544. break;
  25545. case 6: // hlineto
  25546. while (stack.length > 0) {
  25547. x += stack.shift();
  25548. lineTo(x, y);
  25549. if (stack.length === 0) {
  25550. break;
  25551. }
  25552. y += stack.shift();
  25553. lineTo(x, y);
  25554. }
  25555. break;
  25556. case 7: // vlineto
  25557. while (stack.length > 0) {
  25558. y += stack.shift();
  25559. lineTo(x, y);
  25560. if (stack.length === 0) {
  25561. break;
  25562. }
  25563. x += stack.shift();
  25564. lineTo(x, y);
  25565. }
  25566. break;
  25567. case 8: // rrcurveto
  25568. while (stack.length > 0) {
  25569. xa = x + stack.shift(); ya = y + stack.shift();
  25570. xb = xa + stack.shift(); yb = ya + stack.shift();
  25571. x = xb + stack.shift(); y = yb + stack.shift();
  25572. bezierCurveTo(xa, ya, xb, yb, x, y);
  25573. }
  25574. break;
  25575. case 10: // callsubr
  25576. n = stack.pop() + font.subrsBias;
  25577. subrCode = font.subrs[n];
  25578. if (subrCode) {
  25579. parse(subrCode);
  25580. }
  25581. break;
  25582. case 11: // return
  25583. return;
  25584. case 12:
  25585. v = code[i++];
  25586. switch (v) {
  25587. case 34: // flex
  25588. xa = x + stack.shift();
  25589. xb = xa + stack.shift(); y1 = y + stack.shift();
  25590. x = xb + stack.shift();
  25591. bezierCurveTo(xa, y, xb, y1, x, y1);
  25592. xa = x + stack.shift();
  25593. xb = xa + stack.shift();
  25594. x = xb + stack.shift();
  25595. bezierCurveTo(xa, y1, xb, y, x, y);
  25596. break;
  25597. case 35: // flex
  25598. xa = x + stack.shift(); ya = y + stack.shift();
  25599. xb = xa + stack.shift(); yb = ya + stack.shift();
  25600. x = xb + stack.shift(); y = yb + stack.shift();
  25601. bezierCurveTo(xa, ya, xb, yb, x, y);
  25602. xa = x + stack.shift(); ya = y + stack.shift();
  25603. xb = xa + stack.shift(); yb = ya + stack.shift();
  25604. x = xb + stack.shift(); y = yb + stack.shift();
  25605. bezierCurveTo(xa, ya, xb, yb, x, y);
  25606. stack.pop(); // fd
  25607. break;
  25608. case 36: // hflex1
  25609. xa = x + stack.shift(); y1 = y + stack.shift();
  25610. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25611. x = xb + stack.shift();
  25612. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25613. xa = x + stack.shift();
  25614. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25615. x = xb + stack.shift();
  25616. bezierCurveTo(xa, y2, xb, y3, x, y);
  25617. break;
  25618. case 37: // flex1
  25619. var x0 = x, y0 = y;
  25620. xa = x + stack.shift(); ya = y + stack.shift();
  25621. xb = xa + stack.shift(); yb = ya + stack.shift();
  25622. x = xb + stack.shift(); y = yb + stack.shift();
  25623. bezierCurveTo(xa, ya, xb, yb, x, y);
  25624. xa = x + stack.shift(); ya = y + stack.shift();
  25625. xb = xa + stack.shift(); yb = ya + stack.shift();
  25626. x = xb; y = yb;
  25627. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25628. x += stack.shift();
  25629. } else {
  25630. y += stack.shift();
  25631. }
  25632. bezierCurveTo(xa, ya, xb, yb, x, y);
  25633. break;
  25634. default:
  25635. error('unknown operator: 12 ' + v);
  25636. }
  25637. break;
  25638. case 14: // endchar
  25639. if (stack.length >= 4) {
  25640. var achar = stack.pop();
  25641. var bchar = stack.pop();
  25642. y = stack.pop();
  25643. x = stack.pop();
  25644. js.push('c.save();');
  25645. js.push('c.translate('+ x + ',' + y + ');');
  25646. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25647. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  25648. compileCharString(font.glyphs[gid], js, font);
  25649. js.push('c.restore();');
  25650. gid = lookupCmap(font.cmap, String.fromCharCode(
  25651. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  25652. compileCharString(font.glyphs[gid], js, font);
  25653. }
  25654. return;
  25655. case 18: // hstemhm
  25656. stems += stack.length >> 1;
  25657. stackClean = true;
  25658. break;
  25659. case 19: // hintmask
  25660. stems += stack.length >> 1;
  25661. i += (stems + 7) >> 3;
  25662. stackClean = true;
  25663. break;
  25664. case 20: // cntrmask
  25665. stems += stack.length >> 1;
  25666. i += (stems + 7) >> 3;
  25667. stackClean = true;
  25668. break;
  25669. case 21: // rmoveto
  25670. y += stack.pop();
  25671. x += stack.pop();
  25672. moveTo(x, y);
  25673. stackClean = true;
  25674. break;
  25675. case 22: // hmoveto
  25676. x += stack.pop();
  25677. moveTo(x, y);
  25678. stackClean = true;
  25679. break;
  25680. case 23: // vstemhm
  25681. stems += stack.length >> 1;
  25682. stackClean = true;
  25683. break;
  25684. case 24: // rcurveline
  25685. while (stack.length > 2) {
  25686. xa = x + stack.shift(); ya = y + stack.shift();
  25687. xb = xa + stack.shift(); yb = ya + stack.shift();
  25688. x = xb + stack.shift(); y = yb + stack.shift();
  25689. bezierCurveTo(xa, ya, xb, yb, x, y);
  25690. }
  25691. x += stack.shift();
  25692. y += stack.shift();
  25693. lineTo(x, y);
  25694. break;
  25695. case 25: // rlinecurve
  25696. while (stack.length > 6) {
  25697. x += stack.shift();
  25698. y += stack.shift();
  25699. lineTo(x, y);
  25700. }
  25701. xa = x + stack.shift(); ya = y + stack.shift();
  25702. xb = xa + stack.shift(); yb = ya + stack.shift();
  25703. x = xb + stack.shift(); y = yb + stack.shift();
  25704. bezierCurveTo(xa, ya, xb, yb, x, y);
  25705. break;
  25706. case 26: // vvcurveto
  25707. if (stack.length % 2) {
  25708. x += stack.shift();
  25709. }
  25710. while (stack.length > 0) {
  25711. xa = x; ya = y + stack.shift();
  25712. xb = xa + stack.shift(); yb = ya + stack.shift();
  25713. x = xb; y = yb + stack.shift();
  25714. bezierCurveTo(xa, ya, xb, yb, x, y);
  25715. }
  25716. break;
  25717. case 27: // hhcurveto
  25718. if (stack.length % 2) {
  25719. y += stack.shift();
  25720. }
  25721. while (stack.length > 0) {
  25722. xa = x + stack.shift(); ya = y;
  25723. xb = xa + stack.shift(); yb = ya + stack.shift();
  25724. x = xb + stack.shift(); y = yb;
  25725. bezierCurveTo(xa, ya, xb, yb, x, y);
  25726. }
  25727. break;
  25728. case 28:
  25729. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25730. i += 2;
  25731. break;
  25732. case 29: // callgsubr
  25733. n = stack.pop() + font.gsubrsBias;
  25734. subrCode = font.gsubrs[n];
  25735. if (subrCode) {
  25736. parse(subrCode);
  25737. }
  25738. break;
  25739. case 30: // vhcurveto
  25740. while (stack.length > 0) {
  25741. xa = x; ya = y + stack.shift();
  25742. xb = xa + stack.shift(); yb = ya + stack.shift();
  25743. x = xb + stack.shift();
  25744. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25745. bezierCurveTo(xa, ya, xb, yb, x, y);
  25746. if (stack.length === 0) {
  25747. break;
  25748. }
  25749. xa = x + stack.shift(); ya = y;
  25750. xb = xa + stack.shift(); yb = ya + stack.shift();
  25751. y = yb + stack.shift();
  25752. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25753. bezierCurveTo(xa, ya, xb, yb, x, y);
  25754. }
  25755. break;
  25756. case 31: // hvcurveto
  25757. while (stack.length > 0) {
  25758. xa = x + stack.shift(); ya = y;
  25759. xb = xa + stack.shift(); yb = ya + stack.shift();
  25760. y = yb + stack.shift();
  25761. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25762. bezierCurveTo(xa, ya, xb, yb, x, y);
  25763. if (stack.length === 0) {
  25764. break;
  25765. }
  25766. xa = x; ya = y + stack.shift();
  25767. xb = xa + stack.shift(); yb = ya + stack.shift();
  25768. x = xb + stack.shift();
  25769. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25770. bezierCurveTo(xa, ya, xb, yb, x, y);
  25771. }
  25772. break;
  25773. default:
  25774. if (v < 32) {
  25775. error('unknown operator: ' + v);
  25776. }
  25777. if (v < 247) {
  25778. stack.push(v - 139);
  25779. } else if (v < 251) {
  25780. stack.push((v - 247) * 256 + code[i++] + 108);
  25781. } else if (v < 255) {
  25782. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25783. } else {
  25784. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25785. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25786. i += 4;
  25787. }
  25788. break;
  25789. }
  25790. if (stackClean) {
  25791. stack.length = 0;
  25792. }
  25793. }
  25794. }
  25795. parse(code);
  25796. }
  25797. var noop = '';
  25798. function CompiledFont(fontMatrix) {
  25799. this.compiledGlyphs = {};
  25800. this.fontMatrix = fontMatrix;
  25801. }
  25802. CompiledFont.prototype = {
  25803. getPathJs: function (unicode) {
  25804. var gid = lookupCmap(this.cmap, unicode);
  25805. var fn = this.compiledGlyphs[gid];
  25806. if (!fn) {
  25807. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25808. }
  25809. return fn;
  25810. },
  25811. compileGlyph: function (code) {
  25812. if (!code || code.length === 0 || code[0] === 14) {
  25813. return noop;
  25814. }
  25815. var js = [];
  25816. js.push('c.save();');
  25817. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  25818. js.push('c.scale(size, -size);');
  25819. this.compileGlyphImpl(code, js);
  25820. js.push('c.restore();');
  25821. return js.join('\n');
  25822. },
  25823. compileGlyphImpl: function () {
  25824. error('Children classes should implement this.');
  25825. },
  25826. hasBuiltPath: function (unicode) {
  25827. var gid = lookupCmap(this.cmap, unicode);
  25828. return gid in this.compiledGlyphs;
  25829. }
  25830. };
  25831. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25832. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25833. CompiledFont.call(this, fontMatrix);
  25834. this.glyphs = glyphs;
  25835. this.cmap = cmap;
  25836. this.compiledGlyphs = [];
  25837. }
  25838. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25839. compileGlyphImpl: function (code, js) {
  25840. compileGlyf(code, js, this);
  25841. }
  25842. });
  25843. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25844. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25845. CompiledFont.call(this, fontMatrix);
  25846. this.glyphs = cffInfo.glyphs;
  25847. this.gsubrs = cffInfo.gsubrs || [];
  25848. this.subrs = cffInfo.subrs || [];
  25849. this.cmap = cmap;
  25850. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  25851. this.compiledGlyphs = [];
  25852. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25853. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25854. this.subrsBias = (this.subrs.length < 1240 ?
  25855. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25856. }
  25857. Util.inherit(Type2Compiled, CompiledFont, {
  25858. compileGlyphImpl: function (code, js) {
  25859. compileCharString(code, js, this);
  25860. }
  25861. });
  25862. return {
  25863. create: function FontRendererFactory_create(font) {
  25864. var data = new Uint8Array(font.data);
  25865. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25866. var numTables = getUshort(data, 4);
  25867. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25868. var tag = bytesToString(data.subarray(p, p + 4));
  25869. var offset = getLong(data, p + 8);
  25870. var length = getLong(data, p + 12);
  25871. switch (tag) {
  25872. case 'cmap':
  25873. cmap = parseCmap(data, offset, offset + length);
  25874. break;
  25875. case 'glyf':
  25876. glyf = data.subarray(offset, offset + length);
  25877. break;
  25878. case 'loca':
  25879. loca = data.subarray(offset, offset + length);
  25880. break;
  25881. case 'head':
  25882. unitsPerEm = getUshort(data, offset + 18);
  25883. indexToLocFormat = getUshort(data, offset + 50);
  25884. break;
  25885. case 'CFF ':
  25886. cff = parseCff(data, offset, offset + length);
  25887. break;
  25888. }
  25889. }
  25890. if (glyf) {
  25891. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25892. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25893. return new TrueTypeCompiled(
  25894. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25895. } else {
  25896. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25897. }
  25898. }
  25899. };
  25900. })();
  25901. var GlyphsUnicode = {
  25902. A: 0x0041,
  25903. AE: 0x00C6,
  25904. AEacute: 0x01FC,
  25905. AEmacron: 0x01E2,
  25906. AEsmall: 0xF7E6,
  25907. Aacute: 0x00C1,
  25908. Aacutesmall: 0xF7E1,
  25909. Abreve: 0x0102,
  25910. Abreveacute: 0x1EAE,
  25911. Abrevecyrillic: 0x04D0,
  25912. Abrevedotbelow: 0x1EB6,
  25913. Abrevegrave: 0x1EB0,
  25914. Abrevehookabove: 0x1EB2,
  25915. Abrevetilde: 0x1EB4,
  25916. Acaron: 0x01CD,
  25917. Acircle: 0x24B6,
  25918. Acircumflex: 0x00C2,
  25919. Acircumflexacute: 0x1EA4,
  25920. Acircumflexdotbelow: 0x1EAC,
  25921. Acircumflexgrave: 0x1EA6,
  25922. Acircumflexhookabove: 0x1EA8,
  25923. Acircumflexsmall: 0xF7E2,
  25924. Acircumflextilde: 0x1EAA,
  25925. Acute: 0xF6C9,
  25926. Acutesmall: 0xF7B4,
  25927. Acyrillic: 0x0410,
  25928. Adblgrave: 0x0200,
  25929. Adieresis: 0x00C4,
  25930. Adieresiscyrillic: 0x04D2,
  25931. Adieresismacron: 0x01DE,
  25932. Adieresissmall: 0xF7E4,
  25933. Adotbelow: 0x1EA0,
  25934. Adotmacron: 0x01E0,
  25935. Agrave: 0x00C0,
  25936. Agravesmall: 0xF7E0,
  25937. Ahookabove: 0x1EA2,
  25938. Aiecyrillic: 0x04D4,
  25939. Ainvertedbreve: 0x0202,
  25940. Alpha: 0x0391,
  25941. Alphatonos: 0x0386,
  25942. Amacron: 0x0100,
  25943. Amonospace: 0xFF21,
  25944. Aogonek: 0x0104,
  25945. Aring: 0x00C5,
  25946. Aringacute: 0x01FA,
  25947. Aringbelow: 0x1E00,
  25948. Aringsmall: 0xF7E5,
  25949. Asmall: 0xF761,
  25950. Atilde: 0x00C3,
  25951. Atildesmall: 0xF7E3,
  25952. Aybarmenian: 0x0531,
  25953. B: 0x0042,
  25954. Bcircle: 0x24B7,
  25955. Bdotaccent: 0x1E02,
  25956. Bdotbelow: 0x1E04,
  25957. Becyrillic: 0x0411,
  25958. Benarmenian: 0x0532,
  25959. Beta: 0x0392,
  25960. Bhook: 0x0181,
  25961. Blinebelow: 0x1E06,
  25962. Bmonospace: 0xFF22,
  25963. Brevesmall: 0xF6F4,
  25964. Bsmall: 0xF762,
  25965. Btopbar: 0x0182,
  25966. C: 0x0043,
  25967. Caarmenian: 0x053E,
  25968. Cacute: 0x0106,
  25969. Caron: 0xF6CA,
  25970. Caronsmall: 0xF6F5,
  25971. Ccaron: 0x010C,
  25972. Ccedilla: 0x00C7,
  25973. Ccedillaacute: 0x1E08,
  25974. Ccedillasmall: 0xF7E7,
  25975. Ccircle: 0x24B8,
  25976. Ccircumflex: 0x0108,
  25977. Cdot: 0x010A,
  25978. Cdotaccent: 0x010A,
  25979. Cedillasmall: 0xF7B8,
  25980. Chaarmenian: 0x0549,
  25981. Cheabkhasiancyrillic: 0x04BC,
  25982. Checyrillic: 0x0427,
  25983. Chedescenderabkhasiancyrillic: 0x04BE,
  25984. Chedescendercyrillic: 0x04B6,
  25985. Chedieresiscyrillic: 0x04F4,
  25986. Cheharmenian: 0x0543,
  25987. Chekhakassiancyrillic: 0x04CB,
  25988. Cheverticalstrokecyrillic: 0x04B8,
  25989. Chi: 0x03A7,
  25990. Chook: 0x0187,
  25991. Circumflexsmall: 0xF6F6,
  25992. Cmonospace: 0xFF23,
  25993. Coarmenian: 0x0551,
  25994. Csmall: 0xF763,
  25995. D: 0x0044,
  25996. DZ: 0x01F1,
  25997. DZcaron: 0x01C4,
  25998. Daarmenian: 0x0534,
  25999. Dafrican: 0x0189,
  26000. Dcaron: 0x010E,
  26001. Dcedilla: 0x1E10,
  26002. Dcircle: 0x24B9,
  26003. Dcircumflexbelow: 0x1E12,
  26004. Dcroat: 0x0110,
  26005. Ddotaccent: 0x1E0A,
  26006. Ddotbelow: 0x1E0C,
  26007. Decyrillic: 0x0414,
  26008. Deicoptic: 0x03EE,
  26009. Delta: 0x2206,
  26010. Deltagreek: 0x0394,
  26011. Dhook: 0x018A,
  26012. Dieresis: 0xF6CB,
  26013. DieresisAcute: 0xF6CC,
  26014. DieresisGrave: 0xF6CD,
  26015. Dieresissmall: 0xF7A8,
  26016. Digammagreek: 0x03DC,
  26017. Djecyrillic: 0x0402,
  26018. Dlinebelow: 0x1E0E,
  26019. Dmonospace: 0xFF24,
  26020. Dotaccentsmall: 0xF6F7,
  26021. Dslash: 0x0110,
  26022. Dsmall: 0xF764,
  26023. Dtopbar: 0x018B,
  26024. Dz: 0x01F2,
  26025. Dzcaron: 0x01C5,
  26026. Dzeabkhasiancyrillic: 0x04E0,
  26027. Dzecyrillic: 0x0405,
  26028. Dzhecyrillic: 0x040F,
  26029. E: 0x0045,
  26030. Eacute: 0x00C9,
  26031. Eacutesmall: 0xF7E9,
  26032. Ebreve: 0x0114,
  26033. Ecaron: 0x011A,
  26034. Ecedillabreve: 0x1E1C,
  26035. Echarmenian: 0x0535,
  26036. Ecircle: 0x24BA,
  26037. Ecircumflex: 0x00CA,
  26038. Ecircumflexacute: 0x1EBE,
  26039. Ecircumflexbelow: 0x1E18,
  26040. Ecircumflexdotbelow: 0x1EC6,
  26041. Ecircumflexgrave: 0x1EC0,
  26042. Ecircumflexhookabove: 0x1EC2,
  26043. Ecircumflexsmall: 0xF7EA,
  26044. Ecircumflextilde: 0x1EC4,
  26045. Ecyrillic: 0x0404,
  26046. Edblgrave: 0x0204,
  26047. Edieresis: 0x00CB,
  26048. Edieresissmall: 0xF7EB,
  26049. Edot: 0x0116,
  26050. Edotaccent: 0x0116,
  26051. Edotbelow: 0x1EB8,
  26052. Efcyrillic: 0x0424,
  26053. Egrave: 0x00C8,
  26054. Egravesmall: 0xF7E8,
  26055. Eharmenian: 0x0537,
  26056. Ehookabove: 0x1EBA,
  26057. Eightroman: 0x2167,
  26058. Einvertedbreve: 0x0206,
  26059. Eiotifiedcyrillic: 0x0464,
  26060. Elcyrillic: 0x041B,
  26061. Elevenroman: 0x216A,
  26062. Emacron: 0x0112,
  26063. Emacronacute: 0x1E16,
  26064. Emacrongrave: 0x1E14,
  26065. Emcyrillic: 0x041C,
  26066. Emonospace: 0xFF25,
  26067. Encyrillic: 0x041D,
  26068. Endescendercyrillic: 0x04A2,
  26069. Eng: 0x014A,
  26070. Enghecyrillic: 0x04A4,
  26071. Enhookcyrillic: 0x04C7,
  26072. Eogonek: 0x0118,
  26073. Eopen: 0x0190,
  26074. Epsilon: 0x0395,
  26075. Epsilontonos: 0x0388,
  26076. Ercyrillic: 0x0420,
  26077. Ereversed: 0x018E,
  26078. Ereversedcyrillic: 0x042D,
  26079. Escyrillic: 0x0421,
  26080. Esdescendercyrillic: 0x04AA,
  26081. Esh: 0x01A9,
  26082. Esmall: 0xF765,
  26083. Eta: 0x0397,
  26084. Etarmenian: 0x0538,
  26085. Etatonos: 0x0389,
  26086. Eth: 0x00D0,
  26087. Ethsmall: 0xF7F0,
  26088. Etilde: 0x1EBC,
  26089. Etildebelow: 0x1E1A,
  26090. Euro: 0x20AC,
  26091. Ezh: 0x01B7,
  26092. Ezhcaron: 0x01EE,
  26093. Ezhreversed: 0x01B8,
  26094. F: 0x0046,
  26095. Fcircle: 0x24BB,
  26096. Fdotaccent: 0x1E1E,
  26097. Feharmenian: 0x0556,
  26098. Feicoptic: 0x03E4,
  26099. Fhook: 0x0191,
  26100. Fitacyrillic: 0x0472,
  26101. Fiveroman: 0x2164,
  26102. Fmonospace: 0xFF26,
  26103. Fourroman: 0x2163,
  26104. Fsmall: 0xF766,
  26105. G: 0x0047,
  26106. GBsquare: 0x3387,
  26107. Gacute: 0x01F4,
  26108. Gamma: 0x0393,
  26109. Gammaafrican: 0x0194,
  26110. Gangiacoptic: 0x03EA,
  26111. Gbreve: 0x011E,
  26112. Gcaron: 0x01E6,
  26113. Gcedilla: 0x0122,
  26114. Gcircle: 0x24BC,
  26115. Gcircumflex: 0x011C,
  26116. Gcommaaccent: 0x0122,
  26117. Gdot: 0x0120,
  26118. Gdotaccent: 0x0120,
  26119. Gecyrillic: 0x0413,
  26120. Ghadarmenian: 0x0542,
  26121. Ghemiddlehookcyrillic: 0x0494,
  26122. Ghestrokecyrillic: 0x0492,
  26123. Gheupturncyrillic: 0x0490,
  26124. Ghook: 0x0193,
  26125. Gimarmenian: 0x0533,
  26126. Gjecyrillic: 0x0403,
  26127. Gmacron: 0x1E20,
  26128. Gmonospace: 0xFF27,
  26129. Grave: 0xF6CE,
  26130. Gravesmall: 0xF760,
  26131. Gsmall: 0xF767,
  26132. Gsmallhook: 0x029B,
  26133. Gstroke: 0x01E4,
  26134. H: 0x0048,
  26135. H18533: 0x25CF,
  26136. H18543: 0x25AA,
  26137. H18551: 0x25AB,
  26138. H22073: 0x25A1,
  26139. HPsquare: 0x33CB,
  26140. Haabkhasiancyrillic: 0x04A8,
  26141. Hadescendercyrillic: 0x04B2,
  26142. Hardsigncyrillic: 0x042A,
  26143. Hbar: 0x0126,
  26144. Hbrevebelow: 0x1E2A,
  26145. Hcedilla: 0x1E28,
  26146. Hcircle: 0x24BD,
  26147. Hcircumflex: 0x0124,
  26148. Hdieresis: 0x1E26,
  26149. Hdotaccent: 0x1E22,
  26150. Hdotbelow: 0x1E24,
  26151. Hmonospace: 0xFF28,
  26152. Hoarmenian: 0x0540,
  26153. Horicoptic: 0x03E8,
  26154. Hsmall: 0xF768,
  26155. Hungarumlaut: 0xF6CF,
  26156. Hungarumlautsmall: 0xF6F8,
  26157. Hzsquare: 0x3390,
  26158. I: 0x0049,
  26159. IAcyrillic: 0x042F,
  26160. IJ: 0x0132,
  26161. IUcyrillic: 0x042E,
  26162. Iacute: 0x00CD,
  26163. Iacutesmall: 0xF7ED,
  26164. Ibreve: 0x012C,
  26165. Icaron: 0x01CF,
  26166. Icircle: 0x24BE,
  26167. Icircumflex: 0x00CE,
  26168. Icircumflexsmall: 0xF7EE,
  26169. Icyrillic: 0x0406,
  26170. Idblgrave: 0x0208,
  26171. Idieresis: 0x00CF,
  26172. Idieresisacute: 0x1E2E,
  26173. Idieresiscyrillic: 0x04E4,
  26174. Idieresissmall: 0xF7EF,
  26175. Idot: 0x0130,
  26176. Idotaccent: 0x0130,
  26177. Idotbelow: 0x1ECA,
  26178. Iebrevecyrillic: 0x04D6,
  26179. Iecyrillic: 0x0415,
  26180. Ifraktur: 0x2111,
  26181. Igrave: 0x00CC,
  26182. Igravesmall: 0xF7EC,
  26183. Ihookabove: 0x1EC8,
  26184. Iicyrillic: 0x0418,
  26185. Iinvertedbreve: 0x020A,
  26186. Iishortcyrillic: 0x0419,
  26187. Imacron: 0x012A,
  26188. Imacroncyrillic: 0x04E2,
  26189. Imonospace: 0xFF29,
  26190. Iniarmenian: 0x053B,
  26191. Iocyrillic: 0x0401,
  26192. Iogonek: 0x012E,
  26193. Iota: 0x0399,
  26194. Iotaafrican: 0x0196,
  26195. Iotadieresis: 0x03AA,
  26196. Iotatonos: 0x038A,
  26197. Ismall: 0xF769,
  26198. Istroke: 0x0197,
  26199. Itilde: 0x0128,
  26200. Itildebelow: 0x1E2C,
  26201. Izhitsacyrillic: 0x0474,
  26202. Izhitsadblgravecyrillic: 0x0476,
  26203. J: 0x004A,
  26204. Jaarmenian: 0x0541,
  26205. Jcircle: 0x24BF,
  26206. Jcircumflex: 0x0134,
  26207. Jecyrillic: 0x0408,
  26208. Jheharmenian: 0x054B,
  26209. Jmonospace: 0xFF2A,
  26210. Jsmall: 0xF76A,
  26211. K: 0x004B,
  26212. KBsquare: 0x3385,
  26213. KKsquare: 0x33CD,
  26214. Kabashkircyrillic: 0x04A0,
  26215. Kacute: 0x1E30,
  26216. Kacyrillic: 0x041A,
  26217. Kadescendercyrillic: 0x049A,
  26218. Kahookcyrillic: 0x04C3,
  26219. Kappa: 0x039A,
  26220. Kastrokecyrillic: 0x049E,
  26221. Kaverticalstrokecyrillic: 0x049C,
  26222. Kcaron: 0x01E8,
  26223. Kcedilla: 0x0136,
  26224. Kcircle: 0x24C0,
  26225. Kcommaaccent: 0x0136,
  26226. Kdotbelow: 0x1E32,
  26227. Keharmenian: 0x0554,
  26228. Kenarmenian: 0x053F,
  26229. Khacyrillic: 0x0425,
  26230. Kheicoptic: 0x03E6,
  26231. Khook: 0x0198,
  26232. Kjecyrillic: 0x040C,
  26233. Klinebelow: 0x1E34,
  26234. Kmonospace: 0xFF2B,
  26235. Koppacyrillic: 0x0480,
  26236. Koppagreek: 0x03DE,
  26237. Ksicyrillic: 0x046E,
  26238. Ksmall: 0xF76B,
  26239. L: 0x004C,
  26240. LJ: 0x01C7,
  26241. LL: 0xF6BF,
  26242. Lacute: 0x0139,
  26243. Lambda: 0x039B,
  26244. Lcaron: 0x013D,
  26245. Lcedilla: 0x013B,
  26246. Lcircle: 0x24C1,
  26247. Lcircumflexbelow: 0x1E3C,
  26248. Lcommaaccent: 0x013B,
  26249. Ldot: 0x013F,
  26250. Ldotaccent: 0x013F,
  26251. Ldotbelow: 0x1E36,
  26252. Ldotbelowmacron: 0x1E38,
  26253. Liwnarmenian: 0x053C,
  26254. Lj: 0x01C8,
  26255. Ljecyrillic: 0x0409,
  26256. Llinebelow: 0x1E3A,
  26257. Lmonospace: 0xFF2C,
  26258. Lslash: 0x0141,
  26259. Lslashsmall: 0xF6F9,
  26260. Lsmall: 0xF76C,
  26261. M: 0x004D,
  26262. MBsquare: 0x3386,
  26263. Macron: 0xF6D0,
  26264. Macronsmall: 0xF7AF,
  26265. Macute: 0x1E3E,
  26266. Mcircle: 0x24C2,
  26267. Mdotaccent: 0x1E40,
  26268. Mdotbelow: 0x1E42,
  26269. Menarmenian: 0x0544,
  26270. Mmonospace: 0xFF2D,
  26271. Msmall: 0xF76D,
  26272. Mturned: 0x019C,
  26273. Mu: 0x039C,
  26274. N: 0x004E,
  26275. NJ: 0x01CA,
  26276. Nacute: 0x0143,
  26277. Ncaron: 0x0147,
  26278. Ncedilla: 0x0145,
  26279. Ncircle: 0x24C3,
  26280. Ncircumflexbelow: 0x1E4A,
  26281. Ncommaaccent: 0x0145,
  26282. Ndotaccent: 0x1E44,
  26283. Ndotbelow: 0x1E46,
  26284. Nhookleft: 0x019D,
  26285. Nineroman: 0x2168,
  26286. Nj: 0x01CB,
  26287. Njecyrillic: 0x040A,
  26288. Nlinebelow: 0x1E48,
  26289. Nmonospace: 0xFF2E,
  26290. Nowarmenian: 0x0546,
  26291. Nsmall: 0xF76E,
  26292. Ntilde: 0x00D1,
  26293. Ntildesmall: 0xF7F1,
  26294. Nu: 0x039D,
  26295. O: 0x004F,
  26296. OE: 0x0152,
  26297. OEsmall: 0xF6FA,
  26298. Oacute: 0x00D3,
  26299. Oacutesmall: 0xF7F3,
  26300. Obarredcyrillic: 0x04E8,
  26301. Obarreddieresiscyrillic: 0x04EA,
  26302. Obreve: 0x014E,
  26303. Ocaron: 0x01D1,
  26304. Ocenteredtilde: 0x019F,
  26305. Ocircle: 0x24C4,
  26306. Ocircumflex: 0x00D4,
  26307. Ocircumflexacute: 0x1ED0,
  26308. Ocircumflexdotbelow: 0x1ED8,
  26309. Ocircumflexgrave: 0x1ED2,
  26310. Ocircumflexhookabove: 0x1ED4,
  26311. Ocircumflexsmall: 0xF7F4,
  26312. Ocircumflextilde: 0x1ED6,
  26313. Ocyrillic: 0x041E,
  26314. Odblacute: 0x0150,
  26315. Odblgrave: 0x020C,
  26316. Odieresis: 0x00D6,
  26317. Odieresiscyrillic: 0x04E6,
  26318. Odieresissmall: 0xF7F6,
  26319. Odotbelow: 0x1ECC,
  26320. Ogoneksmall: 0xF6FB,
  26321. Ograve: 0x00D2,
  26322. Ogravesmall: 0xF7F2,
  26323. Oharmenian: 0x0555,
  26324. Ohm: 0x2126,
  26325. Ohookabove: 0x1ECE,
  26326. Ohorn: 0x01A0,
  26327. Ohornacute: 0x1EDA,
  26328. Ohorndotbelow: 0x1EE2,
  26329. Ohorngrave: 0x1EDC,
  26330. Ohornhookabove: 0x1EDE,
  26331. Ohorntilde: 0x1EE0,
  26332. Ohungarumlaut: 0x0150,
  26333. Oi: 0x01A2,
  26334. Oinvertedbreve: 0x020E,
  26335. Omacron: 0x014C,
  26336. Omacronacute: 0x1E52,
  26337. Omacrongrave: 0x1E50,
  26338. Omega: 0x2126,
  26339. Omegacyrillic: 0x0460,
  26340. Omegagreek: 0x03A9,
  26341. Omegaroundcyrillic: 0x047A,
  26342. Omegatitlocyrillic: 0x047C,
  26343. Omegatonos: 0x038F,
  26344. Omicron: 0x039F,
  26345. Omicrontonos: 0x038C,
  26346. Omonospace: 0xFF2F,
  26347. Oneroman: 0x2160,
  26348. Oogonek: 0x01EA,
  26349. Oogonekmacron: 0x01EC,
  26350. Oopen: 0x0186,
  26351. Oslash: 0x00D8,
  26352. Oslashacute: 0x01FE,
  26353. Oslashsmall: 0xF7F8,
  26354. Osmall: 0xF76F,
  26355. Ostrokeacute: 0x01FE,
  26356. Otcyrillic: 0x047E,
  26357. Otilde: 0x00D5,
  26358. Otildeacute: 0x1E4C,
  26359. Otildedieresis: 0x1E4E,
  26360. Otildesmall: 0xF7F5,
  26361. P: 0x0050,
  26362. Pacute: 0x1E54,
  26363. Pcircle: 0x24C5,
  26364. Pdotaccent: 0x1E56,
  26365. Pecyrillic: 0x041F,
  26366. Peharmenian: 0x054A,
  26367. Pemiddlehookcyrillic: 0x04A6,
  26368. Phi: 0x03A6,
  26369. Phook: 0x01A4,
  26370. Pi: 0x03A0,
  26371. Piwrarmenian: 0x0553,
  26372. Pmonospace: 0xFF30,
  26373. Psi: 0x03A8,
  26374. Psicyrillic: 0x0470,
  26375. Psmall: 0xF770,
  26376. Q: 0x0051,
  26377. Qcircle: 0x24C6,
  26378. Qmonospace: 0xFF31,
  26379. Qsmall: 0xF771,
  26380. R: 0x0052,
  26381. Raarmenian: 0x054C,
  26382. Racute: 0x0154,
  26383. Rcaron: 0x0158,
  26384. Rcedilla: 0x0156,
  26385. Rcircle: 0x24C7,
  26386. Rcommaaccent: 0x0156,
  26387. Rdblgrave: 0x0210,
  26388. Rdotaccent: 0x1E58,
  26389. Rdotbelow: 0x1E5A,
  26390. Rdotbelowmacron: 0x1E5C,
  26391. Reharmenian: 0x0550,
  26392. Rfraktur: 0x211C,
  26393. Rho: 0x03A1,
  26394. Ringsmall: 0xF6FC,
  26395. Rinvertedbreve: 0x0212,
  26396. Rlinebelow: 0x1E5E,
  26397. Rmonospace: 0xFF32,
  26398. Rsmall: 0xF772,
  26399. Rsmallinverted: 0x0281,
  26400. Rsmallinvertedsuperior: 0x02B6,
  26401. S: 0x0053,
  26402. SF010000: 0x250C,
  26403. SF020000: 0x2514,
  26404. SF030000: 0x2510,
  26405. SF040000: 0x2518,
  26406. SF050000: 0x253C,
  26407. SF060000: 0x252C,
  26408. SF070000: 0x2534,
  26409. SF080000: 0x251C,
  26410. SF090000: 0x2524,
  26411. SF100000: 0x2500,
  26412. SF110000: 0x2502,
  26413. SF190000: 0x2561,
  26414. SF200000: 0x2562,
  26415. SF210000: 0x2556,
  26416. SF220000: 0x2555,
  26417. SF230000: 0x2563,
  26418. SF240000: 0x2551,
  26419. SF250000: 0x2557,
  26420. SF260000: 0x255D,
  26421. SF270000: 0x255C,
  26422. SF280000: 0x255B,
  26423. SF360000: 0x255E,
  26424. SF370000: 0x255F,
  26425. SF380000: 0x255A,
  26426. SF390000: 0x2554,
  26427. SF400000: 0x2569,
  26428. SF410000: 0x2566,
  26429. SF420000: 0x2560,
  26430. SF430000: 0x2550,
  26431. SF440000: 0x256C,
  26432. SF450000: 0x2567,
  26433. SF460000: 0x2568,
  26434. SF470000: 0x2564,
  26435. SF480000: 0x2565,
  26436. SF490000: 0x2559,
  26437. SF500000: 0x2558,
  26438. SF510000: 0x2552,
  26439. SF520000: 0x2553,
  26440. SF530000: 0x256B,
  26441. SF540000: 0x256A,
  26442. Sacute: 0x015A,
  26443. Sacutedotaccent: 0x1E64,
  26444. Sampigreek: 0x03E0,
  26445. Scaron: 0x0160,
  26446. Scarondotaccent: 0x1E66,
  26447. Scaronsmall: 0xF6FD,
  26448. Scedilla: 0x015E,
  26449. Schwa: 0x018F,
  26450. Schwacyrillic: 0x04D8,
  26451. Schwadieresiscyrillic: 0x04DA,
  26452. Scircle: 0x24C8,
  26453. Scircumflex: 0x015C,
  26454. Scommaaccent: 0x0218,
  26455. Sdotaccent: 0x1E60,
  26456. Sdotbelow: 0x1E62,
  26457. Sdotbelowdotaccent: 0x1E68,
  26458. Seharmenian: 0x054D,
  26459. Sevenroman: 0x2166,
  26460. Shaarmenian: 0x0547,
  26461. Shacyrillic: 0x0428,
  26462. Shchacyrillic: 0x0429,
  26463. Sheicoptic: 0x03E2,
  26464. Shhacyrillic: 0x04BA,
  26465. Shimacoptic: 0x03EC,
  26466. Sigma: 0x03A3,
  26467. Sixroman: 0x2165,
  26468. Smonospace: 0xFF33,
  26469. Softsigncyrillic: 0x042C,
  26470. Ssmall: 0xF773,
  26471. Stigmagreek: 0x03DA,
  26472. T: 0x0054,
  26473. Tau: 0x03A4,
  26474. Tbar: 0x0166,
  26475. Tcaron: 0x0164,
  26476. Tcedilla: 0x0162,
  26477. Tcircle: 0x24C9,
  26478. Tcircumflexbelow: 0x1E70,
  26479. Tcommaaccent: 0x0162,
  26480. Tdotaccent: 0x1E6A,
  26481. Tdotbelow: 0x1E6C,
  26482. Tecyrillic: 0x0422,
  26483. Tedescendercyrillic: 0x04AC,
  26484. Tenroman: 0x2169,
  26485. Tetsecyrillic: 0x04B4,
  26486. Theta: 0x0398,
  26487. Thook: 0x01AC,
  26488. Thorn: 0x00DE,
  26489. Thornsmall: 0xF7FE,
  26490. Threeroman: 0x2162,
  26491. Tildesmall: 0xF6FE,
  26492. Tiwnarmenian: 0x054F,
  26493. Tlinebelow: 0x1E6E,
  26494. Tmonospace: 0xFF34,
  26495. Toarmenian: 0x0539,
  26496. Tonefive: 0x01BC,
  26497. Tonesix: 0x0184,
  26498. Tonetwo: 0x01A7,
  26499. Tretroflexhook: 0x01AE,
  26500. Tsecyrillic: 0x0426,
  26501. Tshecyrillic: 0x040B,
  26502. Tsmall: 0xF774,
  26503. Twelveroman: 0x216B,
  26504. Tworoman: 0x2161,
  26505. U: 0x0055,
  26506. Uacute: 0x00DA,
  26507. Uacutesmall: 0xF7FA,
  26508. Ubreve: 0x016C,
  26509. Ucaron: 0x01D3,
  26510. Ucircle: 0x24CA,
  26511. Ucircumflex: 0x00DB,
  26512. Ucircumflexbelow: 0x1E76,
  26513. Ucircumflexsmall: 0xF7FB,
  26514. Ucyrillic: 0x0423,
  26515. Udblacute: 0x0170,
  26516. Udblgrave: 0x0214,
  26517. Udieresis: 0x00DC,
  26518. Udieresisacute: 0x01D7,
  26519. Udieresisbelow: 0x1E72,
  26520. Udieresiscaron: 0x01D9,
  26521. Udieresiscyrillic: 0x04F0,
  26522. Udieresisgrave: 0x01DB,
  26523. Udieresismacron: 0x01D5,
  26524. Udieresissmall: 0xF7FC,
  26525. Udotbelow: 0x1EE4,
  26526. Ugrave: 0x00D9,
  26527. Ugravesmall: 0xF7F9,
  26528. Uhookabove: 0x1EE6,
  26529. Uhorn: 0x01AF,
  26530. Uhornacute: 0x1EE8,
  26531. Uhorndotbelow: 0x1EF0,
  26532. Uhorngrave: 0x1EEA,
  26533. Uhornhookabove: 0x1EEC,
  26534. Uhorntilde: 0x1EEE,
  26535. Uhungarumlaut: 0x0170,
  26536. Uhungarumlautcyrillic: 0x04F2,
  26537. Uinvertedbreve: 0x0216,
  26538. Ukcyrillic: 0x0478,
  26539. Umacron: 0x016A,
  26540. Umacroncyrillic: 0x04EE,
  26541. Umacrondieresis: 0x1E7A,
  26542. Umonospace: 0xFF35,
  26543. Uogonek: 0x0172,
  26544. Upsilon: 0x03A5,
  26545. Upsilon1: 0x03D2,
  26546. Upsilonacutehooksymbolgreek: 0x03D3,
  26547. Upsilonafrican: 0x01B1,
  26548. Upsilondieresis: 0x03AB,
  26549. Upsilondieresishooksymbolgreek: 0x03D4,
  26550. Upsilonhooksymbol: 0x03D2,
  26551. Upsilontonos: 0x038E,
  26552. Uring: 0x016E,
  26553. Ushortcyrillic: 0x040E,
  26554. Usmall: 0xF775,
  26555. Ustraightcyrillic: 0x04AE,
  26556. Ustraightstrokecyrillic: 0x04B0,
  26557. Utilde: 0x0168,
  26558. Utildeacute: 0x1E78,
  26559. Utildebelow: 0x1E74,
  26560. V: 0x0056,
  26561. Vcircle: 0x24CB,
  26562. Vdotbelow: 0x1E7E,
  26563. Vecyrillic: 0x0412,
  26564. Vewarmenian: 0x054E,
  26565. Vhook: 0x01B2,
  26566. Vmonospace: 0xFF36,
  26567. Voarmenian: 0x0548,
  26568. Vsmall: 0xF776,
  26569. Vtilde: 0x1E7C,
  26570. W: 0x0057,
  26571. Wacute: 0x1E82,
  26572. Wcircle: 0x24CC,
  26573. Wcircumflex: 0x0174,
  26574. Wdieresis: 0x1E84,
  26575. Wdotaccent: 0x1E86,
  26576. Wdotbelow: 0x1E88,
  26577. Wgrave: 0x1E80,
  26578. Wmonospace: 0xFF37,
  26579. Wsmall: 0xF777,
  26580. X: 0x0058,
  26581. Xcircle: 0x24CD,
  26582. Xdieresis: 0x1E8C,
  26583. Xdotaccent: 0x1E8A,
  26584. Xeharmenian: 0x053D,
  26585. Xi: 0x039E,
  26586. Xmonospace: 0xFF38,
  26587. Xsmall: 0xF778,
  26588. Y: 0x0059,
  26589. Yacute: 0x00DD,
  26590. Yacutesmall: 0xF7FD,
  26591. Yatcyrillic: 0x0462,
  26592. Ycircle: 0x24CE,
  26593. Ycircumflex: 0x0176,
  26594. Ydieresis: 0x0178,
  26595. Ydieresissmall: 0xF7FF,
  26596. Ydotaccent: 0x1E8E,
  26597. Ydotbelow: 0x1EF4,
  26598. Yericyrillic: 0x042B,
  26599. Yerudieresiscyrillic: 0x04F8,
  26600. Ygrave: 0x1EF2,
  26601. Yhook: 0x01B3,
  26602. Yhookabove: 0x1EF6,
  26603. Yiarmenian: 0x0545,
  26604. Yicyrillic: 0x0407,
  26605. Yiwnarmenian: 0x0552,
  26606. Ymonospace: 0xFF39,
  26607. Ysmall: 0xF779,
  26608. Ytilde: 0x1EF8,
  26609. Yusbigcyrillic: 0x046A,
  26610. Yusbigiotifiedcyrillic: 0x046C,
  26611. Yuslittlecyrillic: 0x0466,
  26612. Yuslittleiotifiedcyrillic: 0x0468,
  26613. Z: 0x005A,
  26614. Zaarmenian: 0x0536,
  26615. Zacute: 0x0179,
  26616. Zcaron: 0x017D,
  26617. Zcaronsmall: 0xF6FF,
  26618. Zcircle: 0x24CF,
  26619. Zcircumflex: 0x1E90,
  26620. Zdot: 0x017B,
  26621. Zdotaccent: 0x017B,
  26622. Zdotbelow: 0x1E92,
  26623. Zecyrillic: 0x0417,
  26624. Zedescendercyrillic: 0x0498,
  26625. Zedieresiscyrillic: 0x04DE,
  26626. Zeta: 0x0396,
  26627. Zhearmenian: 0x053A,
  26628. Zhebrevecyrillic: 0x04C1,
  26629. Zhecyrillic: 0x0416,
  26630. Zhedescendercyrillic: 0x0496,
  26631. Zhedieresiscyrillic: 0x04DC,
  26632. Zlinebelow: 0x1E94,
  26633. Zmonospace: 0xFF3A,
  26634. Zsmall: 0xF77A,
  26635. Zstroke: 0x01B5,
  26636. a: 0x0061,
  26637. aabengali: 0x0986,
  26638. aacute: 0x00E1,
  26639. aadeva: 0x0906,
  26640. aagujarati: 0x0A86,
  26641. aagurmukhi: 0x0A06,
  26642. aamatragurmukhi: 0x0A3E,
  26643. aarusquare: 0x3303,
  26644. aavowelsignbengali: 0x09BE,
  26645. aavowelsigndeva: 0x093E,
  26646. aavowelsigngujarati: 0x0ABE,
  26647. abbreviationmarkarmenian: 0x055F,
  26648. abbreviationsigndeva: 0x0970,
  26649. abengali: 0x0985,
  26650. abopomofo: 0x311A,
  26651. abreve: 0x0103,
  26652. abreveacute: 0x1EAF,
  26653. abrevecyrillic: 0x04D1,
  26654. abrevedotbelow: 0x1EB7,
  26655. abrevegrave: 0x1EB1,
  26656. abrevehookabove: 0x1EB3,
  26657. abrevetilde: 0x1EB5,
  26658. acaron: 0x01CE,
  26659. acircle: 0x24D0,
  26660. acircumflex: 0x00E2,
  26661. acircumflexacute: 0x1EA5,
  26662. acircumflexdotbelow: 0x1EAD,
  26663. acircumflexgrave: 0x1EA7,
  26664. acircumflexhookabove: 0x1EA9,
  26665. acircumflextilde: 0x1EAB,
  26666. acute: 0x00B4,
  26667. acutebelowcmb: 0x0317,
  26668. acutecmb: 0x0301,
  26669. acutecomb: 0x0301,
  26670. acutedeva: 0x0954,
  26671. acutelowmod: 0x02CF,
  26672. acutetonecmb: 0x0341,
  26673. acyrillic: 0x0430,
  26674. adblgrave: 0x0201,
  26675. addakgurmukhi: 0x0A71,
  26676. adeva: 0x0905,
  26677. adieresis: 0x00E4,
  26678. adieresiscyrillic: 0x04D3,
  26679. adieresismacron: 0x01DF,
  26680. adotbelow: 0x1EA1,
  26681. adotmacron: 0x01E1,
  26682. ae: 0x00E6,
  26683. aeacute: 0x01FD,
  26684. aekorean: 0x3150,
  26685. aemacron: 0x01E3,
  26686. afii00208: 0x2015,
  26687. afii08941: 0x20A4,
  26688. afii10017: 0x0410,
  26689. afii10018: 0x0411,
  26690. afii10019: 0x0412,
  26691. afii10020: 0x0413,
  26692. afii10021: 0x0414,
  26693. afii10022: 0x0415,
  26694. afii10023: 0x0401,
  26695. afii10024: 0x0416,
  26696. afii10025: 0x0417,
  26697. afii10026: 0x0418,
  26698. afii10027: 0x0419,
  26699. afii10028: 0x041A,
  26700. afii10029: 0x041B,
  26701. afii10030: 0x041C,
  26702. afii10031: 0x041D,
  26703. afii10032: 0x041E,
  26704. afii10033: 0x041F,
  26705. afii10034: 0x0420,
  26706. afii10035: 0x0421,
  26707. afii10036: 0x0422,
  26708. afii10037: 0x0423,
  26709. afii10038: 0x0424,
  26710. afii10039: 0x0425,
  26711. afii10040: 0x0426,
  26712. afii10041: 0x0427,
  26713. afii10042: 0x0428,
  26714. afii10043: 0x0429,
  26715. afii10044: 0x042A,
  26716. afii10045: 0x042B,
  26717. afii10046: 0x042C,
  26718. afii10047: 0x042D,
  26719. afii10048: 0x042E,
  26720. afii10049: 0x042F,
  26721. afii10050: 0x0490,
  26722. afii10051: 0x0402,
  26723. afii10052: 0x0403,
  26724. afii10053: 0x0404,
  26725. afii10054: 0x0405,
  26726. afii10055: 0x0406,
  26727. afii10056: 0x0407,
  26728. afii10057: 0x0408,
  26729. afii10058: 0x0409,
  26730. afii10059: 0x040A,
  26731. afii10060: 0x040B,
  26732. afii10061: 0x040C,
  26733. afii10062: 0x040E,
  26734. afii10063: 0xF6C4,
  26735. afii10064: 0xF6C5,
  26736. afii10065: 0x0430,
  26737. afii10066: 0x0431,
  26738. afii10067: 0x0432,
  26739. afii10068: 0x0433,
  26740. afii10069: 0x0434,
  26741. afii10070: 0x0435,
  26742. afii10071: 0x0451,
  26743. afii10072: 0x0436,
  26744. afii10073: 0x0437,
  26745. afii10074: 0x0438,
  26746. afii10075: 0x0439,
  26747. afii10076: 0x043A,
  26748. afii10077: 0x043B,
  26749. afii10078: 0x043C,
  26750. afii10079: 0x043D,
  26751. afii10080: 0x043E,
  26752. afii10081: 0x043F,
  26753. afii10082: 0x0440,
  26754. afii10083: 0x0441,
  26755. afii10084: 0x0442,
  26756. afii10085: 0x0443,
  26757. afii10086: 0x0444,
  26758. afii10087: 0x0445,
  26759. afii10088: 0x0446,
  26760. afii10089: 0x0447,
  26761. afii10090: 0x0448,
  26762. afii10091: 0x0449,
  26763. afii10092: 0x044A,
  26764. afii10093: 0x044B,
  26765. afii10094: 0x044C,
  26766. afii10095: 0x044D,
  26767. afii10096: 0x044E,
  26768. afii10097: 0x044F,
  26769. afii10098: 0x0491,
  26770. afii10099: 0x0452,
  26771. afii10100: 0x0453,
  26772. afii10101: 0x0454,
  26773. afii10102: 0x0455,
  26774. afii10103: 0x0456,
  26775. afii10104: 0x0457,
  26776. afii10105: 0x0458,
  26777. afii10106: 0x0459,
  26778. afii10107: 0x045A,
  26779. afii10108: 0x045B,
  26780. afii10109: 0x045C,
  26781. afii10110: 0x045E,
  26782. afii10145: 0x040F,
  26783. afii10146: 0x0462,
  26784. afii10147: 0x0472,
  26785. afii10148: 0x0474,
  26786. afii10192: 0xF6C6,
  26787. afii10193: 0x045F,
  26788. afii10194: 0x0463,
  26789. afii10195: 0x0473,
  26790. afii10196: 0x0475,
  26791. afii10831: 0xF6C7,
  26792. afii10832: 0xF6C8,
  26793. afii10846: 0x04D9,
  26794. afii299: 0x200E,
  26795. afii300: 0x200F,
  26796. afii301: 0x200D,
  26797. afii57381: 0x066A,
  26798. afii57388: 0x060C,
  26799. afii57392: 0x0660,
  26800. afii57393: 0x0661,
  26801. afii57394: 0x0662,
  26802. afii57395: 0x0663,
  26803. afii57396: 0x0664,
  26804. afii57397: 0x0665,
  26805. afii57398: 0x0666,
  26806. afii57399: 0x0667,
  26807. afii57400: 0x0668,
  26808. afii57401: 0x0669,
  26809. afii57403: 0x061B,
  26810. afii57407: 0x061F,
  26811. afii57409: 0x0621,
  26812. afii57410: 0x0622,
  26813. afii57411: 0x0623,
  26814. afii57412: 0x0624,
  26815. afii57413: 0x0625,
  26816. afii57414: 0x0626,
  26817. afii57415: 0x0627,
  26818. afii57416: 0x0628,
  26819. afii57417: 0x0629,
  26820. afii57418: 0x062A,
  26821. afii57419: 0x062B,
  26822. afii57420: 0x062C,
  26823. afii57421: 0x062D,
  26824. afii57422: 0x062E,
  26825. afii57423: 0x062F,
  26826. afii57424: 0x0630,
  26827. afii57425: 0x0631,
  26828. afii57426: 0x0632,
  26829. afii57427: 0x0633,
  26830. afii57428: 0x0634,
  26831. afii57429: 0x0635,
  26832. afii57430: 0x0636,
  26833. afii57431: 0x0637,
  26834. afii57432: 0x0638,
  26835. afii57433: 0x0639,
  26836. afii57434: 0x063A,
  26837. afii57440: 0x0640,
  26838. afii57441: 0x0641,
  26839. afii57442: 0x0642,
  26840. afii57443: 0x0643,
  26841. afii57444: 0x0644,
  26842. afii57445: 0x0645,
  26843. afii57446: 0x0646,
  26844. afii57448: 0x0648,
  26845. afii57449: 0x0649,
  26846. afii57450: 0x064A,
  26847. afii57451: 0x064B,
  26848. afii57452: 0x064C,
  26849. afii57453: 0x064D,
  26850. afii57454: 0x064E,
  26851. afii57455: 0x064F,
  26852. afii57456: 0x0650,
  26853. afii57457: 0x0651,
  26854. afii57458: 0x0652,
  26855. afii57470: 0x0647,
  26856. afii57505: 0x06A4,
  26857. afii57506: 0x067E,
  26858. afii57507: 0x0686,
  26859. afii57508: 0x0698,
  26860. afii57509: 0x06AF,
  26861. afii57511: 0x0679,
  26862. afii57512: 0x0688,
  26863. afii57513: 0x0691,
  26864. afii57514: 0x06BA,
  26865. afii57519: 0x06D2,
  26866. afii57534: 0x06D5,
  26867. afii57636: 0x20AA,
  26868. afii57645: 0x05BE,
  26869. afii57658: 0x05C3,
  26870. afii57664: 0x05D0,
  26871. afii57665: 0x05D1,
  26872. afii57666: 0x05D2,
  26873. afii57667: 0x05D3,
  26874. afii57668: 0x05D4,
  26875. afii57669: 0x05D5,
  26876. afii57670: 0x05D6,
  26877. afii57671: 0x05D7,
  26878. afii57672: 0x05D8,
  26879. afii57673: 0x05D9,
  26880. afii57674: 0x05DA,
  26881. afii57675: 0x05DB,
  26882. afii57676: 0x05DC,
  26883. afii57677: 0x05DD,
  26884. afii57678: 0x05DE,
  26885. afii57679: 0x05DF,
  26886. afii57680: 0x05E0,
  26887. afii57681: 0x05E1,
  26888. afii57682: 0x05E2,
  26889. afii57683: 0x05E3,
  26890. afii57684: 0x05E4,
  26891. afii57685: 0x05E5,
  26892. afii57686: 0x05E6,
  26893. afii57687: 0x05E7,
  26894. afii57688: 0x05E8,
  26895. afii57689: 0x05E9,
  26896. afii57690: 0x05EA,
  26897. afii57694: 0xFB2A,
  26898. afii57695: 0xFB2B,
  26899. afii57700: 0xFB4B,
  26900. afii57705: 0xFB1F,
  26901. afii57716: 0x05F0,
  26902. afii57717: 0x05F1,
  26903. afii57718: 0x05F2,
  26904. afii57723: 0xFB35,
  26905. afii57793: 0x05B4,
  26906. afii57794: 0x05B5,
  26907. afii57795: 0x05B6,
  26908. afii57796: 0x05BB,
  26909. afii57797: 0x05B8,
  26910. afii57798: 0x05B7,
  26911. afii57799: 0x05B0,
  26912. afii57800: 0x05B2,
  26913. afii57801: 0x05B1,
  26914. afii57802: 0x05B3,
  26915. afii57803: 0x05C2,
  26916. afii57804: 0x05C1,
  26917. afii57806: 0x05B9,
  26918. afii57807: 0x05BC,
  26919. afii57839: 0x05BD,
  26920. afii57841: 0x05BF,
  26921. afii57842: 0x05C0,
  26922. afii57929: 0x02BC,
  26923. afii61248: 0x2105,
  26924. afii61289: 0x2113,
  26925. afii61352: 0x2116,
  26926. afii61573: 0x202C,
  26927. afii61574: 0x202D,
  26928. afii61575: 0x202E,
  26929. afii61664: 0x200C,
  26930. afii63167: 0x066D,
  26931. afii64937: 0x02BD,
  26932. agrave: 0x00E0,
  26933. agujarati: 0x0A85,
  26934. agurmukhi: 0x0A05,
  26935. ahiragana: 0x3042,
  26936. ahookabove: 0x1EA3,
  26937. aibengali: 0x0990,
  26938. aibopomofo: 0x311E,
  26939. aideva: 0x0910,
  26940. aiecyrillic: 0x04D5,
  26941. aigujarati: 0x0A90,
  26942. aigurmukhi: 0x0A10,
  26943. aimatragurmukhi: 0x0A48,
  26944. ainarabic: 0x0639,
  26945. ainfinalarabic: 0xFECA,
  26946. aininitialarabic: 0xFECB,
  26947. ainmedialarabic: 0xFECC,
  26948. ainvertedbreve: 0x0203,
  26949. aivowelsignbengali: 0x09C8,
  26950. aivowelsigndeva: 0x0948,
  26951. aivowelsigngujarati: 0x0AC8,
  26952. akatakana: 0x30A2,
  26953. akatakanahalfwidth: 0xFF71,
  26954. akorean: 0x314F,
  26955. alef: 0x05D0,
  26956. alefarabic: 0x0627,
  26957. alefdageshhebrew: 0xFB30,
  26958. aleffinalarabic: 0xFE8E,
  26959. alefhamzaabovearabic: 0x0623,
  26960. alefhamzaabovefinalarabic: 0xFE84,
  26961. alefhamzabelowarabic: 0x0625,
  26962. alefhamzabelowfinalarabic: 0xFE88,
  26963. alefhebrew: 0x05D0,
  26964. aleflamedhebrew: 0xFB4F,
  26965. alefmaddaabovearabic: 0x0622,
  26966. alefmaddaabovefinalarabic: 0xFE82,
  26967. alefmaksuraarabic: 0x0649,
  26968. alefmaksurafinalarabic: 0xFEF0,
  26969. alefmaksurainitialarabic: 0xFEF3,
  26970. alefmaksuramedialarabic: 0xFEF4,
  26971. alefpatahhebrew: 0xFB2E,
  26972. alefqamatshebrew: 0xFB2F,
  26973. aleph: 0x2135,
  26974. allequal: 0x224C,
  26975. alpha: 0x03B1,
  26976. alphatonos: 0x03AC,
  26977. amacron: 0x0101,
  26978. amonospace: 0xFF41,
  26979. ampersand: 0x0026,
  26980. ampersandmonospace: 0xFF06,
  26981. ampersandsmall: 0xF726,
  26982. amsquare: 0x33C2,
  26983. anbopomofo: 0x3122,
  26984. angbopomofo: 0x3124,
  26985. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  26986. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  26987. angkhankhuthai: 0x0E5A,
  26988. angle: 0x2220,
  26989. anglebracketleft: 0x3008,
  26990. anglebracketleftvertical: 0xFE3F,
  26991. anglebracketright: 0x3009,
  26992. anglebracketrightvertical: 0xFE40,
  26993. angleleft: 0x2329,
  26994. angleright: 0x232A,
  26995. angstrom: 0x212B,
  26996. anoteleia: 0x0387,
  26997. anudattadeva: 0x0952,
  26998. anusvarabengali: 0x0982,
  26999. anusvaradeva: 0x0902,
  27000. anusvaragujarati: 0x0A82,
  27001. aogonek: 0x0105,
  27002. apaatosquare: 0x3300,
  27003. aparen: 0x249C,
  27004. apostrophearmenian: 0x055A,
  27005. apostrophemod: 0x02BC,
  27006. apple: 0xF8FF,
  27007. approaches: 0x2250,
  27008. approxequal: 0x2248,
  27009. approxequalorimage: 0x2252,
  27010. approximatelyequal: 0x2245,
  27011. araeaekorean: 0x318E,
  27012. araeakorean: 0x318D,
  27013. arc: 0x2312,
  27014. arighthalfring: 0x1E9A,
  27015. aring: 0x00E5,
  27016. aringacute: 0x01FB,
  27017. aringbelow: 0x1E01,
  27018. arrowboth: 0x2194,
  27019. arrowdashdown: 0x21E3,
  27020. arrowdashleft: 0x21E0,
  27021. arrowdashright: 0x21E2,
  27022. arrowdashup: 0x21E1,
  27023. arrowdblboth: 0x21D4,
  27024. arrowdbldown: 0x21D3,
  27025. arrowdblleft: 0x21D0,
  27026. arrowdblright: 0x21D2,
  27027. arrowdblup: 0x21D1,
  27028. arrowdown: 0x2193,
  27029. arrowdownleft: 0x2199,
  27030. arrowdownright: 0x2198,
  27031. arrowdownwhite: 0x21E9,
  27032. arrowheaddownmod: 0x02C5,
  27033. arrowheadleftmod: 0x02C2,
  27034. arrowheadrightmod: 0x02C3,
  27035. arrowheadupmod: 0x02C4,
  27036. arrowhorizex: 0xF8E7,
  27037. arrowleft: 0x2190,
  27038. arrowleftdbl: 0x21D0,
  27039. arrowleftdblstroke: 0x21CD,
  27040. arrowleftoverright: 0x21C6,
  27041. arrowleftwhite: 0x21E6,
  27042. arrowright: 0x2192,
  27043. arrowrightdblstroke: 0x21CF,
  27044. arrowrightheavy: 0x279E,
  27045. arrowrightoverleft: 0x21C4,
  27046. arrowrightwhite: 0x21E8,
  27047. arrowtableft: 0x21E4,
  27048. arrowtabright: 0x21E5,
  27049. arrowup: 0x2191,
  27050. arrowupdn: 0x2195,
  27051. arrowupdnbse: 0x21A8,
  27052. arrowupdownbase: 0x21A8,
  27053. arrowupleft: 0x2196,
  27054. arrowupleftofdown: 0x21C5,
  27055. arrowupright: 0x2197,
  27056. arrowupwhite: 0x21E7,
  27057. arrowvertex: 0xF8E6,
  27058. asciicircum: 0x005E,
  27059. asciicircummonospace: 0xFF3E,
  27060. asciitilde: 0x007E,
  27061. asciitildemonospace: 0xFF5E,
  27062. ascript: 0x0251,
  27063. ascriptturned: 0x0252,
  27064. asmallhiragana: 0x3041,
  27065. asmallkatakana: 0x30A1,
  27066. asmallkatakanahalfwidth: 0xFF67,
  27067. asterisk: 0x002A,
  27068. asteriskaltonearabic: 0x066D,
  27069. asteriskarabic: 0x066D,
  27070. asteriskmath: 0x2217,
  27071. asteriskmonospace: 0xFF0A,
  27072. asterisksmall: 0xFE61,
  27073. asterism: 0x2042,
  27074. asuperior: 0xF6E9,
  27075. asymptoticallyequal: 0x2243,
  27076. at: 0x0040,
  27077. atilde: 0x00E3,
  27078. atmonospace: 0xFF20,
  27079. atsmall: 0xFE6B,
  27080. aturned: 0x0250,
  27081. aubengali: 0x0994,
  27082. aubopomofo: 0x3120,
  27083. audeva: 0x0914,
  27084. augujarati: 0x0A94,
  27085. augurmukhi: 0x0A14,
  27086. aulengthmarkbengali: 0x09D7,
  27087. aumatragurmukhi: 0x0A4C,
  27088. auvowelsignbengali: 0x09CC,
  27089. auvowelsigndeva: 0x094C,
  27090. auvowelsigngujarati: 0x0ACC,
  27091. avagrahadeva: 0x093D,
  27092. aybarmenian: 0x0561,
  27093. ayin: 0x05E2,
  27094. ayinaltonehebrew: 0xFB20,
  27095. ayinhebrew: 0x05E2,
  27096. b: 0x0062,
  27097. babengali: 0x09AC,
  27098. backslash: 0x005C,
  27099. backslashmonospace: 0xFF3C,
  27100. badeva: 0x092C,
  27101. bagujarati: 0x0AAC,
  27102. bagurmukhi: 0x0A2C,
  27103. bahiragana: 0x3070,
  27104. bahtthai: 0x0E3F,
  27105. bakatakana: 0x30D0,
  27106. bar: 0x007C,
  27107. barmonospace: 0xFF5C,
  27108. bbopomofo: 0x3105,
  27109. bcircle: 0x24D1,
  27110. bdotaccent: 0x1E03,
  27111. bdotbelow: 0x1E05,
  27112. beamedsixteenthnotes: 0x266C,
  27113. because: 0x2235,
  27114. becyrillic: 0x0431,
  27115. beharabic: 0x0628,
  27116. behfinalarabic: 0xFE90,
  27117. behinitialarabic: 0xFE91,
  27118. behiragana: 0x3079,
  27119. behmedialarabic: 0xFE92,
  27120. behmeeminitialarabic: 0xFC9F,
  27121. behmeemisolatedarabic: 0xFC08,
  27122. behnoonfinalarabic: 0xFC6D,
  27123. bekatakana: 0x30D9,
  27124. benarmenian: 0x0562,
  27125. bet: 0x05D1,
  27126. beta: 0x03B2,
  27127. betasymbolgreek: 0x03D0,
  27128. betdagesh: 0xFB31,
  27129. betdageshhebrew: 0xFB31,
  27130. bethebrew: 0x05D1,
  27131. betrafehebrew: 0xFB4C,
  27132. bhabengali: 0x09AD,
  27133. bhadeva: 0x092D,
  27134. bhagujarati: 0x0AAD,
  27135. bhagurmukhi: 0x0A2D,
  27136. bhook: 0x0253,
  27137. bihiragana: 0x3073,
  27138. bikatakana: 0x30D3,
  27139. bilabialclick: 0x0298,
  27140. bindigurmukhi: 0x0A02,
  27141. birusquare: 0x3331,
  27142. blackcircle: 0x25CF,
  27143. blackdiamond: 0x25C6,
  27144. blackdownpointingtriangle: 0x25BC,
  27145. blackleftpointingpointer: 0x25C4,
  27146. blackleftpointingtriangle: 0x25C0,
  27147. blacklenticularbracketleft: 0x3010,
  27148. blacklenticularbracketleftvertical: 0xFE3B,
  27149. blacklenticularbracketright: 0x3011,
  27150. blacklenticularbracketrightvertical: 0xFE3C,
  27151. blacklowerlefttriangle: 0x25E3,
  27152. blacklowerrighttriangle: 0x25E2,
  27153. blackrectangle: 0x25AC,
  27154. blackrightpointingpointer: 0x25BA,
  27155. blackrightpointingtriangle: 0x25B6,
  27156. blacksmallsquare: 0x25AA,
  27157. blacksmilingface: 0x263B,
  27158. blacksquare: 0x25A0,
  27159. blackstar: 0x2605,
  27160. blackupperlefttriangle: 0x25E4,
  27161. blackupperrighttriangle: 0x25E5,
  27162. blackuppointingsmalltriangle: 0x25B4,
  27163. blackuppointingtriangle: 0x25B2,
  27164. blank: 0x2423,
  27165. blinebelow: 0x1E07,
  27166. block: 0x2588,
  27167. bmonospace: 0xFF42,
  27168. bobaimaithai: 0x0E1A,
  27169. bohiragana: 0x307C,
  27170. bokatakana: 0x30DC,
  27171. bparen: 0x249D,
  27172. bqsquare: 0x33C3,
  27173. braceex: 0xF8F4,
  27174. braceleft: 0x007B,
  27175. braceleftbt: 0xF8F3,
  27176. braceleftmid: 0xF8F2,
  27177. braceleftmonospace: 0xFF5B,
  27178. braceleftsmall: 0xFE5B,
  27179. bracelefttp: 0xF8F1,
  27180. braceleftvertical: 0xFE37,
  27181. braceright: 0x007D,
  27182. bracerightbt: 0xF8FE,
  27183. bracerightmid: 0xF8FD,
  27184. bracerightmonospace: 0xFF5D,
  27185. bracerightsmall: 0xFE5C,
  27186. bracerighttp: 0xF8FC,
  27187. bracerightvertical: 0xFE38,
  27188. bracketleft: 0x005B,
  27189. bracketleftbt: 0xF8F0,
  27190. bracketleftex: 0xF8EF,
  27191. bracketleftmonospace: 0xFF3B,
  27192. bracketlefttp: 0xF8EE,
  27193. bracketright: 0x005D,
  27194. bracketrightbt: 0xF8FB,
  27195. bracketrightex: 0xF8FA,
  27196. bracketrightmonospace: 0xFF3D,
  27197. bracketrighttp: 0xF8F9,
  27198. breve: 0x02D8,
  27199. brevebelowcmb: 0x032E,
  27200. brevecmb: 0x0306,
  27201. breveinvertedbelowcmb: 0x032F,
  27202. breveinvertedcmb: 0x0311,
  27203. breveinverteddoublecmb: 0x0361,
  27204. bridgebelowcmb: 0x032A,
  27205. bridgeinvertedbelowcmb: 0x033A,
  27206. brokenbar: 0x00A6,
  27207. bstroke: 0x0180,
  27208. bsuperior: 0xF6EA,
  27209. btopbar: 0x0183,
  27210. buhiragana: 0x3076,
  27211. bukatakana: 0x30D6,
  27212. bullet: 0x2022,
  27213. bulletinverse: 0x25D8,
  27214. bulletoperator: 0x2219,
  27215. bullseye: 0x25CE,
  27216. c: 0x0063,
  27217. caarmenian: 0x056E,
  27218. cabengali: 0x099A,
  27219. cacute: 0x0107,
  27220. cadeva: 0x091A,
  27221. cagujarati: 0x0A9A,
  27222. cagurmukhi: 0x0A1A,
  27223. calsquare: 0x3388,
  27224. candrabindubengali: 0x0981,
  27225. candrabinducmb: 0x0310,
  27226. candrabindudeva: 0x0901,
  27227. candrabindugujarati: 0x0A81,
  27228. capslock: 0x21EA,
  27229. careof: 0x2105,
  27230. caron: 0x02C7,
  27231. caronbelowcmb: 0x032C,
  27232. caroncmb: 0x030C,
  27233. carriagereturn: 0x21B5,
  27234. cbopomofo: 0x3118,
  27235. ccaron: 0x010D,
  27236. ccedilla: 0x00E7,
  27237. ccedillaacute: 0x1E09,
  27238. ccircle: 0x24D2,
  27239. ccircumflex: 0x0109,
  27240. ccurl: 0x0255,
  27241. cdot: 0x010B,
  27242. cdotaccent: 0x010B,
  27243. cdsquare: 0x33C5,
  27244. cedilla: 0x00B8,
  27245. cedillacmb: 0x0327,
  27246. cent: 0x00A2,
  27247. centigrade: 0x2103,
  27248. centinferior: 0xF6DF,
  27249. centmonospace: 0xFFE0,
  27250. centoldstyle: 0xF7A2,
  27251. centsuperior: 0xF6E0,
  27252. chaarmenian: 0x0579,
  27253. chabengali: 0x099B,
  27254. chadeva: 0x091B,
  27255. chagujarati: 0x0A9B,
  27256. chagurmukhi: 0x0A1B,
  27257. chbopomofo: 0x3114,
  27258. cheabkhasiancyrillic: 0x04BD,
  27259. checkmark: 0x2713,
  27260. checyrillic: 0x0447,
  27261. chedescenderabkhasiancyrillic: 0x04BF,
  27262. chedescendercyrillic: 0x04B7,
  27263. chedieresiscyrillic: 0x04F5,
  27264. cheharmenian: 0x0573,
  27265. chekhakassiancyrillic: 0x04CC,
  27266. cheverticalstrokecyrillic: 0x04B9,
  27267. chi: 0x03C7,
  27268. chieuchacirclekorean: 0x3277,
  27269. chieuchaparenkorean: 0x3217,
  27270. chieuchcirclekorean: 0x3269,
  27271. chieuchkorean: 0x314A,
  27272. chieuchparenkorean: 0x3209,
  27273. chochangthai: 0x0E0A,
  27274. chochanthai: 0x0E08,
  27275. chochingthai: 0x0E09,
  27276. chochoethai: 0x0E0C,
  27277. chook: 0x0188,
  27278. cieucacirclekorean: 0x3276,
  27279. cieucaparenkorean: 0x3216,
  27280. cieuccirclekorean: 0x3268,
  27281. cieuckorean: 0x3148,
  27282. cieucparenkorean: 0x3208,
  27283. cieucuparenkorean: 0x321C,
  27284. circle: 0x25CB,
  27285. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  27286. circlemultiply: 0x2297,
  27287. circleot: 0x2299,
  27288. circleplus: 0x2295,
  27289. circlepostalmark: 0x3036,
  27290. circlewithlefthalfblack: 0x25D0,
  27291. circlewithrighthalfblack: 0x25D1,
  27292. circumflex: 0x02C6,
  27293. circumflexbelowcmb: 0x032D,
  27294. circumflexcmb: 0x0302,
  27295. clear: 0x2327,
  27296. clickalveolar: 0x01C2,
  27297. clickdental: 0x01C0,
  27298. clicklateral: 0x01C1,
  27299. clickretroflex: 0x01C3,
  27300. club: 0x2663,
  27301. clubsuitblack: 0x2663,
  27302. clubsuitwhite: 0x2667,
  27303. cmcubedsquare: 0x33A4,
  27304. cmonospace: 0xFF43,
  27305. cmsquaredsquare: 0x33A0,
  27306. coarmenian: 0x0581,
  27307. colon: 0x003A,
  27308. colonmonetary: 0x20A1,
  27309. colonmonospace: 0xFF1A,
  27310. colonsign: 0x20A1,
  27311. colonsmall: 0xFE55,
  27312. colontriangularhalfmod: 0x02D1,
  27313. colontriangularmod: 0x02D0,
  27314. comma: 0x002C,
  27315. commaabovecmb: 0x0313,
  27316. commaaboverightcmb: 0x0315,
  27317. commaaccent: 0xF6C3,
  27318. commaarabic: 0x060C,
  27319. commaarmenian: 0x055D,
  27320. commainferior: 0xF6E1,
  27321. commamonospace: 0xFF0C,
  27322. commareversedabovecmb: 0x0314,
  27323. commareversedmod: 0x02BD,
  27324. commasmall: 0xFE50,
  27325. commasuperior: 0xF6E2,
  27326. commaturnedabovecmb: 0x0312,
  27327. commaturnedmod: 0x02BB,
  27328. compass: 0x263C,
  27329. congruent: 0x2245,
  27330. contourintegral: 0x222E,
  27331. control: 0x2303,
  27332. controlACK: 0x0006,
  27333. controlBEL: 0x0007,
  27334. controlBS: 0x0008,
  27335. controlCAN: 0x0018,
  27336. controlCR: 0x000D,
  27337. controlDC1: 0x0011,
  27338. controlDC2: 0x0012,
  27339. controlDC3: 0x0013,
  27340. controlDC4: 0x0014,
  27341. controlDEL: 0x007F,
  27342. controlDLE: 0x0010,
  27343. controlEM: 0x0019,
  27344. controlENQ: 0x0005,
  27345. controlEOT: 0x0004,
  27346. controlESC: 0x001B,
  27347. controlETB: 0x0017,
  27348. controlETX: 0x0003,
  27349. controlFF: 0x000C,
  27350. controlFS: 0x001C,
  27351. controlGS: 0x001D,
  27352. controlHT: 0x0009,
  27353. controlLF: 0x000A,
  27354. controlNAK: 0x0015,
  27355. controlRS: 0x001E,
  27356. controlSI: 0x000F,
  27357. controlSO: 0x000E,
  27358. controlSOT: 0x0002,
  27359. controlSTX: 0x0001,
  27360. controlSUB: 0x001A,
  27361. controlSYN: 0x0016,
  27362. controlUS: 0x001F,
  27363. controlVT: 0x000B,
  27364. copyright: 0x00A9,
  27365. copyrightsans: 0xF8E9,
  27366. copyrightserif: 0xF6D9,
  27367. cornerbracketleft: 0x300C,
  27368. cornerbracketlefthalfwidth: 0xFF62,
  27369. cornerbracketleftvertical: 0xFE41,
  27370. cornerbracketright: 0x300D,
  27371. cornerbracketrighthalfwidth: 0xFF63,
  27372. cornerbracketrightvertical: 0xFE42,
  27373. corporationsquare: 0x337F,
  27374. cosquare: 0x33C7,
  27375. coverkgsquare: 0x33C6,
  27376. cparen: 0x249E,
  27377. cruzeiro: 0x20A2,
  27378. cstretched: 0x0297,
  27379. curlyand: 0x22CF,
  27380. curlyor: 0x22CE,
  27381. currency: 0x00A4,
  27382. cyrBreve: 0xF6D1,
  27383. cyrFlex: 0xF6D2,
  27384. cyrbreve: 0xF6D4,
  27385. cyrflex: 0xF6D5,
  27386. d: 0x0064,
  27387. daarmenian: 0x0564,
  27388. dabengali: 0x09A6,
  27389. dadarabic: 0x0636,
  27390. dadeva: 0x0926,
  27391. dadfinalarabic: 0xFEBE,
  27392. dadinitialarabic: 0xFEBF,
  27393. dadmedialarabic: 0xFEC0,
  27394. dagesh: 0x05BC,
  27395. dageshhebrew: 0x05BC,
  27396. dagger: 0x2020,
  27397. daggerdbl: 0x2021,
  27398. dagujarati: 0x0AA6,
  27399. dagurmukhi: 0x0A26,
  27400. dahiragana: 0x3060,
  27401. dakatakana: 0x30C0,
  27402. dalarabic: 0x062F,
  27403. dalet: 0x05D3,
  27404. daletdagesh: 0xFB33,
  27405. daletdageshhebrew: 0xFB33,
  27406. dalethebrew: 0x05D3,
  27407. dalfinalarabic: 0xFEAA,
  27408. dammaarabic: 0x064F,
  27409. dammalowarabic: 0x064F,
  27410. dammatanaltonearabic: 0x064C,
  27411. dammatanarabic: 0x064C,
  27412. danda: 0x0964,
  27413. dargahebrew: 0x05A7,
  27414. dargalefthebrew: 0x05A7,
  27415. dasiapneumatacyrilliccmb: 0x0485,
  27416. dblGrave: 0xF6D3,
  27417. dblanglebracketleft: 0x300A,
  27418. dblanglebracketleftvertical: 0xFE3D,
  27419. dblanglebracketright: 0x300B,
  27420. dblanglebracketrightvertical: 0xFE3E,
  27421. dblarchinvertedbelowcmb: 0x032B,
  27422. dblarrowleft: 0x21D4,
  27423. dblarrowright: 0x21D2,
  27424. dbldanda: 0x0965,
  27425. dblgrave: 0xF6D6,
  27426. dblgravecmb: 0x030F,
  27427. dblintegral: 0x222C,
  27428. dbllowline: 0x2017,
  27429. dbllowlinecmb: 0x0333,
  27430. dbloverlinecmb: 0x033F,
  27431. dblprimemod: 0x02BA,
  27432. dblverticalbar: 0x2016,
  27433. dblverticallineabovecmb: 0x030E,
  27434. dbopomofo: 0x3109,
  27435. dbsquare: 0x33C8,
  27436. dcaron: 0x010F,
  27437. dcedilla: 0x1E11,
  27438. dcircle: 0x24D3,
  27439. dcircumflexbelow: 0x1E13,
  27440. dcroat: 0x0111,
  27441. ddabengali: 0x09A1,
  27442. ddadeva: 0x0921,
  27443. ddagujarati: 0x0AA1,
  27444. ddagurmukhi: 0x0A21,
  27445. ddalarabic: 0x0688,
  27446. ddalfinalarabic: 0xFB89,
  27447. dddhadeva: 0x095C,
  27448. ddhabengali: 0x09A2,
  27449. ddhadeva: 0x0922,
  27450. ddhagujarati: 0x0AA2,
  27451. ddhagurmukhi: 0x0A22,
  27452. ddotaccent: 0x1E0B,
  27453. ddotbelow: 0x1E0D,
  27454. decimalseparatorarabic: 0x066B,
  27455. decimalseparatorpersian: 0x066B,
  27456. decyrillic: 0x0434,
  27457. degree: 0x00B0,
  27458. dehihebrew: 0x05AD,
  27459. dehiragana: 0x3067,
  27460. deicoptic: 0x03EF,
  27461. dekatakana: 0x30C7,
  27462. deleteleft: 0x232B,
  27463. deleteright: 0x2326,
  27464. delta: 0x03B4,
  27465. deltaturned: 0x018D,
  27466. denominatorminusonenumeratorbengali: 0x09F8,
  27467. dezh: 0x02A4,
  27468. dhabengali: 0x09A7,
  27469. dhadeva: 0x0927,
  27470. dhagujarati: 0x0AA7,
  27471. dhagurmukhi: 0x0A27,
  27472. dhook: 0x0257,
  27473. dialytikatonos: 0x0385,
  27474. dialytikatonoscmb: 0x0344,
  27475. diamond: 0x2666,
  27476. diamondsuitwhite: 0x2662,
  27477. dieresis: 0x00A8,
  27478. dieresisacute: 0xF6D7,
  27479. dieresisbelowcmb: 0x0324,
  27480. dieresiscmb: 0x0308,
  27481. dieresisgrave: 0xF6D8,
  27482. dieresistonos: 0x0385,
  27483. dihiragana: 0x3062,
  27484. dikatakana: 0x30C2,
  27485. dittomark: 0x3003,
  27486. divide: 0x00F7,
  27487. divides: 0x2223,
  27488. divisionslash: 0x2215,
  27489. djecyrillic: 0x0452,
  27490. dkshade: 0x2593,
  27491. dlinebelow: 0x1E0F,
  27492. dlsquare: 0x3397,
  27493. dmacron: 0x0111,
  27494. dmonospace: 0xFF44,
  27495. dnblock: 0x2584,
  27496. dochadathai: 0x0E0E,
  27497. dodekthai: 0x0E14,
  27498. dohiragana: 0x3069,
  27499. dokatakana: 0x30C9,
  27500. dollar: 0x0024,
  27501. dollarinferior: 0xF6E3,
  27502. dollarmonospace: 0xFF04,
  27503. dollaroldstyle: 0xF724,
  27504. dollarsmall: 0xFE69,
  27505. dollarsuperior: 0xF6E4,
  27506. dong: 0x20AB,
  27507. dorusquare: 0x3326,
  27508. dotaccent: 0x02D9,
  27509. dotaccentcmb: 0x0307,
  27510. dotbelowcmb: 0x0323,
  27511. dotbelowcomb: 0x0323,
  27512. dotkatakana: 0x30FB,
  27513. dotlessi: 0x0131,
  27514. dotlessj: 0xF6BE,
  27515. dotlessjstrokehook: 0x0284,
  27516. dotmath: 0x22C5,
  27517. dottedcircle: 0x25CC,
  27518. doubleyodpatah: 0xFB1F,
  27519. doubleyodpatahhebrew: 0xFB1F,
  27520. downtackbelowcmb: 0x031E,
  27521. downtackmod: 0x02D5,
  27522. dparen: 0x249F,
  27523. dsuperior: 0xF6EB,
  27524. dtail: 0x0256,
  27525. dtopbar: 0x018C,
  27526. duhiragana: 0x3065,
  27527. dukatakana: 0x30C5,
  27528. dz: 0x01F3,
  27529. dzaltone: 0x02A3,
  27530. dzcaron: 0x01C6,
  27531. dzcurl: 0x02A5,
  27532. dzeabkhasiancyrillic: 0x04E1,
  27533. dzecyrillic: 0x0455,
  27534. dzhecyrillic: 0x045F,
  27535. e: 0x0065,
  27536. eacute: 0x00E9,
  27537. earth: 0x2641,
  27538. ebengali: 0x098F,
  27539. ebopomofo: 0x311C,
  27540. ebreve: 0x0115,
  27541. ecandradeva: 0x090D,
  27542. ecandragujarati: 0x0A8D,
  27543. ecandravowelsigndeva: 0x0945,
  27544. ecandravowelsigngujarati: 0x0AC5,
  27545. ecaron: 0x011B,
  27546. ecedillabreve: 0x1E1D,
  27547. echarmenian: 0x0565,
  27548. echyiwnarmenian: 0x0587,
  27549. ecircle: 0x24D4,
  27550. ecircumflex: 0x00EA,
  27551. ecircumflexacute: 0x1EBF,
  27552. ecircumflexbelow: 0x1E19,
  27553. ecircumflexdotbelow: 0x1EC7,
  27554. ecircumflexgrave: 0x1EC1,
  27555. ecircumflexhookabove: 0x1EC3,
  27556. ecircumflextilde: 0x1EC5,
  27557. ecyrillic: 0x0454,
  27558. edblgrave: 0x0205,
  27559. edeva: 0x090F,
  27560. edieresis: 0x00EB,
  27561. edot: 0x0117,
  27562. edotaccent: 0x0117,
  27563. edotbelow: 0x1EB9,
  27564. eegurmukhi: 0x0A0F,
  27565. eematragurmukhi: 0x0A47,
  27566. efcyrillic: 0x0444,
  27567. egrave: 0x00E8,
  27568. egujarati: 0x0A8F,
  27569. eharmenian: 0x0567,
  27570. ehbopomofo: 0x311D,
  27571. ehiragana: 0x3048,
  27572. ehookabove: 0x1EBB,
  27573. eibopomofo: 0x311F,
  27574. eight: 0x0038,
  27575. eightarabic: 0x0668,
  27576. eightbengali: 0x09EE,
  27577. eightcircle: 0x2467,
  27578. eightcircleinversesansserif: 0x2791,
  27579. eightdeva: 0x096E,
  27580. eighteencircle: 0x2471,
  27581. eighteenparen: 0x2485,
  27582. eighteenperiod: 0x2499,
  27583. eightgujarati: 0x0AEE,
  27584. eightgurmukhi: 0x0A6E,
  27585. eighthackarabic: 0x0668,
  27586. eighthangzhou: 0x3028,
  27587. eighthnotebeamed: 0x266B,
  27588. eightideographicparen: 0x3227,
  27589. eightinferior: 0x2088,
  27590. eightmonospace: 0xFF18,
  27591. eightoldstyle: 0xF738,
  27592. eightparen: 0x247B,
  27593. eightperiod: 0x248F,
  27594. eightpersian: 0x06F8,
  27595. eightroman: 0x2177,
  27596. eightsuperior: 0x2078,
  27597. eightthai: 0x0E58,
  27598. einvertedbreve: 0x0207,
  27599. eiotifiedcyrillic: 0x0465,
  27600. ekatakana: 0x30A8,
  27601. ekatakanahalfwidth: 0xFF74,
  27602. ekonkargurmukhi: 0x0A74,
  27603. ekorean: 0x3154,
  27604. elcyrillic: 0x043B,
  27605. element: 0x2208,
  27606. elevencircle: 0x246A,
  27607. elevenparen: 0x247E,
  27608. elevenperiod: 0x2492,
  27609. elevenroman: 0x217A,
  27610. ellipsis: 0x2026,
  27611. ellipsisvertical: 0x22EE,
  27612. emacron: 0x0113,
  27613. emacronacute: 0x1E17,
  27614. emacrongrave: 0x1E15,
  27615. emcyrillic: 0x043C,
  27616. emdash: 0x2014,
  27617. emdashvertical: 0xFE31,
  27618. emonospace: 0xFF45,
  27619. emphasismarkarmenian: 0x055B,
  27620. emptyset: 0x2205,
  27621. enbopomofo: 0x3123,
  27622. encyrillic: 0x043D,
  27623. endash: 0x2013,
  27624. endashvertical: 0xFE32,
  27625. endescendercyrillic: 0x04A3,
  27626. eng: 0x014B,
  27627. engbopomofo: 0x3125,
  27628. enghecyrillic: 0x04A5,
  27629. enhookcyrillic: 0x04C8,
  27630. enspace: 0x2002,
  27631. eogonek: 0x0119,
  27632. eokorean: 0x3153,
  27633. eopen: 0x025B,
  27634. eopenclosed: 0x029A,
  27635. eopenreversed: 0x025C,
  27636. eopenreversedclosed: 0x025E,
  27637. eopenreversedhook: 0x025D,
  27638. eparen: 0x24A0,
  27639. epsilon: 0x03B5,
  27640. epsilontonos: 0x03AD,
  27641. equal: 0x003D,
  27642. equalmonospace: 0xFF1D,
  27643. equalsmall: 0xFE66,
  27644. equalsuperior: 0x207C,
  27645. equivalence: 0x2261,
  27646. erbopomofo: 0x3126,
  27647. ercyrillic: 0x0440,
  27648. ereversed: 0x0258,
  27649. ereversedcyrillic: 0x044D,
  27650. escyrillic: 0x0441,
  27651. esdescendercyrillic: 0x04AB,
  27652. esh: 0x0283,
  27653. eshcurl: 0x0286,
  27654. eshortdeva: 0x090E,
  27655. eshortvowelsigndeva: 0x0946,
  27656. eshreversedloop: 0x01AA,
  27657. eshsquatreversed: 0x0285,
  27658. esmallhiragana: 0x3047,
  27659. esmallkatakana: 0x30A7,
  27660. esmallkatakanahalfwidth: 0xFF6A,
  27661. estimated: 0x212E,
  27662. esuperior: 0xF6EC,
  27663. eta: 0x03B7,
  27664. etarmenian: 0x0568,
  27665. etatonos: 0x03AE,
  27666. eth: 0x00F0,
  27667. etilde: 0x1EBD,
  27668. etildebelow: 0x1E1B,
  27669. etnahtafoukhhebrew: 0x0591,
  27670. etnahtafoukhlefthebrew: 0x0591,
  27671. etnahtahebrew: 0x0591,
  27672. etnahtalefthebrew: 0x0591,
  27673. eturned: 0x01DD,
  27674. eukorean: 0x3161,
  27675. euro: 0x20AC,
  27676. evowelsignbengali: 0x09C7,
  27677. evowelsigndeva: 0x0947,
  27678. evowelsigngujarati: 0x0AC7,
  27679. exclam: 0x0021,
  27680. exclamarmenian: 0x055C,
  27681. exclamdbl: 0x203C,
  27682. exclamdown: 0x00A1,
  27683. exclamdownsmall: 0xF7A1,
  27684. exclammonospace: 0xFF01,
  27685. exclamsmall: 0xF721,
  27686. existential: 0x2203,
  27687. ezh: 0x0292,
  27688. ezhcaron: 0x01EF,
  27689. ezhcurl: 0x0293,
  27690. ezhreversed: 0x01B9,
  27691. ezhtail: 0x01BA,
  27692. f: 0x0066,
  27693. fadeva: 0x095E,
  27694. fagurmukhi: 0x0A5E,
  27695. fahrenheit: 0x2109,
  27696. fathaarabic: 0x064E,
  27697. fathalowarabic: 0x064E,
  27698. fathatanarabic: 0x064B,
  27699. fbopomofo: 0x3108,
  27700. fcircle: 0x24D5,
  27701. fdotaccent: 0x1E1F,
  27702. feharabic: 0x0641,
  27703. feharmenian: 0x0586,
  27704. fehfinalarabic: 0xFED2,
  27705. fehinitialarabic: 0xFED3,
  27706. fehmedialarabic: 0xFED4,
  27707. feicoptic: 0x03E5,
  27708. female: 0x2640,
  27709. ff: 0xFB00,
  27710. ffi: 0xFB03,
  27711. ffl: 0xFB04,
  27712. fi: 0xFB01,
  27713. fifteencircle: 0x246E,
  27714. fifteenparen: 0x2482,
  27715. fifteenperiod: 0x2496,
  27716. figuredash: 0x2012,
  27717. filledbox: 0x25A0,
  27718. filledrect: 0x25AC,
  27719. finalkaf: 0x05DA,
  27720. finalkafdagesh: 0xFB3A,
  27721. finalkafdageshhebrew: 0xFB3A,
  27722. finalkafhebrew: 0x05DA,
  27723. finalmem: 0x05DD,
  27724. finalmemhebrew: 0x05DD,
  27725. finalnun: 0x05DF,
  27726. finalnunhebrew: 0x05DF,
  27727. finalpe: 0x05E3,
  27728. finalpehebrew: 0x05E3,
  27729. finaltsadi: 0x05E5,
  27730. finaltsadihebrew: 0x05E5,
  27731. firsttonechinese: 0x02C9,
  27732. fisheye: 0x25C9,
  27733. fitacyrillic: 0x0473,
  27734. five: 0x0035,
  27735. fivearabic: 0x0665,
  27736. fivebengali: 0x09EB,
  27737. fivecircle: 0x2464,
  27738. fivecircleinversesansserif: 0x278E,
  27739. fivedeva: 0x096B,
  27740. fiveeighths: 0x215D,
  27741. fivegujarati: 0x0AEB,
  27742. fivegurmukhi: 0x0A6B,
  27743. fivehackarabic: 0x0665,
  27744. fivehangzhou: 0x3025,
  27745. fiveideographicparen: 0x3224,
  27746. fiveinferior: 0x2085,
  27747. fivemonospace: 0xFF15,
  27748. fiveoldstyle: 0xF735,
  27749. fiveparen: 0x2478,
  27750. fiveperiod: 0x248C,
  27751. fivepersian: 0x06F5,
  27752. fiveroman: 0x2174,
  27753. fivesuperior: 0x2075,
  27754. fivethai: 0x0E55,
  27755. fl: 0xFB02,
  27756. florin: 0x0192,
  27757. fmonospace: 0xFF46,
  27758. fmsquare: 0x3399,
  27759. fofanthai: 0x0E1F,
  27760. fofathai: 0x0E1D,
  27761. fongmanthai: 0x0E4F,
  27762. forall: 0x2200,
  27763. four: 0x0034,
  27764. fourarabic: 0x0664,
  27765. fourbengali: 0x09EA,
  27766. fourcircle: 0x2463,
  27767. fourcircleinversesansserif: 0x278D,
  27768. fourdeva: 0x096A,
  27769. fourgujarati: 0x0AEA,
  27770. fourgurmukhi: 0x0A6A,
  27771. fourhackarabic: 0x0664,
  27772. fourhangzhou: 0x3024,
  27773. fourideographicparen: 0x3223,
  27774. fourinferior: 0x2084,
  27775. fourmonospace: 0xFF14,
  27776. fournumeratorbengali: 0x09F7,
  27777. fouroldstyle: 0xF734,
  27778. fourparen: 0x2477,
  27779. fourperiod: 0x248B,
  27780. fourpersian: 0x06F4,
  27781. fourroman: 0x2173,
  27782. foursuperior: 0x2074,
  27783. fourteencircle: 0x246D,
  27784. fourteenparen: 0x2481,
  27785. fourteenperiod: 0x2495,
  27786. fourthai: 0x0E54,
  27787. fourthtonechinese: 0x02CB,
  27788. fparen: 0x24A1,
  27789. fraction: 0x2044,
  27790. franc: 0x20A3,
  27791. g: 0x0067,
  27792. gabengali: 0x0997,
  27793. gacute: 0x01F5,
  27794. gadeva: 0x0917,
  27795. gafarabic: 0x06AF,
  27796. gaffinalarabic: 0xFB93,
  27797. gafinitialarabic: 0xFB94,
  27798. gafmedialarabic: 0xFB95,
  27799. gagujarati: 0x0A97,
  27800. gagurmukhi: 0x0A17,
  27801. gahiragana: 0x304C,
  27802. gakatakana: 0x30AC,
  27803. gamma: 0x03B3,
  27804. gammalatinsmall: 0x0263,
  27805. gammasuperior: 0x02E0,
  27806. gangiacoptic: 0x03EB,
  27807. gbopomofo: 0x310D,
  27808. gbreve: 0x011F,
  27809. gcaron: 0x01E7,
  27810. gcedilla: 0x0123,
  27811. gcircle: 0x24D6,
  27812. gcircumflex: 0x011D,
  27813. gcommaaccent: 0x0123,
  27814. gdot: 0x0121,
  27815. gdotaccent: 0x0121,
  27816. gecyrillic: 0x0433,
  27817. gehiragana: 0x3052,
  27818. gekatakana: 0x30B2,
  27819. geometricallyequal: 0x2251,
  27820. gereshaccenthebrew: 0x059C,
  27821. gereshhebrew: 0x05F3,
  27822. gereshmuqdamhebrew: 0x059D,
  27823. germandbls: 0x00DF,
  27824. gershayimaccenthebrew: 0x059E,
  27825. gershayimhebrew: 0x05F4,
  27826. getamark: 0x3013,
  27827. ghabengali: 0x0998,
  27828. ghadarmenian: 0x0572,
  27829. ghadeva: 0x0918,
  27830. ghagujarati: 0x0A98,
  27831. ghagurmukhi: 0x0A18,
  27832. ghainarabic: 0x063A,
  27833. ghainfinalarabic: 0xFECE,
  27834. ghaininitialarabic: 0xFECF,
  27835. ghainmedialarabic: 0xFED0,
  27836. ghemiddlehookcyrillic: 0x0495,
  27837. ghestrokecyrillic: 0x0493,
  27838. gheupturncyrillic: 0x0491,
  27839. ghhadeva: 0x095A,
  27840. ghhagurmukhi: 0x0A5A,
  27841. ghook: 0x0260,
  27842. ghzsquare: 0x3393,
  27843. gihiragana: 0x304E,
  27844. gikatakana: 0x30AE,
  27845. gimarmenian: 0x0563,
  27846. gimel: 0x05D2,
  27847. gimeldagesh: 0xFB32,
  27848. gimeldageshhebrew: 0xFB32,
  27849. gimelhebrew: 0x05D2,
  27850. gjecyrillic: 0x0453,
  27851. glottalinvertedstroke: 0x01BE,
  27852. glottalstop: 0x0294,
  27853. glottalstopinverted: 0x0296,
  27854. glottalstopmod: 0x02C0,
  27855. glottalstopreversed: 0x0295,
  27856. glottalstopreversedmod: 0x02C1,
  27857. glottalstopreversedsuperior: 0x02E4,
  27858. glottalstopstroke: 0x02A1,
  27859. glottalstopstrokereversed: 0x02A2,
  27860. gmacron: 0x1E21,
  27861. gmonospace: 0xFF47,
  27862. gohiragana: 0x3054,
  27863. gokatakana: 0x30B4,
  27864. gparen: 0x24A2,
  27865. gpasquare: 0x33AC,
  27866. gradient: 0x2207,
  27867. grave: 0x0060,
  27868. gravebelowcmb: 0x0316,
  27869. gravecmb: 0x0300,
  27870. gravecomb: 0x0300,
  27871. gravedeva: 0x0953,
  27872. gravelowmod: 0x02CE,
  27873. gravemonospace: 0xFF40,
  27874. gravetonecmb: 0x0340,
  27875. greater: 0x003E,
  27876. greaterequal: 0x2265,
  27877. greaterequalorless: 0x22DB,
  27878. greatermonospace: 0xFF1E,
  27879. greaterorequivalent: 0x2273,
  27880. greaterorless: 0x2277,
  27881. greateroverequal: 0x2267,
  27882. greatersmall: 0xFE65,
  27883. gscript: 0x0261,
  27884. gstroke: 0x01E5,
  27885. guhiragana: 0x3050,
  27886. guillemotleft: 0x00AB,
  27887. guillemotright: 0x00BB,
  27888. guilsinglleft: 0x2039,
  27889. guilsinglright: 0x203A,
  27890. gukatakana: 0x30B0,
  27891. guramusquare: 0x3318,
  27892. gysquare: 0x33C9,
  27893. h: 0x0068,
  27894. haabkhasiancyrillic: 0x04A9,
  27895. haaltonearabic: 0x06C1,
  27896. habengali: 0x09B9,
  27897. hadescendercyrillic: 0x04B3,
  27898. hadeva: 0x0939,
  27899. hagujarati: 0x0AB9,
  27900. hagurmukhi: 0x0A39,
  27901. haharabic: 0x062D,
  27902. hahfinalarabic: 0xFEA2,
  27903. hahinitialarabic: 0xFEA3,
  27904. hahiragana: 0x306F,
  27905. hahmedialarabic: 0xFEA4,
  27906. haitusquare: 0x332A,
  27907. hakatakana: 0x30CF,
  27908. hakatakanahalfwidth: 0xFF8A,
  27909. halantgurmukhi: 0x0A4D,
  27910. hamzaarabic: 0x0621,
  27911. hamzalowarabic: 0x0621,
  27912. hangulfiller: 0x3164,
  27913. hardsigncyrillic: 0x044A,
  27914. harpoonleftbarbup: 0x21BC,
  27915. harpoonrightbarbup: 0x21C0,
  27916. hasquare: 0x33CA,
  27917. hatafpatah: 0x05B2,
  27918. hatafpatah16: 0x05B2,
  27919. hatafpatah23: 0x05B2,
  27920. hatafpatah2f: 0x05B2,
  27921. hatafpatahhebrew: 0x05B2,
  27922. hatafpatahnarrowhebrew: 0x05B2,
  27923. hatafpatahquarterhebrew: 0x05B2,
  27924. hatafpatahwidehebrew: 0x05B2,
  27925. hatafqamats: 0x05B3,
  27926. hatafqamats1b: 0x05B3,
  27927. hatafqamats28: 0x05B3,
  27928. hatafqamats34: 0x05B3,
  27929. hatafqamatshebrew: 0x05B3,
  27930. hatafqamatsnarrowhebrew: 0x05B3,
  27931. hatafqamatsquarterhebrew: 0x05B3,
  27932. hatafqamatswidehebrew: 0x05B3,
  27933. hatafsegol: 0x05B1,
  27934. hatafsegol17: 0x05B1,
  27935. hatafsegol24: 0x05B1,
  27936. hatafsegol30: 0x05B1,
  27937. hatafsegolhebrew: 0x05B1,
  27938. hatafsegolnarrowhebrew: 0x05B1,
  27939. hatafsegolquarterhebrew: 0x05B1,
  27940. hatafsegolwidehebrew: 0x05B1,
  27941. hbar: 0x0127,
  27942. hbopomofo: 0x310F,
  27943. hbrevebelow: 0x1E2B,
  27944. hcedilla: 0x1E29,
  27945. hcircle: 0x24D7,
  27946. hcircumflex: 0x0125,
  27947. hdieresis: 0x1E27,
  27948. hdotaccent: 0x1E23,
  27949. hdotbelow: 0x1E25,
  27950. he: 0x05D4,
  27951. heart: 0x2665,
  27952. heartsuitblack: 0x2665,
  27953. heartsuitwhite: 0x2661,
  27954. hedagesh: 0xFB34,
  27955. hedageshhebrew: 0xFB34,
  27956. hehaltonearabic: 0x06C1,
  27957. heharabic: 0x0647,
  27958. hehebrew: 0x05D4,
  27959. hehfinalaltonearabic: 0xFBA7,
  27960. hehfinalalttwoarabic: 0xFEEA,
  27961. hehfinalarabic: 0xFEEA,
  27962. hehhamzaabovefinalarabic: 0xFBA5,
  27963. hehhamzaaboveisolatedarabic: 0xFBA4,
  27964. hehinitialaltonearabic: 0xFBA8,
  27965. hehinitialarabic: 0xFEEB,
  27966. hehiragana: 0x3078,
  27967. hehmedialaltonearabic: 0xFBA9,
  27968. hehmedialarabic: 0xFEEC,
  27969. heiseierasquare: 0x337B,
  27970. hekatakana: 0x30D8,
  27971. hekatakanahalfwidth: 0xFF8D,
  27972. hekutaarusquare: 0x3336,
  27973. henghook: 0x0267,
  27974. herutusquare: 0x3339,
  27975. het: 0x05D7,
  27976. hethebrew: 0x05D7,
  27977. hhook: 0x0266,
  27978. hhooksuperior: 0x02B1,
  27979. hieuhacirclekorean: 0x327B,
  27980. hieuhaparenkorean: 0x321B,
  27981. hieuhcirclekorean: 0x326D,
  27982. hieuhkorean: 0x314E,
  27983. hieuhparenkorean: 0x320D,
  27984. hihiragana: 0x3072,
  27985. hikatakana: 0x30D2,
  27986. hikatakanahalfwidth: 0xFF8B,
  27987. hiriq: 0x05B4,
  27988. hiriq14: 0x05B4,
  27989. hiriq21: 0x05B4,
  27990. hiriq2d: 0x05B4,
  27991. hiriqhebrew: 0x05B4,
  27992. hiriqnarrowhebrew: 0x05B4,
  27993. hiriqquarterhebrew: 0x05B4,
  27994. hiriqwidehebrew: 0x05B4,
  27995. hlinebelow: 0x1E96,
  27996. hmonospace: 0xFF48,
  27997. hoarmenian: 0x0570,
  27998. hohipthai: 0x0E2B,
  27999. hohiragana: 0x307B,
  28000. hokatakana: 0x30DB,
  28001. hokatakanahalfwidth: 0xFF8E,
  28002. holam: 0x05B9,
  28003. holam19: 0x05B9,
  28004. holam26: 0x05B9,
  28005. holam32: 0x05B9,
  28006. holamhebrew: 0x05B9,
  28007. holamnarrowhebrew: 0x05B9,
  28008. holamquarterhebrew: 0x05B9,
  28009. holamwidehebrew: 0x05B9,
  28010. honokhukthai: 0x0E2E,
  28011. hookabovecomb: 0x0309,
  28012. hookcmb: 0x0309,
  28013. hookpalatalizedbelowcmb: 0x0321,
  28014. hookretroflexbelowcmb: 0x0322,
  28015. hoonsquare: 0x3342,
  28016. horicoptic: 0x03E9,
  28017. horizontalbar: 0x2015,
  28018. horncmb: 0x031B,
  28019. hotsprings: 0x2668,
  28020. house: 0x2302,
  28021. hparen: 0x24A3,
  28022. hsuperior: 0x02B0,
  28023. hturned: 0x0265,
  28024. huhiragana: 0x3075,
  28025. huiitosquare: 0x3333,
  28026. hukatakana: 0x30D5,
  28027. hukatakanahalfwidth: 0xFF8C,
  28028. hungarumlaut: 0x02DD,
  28029. hungarumlautcmb: 0x030B,
  28030. hv: 0x0195,
  28031. hyphen: 0x002D,
  28032. hypheninferior: 0xF6E5,
  28033. hyphenmonospace: 0xFF0D,
  28034. hyphensmall: 0xFE63,
  28035. hyphensuperior: 0xF6E6,
  28036. hyphentwo: 0x2010,
  28037. i: 0x0069,
  28038. iacute: 0x00ED,
  28039. iacyrillic: 0x044F,
  28040. ibengali: 0x0987,
  28041. ibopomofo: 0x3127,
  28042. ibreve: 0x012D,
  28043. icaron: 0x01D0,
  28044. icircle: 0x24D8,
  28045. icircumflex: 0x00EE,
  28046. icyrillic: 0x0456,
  28047. idblgrave: 0x0209,
  28048. ideographearthcircle: 0x328F,
  28049. ideographfirecircle: 0x328B,
  28050. ideographicallianceparen: 0x323F,
  28051. ideographiccallparen: 0x323A,
  28052. ideographiccentrecircle: 0x32A5,
  28053. ideographicclose: 0x3006,
  28054. ideographiccomma: 0x3001,
  28055. ideographiccommaleft: 0xFF64,
  28056. ideographiccongratulationparen: 0x3237,
  28057. ideographiccorrectcircle: 0x32A3,
  28058. ideographicearthparen: 0x322F,
  28059. ideographicenterpriseparen: 0x323D,
  28060. ideographicexcellentcircle: 0x329D,
  28061. ideographicfestivalparen: 0x3240,
  28062. ideographicfinancialcircle: 0x3296,
  28063. ideographicfinancialparen: 0x3236,
  28064. ideographicfireparen: 0x322B,
  28065. ideographichaveparen: 0x3232,
  28066. ideographichighcircle: 0x32A4,
  28067. ideographiciterationmark: 0x3005,
  28068. ideographiclaborcircle: 0x3298,
  28069. ideographiclaborparen: 0x3238,
  28070. ideographicleftcircle: 0x32A7,
  28071. ideographiclowcircle: 0x32A6,
  28072. ideographicmedicinecircle: 0x32A9,
  28073. ideographicmetalparen: 0x322E,
  28074. ideographicmoonparen: 0x322A,
  28075. ideographicnameparen: 0x3234,
  28076. ideographicperiod: 0x3002,
  28077. ideographicprintcircle: 0x329E,
  28078. ideographicreachparen: 0x3243,
  28079. ideographicrepresentparen: 0x3239,
  28080. ideographicresourceparen: 0x323E,
  28081. ideographicrightcircle: 0x32A8,
  28082. ideographicsecretcircle: 0x3299,
  28083. ideographicselfparen: 0x3242,
  28084. ideographicsocietyparen: 0x3233,
  28085. ideographicspace: 0x3000,
  28086. ideographicspecialparen: 0x3235,
  28087. ideographicstockparen: 0x3231,
  28088. ideographicstudyparen: 0x323B,
  28089. ideographicsunparen: 0x3230,
  28090. ideographicsuperviseparen: 0x323C,
  28091. ideographicwaterparen: 0x322C,
  28092. ideographicwoodparen: 0x322D,
  28093. ideographiczero: 0x3007,
  28094. ideographmetalcircle: 0x328E,
  28095. ideographmooncircle: 0x328A,
  28096. ideographnamecircle: 0x3294,
  28097. ideographsuncircle: 0x3290,
  28098. ideographwatercircle: 0x328C,
  28099. ideographwoodcircle: 0x328D,
  28100. ideva: 0x0907,
  28101. idieresis: 0x00EF,
  28102. idieresisacute: 0x1E2F,
  28103. idieresiscyrillic: 0x04E5,
  28104. idotbelow: 0x1ECB,
  28105. iebrevecyrillic: 0x04D7,
  28106. iecyrillic: 0x0435,
  28107. ieungacirclekorean: 0x3275,
  28108. ieungaparenkorean: 0x3215,
  28109. ieungcirclekorean: 0x3267,
  28110. ieungkorean: 0x3147,
  28111. ieungparenkorean: 0x3207,
  28112. igrave: 0x00EC,
  28113. igujarati: 0x0A87,
  28114. igurmukhi: 0x0A07,
  28115. ihiragana: 0x3044,
  28116. ihookabove: 0x1EC9,
  28117. iibengali: 0x0988,
  28118. iicyrillic: 0x0438,
  28119. iideva: 0x0908,
  28120. iigujarati: 0x0A88,
  28121. iigurmukhi: 0x0A08,
  28122. iimatragurmukhi: 0x0A40,
  28123. iinvertedbreve: 0x020B,
  28124. iishortcyrillic: 0x0439,
  28125. iivowelsignbengali: 0x09C0,
  28126. iivowelsigndeva: 0x0940,
  28127. iivowelsigngujarati: 0x0AC0,
  28128. ij: 0x0133,
  28129. ikatakana: 0x30A4,
  28130. ikatakanahalfwidth: 0xFF72,
  28131. ikorean: 0x3163,
  28132. ilde: 0x02DC,
  28133. iluyhebrew: 0x05AC,
  28134. imacron: 0x012B,
  28135. imacroncyrillic: 0x04E3,
  28136. imageorapproximatelyequal: 0x2253,
  28137. imatragurmukhi: 0x0A3F,
  28138. imonospace: 0xFF49,
  28139. increment: 0x2206,
  28140. infinity: 0x221E,
  28141. iniarmenian: 0x056B,
  28142. integral: 0x222B,
  28143. integralbottom: 0x2321,
  28144. integralbt: 0x2321,
  28145. integralex: 0xF8F5,
  28146. integraltop: 0x2320,
  28147. integraltp: 0x2320,
  28148. intersection: 0x2229,
  28149. intisquare: 0x3305,
  28150. invbullet: 0x25D8,
  28151. invcircle: 0x25D9,
  28152. invsmileface: 0x263B,
  28153. iocyrillic: 0x0451,
  28154. iogonek: 0x012F,
  28155. iota: 0x03B9,
  28156. iotadieresis: 0x03CA,
  28157. iotadieresistonos: 0x0390,
  28158. iotalatin: 0x0269,
  28159. iotatonos: 0x03AF,
  28160. iparen: 0x24A4,
  28161. irigurmukhi: 0x0A72,
  28162. ismallhiragana: 0x3043,
  28163. ismallkatakana: 0x30A3,
  28164. ismallkatakanahalfwidth: 0xFF68,
  28165. issharbengali: 0x09FA,
  28166. istroke: 0x0268,
  28167. isuperior: 0xF6ED,
  28168. iterationhiragana: 0x309D,
  28169. iterationkatakana: 0x30FD,
  28170. itilde: 0x0129,
  28171. itildebelow: 0x1E2D,
  28172. iubopomofo: 0x3129,
  28173. iucyrillic: 0x044E,
  28174. ivowelsignbengali: 0x09BF,
  28175. ivowelsigndeva: 0x093F,
  28176. ivowelsigngujarati: 0x0ABF,
  28177. izhitsacyrillic: 0x0475,
  28178. izhitsadblgravecyrillic: 0x0477,
  28179. j: 0x006A,
  28180. jaarmenian: 0x0571,
  28181. jabengali: 0x099C,
  28182. jadeva: 0x091C,
  28183. jagujarati: 0x0A9C,
  28184. jagurmukhi: 0x0A1C,
  28185. jbopomofo: 0x3110,
  28186. jcaron: 0x01F0,
  28187. jcircle: 0x24D9,
  28188. jcircumflex: 0x0135,
  28189. jcrossedtail: 0x029D,
  28190. jdotlessstroke: 0x025F,
  28191. jecyrillic: 0x0458,
  28192. jeemarabic: 0x062C,
  28193. jeemfinalarabic: 0xFE9E,
  28194. jeeminitialarabic: 0xFE9F,
  28195. jeemmedialarabic: 0xFEA0,
  28196. jeharabic: 0x0698,
  28197. jehfinalarabic: 0xFB8B,
  28198. jhabengali: 0x099D,
  28199. jhadeva: 0x091D,
  28200. jhagujarati: 0x0A9D,
  28201. jhagurmukhi: 0x0A1D,
  28202. jheharmenian: 0x057B,
  28203. jis: 0x3004,
  28204. jmonospace: 0xFF4A,
  28205. jparen: 0x24A5,
  28206. jsuperior: 0x02B2,
  28207. k: 0x006B,
  28208. kabashkircyrillic: 0x04A1,
  28209. kabengali: 0x0995,
  28210. kacute: 0x1E31,
  28211. kacyrillic: 0x043A,
  28212. kadescendercyrillic: 0x049B,
  28213. kadeva: 0x0915,
  28214. kaf: 0x05DB,
  28215. kafarabic: 0x0643,
  28216. kafdagesh: 0xFB3B,
  28217. kafdageshhebrew: 0xFB3B,
  28218. kaffinalarabic: 0xFEDA,
  28219. kafhebrew: 0x05DB,
  28220. kafinitialarabic: 0xFEDB,
  28221. kafmedialarabic: 0xFEDC,
  28222. kafrafehebrew: 0xFB4D,
  28223. kagujarati: 0x0A95,
  28224. kagurmukhi: 0x0A15,
  28225. kahiragana: 0x304B,
  28226. kahookcyrillic: 0x04C4,
  28227. kakatakana: 0x30AB,
  28228. kakatakanahalfwidth: 0xFF76,
  28229. kappa: 0x03BA,
  28230. kappasymbolgreek: 0x03F0,
  28231. kapyeounmieumkorean: 0x3171,
  28232. kapyeounphieuphkorean: 0x3184,
  28233. kapyeounpieupkorean: 0x3178,
  28234. kapyeounssangpieupkorean: 0x3179,
  28235. karoriisquare: 0x330D,
  28236. kashidaautoarabic: 0x0640,
  28237. kashidaautonosidebearingarabic: 0x0640,
  28238. kasmallkatakana: 0x30F5,
  28239. kasquare: 0x3384,
  28240. kasraarabic: 0x0650,
  28241. kasratanarabic: 0x064D,
  28242. kastrokecyrillic: 0x049F,
  28243. katahiraprolongmarkhalfwidth: 0xFF70,
  28244. kaverticalstrokecyrillic: 0x049D,
  28245. kbopomofo: 0x310E,
  28246. kcalsquare: 0x3389,
  28247. kcaron: 0x01E9,
  28248. kcedilla: 0x0137,
  28249. kcircle: 0x24DA,
  28250. kcommaaccent: 0x0137,
  28251. kdotbelow: 0x1E33,
  28252. keharmenian: 0x0584,
  28253. kehiragana: 0x3051,
  28254. kekatakana: 0x30B1,
  28255. kekatakanahalfwidth: 0xFF79,
  28256. kenarmenian: 0x056F,
  28257. kesmallkatakana: 0x30F6,
  28258. kgreenlandic: 0x0138,
  28259. khabengali: 0x0996,
  28260. khacyrillic: 0x0445,
  28261. khadeva: 0x0916,
  28262. khagujarati: 0x0A96,
  28263. khagurmukhi: 0x0A16,
  28264. khaharabic: 0x062E,
  28265. khahfinalarabic: 0xFEA6,
  28266. khahinitialarabic: 0xFEA7,
  28267. khahmedialarabic: 0xFEA8,
  28268. kheicoptic: 0x03E7,
  28269. khhadeva: 0x0959,
  28270. khhagurmukhi: 0x0A59,
  28271. khieukhacirclekorean: 0x3278,
  28272. khieukhaparenkorean: 0x3218,
  28273. khieukhcirclekorean: 0x326A,
  28274. khieukhkorean: 0x314B,
  28275. khieukhparenkorean: 0x320A,
  28276. khokhaithai: 0x0E02,
  28277. khokhonthai: 0x0E05,
  28278. khokhuatthai: 0x0E03,
  28279. khokhwaithai: 0x0E04,
  28280. khomutthai: 0x0E5B,
  28281. khook: 0x0199,
  28282. khorakhangthai: 0x0E06,
  28283. khzsquare: 0x3391,
  28284. kihiragana: 0x304D,
  28285. kikatakana: 0x30AD,
  28286. kikatakanahalfwidth: 0xFF77,
  28287. kiroguramusquare: 0x3315,
  28288. kiromeetorusquare: 0x3316,
  28289. kirosquare: 0x3314,
  28290. kiyeokacirclekorean: 0x326E,
  28291. kiyeokaparenkorean: 0x320E,
  28292. kiyeokcirclekorean: 0x3260,
  28293. kiyeokkorean: 0x3131,
  28294. kiyeokparenkorean: 0x3200,
  28295. kiyeoksioskorean: 0x3133,
  28296. kjecyrillic: 0x045C,
  28297. klinebelow: 0x1E35,
  28298. klsquare: 0x3398,
  28299. kmcubedsquare: 0x33A6,
  28300. kmonospace: 0xFF4B,
  28301. kmsquaredsquare: 0x33A2,
  28302. kohiragana: 0x3053,
  28303. kohmsquare: 0x33C0,
  28304. kokaithai: 0x0E01,
  28305. kokatakana: 0x30B3,
  28306. kokatakanahalfwidth: 0xFF7A,
  28307. kooposquare: 0x331E,
  28308. koppacyrillic: 0x0481,
  28309. koreanstandardsymbol: 0x327F,
  28310. koroniscmb: 0x0343,
  28311. kparen: 0x24A6,
  28312. kpasquare: 0x33AA,
  28313. ksicyrillic: 0x046F,
  28314. ktsquare: 0x33CF,
  28315. kturned: 0x029E,
  28316. kuhiragana: 0x304F,
  28317. kukatakana: 0x30AF,
  28318. kukatakanahalfwidth: 0xFF78,
  28319. kvsquare: 0x33B8,
  28320. kwsquare: 0x33BE,
  28321. l: 0x006C,
  28322. labengali: 0x09B2,
  28323. lacute: 0x013A,
  28324. ladeva: 0x0932,
  28325. lagujarati: 0x0AB2,
  28326. lagurmukhi: 0x0A32,
  28327. lakkhangyaothai: 0x0E45,
  28328. lamaleffinalarabic: 0xFEFC,
  28329. lamalefhamzaabovefinalarabic: 0xFEF8,
  28330. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  28331. lamalefhamzabelowfinalarabic: 0xFEFA,
  28332. lamalefhamzabelowisolatedarabic: 0xFEF9,
  28333. lamalefisolatedarabic: 0xFEFB,
  28334. lamalefmaddaabovefinalarabic: 0xFEF6,
  28335. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  28336. lamarabic: 0x0644,
  28337. lambda: 0x03BB,
  28338. lambdastroke: 0x019B,
  28339. lamed: 0x05DC,
  28340. lameddagesh: 0xFB3C,
  28341. lameddageshhebrew: 0xFB3C,
  28342. lamedhebrew: 0x05DC,
  28343. lamfinalarabic: 0xFEDE,
  28344. lamhahinitialarabic: 0xFCCA,
  28345. laminitialarabic: 0xFEDF,
  28346. lamjeeminitialarabic: 0xFCC9,
  28347. lamkhahinitialarabic: 0xFCCB,
  28348. lamlamhehisolatedarabic: 0xFDF2,
  28349. lammedialarabic: 0xFEE0,
  28350. lammeemhahinitialarabic: 0xFD88,
  28351. lammeeminitialarabic: 0xFCCC,
  28352. largecircle: 0x25EF,
  28353. lbar: 0x019A,
  28354. lbelt: 0x026C,
  28355. lbopomofo: 0x310C,
  28356. lcaron: 0x013E,
  28357. lcedilla: 0x013C,
  28358. lcircle: 0x24DB,
  28359. lcircumflexbelow: 0x1E3D,
  28360. lcommaaccent: 0x013C,
  28361. ldot: 0x0140,
  28362. ldotaccent: 0x0140,
  28363. ldotbelow: 0x1E37,
  28364. ldotbelowmacron: 0x1E39,
  28365. leftangleabovecmb: 0x031A,
  28366. lefttackbelowcmb: 0x0318,
  28367. less: 0x003C,
  28368. lessequal: 0x2264,
  28369. lessequalorgreater: 0x22DA,
  28370. lessmonospace: 0xFF1C,
  28371. lessorequivalent: 0x2272,
  28372. lessorgreater: 0x2276,
  28373. lessoverequal: 0x2266,
  28374. lesssmall: 0xFE64,
  28375. lezh: 0x026E,
  28376. lfblock: 0x258C,
  28377. lhookretroflex: 0x026D,
  28378. lira: 0x20A4,
  28379. liwnarmenian: 0x056C,
  28380. lj: 0x01C9,
  28381. ljecyrillic: 0x0459,
  28382. ll: 0xF6C0,
  28383. lladeva: 0x0933,
  28384. llagujarati: 0x0AB3,
  28385. llinebelow: 0x1E3B,
  28386. llladeva: 0x0934,
  28387. llvocalicbengali: 0x09E1,
  28388. llvocalicdeva: 0x0961,
  28389. llvocalicvowelsignbengali: 0x09E3,
  28390. llvocalicvowelsigndeva: 0x0963,
  28391. lmiddletilde: 0x026B,
  28392. lmonospace: 0xFF4C,
  28393. lmsquare: 0x33D0,
  28394. lochulathai: 0x0E2C,
  28395. logicaland: 0x2227,
  28396. logicalnot: 0x00AC,
  28397. logicalnotreversed: 0x2310,
  28398. logicalor: 0x2228,
  28399. lolingthai: 0x0E25,
  28400. longs: 0x017F,
  28401. lowlinecenterline: 0xFE4E,
  28402. lowlinecmb: 0x0332,
  28403. lowlinedashed: 0xFE4D,
  28404. lozenge: 0x25CA,
  28405. lparen: 0x24A7,
  28406. lslash: 0x0142,
  28407. lsquare: 0x2113,
  28408. lsuperior: 0xF6EE,
  28409. ltshade: 0x2591,
  28410. luthai: 0x0E26,
  28411. lvocalicbengali: 0x098C,
  28412. lvocalicdeva: 0x090C,
  28413. lvocalicvowelsignbengali: 0x09E2,
  28414. lvocalicvowelsigndeva: 0x0962,
  28415. lxsquare: 0x33D3,
  28416. m: 0x006D,
  28417. mabengali: 0x09AE,
  28418. macron: 0x00AF,
  28419. macronbelowcmb: 0x0331,
  28420. macroncmb: 0x0304,
  28421. macronlowmod: 0x02CD,
  28422. macronmonospace: 0xFFE3,
  28423. macute: 0x1E3F,
  28424. madeva: 0x092E,
  28425. magujarati: 0x0AAE,
  28426. magurmukhi: 0x0A2E,
  28427. mahapakhhebrew: 0x05A4,
  28428. mahapakhlefthebrew: 0x05A4,
  28429. mahiragana: 0x307E,
  28430. maichattawalowleftthai: 0xF895,
  28431. maichattawalowrightthai: 0xF894,
  28432. maichattawathai: 0x0E4B,
  28433. maichattawaupperleftthai: 0xF893,
  28434. maieklowleftthai: 0xF88C,
  28435. maieklowrightthai: 0xF88B,
  28436. maiekthai: 0x0E48,
  28437. maiekupperleftthai: 0xF88A,
  28438. maihanakatleftthai: 0xF884,
  28439. maihanakatthai: 0x0E31,
  28440. maitaikhuleftthai: 0xF889,
  28441. maitaikhuthai: 0x0E47,
  28442. maitholowleftthai: 0xF88F,
  28443. maitholowrightthai: 0xF88E,
  28444. maithothai: 0x0E49,
  28445. maithoupperleftthai: 0xF88D,
  28446. maitrilowleftthai: 0xF892,
  28447. maitrilowrightthai: 0xF891,
  28448. maitrithai: 0x0E4A,
  28449. maitriupperleftthai: 0xF890,
  28450. maiyamokthai: 0x0E46,
  28451. makatakana: 0x30DE,
  28452. makatakanahalfwidth: 0xFF8F,
  28453. male: 0x2642,
  28454. mansyonsquare: 0x3347,
  28455. maqafhebrew: 0x05BE,
  28456. mars: 0x2642,
  28457. masoracirclehebrew: 0x05AF,
  28458. masquare: 0x3383,
  28459. mbopomofo: 0x3107,
  28460. mbsquare: 0x33D4,
  28461. mcircle: 0x24DC,
  28462. mcubedsquare: 0x33A5,
  28463. mdotaccent: 0x1E41,
  28464. mdotbelow: 0x1E43,
  28465. meemarabic: 0x0645,
  28466. meemfinalarabic: 0xFEE2,
  28467. meeminitialarabic: 0xFEE3,
  28468. meemmedialarabic: 0xFEE4,
  28469. meemmeeminitialarabic: 0xFCD1,
  28470. meemmeemisolatedarabic: 0xFC48,
  28471. meetorusquare: 0x334D,
  28472. mehiragana: 0x3081,
  28473. meizierasquare: 0x337E,
  28474. mekatakana: 0x30E1,
  28475. mekatakanahalfwidth: 0xFF92,
  28476. mem: 0x05DE,
  28477. memdagesh: 0xFB3E,
  28478. memdageshhebrew: 0xFB3E,
  28479. memhebrew: 0x05DE,
  28480. menarmenian: 0x0574,
  28481. merkhahebrew: 0x05A5,
  28482. merkhakefulahebrew: 0x05A6,
  28483. merkhakefulalefthebrew: 0x05A6,
  28484. merkhalefthebrew: 0x05A5,
  28485. mhook: 0x0271,
  28486. mhzsquare: 0x3392,
  28487. middledotkatakanahalfwidth: 0xFF65,
  28488. middot: 0x00B7,
  28489. mieumacirclekorean: 0x3272,
  28490. mieumaparenkorean: 0x3212,
  28491. mieumcirclekorean: 0x3264,
  28492. mieumkorean: 0x3141,
  28493. mieumpansioskorean: 0x3170,
  28494. mieumparenkorean: 0x3204,
  28495. mieumpieupkorean: 0x316E,
  28496. mieumsioskorean: 0x316F,
  28497. mihiragana: 0x307F,
  28498. mikatakana: 0x30DF,
  28499. mikatakanahalfwidth: 0xFF90,
  28500. minus: 0x2212,
  28501. minusbelowcmb: 0x0320,
  28502. minuscircle: 0x2296,
  28503. minusmod: 0x02D7,
  28504. minusplus: 0x2213,
  28505. minute: 0x2032,
  28506. miribaarusquare: 0x334A,
  28507. mirisquare: 0x3349,
  28508. mlonglegturned: 0x0270,
  28509. mlsquare: 0x3396,
  28510. mmcubedsquare: 0x33A3,
  28511. mmonospace: 0xFF4D,
  28512. mmsquaredsquare: 0x339F,
  28513. mohiragana: 0x3082,
  28514. mohmsquare: 0x33C1,
  28515. mokatakana: 0x30E2,
  28516. mokatakanahalfwidth: 0xFF93,
  28517. molsquare: 0x33D6,
  28518. momathai: 0x0E21,
  28519. moverssquare: 0x33A7,
  28520. moverssquaredsquare: 0x33A8,
  28521. mparen: 0x24A8,
  28522. mpasquare: 0x33AB,
  28523. mssquare: 0x33B3,
  28524. msuperior: 0xF6EF,
  28525. mturned: 0x026F,
  28526. mu: 0x00B5,
  28527. mu1: 0x00B5,
  28528. muasquare: 0x3382,
  28529. muchgreater: 0x226B,
  28530. muchless: 0x226A,
  28531. mufsquare: 0x338C,
  28532. mugreek: 0x03BC,
  28533. mugsquare: 0x338D,
  28534. muhiragana: 0x3080,
  28535. mukatakana: 0x30E0,
  28536. mukatakanahalfwidth: 0xFF91,
  28537. mulsquare: 0x3395,
  28538. multiply: 0x00D7,
  28539. mumsquare: 0x339B,
  28540. munahhebrew: 0x05A3,
  28541. munahlefthebrew: 0x05A3,
  28542. musicalnote: 0x266A,
  28543. musicalnotedbl: 0x266B,
  28544. musicflatsign: 0x266D,
  28545. musicsharpsign: 0x266F,
  28546. mussquare: 0x33B2,
  28547. muvsquare: 0x33B6,
  28548. muwsquare: 0x33BC,
  28549. mvmegasquare: 0x33B9,
  28550. mvsquare: 0x33B7,
  28551. mwmegasquare: 0x33BF,
  28552. mwsquare: 0x33BD,
  28553. n: 0x006E,
  28554. nabengali: 0x09A8,
  28555. nabla: 0x2207,
  28556. nacute: 0x0144,
  28557. nadeva: 0x0928,
  28558. nagujarati: 0x0AA8,
  28559. nagurmukhi: 0x0A28,
  28560. nahiragana: 0x306A,
  28561. nakatakana: 0x30CA,
  28562. nakatakanahalfwidth: 0xFF85,
  28563. napostrophe: 0x0149,
  28564. nasquare: 0x3381,
  28565. nbopomofo: 0x310B,
  28566. nbspace: 0x00A0,
  28567. ncaron: 0x0148,
  28568. ncedilla: 0x0146,
  28569. ncircle: 0x24DD,
  28570. ncircumflexbelow: 0x1E4B,
  28571. ncommaaccent: 0x0146,
  28572. ndotaccent: 0x1E45,
  28573. ndotbelow: 0x1E47,
  28574. nehiragana: 0x306D,
  28575. nekatakana: 0x30CD,
  28576. nekatakanahalfwidth: 0xFF88,
  28577. newsheqelsign: 0x20AA,
  28578. nfsquare: 0x338B,
  28579. ngabengali: 0x0999,
  28580. ngadeva: 0x0919,
  28581. ngagujarati: 0x0A99,
  28582. ngagurmukhi: 0x0A19,
  28583. ngonguthai: 0x0E07,
  28584. nhiragana: 0x3093,
  28585. nhookleft: 0x0272,
  28586. nhookretroflex: 0x0273,
  28587. nieunacirclekorean: 0x326F,
  28588. nieunaparenkorean: 0x320F,
  28589. nieuncieuckorean: 0x3135,
  28590. nieuncirclekorean: 0x3261,
  28591. nieunhieuhkorean: 0x3136,
  28592. nieunkorean: 0x3134,
  28593. nieunpansioskorean: 0x3168,
  28594. nieunparenkorean: 0x3201,
  28595. nieunsioskorean: 0x3167,
  28596. nieuntikeutkorean: 0x3166,
  28597. nihiragana: 0x306B,
  28598. nikatakana: 0x30CB,
  28599. nikatakanahalfwidth: 0xFF86,
  28600. nikhahitleftthai: 0xF899,
  28601. nikhahitthai: 0x0E4D,
  28602. nine: 0x0039,
  28603. ninearabic: 0x0669,
  28604. ninebengali: 0x09EF,
  28605. ninecircle: 0x2468,
  28606. ninecircleinversesansserif: 0x2792,
  28607. ninedeva: 0x096F,
  28608. ninegujarati: 0x0AEF,
  28609. ninegurmukhi: 0x0A6F,
  28610. ninehackarabic: 0x0669,
  28611. ninehangzhou: 0x3029,
  28612. nineideographicparen: 0x3228,
  28613. nineinferior: 0x2089,
  28614. ninemonospace: 0xFF19,
  28615. nineoldstyle: 0xF739,
  28616. nineparen: 0x247C,
  28617. nineperiod: 0x2490,
  28618. ninepersian: 0x06F9,
  28619. nineroman: 0x2178,
  28620. ninesuperior: 0x2079,
  28621. nineteencircle: 0x2472,
  28622. nineteenparen: 0x2486,
  28623. nineteenperiod: 0x249A,
  28624. ninethai: 0x0E59,
  28625. nj: 0x01CC,
  28626. njecyrillic: 0x045A,
  28627. nkatakana: 0x30F3,
  28628. nkatakanahalfwidth: 0xFF9D,
  28629. nlegrightlong: 0x019E,
  28630. nlinebelow: 0x1E49,
  28631. nmonospace: 0xFF4E,
  28632. nmsquare: 0x339A,
  28633. nnabengali: 0x09A3,
  28634. nnadeva: 0x0923,
  28635. nnagujarati: 0x0AA3,
  28636. nnagurmukhi: 0x0A23,
  28637. nnnadeva: 0x0929,
  28638. nohiragana: 0x306E,
  28639. nokatakana: 0x30CE,
  28640. nokatakanahalfwidth: 0xFF89,
  28641. nonbreakingspace: 0x00A0,
  28642. nonenthai: 0x0E13,
  28643. nonuthai: 0x0E19,
  28644. noonarabic: 0x0646,
  28645. noonfinalarabic: 0xFEE6,
  28646. noonghunnaarabic: 0x06BA,
  28647. noonghunnafinalarabic: 0xFB9F,
  28648. nooninitialarabic: 0xFEE7,
  28649. noonjeeminitialarabic: 0xFCD2,
  28650. noonjeemisolatedarabic: 0xFC4B,
  28651. noonmedialarabic: 0xFEE8,
  28652. noonmeeminitialarabic: 0xFCD5,
  28653. noonmeemisolatedarabic: 0xFC4E,
  28654. noonnoonfinalarabic: 0xFC8D,
  28655. notcontains: 0x220C,
  28656. notelement: 0x2209,
  28657. notelementof: 0x2209,
  28658. notequal: 0x2260,
  28659. notgreater: 0x226F,
  28660. notgreaternorequal: 0x2271,
  28661. notgreaternorless: 0x2279,
  28662. notidentical: 0x2262,
  28663. notless: 0x226E,
  28664. notlessnorequal: 0x2270,
  28665. notparallel: 0x2226,
  28666. notprecedes: 0x2280,
  28667. notsubset: 0x2284,
  28668. notsucceeds: 0x2281,
  28669. notsuperset: 0x2285,
  28670. nowarmenian: 0x0576,
  28671. nparen: 0x24A9,
  28672. nssquare: 0x33B1,
  28673. nsuperior: 0x207F,
  28674. ntilde: 0x00F1,
  28675. nu: 0x03BD,
  28676. nuhiragana: 0x306C,
  28677. nukatakana: 0x30CC,
  28678. nukatakanahalfwidth: 0xFF87,
  28679. nuktabengali: 0x09BC,
  28680. nuktadeva: 0x093C,
  28681. nuktagujarati: 0x0ABC,
  28682. nuktagurmukhi: 0x0A3C,
  28683. numbersign: 0x0023,
  28684. numbersignmonospace: 0xFF03,
  28685. numbersignsmall: 0xFE5F,
  28686. numeralsigngreek: 0x0374,
  28687. numeralsignlowergreek: 0x0375,
  28688. numero: 0x2116,
  28689. nun: 0x05E0,
  28690. nundagesh: 0xFB40,
  28691. nundageshhebrew: 0xFB40,
  28692. nunhebrew: 0x05E0,
  28693. nvsquare: 0x33B5,
  28694. nwsquare: 0x33BB,
  28695. nyabengali: 0x099E,
  28696. nyadeva: 0x091E,
  28697. nyagujarati: 0x0A9E,
  28698. nyagurmukhi: 0x0A1E,
  28699. o: 0x006F,
  28700. oacute: 0x00F3,
  28701. oangthai: 0x0E2D,
  28702. obarred: 0x0275,
  28703. obarredcyrillic: 0x04E9,
  28704. obarreddieresiscyrillic: 0x04EB,
  28705. obengali: 0x0993,
  28706. obopomofo: 0x311B,
  28707. obreve: 0x014F,
  28708. ocandradeva: 0x0911,
  28709. ocandragujarati: 0x0A91,
  28710. ocandravowelsigndeva: 0x0949,
  28711. ocandravowelsigngujarati: 0x0AC9,
  28712. ocaron: 0x01D2,
  28713. ocircle: 0x24DE,
  28714. ocircumflex: 0x00F4,
  28715. ocircumflexacute: 0x1ED1,
  28716. ocircumflexdotbelow: 0x1ED9,
  28717. ocircumflexgrave: 0x1ED3,
  28718. ocircumflexhookabove: 0x1ED5,
  28719. ocircumflextilde: 0x1ED7,
  28720. ocyrillic: 0x043E,
  28721. odblacute: 0x0151,
  28722. odblgrave: 0x020D,
  28723. odeva: 0x0913,
  28724. odieresis: 0x00F6,
  28725. odieresiscyrillic: 0x04E7,
  28726. odotbelow: 0x1ECD,
  28727. oe: 0x0153,
  28728. oekorean: 0x315A,
  28729. ogonek: 0x02DB,
  28730. ogonekcmb: 0x0328,
  28731. ograve: 0x00F2,
  28732. ogujarati: 0x0A93,
  28733. oharmenian: 0x0585,
  28734. ohiragana: 0x304A,
  28735. ohookabove: 0x1ECF,
  28736. ohorn: 0x01A1,
  28737. ohornacute: 0x1EDB,
  28738. ohorndotbelow: 0x1EE3,
  28739. ohorngrave: 0x1EDD,
  28740. ohornhookabove: 0x1EDF,
  28741. ohorntilde: 0x1EE1,
  28742. ohungarumlaut: 0x0151,
  28743. oi: 0x01A3,
  28744. oinvertedbreve: 0x020F,
  28745. okatakana: 0x30AA,
  28746. okatakanahalfwidth: 0xFF75,
  28747. okorean: 0x3157,
  28748. olehebrew: 0x05AB,
  28749. omacron: 0x014D,
  28750. omacronacute: 0x1E53,
  28751. omacrongrave: 0x1E51,
  28752. omdeva: 0x0950,
  28753. omega: 0x03C9,
  28754. omega1: 0x03D6,
  28755. omegacyrillic: 0x0461,
  28756. omegalatinclosed: 0x0277,
  28757. omegaroundcyrillic: 0x047B,
  28758. omegatitlocyrillic: 0x047D,
  28759. omegatonos: 0x03CE,
  28760. omgujarati: 0x0AD0,
  28761. omicron: 0x03BF,
  28762. omicrontonos: 0x03CC,
  28763. omonospace: 0xFF4F,
  28764. one: 0x0031,
  28765. onearabic: 0x0661,
  28766. onebengali: 0x09E7,
  28767. onecircle: 0x2460,
  28768. onecircleinversesansserif: 0x278A,
  28769. onedeva: 0x0967,
  28770. onedotenleader: 0x2024,
  28771. oneeighth: 0x215B,
  28772. onefitted: 0xF6DC,
  28773. onegujarati: 0x0AE7,
  28774. onegurmukhi: 0x0A67,
  28775. onehackarabic: 0x0661,
  28776. onehalf: 0x00BD,
  28777. onehangzhou: 0x3021,
  28778. oneideographicparen: 0x3220,
  28779. oneinferior: 0x2081,
  28780. onemonospace: 0xFF11,
  28781. onenumeratorbengali: 0x09F4,
  28782. oneoldstyle: 0xF731,
  28783. oneparen: 0x2474,
  28784. oneperiod: 0x2488,
  28785. onepersian: 0x06F1,
  28786. onequarter: 0x00BC,
  28787. oneroman: 0x2170,
  28788. onesuperior: 0x00B9,
  28789. onethai: 0x0E51,
  28790. onethird: 0x2153,
  28791. oogonek: 0x01EB,
  28792. oogonekmacron: 0x01ED,
  28793. oogurmukhi: 0x0A13,
  28794. oomatragurmukhi: 0x0A4B,
  28795. oopen: 0x0254,
  28796. oparen: 0x24AA,
  28797. openbullet: 0x25E6,
  28798. option: 0x2325,
  28799. ordfeminine: 0x00AA,
  28800. ordmasculine: 0x00BA,
  28801. orthogonal: 0x221F,
  28802. oshortdeva: 0x0912,
  28803. oshortvowelsigndeva: 0x094A,
  28804. oslash: 0x00F8,
  28805. oslashacute: 0x01FF,
  28806. osmallhiragana: 0x3049,
  28807. osmallkatakana: 0x30A9,
  28808. osmallkatakanahalfwidth: 0xFF6B,
  28809. ostrokeacute: 0x01FF,
  28810. osuperior: 0xF6F0,
  28811. otcyrillic: 0x047F,
  28812. otilde: 0x00F5,
  28813. otildeacute: 0x1E4D,
  28814. otildedieresis: 0x1E4F,
  28815. oubopomofo: 0x3121,
  28816. overline: 0x203E,
  28817. overlinecenterline: 0xFE4A,
  28818. overlinecmb: 0x0305,
  28819. overlinedashed: 0xFE49,
  28820. overlinedblwavy: 0xFE4C,
  28821. overlinewavy: 0xFE4B,
  28822. overscore: 0x00AF,
  28823. ovowelsignbengali: 0x09CB,
  28824. ovowelsigndeva: 0x094B,
  28825. ovowelsigngujarati: 0x0ACB,
  28826. p: 0x0070,
  28827. paampssquare: 0x3380,
  28828. paasentosquare: 0x332B,
  28829. pabengali: 0x09AA,
  28830. pacute: 0x1E55,
  28831. padeva: 0x092A,
  28832. pagedown: 0x21DF,
  28833. pageup: 0x21DE,
  28834. pagujarati: 0x0AAA,
  28835. pagurmukhi: 0x0A2A,
  28836. pahiragana: 0x3071,
  28837. paiyannoithai: 0x0E2F,
  28838. pakatakana: 0x30D1,
  28839. palatalizationcyrilliccmb: 0x0484,
  28840. palochkacyrillic: 0x04C0,
  28841. pansioskorean: 0x317F,
  28842. paragraph: 0x00B6,
  28843. parallel: 0x2225,
  28844. parenleft: 0x0028,
  28845. parenleftaltonearabic: 0xFD3E,
  28846. parenleftbt: 0xF8ED,
  28847. parenleftex: 0xF8EC,
  28848. parenleftinferior: 0x208D,
  28849. parenleftmonospace: 0xFF08,
  28850. parenleftsmall: 0xFE59,
  28851. parenleftsuperior: 0x207D,
  28852. parenlefttp: 0xF8EB,
  28853. parenleftvertical: 0xFE35,
  28854. parenright: 0x0029,
  28855. parenrightaltonearabic: 0xFD3F,
  28856. parenrightbt: 0xF8F8,
  28857. parenrightex: 0xF8F7,
  28858. parenrightinferior: 0x208E,
  28859. parenrightmonospace: 0xFF09,
  28860. parenrightsmall: 0xFE5A,
  28861. parenrightsuperior: 0x207E,
  28862. parenrighttp: 0xF8F6,
  28863. parenrightvertical: 0xFE36,
  28864. partialdiff: 0x2202,
  28865. paseqhebrew: 0x05C0,
  28866. pashtahebrew: 0x0599,
  28867. pasquare: 0x33A9,
  28868. patah: 0x05B7,
  28869. patah11: 0x05B7,
  28870. patah1d: 0x05B7,
  28871. patah2a: 0x05B7,
  28872. patahhebrew: 0x05B7,
  28873. patahnarrowhebrew: 0x05B7,
  28874. patahquarterhebrew: 0x05B7,
  28875. patahwidehebrew: 0x05B7,
  28876. pazerhebrew: 0x05A1,
  28877. pbopomofo: 0x3106,
  28878. pcircle: 0x24DF,
  28879. pdotaccent: 0x1E57,
  28880. pe: 0x05E4,
  28881. pecyrillic: 0x043F,
  28882. pedagesh: 0xFB44,
  28883. pedageshhebrew: 0xFB44,
  28884. peezisquare: 0x333B,
  28885. pefinaldageshhebrew: 0xFB43,
  28886. peharabic: 0x067E,
  28887. peharmenian: 0x057A,
  28888. pehebrew: 0x05E4,
  28889. pehfinalarabic: 0xFB57,
  28890. pehinitialarabic: 0xFB58,
  28891. pehiragana: 0x307A,
  28892. pehmedialarabic: 0xFB59,
  28893. pekatakana: 0x30DA,
  28894. pemiddlehookcyrillic: 0x04A7,
  28895. perafehebrew: 0xFB4E,
  28896. percent: 0x0025,
  28897. percentarabic: 0x066A,
  28898. percentmonospace: 0xFF05,
  28899. percentsmall: 0xFE6A,
  28900. period: 0x002E,
  28901. periodarmenian: 0x0589,
  28902. periodcentered: 0x00B7,
  28903. periodhalfwidth: 0xFF61,
  28904. periodinferior: 0xF6E7,
  28905. periodmonospace: 0xFF0E,
  28906. periodsmall: 0xFE52,
  28907. periodsuperior: 0xF6E8,
  28908. perispomenigreekcmb: 0x0342,
  28909. perpendicular: 0x22A5,
  28910. perthousand: 0x2030,
  28911. peseta: 0x20A7,
  28912. pfsquare: 0x338A,
  28913. phabengali: 0x09AB,
  28914. phadeva: 0x092B,
  28915. phagujarati: 0x0AAB,
  28916. phagurmukhi: 0x0A2B,
  28917. phi: 0x03C6,
  28918. phi1: 0x03D5,
  28919. phieuphacirclekorean: 0x327A,
  28920. phieuphaparenkorean: 0x321A,
  28921. phieuphcirclekorean: 0x326C,
  28922. phieuphkorean: 0x314D,
  28923. phieuphparenkorean: 0x320C,
  28924. philatin: 0x0278,
  28925. phinthuthai: 0x0E3A,
  28926. phisymbolgreek: 0x03D5,
  28927. phook: 0x01A5,
  28928. phophanthai: 0x0E1E,
  28929. phophungthai: 0x0E1C,
  28930. phosamphaothai: 0x0E20,
  28931. pi: 0x03C0,
  28932. pieupacirclekorean: 0x3273,
  28933. pieupaparenkorean: 0x3213,
  28934. pieupcieuckorean: 0x3176,
  28935. pieupcirclekorean: 0x3265,
  28936. pieupkiyeokkorean: 0x3172,
  28937. pieupkorean: 0x3142,
  28938. pieupparenkorean: 0x3205,
  28939. pieupsioskiyeokkorean: 0x3174,
  28940. pieupsioskorean: 0x3144,
  28941. pieupsiostikeutkorean: 0x3175,
  28942. pieupthieuthkorean: 0x3177,
  28943. pieuptikeutkorean: 0x3173,
  28944. pihiragana: 0x3074,
  28945. pikatakana: 0x30D4,
  28946. pisymbolgreek: 0x03D6,
  28947. piwrarmenian: 0x0583,
  28948. plus: 0x002B,
  28949. plusbelowcmb: 0x031F,
  28950. pluscircle: 0x2295,
  28951. plusminus: 0x00B1,
  28952. plusmod: 0x02D6,
  28953. plusmonospace: 0xFF0B,
  28954. plussmall: 0xFE62,
  28955. plussuperior: 0x207A,
  28956. pmonospace: 0xFF50,
  28957. pmsquare: 0x33D8,
  28958. pohiragana: 0x307D,
  28959. pointingindexdownwhite: 0x261F,
  28960. pointingindexleftwhite: 0x261C,
  28961. pointingindexrightwhite: 0x261E,
  28962. pointingindexupwhite: 0x261D,
  28963. pokatakana: 0x30DD,
  28964. poplathai: 0x0E1B,
  28965. postalmark: 0x3012,
  28966. postalmarkface: 0x3020,
  28967. pparen: 0x24AB,
  28968. precedes: 0x227A,
  28969. prescription: 0x211E,
  28970. primemod: 0x02B9,
  28971. primereversed: 0x2035,
  28972. product: 0x220F,
  28973. projective: 0x2305,
  28974. prolongedkana: 0x30FC,
  28975. propellor: 0x2318,
  28976. propersubset: 0x2282,
  28977. propersuperset: 0x2283,
  28978. proportion: 0x2237,
  28979. proportional: 0x221D,
  28980. psi: 0x03C8,
  28981. psicyrillic: 0x0471,
  28982. psilipneumatacyrilliccmb: 0x0486,
  28983. pssquare: 0x33B0,
  28984. puhiragana: 0x3077,
  28985. pukatakana: 0x30D7,
  28986. pvsquare: 0x33B4,
  28987. pwsquare: 0x33BA,
  28988. q: 0x0071,
  28989. qadeva: 0x0958,
  28990. qadmahebrew: 0x05A8,
  28991. qafarabic: 0x0642,
  28992. qaffinalarabic: 0xFED6,
  28993. qafinitialarabic: 0xFED7,
  28994. qafmedialarabic: 0xFED8,
  28995. qamats: 0x05B8,
  28996. qamats10: 0x05B8,
  28997. qamats1a: 0x05B8,
  28998. qamats1c: 0x05B8,
  28999. qamats27: 0x05B8,
  29000. qamats29: 0x05B8,
  29001. qamats33: 0x05B8,
  29002. qamatsde: 0x05B8,
  29003. qamatshebrew: 0x05B8,
  29004. qamatsnarrowhebrew: 0x05B8,
  29005. qamatsqatanhebrew: 0x05B8,
  29006. qamatsqatannarrowhebrew: 0x05B8,
  29007. qamatsqatanquarterhebrew: 0x05B8,
  29008. qamatsqatanwidehebrew: 0x05B8,
  29009. qamatsquarterhebrew: 0x05B8,
  29010. qamatswidehebrew: 0x05B8,
  29011. qarneyparahebrew: 0x059F,
  29012. qbopomofo: 0x3111,
  29013. qcircle: 0x24E0,
  29014. qhook: 0x02A0,
  29015. qmonospace: 0xFF51,
  29016. qof: 0x05E7,
  29017. qofdagesh: 0xFB47,
  29018. qofdageshhebrew: 0xFB47,
  29019. qofhebrew: 0x05E7,
  29020. qparen: 0x24AC,
  29021. quarternote: 0x2669,
  29022. qubuts: 0x05BB,
  29023. qubuts18: 0x05BB,
  29024. qubuts25: 0x05BB,
  29025. qubuts31: 0x05BB,
  29026. qubutshebrew: 0x05BB,
  29027. qubutsnarrowhebrew: 0x05BB,
  29028. qubutsquarterhebrew: 0x05BB,
  29029. qubutswidehebrew: 0x05BB,
  29030. question: 0x003F,
  29031. questionarabic: 0x061F,
  29032. questionarmenian: 0x055E,
  29033. questiondown: 0x00BF,
  29034. questiondownsmall: 0xF7BF,
  29035. questiongreek: 0x037E,
  29036. questionmonospace: 0xFF1F,
  29037. questionsmall: 0xF73F,
  29038. quotedbl: 0x0022,
  29039. quotedblbase: 0x201E,
  29040. quotedblleft: 0x201C,
  29041. quotedblmonospace: 0xFF02,
  29042. quotedblprime: 0x301E,
  29043. quotedblprimereversed: 0x301D,
  29044. quotedblright: 0x201D,
  29045. quoteleft: 0x2018,
  29046. quoteleftreversed: 0x201B,
  29047. quotereversed: 0x201B,
  29048. quoteright: 0x2019,
  29049. quoterightn: 0x0149,
  29050. quotesinglbase: 0x201A,
  29051. quotesingle: 0x0027,
  29052. quotesinglemonospace: 0xFF07,
  29053. r: 0x0072,
  29054. raarmenian: 0x057C,
  29055. rabengali: 0x09B0,
  29056. racute: 0x0155,
  29057. radeva: 0x0930,
  29058. radical: 0x221A,
  29059. radicalex: 0xF8E5,
  29060. radoverssquare: 0x33AE,
  29061. radoverssquaredsquare: 0x33AF,
  29062. radsquare: 0x33AD,
  29063. rafe: 0x05BF,
  29064. rafehebrew: 0x05BF,
  29065. ragujarati: 0x0AB0,
  29066. ragurmukhi: 0x0A30,
  29067. rahiragana: 0x3089,
  29068. rakatakana: 0x30E9,
  29069. rakatakanahalfwidth: 0xFF97,
  29070. ralowerdiagonalbengali: 0x09F1,
  29071. ramiddlediagonalbengali: 0x09F0,
  29072. ramshorn: 0x0264,
  29073. ratio: 0x2236,
  29074. rbopomofo: 0x3116,
  29075. rcaron: 0x0159,
  29076. rcedilla: 0x0157,
  29077. rcircle: 0x24E1,
  29078. rcommaaccent: 0x0157,
  29079. rdblgrave: 0x0211,
  29080. rdotaccent: 0x1E59,
  29081. rdotbelow: 0x1E5B,
  29082. rdotbelowmacron: 0x1E5D,
  29083. referencemark: 0x203B,
  29084. reflexsubset: 0x2286,
  29085. reflexsuperset: 0x2287,
  29086. registered: 0x00AE,
  29087. registersans: 0xF8E8,
  29088. registerserif: 0xF6DA,
  29089. reharabic: 0x0631,
  29090. reharmenian: 0x0580,
  29091. rehfinalarabic: 0xFEAE,
  29092. rehiragana: 0x308C,
  29093. rekatakana: 0x30EC,
  29094. rekatakanahalfwidth: 0xFF9A,
  29095. resh: 0x05E8,
  29096. reshdageshhebrew: 0xFB48,
  29097. reshhebrew: 0x05E8,
  29098. reversedtilde: 0x223D,
  29099. reviahebrew: 0x0597,
  29100. reviamugrashhebrew: 0x0597,
  29101. revlogicalnot: 0x2310,
  29102. rfishhook: 0x027E,
  29103. rfishhookreversed: 0x027F,
  29104. rhabengali: 0x09DD,
  29105. rhadeva: 0x095D,
  29106. rho: 0x03C1,
  29107. rhook: 0x027D,
  29108. rhookturned: 0x027B,
  29109. rhookturnedsuperior: 0x02B5,
  29110. rhosymbolgreek: 0x03F1,
  29111. rhotichookmod: 0x02DE,
  29112. rieulacirclekorean: 0x3271,
  29113. rieulaparenkorean: 0x3211,
  29114. rieulcirclekorean: 0x3263,
  29115. rieulhieuhkorean: 0x3140,
  29116. rieulkiyeokkorean: 0x313A,
  29117. rieulkiyeoksioskorean: 0x3169,
  29118. rieulkorean: 0x3139,
  29119. rieulmieumkorean: 0x313B,
  29120. rieulpansioskorean: 0x316C,
  29121. rieulparenkorean: 0x3203,
  29122. rieulphieuphkorean: 0x313F,
  29123. rieulpieupkorean: 0x313C,
  29124. rieulpieupsioskorean: 0x316B,
  29125. rieulsioskorean: 0x313D,
  29126. rieulthieuthkorean: 0x313E,
  29127. rieultikeutkorean: 0x316A,
  29128. rieulyeorinhieuhkorean: 0x316D,
  29129. rightangle: 0x221F,
  29130. righttackbelowcmb: 0x0319,
  29131. righttriangle: 0x22BF,
  29132. rihiragana: 0x308A,
  29133. rikatakana: 0x30EA,
  29134. rikatakanahalfwidth: 0xFF98,
  29135. ring: 0x02DA,
  29136. ringbelowcmb: 0x0325,
  29137. ringcmb: 0x030A,
  29138. ringhalfleft: 0x02BF,
  29139. ringhalfleftarmenian: 0x0559,
  29140. ringhalfleftbelowcmb: 0x031C,
  29141. ringhalfleftcentered: 0x02D3,
  29142. ringhalfright: 0x02BE,
  29143. ringhalfrightbelowcmb: 0x0339,
  29144. ringhalfrightcentered: 0x02D2,
  29145. rinvertedbreve: 0x0213,
  29146. rittorusquare: 0x3351,
  29147. rlinebelow: 0x1E5F,
  29148. rlongleg: 0x027C,
  29149. rlonglegturned: 0x027A,
  29150. rmonospace: 0xFF52,
  29151. rohiragana: 0x308D,
  29152. rokatakana: 0x30ED,
  29153. rokatakanahalfwidth: 0xFF9B,
  29154. roruathai: 0x0E23,
  29155. rparen: 0x24AD,
  29156. rrabengali: 0x09DC,
  29157. rradeva: 0x0931,
  29158. rragurmukhi: 0x0A5C,
  29159. rreharabic: 0x0691,
  29160. rrehfinalarabic: 0xFB8D,
  29161. rrvocalicbengali: 0x09E0,
  29162. rrvocalicdeva: 0x0960,
  29163. rrvocalicgujarati: 0x0AE0,
  29164. rrvocalicvowelsignbengali: 0x09C4,
  29165. rrvocalicvowelsigndeva: 0x0944,
  29166. rrvocalicvowelsigngujarati: 0x0AC4,
  29167. rsuperior: 0xF6F1,
  29168. rtblock: 0x2590,
  29169. rturned: 0x0279,
  29170. rturnedsuperior: 0x02B4,
  29171. ruhiragana: 0x308B,
  29172. rukatakana: 0x30EB,
  29173. rukatakanahalfwidth: 0xFF99,
  29174. rupeemarkbengali: 0x09F2,
  29175. rupeesignbengali: 0x09F3,
  29176. rupiah: 0xF6DD,
  29177. ruthai: 0x0E24,
  29178. rvocalicbengali: 0x098B,
  29179. rvocalicdeva: 0x090B,
  29180. rvocalicgujarati: 0x0A8B,
  29181. rvocalicvowelsignbengali: 0x09C3,
  29182. rvocalicvowelsigndeva: 0x0943,
  29183. rvocalicvowelsigngujarati: 0x0AC3,
  29184. s: 0x0073,
  29185. sabengali: 0x09B8,
  29186. sacute: 0x015B,
  29187. sacutedotaccent: 0x1E65,
  29188. sadarabic: 0x0635,
  29189. sadeva: 0x0938,
  29190. sadfinalarabic: 0xFEBA,
  29191. sadinitialarabic: 0xFEBB,
  29192. sadmedialarabic: 0xFEBC,
  29193. sagujarati: 0x0AB8,
  29194. sagurmukhi: 0x0A38,
  29195. sahiragana: 0x3055,
  29196. sakatakana: 0x30B5,
  29197. sakatakanahalfwidth: 0xFF7B,
  29198. sallallahoualayhewasallamarabic: 0xFDFA,
  29199. samekh: 0x05E1,
  29200. samekhdagesh: 0xFB41,
  29201. samekhdageshhebrew: 0xFB41,
  29202. samekhhebrew: 0x05E1,
  29203. saraaathai: 0x0E32,
  29204. saraaethai: 0x0E41,
  29205. saraaimaimalaithai: 0x0E44,
  29206. saraaimaimuanthai: 0x0E43,
  29207. saraamthai: 0x0E33,
  29208. saraathai: 0x0E30,
  29209. saraethai: 0x0E40,
  29210. saraiileftthai: 0xF886,
  29211. saraiithai: 0x0E35,
  29212. saraileftthai: 0xF885,
  29213. saraithai: 0x0E34,
  29214. saraothai: 0x0E42,
  29215. saraueeleftthai: 0xF888,
  29216. saraueethai: 0x0E37,
  29217. saraueleftthai: 0xF887,
  29218. sarauethai: 0x0E36,
  29219. sarauthai: 0x0E38,
  29220. sarauuthai: 0x0E39,
  29221. sbopomofo: 0x3119,
  29222. scaron: 0x0161,
  29223. scarondotaccent: 0x1E67,
  29224. scedilla: 0x015F,
  29225. schwa: 0x0259,
  29226. schwacyrillic: 0x04D9,
  29227. schwadieresiscyrillic: 0x04DB,
  29228. schwahook: 0x025A,
  29229. scircle: 0x24E2,
  29230. scircumflex: 0x015D,
  29231. scommaaccent: 0x0219,
  29232. sdotaccent: 0x1E61,
  29233. sdotbelow: 0x1E63,
  29234. sdotbelowdotaccent: 0x1E69,
  29235. seagullbelowcmb: 0x033C,
  29236. second: 0x2033,
  29237. secondtonechinese: 0x02CA,
  29238. section: 0x00A7,
  29239. seenarabic: 0x0633,
  29240. seenfinalarabic: 0xFEB2,
  29241. seeninitialarabic: 0xFEB3,
  29242. seenmedialarabic: 0xFEB4,
  29243. segol: 0x05B6,
  29244. segol13: 0x05B6,
  29245. segol1f: 0x05B6,
  29246. segol2c: 0x05B6,
  29247. segolhebrew: 0x05B6,
  29248. segolnarrowhebrew: 0x05B6,
  29249. segolquarterhebrew: 0x05B6,
  29250. segoltahebrew: 0x0592,
  29251. segolwidehebrew: 0x05B6,
  29252. seharmenian: 0x057D,
  29253. sehiragana: 0x305B,
  29254. sekatakana: 0x30BB,
  29255. sekatakanahalfwidth: 0xFF7E,
  29256. semicolon: 0x003B,
  29257. semicolonarabic: 0x061B,
  29258. semicolonmonospace: 0xFF1B,
  29259. semicolonsmall: 0xFE54,
  29260. semivoicedmarkkana: 0x309C,
  29261. semivoicedmarkkanahalfwidth: 0xFF9F,
  29262. sentisquare: 0x3322,
  29263. sentosquare: 0x3323,
  29264. seven: 0x0037,
  29265. sevenarabic: 0x0667,
  29266. sevenbengali: 0x09ED,
  29267. sevencircle: 0x2466,
  29268. sevencircleinversesansserif: 0x2790,
  29269. sevendeva: 0x096D,
  29270. seveneighths: 0x215E,
  29271. sevengujarati: 0x0AED,
  29272. sevengurmukhi: 0x0A6D,
  29273. sevenhackarabic: 0x0667,
  29274. sevenhangzhou: 0x3027,
  29275. sevenideographicparen: 0x3226,
  29276. seveninferior: 0x2087,
  29277. sevenmonospace: 0xFF17,
  29278. sevenoldstyle: 0xF737,
  29279. sevenparen: 0x247A,
  29280. sevenperiod: 0x248E,
  29281. sevenpersian: 0x06F7,
  29282. sevenroman: 0x2176,
  29283. sevensuperior: 0x2077,
  29284. seventeencircle: 0x2470,
  29285. seventeenparen: 0x2484,
  29286. seventeenperiod: 0x2498,
  29287. seventhai: 0x0E57,
  29288. sfthyphen: 0x00AD,
  29289. shaarmenian: 0x0577,
  29290. shabengali: 0x09B6,
  29291. shacyrillic: 0x0448,
  29292. shaddaarabic: 0x0651,
  29293. shaddadammaarabic: 0xFC61,
  29294. shaddadammatanarabic: 0xFC5E,
  29295. shaddafathaarabic: 0xFC60,
  29296. shaddakasraarabic: 0xFC62,
  29297. shaddakasratanarabic: 0xFC5F,
  29298. shade: 0x2592,
  29299. shadedark: 0x2593,
  29300. shadelight: 0x2591,
  29301. shademedium: 0x2592,
  29302. shadeva: 0x0936,
  29303. shagujarati: 0x0AB6,
  29304. shagurmukhi: 0x0A36,
  29305. shalshelethebrew: 0x0593,
  29306. shbopomofo: 0x3115,
  29307. shchacyrillic: 0x0449,
  29308. sheenarabic: 0x0634,
  29309. sheenfinalarabic: 0xFEB6,
  29310. sheeninitialarabic: 0xFEB7,
  29311. sheenmedialarabic: 0xFEB8,
  29312. sheicoptic: 0x03E3,
  29313. sheqel: 0x20AA,
  29314. sheqelhebrew: 0x20AA,
  29315. sheva: 0x05B0,
  29316. sheva115: 0x05B0,
  29317. sheva15: 0x05B0,
  29318. sheva22: 0x05B0,
  29319. sheva2e: 0x05B0,
  29320. shevahebrew: 0x05B0,
  29321. shevanarrowhebrew: 0x05B0,
  29322. shevaquarterhebrew: 0x05B0,
  29323. shevawidehebrew: 0x05B0,
  29324. shhacyrillic: 0x04BB,
  29325. shimacoptic: 0x03ED,
  29326. shin: 0x05E9,
  29327. shindagesh: 0xFB49,
  29328. shindageshhebrew: 0xFB49,
  29329. shindageshshindot: 0xFB2C,
  29330. shindageshshindothebrew: 0xFB2C,
  29331. shindageshsindot: 0xFB2D,
  29332. shindageshsindothebrew: 0xFB2D,
  29333. shindothebrew: 0x05C1,
  29334. shinhebrew: 0x05E9,
  29335. shinshindot: 0xFB2A,
  29336. shinshindothebrew: 0xFB2A,
  29337. shinsindot: 0xFB2B,
  29338. shinsindothebrew: 0xFB2B,
  29339. shook: 0x0282,
  29340. sigma: 0x03C3,
  29341. sigma1: 0x03C2,
  29342. sigmafinal: 0x03C2,
  29343. sigmalunatesymbolgreek: 0x03F2,
  29344. sihiragana: 0x3057,
  29345. sikatakana: 0x30B7,
  29346. sikatakanahalfwidth: 0xFF7C,
  29347. siluqhebrew: 0x05BD,
  29348. siluqlefthebrew: 0x05BD,
  29349. similar: 0x223C,
  29350. sindothebrew: 0x05C2,
  29351. siosacirclekorean: 0x3274,
  29352. siosaparenkorean: 0x3214,
  29353. sioscieuckorean: 0x317E,
  29354. sioscirclekorean: 0x3266,
  29355. sioskiyeokkorean: 0x317A,
  29356. sioskorean: 0x3145,
  29357. siosnieunkorean: 0x317B,
  29358. siosparenkorean: 0x3206,
  29359. siospieupkorean: 0x317D,
  29360. siostikeutkorean: 0x317C,
  29361. six: 0x0036,
  29362. sixarabic: 0x0666,
  29363. sixbengali: 0x09EC,
  29364. sixcircle: 0x2465,
  29365. sixcircleinversesansserif: 0x278F,
  29366. sixdeva: 0x096C,
  29367. sixgujarati: 0x0AEC,
  29368. sixgurmukhi: 0x0A6C,
  29369. sixhackarabic: 0x0666,
  29370. sixhangzhou: 0x3026,
  29371. sixideographicparen: 0x3225,
  29372. sixinferior: 0x2086,
  29373. sixmonospace: 0xFF16,
  29374. sixoldstyle: 0xF736,
  29375. sixparen: 0x2479,
  29376. sixperiod: 0x248D,
  29377. sixpersian: 0x06F6,
  29378. sixroman: 0x2175,
  29379. sixsuperior: 0x2076,
  29380. sixteencircle: 0x246F,
  29381. sixteencurrencydenominatorbengali: 0x09F9,
  29382. sixteenparen: 0x2483,
  29383. sixteenperiod: 0x2497,
  29384. sixthai: 0x0E56,
  29385. slash: 0x002F,
  29386. slashmonospace: 0xFF0F,
  29387. slong: 0x017F,
  29388. slongdotaccent: 0x1E9B,
  29389. smileface: 0x263A,
  29390. smonospace: 0xFF53,
  29391. sofpasuqhebrew: 0x05C3,
  29392. softhyphen: 0x00AD,
  29393. softsigncyrillic: 0x044C,
  29394. sohiragana: 0x305D,
  29395. sokatakana: 0x30BD,
  29396. sokatakanahalfwidth: 0xFF7F,
  29397. soliduslongoverlaycmb: 0x0338,
  29398. solidusshortoverlaycmb: 0x0337,
  29399. sorusithai: 0x0E29,
  29400. sosalathai: 0x0E28,
  29401. sosothai: 0x0E0B,
  29402. sosuathai: 0x0E2A,
  29403. space: 0x0020,
  29404. spacehackarabic: 0x0020,
  29405. spade: 0x2660,
  29406. spadesuitblack: 0x2660,
  29407. spadesuitwhite: 0x2664,
  29408. sparen: 0x24AE,
  29409. squarebelowcmb: 0x033B,
  29410. squarecc: 0x33C4,
  29411. squarecm: 0x339D,
  29412. squarediagonalcrosshatchfill: 0x25A9,
  29413. squarehorizontalfill: 0x25A4,
  29414. squarekg: 0x338F,
  29415. squarekm: 0x339E,
  29416. squarekmcapital: 0x33CE,
  29417. squareln: 0x33D1,
  29418. squarelog: 0x33D2,
  29419. squaremg: 0x338E,
  29420. squaremil: 0x33D5,
  29421. squaremm: 0x339C,
  29422. squaremsquared: 0x33A1,
  29423. squareorthogonalcrosshatchfill: 0x25A6,
  29424. squareupperlefttolowerrightfill: 0x25A7,
  29425. squareupperrighttolowerleftfill: 0x25A8,
  29426. squareverticalfill: 0x25A5,
  29427. squarewhitewithsmallblack: 0x25A3,
  29428. srsquare: 0x33DB,
  29429. ssabengali: 0x09B7,
  29430. ssadeva: 0x0937,
  29431. ssagujarati: 0x0AB7,
  29432. ssangcieuckorean: 0x3149,
  29433. ssanghieuhkorean: 0x3185,
  29434. ssangieungkorean: 0x3180,
  29435. ssangkiyeokkorean: 0x3132,
  29436. ssangnieunkorean: 0x3165,
  29437. ssangpieupkorean: 0x3143,
  29438. ssangsioskorean: 0x3146,
  29439. ssangtikeutkorean: 0x3138,
  29440. ssuperior: 0xF6F2,
  29441. sterling: 0x00A3,
  29442. sterlingmonospace: 0xFFE1,
  29443. strokelongoverlaycmb: 0x0336,
  29444. strokeshortoverlaycmb: 0x0335,
  29445. subset: 0x2282,
  29446. subsetnotequal: 0x228A,
  29447. subsetorequal: 0x2286,
  29448. succeeds: 0x227B,
  29449. suchthat: 0x220B,
  29450. suhiragana: 0x3059,
  29451. sukatakana: 0x30B9,
  29452. sukatakanahalfwidth: 0xFF7D,
  29453. sukunarabic: 0x0652,
  29454. summation: 0x2211,
  29455. sun: 0x263C,
  29456. superset: 0x2283,
  29457. supersetnotequal: 0x228B,
  29458. supersetorequal: 0x2287,
  29459. svsquare: 0x33DC,
  29460. syouwaerasquare: 0x337C,
  29461. t: 0x0074,
  29462. tabengali: 0x09A4,
  29463. tackdown: 0x22A4,
  29464. tackleft: 0x22A3,
  29465. tadeva: 0x0924,
  29466. tagujarati: 0x0AA4,
  29467. tagurmukhi: 0x0A24,
  29468. taharabic: 0x0637,
  29469. tahfinalarabic: 0xFEC2,
  29470. tahinitialarabic: 0xFEC3,
  29471. tahiragana: 0x305F,
  29472. tahmedialarabic: 0xFEC4,
  29473. taisyouerasquare: 0x337D,
  29474. takatakana: 0x30BF,
  29475. takatakanahalfwidth: 0xFF80,
  29476. tatweelarabic: 0x0640,
  29477. tau: 0x03C4,
  29478. tav: 0x05EA,
  29479. tavdages: 0xFB4A,
  29480. tavdagesh: 0xFB4A,
  29481. tavdageshhebrew: 0xFB4A,
  29482. tavhebrew: 0x05EA,
  29483. tbar: 0x0167,
  29484. tbopomofo: 0x310A,
  29485. tcaron: 0x0165,
  29486. tccurl: 0x02A8,
  29487. tcedilla: 0x0163,
  29488. tcheharabic: 0x0686,
  29489. tchehfinalarabic: 0xFB7B,
  29490. tchehinitialarabic: 0xFB7C,
  29491. tchehmedialarabic: 0xFB7D,
  29492. tcircle: 0x24E3,
  29493. tcircumflexbelow: 0x1E71,
  29494. tcommaaccent: 0x0163,
  29495. tdieresis: 0x1E97,
  29496. tdotaccent: 0x1E6B,
  29497. tdotbelow: 0x1E6D,
  29498. tecyrillic: 0x0442,
  29499. tedescendercyrillic: 0x04AD,
  29500. teharabic: 0x062A,
  29501. tehfinalarabic: 0xFE96,
  29502. tehhahinitialarabic: 0xFCA2,
  29503. tehhahisolatedarabic: 0xFC0C,
  29504. tehinitialarabic: 0xFE97,
  29505. tehiragana: 0x3066,
  29506. tehjeeminitialarabic: 0xFCA1,
  29507. tehjeemisolatedarabic: 0xFC0B,
  29508. tehmarbutaarabic: 0x0629,
  29509. tehmarbutafinalarabic: 0xFE94,
  29510. tehmedialarabic: 0xFE98,
  29511. tehmeeminitialarabic: 0xFCA4,
  29512. tehmeemisolatedarabic: 0xFC0E,
  29513. tehnoonfinalarabic: 0xFC73,
  29514. tekatakana: 0x30C6,
  29515. tekatakanahalfwidth: 0xFF83,
  29516. telephone: 0x2121,
  29517. telephoneblack: 0x260E,
  29518. telishagedolahebrew: 0x05A0,
  29519. telishaqetanahebrew: 0x05A9,
  29520. tencircle: 0x2469,
  29521. tenideographicparen: 0x3229,
  29522. tenparen: 0x247D,
  29523. tenperiod: 0x2491,
  29524. tenroman: 0x2179,
  29525. tesh: 0x02A7,
  29526. tet: 0x05D8,
  29527. tetdagesh: 0xFB38,
  29528. tetdageshhebrew: 0xFB38,
  29529. tethebrew: 0x05D8,
  29530. tetsecyrillic: 0x04B5,
  29531. tevirhebrew: 0x059B,
  29532. tevirlefthebrew: 0x059B,
  29533. thabengali: 0x09A5,
  29534. thadeva: 0x0925,
  29535. thagujarati: 0x0AA5,
  29536. thagurmukhi: 0x0A25,
  29537. thalarabic: 0x0630,
  29538. thalfinalarabic: 0xFEAC,
  29539. thanthakhatlowleftthai: 0xF898,
  29540. thanthakhatlowrightthai: 0xF897,
  29541. thanthakhatthai: 0x0E4C,
  29542. thanthakhatupperleftthai: 0xF896,
  29543. theharabic: 0x062B,
  29544. thehfinalarabic: 0xFE9A,
  29545. thehinitialarabic: 0xFE9B,
  29546. thehmedialarabic: 0xFE9C,
  29547. thereexists: 0x2203,
  29548. therefore: 0x2234,
  29549. theta: 0x03B8,
  29550. theta1: 0x03D1,
  29551. thetasymbolgreek: 0x03D1,
  29552. thieuthacirclekorean: 0x3279,
  29553. thieuthaparenkorean: 0x3219,
  29554. thieuthcirclekorean: 0x326B,
  29555. thieuthkorean: 0x314C,
  29556. thieuthparenkorean: 0x320B,
  29557. thirteencircle: 0x246C,
  29558. thirteenparen: 0x2480,
  29559. thirteenperiod: 0x2494,
  29560. thonangmonthothai: 0x0E11,
  29561. thook: 0x01AD,
  29562. thophuthaothai: 0x0E12,
  29563. thorn: 0x00FE,
  29564. thothahanthai: 0x0E17,
  29565. thothanthai: 0x0E10,
  29566. thothongthai: 0x0E18,
  29567. thothungthai: 0x0E16,
  29568. thousandcyrillic: 0x0482,
  29569. thousandsseparatorarabic: 0x066C,
  29570. thousandsseparatorpersian: 0x066C,
  29571. three: 0x0033,
  29572. threearabic: 0x0663,
  29573. threebengali: 0x09E9,
  29574. threecircle: 0x2462,
  29575. threecircleinversesansserif: 0x278C,
  29576. threedeva: 0x0969,
  29577. threeeighths: 0x215C,
  29578. threegujarati: 0x0AE9,
  29579. threegurmukhi: 0x0A69,
  29580. threehackarabic: 0x0663,
  29581. threehangzhou: 0x3023,
  29582. threeideographicparen: 0x3222,
  29583. threeinferior: 0x2083,
  29584. threemonospace: 0xFF13,
  29585. threenumeratorbengali: 0x09F6,
  29586. threeoldstyle: 0xF733,
  29587. threeparen: 0x2476,
  29588. threeperiod: 0x248A,
  29589. threepersian: 0x06F3,
  29590. threequarters: 0x00BE,
  29591. threequartersemdash: 0xF6DE,
  29592. threeroman: 0x2172,
  29593. threesuperior: 0x00B3,
  29594. threethai: 0x0E53,
  29595. thzsquare: 0x3394,
  29596. tihiragana: 0x3061,
  29597. tikatakana: 0x30C1,
  29598. tikatakanahalfwidth: 0xFF81,
  29599. tikeutacirclekorean: 0x3270,
  29600. tikeutaparenkorean: 0x3210,
  29601. tikeutcirclekorean: 0x3262,
  29602. tikeutkorean: 0x3137,
  29603. tikeutparenkorean: 0x3202,
  29604. tilde: 0x02DC,
  29605. tildebelowcmb: 0x0330,
  29606. tildecmb: 0x0303,
  29607. tildecomb: 0x0303,
  29608. tildedoublecmb: 0x0360,
  29609. tildeoperator: 0x223C,
  29610. tildeoverlaycmb: 0x0334,
  29611. tildeverticalcmb: 0x033E,
  29612. timescircle: 0x2297,
  29613. tipehahebrew: 0x0596,
  29614. tipehalefthebrew: 0x0596,
  29615. tippigurmukhi: 0x0A70,
  29616. titlocyrilliccmb: 0x0483,
  29617. tiwnarmenian: 0x057F,
  29618. tlinebelow: 0x1E6F,
  29619. tmonospace: 0xFF54,
  29620. toarmenian: 0x0569,
  29621. tohiragana: 0x3068,
  29622. tokatakana: 0x30C8,
  29623. tokatakanahalfwidth: 0xFF84,
  29624. tonebarextrahighmod: 0x02E5,
  29625. tonebarextralowmod: 0x02E9,
  29626. tonebarhighmod: 0x02E6,
  29627. tonebarlowmod: 0x02E8,
  29628. tonebarmidmod: 0x02E7,
  29629. tonefive: 0x01BD,
  29630. tonesix: 0x0185,
  29631. tonetwo: 0x01A8,
  29632. tonos: 0x0384,
  29633. tonsquare: 0x3327,
  29634. topatakthai: 0x0E0F,
  29635. tortoiseshellbracketleft: 0x3014,
  29636. tortoiseshellbracketleftsmall: 0xFE5D,
  29637. tortoiseshellbracketleftvertical: 0xFE39,
  29638. tortoiseshellbracketright: 0x3015,
  29639. tortoiseshellbracketrightsmall: 0xFE5E,
  29640. tortoiseshellbracketrightvertical: 0xFE3A,
  29641. totaothai: 0x0E15,
  29642. tpalatalhook: 0x01AB,
  29643. tparen: 0x24AF,
  29644. trademark: 0x2122,
  29645. trademarksans: 0xF8EA,
  29646. trademarkserif: 0xF6DB,
  29647. tretroflexhook: 0x0288,
  29648. triagdn: 0x25BC,
  29649. triaglf: 0x25C4,
  29650. triagrt: 0x25BA,
  29651. triagup: 0x25B2,
  29652. ts: 0x02A6,
  29653. tsadi: 0x05E6,
  29654. tsadidagesh: 0xFB46,
  29655. tsadidageshhebrew: 0xFB46,
  29656. tsadihebrew: 0x05E6,
  29657. tsecyrillic: 0x0446,
  29658. tsere: 0x05B5,
  29659. tsere12: 0x05B5,
  29660. tsere1e: 0x05B5,
  29661. tsere2b: 0x05B5,
  29662. tserehebrew: 0x05B5,
  29663. tserenarrowhebrew: 0x05B5,
  29664. tserequarterhebrew: 0x05B5,
  29665. tserewidehebrew: 0x05B5,
  29666. tshecyrillic: 0x045B,
  29667. tsuperior: 0xF6F3,
  29668. ttabengali: 0x099F,
  29669. ttadeva: 0x091F,
  29670. ttagujarati: 0x0A9F,
  29671. ttagurmukhi: 0x0A1F,
  29672. tteharabic: 0x0679,
  29673. ttehfinalarabic: 0xFB67,
  29674. ttehinitialarabic: 0xFB68,
  29675. ttehmedialarabic: 0xFB69,
  29676. tthabengali: 0x09A0,
  29677. tthadeva: 0x0920,
  29678. tthagujarati: 0x0AA0,
  29679. tthagurmukhi: 0x0A20,
  29680. tturned: 0x0287,
  29681. tuhiragana: 0x3064,
  29682. tukatakana: 0x30C4,
  29683. tukatakanahalfwidth: 0xFF82,
  29684. tusmallhiragana: 0x3063,
  29685. tusmallkatakana: 0x30C3,
  29686. tusmallkatakanahalfwidth: 0xFF6F,
  29687. twelvecircle: 0x246B,
  29688. twelveparen: 0x247F,
  29689. twelveperiod: 0x2493,
  29690. twelveroman: 0x217B,
  29691. twentycircle: 0x2473,
  29692. twentyhangzhou: 0x5344,
  29693. twentyparen: 0x2487,
  29694. twentyperiod: 0x249B,
  29695. two: 0x0032,
  29696. twoarabic: 0x0662,
  29697. twobengali: 0x09E8,
  29698. twocircle: 0x2461,
  29699. twocircleinversesansserif: 0x278B,
  29700. twodeva: 0x0968,
  29701. twodotenleader: 0x2025,
  29702. twodotleader: 0x2025,
  29703. twodotleadervertical: 0xFE30,
  29704. twogujarati: 0x0AE8,
  29705. twogurmukhi: 0x0A68,
  29706. twohackarabic: 0x0662,
  29707. twohangzhou: 0x3022,
  29708. twoideographicparen: 0x3221,
  29709. twoinferior: 0x2082,
  29710. twomonospace: 0xFF12,
  29711. twonumeratorbengali: 0x09F5,
  29712. twooldstyle: 0xF732,
  29713. twoparen: 0x2475,
  29714. twoperiod: 0x2489,
  29715. twopersian: 0x06F2,
  29716. tworoman: 0x2171,
  29717. twostroke: 0x01BB,
  29718. twosuperior: 0x00B2,
  29719. twothai: 0x0E52,
  29720. twothirds: 0x2154,
  29721. u: 0x0075,
  29722. uacute: 0x00FA,
  29723. ubar: 0x0289,
  29724. ubengali: 0x0989,
  29725. ubopomofo: 0x3128,
  29726. ubreve: 0x016D,
  29727. ucaron: 0x01D4,
  29728. ucircle: 0x24E4,
  29729. ucircumflex: 0x00FB,
  29730. ucircumflexbelow: 0x1E77,
  29731. ucyrillic: 0x0443,
  29732. udattadeva: 0x0951,
  29733. udblacute: 0x0171,
  29734. udblgrave: 0x0215,
  29735. udeva: 0x0909,
  29736. udieresis: 0x00FC,
  29737. udieresisacute: 0x01D8,
  29738. udieresisbelow: 0x1E73,
  29739. udieresiscaron: 0x01DA,
  29740. udieresiscyrillic: 0x04F1,
  29741. udieresisgrave: 0x01DC,
  29742. udieresismacron: 0x01D6,
  29743. udotbelow: 0x1EE5,
  29744. ugrave: 0x00F9,
  29745. ugujarati: 0x0A89,
  29746. ugurmukhi: 0x0A09,
  29747. uhiragana: 0x3046,
  29748. uhookabove: 0x1EE7,
  29749. uhorn: 0x01B0,
  29750. uhornacute: 0x1EE9,
  29751. uhorndotbelow: 0x1EF1,
  29752. uhorngrave: 0x1EEB,
  29753. uhornhookabove: 0x1EED,
  29754. uhorntilde: 0x1EEF,
  29755. uhungarumlaut: 0x0171,
  29756. uhungarumlautcyrillic: 0x04F3,
  29757. uinvertedbreve: 0x0217,
  29758. ukatakana: 0x30A6,
  29759. ukatakanahalfwidth: 0xFF73,
  29760. ukcyrillic: 0x0479,
  29761. ukorean: 0x315C,
  29762. umacron: 0x016B,
  29763. umacroncyrillic: 0x04EF,
  29764. umacrondieresis: 0x1E7B,
  29765. umatragurmukhi: 0x0A41,
  29766. umonospace: 0xFF55,
  29767. underscore: 0x005F,
  29768. underscoredbl: 0x2017,
  29769. underscoremonospace: 0xFF3F,
  29770. underscorevertical: 0xFE33,
  29771. underscorewavy: 0xFE4F,
  29772. union: 0x222A,
  29773. universal: 0x2200,
  29774. uogonek: 0x0173,
  29775. uparen: 0x24B0,
  29776. upblock: 0x2580,
  29777. upperdothebrew: 0x05C4,
  29778. upsilon: 0x03C5,
  29779. upsilondieresis: 0x03CB,
  29780. upsilondieresistonos: 0x03B0,
  29781. upsilonlatin: 0x028A,
  29782. upsilontonos: 0x03CD,
  29783. uptackbelowcmb: 0x031D,
  29784. uptackmod: 0x02D4,
  29785. uragurmukhi: 0x0A73,
  29786. uring: 0x016F,
  29787. ushortcyrillic: 0x045E,
  29788. usmallhiragana: 0x3045,
  29789. usmallkatakana: 0x30A5,
  29790. usmallkatakanahalfwidth: 0xFF69,
  29791. ustraightcyrillic: 0x04AF,
  29792. ustraightstrokecyrillic: 0x04B1,
  29793. utilde: 0x0169,
  29794. utildeacute: 0x1E79,
  29795. utildebelow: 0x1E75,
  29796. uubengali: 0x098A,
  29797. uudeva: 0x090A,
  29798. uugujarati: 0x0A8A,
  29799. uugurmukhi: 0x0A0A,
  29800. uumatragurmukhi: 0x0A42,
  29801. uuvowelsignbengali: 0x09C2,
  29802. uuvowelsigndeva: 0x0942,
  29803. uuvowelsigngujarati: 0x0AC2,
  29804. uvowelsignbengali: 0x09C1,
  29805. uvowelsigndeva: 0x0941,
  29806. uvowelsigngujarati: 0x0AC1,
  29807. v: 0x0076,
  29808. vadeva: 0x0935,
  29809. vagujarati: 0x0AB5,
  29810. vagurmukhi: 0x0A35,
  29811. vakatakana: 0x30F7,
  29812. vav: 0x05D5,
  29813. vavdagesh: 0xFB35,
  29814. vavdagesh65: 0xFB35,
  29815. vavdageshhebrew: 0xFB35,
  29816. vavhebrew: 0x05D5,
  29817. vavholam: 0xFB4B,
  29818. vavholamhebrew: 0xFB4B,
  29819. vavvavhebrew: 0x05F0,
  29820. vavyodhebrew: 0x05F1,
  29821. vcircle: 0x24E5,
  29822. vdotbelow: 0x1E7F,
  29823. vecyrillic: 0x0432,
  29824. veharabic: 0x06A4,
  29825. vehfinalarabic: 0xFB6B,
  29826. vehinitialarabic: 0xFB6C,
  29827. vehmedialarabic: 0xFB6D,
  29828. vekatakana: 0x30F9,
  29829. venus: 0x2640,
  29830. verticalbar: 0x007C,
  29831. verticallineabovecmb: 0x030D,
  29832. verticallinebelowcmb: 0x0329,
  29833. verticallinelowmod: 0x02CC,
  29834. verticallinemod: 0x02C8,
  29835. vewarmenian: 0x057E,
  29836. vhook: 0x028B,
  29837. vikatakana: 0x30F8,
  29838. viramabengali: 0x09CD,
  29839. viramadeva: 0x094D,
  29840. viramagujarati: 0x0ACD,
  29841. visargabengali: 0x0983,
  29842. visargadeva: 0x0903,
  29843. visargagujarati: 0x0A83,
  29844. vmonospace: 0xFF56,
  29845. voarmenian: 0x0578,
  29846. voicediterationhiragana: 0x309E,
  29847. voicediterationkatakana: 0x30FE,
  29848. voicedmarkkana: 0x309B,
  29849. voicedmarkkanahalfwidth: 0xFF9E,
  29850. vokatakana: 0x30FA,
  29851. vparen: 0x24B1,
  29852. vtilde: 0x1E7D,
  29853. vturned: 0x028C,
  29854. vuhiragana: 0x3094,
  29855. vukatakana: 0x30F4,
  29856. w: 0x0077,
  29857. wacute: 0x1E83,
  29858. waekorean: 0x3159,
  29859. wahiragana: 0x308F,
  29860. wakatakana: 0x30EF,
  29861. wakatakanahalfwidth: 0xFF9C,
  29862. wakorean: 0x3158,
  29863. wasmallhiragana: 0x308E,
  29864. wasmallkatakana: 0x30EE,
  29865. wattosquare: 0x3357,
  29866. wavedash: 0x301C,
  29867. wavyunderscorevertical: 0xFE34,
  29868. wawarabic: 0x0648,
  29869. wawfinalarabic: 0xFEEE,
  29870. wawhamzaabovearabic: 0x0624,
  29871. wawhamzaabovefinalarabic: 0xFE86,
  29872. wbsquare: 0x33DD,
  29873. wcircle: 0x24E6,
  29874. wcircumflex: 0x0175,
  29875. wdieresis: 0x1E85,
  29876. wdotaccent: 0x1E87,
  29877. wdotbelow: 0x1E89,
  29878. wehiragana: 0x3091,
  29879. weierstrass: 0x2118,
  29880. wekatakana: 0x30F1,
  29881. wekorean: 0x315E,
  29882. weokorean: 0x315D,
  29883. wgrave: 0x1E81,
  29884. whitebullet: 0x25E6,
  29885. whitecircle: 0x25CB,
  29886. whitecircleinverse: 0x25D9,
  29887. whitecornerbracketleft: 0x300E,
  29888. whitecornerbracketleftvertical: 0xFE43,
  29889. whitecornerbracketright: 0x300F,
  29890. whitecornerbracketrightvertical: 0xFE44,
  29891. whitediamond: 0x25C7,
  29892. whitediamondcontainingblacksmalldiamond: 0x25C8,
  29893. whitedownpointingsmalltriangle: 0x25BF,
  29894. whitedownpointingtriangle: 0x25BD,
  29895. whiteleftpointingsmalltriangle: 0x25C3,
  29896. whiteleftpointingtriangle: 0x25C1,
  29897. whitelenticularbracketleft: 0x3016,
  29898. whitelenticularbracketright: 0x3017,
  29899. whiterightpointingsmalltriangle: 0x25B9,
  29900. whiterightpointingtriangle: 0x25B7,
  29901. whitesmallsquare: 0x25AB,
  29902. whitesmilingface: 0x263A,
  29903. whitesquare: 0x25A1,
  29904. whitestar: 0x2606,
  29905. whitetelephone: 0x260F,
  29906. whitetortoiseshellbracketleft: 0x3018,
  29907. whitetortoiseshellbracketright: 0x3019,
  29908. whiteuppointingsmalltriangle: 0x25B5,
  29909. whiteuppointingtriangle: 0x25B3,
  29910. wihiragana: 0x3090,
  29911. wikatakana: 0x30F0,
  29912. wikorean: 0x315F,
  29913. wmonospace: 0xFF57,
  29914. wohiragana: 0x3092,
  29915. wokatakana: 0x30F2,
  29916. wokatakanahalfwidth: 0xFF66,
  29917. won: 0x20A9,
  29918. wonmonospace: 0xFFE6,
  29919. wowaenthai: 0x0E27,
  29920. wparen: 0x24B2,
  29921. wring: 0x1E98,
  29922. wsuperior: 0x02B7,
  29923. wturned: 0x028D,
  29924. wynn: 0x01BF,
  29925. x: 0x0078,
  29926. xabovecmb: 0x033D,
  29927. xbopomofo: 0x3112,
  29928. xcircle: 0x24E7,
  29929. xdieresis: 0x1E8D,
  29930. xdotaccent: 0x1E8B,
  29931. xeharmenian: 0x056D,
  29932. xi: 0x03BE,
  29933. xmonospace: 0xFF58,
  29934. xparen: 0x24B3,
  29935. xsuperior: 0x02E3,
  29936. y: 0x0079,
  29937. yaadosquare: 0x334E,
  29938. yabengali: 0x09AF,
  29939. yacute: 0x00FD,
  29940. yadeva: 0x092F,
  29941. yaekorean: 0x3152,
  29942. yagujarati: 0x0AAF,
  29943. yagurmukhi: 0x0A2F,
  29944. yahiragana: 0x3084,
  29945. yakatakana: 0x30E4,
  29946. yakatakanahalfwidth: 0xFF94,
  29947. yakorean: 0x3151,
  29948. yamakkanthai: 0x0E4E,
  29949. yasmallhiragana: 0x3083,
  29950. yasmallkatakana: 0x30E3,
  29951. yasmallkatakanahalfwidth: 0xFF6C,
  29952. yatcyrillic: 0x0463,
  29953. ycircle: 0x24E8,
  29954. ycircumflex: 0x0177,
  29955. ydieresis: 0x00FF,
  29956. ydotaccent: 0x1E8F,
  29957. ydotbelow: 0x1EF5,
  29958. yeharabic: 0x064A,
  29959. yehbarreearabic: 0x06D2,
  29960. yehbarreefinalarabic: 0xFBAF,
  29961. yehfinalarabic: 0xFEF2,
  29962. yehhamzaabovearabic: 0x0626,
  29963. yehhamzaabovefinalarabic: 0xFE8A,
  29964. yehhamzaaboveinitialarabic: 0xFE8B,
  29965. yehhamzaabovemedialarabic: 0xFE8C,
  29966. yehinitialarabic: 0xFEF3,
  29967. yehmedialarabic: 0xFEF4,
  29968. yehmeeminitialarabic: 0xFCDD,
  29969. yehmeemisolatedarabic: 0xFC58,
  29970. yehnoonfinalarabic: 0xFC94,
  29971. yehthreedotsbelowarabic: 0x06D1,
  29972. yekorean: 0x3156,
  29973. yen: 0x00A5,
  29974. yenmonospace: 0xFFE5,
  29975. yeokorean: 0x3155,
  29976. yeorinhieuhkorean: 0x3186,
  29977. yerahbenyomohebrew: 0x05AA,
  29978. yerahbenyomolefthebrew: 0x05AA,
  29979. yericyrillic: 0x044B,
  29980. yerudieresiscyrillic: 0x04F9,
  29981. yesieungkorean: 0x3181,
  29982. yesieungpansioskorean: 0x3183,
  29983. yesieungsioskorean: 0x3182,
  29984. yetivhebrew: 0x059A,
  29985. ygrave: 0x1EF3,
  29986. yhook: 0x01B4,
  29987. yhookabove: 0x1EF7,
  29988. yiarmenian: 0x0575,
  29989. yicyrillic: 0x0457,
  29990. yikorean: 0x3162,
  29991. yinyang: 0x262F,
  29992. yiwnarmenian: 0x0582,
  29993. ymonospace: 0xFF59,
  29994. yod: 0x05D9,
  29995. yoddagesh: 0xFB39,
  29996. yoddageshhebrew: 0xFB39,
  29997. yodhebrew: 0x05D9,
  29998. yodyodhebrew: 0x05F2,
  29999. yodyodpatahhebrew: 0xFB1F,
  30000. yohiragana: 0x3088,
  30001. yoikorean: 0x3189,
  30002. yokatakana: 0x30E8,
  30003. yokatakanahalfwidth: 0xFF96,
  30004. yokorean: 0x315B,
  30005. yosmallhiragana: 0x3087,
  30006. yosmallkatakana: 0x30E7,
  30007. yosmallkatakanahalfwidth: 0xFF6E,
  30008. yotgreek: 0x03F3,
  30009. yoyaekorean: 0x3188,
  30010. yoyakorean: 0x3187,
  30011. yoyakthai: 0x0E22,
  30012. yoyingthai: 0x0E0D,
  30013. yparen: 0x24B4,
  30014. ypogegrammeni: 0x037A,
  30015. ypogegrammenigreekcmb: 0x0345,
  30016. yr: 0x01A6,
  30017. yring: 0x1E99,
  30018. ysuperior: 0x02B8,
  30019. ytilde: 0x1EF9,
  30020. yturned: 0x028E,
  30021. yuhiragana: 0x3086,
  30022. yuikorean: 0x318C,
  30023. yukatakana: 0x30E6,
  30024. yukatakanahalfwidth: 0xFF95,
  30025. yukorean: 0x3160,
  30026. yusbigcyrillic: 0x046B,
  30027. yusbigiotifiedcyrillic: 0x046D,
  30028. yuslittlecyrillic: 0x0467,
  30029. yuslittleiotifiedcyrillic: 0x0469,
  30030. yusmallhiragana: 0x3085,
  30031. yusmallkatakana: 0x30E5,
  30032. yusmallkatakanahalfwidth: 0xFF6D,
  30033. yuyekorean: 0x318B,
  30034. yuyeokorean: 0x318A,
  30035. yyabengali: 0x09DF,
  30036. yyadeva: 0x095F,
  30037. z: 0x007A,
  30038. zaarmenian: 0x0566,
  30039. zacute: 0x017A,
  30040. zadeva: 0x095B,
  30041. zagurmukhi: 0x0A5B,
  30042. zaharabic: 0x0638,
  30043. zahfinalarabic: 0xFEC6,
  30044. zahinitialarabic: 0xFEC7,
  30045. zahiragana: 0x3056,
  30046. zahmedialarabic: 0xFEC8,
  30047. zainarabic: 0x0632,
  30048. zainfinalarabic: 0xFEB0,
  30049. zakatakana: 0x30B6,
  30050. zaqefgadolhebrew: 0x0595,
  30051. zaqefqatanhebrew: 0x0594,
  30052. zarqahebrew: 0x0598,
  30053. zayin: 0x05D6,
  30054. zayindagesh: 0xFB36,
  30055. zayindageshhebrew: 0xFB36,
  30056. zayinhebrew: 0x05D6,
  30057. zbopomofo: 0x3117,
  30058. zcaron: 0x017E,
  30059. zcircle: 0x24E9,
  30060. zcircumflex: 0x1E91,
  30061. zcurl: 0x0291,
  30062. zdot: 0x017C,
  30063. zdotaccent: 0x017C,
  30064. zdotbelow: 0x1E93,
  30065. zecyrillic: 0x0437,
  30066. zedescendercyrillic: 0x0499,
  30067. zedieresiscyrillic: 0x04DF,
  30068. zehiragana: 0x305C,
  30069. zekatakana: 0x30BC,
  30070. zero: 0x0030,
  30071. zeroarabic: 0x0660,
  30072. zerobengali: 0x09E6,
  30073. zerodeva: 0x0966,
  30074. zerogujarati: 0x0AE6,
  30075. zerogurmukhi: 0x0A66,
  30076. zerohackarabic: 0x0660,
  30077. zeroinferior: 0x2080,
  30078. zeromonospace: 0xFF10,
  30079. zerooldstyle: 0xF730,
  30080. zeropersian: 0x06F0,
  30081. zerosuperior: 0x2070,
  30082. zerothai: 0x0E50,
  30083. zerowidthjoiner: 0xFEFF,
  30084. zerowidthnonjoiner: 0x200C,
  30085. zerowidthspace: 0x200B,
  30086. zeta: 0x03B6,
  30087. zhbopomofo: 0x3113,
  30088. zhearmenian: 0x056A,
  30089. zhebrevecyrillic: 0x04C2,
  30090. zhecyrillic: 0x0436,
  30091. zhedescendercyrillic: 0x0497,
  30092. zhedieresiscyrillic: 0x04DD,
  30093. zihiragana: 0x3058,
  30094. zikatakana: 0x30B8,
  30095. zinorhebrew: 0x05AE,
  30096. zlinebelow: 0x1E95,
  30097. zmonospace: 0xFF5A,
  30098. zohiragana: 0x305E,
  30099. zokatakana: 0x30BE,
  30100. zparen: 0x24B5,
  30101. zretroflexhook: 0x0290,
  30102. zstroke: 0x01B6,
  30103. zuhiragana: 0x305A,
  30104. zukatakana: 0x30BA,
  30105. '.notdef': 0x0000
  30106. };
  30107. var DingbatsGlyphsUnicode = {
  30108. space: 0x0020,
  30109. a1: 0x2701,
  30110. a2: 0x2702,
  30111. a202: 0x2703,
  30112. a3: 0x2704,
  30113. a4: 0x260E,
  30114. a5: 0x2706,
  30115. a119: 0x2707,
  30116. a118: 0x2708,
  30117. a117: 0x2709,
  30118. a11: 0x261B,
  30119. a12: 0x261E,
  30120. a13: 0x270C,
  30121. a14: 0x270D,
  30122. a15: 0x270E,
  30123. a16: 0x270F,
  30124. a105: 0x2710,
  30125. a17: 0x2711,
  30126. a18: 0x2712,
  30127. a19: 0x2713,
  30128. a20: 0x2714,
  30129. a21: 0x2715,
  30130. a22: 0x2716,
  30131. a23: 0x2717,
  30132. a24: 0x2718,
  30133. a25: 0x2719,
  30134. a26: 0x271A,
  30135. a27: 0x271B,
  30136. a28: 0x271C,
  30137. a6: 0x271D,
  30138. a7: 0x271E,
  30139. a8: 0x271F,
  30140. a9: 0x2720,
  30141. a10: 0x2721,
  30142. a29: 0x2722,
  30143. a30: 0x2723,
  30144. a31: 0x2724,
  30145. a32: 0x2725,
  30146. a33: 0x2726,
  30147. a34: 0x2727,
  30148. a35: 0x2605,
  30149. a36: 0x2729,
  30150. a37: 0x272A,
  30151. a38: 0x272B,
  30152. a39: 0x272C,
  30153. a40: 0x272D,
  30154. a41: 0x272E,
  30155. a42: 0x272F,
  30156. a43: 0x2730,
  30157. a44: 0x2731,
  30158. a45: 0x2732,
  30159. a46: 0x2733,
  30160. a47: 0x2734,
  30161. a48: 0x2735,
  30162. a49: 0x2736,
  30163. a50: 0x2737,
  30164. a51: 0x2738,
  30165. a52: 0x2739,
  30166. a53: 0x273A,
  30167. a54: 0x273B,
  30168. a55: 0x273C,
  30169. a56: 0x273D,
  30170. a57: 0x273E,
  30171. a58: 0x273F,
  30172. a59: 0x2740,
  30173. a60: 0x2741,
  30174. a61: 0x2742,
  30175. a62: 0x2743,
  30176. a63: 0x2744,
  30177. a64: 0x2745,
  30178. a65: 0x2746,
  30179. a66: 0x2747,
  30180. a67: 0x2748,
  30181. a68: 0x2749,
  30182. a69: 0x274A,
  30183. a70: 0x274B,
  30184. a71: 0x25CF,
  30185. a72: 0x274D,
  30186. a73: 0x25A0,
  30187. a74: 0x274F,
  30188. a203: 0x2750,
  30189. a75: 0x2751,
  30190. a204: 0x2752,
  30191. a76: 0x25B2,
  30192. a77: 0x25BC,
  30193. a78: 0x25C6,
  30194. a79: 0x2756,
  30195. a81: 0x25D7,
  30196. a82: 0x2758,
  30197. a83: 0x2759,
  30198. a84: 0x275A,
  30199. a97: 0x275B,
  30200. a98: 0x275C,
  30201. a99: 0x275D,
  30202. a100: 0x275E,
  30203. a101: 0x2761,
  30204. a102: 0x2762,
  30205. a103: 0x2763,
  30206. a104: 0x2764,
  30207. a106: 0x2765,
  30208. a107: 0x2766,
  30209. a108: 0x2767,
  30210. a112: 0x2663,
  30211. a111: 0x2666,
  30212. a110: 0x2665,
  30213. a109: 0x2660,
  30214. a120: 0x2460,
  30215. a121: 0x2461,
  30216. a122: 0x2462,
  30217. a123: 0x2463,
  30218. a124: 0x2464,
  30219. a125: 0x2465,
  30220. a126: 0x2466,
  30221. a127: 0x2467,
  30222. a128: 0x2468,
  30223. a129: 0x2469,
  30224. a130: 0x2776,
  30225. a131: 0x2777,
  30226. a132: 0x2778,
  30227. a133: 0x2779,
  30228. a134: 0x277A,
  30229. a135: 0x277B,
  30230. a136: 0x277C,
  30231. a137: 0x277D,
  30232. a138: 0x277E,
  30233. a139: 0x277F,
  30234. a140: 0x2780,
  30235. a141: 0x2781,
  30236. a142: 0x2782,
  30237. a143: 0x2783,
  30238. a144: 0x2784,
  30239. a145: 0x2785,
  30240. a146: 0x2786,
  30241. a147: 0x2787,
  30242. a148: 0x2788,
  30243. a149: 0x2789,
  30244. a150: 0x278A,
  30245. a151: 0x278B,
  30246. a152: 0x278C,
  30247. a153: 0x278D,
  30248. a154: 0x278E,
  30249. a155: 0x278F,
  30250. a156: 0x2790,
  30251. a157: 0x2791,
  30252. a158: 0x2792,
  30253. a159: 0x2793,
  30254. a160: 0x2794,
  30255. a161: 0x2192,
  30256. a163: 0x2194,
  30257. a164: 0x2195,
  30258. a196: 0x2798,
  30259. a165: 0x2799,
  30260. a192: 0x279A,
  30261. a166: 0x279B,
  30262. a167: 0x279C,
  30263. a168: 0x279D,
  30264. a169: 0x279E,
  30265. a170: 0x279F,
  30266. a171: 0x27A0,
  30267. a172: 0x27A1,
  30268. a173: 0x27A2,
  30269. a162: 0x27A3,
  30270. a174: 0x27A4,
  30271. a175: 0x27A5,
  30272. a176: 0x27A6,
  30273. a177: 0x27A7,
  30274. a178: 0x27A8,
  30275. a179: 0x27A9,
  30276. a193: 0x27AA,
  30277. a180: 0x27AB,
  30278. a199: 0x27AC,
  30279. a181: 0x27AD,
  30280. a200: 0x27AE,
  30281. a182: 0x27AF,
  30282. a201: 0x27B1,
  30283. a183: 0x27B2,
  30284. a184: 0x27B3,
  30285. a197: 0x27B4,
  30286. a185: 0x27B5,
  30287. a194: 0x27B6,
  30288. a198: 0x27B7,
  30289. a186: 0x27B8,
  30290. a195: 0x27B9,
  30291. a187: 0x27BA,
  30292. a188: 0x27BB,
  30293. a189: 0x27BC,
  30294. a190: 0x27BD,
  30295. a191: 0x27BE,
  30296. a89: 0x2768, // 0xF8D7
  30297. a90: 0x2769, // 0xF8D8
  30298. a93: 0x276A, // 0xF8D9
  30299. a94: 0x276B, // 0xF8DA
  30300. a91: 0x276C, // 0xF8DB
  30301. a92: 0x276D, // 0xF8DC
  30302. a205: 0x276E, // 0xF8DD
  30303. a85: 0x276F, // 0xF8DE
  30304. a206: 0x2770, // 0xF8DF
  30305. a86: 0x2771, // 0xF8E0
  30306. a87: 0x2772, // 0xF8E1
  30307. a88: 0x2773, // 0xF8E2
  30308. a95: 0x2774, // 0xF8E3
  30309. a96: 0x2775, // 0xF8E4
  30310. '.notdef': 0x0000
  30311. };
  30312. var PDFImage = (function PDFImageClosure() {
  30313. /**
  30314. * Decode the image in the main thread if it supported. Resovles the promise
  30315. * when the image data is ready.
  30316. */
  30317. function handleImageData(handler, xref, res, image) {
  30318. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  30319. // For natively supported jpegs send them to the main thread for decoding.
  30320. var dict = image.dict;
  30321. var colorSpace = dict.get('ColorSpace', 'CS');
  30322. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30323. var numComps = colorSpace.numComps;
  30324. var decodePromise = handler.sendWithPromise('JpegDecode',
  30325. [image.getIR(), numComps]);
  30326. return decodePromise.then(function (message) {
  30327. var data = message.data;
  30328. return new Stream(data, 0, data.length, image.dict);
  30329. });
  30330. } else {
  30331. return Promise.resolve(image);
  30332. }
  30333. }
  30334. /**
  30335. * Decode and clamp a value. The formula is different from the spec because we
  30336. * don't decode to float range [0,1], we decode it in the [0,max] range.
  30337. */
  30338. function decodeAndClamp(value, addend, coefficient, max) {
  30339. value = addend + value * coefficient;
  30340. // Clamp the value to the range
  30341. return (value < 0 ? 0 : (value > max ? max : value));
  30342. }
  30343. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  30344. this.image = image;
  30345. var dict = image.dict;
  30346. if (dict.has('Filter')) {
  30347. var filter = dict.get('Filter').name;
  30348. if (filter === 'JPXDecode') {
  30349. var jpxImage = new JpxImage();
  30350. jpxImage.parseImageProperties(image.stream);
  30351. image.stream.reset();
  30352. image.bitsPerComponent = jpxImage.bitsPerComponent;
  30353. image.numComps = jpxImage.componentsCount;
  30354. } else if (filter === 'JBIG2Decode') {
  30355. image.bitsPerComponent = 1;
  30356. image.numComps = 1;
  30357. }
  30358. }
  30359. // TODO cache rendered images?
  30360. this.width = dict.get('Width', 'W');
  30361. this.height = dict.get('Height', 'H');
  30362. if (this.width < 1 || this.height < 1) {
  30363. error('Invalid image width: ' + this.width + ' or height: ' +
  30364. this.height);
  30365. }
  30366. this.interpolate = dict.get('Interpolate', 'I') || false;
  30367. this.imageMask = dict.get('ImageMask', 'IM') || false;
  30368. this.matte = dict.get('Matte') || false;
  30369. var bitsPerComponent = image.bitsPerComponent;
  30370. if (!bitsPerComponent) {
  30371. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  30372. if (!bitsPerComponent) {
  30373. if (this.imageMask) {
  30374. bitsPerComponent = 1;
  30375. } else {
  30376. error('Bits per component missing in image: ' + this.imageMask);
  30377. }
  30378. }
  30379. }
  30380. this.bpc = bitsPerComponent;
  30381. if (!this.imageMask) {
  30382. var colorSpace = dict.get('ColorSpace', 'CS');
  30383. if (!colorSpace) {
  30384. info('JPX images (which do not require color spaces)');
  30385. switch (image.numComps) {
  30386. case 1:
  30387. colorSpace = Name.get('DeviceGray');
  30388. break;
  30389. case 3:
  30390. colorSpace = Name.get('DeviceRGB');
  30391. break;
  30392. case 4:
  30393. colorSpace = Name.get('DeviceCMYK');
  30394. break;
  30395. default:
  30396. error('JPX images with ' + this.numComps +
  30397. ' color components not supported.');
  30398. }
  30399. }
  30400. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30401. this.numComps = this.colorSpace.numComps;
  30402. }
  30403. this.decode = dict.get('Decode', 'D');
  30404. this.needsDecode = false;
  30405. if (this.decode &&
  30406. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  30407. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  30408. this.needsDecode = true;
  30409. // Do some preprocessing to avoid more math.
  30410. var max = (1 << bitsPerComponent) - 1;
  30411. this.decodeCoefficients = [];
  30412. this.decodeAddends = [];
  30413. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  30414. var dmin = this.decode[i];
  30415. var dmax = this.decode[i + 1];
  30416. this.decodeCoefficients[j] = dmax - dmin;
  30417. this.decodeAddends[j] = max * dmin;
  30418. }
  30419. }
  30420. if (smask) {
  30421. this.smask = new PDFImage(xref, res, smask, false);
  30422. } else if (mask) {
  30423. if (isStream(mask)) {
  30424. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  30425. } else {
  30426. // Color key mask (just an array).
  30427. this.mask = mask;
  30428. }
  30429. }
  30430. }
  30431. /**
  30432. * Handles processing of image data and returns the Promise that is resolved
  30433. * with a PDFImage when the image is ready to be used.
  30434. */
  30435. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  30436. res, image, inline) {
  30437. var imagePromise = handleImageData(handler, xref, res, image);
  30438. var smaskPromise;
  30439. var maskPromise;
  30440. var smask = image.dict.get('SMask');
  30441. var mask = image.dict.get('Mask');
  30442. if (smask) {
  30443. smaskPromise = handleImageData(handler, xref, res, smask);
  30444. maskPromise = Promise.resolve(null);
  30445. } else {
  30446. smaskPromise = Promise.resolve(null);
  30447. if (mask) {
  30448. if (isStream(mask)) {
  30449. maskPromise = handleImageData(handler, xref, res, mask);
  30450. } else if (isArray(mask)) {
  30451. maskPromise = Promise.resolve(mask);
  30452. } else {
  30453. warn('Unsupported mask format.');
  30454. maskPromise = Promise.resolve(null);
  30455. }
  30456. } else {
  30457. maskPromise = Promise.resolve(null);
  30458. }
  30459. }
  30460. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  30461. function(results) {
  30462. var imageData = results[0];
  30463. var smaskData = results[1];
  30464. var maskData = results[2];
  30465. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  30466. });
  30467. };
  30468. /**
  30469. * Resize an image using the nearest neighbor algorithm. Currently only
  30470. * supports one and three component images.
  30471. * @param {TypedArray} pixels The original image with one component.
  30472. * @param {Number} bpc Number of bits per component.
  30473. * @param {Number} components Number of color components, 1 or 3 is supported.
  30474. * @param {Number} w1 Original width.
  30475. * @param {Number} h1 Original height.
  30476. * @param {Number} w2 New width.
  30477. * @param {Number} h2 New height.
  30478. * @param {TypedArray} dest (Optional) The destination buffer.
  30479. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  30480. * @return {TypedArray} Resized image data.
  30481. */
  30482. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  30483. w1, h1, w2, h2, dest, alpha01) {
  30484. if (components !== 1 && components !== 3) {
  30485. error('Unsupported component count for resizing.');
  30486. }
  30487. var length = w2 * h2 * components;
  30488. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  30489. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30490. var xRatio = w1 / w2;
  30491. var yRatio = h1 / h2;
  30492. var i, j, py, newIndex = 0, oldIndex;
  30493. var xScaled = new Uint16Array(w2);
  30494. var w1Scanline = w1 * components;
  30495. if (alpha01 !== 1) {
  30496. alpha01 = 0;
  30497. }
  30498. for (j = 0; j < w2; j++) {
  30499. xScaled[j] = Math.floor(j * xRatio) * components;
  30500. }
  30501. if (components === 1) {
  30502. for (i = 0; i < h2; i++) {
  30503. py = Math.floor(i * yRatio) * w1Scanline;
  30504. for (j = 0; j < w2; j++) {
  30505. oldIndex = py + xScaled[j];
  30506. temp[newIndex++] = pixels[oldIndex];
  30507. }
  30508. }
  30509. } else if (components === 3) {
  30510. for (i = 0; i < h2; i++) {
  30511. py = Math.floor(i * yRatio) * w1Scanline;
  30512. for (j = 0; j < w2; j++) {
  30513. oldIndex = py + xScaled[j];
  30514. temp[newIndex++] = pixels[oldIndex++];
  30515. temp[newIndex++] = pixels[oldIndex++];
  30516. temp[newIndex++] = pixels[oldIndex++];
  30517. newIndex += alpha01;
  30518. }
  30519. }
  30520. }
  30521. return temp;
  30522. };
  30523. PDFImage.createMask =
  30524. function PDFImage_createMask(imgArray, width, height,
  30525. imageIsFromDecodeStream, inverseDecode) {
  30526. // |imgArray| might not contain full data for every pixel of the mask, so
  30527. // we need to distinguish between |computedLength| and |actualLength|.
  30528. // In particular, if inverseDecode is true, then the array we return must
  30529. // have a length of |computedLength|.
  30530. var computedLength = ((width + 7) >> 3) * height;
  30531. var actualLength = imgArray.byteLength;
  30532. var haveFullData = computedLength === actualLength;
  30533. var data, i;
  30534. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  30535. // imgArray came from a DecodeStream and its data is in an appropriate
  30536. // form, so we can just transfer it.
  30537. data = imgArray;
  30538. } else if (!inverseDecode) {
  30539. data = new Uint8Array(actualLength);
  30540. data.set(imgArray);
  30541. } else {
  30542. data = new Uint8Array(computedLength);
  30543. data.set(imgArray);
  30544. for (i = actualLength; i < computedLength; i++) {
  30545. data[i] = 0xff;
  30546. }
  30547. }
  30548. // If necessary, invert the original mask data (but not any extra we might
  30549. // have added above). It's safe to modify the array -- whether it's the
  30550. // original or a copy, we're about to transfer it anyway, so nothing else
  30551. // in this thread can be relying on its contents.
  30552. if (inverseDecode) {
  30553. for (i = 0; i < actualLength; i++) {
  30554. data[i] = ~data[i];
  30555. }
  30556. }
  30557. return {data: data, width: width, height: height};
  30558. };
  30559. PDFImage.prototype = {
  30560. get drawWidth() {
  30561. return Math.max(this.width,
  30562. this.smask && this.smask.width || 0,
  30563. this.mask && this.mask.width || 0);
  30564. },
  30565. get drawHeight() {
  30566. return Math.max(this.height,
  30567. this.smask && this.smask.height || 0,
  30568. this.mask && this.mask.height || 0);
  30569. },
  30570. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  30571. var bpc = this.bpc;
  30572. var numComps = this.numComps;
  30573. var decodeAddends = this.decodeAddends;
  30574. var decodeCoefficients = this.decodeCoefficients;
  30575. var max = (1 << bpc) - 1;
  30576. var i, ii;
  30577. if (bpc === 1) {
  30578. // If the buffer needed decode that means it just needs to be inverted.
  30579. for (i = 0, ii = buffer.length; i < ii; i++) {
  30580. buffer[i] = +!(buffer[i]);
  30581. }
  30582. return;
  30583. }
  30584. var index = 0;
  30585. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  30586. for (var j = 0; j < numComps; j++) {
  30587. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  30588. decodeCoefficients[j], max);
  30589. index++;
  30590. }
  30591. }
  30592. },
  30593. getComponents: function PDFImage_getComponents(buffer) {
  30594. var bpc = this.bpc;
  30595. // This image doesn't require any extra work.
  30596. if (bpc === 8) {
  30597. return buffer;
  30598. }
  30599. var width = this.width;
  30600. var height = this.height;
  30601. var numComps = this.numComps;
  30602. var length = width * height * numComps;
  30603. var bufferPos = 0;
  30604. var output = (bpc <= 8 ? new Uint8Array(length) :
  30605. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30606. var rowComps = width * numComps;
  30607. var max = (1 << bpc) - 1;
  30608. var i = 0, ii, buf;
  30609. if (bpc === 1) {
  30610. // Optimization for reading 1 bpc images.
  30611. var mask, loop1End, loop2End;
  30612. for (var j = 0; j < height; j++) {
  30613. loop1End = i + (rowComps & ~7);
  30614. loop2End = i + rowComps;
  30615. // unroll loop for all full bytes
  30616. while (i < loop1End) {
  30617. buf = buffer[bufferPos++];
  30618. output[i] = (buf >> 7) & 1;
  30619. output[i + 1] = (buf >> 6) & 1;
  30620. output[i + 2] = (buf >> 5) & 1;
  30621. output[i + 3] = (buf >> 4) & 1;
  30622. output[i + 4] = (buf >> 3) & 1;
  30623. output[i + 5] = (buf >> 2) & 1;
  30624. output[i + 6] = (buf >> 1) & 1;
  30625. output[i + 7] = buf & 1;
  30626. i += 8;
  30627. }
  30628. // handle remaing bits
  30629. if (i < loop2End) {
  30630. buf = buffer[bufferPos++];
  30631. mask = 128;
  30632. while (i < loop2End) {
  30633. output[i++] = +!!(buf & mask);
  30634. mask >>= 1;
  30635. }
  30636. }
  30637. }
  30638. } else {
  30639. // The general case that handles all other bpc values.
  30640. var bits = 0;
  30641. buf = 0;
  30642. for (i = 0, ii = length; i < ii; ++i) {
  30643. if (i % rowComps === 0) {
  30644. buf = 0;
  30645. bits = 0;
  30646. }
  30647. while (bits < bpc) {
  30648. buf = (buf << 8) | buffer[bufferPos++];
  30649. bits += 8;
  30650. }
  30651. var remainingBits = bits - bpc;
  30652. var value = buf >> remainingBits;
  30653. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  30654. buf = buf & ((1 << remainingBits) - 1);
  30655. bits = remainingBits;
  30656. }
  30657. }
  30658. return output;
  30659. },
  30660. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  30661. actualHeight, image) {
  30662. var smask = this.smask;
  30663. var mask = this.mask;
  30664. var alphaBuf, sw, sh, i, ii, j;
  30665. if (smask) {
  30666. sw = smask.width;
  30667. sh = smask.height;
  30668. alphaBuf = new Uint8Array(sw * sh);
  30669. smask.fillGrayBuffer(alphaBuf);
  30670. if (sw !== width || sh !== height) {
  30671. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  30672. height);
  30673. }
  30674. } else if (mask) {
  30675. if (mask instanceof PDFImage) {
  30676. sw = mask.width;
  30677. sh = mask.height;
  30678. alphaBuf = new Uint8Array(sw * sh);
  30679. mask.numComps = 1;
  30680. mask.fillGrayBuffer(alphaBuf);
  30681. // Need to invert values in rgbaBuf
  30682. for (i = 0, ii = sw * sh; i < ii; ++i) {
  30683. alphaBuf[i] = 255 - alphaBuf[i];
  30684. }
  30685. if (sw !== width || sh !== height) {
  30686. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  30687. height);
  30688. }
  30689. } else if (isArray(mask)) {
  30690. // Color key mask: if any of the compontents are outside the range
  30691. // then they should be painted.
  30692. alphaBuf = new Uint8Array(width * height);
  30693. var numComps = this.numComps;
  30694. for (i = 0, ii = width * height; i < ii; ++i) {
  30695. var opacity = 0;
  30696. var imageOffset = i * numComps;
  30697. for (j = 0; j < numComps; ++j) {
  30698. var color = image[imageOffset + j];
  30699. var maskOffset = j * 2;
  30700. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  30701. opacity = 255;
  30702. break;
  30703. }
  30704. }
  30705. alphaBuf[i] = opacity;
  30706. }
  30707. } else {
  30708. error('Unknown mask format.');
  30709. }
  30710. }
  30711. if (alphaBuf) {
  30712. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30713. rgbaBuf[j] = alphaBuf[i];
  30714. }
  30715. } else {
  30716. // No mask.
  30717. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30718. rgbaBuf[j] = 255;
  30719. }
  30720. }
  30721. },
  30722. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  30723. var matte = this.smask && this.smask.matte;
  30724. if (!matte) {
  30725. return;
  30726. }
  30727. var matteRgb = this.colorSpace.getRgb(matte, 0);
  30728. var matteR = matteRgb[0];
  30729. var matteG = matteRgb[1];
  30730. var matteB = matteRgb[2];
  30731. var length = width * height * 4;
  30732. var r, g, b;
  30733. for (var i = 0; i < length; i += 4) {
  30734. var alpha = buffer[i + 3];
  30735. if (alpha === 0) {
  30736. // according formula we have to get Infinity in all components
  30737. // making it white (typical paper color) should be okay
  30738. buffer[i] = 255;
  30739. buffer[i + 1] = 255;
  30740. buffer[i + 2] = 255;
  30741. continue;
  30742. }
  30743. var k = 255 / alpha;
  30744. r = (buffer[i] - matteR) * k + matteR;
  30745. g = (buffer[i + 1] - matteG) * k + matteG;
  30746. b = (buffer[i + 2] - matteB) * k + matteB;
  30747. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  30748. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  30749. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  30750. }
  30751. },
  30752. createImageData: function PDFImage_createImageData(forceRGBA) {
  30753. var drawWidth = this.drawWidth;
  30754. var drawHeight = this.drawHeight;
  30755. var imgData = { // other fields are filled in below
  30756. width: drawWidth,
  30757. height: drawHeight
  30758. };
  30759. var numComps = this.numComps;
  30760. var originalWidth = this.width;
  30761. var originalHeight = this.height;
  30762. var bpc = this.bpc;
  30763. // Rows start at byte boundary.
  30764. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  30765. var imgArray;
  30766. if (!forceRGBA) {
  30767. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  30768. // without any complications, we pass a same-sized copy to the main
  30769. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  30770. // of memory for many scanned documents. It's also much faster.
  30771. //
  30772. // Similarly, if it is a 24-bit-per pixel RGB image without any
  30773. // complications, we avoid expanding by 1.333x to RGBA form.
  30774. var kind;
  30775. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  30776. kind = ImageKind.GRAYSCALE_1BPP;
  30777. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  30778. !this.needsDecode) {
  30779. kind = ImageKind.RGB_24BPP;
  30780. }
  30781. if (kind && !this.smask && !this.mask &&
  30782. drawWidth === originalWidth && drawHeight === originalHeight) {
  30783. imgData.kind = kind;
  30784. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30785. // If imgArray came from a DecodeStream, we're safe to transfer it
  30786. // (and thus neuter it) because it will constitute the entire
  30787. // DecodeStream's data. But if it came from a Stream, we need to
  30788. // copy it because it'll only be a portion of the Stream's data, and
  30789. // the rest will be read later on.
  30790. if (this.image instanceof DecodeStream) {
  30791. imgData.data = imgArray;
  30792. } else {
  30793. var newArray = new Uint8Array(imgArray.length);
  30794. newArray.set(imgArray);
  30795. imgData.data = newArray;
  30796. }
  30797. if (this.needsDecode) {
  30798. // Invert the buffer (which must be grayscale if we reached here).
  30799. assert(kind === ImageKind.GRAYSCALE_1BPP);
  30800. var buffer = imgData.data;
  30801. for (var i = 0, ii = buffer.length; i < ii; i++) {
  30802. buffer[i] ^= 0xff;
  30803. }
  30804. }
  30805. return imgData;
  30806. }
  30807. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  30808. imgData.kind = ImageKind.RGB_24BPP;
  30809. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  30810. drawWidth, drawHeight, true);
  30811. return imgData;
  30812. }
  30813. }
  30814. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30815. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  30816. var actualHeight = 0 | (imgArray.length / rowBytes *
  30817. drawHeight / originalHeight);
  30818. var comps = this.getComponents(imgArray);
  30819. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  30820. // more compact RGB_24BPP form if allowable.
  30821. var alpha01, maybeUndoPreblend;
  30822. if (!forceRGBA && !this.smask && !this.mask) {
  30823. imgData.kind = ImageKind.RGB_24BPP;
  30824. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  30825. alpha01 = 0;
  30826. maybeUndoPreblend = false;
  30827. } else {
  30828. imgData.kind = ImageKind.RGBA_32BPP;
  30829. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  30830. alpha01 = 1;
  30831. maybeUndoPreblend = true;
  30832. // Color key masking (opacity) must be performed before decoding.
  30833. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  30834. comps);
  30835. }
  30836. if (this.needsDecode) {
  30837. this.decodeBuffer(comps);
  30838. }
  30839. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  30840. drawWidth, drawHeight, actualHeight, bpc, comps,
  30841. alpha01);
  30842. if (maybeUndoPreblend) {
  30843. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  30844. }
  30845. return imgData;
  30846. },
  30847. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  30848. var numComps = this.numComps;
  30849. if (numComps !== 1) {
  30850. error('Reading gray scale from a color image: ' + numComps);
  30851. }
  30852. var width = this.width;
  30853. var height = this.height;
  30854. var bpc = this.bpc;
  30855. // rows start at byte boundary
  30856. var rowBytes = (width * numComps * bpc + 7) >> 3;
  30857. var imgArray = this.getImageBytes(height * rowBytes);
  30858. var comps = this.getComponents(imgArray);
  30859. var i, length;
  30860. if (bpc === 1) {
  30861. // inline decoding (= inversion) for 1 bpc images
  30862. length = width * height;
  30863. if (this.needsDecode) {
  30864. // invert and scale to {0, 255}
  30865. for (i = 0; i < length; ++i) {
  30866. buffer[i] = (comps[i] - 1) & 255;
  30867. }
  30868. } else {
  30869. // scale to {0, 255}
  30870. for (i = 0; i < length; ++i) {
  30871. buffer[i] = (-comps[i]) & 255;
  30872. }
  30873. }
  30874. return;
  30875. }
  30876. if (this.needsDecode) {
  30877. this.decodeBuffer(comps);
  30878. }
  30879. length = width * height;
  30880. // we aren't using a colorspace so we need to scale the value
  30881. var scale = 255 / ((1 << bpc) - 1);
  30882. for (i = 0; i < length; ++i) {
  30883. buffer[i] = (scale * comps[i]) | 0;
  30884. }
  30885. },
  30886. getImageBytes: function PDFImage_getImageBytes(length,
  30887. drawWidth, drawHeight,
  30888. forceRGB) {
  30889. this.image.reset();
  30890. this.image.drawWidth = drawWidth || this.width;
  30891. this.image.drawHeight = drawHeight || this.height;
  30892. this.image.forceRGB = !!forceRGB;
  30893. return this.image.getBytes(length);
  30894. }
  30895. };
  30896. return PDFImage;
  30897. })();
  30898. // The Metrics object contains glyph widths (in glyph space units).
  30899. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  30900. // space unit corresponds to 1/1000th of text space unit.
  30901. var Metrics = {
  30902. 'Courier': 600,
  30903. 'Courier-Bold': 600,
  30904. 'Courier-BoldOblique': 600,
  30905. 'Courier-Oblique': 600,
  30906. 'Helvetica' : {
  30907. 'space': 278,
  30908. 'exclam': 278,
  30909. 'quotedbl': 355,
  30910. 'numbersign': 556,
  30911. 'dollar': 556,
  30912. 'percent': 889,
  30913. 'ampersand': 667,
  30914. 'quoteright': 222,
  30915. 'parenleft': 333,
  30916. 'parenright': 333,
  30917. 'asterisk': 389,
  30918. 'plus': 584,
  30919. 'comma': 278,
  30920. 'hyphen': 333,
  30921. 'period': 278,
  30922. 'slash': 278,
  30923. 'zero': 556,
  30924. 'one': 556,
  30925. 'two': 556,
  30926. 'three': 556,
  30927. 'four': 556,
  30928. 'five': 556,
  30929. 'six': 556,
  30930. 'seven': 556,
  30931. 'eight': 556,
  30932. 'nine': 556,
  30933. 'colon': 278,
  30934. 'semicolon': 278,
  30935. 'less': 584,
  30936. 'equal': 584,
  30937. 'greater': 584,
  30938. 'question': 556,
  30939. 'at': 1015,
  30940. 'A': 667,
  30941. 'B': 667,
  30942. 'C': 722,
  30943. 'D': 722,
  30944. 'E': 667,
  30945. 'F': 611,
  30946. 'G': 778,
  30947. 'H': 722,
  30948. 'I': 278,
  30949. 'J': 500,
  30950. 'K': 667,
  30951. 'L': 556,
  30952. 'M': 833,
  30953. 'N': 722,
  30954. 'O': 778,
  30955. 'P': 667,
  30956. 'Q': 778,
  30957. 'R': 722,
  30958. 'S': 667,
  30959. 'T': 611,
  30960. 'U': 722,
  30961. 'V': 667,
  30962. 'W': 944,
  30963. 'X': 667,
  30964. 'Y': 667,
  30965. 'Z': 611,
  30966. 'bracketleft': 278,
  30967. 'backslash': 278,
  30968. 'bracketright': 278,
  30969. 'asciicircum': 469,
  30970. 'underscore': 556,
  30971. 'quoteleft': 222,
  30972. 'a': 556,
  30973. 'b': 556,
  30974. 'c': 500,
  30975. 'd': 556,
  30976. 'e': 556,
  30977. 'f': 278,
  30978. 'g': 556,
  30979. 'h': 556,
  30980. 'i': 222,
  30981. 'j': 222,
  30982. 'k': 500,
  30983. 'l': 222,
  30984. 'm': 833,
  30985. 'n': 556,
  30986. 'o': 556,
  30987. 'p': 556,
  30988. 'q': 556,
  30989. 'r': 333,
  30990. 's': 500,
  30991. 't': 278,
  30992. 'u': 556,
  30993. 'v': 500,
  30994. 'w': 722,
  30995. 'x': 500,
  30996. 'y': 500,
  30997. 'z': 500,
  30998. 'braceleft': 334,
  30999. 'bar': 260,
  31000. 'braceright': 334,
  31001. 'asciitilde': 584,
  31002. 'exclamdown': 333,
  31003. 'cent': 556,
  31004. 'sterling': 556,
  31005. 'fraction': 167,
  31006. 'yen': 556,
  31007. 'florin': 556,
  31008. 'section': 556,
  31009. 'currency': 556,
  31010. 'quotesingle': 191,
  31011. 'quotedblleft': 333,
  31012. 'guillemotleft': 556,
  31013. 'guilsinglleft': 333,
  31014. 'guilsinglright': 333,
  31015. 'fi': 500,
  31016. 'fl': 500,
  31017. 'endash': 556,
  31018. 'dagger': 556,
  31019. 'daggerdbl': 556,
  31020. 'periodcentered': 278,
  31021. 'paragraph': 537,
  31022. 'bullet': 350,
  31023. 'quotesinglbase': 222,
  31024. 'quotedblbase': 333,
  31025. 'quotedblright': 333,
  31026. 'guillemotright': 556,
  31027. 'ellipsis': 1000,
  31028. 'perthousand': 1000,
  31029. 'questiondown': 611,
  31030. 'grave': 333,
  31031. 'acute': 333,
  31032. 'circumflex': 333,
  31033. 'tilde': 333,
  31034. 'macron': 333,
  31035. 'breve': 333,
  31036. 'dotaccent': 333,
  31037. 'dieresis': 333,
  31038. 'ring': 333,
  31039. 'cedilla': 333,
  31040. 'hungarumlaut': 333,
  31041. 'ogonek': 333,
  31042. 'caron': 333,
  31043. 'emdash': 1000,
  31044. 'AE': 1000,
  31045. 'ordfeminine': 370,
  31046. 'Lslash': 556,
  31047. 'Oslash': 778,
  31048. 'OE': 1000,
  31049. 'ordmasculine': 365,
  31050. 'ae': 889,
  31051. 'dotlessi': 278,
  31052. 'lslash': 222,
  31053. 'oslash': 611,
  31054. 'oe': 944,
  31055. 'germandbls': 611,
  31056. 'Idieresis': 278,
  31057. 'eacute': 556,
  31058. 'abreve': 556,
  31059. 'uhungarumlaut': 556,
  31060. 'ecaron': 556,
  31061. 'Ydieresis': 667,
  31062. 'divide': 584,
  31063. 'Yacute': 667,
  31064. 'Acircumflex': 667,
  31065. 'aacute': 556,
  31066. 'Ucircumflex': 722,
  31067. 'yacute': 500,
  31068. 'scommaaccent': 500,
  31069. 'ecircumflex': 556,
  31070. 'Uring': 722,
  31071. 'Udieresis': 722,
  31072. 'aogonek': 556,
  31073. 'Uacute': 722,
  31074. 'uogonek': 556,
  31075. 'Edieresis': 667,
  31076. 'Dcroat': 722,
  31077. 'commaaccent': 250,
  31078. 'copyright': 737,
  31079. 'Emacron': 667,
  31080. 'ccaron': 500,
  31081. 'aring': 556,
  31082. 'Ncommaaccent': 722,
  31083. 'lacute': 222,
  31084. 'agrave': 556,
  31085. 'Tcommaaccent': 611,
  31086. 'Cacute': 722,
  31087. 'atilde': 556,
  31088. 'Edotaccent': 667,
  31089. 'scaron': 500,
  31090. 'scedilla': 500,
  31091. 'iacute': 278,
  31092. 'lozenge': 471,
  31093. 'Rcaron': 722,
  31094. 'Gcommaaccent': 778,
  31095. 'ucircumflex': 556,
  31096. 'acircumflex': 556,
  31097. 'Amacron': 667,
  31098. 'rcaron': 333,
  31099. 'ccedilla': 500,
  31100. 'Zdotaccent': 611,
  31101. 'Thorn': 667,
  31102. 'Omacron': 778,
  31103. 'Racute': 722,
  31104. 'Sacute': 667,
  31105. 'dcaron': 643,
  31106. 'Umacron': 722,
  31107. 'uring': 556,
  31108. 'threesuperior': 333,
  31109. 'Ograve': 778,
  31110. 'Agrave': 667,
  31111. 'Abreve': 667,
  31112. 'multiply': 584,
  31113. 'uacute': 556,
  31114. 'Tcaron': 611,
  31115. 'partialdiff': 476,
  31116. 'ydieresis': 500,
  31117. 'Nacute': 722,
  31118. 'icircumflex': 278,
  31119. 'Ecircumflex': 667,
  31120. 'adieresis': 556,
  31121. 'edieresis': 556,
  31122. 'cacute': 500,
  31123. 'nacute': 556,
  31124. 'umacron': 556,
  31125. 'Ncaron': 722,
  31126. 'Iacute': 278,
  31127. 'plusminus': 584,
  31128. 'brokenbar': 260,
  31129. 'registered': 737,
  31130. 'Gbreve': 778,
  31131. 'Idotaccent': 278,
  31132. 'summation': 600,
  31133. 'Egrave': 667,
  31134. 'racute': 333,
  31135. 'omacron': 556,
  31136. 'Zacute': 611,
  31137. 'Zcaron': 611,
  31138. 'greaterequal': 549,
  31139. 'Eth': 722,
  31140. 'Ccedilla': 722,
  31141. 'lcommaaccent': 222,
  31142. 'tcaron': 317,
  31143. 'eogonek': 556,
  31144. 'Uogonek': 722,
  31145. 'Aacute': 667,
  31146. 'Adieresis': 667,
  31147. 'egrave': 556,
  31148. 'zacute': 500,
  31149. 'iogonek': 222,
  31150. 'Oacute': 778,
  31151. 'oacute': 556,
  31152. 'amacron': 556,
  31153. 'sacute': 500,
  31154. 'idieresis': 278,
  31155. 'Ocircumflex': 778,
  31156. 'Ugrave': 722,
  31157. 'Delta': 612,
  31158. 'thorn': 556,
  31159. 'twosuperior': 333,
  31160. 'Odieresis': 778,
  31161. 'mu': 556,
  31162. 'igrave': 278,
  31163. 'ohungarumlaut': 556,
  31164. 'Eogonek': 667,
  31165. 'dcroat': 556,
  31166. 'threequarters': 834,
  31167. 'Scedilla': 667,
  31168. 'lcaron': 299,
  31169. 'Kcommaaccent': 667,
  31170. 'Lacute': 556,
  31171. 'trademark': 1000,
  31172. 'edotaccent': 556,
  31173. 'Igrave': 278,
  31174. 'Imacron': 278,
  31175. 'Lcaron': 556,
  31176. 'onehalf': 834,
  31177. 'lessequal': 549,
  31178. 'ocircumflex': 556,
  31179. 'ntilde': 556,
  31180. 'Uhungarumlaut': 722,
  31181. 'Eacute': 667,
  31182. 'emacron': 556,
  31183. 'gbreve': 556,
  31184. 'onequarter': 834,
  31185. 'Scaron': 667,
  31186. 'Scommaaccent': 667,
  31187. 'Ohungarumlaut': 778,
  31188. 'degree': 400,
  31189. 'ograve': 556,
  31190. 'Ccaron': 722,
  31191. 'ugrave': 556,
  31192. 'radical': 453,
  31193. 'Dcaron': 722,
  31194. 'rcommaaccent': 333,
  31195. 'Ntilde': 722,
  31196. 'otilde': 556,
  31197. 'Rcommaaccent': 722,
  31198. 'Lcommaaccent': 556,
  31199. 'Atilde': 667,
  31200. 'Aogonek': 667,
  31201. 'Aring': 667,
  31202. 'Otilde': 778,
  31203. 'zdotaccent': 500,
  31204. 'Ecaron': 667,
  31205. 'Iogonek': 278,
  31206. 'kcommaaccent': 500,
  31207. 'minus': 584,
  31208. 'Icircumflex': 278,
  31209. 'ncaron': 556,
  31210. 'tcommaaccent': 278,
  31211. 'logicalnot': 584,
  31212. 'odieresis': 556,
  31213. 'udieresis': 556,
  31214. 'notequal': 549,
  31215. 'gcommaaccent': 556,
  31216. 'eth': 556,
  31217. 'zcaron': 500,
  31218. 'ncommaaccent': 556,
  31219. 'onesuperior': 333,
  31220. 'imacron': 278,
  31221. 'Euro': 556
  31222. },
  31223. 'Helvetica-Bold': {
  31224. 'space': 278,
  31225. 'exclam': 333,
  31226. 'quotedbl': 474,
  31227. 'numbersign': 556,
  31228. 'dollar': 556,
  31229. 'percent': 889,
  31230. 'ampersand': 722,
  31231. 'quoteright': 278,
  31232. 'parenleft': 333,
  31233. 'parenright': 333,
  31234. 'asterisk': 389,
  31235. 'plus': 584,
  31236. 'comma': 278,
  31237. 'hyphen': 333,
  31238. 'period': 278,
  31239. 'slash': 278,
  31240. 'zero': 556,
  31241. 'one': 556,
  31242. 'two': 556,
  31243. 'three': 556,
  31244. 'four': 556,
  31245. 'five': 556,
  31246. 'six': 556,
  31247. 'seven': 556,
  31248. 'eight': 556,
  31249. 'nine': 556,
  31250. 'colon': 333,
  31251. 'semicolon': 333,
  31252. 'less': 584,
  31253. 'equal': 584,
  31254. 'greater': 584,
  31255. 'question': 611,
  31256. 'at': 975,
  31257. 'A': 722,
  31258. 'B': 722,
  31259. 'C': 722,
  31260. 'D': 722,
  31261. 'E': 667,
  31262. 'F': 611,
  31263. 'G': 778,
  31264. 'H': 722,
  31265. 'I': 278,
  31266. 'J': 556,
  31267. 'K': 722,
  31268. 'L': 611,
  31269. 'M': 833,
  31270. 'N': 722,
  31271. 'O': 778,
  31272. 'P': 667,
  31273. 'Q': 778,
  31274. 'R': 722,
  31275. 'S': 667,
  31276. 'T': 611,
  31277. 'U': 722,
  31278. 'V': 667,
  31279. 'W': 944,
  31280. 'X': 667,
  31281. 'Y': 667,
  31282. 'Z': 611,
  31283. 'bracketleft': 333,
  31284. 'backslash': 278,
  31285. 'bracketright': 333,
  31286. 'asciicircum': 584,
  31287. 'underscore': 556,
  31288. 'quoteleft': 278,
  31289. 'a': 556,
  31290. 'b': 611,
  31291. 'c': 556,
  31292. 'd': 611,
  31293. 'e': 556,
  31294. 'f': 333,
  31295. 'g': 611,
  31296. 'h': 611,
  31297. 'i': 278,
  31298. 'j': 278,
  31299. 'k': 556,
  31300. 'l': 278,
  31301. 'm': 889,
  31302. 'n': 611,
  31303. 'o': 611,
  31304. 'p': 611,
  31305. 'q': 611,
  31306. 'r': 389,
  31307. 's': 556,
  31308. 't': 333,
  31309. 'u': 611,
  31310. 'v': 556,
  31311. 'w': 778,
  31312. 'x': 556,
  31313. 'y': 556,
  31314. 'z': 500,
  31315. 'braceleft': 389,
  31316. 'bar': 280,
  31317. 'braceright': 389,
  31318. 'asciitilde': 584,
  31319. 'exclamdown': 333,
  31320. 'cent': 556,
  31321. 'sterling': 556,
  31322. 'fraction': 167,
  31323. 'yen': 556,
  31324. 'florin': 556,
  31325. 'section': 556,
  31326. 'currency': 556,
  31327. 'quotesingle': 238,
  31328. 'quotedblleft': 500,
  31329. 'guillemotleft': 556,
  31330. 'guilsinglleft': 333,
  31331. 'guilsinglright': 333,
  31332. 'fi': 611,
  31333. 'fl': 611,
  31334. 'endash': 556,
  31335. 'dagger': 556,
  31336. 'daggerdbl': 556,
  31337. 'periodcentered': 278,
  31338. 'paragraph': 556,
  31339. 'bullet': 350,
  31340. 'quotesinglbase': 278,
  31341. 'quotedblbase': 500,
  31342. 'quotedblright': 500,
  31343. 'guillemotright': 556,
  31344. 'ellipsis': 1000,
  31345. 'perthousand': 1000,
  31346. 'questiondown': 611,
  31347. 'grave': 333,
  31348. 'acute': 333,
  31349. 'circumflex': 333,
  31350. 'tilde': 333,
  31351. 'macron': 333,
  31352. 'breve': 333,
  31353. 'dotaccent': 333,
  31354. 'dieresis': 333,
  31355. 'ring': 333,
  31356. 'cedilla': 333,
  31357. 'hungarumlaut': 333,
  31358. 'ogonek': 333,
  31359. 'caron': 333,
  31360. 'emdash': 1000,
  31361. 'AE': 1000,
  31362. 'ordfeminine': 370,
  31363. 'Lslash': 611,
  31364. 'Oslash': 778,
  31365. 'OE': 1000,
  31366. 'ordmasculine': 365,
  31367. 'ae': 889,
  31368. 'dotlessi': 278,
  31369. 'lslash': 278,
  31370. 'oslash': 611,
  31371. 'oe': 944,
  31372. 'germandbls': 611,
  31373. 'Idieresis': 278,
  31374. 'eacute': 556,
  31375. 'abreve': 556,
  31376. 'uhungarumlaut': 611,
  31377. 'ecaron': 556,
  31378. 'Ydieresis': 667,
  31379. 'divide': 584,
  31380. 'Yacute': 667,
  31381. 'Acircumflex': 722,
  31382. 'aacute': 556,
  31383. 'Ucircumflex': 722,
  31384. 'yacute': 556,
  31385. 'scommaaccent': 556,
  31386. 'ecircumflex': 556,
  31387. 'Uring': 722,
  31388. 'Udieresis': 722,
  31389. 'aogonek': 556,
  31390. 'Uacute': 722,
  31391. 'uogonek': 611,
  31392. 'Edieresis': 667,
  31393. 'Dcroat': 722,
  31394. 'commaaccent': 250,
  31395. 'copyright': 737,
  31396. 'Emacron': 667,
  31397. 'ccaron': 556,
  31398. 'aring': 556,
  31399. 'Ncommaaccent': 722,
  31400. 'lacute': 278,
  31401. 'agrave': 556,
  31402. 'Tcommaaccent': 611,
  31403. 'Cacute': 722,
  31404. 'atilde': 556,
  31405. 'Edotaccent': 667,
  31406. 'scaron': 556,
  31407. 'scedilla': 556,
  31408. 'iacute': 278,
  31409. 'lozenge': 494,
  31410. 'Rcaron': 722,
  31411. 'Gcommaaccent': 778,
  31412. 'ucircumflex': 611,
  31413. 'acircumflex': 556,
  31414. 'Amacron': 722,
  31415. 'rcaron': 389,
  31416. 'ccedilla': 556,
  31417. 'Zdotaccent': 611,
  31418. 'Thorn': 667,
  31419. 'Omacron': 778,
  31420. 'Racute': 722,
  31421. 'Sacute': 667,
  31422. 'dcaron': 743,
  31423. 'Umacron': 722,
  31424. 'uring': 611,
  31425. 'threesuperior': 333,
  31426. 'Ograve': 778,
  31427. 'Agrave': 722,
  31428. 'Abreve': 722,
  31429. 'multiply': 584,
  31430. 'uacute': 611,
  31431. 'Tcaron': 611,
  31432. 'partialdiff': 494,
  31433. 'ydieresis': 556,
  31434. 'Nacute': 722,
  31435. 'icircumflex': 278,
  31436. 'Ecircumflex': 667,
  31437. 'adieresis': 556,
  31438. 'edieresis': 556,
  31439. 'cacute': 556,
  31440. 'nacute': 611,
  31441. 'umacron': 611,
  31442. 'Ncaron': 722,
  31443. 'Iacute': 278,
  31444. 'plusminus': 584,
  31445. 'brokenbar': 280,
  31446. 'registered': 737,
  31447. 'Gbreve': 778,
  31448. 'Idotaccent': 278,
  31449. 'summation': 600,
  31450. 'Egrave': 667,
  31451. 'racute': 389,
  31452. 'omacron': 611,
  31453. 'Zacute': 611,
  31454. 'Zcaron': 611,
  31455. 'greaterequal': 549,
  31456. 'Eth': 722,
  31457. 'Ccedilla': 722,
  31458. 'lcommaaccent': 278,
  31459. 'tcaron': 389,
  31460. 'eogonek': 556,
  31461. 'Uogonek': 722,
  31462. 'Aacute': 722,
  31463. 'Adieresis': 722,
  31464. 'egrave': 556,
  31465. 'zacute': 500,
  31466. 'iogonek': 278,
  31467. 'Oacute': 778,
  31468. 'oacute': 611,
  31469. 'amacron': 556,
  31470. 'sacute': 556,
  31471. 'idieresis': 278,
  31472. 'Ocircumflex': 778,
  31473. 'Ugrave': 722,
  31474. 'Delta': 612,
  31475. 'thorn': 611,
  31476. 'twosuperior': 333,
  31477. 'Odieresis': 778,
  31478. 'mu': 611,
  31479. 'igrave': 278,
  31480. 'ohungarumlaut': 611,
  31481. 'Eogonek': 667,
  31482. 'dcroat': 611,
  31483. 'threequarters': 834,
  31484. 'Scedilla': 667,
  31485. 'lcaron': 400,
  31486. 'Kcommaaccent': 722,
  31487. 'Lacute': 611,
  31488. 'trademark': 1000,
  31489. 'edotaccent': 556,
  31490. 'Igrave': 278,
  31491. 'Imacron': 278,
  31492. 'Lcaron': 611,
  31493. 'onehalf': 834,
  31494. 'lessequal': 549,
  31495. 'ocircumflex': 611,
  31496. 'ntilde': 611,
  31497. 'Uhungarumlaut': 722,
  31498. 'Eacute': 667,
  31499. 'emacron': 556,
  31500. 'gbreve': 611,
  31501. 'onequarter': 834,
  31502. 'Scaron': 667,
  31503. 'Scommaaccent': 667,
  31504. 'Ohungarumlaut': 778,
  31505. 'degree': 400,
  31506. 'ograve': 611,
  31507. 'Ccaron': 722,
  31508. 'ugrave': 611,
  31509. 'radical': 549,
  31510. 'Dcaron': 722,
  31511. 'rcommaaccent': 389,
  31512. 'Ntilde': 722,
  31513. 'otilde': 611,
  31514. 'Rcommaaccent': 722,
  31515. 'Lcommaaccent': 611,
  31516. 'Atilde': 722,
  31517. 'Aogonek': 722,
  31518. 'Aring': 722,
  31519. 'Otilde': 778,
  31520. 'zdotaccent': 500,
  31521. 'Ecaron': 667,
  31522. 'Iogonek': 278,
  31523. 'kcommaaccent': 556,
  31524. 'minus': 584,
  31525. 'Icircumflex': 278,
  31526. 'ncaron': 611,
  31527. 'tcommaaccent': 333,
  31528. 'logicalnot': 584,
  31529. 'odieresis': 611,
  31530. 'udieresis': 611,
  31531. 'notequal': 549,
  31532. 'gcommaaccent': 611,
  31533. 'eth': 611,
  31534. 'zcaron': 500,
  31535. 'ncommaaccent': 611,
  31536. 'onesuperior': 333,
  31537. 'imacron': 278,
  31538. 'Euro': 556
  31539. },
  31540. 'Helvetica-BoldOblique': {
  31541. 'space': 278,
  31542. 'exclam': 333,
  31543. 'quotedbl': 474,
  31544. 'numbersign': 556,
  31545. 'dollar': 556,
  31546. 'percent': 889,
  31547. 'ampersand': 722,
  31548. 'quoteright': 278,
  31549. 'parenleft': 333,
  31550. 'parenright': 333,
  31551. 'asterisk': 389,
  31552. 'plus': 584,
  31553. 'comma': 278,
  31554. 'hyphen': 333,
  31555. 'period': 278,
  31556. 'slash': 278,
  31557. 'zero': 556,
  31558. 'one': 556,
  31559. 'two': 556,
  31560. 'three': 556,
  31561. 'four': 556,
  31562. 'five': 556,
  31563. 'six': 556,
  31564. 'seven': 556,
  31565. 'eight': 556,
  31566. 'nine': 556,
  31567. 'colon': 333,
  31568. 'semicolon': 333,
  31569. 'less': 584,
  31570. 'equal': 584,
  31571. 'greater': 584,
  31572. 'question': 611,
  31573. 'at': 975,
  31574. 'A': 722,
  31575. 'B': 722,
  31576. 'C': 722,
  31577. 'D': 722,
  31578. 'E': 667,
  31579. 'F': 611,
  31580. 'G': 778,
  31581. 'H': 722,
  31582. 'I': 278,
  31583. 'J': 556,
  31584. 'K': 722,
  31585. 'L': 611,
  31586. 'M': 833,
  31587. 'N': 722,
  31588. 'O': 778,
  31589. 'P': 667,
  31590. 'Q': 778,
  31591. 'R': 722,
  31592. 'S': 667,
  31593. 'T': 611,
  31594. 'U': 722,
  31595. 'V': 667,
  31596. 'W': 944,
  31597. 'X': 667,
  31598. 'Y': 667,
  31599. 'Z': 611,
  31600. 'bracketleft': 333,
  31601. 'backslash': 278,
  31602. 'bracketright': 333,
  31603. 'asciicircum': 584,
  31604. 'underscore': 556,
  31605. 'quoteleft': 278,
  31606. 'a': 556,
  31607. 'b': 611,
  31608. 'c': 556,
  31609. 'd': 611,
  31610. 'e': 556,
  31611. 'f': 333,
  31612. 'g': 611,
  31613. 'h': 611,
  31614. 'i': 278,
  31615. 'j': 278,
  31616. 'k': 556,
  31617. 'l': 278,
  31618. 'm': 889,
  31619. 'n': 611,
  31620. 'o': 611,
  31621. 'p': 611,
  31622. 'q': 611,
  31623. 'r': 389,
  31624. 's': 556,
  31625. 't': 333,
  31626. 'u': 611,
  31627. 'v': 556,
  31628. 'w': 778,
  31629. 'x': 556,
  31630. 'y': 556,
  31631. 'z': 500,
  31632. 'braceleft': 389,
  31633. 'bar': 280,
  31634. 'braceright': 389,
  31635. 'asciitilde': 584,
  31636. 'exclamdown': 333,
  31637. 'cent': 556,
  31638. 'sterling': 556,
  31639. 'fraction': 167,
  31640. 'yen': 556,
  31641. 'florin': 556,
  31642. 'section': 556,
  31643. 'currency': 556,
  31644. 'quotesingle': 238,
  31645. 'quotedblleft': 500,
  31646. 'guillemotleft': 556,
  31647. 'guilsinglleft': 333,
  31648. 'guilsinglright': 333,
  31649. 'fi': 611,
  31650. 'fl': 611,
  31651. 'endash': 556,
  31652. 'dagger': 556,
  31653. 'daggerdbl': 556,
  31654. 'periodcentered': 278,
  31655. 'paragraph': 556,
  31656. 'bullet': 350,
  31657. 'quotesinglbase': 278,
  31658. 'quotedblbase': 500,
  31659. 'quotedblright': 500,
  31660. 'guillemotright': 556,
  31661. 'ellipsis': 1000,
  31662. 'perthousand': 1000,
  31663. 'questiondown': 611,
  31664. 'grave': 333,
  31665. 'acute': 333,
  31666. 'circumflex': 333,
  31667. 'tilde': 333,
  31668. 'macron': 333,
  31669. 'breve': 333,
  31670. 'dotaccent': 333,
  31671. 'dieresis': 333,
  31672. 'ring': 333,
  31673. 'cedilla': 333,
  31674. 'hungarumlaut': 333,
  31675. 'ogonek': 333,
  31676. 'caron': 333,
  31677. 'emdash': 1000,
  31678. 'AE': 1000,
  31679. 'ordfeminine': 370,
  31680. 'Lslash': 611,
  31681. 'Oslash': 778,
  31682. 'OE': 1000,
  31683. 'ordmasculine': 365,
  31684. 'ae': 889,
  31685. 'dotlessi': 278,
  31686. 'lslash': 278,
  31687. 'oslash': 611,
  31688. 'oe': 944,
  31689. 'germandbls': 611,
  31690. 'Idieresis': 278,
  31691. 'eacute': 556,
  31692. 'abreve': 556,
  31693. 'uhungarumlaut': 611,
  31694. 'ecaron': 556,
  31695. 'Ydieresis': 667,
  31696. 'divide': 584,
  31697. 'Yacute': 667,
  31698. 'Acircumflex': 722,
  31699. 'aacute': 556,
  31700. 'Ucircumflex': 722,
  31701. 'yacute': 556,
  31702. 'scommaaccent': 556,
  31703. 'ecircumflex': 556,
  31704. 'Uring': 722,
  31705. 'Udieresis': 722,
  31706. 'aogonek': 556,
  31707. 'Uacute': 722,
  31708. 'uogonek': 611,
  31709. 'Edieresis': 667,
  31710. 'Dcroat': 722,
  31711. 'commaaccent': 250,
  31712. 'copyright': 737,
  31713. 'Emacron': 667,
  31714. 'ccaron': 556,
  31715. 'aring': 556,
  31716. 'Ncommaaccent': 722,
  31717. 'lacute': 278,
  31718. 'agrave': 556,
  31719. 'Tcommaaccent': 611,
  31720. 'Cacute': 722,
  31721. 'atilde': 556,
  31722. 'Edotaccent': 667,
  31723. 'scaron': 556,
  31724. 'scedilla': 556,
  31725. 'iacute': 278,
  31726. 'lozenge': 494,
  31727. 'Rcaron': 722,
  31728. 'Gcommaaccent': 778,
  31729. 'ucircumflex': 611,
  31730. 'acircumflex': 556,
  31731. 'Amacron': 722,
  31732. 'rcaron': 389,
  31733. 'ccedilla': 556,
  31734. 'Zdotaccent': 611,
  31735. 'Thorn': 667,
  31736. 'Omacron': 778,
  31737. 'Racute': 722,
  31738. 'Sacute': 667,
  31739. 'dcaron': 743,
  31740. 'Umacron': 722,
  31741. 'uring': 611,
  31742. 'threesuperior': 333,
  31743. 'Ograve': 778,
  31744. 'Agrave': 722,
  31745. 'Abreve': 722,
  31746. 'multiply': 584,
  31747. 'uacute': 611,
  31748. 'Tcaron': 611,
  31749. 'partialdiff': 494,
  31750. 'ydieresis': 556,
  31751. 'Nacute': 722,
  31752. 'icircumflex': 278,
  31753. 'Ecircumflex': 667,
  31754. 'adieresis': 556,
  31755. 'edieresis': 556,
  31756. 'cacute': 556,
  31757. 'nacute': 611,
  31758. 'umacron': 611,
  31759. 'Ncaron': 722,
  31760. 'Iacute': 278,
  31761. 'plusminus': 584,
  31762. 'brokenbar': 280,
  31763. 'registered': 737,
  31764. 'Gbreve': 778,
  31765. 'Idotaccent': 278,
  31766. 'summation': 600,
  31767. 'Egrave': 667,
  31768. 'racute': 389,
  31769. 'omacron': 611,
  31770. 'Zacute': 611,
  31771. 'Zcaron': 611,
  31772. 'greaterequal': 549,
  31773. 'Eth': 722,
  31774. 'Ccedilla': 722,
  31775. 'lcommaaccent': 278,
  31776. 'tcaron': 389,
  31777. 'eogonek': 556,
  31778. 'Uogonek': 722,
  31779. 'Aacute': 722,
  31780. 'Adieresis': 722,
  31781. 'egrave': 556,
  31782. 'zacute': 500,
  31783. 'iogonek': 278,
  31784. 'Oacute': 778,
  31785. 'oacute': 611,
  31786. 'amacron': 556,
  31787. 'sacute': 556,
  31788. 'idieresis': 278,
  31789. 'Ocircumflex': 778,
  31790. 'Ugrave': 722,
  31791. 'Delta': 612,
  31792. 'thorn': 611,
  31793. 'twosuperior': 333,
  31794. 'Odieresis': 778,
  31795. 'mu': 611,
  31796. 'igrave': 278,
  31797. 'ohungarumlaut': 611,
  31798. 'Eogonek': 667,
  31799. 'dcroat': 611,
  31800. 'threequarters': 834,
  31801. 'Scedilla': 667,
  31802. 'lcaron': 400,
  31803. 'Kcommaaccent': 722,
  31804. 'Lacute': 611,
  31805. 'trademark': 1000,
  31806. 'edotaccent': 556,
  31807. 'Igrave': 278,
  31808. 'Imacron': 278,
  31809. 'Lcaron': 611,
  31810. 'onehalf': 834,
  31811. 'lessequal': 549,
  31812. 'ocircumflex': 611,
  31813. 'ntilde': 611,
  31814. 'Uhungarumlaut': 722,
  31815. 'Eacute': 667,
  31816. 'emacron': 556,
  31817. 'gbreve': 611,
  31818. 'onequarter': 834,
  31819. 'Scaron': 667,
  31820. 'Scommaaccent': 667,
  31821. 'Ohungarumlaut': 778,
  31822. 'degree': 400,
  31823. 'ograve': 611,
  31824. 'Ccaron': 722,
  31825. 'ugrave': 611,
  31826. 'radical': 549,
  31827. 'Dcaron': 722,
  31828. 'rcommaaccent': 389,
  31829. 'Ntilde': 722,
  31830. 'otilde': 611,
  31831. 'Rcommaaccent': 722,
  31832. 'Lcommaaccent': 611,
  31833. 'Atilde': 722,
  31834. 'Aogonek': 722,
  31835. 'Aring': 722,
  31836. 'Otilde': 778,
  31837. 'zdotaccent': 500,
  31838. 'Ecaron': 667,
  31839. 'Iogonek': 278,
  31840. 'kcommaaccent': 556,
  31841. 'minus': 584,
  31842. 'Icircumflex': 278,
  31843. 'ncaron': 611,
  31844. 'tcommaaccent': 333,
  31845. 'logicalnot': 584,
  31846. 'odieresis': 611,
  31847. 'udieresis': 611,
  31848. 'notequal': 549,
  31849. 'gcommaaccent': 611,
  31850. 'eth': 611,
  31851. 'zcaron': 500,
  31852. 'ncommaaccent': 611,
  31853. 'onesuperior': 333,
  31854. 'imacron': 278,
  31855. 'Euro': 556
  31856. },
  31857. 'Helvetica-Oblique' : {
  31858. 'space': 278,
  31859. 'exclam': 278,
  31860. 'quotedbl': 355,
  31861. 'numbersign': 556,
  31862. 'dollar': 556,
  31863. 'percent': 889,
  31864. 'ampersand': 667,
  31865. 'quoteright': 222,
  31866. 'parenleft': 333,
  31867. 'parenright': 333,
  31868. 'asterisk': 389,
  31869. 'plus': 584,
  31870. 'comma': 278,
  31871. 'hyphen': 333,
  31872. 'period': 278,
  31873. 'slash': 278,
  31874. 'zero': 556,
  31875. 'one': 556,
  31876. 'two': 556,
  31877. 'three': 556,
  31878. 'four': 556,
  31879. 'five': 556,
  31880. 'six': 556,
  31881. 'seven': 556,
  31882. 'eight': 556,
  31883. 'nine': 556,
  31884. 'colon': 278,
  31885. 'semicolon': 278,
  31886. 'less': 584,
  31887. 'equal': 584,
  31888. 'greater': 584,
  31889. 'question': 556,
  31890. 'at': 1015,
  31891. 'A': 667,
  31892. 'B': 667,
  31893. 'C': 722,
  31894. 'D': 722,
  31895. 'E': 667,
  31896. 'F': 611,
  31897. 'G': 778,
  31898. 'H': 722,
  31899. 'I': 278,
  31900. 'J': 500,
  31901. 'K': 667,
  31902. 'L': 556,
  31903. 'M': 833,
  31904. 'N': 722,
  31905. 'O': 778,
  31906. 'P': 667,
  31907. 'Q': 778,
  31908. 'R': 722,
  31909. 'S': 667,
  31910. 'T': 611,
  31911. 'U': 722,
  31912. 'V': 667,
  31913. 'W': 944,
  31914. 'X': 667,
  31915. 'Y': 667,
  31916. 'Z': 611,
  31917. 'bracketleft': 278,
  31918. 'backslash': 278,
  31919. 'bracketright': 278,
  31920. 'asciicircum': 469,
  31921. 'underscore': 556,
  31922. 'quoteleft': 222,
  31923. 'a': 556,
  31924. 'b': 556,
  31925. 'c': 500,
  31926. 'd': 556,
  31927. 'e': 556,
  31928. 'f': 278,
  31929. 'g': 556,
  31930. 'h': 556,
  31931. 'i': 222,
  31932. 'j': 222,
  31933. 'k': 500,
  31934. 'l': 222,
  31935. 'm': 833,
  31936. 'n': 556,
  31937. 'o': 556,
  31938. 'p': 556,
  31939. 'q': 556,
  31940. 'r': 333,
  31941. 's': 500,
  31942. 't': 278,
  31943. 'u': 556,
  31944. 'v': 500,
  31945. 'w': 722,
  31946. 'x': 500,
  31947. 'y': 500,
  31948. 'z': 500,
  31949. 'braceleft': 334,
  31950. 'bar': 260,
  31951. 'braceright': 334,
  31952. 'asciitilde': 584,
  31953. 'exclamdown': 333,
  31954. 'cent': 556,
  31955. 'sterling': 556,
  31956. 'fraction': 167,
  31957. 'yen': 556,
  31958. 'florin': 556,
  31959. 'section': 556,
  31960. 'currency': 556,
  31961. 'quotesingle': 191,
  31962. 'quotedblleft': 333,
  31963. 'guillemotleft': 556,
  31964. 'guilsinglleft': 333,
  31965. 'guilsinglright': 333,
  31966. 'fi': 500,
  31967. 'fl': 500,
  31968. 'endash': 556,
  31969. 'dagger': 556,
  31970. 'daggerdbl': 556,
  31971. 'periodcentered': 278,
  31972. 'paragraph': 537,
  31973. 'bullet': 350,
  31974. 'quotesinglbase': 222,
  31975. 'quotedblbase': 333,
  31976. 'quotedblright': 333,
  31977. 'guillemotright': 556,
  31978. 'ellipsis': 1000,
  31979. 'perthousand': 1000,
  31980. 'questiondown': 611,
  31981. 'grave': 333,
  31982. 'acute': 333,
  31983. 'circumflex': 333,
  31984. 'tilde': 333,
  31985. 'macron': 333,
  31986. 'breve': 333,
  31987. 'dotaccent': 333,
  31988. 'dieresis': 333,
  31989. 'ring': 333,
  31990. 'cedilla': 333,
  31991. 'hungarumlaut': 333,
  31992. 'ogonek': 333,
  31993. 'caron': 333,
  31994. 'emdash': 1000,
  31995. 'AE': 1000,
  31996. 'ordfeminine': 370,
  31997. 'Lslash': 556,
  31998. 'Oslash': 778,
  31999. 'OE': 1000,
  32000. 'ordmasculine': 365,
  32001. 'ae': 889,
  32002. 'dotlessi': 278,
  32003. 'lslash': 222,
  32004. 'oslash': 611,
  32005. 'oe': 944,
  32006. 'germandbls': 611,
  32007. 'Idieresis': 278,
  32008. 'eacute': 556,
  32009. 'abreve': 556,
  32010. 'uhungarumlaut': 556,
  32011. 'ecaron': 556,
  32012. 'Ydieresis': 667,
  32013. 'divide': 584,
  32014. 'Yacute': 667,
  32015. 'Acircumflex': 667,
  32016. 'aacute': 556,
  32017. 'Ucircumflex': 722,
  32018. 'yacute': 500,
  32019. 'scommaaccent': 500,
  32020. 'ecircumflex': 556,
  32021. 'Uring': 722,
  32022. 'Udieresis': 722,
  32023. 'aogonek': 556,
  32024. 'Uacute': 722,
  32025. 'uogonek': 556,
  32026. 'Edieresis': 667,
  32027. 'Dcroat': 722,
  32028. 'commaaccent': 250,
  32029. 'copyright': 737,
  32030. 'Emacron': 667,
  32031. 'ccaron': 500,
  32032. 'aring': 556,
  32033. 'Ncommaaccent': 722,
  32034. 'lacute': 222,
  32035. 'agrave': 556,
  32036. 'Tcommaaccent': 611,
  32037. 'Cacute': 722,
  32038. 'atilde': 556,
  32039. 'Edotaccent': 667,
  32040. 'scaron': 500,
  32041. 'scedilla': 500,
  32042. 'iacute': 278,
  32043. 'lozenge': 471,
  32044. 'Rcaron': 722,
  32045. 'Gcommaaccent': 778,
  32046. 'ucircumflex': 556,
  32047. 'acircumflex': 556,
  32048. 'Amacron': 667,
  32049. 'rcaron': 333,
  32050. 'ccedilla': 500,
  32051. 'Zdotaccent': 611,
  32052. 'Thorn': 667,
  32053. 'Omacron': 778,
  32054. 'Racute': 722,
  32055. 'Sacute': 667,
  32056. 'dcaron': 643,
  32057. 'Umacron': 722,
  32058. 'uring': 556,
  32059. 'threesuperior': 333,
  32060. 'Ograve': 778,
  32061. 'Agrave': 667,
  32062. 'Abreve': 667,
  32063. 'multiply': 584,
  32064. 'uacute': 556,
  32065. 'Tcaron': 611,
  32066. 'partialdiff': 476,
  32067. 'ydieresis': 500,
  32068. 'Nacute': 722,
  32069. 'icircumflex': 278,
  32070. 'Ecircumflex': 667,
  32071. 'adieresis': 556,
  32072. 'edieresis': 556,
  32073. 'cacute': 500,
  32074. 'nacute': 556,
  32075. 'umacron': 556,
  32076. 'Ncaron': 722,
  32077. 'Iacute': 278,
  32078. 'plusminus': 584,
  32079. 'brokenbar': 260,
  32080. 'registered': 737,
  32081. 'Gbreve': 778,
  32082. 'Idotaccent': 278,
  32083. 'summation': 600,
  32084. 'Egrave': 667,
  32085. 'racute': 333,
  32086. 'omacron': 556,
  32087. 'Zacute': 611,
  32088. 'Zcaron': 611,
  32089. 'greaterequal': 549,
  32090. 'Eth': 722,
  32091. 'Ccedilla': 722,
  32092. 'lcommaaccent': 222,
  32093. 'tcaron': 317,
  32094. 'eogonek': 556,
  32095. 'Uogonek': 722,
  32096. 'Aacute': 667,
  32097. 'Adieresis': 667,
  32098. 'egrave': 556,
  32099. 'zacute': 500,
  32100. 'iogonek': 222,
  32101. 'Oacute': 778,
  32102. 'oacute': 556,
  32103. 'amacron': 556,
  32104. 'sacute': 500,
  32105. 'idieresis': 278,
  32106. 'Ocircumflex': 778,
  32107. 'Ugrave': 722,
  32108. 'Delta': 612,
  32109. 'thorn': 556,
  32110. 'twosuperior': 333,
  32111. 'Odieresis': 778,
  32112. 'mu': 556,
  32113. 'igrave': 278,
  32114. 'ohungarumlaut': 556,
  32115. 'Eogonek': 667,
  32116. 'dcroat': 556,
  32117. 'threequarters': 834,
  32118. 'Scedilla': 667,
  32119. 'lcaron': 299,
  32120. 'Kcommaaccent': 667,
  32121. 'Lacute': 556,
  32122. 'trademark': 1000,
  32123. 'edotaccent': 556,
  32124. 'Igrave': 278,
  32125. 'Imacron': 278,
  32126. 'Lcaron': 556,
  32127. 'onehalf': 834,
  32128. 'lessequal': 549,
  32129. 'ocircumflex': 556,
  32130. 'ntilde': 556,
  32131. 'Uhungarumlaut': 722,
  32132. 'Eacute': 667,
  32133. 'emacron': 556,
  32134. 'gbreve': 556,
  32135. 'onequarter': 834,
  32136. 'Scaron': 667,
  32137. 'Scommaaccent': 667,
  32138. 'Ohungarumlaut': 778,
  32139. 'degree': 400,
  32140. 'ograve': 556,
  32141. 'Ccaron': 722,
  32142. 'ugrave': 556,
  32143. 'radical': 453,
  32144. 'Dcaron': 722,
  32145. 'rcommaaccent': 333,
  32146. 'Ntilde': 722,
  32147. 'otilde': 556,
  32148. 'Rcommaaccent': 722,
  32149. 'Lcommaaccent': 556,
  32150. 'Atilde': 667,
  32151. 'Aogonek': 667,
  32152. 'Aring': 667,
  32153. 'Otilde': 778,
  32154. 'zdotaccent': 500,
  32155. 'Ecaron': 667,
  32156. 'Iogonek': 278,
  32157. 'kcommaaccent': 500,
  32158. 'minus': 584,
  32159. 'Icircumflex': 278,
  32160. 'ncaron': 556,
  32161. 'tcommaaccent': 278,
  32162. 'logicalnot': 584,
  32163. 'odieresis': 556,
  32164. 'udieresis': 556,
  32165. 'notequal': 549,
  32166. 'gcommaaccent': 556,
  32167. 'eth': 556,
  32168. 'zcaron': 500,
  32169. 'ncommaaccent': 556,
  32170. 'onesuperior': 333,
  32171. 'imacron': 278,
  32172. 'Euro': 556
  32173. },
  32174. 'Symbol': {
  32175. 'space': 250,
  32176. 'exclam': 333,
  32177. 'universal': 713,
  32178. 'numbersign': 500,
  32179. 'existential': 549,
  32180. 'percent': 833,
  32181. 'ampersand': 778,
  32182. 'suchthat': 439,
  32183. 'parenleft': 333,
  32184. 'parenright': 333,
  32185. 'asteriskmath': 500,
  32186. 'plus': 549,
  32187. 'comma': 250,
  32188. 'minus': 549,
  32189. 'period': 250,
  32190. 'slash': 278,
  32191. 'zero': 500,
  32192. 'one': 500,
  32193. 'two': 500,
  32194. 'three': 500,
  32195. 'four': 500,
  32196. 'five': 500,
  32197. 'six': 500,
  32198. 'seven': 500,
  32199. 'eight': 500,
  32200. 'nine': 500,
  32201. 'colon': 278,
  32202. 'semicolon': 278,
  32203. 'less': 549,
  32204. 'equal': 549,
  32205. 'greater': 549,
  32206. 'question': 444,
  32207. 'congruent': 549,
  32208. 'Alpha': 722,
  32209. 'Beta': 667,
  32210. 'Chi': 722,
  32211. 'Delta': 612,
  32212. 'Epsilon': 611,
  32213. 'Phi': 763,
  32214. 'Gamma': 603,
  32215. 'Eta': 722,
  32216. 'Iota': 333,
  32217. 'theta1': 631,
  32218. 'Kappa': 722,
  32219. 'Lambda': 686,
  32220. 'Mu': 889,
  32221. 'Nu': 722,
  32222. 'Omicron': 722,
  32223. 'Pi': 768,
  32224. 'Theta': 741,
  32225. 'Rho': 556,
  32226. 'Sigma': 592,
  32227. 'Tau': 611,
  32228. 'Upsilon': 690,
  32229. 'sigma1': 439,
  32230. 'Omega': 768,
  32231. 'Xi': 645,
  32232. 'Psi': 795,
  32233. 'Zeta': 611,
  32234. 'bracketleft': 333,
  32235. 'therefore': 863,
  32236. 'bracketright': 333,
  32237. 'perpendicular': 658,
  32238. 'underscore': 500,
  32239. 'radicalex': 500,
  32240. 'alpha': 631,
  32241. 'beta': 549,
  32242. 'chi': 549,
  32243. 'delta': 494,
  32244. 'epsilon': 439,
  32245. 'phi': 521,
  32246. 'gamma': 411,
  32247. 'eta': 603,
  32248. 'iota': 329,
  32249. 'phi1': 603,
  32250. 'kappa': 549,
  32251. 'lambda': 549,
  32252. 'mu': 576,
  32253. 'nu': 521,
  32254. 'omicron': 549,
  32255. 'pi': 549,
  32256. 'theta': 521,
  32257. 'rho': 549,
  32258. 'sigma': 603,
  32259. 'tau': 439,
  32260. 'upsilon': 576,
  32261. 'omega1': 713,
  32262. 'omega': 686,
  32263. 'xi': 493,
  32264. 'psi': 686,
  32265. 'zeta': 494,
  32266. 'braceleft': 480,
  32267. 'bar': 200,
  32268. 'braceright': 480,
  32269. 'similar': 549,
  32270. 'Euro': 750,
  32271. 'Upsilon1': 620,
  32272. 'minute': 247,
  32273. 'lessequal': 549,
  32274. 'fraction': 167,
  32275. 'infinity': 713,
  32276. 'florin': 500,
  32277. 'club': 753,
  32278. 'diamond': 753,
  32279. 'heart': 753,
  32280. 'spade': 753,
  32281. 'arrowboth': 1042,
  32282. 'arrowleft': 987,
  32283. 'arrowup': 603,
  32284. 'arrowright': 987,
  32285. 'arrowdown': 603,
  32286. 'degree': 400,
  32287. 'plusminus': 549,
  32288. 'second': 411,
  32289. 'greaterequal': 549,
  32290. 'multiply': 549,
  32291. 'proportional': 713,
  32292. 'partialdiff': 494,
  32293. 'bullet': 460,
  32294. 'divide': 549,
  32295. 'notequal': 549,
  32296. 'equivalence': 549,
  32297. 'approxequal': 549,
  32298. 'ellipsis': 1000,
  32299. 'arrowvertex': 603,
  32300. 'arrowhorizex': 1000,
  32301. 'carriagereturn': 658,
  32302. 'aleph': 823,
  32303. 'Ifraktur': 686,
  32304. 'Rfraktur': 795,
  32305. 'weierstrass': 987,
  32306. 'circlemultiply': 768,
  32307. 'circleplus': 768,
  32308. 'emptyset': 823,
  32309. 'intersection': 768,
  32310. 'union': 768,
  32311. 'propersuperset': 713,
  32312. 'reflexsuperset': 713,
  32313. 'notsubset': 713,
  32314. 'propersubset': 713,
  32315. 'reflexsubset': 713,
  32316. 'element': 713,
  32317. 'notelement': 713,
  32318. 'angle': 768,
  32319. 'gradient': 713,
  32320. 'registerserif': 790,
  32321. 'copyrightserif': 790,
  32322. 'trademarkserif': 890,
  32323. 'product': 823,
  32324. 'radical': 549,
  32325. 'dotmath': 250,
  32326. 'logicalnot': 713,
  32327. 'logicaland': 603,
  32328. 'logicalor': 603,
  32329. 'arrowdblboth': 1042,
  32330. 'arrowdblleft': 987,
  32331. 'arrowdblup': 603,
  32332. 'arrowdblright': 987,
  32333. 'arrowdbldown': 603,
  32334. 'lozenge': 494,
  32335. 'angleleft': 329,
  32336. 'registersans': 790,
  32337. 'copyrightsans': 790,
  32338. 'trademarksans': 786,
  32339. 'summation': 713,
  32340. 'parenlefttp': 384,
  32341. 'parenleftex': 384,
  32342. 'parenleftbt': 384,
  32343. 'bracketlefttp': 384,
  32344. 'bracketleftex': 384,
  32345. 'bracketleftbt': 384,
  32346. 'bracelefttp': 494,
  32347. 'braceleftmid': 494,
  32348. 'braceleftbt': 494,
  32349. 'braceex': 494,
  32350. 'angleright': 329,
  32351. 'integral': 274,
  32352. 'integraltp': 686,
  32353. 'integralex': 686,
  32354. 'integralbt': 686,
  32355. 'parenrighttp': 384,
  32356. 'parenrightex': 384,
  32357. 'parenrightbt': 384,
  32358. 'bracketrighttp': 384,
  32359. 'bracketrightex': 384,
  32360. 'bracketrightbt': 384,
  32361. 'bracerighttp': 494,
  32362. 'bracerightmid': 494,
  32363. 'bracerightbt': 494,
  32364. 'apple': 790
  32365. },
  32366. 'Times-Roman': {
  32367. 'space': 250,
  32368. 'exclam': 333,
  32369. 'quotedbl': 408,
  32370. 'numbersign': 500,
  32371. 'dollar': 500,
  32372. 'percent': 833,
  32373. 'ampersand': 778,
  32374. 'quoteright': 333,
  32375. 'parenleft': 333,
  32376. 'parenright': 333,
  32377. 'asterisk': 500,
  32378. 'plus': 564,
  32379. 'comma': 250,
  32380. 'hyphen': 333,
  32381. 'period': 250,
  32382. 'slash': 278,
  32383. 'zero': 500,
  32384. 'one': 500,
  32385. 'two': 500,
  32386. 'three': 500,
  32387. 'four': 500,
  32388. 'five': 500,
  32389. 'six': 500,
  32390. 'seven': 500,
  32391. 'eight': 500,
  32392. 'nine': 500,
  32393. 'colon': 278,
  32394. 'semicolon': 278,
  32395. 'less': 564,
  32396. 'equal': 564,
  32397. 'greater': 564,
  32398. 'question': 444,
  32399. 'at': 921,
  32400. 'A': 722,
  32401. 'B': 667,
  32402. 'C': 667,
  32403. 'D': 722,
  32404. 'E': 611,
  32405. 'F': 556,
  32406. 'G': 722,
  32407. 'H': 722,
  32408. 'I': 333,
  32409. 'J': 389,
  32410. 'K': 722,
  32411. 'L': 611,
  32412. 'M': 889,
  32413. 'N': 722,
  32414. 'O': 722,
  32415. 'P': 556,
  32416. 'Q': 722,
  32417. 'R': 667,
  32418. 'S': 556,
  32419. 'T': 611,
  32420. 'U': 722,
  32421. 'V': 722,
  32422. 'W': 944,
  32423. 'X': 722,
  32424. 'Y': 722,
  32425. 'Z': 611,
  32426. 'bracketleft': 333,
  32427. 'backslash': 278,
  32428. 'bracketright': 333,
  32429. 'asciicircum': 469,
  32430. 'underscore': 500,
  32431. 'quoteleft': 333,
  32432. 'a': 444,
  32433. 'b': 500,
  32434. 'c': 444,
  32435. 'd': 500,
  32436. 'e': 444,
  32437. 'f': 333,
  32438. 'g': 500,
  32439. 'h': 500,
  32440. 'i': 278,
  32441. 'j': 278,
  32442. 'k': 500,
  32443. 'l': 278,
  32444. 'm': 778,
  32445. 'n': 500,
  32446. 'o': 500,
  32447. 'p': 500,
  32448. 'q': 500,
  32449. 'r': 333,
  32450. 's': 389,
  32451. 't': 278,
  32452. 'u': 500,
  32453. 'v': 500,
  32454. 'w': 722,
  32455. 'x': 500,
  32456. 'y': 500,
  32457. 'z': 444,
  32458. 'braceleft': 480,
  32459. 'bar': 200,
  32460. 'braceright': 480,
  32461. 'asciitilde': 541,
  32462. 'exclamdown': 333,
  32463. 'cent': 500,
  32464. 'sterling': 500,
  32465. 'fraction': 167,
  32466. 'yen': 500,
  32467. 'florin': 500,
  32468. 'section': 500,
  32469. 'currency': 500,
  32470. 'quotesingle': 180,
  32471. 'quotedblleft': 444,
  32472. 'guillemotleft': 500,
  32473. 'guilsinglleft': 333,
  32474. 'guilsinglright': 333,
  32475. 'fi': 556,
  32476. 'fl': 556,
  32477. 'endash': 500,
  32478. 'dagger': 500,
  32479. 'daggerdbl': 500,
  32480. 'periodcentered': 250,
  32481. 'paragraph': 453,
  32482. 'bullet': 350,
  32483. 'quotesinglbase': 333,
  32484. 'quotedblbase': 444,
  32485. 'quotedblright': 444,
  32486. 'guillemotright': 500,
  32487. 'ellipsis': 1000,
  32488. 'perthousand': 1000,
  32489. 'questiondown': 444,
  32490. 'grave': 333,
  32491. 'acute': 333,
  32492. 'circumflex': 333,
  32493. 'tilde': 333,
  32494. 'macron': 333,
  32495. 'breve': 333,
  32496. 'dotaccent': 333,
  32497. 'dieresis': 333,
  32498. 'ring': 333,
  32499. 'cedilla': 333,
  32500. 'hungarumlaut': 333,
  32501. 'ogonek': 333,
  32502. 'caron': 333,
  32503. 'emdash': 1000,
  32504. 'AE': 889,
  32505. 'ordfeminine': 276,
  32506. 'Lslash': 611,
  32507. 'Oslash': 722,
  32508. 'OE': 889,
  32509. 'ordmasculine': 310,
  32510. 'ae': 667,
  32511. 'dotlessi': 278,
  32512. 'lslash': 278,
  32513. 'oslash': 500,
  32514. 'oe': 722,
  32515. 'germandbls': 500,
  32516. 'Idieresis': 333,
  32517. 'eacute': 444,
  32518. 'abreve': 444,
  32519. 'uhungarumlaut': 500,
  32520. 'ecaron': 444,
  32521. 'Ydieresis': 722,
  32522. 'divide': 564,
  32523. 'Yacute': 722,
  32524. 'Acircumflex': 722,
  32525. 'aacute': 444,
  32526. 'Ucircumflex': 722,
  32527. 'yacute': 500,
  32528. 'scommaaccent': 389,
  32529. 'ecircumflex': 444,
  32530. 'Uring': 722,
  32531. 'Udieresis': 722,
  32532. 'aogonek': 444,
  32533. 'Uacute': 722,
  32534. 'uogonek': 500,
  32535. 'Edieresis': 611,
  32536. 'Dcroat': 722,
  32537. 'commaaccent': 250,
  32538. 'copyright': 760,
  32539. 'Emacron': 611,
  32540. 'ccaron': 444,
  32541. 'aring': 444,
  32542. 'Ncommaaccent': 722,
  32543. 'lacute': 278,
  32544. 'agrave': 444,
  32545. 'Tcommaaccent': 611,
  32546. 'Cacute': 667,
  32547. 'atilde': 444,
  32548. 'Edotaccent': 611,
  32549. 'scaron': 389,
  32550. 'scedilla': 389,
  32551. 'iacute': 278,
  32552. 'lozenge': 471,
  32553. 'Rcaron': 667,
  32554. 'Gcommaaccent': 722,
  32555. 'ucircumflex': 500,
  32556. 'acircumflex': 444,
  32557. 'Amacron': 722,
  32558. 'rcaron': 333,
  32559. 'ccedilla': 444,
  32560. 'Zdotaccent': 611,
  32561. 'Thorn': 556,
  32562. 'Omacron': 722,
  32563. 'Racute': 667,
  32564. 'Sacute': 556,
  32565. 'dcaron': 588,
  32566. 'Umacron': 722,
  32567. 'uring': 500,
  32568. 'threesuperior': 300,
  32569. 'Ograve': 722,
  32570. 'Agrave': 722,
  32571. 'Abreve': 722,
  32572. 'multiply': 564,
  32573. 'uacute': 500,
  32574. 'Tcaron': 611,
  32575. 'partialdiff': 476,
  32576. 'ydieresis': 500,
  32577. 'Nacute': 722,
  32578. 'icircumflex': 278,
  32579. 'Ecircumflex': 611,
  32580. 'adieresis': 444,
  32581. 'edieresis': 444,
  32582. 'cacute': 444,
  32583. 'nacute': 500,
  32584. 'umacron': 500,
  32585. 'Ncaron': 722,
  32586. 'Iacute': 333,
  32587. 'plusminus': 564,
  32588. 'brokenbar': 200,
  32589. 'registered': 760,
  32590. 'Gbreve': 722,
  32591. 'Idotaccent': 333,
  32592. 'summation': 600,
  32593. 'Egrave': 611,
  32594. 'racute': 333,
  32595. 'omacron': 500,
  32596. 'Zacute': 611,
  32597. 'Zcaron': 611,
  32598. 'greaterequal': 549,
  32599. 'Eth': 722,
  32600. 'Ccedilla': 667,
  32601. 'lcommaaccent': 278,
  32602. 'tcaron': 326,
  32603. 'eogonek': 444,
  32604. 'Uogonek': 722,
  32605. 'Aacute': 722,
  32606. 'Adieresis': 722,
  32607. 'egrave': 444,
  32608. 'zacute': 444,
  32609. 'iogonek': 278,
  32610. 'Oacute': 722,
  32611. 'oacute': 500,
  32612. 'amacron': 444,
  32613. 'sacute': 389,
  32614. 'idieresis': 278,
  32615. 'Ocircumflex': 722,
  32616. 'Ugrave': 722,
  32617. 'Delta': 612,
  32618. 'thorn': 500,
  32619. 'twosuperior': 300,
  32620. 'Odieresis': 722,
  32621. 'mu': 500,
  32622. 'igrave': 278,
  32623. 'ohungarumlaut': 500,
  32624. 'Eogonek': 611,
  32625. 'dcroat': 500,
  32626. 'threequarters': 750,
  32627. 'Scedilla': 556,
  32628. 'lcaron': 344,
  32629. 'Kcommaaccent': 722,
  32630. 'Lacute': 611,
  32631. 'trademark': 980,
  32632. 'edotaccent': 444,
  32633. 'Igrave': 333,
  32634. 'Imacron': 333,
  32635. 'Lcaron': 611,
  32636. 'onehalf': 750,
  32637. 'lessequal': 549,
  32638. 'ocircumflex': 500,
  32639. 'ntilde': 500,
  32640. 'Uhungarumlaut': 722,
  32641. 'Eacute': 611,
  32642. 'emacron': 444,
  32643. 'gbreve': 500,
  32644. 'onequarter': 750,
  32645. 'Scaron': 556,
  32646. 'Scommaaccent': 556,
  32647. 'Ohungarumlaut': 722,
  32648. 'degree': 400,
  32649. 'ograve': 500,
  32650. 'Ccaron': 667,
  32651. 'ugrave': 500,
  32652. 'radical': 453,
  32653. 'Dcaron': 722,
  32654. 'rcommaaccent': 333,
  32655. 'Ntilde': 722,
  32656. 'otilde': 500,
  32657. 'Rcommaaccent': 667,
  32658. 'Lcommaaccent': 611,
  32659. 'Atilde': 722,
  32660. 'Aogonek': 722,
  32661. 'Aring': 722,
  32662. 'Otilde': 722,
  32663. 'zdotaccent': 444,
  32664. 'Ecaron': 611,
  32665. 'Iogonek': 333,
  32666. 'kcommaaccent': 500,
  32667. 'minus': 564,
  32668. 'Icircumflex': 333,
  32669. 'ncaron': 500,
  32670. 'tcommaaccent': 278,
  32671. 'logicalnot': 564,
  32672. 'odieresis': 500,
  32673. 'udieresis': 500,
  32674. 'notequal': 549,
  32675. 'gcommaaccent': 500,
  32676. 'eth': 500,
  32677. 'zcaron': 444,
  32678. 'ncommaaccent': 500,
  32679. 'onesuperior': 300,
  32680. 'imacron': 278,
  32681. 'Euro': 500
  32682. },
  32683. 'Times-Bold': {
  32684. 'space': 250,
  32685. 'exclam': 333,
  32686. 'quotedbl': 555,
  32687. 'numbersign': 500,
  32688. 'dollar': 500,
  32689. 'percent': 1000,
  32690. 'ampersand': 833,
  32691. 'quoteright': 333,
  32692. 'parenleft': 333,
  32693. 'parenright': 333,
  32694. 'asterisk': 500,
  32695. 'plus': 570,
  32696. 'comma': 250,
  32697. 'hyphen': 333,
  32698. 'period': 250,
  32699. 'slash': 278,
  32700. 'zero': 500,
  32701. 'one': 500,
  32702. 'two': 500,
  32703. 'three': 500,
  32704. 'four': 500,
  32705. 'five': 500,
  32706. 'six': 500,
  32707. 'seven': 500,
  32708. 'eight': 500,
  32709. 'nine': 500,
  32710. 'colon': 333,
  32711. 'semicolon': 333,
  32712. 'less': 570,
  32713. 'equal': 570,
  32714. 'greater': 570,
  32715. 'question': 500,
  32716. 'at': 930,
  32717. 'A': 722,
  32718. 'B': 667,
  32719. 'C': 722,
  32720. 'D': 722,
  32721. 'E': 667,
  32722. 'F': 611,
  32723. 'G': 778,
  32724. 'H': 778,
  32725. 'I': 389,
  32726. 'J': 500,
  32727. 'K': 778,
  32728. 'L': 667,
  32729. 'M': 944,
  32730. 'N': 722,
  32731. 'O': 778,
  32732. 'P': 611,
  32733. 'Q': 778,
  32734. 'R': 722,
  32735. 'S': 556,
  32736. 'T': 667,
  32737. 'U': 722,
  32738. 'V': 722,
  32739. 'W': 1000,
  32740. 'X': 722,
  32741. 'Y': 722,
  32742. 'Z': 667,
  32743. 'bracketleft': 333,
  32744. 'backslash': 278,
  32745. 'bracketright': 333,
  32746. 'asciicircum': 581,
  32747. 'underscore': 500,
  32748. 'quoteleft': 333,
  32749. 'a': 500,
  32750. 'b': 556,
  32751. 'c': 444,
  32752. 'd': 556,
  32753. 'e': 444,
  32754. 'f': 333,
  32755. 'g': 500,
  32756. 'h': 556,
  32757. 'i': 278,
  32758. 'j': 333,
  32759. 'k': 556,
  32760. 'l': 278,
  32761. 'm': 833,
  32762. 'n': 556,
  32763. 'o': 500,
  32764. 'p': 556,
  32765. 'q': 556,
  32766. 'r': 444,
  32767. 's': 389,
  32768. 't': 333,
  32769. 'u': 556,
  32770. 'v': 500,
  32771. 'w': 722,
  32772. 'x': 500,
  32773. 'y': 500,
  32774. 'z': 444,
  32775. 'braceleft': 394,
  32776. 'bar': 220,
  32777. 'braceright': 394,
  32778. 'asciitilde': 520,
  32779. 'exclamdown': 333,
  32780. 'cent': 500,
  32781. 'sterling': 500,
  32782. 'fraction': 167,
  32783. 'yen': 500,
  32784. 'florin': 500,
  32785. 'section': 500,
  32786. 'currency': 500,
  32787. 'quotesingle': 278,
  32788. 'quotedblleft': 500,
  32789. 'guillemotleft': 500,
  32790. 'guilsinglleft': 333,
  32791. 'guilsinglright': 333,
  32792. 'fi': 556,
  32793. 'fl': 556,
  32794. 'endash': 500,
  32795. 'dagger': 500,
  32796. 'daggerdbl': 500,
  32797. 'periodcentered': 250,
  32798. 'paragraph': 540,
  32799. 'bullet': 350,
  32800. 'quotesinglbase': 333,
  32801. 'quotedblbase': 500,
  32802. 'quotedblright': 500,
  32803. 'guillemotright': 500,
  32804. 'ellipsis': 1000,
  32805. 'perthousand': 1000,
  32806. 'questiondown': 500,
  32807. 'grave': 333,
  32808. 'acute': 333,
  32809. 'circumflex': 333,
  32810. 'tilde': 333,
  32811. 'macron': 333,
  32812. 'breve': 333,
  32813. 'dotaccent': 333,
  32814. 'dieresis': 333,
  32815. 'ring': 333,
  32816. 'cedilla': 333,
  32817. 'hungarumlaut': 333,
  32818. 'ogonek': 333,
  32819. 'caron': 333,
  32820. 'emdash': 1000,
  32821. 'AE': 1000,
  32822. 'ordfeminine': 300,
  32823. 'Lslash': 667,
  32824. 'Oslash': 778,
  32825. 'OE': 1000,
  32826. 'ordmasculine': 330,
  32827. 'ae': 722,
  32828. 'dotlessi': 278,
  32829. 'lslash': 278,
  32830. 'oslash': 500,
  32831. 'oe': 722,
  32832. 'germandbls': 556,
  32833. 'Idieresis': 389,
  32834. 'eacute': 444,
  32835. 'abreve': 500,
  32836. 'uhungarumlaut': 556,
  32837. 'ecaron': 444,
  32838. 'Ydieresis': 722,
  32839. 'divide': 570,
  32840. 'Yacute': 722,
  32841. 'Acircumflex': 722,
  32842. 'aacute': 500,
  32843. 'Ucircumflex': 722,
  32844. 'yacute': 500,
  32845. 'scommaaccent': 389,
  32846. 'ecircumflex': 444,
  32847. 'Uring': 722,
  32848. 'Udieresis': 722,
  32849. 'aogonek': 500,
  32850. 'Uacute': 722,
  32851. 'uogonek': 556,
  32852. 'Edieresis': 667,
  32853. 'Dcroat': 722,
  32854. 'commaaccent': 250,
  32855. 'copyright': 747,
  32856. 'Emacron': 667,
  32857. 'ccaron': 444,
  32858. 'aring': 500,
  32859. 'Ncommaaccent': 722,
  32860. 'lacute': 278,
  32861. 'agrave': 500,
  32862. 'Tcommaaccent': 667,
  32863. 'Cacute': 722,
  32864. 'atilde': 500,
  32865. 'Edotaccent': 667,
  32866. 'scaron': 389,
  32867. 'scedilla': 389,
  32868. 'iacute': 278,
  32869. 'lozenge': 494,
  32870. 'Rcaron': 722,
  32871. 'Gcommaaccent': 778,
  32872. 'ucircumflex': 556,
  32873. 'acircumflex': 500,
  32874. 'Amacron': 722,
  32875. 'rcaron': 444,
  32876. 'ccedilla': 444,
  32877. 'Zdotaccent': 667,
  32878. 'Thorn': 611,
  32879. 'Omacron': 778,
  32880. 'Racute': 722,
  32881. 'Sacute': 556,
  32882. 'dcaron': 672,
  32883. 'Umacron': 722,
  32884. 'uring': 556,
  32885. 'threesuperior': 300,
  32886. 'Ograve': 778,
  32887. 'Agrave': 722,
  32888. 'Abreve': 722,
  32889. 'multiply': 570,
  32890. 'uacute': 556,
  32891. 'Tcaron': 667,
  32892. 'partialdiff': 494,
  32893. 'ydieresis': 500,
  32894. 'Nacute': 722,
  32895. 'icircumflex': 278,
  32896. 'Ecircumflex': 667,
  32897. 'adieresis': 500,
  32898. 'edieresis': 444,
  32899. 'cacute': 444,
  32900. 'nacute': 556,
  32901. 'umacron': 556,
  32902. 'Ncaron': 722,
  32903. 'Iacute': 389,
  32904. 'plusminus': 570,
  32905. 'brokenbar': 220,
  32906. 'registered': 747,
  32907. 'Gbreve': 778,
  32908. 'Idotaccent': 389,
  32909. 'summation': 600,
  32910. 'Egrave': 667,
  32911. 'racute': 444,
  32912. 'omacron': 500,
  32913. 'Zacute': 667,
  32914. 'Zcaron': 667,
  32915. 'greaterequal': 549,
  32916. 'Eth': 722,
  32917. 'Ccedilla': 722,
  32918. 'lcommaaccent': 278,
  32919. 'tcaron': 416,
  32920. 'eogonek': 444,
  32921. 'Uogonek': 722,
  32922. 'Aacute': 722,
  32923. 'Adieresis': 722,
  32924. 'egrave': 444,
  32925. 'zacute': 444,
  32926. 'iogonek': 278,
  32927. 'Oacute': 778,
  32928. 'oacute': 500,
  32929. 'amacron': 500,
  32930. 'sacute': 389,
  32931. 'idieresis': 278,
  32932. 'Ocircumflex': 778,
  32933. 'Ugrave': 722,
  32934. 'Delta': 612,
  32935. 'thorn': 556,
  32936. 'twosuperior': 300,
  32937. 'Odieresis': 778,
  32938. 'mu': 556,
  32939. 'igrave': 278,
  32940. 'ohungarumlaut': 500,
  32941. 'Eogonek': 667,
  32942. 'dcroat': 556,
  32943. 'threequarters': 750,
  32944. 'Scedilla': 556,
  32945. 'lcaron': 394,
  32946. 'Kcommaaccent': 778,
  32947. 'Lacute': 667,
  32948. 'trademark': 1000,
  32949. 'edotaccent': 444,
  32950. 'Igrave': 389,
  32951. 'Imacron': 389,
  32952. 'Lcaron': 667,
  32953. 'onehalf': 750,
  32954. 'lessequal': 549,
  32955. 'ocircumflex': 500,
  32956. 'ntilde': 556,
  32957. 'Uhungarumlaut': 722,
  32958. 'Eacute': 667,
  32959. 'emacron': 444,
  32960. 'gbreve': 500,
  32961. 'onequarter': 750,
  32962. 'Scaron': 556,
  32963. 'Scommaaccent': 556,
  32964. 'Ohungarumlaut': 778,
  32965. 'degree': 400,
  32966. 'ograve': 500,
  32967. 'Ccaron': 722,
  32968. 'ugrave': 556,
  32969. 'radical': 549,
  32970. 'Dcaron': 722,
  32971. 'rcommaaccent': 444,
  32972. 'Ntilde': 722,
  32973. 'otilde': 500,
  32974. 'Rcommaaccent': 722,
  32975. 'Lcommaaccent': 667,
  32976. 'Atilde': 722,
  32977. 'Aogonek': 722,
  32978. 'Aring': 722,
  32979. 'Otilde': 778,
  32980. 'zdotaccent': 444,
  32981. 'Ecaron': 667,
  32982. 'Iogonek': 389,
  32983. 'kcommaaccent': 556,
  32984. 'minus': 570,
  32985. 'Icircumflex': 389,
  32986. 'ncaron': 556,
  32987. 'tcommaaccent': 333,
  32988. 'logicalnot': 570,
  32989. 'odieresis': 500,
  32990. 'udieresis': 556,
  32991. 'notequal': 549,
  32992. 'gcommaaccent': 500,
  32993. 'eth': 500,
  32994. 'zcaron': 444,
  32995. 'ncommaaccent': 556,
  32996. 'onesuperior': 300,
  32997. 'imacron': 278,
  32998. 'Euro': 500
  32999. },
  33000. 'Times-BoldItalic': {
  33001. 'space': 250,
  33002. 'exclam': 389,
  33003. 'quotedbl': 555,
  33004. 'numbersign': 500,
  33005. 'dollar': 500,
  33006. 'percent': 833,
  33007. 'ampersand': 778,
  33008. 'quoteright': 333,
  33009. 'parenleft': 333,
  33010. 'parenright': 333,
  33011. 'asterisk': 500,
  33012. 'plus': 570,
  33013. 'comma': 250,
  33014. 'hyphen': 333,
  33015. 'period': 250,
  33016. 'slash': 278,
  33017. 'zero': 500,
  33018. 'one': 500,
  33019. 'two': 500,
  33020. 'three': 500,
  33021. 'four': 500,
  33022. 'five': 500,
  33023. 'six': 500,
  33024. 'seven': 500,
  33025. 'eight': 500,
  33026. 'nine': 500,
  33027. 'colon': 333,
  33028. 'semicolon': 333,
  33029. 'less': 570,
  33030. 'equal': 570,
  33031. 'greater': 570,
  33032. 'question': 500,
  33033. 'at': 832,
  33034. 'A': 667,
  33035. 'B': 667,
  33036. 'C': 667,
  33037. 'D': 722,
  33038. 'E': 667,
  33039. 'F': 667,
  33040. 'G': 722,
  33041. 'H': 778,
  33042. 'I': 389,
  33043. 'J': 500,
  33044. 'K': 667,
  33045. 'L': 611,
  33046. 'M': 889,
  33047. 'N': 722,
  33048. 'O': 722,
  33049. 'P': 611,
  33050. 'Q': 722,
  33051. 'R': 667,
  33052. 'S': 556,
  33053. 'T': 611,
  33054. 'U': 722,
  33055. 'V': 667,
  33056. 'W': 889,
  33057. 'X': 667,
  33058. 'Y': 611,
  33059. 'Z': 611,
  33060. 'bracketleft': 333,
  33061. 'backslash': 278,
  33062. 'bracketright': 333,
  33063. 'asciicircum': 570,
  33064. 'underscore': 500,
  33065. 'quoteleft': 333,
  33066. 'a': 500,
  33067. 'b': 500,
  33068. 'c': 444,
  33069. 'd': 500,
  33070. 'e': 444,
  33071. 'f': 333,
  33072. 'g': 500,
  33073. 'h': 556,
  33074. 'i': 278,
  33075. 'j': 278,
  33076. 'k': 500,
  33077. 'l': 278,
  33078. 'm': 778,
  33079. 'n': 556,
  33080. 'o': 500,
  33081. 'p': 500,
  33082. 'q': 500,
  33083. 'r': 389,
  33084. 's': 389,
  33085. 't': 278,
  33086. 'u': 556,
  33087. 'v': 444,
  33088. 'w': 667,
  33089. 'x': 500,
  33090. 'y': 444,
  33091. 'z': 389,
  33092. 'braceleft': 348,
  33093. 'bar': 220,
  33094. 'braceright': 348,
  33095. 'asciitilde': 570,
  33096. 'exclamdown': 389,
  33097. 'cent': 500,
  33098. 'sterling': 500,
  33099. 'fraction': 167,
  33100. 'yen': 500,
  33101. 'florin': 500,
  33102. 'section': 500,
  33103. 'currency': 500,
  33104. 'quotesingle': 278,
  33105. 'quotedblleft': 500,
  33106. 'guillemotleft': 500,
  33107. 'guilsinglleft': 333,
  33108. 'guilsinglright': 333,
  33109. 'fi': 556,
  33110. 'fl': 556,
  33111. 'endash': 500,
  33112. 'dagger': 500,
  33113. 'daggerdbl': 500,
  33114. 'periodcentered': 250,
  33115. 'paragraph': 500,
  33116. 'bullet': 350,
  33117. 'quotesinglbase': 333,
  33118. 'quotedblbase': 500,
  33119. 'quotedblright': 500,
  33120. 'guillemotright': 500,
  33121. 'ellipsis': 1000,
  33122. 'perthousand': 1000,
  33123. 'questiondown': 500,
  33124. 'grave': 333,
  33125. 'acute': 333,
  33126. 'circumflex': 333,
  33127. 'tilde': 333,
  33128. 'macron': 333,
  33129. 'breve': 333,
  33130. 'dotaccent': 333,
  33131. 'dieresis': 333,
  33132. 'ring': 333,
  33133. 'cedilla': 333,
  33134. 'hungarumlaut': 333,
  33135. 'ogonek': 333,
  33136. 'caron': 333,
  33137. 'emdash': 1000,
  33138. 'AE': 944,
  33139. 'ordfeminine': 266,
  33140. 'Lslash': 611,
  33141. 'Oslash': 722,
  33142. 'OE': 944,
  33143. 'ordmasculine': 300,
  33144. 'ae': 722,
  33145. 'dotlessi': 278,
  33146. 'lslash': 278,
  33147. 'oslash': 500,
  33148. 'oe': 722,
  33149. 'germandbls': 500,
  33150. 'Idieresis': 389,
  33151. 'eacute': 444,
  33152. 'abreve': 500,
  33153. 'uhungarumlaut': 556,
  33154. 'ecaron': 444,
  33155. 'Ydieresis': 611,
  33156. 'divide': 570,
  33157. 'Yacute': 611,
  33158. 'Acircumflex': 667,
  33159. 'aacute': 500,
  33160. 'Ucircumflex': 722,
  33161. 'yacute': 444,
  33162. 'scommaaccent': 389,
  33163. 'ecircumflex': 444,
  33164. 'Uring': 722,
  33165. 'Udieresis': 722,
  33166. 'aogonek': 500,
  33167. 'Uacute': 722,
  33168. 'uogonek': 556,
  33169. 'Edieresis': 667,
  33170. 'Dcroat': 722,
  33171. 'commaaccent': 250,
  33172. 'copyright': 747,
  33173. 'Emacron': 667,
  33174. 'ccaron': 444,
  33175. 'aring': 500,
  33176. 'Ncommaaccent': 722,
  33177. 'lacute': 278,
  33178. 'agrave': 500,
  33179. 'Tcommaaccent': 611,
  33180. 'Cacute': 667,
  33181. 'atilde': 500,
  33182. 'Edotaccent': 667,
  33183. 'scaron': 389,
  33184. 'scedilla': 389,
  33185. 'iacute': 278,
  33186. 'lozenge': 494,
  33187. 'Rcaron': 667,
  33188. 'Gcommaaccent': 722,
  33189. 'ucircumflex': 556,
  33190. 'acircumflex': 500,
  33191. 'Amacron': 667,
  33192. 'rcaron': 389,
  33193. 'ccedilla': 444,
  33194. 'Zdotaccent': 611,
  33195. 'Thorn': 611,
  33196. 'Omacron': 722,
  33197. 'Racute': 667,
  33198. 'Sacute': 556,
  33199. 'dcaron': 608,
  33200. 'Umacron': 722,
  33201. 'uring': 556,
  33202. 'threesuperior': 300,
  33203. 'Ograve': 722,
  33204. 'Agrave': 667,
  33205. 'Abreve': 667,
  33206. 'multiply': 570,
  33207. 'uacute': 556,
  33208. 'Tcaron': 611,
  33209. 'partialdiff': 494,
  33210. 'ydieresis': 444,
  33211. 'Nacute': 722,
  33212. 'icircumflex': 278,
  33213. 'Ecircumflex': 667,
  33214. 'adieresis': 500,
  33215. 'edieresis': 444,
  33216. 'cacute': 444,
  33217. 'nacute': 556,
  33218. 'umacron': 556,
  33219. 'Ncaron': 722,
  33220. 'Iacute': 389,
  33221. 'plusminus': 570,
  33222. 'brokenbar': 220,
  33223. 'registered': 747,
  33224. 'Gbreve': 722,
  33225. 'Idotaccent': 389,
  33226. 'summation': 600,
  33227. 'Egrave': 667,
  33228. 'racute': 389,
  33229. 'omacron': 500,
  33230. 'Zacute': 611,
  33231. 'Zcaron': 611,
  33232. 'greaterequal': 549,
  33233. 'Eth': 722,
  33234. 'Ccedilla': 667,
  33235. 'lcommaaccent': 278,
  33236. 'tcaron': 366,
  33237. 'eogonek': 444,
  33238. 'Uogonek': 722,
  33239. 'Aacute': 667,
  33240. 'Adieresis': 667,
  33241. 'egrave': 444,
  33242. 'zacute': 389,
  33243. 'iogonek': 278,
  33244. 'Oacute': 722,
  33245. 'oacute': 500,
  33246. 'amacron': 500,
  33247. 'sacute': 389,
  33248. 'idieresis': 278,
  33249. 'Ocircumflex': 722,
  33250. 'Ugrave': 722,
  33251. 'Delta': 612,
  33252. 'thorn': 500,
  33253. 'twosuperior': 300,
  33254. 'Odieresis': 722,
  33255. 'mu': 576,
  33256. 'igrave': 278,
  33257. 'ohungarumlaut': 500,
  33258. 'Eogonek': 667,
  33259. 'dcroat': 500,
  33260. 'threequarters': 750,
  33261. 'Scedilla': 556,
  33262. 'lcaron': 382,
  33263. 'Kcommaaccent': 667,
  33264. 'Lacute': 611,
  33265. 'trademark': 1000,
  33266. 'edotaccent': 444,
  33267. 'Igrave': 389,
  33268. 'Imacron': 389,
  33269. 'Lcaron': 611,
  33270. 'onehalf': 750,
  33271. 'lessequal': 549,
  33272. 'ocircumflex': 500,
  33273. 'ntilde': 556,
  33274. 'Uhungarumlaut': 722,
  33275. 'Eacute': 667,
  33276. 'emacron': 444,
  33277. 'gbreve': 500,
  33278. 'onequarter': 750,
  33279. 'Scaron': 556,
  33280. 'Scommaaccent': 556,
  33281. 'Ohungarumlaut': 722,
  33282. 'degree': 400,
  33283. 'ograve': 500,
  33284. 'Ccaron': 667,
  33285. 'ugrave': 556,
  33286. 'radical': 549,
  33287. 'Dcaron': 722,
  33288. 'rcommaaccent': 389,
  33289. 'Ntilde': 722,
  33290. 'otilde': 500,
  33291. 'Rcommaaccent': 667,
  33292. 'Lcommaaccent': 611,
  33293. 'Atilde': 667,
  33294. 'Aogonek': 667,
  33295. 'Aring': 667,
  33296. 'Otilde': 722,
  33297. 'zdotaccent': 389,
  33298. 'Ecaron': 667,
  33299. 'Iogonek': 389,
  33300. 'kcommaaccent': 500,
  33301. 'minus': 606,
  33302. 'Icircumflex': 389,
  33303. 'ncaron': 556,
  33304. 'tcommaaccent': 278,
  33305. 'logicalnot': 606,
  33306. 'odieresis': 500,
  33307. 'udieresis': 556,
  33308. 'notequal': 549,
  33309. 'gcommaaccent': 500,
  33310. 'eth': 500,
  33311. 'zcaron': 389,
  33312. 'ncommaaccent': 556,
  33313. 'onesuperior': 300,
  33314. 'imacron': 278,
  33315. 'Euro': 500
  33316. },
  33317. 'Times-Italic': {
  33318. 'space': 250,
  33319. 'exclam': 333,
  33320. 'quotedbl': 420,
  33321. 'numbersign': 500,
  33322. 'dollar': 500,
  33323. 'percent': 833,
  33324. 'ampersand': 778,
  33325. 'quoteright': 333,
  33326. 'parenleft': 333,
  33327. 'parenright': 333,
  33328. 'asterisk': 500,
  33329. 'plus': 675,
  33330. 'comma': 250,
  33331. 'hyphen': 333,
  33332. 'period': 250,
  33333. 'slash': 278,
  33334. 'zero': 500,
  33335. 'one': 500,
  33336. 'two': 500,
  33337. 'three': 500,
  33338. 'four': 500,
  33339. 'five': 500,
  33340. 'six': 500,
  33341. 'seven': 500,
  33342. 'eight': 500,
  33343. 'nine': 500,
  33344. 'colon': 333,
  33345. 'semicolon': 333,
  33346. 'less': 675,
  33347. 'equal': 675,
  33348. 'greater': 675,
  33349. 'question': 500,
  33350. 'at': 920,
  33351. 'A': 611,
  33352. 'B': 611,
  33353. 'C': 667,
  33354. 'D': 722,
  33355. 'E': 611,
  33356. 'F': 611,
  33357. 'G': 722,
  33358. 'H': 722,
  33359. 'I': 333,
  33360. 'J': 444,
  33361. 'K': 667,
  33362. 'L': 556,
  33363. 'M': 833,
  33364. 'N': 667,
  33365. 'O': 722,
  33366. 'P': 611,
  33367. 'Q': 722,
  33368. 'R': 611,
  33369. 'S': 500,
  33370. 'T': 556,
  33371. 'U': 722,
  33372. 'V': 611,
  33373. 'W': 833,
  33374. 'X': 611,
  33375. 'Y': 556,
  33376. 'Z': 556,
  33377. 'bracketleft': 389,
  33378. 'backslash': 278,
  33379. 'bracketright': 389,
  33380. 'asciicircum': 422,
  33381. 'underscore': 500,
  33382. 'quoteleft': 333,
  33383. 'a': 500,
  33384. 'b': 500,
  33385. 'c': 444,
  33386. 'd': 500,
  33387. 'e': 444,
  33388. 'f': 278,
  33389. 'g': 500,
  33390. 'h': 500,
  33391. 'i': 278,
  33392. 'j': 278,
  33393. 'k': 444,
  33394. 'l': 278,
  33395. 'm': 722,
  33396. 'n': 500,
  33397. 'o': 500,
  33398. 'p': 500,
  33399. 'q': 500,
  33400. 'r': 389,
  33401. 's': 389,
  33402. 't': 278,
  33403. 'u': 500,
  33404. 'v': 444,
  33405. 'w': 667,
  33406. 'x': 444,
  33407. 'y': 444,
  33408. 'z': 389,
  33409. 'braceleft': 400,
  33410. 'bar': 275,
  33411. 'braceright': 400,
  33412. 'asciitilde': 541,
  33413. 'exclamdown': 389,
  33414. 'cent': 500,
  33415. 'sterling': 500,
  33416. 'fraction': 167,
  33417. 'yen': 500,
  33418. 'florin': 500,
  33419. 'section': 500,
  33420. 'currency': 500,
  33421. 'quotesingle': 214,
  33422. 'quotedblleft': 556,
  33423. 'guillemotleft': 500,
  33424. 'guilsinglleft': 333,
  33425. 'guilsinglright': 333,
  33426. 'fi': 500,
  33427. 'fl': 500,
  33428. 'endash': 500,
  33429. 'dagger': 500,
  33430. 'daggerdbl': 500,
  33431. 'periodcentered': 250,
  33432. 'paragraph': 523,
  33433. 'bullet': 350,
  33434. 'quotesinglbase': 333,
  33435. 'quotedblbase': 556,
  33436. 'quotedblright': 556,
  33437. 'guillemotright': 500,
  33438. 'ellipsis': 889,
  33439. 'perthousand': 1000,
  33440. 'questiondown': 500,
  33441. 'grave': 333,
  33442. 'acute': 333,
  33443. 'circumflex': 333,
  33444. 'tilde': 333,
  33445. 'macron': 333,
  33446. 'breve': 333,
  33447. 'dotaccent': 333,
  33448. 'dieresis': 333,
  33449. 'ring': 333,
  33450. 'cedilla': 333,
  33451. 'hungarumlaut': 333,
  33452. 'ogonek': 333,
  33453. 'caron': 333,
  33454. 'emdash': 889,
  33455. 'AE': 889,
  33456. 'ordfeminine': 276,
  33457. 'Lslash': 556,
  33458. 'Oslash': 722,
  33459. 'OE': 944,
  33460. 'ordmasculine': 310,
  33461. 'ae': 667,
  33462. 'dotlessi': 278,
  33463. 'lslash': 278,
  33464. 'oslash': 500,
  33465. 'oe': 667,
  33466. 'germandbls': 500,
  33467. 'Idieresis': 333,
  33468. 'eacute': 444,
  33469. 'abreve': 500,
  33470. 'uhungarumlaut': 500,
  33471. 'ecaron': 444,
  33472. 'Ydieresis': 556,
  33473. 'divide': 675,
  33474. 'Yacute': 556,
  33475. 'Acircumflex': 611,
  33476. 'aacute': 500,
  33477. 'Ucircumflex': 722,
  33478. 'yacute': 444,
  33479. 'scommaaccent': 389,
  33480. 'ecircumflex': 444,
  33481. 'Uring': 722,
  33482. 'Udieresis': 722,
  33483. 'aogonek': 500,
  33484. 'Uacute': 722,
  33485. 'uogonek': 500,
  33486. 'Edieresis': 611,
  33487. 'Dcroat': 722,
  33488. 'commaaccent': 250,
  33489. 'copyright': 760,
  33490. 'Emacron': 611,
  33491. 'ccaron': 444,
  33492. 'aring': 500,
  33493. 'Ncommaaccent': 667,
  33494. 'lacute': 278,
  33495. 'agrave': 500,
  33496. 'Tcommaaccent': 556,
  33497. 'Cacute': 667,
  33498. 'atilde': 500,
  33499. 'Edotaccent': 611,
  33500. 'scaron': 389,
  33501. 'scedilla': 389,
  33502. 'iacute': 278,
  33503. 'lozenge': 471,
  33504. 'Rcaron': 611,
  33505. 'Gcommaaccent': 722,
  33506. 'ucircumflex': 500,
  33507. 'acircumflex': 500,
  33508. 'Amacron': 611,
  33509. 'rcaron': 389,
  33510. 'ccedilla': 444,
  33511. 'Zdotaccent': 556,
  33512. 'Thorn': 611,
  33513. 'Omacron': 722,
  33514. 'Racute': 611,
  33515. 'Sacute': 500,
  33516. 'dcaron': 544,
  33517. 'Umacron': 722,
  33518. 'uring': 500,
  33519. 'threesuperior': 300,
  33520. 'Ograve': 722,
  33521. 'Agrave': 611,
  33522. 'Abreve': 611,
  33523. 'multiply': 675,
  33524. 'uacute': 500,
  33525. 'Tcaron': 556,
  33526. 'partialdiff': 476,
  33527. 'ydieresis': 444,
  33528. 'Nacute': 667,
  33529. 'icircumflex': 278,
  33530. 'Ecircumflex': 611,
  33531. 'adieresis': 500,
  33532. 'edieresis': 444,
  33533. 'cacute': 444,
  33534. 'nacute': 500,
  33535. 'umacron': 500,
  33536. 'Ncaron': 667,
  33537. 'Iacute': 333,
  33538. 'plusminus': 675,
  33539. 'brokenbar': 275,
  33540. 'registered': 760,
  33541. 'Gbreve': 722,
  33542. 'Idotaccent': 333,
  33543. 'summation': 600,
  33544. 'Egrave': 611,
  33545. 'racute': 389,
  33546. 'omacron': 500,
  33547. 'Zacute': 556,
  33548. 'Zcaron': 556,
  33549. 'greaterequal': 549,
  33550. 'Eth': 722,
  33551. 'Ccedilla': 667,
  33552. 'lcommaaccent': 278,
  33553. 'tcaron': 300,
  33554. 'eogonek': 444,
  33555. 'Uogonek': 722,
  33556. 'Aacute': 611,
  33557. 'Adieresis': 611,
  33558. 'egrave': 444,
  33559. 'zacute': 389,
  33560. 'iogonek': 278,
  33561. 'Oacute': 722,
  33562. 'oacute': 500,
  33563. 'amacron': 500,
  33564. 'sacute': 389,
  33565. 'idieresis': 278,
  33566. 'Ocircumflex': 722,
  33567. 'Ugrave': 722,
  33568. 'Delta': 612,
  33569. 'thorn': 500,
  33570. 'twosuperior': 300,
  33571. 'Odieresis': 722,
  33572. 'mu': 500,
  33573. 'igrave': 278,
  33574. 'ohungarumlaut': 500,
  33575. 'Eogonek': 611,
  33576. 'dcroat': 500,
  33577. 'threequarters': 750,
  33578. 'Scedilla': 500,
  33579. 'lcaron': 300,
  33580. 'Kcommaaccent': 667,
  33581. 'Lacute': 556,
  33582. 'trademark': 980,
  33583. 'edotaccent': 444,
  33584. 'Igrave': 333,
  33585. 'Imacron': 333,
  33586. 'Lcaron': 611,
  33587. 'onehalf': 750,
  33588. 'lessequal': 549,
  33589. 'ocircumflex': 500,
  33590. 'ntilde': 500,
  33591. 'Uhungarumlaut': 722,
  33592. 'Eacute': 611,
  33593. 'emacron': 444,
  33594. 'gbreve': 500,
  33595. 'onequarter': 750,
  33596. 'Scaron': 500,
  33597. 'Scommaaccent': 500,
  33598. 'Ohungarumlaut': 722,
  33599. 'degree': 400,
  33600. 'ograve': 500,
  33601. 'Ccaron': 667,
  33602. 'ugrave': 500,
  33603. 'radical': 453,
  33604. 'Dcaron': 722,
  33605. 'rcommaaccent': 389,
  33606. 'Ntilde': 667,
  33607. 'otilde': 500,
  33608. 'Rcommaaccent': 611,
  33609. 'Lcommaaccent': 556,
  33610. 'Atilde': 611,
  33611. 'Aogonek': 611,
  33612. 'Aring': 611,
  33613. 'Otilde': 722,
  33614. 'zdotaccent': 389,
  33615. 'Ecaron': 611,
  33616. 'Iogonek': 333,
  33617. 'kcommaaccent': 444,
  33618. 'minus': 675,
  33619. 'Icircumflex': 333,
  33620. 'ncaron': 500,
  33621. 'tcommaaccent': 278,
  33622. 'logicalnot': 675,
  33623. 'odieresis': 500,
  33624. 'udieresis': 500,
  33625. 'notequal': 549,
  33626. 'gcommaaccent': 500,
  33627. 'eth': 500,
  33628. 'zcaron': 389,
  33629. 'ncommaaccent': 500,
  33630. 'onesuperior': 300,
  33631. 'imacron': 278,
  33632. 'Euro': 500
  33633. },
  33634. 'ZapfDingbats': {
  33635. 'space': 278,
  33636. 'a1': 974,
  33637. 'a2': 961,
  33638. 'a202': 974,
  33639. 'a3': 980,
  33640. 'a4': 719,
  33641. 'a5': 789,
  33642. 'a119': 790,
  33643. 'a118': 791,
  33644. 'a117': 690,
  33645. 'a11': 960,
  33646. 'a12': 939,
  33647. 'a13': 549,
  33648. 'a14': 855,
  33649. 'a15': 911,
  33650. 'a16': 933,
  33651. 'a105': 911,
  33652. 'a17': 945,
  33653. 'a18': 974,
  33654. 'a19': 755,
  33655. 'a20': 846,
  33656. 'a21': 762,
  33657. 'a22': 761,
  33658. 'a23': 571,
  33659. 'a24': 677,
  33660. 'a25': 763,
  33661. 'a26': 760,
  33662. 'a27': 759,
  33663. 'a28': 754,
  33664. 'a6': 494,
  33665. 'a7': 552,
  33666. 'a8': 537,
  33667. 'a9': 577,
  33668. 'a10': 692,
  33669. 'a29': 786,
  33670. 'a30': 788,
  33671. 'a31': 788,
  33672. 'a32': 790,
  33673. 'a33': 793,
  33674. 'a34': 794,
  33675. 'a35': 816,
  33676. 'a36': 823,
  33677. 'a37': 789,
  33678. 'a38': 841,
  33679. 'a39': 823,
  33680. 'a40': 833,
  33681. 'a41': 816,
  33682. 'a42': 831,
  33683. 'a43': 923,
  33684. 'a44': 744,
  33685. 'a45': 723,
  33686. 'a46': 749,
  33687. 'a47': 790,
  33688. 'a48': 792,
  33689. 'a49': 695,
  33690. 'a50': 776,
  33691. 'a51': 768,
  33692. 'a52': 792,
  33693. 'a53': 759,
  33694. 'a54': 707,
  33695. 'a55': 708,
  33696. 'a56': 682,
  33697. 'a57': 701,
  33698. 'a58': 826,
  33699. 'a59': 815,
  33700. 'a60': 789,
  33701. 'a61': 789,
  33702. 'a62': 707,
  33703. 'a63': 687,
  33704. 'a64': 696,
  33705. 'a65': 689,
  33706. 'a66': 786,
  33707. 'a67': 787,
  33708. 'a68': 713,
  33709. 'a69': 791,
  33710. 'a70': 785,
  33711. 'a71': 791,
  33712. 'a72': 873,
  33713. 'a73': 761,
  33714. 'a74': 762,
  33715. 'a203': 762,
  33716. 'a75': 759,
  33717. 'a204': 759,
  33718. 'a76': 892,
  33719. 'a77': 892,
  33720. 'a78': 788,
  33721. 'a79': 784,
  33722. 'a81': 438,
  33723. 'a82': 138,
  33724. 'a83': 277,
  33725. 'a84': 415,
  33726. 'a97': 392,
  33727. 'a98': 392,
  33728. 'a99': 668,
  33729. 'a100': 668,
  33730. 'a89': 390,
  33731. 'a90': 390,
  33732. 'a93': 317,
  33733. 'a94': 317,
  33734. 'a91': 276,
  33735. 'a92': 276,
  33736. 'a205': 509,
  33737. 'a85': 509,
  33738. 'a206': 410,
  33739. 'a86': 410,
  33740. 'a87': 234,
  33741. 'a88': 234,
  33742. 'a95': 334,
  33743. 'a96': 334,
  33744. 'a101': 732,
  33745. 'a102': 544,
  33746. 'a103': 544,
  33747. 'a104': 910,
  33748. 'a106': 667,
  33749. 'a107': 760,
  33750. 'a108': 760,
  33751. 'a112': 776,
  33752. 'a111': 595,
  33753. 'a110': 694,
  33754. 'a109': 626,
  33755. 'a120': 788,
  33756. 'a121': 788,
  33757. 'a122': 788,
  33758. 'a123': 788,
  33759. 'a124': 788,
  33760. 'a125': 788,
  33761. 'a126': 788,
  33762. 'a127': 788,
  33763. 'a128': 788,
  33764. 'a129': 788,
  33765. 'a130': 788,
  33766. 'a131': 788,
  33767. 'a132': 788,
  33768. 'a133': 788,
  33769. 'a134': 788,
  33770. 'a135': 788,
  33771. 'a136': 788,
  33772. 'a137': 788,
  33773. 'a138': 788,
  33774. 'a139': 788,
  33775. 'a140': 788,
  33776. 'a141': 788,
  33777. 'a142': 788,
  33778. 'a143': 788,
  33779. 'a144': 788,
  33780. 'a145': 788,
  33781. 'a146': 788,
  33782. 'a147': 788,
  33783. 'a148': 788,
  33784. 'a149': 788,
  33785. 'a150': 788,
  33786. 'a151': 788,
  33787. 'a152': 788,
  33788. 'a153': 788,
  33789. 'a154': 788,
  33790. 'a155': 788,
  33791. 'a156': 788,
  33792. 'a157': 788,
  33793. 'a158': 788,
  33794. 'a159': 788,
  33795. 'a160': 894,
  33796. 'a161': 838,
  33797. 'a163': 1016,
  33798. 'a164': 458,
  33799. 'a196': 748,
  33800. 'a165': 924,
  33801. 'a192': 748,
  33802. 'a166': 918,
  33803. 'a167': 927,
  33804. 'a168': 928,
  33805. 'a169': 928,
  33806. 'a170': 834,
  33807. 'a171': 873,
  33808. 'a172': 828,
  33809. 'a173': 924,
  33810. 'a162': 924,
  33811. 'a174': 917,
  33812. 'a175': 930,
  33813. 'a176': 931,
  33814. 'a177': 463,
  33815. 'a178': 883,
  33816. 'a179': 836,
  33817. 'a193': 836,
  33818. 'a180': 867,
  33819. 'a199': 867,
  33820. 'a181': 696,
  33821. 'a200': 696,
  33822. 'a182': 874,
  33823. 'a201': 874,
  33824. 'a183': 760,
  33825. 'a184': 946,
  33826. 'a197': 771,
  33827. 'a185': 865,
  33828. 'a194': 771,
  33829. 'a198': 888,
  33830. 'a186': 967,
  33831. 'a195': 888,
  33832. 'a187': 831,
  33833. 'a188': 873,
  33834. 'a189': 927,
  33835. 'a190': 970,
  33836. 'a191': 918
  33837. }
  33838. };
  33839. var EOF = {};
  33840. function isEOF(v) {
  33841. return (v === EOF);
  33842. }
  33843. var MAX_LENGTH_TO_CACHE = 1000;
  33844. var Parser = (function ParserClosure() {
  33845. function Parser(lexer, allowStreams, xref) {
  33846. this.lexer = lexer;
  33847. this.allowStreams = allowStreams;
  33848. this.xref = xref;
  33849. this.imageCache = {};
  33850. this.refill();
  33851. }
  33852. Parser.prototype = {
  33853. refill: function Parser_refill() {
  33854. this.buf1 = this.lexer.getObj();
  33855. this.buf2 = this.lexer.getObj();
  33856. },
  33857. shift: function Parser_shift() {
  33858. if (isCmd(this.buf2, 'ID')) {
  33859. this.buf1 = this.buf2;
  33860. this.buf2 = null;
  33861. } else {
  33862. this.buf1 = this.buf2;
  33863. this.buf2 = this.lexer.getObj();
  33864. }
  33865. },
  33866. getObj: function Parser_getObj(cipherTransform) {
  33867. var buf1 = this.buf1;
  33868. this.shift();
  33869. if (buf1 instanceof Cmd) {
  33870. switch (buf1.cmd) {
  33871. case 'BI': // inline image
  33872. return this.makeInlineImage(cipherTransform);
  33873. case '[': // array
  33874. var array = [];
  33875. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  33876. array.push(this.getObj(cipherTransform));
  33877. }
  33878. if (isEOF(this.buf1)) {
  33879. error('End of file inside array');
  33880. }
  33881. this.shift();
  33882. return array;
  33883. case '<<': // dictionary or stream
  33884. var dict = new Dict(this.xref);
  33885. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  33886. if (!isName(this.buf1)) {
  33887. info('Malformed dictionary: key must be a name object');
  33888. this.shift();
  33889. continue;
  33890. }
  33891. var key = this.buf1.name;
  33892. this.shift();
  33893. if (isEOF(this.buf1)) {
  33894. break;
  33895. }
  33896. dict.set(key, this.getObj(cipherTransform));
  33897. }
  33898. if (isEOF(this.buf1)) {
  33899. error('End of file inside dictionary');
  33900. }
  33901. // Stream objects are not allowed inside content streams or
  33902. // object streams.
  33903. if (isCmd(this.buf2, 'stream')) {
  33904. return (this.allowStreams ?
  33905. this.makeStream(dict, cipherTransform) : dict);
  33906. }
  33907. this.shift();
  33908. return dict;
  33909. default: // simple object
  33910. return buf1;
  33911. }
  33912. }
  33913. if (isInt(buf1)) { // indirect reference or integer
  33914. var num = buf1;
  33915. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  33916. var ref = new Ref(num, this.buf1);
  33917. this.shift();
  33918. this.shift();
  33919. return ref;
  33920. }
  33921. return num;
  33922. }
  33923. if (isString(buf1)) { // string
  33924. var str = buf1;
  33925. if (cipherTransform) {
  33926. str = cipherTransform.decryptString(str);
  33927. }
  33928. return str;
  33929. }
  33930. // simple object
  33931. return buf1;
  33932. },
  33933. /**
  33934. * Find the end of the stream by searching for the /EI\s/.
  33935. * @returns {number} The inline stream length.
  33936. */
  33937. findDefaultInlineStreamEnd:
  33938. function Parser_findDefaultInlineStreamEnd(stream) {
  33939. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  33940. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  33941. while ((ch = stream.getByte()) !== -1) {
  33942. if (state === 0) {
  33943. state = (ch === E) ? 1 : 0;
  33944. } else if (state === 1) {
  33945. state = (ch === I) ? 2 : 0;
  33946. } else {
  33947. assert(state === 2);
  33948. if (ch === SPACE || ch === LF || ch === CR) {
  33949. // Let's check the next five bytes are ASCII... just be sure.
  33950. n = 5;
  33951. followingBytes = stream.peekBytes(n);
  33952. for (i = 0; i < n; i++) {
  33953. ch = followingBytes[i];
  33954. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  33955. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  33956. // it's binary stuff. Resetting the state.
  33957. state = 0;
  33958. break;
  33959. }
  33960. }
  33961. if (state === 2) {
  33962. break; // Finished!
  33963. }
  33964. } else {
  33965. state = 0;
  33966. }
  33967. }
  33968. }
  33969. return ((stream.pos - 4) - startPos);
  33970. },
  33971. /**
  33972. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  33973. * @returns {number} The inline stream length.
  33974. */
  33975. findDCTDecodeInlineStreamEnd:
  33976. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  33977. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  33978. while ((b = stream.getByte()) !== -1) {
  33979. if (b !== 0xFF) { // Not a valid marker.
  33980. continue;
  33981. }
  33982. switch (stream.getByte()) {
  33983. case 0x00: // Byte stuffing.
  33984. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  33985. break;
  33986. case 0xFF: // Fill byte.
  33987. // Avoid skipping a valid marker, resetting the stream position.
  33988. stream.skip(-1);
  33989. break;
  33990. case 0xD9: // EOI
  33991. foundEOI = true;
  33992. break;
  33993. case 0xC0: // SOF0
  33994. case 0xC1: // SOF1
  33995. case 0xC2: // SOF2
  33996. case 0xC3: // SOF3
  33997. case 0xC5: // SOF5
  33998. case 0xC6: // SOF6
  33999. case 0xC7: // SOF7
  34000. case 0xC9: // SOF9
  34001. case 0xCA: // SOF10
  34002. case 0xCB: // SOF11
  34003. case 0xCD: // SOF13
  34004. case 0xCE: // SOF14
  34005. case 0xCF: // SOF15
  34006. case 0xC4: // DHT
  34007. case 0xCC: // DAC
  34008. case 0xDA: // SOS
  34009. case 0xDB: // DQT
  34010. case 0xDC: // DNL
  34011. case 0xDD: // DRI
  34012. case 0xDE: // DHP
  34013. case 0xDF: // EXP
  34014. case 0xE0: // APP0
  34015. case 0xE1: // APP1
  34016. case 0xE2: // APP2
  34017. case 0xE3: // APP3
  34018. case 0xE4: // APP4
  34019. case 0xE5: // APP5
  34020. case 0xE6: // APP6
  34021. case 0xE7: // APP7
  34022. case 0xE8: // APP8
  34023. case 0xE9: // APP9
  34024. case 0xEA: // APP10
  34025. case 0xEB: // APP11
  34026. case 0xEC: // APP12
  34027. case 0xED: // APP13
  34028. case 0xEE: // APP14
  34029. case 0xEF: // APP15
  34030. case 0xFE: // COM
  34031. // The marker should be followed by the length of the segment.
  34032. markerLength = stream.getUint16();
  34033. if (markerLength > 2) {
  34034. // |markerLength| contains the byte length of the marker segment,
  34035. // including its own length (2 bytes) and excluding the marker.
  34036. stream.skip(markerLength - 2); // Jump to the next marker.
  34037. } else {
  34038. // The marker length is invalid, resetting the stream position.
  34039. stream.skip(-2);
  34040. }
  34041. break;
  34042. }
  34043. if (foundEOI) {
  34044. break;
  34045. }
  34046. }
  34047. length = stream.pos - startPos;
  34048. if (b === -1) {
  34049. warn('Inline DCTDecode image stream: ' +
  34050. 'EOI marker not found, searching for /EI/ instead.');
  34051. stream.skip(-length); // Reset the stream position.
  34052. return this.findDefaultInlineStreamEnd(stream);
  34053. }
  34054. this.inlineStreamSkipEI(stream);
  34055. return length;
  34056. },
  34057. /**
  34058. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  34059. * @returns {number} The inline stream length.
  34060. */
  34061. findASCII85DecodeInlineStreamEnd:
  34062. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  34063. var TILDE = 0x7E, GT = 0x3E;
  34064. var startPos = stream.pos, ch, length;
  34065. while ((ch = stream.getByte()) !== -1) {
  34066. if (ch === TILDE && stream.peekByte() === GT) {
  34067. stream.skip();
  34068. break;
  34069. }
  34070. }
  34071. length = stream.pos - startPos;
  34072. if (ch === -1) {
  34073. warn('Inline ASCII85Decode image stream: ' +
  34074. 'EOD marker not found, searching for /EI/ instead.');
  34075. stream.skip(-length); // Reset the stream position.
  34076. return this.findDefaultInlineStreamEnd(stream);
  34077. }
  34078. this.inlineStreamSkipEI(stream);
  34079. return length;
  34080. },
  34081. /**
  34082. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  34083. * @returns {number} The inline stream length.
  34084. */
  34085. findASCIIHexDecodeInlineStreamEnd:
  34086. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  34087. var GT = 0x3E;
  34088. var startPos = stream.pos, ch, length;
  34089. while ((ch = stream.getByte()) !== -1) {
  34090. if (ch === GT) {
  34091. break;
  34092. }
  34093. }
  34094. length = stream.pos - startPos;
  34095. if (ch === -1) {
  34096. warn('Inline ASCIIHexDecode image stream: ' +
  34097. 'EOD marker not found, searching for /EI/ instead.');
  34098. stream.skip(-length); // Reset the stream position.
  34099. return this.findDefaultInlineStreamEnd(stream);
  34100. }
  34101. this.inlineStreamSkipEI(stream);
  34102. return length;
  34103. },
  34104. /**
  34105. * Skip over the /EI/ for streams where we search for an EOD marker.
  34106. */
  34107. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  34108. var E = 0x45, I = 0x49;
  34109. var state = 0, ch;
  34110. while ((ch = stream.getByte()) !== -1) {
  34111. if (state === 0) {
  34112. state = (ch === E) ? 1 : 0;
  34113. } else if (state === 1) {
  34114. state = (ch === I) ? 2 : 0;
  34115. } else if (state === 2) {
  34116. break;
  34117. }
  34118. }
  34119. },
  34120. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  34121. var lexer = this.lexer;
  34122. var stream = lexer.stream;
  34123. // Parse dictionary.
  34124. var dict = new Dict(null);
  34125. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  34126. if (!isName(this.buf1)) {
  34127. error('Dictionary key must be a name object');
  34128. }
  34129. var key = this.buf1.name;
  34130. this.shift();
  34131. if (isEOF(this.buf1)) {
  34132. break;
  34133. }
  34134. dict.set(key, this.getObj(cipherTransform));
  34135. }
  34136. // Extract the name of the first (i.e. the current) image filter.
  34137. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  34138. if (isName(filter)) {
  34139. filterName = filter.name;
  34140. } else if (isArray(filter) && isName(filter[0])) {
  34141. filterName = filter[0].name;
  34142. }
  34143. // Parse image stream.
  34144. var startPos = stream.pos, length, i, ii;
  34145. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  34146. length = this.findDCTDecodeInlineStreamEnd(stream);
  34147. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  34148. length = this.findASCII85DecodeInlineStreamEnd(stream);
  34149. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  34150. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  34151. } else {
  34152. length = this.findDefaultInlineStreamEnd(stream);
  34153. }
  34154. var imageStream = stream.makeSubStream(startPos, length, dict);
  34155. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  34156. // adler32 checksum.
  34157. var adler32;
  34158. if (length < MAX_LENGTH_TO_CACHE) {
  34159. var imageBytes = imageStream.getBytes();
  34160. imageStream.reset();
  34161. var a = 1;
  34162. var b = 0;
  34163. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  34164. // No modulo required in the loop if imageBytes.length < 5552.
  34165. a += imageBytes[i] & 0xff;
  34166. b += a;
  34167. }
  34168. adler32 = ((b % 65521) << 16) | (a % 65521);
  34169. if (this.imageCache.adler32 === adler32) {
  34170. this.buf2 = Cmd.get('EI');
  34171. this.shift();
  34172. this.imageCache[adler32].reset();
  34173. return this.imageCache[adler32];
  34174. }
  34175. }
  34176. if (cipherTransform) {
  34177. imageStream = cipherTransform.createStream(imageStream, length);
  34178. }
  34179. imageStream = this.filter(imageStream, dict, length);
  34180. imageStream.dict = dict;
  34181. if (adler32 !== undefined) {
  34182. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  34183. this.imageCache[adler32] = imageStream;
  34184. }
  34185. this.buf2 = Cmd.get('EI');
  34186. this.shift();
  34187. return imageStream;
  34188. },
  34189. fetchIfRef: function Parser_fetchIfRef(obj) {
  34190. // not relying on the xref.fetchIfRef -- xref might not be set
  34191. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  34192. },
  34193. makeStream: function Parser_makeStream(dict, cipherTransform) {
  34194. var lexer = this.lexer;
  34195. var stream = lexer.stream;
  34196. // get stream start position
  34197. lexer.skipToNextLine();
  34198. var pos = stream.pos - 1;
  34199. // get length
  34200. var length = this.fetchIfRef(dict.get('Length'));
  34201. if (!isInt(length)) {
  34202. info('Bad ' + length + ' attribute in stream');
  34203. length = 0;
  34204. }
  34205. // skip over the stream data
  34206. stream.pos = pos + length;
  34207. lexer.nextChar();
  34208. this.shift(); // '>>'
  34209. this.shift(); // 'stream'
  34210. if (!isCmd(this.buf1, 'endstream')) {
  34211. // bad stream length, scanning for endstream
  34212. stream.pos = pos;
  34213. var SCAN_BLOCK_SIZE = 2048;
  34214. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  34215. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  34216. 0x61, 0x6D];
  34217. var skipped = 0, found = false, i, j;
  34218. while (stream.pos < stream.end) {
  34219. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  34220. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  34221. if (scanLength <= 0) {
  34222. break;
  34223. }
  34224. found = false;
  34225. for (i = 0, j = 0; i < scanLength; i++) {
  34226. var b = scanBytes[i];
  34227. if (b !== ENDSTREAM_SIGNATURE[j]) {
  34228. i -= j;
  34229. j = 0;
  34230. } else {
  34231. j++;
  34232. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  34233. i++;
  34234. found = true;
  34235. break;
  34236. }
  34237. }
  34238. }
  34239. if (found) {
  34240. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  34241. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  34242. break;
  34243. }
  34244. skipped += scanLength;
  34245. stream.pos += scanLength;
  34246. }
  34247. if (!found) {
  34248. error('Missing endstream');
  34249. }
  34250. length = skipped;
  34251. lexer.nextChar();
  34252. this.shift();
  34253. this.shift();
  34254. }
  34255. this.shift(); // 'endstream'
  34256. stream = stream.makeSubStream(pos, length, dict);
  34257. if (cipherTransform) {
  34258. stream = cipherTransform.createStream(stream, length);
  34259. }
  34260. stream = this.filter(stream, dict, length);
  34261. stream.dict = dict;
  34262. return stream;
  34263. },
  34264. filter: function Parser_filter(stream, dict, length) {
  34265. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  34266. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  34267. if (isName(filter)) {
  34268. return this.makeFilter(stream, filter.name, length, params);
  34269. }
  34270. var maybeLength = length;
  34271. if (isArray(filter)) {
  34272. var filterArray = filter;
  34273. var paramsArray = params;
  34274. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  34275. filter = filterArray[i];
  34276. if (!isName(filter)) {
  34277. error('Bad filter name: ' + filter);
  34278. }
  34279. params = null;
  34280. if (isArray(paramsArray) && (i in paramsArray)) {
  34281. params = paramsArray[i];
  34282. }
  34283. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  34284. // after the first stream the length variable is invalid
  34285. maybeLength = null;
  34286. }
  34287. }
  34288. return stream;
  34289. },
  34290. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  34291. if (stream.dict.get('Length') === 0) {
  34292. return new NullStream(stream);
  34293. }
  34294. try {
  34295. if (params) {
  34296. params = this.fetchIfRef(params);
  34297. }
  34298. var xrefStreamStats = this.xref.stats.streamTypes;
  34299. if (name === 'FlateDecode' || name === 'Fl') {
  34300. xrefStreamStats[StreamType.FLATE] = true;
  34301. if (params) {
  34302. return new PredictorStream(new FlateStream(stream, maybeLength),
  34303. maybeLength, params);
  34304. }
  34305. return new FlateStream(stream, maybeLength);
  34306. }
  34307. if (name === 'LZWDecode' || name === 'LZW') {
  34308. xrefStreamStats[StreamType.LZW] = true;
  34309. var earlyChange = 1;
  34310. if (params) {
  34311. if (params.has('EarlyChange')) {
  34312. earlyChange = params.get('EarlyChange');
  34313. }
  34314. return new PredictorStream(
  34315. new LZWStream(stream, maybeLength, earlyChange),
  34316. maybeLength, params);
  34317. }
  34318. return new LZWStream(stream, maybeLength, earlyChange);
  34319. }
  34320. if (name === 'DCTDecode' || name === 'DCT') {
  34321. xrefStreamStats[StreamType.DCT] = true;
  34322. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  34323. }
  34324. if (name === 'JPXDecode' || name === 'JPX') {
  34325. xrefStreamStats[StreamType.JPX] = true;
  34326. return new JpxStream(stream, maybeLength, stream.dict);
  34327. }
  34328. if (name === 'ASCII85Decode' || name === 'A85') {
  34329. xrefStreamStats[StreamType.A85] = true;
  34330. return new Ascii85Stream(stream, maybeLength);
  34331. }
  34332. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  34333. xrefStreamStats[StreamType.AHX] = true;
  34334. return new AsciiHexStream(stream, maybeLength);
  34335. }
  34336. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  34337. xrefStreamStats[StreamType.CCF] = true;
  34338. return new CCITTFaxStream(stream, maybeLength, params);
  34339. }
  34340. if (name === 'RunLengthDecode' || name === 'RL') {
  34341. xrefStreamStats[StreamType.RL] = true;
  34342. return new RunLengthStream(stream, maybeLength);
  34343. }
  34344. if (name === 'JBIG2Decode') {
  34345. xrefStreamStats[StreamType.JBIG] = true;
  34346. return new Jbig2Stream(stream, maybeLength, stream.dict);
  34347. }
  34348. warn('filter "' + name + '" not supported yet');
  34349. return stream;
  34350. } catch (ex) {
  34351. if (ex instanceof MissingDataException) {
  34352. throw ex;
  34353. }
  34354. warn('Invalid stream: \"' + ex + '\"');
  34355. return new NullStream(stream);
  34356. }
  34357. }
  34358. };
  34359. return Parser;
  34360. })();
  34361. var Lexer = (function LexerClosure() {
  34362. function Lexer(stream, knownCommands) {
  34363. this.stream = stream;
  34364. this.nextChar();
  34365. // While lexing, we build up many strings one char at a time. Using += for
  34366. // this can result in lots of garbage strings. It's better to build an
  34367. // array of single-char strings and then join() them together at the end.
  34368. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  34369. // purpose uses less memory than using a new array for each string.
  34370. this.strBuf = [];
  34371. // The PDFs might have "glued" commands with other commands, operands or
  34372. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  34373. // commands and their prefixes. The prefixes are built the following way:
  34374. // if there a command that is a prefix of the other valid command or
  34375. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  34376. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  34377. // other commands or literals as a prefix. The knowCommands is optional.
  34378. this.knownCommands = knownCommands;
  34379. }
  34380. Lexer.isSpace = function Lexer_isSpace(ch) {
  34381. // Space is one of the following characters: SPACE, TAB, CR or LF.
  34382. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  34383. };
  34384. // A '1' in this array means the character is white space. A '1' or
  34385. // '2' means the character ends a name or command.
  34386. var specialChars = [
  34387. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  34388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  34389. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  34390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  34391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  34392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  34393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  34394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  34395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  34396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  34397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  34398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  34399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  34400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  34401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  34402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  34403. ];
  34404. function toHexDigit(ch) {
  34405. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  34406. return ch & 0x0F;
  34407. }
  34408. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  34409. // 'A'-'F', 'a'-'f'
  34410. return (ch & 0x0F) + 9;
  34411. }
  34412. return -1;
  34413. }
  34414. Lexer.prototype = {
  34415. nextChar: function Lexer_nextChar() {
  34416. return (this.currentChar = this.stream.getByte());
  34417. },
  34418. peekChar: function Lexer_peekChar() {
  34419. return this.stream.peekByte();
  34420. },
  34421. getNumber: function Lexer_getNumber() {
  34422. var ch = this.currentChar;
  34423. var eNotation = false;
  34424. var divideBy = 0; // different from 0 if it's a floating point value
  34425. var sign = 1;
  34426. if (ch === 0x2D) { // '-'
  34427. sign = -1;
  34428. ch = this.nextChar();
  34429. } else if (ch === 0x2B) { // '+'
  34430. ch = this.nextChar();
  34431. }
  34432. if (ch === 0x2E) { // '.'
  34433. divideBy = 10;
  34434. ch = this.nextChar();
  34435. }
  34436. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34437. error('Invalid number: ' + String.fromCharCode(ch));
  34438. return 0;
  34439. }
  34440. var baseValue = ch - 0x30; // '0'
  34441. var powerValue = 0;
  34442. var powerValueSign = 1;
  34443. while ((ch = this.nextChar()) >= 0) {
  34444. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  34445. var currentDigit = ch - 0x30; // '0'
  34446. if (eNotation) { // We are after an 'e' or 'E'
  34447. powerValue = powerValue * 10 + currentDigit;
  34448. } else {
  34449. if (divideBy !== 0) { // We are after a point
  34450. divideBy *= 10;
  34451. }
  34452. baseValue = baseValue * 10 + currentDigit;
  34453. }
  34454. } else if (ch === 0x2E) { // '.'
  34455. if (divideBy === 0) {
  34456. divideBy = 1;
  34457. } else {
  34458. // A number can have only one '.'
  34459. break;
  34460. }
  34461. } else if (ch === 0x2D) { // '-'
  34462. // ignore minus signs in the middle of numbers to match
  34463. // Adobe's behavior
  34464. warn('Badly formated number');
  34465. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  34466. // 'E' can be either a scientific notation or the beginning of a new
  34467. // operator
  34468. ch = this.peekChar();
  34469. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  34470. powerValueSign = (ch === 0x2D) ? -1 : 1;
  34471. this.nextChar(); // Consume the sign character
  34472. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34473. // The 'E' must be the beginning of a new operator
  34474. break;
  34475. }
  34476. eNotation = true;
  34477. } else {
  34478. // the last character doesn't belong to us
  34479. break;
  34480. }
  34481. }
  34482. if (divideBy !== 0) {
  34483. baseValue /= divideBy;
  34484. }
  34485. if (eNotation) {
  34486. baseValue *= Math.pow(10, powerValueSign * powerValue);
  34487. }
  34488. return sign * baseValue;
  34489. },
  34490. getString: function Lexer_getString() {
  34491. var numParen = 1;
  34492. var done = false;
  34493. var strBuf = this.strBuf;
  34494. strBuf.length = 0;
  34495. var ch = this.nextChar();
  34496. while (true) {
  34497. var charBuffered = false;
  34498. switch (ch | 0) {
  34499. case -1:
  34500. warn('Unterminated string');
  34501. done = true;
  34502. break;
  34503. case 0x28: // '('
  34504. ++numParen;
  34505. strBuf.push('(');
  34506. break;
  34507. case 0x29: // ')'
  34508. if (--numParen === 0) {
  34509. this.nextChar(); // consume strings ')'
  34510. done = true;
  34511. } else {
  34512. strBuf.push(')');
  34513. }
  34514. break;
  34515. case 0x5C: // '\\'
  34516. ch = this.nextChar();
  34517. switch (ch) {
  34518. case -1:
  34519. warn('Unterminated string');
  34520. done = true;
  34521. break;
  34522. case 0x6E: // 'n'
  34523. strBuf.push('\n');
  34524. break;
  34525. case 0x72: // 'r'
  34526. strBuf.push('\r');
  34527. break;
  34528. case 0x74: // 't'
  34529. strBuf.push('\t');
  34530. break;
  34531. case 0x62: // 'b'
  34532. strBuf.push('\b');
  34533. break;
  34534. case 0x66: // 'f'
  34535. strBuf.push('\f');
  34536. break;
  34537. case 0x5C: // '\'
  34538. case 0x28: // '('
  34539. case 0x29: // ')'
  34540. strBuf.push(String.fromCharCode(ch));
  34541. break;
  34542. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  34543. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  34544. var x = ch & 0x0F;
  34545. ch = this.nextChar();
  34546. charBuffered = true;
  34547. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34548. x = (x << 3) + (ch & 0x0F);
  34549. ch = this.nextChar();
  34550. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34551. charBuffered = false;
  34552. x = (x << 3) + (ch & 0x0F);
  34553. }
  34554. }
  34555. strBuf.push(String.fromCharCode(x));
  34556. break;
  34557. case 0x0D: // CR
  34558. if (this.peekChar() === 0x0A) { // LF
  34559. this.nextChar();
  34560. }
  34561. break;
  34562. case 0x0A: // LF
  34563. break;
  34564. default:
  34565. strBuf.push(String.fromCharCode(ch));
  34566. break;
  34567. }
  34568. break;
  34569. default:
  34570. strBuf.push(String.fromCharCode(ch));
  34571. break;
  34572. }
  34573. if (done) {
  34574. break;
  34575. }
  34576. if (!charBuffered) {
  34577. ch = this.nextChar();
  34578. }
  34579. }
  34580. return strBuf.join('');
  34581. },
  34582. getName: function Lexer_getName() {
  34583. var ch;
  34584. var strBuf = this.strBuf;
  34585. strBuf.length = 0;
  34586. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34587. if (ch === 0x23) { // '#'
  34588. ch = this.nextChar();
  34589. var x = toHexDigit(ch);
  34590. if (x !== -1) {
  34591. var x2 = toHexDigit(this.nextChar());
  34592. if (x2 === -1) {
  34593. error('Illegal digit in hex char in name: ' + x2);
  34594. }
  34595. strBuf.push(String.fromCharCode((x << 4) | x2));
  34596. } else {
  34597. strBuf.push('#', String.fromCharCode(ch));
  34598. }
  34599. } else {
  34600. strBuf.push(String.fromCharCode(ch));
  34601. }
  34602. }
  34603. if (strBuf.length > 128) {
  34604. error('Warning: name token is longer than allowed by the spec: ' +
  34605. strBuf.length);
  34606. }
  34607. return Name.get(strBuf.join(''));
  34608. },
  34609. getHexString: function Lexer_getHexString() {
  34610. var strBuf = this.strBuf;
  34611. strBuf.length = 0;
  34612. var ch = this.currentChar;
  34613. var isFirstHex = true;
  34614. var firstDigit;
  34615. var secondDigit;
  34616. while (true) {
  34617. if (ch < 0) {
  34618. warn('Unterminated hex string');
  34619. break;
  34620. } else if (ch === 0x3E) { // '>'
  34621. this.nextChar();
  34622. break;
  34623. } else if (specialChars[ch] === 1) {
  34624. ch = this.nextChar();
  34625. continue;
  34626. } else {
  34627. if (isFirstHex) {
  34628. firstDigit = toHexDigit(ch);
  34629. if (firstDigit === -1) {
  34630. warn('Ignoring invalid character "' + ch + '" in hex string');
  34631. ch = this.nextChar();
  34632. continue;
  34633. }
  34634. } else {
  34635. secondDigit = toHexDigit(ch);
  34636. if (secondDigit === -1) {
  34637. warn('Ignoring invalid character "' + ch + '" in hex string');
  34638. ch = this.nextChar();
  34639. continue;
  34640. }
  34641. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  34642. }
  34643. isFirstHex = !isFirstHex;
  34644. ch = this.nextChar();
  34645. }
  34646. }
  34647. return strBuf.join('');
  34648. },
  34649. getObj: function Lexer_getObj() {
  34650. // skip whitespace and comments
  34651. var comment = false;
  34652. var ch = this.currentChar;
  34653. while (true) {
  34654. if (ch < 0) {
  34655. return EOF;
  34656. }
  34657. if (comment) {
  34658. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  34659. comment = false;
  34660. }
  34661. } else if (ch === 0x25) { // '%'
  34662. comment = true;
  34663. } else if (specialChars[ch] !== 1) {
  34664. break;
  34665. }
  34666. ch = this.nextChar();
  34667. }
  34668. // start reading token
  34669. switch (ch | 0) {
  34670. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34671. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34672. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34673. return this.getNumber();
  34674. case 0x28: // '('
  34675. return this.getString();
  34676. case 0x2F: // '/'
  34677. return this.getName();
  34678. // array punctuation
  34679. case 0x5B: // '['
  34680. this.nextChar();
  34681. return Cmd.get('[');
  34682. case 0x5D: // ']'
  34683. this.nextChar();
  34684. return Cmd.get(']');
  34685. // hex string or dict punctuation
  34686. case 0x3C: // '<'
  34687. ch = this.nextChar();
  34688. if (ch === 0x3C) {
  34689. // dict punctuation
  34690. this.nextChar();
  34691. return Cmd.get('<<');
  34692. }
  34693. return this.getHexString();
  34694. // dict punctuation
  34695. case 0x3E: // '>'
  34696. ch = this.nextChar();
  34697. if (ch === 0x3E) {
  34698. this.nextChar();
  34699. return Cmd.get('>>');
  34700. }
  34701. return Cmd.get('>');
  34702. case 0x7B: // '{'
  34703. this.nextChar();
  34704. return Cmd.get('{');
  34705. case 0x7D: // '}'
  34706. this.nextChar();
  34707. return Cmd.get('}');
  34708. case 0x29: // ')'
  34709. error('Illegal character: ' + ch);
  34710. break;
  34711. }
  34712. // command
  34713. var str = String.fromCharCode(ch);
  34714. var knownCommands = this.knownCommands;
  34715. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34716. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34717. // stop if known command is found and next character does not make
  34718. // the str a command
  34719. var possibleCommand = str + String.fromCharCode(ch);
  34720. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  34721. break;
  34722. }
  34723. if (str.length === 128) {
  34724. error('Command token too long: ' + str.length);
  34725. }
  34726. str = possibleCommand;
  34727. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34728. }
  34729. if (str === 'true') {
  34730. return true;
  34731. }
  34732. if (str === 'false') {
  34733. return false;
  34734. }
  34735. if (str === 'null') {
  34736. return null;
  34737. }
  34738. return Cmd.get(str);
  34739. },
  34740. skipToNextLine: function Lexer_skipToNextLine() {
  34741. var ch = this.currentChar;
  34742. while (ch >= 0) {
  34743. if (ch === 0x0D) { // CR
  34744. ch = this.nextChar();
  34745. if (ch === 0x0A) { // LF
  34746. this.nextChar();
  34747. }
  34748. break;
  34749. } else if (ch === 0x0A) { // LF
  34750. this.nextChar();
  34751. break;
  34752. }
  34753. ch = this.nextChar();
  34754. }
  34755. }
  34756. };
  34757. return Lexer;
  34758. })();
  34759. var Linearization = {
  34760. create: function LinearizationCreate(stream) {
  34761. function getInt(name, allowZeroValue) {
  34762. var obj = linDict.get(name);
  34763. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  34764. return obj;
  34765. }
  34766. throw new Error('The "' + name + '" parameter in the linearization ' +
  34767. 'dictionary is invalid.');
  34768. }
  34769. function getHints() {
  34770. var hints = linDict.get('H'), hintsLength, item;
  34771. if (isArray(hints) &&
  34772. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  34773. for (var index = 0; index < hintsLength; index++) {
  34774. if (!(isInt(item = hints[index]) && item > 0)) {
  34775. throw new Error('Hint (' + index +
  34776. ') in the linearization dictionary is invalid.');
  34777. }
  34778. }
  34779. return hints;
  34780. }
  34781. throw new Error('Hint array in the linearization dictionary is invalid.');
  34782. }
  34783. var parser = new Parser(new Lexer(stream), false, null);
  34784. var obj1 = parser.getObj();
  34785. var obj2 = parser.getObj();
  34786. var obj3 = parser.getObj();
  34787. var linDict = parser.getObj();
  34788. var obj, length;
  34789. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  34790. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  34791. return null; // No valid linearization dictionary found.
  34792. } else if ((length = getInt('L')) !== stream.length) {
  34793. throw new Error('The "L" parameter in the linearization dictionary ' +
  34794. 'does not equal the stream length.');
  34795. }
  34796. return {
  34797. length: length,
  34798. hints: getHints(),
  34799. objectNumberFirst: getInt('O'),
  34800. endFirst: getInt('E'),
  34801. numPages: getInt('N'),
  34802. mainXRefEntriesOffset: getInt('T'),
  34803. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  34804. };
  34805. }
  34806. };
  34807. var PostScriptParser = (function PostScriptParserClosure() {
  34808. function PostScriptParser(lexer) {
  34809. this.lexer = lexer;
  34810. this.operators = [];
  34811. this.token = null;
  34812. this.prev = null;
  34813. }
  34814. PostScriptParser.prototype = {
  34815. nextToken: function PostScriptParser_nextToken() {
  34816. this.prev = this.token;
  34817. this.token = this.lexer.getToken();
  34818. },
  34819. accept: function PostScriptParser_accept(type) {
  34820. if (this.token.type === type) {
  34821. this.nextToken();
  34822. return true;
  34823. }
  34824. return false;
  34825. },
  34826. expect: function PostScriptParser_expect(type) {
  34827. if (this.accept(type)) {
  34828. return true;
  34829. }
  34830. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  34831. type + '.');
  34832. },
  34833. parse: function PostScriptParser_parse() {
  34834. this.nextToken();
  34835. this.expect(PostScriptTokenTypes.LBRACE);
  34836. this.parseBlock();
  34837. this.expect(PostScriptTokenTypes.RBRACE);
  34838. return this.operators;
  34839. },
  34840. parseBlock: function PostScriptParser_parseBlock() {
  34841. while (true) {
  34842. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  34843. this.operators.push(this.prev.value);
  34844. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  34845. this.operators.push(this.prev.value);
  34846. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34847. this.parseCondition();
  34848. } else {
  34849. return;
  34850. }
  34851. }
  34852. },
  34853. parseCondition: function PostScriptParser_parseCondition() {
  34854. // Add two place holders that will be updated later
  34855. var conditionLocation = this.operators.length;
  34856. this.operators.push(null, null);
  34857. this.parseBlock();
  34858. this.expect(PostScriptTokenTypes.RBRACE);
  34859. if (this.accept(PostScriptTokenTypes.IF)) {
  34860. // The true block is right after the 'if' so it just falls through on
  34861. // true else it jumps and skips the true block.
  34862. this.operators[conditionLocation] = this.operators.length;
  34863. this.operators[conditionLocation + 1] = 'jz';
  34864. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34865. var jumpLocation = this.operators.length;
  34866. this.operators.push(null, null);
  34867. var endOfTrue = this.operators.length;
  34868. this.parseBlock();
  34869. this.expect(PostScriptTokenTypes.RBRACE);
  34870. this.expect(PostScriptTokenTypes.IFELSE);
  34871. // The jump is added at the end of the true block to skip the false
  34872. // block.
  34873. this.operators[jumpLocation] = this.operators.length;
  34874. this.operators[jumpLocation + 1] = 'j';
  34875. this.operators[conditionLocation] = endOfTrue;
  34876. this.operators[conditionLocation + 1] = 'jz';
  34877. } else {
  34878. error('PS Function: error parsing conditional.');
  34879. }
  34880. }
  34881. };
  34882. return PostScriptParser;
  34883. })();
  34884. var PostScriptTokenTypes = {
  34885. LBRACE: 0,
  34886. RBRACE: 1,
  34887. NUMBER: 2,
  34888. OPERATOR: 3,
  34889. IF: 4,
  34890. IFELSE: 5
  34891. };
  34892. var PostScriptToken = (function PostScriptTokenClosure() {
  34893. function PostScriptToken(type, value) {
  34894. this.type = type;
  34895. this.value = value;
  34896. }
  34897. var opCache = {};
  34898. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  34899. var opValue = opCache[op];
  34900. if (opValue) {
  34901. return opValue;
  34902. }
  34903. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  34904. };
  34905. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  34906. '{');
  34907. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  34908. '}');
  34909. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  34910. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  34911. 'IFELSE');
  34912. return PostScriptToken;
  34913. })();
  34914. var PostScriptLexer = (function PostScriptLexerClosure() {
  34915. function PostScriptLexer(stream) {
  34916. this.stream = stream;
  34917. this.nextChar();
  34918. this.strBuf = [];
  34919. }
  34920. PostScriptLexer.prototype = {
  34921. nextChar: function PostScriptLexer_nextChar() {
  34922. return (this.currentChar = this.stream.getByte());
  34923. },
  34924. getToken: function PostScriptLexer_getToken() {
  34925. var comment = false;
  34926. var ch = this.currentChar;
  34927. // skip comments
  34928. while (true) {
  34929. if (ch < 0) {
  34930. return EOF;
  34931. }
  34932. if (comment) {
  34933. if (ch === 0x0A || ch === 0x0D) {
  34934. comment = false;
  34935. }
  34936. } else if (ch === 0x25) { // '%'
  34937. comment = true;
  34938. } else if (!Lexer.isSpace(ch)) {
  34939. break;
  34940. }
  34941. ch = this.nextChar();
  34942. }
  34943. switch (ch | 0) {
  34944. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34945. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34946. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34947. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  34948. this.getNumber());
  34949. case 0x7B: // '{'
  34950. this.nextChar();
  34951. return PostScriptToken.LBRACE;
  34952. case 0x7D: // '}'
  34953. this.nextChar();
  34954. return PostScriptToken.RBRACE;
  34955. }
  34956. // operator
  34957. var strBuf = this.strBuf;
  34958. strBuf.length = 0;
  34959. strBuf[0] = String.fromCharCode(ch);
  34960. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  34961. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  34962. strBuf.push(String.fromCharCode(ch));
  34963. }
  34964. var str = strBuf.join('');
  34965. switch (str.toLowerCase()) {
  34966. case 'if':
  34967. return PostScriptToken.IF;
  34968. case 'ifelse':
  34969. return PostScriptToken.IFELSE;
  34970. default:
  34971. return PostScriptToken.getOperator(str);
  34972. }
  34973. },
  34974. getNumber: function PostScriptLexer_getNumber() {
  34975. var ch = this.currentChar;
  34976. var strBuf = this.strBuf;
  34977. strBuf.length = 0;
  34978. strBuf[0] = String.fromCharCode(ch);
  34979. while ((ch = this.nextChar()) >= 0) {
  34980. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  34981. ch === 0x2D || ch === 0x2E) { // '-', '.'
  34982. strBuf.push(String.fromCharCode(ch));
  34983. } else {
  34984. break;
  34985. }
  34986. }
  34987. var value = parseFloat(strBuf.join(''));
  34988. if (isNaN(value)) {
  34989. error('Invalid floating point number: ' + value);
  34990. }
  34991. return value;
  34992. }
  34993. };
  34994. return PostScriptLexer;
  34995. })();
  34996. var Stream = (function StreamClosure() {
  34997. function Stream(arrayBuffer, start, length, dict) {
  34998. this.bytes = (arrayBuffer instanceof Uint8Array ?
  34999. arrayBuffer : new Uint8Array(arrayBuffer));
  35000. this.start = start || 0;
  35001. this.pos = this.start;
  35002. this.end = (start + length) || this.bytes.length;
  35003. this.dict = dict;
  35004. }
  35005. // required methods for a stream. if a particular stream does not
  35006. // implement these, an error should be thrown
  35007. Stream.prototype = {
  35008. get length() {
  35009. return this.end - this.start;
  35010. },
  35011. get isEmpty() {
  35012. return this.length === 0;
  35013. },
  35014. getByte: function Stream_getByte() {
  35015. if (this.pos >= this.end) {
  35016. return -1;
  35017. }
  35018. return this.bytes[this.pos++];
  35019. },
  35020. getUint16: function Stream_getUint16() {
  35021. var b0 = this.getByte();
  35022. var b1 = this.getByte();
  35023. if (b0 === -1 || b1 === -1) {
  35024. return -1;
  35025. }
  35026. return (b0 << 8) + b1;
  35027. },
  35028. getInt32: function Stream_getInt32() {
  35029. var b0 = this.getByte();
  35030. var b1 = this.getByte();
  35031. var b2 = this.getByte();
  35032. var b3 = this.getByte();
  35033. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35034. },
  35035. // returns subarray of original buffer
  35036. // should only be read
  35037. getBytes: function Stream_getBytes(length) {
  35038. var bytes = this.bytes;
  35039. var pos = this.pos;
  35040. var strEnd = this.end;
  35041. if (!length) {
  35042. return bytes.subarray(pos, strEnd);
  35043. }
  35044. var end = pos + length;
  35045. if (end > strEnd) {
  35046. end = strEnd;
  35047. }
  35048. this.pos = end;
  35049. return bytes.subarray(pos, end);
  35050. },
  35051. peekByte: function Stream_peekByte() {
  35052. var peekedByte = this.getByte();
  35053. this.pos--;
  35054. return peekedByte;
  35055. },
  35056. peekBytes: function Stream_peekBytes(length) {
  35057. var bytes = this.getBytes(length);
  35058. this.pos -= bytes.length;
  35059. return bytes;
  35060. },
  35061. skip: function Stream_skip(n) {
  35062. if (!n) {
  35063. n = 1;
  35064. }
  35065. this.pos += n;
  35066. },
  35067. reset: function Stream_reset() {
  35068. this.pos = this.start;
  35069. },
  35070. moveStart: function Stream_moveStart() {
  35071. this.start = this.pos;
  35072. },
  35073. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  35074. return new Stream(this.bytes.buffer, start, length, dict);
  35075. },
  35076. isStream: true
  35077. };
  35078. return Stream;
  35079. })();
  35080. var StringStream = (function StringStreamClosure() {
  35081. function StringStream(str) {
  35082. var length = str.length;
  35083. var bytes = new Uint8Array(length);
  35084. for (var n = 0; n < length; ++n) {
  35085. bytes[n] = str.charCodeAt(n);
  35086. }
  35087. Stream.call(this, bytes);
  35088. }
  35089. StringStream.prototype = Stream.prototype;
  35090. return StringStream;
  35091. })();
  35092. // super class for the decoding streams
  35093. var DecodeStream = (function DecodeStreamClosure() {
  35094. // Lots of DecodeStreams are created whose buffers are never used. For these
  35095. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  35096. // having special cases that would be required if we used |null| for an empty
  35097. // buffer.
  35098. var emptyBuffer = new Uint8Array(0);
  35099. function DecodeStream(maybeMinBufferLength) {
  35100. this.pos = 0;
  35101. this.bufferLength = 0;
  35102. this.eof = false;
  35103. this.buffer = emptyBuffer;
  35104. this.minBufferLength = 512;
  35105. if (maybeMinBufferLength) {
  35106. // Compute the first power of two that is as big as maybeMinBufferLength.
  35107. while (this.minBufferLength < maybeMinBufferLength) {
  35108. this.minBufferLength *= 2;
  35109. }
  35110. }
  35111. }
  35112. DecodeStream.prototype = {
  35113. get isEmpty() {
  35114. while (!this.eof && this.bufferLength === 0) {
  35115. this.readBlock();
  35116. }
  35117. return this.bufferLength === 0;
  35118. },
  35119. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  35120. var buffer = this.buffer;
  35121. if (requested <= buffer.byteLength) {
  35122. return buffer;
  35123. }
  35124. var size = this.minBufferLength;
  35125. while (size < requested) {
  35126. size *= 2;
  35127. }
  35128. var buffer2 = new Uint8Array(size);
  35129. buffer2.set(buffer);
  35130. return (this.buffer = buffer2);
  35131. },
  35132. getByte: function DecodeStream_getByte() {
  35133. var pos = this.pos;
  35134. while (this.bufferLength <= pos) {
  35135. if (this.eof) {
  35136. return -1;
  35137. }
  35138. this.readBlock();
  35139. }
  35140. return this.buffer[this.pos++];
  35141. },
  35142. getUint16: function DecodeStream_getUint16() {
  35143. var b0 = this.getByte();
  35144. var b1 = this.getByte();
  35145. if (b0 === -1 || b1 === -1) {
  35146. return -1;
  35147. }
  35148. return (b0 << 8) + b1;
  35149. },
  35150. getInt32: function DecodeStream_getInt32() {
  35151. var b0 = this.getByte();
  35152. var b1 = this.getByte();
  35153. var b2 = this.getByte();
  35154. var b3 = this.getByte();
  35155. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35156. },
  35157. getBytes: function DecodeStream_getBytes(length) {
  35158. var end, pos = this.pos;
  35159. if (length) {
  35160. this.ensureBuffer(pos + length);
  35161. end = pos + length;
  35162. while (!this.eof && this.bufferLength < end) {
  35163. this.readBlock();
  35164. }
  35165. var bufEnd = this.bufferLength;
  35166. if (end > bufEnd) {
  35167. end = bufEnd;
  35168. }
  35169. } else {
  35170. while (!this.eof) {
  35171. this.readBlock();
  35172. }
  35173. end = this.bufferLength;
  35174. }
  35175. this.pos = end;
  35176. return this.buffer.subarray(pos, end);
  35177. },
  35178. peekByte: function DecodeStream_peekByte() {
  35179. var peekedByte = this.getByte();
  35180. this.pos--;
  35181. return peekedByte;
  35182. },
  35183. peekBytes: function DecodeStream_peekBytes(length) {
  35184. var bytes = this.getBytes(length);
  35185. this.pos -= bytes.length;
  35186. return bytes;
  35187. },
  35188. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  35189. var end = start + length;
  35190. while (this.bufferLength <= end && !this.eof) {
  35191. this.readBlock();
  35192. }
  35193. return new Stream(this.buffer, start, length, dict);
  35194. },
  35195. skip: function DecodeStream_skip(n) {
  35196. if (!n) {
  35197. n = 1;
  35198. }
  35199. this.pos += n;
  35200. },
  35201. reset: function DecodeStream_reset() {
  35202. this.pos = 0;
  35203. },
  35204. getBaseStreams: function DecodeStream_getBaseStreams() {
  35205. if (this.str && this.str.getBaseStreams) {
  35206. return this.str.getBaseStreams();
  35207. }
  35208. return [];
  35209. }
  35210. };
  35211. return DecodeStream;
  35212. })();
  35213. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  35214. function StreamsSequenceStream(streams) {
  35215. this.streams = streams;
  35216. DecodeStream.call(this, /* maybeLength = */ null);
  35217. }
  35218. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  35219. StreamsSequenceStream.prototype.readBlock =
  35220. function streamSequenceStreamReadBlock() {
  35221. var streams = this.streams;
  35222. if (streams.length === 0) {
  35223. this.eof = true;
  35224. return;
  35225. }
  35226. var stream = streams.shift();
  35227. var chunk = stream.getBytes();
  35228. var bufferLength = this.bufferLength;
  35229. var newLength = bufferLength + chunk.length;
  35230. var buffer = this.ensureBuffer(newLength);
  35231. buffer.set(chunk, bufferLength);
  35232. this.bufferLength = newLength;
  35233. };
  35234. StreamsSequenceStream.prototype.getBaseStreams =
  35235. function StreamsSequenceStream_getBaseStreams() {
  35236. var baseStreams = [];
  35237. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  35238. var stream = this.streams[i];
  35239. if (stream.getBaseStreams) {
  35240. Util.appendToArray(baseStreams, stream.getBaseStreams());
  35241. }
  35242. }
  35243. return baseStreams;
  35244. };
  35245. return StreamsSequenceStream;
  35246. })();
  35247. var FlateStream = (function FlateStreamClosure() {
  35248. var codeLenCodeMap = new Uint32Array([
  35249. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  35250. ]);
  35251. var lengthDecode = new Uint32Array([
  35252. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  35253. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  35254. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  35255. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  35256. ]);
  35257. var distDecode = new Uint32Array([
  35258. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  35259. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  35260. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  35261. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  35262. ]);
  35263. var fixedLitCodeTab = [new Uint32Array([
  35264. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  35265. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  35266. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  35267. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  35268. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  35269. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  35270. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  35271. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  35272. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  35273. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  35274. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  35275. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  35276. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  35277. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  35278. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  35279. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  35280. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  35281. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  35282. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  35283. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  35284. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  35285. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  35286. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  35287. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  35288. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  35289. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  35290. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  35291. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  35292. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  35293. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  35294. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  35295. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  35296. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  35297. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  35298. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  35299. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  35300. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  35301. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  35302. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  35303. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  35304. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  35305. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  35306. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  35307. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  35308. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  35309. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  35310. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  35311. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  35312. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  35313. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  35314. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  35315. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  35316. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  35317. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  35318. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  35319. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  35320. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  35321. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  35322. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  35323. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  35324. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  35325. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  35326. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  35327. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  35328. ]), 9];
  35329. var fixedDistCodeTab = [new Uint32Array([
  35330. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  35331. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  35332. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  35333. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  35334. ]), 5];
  35335. function FlateStream(str, maybeLength) {
  35336. this.str = str;
  35337. this.dict = str.dict;
  35338. var cmf = str.getByte();
  35339. var flg = str.getByte();
  35340. if (cmf === -1 || flg === -1) {
  35341. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  35342. }
  35343. if ((cmf & 0x0f) !== 0x08) {
  35344. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  35345. }
  35346. if ((((cmf << 8) + flg) % 31) !== 0) {
  35347. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  35348. }
  35349. if (flg & 0x20) {
  35350. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  35351. }
  35352. this.codeSize = 0;
  35353. this.codeBuf = 0;
  35354. DecodeStream.call(this, maybeLength);
  35355. }
  35356. FlateStream.prototype = Object.create(DecodeStream.prototype);
  35357. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  35358. var str = this.str;
  35359. var codeSize = this.codeSize;
  35360. var codeBuf = this.codeBuf;
  35361. var b;
  35362. while (codeSize < bits) {
  35363. if ((b = str.getByte()) === -1) {
  35364. error('Bad encoding in flate stream');
  35365. }
  35366. codeBuf |= b << codeSize;
  35367. codeSize += 8;
  35368. }
  35369. b = codeBuf & ((1 << bits) - 1);
  35370. this.codeBuf = codeBuf >> bits;
  35371. this.codeSize = codeSize -= bits;
  35372. return b;
  35373. };
  35374. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  35375. var str = this.str;
  35376. var codes = table[0];
  35377. var maxLen = table[1];
  35378. var codeSize = this.codeSize;
  35379. var codeBuf = this.codeBuf;
  35380. var b;
  35381. while (codeSize < maxLen) {
  35382. if ((b = str.getByte()) === -1) {
  35383. // premature end of stream. code might however still be valid.
  35384. // codeSize < codeLen check below guards against incomplete codeVal.
  35385. break;
  35386. }
  35387. codeBuf |= (b << codeSize);
  35388. codeSize += 8;
  35389. }
  35390. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  35391. var codeLen = code >> 16;
  35392. var codeVal = code & 0xffff;
  35393. if (codeLen < 1 || codeSize < codeLen) {
  35394. error('Bad encoding in flate stream');
  35395. }
  35396. this.codeBuf = (codeBuf >> codeLen);
  35397. this.codeSize = (codeSize - codeLen);
  35398. return codeVal;
  35399. };
  35400. FlateStream.prototype.generateHuffmanTable =
  35401. function flateStreamGenerateHuffmanTable(lengths) {
  35402. var n = lengths.length;
  35403. // find max code length
  35404. var maxLen = 0;
  35405. var i;
  35406. for (i = 0; i < n; ++i) {
  35407. if (lengths[i] > maxLen) {
  35408. maxLen = lengths[i];
  35409. }
  35410. }
  35411. // build the table
  35412. var size = 1 << maxLen;
  35413. var codes = new Uint32Array(size);
  35414. for (var len = 1, code = 0, skip = 2;
  35415. len <= maxLen;
  35416. ++len, code <<= 1, skip <<= 1) {
  35417. for (var val = 0; val < n; ++val) {
  35418. if (lengths[val] === len) {
  35419. // bit-reverse the code
  35420. var code2 = 0;
  35421. var t = code;
  35422. for (i = 0; i < len; ++i) {
  35423. code2 = (code2 << 1) | (t & 1);
  35424. t >>= 1;
  35425. }
  35426. // fill the table entries
  35427. for (i = code2; i < size; i += skip) {
  35428. codes[i] = (len << 16) | val;
  35429. }
  35430. ++code;
  35431. }
  35432. }
  35433. }
  35434. return [codes, maxLen];
  35435. };
  35436. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  35437. var buffer, len;
  35438. var str = this.str;
  35439. // read block header
  35440. var hdr = this.getBits(3);
  35441. if (hdr & 1) {
  35442. this.eof = true;
  35443. }
  35444. hdr >>= 1;
  35445. if (hdr === 0) { // uncompressed block
  35446. var b;
  35447. if ((b = str.getByte()) === -1) {
  35448. error('Bad block header in flate stream');
  35449. }
  35450. var blockLen = b;
  35451. if ((b = str.getByte()) === -1) {
  35452. error('Bad block header in flate stream');
  35453. }
  35454. blockLen |= (b << 8);
  35455. if ((b = str.getByte()) === -1) {
  35456. error('Bad block header in flate stream');
  35457. }
  35458. var check = b;
  35459. if ((b = str.getByte()) === -1) {
  35460. error('Bad block header in flate stream');
  35461. }
  35462. check |= (b << 8);
  35463. if (check !== (~blockLen & 0xffff) &&
  35464. (blockLen !== 0 || check !== 0)) {
  35465. // Ignoring error for bad "empty" block (see issue 1277)
  35466. error('Bad uncompressed block length in flate stream');
  35467. }
  35468. this.codeBuf = 0;
  35469. this.codeSize = 0;
  35470. var bufferLength = this.bufferLength;
  35471. buffer = this.ensureBuffer(bufferLength + blockLen);
  35472. var end = bufferLength + blockLen;
  35473. this.bufferLength = end;
  35474. if (blockLen === 0) {
  35475. if (str.peekByte() === -1) {
  35476. this.eof = true;
  35477. }
  35478. } else {
  35479. for (var n = bufferLength; n < end; ++n) {
  35480. if ((b = str.getByte()) === -1) {
  35481. this.eof = true;
  35482. break;
  35483. }
  35484. buffer[n] = b;
  35485. }
  35486. }
  35487. return;
  35488. }
  35489. var litCodeTable;
  35490. var distCodeTable;
  35491. if (hdr === 1) { // compressed block, fixed codes
  35492. litCodeTable = fixedLitCodeTab;
  35493. distCodeTable = fixedDistCodeTab;
  35494. } else if (hdr === 2) { // compressed block, dynamic codes
  35495. var numLitCodes = this.getBits(5) + 257;
  35496. var numDistCodes = this.getBits(5) + 1;
  35497. var numCodeLenCodes = this.getBits(4) + 4;
  35498. // build the code lengths code table
  35499. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  35500. var i;
  35501. for (i = 0; i < numCodeLenCodes; ++i) {
  35502. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  35503. }
  35504. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  35505. // build the literal and distance code tables
  35506. len = 0;
  35507. i = 0;
  35508. var codes = numLitCodes + numDistCodes;
  35509. var codeLengths = new Uint8Array(codes);
  35510. var bitsLength, bitsOffset, what;
  35511. while (i < codes) {
  35512. var code = this.getCode(codeLenCodeTab);
  35513. if (code === 16) {
  35514. bitsLength = 2; bitsOffset = 3; what = len;
  35515. } else if (code === 17) {
  35516. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  35517. } else if (code === 18) {
  35518. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  35519. } else {
  35520. codeLengths[i++] = len = code;
  35521. continue;
  35522. }
  35523. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  35524. while (repeatLength-- > 0) {
  35525. codeLengths[i++] = what;
  35526. }
  35527. }
  35528. litCodeTable =
  35529. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  35530. distCodeTable =
  35531. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  35532. } else {
  35533. error('Unknown block type in flate stream');
  35534. }
  35535. buffer = this.buffer;
  35536. var limit = buffer ? buffer.length : 0;
  35537. var pos = this.bufferLength;
  35538. while (true) {
  35539. var code1 = this.getCode(litCodeTable);
  35540. if (code1 < 256) {
  35541. if (pos + 1 >= limit) {
  35542. buffer = this.ensureBuffer(pos + 1);
  35543. limit = buffer.length;
  35544. }
  35545. buffer[pos++] = code1;
  35546. continue;
  35547. }
  35548. if (code1 === 256) {
  35549. this.bufferLength = pos;
  35550. return;
  35551. }
  35552. code1 -= 257;
  35553. code1 = lengthDecode[code1];
  35554. var code2 = code1 >> 16;
  35555. if (code2 > 0) {
  35556. code2 = this.getBits(code2);
  35557. }
  35558. len = (code1 & 0xffff) + code2;
  35559. code1 = this.getCode(distCodeTable);
  35560. code1 = distDecode[code1];
  35561. code2 = code1 >> 16;
  35562. if (code2 > 0) {
  35563. code2 = this.getBits(code2);
  35564. }
  35565. var dist = (code1 & 0xffff) + code2;
  35566. if (pos + len >= limit) {
  35567. buffer = this.ensureBuffer(pos + len);
  35568. limit = buffer.length;
  35569. }
  35570. for (var k = 0; k < len; ++k, ++pos) {
  35571. buffer[pos] = buffer[pos - dist];
  35572. }
  35573. }
  35574. };
  35575. return FlateStream;
  35576. })();
  35577. var PredictorStream = (function PredictorStreamClosure() {
  35578. function PredictorStream(str, maybeLength, params) {
  35579. var predictor = this.predictor = params.get('Predictor') || 1;
  35580. if (predictor <= 1) {
  35581. return str; // no prediction
  35582. }
  35583. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  35584. error('Unsupported predictor: ' + predictor);
  35585. }
  35586. if (predictor === 2) {
  35587. this.readBlock = this.readBlockTiff;
  35588. } else {
  35589. this.readBlock = this.readBlockPng;
  35590. }
  35591. this.str = str;
  35592. this.dict = str.dict;
  35593. var colors = this.colors = params.get('Colors') || 1;
  35594. var bits = this.bits = params.get('BitsPerComponent') || 8;
  35595. var columns = this.columns = params.get('Columns') || 1;
  35596. this.pixBytes = (colors * bits + 7) >> 3;
  35597. this.rowBytes = (columns * colors * bits + 7) >> 3;
  35598. DecodeStream.call(this, maybeLength);
  35599. return this;
  35600. }
  35601. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  35602. PredictorStream.prototype.readBlockTiff =
  35603. function predictorStreamReadBlockTiff() {
  35604. var rowBytes = this.rowBytes;
  35605. var bufferLength = this.bufferLength;
  35606. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35607. var bits = this.bits;
  35608. var colors = this.colors;
  35609. var rawBytes = this.str.getBytes(rowBytes);
  35610. this.eof = !rawBytes.length;
  35611. if (this.eof) {
  35612. return;
  35613. }
  35614. var inbuf = 0, outbuf = 0;
  35615. var inbits = 0, outbits = 0;
  35616. var pos = bufferLength;
  35617. var i;
  35618. if (bits === 1) {
  35619. for (i = 0; i < rowBytes; ++i) {
  35620. var c = rawBytes[i];
  35621. inbuf = (inbuf << 8) | c;
  35622. // bitwise addition is exclusive or
  35623. // first shift inbuf and then add
  35624. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  35625. // truncate inbuf (assumes colors < 16)
  35626. inbuf &= 0xFFFF;
  35627. }
  35628. } else if (bits === 8) {
  35629. for (i = 0; i < colors; ++i) {
  35630. buffer[pos++] = rawBytes[i];
  35631. }
  35632. for (; i < rowBytes; ++i) {
  35633. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  35634. pos++;
  35635. }
  35636. } else {
  35637. var compArray = new Uint8Array(colors + 1);
  35638. var bitMask = (1 << bits) - 1;
  35639. var j = 0, k = bufferLength;
  35640. var columns = this.columns;
  35641. for (i = 0; i < columns; ++i) {
  35642. for (var kk = 0; kk < colors; ++kk) {
  35643. if (inbits < bits) {
  35644. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  35645. inbits += 8;
  35646. }
  35647. compArray[kk] = (compArray[kk] +
  35648. (inbuf >> (inbits - bits))) & bitMask;
  35649. inbits -= bits;
  35650. outbuf = (outbuf << bits) | compArray[kk];
  35651. outbits += bits;
  35652. if (outbits >= 8) {
  35653. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  35654. outbits -= 8;
  35655. }
  35656. }
  35657. }
  35658. if (outbits > 0) {
  35659. buffer[k++] = (outbuf << (8 - outbits)) +
  35660. (inbuf & ((1 << (8 - outbits)) - 1));
  35661. }
  35662. }
  35663. this.bufferLength += rowBytes;
  35664. };
  35665. PredictorStream.prototype.readBlockPng =
  35666. function predictorStreamReadBlockPng() {
  35667. var rowBytes = this.rowBytes;
  35668. var pixBytes = this.pixBytes;
  35669. var predictor = this.str.getByte();
  35670. var rawBytes = this.str.getBytes(rowBytes);
  35671. this.eof = !rawBytes.length;
  35672. if (this.eof) {
  35673. return;
  35674. }
  35675. var bufferLength = this.bufferLength;
  35676. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35677. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  35678. if (prevRow.length === 0) {
  35679. prevRow = new Uint8Array(rowBytes);
  35680. }
  35681. var i, j = bufferLength, up, c;
  35682. switch (predictor) {
  35683. case 0:
  35684. for (i = 0; i < rowBytes; ++i) {
  35685. buffer[j++] = rawBytes[i];
  35686. }
  35687. break;
  35688. case 1:
  35689. for (i = 0; i < pixBytes; ++i) {
  35690. buffer[j++] = rawBytes[i];
  35691. }
  35692. for (; i < rowBytes; ++i) {
  35693. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  35694. j++;
  35695. }
  35696. break;
  35697. case 2:
  35698. for (i = 0; i < rowBytes; ++i) {
  35699. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  35700. }
  35701. break;
  35702. case 3:
  35703. for (i = 0; i < pixBytes; ++i) {
  35704. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  35705. }
  35706. for (; i < rowBytes; ++i) {
  35707. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  35708. rawBytes[i]) & 0xFF;
  35709. j++;
  35710. }
  35711. break;
  35712. case 4:
  35713. // we need to save the up left pixels values. the simplest way
  35714. // is to create a new buffer
  35715. for (i = 0; i < pixBytes; ++i) {
  35716. up = prevRow[i];
  35717. c = rawBytes[i];
  35718. buffer[j++] = up + c;
  35719. }
  35720. for (; i < rowBytes; ++i) {
  35721. up = prevRow[i];
  35722. var upLeft = prevRow[i - pixBytes];
  35723. var left = buffer[j - pixBytes];
  35724. var p = left + up - upLeft;
  35725. var pa = p - left;
  35726. if (pa < 0) {
  35727. pa = -pa;
  35728. }
  35729. var pb = p - up;
  35730. if (pb < 0) {
  35731. pb = -pb;
  35732. }
  35733. var pc = p - upLeft;
  35734. if (pc < 0) {
  35735. pc = -pc;
  35736. }
  35737. c = rawBytes[i];
  35738. if (pa <= pb && pa <= pc) {
  35739. buffer[j++] = left + c;
  35740. } else if (pb <= pc) {
  35741. buffer[j++] = up + c;
  35742. } else {
  35743. buffer[j++] = upLeft + c;
  35744. }
  35745. }
  35746. break;
  35747. default:
  35748. error('Unsupported predictor: ' + predictor);
  35749. }
  35750. this.bufferLength += rowBytes;
  35751. };
  35752. return PredictorStream;
  35753. })();
  35754. /**
  35755. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  35756. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  35757. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  35758. * a library to decode these images and the stream behaves like all the other
  35759. * DecodeStreams.
  35760. */
  35761. var JpegStream = (function JpegStreamClosure() {
  35762. function JpegStream(stream, maybeLength, dict, xref) {
  35763. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  35764. // Note: this seems to mainly affect inline images.
  35765. var ch;
  35766. while ((ch = stream.getByte()) !== -1) {
  35767. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  35768. stream.skip(-1); // Reset the stream position to the SOI.
  35769. break;
  35770. }
  35771. }
  35772. this.stream = stream;
  35773. this.maybeLength = maybeLength;
  35774. this.dict = dict;
  35775. DecodeStream.call(this, maybeLength);
  35776. }
  35777. JpegStream.prototype = Object.create(DecodeStream.prototype);
  35778. Object.defineProperty(JpegStream.prototype, 'bytes', {
  35779. get: function JpegStream_bytes() {
  35780. // If this.maybeLength is null, we'll get the entire stream.
  35781. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35782. },
  35783. configurable: true
  35784. });
  35785. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  35786. if (this.bufferLength) {
  35787. return;
  35788. }
  35789. try {
  35790. var jpegImage = new JpegImage();
  35791. // checking if values needs to be transformed before conversion
  35792. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  35793. var decodeArr = this.dict.get('Decode');
  35794. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  35795. var decodeArrLength = decodeArr.length;
  35796. var transform = new Int32Array(decodeArrLength);
  35797. var transformNeeded = false;
  35798. var maxValue = (1 << bitsPerComponent) - 1;
  35799. for (var i = 0; i < decodeArrLength; i += 2) {
  35800. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  35801. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  35802. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  35803. transformNeeded = true;
  35804. }
  35805. }
  35806. if (transformNeeded) {
  35807. jpegImage.decodeTransform = transform;
  35808. }
  35809. }
  35810. jpegImage.parse(this.bytes);
  35811. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  35812. this.forceRGB);
  35813. this.buffer = data;
  35814. this.bufferLength = data.length;
  35815. this.eof = true;
  35816. } catch (e) {
  35817. error('JPEG error: ' + e);
  35818. }
  35819. };
  35820. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  35821. this.ensureBuffer();
  35822. return this.buffer;
  35823. };
  35824. JpegStream.prototype.getIR = function JpegStream_getIR() {
  35825. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  35826. };
  35827. /**
  35828. * Checks if the image can be decoded and displayed by the browser without any
  35829. * further processing such as color space conversions.
  35830. */
  35831. JpegStream.prototype.isNativelySupported =
  35832. function JpegStream_isNativelySupported(xref, res) {
  35833. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35834. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  35835. };
  35836. /**
  35837. * Checks if the image can be decoded by the browser.
  35838. */
  35839. JpegStream.prototype.isNativelyDecodable =
  35840. function JpegStream_isNativelyDecodable(xref, res) {
  35841. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35842. var numComps = cs.numComps;
  35843. return numComps === 1 || numComps === 3;
  35844. };
  35845. return JpegStream;
  35846. })();
  35847. /**
  35848. * For JPEG 2000's we use a library to decode these images and
  35849. * the stream behaves like all the other DecodeStreams.
  35850. */
  35851. var JpxStream = (function JpxStreamClosure() {
  35852. function JpxStream(stream, maybeLength, dict) {
  35853. this.stream = stream;
  35854. this.maybeLength = maybeLength;
  35855. this.dict = dict;
  35856. DecodeStream.call(this, maybeLength);
  35857. }
  35858. JpxStream.prototype = Object.create(DecodeStream.prototype);
  35859. Object.defineProperty(JpxStream.prototype, 'bytes', {
  35860. get: function JpxStream_bytes() {
  35861. // If this.maybeLength is null, we'll get the entire stream.
  35862. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35863. },
  35864. configurable: true
  35865. });
  35866. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  35867. if (this.bufferLength) {
  35868. return;
  35869. }
  35870. var jpxImage = new JpxImage();
  35871. jpxImage.parse(this.bytes);
  35872. var width = jpxImage.width;
  35873. var height = jpxImage.height;
  35874. var componentsCount = jpxImage.componentsCount;
  35875. var tileCount = jpxImage.tiles.length;
  35876. if (tileCount === 1) {
  35877. this.buffer = jpxImage.tiles[0].items;
  35878. } else {
  35879. var data = new Uint8Array(width * height * componentsCount);
  35880. for (var k = 0; k < tileCount; k++) {
  35881. var tileComponents = jpxImage.tiles[k];
  35882. var tileWidth = tileComponents.width;
  35883. var tileHeight = tileComponents.height;
  35884. var tileLeft = tileComponents.left;
  35885. var tileTop = tileComponents.top;
  35886. var src = tileComponents.items;
  35887. var srcPosition = 0;
  35888. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  35889. var imgRowSize = width * componentsCount;
  35890. var tileRowSize = tileWidth * componentsCount;
  35891. for (var j = 0; j < tileHeight; j++) {
  35892. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  35893. data.set(rowBytes, dataPosition);
  35894. srcPosition += tileRowSize;
  35895. dataPosition += imgRowSize;
  35896. }
  35897. }
  35898. this.buffer = data;
  35899. }
  35900. this.bufferLength = this.buffer.length;
  35901. this.eof = true;
  35902. };
  35903. return JpxStream;
  35904. })();
  35905. /**
  35906. * For JBIG2's we use a library to decode these images and
  35907. * the stream behaves like all the other DecodeStreams.
  35908. */
  35909. var Jbig2Stream = (function Jbig2StreamClosure() {
  35910. function Jbig2Stream(stream, maybeLength, dict) {
  35911. this.stream = stream;
  35912. this.maybeLength = maybeLength;
  35913. this.dict = dict;
  35914. DecodeStream.call(this, maybeLength);
  35915. }
  35916. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  35917. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  35918. get: function Jbig2Stream_bytes() {
  35919. // If this.maybeLength is null, we'll get the entire stream.
  35920. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35921. },
  35922. configurable: true
  35923. });
  35924. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  35925. if (this.bufferLength) {
  35926. return;
  35927. }
  35928. var jbig2Image = new Jbig2Image();
  35929. var chunks = [], xref = this.dict.xref;
  35930. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  35931. // According to the PDF specification, DecodeParms can be either
  35932. // a dictionary, or an array whose elements are dictionaries.
  35933. if (isArray(decodeParams)) {
  35934. if (decodeParams.length > 1) {
  35935. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  35936. 'not supported.');
  35937. }
  35938. decodeParams = xref.fetchIfRef(decodeParams[0]);
  35939. }
  35940. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  35941. var globalsStream = decodeParams.get('JBIG2Globals');
  35942. var globals = globalsStream.getBytes();
  35943. chunks.push({data: globals, start: 0, end: globals.length});
  35944. }
  35945. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  35946. var data = jbig2Image.parseChunks(chunks);
  35947. var dataLength = data.length;
  35948. // JBIG2 had black as 1 and white as 0, inverting the colors
  35949. for (var i = 0; i < dataLength; i++) {
  35950. data[i] ^= 0xFF;
  35951. }
  35952. this.buffer = data;
  35953. this.bufferLength = dataLength;
  35954. this.eof = true;
  35955. };
  35956. return Jbig2Stream;
  35957. })();
  35958. var DecryptStream = (function DecryptStreamClosure() {
  35959. function DecryptStream(str, maybeLength, decrypt) {
  35960. this.str = str;
  35961. this.dict = str.dict;
  35962. this.decrypt = decrypt;
  35963. this.nextChunk = null;
  35964. this.initialized = false;
  35965. DecodeStream.call(this, maybeLength);
  35966. }
  35967. var chunkSize = 512;
  35968. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  35969. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  35970. var chunk;
  35971. if (this.initialized) {
  35972. chunk = this.nextChunk;
  35973. } else {
  35974. chunk = this.str.getBytes(chunkSize);
  35975. this.initialized = true;
  35976. }
  35977. if (!chunk || chunk.length === 0) {
  35978. this.eof = true;
  35979. return;
  35980. }
  35981. this.nextChunk = this.str.getBytes(chunkSize);
  35982. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  35983. var decrypt = this.decrypt;
  35984. chunk = decrypt(chunk, !hasMoreData);
  35985. var bufferLength = this.bufferLength;
  35986. var i, n = chunk.length;
  35987. var buffer = this.ensureBuffer(bufferLength + n);
  35988. for (i = 0; i < n; i++) {
  35989. buffer[bufferLength++] = chunk[i];
  35990. }
  35991. this.bufferLength = bufferLength;
  35992. };
  35993. return DecryptStream;
  35994. })();
  35995. var Ascii85Stream = (function Ascii85StreamClosure() {
  35996. function Ascii85Stream(str, maybeLength) {
  35997. this.str = str;
  35998. this.dict = str.dict;
  35999. this.input = new Uint8Array(5);
  36000. // Most streams increase in size when decoded, but Ascii85 streams
  36001. // typically shrink by ~20%.
  36002. if (maybeLength) {
  36003. maybeLength = 0.8 * maybeLength;
  36004. }
  36005. DecodeStream.call(this, maybeLength);
  36006. }
  36007. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  36008. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  36009. var TILDA_CHAR = 0x7E; // '~'
  36010. var Z_LOWER_CHAR = 0x7A; // 'z'
  36011. var EOF = -1;
  36012. var str = this.str;
  36013. var c = str.getByte();
  36014. while (Lexer.isSpace(c)) {
  36015. c = str.getByte();
  36016. }
  36017. if (c === EOF || c === TILDA_CHAR) {
  36018. this.eof = true;
  36019. return;
  36020. }
  36021. var bufferLength = this.bufferLength, buffer;
  36022. var i;
  36023. // special code for z
  36024. if (c === Z_LOWER_CHAR) {
  36025. buffer = this.ensureBuffer(bufferLength + 4);
  36026. for (i = 0; i < 4; ++i) {
  36027. buffer[bufferLength + i] = 0;
  36028. }
  36029. this.bufferLength += 4;
  36030. } else {
  36031. var input = this.input;
  36032. input[0] = c;
  36033. for (i = 1; i < 5; ++i) {
  36034. c = str.getByte();
  36035. while (Lexer.isSpace(c)) {
  36036. c = str.getByte();
  36037. }
  36038. input[i] = c;
  36039. if (c === EOF || c === TILDA_CHAR) {
  36040. break;
  36041. }
  36042. }
  36043. buffer = this.ensureBuffer(bufferLength + i - 1);
  36044. this.bufferLength += i - 1;
  36045. // partial ending;
  36046. if (i < 5) {
  36047. for (; i < 5; ++i) {
  36048. input[i] = 0x21 + 84;
  36049. }
  36050. this.eof = true;
  36051. }
  36052. var t = 0;
  36053. for (i = 0; i < 5; ++i) {
  36054. t = t * 85 + (input[i] - 0x21);
  36055. }
  36056. for (i = 3; i >= 0; --i) {
  36057. buffer[bufferLength + i] = t & 0xFF;
  36058. t >>= 8;
  36059. }
  36060. }
  36061. };
  36062. return Ascii85Stream;
  36063. })();
  36064. var AsciiHexStream = (function AsciiHexStreamClosure() {
  36065. function AsciiHexStream(str, maybeLength) {
  36066. this.str = str;
  36067. this.dict = str.dict;
  36068. this.firstDigit = -1;
  36069. // Most streams increase in size when decoded, but AsciiHex streams shrink
  36070. // by 50%.
  36071. if (maybeLength) {
  36072. maybeLength = 0.5 * maybeLength;
  36073. }
  36074. DecodeStream.call(this, maybeLength);
  36075. }
  36076. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  36077. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  36078. var UPSTREAM_BLOCK_SIZE = 8000;
  36079. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  36080. if (!bytes.length) {
  36081. this.eof = true;
  36082. return;
  36083. }
  36084. var maxDecodeLength = (bytes.length + 1) >> 1;
  36085. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  36086. var bufferLength = this.bufferLength;
  36087. var firstDigit = this.firstDigit;
  36088. for (var i = 0, ii = bytes.length; i < ii; i++) {
  36089. var ch = bytes[i], digit;
  36090. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  36091. digit = ch & 0x0F;
  36092. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  36093. // 'A'-'Z', 'a'-'z'
  36094. digit = (ch & 0x0F) + 9;
  36095. } else if (ch === 0x3E) { // '>'
  36096. this.eof = true;
  36097. break;
  36098. } else { // probably whitespace
  36099. continue; // ignoring
  36100. }
  36101. if (firstDigit < 0) {
  36102. firstDigit = digit;
  36103. } else {
  36104. buffer[bufferLength++] = (firstDigit << 4) | digit;
  36105. firstDigit = -1;
  36106. }
  36107. }
  36108. if (firstDigit >= 0 && this.eof) {
  36109. // incomplete byte
  36110. buffer[bufferLength++] = (firstDigit << 4);
  36111. firstDigit = -1;
  36112. }
  36113. this.firstDigit = firstDigit;
  36114. this.bufferLength = bufferLength;
  36115. };
  36116. return AsciiHexStream;
  36117. })();
  36118. var RunLengthStream = (function RunLengthStreamClosure() {
  36119. function RunLengthStream(str, maybeLength) {
  36120. this.str = str;
  36121. this.dict = str.dict;
  36122. DecodeStream.call(this, maybeLength);
  36123. }
  36124. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  36125. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  36126. // The repeatHeader has following format. The first byte defines type of run
  36127. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  36128. // (in addition to the second byte from the header), n = 129 through 255 -
  36129. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  36130. var repeatHeader = this.str.getBytes(2);
  36131. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  36132. this.eof = true;
  36133. return;
  36134. }
  36135. var buffer;
  36136. var bufferLength = this.bufferLength;
  36137. var n = repeatHeader[0];
  36138. if (n < 128) {
  36139. // copy n bytes
  36140. buffer = this.ensureBuffer(bufferLength + n + 1);
  36141. buffer[bufferLength++] = repeatHeader[1];
  36142. if (n > 0) {
  36143. var source = this.str.getBytes(n);
  36144. buffer.set(source, bufferLength);
  36145. bufferLength += n;
  36146. }
  36147. } else {
  36148. n = 257 - n;
  36149. var b = repeatHeader[1];
  36150. buffer = this.ensureBuffer(bufferLength + n + 1);
  36151. for (var i = 0; i < n; i++) {
  36152. buffer[bufferLength++] = b;
  36153. }
  36154. }
  36155. this.bufferLength = bufferLength;
  36156. };
  36157. return RunLengthStream;
  36158. })();
  36159. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  36160. var ccittEOL = -2;
  36161. var twoDimPass = 0;
  36162. var twoDimHoriz = 1;
  36163. var twoDimVert0 = 2;
  36164. var twoDimVertR1 = 3;
  36165. var twoDimVertL1 = 4;
  36166. var twoDimVertR2 = 5;
  36167. var twoDimVertL2 = 6;
  36168. var twoDimVertR3 = 7;
  36169. var twoDimVertL3 = 8;
  36170. var twoDimTable = [
  36171. [-1, -1], [-1, -1], // 000000x
  36172. [7, twoDimVertL3], // 0000010
  36173. [7, twoDimVertR3], // 0000011
  36174. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  36175. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  36176. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  36177. [4, twoDimPass], [4, twoDimPass],
  36178. [4, twoDimPass], [4, twoDimPass],
  36179. [4, twoDimPass], [4, twoDimPass],
  36180. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  36181. [3, twoDimHoriz], [3, twoDimHoriz],
  36182. [3, twoDimHoriz], [3, twoDimHoriz],
  36183. [3, twoDimHoriz], [3, twoDimHoriz],
  36184. [3, twoDimHoriz], [3, twoDimHoriz],
  36185. [3, twoDimHoriz], [3, twoDimHoriz],
  36186. [3, twoDimHoriz], [3, twoDimHoriz],
  36187. [3, twoDimHoriz], [3, twoDimHoriz],
  36188. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  36189. [3, twoDimVertL1], [3, twoDimVertL1],
  36190. [3, twoDimVertL1], [3, twoDimVertL1],
  36191. [3, twoDimVertL1], [3, twoDimVertL1],
  36192. [3, twoDimVertL1], [3, twoDimVertL1],
  36193. [3, twoDimVertL1], [3, twoDimVertL1],
  36194. [3, twoDimVertL1], [3, twoDimVertL1],
  36195. [3, twoDimVertL1], [3, twoDimVertL1],
  36196. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  36197. [3, twoDimVertR1], [3, twoDimVertR1],
  36198. [3, twoDimVertR1], [3, twoDimVertR1],
  36199. [3, twoDimVertR1], [3, twoDimVertR1],
  36200. [3, twoDimVertR1], [3, twoDimVertR1],
  36201. [3, twoDimVertR1], [3, twoDimVertR1],
  36202. [3, twoDimVertR1], [3, twoDimVertR1],
  36203. [3, twoDimVertR1], [3, twoDimVertR1],
  36204. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  36205. [1, twoDimVert0], [1, twoDimVert0],
  36206. [1, twoDimVert0], [1, twoDimVert0],
  36207. [1, twoDimVert0], [1, twoDimVert0],
  36208. [1, twoDimVert0], [1, twoDimVert0],
  36209. [1, twoDimVert0], [1, twoDimVert0],
  36210. [1, twoDimVert0], [1, twoDimVert0],
  36211. [1, twoDimVert0], [1, twoDimVert0],
  36212. [1, twoDimVert0], [1, twoDimVert0],
  36213. [1, twoDimVert0], [1, twoDimVert0],
  36214. [1, twoDimVert0], [1, twoDimVert0],
  36215. [1, twoDimVert0], [1, twoDimVert0],
  36216. [1, twoDimVert0], [1, twoDimVert0],
  36217. [1, twoDimVert0], [1, twoDimVert0],
  36218. [1, twoDimVert0], [1, twoDimVert0],
  36219. [1, twoDimVert0], [1, twoDimVert0],
  36220. [1, twoDimVert0], [1, twoDimVert0],
  36221. [1, twoDimVert0], [1, twoDimVert0],
  36222. [1, twoDimVert0], [1, twoDimVert0],
  36223. [1, twoDimVert0], [1, twoDimVert0],
  36224. [1, twoDimVert0], [1, twoDimVert0],
  36225. [1, twoDimVert0], [1, twoDimVert0],
  36226. [1, twoDimVert0], [1, twoDimVert0],
  36227. [1, twoDimVert0], [1, twoDimVert0],
  36228. [1, twoDimVert0], [1, twoDimVert0],
  36229. [1, twoDimVert0], [1, twoDimVert0],
  36230. [1, twoDimVert0], [1, twoDimVert0],
  36231. [1, twoDimVert0], [1, twoDimVert0],
  36232. [1, twoDimVert0], [1, twoDimVert0],
  36233. [1, twoDimVert0], [1, twoDimVert0],
  36234. [1, twoDimVert0], [1, twoDimVert0],
  36235. [1, twoDimVert0], [1, twoDimVert0]
  36236. ];
  36237. var whiteTable1 = [
  36238. [-1, -1], // 00000
  36239. [12, ccittEOL], // 00001
  36240. [-1, -1], [-1, -1], // 0001x
  36241. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  36242. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  36243. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  36244. [11, 1792], [11, 1792], // 1000x
  36245. [12, 1984], // 10010
  36246. [12, 2048], // 10011
  36247. [12, 2112], // 10100
  36248. [12, 2176], // 10101
  36249. [12, 2240], // 10110
  36250. [12, 2304], // 10111
  36251. [11, 1856], [11, 1856], // 1100x
  36252. [11, 1920], [11, 1920], // 1101x
  36253. [12, 2368], // 11100
  36254. [12, 2432], // 11101
  36255. [12, 2496], // 11110
  36256. [12, 2560] // 11111
  36257. ];
  36258. var whiteTable2 = [
  36259. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  36260. [8, 29], [8, 29], // 00000010x
  36261. [8, 30], [8, 30], // 00000011x
  36262. [8, 45], [8, 45], // 00000100x
  36263. [8, 46], [8, 46], // 00000101x
  36264. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  36265. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  36266. [8, 47], [8, 47], // 00001010x
  36267. [8, 48], [8, 48], // 00001011x
  36268. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  36269. [6, 13], [6, 13], [6, 13], [6, 13],
  36270. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  36271. [8, 33], [8, 33], // 00010010x
  36272. [8, 34], [8, 34], // 00010011x
  36273. [8, 35], [8, 35], // 00010100x
  36274. [8, 36], [8, 36], // 00010101x
  36275. [8, 37], [8, 37], // 00010110x
  36276. [8, 38], [8, 38], // 00010111x
  36277. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  36278. [8, 31], [8, 31], // 00011010x
  36279. [8, 32], [8, 32], // 00011011x
  36280. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  36281. [6, 1], [6, 1], [6, 1], [6, 1],
  36282. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  36283. [6, 12], [6, 12], [6, 12], [6, 12],
  36284. [8, 53], [8, 53], // 00100100x
  36285. [8, 54], [8, 54], // 00100101x
  36286. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  36287. [8, 39], [8, 39], // 00101000x
  36288. [8, 40], [8, 40], // 00101001x
  36289. [8, 41], [8, 41], // 00101010x
  36290. [8, 42], [8, 42], // 00101011x
  36291. [8, 43], [8, 43], // 00101100x
  36292. [8, 44], [8, 44], // 00101101x
  36293. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  36294. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  36295. [8, 61], [8, 61], // 00110010x
  36296. [8, 62], [8, 62], // 00110011x
  36297. [8, 63], [8, 63], // 00110100x
  36298. [8, 0], [8, 0], // 00110101x
  36299. [8, 320], [8, 320], // 00110110x
  36300. [8, 384], [8, 384], // 00110111x
  36301. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  36302. [5, 10], [5, 10], [5, 10], [5, 10],
  36303. [5, 10], [5, 10], [5, 10], [5, 10],
  36304. [5, 10], [5, 10], [5, 10], [5, 10],
  36305. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  36306. [5, 11], [5, 11], [5, 11], [5, 11],
  36307. [5, 11], [5, 11], [5, 11], [5, 11],
  36308. [5, 11], [5, 11], [5, 11], [5, 11],
  36309. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  36310. [8, 59], [8, 59], // 01001010x
  36311. [8, 60], [8, 60], // 01001011x
  36312. [9, 1472], // 010011000
  36313. [9, 1536], // 010011001
  36314. [9, 1600], // 010011010
  36315. [9, 1728], // 010011011
  36316. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  36317. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  36318. [8, 49], [8, 49], // 01010010x
  36319. [8, 50], [8, 50], // 01010011x
  36320. [8, 51], [8, 51], // 01010100x
  36321. [8, 52], [8, 52], // 01010101x
  36322. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  36323. [8, 55], [8, 55], // 01011000x
  36324. [8, 56], [8, 56], // 01011001x
  36325. [8, 57], [8, 57], // 01011010x
  36326. [8, 58], [8, 58], // 01011011x
  36327. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  36328. [6, 192], [6, 192], [6, 192], [6, 192],
  36329. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  36330. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  36331. [8, 448], [8, 448], // 01100100x
  36332. [8, 512], [8, 512], // 01100101x
  36333. [9, 704], // 011001100
  36334. [9, 768], // 011001101
  36335. [8, 640], [8, 640], // 01100111x
  36336. [8, 576], [8, 576], // 01101000x
  36337. [9, 832], // 011010010
  36338. [9, 896], // 011010011
  36339. [9, 960], // 011010100
  36340. [9, 1024], // 011010101
  36341. [9, 1088], // 011010110
  36342. [9, 1152], // 011010111
  36343. [9, 1216], // 011011000
  36344. [9, 1280], // 011011001
  36345. [9, 1344], // 011011010
  36346. [9, 1408], // 011011011
  36347. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  36348. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  36349. [4, 2], [4, 2], [4, 2], [4, 2],
  36350. [4, 2], [4, 2], [4, 2], [4, 2],
  36351. [4, 2], [4, 2], [4, 2], [4, 2],
  36352. [4, 2], [4, 2], [4, 2], [4, 2],
  36353. [4, 2], [4, 2], [4, 2], [4, 2],
  36354. [4, 2], [4, 2], [4, 2], [4, 2],
  36355. [4, 2], [4, 2], [4, 2], [4, 2],
  36356. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  36357. [4, 3], [4, 3], [4, 3], [4, 3],
  36358. [4, 3], [4, 3], [4, 3], [4, 3],
  36359. [4, 3], [4, 3], [4, 3], [4, 3],
  36360. [4, 3], [4, 3], [4, 3], [4, 3],
  36361. [4, 3], [4, 3], [4, 3], [4, 3],
  36362. [4, 3], [4, 3], [4, 3], [4, 3],
  36363. [4, 3], [4, 3], [4, 3], [4, 3],
  36364. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  36365. [5, 128], [5, 128], [5, 128], [5, 128],
  36366. [5, 128], [5, 128], [5, 128], [5, 128],
  36367. [5, 128], [5, 128], [5, 128], [5, 128],
  36368. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  36369. [5, 8], [5, 8], [5, 8], [5, 8],
  36370. [5, 8], [5, 8], [5, 8], [5, 8],
  36371. [5, 8], [5, 8], [5, 8], [5, 8],
  36372. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  36373. [5, 9], [5, 9], [5, 9], [5, 9],
  36374. [5, 9], [5, 9], [5, 9], [5, 9],
  36375. [5, 9], [5, 9], [5, 9], [5, 9],
  36376. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  36377. [6, 16], [6, 16], [6, 16], [6, 16],
  36378. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  36379. [6, 17], [6, 17], [6, 17], [6, 17],
  36380. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  36381. [4, 4], [4, 4], [4, 4], [4, 4],
  36382. [4, 4], [4, 4], [4, 4], [4, 4],
  36383. [4, 4], [4, 4], [4, 4], [4, 4],
  36384. [4, 4], [4, 4], [4, 4], [4, 4],
  36385. [4, 4], [4, 4], [4, 4], [4, 4],
  36386. [4, 4], [4, 4], [4, 4], [4, 4],
  36387. [4, 4], [4, 4], [4, 4], [4, 4],
  36388. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  36389. [4, 5], [4, 5], [4, 5], [4, 5],
  36390. [4, 5], [4, 5], [4, 5], [4, 5],
  36391. [4, 5], [4, 5], [4, 5], [4, 5],
  36392. [4, 5], [4, 5], [4, 5], [4, 5],
  36393. [4, 5], [4, 5], [4, 5], [4, 5],
  36394. [4, 5], [4, 5], [4, 5], [4, 5],
  36395. [4, 5], [4, 5], [4, 5], [4, 5],
  36396. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  36397. [6, 14], [6, 14], [6, 14], [6, 14],
  36398. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  36399. [6, 15], [6, 15], [6, 15], [6, 15],
  36400. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  36401. [5, 64], [5, 64], [5, 64], [5, 64],
  36402. [5, 64], [5, 64], [5, 64], [5, 64],
  36403. [5, 64], [5, 64], [5, 64], [5, 64],
  36404. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  36405. [4, 6], [4, 6], [4, 6], [4, 6],
  36406. [4, 6], [4, 6], [4, 6], [4, 6],
  36407. [4, 6], [4, 6], [4, 6], [4, 6],
  36408. [4, 6], [4, 6], [4, 6], [4, 6],
  36409. [4, 6], [4, 6], [4, 6], [4, 6],
  36410. [4, 6], [4, 6], [4, 6], [4, 6],
  36411. [4, 6], [4, 6], [4, 6], [4, 6],
  36412. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  36413. [4, 7], [4, 7], [4, 7], [4, 7],
  36414. [4, 7], [4, 7], [4, 7], [4, 7],
  36415. [4, 7], [4, 7], [4, 7], [4, 7],
  36416. [4, 7], [4, 7], [4, 7], [4, 7],
  36417. [4, 7], [4, 7], [4, 7], [4, 7],
  36418. [4, 7], [4, 7], [4, 7], [4, 7],
  36419. [4, 7], [4, 7], [4, 7], [4, 7]
  36420. ];
  36421. var blackTable1 = [
  36422. [-1, -1], [-1, -1], // 000000000000x
  36423. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  36424. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  36425. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  36426. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  36427. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  36428. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  36429. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  36430. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  36431. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  36432. [12, 1984], [12, 1984], // 000000010010x
  36433. [12, 2048], [12, 2048], // 000000010011x
  36434. [12, 2112], [12, 2112], // 000000010100x
  36435. [12, 2176], [12, 2176], // 000000010101x
  36436. [12, 2240], [12, 2240], // 000000010110x
  36437. [12, 2304], [12, 2304], // 000000010111x
  36438. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  36439. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  36440. [12, 2368], [12, 2368], // 000000011100x
  36441. [12, 2432], [12, 2432], // 000000011101x
  36442. [12, 2496], [12, 2496], // 000000011110x
  36443. [12, 2560], [12, 2560], // 000000011111x
  36444. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  36445. [10, 18], [10, 18], [10, 18], [10, 18],
  36446. [12, 52], [12, 52], // 000000100100x
  36447. [13, 640], // 0000001001010
  36448. [13, 704], // 0000001001011
  36449. [13, 768], // 0000001001100
  36450. [13, 832], // 0000001001101
  36451. [12, 55], [12, 55], // 000000100111x
  36452. [12, 56], [12, 56], // 000000101000x
  36453. [13, 1280], // 0000001010010
  36454. [13, 1344], // 0000001010011
  36455. [13, 1408], // 0000001010100
  36456. [13, 1472], // 0000001010101
  36457. [12, 59], [12, 59], // 000000101011x
  36458. [12, 60], [12, 60], // 000000101100x
  36459. [13, 1536], // 0000001011010
  36460. [13, 1600], // 0000001011011
  36461. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  36462. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  36463. [13, 1664], // 0000001100100
  36464. [13, 1728], // 0000001100101
  36465. [12, 320], [12, 320], // 000000110011x
  36466. [12, 384], [12, 384], // 000000110100x
  36467. [12, 448], [12, 448], // 000000110101x
  36468. [13, 512], // 0000001101100
  36469. [13, 576], // 0000001101101
  36470. [12, 53], [12, 53], // 000000110111x
  36471. [12, 54], [12, 54], // 000000111000x
  36472. [13, 896], // 0000001110010
  36473. [13, 960], // 0000001110011
  36474. [13, 1024], // 0000001110100
  36475. [13, 1088], // 0000001110101
  36476. [13, 1152], // 0000001110110
  36477. [13, 1216], // 0000001110111
  36478. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  36479. [10, 64], [10, 64], [10, 64], [10, 64]
  36480. ];
  36481. var blackTable2 = [
  36482. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  36483. [8, 13], [8, 13], [8, 13], [8, 13],
  36484. [8, 13], [8, 13], [8, 13], [8, 13],
  36485. [8, 13], [8, 13], [8, 13], [8, 13],
  36486. [11, 23], [11, 23], // 00000101000x
  36487. [12, 50], // 000001010010
  36488. [12, 51], // 000001010011
  36489. [12, 44], // 000001010100
  36490. [12, 45], // 000001010101
  36491. [12, 46], // 000001010110
  36492. [12, 47], // 000001010111
  36493. [12, 57], // 000001011000
  36494. [12, 58], // 000001011001
  36495. [12, 61], // 000001011010
  36496. [12, 256], // 000001011011
  36497. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  36498. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  36499. [12, 48], // 000001100100
  36500. [12, 49], // 000001100101
  36501. [12, 62], // 000001100110
  36502. [12, 63], // 000001100111
  36503. [12, 30], // 000001101000
  36504. [12, 31], // 000001101001
  36505. [12, 32], // 000001101010
  36506. [12, 33], // 000001101011
  36507. [12, 40], // 000001101100
  36508. [12, 41], // 000001101101
  36509. [11, 22], [11, 22], // 00000110111x
  36510. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  36511. [8, 14], [8, 14], [8, 14], [8, 14],
  36512. [8, 14], [8, 14], [8, 14], [8, 14],
  36513. [8, 14], [8, 14], [8, 14], [8, 14],
  36514. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  36515. [7, 10], [7, 10], [7, 10], [7, 10],
  36516. [7, 10], [7, 10], [7, 10], [7, 10],
  36517. [7, 10], [7, 10], [7, 10], [7, 10],
  36518. [7, 10], [7, 10], [7, 10], [7, 10],
  36519. [7, 10], [7, 10], [7, 10], [7, 10],
  36520. [7, 10], [7, 10], [7, 10], [7, 10],
  36521. [7, 10], [7, 10], [7, 10], [7, 10],
  36522. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  36523. [7, 11], [7, 11], [7, 11], [7, 11],
  36524. [7, 11], [7, 11], [7, 11], [7, 11],
  36525. [7, 11], [7, 11], [7, 11], [7, 11],
  36526. [7, 11], [7, 11], [7, 11], [7, 11],
  36527. [7, 11], [7, 11], [7, 11], [7, 11],
  36528. [7, 11], [7, 11], [7, 11], [7, 11],
  36529. [7, 11], [7, 11], [7, 11], [7, 11],
  36530. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  36531. [9, 15], [9, 15], [9, 15], [9, 15],
  36532. [12, 128], // 000011001000
  36533. [12, 192], // 000011001001
  36534. [12, 26], // 000011001010
  36535. [12, 27], // 000011001011
  36536. [12, 28], // 000011001100
  36537. [12, 29], // 000011001101
  36538. [11, 19], [11, 19], // 00001100111x
  36539. [11, 20], [11, 20], // 00001101000x
  36540. [12, 34], // 000011010010
  36541. [12, 35], // 000011010011
  36542. [12, 36], // 000011010100
  36543. [12, 37], // 000011010101
  36544. [12, 38], // 000011010110
  36545. [12, 39], // 000011010111
  36546. [11, 21], [11, 21], // 00001101100x
  36547. [12, 42], // 000011011010
  36548. [12, 43], // 000011011011
  36549. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  36550. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  36551. [7, 12], [7, 12], [7, 12], [7, 12],
  36552. [7, 12], [7, 12], [7, 12], [7, 12],
  36553. [7, 12], [7, 12], [7, 12], [7, 12],
  36554. [7, 12], [7, 12], [7, 12], [7, 12],
  36555. [7, 12], [7, 12], [7, 12], [7, 12],
  36556. [7, 12], [7, 12], [7, 12], [7, 12],
  36557. [7, 12], [7, 12], [7, 12], [7, 12]
  36558. ];
  36559. var blackTable3 = [
  36560. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  36561. [6, 9], // 000100
  36562. [6, 8], // 000101
  36563. [5, 7], [5, 7], // 00011x
  36564. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  36565. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  36566. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  36567. [3, 1], [3, 1], [3, 1], [3, 1],
  36568. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  36569. [3, 4], [3, 4], [3, 4], [3, 4],
  36570. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  36571. [2, 3], [2, 3], [2, 3], [2, 3],
  36572. [2, 3], [2, 3], [2, 3], [2, 3],
  36573. [2, 3], [2, 3], [2, 3], [2, 3],
  36574. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  36575. [2, 2], [2, 2], [2, 2], [2, 2],
  36576. [2, 2], [2, 2], [2, 2], [2, 2],
  36577. [2, 2], [2, 2], [2, 2], [2, 2]
  36578. ];
  36579. function CCITTFaxStream(str, maybeLength, params) {
  36580. this.str = str;
  36581. this.dict = str.dict;
  36582. params = params || Dict.empty;
  36583. this.encoding = params.get('K') || 0;
  36584. this.eoline = params.get('EndOfLine') || false;
  36585. this.byteAlign = params.get('EncodedByteAlign') || false;
  36586. this.columns = params.get('Columns') || 1728;
  36587. this.rows = params.get('Rows') || 0;
  36588. var eoblock = params.get('EndOfBlock');
  36589. if (eoblock === null || eoblock === undefined) {
  36590. eoblock = true;
  36591. }
  36592. this.eoblock = eoblock;
  36593. this.black = params.get('BlackIs1') || false;
  36594. this.codingLine = new Uint32Array(this.columns + 1);
  36595. this.refLine = new Uint32Array(this.columns + 2);
  36596. this.codingLine[0] = this.columns;
  36597. this.codingPos = 0;
  36598. this.row = 0;
  36599. this.nextLine2D = this.encoding < 0;
  36600. this.inputBits = 0;
  36601. this.inputBuf = 0;
  36602. this.outputBits = 0;
  36603. var code1;
  36604. while ((code1 = this.lookBits(12)) === 0) {
  36605. this.eatBits(1);
  36606. }
  36607. if (code1 === 1) {
  36608. this.eatBits(12);
  36609. }
  36610. if (this.encoding > 0) {
  36611. this.nextLine2D = !this.lookBits(1);
  36612. this.eatBits(1);
  36613. }
  36614. DecodeStream.call(this, maybeLength);
  36615. }
  36616. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  36617. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  36618. while (!this.eof) {
  36619. var c = this.lookChar();
  36620. this.ensureBuffer(this.bufferLength + 1);
  36621. this.buffer[this.bufferLength++] = c;
  36622. }
  36623. };
  36624. CCITTFaxStream.prototype.addPixels =
  36625. function ccittFaxStreamAddPixels(a1, blackPixels) {
  36626. var codingLine = this.codingLine;
  36627. var codingPos = this.codingPos;
  36628. if (a1 > codingLine[codingPos]) {
  36629. if (a1 > this.columns) {
  36630. info('row is wrong length');
  36631. this.err = true;
  36632. a1 = this.columns;
  36633. }
  36634. if ((codingPos & 1) ^ blackPixels) {
  36635. ++codingPos;
  36636. }
  36637. codingLine[codingPos] = a1;
  36638. }
  36639. this.codingPos = codingPos;
  36640. };
  36641. CCITTFaxStream.prototype.addPixelsNeg =
  36642. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  36643. var codingLine = this.codingLine;
  36644. var codingPos = this.codingPos;
  36645. if (a1 > codingLine[codingPos]) {
  36646. if (a1 > this.columns) {
  36647. info('row is wrong length');
  36648. this.err = true;
  36649. a1 = this.columns;
  36650. }
  36651. if ((codingPos & 1) ^ blackPixels) {
  36652. ++codingPos;
  36653. }
  36654. codingLine[codingPos] = a1;
  36655. } else if (a1 < codingLine[codingPos]) {
  36656. if (a1 < 0) {
  36657. info('invalid code');
  36658. this.err = true;
  36659. a1 = 0;
  36660. }
  36661. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  36662. --codingPos;
  36663. }
  36664. codingLine[codingPos] = a1;
  36665. }
  36666. this.codingPos = codingPos;
  36667. };
  36668. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  36669. var refLine = this.refLine;
  36670. var codingLine = this.codingLine;
  36671. var columns = this.columns;
  36672. var refPos, blackPixels, bits, i;
  36673. if (this.outputBits === 0) {
  36674. if (this.eof) {
  36675. return null;
  36676. }
  36677. this.err = false;
  36678. var code1, code2, code3;
  36679. if (this.nextLine2D) {
  36680. for (i = 0; codingLine[i] < columns; ++i) {
  36681. refLine[i] = codingLine[i];
  36682. }
  36683. refLine[i++] = columns;
  36684. refLine[i] = columns;
  36685. codingLine[0] = 0;
  36686. this.codingPos = 0;
  36687. refPos = 0;
  36688. blackPixels = 0;
  36689. while (codingLine[this.codingPos] < columns) {
  36690. code1 = this.getTwoDimCode();
  36691. switch (code1) {
  36692. case twoDimPass:
  36693. this.addPixels(refLine[refPos + 1], blackPixels);
  36694. if (refLine[refPos + 1] < columns) {
  36695. refPos += 2;
  36696. }
  36697. break;
  36698. case twoDimHoriz:
  36699. code1 = code2 = 0;
  36700. if (blackPixels) {
  36701. do {
  36702. code1 += (code3 = this.getBlackCode());
  36703. } while (code3 >= 64);
  36704. do {
  36705. code2 += (code3 = this.getWhiteCode());
  36706. } while (code3 >= 64);
  36707. } else {
  36708. do {
  36709. code1 += (code3 = this.getWhiteCode());
  36710. } while (code3 >= 64);
  36711. do {
  36712. code2 += (code3 = this.getBlackCode());
  36713. } while (code3 >= 64);
  36714. }
  36715. this.addPixels(codingLine[this.codingPos] +
  36716. code1, blackPixels);
  36717. if (codingLine[this.codingPos] < columns) {
  36718. this.addPixels(codingLine[this.codingPos] + code2,
  36719. blackPixels ^ 1);
  36720. }
  36721. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36722. refLine[refPos] < columns) {
  36723. refPos += 2;
  36724. }
  36725. break;
  36726. case twoDimVertR3:
  36727. this.addPixels(refLine[refPos] + 3, blackPixels);
  36728. blackPixels ^= 1;
  36729. if (codingLine[this.codingPos] < columns) {
  36730. ++refPos;
  36731. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36732. refLine[refPos] < columns) {
  36733. refPos += 2;
  36734. }
  36735. }
  36736. break;
  36737. case twoDimVertR2:
  36738. this.addPixels(refLine[refPos] + 2, blackPixels);
  36739. blackPixels ^= 1;
  36740. if (codingLine[this.codingPos] < columns) {
  36741. ++refPos;
  36742. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36743. refLine[refPos] < columns) {
  36744. refPos += 2;
  36745. }
  36746. }
  36747. break;
  36748. case twoDimVertR1:
  36749. this.addPixels(refLine[refPos] + 1, blackPixels);
  36750. blackPixels ^= 1;
  36751. if (codingLine[this.codingPos] < columns) {
  36752. ++refPos;
  36753. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36754. refLine[refPos] < columns) {
  36755. refPos += 2;
  36756. }
  36757. }
  36758. break;
  36759. case twoDimVert0:
  36760. this.addPixels(refLine[refPos], blackPixels);
  36761. blackPixels ^= 1;
  36762. if (codingLine[this.codingPos] < columns) {
  36763. ++refPos;
  36764. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36765. refLine[refPos] < columns) {
  36766. refPos += 2;
  36767. }
  36768. }
  36769. break;
  36770. case twoDimVertL3:
  36771. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  36772. blackPixels ^= 1;
  36773. if (codingLine[this.codingPos] < columns) {
  36774. if (refPos > 0) {
  36775. --refPos;
  36776. } else {
  36777. ++refPos;
  36778. }
  36779. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36780. refLine[refPos] < columns) {
  36781. refPos += 2;
  36782. }
  36783. }
  36784. break;
  36785. case twoDimVertL2:
  36786. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  36787. blackPixels ^= 1;
  36788. if (codingLine[this.codingPos] < columns) {
  36789. if (refPos > 0) {
  36790. --refPos;
  36791. } else {
  36792. ++refPos;
  36793. }
  36794. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36795. refLine[refPos] < columns) {
  36796. refPos += 2;
  36797. }
  36798. }
  36799. break;
  36800. case twoDimVertL1:
  36801. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  36802. blackPixels ^= 1;
  36803. if (codingLine[this.codingPos] < columns) {
  36804. if (refPos > 0) {
  36805. --refPos;
  36806. } else {
  36807. ++refPos;
  36808. }
  36809. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36810. refLine[refPos] < columns) {
  36811. refPos += 2;
  36812. }
  36813. }
  36814. break;
  36815. case EOF:
  36816. this.addPixels(columns, 0);
  36817. this.eof = true;
  36818. break;
  36819. default:
  36820. info('bad 2d code');
  36821. this.addPixels(columns, 0);
  36822. this.err = true;
  36823. }
  36824. }
  36825. } else {
  36826. codingLine[0] = 0;
  36827. this.codingPos = 0;
  36828. blackPixels = 0;
  36829. while (codingLine[this.codingPos] < columns) {
  36830. code1 = 0;
  36831. if (blackPixels) {
  36832. do {
  36833. code1 += (code3 = this.getBlackCode());
  36834. } while (code3 >= 64);
  36835. } else {
  36836. do {
  36837. code1 += (code3 = this.getWhiteCode());
  36838. } while (code3 >= 64);
  36839. }
  36840. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  36841. blackPixels ^= 1;
  36842. }
  36843. }
  36844. var gotEOL = false;
  36845. if (!this.eoblock && this.row === this.rows - 1) {
  36846. this.eof = true;
  36847. } else {
  36848. code1 = this.lookBits(12);
  36849. if (this.eoline) {
  36850. while (code1 !== EOF && code1 !== 1) {
  36851. this.eatBits(1);
  36852. code1 = this.lookBits(12);
  36853. }
  36854. } else {
  36855. while (code1 === 0) {
  36856. this.eatBits(1);
  36857. code1 = this.lookBits(12);
  36858. }
  36859. }
  36860. if (code1 === 1) {
  36861. this.eatBits(12);
  36862. gotEOL = true;
  36863. } else if (code1 === EOF) {
  36864. this.eof = true;
  36865. }
  36866. }
  36867. if (this.byteAlign && !gotEOL) {
  36868. this.inputBits &= ~7;
  36869. }
  36870. if (!this.eof && this.encoding > 0) {
  36871. this.nextLine2D = !this.lookBits(1);
  36872. this.eatBits(1);
  36873. }
  36874. if (this.eoblock && gotEOL && this.byteAlign) {
  36875. code1 = this.lookBits(12);
  36876. if (code1 === 1) {
  36877. this.eatBits(12);
  36878. if (this.encoding > 0) {
  36879. this.lookBits(1);
  36880. this.eatBits(1);
  36881. }
  36882. if (this.encoding >= 0) {
  36883. for (i = 0; i < 4; ++i) {
  36884. code1 = this.lookBits(12);
  36885. if (code1 !== 1) {
  36886. info('bad rtc code: ' + code1);
  36887. }
  36888. this.eatBits(12);
  36889. if (this.encoding > 0) {
  36890. this.lookBits(1);
  36891. this.eatBits(1);
  36892. }
  36893. }
  36894. }
  36895. this.eof = true;
  36896. }
  36897. } else if (this.err && this.eoline) {
  36898. while (true) {
  36899. code1 = this.lookBits(13);
  36900. if (code1 === EOF) {
  36901. this.eof = true;
  36902. return null;
  36903. }
  36904. if ((code1 >> 1) === 1) {
  36905. break;
  36906. }
  36907. this.eatBits(1);
  36908. }
  36909. this.eatBits(12);
  36910. if (this.encoding > 0) {
  36911. this.eatBits(1);
  36912. this.nextLine2D = !(code1 & 1);
  36913. }
  36914. }
  36915. if (codingLine[0] > 0) {
  36916. this.outputBits = codingLine[this.codingPos = 0];
  36917. } else {
  36918. this.outputBits = codingLine[this.codingPos = 1];
  36919. }
  36920. this.row++;
  36921. }
  36922. var c;
  36923. if (this.outputBits >= 8) {
  36924. c = (this.codingPos & 1) ? 0 : 0xFF;
  36925. this.outputBits -= 8;
  36926. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  36927. this.codingPos++;
  36928. this.outputBits = (codingLine[this.codingPos] -
  36929. codingLine[this.codingPos - 1]);
  36930. }
  36931. } else {
  36932. bits = 8;
  36933. c = 0;
  36934. do {
  36935. if (this.outputBits > bits) {
  36936. c <<= bits;
  36937. if (!(this.codingPos & 1)) {
  36938. c |= 0xFF >> (8 - bits);
  36939. }
  36940. this.outputBits -= bits;
  36941. bits = 0;
  36942. } else {
  36943. c <<= this.outputBits;
  36944. if (!(this.codingPos & 1)) {
  36945. c |= 0xFF >> (8 - this.outputBits);
  36946. }
  36947. bits -= this.outputBits;
  36948. this.outputBits = 0;
  36949. if (codingLine[this.codingPos] < columns) {
  36950. this.codingPos++;
  36951. this.outputBits = (codingLine[this.codingPos] -
  36952. codingLine[this.codingPos - 1]);
  36953. } else if (bits > 0) {
  36954. c <<= bits;
  36955. bits = 0;
  36956. }
  36957. }
  36958. } while (bits);
  36959. }
  36960. if (this.black) {
  36961. c ^= 0xFF;
  36962. }
  36963. return c;
  36964. };
  36965. // This functions returns the code found from the table.
  36966. // The start and end parameters set the boundaries for searching the table.
  36967. // The limit parameter is optional. Function returns an array with three
  36968. // values. The first array element indicates whether a valid code is being
  36969. // returned. The second array element is the actual code. The third array
  36970. // element indicates whether EOF was reached.
  36971. CCITTFaxStream.prototype.findTableCode =
  36972. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  36973. var limitValue = limit || 0;
  36974. for (var i = start; i <= end; ++i) {
  36975. var code = this.lookBits(i);
  36976. if (code === EOF) {
  36977. return [true, 1, false];
  36978. }
  36979. if (i < end) {
  36980. code <<= end - i;
  36981. }
  36982. if (!limitValue || code >= limitValue) {
  36983. var p = table[code - limitValue];
  36984. if (p[0] === i) {
  36985. this.eatBits(i);
  36986. return [true, p[1], true];
  36987. }
  36988. }
  36989. }
  36990. return [false, 0, false];
  36991. };
  36992. CCITTFaxStream.prototype.getTwoDimCode =
  36993. function ccittFaxStreamGetTwoDimCode() {
  36994. var code = 0;
  36995. var p;
  36996. if (this.eoblock) {
  36997. code = this.lookBits(7);
  36998. p = twoDimTable[code];
  36999. if (p && p[0] > 0) {
  37000. this.eatBits(p[0]);
  37001. return p[1];
  37002. }
  37003. } else {
  37004. var result = this.findTableCode(1, 7, twoDimTable);
  37005. if (result[0] && result[2]) {
  37006. return result[1];
  37007. }
  37008. }
  37009. info('Bad two dim code');
  37010. return EOF;
  37011. };
  37012. CCITTFaxStream.prototype.getWhiteCode =
  37013. function ccittFaxStreamGetWhiteCode() {
  37014. var code = 0;
  37015. var p;
  37016. if (this.eoblock) {
  37017. code = this.lookBits(12);
  37018. if (code === EOF) {
  37019. return 1;
  37020. }
  37021. if ((code >> 5) === 0) {
  37022. p = whiteTable1[code];
  37023. } else {
  37024. p = whiteTable2[code >> 3];
  37025. }
  37026. if (p[0] > 0) {
  37027. this.eatBits(p[0]);
  37028. return p[1];
  37029. }
  37030. } else {
  37031. var result = this.findTableCode(1, 9, whiteTable2);
  37032. if (result[0]) {
  37033. return result[1];
  37034. }
  37035. result = this.findTableCode(11, 12, whiteTable1);
  37036. if (result[0]) {
  37037. return result[1];
  37038. }
  37039. }
  37040. info('bad white code');
  37041. this.eatBits(1);
  37042. return 1;
  37043. };
  37044. CCITTFaxStream.prototype.getBlackCode =
  37045. function ccittFaxStreamGetBlackCode() {
  37046. var code, p;
  37047. if (this.eoblock) {
  37048. code = this.lookBits(13);
  37049. if (code === EOF) {
  37050. return 1;
  37051. }
  37052. if ((code >> 7) === 0) {
  37053. p = blackTable1[code];
  37054. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  37055. p = blackTable2[(code >> 1) - 64];
  37056. } else {
  37057. p = blackTable3[code >> 7];
  37058. }
  37059. if (p[0] > 0) {
  37060. this.eatBits(p[0]);
  37061. return p[1];
  37062. }
  37063. } else {
  37064. var result = this.findTableCode(2, 6, blackTable3);
  37065. if (result[0]) {
  37066. return result[1];
  37067. }
  37068. result = this.findTableCode(7, 12, blackTable2, 64);
  37069. if (result[0]) {
  37070. return result[1];
  37071. }
  37072. result = this.findTableCode(10, 13, blackTable1);
  37073. if (result[0]) {
  37074. return result[1];
  37075. }
  37076. }
  37077. info('bad black code');
  37078. this.eatBits(1);
  37079. return 1;
  37080. };
  37081. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  37082. var c;
  37083. while (this.inputBits < n) {
  37084. if ((c = this.str.getByte()) === -1) {
  37085. if (this.inputBits === 0) {
  37086. return EOF;
  37087. }
  37088. return ((this.inputBuf << (n - this.inputBits)) &
  37089. (0xFFFF >> (16 - n)));
  37090. }
  37091. this.inputBuf = (this.inputBuf << 8) + c;
  37092. this.inputBits += 8;
  37093. }
  37094. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  37095. };
  37096. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  37097. if ((this.inputBits -= n) < 0) {
  37098. this.inputBits = 0;
  37099. }
  37100. };
  37101. return CCITTFaxStream;
  37102. })();
  37103. var LZWStream = (function LZWStreamClosure() {
  37104. function LZWStream(str, maybeLength, earlyChange) {
  37105. this.str = str;
  37106. this.dict = str.dict;
  37107. this.cachedData = 0;
  37108. this.bitsCached = 0;
  37109. var maxLzwDictionarySize = 4096;
  37110. var lzwState = {
  37111. earlyChange: earlyChange,
  37112. codeLength: 9,
  37113. nextCode: 258,
  37114. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  37115. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  37116. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  37117. currentSequence: new Uint8Array(maxLzwDictionarySize),
  37118. currentSequenceLength: 0
  37119. };
  37120. for (var i = 0; i < 256; ++i) {
  37121. lzwState.dictionaryValues[i] = i;
  37122. lzwState.dictionaryLengths[i] = 1;
  37123. }
  37124. this.lzwState = lzwState;
  37125. DecodeStream.call(this, maybeLength);
  37126. }
  37127. LZWStream.prototype = Object.create(DecodeStream.prototype);
  37128. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  37129. var bitsCached = this.bitsCached;
  37130. var cachedData = this.cachedData;
  37131. while (bitsCached < n) {
  37132. var c = this.str.getByte();
  37133. if (c === -1) {
  37134. this.eof = true;
  37135. return null;
  37136. }
  37137. cachedData = (cachedData << 8) | c;
  37138. bitsCached += 8;
  37139. }
  37140. this.bitsCached = (bitsCached -= n);
  37141. this.cachedData = cachedData;
  37142. this.lastCode = null;
  37143. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  37144. };
  37145. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  37146. var blockSize = 512;
  37147. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  37148. var i, j, q;
  37149. var lzwState = this.lzwState;
  37150. if (!lzwState) {
  37151. return; // eof was found
  37152. }
  37153. var earlyChange = lzwState.earlyChange;
  37154. var nextCode = lzwState.nextCode;
  37155. var dictionaryValues = lzwState.dictionaryValues;
  37156. var dictionaryLengths = lzwState.dictionaryLengths;
  37157. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  37158. var codeLength = lzwState.codeLength;
  37159. var prevCode = lzwState.prevCode;
  37160. var currentSequence = lzwState.currentSequence;
  37161. var currentSequenceLength = lzwState.currentSequenceLength;
  37162. var decodedLength = 0;
  37163. var currentBufferLength = this.bufferLength;
  37164. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37165. for (i = 0; i < blockSize; i++) {
  37166. var code = this.readBits(codeLength);
  37167. var hasPrev = currentSequenceLength > 0;
  37168. if (code < 256) {
  37169. currentSequence[0] = code;
  37170. currentSequenceLength = 1;
  37171. } else if (code >= 258) {
  37172. if (code < nextCode) {
  37173. currentSequenceLength = dictionaryLengths[code];
  37174. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  37175. currentSequence[j] = dictionaryValues[q];
  37176. q = dictionaryPrevCodes[q];
  37177. }
  37178. } else {
  37179. currentSequence[currentSequenceLength++] = currentSequence[0];
  37180. }
  37181. } else if (code === 256) {
  37182. codeLength = 9;
  37183. nextCode = 258;
  37184. currentSequenceLength = 0;
  37185. continue;
  37186. } else {
  37187. this.eof = true;
  37188. delete this.lzwState;
  37189. break;
  37190. }
  37191. if (hasPrev) {
  37192. dictionaryPrevCodes[nextCode] = prevCode;
  37193. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  37194. dictionaryValues[nextCode] = currentSequence[0];
  37195. nextCode++;
  37196. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  37197. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  37198. 0.6931471805599453 + 1, 12) | 0;
  37199. }
  37200. prevCode = code;
  37201. decodedLength += currentSequenceLength;
  37202. if (estimatedDecodedSize < decodedLength) {
  37203. do {
  37204. estimatedDecodedSize += decodedSizeDelta;
  37205. } while (estimatedDecodedSize < decodedLength);
  37206. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37207. }
  37208. for (j = 0; j < currentSequenceLength; j++) {
  37209. buffer[currentBufferLength++] = currentSequence[j];
  37210. }
  37211. }
  37212. lzwState.nextCode = nextCode;
  37213. lzwState.codeLength = codeLength;
  37214. lzwState.prevCode = prevCode;
  37215. lzwState.currentSequenceLength = currentSequenceLength;
  37216. this.bufferLength = currentBufferLength;
  37217. };
  37218. return LZWStream;
  37219. })();
  37220. var NullStream = (function NullStreamClosure() {
  37221. function NullStream() {
  37222. Stream.call(this, new Uint8Array(0));
  37223. }
  37224. NullStream.prototype = Stream.prototype;
  37225. return NullStream;
  37226. })();
  37227. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  37228. setup: function wphSetup(handler) {
  37229. var pdfManager;
  37230. function loadDocument(recoveryMode) {
  37231. var loadDocumentCapability = createPromiseCapability();
  37232. var parseSuccess = function parseSuccess() {
  37233. var numPagesPromise = pdfManager.ensureDoc('numPages');
  37234. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  37235. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  37236. Promise.all([numPagesPromise, fingerprintPromise,
  37237. encryptedPromise]).then(function onDocReady(results) {
  37238. var doc = {
  37239. numPages: results[0],
  37240. fingerprint: results[1],
  37241. encrypted: !!results[2],
  37242. };
  37243. loadDocumentCapability.resolve(doc);
  37244. },
  37245. parseFailure);
  37246. };
  37247. var parseFailure = function parseFailure(e) {
  37248. loadDocumentCapability.reject(e);
  37249. };
  37250. pdfManager.ensureDoc('checkHeader', []).then(function() {
  37251. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  37252. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  37253. parseSuccess, parseFailure);
  37254. }, parseFailure);
  37255. }, parseFailure);
  37256. return loadDocumentCapability.promise;
  37257. }
  37258. function getPdfManager(data) {
  37259. var pdfManagerCapability = createPromiseCapability();
  37260. var source = data.source;
  37261. var disableRange = data.disableRange;
  37262. if (source.data) {
  37263. try {
  37264. pdfManager = new LocalPdfManager(source.data, source.password);
  37265. pdfManagerCapability.resolve();
  37266. } catch (ex) {
  37267. pdfManagerCapability.reject(ex);
  37268. }
  37269. return pdfManagerCapability.promise;
  37270. } else if (source.chunkedViewerLoading) {
  37271. try {
  37272. pdfManager = new NetworkPdfManager(source, handler);
  37273. pdfManagerCapability.resolve();
  37274. } catch (ex) {
  37275. pdfManagerCapability.reject(ex);
  37276. }
  37277. return pdfManagerCapability.promise;
  37278. }
  37279. var networkManager = new NetworkManager(source.url, {
  37280. httpHeaders: source.httpHeaders,
  37281. withCredentials: source.withCredentials
  37282. });
  37283. var cachedChunks = [];
  37284. var fullRequestXhrId = networkManager.requestFull({
  37285. onHeadersReceived: function onHeadersReceived() {
  37286. if (disableRange) {
  37287. return;
  37288. }
  37289. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  37290. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  37291. return;
  37292. }
  37293. var contentEncoding =
  37294. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  37295. if (contentEncoding !== 'identity') {
  37296. return;
  37297. }
  37298. var length = fullRequestXhr.getResponseHeader('Content-Length');
  37299. length = parseInt(length, 10);
  37300. if (!isInt(length)) {
  37301. return;
  37302. }
  37303. source.length = length;
  37304. if (length <= 2 * RANGE_CHUNK_SIZE) {
  37305. // The file size is smaller than the size of two chunks, so it does
  37306. // not make any sense to abort the request and retry with a range
  37307. // request.
  37308. return;
  37309. }
  37310. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  37311. // We can continue fetching when progressive loading is enabled,
  37312. // and we don't need the autoFetch feature.
  37313. source.disableAutoFetch = true;
  37314. } else {
  37315. // NOTE: by cancelling the full request, and then issuing range
  37316. // requests, there will be an issue for sites where you can only
  37317. // request the pdf once. However, if this is the case, then the
  37318. // server should not be returning that it can support range
  37319. // requests.
  37320. networkManager.abortRequest(fullRequestXhrId);
  37321. }
  37322. try {
  37323. pdfManager = new NetworkPdfManager(source, handler);
  37324. pdfManagerCapability.resolve(pdfManager);
  37325. } catch (ex) {
  37326. pdfManagerCapability.reject(ex);
  37327. }
  37328. },
  37329. onProgressiveData: source.disableStream ? null :
  37330. function onProgressiveData(chunk) {
  37331. if (!pdfManager) {
  37332. cachedChunks.push(chunk);
  37333. return;
  37334. }
  37335. pdfManager.sendProgressiveData(chunk);
  37336. },
  37337. onDone: function onDone(args) {
  37338. if (pdfManager) {
  37339. return; // already processed
  37340. }
  37341. var pdfFile;
  37342. if (args === null) {
  37343. // TODO add some streaming manager, e.g. for unknown length files.
  37344. // The data was returned in the onProgressiveData, combining...
  37345. var pdfFileLength = 0, pos = 0;
  37346. cachedChunks.forEach(function (chunk) {
  37347. pdfFileLength += chunk.byteLength;
  37348. });
  37349. if (source.length && pdfFileLength !== source.length) {
  37350. warn('reported HTTP length is different from actual');
  37351. }
  37352. var pdfFileArray = new Uint8Array(pdfFileLength);
  37353. cachedChunks.forEach(function (chunk) {
  37354. pdfFileArray.set(new Uint8Array(chunk), pos);
  37355. pos += chunk.byteLength;
  37356. });
  37357. pdfFile = pdfFileArray.buffer;
  37358. } else {
  37359. pdfFile = args.chunk;
  37360. }
  37361. // the data is array, instantiating directly from it
  37362. try {
  37363. pdfManager = new LocalPdfManager(pdfFile, source.password);
  37364. pdfManagerCapability.resolve();
  37365. } catch (ex) {
  37366. pdfManagerCapability.reject(ex);
  37367. }
  37368. },
  37369. onError: function onError(status) {
  37370. var exception;
  37371. if (status === 404) {
  37372. exception = new MissingPDFException('Missing PDF "' +
  37373. source.url + '".');
  37374. handler.send('MissingPDF', exception);
  37375. } else {
  37376. exception = new UnexpectedResponseException(
  37377. 'Unexpected server response (' + status +
  37378. ') while retrieving PDF "' + source.url + '".', status);
  37379. handler.send('UnexpectedResponse', exception);
  37380. }
  37381. },
  37382. onProgress: function onProgress(evt) {
  37383. handler.send('DocProgress', {
  37384. loaded: evt.loaded,
  37385. total: evt.lengthComputable ? evt.total : source.length
  37386. });
  37387. }
  37388. });
  37389. return pdfManagerCapability.promise;
  37390. }
  37391. handler.on('test', function wphSetupTest(data) {
  37392. // check if Uint8Array can be sent to worker
  37393. if (!(data instanceof Uint8Array)) {
  37394. handler.send('test', false);
  37395. return;
  37396. }
  37397. // making sure postMessage transfers are working
  37398. var supportTransfers = data[0] === 255;
  37399. handler.postMessageTransfers = supportTransfers;
  37400. // check if the response property is supported by xhr
  37401. var xhr = new XMLHttpRequest();
  37402. var responseExists = 'response' in xhr;
  37403. // check if the property is actually implemented
  37404. try {
  37405. var dummy = xhr.responseType;
  37406. } catch (e) {
  37407. responseExists = false;
  37408. }
  37409. if (!responseExists) {
  37410. handler.send('test', false);
  37411. return;
  37412. }
  37413. handler.send('test', {
  37414. supportTypedArray: true,
  37415. supportTransfers: supportTransfers
  37416. });
  37417. });
  37418. handler.on('GetDocRequest', function wphSetupDoc(data) {
  37419. var onSuccess = function(doc) {
  37420. handler.send('GetDoc', { pdfInfo: doc });
  37421. };
  37422. var onFailure = function(e) {
  37423. if (e instanceof PasswordException) {
  37424. if (e.code === PasswordResponses.NEED_PASSWORD) {
  37425. handler.send('NeedPassword', e);
  37426. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  37427. handler.send('IncorrectPassword', e);
  37428. }
  37429. } else if (e instanceof InvalidPDFException) {
  37430. handler.send('InvalidPDF', e);
  37431. } else if (e instanceof MissingPDFException) {
  37432. handler.send('MissingPDF', e);
  37433. } else if (e instanceof UnexpectedResponseException) {
  37434. handler.send('UnexpectedResponse', e);
  37435. } else {
  37436. handler.send('UnknownError',
  37437. new UnknownErrorException(e.message, e.toString()));
  37438. }
  37439. };
  37440. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  37441. -1 : data.maxImageSize;
  37442. PDFJS.disableFontFace = data.disableFontFace;
  37443. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  37444. PDFJS.verbosity = data.verbosity;
  37445. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  37446. null : data.cMapUrl;
  37447. PDFJS.cMapPacked = data.cMapPacked === true;
  37448. getPdfManager(data).then(function () {
  37449. handler.send('PDFManagerReady', null);
  37450. pdfManager.onLoadedStream().then(function(stream) {
  37451. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  37452. });
  37453. }).then(function pdfManagerReady() {
  37454. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  37455. // Try again with recoveryMode == true
  37456. if (!(ex instanceof XRefParseException)) {
  37457. if (ex instanceof PasswordException) {
  37458. // after password exception prepare to receive a new password
  37459. // to repeat loading
  37460. pdfManager.passwordChanged().then(pdfManagerReady);
  37461. }
  37462. onFailure(ex);
  37463. return;
  37464. }
  37465. pdfManager.requestLoadedStream();
  37466. pdfManager.onLoadedStream().then(function() {
  37467. loadDocument(true).then(onSuccess, onFailure);
  37468. });
  37469. }, onFailure);
  37470. }, onFailure);
  37471. });
  37472. handler.on('GetPage', function wphSetupGetPage(data) {
  37473. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37474. var rotatePromise = pdfManager.ensure(page, 'rotate');
  37475. var refPromise = pdfManager.ensure(page, 'ref');
  37476. var viewPromise = pdfManager.ensure(page, 'view');
  37477. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  37478. function(results) {
  37479. return {
  37480. rotate: results[0],
  37481. ref: results[1],
  37482. view: results[2]
  37483. };
  37484. });
  37485. });
  37486. });
  37487. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  37488. var ref = new Ref(data.ref.num, data.ref.gen);
  37489. var catalog = pdfManager.pdfDocument.catalog;
  37490. return catalog.getPageIndex(ref);
  37491. });
  37492. handler.on('GetDestinations',
  37493. function wphSetupGetDestinations(data) {
  37494. return pdfManager.ensureCatalog('destinations');
  37495. }
  37496. );
  37497. handler.on('GetDestination',
  37498. function wphSetupGetDestination(data) {
  37499. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  37500. }
  37501. );
  37502. handler.on('GetAttachments',
  37503. function wphSetupGetAttachments(data) {
  37504. return pdfManager.ensureCatalog('attachments');
  37505. }
  37506. );
  37507. handler.on('GetJavaScript',
  37508. function wphSetupGetJavaScript(data) {
  37509. return pdfManager.ensureCatalog('javaScript');
  37510. }
  37511. );
  37512. handler.on('GetOutline',
  37513. function wphSetupGetOutline(data) {
  37514. return pdfManager.ensureCatalog('documentOutline');
  37515. }
  37516. );
  37517. handler.on('GetMetadata',
  37518. function wphSetupGetMetadata(data) {
  37519. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  37520. pdfManager.ensureCatalog('metadata')]);
  37521. }
  37522. );
  37523. handler.on('GetData', function wphSetupGetData(data) {
  37524. pdfManager.requestLoadedStream();
  37525. return pdfManager.onLoadedStream().then(function(stream) {
  37526. return stream.bytes;
  37527. });
  37528. });
  37529. handler.on('GetStats',
  37530. function wphSetupGetStats(data) {
  37531. return pdfManager.pdfDocument.xref.stats;
  37532. }
  37533. );
  37534. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  37535. pdfManager.updatePassword(data);
  37536. });
  37537. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  37538. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37539. return pdfManager.ensure(page, 'getAnnotationsData', []);
  37540. });
  37541. });
  37542. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  37543. pdfManager.getPage(data.pageIndex).then(function(page) {
  37544. var pageNum = data.pageIndex + 1;
  37545. var start = Date.now();
  37546. // Pre compile the pdf page and fetch the fonts/images.
  37547. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  37548. info('page=' + pageNum + ' - getOperatorList: time=' +
  37549. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  37550. }, function(e) {
  37551. var minimumStackMessage =
  37552. 'worker.js: while trying to getPage() and getOperatorList()';
  37553. var wrappedException;
  37554. // Turn the error into an obj that can be serialized
  37555. if (typeof e === 'string') {
  37556. wrappedException = {
  37557. message: e,
  37558. stack: minimumStackMessage
  37559. };
  37560. } else if (typeof e === 'object') {
  37561. wrappedException = {
  37562. message: e.message || e.toString(),
  37563. stack: e.stack || minimumStackMessage
  37564. };
  37565. } else {
  37566. wrappedException = {
  37567. message: 'Unknown exception type: ' + (typeof e),
  37568. stack: minimumStackMessage
  37569. };
  37570. }
  37571. handler.send('PageError', {
  37572. pageNum: pageNum,
  37573. error: wrappedException,
  37574. intent: data.intent
  37575. });
  37576. });
  37577. });
  37578. }, this);
  37579. handler.on('GetTextContent', function wphExtractText(data) {
  37580. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37581. var pageNum = data.pageIndex + 1;
  37582. var start = Date.now();
  37583. return page.extractTextContent().then(function(textContent) {
  37584. info('text indexing: page=' + pageNum + ' - time=' +
  37585. (Date.now() - start) + 'ms');
  37586. return textContent;
  37587. });
  37588. });
  37589. });
  37590. handler.on('Cleanup', function wphCleanup(data) {
  37591. return pdfManager.cleanup();
  37592. });
  37593. handler.on('Terminate', function wphTerminate(data) {
  37594. pdfManager.terminate();
  37595. });
  37596. }
  37597. };
  37598. var consoleTimer = {};
  37599. var workerConsole = {
  37600. log: function log() {
  37601. var args = Array.prototype.slice.call(arguments);
  37602. globalScope.postMessage({
  37603. action: 'console_log',
  37604. data: args
  37605. });
  37606. },
  37607. error: function error() {
  37608. var args = Array.prototype.slice.call(arguments);
  37609. globalScope.postMessage({
  37610. action: 'console_error',
  37611. data: args
  37612. });
  37613. throw 'pdf.js execution error';
  37614. },
  37615. time: function time(name) {
  37616. consoleTimer[name] = Date.now();
  37617. },
  37618. timeEnd: function timeEnd(name) {
  37619. var time = consoleTimer[name];
  37620. if (!time) {
  37621. error('Unknown timer name ' + name);
  37622. }
  37623. this.log('Timer:', name, Date.now() - time);
  37624. }
  37625. };
  37626. // Worker thread?
  37627. if (typeof window === 'undefined') {
  37628. if (!('console' in globalScope)) {
  37629. globalScope.console = workerConsole;
  37630. }
  37631. // Listen for unsupported features so we can pass them on to the main thread.
  37632. PDFJS.UnsupportedManager.listen(function (msg) {
  37633. globalScope.postMessage({
  37634. action: '_unsupported_feature',
  37635. data: msg
  37636. });
  37637. });
  37638. var handler = new MessageHandler('worker_processor', this);
  37639. WorkerMessageHandler.setup(handler);
  37640. }
  37641. /* This class implements the QM Coder decoding as defined in
  37642. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37643. * Annex C.3 Arithmetic decoding procedure
  37644. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  37645. *
  37646. * The arithmetic decoder is used in conjunction with context models to decode
  37647. * JPEG2000 and JBIG2 streams.
  37648. */
  37649. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  37650. // Table C-2
  37651. var QeTable = [
  37652. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  37653. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  37654. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  37655. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  37656. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  37657. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  37658. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  37659. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  37660. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  37661. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  37662. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  37663. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  37664. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  37665. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  37666. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  37667. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  37668. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  37669. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  37670. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  37671. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  37672. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  37673. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  37674. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  37675. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  37676. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  37677. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  37678. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  37679. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  37680. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  37681. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  37682. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  37683. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  37684. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  37685. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  37686. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  37687. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  37688. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  37689. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  37690. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  37691. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  37692. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  37693. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  37694. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  37695. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  37696. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  37697. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  37698. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  37699. ];
  37700. // C.3.5 Initialisation of the decoder (INITDEC)
  37701. function ArithmeticDecoder(data, start, end) {
  37702. this.data = data;
  37703. this.bp = start;
  37704. this.dataEnd = end;
  37705. this.chigh = data[start];
  37706. this.clow = 0;
  37707. this.byteIn();
  37708. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  37709. this.clow = (this.clow << 7) & 0xFFFF;
  37710. this.ct -= 7;
  37711. this.a = 0x8000;
  37712. }
  37713. ArithmeticDecoder.prototype = {
  37714. // C.3.4 Compressed data input (BYTEIN)
  37715. byteIn: function ArithmeticDecoder_byteIn() {
  37716. var data = this.data;
  37717. var bp = this.bp;
  37718. if (data[bp] === 0xFF) {
  37719. var b1 = data[bp + 1];
  37720. if (b1 > 0x8F) {
  37721. this.clow += 0xFF00;
  37722. this.ct = 8;
  37723. } else {
  37724. bp++;
  37725. this.clow += (data[bp] << 9);
  37726. this.ct = 7;
  37727. this.bp = bp;
  37728. }
  37729. } else {
  37730. bp++;
  37731. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  37732. this.ct = 8;
  37733. this.bp = bp;
  37734. }
  37735. if (this.clow > 0xFFFF) {
  37736. this.chigh += (this.clow >> 16);
  37737. this.clow &= 0xFFFF;
  37738. }
  37739. },
  37740. // C.3.2 Decoding a decision (DECODE)
  37741. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  37742. // contexts are packed into 1 byte:
  37743. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  37744. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  37745. var qeTableIcx = QeTable[cx_index];
  37746. var qeIcx = qeTableIcx.qe;
  37747. var d;
  37748. var a = this.a - qeIcx;
  37749. if (this.chigh < qeIcx) {
  37750. // exchangeLps
  37751. if (a < qeIcx) {
  37752. a = qeIcx;
  37753. d = cx_mps;
  37754. cx_index = qeTableIcx.nmps;
  37755. } else {
  37756. a = qeIcx;
  37757. d = 1 ^ cx_mps;
  37758. if (qeTableIcx.switchFlag === 1) {
  37759. cx_mps = d;
  37760. }
  37761. cx_index = qeTableIcx.nlps;
  37762. }
  37763. } else {
  37764. this.chigh -= qeIcx;
  37765. if ((a & 0x8000) !== 0) {
  37766. this.a = a;
  37767. return cx_mps;
  37768. }
  37769. // exchangeMps
  37770. if (a < qeIcx) {
  37771. d = 1 ^ cx_mps;
  37772. if (qeTableIcx.switchFlag === 1) {
  37773. cx_mps = d;
  37774. }
  37775. cx_index = qeTableIcx.nlps;
  37776. } else {
  37777. d = cx_mps;
  37778. cx_index = qeTableIcx.nmps;
  37779. }
  37780. }
  37781. // C.3.3 renormD;
  37782. do {
  37783. if (this.ct === 0) {
  37784. this.byteIn();
  37785. }
  37786. a <<= 1;
  37787. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  37788. this.clow = (this.clow << 1) & 0xFFFF;
  37789. this.ct--;
  37790. } while ((a & 0x8000) === 0);
  37791. this.a = a;
  37792. contexts[pos] = cx_index << 1 | cx_mps;
  37793. return d;
  37794. }
  37795. };
  37796. return ArithmeticDecoder;
  37797. })();
  37798. var JpegImage = (function jpegImage() {
  37799. var dctZigZag = new Uint8Array([
  37800. 0,
  37801. 1, 8,
  37802. 16, 9, 2,
  37803. 3, 10, 17, 24,
  37804. 32, 25, 18, 11, 4,
  37805. 5, 12, 19, 26, 33, 40,
  37806. 48, 41, 34, 27, 20, 13, 6,
  37807. 7, 14, 21, 28, 35, 42, 49, 56,
  37808. 57, 50, 43, 36, 29, 22, 15,
  37809. 23, 30, 37, 44, 51, 58,
  37810. 59, 52, 45, 38, 31,
  37811. 39, 46, 53, 60,
  37812. 61, 54, 47,
  37813. 55, 62,
  37814. 63
  37815. ]);
  37816. var dctCos1 = 4017; // cos(pi/16)
  37817. var dctSin1 = 799; // sin(pi/16)
  37818. var dctCos3 = 3406; // cos(3*pi/16)
  37819. var dctSin3 = 2276; // sin(3*pi/16)
  37820. var dctCos6 = 1567; // cos(6*pi/16)
  37821. var dctSin6 = 3784; // sin(6*pi/16)
  37822. var dctSqrt2 = 5793; // sqrt(2)
  37823. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  37824. function constructor() {
  37825. }
  37826. function buildHuffmanTable(codeLengths, values) {
  37827. var k = 0, code = [], i, j, length = 16;
  37828. while (length > 0 && !codeLengths[length - 1]) {
  37829. length--;
  37830. }
  37831. code.push({children: [], index: 0});
  37832. var p = code[0], q;
  37833. for (i = 0; i < length; i++) {
  37834. for (j = 0; j < codeLengths[i]; j++) {
  37835. p = code.pop();
  37836. p.children[p.index] = values[k];
  37837. while (p.index > 0) {
  37838. p = code.pop();
  37839. }
  37840. p.index++;
  37841. code.push(p);
  37842. while (code.length <= i) {
  37843. code.push(q = {children: [], index: 0});
  37844. p.children[p.index] = q.children;
  37845. p = q;
  37846. }
  37847. k++;
  37848. }
  37849. if (i + 1 < length) {
  37850. // p here points to last code
  37851. code.push(q = {children: [], index: 0});
  37852. p.children[p.index] = q.children;
  37853. p = q;
  37854. }
  37855. }
  37856. return code[0].children;
  37857. }
  37858. function getBlockBufferOffset(component, row, col) {
  37859. return 64 * ((component.blocksPerLine + 1) * row + col);
  37860. }
  37861. function decodeScan(data, offset, frame, components, resetInterval,
  37862. spectralStart, spectralEnd, successivePrev, successive) {
  37863. var precision = frame.precision;
  37864. var samplesPerLine = frame.samplesPerLine;
  37865. var scanLines = frame.scanLines;
  37866. var mcusPerLine = frame.mcusPerLine;
  37867. var progressive = frame.progressive;
  37868. var maxH = frame.maxH, maxV = frame.maxV;
  37869. var startOffset = offset, bitsData = 0, bitsCount = 0;
  37870. function readBit() {
  37871. if (bitsCount > 0) {
  37872. bitsCount--;
  37873. return (bitsData >> bitsCount) & 1;
  37874. }
  37875. bitsData = data[offset++];
  37876. if (bitsData === 0xFF) {
  37877. var nextByte = data[offset++];
  37878. if (nextByte) {
  37879. throw 'unexpected marker: ' +
  37880. ((bitsData << 8) | nextByte).toString(16);
  37881. }
  37882. // unstuff 0
  37883. }
  37884. bitsCount = 7;
  37885. return bitsData >>> 7;
  37886. }
  37887. function decodeHuffman(tree) {
  37888. var node = tree;
  37889. while (true) {
  37890. node = node[readBit()];
  37891. if (typeof node === 'number') {
  37892. return node;
  37893. }
  37894. if (typeof node !== 'object') {
  37895. throw 'invalid huffman sequence';
  37896. }
  37897. }
  37898. }
  37899. function receive(length) {
  37900. var n = 0;
  37901. while (length > 0) {
  37902. n = (n << 1) | readBit();
  37903. length--;
  37904. }
  37905. return n;
  37906. }
  37907. function receiveAndExtend(length) {
  37908. if (length === 1) {
  37909. return readBit() === 1 ? 1 : -1;
  37910. }
  37911. var n = receive(length);
  37912. if (n >= 1 << (length - 1)) {
  37913. return n;
  37914. }
  37915. return n + (-1 << length) + 1;
  37916. }
  37917. function decodeBaseline(component, offset) {
  37918. var t = decodeHuffman(component.huffmanTableDC);
  37919. var diff = t === 0 ? 0 : receiveAndExtend(t);
  37920. component.blockData[offset] = (component.pred += diff);
  37921. var k = 1;
  37922. while (k < 64) {
  37923. var rs = decodeHuffman(component.huffmanTableAC);
  37924. var s = rs & 15, r = rs >> 4;
  37925. if (s === 0) {
  37926. if (r < 15) {
  37927. break;
  37928. }
  37929. k += 16;
  37930. continue;
  37931. }
  37932. k += r;
  37933. var z = dctZigZag[k];
  37934. component.blockData[offset + z] = receiveAndExtend(s);
  37935. k++;
  37936. }
  37937. }
  37938. function decodeDCFirst(component, offset) {
  37939. var t = decodeHuffman(component.huffmanTableDC);
  37940. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  37941. component.blockData[offset] = (component.pred += diff);
  37942. }
  37943. function decodeDCSuccessive(component, offset) {
  37944. component.blockData[offset] |= readBit() << successive;
  37945. }
  37946. var eobrun = 0;
  37947. function decodeACFirst(component, offset) {
  37948. if (eobrun > 0) {
  37949. eobrun--;
  37950. return;
  37951. }
  37952. var k = spectralStart, e = spectralEnd;
  37953. while (k <= e) {
  37954. var rs = decodeHuffman(component.huffmanTableAC);
  37955. var s = rs & 15, r = rs >> 4;
  37956. if (s === 0) {
  37957. if (r < 15) {
  37958. eobrun = receive(r) + (1 << r) - 1;
  37959. break;
  37960. }
  37961. k += 16;
  37962. continue;
  37963. }
  37964. k += r;
  37965. var z = dctZigZag[k];
  37966. component.blockData[offset + z] =
  37967. receiveAndExtend(s) * (1 << successive);
  37968. k++;
  37969. }
  37970. }
  37971. var successiveACState = 0, successiveACNextValue;
  37972. function decodeACSuccessive(component, offset) {
  37973. var k = spectralStart;
  37974. var e = spectralEnd;
  37975. var r = 0;
  37976. var s;
  37977. var rs;
  37978. while (k <= e) {
  37979. var z = dctZigZag[k];
  37980. switch (successiveACState) {
  37981. case 0: // initial state
  37982. rs = decodeHuffman(component.huffmanTableAC);
  37983. s = rs & 15;
  37984. r = rs >> 4;
  37985. if (s === 0) {
  37986. if (r < 15) {
  37987. eobrun = receive(r) + (1 << r);
  37988. successiveACState = 4;
  37989. } else {
  37990. r = 16;
  37991. successiveACState = 1;
  37992. }
  37993. } else {
  37994. if (s !== 1) {
  37995. throw 'invalid ACn encoding';
  37996. }
  37997. successiveACNextValue = receiveAndExtend(s);
  37998. successiveACState = r ? 2 : 3;
  37999. }
  38000. continue;
  38001. case 1: // skipping r zero items
  38002. case 2:
  38003. if (component.blockData[offset + z]) {
  38004. component.blockData[offset + z] += (readBit() << successive);
  38005. } else {
  38006. r--;
  38007. if (r === 0) {
  38008. successiveACState = successiveACState === 2 ? 3 : 0;
  38009. }
  38010. }
  38011. break;
  38012. case 3: // set value for a zero item
  38013. if (component.blockData[offset + z]) {
  38014. component.blockData[offset + z] += (readBit() << successive);
  38015. } else {
  38016. component.blockData[offset + z] =
  38017. successiveACNextValue << successive;
  38018. successiveACState = 0;
  38019. }
  38020. break;
  38021. case 4: // eob
  38022. if (component.blockData[offset + z]) {
  38023. component.blockData[offset + z] += (readBit() << successive);
  38024. }
  38025. break;
  38026. }
  38027. k++;
  38028. }
  38029. if (successiveACState === 4) {
  38030. eobrun--;
  38031. if (eobrun === 0) {
  38032. successiveACState = 0;
  38033. }
  38034. }
  38035. }
  38036. function decodeMcu(component, decode, mcu, row, col) {
  38037. var mcuRow = (mcu / mcusPerLine) | 0;
  38038. var mcuCol = mcu % mcusPerLine;
  38039. var blockRow = mcuRow * component.v + row;
  38040. var blockCol = mcuCol * component.h + col;
  38041. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38042. decode(component, offset);
  38043. }
  38044. function decodeBlock(component, decode, mcu) {
  38045. var blockRow = (mcu / component.blocksPerLine) | 0;
  38046. var blockCol = mcu % component.blocksPerLine;
  38047. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38048. decode(component, offset);
  38049. }
  38050. var componentsLength = components.length;
  38051. var component, i, j, k, n;
  38052. var decodeFn;
  38053. if (progressive) {
  38054. if (spectralStart === 0) {
  38055. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  38056. } else {
  38057. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  38058. }
  38059. } else {
  38060. decodeFn = decodeBaseline;
  38061. }
  38062. var mcu = 0, marker;
  38063. var mcuExpected;
  38064. if (componentsLength === 1) {
  38065. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  38066. } else {
  38067. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  38068. }
  38069. if (!resetInterval) {
  38070. resetInterval = mcuExpected;
  38071. }
  38072. var h, v;
  38073. while (mcu < mcuExpected) {
  38074. // reset interval stuff
  38075. for (i = 0; i < componentsLength; i++) {
  38076. components[i].pred = 0;
  38077. }
  38078. eobrun = 0;
  38079. if (componentsLength === 1) {
  38080. component = components[0];
  38081. for (n = 0; n < resetInterval; n++) {
  38082. decodeBlock(component, decodeFn, mcu);
  38083. mcu++;
  38084. }
  38085. } else {
  38086. for (n = 0; n < resetInterval; n++) {
  38087. for (i = 0; i < componentsLength; i++) {
  38088. component = components[i];
  38089. h = component.h;
  38090. v = component.v;
  38091. for (j = 0; j < v; j++) {
  38092. for (k = 0; k < h; k++) {
  38093. decodeMcu(component, decodeFn, mcu, j, k);
  38094. }
  38095. }
  38096. }
  38097. mcu++;
  38098. }
  38099. }
  38100. // find marker
  38101. bitsCount = 0;
  38102. marker = (data[offset] << 8) | data[offset + 1];
  38103. if (marker <= 0xFF00) {
  38104. throw 'marker was not found';
  38105. }
  38106. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  38107. offset += 2;
  38108. } else {
  38109. break;
  38110. }
  38111. }
  38112. return offset - startOffset;
  38113. }
  38114. // A port of poppler's IDCT method which in turn is taken from:
  38115. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  38116. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  38117. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  38118. // 988-991.
  38119. function quantizeAndInverse(component, blockBufferOffset, p) {
  38120. var qt = component.quantizationTable, blockData = component.blockData;
  38121. var v0, v1, v2, v3, v4, v5, v6, v7;
  38122. var p0, p1, p2, p3, p4, p5, p6, p7;
  38123. var t;
  38124. // inverse DCT on rows
  38125. for (var row = 0; row < 64; row += 8) {
  38126. // gather block data
  38127. p0 = blockData[blockBufferOffset + row];
  38128. p1 = blockData[blockBufferOffset + row + 1];
  38129. p2 = blockData[blockBufferOffset + row + 2];
  38130. p3 = blockData[blockBufferOffset + row + 3];
  38131. p4 = blockData[blockBufferOffset + row + 4];
  38132. p5 = blockData[blockBufferOffset + row + 5];
  38133. p6 = blockData[blockBufferOffset + row + 6];
  38134. p7 = blockData[blockBufferOffset + row + 7];
  38135. // dequant p0
  38136. p0 *= qt[row];
  38137. // check for all-zero AC coefficients
  38138. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38139. t = (dctSqrt2 * p0 + 512) >> 10;
  38140. p[row] = t;
  38141. p[row + 1] = t;
  38142. p[row + 2] = t;
  38143. p[row + 3] = t;
  38144. p[row + 4] = t;
  38145. p[row + 5] = t;
  38146. p[row + 6] = t;
  38147. p[row + 7] = t;
  38148. continue;
  38149. }
  38150. // dequant p1 ... p7
  38151. p1 *= qt[row + 1];
  38152. p2 *= qt[row + 2];
  38153. p3 *= qt[row + 3];
  38154. p4 *= qt[row + 4];
  38155. p5 *= qt[row + 5];
  38156. p6 *= qt[row + 6];
  38157. p7 *= qt[row + 7];
  38158. // stage 4
  38159. v0 = (dctSqrt2 * p0 + 128) >> 8;
  38160. v1 = (dctSqrt2 * p4 + 128) >> 8;
  38161. v2 = p2;
  38162. v3 = p6;
  38163. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  38164. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  38165. v5 = p3 << 4;
  38166. v6 = p5 << 4;
  38167. // stage 3
  38168. v0 = (v0 + v1 + 1) >> 1;
  38169. v1 = v0 - v1;
  38170. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  38171. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  38172. v3 = t;
  38173. v4 = (v4 + v6 + 1) >> 1;
  38174. v6 = v4 - v6;
  38175. v7 = (v7 + v5 + 1) >> 1;
  38176. v5 = v7 - v5;
  38177. // stage 2
  38178. v0 = (v0 + v3 + 1) >> 1;
  38179. v3 = v0 - v3;
  38180. v1 = (v1 + v2 + 1) >> 1;
  38181. v2 = v1 - v2;
  38182. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38183. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38184. v7 = t;
  38185. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38186. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38187. v6 = t;
  38188. // stage 1
  38189. p[row] = v0 + v7;
  38190. p[row + 7] = v0 - v7;
  38191. p[row + 1] = v1 + v6;
  38192. p[row + 6] = v1 - v6;
  38193. p[row + 2] = v2 + v5;
  38194. p[row + 5] = v2 - v5;
  38195. p[row + 3] = v3 + v4;
  38196. p[row + 4] = v3 - v4;
  38197. }
  38198. // inverse DCT on columns
  38199. for (var col = 0; col < 8; ++col) {
  38200. p0 = p[col];
  38201. p1 = p[col + 8];
  38202. p2 = p[col + 16];
  38203. p3 = p[col + 24];
  38204. p4 = p[col + 32];
  38205. p5 = p[col + 40];
  38206. p6 = p[col + 48];
  38207. p7 = p[col + 56];
  38208. // check for all-zero AC coefficients
  38209. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38210. t = (dctSqrt2 * p0 + 8192) >> 14;
  38211. // convert to 8 bit
  38212. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  38213. blockData[blockBufferOffset + col] = t;
  38214. blockData[blockBufferOffset + col + 8] = t;
  38215. blockData[blockBufferOffset + col + 16] = t;
  38216. blockData[blockBufferOffset + col + 24] = t;
  38217. blockData[blockBufferOffset + col + 32] = t;
  38218. blockData[blockBufferOffset + col + 40] = t;
  38219. blockData[blockBufferOffset + col + 48] = t;
  38220. blockData[blockBufferOffset + col + 56] = t;
  38221. continue;
  38222. }
  38223. // stage 4
  38224. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  38225. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  38226. v2 = p2;
  38227. v3 = p6;
  38228. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  38229. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  38230. v5 = p3;
  38231. v6 = p5;
  38232. // stage 3
  38233. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  38234. // converting to UInt8 range later.
  38235. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  38236. v1 = v0 - v1;
  38237. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  38238. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  38239. v3 = t;
  38240. v4 = (v4 + v6 + 1) >> 1;
  38241. v6 = v4 - v6;
  38242. v7 = (v7 + v5 + 1) >> 1;
  38243. v5 = v7 - v5;
  38244. // stage 2
  38245. v0 = (v0 + v3 + 1) >> 1;
  38246. v3 = v0 - v3;
  38247. v1 = (v1 + v2 + 1) >> 1;
  38248. v2 = v1 - v2;
  38249. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38250. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38251. v7 = t;
  38252. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38253. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38254. v6 = t;
  38255. // stage 1
  38256. p0 = v0 + v7;
  38257. p7 = v0 - v7;
  38258. p1 = v1 + v6;
  38259. p6 = v1 - v6;
  38260. p2 = v2 + v5;
  38261. p5 = v2 - v5;
  38262. p3 = v3 + v4;
  38263. p4 = v3 - v4;
  38264. // convert to 8-bit integers
  38265. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  38266. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  38267. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  38268. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  38269. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  38270. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  38271. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  38272. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  38273. // store block data
  38274. blockData[blockBufferOffset + col] = p0;
  38275. blockData[blockBufferOffset + col + 8] = p1;
  38276. blockData[blockBufferOffset + col + 16] = p2;
  38277. blockData[blockBufferOffset + col + 24] = p3;
  38278. blockData[blockBufferOffset + col + 32] = p4;
  38279. blockData[blockBufferOffset + col + 40] = p5;
  38280. blockData[blockBufferOffset + col + 48] = p6;
  38281. blockData[blockBufferOffset + col + 56] = p7;
  38282. }
  38283. }
  38284. function buildComponentData(frame, component) {
  38285. var blocksPerLine = component.blocksPerLine;
  38286. var blocksPerColumn = component.blocksPerColumn;
  38287. var computationBuffer = new Int16Array(64);
  38288. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  38289. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  38290. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38291. quantizeAndInverse(component, offset, computationBuffer);
  38292. }
  38293. }
  38294. return component.blockData;
  38295. }
  38296. function clamp0to255(a) {
  38297. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  38298. }
  38299. constructor.prototype = {
  38300. parse: function parse(data) {
  38301. function readUint16() {
  38302. var value = (data[offset] << 8) | data[offset + 1];
  38303. offset += 2;
  38304. return value;
  38305. }
  38306. function readDataBlock() {
  38307. var length = readUint16();
  38308. var array = data.subarray(offset, offset + length - 2);
  38309. offset += array.length;
  38310. return array;
  38311. }
  38312. function prepareComponents(frame) {
  38313. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  38314. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  38315. for (var i = 0; i < frame.components.length; i++) {
  38316. component = frame.components[i];
  38317. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  38318. component.h / frame.maxH);
  38319. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  38320. component.v / frame.maxV);
  38321. var blocksPerLineForMcu = mcusPerLine * component.h;
  38322. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  38323. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  38324. (blocksPerLineForMcu + 1);
  38325. component.blockData = new Int16Array(blocksBufferSize);
  38326. component.blocksPerLine = blocksPerLine;
  38327. component.blocksPerColumn = blocksPerColumn;
  38328. }
  38329. frame.mcusPerLine = mcusPerLine;
  38330. frame.mcusPerColumn = mcusPerColumn;
  38331. }
  38332. var offset = 0, length = data.length;
  38333. var jfif = null;
  38334. var adobe = null;
  38335. var pixels = null;
  38336. var frame, resetInterval;
  38337. var quantizationTables = [];
  38338. var huffmanTablesAC = [], huffmanTablesDC = [];
  38339. var fileMarker = readUint16();
  38340. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  38341. throw 'SOI not found';
  38342. }
  38343. fileMarker = readUint16();
  38344. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  38345. var i, j, l;
  38346. switch(fileMarker) {
  38347. case 0xFFE0: // APP0 (Application Specific)
  38348. case 0xFFE1: // APP1
  38349. case 0xFFE2: // APP2
  38350. case 0xFFE3: // APP3
  38351. case 0xFFE4: // APP4
  38352. case 0xFFE5: // APP5
  38353. case 0xFFE6: // APP6
  38354. case 0xFFE7: // APP7
  38355. case 0xFFE8: // APP8
  38356. case 0xFFE9: // APP9
  38357. case 0xFFEA: // APP10
  38358. case 0xFFEB: // APP11
  38359. case 0xFFEC: // APP12
  38360. case 0xFFED: // APP13
  38361. case 0xFFEE: // APP14
  38362. case 0xFFEF: // APP15
  38363. case 0xFFFE: // COM (Comment)
  38364. var appData = readDataBlock();
  38365. if (fileMarker === 0xFFE0) {
  38366. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  38367. appData[2] === 0x49 && appData[3] === 0x46 &&
  38368. appData[4] === 0) { // 'JFIF\x00'
  38369. jfif = {
  38370. version: { major: appData[5], minor: appData[6] },
  38371. densityUnits: appData[7],
  38372. xDensity: (appData[8] << 8) | appData[9],
  38373. yDensity: (appData[10] << 8) | appData[11],
  38374. thumbWidth: appData[12],
  38375. thumbHeight: appData[13],
  38376. thumbData: appData.subarray(14, 14 +
  38377. 3 * appData[12] * appData[13])
  38378. };
  38379. }
  38380. }
  38381. // TODO APP1 - Exif
  38382. if (fileMarker === 0xFFEE) {
  38383. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  38384. appData[2] === 0x6F && appData[3] === 0x62 &&
  38385. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  38386. adobe = {
  38387. version: appData[6],
  38388. flags0: (appData[7] << 8) | appData[8],
  38389. flags1: (appData[9] << 8) | appData[10],
  38390. transformCode: appData[11]
  38391. };
  38392. }
  38393. }
  38394. break;
  38395. case 0xFFDB: // DQT (Define Quantization Tables)
  38396. var quantizationTablesLength = readUint16();
  38397. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  38398. var z;
  38399. while (offset < quantizationTablesEnd) {
  38400. var quantizationTableSpec = data[offset++];
  38401. var tableData = new Uint16Array(64);
  38402. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  38403. for (j = 0; j < 64; j++) {
  38404. z = dctZigZag[j];
  38405. tableData[z] = data[offset++];
  38406. }
  38407. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  38408. for (j = 0; j < 64; j++) {
  38409. z = dctZigZag[j];
  38410. tableData[z] = readUint16();
  38411. }
  38412. } else {
  38413. throw 'DQT: invalid table spec';
  38414. }
  38415. quantizationTables[quantizationTableSpec & 15] = tableData;
  38416. }
  38417. break;
  38418. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  38419. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  38420. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  38421. if (frame) {
  38422. throw 'Only single frame JPEGs supported';
  38423. }
  38424. readUint16(); // skip data length
  38425. frame = {};
  38426. frame.extended = (fileMarker === 0xFFC1);
  38427. frame.progressive = (fileMarker === 0xFFC2);
  38428. frame.precision = data[offset++];
  38429. frame.scanLines = readUint16();
  38430. frame.samplesPerLine = readUint16();
  38431. frame.components = [];
  38432. frame.componentIds = {};
  38433. var componentsCount = data[offset++], componentId;
  38434. var maxH = 0, maxV = 0;
  38435. for (i = 0; i < componentsCount; i++) {
  38436. componentId = data[offset];
  38437. var h = data[offset + 1] >> 4;
  38438. var v = data[offset + 1] & 15;
  38439. if (maxH < h) {
  38440. maxH = h;
  38441. }
  38442. if (maxV < v) {
  38443. maxV = v;
  38444. }
  38445. var qId = data[offset + 2];
  38446. l = frame.components.push({
  38447. h: h,
  38448. v: v,
  38449. quantizationTable: quantizationTables[qId]
  38450. });
  38451. frame.componentIds[componentId] = l - 1;
  38452. offset += 3;
  38453. }
  38454. frame.maxH = maxH;
  38455. frame.maxV = maxV;
  38456. prepareComponents(frame);
  38457. break;
  38458. case 0xFFC4: // DHT (Define Huffman Tables)
  38459. var huffmanLength = readUint16();
  38460. for (i = 2; i < huffmanLength;) {
  38461. var huffmanTableSpec = data[offset++];
  38462. var codeLengths = new Uint8Array(16);
  38463. var codeLengthSum = 0;
  38464. for (j = 0; j < 16; j++, offset++) {
  38465. codeLengthSum += (codeLengths[j] = data[offset]);
  38466. }
  38467. var huffmanValues = new Uint8Array(codeLengthSum);
  38468. for (j = 0; j < codeLengthSum; j++, offset++) {
  38469. huffmanValues[j] = data[offset];
  38470. }
  38471. i += 17 + codeLengthSum;
  38472. ((huffmanTableSpec >> 4) === 0 ?
  38473. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  38474. buildHuffmanTable(codeLengths, huffmanValues);
  38475. }
  38476. break;
  38477. case 0xFFDD: // DRI (Define Restart Interval)
  38478. readUint16(); // skip data length
  38479. resetInterval = readUint16();
  38480. break;
  38481. case 0xFFDA: // SOS (Start of Scan)
  38482. var scanLength = readUint16();
  38483. var selectorsCount = data[offset++];
  38484. var components = [], component;
  38485. for (i = 0; i < selectorsCount; i++) {
  38486. var componentIndex = frame.componentIds[data[offset++]];
  38487. component = frame.components[componentIndex];
  38488. var tableSpec = data[offset++];
  38489. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  38490. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  38491. components.push(component);
  38492. }
  38493. var spectralStart = data[offset++];
  38494. var spectralEnd = data[offset++];
  38495. var successiveApproximation = data[offset++];
  38496. var processed = decodeScan(data, offset,
  38497. frame, components, resetInterval,
  38498. spectralStart, spectralEnd,
  38499. successiveApproximation >> 4, successiveApproximation & 15);
  38500. offset += processed;
  38501. break;
  38502. default:
  38503. if (data[offset - 3] === 0xFF &&
  38504. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  38505. // could be incorrect encoding -- last 0xFF byte of the previous
  38506. // block was eaten by the encoder
  38507. offset -= 3;
  38508. break;
  38509. }
  38510. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  38511. }
  38512. fileMarker = readUint16();
  38513. }
  38514. this.width = frame.samplesPerLine;
  38515. this.height = frame.scanLines;
  38516. this.jfif = jfif;
  38517. this.adobe = adobe;
  38518. this.components = [];
  38519. for (i = 0; i < frame.components.length; i++) {
  38520. component = frame.components[i];
  38521. this.components.push({
  38522. output: buildComponentData(frame, component),
  38523. scaleX: component.h / frame.maxH,
  38524. scaleY: component.v / frame.maxV,
  38525. blocksPerLine: component.blocksPerLine,
  38526. blocksPerColumn: component.blocksPerColumn
  38527. });
  38528. }
  38529. this.numComponents = this.components.length;
  38530. },
  38531. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  38532. var scaleX = this.width / width, scaleY = this.height / height;
  38533. var component, componentScaleX, componentScaleY, blocksPerScanline;
  38534. var x, y, i, j, k;
  38535. var index;
  38536. var offset = 0;
  38537. var output;
  38538. var numComponents = this.components.length;
  38539. var dataLength = width * height * numComponents;
  38540. var data = new Uint8Array(dataLength);
  38541. var xScaleBlockOffset = new Uint32Array(width);
  38542. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  38543. for (i = 0; i < numComponents; i++) {
  38544. component = this.components[i];
  38545. componentScaleX = component.scaleX * scaleX;
  38546. componentScaleY = component.scaleY * scaleY;
  38547. offset = i;
  38548. output = component.output;
  38549. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  38550. // precalculate the xScaleBlockOffset
  38551. for (x = 0; x < width; x++) {
  38552. j = 0 | (x * componentScaleX);
  38553. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  38554. }
  38555. // linearize the blocks of the component
  38556. for (y = 0; y < height; y++) {
  38557. j = 0 | (y * componentScaleY);
  38558. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  38559. for (x = 0; x < width; x++) {
  38560. data[offset] = output[index + xScaleBlockOffset[x]];
  38561. offset += numComponents;
  38562. }
  38563. }
  38564. }
  38565. // decodeTransform contains pairs of multiplier (-256..256) and additive
  38566. var transform = this.decodeTransform;
  38567. if (transform) {
  38568. for (i = 0; i < dataLength;) {
  38569. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  38570. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  38571. }
  38572. }
  38573. }
  38574. return data;
  38575. },
  38576. _isColorConversionNeeded: function isColorConversionNeeded() {
  38577. if (this.adobe && this.adobe.transformCode) {
  38578. // The adobe transform marker overrides any previous setting
  38579. return true;
  38580. } else if (this.numComponents === 3) {
  38581. return true;
  38582. } else {
  38583. return false;
  38584. }
  38585. },
  38586. _convertYccToRgb: function convertYccToRgb(data) {
  38587. var Y, Cb, Cr;
  38588. for (var i = 0, length = data.length; i < length; i += 3) {
  38589. Y = data[i ];
  38590. Cb = data[i + 1];
  38591. Cr = data[i + 2];
  38592. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  38593. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  38594. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  38595. }
  38596. return data;
  38597. },
  38598. _convertYcckToRgb: function convertYcckToRgb(data) {
  38599. var Y, Cb, Cr, k;
  38600. var offset = 0;
  38601. for (var i = 0, length = data.length; i < length; i += 4) {
  38602. Y = data[i];
  38603. Cb = data[i + 1];
  38604. Cr = data[i + 2];
  38605. k = data[i + 3];
  38606. var r = -122.67195406894 +
  38607. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  38608. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  38609. 0.154362151871126) +
  38610. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  38611. 0.00477271405408747 * k + 1.53380253221734) +
  38612. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  38613. 0.48357088451265) +
  38614. k * (-0.000336197177618394 * k + 0.484791561490776);
  38615. var g = 107.268039397724 +
  38616. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  38617. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  38618. 0.176491792462875) +
  38619. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  38620. 0.000770482631801132 * k - 0.151051492775562) +
  38621. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  38622. 0.25802910206845) +
  38623. k * (-0.000318913117588328 * k - 0.213742400323665);
  38624. var b = -20.810012546947 +
  38625. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  38626. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  38627. 0.814272968359295) +
  38628. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  38629. 0.000560833691242812 * k - 0.195152027534049) +
  38630. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  38631. 0.116935020465145) +
  38632. k * (-0.000343531996510555 * k + 0.24165260232407);
  38633. data[offset++] = clamp0to255(r);
  38634. data[offset++] = clamp0to255(g);
  38635. data[offset++] = clamp0to255(b);
  38636. }
  38637. return data;
  38638. },
  38639. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  38640. var Y, Cb, Cr;
  38641. for (var i = 0, length = data.length; i < length; i += 4) {
  38642. Y = data[i];
  38643. Cb = data[i + 1];
  38644. Cr = data[i + 2];
  38645. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  38646. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  38647. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  38648. // K in data[i + 3] is unchanged
  38649. }
  38650. return data;
  38651. },
  38652. _convertCmykToRgb: function convertCmykToRgb(data) {
  38653. var c, m, y, k;
  38654. var offset = 0;
  38655. var min = -255 * 255 * 255;
  38656. var scale = 1 / 255 / 255;
  38657. for (var i = 0, length = data.length; i < length; i += 4) {
  38658. c = data[i];
  38659. m = data[i + 1];
  38660. y = data[i + 2];
  38661. k = data[i + 3];
  38662. var r =
  38663. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38664. 18.82290502165302 * y + 212.25662451639585 * k -
  38665. 72734.4411664936) +
  38666. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  38667. 17.873870861415444 * k - 1401.7366389350734) +
  38668. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38669. 4465.541406466231) -
  38670. k * (21.86122147463605 * k + 48317.86113160301);
  38671. var g =
  38672. c * (8.841041422036149 * c + 60.118027045597366 * m +
  38673. 6.871425592049007 * y + 31.159100130055922 * k -
  38674. 20220.756542821975) +
  38675. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38676. 131.35250912493976 * k - 48691.05921601825) +
  38677. y * (4.444339102852739 * y + 9.8632861493405 * k -
  38678. 6341.191035517494) -
  38679. k * (20.737325471181034 * k + 47890.15695978492);
  38680. var b =
  38681. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38682. 30.89978309703729 * y - 0.23883238689178934 * k -
  38683. 3616.812083916688) +
  38684. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38685. 50.606957656360734 * k - 28620.90484698408) +
  38686. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  38687. 49363.43385999684) -
  38688. k * (22.33816807309886 * k + 45932.16563550634);
  38689. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  38690. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  38691. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  38692. }
  38693. return data;
  38694. },
  38695. getData: function getData(width, height, forceRGBoutput) {
  38696. if (this.numComponents > 4) {
  38697. throw 'Unsupported color mode';
  38698. }
  38699. // type of data: Uint8Array(width * height * numComponents)
  38700. var data = this._getLinearizedBlockData(width, height);
  38701. if (this.numComponents === 3) {
  38702. return this._convertYccToRgb(data);
  38703. } else if (this.numComponents === 4) {
  38704. if (this._isColorConversionNeeded()) {
  38705. if (forceRGBoutput) {
  38706. return this._convertYcckToRgb(data);
  38707. } else {
  38708. return this._convertYcckToCmyk(data);
  38709. }
  38710. } else if (forceRGBoutput) {
  38711. return this._convertCmykToRgb(data);
  38712. }
  38713. }
  38714. return data;
  38715. }
  38716. };
  38717. return constructor;
  38718. })();
  38719. var JpxImage = (function JpxImageClosure() {
  38720. // Table E.1
  38721. var SubbandsGainLog2 = {
  38722. 'LL': 0,
  38723. 'LH': 1,
  38724. 'HL': 1,
  38725. 'HH': 2
  38726. };
  38727. function JpxImage() {
  38728. this.failOnCorruptedImage = false;
  38729. }
  38730. JpxImage.prototype = {
  38731. parse: function JpxImage_parse(data) {
  38732. var head = readUint16(data, 0);
  38733. // No box header, immediate start of codestream (SOC)
  38734. if (head === 0xFF4F) {
  38735. this.parseCodestream(data, 0, data.length);
  38736. return;
  38737. }
  38738. var position = 0, length = data.length;
  38739. while (position < length) {
  38740. var headerSize = 8;
  38741. var lbox = readUint32(data, position);
  38742. var tbox = readUint32(data, position + 4);
  38743. position += headerSize;
  38744. if (lbox === 1) {
  38745. // XLBox: read UInt64 according to spec.
  38746. // JavaScript's int precision of 53 bit should be sufficient here.
  38747. lbox = readUint32(data, position) * 4294967296 +
  38748. readUint32(data, position + 4);
  38749. position += 8;
  38750. headerSize += 8;
  38751. }
  38752. if (lbox === 0) {
  38753. lbox = length - position + headerSize;
  38754. }
  38755. if (lbox < headerSize) {
  38756. throw new Error('JPX Error: Invalid box field size');
  38757. }
  38758. var dataLength = lbox - headerSize;
  38759. var jumpDataLength = true;
  38760. switch (tbox) {
  38761. case 0x6A703268: // 'jp2h'
  38762. jumpDataLength = false; // parsing child boxes
  38763. break;
  38764. case 0x636F6C72: // 'colr'
  38765. // Colorspaces are not used, the CS from the PDF is used.
  38766. var method = data[position];
  38767. var precedence = data[position + 1];
  38768. var approximation = data[position + 2];
  38769. if (method === 1) {
  38770. // enumerated colorspace
  38771. var colorspace = readUint32(data, position + 3);
  38772. switch (colorspace) {
  38773. case 16: // this indicates a sRGB colorspace
  38774. case 17: // this indicates a grayscale colorspace
  38775. case 18: // this indicates a YUV colorspace
  38776. break;
  38777. default:
  38778. warn('Unknown colorspace ' + colorspace);
  38779. break;
  38780. }
  38781. } else if (method === 2) {
  38782. info('ICC profile not supported');
  38783. }
  38784. break;
  38785. case 0x6A703263: // 'jp2c'
  38786. this.parseCodestream(data, position, position + dataLength);
  38787. break;
  38788. case 0x6A502020: // 'jP\024\024'
  38789. if (0x0d0a870a !== readUint32(data, position)) {
  38790. warn('Invalid JP2 signature');
  38791. }
  38792. break;
  38793. // The following header types are valid but currently not used:
  38794. case 0x6A501A1A: // 'jP\032\032'
  38795. case 0x66747970: // 'ftyp'
  38796. case 0x72726571: // 'rreq'
  38797. case 0x72657320: // 'res '
  38798. case 0x69686472: // 'ihdr'
  38799. break;
  38800. default:
  38801. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  38802. (tbox >> 16) & 0xFF,
  38803. (tbox >> 8) & 0xFF,
  38804. tbox & 0xFF);
  38805. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  38806. break;
  38807. }
  38808. if (jumpDataLength) {
  38809. position += dataLength;
  38810. }
  38811. }
  38812. },
  38813. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  38814. var newByte = stream.getByte();
  38815. while (newByte >= 0) {
  38816. var oldByte = newByte;
  38817. newByte = stream.getByte();
  38818. var code = (oldByte << 8) | newByte;
  38819. // Image and tile size (SIZ)
  38820. if (code === 0xFF51) {
  38821. stream.skip(4);
  38822. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  38823. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  38824. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  38825. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  38826. stream.skip(16);
  38827. var Csiz = stream.getUint16(); // Byte 36
  38828. this.width = Xsiz - XOsiz;
  38829. this.height = Ysiz - YOsiz;
  38830. this.componentsCount = Csiz;
  38831. // Results are always returned as Uint8Arrays
  38832. this.bitsPerComponent = 8;
  38833. return;
  38834. }
  38835. }
  38836. throw new Error('JPX Error: No size marker found in JPX stream');
  38837. },
  38838. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  38839. var context = {};
  38840. try {
  38841. var doNotRecover = false;
  38842. var position = start;
  38843. while (position + 1 < end) {
  38844. var code = readUint16(data, position);
  38845. position += 2;
  38846. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  38847. switch (code) {
  38848. case 0xFF4F: // Start of codestream (SOC)
  38849. context.mainHeader = true;
  38850. break;
  38851. case 0xFFD9: // End of codestream (EOC)
  38852. break;
  38853. case 0xFF51: // Image and tile size (SIZ)
  38854. length = readUint16(data, position);
  38855. var siz = {};
  38856. siz.Xsiz = readUint32(data, position + 4);
  38857. siz.Ysiz = readUint32(data, position + 8);
  38858. siz.XOsiz = readUint32(data, position + 12);
  38859. siz.YOsiz = readUint32(data, position + 16);
  38860. siz.XTsiz = readUint32(data, position + 20);
  38861. siz.YTsiz = readUint32(data, position + 24);
  38862. siz.XTOsiz = readUint32(data, position + 28);
  38863. siz.YTOsiz = readUint32(data, position + 32);
  38864. var componentsCount = readUint16(data, position + 36);
  38865. siz.Csiz = componentsCount;
  38866. var components = [];
  38867. j = position + 38;
  38868. for (var i = 0; i < componentsCount; i++) {
  38869. var component = {
  38870. precision: (data[j] & 0x7F) + 1,
  38871. isSigned: !!(data[j] & 0x80),
  38872. XRsiz: data[j + 1],
  38873. YRsiz: data[j + 1]
  38874. };
  38875. calculateComponentDimensions(component, siz);
  38876. components.push(component);
  38877. }
  38878. context.SIZ = siz;
  38879. context.components = components;
  38880. calculateTileGrids(context, components);
  38881. context.QCC = [];
  38882. context.COC = [];
  38883. break;
  38884. case 0xFF55: // Tile-part lengths, main header (TLM)
  38885. var Ltlm = readUint16(data, position); // Marker segment length
  38886. // Skip tile length markers
  38887. position += Ltlm;
  38888. break;
  38889. case 0xFF5C: // Quantization default (QCD)
  38890. length = readUint16(data, position);
  38891. var qcd = {};
  38892. j = position + 2;
  38893. sqcd = data[j++];
  38894. switch (sqcd & 0x1F) {
  38895. case 0:
  38896. spqcdSize = 8;
  38897. scalarExpounded = true;
  38898. break;
  38899. case 1:
  38900. spqcdSize = 16;
  38901. scalarExpounded = false;
  38902. break;
  38903. case 2:
  38904. spqcdSize = 16;
  38905. scalarExpounded = true;
  38906. break;
  38907. default:
  38908. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  38909. }
  38910. qcd.noQuantization = (spqcdSize === 8);
  38911. qcd.scalarExpounded = scalarExpounded;
  38912. qcd.guardBits = sqcd >> 5;
  38913. spqcds = [];
  38914. while (j < length + position) {
  38915. var spqcd = {};
  38916. if (spqcdSize === 8) {
  38917. spqcd.epsilon = data[j++] >> 3;
  38918. spqcd.mu = 0;
  38919. } else {
  38920. spqcd.epsilon = data[j] >> 3;
  38921. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  38922. j += 2;
  38923. }
  38924. spqcds.push(spqcd);
  38925. }
  38926. qcd.SPqcds = spqcds;
  38927. if (context.mainHeader) {
  38928. context.QCD = qcd;
  38929. } else {
  38930. context.currentTile.QCD = qcd;
  38931. context.currentTile.QCC = [];
  38932. }
  38933. break;
  38934. case 0xFF5D: // Quantization component (QCC)
  38935. length = readUint16(data, position);
  38936. var qcc = {};
  38937. j = position + 2;
  38938. var cqcc;
  38939. if (context.SIZ.Csiz < 257) {
  38940. cqcc = data[j++];
  38941. } else {
  38942. cqcc = readUint16(data, j);
  38943. j += 2;
  38944. }
  38945. sqcd = data[j++];
  38946. switch (sqcd & 0x1F) {
  38947. case 0:
  38948. spqcdSize = 8;
  38949. scalarExpounded = true;
  38950. break;
  38951. case 1:
  38952. spqcdSize = 16;
  38953. scalarExpounded = false;
  38954. break;
  38955. case 2:
  38956. spqcdSize = 16;
  38957. scalarExpounded = true;
  38958. break;
  38959. default:
  38960. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  38961. }
  38962. qcc.noQuantization = (spqcdSize === 8);
  38963. qcc.scalarExpounded = scalarExpounded;
  38964. qcc.guardBits = sqcd >> 5;
  38965. spqcds = [];
  38966. while (j < (length + position)) {
  38967. spqcd = {};
  38968. if (spqcdSize === 8) {
  38969. spqcd.epsilon = data[j++] >> 3;
  38970. spqcd.mu = 0;
  38971. } else {
  38972. spqcd.epsilon = data[j] >> 3;
  38973. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  38974. j += 2;
  38975. }
  38976. spqcds.push(spqcd);
  38977. }
  38978. qcc.SPqcds = spqcds;
  38979. if (context.mainHeader) {
  38980. context.QCC[cqcc] = qcc;
  38981. } else {
  38982. context.currentTile.QCC[cqcc] = qcc;
  38983. }
  38984. break;
  38985. case 0xFF52: // Coding style default (COD)
  38986. length = readUint16(data, position);
  38987. var cod = {};
  38988. j = position + 2;
  38989. var scod = data[j++];
  38990. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  38991. cod.sopMarkerUsed = !!(scod & 2);
  38992. cod.ephMarkerUsed = !!(scod & 4);
  38993. cod.progressionOrder = data[j++];
  38994. cod.layersCount = readUint16(data, j);
  38995. j += 2;
  38996. cod.multipleComponentTransform = data[j++];
  38997. cod.decompositionLevelsCount = data[j++];
  38998. cod.xcb = (data[j++] & 0xF) + 2;
  38999. cod.ycb = (data[j++] & 0xF) + 2;
  39000. var blockStyle = data[j++];
  39001. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  39002. cod.resetContextProbabilities = !!(blockStyle & 2);
  39003. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  39004. cod.verticalyStripe = !!(blockStyle & 8);
  39005. cod.predictableTermination = !!(blockStyle & 16);
  39006. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  39007. cod.reversibleTransformation = data[j++];
  39008. if (cod.entropyCoderWithCustomPrecincts) {
  39009. var precinctsSizes = [];
  39010. while (j < length + position) {
  39011. var precinctsSize = data[j++];
  39012. precinctsSizes.push({
  39013. PPx: precinctsSize & 0xF,
  39014. PPy: precinctsSize >> 4
  39015. });
  39016. }
  39017. cod.precinctsSizes = precinctsSizes;
  39018. }
  39019. var unsupported = [];
  39020. if (cod.selectiveArithmeticCodingBypass) {
  39021. unsupported.push('selectiveArithmeticCodingBypass');
  39022. }
  39023. if (cod.resetContextProbabilities) {
  39024. unsupported.push('resetContextProbabilities');
  39025. }
  39026. if (cod.terminationOnEachCodingPass) {
  39027. unsupported.push('terminationOnEachCodingPass');
  39028. }
  39029. if (cod.verticalyStripe) {
  39030. unsupported.push('verticalyStripe');
  39031. }
  39032. if (cod.predictableTermination) {
  39033. unsupported.push('predictableTermination');
  39034. }
  39035. if (unsupported.length > 0) {
  39036. doNotRecover = true;
  39037. throw new Error('JPX Error: Unsupported COD options (' +
  39038. unsupported.join(', ') + ')');
  39039. }
  39040. if (context.mainHeader) {
  39041. context.COD = cod;
  39042. } else {
  39043. context.currentTile.COD = cod;
  39044. context.currentTile.COC = [];
  39045. }
  39046. break;
  39047. case 0xFF90: // Start of tile-part (SOT)
  39048. length = readUint16(data, position);
  39049. tile = {};
  39050. tile.index = readUint16(data, position + 2);
  39051. tile.length = readUint32(data, position + 4);
  39052. tile.dataEnd = tile.length + position - 2;
  39053. tile.partIndex = data[position + 8];
  39054. tile.partsCount = data[position + 9];
  39055. context.mainHeader = false;
  39056. if (tile.partIndex === 0) {
  39057. // reset component specific settings
  39058. tile.COD = context.COD;
  39059. tile.COC = context.COC.slice(0); // clone of the global COC
  39060. tile.QCD = context.QCD;
  39061. tile.QCC = context.QCC.slice(0); // clone of the global COC
  39062. }
  39063. context.currentTile = tile;
  39064. break;
  39065. case 0xFF93: // Start of data (SOD)
  39066. tile = context.currentTile;
  39067. if (tile.partIndex === 0) {
  39068. initializeTile(context, tile.index);
  39069. buildPackets(context);
  39070. }
  39071. // moving to the end of the data
  39072. length = tile.dataEnd - position;
  39073. parseTilePackets(context, data, position, length);
  39074. break;
  39075. case 0xFF64: // Comment (COM)
  39076. length = readUint16(data, position);
  39077. // skipping content
  39078. break;
  39079. case 0xFF53: // Coding style component (COC)
  39080. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  39081. 'not implemented');
  39082. default:
  39083. throw new Error('JPX Error: Unknown codestream code: ' +
  39084. code.toString(16));
  39085. }
  39086. position += length;
  39087. }
  39088. } catch (e) {
  39089. if (doNotRecover || this.failOnCorruptedImage) {
  39090. throw e;
  39091. } else {
  39092. warn('Trying to recover from ' + e.message);
  39093. }
  39094. }
  39095. this.tiles = transformComponents(context);
  39096. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  39097. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  39098. this.componentsCount = context.SIZ.Csiz;
  39099. }
  39100. };
  39101. function calculateComponentDimensions(component, siz) {
  39102. // Section B.2 Component mapping
  39103. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  39104. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  39105. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  39106. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  39107. component.width = component.x1 - component.x0;
  39108. component.height = component.y1 - component.y0;
  39109. }
  39110. function calculateTileGrids(context, components) {
  39111. var siz = context.SIZ;
  39112. // Section B.3 Division into tile and tile-components
  39113. var tile, tiles = [];
  39114. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  39115. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  39116. for (var q = 0; q < numYtiles; q++) {
  39117. for (var p = 0; p < numXtiles; p++) {
  39118. tile = {};
  39119. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  39120. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  39121. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  39122. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  39123. tile.width = tile.tx1 - tile.tx0;
  39124. tile.height = tile.ty1 - tile.ty0;
  39125. tile.components = [];
  39126. tiles.push(tile);
  39127. }
  39128. }
  39129. context.tiles = tiles;
  39130. var componentsCount = siz.Csiz;
  39131. for (var i = 0, ii = componentsCount; i < ii; i++) {
  39132. var component = components[i];
  39133. for (var j = 0, jj = tiles.length; j < jj; j++) {
  39134. var tileComponent = {};
  39135. tile = tiles[j];
  39136. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  39137. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  39138. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  39139. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  39140. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  39141. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  39142. tile.components[i] = tileComponent;
  39143. }
  39144. }
  39145. }
  39146. function getBlocksDimensions(context, component, r) {
  39147. var codOrCoc = component.codingStyleParameters;
  39148. var result = {};
  39149. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  39150. result.PPx = 15;
  39151. result.PPy = 15;
  39152. } else {
  39153. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  39154. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  39155. }
  39156. // calculate codeblock size as described in section B.7
  39157. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  39158. Math.min(codOrCoc.xcb, result.PPx));
  39159. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  39160. Math.min(codOrCoc.ycb, result.PPy));
  39161. return result;
  39162. }
  39163. function buildPrecincts(context, resolution, dimensions) {
  39164. // Section B.6 Division resolution to precincts
  39165. var precinctWidth = 1 << dimensions.PPx;
  39166. var precinctHeight = 1 << dimensions.PPy;
  39167. // Jasper introduces codeblock groups for mapping each subband codeblocks
  39168. // to precincts. Precinct partition divides a resolution according to width
  39169. // and height parameters. The subband that belongs to the resolution level
  39170. // has a different size than the level, unless it is the zero resolution.
  39171. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  39172. // The precinct partitioning for a particular subband is derived from a
  39173. // partitioning of its parent LL band (i.e., the LL band at the next higher
  39174. // resolution level)... The LL band associated with each resolution level is
  39175. // divided into precincts... Each of the resulting precinct regions is then
  39176. // mapped into its child subbands (if any) at the next lower resolution
  39177. // level. This is accomplished by using the coordinate transformation
  39178. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  39179. // coordinates of a point in the LL band and child subband, respectively.
  39180. var isZeroRes = resolution.resLevel === 0;
  39181. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  39182. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  39183. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  39184. Math.ceil(resolution.trx1 / precinctWidth) -
  39185. Math.floor(resolution.trx0 / precinctWidth) : 0);
  39186. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  39187. Math.ceil(resolution.try1 / precinctHeight) -
  39188. Math.floor(resolution.try0 / precinctHeight) : 0);
  39189. var numprecincts = numprecinctswide * numprecinctshigh;
  39190. resolution.precinctParameters = {
  39191. precinctWidth: precinctWidth,
  39192. precinctHeight: precinctHeight,
  39193. numprecinctswide: numprecinctswide,
  39194. numprecinctshigh: numprecinctshigh,
  39195. numprecincts: numprecincts,
  39196. precinctWidthInSubband: precinctWidthInSubband,
  39197. precinctHeightInSubband: precinctHeightInSubband
  39198. };
  39199. }
  39200. function buildCodeblocks(context, subband, dimensions) {
  39201. // Section B.7 Division sub-band into code-blocks
  39202. var xcb_ = dimensions.xcb_;
  39203. var ycb_ = dimensions.ycb_;
  39204. var codeblockWidth = 1 << xcb_;
  39205. var codeblockHeight = 1 << ycb_;
  39206. var cbx0 = subband.tbx0 >> xcb_;
  39207. var cby0 = subband.tby0 >> ycb_;
  39208. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  39209. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  39210. var precinctParameters = subband.resolution.precinctParameters;
  39211. var codeblocks = [];
  39212. var precincts = [];
  39213. var i, j, codeblock, precinctNumber;
  39214. for (j = cby0; j < cby1; j++) {
  39215. for (i = cbx0; i < cbx1; i++) {
  39216. codeblock = {
  39217. cbx: i,
  39218. cby: j,
  39219. tbx0: codeblockWidth * i,
  39220. tby0: codeblockHeight * j,
  39221. tbx1: codeblockWidth * (i + 1),
  39222. tby1: codeblockHeight * (j + 1)
  39223. };
  39224. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  39225. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  39226. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  39227. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  39228. // Calculate precinct number for this codeblock, codeblock position
  39229. // should be relative to its subband, use actual dimension and position
  39230. // See comment about codeblock group width and height
  39231. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  39232. precinctParameters.precinctWidthInSubband);
  39233. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  39234. precinctParameters.precinctHeightInSubband);
  39235. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  39236. codeblock.precinctNumber = precinctNumber;
  39237. codeblock.subbandType = subband.type;
  39238. codeblock.Lblock = 3;
  39239. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  39240. codeblock.tby1_ <= codeblock.tby0_) {
  39241. continue;
  39242. }
  39243. codeblocks.push(codeblock);
  39244. // building precinct for the sub-band
  39245. var precinct = precincts[precinctNumber];
  39246. if (precinct !== undefined) {
  39247. if (i < precinct.cbxMin) {
  39248. precinct.cbxMin = i;
  39249. } else if (i > precinct.cbxMax) {
  39250. precinct.cbxMax = i;
  39251. }
  39252. if (j < precinct.cbyMin) {
  39253. precinct.cbxMin = j;
  39254. } else if (j > precinct.cbyMax) {
  39255. precinct.cbyMax = j;
  39256. }
  39257. } else {
  39258. precincts[precinctNumber] = precinct = {
  39259. cbxMin: i,
  39260. cbyMin: j,
  39261. cbxMax: i,
  39262. cbyMax: j
  39263. };
  39264. }
  39265. codeblock.precinct = precinct;
  39266. }
  39267. }
  39268. subband.codeblockParameters = {
  39269. codeblockWidth: xcb_,
  39270. codeblockHeight: ycb_,
  39271. numcodeblockwide: cbx1 - cbx0 + 1,
  39272. numcodeblockhigh: cby1 - cby0 + 1
  39273. };
  39274. subband.codeblocks = codeblocks;
  39275. subband.precincts = precincts;
  39276. }
  39277. function createPacket(resolution, precinctNumber, layerNumber) {
  39278. var precinctCodeblocks = [];
  39279. // Section B.10.8 Order of info in packet
  39280. var subbands = resolution.subbands;
  39281. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  39282. for (var i = 0, ii = subbands.length; i < ii; i++) {
  39283. var subband = subbands[i];
  39284. var codeblocks = subband.codeblocks;
  39285. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  39286. var codeblock = codeblocks[j];
  39287. if (codeblock.precinctNumber !== precinctNumber) {
  39288. continue;
  39289. }
  39290. precinctCodeblocks.push(codeblock);
  39291. }
  39292. }
  39293. return {
  39294. layerNumber: layerNumber,
  39295. codeblocks: precinctCodeblocks
  39296. };
  39297. }
  39298. function LayerResolutionComponentPositionIterator(context) {
  39299. var siz = context.SIZ;
  39300. var tileIndex = context.currentTile.index;
  39301. var tile = context.tiles[tileIndex];
  39302. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39303. var componentsCount = siz.Csiz;
  39304. var maxDecompositionLevelsCount = 0;
  39305. for (var q = 0; q < componentsCount; q++) {
  39306. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39307. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39308. }
  39309. var l = 0, r = 0, i = 0, k = 0;
  39310. this.nextPacket = function JpxImage_nextPacket() {
  39311. // Section B.12.1.1 Layer-resolution-component-position
  39312. for (; l < layersCount; l++) {
  39313. for (; r <= maxDecompositionLevelsCount; r++) {
  39314. for (; i < componentsCount; i++) {
  39315. var component = tile.components[i];
  39316. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39317. continue;
  39318. }
  39319. var resolution = component.resolutions[r];
  39320. var numprecincts = resolution.precinctParameters.numprecincts;
  39321. for (; k < numprecincts;) {
  39322. var packet = createPacket(resolution, k, l);
  39323. k++;
  39324. return packet;
  39325. }
  39326. k = 0;
  39327. }
  39328. i = 0;
  39329. }
  39330. r = 0;
  39331. }
  39332. throw new Error('JPX Error: Out of packets');
  39333. };
  39334. }
  39335. function ResolutionLayerComponentPositionIterator(context) {
  39336. var siz = context.SIZ;
  39337. var tileIndex = context.currentTile.index;
  39338. var tile = context.tiles[tileIndex];
  39339. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39340. var componentsCount = siz.Csiz;
  39341. var maxDecompositionLevelsCount = 0;
  39342. for (var q = 0; q < componentsCount; q++) {
  39343. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39344. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39345. }
  39346. var r = 0, l = 0, i = 0, k = 0;
  39347. this.nextPacket = function JpxImage_nextPacket() {
  39348. // Section B.12.1.2 Resolution-layer-component-position
  39349. for (; r <= maxDecompositionLevelsCount; r++) {
  39350. for (; l < layersCount; l++) {
  39351. for (; i < componentsCount; i++) {
  39352. var component = tile.components[i];
  39353. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39354. continue;
  39355. }
  39356. var resolution = component.resolutions[r];
  39357. var numprecincts = resolution.precinctParameters.numprecincts;
  39358. for (; k < numprecincts;) {
  39359. var packet = createPacket(resolution, k, l);
  39360. k++;
  39361. return packet;
  39362. }
  39363. k = 0;
  39364. }
  39365. i = 0;
  39366. }
  39367. l = 0;
  39368. }
  39369. throw new Error('JPX Error: Out of packets');
  39370. };
  39371. }
  39372. function ResolutionPositionComponentLayerIterator(context) {
  39373. var siz = context.SIZ;
  39374. var tileIndex = context.currentTile.index;
  39375. var tile = context.tiles[tileIndex];
  39376. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39377. var componentsCount = siz.Csiz;
  39378. var l, r, c, p;
  39379. var maxDecompositionLevelsCount = 0;
  39380. for (c = 0; c < componentsCount; c++) {
  39381. var component = tile.components[c];
  39382. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39383. component.codingStyleParameters.decompositionLevelsCount);
  39384. }
  39385. var maxNumPrecinctsInLevel = new Int32Array(
  39386. maxDecompositionLevelsCount + 1);
  39387. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  39388. var maxNumPrecincts = 0;
  39389. for (c = 0; c < componentsCount; ++c) {
  39390. var resolutions = tile.components[c].resolutions;
  39391. if (r < resolutions.length) {
  39392. maxNumPrecincts = Math.max(maxNumPrecincts,
  39393. resolutions[r].precinctParameters.numprecincts);
  39394. }
  39395. }
  39396. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  39397. }
  39398. l = 0;
  39399. r = 0;
  39400. c = 0;
  39401. p = 0;
  39402. this.nextPacket = function JpxImage_nextPacket() {
  39403. // Section B.12.1.3 Resolution-position-component-layer
  39404. for (; r <= maxDecompositionLevelsCount; r++) {
  39405. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  39406. for (; c < componentsCount; c++) {
  39407. var component = tile.components[c];
  39408. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39409. continue;
  39410. }
  39411. var resolution = component.resolutions[r];
  39412. var numprecincts = resolution.precinctParameters.numprecincts;
  39413. if (p >= numprecincts) {
  39414. continue;
  39415. }
  39416. for (; l < layersCount;) {
  39417. var packet = createPacket(resolution, p, l);
  39418. l++;
  39419. return packet;
  39420. }
  39421. l = 0;
  39422. }
  39423. c = 0;
  39424. }
  39425. p = 0;
  39426. }
  39427. throw new Error('JPX Error: Out of packets');
  39428. };
  39429. }
  39430. function PositionComponentResolutionLayerIterator(context) {
  39431. var siz = context.SIZ;
  39432. var tileIndex = context.currentTile.index;
  39433. var tile = context.tiles[tileIndex];
  39434. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39435. var componentsCount = siz.Csiz;
  39436. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39437. var precinctsIterationSizes = precinctsSizes;
  39438. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39439. this.nextPacket = function JpxImage_nextPacket() {
  39440. // Section B.12.1.4 Position-component-resolution-layer
  39441. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39442. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39443. for (; c < componentsCount; c++) {
  39444. var component = tile.components[c];
  39445. var decompositionLevelsCount =
  39446. component.codingStyleParameters.decompositionLevelsCount;
  39447. for (; r <= decompositionLevelsCount; r++) {
  39448. var resolution = component.resolutions[r];
  39449. var sizeInImageScale =
  39450. precinctsSizes.components[c].resolutions[r];
  39451. var k = getPrecinctIndexIfExist(
  39452. px,
  39453. py,
  39454. sizeInImageScale,
  39455. precinctsIterationSizes,
  39456. resolution);
  39457. if (k === null) {
  39458. continue;
  39459. }
  39460. for (; l < layersCount;) {
  39461. var packet = createPacket(resolution, k, l);
  39462. l++;
  39463. return packet;
  39464. }
  39465. l = 0;
  39466. }
  39467. r = 0;
  39468. }
  39469. c = 0;
  39470. }
  39471. px = 0;
  39472. }
  39473. throw new Error('JPX Error: Out of packets');
  39474. };
  39475. }
  39476. function ComponentPositionResolutionLayerIterator(context) {
  39477. var siz = context.SIZ;
  39478. var tileIndex = context.currentTile.index;
  39479. var tile = context.tiles[tileIndex];
  39480. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39481. var componentsCount = siz.Csiz;
  39482. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39483. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39484. this.nextPacket = function JpxImage_nextPacket() {
  39485. // Section B.12.1.5 Component-position-resolution-layer
  39486. for (; c < componentsCount; ++c) {
  39487. var component = tile.components[c];
  39488. var precinctsIterationSizes = precinctsSizes.components[c];
  39489. var decompositionLevelsCount =
  39490. component.codingStyleParameters.decompositionLevelsCount;
  39491. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39492. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39493. for (; r <= decompositionLevelsCount; r++) {
  39494. var resolution = component.resolutions[r];
  39495. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  39496. var k = getPrecinctIndexIfExist(
  39497. px,
  39498. py,
  39499. sizeInImageScale,
  39500. precinctsIterationSizes,
  39501. resolution);
  39502. if (k === null) {
  39503. continue;
  39504. }
  39505. for (; l < layersCount;) {
  39506. var packet = createPacket(resolution, k, l);
  39507. l++;
  39508. return packet;
  39509. }
  39510. l = 0;
  39511. }
  39512. r = 0;
  39513. }
  39514. px = 0;
  39515. }
  39516. py = 0;
  39517. }
  39518. throw new Error('JPX Error: Out of packets');
  39519. };
  39520. }
  39521. function getPrecinctIndexIfExist(
  39522. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  39523. var posX = pxIndex * precinctIterationSizes.minWidth;
  39524. var posY = pyIndex * precinctIterationSizes.minHeight;
  39525. if (posX % sizeInImageScale.width !== 0 ||
  39526. posY % sizeInImageScale.height !== 0) {
  39527. return null;
  39528. }
  39529. var startPrecinctRowIndex =
  39530. (posY / sizeInImageScale.width) *
  39531. resolution.precinctParameters.numprecinctswide;
  39532. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  39533. }
  39534. function getPrecinctSizesInImageScale(tile) {
  39535. var componentsCount = tile.components.length;
  39536. var minWidth = Number.MAX_VALUE;
  39537. var minHeight = Number.MAX_VALUE;
  39538. var maxNumWide = 0;
  39539. var maxNumHigh = 0;
  39540. var sizePerComponent = new Array(componentsCount);
  39541. for (var c = 0; c < componentsCount; c++) {
  39542. var component = tile.components[c];
  39543. var decompositionLevelsCount =
  39544. component.codingStyleParameters.decompositionLevelsCount;
  39545. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  39546. var minWidthCurrentComponent = Number.MAX_VALUE;
  39547. var minHeightCurrentComponent = Number.MAX_VALUE;
  39548. var maxNumWideCurrentComponent = 0;
  39549. var maxNumHighCurrentComponent = 0;
  39550. var scale = 1;
  39551. for (var r = decompositionLevelsCount; r >= 0; --r) {
  39552. var resolution = component.resolutions[r];
  39553. var widthCurrentResolution =
  39554. scale * resolution.precinctParameters.precinctWidth;
  39555. var heightCurrentResolution =
  39556. scale * resolution.precinctParameters.precinctHeight;
  39557. minWidthCurrentComponent = Math.min(
  39558. minWidthCurrentComponent,
  39559. widthCurrentResolution);
  39560. minHeightCurrentComponent = Math.min(
  39561. minHeightCurrentComponent,
  39562. heightCurrentResolution);
  39563. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  39564. resolution.precinctParameters.numprecinctswide);
  39565. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  39566. resolution.precinctParameters.numprecinctshigh);
  39567. sizePerResolution[r] = {
  39568. width: widthCurrentResolution,
  39569. height: heightCurrentResolution
  39570. };
  39571. scale <<= 1;
  39572. }
  39573. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  39574. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  39575. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  39576. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  39577. sizePerComponent[c] = {
  39578. resolutions: sizePerResolution,
  39579. minWidth: minWidthCurrentComponent,
  39580. minHeight: minHeightCurrentComponent,
  39581. maxNumWide: maxNumWideCurrentComponent,
  39582. maxNumHigh: maxNumHighCurrentComponent
  39583. };
  39584. }
  39585. return {
  39586. components: sizePerComponent,
  39587. minWidth: minWidth,
  39588. minHeight: minHeight,
  39589. maxNumWide: maxNumWide,
  39590. maxNumHigh: maxNumHigh
  39591. };
  39592. }
  39593. function buildPackets(context) {
  39594. var siz = context.SIZ;
  39595. var tileIndex = context.currentTile.index;
  39596. var tile = context.tiles[tileIndex];
  39597. var componentsCount = siz.Csiz;
  39598. // Creating resolutions and sub-bands for each component
  39599. for (var c = 0; c < componentsCount; c++) {
  39600. var component = tile.components[c];
  39601. var decompositionLevelsCount =
  39602. component.codingStyleParameters.decompositionLevelsCount;
  39603. // Section B.5 Resolution levels and sub-bands
  39604. var resolutions = [];
  39605. var subbands = [];
  39606. for (var r = 0; r <= decompositionLevelsCount; r++) {
  39607. var blocksDimensions = getBlocksDimensions(context, component, r);
  39608. var resolution = {};
  39609. var scale = 1 << (decompositionLevelsCount - r);
  39610. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  39611. resolution.try0 = Math.ceil(component.tcy0 / scale);
  39612. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  39613. resolution.try1 = Math.ceil(component.tcy1 / scale);
  39614. resolution.resLevel = r;
  39615. buildPrecincts(context, resolution, blocksDimensions);
  39616. resolutions.push(resolution);
  39617. var subband;
  39618. if (r === 0) {
  39619. // one sub-band (LL) with last decomposition
  39620. subband = {};
  39621. subband.type = 'LL';
  39622. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  39623. subband.tby0 = Math.ceil(component.tcy0 / scale);
  39624. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  39625. subband.tby1 = Math.ceil(component.tcy1 / scale);
  39626. subband.resolution = resolution;
  39627. buildCodeblocks(context, subband, blocksDimensions);
  39628. subbands.push(subband);
  39629. resolution.subbands = [subband];
  39630. } else {
  39631. var bscale = 1 << (decompositionLevelsCount - r + 1);
  39632. var resolutionSubbands = [];
  39633. // three sub-bands (HL, LH and HH) with rest of decompositions
  39634. subband = {};
  39635. subband.type = 'HL';
  39636. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39637. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  39638. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39639. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  39640. subband.resolution = resolution;
  39641. buildCodeblocks(context, subband, blocksDimensions);
  39642. subbands.push(subband);
  39643. resolutionSubbands.push(subband);
  39644. subband = {};
  39645. subband.type = 'LH';
  39646. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  39647. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39648. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  39649. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39650. subband.resolution = resolution;
  39651. buildCodeblocks(context, subband, blocksDimensions);
  39652. subbands.push(subband);
  39653. resolutionSubbands.push(subband);
  39654. subband = {};
  39655. subband.type = 'HH';
  39656. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39657. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39658. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39659. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39660. subband.resolution = resolution;
  39661. buildCodeblocks(context, subband, blocksDimensions);
  39662. subbands.push(subband);
  39663. resolutionSubbands.push(subband);
  39664. resolution.subbands = resolutionSubbands;
  39665. }
  39666. }
  39667. component.resolutions = resolutions;
  39668. component.subbands = subbands;
  39669. }
  39670. // Generate the packets sequence
  39671. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  39672. switch (progressionOrder) {
  39673. case 0:
  39674. tile.packetsIterator =
  39675. new LayerResolutionComponentPositionIterator(context);
  39676. break;
  39677. case 1:
  39678. tile.packetsIterator =
  39679. new ResolutionLayerComponentPositionIterator(context);
  39680. break;
  39681. case 2:
  39682. tile.packetsIterator =
  39683. new ResolutionPositionComponentLayerIterator(context);
  39684. break;
  39685. case 3:
  39686. tile.packetsIterator =
  39687. new PositionComponentResolutionLayerIterator(context);
  39688. break;
  39689. case 4:
  39690. tile.packetsIterator =
  39691. new ComponentPositionResolutionLayerIterator(context);
  39692. break;
  39693. default:
  39694. throw new Error('JPX Error: Unsupported progression order ' +
  39695. progressionOrder);
  39696. }
  39697. }
  39698. function parseTilePackets(context, data, offset, dataLength) {
  39699. var position = 0;
  39700. var buffer, bufferSize = 0, skipNextBit = false;
  39701. function readBits(count) {
  39702. while (bufferSize < count) {
  39703. var b = data[offset + position];
  39704. position++;
  39705. if (skipNextBit) {
  39706. buffer = (buffer << 7) | b;
  39707. bufferSize += 7;
  39708. skipNextBit = false;
  39709. } else {
  39710. buffer = (buffer << 8) | b;
  39711. bufferSize += 8;
  39712. }
  39713. if (b === 0xFF) {
  39714. skipNextBit = true;
  39715. }
  39716. }
  39717. bufferSize -= count;
  39718. return (buffer >>> bufferSize) & ((1 << count) - 1);
  39719. }
  39720. function skipMarkerIfEqual(value) {
  39721. if (data[offset + position - 1] === 0xFF &&
  39722. data[offset + position] === value) {
  39723. skipBytes(1);
  39724. return true;
  39725. } else if (data[offset + position] === 0xFF &&
  39726. data[offset + position + 1] === value) {
  39727. skipBytes(2);
  39728. return true;
  39729. }
  39730. return false;
  39731. }
  39732. function skipBytes(count) {
  39733. position += count;
  39734. }
  39735. function alignToByte() {
  39736. bufferSize = 0;
  39737. if (skipNextBit) {
  39738. position++;
  39739. skipNextBit = false;
  39740. }
  39741. }
  39742. function readCodingpasses() {
  39743. if (readBits(1) === 0) {
  39744. return 1;
  39745. }
  39746. if (readBits(1) === 0) {
  39747. return 2;
  39748. }
  39749. var value = readBits(2);
  39750. if (value < 3) {
  39751. return value + 3;
  39752. }
  39753. value = readBits(5);
  39754. if (value < 31) {
  39755. return value + 6;
  39756. }
  39757. value = readBits(7);
  39758. return value + 37;
  39759. }
  39760. var tileIndex = context.currentTile.index;
  39761. var tile = context.tiles[tileIndex];
  39762. var sopMarkerUsed = context.COD.sopMarkerUsed;
  39763. var ephMarkerUsed = context.COD.ephMarkerUsed;
  39764. var packetsIterator = tile.packetsIterator;
  39765. while (position < dataLength) {
  39766. alignToByte();
  39767. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  39768. // Skip also marker segment length and packet sequence ID
  39769. skipBytes(4);
  39770. }
  39771. var packet = packetsIterator.nextPacket();
  39772. if (!readBits(1)) {
  39773. continue;
  39774. }
  39775. var layerNumber = packet.layerNumber;
  39776. var queue = [], codeblock;
  39777. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  39778. codeblock = packet.codeblocks[i];
  39779. var precinct = codeblock.precinct;
  39780. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  39781. var codeblockRow = codeblock.cby - precinct.cbyMin;
  39782. var codeblockIncluded = false;
  39783. var firstTimeInclusion = false;
  39784. var valueReady;
  39785. if (codeblock['included'] !== undefined) {
  39786. codeblockIncluded = !!readBits(1);
  39787. } else {
  39788. // reading inclusion tree
  39789. precinct = codeblock.precinct;
  39790. var inclusionTree, zeroBitPlanesTree;
  39791. if (precinct['inclusionTree'] !== undefined) {
  39792. inclusionTree = precinct.inclusionTree;
  39793. } else {
  39794. // building inclusion and zero bit-planes trees
  39795. var width = precinct.cbxMax - precinct.cbxMin + 1;
  39796. var height = precinct.cbyMax - precinct.cbyMin + 1;
  39797. inclusionTree = new InclusionTree(width, height, layerNumber);
  39798. zeroBitPlanesTree = new TagTree(width, height);
  39799. precinct.inclusionTree = inclusionTree;
  39800. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  39801. }
  39802. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  39803. while (true) {
  39804. if (readBits(1)) {
  39805. valueReady = !inclusionTree.nextLevel();
  39806. if (valueReady) {
  39807. codeblock.included = true;
  39808. codeblockIncluded = firstTimeInclusion = true;
  39809. break;
  39810. }
  39811. } else {
  39812. inclusionTree.incrementValue(layerNumber);
  39813. break;
  39814. }
  39815. }
  39816. }
  39817. }
  39818. if (!codeblockIncluded) {
  39819. continue;
  39820. }
  39821. if (firstTimeInclusion) {
  39822. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  39823. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  39824. while (true) {
  39825. if (readBits(1)) {
  39826. valueReady = !zeroBitPlanesTree.nextLevel();
  39827. if (valueReady) {
  39828. break;
  39829. }
  39830. } else {
  39831. zeroBitPlanesTree.incrementValue();
  39832. }
  39833. }
  39834. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  39835. }
  39836. var codingpasses = readCodingpasses();
  39837. while (readBits(1)) {
  39838. codeblock.Lblock++;
  39839. }
  39840. var codingpassesLog2 = log2(codingpasses);
  39841. // rounding down log2
  39842. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  39843. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  39844. var codedDataLength = readBits(bits);
  39845. queue.push({
  39846. codeblock: codeblock,
  39847. codingpasses: codingpasses,
  39848. dataLength: codedDataLength
  39849. });
  39850. }
  39851. alignToByte();
  39852. if (ephMarkerUsed) {
  39853. skipMarkerIfEqual(0x92);
  39854. }
  39855. while (queue.length > 0) {
  39856. var packetItem = queue.shift();
  39857. codeblock = packetItem.codeblock;
  39858. if (codeblock['data'] === undefined) {
  39859. codeblock.data = [];
  39860. }
  39861. codeblock.data.push({
  39862. data: data,
  39863. start: offset + position,
  39864. end: offset + position + packetItem.dataLength,
  39865. codingpasses: packetItem.codingpasses
  39866. });
  39867. position += packetItem.dataLength;
  39868. }
  39869. }
  39870. return position;
  39871. }
  39872. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  39873. delta, mb, reversible, segmentationSymbolUsed) {
  39874. var x0 = subband.tbx0;
  39875. var y0 = subband.tby0;
  39876. var width = subband.tbx1 - subband.tbx0;
  39877. var codeblocks = subband.codeblocks;
  39878. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  39879. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  39880. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  39881. var codeblock = codeblocks[i];
  39882. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  39883. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  39884. if (blockWidth === 0 || blockHeight === 0) {
  39885. continue;
  39886. }
  39887. if (codeblock['data'] === undefined) {
  39888. continue;
  39889. }
  39890. var bitModel, currentCodingpassType;
  39891. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  39892. codeblock.zeroBitPlanes, mb);
  39893. currentCodingpassType = 2; // first bit plane starts from cleanup
  39894. // collect data
  39895. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  39896. var j, jj, dataItem;
  39897. for (j = 0, jj = data.length; j < jj; j++) {
  39898. dataItem = data[j];
  39899. totalLength += dataItem.end - dataItem.start;
  39900. codingpasses += dataItem.codingpasses;
  39901. }
  39902. var encodedData = new Uint8Array(totalLength);
  39903. var position = 0;
  39904. for (j = 0, jj = data.length; j < jj; j++) {
  39905. dataItem = data[j];
  39906. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  39907. encodedData.set(chunk, position);
  39908. position += chunk.length;
  39909. }
  39910. // decoding the item
  39911. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  39912. bitModel.setDecoder(decoder);
  39913. for (j = 0; j < codingpasses; j++) {
  39914. switch (currentCodingpassType) {
  39915. case 0:
  39916. bitModel.runSignificancePropogationPass();
  39917. break;
  39918. case 1:
  39919. bitModel.runMagnitudeRefinementPass();
  39920. break;
  39921. case 2:
  39922. bitModel.runCleanupPass();
  39923. if (segmentationSymbolUsed) {
  39924. bitModel.checkSegmentationSymbol();
  39925. }
  39926. break;
  39927. }
  39928. currentCodingpassType = (currentCodingpassType + 1) % 3;
  39929. }
  39930. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  39931. var sign = bitModel.coefficentsSign;
  39932. var magnitude = bitModel.coefficentsMagnitude;
  39933. var bitsDecoded = bitModel.bitsDecoded;
  39934. var magnitudeCorrection = reversible ? 0 : 0.5;
  39935. var k, n, nb;
  39936. position = 0;
  39937. // Do the interleaving of Section F.3.3 here, so we do not need
  39938. // to copy later. LL level is not interleaved, just copied.
  39939. var interleave = (subband.type !== 'LL');
  39940. for (j = 0; j < blockHeight; j++) {
  39941. var row = (offset / width) | 0; // row in the non-interleaved subband
  39942. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  39943. for (k = 0; k < blockWidth; k++) {
  39944. n = magnitude[position];
  39945. if (n !== 0) {
  39946. n = (n + magnitudeCorrection) * delta;
  39947. if (sign[position] !== 0) {
  39948. n = -n;
  39949. }
  39950. nb = bitsDecoded[position];
  39951. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  39952. if (reversible && (nb >= mb)) {
  39953. coefficients[pos] = n;
  39954. } else {
  39955. coefficients[pos] = n * (1 << (mb - nb));
  39956. }
  39957. }
  39958. offset++;
  39959. position++;
  39960. }
  39961. offset += width - blockWidth;
  39962. }
  39963. }
  39964. }
  39965. function transformTile(context, tile, c) {
  39966. var component = tile.components[c];
  39967. var codingStyleParameters = component.codingStyleParameters;
  39968. var quantizationParameters = component.quantizationParameters;
  39969. var decompositionLevelsCount =
  39970. codingStyleParameters.decompositionLevelsCount;
  39971. var spqcds = quantizationParameters.SPqcds;
  39972. var scalarExpounded = quantizationParameters.scalarExpounded;
  39973. var guardBits = quantizationParameters.guardBits;
  39974. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  39975. var precision = context.components[c].precision;
  39976. var reversible = codingStyleParameters.reversibleTransformation;
  39977. var transform = (reversible ? new ReversibleTransform() :
  39978. new IrreversibleTransform());
  39979. var subbandCoefficients = [];
  39980. var b = 0;
  39981. for (var i = 0; i <= decompositionLevelsCount; i++) {
  39982. var resolution = component.resolutions[i];
  39983. var width = resolution.trx1 - resolution.trx0;
  39984. var height = resolution.try1 - resolution.try0;
  39985. // Allocate space for the whole sublevel.
  39986. var coefficients = new Float32Array(width * height);
  39987. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  39988. var mu, epsilon;
  39989. if (!scalarExpounded) {
  39990. // formula E-5
  39991. mu = spqcds[0].mu;
  39992. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  39993. } else {
  39994. mu = spqcds[b].mu;
  39995. epsilon = spqcds[b].epsilon;
  39996. b++;
  39997. }
  39998. var subband = resolution.subbands[j];
  39999. var gainLog2 = SubbandsGainLog2[subband.type];
  40000. // calulate quantization coefficient (Section E.1.1.1)
  40001. var delta = (reversible ? 1 :
  40002. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  40003. var mb = (guardBits + epsilon - 1);
  40004. // In the first resolution level, copyCoefficients will fill the
  40005. // whole array with coefficients. In the succeding passes,
  40006. // copyCoefficients will consecutively fill in the values that belong
  40007. // to the interleaved positions of the HL, LH, and HH coefficients.
  40008. // The LL coefficients will then be interleaved in Transform.iterate().
  40009. copyCoefficients(coefficients, width, height, subband, delta, mb,
  40010. reversible, segmentationSymbolUsed);
  40011. }
  40012. subbandCoefficients.push({
  40013. width: width,
  40014. height: height,
  40015. items: coefficients
  40016. });
  40017. }
  40018. var result = transform.calculate(subbandCoefficients,
  40019. component.tcx0, component.tcy0);
  40020. return {
  40021. left: component.tcx0,
  40022. top: component.tcy0,
  40023. width: result.width,
  40024. height: result.height,
  40025. items: result.items
  40026. };
  40027. }
  40028. function transformComponents(context) {
  40029. var siz = context.SIZ;
  40030. var components = context.components;
  40031. var componentsCount = siz.Csiz;
  40032. var resultImages = [];
  40033. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  40034. var tile = context.tiles[i];
  40035. var transformedTiles = [];
  40036. var c;
  40037. for (c = 0; c < componentsCount; c++) {
  40038. transformedTiles[c] = transformTile(context, tile, c);
  40039. }
  40040. var tile0 = transformedTiles[0];
  40041. var out = new Uint8Array(tile0.items.length * componentsCount);
  40042. var result = {
  40043. left: tile0.left,
  40044. top: tile0.top,
  40045. width: tile0.width,
  40046. height: tile0.height,
  40047. items: out
  40048. };
  40049. // Section G.2.2 Inverse multi component transform
  40050. var shift, offset, max, min, maxK;
  40051. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  40052. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  40053. var fourComponents = componentsCount === 4;
  40054. var y0items = transformedTiles[0].items;
  40055. var y1items = transformedTiles[1].items;
  40056. var y2items = transformedTiles[2].items;
  40057. var y3items = fourComponents ? transformedTiles[3].items : null;
  40058. // HACK: The multiple component transform formulas below assume that
  40059. // all components have the same precision. With this in mind, we
  40060. // compute shift and offset only once.
  40061. shift = components[0].precision - 8;
  40062. offset = (128 << shift) + 0.5;
  40063. max = 255 * (1 << shift);
  40064. maxK = max * 0.5;
  40065. min = -maxK;
  40066. var component0 = tile.components[0];
  40067. var alpha01 = componentsCount - 3;
  40068. jj = y0items.length;
  40069. if (!component0.codingStyleParameters.reversibleTransformation) {
  40070. // inverse irreversible multiple component transform
  40071. for (j = 0; j < jj; j++, pos += alpha01) {
  40072. y0 = y0items[j] + offset;
  40073. y1 = y1items[j];
  40074. y2 = y2items[j];
  40075. r = y0 + 1.402 * y2;
  40076. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  40077. b = y0 + 1.772 * y1;
  40078. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40079. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40080. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40081. }
  40082. } else {
  40083. // inverse reversible multiple component transform
  40084. for (j = 0; j < jj; j++, pos += alpha01) {
  40085. y0 = y0items[j] + offset;
  40086. y1 = y1items[j];
  40087. y2 = y2items[j];
  40088. g = y0 - ((y2 + y1) >> 2);
  40089. r = g + y2;
  40090. b = g + y1;
  40091. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40092. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40093. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40094. }
  40095. }
  40096. if (fourComponents) {
  40097. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  40098. k = y3items[j];
  40099. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  40100. }
  40101. }
  40102. } else { // no multi-component transform
  40103. for (c = 0; c < componentsCount; c++) {
  40104. var items = transformedTiles[c].items;
  40105. shift = components[c].precision - 8;
  40106. offset = (128 << shift) + 0.5;
  40107. max = (127.5 * (1 << shift));
  40108. min = -max;
  40109. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  40110. val = items[j];
  40111. out[pos] = val <= min ? 0 :
  40112. val >= max ? 255 : (val + offset) >> shift;
  40113. pos += componentsCount;
  40114. }
  40115. }
  40116. }
  40117. resultImages.push(result);
  40118. }
  40119. return resultImages;
  40120. }
  40121. function initializeTile(context, tileIndex) {
  40122. var siz = context.SIZ;
  40123. var componentsCount = siz.Csiz;
  40124. var tile = context.tiles[tileIndex];
  40125. for (var c = 0; c < componentsCount; c++) {
  40126. var component = tile.components[c];
  40127. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  40128. context.currentTile.QCC[c] : context.currentTile.QCD);
  40129. component.quantizationParameters = qcdOrQcc;
  40130. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  40131. context.currentTile.COC[c] : context.currentTile.COD);
  40132. component.codingStyleParameters = codOrCoc;
  40133. }
  40134. tile.codingStyleDefaultParameters = context.currentTile.COD;
  40135. }
  40136. // Section B.10.2 Tag trees
  40137. var TagTree = (function TagTreeClosure() {
  40138. function TagTree(width, height) {
  40139. var levelsLength = log2(Math.max(width, height)) + 1;
  40140. this.levels = [];
  40141. for (var i = 0; i < levelsLength; i++) {
  40142. var level = {
  40143. width: width,
  40144. height: height,
  40145. items: []
  40146. };
  40147. this.levels.push(level);
  40148. width = Math.ceil(width / 2);
  40149. height = Math.ceil(height / 2);
  40150. }
  40151. }
  40152. TagTree.prototype = {
  40153. reset: function TagTree_reset(i, j) {
  40154. var currentLevel = 0, value = 0, level;
  40155. while (currentLevel < this.levels.length) {
  40156. level = this.levels[currentLevel];
  40157. var index = i + j * level.width;
  40158. if (level.items[index] !== undefined) {
  40159. value = level.items[index];
  40160. break;
  40161. }
  40162. level.index = index;
  40163. i >>= 1;
  40164. j >>= 1;
  40165. currentLevel++;
  40166. }
  40167. currentLevel--;
  40168. level = this.levels[currentLevel];
  40169. level.items[level.index] = value;
  40170. this.currentLevel = currentLevel;
  40171. delete this.value;
  40172. },
  40173. incrementValue: function TagTree_incrementValue() {
  40174. var level = this.levels[this.currentLevel];
  40175. level.items[level.index]++;
  40176. },
  40177. nextLevel: function TagTree_nextLevel() {
  40178. var currentLevel = this.currentLevel;
  40179. var level = this.levels[currentLevel];
  40180. var value = level.items[level.index];
  40181. currentLevel--;
  40182. if (currentLevel < 0) {
  40183. this.value = value;
  40184. return false;
  40185. }
  40186. this.currentLevel = currentLevel;
  40187. level = this.levels[currentLevel];
  40188. level.items[level.index] = value;
  40189. return true;
  40190. }
  40191. };
  40192. return TagTree;
  40193. })();
  40194. var InclusionTree = (function InclusionTreeClosure() {
  40195. function InclusionTree(width, height, defaultValue) {
  40196. var levelsLength = log2(Math.max(width, height)) + 1;
  40197. this.levels = [];
  40198. for (var i = 0; i < levelsLength; i++) {
  40199. var items = new Uint8Array(width * height);
  40200. for (var j = 0, jj = items.length; j < jj; j++) {
  40201. items[j] = defaultValue;
  40202. }
  40203. var level = {
  40204. width: width,
  40205. height: height,
  40206. items: items
  40207. };
  40208. this.levels.push(level);
  40209. width = Math.ceil(width / 2);
  40210. height = Math.ceil(height / 2);
  40211. }
  40212. }
  40213. InclusionTree.prototype = {
  40214. reset: function InclusionTree_reset(i, j, stopValue) {
  40215. var currentLevel = 0;
  40216. while (currentLevel < this.levels.length) {
  40217. var level = this.levels[currentLevel];
  40218. var index = i + j * level.width;
  40219. level.index = index;
  40220. var value = level.items[index];
  40221. if (value === 0xFF) {
  40222. break;
  40223. }
  40224. if (value > stopValue) {
  40225. this.currentLevel = currentLevel;
  40226. // already know about this one, propagating the value to top levels
  40227. this.propagateValues();
  40228. return false;
  40229. }
  40230. i >>= 1;
  40231. j >>= 1;
  40232. currentLevel++;
  40233. }
  40234. this.currentLevel = currentLevel - 1;
  40235. return true;
  40236. },
  40237. incrementValue: function InclusionTree_incrementValue(stopValue) {
  40238. var level = this.levels[this.currentLevel];
  40239. level.items[level.index] = stopValue + 1;
  40240. this.propagateValues();
  40241. },
  40242. propagateValues: function InclusionTree_propagateValues() {
  40243. var levelIndex = this.currentLevel;
  40244. var level = this.levels[levelIndex];
  40245. var currentValue = level.items[level.index];
  40246. while (--levelIndex >= 0) {
  40247. level = this.levels[levelIndex];
  40248. level.items[level.index] = currentValue;
  40249. }
  40250. },
  40251. nextLevel: function InclusionTree_nextLevel() {
  40252. var currentLevel = this.currentLevel;
  40253. var level = this.levels[currentLevel];
  40254. var value = level.items[level.index];
  40255. level.items[level.index] = 0xFF;
  40256. currentLevel--;
  40257. if (currentLevel < 0) {
  40258. return false;
  40259. }
  40260. this.currentLevel = currentLevel;
  40261. level = this.levels[currentLevel];
  40262. level.items[level.index] = value;
  40263. return true;
  40264. }
  40265. };
  40266. return InclusionTree;
  40267. })();
  40268. // Section D. Coefficient bit modeling
  40269. var BitModel = (function BitModelClosure() {
  40270. var UNIFORM_CONTEXT = 17;
  40271. var RUNLENGTH_CONTEXT = 18;
  40272. // Table D-1
  40273. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  40274. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  40275. var LLAndLHContextsLabel = new Uint8Array([
  40276. 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,
  40277. 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,
  40278. 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
  40279. ]);
  40280. var HLContextLabel = new Uint8Array([
  40281. 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,
  40282. 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,
  40283. 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
  40284. ]);
  40285. var HHContextLabel = new Uint8Array([
  40286. 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,
  40287. 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,
  40288. 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
  40289. ]);
  40290. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  40291. this.width = width;
  40292. this.height = height;
  40293. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  40294. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  40295. var coefficientCount = width * height;
  40296. // coefficients outside the encoding region treated as insignificant
  40297. // add border state cells for significanceState
  40298. this.neighborsSignificance = new Uint8Array(coefficientCount);
  40299. this.coefficentsSign = new Uint8Array(coefficientCount);
  40300. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  40301. mb > 6 ? new Uint16Array(coefficientCount) :
  40302. new Uint8Array(coefficientCount);
  40303. this.processingFlags = new Uint8Array(coefficientCount);
  40304. var bitsDecoded = new Uint8Array(coefficientCount);
  40305. if (zeroBitPlanes !== 0) {
  40306. for (var i = 0; i < coefficientCount; i++) {
  40307. bitsDecoded[i] = zeroBitPlanes;
  40308. }
  40309. }
  40310. this.bitsDecoded = bitsDecoded;
  40311. this.reset();
  40312. }
  40313. BitModel.prototype = {
  40314. setDecoder: function BitModel_setDecoder(decoder) {
  40315. this.decoder = decoder;
  40316. },
  40317. reset: function BitModel_reset() {
  40318. // We have 17 contexts that are accessed via context labels,
  40319. // plus the uniform and runlength context.
  40320. this.contexts = new Int8Array(19);
  40321. // Contexts are packed into 1 byte:
  40322. // highest 7 bits carry the index, lowest bit carries mps
  40323. this.contexts[0] = (4 << 1) | 0;
  40324. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  40325. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  40326. },
  40327. setNeighborsSignificance:
  40328. function BitModel_setNeighborsSignificance(row, column, index) {
  40329. var neighborsSignificance = this.neighborsSignificance;
  40330. var width = this.width, height = this.height;
  40331. var left = (column > 0);
  40332. var right = (column + 1 < width);
  40333. var i;
  40334. if (row > 0) {
  40335. i = index - width;
  40336. if (left) {
  40337. neighborsSignificance[i - 1] += 0x10;
  40338. }
  40339. if (right) {
  40340. neighborsSignificance[i + 1] += 0x10;
  40341. }
  40342. neighborsSignificance[i] += 0x04;
  40343. }
  40344. if (row + 1 < height) {
  40345. i = index + width;
  40346. if (left) {
  40347. neighborsSignificance[i - 1] += 0x10;
  40348. }
  40349. if (right) {
  40350. neighborsSignificance[i + 1] += 0x10;
  40351. }
  40352. neighborsSignificance[i] += 0x04;
  40353. }
  40354. if (left) {
  40355. neighborsSignificance[index - 1] += 0x01;
  40356. }
  40357. if (right) {
  40358. neighborsSignificance[index + 1] += 0x01;
  40359. }
  40360. neighborsSignificance[index] |= 0x80;
  40361. },
  40362. runSignificancePropogationPass:
  40363. function BitModel_runSignificancePropogationPass() {
  40364. var decoder = this.decoder;
  40365. var width = this.width, height = this.height;
  40366. var coefficentsMagnitude = this.coefficentsMagnitude;
  40367. var coefficentsSign = this.coefficentsSign;
  40368. var neighborsSignificance = this.neighborsSignificance;
  40369. var processingFlags = this.processingFlags;
  40370. var contexts = this.contexts;
  40371. var labels = this.contextLabelTable;
  40372. var bitsDecoded = this.bitsDecoded;
  40373. var processedInverseMask = ~1;
  40374. var processedMask = 1;
  40375. var firstMagnitudeBitMask = 2;
  40376. for (var i0 = 0; i0 < height; i0 += 4) {
  40377. for (var j = 0; j < width; j++) {
  40378. var index = i0 * width + j;
  40379. for (var i1 = 0; i1 < 4; i1++, index += width) {
  40380. var i = i0 + i1;
  40381. if (i >= height) {
  40382. break;
  40383. }
  40384. // clear processed flag first
  40385. processingFlags[index] &= processedInverseMask;
  40386. if (coefficentsMagnitude[index] ||
  40387. !neighborsSignificance[index]) {
  40388. continue;
  40389. }
  40390. var contextLabel = labels[neighborsSignificance[index]];
  40391. var decision = decoder.readBit(contexts, contextLabel);
  40392. if (decision) {
  40393. var sign = this.decodeSignBit(i, j, index);
  40394. coefficentsSign[index] = sign;
  40395. coefficentsMagnitude[index] = 1;
  40396. this.setNeighborsSignificance(i, j, index);
  40397. processingFlags[index] |= firstMagnitudeBitMask;
  40398. }
  40399. bitsDecoded[index]++;
  40400. processingFlags[index] |= processedMask;
  40401. }
  40402. }
  40403. }
  40404. },
  40405. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  40406. var width = this.width, height = this.height;
  40407. var coefficentsMagnitude = this.coefficentsMagnitude;
  40408. var coefficentsSign = this.coefficentsSign;
  40409. var contribution, sign0, sign1, significance1;
  40410. var contextLabel, decoded;
  40411. // calculate horizontal contribution
  40412. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  40413. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  40414. sign1 = coefficentsSign[index + 1];
  40415. if (significance1) {
  40416. sign0 = coefficentsSign[index - 1];
  40417. contribution = 1 - sign1 - sign0;
  40418. } else {
  40419. contribution = 1 - sign1 - sign1;
  40420. }
  40421. } else if (significance1) {
  40422. sign0 = coefficentsSign[index - 1];
  40423. contribution = 1 - sign0 - sign0;
  40424. } else {
  40425. contribution = 0;
  40426. }
  40427. var horizontalContribution = 3 * contribution;
  40428. // calculate vertical contribution and combine with the horizontal
  40429. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  40430. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  40431. sign1 = coefficentsSign[index + width];
  40432. if (significance1) {
  40433. sign0 = coefficentsSign[index - width];
  40434. contribution = 1 - sign1 - sign0 + horizontalContribution;
  40435. } else {
  40436. contribution = 1 - sign1 - sign1 + horizontalContribution;
  40437. }
  40438. } else if (significance1) {
  40439. sign0 = coefficentsSign[index - width];
  40440. contribution = 1 - sign0 - sign0 + horizontalContribution;
  40441. } else {
  40442. contribution = horizontalContribution;
  40443. }
  40444. if (contribution >= 0) {
  40445. contextLabel = 9 + contribution;
  40446. decoded = this.decoder.readBit(this.contexts, contextLabel);
  40447. } else {
  40448. contextLabel = 9 - contribution;
  40449. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  40450. }
  40451. return decoded;
  40452. },
  40453. runMagnitudeRefinementPass:
  40454. function BitModel_runMagnitudeRefinementPass() {
  40455. var decoder = this.decoder;
  40456. var width = this.width, height = this.height;
  40457. var coefficentsMagnitude = this.coefficentsMagnitude;
  40458. var neighborsSignificance = this.neighborsSignificance;
  40459. var contexts = this.contexts;
  40460. var bitsDecoded = this.bitsDecoded;
  40461. var processingFlags = this.processingFlags;
  40462. var processedMask = 1;
  40463. var firstMagnitudeBitMask = 2;
  40464. var length = width * height;
  40465. var width4 = width * 4;
  40466. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  40467. indexNext = Math.min(length, index0 + width4);
  40468. for (var j = 0; j < width; j++) {
  40469. for (var index = index0 + j; index < indexNext; index += width) {
  40470. // significant but not those that have just become
  40471. if (!coefficentsMagnitude[index] ||
  40472. (processingFlags[index] & processedMask) !== 0) {
  40473. continue;
  40474. }
  40475. var contextLabel = 16;
  40476. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  40477. processingFlags[index] ^= firstMagnitudeBitMask;
  40478. // first refinement
  40479. var significance = neighborsSignificance[index] & 127;
  40480. contextLabel = significance === 0 ? 15 : 14;
  40481. }
  40482. var bit = decoder.readBit(contexts, contextLabel);
  40483. coefficentsMagnitude[index] =
  40484. (coefficentsMagnitude[index] << 1) | bit;
  40485. bitsDecoded[index]++;
  40486. processingFlags[index] |= processedMask;
  40487. }
  40488. }
  40489. }
  40490. },
  40491. runCleanupPass: function BitModel_runCleanupPass() {
  40492. var decoder = this.decoder;
  40493. var width = this.width, height = this.height;
  40494. var neighborsSignificance = this.neighborsSignificance;
  40495. var coefficentsMagnitude = this.coefficentsMagnitude;
  40496. var coefficentsSign = this.coefficentsSign;
  40497. var contexts = this.contexts;
  40498. var labels = this.contextLabelTable;
  40499. var bitsDecoded = this.bitsDecoded;
  40500. var processingFlags = this.processingFlags;
  40501. var processedMask = 1;
  40502. var firstMagnitudeBitMask = 2;
  40503. var oneRowDown = width;
  40504. var twoRowsDown = width * 2;
  40505. var threeRowsDown = width * 3;
  40506. var iNext;
  40507. for (var i0 = 0; i0 < height; i0 = iNext) {
  40508. iNext = Math.min(i0 + 4, height);
  40509. var indexBase = i0 * width;
  40510. var checkAllEmpty = i0 + 3 < height;
  40511. for (var j = 0; j < width; j++) {
  40512. var index0 = indexBase + j;
  40513. // using the property: labels[neighborsSignificance[index]] === 0
  40514. // when neighborsSignificance[index] === 0
  40515. var allEmpty = (checkAllEmpty &&
  40516. processingFlags[index0] === 0 &&
  40517. processingFlags[index0 + oneRowDown] === 0 &&
  40518. processingFlags[index0 + twoRowsDown] === 0 &&
  40519. processingFlags[index0 + threeRowsDown] === 0 &&
  40520. neighborsSignificance[index0] === 0 &&
  40521. neighborsSignificance[index0 + oneRowDown] === 0 &&
  40522. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  40523. neighborsSignificance[index0 + threeRowsDown] === 0);
  40524. var i1 = 0, index = index0;
  40525. var i = i0, sign;
  40526. if (allEmpty) {
  40527. var hasSignificantCoefficent =
  40528. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  40529. if (!hasSignificantCoefficent) {
  40530. bitsDecoded[index0]++;
  40531. bitsDecoded[index0 + oneRowDown]++;
  40532. bitsDecoded[index0 + twoRowsDown]++;
  40533. bitsDecoded[index0 + threeRowsDown]++;
  40534. continue; // next column
  40535. }
  40536. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40537. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40538. if (i1 !== 0) {
  40539. i = i0 + i1;
  40540. index += i1 * width;
  40541. }
  40542. sign = this.decodeSignBit(i, j, index);
  40543. coefficentsSign[index] = sign;
  40544. coefficentsMagnitude[index] = 1;
  40545. this.setNeighborsSignificance(i, j, index);
  40546. processingFlags[index] |= firstMagnitudeBitMask;
  40547. index = index0;
  40548. for (var i2 = i0; i2 <= i; i2++, index += width) {
  40549. bitsDecoded[index]++;
  40550. }
  40551. i1++;
  40552. }
  40553. for (i = i0 + i1; i < iNext; i++, index += width) {
  40554. if (coefficentsMagnitude[index] ||
  40555. (processingFlags[index] & processedMask) !== 0) {
  40556. continue;
  40557. }
  40558. var contextLabel = labels[neighborsSignificance[index]];
  40559. var decision = decoder.readBit(contexts, contextLabel);
  40560. if (decision === 1) {
  40561. sign = this.decodeSignBit(i, j, index);
  40562. coefficentsSign[index] = sign;
  40563. coefficentsMagnitude[index] = 1;
  40564. this.setNeighborsSignificance(i, j, index);
  40565. processingFlags[index] |= firstMagnitudeBitMask;
  40566. }
  40567. bitsDecoded[index]++;
  40568. }
  40569. }
  40570. }
  40571. },
  40572. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  40573. var decoder = this.decoder;
  40574. var contexts = this.contexts;
  40575. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  40576. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  40577. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40578. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40579. if (symbol !== 0xA) {
  40580. throw new Error('JPX Error: Invalid segmentation symbol');
  40581. }
  40582. }
  40583. };
  40584. return BitModel;
  40585. })();
  40586. // Section F, Discrete wavelet transformation
  40587. var Transform = (function TransformClosure() {
  40588. function Transform() {}
  40589. Transform.prototype.calculate =
  40590. function transformCalculate(subbands, u0, v0) {
  40591. var ll = subbands[0];
  40592. for (var i = 1, ii = subbands.length; i < ii; i++) {
  40593. ll = this.iterate(ll, subbands[i], u0, v0);
  40594. }
  40595. return ll;
  40596. };
  40597. Transform.prototype.extend = function extend(buffer, offset, size) {
  40598. // Section F.3.7 extending... using max extension of 4
  40599. var i1 = offset - 1, j1 = offset + 1;
  40600. var i2 = offset + size - 2, j2 = offset + size;
  40601. buffer[i1--] = buffer[j1++];
  40602. buffer[j2++] = buffer[i2--];
  40603. buffer[i1--] = buffer[j1++];
  40604. buffer[j2++] = buffer[i2--];
  40605. buffer[i1--] = buffer[j1++];
  40606. buffer[j2++] = buffer[i2--];
  40607. buffer[i1] = buffer[j1];
  40608. buffer[j2] = buffer[i2];
  40609. };
  40610. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  40611. u0, v0) {
  40612. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  40613. var width = hl_lh_hh.width;
  40614. var height = hl_lh_hh.height;
  40615. var items = hl_lh_hh.items;
  40616. var i, j, k, l, u, v;
  40617. // Interleave LL according to Section F.3.3
  40618. for (k = 0, i = 0; i < llHeight; i++) {
  40619. l = i * 2 * width;
  40620. for (j = 0; j < llWidth; j++, k++, l += 2) {
  40621. items[l] = llItems[k];
  40622. }
  40623. }
  40624. // The LL band is not needed anymore.
  40625. llItems = ll.items = null;
  40626. var bufferPadding = 4;
  40627. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  40628. // Section F.3.4 HOR_SR
  40629. if (width === 1) {
  40630. // if width = 1, when u0 even keep items as is, when odd divide by 2
  40631. if ((u0 & 1) !== 0) {
  40632. for (v = 0, k = 0; v < height; v++, k += width) {
  40633. items[k] *= 0.5;
  40634. }
  40635. }
  40636. } else {
  40637. for (v = 0, k = 0; v < height; v++, k += width) {
  40638. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  40639. this.extend(rowBuffer, bufferPadding, width);
  40640. this.filter(rowBuffer, bufferPadding, width);
  40641. items.set(
  40642. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  40643. k);
  40644. }
  40645. }
  40646. // Accesses to the items array can take long, because it may not fit into
  40647. // CPU cache and has to be fetched from main memory. Since subsequent
  40648. // accesses to the items array are not local when reading columns, we
  40649. // have a cache miss every time. To reduce cache misses, get up to
  40650. // 'numBuffers' items at a time and store them into the individual
  40651. // buffers. The colBuffers should be small enough to fit into CPU cache.
  40652. var numBuffers = 16;
  40653. var colBuffers = [];
  40654. for (i = 0; i < numBuffers; i++) {
  40655. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  40656. }
  40657. var b, currentBuffer = 0;
  40658. ll = bufferPadding + height;
  40659. // Section F.3.5 VER_SR
  40660. if (height === 1) {
  40661. // if height = 1, when v0 even keep items as is, when odd divide by 2
  40662. if ((v0 & 1) !== 0) {
  40663. for (u = 0; u < width; u++) {
  40664. items[u] *= 0.5;
  40665. }
  40666. }
  40667. } else {
  40668. for (u = 0; u < width; u++) {
  40669. // if we ran out of buffers, copy several image columns at once
  40670. if (currentBuffer === 0) {
  40671. numBuffers = Math.min(width - u, numBuffers);
  40672. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  40673. for (b = 0; b < numBuffers; b++) {
  40674. colBuffers[b][l] = items[k + b];
  40675. }
  40676. }
  40677. currentBuffer = numBuffers;
  40678. }
  40679. currentBuffer--;
  40680. var buffer = colBuffers[currentBuffer];
  40681. this.extend(buffer, bufferPadding, height);
  40682. this.filter(buffer, bufferPadding, height);
  40683. // If this is last buffer in this group of buffers, flush all buffers.
  40684. if (currentBuffer === 0) {
  40685. k = u - numBuffers + 1;
  40686. for (l = bufferPadding; l < ll; k += width, l++) {
  40687. for (b = 0; b < numBuffers; b++) {
  40688. items[k + b] = colBuffers[b][l];
  40689. }
  40690. }
  40691. }
  40692. }
  40693. }
  40694. return {
  40695. width: width,
  40696. height: height,
  40697. items: items
  40698. };
  40699. };
  40700. return Transform;
  40701. })();
  40702. // Section 3.8.2 Irreversible 9-7 filter
  40703. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  40704. function IrreversibleTransform() {
  40705. Transform.call(this);
  40706. }
  40707. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  40708. IrreversibleTransform.prototype.filter =
  40709. function irreversibleTransformFilter(x, offset, length) {
  40710. var len = length >> 1;
  40711. offset = offset | 0;
  40712. var j, n, current, next;
  40713. var alpha = -1.586134342059924;
  40714. var beta = -0.052980118572961;
  40715. var gamma = 0.882911075530934;
  40716. var delta = 0.443506852043971;
  40717. var K = 1.230174104914001;
  40718. var K_ = 1 / K;
  40719. // step 1 is combined with step 3
  40720. // step 2
  40721. j = offset - 3;
  40722. for (n = len + 4; n--; j += 2) {
  40723. x[j] *= K_;
  40724. }
  40725. // step 1 & 3
  40726. j = offset - 2;
  40727. current = delta * x[j -1];
  40728. for (n = len + 3; n--; j += 2) {
  40729. next = delta * x[j + 1];
  40730. x[j] = K * x[j] - current - next;
  40731. if (n--) {
  40732. j += 2;
  40733. current = delta * x[j + 1];
  40734. x[j] = K * x[j] - current - next;
  40735. } else {
  40736. break;
  40737. }
  40738. }
  40739. // step 4
  40740. j = offset - 1;
  40741. current = gamma * x[j - 1];
  40742. for (n = len + 2; n--; j += 2) {
  40743. next = gamma * x[j + 1];
  40744. x[j] -= current + next;
  40745. if (n--) {
  40746. j += 2;
  40747. current = gamma * x[j + 1];
  40748. x[j] -= current + next;
  40749. } else {
  40750. break;
  40751. }
  40752. }
  40753. // step 5
  40754. j = offset;
  40755. current = beta * x[j - 1];
  40756. for (n = len + 1; n--; j += 2) {
  40757. next = beta * x[j + 1];
  40758. x[j] -= current + next;
  40759. if (n--) {
  40760. j += 2;
  40761. current = beta * x[j + 1];
  40762. x[j] -= current + next;
  40763. } else {
  40764. break;
  40765. }
  40766. }
  40767. // step 6
  40768. if (len !== 0) {
  40769. j = offset + 1;
  40770. current = alpha * x[j - 1];
  40771. for (n = len; n--; j += 2) {
  40772. next = alpha * x[j + 1];
  40773. x[j] -= current + next;
  40774. if (n--) {
  40775. j += 2;
  40776. current = alpha * x[j + 1];
  40777. x[j] -= current + next;
  40778. } else {
  40779. break;
  40780. }
  40781. }
  40782. }
  40783. };
  40784. return IrreversibleTransform;
  40785. })();
  40786. // Section 3.8.1 Reversible 5-3 filter
  40787. var ReversibleTransform = (function ReversibleTransformClosure() {
  40788. function ReversibleTransform() {
  40789. Transform.call(this);
  40790. }
  40791. ReversibleTransform.prototype = Object.create(Transform.prototype);
  40792. ReversibleTransform.prototype.filter =
  40793. function reversibleTransformFilter(x, offset, length) {
  40794. var len = length >> 1;
  40795. offset = offset | 0;
  40796. var j, n;
  40797. for (j = offset, n = len + 1; n--; j += 2) {
  40798. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  40799. }
  40800. for (j = offset + 1, n = len; n--; j += 2) {
  40801. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  40802. }
  40803. };
  40804. return ReversibleTransform;
  40805. })();
  40806. return JpxImage;
  40807. })();
  40808. var Jbig2Image = (function Jbig2ImageClosure() {
  40809. // Utility data structures
  40810. function ContextCache() {}
  40811. ContextCache.prototype = {
  40812. getContexts: function(id) {
  40813. if (id in this) {
  40814. return this[id];
  40815. }
  40816. return (this[id] = new Int8Array(1 << 16));
  40817. }
  40818. };
  40819. function DecodingContext(data, start, end) {
  40820. this.data = data;
  40821. this.start = start;
  40822. this.end = end;
  40823. }
  40824. DecodingContext.prototype = {
  40825. get decoder() {
  40826. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  40827. return shadow(this, 'decoder', decoder);
  40828. },
  40829. get contextCache() {
  40830. var cache = new ContextCache();
  40831. return shadow(this, 'contextCache', cache);
  40832. }
  40833. };
  40834. // Annex A. Arithmetic Integer Decoding Procedure
  40835. // A.2 Procedure for decoding values
  40836. function decodeInteger(contextCache, procedure, decoder) {
  40837. var contexts = contextCache.getContexts(procedure);
  40838. var prev = 1;
  40839. function readBits(length) {
  40840. var v = 0;
  40841. for (var i = 0; i < length; i++) {
  40842. var bit = decoder.readBit(contexts, prev);
  40843. prev = (prev < 256 ? (prev << 1) | bit :
  40844. (((prev << 1) | bit) & 511) | 256);
  40845. v = (v << 1) | bit;
  40846. }
  40847. return v >>> 0;
  40848. }
  40849. var sign = readBits(1);
  40850. var value = readBits(1) ?
  40851. (readBits(1) ?
  40852. (readBits(1) ?
  40853. (readBits(1) ?
  40854. (readBits(1) ?
  40855. (readBits(32) + 4436) :
  40856. readBits(12) + 340) :
  40857. readBits(8) + 84) :
  40858. readBits(6) + 20) :
  40859. readBits(4) + 4) :
  40860. readBits(2);
  40861. return (sign === 0 ? value : (value > 0 ? -value : null));
  40862. }
  40863. // A.3 The IAID decoding procedure
  40864. function decodeIAID(contextCache, decoder, codeLength) {
  40865. var contexts = contextCache.getContexts('IAID');
  40866. var prev = 1;
  40867. for (var i = 0; i < codeLength; i++) {
  40868. var bit = decoder.readBit(contexts, prev);
  40869. prev = (prev << 1) | bit;
  40870. }
  40871. if (codeLength < 31) {
  40872. return prev & ((1 << codeLength) - 1);
  40873. }
  40874. return prev & 0x7FFFFFFF;
  40875. }
  40876. // 7.3 Segment types
  40877. var SegmentTypes = [
  40878. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  40879. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  40880. null, null, null, null, null, 'patternDictionary', null, null, null,
  40881. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  40882. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  40883. null, null, null, null, null, 'IntermediateGenericRegion', null,
  40884. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  40885. 'IntermediateGenericRefinementRegion', null,
  40886. 'ImmediateGenericRefinementRegion',
  40887. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  40888. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  40889. 'Tables', null, null, null, null, null, null, null, null,
  40890. 'Extension'
  40891. ];
  40892. var CodingTemplates = [
  40893. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40894. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  40895. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40896. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  40897. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  40898. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40899. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40900. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  40901. {x: -1, y: 0}],
  40902. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  40903. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  40904. ];
  40905. var RefinementTemplates = [
  40906. {
  40907. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40908. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  40909. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  40910. },
  40911. {
  40912. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40913. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  40914. {x: 0, y: 1}, {x: 1, y: 1}]
  40915. }
  40916. ];
  40917. // See 6.2.5.7 Decoding the bitmap.
  40918. var ReusedContexts = [
  40919. 0x9B25, // 10011 0110010 0101
  40920. 0x0795, // 0011 110010 101
  40921. 0x00E5, // 001 11001 01
  40922. 0x0195 // 011001 0101
  40923. ];
  40924. var RefinementReusedContexts = [
  40925. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  40926. 0x0008 // '0000' + '001000'
  40927. ];
  40928. function decodeBitmapTemplate0(width, height, decodingContext) {
  40929. var decoder = decodingContext.decoder;
  40930. var contexts = decodingContext.contextCache.getContexts('GB');
  40931. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  40932. // ...ooooo....
  40933. // ..ooooooo... Context template for current pixel (X)
  40934. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  40935. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  40936. for (i = 0; i < height; i++) {
  40937. row = bitmap[i] = new Uint8Array(width);
  40938. row1 = (i < 1) ? row : bitmap[i - 1];
  40939. row2 = (i < 2) ? row : bitmap[i - 2];
  40940. // At the beginning of each row:
  40941. // Fill contextLabel with pixels that are above/right of (X)
  40942. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  40943. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  40944. (row1[3] << 4);
  40945. for (j = 0; j < width; j++) {
  40946. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  40947. // At each pixel: Clear contextLabel pixels that are shifted
  40948. // out of the context, then add new ones.
  40949. // If j + n is out of range at the right image border, then
  40950. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  40951. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  40952. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  40953. }
  40954. }
  40955. return bitmap;
  40956. }
  40957. // 6.2 Generic Region Decoding Procedure
  40958. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  40959. decodingContext) {
  40960. if (mmr) {
  40961. error('JBIG2 error: MMR encoding is not supported');
  40962. }
  40963. // Use optimized version for the most common case
  40964. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  40965. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  40966. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  40967. return decodeBitmapTemplate0(width, height, decodingContext);
  40968. }
  40969. var useskip = !!skip;
  40970. var template = CodingTemplates[templateIndex].concat(at);
  40971. // Sorting is non-standard, and it is not required. But sorting increases
  40972. // the number of template bits that can be reused from the previous
  40973. // contextLabel in the main loop.
  40974. template.sort(function (a, b) {
  40975. return (a.y - b.y) || (a.x - b.x);
  40976. });
  40977. var templateLength = template.length;
  40978. var templateX = new Int8Array(templateLength);
  40979. var templateY = new Int8Array(templateLength);
  40980. var changingTemplateEntries = [];
  40981. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  40982. var c, k;
  40983. for (k = 0; k < templateLength; k++) {
  40984. templateX[k] = template[k].x;
  40985. templateY[k] = template[k].y;
  40986. minX = Math.min(minX, template[k].x);
  40987. maxX = Math.max(maxX, template[k].x);
  40988. minY = Math.min(minY, template[k].y);
  40989. // Check if the template pixel appears in two consecutive context labels,
  40990. // so it can be reused. Otherwise, we add it to the list of changing
  40991. // template entries.
  40992. if (k < templateLength - 1 &&
  40993. template[k].y === template[k + 1].y &&
  40994. template[k].x === template[k + 1].x - 1) {
  40995. reuseMask |= 1 << (templateLength - 1 - k);
  40996. } else {
  40997. changingTemplateEntries.push(k);
  40998. }
  40999. }
  41000. var changingEntriesLength = changingTemplateEntries.length;
  41001. var changingTemplateX = new Int8Array(changingEntriesLength);
  41002. var changingTemplateY = new Int8Array(changingEntriesLength);
  41003. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  41004. for (c = 0; c < changingEntriesLength; c++) {
  41005. k = changingTemplateEntries[c];
  41006. changingTemplateX[c] = template[k].x;
  41007. changingTemplateY[c] = template[k].y;
  41008. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  41009. }
  41010. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  41011. var sbb_left = -minX;
  41012. var sbb_top = -minY;
  41013. var sbb_right = width - maxX;
  41014. var pseudoPixelContext = ReusedContexts[templateIndex];
  41015. var row = new Uint8Array(width);
  41016. var bitmap = [];
  41017. var decoder = decodingContext.decoder;
  41018. var contexts = decodingContext.contextCache.getContexts('GB');
  41019. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  41020. for (var i = 0; i < height; i++) {
  41021. if (prediction) {
  41022. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41023. ltp ^= sltp;
  41024. if (ltp) {
  41025. bitmap.push(row); // duplicate previous row
  41026. continue;
  41027. }
  41028. }
  41029. row = new Uint8Array(row);
  41030. bitmap.push(row);
  41031. for (j = 0; j < width; j++) {
  41032. if (useskip && skip[i][j]) {
  41033. row[j] = 0;
  41034. continue;
  41035. }
  41036. // Are we in the middle of a scanline, so we can reuse contextLabel
  41037. // bits?
  41038. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  41039. // If yes, we can just shift the bits that are reusable and only
  41040. // fetch the remaining ones.
  41041. contextLabel = (contextLabel << 1) & reuseMask;
  41042. for (k = 0; k < changingEntriesLength; k++) {
  41043. i0 = i + changingTemplateY[k];
  41044. j0 = j + changingTemplateX[k];
  41045. bit = bitmap[i0][j0];
  41046. if (bit) {
  41047. bit = changingTemplateBit[k];
  41048. contextLabel |= bit;
  41049. }
  41050. }
  41051. } else {
  41052. // compute the contextLabel from scratch
  41053. contextLabel = 0;
  41054. shift = templateLength - 1;
  41055. for (k = 0; k < templateLength; k++, shift--) {
  41056. j0 = j + templateX[k];
  41057. if (j0 >= 0 && j0 < width) {
  41058. i0 = i + templateY[k];
  41059. if (i0 >= 0) {
  41060. bit = bitmap[i0][j0];
  41061. if (bit) {
  41062. contextLabel |= bit << shift;
  41063. }
  41064. }
  41065. }
  41066. }
  41067. }
  41068. var pixel = decoder.readBit(contexts, contextLabel);
  41069. row[j] = pixel;
  41070. }
  41071. }
  41072. return bitmap;
  41073. }
  41074. // 6.3.2 Generic Refinement Region Decoding Procedure
  41075. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  41076. offsetX, offsetY, prediction, at,
  41077. decodingContext) {
  41078. var codingTemplate = RefinementTemplates[templateIndex].coding;
  41079. if (templateIndex === 0) {
  41080. codingTemplate = codingTemplate.concat([at[0]]);
  41081. }
  41082. var codingTemplateLength = codingTemplate.length;
  41083. var codingTemplateX = new Int32Array(codingTemplateLength);
  41084. var codingTemplateY = new Int32Array(codingTemplateLength);
  41085. var k;
  41086. for (k = 0; k < codingTemplateLength; k++) {
  41087. codingTemplateX[k] = codingTemplate[k].x;
  41088. codingTemplateY[k] = codingTemplate[k].y;
  41089. }
  41090. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  41091. if (templateIndex === 0) {
  41092. referenceTemplate = referenceTemplate.concat([at[1]]);
  41093. }
  41094. var referenceTemplateLength = referenceTemplate.length;
  41095. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  41096. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  41097. for (k = 0; k < referenceTemplateLength; k++) {
  41098. referenceTemplateX[k] = referenceTemplate[k].x;
  41099. referenceTemplateY[k] = referenceTemplate[k].y;
  41100. }
  41101. var referenceWidth = referenceBitmap[0].length;
  41102. var referenceHeight = referenceBitmap.length;
  41103. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  41104. var bitmap = [];
  41105. var decoder = decodingContext.decoder;
  41106. var contexts = decodingContext.contextCache.getContexts('GR');
  41107. var ltp = 0;
  41108. for (var i = 0; i < height; i++) {
  41109. if (prediction) {
  41110. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41111. ltp ^= sltp;
  41112. if (ltp) {
  41113. error('JBIG2 error: prediction is not supported');
  41114. }
  41115. }
  41116. var row = new Uint8Array(width);
  41117. bitmap.push(row);
  41118. for (var j = 0; j < width; j++) {
  41119. var i0, j0;
  41120. var contextLabel = 0;
  41121. for (k = 0; k < codingTemplateLength; k++) {
  41122. i0 = i + codingTemplateY[k];
  41123. j0 = j + codingTemplateX[k];
  41124. if (i0 < 0 || j0 < 0 || j0 >= width) {
  41125. contextLabel <<= 1; // out of bound pixel
  41126. } else {
  41127. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  41128. }
  41129. }
  41130. for (k = 0; k < referenceTemplateLength; k++) {
  41131. i0 = i + referenceTemplateY[k] + offsetY;
  41132. j0 = j + referenceTemplateX[k] + offsetX;
  41133. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  41134. j0 >= referenceWidth) {
  41135. contextLabel <<= 1; // out of bound pixel
  41136. } else {
  41137. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  41138. }
  41139. }
  41140. var pixel = decoder.readBit(contexts, contextLabel);
  41141. row[j] = pixel;
  41142. }
  41143. }
  41144. return bitmap;
  41145. }
  41146. // 6.5.5 Decoding the symbol dictionary
  41147. function decodeSymbolDictionary(huffman, refinement, symbols,
  41148. numberOfNewSymbols, numberOfExportedSymbols,
  41149. huffmanTables, templateIndex, at,
  41150. refinementTemplateIndex, refinementAt,
  41151. decodingContext) {
  41152. if (huffman) {
  41153. error('JBIG2 error: huffman is not supported');
  41154. }
  41155. var newSymbols = [];
  41156. var currentHeight = 0;
  41157. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  41158. var decoder = decodingContext.decoder;
  41159. var contextCache = decodingContext.contextCache;
  41160. while (newSymbols.length < numberOfNewSymbols) {
  41161. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  41162. currentHeight += deltaHeight;
  41163. var currentWidth = 0;
  41164. var totalWidth = 0;
  41165. while (true) {
  41166. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  41167. if (deltaWidth === null) {
  41168. break; // OOB
  41169. }
  41170. currentWidth += deltaWidth;
  41171. totalWidth += currentWidth;
  41172. var bitmap;
  41173. if (refinement) {
  41174. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  41175. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  41176. if (numberOfInstances > 1) {
  41177. bitmap = decodeTextRegion(huffman, refinement,
  41178. currentWidth, currentHeight, 0,
  41179. numberOfInstances, 1, //strip size
  41180. symbols.concat(newSymbols),
  41181. symbolCodeLength,
  41182. 0, //transposed
  41183. 0, //ds offset
  41184. 1, //top left 7.4.3.1.1
  41185. 0, //OR operator
  41186. huffmanTables,
  41187. refinementTemplateIndex, refinementAt,
  41188. decodingContext);
  41189. } else {
  41190. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41191. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41192. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41193. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  41194. newSymbols[symbolId - symbols.length]);
  41195. bitmap = decodeRefinement(currentWidth, currentHeight,
  41196. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  41197. decodingContext);
  41198. }
  41199. } else {
  41200. // 6.5.8.1 Direct-coded symbol bitmap
  41201. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  41202. templateIndex, false, null, at, decodingContext);
  41203. }
  41204. newSymbols.push(bitmap);
  41205. }
  41206. }
  41207. // 6.5.10 Exported symbols
  41208. var exportedSymbols = [];
  41209. var flags = [], currentFlag = false;
  41210. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  41211. while (flags.length < totalSymbolsLength) {
  41212. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  41213. while (runLength--) {
  41214. flags.push(currentFlag);
  41215. }
  41216. currentFlag = !currentFlag;
  41217. }
  41218. for (var i = 0, ii = symbols.length; i < ii; i++) {
  41219. if (flags[i]) {
  41220. exportedSymbols.push(symbols[i]);
  41221. }
  41222. }
  41223. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  41224. if (flags[i]) {
  41225. exportedSymbols.push(newSymbols[j]);
  41226. }
  41227. }
  41228. return exportedSymbols;
  41229. }
  41230. function decodeTextRegion(huffman, refinement, width, height,
  41231. defaultPixelValue, numberOfSymbolInstances,
  41232. stripSize, inputSymbols, symbolCodeLength,
  41233. transposed, dsOffset, referenceCorner,
  41234. combinationOperator, huffmanTables,
  41235. refinementTemplateIndex, refinementAt,
  41236. decodingContext) {
  41237. if (huffman) {
  41238. error('JBIG2 error: huffman is not supported');
  41239. }
  41240. // Prepare bitmap
  41241. var bitmap = [];
  41242. var i, row;
  41243. for (i = 0; i < height; i++) {
  41244. row = new Uint8Array(width);
  41245. if (defaultPixelValue) {
  41246. for (var j = 0; j < width; j++) {
  41247. row[j] = defaultPixelValue;
  41248. }
  41249. }
  41250. bitmap.push(row);
  41251. }
  41252. var decoder = decodingContext.decoder;
  41253. var contextCache = decodingContext.contextCache;
  41254. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41255. var firstS = 0;
  41256. i = 0;
  41257. while (i < numberOfSymbolInstances) {
  41258. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41259. stripT += deltaT;
  41260. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  41261. firstS += deltaFirstS;
  41262. var currentS = firstS;
  41263. do {
  41264. var currentT = (stripSize === 1 ? 0 :
  41265. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  41266. var t = stripSize * stripT + currentT;
  41267. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41268. var applyRefinement = (refinement &&
  41269. decodeInteger(contextCache, 'IARI', decoder));
  41270. var symbolBitmap = inputSymbols[symbolId];
  41271. var symbolWidth = symbolBitmap[0].length;
  41272. var symbolHeight = symbolBitmap.length;
  41273. if (applyRefinement) {
  41274. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  41275. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  41276. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41277. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41278. symbolWidth += rdw;
  41279. symbolHeight += rdh;
  41280. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  41281. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  41282. (rdh >> 1) + rdy, false, refinementAt,
  41283. decodingContext);
  41284. }
  41285. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  41286. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  41287. var s2, t2, symbolRow;
  41288. if (transposed) {
  41289. // Place Symbol Bitmap from T1,S1
  41290. for (s2 = 0; s2 < symbolHeight; s2++) {
  41291. row = bitmap[offsetS + s2];
  41292. if (!row) {
  41293. continue;
  41294. }
  41295. symbolRow = symbolBitmap[s2];
  41296. // To ignore Parts of Symbol bitmap which goes
  41297. // outside bitmap region
  41298. var maxWidth = Math.min(width - offsetT, symbolWidth);
  41299. switch (combinationOperator) {
  41300. case 0: // OR
  41301. for (t2 = 0; t2 < maxWidth; t2++) {
  41302. row[offsetT + t2] |= symbolRow[t2];
  41303. }
  41304. break;
  41305. case 2: // XOR
  41306. for (t2 = 0; t2 < maxWidth; t2++) {
  41307. row[offsetT + t2] ^= symbolRow[t2];
  41308. }
  41309. break;
  41310. default:
  41311. error('JBIG2 error: operator ' + combinationOperator +
  41312. ' is not supported');
  41313. }
  41314. }
  41315. currentS += symbolHeight - 1;
  41316. } else {
  41317. for (t2 = 0; t2 < symbolHeight; t2++) {
  41318. row = bitmap[offsetT + t2];
  41319. if (!row) {
  41320. continue;
  41321. }
  41322. symbolRow = symbolBitmap[t2];
  41323. switch (combinationOperator) {
  41324. case 0: // OR
  41325. for (s2 = 0; s2 < symbolWidth; s2++) {
  41326. row[offsetS + s2] |= symbolRow[s2];
  41327. }
  41328. break;
  41329. case 2: // XOR
  41330. for (s2 = 0; s2 < symbolWidth; s2++) {
  41331. row[offsetS + s2] ^= symbolRow[s2];
  41332. }
  41333. break;
  41334. default:
  41335. error('JBIG2 error: operator ' + combinationOperator +
  41336. ' is not supported');
  41337. }
  41338. }
  41339. currentS += symbolWidth - 1;
  41340. }
  41341. i++;
  41342. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  41343. if (deltaS === null) {
  41344. break; // OOB
  41345. }
  41346. currentS += deltaS + dsOffset;
  41347. } while (true);
  41348. }
  41349. return bitmap;
  41350. }
  41351. function readSegmentHeader(data, start) {
  41352. var segmentHeader = {};
  41353. segmentHeader.number = readUint32(data, start);
  41354. var flags = data[start + 4];
  41355. var segmentType = flags & 0x3F;
  41356. if (!SegmentTypes[segmentType]) {
  41357. error('JBIG2 error: invalid segment type: ' + segmentType);
  41358. }
  41359. segmentHeader.type = segmentType;
  41360. segmentHeader.typeName = SegmentTypes[segmentType];
  41361. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  41362. var pageAssociationFieldSize = !!(flags & 0x40);
  41363. var referredFlags = data[start + 5];
  41364. var referredToCount = (referredFlags >> 5) & 7;
  41365. var retainBits = [referredFlags & 31];
  41366. var position = start + 6;
  41367. if (referredFlags === 7) {
  41368. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  41369. position += 3;
  41370. var bytes = (referredToCount + 7) >> 3;
  41371. retainBits[0] = data[position++];
  41372. while (--bytes > 0) {
  41373. retainBits.push(data[position++]);
  41374. }
  41375. } else if (referredFlags === 5 || referredFlags === 6) {
  41376. error('JBIG2 error: invalid referred-to flags');
  41377. }
  41378. segmentHeader.retainBits = retainBits;
  41379. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  41380. (segmentHeader.number <= 65536 ? 2 : 4));
  41381. var referredTo = [];
  41382. var i, ii;
  41383. for (i = 0; i < referredToCount; i++) {
  41384. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  41385. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  41386. readUint32(data, position)));
  41387. referredTo.push(number);
  41388. position += referredToSegmentNumberSize;
  41389. }
  41390. segmentHeader.referredTo = referredTo;
  41391. if (!pageAssociationFieldSize) {
  41392. segmentHeader.pageAssociation = data[position++];
  41393. } else {
  41394. segmentHeader.pageAssociation = readUint32(data, position);
  41395. position += 4;
  41396. }
  41397. segmentHeader.length = readUint32(data, position);
  41398. position += 4;
  41399. if (segmentHeader.length === 0xFFFFFFFF) {
  41400. // 7.2.7 Segment data length, unknown segment length
  41401. if (segmentType === 38) { // ImmediateGenericRegion
  41402. var genericRegionInfo = readRegionSegmentInformation(data, position);
  41403. var genericRegionSegmentFlags = data[position +
  41404. RegionSegmentInformationFieldLength];
  41405. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  41406. // searching for the segment end
  41407. var searchPatternLength = 6;
  41408. var searchPattern = new Uint8Array(searchPatternLength);
  41409. if (!genericRegionMmr) {
  41410. searchPattern[0] = 0xFF;
  41411. searchPattern[1] = 0xAC;
  41412. }
  41413. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  41414. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  41415. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  41416. searchPattern[5] = genericRegionInfo.height & 0xFF;
  41417. for (i = position, ii = data.length; i < ii; i++) {
  41418. var j = 0;
  41419. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  41420. j++;
  41421. }
  41422. if (j === searchPatternLength) {
  41423. segmentHeader.length = i + searchPatternLength;
  41424. break;
  41425. }
  41426. }
  41427. if (segmentHeader.length === 0xFFFFFFFF) {
  41428. error('JBIG2 error: segment end was not found');
  41429. }
  41430. } else {
  41431. error('JBIG2 error: invalid unknown segment length');
  41432. }
  41433. }
  41434. segmentHeader.headerEnd = position;
  41435. return segmentHeader;
  41436. }
  41437. function readSegments(header, data, start, end) {
  41438. var segments = [];
  41439. var position = start;
  41440. while (position < end) {
  41441. var segmentHeader = readSegmentHeader(data, position);
  41442. position = segmentHeader.headerEnd;
  41443. var segment = {
  41444. header: segmentHeader,
  41445. data: data
  41446. };
  41447. if (!header.randomAccess) {
  41448. segment.start = position;
  41449. position += segmentHeader.length;
  41450. segment.end = position;
  41451. }
  41452. segments.push(segment);
  41453. if (segmentHeader.type === 51) {
  41454. break; // end of file is found
  41455. }
  41456. }
  41457. if (header.randomAccess) {
  41458. for (var i = 0, ii = segments.length; i < ii; i++) {
  41459. segments[i].start = position;
  41460. position += segments[i].header.length;
  41461. segments[i].end = position;
  41462. }
  41463. }
  41464. return segments;
  41465. }
  41466. // 7.4.1 Region segment information field
  41467. function readRegionSegmentInformation(data, start) {
  41468. return {
  41469. width: readUint32(data, start),
  41470. height: readUint32(data, start + 4),
  41471. x: readUint32(data, start + 8),
  41472. y: readUint32(data, start + 12),
  41473. combinationOperator: data[start + 16] & 7
  41474. };
  41475. }
  41476. var RegionSegmentInformationFieldLength = 17;
  41477. function processSegment(segment, visitor) {
  41478. var header = segment.header;
  41479. var data = segment.data, position = segment.start, end = segment.end;
  41480. var args, at, i, atLength;
  41481. switch (header.type) {
  41482. case 0: // SymbolDictionary
  41483. // 7.4.2 Symbol dictionary segment syntax
  41484. var dictionary = {};
  41485. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  41486. dictionary.huffman = !!(dictionaryFlags & 1);
  41487. dictionary.refinement = !!(dictionaryFlags & 2);
  41488. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  41489. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  41490. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  41491. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  41492. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  41493. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  41494. dictionary.template = (dictionaryFlags >> 10) & 3;
  41495. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  41496. position += 2;
  41497. if (!dictionary.huffman) {
  41498. atLength = dictionary.template === 0 ? 4 : 1;
  41499. at = [];
  41500. for (i = 0; i < atLength; i++) {
  41501. at.push({
  41502. x: readInt8(data, position),
  41503. y: readInt8(data, position + 1)
  41504. });
  41505. position += 2;
  41506. }
  41507. dictionary.at = at;
  41508. }
  41509. if (dictionary.refinement && !dictionary.refinementTemplate) {
  41510. at = [];
  41511. for (i = 0; i < 2; i++) {
  41512. at.push({
  41513. x: readInt8(data, position),
  41514. y: readInt8(data, position + 1)
  41515. });
  41516. position += 2;
  41517. }
  41518. dictionary.refinementAt = at;
  41519. }
  41520. dictionary.numberOfExportedSymbols = readUint32(data, position);
  41521. position += 4;
  41522. dictionary.numberOfNewSymbols = readUint32(data, position);
  41523. position += 4;
  41524. args = [dictionary, header.number, header.referredTo,
  41525. data, position, end];
  41526. break;
  41527. case 6: // ImmediateTextRegion
  41528. case 7: // ImmediateLosslessTextRegion
  41529. var textRegion = {};
  41530. textRegion.info = readRegionSegmentInformation(data, position);
  41531. position += RegionSegmentInformationFieldLength;
  41532. var textRegionSegmentFlags = readUint16(data, position);
  41533. position += 2;
  41534. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  41535. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  41536. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  41537. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  41538. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  41539. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  41540. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  41541. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  41542. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  41543. if (textRegion.huffman) {
  41544. var textRegionHuffmanFlags = readUint16(data, position);
  41545. position += 2;
  41546. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  41547. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  41548. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  41549. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  41550. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  41551. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  41552. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  41553. textRegion.huffmanRefinementSizeSelector =
  41554. !!(textRegionHuffmanFlags & 14);
  41555. }
  41556. if (textRegion.refinement && !textRegion.refinementTemplate) {
  41557. at = [];
  41558. for (i = 0; i < 2; i++) {
  41559. at.push({
  41560. x: readInt8(data, position),
  41561. y: readInt8(data, position + 1)
  41562. });
  41563. position += 2;
  41564. }
  41565. textRegion.refinementAt = at;
  41566. }
  41567. textRegion.numberOfSymbolInstances = readUint32(data, position);
  41568. position += 4;
  41569. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  41570. if (textRegion.huffman) {
  41571. error('JBIG2 error: huffman is not supported');
  41572. }
  41573. args = [textRegion, header.referredTo, data, position, end];
  41574. break;
  41575. case 38: // ImmediateGenericRegion
  41576. case 39: // ImmediateLosslessGenericRegion
  41577. var genericRegion = {};
  41578. genericRegion.info = readRegionSegmentInformation(data, position);
  41579. position += RegionSegmentInformationFieldLength;
  41580. var genericRegionSegmentFlags = data[position++];
  41581. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  41582. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  41583. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  41584. if (!genericRegion.mmr) {
  41585. atLength = genericRegion.template === 0 ? 4 : 1;
  41586. at = [];
  41587. for (i = 0; i < atLength; i++) {
  41588. at.push({
  41589. x: readInt8(data, position),
  41590. y: readInt8(data, position + 1)
  41591. });
  41592. position += 2;
  41593. }
  41594. genericRegion.at = at;
  41595. }
  41596. args = [genericRegion, data, position, end];
  41597. break;
  41598. case 48: // PageInformation
  41599. var pageInfo = {
  41600. width: readUint32(data, position),
  41601. height: readUint32(data, position + 4),
  41602. resolutionX: readUint32(data, position + 8),
  41603. resolutionY: readUint32(data, position + 12)
  41604. };
  41605. if (pageInfo.height === 0xFFFFFFFF) {
  41606. delete pageInfo.height;
  41607. }
  41608. var pageSegmentFlags = data[position + 16];
  41609. var pageStripingInformatiom = readUint16(data, position + 17);
  41610. pageInfo.lossless = !!(pageSegmentFlags & 1);
  41611. pageInfo.refinement = !!(pageSegmentFlags & 2);
  41612. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  41613. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  41614. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  41615. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  41616. args = [pageInfo];
  41617. break;
  41618. case 49: // EndOfPage
  41619. break;
  41620. case 50: // EndOfStripe
  41621. break;
  41622. case 51: // EndOfFile
  41623. break;
  41624. case 62: // 7.4.15 defines 2 extension types which
  41625. // are comments and can be ignored.
  41626. break;
  41627. default:
  41628. error('JBIG2 error: segment type ' + header.typeName + '(' +
  41629. header.type + ') is not implemented');
  41630. }
  41631. var callbackName = 'on' + header.typeName;
  41632. if (callbackName in visitor) {
  41633. visitor[callbackName].apply(visitor, args);
  41634. }
  41635. }
  41636. function processSegments(segments, visitor) {
  41637. for (var i = 0, ii = segments.length; i < ii; i++) {
  41638. processSegment(segments[i], visitor);
  41639. }
  41640. }
  41641. function parseJbig2(data, start, end) {
  41642. var position = start;
  41643. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  41644. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  41645. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  41646. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  41647. error('JBIG2 error: invalid header');
  41648. }
  41649. var header = {};
  41650. position += 8;
  41651. var flags = data[position++];
  41652. header.randomAccess = !(flags & 1);
  41653. if (!(flags & 2)) {
  41654. header.numberOfPages = readUint32(data, position);
  41655. position += 4;
  41656. }
  41657. var segments = readSegments(header, data, position, end);
  41658. error('Not implemented');
  41659. // processSegments(segments, new SimpleSegmentVisitor());
  41660. }
  41661. function parseJbig2Chunks(chunks) {
  41662. var visitor = new SimpleSegmentVisitor();
  41663. for (var i = 0, ii = chunks.length; i < ii; i++) {
  41664. var chunk = chunks[i];
  41665. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  41666. processSegments(segments, visitor);
  41667. }
  41668. return visitor.buffer;
  41669. }
  41670. function SimpleSegmentVisitor() {}
  41671. SimpleSegmentVisitor.prototype = {
  41672. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  41673. this.currentPageInfo = info;
  41674. var rowSize = (info.width + 7) >> 3;
  41675. var buffer = new Uint8Array(rowSize * info.height);
  41676. // The contents of ArrayBuffers are initialized to 0.
  41677. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  41678. if (info.defaultPixelValue) {
  41679. for (var i = 0, ii = buffer.length; i < ii; i++) {
  41680. buffer[i] = 0xFF;
  41681. }
  41682. }
  41683. this.buffer = buffer;
  41684. },
  41685. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  41686. var pageInfo = this.currentPageInfo;
  41687. var width = regionInfo.width, height = regionInfo.height;
  41688. var rowSize = (pageInfo.width + 7) >> 3;
  41689. var combinationOperator = pageInfo.combinationOperatorOverride ?
  41690. regionInfo.combinationOperator : pageInfo.combinationOperator;
  41691. var buffer = this.buffer;
  41692. var mask0 = 128 >> (regionInfo.x & 7);
  41693. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  41694. var i, j, mask, offset;
  41695. switch (combinationOperator) {
  41696. case 0: // OR
  41697. for (i = 0; i < height; i++) {
  41698. mask = mask0;
  41699. offset = offset0;
  41700. for (j = 0; j < width; j++) {
  41701. if (bitmap[i][j]) {
  41702. buffer[offset] |= mask;
  41703. }
  41704. mask >>= 1;
  41705. if (!mask) {
  41706. mask = 128;
  41707. offset++;
  41708. }
  41709. }
  41710. offset0 += rowSize;
  41711. }
  41712. break;
  41713. case 2: // XOR
  41714. for (i = 0; i < height; i++) {
  41715. mask = mask0;
  41716. offset = offset0;
  41717. for (j = 0; j < width; j++) {
  41718. if (bitmap[i][j]) {
  41719. buffer[offset] ^= mask;
  41720. }
  41721. mask >>= 1;
  41722. if (!mask) {
  41723. mask = 128;
  41724. offset++;
  41725. }
  41726. }
  41727. offset0 += rowSize;
  41728. }
  41729. break;
  41730. default:
  41731. error('JBIG2 error: operator ' + combinationOperator +
  41732. ' is not supported');
  41733. }
  41734. },
  41735. onImmediateGenericRegion:
  41736. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  41737. start, end) {
  41738. var regionInfo = region.info;
  41739. var decodingContext = new DecodingContext(data, start, end);
  41740. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  41741. region.template, region.prediction, null,
  41742. region.at, decodingContext);
  41743. this.drawBitmap(regionInfo, bitmap);
  41744. },
  41745. onImmediateLosslessGenericRegion:
  41746. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  41747. this.onImmediateGenericRegion.apply(this, arguments);
  41748. },
  41749. onSymbolDictionary:
  41750. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  41751. currentSegment,
  41752. referredSegments,
  41753. data, start, end) {
  41754. var huffmanTables;
  41755. if (dictionary.huffman) {
  41756. error('JBIG2 error: huffman is not supported');
  41757. }
  41758. // Combines exported symbols from all referred segments
  41759. var symbols = this.symbols;
  41760. if (!symbols) {
  41761. this.symbols = symbols = {};
  41762. }
  41763. var inputSymbols = [];
  41764. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41765. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41766. }
  41767. var decodingContext = new DecodingContext(data, start, end);
  41768. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  41769. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  41770. dictionary.numberOfExportedSymbols, huffmanTables,
  41771. dictionary.template, dictionary.at,
  41772. dictionary.refinementTemplate, dictionary.refinementAt,
  41773. decodingContext);
  41774. },
  41775. onImmediateTextRegion:
  41776. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  41777. referredSegments,
  41778. data, start, end) {
  41779. var regionInfo = region.info;
  41780. var huffmanTables;
  41781. // Combines exported symbols from all referred segments
  41782. var symbols = this.symbols;
  41783. var inputSymbols = [];
  41784. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41785. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41786. }
  41787. var symbolCodeLength = log2(inputSymbols.length);
  41788. var decodingContext = new DecodingContext(data, start, end);
  41789. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  41790. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  41791. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  41792. symbolCodeLength, region.transposed, region.dsOffset,
  41793. region.referenceCorner, region.combinationOperator, huffmanTables,
  41794. region.refinementTemplate, region.refinementAt, decodingContext);
  41795. this.drawBitmap(regionInfo, bitmap);
  41796. },
  41797. onImmediateLosslessTextRegion:
  41798. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  41799. this.onImmediateTextRegion.apply(this, arguments);
  41800. }
  41801. };
  41802. function Jbig2Image() {}
  41803. Jbig2Image.prototype = {
  41804. parseChunks: function Jbig2Image_parseChunks(chunks) {
  41805. return parseJbig2Chunks(chunks);
  41806. }
  41807. };
  41808. return Jbig2Image;
  41809. })();
  41810. var bidi = PDFJS.bidi = (function bidiClosure() {
  41811. // Character types for symbols from 0000 to 00FF.
  41812. var baseTypes = [
  41813. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  41814. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41815. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  41816. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  41817. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  41818. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41819. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  41820. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41821. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41822. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  41823. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41824. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41825. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  41826. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  41827. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41828. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41829. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41830. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41831. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  41832. ];
  41833. // Character types for symbols from 0600 to 06FF
  41834. var arabicTypes = [
  41835. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41836. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  41837. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41838. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41839. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41840. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41841. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41842. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41843. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  41844. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41845. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41846. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41847. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41848. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41849. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41850. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41851. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41852. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41853. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41854. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  41855. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41856. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  41857. ];
  41858. function isOdd(i) {
  41859. return (i & 1) !== 0;
  41860. }
  41861. function isEven(i) {
  41862. return (i & 1) === 0;
  41863. }
  41864. function findUnequal(arr, start, value) {
  41865. for (var j = start, jj = arr.length; j < jj; ++j) {
  41866. if (arr[j] !== value) {
  41867. return j;
  41868. }
  41869. }
  41870. return j;
  41871. }
  41872. function setValues(arr, start, end, value) {
  41873. for (var j = start; j < end; ++j) {
  41874. arr[j] = value;
  41875. }
  41876. }
  41877. function reverseValues(arr, start, end) {
  41878. for (var i = start, j = end - 1; i < j; ++i, --j) {
  41879. var temp = arr[i];
  41880. arr[i] = arr[j];
  41881. arr[j] = temp;
  41882. }
  41883. }
  41884. function createBidiText(str, isLTR, vertical) {
  41885. return {
  41886. str: str,
  41887. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  41888. };
  41889. }
  41890. // These are used in bidi(), which is called frequently. We re-use them on
  41891. // each call to avoid unnecessary allocations.
  41892. var chars = [];
  41893. var types = [];
  41894. function bidi(str, startLevel, vertical) {
  41895. var isLTR = true;
  41896. var strLength = str.length;
  41897. if (strLength === 0 || vertical) {
  41898. return createBidiText(str, isLTR, vertical);
  41899. }
  41900. // Get types and fill arrays
  41901. chars.length = strLength;
  41902. types.length = strLength;
  41903. var numBidi = 0;
  41904. var i, ii;
  41905. for (i = 0; i < strLength; ++i) {
  41906. chars[i] = str.charAt(i);
  41907. var charCode = str.charCodeAt(i);
  41908. var charType = 'L';
  41909. if (charCode <= 0x00ff) {
  41910. charType = baseTypes[charCode];
  41911. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  41912. charType = 'R';
  41913. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  41914. charType = arabicTypes[charCode & 0xff];
  41915. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  41916. charType = 'AL';
  41917. }
  41918. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  41919. numBidi++;
  41920. }
  41921. types[i] = charType;
  41922. }
  41923. // Detect the bidi method
  41924. // - If there are no rtl characters then no bidi needed
  41925. // - If less than 30% chars are rtl then string is primarily ltr
  41926. // - If more than 30% chars are rtl then string is primarily rtl
  41927. if (numBidi === 0) {
  41928. isLTR = true;
  41929. return createBidiText(str, isLTR);
  41930. }
  41931. if (startLevel === -1) {
  41932. if ((strLength / numBidi) < 0.3) {
  41933. isLTR = true;
  41934. startLevel = 0;
  41935. } else {
  41936. isLTR = false;
  41937. startLevel = 1;
  41938. }
  41939. }
  41940. var levels = [];
  41941. for (i = 0; i < strLength; ++i) {
  41942. levels[i] = startLevel;
  41943. }
  41944. /*
  41945. X1-X10: skip most of this, since we are NOT doing the embeddings.
  41946. */
  41947. var e = (isOdd(startLevel) ? 'R' : 'L');
  41948. var sor = e;
  41949. var eor = sor;
  41950. /*
  41951. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  41952. type of the NSM to the type of the previous character. If the NSM is at the
  41953. start of the level run, it will get the type of sor.
  41954. */
  41955. var lastType = sor;
  41956. for (i = 0; i < strLength; ++i) {
  41957. if (types[i] === 'NSM') {
  41958. types[i] = lastType;
  41959. } else {
  41960. lastType = types[i];
  41961. }
  41962. }
  41963. /*
  41964. W2. Search backwards from each instance of a European number until the
  41965. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  41966. the type of the European number to Arabic number.
  41967. */
  41968. lastType = sor;
  41969. var t;
  41970. for (i = 0; i < strLength; ++i) {
  41971. t = types[i];
  41972. if (t === 'EN') {
  41973. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  41974. } else if (t === 'R' || t === 'L' || t === 'AL') {
  41975. lastType = t;
  41976. }
  41977. }
  41978. /*
  41979. W3. Change all ALs to R.
  41980. */
  41981. for (i = 0; i < strLength; ++i) {
  41982. t = types[i];
  41983. if (t === 'AL') {
  41984. types[i] = 'R';
  41985. }
  41986. }
  41987. /*
  41988. W4. A single European separator between two European numbers changes to a
  41989. European number. A single common separator between two numbers of the same
  41990. type changes to that type:
  41991. */
  41992. for (i = 1; i < strLength - 1; ++i) {
  41993. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  41994. types[i] = 'EN';
  41995. }
  41996. if (types[i] === 'CS' &&
  41997. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  41998. types[i + 1] === types[i - 1]) {
  41999. types[i] = types[i - 1];
  42000. }
  42001. }
  42002. /*
  42003. W5. A sequence of European terminators adjacent to European numbers changes
  42004. to all European numbers:
  42005. */
  42006. for (i = 0; i < strLength; ++i) {
  42007. if (types[i] === 'EN') {
  42008. // do before
  42009. var j;
  42010. for (j = i - 1; j >= 0; --j) {
  42011. if (types[j] !== 'ET') {
  42012. break;
  42013. }
  42014. types[j] = 'EN';
  42015. }
  42016. // do after
  42017. for (j = i + 1; j < strLength; --j) {
  42018. if (types[j] !== 'ET') {
  42019. break;
  42020. }
  42021. types[j] = 'EN';
  42022. }
  42023. }
  42024. }
  42025. /*
  42026. W6. Otherwise, separators and terminators change to Other Neutral:
  42027. */
  42028. for (i = 0; i < strLength; ++i) {
  42029. t = types[i];
  42030. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  42031. types[i] = 'ON';
  42032. }
  42033. }
  42034. /*
  42035. W7. Search backwards from each instance of a European number until the
  42036. first strong type (R, L, or sor) is found. If an L is found, then change
  42037. the type of the European number to L.
  42038. */
  42039. lastType = sor;
  42040. for (i = 0; i < strLength; ++i) {
  42041. t = types[i];
  42042. if (t === 'EN') {
  42043. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  42044. } else if (t === 'R' || t === 'L') {
  42045. lastType = t;
  42046. }
  42047. }
  42048. /*
  42049. N1. A sequence of neutrals takes the direction of the surrounding strong
  42050. text if the text on both sides has the same direction. European and Arabic
  42051. numbers are treated as though they were R. Start-of-level-run (sor) and
  42052. end-of-level-run (eor) are used at level run boundaries.
  42053. */
  42054. for (i = 0; i < strLength; ++i) {
  42055. if (types[i] === 'ON') {
  42056. var end = findUnequal(types, i + 1, 'ON');
  42057. var before = sor;
  42058. if (i > 0) {
  42059. before = types[i - 1];
  42060. }
  42061. var after = eor;
  42062. if (end + 1 < strLength) {
  42063. after = types[end + 1];
  42064. }
  42065. if (before !== 'L') {
  42066. before = 'R';
  42067. }
  42068. if (after !== 'L') {
  42069. after = 'R';
  42070. }
  42071. if (before === after) {
  42072. setValues(types, i, end, before);
  42073. }
  42074. i = end - 1; // reset to end (-1 so next iteration is ok)
  42075. }
  42076. }
  42077. /*
  42078. N2. Any remaining neutrals take the embedding direction.
  42079. */
  42080. for (i = 0; i < strLength; ++i) {
  42081. if (types[i] === 'ON') {
  42082. types[i] = e;
  42083. }
  42084. }
  42085. /*
  42086. I1. For all characters with an even (left-to-right) embedding direction,
  42087. those of type R go up one level and those of type AN or EN go up two
  42088. levels.
  42089. I2. For all characters with an odd (right-to-left) embedding direction,
  42090. those of type L, EN or AN go up one level.
  42091. */
  42092. for (i = 0; i < strLength; ++i) {
  42093. t = types[i];
  42094. if (isEven(levels[i])) {
  42095. if (t === 'R') {
  42096. levels[i] += 1;
  42097. } else if (t === 'AN' || t === 'EN') {
  42098. levels[i] += 2;
  42099. }
  42100. } else { // isOdd
  42101. if (t === 'L' || t === 'AN' || t === 'EN') {
  42102. levels[i] += 1;
  42103. }
  42104. }
  42105. }
  42106. /*
  42107. L1. On each line, reset the embedding level of the following characters to
  42108. the paragraph embedding level:
  42109. segment separators,
  42110. paragraph separators,
  42111. any sequence of whitespace characters preceding a segment separator or
  42112. paragraph separator, and any sequence of white space characters at the end
  42113. of the line.
  42114. */
  42115. // don't bother as text is only single line
  42116. /*
  42117. L2. From the highest level found in the text to the lowest odd level on
  42118. each line, reverse any contiguous sequence of characters that are at that
  42119. level or higher.
  42120. */
  42121. // find highest level & lowest odd level
  42122. var highestLevel = -1;
  42123. var lowestOddLevel = 99;
  42124. var level;
  42125. for (i = 0, ii = levels.length; i < ii; ++i) {
  42126. level = levels[i];
  42127. if (highestLevel < level) {
  42128. highestLevel = level;
  42129. }
  42130. if (lowestOddLevel > level && isOdd(level)) {
  42131. lowestOddLevel = level;
  42132. }
  42133. }
  42134. // now reverse between those limits
  42135. for (level = highestLevel; level >= lowestOddLevel; --level) {
  42136. // find segments to reverse
  42137. var start = -1;
  42138. for (i = 0, ii = levels.length; i < ii; ++i) {
  42139. if (levels[i] < level) {
  42140. if (start >= 0) {
  42141. reverseValues(chars, start, i);
  42142. start = -1;
  42143. }
  42144. } else if (start < 0) {
  42145. start = i;
  42146. }
  42147. }
  42148. if (start >= 0) {
  42149. reverseValues(chars, start, levels.length);
  42150. }
  42151. }
  42152. /*
  42153. L3. Combining marks applied to a right-to-left base character will at this
  42154. point precede their base character. If the rendering engine expects them to
  42155. follow the base characters in the final display process, then the ordering
  42156. of the marks and the base character must be reversed.
  42157. */
  42158. // don't bother for now
  42159. /*
  42160. L4. A character that possesses the mirrored property as specified by
  42161. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  42162. directionality of that character is R.
  42163. */
  42164. // don't mirror as characters are already mirrored in the pdf
  42165. // Finally, return string
  42166. var result = '';
  42167. for (i = 0, ii = chars.length; i < ii; ++i) {
  42168. var ch = chars[i];
  42169. if (ch !== '<' && ch !== '>') {
  42170. result += ch;
  42171. }
  42172. }
  42173. return createBidiText(result, isLTR);
  42174. }
  42175. return bidi;
  42176. })();
  42177. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  42178. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  42179. /* Copyright 2014 Opera Software ASA
  42180. *
  42181. * Licensed under the Apache License, Version 2.0 (the "License");
  42182. * you may not use this file except in compliance with the License.
  42183. * You may obtain a copy of the License at
  42184. *
  42185. * http://www.apache.org/licenses/LICENSE-2.0
  42186. *
  42187. * Unless required by applicable law or agreed to in writing, software
  42188. * distributed under the License is distributed on an "AS IS" BASIS,
  42189. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  42190. * See the License for the specific language governing permissions and
  42191. * limitations under the License.
  42192. *
  42193. *
  42194. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  42195. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  42196. */
  42197. /* globals Uint32ArrayView */
  42198. 'use strict';
  42199. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  42200. // Workaround for missing math precison in JS.
  42201. var MASK_HIGH = 0xffff0000;
  42202. var MASK_LOW = 0xffff;
  42203. function MurmurHash3_64 (seed) {
  42204. var SEED = 0xc3d2e1f0;
  42205. this.h1 = seed ? seed & 0xffffffff : SEED;
  42206. this.h2 = seed ? seed & 0xffffffff : SEED;
  42207. }
  42208. var alwaysUseUint32ArrayView = false;
  42209. // old webkits have issues with non-aligned arrays
  42210. try {
  42211. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  42212. } catch (e) {
  42213. alwaysUseUint32ArrayView = true;
  42214. }
  42215. MurmurHash3_64.prototype = {
  42216. update: function MurmurHash3_64_update(input) {
  42217. var useUint32ArrayView = alwaysUseUint32ArrayView;
  42218. var i;
  42219. if (typeof input === 'string') {
  42220. var data = new Uint8Array(input.length * 2);
  42221. var length = 0;
  42222. for (i = 0; i < input.length; i++) {
  42223. var code = input.charCodeAt(i);
  42224. if (code <= 0xff) {
  42225. data[length++] = code;
  42226. }
  42227. else {
  42228. data[length++] = code >>> 8;
  42229. data[length++] = code & 0xff;
  42230. }
  42231. }
  42232. } else if (input instanceof Uint8Array) {
  42233. data = input;
  42234. length = data.length;
  42235. } else if (typeof input === 'object' && ('length' in input)) {
  42236. // processing regular arrays as well, e.g. for IE9
  42237. data = input;
  42238. length = data.length;
  42239. useUint32ArrayView = true;
  42240. } else {
  42241. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  42242. 'Input must be a string or array.');
  42243. }
  42244. var blockCounts = length >> 2;
  42245. var tailLength = length - blockCounts * 4;
  42246. // we don't care about endianness here
  42247. var dataUint32 = useUint32ArrayView ?
  42248. new Uint32ArrayView(data, blockCounts) :
  42249. new Uint32Array(data.buffer, 0, blockCounts);
  42250. var k1 = 0;
  42251. var k2 = 0;
  42252. var h1 = this.h1;
  42253. var h2 = this.h2;
  42254. var C1 = 0xcc9e2d51;
  42255. var C2 = 0x1b873593;
  42256. var C1_LOW = C1 & MASK_LOW;
  42257. var C2_LOW = C2 & MASK_LOW;
  42258. for (i = 0; i < blockCounts; i++) {
  42259. if (i & 1) {
  42260. k1 = dataUint32[i];
  42261. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42262. k1 = k1 << 15 | k1 >>> 17;
  42263. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42264. h1 ^= k1;
  42265. h1 = h1 << 13 | h1 >>> 19;
  42266. h1 = h1 * 5 + 0xe6546b64;
  42267. } else {
  42268. k2 = dataUint32[i];
  42269. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  42270. k2 = k2 << 15 | k2 >>> 17;
  42271. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  42272. h2 ^= k2;
  42273. h2 = h2 << 13 | h2 >>> 19;
  42274. h2 = h2 * 5 + 0xe6546b64;
  42275. }
  42276. }
  42277. k1 = 0;
  42278. switch (tailLength) {
  42279. case 3:
  42280. k1 ^= data[blockCounts * 4 + 2] << 16;
  42281. /* falls through */
  42282. case 2:
  42283. k1 ^= data[blockCounts * 4 + 1] << 8;
  42284. /* falls through */
  42285. case 1:
  42286. k1 ^= data[blockCounts * 4];
  42287. /* falls through */
  42288. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42289. k1 = k1 << 15 | k1 >>> 17;
  42290. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42291. if (blockCounts & 1) {
  42292. h1 ^= k1;
  42293. } else {
  42294. h2 ^= k1;
  42295. }
  42296. }
  42297. this.h1 = h1;
  42298. this.h2 = h2;
  42299. return this;
  42300. },
  42301. hexdigest: function MurmurHash3_64_hexdigest () {
  42302. var h1 = this.h1;
  42303. var h2 = this.h2;
  42304. h1 ^= h2 >>> 1;
  42305. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  42306. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  42307. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  42308. h1 ^= h2 >>> 1;
  42309. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  42310. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  42311. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  42312. h1 ^= h2 >>> 1;
  42313. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  42314. var hex = (arr[i] >>> 0).toString(16);
  42315. while (hex.length < 8) {
  42316. hex = '0' + hex;
  42317. }
  42318. str += hex;
  42319. }
  42320. return str;
  42321. }
  42322. };
  42323. return MurmurHash3_64;
  42324. })();
  42325. }).call((typeof window === 'undefined') ? this : window);
  42326. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  42327. // workerSrc is not set -- using last script url to define default location
  42328. PDFJS.workerSrc = (function () {
  42329. 'use strict';
  42330. var scriptTagContainer = document.body ||
  42331. document.getElementsByTagName('head')[0];
  42332. var pdfjsSrc = scriptTagContainer.lastChild.src;
  42333. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  42334. })();
  42335. }