pdf.combined.js 1.3 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508
  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.596';
  24. PDFJS.build = '179bb2e';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) === '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. return true;
  319. default:
  320. return false;
  321. }
  322. }
  323. PDFJS.isValidUrl = isValidUrl;
  324. function shadow(obj, prop, value) {
  325. Object.defineProperty(obj, prop, { value: value,
  326. enumerable: true,
  327. configurable: true,
  328. writable: false });
  329. return value;
  330. }
  331. var PasswordResponses = PDFJS.PasswordResponses = {
  332. NEED_PASSWORD: 1,
  333. INCORRECT_PASSWORD: 2
  334. };
  335. var PasswordException = (function PasswordExceptionClosure() {
  336. function PasswordException(msg, code) {
  337. this.name = 'PasswordException';
  338. this.message = msg;
  339. this.code = code;
  340. }
  341. PasswordException.prototype = new Error();
  342. PasswordException.constructor = PasswordException;
  343. return PasswordException;
  344. })();
  345. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  346. function UnknownErrorException(msg, details) {
  347. this.name = 'UnknownErrorException';
  348. this.message = msg;
  349. this.details = details;
  350. }
  351. UnknownErrorException.prototype = new Error();
  352. UnknownErrorException.constructor = UnknownErrorException;
  353. return UnknownErrorException;
  354. })();
  355. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  356. function InvalidPDFException(msg) {
  357. this.name = 'InvalidPDFException';
  358. this.message = msg;
  359. }
  360. InvalidPDFException.prototype = new Error();
  361. InvalidPDFException.constructor = InvalidPDFException;
  362. return InvalidPDFException;
  363. })();
  364. var MissingPDFException = (function MissingPDFExceptionClosure() {
  365. function MissingPDFException(msg) {
  366. this.name = 'MissingPDFException';
  367. this.message = msg;
  368. }
  369. MissingPDFException.prototype = new Error();
  370. MissingPDFException.constructor = MissingPDFException;
  371. return MissingPDFException;
  372. })();
  373. var NotImplementedException = (function NotImplementedExceptionClosure() {
  374. function NotImplementedException(msg) {
  375. this.message = msg;
  376. }
  377. NotImplementedException.prototype = new Error();
  378. NotImplementedException.prototype.name = 'NotImplementedException';
  379. NotImplementedException.constructor = NotImplementedException;
  380. return NotImplementedException;
  381. })();
  382. var MissingDataException = (function MissingDataExceptionClosure() {
  383. function MissingDataException(begin, end) {
  384. this.begin = begin;
  385. this.end = end;
  386. this.message = 'Missing data [' + begin + ', ' + end + ')';
  387. }
  388. MissingDataException.prototype = new Error();
  389. MissingDataException.prototype.name = 'MissingDataException';
  390. MissingDataException.constructor = MissingDataException;
  391. return MissingDataException;
  392. })();
  393. var XRefParseException = (function XRefParseExceptionClosure() {
  394. function XRefParseException(msg) {
  395. this.message = msg;
  396. }
  397. XRefParseException.prototype = new Error();
  398. XRefParseException.prototype.name = 'XRefParseException';
  399. XRefParseException.constructor = XRefParseException;
  400. return XRefParseException;
  401. })();
  402. function bytesToString(bytes) {
  403. var length = bytes.length;
  404. var MAX_ARGUMENT_COUNT = 8192;
  405. if (length < MAX_ARGUMENT_COUNT) {
  406. return String.fromCharCode.apply(null, bytes);
  407. }
  408. var strBuf = [];
  409. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  410. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  411. var chunk = bytes.subarray(i, chunkEnd);
  412. strBuf.push(String.fromCharCode.apply(null, chunk));
  413. }
  414. return strBuf.join('');
  415. }
  416. function stringToArray(str) {
  417. var length = str.length;
  418. var array = new Uint16Array(length);
  419. for (var i = 0; i < length; ++i) {
  420. array[i] = str.charCodeAt(i);
  421. }
  422. return array;
  423. }
  424. function stringToBytes(str) {
  425. var length = str.length;
  426. var bytes = new Uint8Array(length);
  427. for (var i = 0; i < length; ++i) {
  428. bytes[i] = str.charCodeAt(i) & 0xFF;
  429. }
  430. return bytes;
  431. }
  432. function string32(value) {
  433. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  434. (value >> 8) & 0xff, value & 0xff);
  435. }
  436. function log2(x) {
  437. var n = 1, i = 0;
  438. while (x > n) {
  439. n <<= 1;
  440. i++;
  441. }
  442. return i;
  443. }
  444. function readInt8(data, start) {
  445. return (data[start] << 24) >> 24;
  446. }
  447. function readUint16(data, offset) {
  448. return (data[offset] << 8) | data[offset + 1];
  449. }
  450. function readUint32(data, offset) {
  451. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  452. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  453. }
  454. // Lazy test the endianness of the platform
  455. // NOTE: This will be 'true' for simulated TypedArrays
  456. function isLittleEndian() {
  457. var buffer8 = new Uint8Array(2);
  458. buffer8[0] = 1;
  459. var buffer16 = new Uint16Array(buffer8.buffer);
  460. return (buffer16[0] === 1);
  461. }
  462. Object.defineProperty(PDFJS, 'isLittleEndian', {
  463. configurable: true,
  464. get: function PDFJS_isLittleEndian() {
  465. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  466. }
  467. });
  468. // Lazy test if the userAgant support CanvasTypedArrays
  469. function hasCanvasTypedArrays() {
  470. var canvas = document.createElement('canvas');
  471. canvas.width = canvas.height = 1;
  472. var ctx = canvas.getContext('2d');
  473. var imageData = ctx.createImageData(1, 1);
  474. return (typeof imageData.data.buffer !== 'undefined');
  475. }
  476. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  477. configurable: true,
  478. get: function PDFJS_hasCanvasTypedArrays() {
  479. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  480. }
  481. });
  482. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  483. function Uint32ArrayView(buffer, length) {
  484. this.buffer = buffer;
  485. this.byteLength = buffer.length;
  486. this.length = length === undefined ? (this.byteLength >> 2) : length;
  487. ensureUint32ArrayViewProps(this.length);
  488. }
  489. Uint32ArrayView.prototype = Object.create(null);
  490. var uint32ArrayViewSetters = 0;
  491. function createUint32ArrayProp(index) {
  492. return {
  493. get: function () {
  494. var buffer = this.buffer, offset = index << 2;
  495. return (buffer[offset] | (buffer[offset + 1] << 8) |
  496. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  497. },
  498. set: function (value) {
  499. var buffer = this.buffer, offset = index << 2;
  500. buffer[offset] = value & 255;
  501. buffer[offset + 1] = (value >> 8) & 255;
  502. buffer[offset + 2] = (value >> 16) & 255;
  503. buffer[offset + 3] = (value >>> 24) & 255;
  504. }
  505. };
  506. }
  507. function ensureUint32ArrayViewProps(length) {
  508. while (uint32ArrayViewSetters < length) {
  509. Object.defineProperty(Uint32ArrayView.prototype,
  510. uint32ArrayViewSetters,
  511. createUint32ArrayProp(uint32ArrayViewSetters));
  512. uint32ArrayViewSetters++;
  513. }
  514. }
  515. return Uint32ArrayView;
  516. })();
  517. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  518. var Util = PDFJS.Util = (function UtilClosure() {
  519. function Util() {}
  520. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  521. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  522. // creating many intermediate strings.
  523. Util.makeCssRgb = function Util_makeCssRgb(rgb) {
  524. rgbBuf[1] = rgb[0];
  525. rgbBuf[3] = rgb[1];
  526. rgbBuf[5] = rgb[2];
  527. return rgbBuf.join('');
  528. };
  529. // Concatenates two transformation matrices together and returns the result.
  530. Util.transform = function Util_transform(m1, m2) {
  531. return [
  532. m1[0] * m2[0] + m1[2] * m2[1],
  533. m1[1] * m2[0] + m1[3] * m2[1],
  534. m1[0] * m2[2] + m1[2] * m2[3],
  535. m1[1] * m2[2] + m1[3] * m2[3],
  536. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  537. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  538. ];
  539. };
  540. // For 2d affine transforms
  541. Util.applyTransform = function Util_applyTransform(p, m) {
  542. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  543. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  544. return [xt, yt];
  545. };
  546. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  547. var d = m[0] * m[3] - m[1] * m[2];
  548. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  549. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  550. return [xt, yt];
  551. };
  552. // Applies the transform to the rectangle and finds the minimum axially
  553. // aligned bounding box.
  554. Util.getAxialAlignedBoundingBox =
  555. function Util_getAxialAlignedBoundingBox(r, m) {
  556. var p1 = Util.applyTransform(r, m);
  557. var p2 = Util.applyTransform(r.slice(2, 4), m);
  558. var p3 = Util.applyTransform([r[0], r[3]], m);
  559. var p4 = Util.applyTransform([r[2], r[1]], m);
  560. return [
  561. Math.min(p1[0], p2[0], p3[0], p4[0]),
  562. Math.min(p1[1], p2[1], p3[1], p4[1]),
  563. Math.max(p1[0], p2[0], p3[0], p4[0]),
  564. Math.max(p1[1], p2[1], p3[1], p4[1])
  565. ];
  566. };
  567. Util.inverseTransform = function Util_inverseTransform(m) {
  568. var d = m[0] * m[3] - m[1] * m[2];
  569. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  570. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  571. };
  572. // Apply a generic 3d matrix M on a 3-vector v:
  573. // | a b c | | X |
  574. // | d e f | x | Y |
  575. // | g h i | | Z |
  576. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  577. // with v as [X,Y,Z]
  578. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  579. return [
  580. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  581. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  582. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  583. ];
  584. };
  585. // This calculation uses Singular Value Decomposition.
  586. // The SVD can be represented with formula A = USV. We are interested in the
  587. // matrix S here because it represents the scale values.
  588. Util.singularValueDecompose2dScale =
  589. function Util_singularValueDecompose2dScale(m) {
  590. var transpose = [m[0], m[2], m[1], m[3]];
  591. // Multiply matrix m with its transpose.
  592. var a = m[0] * transpose[0] + m[1] * transpose[2];
  593. var b = m[0] * transpose[1] + m[1] * transpose[3];
  594. var c = m[2] * transpose[0] + m[3] * transpose[2];
  595. var d = m[2] * transpose[1] + m[3] * transpose[3];
  596. // Solve the second degree polynomial to get roots.
  597. var first = (a + d) / 2;
  598. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  599. var sx = first + second || 1;
  600. var sy = first - second || 1;
  601. // Scale values are the square roots of the eigenvalues.
  602. return [Math.sqrt(sx), Math.sqrt(sy)];
  603. };
  604. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  605. // For coordinate systems whose origin lies in the bottom-left, this
  606. // means normalization to (BL,TR) ordering. For systems with origin in the
  607. // top-left, this means (TL,BR) ordering.
  608. Util.normalizeRect = function Util_normalizeRect(rect) {
  609. var r = rect.slice(0); // clone rect
  610. if (rect[0] > rect[2]) {
  611. r[0] = rect[2];
  612. r[2] = rect[0];
  613. }
  614. if (rect[1] > rect[3]) {
  615. r[1] = rect[3];
  616. r[3] = rect[1];
  617. }
  618. return r;
  619. };
  620. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  621. // intersection of rect1 and rect2. If no intersection, returns 'false'
  622. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  623. Util.intersect = function Util_intersect(rect1, rect2) {
  624. function compare(a, b) {
  625. return a - b;
  626. }
  627. // Order points along the axes
  628. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  629. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  630. result = [];
  631. rect1 = Util.normalizeRect(rect1);
  632. rect2 = Util.normalizeRect(rect2);
  633. // X: first and second points belong to different rectangles?
  634. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  635. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  636. // Intersection must be between second and third points
  637. result[0] = orderedX[1];
  638. result[2] = orderedX[2];
  639. } else {
  640. return false;
  641. }
  642. // Y: first and second points belong to different rectangles?
  643. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  644. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  645. // Intersection must be between second and third points
  646. result[1] = orderedY[1];
  647. result[3] = orderedY[2];
  648. } else {
  649. return false;
  650. }
  651. return result;
  652. };
  653. Util.sign = function Util_sign(num) {
  654. return num < 0 ? -1 : 1;
  655. };
  656. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  657. Array.prototype.push.apply(arr1, arr2);
  658. };
  659. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  660. Array.prototype.unshift.apply(arr1, arr2);
  661. };
  662. Util.extendObj = function extendObj(obj1, obj2) {
  663. for (var key in obj2) {
  664. obj1[key] = obj2[key];
  665. }
  666. };
  667. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  668. name) {
  669. while (dict && !dict.has(name)) {
  670. dict = dict.get('Parent');
  671. }
  672. if (!dict) {
  673. return null;
  674. }
  675. return dict.get(name);
  676. };
  677. Util.inherit = function Util_inherit(sub, base, prototype) {
  678. sub.prototype = Object.create(base.prototype);
  679. sub.prototype.constructor = sub;
  680. for (var prop in prototype) {
  681. sub.prototype[prop] = prototype[prop];
  682. }
  683. };
  684. Util.loadScript = function Util_loadScript(src, callback) {
  685. var script = document.createElement('script');
  686. var loaded = false;
  687. script.setAttribute('src', src);
  688. if (callback) {
  689. script.onload = function() {
  690. if (!loaded) {
  691. callback();
  692. }
  693. loaded = true;
  694. };
  695. }
  696. document.getElementsByTagName('head')[0].appendChild(script);
  697. };
  698. return Util;
  699. })();
  700. /**
  701. * PDF page viewport created based on scale, rotation and offset.
  702. * @class
  703. * @alias PDFJS.PageViewport
  704. */
  705. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  706. /**
  707. * @constructor
  708. * @private
  709. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  710. * @param scale {number} scale of the viewport.
  711. * @param rotation {number} rotations of the viewport in degrees.
  712. * @param offsetX {number} offset X
  713. * @param offsetY {number} offset Y
  714. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  715. */
  716. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  717. this.viewBox = viewBox;
  718. this.scale = scale;
  719. this.rotation = rotation;
  720. this.offsetX = offsetX;
  721. this.offsetY = offsetY;
  722. // creating transform to convert pdf coordinate system to the normal
  723. // canvas like coordinates taking in account scale and rotation
  724. var centerX = (viewBox[2] + viewBox[0]) / 2;
  725. var centerY = (viewBox[3] + viewBox[1]) / 2;
  726. var rotateA, rotateB, rotateC, rotateD;
  727. rotation = rotation % 360;
  728. rotation = rotation < 0 ? rotation + 360 : rotation;
  729. switch (rotation) {
  730. case 180:
  731. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  732. break;
  733. case 90:
  734. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  735. break;
  736. case 270:
  737. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  738. break;
  739. //case 0:
  740. default:
  741. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  742. break;
  743. }
  744. if (dontFlip) {
  745. rotateC = -rotateC; rotateD = -rotateD;
  746. }
  747. var offsetCanvasX, offsetCanvasY;
  748. var width, height;
  749. if (rotateA === 0) {
  750. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  751. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  752. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  753. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  754. } else {
  755. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  756. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  757. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  758. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  759. }
  760. // creating transform for the following operations:
  761. // translate(-centerX, -centerY), rotate and flip vertically,
  762. // scale, and translate(offsetCanvasX, offsetCanvasY)
  763. this.transform = [
  764. rotateA * scale,
  765. rotateB * scale,
  766. rotateC * scale,
  767. rotateD * scale,
  768. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  769. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  770. ];
  771. this.width = width;
  772. this.height = height;
  773. this.fontScale = scale;
  774. }
  775. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  776. /**
  777. * Clones viewport with additional properties.
  778. * @param args {Object} (optional) If specified, may contain the 'scale' or
  779. * 'rotation' properties to override the corresponding properties in
  780. * the cloned viewport.
  781. * @returns {PDFJS.PageViewport} Cloned viewport.
  782. */
  783. clone: function PageViewPort_clone(args) {
  784. args = args || {};
  785. var scale = 'scale' in args ? args.scale : this.scale;
  786. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  787. return new PageViewport(this.viewBox.slice(), scale, rotation,
  788. this.offsetX, this.offsetY, args.dontFlip);
  789. },
  790. /**
  791. * Converts PDF point to the viewport coordinates. For examples, useful for
  792. * converting PDF location into canvas pixel coordinates.
  793. * @param x {number} X coordinate.
  794. * @param y {number} Y coordinate.
  795. * @returns {Object} Object that contains 'x' and 'y' properties of the
  796. * point in the viewport coordinate space.
  797. * @see {@link convertToPdfPoint}
  798. * @see {@link convertToViewportRectangle}
  799. */
  800. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  801. return Util.applyTransform([x, y], this.transform);
  802. },
  803. /**
  804. * Converts PDF rectangle to the viewport coordinates.
  805. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  806. * @returns {Array} Contains corresponding coordinates of the rectangle
  807. * in the viewport coordinate space.
  808. * @see {@link convertToViewportPoint}
  809. */
  810. convertToViewportRectangle:
  811. function PageViewport_convertToViewportRectangle(rect) {
  812. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  813. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  814. return [tl[0], tl[1], br[0], br[1]];
  815. },
  816. /**
  817. * Converts viewport coordinates to the PDF location. For examples, useful
  818. * for converting canvas pixel location into PDF one.
  819. * @param x {number} X coordinate.
  820. * @param y {number} Y coordinate.
  821. * @returns {Object} Object that contains 'x' and 'y' properties of the
  822. * point in the PDF coordinate space.
  823. * @see {@link convertToViewportPoint}
  824. */
  825. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  826. return Util.applyInverseTransform([x, y], this.transform);
  827. }
  828. };
  829. return PageViewport;
  830. })();
  831. var PDFStringTranslateTable = [
  832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  833. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  834. 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,
  835. 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,
  836. 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,
  837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  838. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  839. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  840. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  841. ];
  842. function stringToPDFString(str) {
  843. var i, n = str.length, strBuf = [];
  844. if (str[0] === '\xFE' && str[1] === '\xFF') {
  845. // UTF16BE BOM
  846. for (i = 2; i < n; i += 2) {
  847. strBuf.push(String.fromCharCode(
  848. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  849. }
  850. } else {
  851. for (i = 0; i < n; ++i) {
  852. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  853. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  854. }
  855. }
  856. return strBuf.join('');
  857. }
  858. function stringToUTF8String(str) {
  859. return decodeURIComponent(escape(str));
  860. }
  861. function isEmptyObj(obj) {
  862. for (var key in obj) {
  863. return false;
  864. }
  865. return true;
  866. }
  867. function isBool(v) {
  868. return typeof v === 'boolean';
  869. }
  870. function isInt(v) {
  871. return typeof v === 'number' && ((v | 0) === v);
  872. }
  873. function isNum(v) {
  874. return typeof v === 'number';
  875. }
  876. function isString(v) {
  877. return typeof v === 'string';
  878. }
  879. function isNull(v) {
  880. return v === null;
  881. }
  882. function isName(v) {
  883. return v instanceof Name;
  884. }
  885. function isCmd(v, cmd) {
  886. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  887. }
  888. function isDict(v, type) {
  889. if (!(v instanceof Dict)) {
  890. return false;
  891. }
  892. if (!type) {
  893. return true;
  894. }
  895. var dictType = v.get('Type');
  896. return isName(dictType) && dictType.name === type;
  897. }
  898. function isArray(v) {
  899. return v instanceof Array;
  900. }
  901. function isStream(v) {
  902. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  903. }
  904. function isArrayBuffer(v) {
  905. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  906. }
  907. function isRef(v) {
  908. return v instanceof Ref;
  909. }
  910. /**
  911. * Promise Capability object.
  912. *
  913. * @typedef {Object} PromiseCapability
  914. * @property {Promise} promise - A promise object.
  915. * @property {function} resolve - Fullfills the promise.
  916. * @property {function} reject - Rejects the promise.
  917. */
  918. /**
  919. * Creates a promise capability object.
  920. * @alias PDFJS.createPromiseCapability
  921. *
  922. * @return {PromiseCapability} A capability object contains:
  923. * - a Promise, resolve and reject methods.
  924. */
  925. function createPromiseCapability() {
  926. var capability = {};
  927. capability.promise = new Promise(function (resolve, reject) {
  928. capability.resolve = resolve;
  929. capability.reject = reject;
  930. });
  931. return capability;
  932. }
  933. PDFJS.createPromiseCapability = createPromiseCapability;
  934. /**
  935. * Polyfill for Promises:
  936. * The following promise implementation tries to generally implement the
  937. * Promise/A+ spec. Some notable differences from other promise libaries are:
  938. * - There currently isn't a seperate deferred and promise object.
  939. * - Unhandled rejections eventually show an error if they aren't handled.
  940. *
  941. * Based off of the work in:
  942. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  943. */
  944. (function PromiseClosure() {
  945. if (globalScope.Promise) {
  946. // Promises existing in the DOM/Worker, checking presence of all/resolve
  947. if (typeof globalScope.Promise.all !== 'function') {
  948. globalScope.Promise.all = function (iterable) {
  949. var count = 0, results = [], resolve, reject;
  950. var promise = new globalScope.Promise(function (resolve_, reject_) {
  951. resolve = resolve_;
  952. reject = reject_;
  953. });
  954. iterable.forEach(function (p, i) {
  955. count++;
  956. p.then(function (result) {
  957. results[i] = result;
  958. count--;
  959. if (count === 0) {
  960. resolve(results);
  961. }
  962. }, reject);
  963. });
  964. if (count === 0) {
  965. resolve(results);
  966. }
  967. return promise;
  968. };
  969. }
  970. if (typeof globalScope.Promise.resolve !== 'function') {
  971. globalScope.Promise.resolve = function (value) {
  972. return new globalScope.Promise(function (resolve) { resolve(value); });
  973. };
  974. }
  975. if (typeof globalScope.Promise.reject !== 'function') {
  976. globalScope.Promise.reject = function (reason) {
  977. return new globalScope.Promise(function (resolve, reject) {
  978. reject(reason);
  979. });
  980. };
  981. }
  982. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  983. globalScope.Promise.prototype.catch = function (onReject) {
  984. return globalScope.Promise.prototype.then(undefined, onReject);
  985. };
  986. }
  987. return;
  988. }
  989. var STATUS_PENDING = 0;
  990. var STATUS_RESOLVED = 1;
  991. var STATUS_REJECTED = 2;
  992. // In an attempt to avoid silent exceptions, unhandled rejections are
  993. // tracked and if they aren't handled in a certain amount of time an
  994. // error is logged.
  995. var REJECTION_TIMEOUT = 500;
  996. var HandlerManager = {
  997. handlers: [],
  998. running: false,
  999. unhandledRejections: [],
  1000. pendingRejectionCheck: false,
  1001. scheduleHandlers: function scheduleHandlers(promise) {
  1002. if (promise._status === STATUS_PENDING) {
  1003. return;
  1004. }
  1005. this.handlers = this.handlers.concat(promise._handlers);
  1006. promise._handlers = [];
  1007. if (this.running) {
  1008. return;
  1009. }
  1010. this.running = true;
  1011. setTimeout(this.runHandlers.bind(this), 0);
  1012. },
  1013. runHandlers: function runHandlers() {
  1014. var RUN_TIMEOUT = 1; // ms
  1015. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1016. while (this.handlers.length > 0) {
  1017. var handler = this.handlers.shift();
  1018. var nextStatus = handler.thisPromise._status;
  1019. var nextValue = handler.thisPromise._value;
  1020. try {
  1021. if (nextStatus === STATUS_RESOLVED) {
  1022. if (typeof handler.onResolve === 'function') {
  1023. nextValue = handler.onResolve(nextValue);
  1024. }
  1025. } else if (typeof handler.onReject === 'function') {
  1026. nextValue = handler.onReject(nextValue);
  1027. nextStatus = STATUS_RESOLVED;
  1028. if (handler.thisPromise._unhandledRejection) {
  1029. this.removeUnhandeledRejection(handler.thisPromise);
  1030. }
  1031. }
  1032. } catch (ex) {
  1033. nextStatus = STATUS_REJECTED;
  1034. nextValue = ex;
  1035. }
  1036. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1037. if (Date.now() >= timeoutAt) {
  1038. break;
  1039. }
  1040. }
  1041. if (this.handlers.length > 0) {
  1042. setTimeout(this.runHandlers.bind(this), 0);
  1043. return;
  1044. }
  1045. this.running = false;
  1046. },
  1047. addUnhandledRejection: function addUnhandledRejection(promise) {
  1048. this.unhandledRejections.push({
  1049. promise: promise,
  1050. time: Date.now()
  1051. });
  1052. this.scheduleRejectionCheck();
  1053. },
  1054. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1055. promise._unhandledRejection = false;
  1056. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1057. if (this.unhandledRejections[i].promise === promise) {
  1058. this.unhandledRejections.splice(i);
  1059. i--;
  1060. }
  1061. }
  1062. },
  1063. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1064. if (this.pendingRejectionCheck) {
  1065. return;
  1066. }
  1067. this.pendingRejectionCheck = true;
  1068. setTimeout(function rejectionCheck() {
  1069. this.pendingRejectionCheck = false;
  1070. var now = Date.now();
  1071. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1072. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1073. var unhandled = this.unhandledRejections[i].promise._value;
  1074. var msg = 'Unhandled rejection: ' + unhandled;
  1075. if (unhandled.stack) {
  1076. msg += '\n' + unhandled.stack;
  1077. }
  1078. warn(msg);
  1079. this.unhandledRejections.splice(i);
  1080. i--;
  1081. }
  1082. }
  1083. if (this.unhandledRejections.length) {
  1084. this.scheduleRejectionCheck();
  1085. }
  1086. }.bind(this), REJECTION_TIMEOUT);
  1087. }
  1088. };
  1089. function Promise(resolver) {
  1090. this._status = STATUS_PENDING;
  1091. this._handlers = [];
  1092. try {
  1093. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1094. } catch (e) {
  1095. this._reject(e);
  1096. }
  1097. }
  1098. /**
  1099. * Builds a promise that is resolved when all the passed in promises are
  1100. * resolved.
  1101. * @param {array} array of data and/or promises to wait for.
  1102. * @return {Promise} New dependant promise.
  1103. */
  1104. Promise.all = function Promise_all(promises) {
  1105. var resolveAll, rejectAll;
  1106. var deferred = new Promise(function (resolve, reject) {
  1107. resolveAll = resolve;
  1108. rejectAll = reject;
  1109. });
  1110. var unresolved = promises.length;
  1111. var results = [];
  1112. if (unresolved === 0) {
  1113. resolveAll(results);
  1114. return deferred;
  1115. }
  1116. function reject(reason) {
  1117. if (deferred._status === STATUS_REJECTED) {
  1118. return;
  1119. }
  1120. results = [];
  1121. rejectAll(reason);
  1122. }
  1123. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1124. var promise = promises[i];
  1125. var resolve = (function(i) {
  1126. return function(value) {
  1127. if (deferred._status === STATUS_REJECTED) {
  1128. return;
  1129. }
  1130. results[i] = value;
  1131. unresolved--;
  1132. if (unresolved === 0) {
  1133. resolveAll(results);
  1134. }
  1135. };
  1136. })(i);
  1137. if (Promise.isPromise(promise)) {
  1138. promise.then(resolve, reject);
  1139. } else {
  1140. resolve(promise);
  1141. }
  1142. }
  1143. return deferred;
  1144. };
  1145. /**
  1146. * Checks if the value is likely a promise (has a 'then' function).
  1147. * @return {boolean} true if value is thenable
  1148. */
  1149. Promise.isPromise = function Promise_isPromise(value) {
  1150. return value && typeof value.then === 'function';
  1151. };
  1152. /**
  1153. * Creates resolved promise
  1154. * @param value resolve value
  1155. * @returns {Promise}
  1156. */
  1157. Promise.resolve = function Promise_resolve(value) {
  1158. return new Promise(function (resolve) { resolve(value); });
  1159. };
  1160. /**
  1161. * Creates rejected promise
  1162. * @param reason rejection value
  1163. * @returns {Promise}
  1164. */
  1165. Promise.reject = function Promise_reject(reason) {
  1166. return new Promise(function (resolve, reject) { reject(reason); });
  1167. };
  1168. Promise.prototype = {
  1169. _status: null,
  1170. _value: null,
  1171. _handlers: null,
  1172. _unhandledRejection: null,
  1173. _updateStatus: function Promise__updateStatus(status, value) {
  1174. if (this._status === STATUS_RESOLVED ||
  1175. this._status === STATUS_REJECTED) {
  1176. return;
  1177. }
  1178. if (status === STATUS_RESOLVED &&
  1179. Promise.isPromise(value)) {
  1180. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1181. this._updateStatus.bind(this, STATUS_REJECTED));
  1182. return;
  1183. }
  1184. this._status = status;
  1185. this._value = value;
  1186. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1187. this._unhandledRejection = true;
  1188. HandlerManager.addUnhandledRejection(this);
  1189. }
  1190. HandlerManager.scheduleHandlers(this);
  1191. },
  1192. _resolve: function Promise_resolve(value) {
  1193. this._updateStatus(STATUS_RESOLVED, value);
  1194. },
  1195. _reject: function Promise_reject(reason) {
  1196. this._updateStatus(STATUS_REJECTED, reason);
  1197. },
  1198. then: function Promise_then(onResolve, onReject) {
  1199. var nextPromise = new Promise(function (resolve, reject) {
  1200. this.resolve = resolve;
  1201. this.reject = reject;
  1202. });
  1203. this._handlers.push({
  1204. thisPromise: this,
  1205. onResolve: onResolve,
  1206. onReject: onReject,
  1207. nextPromise: nextPromise
  1208. });
  1209. HandlerManager.scheduleHandlers(this);
  1210. return nextPromise;
  1211. },
  1212. catch: function Promise_catch(onReject) {
  1213. return this.then(undefined, onReject);
  1214. }
  1215. };
  1216. globalScope.Promise = Promise;
  1217. })();
  1218. var StatTimer = (function StatTimerClosure() {
  1219. function rpad(str, pad, length) {
  1220. while (str.length < length) {
  1221. str += pad;
  1222. }
  1223. return str;
  1224. }
  1225. function StatTimer() {
  1226. this.started = {};
  1227. this.times = [];
  1228. this.enabled = true;
  1229. }
  1230. StatTimer.prototype = {
  1231. time: function StatTimer_time(name) {
  1232. if (!this.enabled) {
  1233. return;
  1234. }
  1235. if (name in this.started) {
  1236. warn('Timer is already running for ' + name);
  1237. }
  1238. this.started[name] = Date.now();
  1239. },
  1240. timeEnd: function StatTimer_timeEnd(name) {
  1241. if (!this.enabled) {
  1242. return;
  1243. }
  1244. if (!(name in this.started)) {
  1245. warn('Timer has not been started for ' + name);
  1246. }
  1247. this.times.push({
  1248. 'name': name,
  1249. 'start': this.started[name],
  1250. 'end': Date.now()
  1251. });
  1252. // Remove timer from started so it can be called again.
  1253. delete this.started[name];
  1254. },
  1255. toString: function StatTimer_toString() {
  1256. var i, ii;
  1257. var times = this.times;
  1258. var out = '';
  1259. // Find the longest name for padding purposes.
  1260. var longest = 0;
  1261. for (i = 0, ii = times.length; i < ii; ++i) {
  1262. var name = times[i]['name'];
  1263. if (name.length > longest) {
  1264. longest = name.length;
  1265. }
  1266. }
  1267. for (i = 0, ii = times.length; i < ii; ++i) {
  1268. var span = times[i];
  1269. var duration = span.end - span.start;
  1270. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1271. }
  1272. return out;
  1273. }
  1274. };
  1275. return StatTimer;
  1276. })();
  1277. PDFJS.createBlob = function createBlob(data, contentType) {
  1278. if (typeof Blob !== 'undefined') {
  1279. return new Blob([data], { type: contentType });
  1280. }
  1281. // Blob builder is deprecated in FF14 and removed in FF18.
  1282. var bb = new MozBlobBuilder();
  1283. bb.append(data);
  1284. return bb.getBlob(contentType);
  1285. };
  1286. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1287. // Blob/createObjectURL is not available, falling back to data schema.
  1288. var digits =
  1289. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1290. return function createObjectURL(data, contentType) {
  1291. if (!PDFJS.disableCreateObjectURL &&
  1292. typeof URL !== 'undefined' && URL.createObjectURL) {
  1293. var blob = PDFJS.createBlob(data, contentType);
  1294. return URL.createObjectURL(blob);
  1295. }
  1296. var buffer = 'data:' + contentType + ';base64,';
  1297. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1298. var b1 = data[i] & 0xFF;
  1299. var b2 = data[i + 1] & 0xFF;
  1300. var b3 = data[i + 2] & 0xFF;
  1301. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1302. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1303. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1304. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1305. }
  1306. return buffer;
  1307. };
  1308. })();
  1309. function MessageHandler(name, comObj) {
  1310. this.name = name;
  1311. this.comObj = comObj;
  1312. this.callbackIndex = 1;
  1313. this.postMessageTransfers = true;
  1314. var callbacksCapabilities = this.callbacksCapabilities = {};
  1315. var ah = this.actionHandler = {};
  1316. ah['console_log'] = [function ahConsoleLog(data) {
  1317. console.log.apply(console, data);
  1318. }];
  1319. ah['console_error'] = [function ahConsoleError(data) {
  1320. console.error.apply(console, data);
  1321. }];
  1322. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1323. UnsupportedManager.notify(data);
  1324. }];
  1325. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1326. var data = event.data;
  1327. if (data.isReply) {
  1328. var callbackId = data.callbackId;
  1329. if (data.callbackId in callbacksCapabilities) {
  1330. var callback = callbacksCapabilities[callbackId];
  1331. delete callbacksCapabilities[callbackId];
  1332. if ('error' in data) {
  1333. callback.reject(data.error);
  1334. } else {
  1335. callback.resolve(data.data);
  1336. }
  1337. } else {
  1338. error('Cannot resolve callback ' + callbackId);
  1339. }
  1340. } else if (data.action in ah) {
  1341. var action = ah[data.action];
  1342. if (data.callbackId) {
  1343. Promise.resolve().then(function () {
  1344. return action[0].call(action[1], data.data);
  1345. }).then(function (result) {
  1346. comObj.postMessage({
  1347. isReply: true,
  1348. callbackId: data.callbackId,
  1349. data: result
  1350. });
  1351. }, function (reason) {
  1352. comObj.postMessage({
  1353. isReply: true,
  1354. callbackId: data.callbackId,
  1355. error: reason
  1356. });
  1357. });
  1358. } else {
  1359. action[0].call(action[1], data.data);
  1360. }
  1361. } else {
  1362. error('Unknown action from worker: ' + data.action);
  1363. }
  1364. };
  1365. }
  1366. MessageHandler.prototype = {
  1367. on: function messageHandlerOn(actionName, handler, scope) {
  1368. var ah = this.actionHandler;
  1369. if (ah[actionName]) {
  1370. error('There is already an actionName called "' + actionName + '"');
  1371. }
  1372. ah[actionName] = [handler, scope];
  1373. },
  1374. /**
  1375. * Sends a message to the comObj to invoke the action with the supplied data.
  1376. * @param {String} actionName Action to call.
  1377. * @param {JSON} data JSON data to send.
  1378. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1379. */
  1380. send: function messageHandlerSend(actionName, data, transfers) {
  1381. var message = {
  1382. action: actionName,
  1383. data: data
  1384. };
  1385. this.postMessage(message, transfers);
  1386. },
  1387. /**
  1388. * Sends a message to the comObj to invoke the action with the supplied data.
  1389. * Expects that other side will callback with the response.
  1390. * @param {String} actionName Action to call.
  1391. * @param {JSON} data JSON data to send.
  1392. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1393. * @returns {Promise} Promise to be resolved with response data.
  1394. */
  1395. sendWithPromise:
  1396. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1397. var callbackId = this.callbackIndex++;
  1398. var message = {
  1399. action: actionName,
  1400. data: data,
  1401. callbackId: callbackId
  1402. };
  1403. var capability = createPromiseCapability();
  1404. this.callbacksCapabilities[callbackId] = capability;
  1405. try {
  1406. this.postMessage(message, transfers);
  1407. } catch (e) {
  1408. capability.reject(e);
  1409. }
  1410. return capability.promise;
  1411. },
  1412. /**
  1413. * Sends raw message to the comObj.
  1414. * @private
  1415. * @param message {Object} Raw message.
  1416. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1417. */
  1418. postMessage: function (message, transfers) {
  1419. if (transfers && this.postMessageTransfers) {
  1420. this.comObj.postMessage(message, transfers);
  1421. } else {
  1422. this.comObj.postMessage(message);
  1423. }
  1424. }
  1425. };
  1426. function loadJpegStream(id, imageUrl, objs) {
  1427. var img = new Image();
  1428. img.onload = (function loadJpegStream_onloadClosure() {
  1429. objs.resolve(id, img);
  1430. });
  1431. img.onerror = (function loadJpegStream_onerrorClosure() {
  1432. objs.resolve(id, null);
  1433. warn('Error during JPEG image loading');
  1434. });
  1435. img.src = imageUrl;
  1436. }
  1437. /**
  1438. * The maximum allowed image size in total pixels e.g. width * height. Images
  1439. * above this value will not be drawn. Use -1 for no limit.
  1440. * @var {number}
  1441. */
  1442. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1443. -1 : PDFJS.maxImageSize);
  1444. /**
  1445. * The url of where the predefined Adobe CMaps are located. Include trailing
  1446. * slash.
  1447. * @var {string}
  1448. */
  1449. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1450. /**
  1451. * Specifies if CMaps are binary packed.
  1452. * @var {boolean}
  1453. */
  1454. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1455. /*
  1456. * By default fonts are converted to OpenType fonts and loaded via font face
  1457. * rules. If disabled, the font will be rendered using a built in font renderer
  1458. * that constructs the glyphs with primitive path commands.
  1459. * @var {boolean}
  1460. */
  1461. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1462. false : PDFJS.disableFontFace);
  1463. /**
  1464. * Path for image resources, mainly for annotation icons. Include trailing
  1465. * slash.
  1466. * @var {string}
  1467. */
  1468. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1469. '' : PDFJS.imageResourcesPath);
  1470. /**
  1471. * Disable the web worker and run all code on the main thread. This will happen
  1472. * automatically if the browser doesn't support workers or sending typed arrays
  1473. * to workers.
  1474. * @var {boolean}
  1475. */
  1476. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1477. false : PDFJS.disableWorker);
  1478. /**
  1479. * Path and filename of the worker file. Required when the worker is enabled in
  1480. * development mode. If unspecified in the production build, the worker will be
  1481. * loaded based on the location of the pdf.js file.
  1482. * @var {string}
  1483. */
  1484. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1485. /**
  1486. * Disable range request loading of PDF files. When enabled and if the server
  1487. * supports partial content requests then the PDF will be fetched in chunks.
  1488. * Enabled (false) by default.
  1489. * @var {boolean}
  1490. */
  1491. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1492. false : PDFJS.disableRange);
  1493. /**
  1494. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1495. * will automatically keep fetching more data even if it isn't needed to display
  1496. * the current page. This default behavior can be disabled.
  1497. * @var {boolean}
  1498. */
  1499. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1500. false : PDFJS.disableAutoFetch);
  1501. /**
  1502. * Enables special hooks for debugging PDF.js.
  1503. * @var {boolean}
  1504. */
  1505. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1506. /**
  1507. * Enables transfer usage in postMessage for ArrayBuffers.
  1508. * @var {boolean}
  1509. */
  1510. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1511. true : PDFJS.postMessageTransfers);
  1512. /**
  1513. * Disables URL.createObjectURL usage.
  1514. * @var {boolean}
  1515. */
  1516. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1517. false : PDFJS.disableCreateObjectURL);
  1518. /**
  1519. * Disables WebGL usage.
  1520. * @var {boolean}
  1521. */
  1522. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1523. true : PDFJS.disableWebGL);
  1524. /**
  1525. * Enables CSS only zooming.
  1526. * @var {boolean}
  1527. */
  1528. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1529. false : PDFJS.useOnlyCssZoom);
  1530. /**
  1531. * Controls the logging level.
  1532. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1533. * - errors
  1534. * - warnings [default]
  1535. * - infos
  1536. * @var {number}
  1537. */
  1538. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1539. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1540. /**
  1541. * The maximum supported canvas size in total pixels e.g. width * height.
  1542. * The default value is 4096 * 4096. Use -1 for no limit.
  1543. * @var {number}
  1544. */
  1545. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1546. 16777216 : PDFJS.maxCanvasPixels);
  1547. /**
  1548. * Document initialization / loading parameters object.
  1549. *
  1550. * @typedef {Object} DocumentInitParameters
  1551. * @property {string} url - The URL of the PDF.
  1552. * @property {TypedArray} data - A typed array with PDF data.
  1553. * @property {Object} httpHeaders - Basic authentication headers.
  1554. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1555. * Access-Control requests should be made using credentials such as cookies
  1556. * or authorization headers. The default is false.
  1557. * @property {string} password - For decrypting password-protected PDFs.
  1558. * @property {TypedArray} initialData - A typed array with the first portion or
  1559. * all of the pdf data. Used by the extension since some data is already
  1560. * loaded before the switch to range requests.
  1561. */
  1562. /**
  1563. * @typedef {Object} PDFDocumentStats
  1564. * @property {Array} streamTypes - Used stream types in the document (an item
  1565. * is set to true if specific stream ID was used in the document).
  1566. * @property {Array} fontTypes - Used font type in the document (an item is set
  1567. * to true if specific font ID was used in the document).
  1568. */
  1569. /**
  1570. * This is the main entry point for loading a PDF and interacting with it.
  1571. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1572. * is used, which means it must follow the same origin rules that any XHR does
  1573. * e.g. No cross domain requests without CORS.
  1574. *
  1575. * @param {string|TypedArray|DocumentInitParameters} source Can be a url to
  1576. * where a PDF is located, a typed array (Uint8Array) already populated with
  1577. * data or parameter object.
  1578. *
  1579. * @param {Object} pdfDataRangeTransport is optional. It is used if you want
  1580. * to manually serve range requests for data in the PDF. See viewer.js for
  1581. * an example of pdfDataRangeTransport's interface.
  1582. *
  1583. * @param {function} passwordCallback is optional. It is used to request a
  1584. * password if wrong or no password was provided. The callback receives two
  1585. * parameters: function that needs to be called with new password and reason
  1586. * (see {PasswordResponses}).
  1587. *
  1588. * @return {Promise} A promise that is resolved with {@link PDFDocumentProxy}
  1589. * object.
  1590. */
  1591. PDFJS.getDocument = function getDocument(source,
  1592. pdfDataRangeTransport,
  1593. passwordCallback,
  1594. progressCallback) {
  1595. var workerInitializedCapability, workerReadyCapability, transport;
  1596. if (typeof source === 'string') {
  1597. source = { url: source };
  1598. } else if (isArrayBuffer(source)) {
  1599. source = { data: source };
  1600. } else if (typeof source !== 'object') {
  1601. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1602. 'string or a parameter object');
  1603. }
  1604. if (!source.url && !source.data) {
  1605. error('Invalid parameter array, need either .data or .url');
  1606. }
  1607. // copy/use all keys as is except 'url' -- full path is required
  1608. var params = {};
  1609. for (var key in source) {
  1610. if (key === 'url' && typeof window !== 'undefined') {
  1611. params[key] = combineUrl(window.location.href, source[key]);
  1612. continue;
  1613. }
  1614. params[key] = source[key];
  1615. }
  1616. workerInitializedCapability = createPromiseCapability();
  1617. workerReadyCapability = createPromiseCapability();
  1618. transport = new WorkerTransport(workerInitializedCapability,
  1619. workerReadyCapability, pdfDataRangeTransport,
  1620. progressCallback);
  1621. workerInitializedCapability.promise.then(function transportInitialized() {
  1622. transport.passwordCallback = passwordCallback;
  1623. transport.fetchDocument(params);
  1624. });
  1625. return workerReadyCapability.promise;
  1626. };
  1627. /**
  1628. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1629. * properties that can be read synchronously.
  1630. * @class
  1631. */
  1632. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1633. function PDFDocumentProxy(pdfInfo, transport) {
  1634. this.pdfInfo = pdfInfo;
  1635. this.transport = transport;
  1636. }
  1637. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1638. /**
  1639. * @return {number} Total number of pages the PDF contains.
  1640. */
  1641. get numPages() {
  1642. return this.pdfInfo.numPages;
  1643. },
  1644. /**
  1645. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1646. * unique.
  1647. */
  1648. get fingerprint() {
  1649. return this.pdfInfo.fingerprint;
  1650. },
  1651. /**
  1652. * @param {number} pageNumber The page number to get. The first page is 1.
  1653. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1654. * object.
  1655. */
  1656. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1657. return this.transport.getPage(pageNumber);
  1658. },
  1659. /**
  1660. * @param {{num: number, gen: number}} ref The page reference. Must have
  1661. * the 'num' and 'gen' properties.
  1662. * @return {Promise} A promise that is resolved with the page index that is
  1663. * associated with the reference.
  1664. */
  1665. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1666. return this.transport.getPageIndex(ref);
  1667. },
  1668. /**
  1669. * @return {Promise} A promise that is resolved with a lookup table for
  1670. * mapping named destinations to reference numbers.
  1671. */
  1672. getDestinations: function PDFDocumentProxy_getDestinations() {
  1673. return this.transport.getDestinations();
  1674. },
  1675. /**
  1676. * @return {Promise} A promise that is resolved with a lookup table for
  1677. * mapping named attachments to their content.
  1678. */
  1679. getAttachments: function PDFDocumentProxy_getAttachments() {
  1680. return this.transport.getAttachments();
  1681. },
  1682. /**
  1683. * @return {Promise} A promise that is resolved with an array of all the
  1684. * JavaScript strings in the name tree.
  1685. */
  1686. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1687. return this.transport.getJavaScript();
  1688. },
  1689. /**
  1690. * @return {Promise} A promise that is resolved with an {Array} that is a
  1691. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1692. * [
  1693. * {
  1694. * title: string,
  1695. * bold: boolean,
  1696. * italic: boolean,
  1697. * color: rgb array,
  1698. * dest: dest obj,
  1699. * items: array of more items like this
  1700. * },
  1701. * ...
  1702. * ].
  1703. */
  1704. getOutline: function PDFDocumentProxy_getOutline() {
  1705. return this.transport.getOutline();
  1706. },
  1707. /**
  1708. * @return {Promise} A promise that is resolved with an {Object} that has
  1709. * info and metadata properties. Info is an {Object} filled with anything
  1710. * available in the information dictionary and similarly metadata is a
  1711. * {Metadata} object with information from the metadata section of the PDF.
  1712. */
  1713. getMetadata: function PDFDocumentProxy_getMetadata() {
  1714. return this.transport.getMetadata();
  1715. },
  1716. /**
  1717. * @return {Promise} A promise that is resolved with a TypedArray that has
  1718. * the raw data from the PDF.
  1719. */
  1720. getData: function PDFDocumentProxy_getData() {
  1721. return this.transport.getData();
  1722. },
  1723. /**
  1724. * @return {Promise} A promise that is resolved when the document's data
  1725. * is loaded. It is resolved with an {Object} that contains the length
  1726. * property that indicates size of the PDF data in bytes.
  1727. */
  1728. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1729. return this.transport.downloadInfoCapability.promise;
  1730. },
  1731. /**
  1732. * @returns {Promise} A promise this is resolved with current stats about
  1733. * document structures (see {@link PDFDocumentStats}).
  1734. */
  1735. getStats: function PDFDocumentProxy_getStats() {
  1736. return this.transport.getStats();
  1737. },
  1738. /**
  1739. * Cleans up resources allocated by the document, e.g. created @font-face.
  1740. */
  1741. cleanup: function PDFDocumentProxy_cleanup() {
  1742. this.transport.startCleanup();
  1743. },
  1744. /**
  1745. * Destroys current document instance and terminates worker.
  1746. */
  1747. destroy: function PDFDocumentProxy_destroy() {
  1748. this.transport.destroy();
  1749. }
  1750. };
  1751. return PDFDocumentProxy;
  1752. })();
  1753. /**
  1754. * Page text content.
  1755. *
  1756. * @typedef {Object} TextContent
  1757. * @property {array} items - array of {@link TextItem}
  1758. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1759. * name.
  1760. */
  1761. /**
  1762. * Page text content part.
  1763. *
  1764. * @typedef {Object} TextItem
  1765. * @property {string} str - text content.
  1766. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1767. * @property {array} transform - transformation matrix.
  1768. * @property {number} width - width in device space.
  1769. * @property {number} height - height in device space.
  1770. * @property {string} fontName - font name used by pdf.js for converted font.
  1771. */
  1772. /**
  1773. * Text style.
  1774. *
  1775. * @typedef {Object} TextStyle
  1776. * @property {number} ascent - font ascent.
  1777. * @property {number} descent - font descent.
  1778. * @property {boolean} vertical - text is in vertical mode.
  1779. * @property {string} fontFamily - possible font family
  1780. */
  1781. /**
  1782. * Page render parameters.
  1783. *
  1784. * @typedef {Object} RenderParameters
  1785. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1786. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1787. * calling of PDFPage.getViewport method.
  1788. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1789. * (default value is 'display').
  1790. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1791. * endLayout and appendImage functions.
  1792. * @property {function} continueCallback - (optional) A function that will be
  1793. * called each time the rendering is paused. To continue
  1794. * rendering call the function that is the first argument
  1795. * to the callback.
  1796. */
  1797. /**
  1798. * PDF page operator list.
  1799. *
  1800. * @typedef {Object} PDFOperatorList
  1801. * @property {Array} fnArray - Array containing the operator functions.
  1802. * @property {Array} argsArray - Array containing the arguments of the
  1803. * functions.
  1804. */
  1805. /**
  1806. * Proxy to a PDFPage in the worker thread.
  1807. * @class
  1808. */
  1809. var PDFPageProxy = (function PDFPageProxyClosure() {
  1810. function PDFPageProxy(pageIndex, pageInfo, transport) {
  1811. this.pageIndex = pageIndex;
  1812. this.pageInfo = pageInfo;
  1813. this.transport = transport;
  1814. this.stats = new StatTimer();
  1815. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  1816. this.commonObjs = transport.commonObjs;
  1817. this.objs = new PDFObjects();
  1818. this.cleanupAfterRender = false;
  1819. this.pendingDestroy = false;
  1820. this.intentStates = {};
  1821. }
  1822. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  1823. /**
  1824. * @return {number} Page number of the page. First page is 1.
  1825. */
  1826. get pageNumber() {
  1827. return this.pageIndex + 1;
  1828. },
  1829. /**
  1830. * @return {number} The number of degrees the page is rotated clockwise.
  1831. */
  1832. get rotate() {
  1833. return this.pageInfo.rotate;
  1834. },
  1835. /**
  1836. * @return {Object} The reference that points to this page. It has 'num' and
  1837. * 'gen' properties.
  1838. */
  1839. get ref() {
  1840. return this.pageInfo.ref;
  1841. },
  1842. /**
  1843. * @return {Array} An array of the visible portion of the PDF page in the
  1844. * user space units - [x1, y1, x2, y2].
  1845. */
  1846. get view() {
  1847. return this.pageInfo.view;
  1848. },
  1849. /**
  1850. * @param {number} scale The desired scale of the viewport.
  1851. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  1852. * defaults to the page rotation.
  1853. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  1854. * along with transforms required for rendering.
  1855. */
  1856. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  1857. if (arguments.length < 2) {
  1858. rotate = this.rotate;
  1859. }
  1860. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  1861. },
  1862. /**
  1863. * @return {Promise} A promise that is resolved with an {Array} of the
  1864. * annotation objects.
  1865. */
  1866. getAnnotations: function PDFPageProxy_getAnnotations() {
  1867. if (this.annotationsPromise) {
  1868. return this.annotationsPromise;
  1869. }
  1870. var promise = this.transport.getAnnotations(this.pageIndex);
  1871. this.annotationsPromise = promise;
  1872. return promise;
  1873. },
  1874. /**
  1875. * Begins the process of rendering a page to the desired context.
  1876. * @param {RenderParameters} params Page render parameters.
  1877. * @return {RenderTask} An object that contains the promise, which
  1878. * is resolved when the page finishes rendering.
  1879. */
  1880. render: function PDFPageProxy_render(params) {
  1881. var stats = this.stats;
  1882. stats.time('Overall');
  1883. // If there was a pending destroy cancel it so no cleanup happens during
  1884. // this call to render.
  1885. this.pendingDestroy = false;
  1886. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  1887. if (!this.intentStates[renderingIntent]) {
  1888. this.intentStates[renderingIntent] = {};
  1889. }
  1890. var intentState = this.intentStates[renderingIntent];
  1891. // If there's no displayReadyCapability yet, then the operatorList
  1892. // was never requested before. Make the request and create the promise.
  1893. if (!intentState.displayReadyCapability) {
  1894. intentState.receivingOperatorList = true;
  1895. intentState.displayReadyCapability = createPromiseCapability();
  1896. intentState.operatorList = {
  1897. fnArray: [],
  1898. argsArray: [],
  1899. lastChunk: false
  1900. };
  1901. this.stats.time('Page Request');
  1902. this.transport.messageHandler.send('RenderPageRequest', {
  1903. pageIndex: this.pageNumber - 1,
  1904. intent: renderingIntent
  1905. });
  1906. }
  1907. var internalRenderTask = new InternalRenderTask(complete, params,
  1908. this.objs,
  1909. this.commonObjs,
  1910. intentState.operatorList,
  1911. this.pageNumber);
  1912. if (!intentState.renderTasks) {
  1913. intentState.renderTasks = [];
  1914. }
  1915. intentState.renderTasks.push(internalRenderTask);
  1916. var renderTask = new RenderTask(internalRenderTask);
  1917. var self = this;
  1918. intentState.displayReadyCapability.promise.then(
  1919. function pageDisplayReadyPromise(transparency) {
  1920. if (self.pendingDestroy) {
  1921. complete();
  1922. return;
  1923. }
  1924. stats.time('Rendering');
  1925. internalRenderTask.initalizeGraphics(transparency);
  1926. internalRenderTask.operatorListChanged();
  1927. },
  1928. function pageDisplayReadPromiseError(reason) {
  1929. complete(reason);
  1930. }
  1931. );
  1932. function complete(error) {
  1933. var i = intentState.renderTasks.indexOf(internalRenderTask);
  1934. if (i >= 0) {
  1935. intentState.renderTasks.splice(i, 1);
  1936. }
  1937. if (self.cleanupAfterRender) {
  1938. self.pendingDestroy = true;
  1939. }
  1940. self._tryDestroy();
  1941. if (error) {
  1942. internalRenderTask.capability.reject(error);
  1943. } else {
  1944. internalRenderTask.capability.resolve();
  1945. }
  1946. stats.timeEnd('Rendering');
  1947. stats.timeEnd('Overall');
  1948. }
  1949. return renderTask;
  1950. },
  1951. /**
  1952. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  1953. * object that represents page's operator list.
  1954. */
  1955. getOperatorList: function PDFPageProxy_getOperatorList() {
  1956. function operatorListChanged() {
  1957. if (intentState.operatorList.lastChunk) {
  1958. intentState.opListReadCapability.resolve(intentState.operatorList);
  1959. }
  1960. }
  1961. var renderingIntent = 'oplist';
  1962. if (!this.intentStates[renderingIntent]) {
  1963. this.intentStates[renderingIntent] = {};
  1964. }
  1965. var intentState = this.intentStates[renderingIntent];
  1966. if (!intentState.opListReadCapability) {
  1967. var opListTask = {};
  1968. opListTask.operatorListChanged = operatorListChanged;
  1969. intentState.receivingOperatorList = true;
  1970. intentState.opListReadCapability = createPromiseCapability();
  1971. intentState.renderTasks = [];
  1972. intentState.renderTasks.push(opListTask);
  1973. intentState.operatorList = {
  1974. fnArray: [],
  1975. argsArray: [],
  1976. lastChunk: false
  1977. };
  1978. this.transport.messageHandler.send('RenderPageRequest', {
  1979. pageIndex: this.pageIndex,
  1980. intent: renderingIntent
  1981. });
  1982. }
  1983. return intentState.opListReadCapability.promise;
  1984. },
  1985. /**
  1986. * @return {Promise} That is resolved a {@link TextContent}
  1987. * object that represent the page text content.
  1988. */
  1989. getTextContent: function PDFPageProxy_getTextContent() {
  1990. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  1991. pageIndex: this.pageNumber - 1
  1992. });
  1993. },
  1994. /**
  1995. * Destroys resources allocated by the page.
  1996. */
  1997. destroy: function PDFPageProxy_destroy() {
  1998. this.pendingDestroy = true;
  1999. this._tryDestroy();
  2000. },
  2001. /**
  2002. * For internal use only. Attempts to clean up if rendering is in a state
  2003. * where that's possible.
  2004. * @ignore
  2005. */
  2006. _tryDestroy: function PDFPageProxy__destroy() {
  2007. if (!this.pendingDestroy ||
  2008. Object.keys(this.intentStates).some(function(intent) {
  2009. var intentState = this.intentStates[intent];
  2010. return (intentState.renderTasks.length !== 0 ||
  2011. intentState.receivingOperatorList);
  2012. }, this)) {
  2013. return;
  2014. }
  2015. Object.keys(this.intentStates).forEach(function(intent) {
  2016. delete this.intentStates[intent];
  2017. }, this);
  2018. this.objs.clear();
  2019. this.annotationsPromise = null;
  2020. this.pendingDestroy = false;
  2021. },
  2022. /**
  2023. * For internal use only.
  2024. * @ignore
  2025. */
  2026. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2027. intent) {
  2028. var intentState = this.intentStates[intent];
  2029. // TODO Refactor RenderPageRequest to separate rendering
  2030. // and operator list logic
  2031. if (intentState.displayReadyCapability) {
  2032. intentState.displayReadyCapability.resolve(transparency);
  2033. }
  2034. },
  2035. /**
  2036. * For internal use only.
  2037. * @ignore
  2038. */
  2039. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2040. intent) {
  2041. var intentState = this.intentStates[intent];
  2042. var i, ii;
  2043. // Add the new chunk to the current operator list.
  2044. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2045. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2046. intentState.operatorList.argsArray.push(
  2047. operatorListChunk.argsArray[i]);
  2048. }
  2049. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2050. // Notify all the rendering tasks there are more operators to be consumed.
  2051. for (i = 0; i < intentState.renderTasks.length; i++) {
  2052. intentState.renderTasks[i].operatorListChanged();
  2053. }
  2054. if (operatorListChunk.lastChunk) {
  2055. intentState.receivingOperatorList = false;
  2056. this._tryDestroy();
  2057. }
  2058. }
  2059. };
  2060. return PDFPageProxy;
  2061. })();
  2062. /**
  2063. * For internal use only.
  2064. * @ignore
  2065. */
  2066. var WorkerTransport = (function WorkerTransportClosure() {
  2067. function WorkerTransport(workerInitializedCapability, workerReadyCapability,
  2068. pdfDataRangeTransport, progressCallback) {
  2069. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2070. this.workerInitializedCapability = workerInitializedCapability;
  2071. this.workerReadyCapability = workerReadyCapability;
  2072. this.progressCallback = progressCallback;
  2073. this.commonObjs = new PDFObjects();
  2074. this.pageCache = [];
  2075. this.pagePromises = [];
  2076. this.downloadInfoCapability = createPromiseCapability();
  2077. this.passwordCallback = null;
  2078. // If worker support isn't disabled explicit and the browser has worker
  2079. // support, create a new web worker and test if it/the browser fullfills
  2080. // all requirements to run parts of pdf.js in a web worker.
  2081. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2082. // as it arrives on the worker. Chrome added this with version 15.
  2083. // Either workers are disabled, not supported or have thrown an exception.
  2084. // Thus, we fallback to a faked worker.
  2085. this.setupFakeWorker();
  2086. }
  2087. WorkerTransport.prototype = {
  2088. destroy: function WorkerTransport_destroy() {
  2089. this.pageCache = [];
  2090. this.pagePromises = [];
  2091. var self = this;
  2092. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2093. FontLoader.clear();
  2094. if (self.worker) {
  2095. self.worker.terminate();
  2096. }
  2097. });
  2098. },
  2099. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2100. globalScope.PDFJS.disableWorker = true;
  2101. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2102. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2103. // In the developer build load worker_loader which in turn loads all the
  2104. // other files and resolves the promise. In production only the
  2105. // pdf.worker.js file is needed.
  2106. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2107. }
  2108. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2109. warn('Setting up fake worker.');
  2110. // If we don't use a worker, just post/sendMessage to the main thread.
  2111. var fakeWorker = {
  2112. postMessage: function WorkerTransport_postMessage(obj) {
  2113. fakeWorker.onmessage({data: obj});
  2114. },
  2115. terminate: function WorkerTransport_terminate() {}
  2116. };
  2117. var messageHandler = new MessageHandler('main', fakeWorker);
  2118. this.setupMessageHandler(messageHandler);
  2119. // If the main thread is our worker, setup the handling for the messages
  2120. // the main thread sends to it self.
  2121. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2122. this.workerInitializedCapability.resolve();
  2123. }.bind(this));
  2124. },
  2125. setupMessageHandler:
  2126. function WorkerTransport_setupMessageHandler(messageHandler) {
  2127. this.messageHandler = messageHandler;
  2128. function updatePassword(password) {
  2129. messageHandler.send('UpdatePassword', password);
  2130. }
  2131. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2132. if (pdfDataRangeTransport) {
  2133. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2134. messageHandler.send('OnDataRange', {
  2135. begin: begin,
  2136. chunk: chunk
  2137. });
  2138. });
  2139. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2140. messageHandler.send('OnDataProgress', {
  2141. loaded: loaded
  2142. });
  2143. });
  2144. messageHandler.on('RequestDataRange',
  2145. function transportDataRange(data) {
  2146. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2147. }, this);
  2148. }
  2149. messageHandler.on('GetDoc', function transportDoc(data) {
  2150. var pdfInfo = data.pdfInfo;
  2151. this.numPages = data.pdfInfo.numPages;
  2152. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2153. this.pdfDocument = pdfDocument;
  2154. this.workerReadyCapability.resolve(pdfDocument);
  2155. }, this);
  2156. messageHandler.on('NeedPassword', function transportPassword(data) {
  2157. if (this.passwordCallback) {
  2158. return this.passwordCallback(updatePassword,
  2159. PasswordResponses.NEED_PASSWORD);
  2160. }
  2161. this.workerReadyCapability.reject(data.exception.message,
  2162. data.exception);
  2163. }, this);
  2164. messageHandler.on('IncorrectPassword', function transportBadPass(data) {
  2165. if (this.passwordCallback) {
  2166. return this.passwordCallback(updatePassword,
  2167. PasswordResponses.INCORRECT_PASSWORD);
  2168. }
  2169. this.workerReadyCapability.reject(data.exception.message,
  2170. data.exception);
  2171. }, this);
  2172. messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
  2173. this.workerReadyCapability.reject(data.exception.name, data.exception);
  2174. }, this);
  2175. messageHandler.on('MissingPDF', function transportMissingPDF(data) {
  2176. this.workerReadyCapability.reject(data.exception.message,
  2177. data.exception);
  2178. }, this);
  2179. messageHandler.on('UnknownError', function transportUnknownError(data) {
  2180. this.workerReadyCapability.reject(data.exception.message,
  2181. data.exception);
  2182. }, this);
  2183. messageHandler.on('DataLoaded', function transportPage(data) {
  2184. this.downloadInfoCapability.resolve(data);
  2185. }, this);
  2186. messageHandler.on('StartRenderPage', function transportRender(data) {
  2187. var page = this.pageCache[data.pageIndex];
  2188. page.stats.timeEnd('Page Request');
  2189. page._startRenderPage(data.transparency, data.intent);
  2190. }, this);
  2191. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2192. var page = this.pageCache[data.pageIndex];
  2193. page._renderPageChunk(data.operatorList, data.intent);
  2194. }, this);
  2195. messageHandler.on('commonobj', function transportObj(data) {
  2196. var id = data[0];
  2197. var type = data[1];
  2198. if (this.commonObjs.hasData(id)) {
  2199. return;
  2200. }
  2201. switch (type) {
  2202. case 'Font':
  2203. var exportedData = data[2];
  2204. var font;
  2205. if ('error' in exportedData) {
  2206. var error = exportedData.error;
  2207. warn('Error during font loading: ' + error);
  2208. this.commonObjs.resolve(id, error);
  2209. break;
  2210. } else {
  2211. font = new FontFace(exportedData);
  2212. }
  2213. FontLoader.bind(
  2214. [font],
  2215. function fontReady(fontObjs) {
  2216. this.commonObjs.resolve(id, font);
  2217. }.bind(this)
  2218. );
  2219. break;
  2220. case 'FontPath':
  2221. this.commonObjs.resolve(id, data[2]);
  2222. break;
  2223. default:
  2224. error('Got unknown common object type ' + type);
  2225. }
  2226. }, this);
  2227. messageHandler.on('obj', function transportObj(data) {
  2228. var id = data[0];
  2229. var pageIndex = data[1];
  2230. var type = data[2];
  2231. var pageProxy = this.pageCache[pageIndex];
  2232. var imageData;
  2233. if (pageProxy.objs.hasData(id)) {
  2234. return;
  2235. }
  2236. switch (type) {
  2237. case 'JpegStream':
  2238. imageData = data[3];
  2239. loadJpegStream(id, imageData, pageProxy.objs);
  2240. break;
  2241. case 'Image':
  2242. imageData = data[3];
  2243. pageProxy.objs.resolve(id, imageData);
  2244. // heuristics that will allow not to store large data
  2245. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2246. if (imageData && 'data' in imageData &&
  2247. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2248. pageProxy.cleanupAfterRender = true;
  2249. }
  2250. break;
  2251. default:
  2252. error('Got unknown object type ' + type);
  2253. }
  2254. }, this);
  2255. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2256. if (this.progressCallback) {
  2257. this.progressCallback({
  2258. loaded: data.loaded,
  2259. total: data.total
  2260. });
  2261. }
  2262. }, this);
  2263. messageHandler.on('DocError', function transportDocError(data) {
  2264. this.workerReadyCapability.reject(data);
  2265. }, this);
  2266. messageHandler.on('PageError', function transportError(data) {
  2267. var page = this.pageCache[data.pageNum - 1];
  2268. var intentState = page.intentStates[data.intent];
  2269. if (intentState.displayReadyCapability.promise) {
  2270. intentState.displayReadyCapability.reject(data.error);
  2271. } else {
  2272. error(data.error);
  2273. }
  2274. }, this);
  2275. messageHandler.on('JpegDecode', function(data) {
  2276. var imageUrl = data[0];
  2277. var components = data[1];
  2278. if (components !== 3 && components !== 1) {
  2279. return Promise.reject(
  2280. new Error('Only 3 components or 1 component can be returned'));
  2281. }
  2282. return new Promise(function (resolve, reject) {
  2283. var img = new Image();
  2284. img.onload = function () {
  2285. var width = img.width;
  2286. var height = img.height;
  2287. var size = width * height;
  2288. var rgbaLength = size * 4;
  2289. var buf = new Uint8Array(size * components);
  2290. var tmpCanvas = createScratchCanvas(width, height);
  2291. var tmpCtx = tmpCanvas.getContext('2d');
  2292. tmpCtx.drawImage(img, 0, 0);
  2293. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2294. var i, j;
  2295. if (components === 3) {
  2296. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2297. buf[j] = data[i];
  2298. buf[j + 1] = data[i + 1];
  2299. buf[j + 2] = data[i + 2];
  2300. }
  2301. } else if (components === 1) {
  2302. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2303. buf[j] = data[i];
  2304. }
  2305. }
  2306. resolve({ data: buf, width: width, height: height});
  2307. };
  2308. img.onerror = function () {
  2309. reject(new Error('JpegDecode failed to load image'));
  2310. };
  2311. img.src = imageUrl;
  2312. });
  2313. });
  2314. },
  2315. fetchDocument: function WorkerTransport_fetchDocument(source) {
  2316. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2317. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2318. this.messageHandler.send('GetDocRequest', {
  2319. source: source,
  2320. disableRange: PDFJS.disableRange,
  2321. maxImageSize: PDFJS.maxImageSize,
  2322. cMapUrl: PDFJS.cMapUrl,
  2323. cMapPacked: PDFJS.cMapPacked,
  2324. disableFontFace: PDFJS.disableFontFace,
  2325. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2326. verbosity: PDFJS.verbosity
  2327. });
  2328. },
  2329. getData: function WorkerTransport_getData() {
  2330. return this.messageHandler.sendWithPromise('GetData', null);
  2331. },
  2332. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2333. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2334. (pageNumber|0) !== pageNumber) {
  2335. return Promise.reject(new Error('Invalid page request'));
  2336. }
  2337. var pageIndex = pageNumber - 1;
  2338. if (pageIndex in this.pagePromises) {
  2339. return this.pagePromises[pageIndex];
  2340. }
  2341. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2342. pageIndex: pageIndex
  2343. }).then(function (pageInfo) {
  2344. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2345. this.pageCache[pageIndex] = page;
  2346. return page;
  2347. }.bind(this));
  2348. this.pagePromises[pageIndex] = promise;
  2349. return promise;
  2350. },
  2351. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2352. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2353. },
  2354. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2355. return this.messageHandler.sendWithPromise('GetAnnotations',
  2356. { pageIndex: pageIndex });
  2357. },
  2358. getDestinations: function WorkerTransport_getDestinations() {
  2359. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2360. },
  2361. getAttachments: function WorkerTransport_getAttachments() {
  2362. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2363. },
  2364. getJavaScript: function WorkerTransport_getJavaScript() {
  2365. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2366. },
  2367. getOutline: function WorkerTransport_getOutline() {
  2368. return this.messageHandler.sendWithPromise('GetOutline', null);
  2369. },
  2370. getMetadata: function WorkerTransport_getMetadata() {
  2371. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2372. then(function transportMetadata(results) {
  2373. return {
  2374. info: results[0],
  2375. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2376. };
  2377. });
  2378. },
  2379. getStats: function WorkerTransport_getStats() {
  2380. return this.messageHandler.sendWithPromise('GetStats', null);
  2381. },
  2382. startCleanup: function WorkerTransport_startCleanup() {
  2383. this.messageHandler.sendWithPromise('Cleanup', null).
  2384. then(function endCleanup() {
  2385. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2386. var page = this.pageCache[i];
  2387. if (page) {
  2388. page.destroy();
  2389. }
  2390. }
  2391. this.commonObjs.clear();
  2392. FontLoader.clear();
  2393. }.bind(this));
  2394. }
  2395. };
  2396. return WorkerTransport;
  2397. })();
  2398. /**
  2399. * A PDF document and page is built of many objects. E.g. there are objects
  2400. * for fonts, images, rendering code and such. These objects might get processed
  2401. * inside of a worker. The `PDFObjects` implements some basic functions to
  2402. * manage these objects.
  2403. * @ignore
  2404. */
  2405. var PDFObjects = (function PDFObjectsClosure() {
  2406. function PDFObjects() {
  2407. this.objs = {};
  2408. }
  2409. PDFObjects.prototype = {
  2410. /**
  2411. * Internal function.
  2412. * Ensures there is an object defined for `objId`.
  2413. */
  2414. ensureObj: function PDFObjects_ensureObj(objId) {
  2415. if (this.objs[objId]) {
  2416. return this.objs[objId];
  2417. }
  2418. var obj = {
  2419. capability: createPromiseCapability(),
  2420. data: null,
  2421. resolved: false
  2422. };
  2423. this.objs[objId] = obj;
  2424. return obj;
  2425. },
  2426. /**
  2427. * If called *without* callback, this returns the data of `objId` but the
  2428. * object needs to be resolved. If it isn't, this function throws.
  2429. *
  2430. * If called *with* a callback, the callback is called with the data of the
  2431. * object once the object is resolved. That means, if you call this
  2432. * function and the object is already resolved, the callback gets called
  2433. * right away.
  2434. */
  2435. get: function PDFObjects_get(objId, callback) {
  2436. // If there is a callback, then the get can be async and the object is
  2437. // not required to be resolved right now
  2438. if (callback) {
  2439. this.ensureObj(objId).capability.promise.then(callback);
  2440. return null;
  2441. }
  2442. // If there isn't a callback, the user expects to get the resolved data
  2443. // directly.
  2444. var obj = this.objs[objId];
  2445. // If there isn't an object yet or the object isn't resolved, then the
  2446. // data isn't ready yet!
  2447. if (!obj || !obj.resolved) {
  2448. error('Requesting object that isn\'t resolved yet ' + objId);
  2449. }
  2450. return obj.data;
  2451. },
  2452. /**
  2453. * Resolves the object `objId` with optional `data`.
  2454. */
  2455. resolve: function PDFObjects_resolve(objId, data) {
  2456. var obj = this.ensureObj(objId);
  2457. obj.resolved = true;
  2458. obj.data = data;
  2459. obj.capability.resolve(data);
  2460. },
  2461. isResolved: function PDFObjects_isResolved(objId) {
  2462. var objs = this.objs;
  2463. if (!objs[objId]) {
  2464. return false;
  2465. } else {
  2466. return objs[objId].resolved;
  2467. }
  2468. },
  2469. hasData: function PDFObjects_hasData(objId) {
  2470. return this.isResolved(objId);
  2471. },
  2472. /**
  2473. * Returns the data of `objId` if object exists, null otherwise.
  2474. */
  2475. getData: function PDFObjects_getData(objId) {
  2476. var objs = this.objs;
  2477. if (!objs[objId] || !objs[objId].resolved) {
  2478. return null;
  2479. } else {
  2480. return objs[objId].data;
  2481. }
  2482. },
  2483. clear: function PDFObjects_clear() {
  2484. this.objs = {};
  2485. }
  2486. };
  2487. return PDFObjects;
  2488. })();
  2489. /**
  2490. * Allows controlling of the rendering tasks.
  2491. * @class
  2492. */
  2493. var RenderTask = (function RenderTaskClosure() {
  2494. function RenderTask(internalRenderTask) {
  2495. this.internalRenderTask = internalRenderTask;
  2496. /**
  2497. * Promise for rendering task completion.
  2498. * @type {Promise}
  2499. */
  2500. this.promise = this.internalRenderTask.capability.promise;
  2501. }
  2502. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2503. /**
  2504. * Cancels the rendering task. If the task is currently rendering it will
  2505. * not be cancelled until graphics pauses with a timeout. The promise that
  2506. * this object extends will resolved when cancelled.
  2507. */
  2508. cancel: function RenderTask_cancel() {
  2509. this.internalRenderTask.cancel();
  2510. },
  2511. /**
  2512. * Registers callback to indicate the rendering task completion.
  2513. *
  2514. * @param {function} onFulfilled The callback for the rendering completion.
  2515. * @param {function} onRejected The callback for the rendering failure.
  2516. * @return {Promise} A promise that is resolved after the onFulfilled or
  2517. * onRejected callback.
  2518. */
  2519. then: function RenderTask_then(onFulfilled, onRejected) {
  2520. return this.promise.then(onFulfilled, onRejected);
  2521. }
  2522. };
  2523. return RenderTask;
  2524. })();
  2525. /**
  2526. * For internal use only.
  2527. * @ignore
  2528. */
  2529. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2530. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2531. pageNumber) {
  2532. this.callback = callback;
  2533. this.params = params;
  2534. this.objs = objs;
  2535. this.commonObjs = commonObjs;
  2536. this.operatorListIdx = null;
  2537. this.operatorList = operatorList;
  2538. this.pageNumber = pageNumber;
  2539. this.running = false;
  2540. this.graphicsReadyCallback = null;
  2541. this.graphicsReady = false;
  2542. this.cancelled = false;
  2543. this.capability = createPromiseCapability();
  2544. // caching this-bound methods
  2545. this._continueBound = this._continue.bind(this);
  2546. this._scheduleNextBound = this._scheduleNext.bind(this);
  2547. this._nextBound = this._next.bind(this);
  2548. }
  2549. InternalRenderTask.prototype = {
  2550. initalizeGraphics:
  2551. function InternalRenderTask_initalizeGraphics(transparency) {
  2552. if (this.cancelled) {
  2553. return;
  2554. }
  2555. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2556. globalScope.StepperManager.enabled) {
  2557. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2558. this.stepper.init(this.operatorList);
  2559. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2560. }
  2561. var params = this.params;
  2562. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2563. this.objs, params.imageLayer);
  2564. this.gfx.beginDrawing(params.viewport, transparency);
  2565. this.operatorListIdx = 0;
  2566. this.graphicsReady = true;
  2567. if (this.graphicsReadyCallback) {
  2568. this.graphicsReadyCallback();
  2569. }
  2570. },
  2571. cancel: function InternalRenderTask_cancel() {
  2572. this.running = false;
  2573. this.cancelled = true;
  2574. this.callback('cancelled');
  2575. },
  2576. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2577. if (!this.graphicsReady) {
  2578. if (!this.graphicsReadyCallback) {
  2579. this.graphicsReadyCallback = this._continueBound;
  2580. }
  2581. return;
  2582. }
  2583. if (this.stepper) {
  2584. this.stepper.updateOperatorList(this.operatorList);
  2585. }
  2586. if (this.running) {
  2587. return;
  2588. }
  2589. this._continue();
  2590. },
  2591. _continue: function InternalRenderTask__continue() {
  2592. this.running = true;
  2593. if (this.cancelled) {
  2594. return;
  2595. }
  2596. if (this.params.continueCallback) {
  2597. this.params.continueCallback(this._scheduleNextBound);
  2598. } else {
  2599. this._scheduleNext();
  2600. }
  2601. },
  2602. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2603. window.requestAnimationFrame(this._nextBound);
  2604. },
  2605. _next: function InternalRenderTask__next() {
  2606. if (this.cancelled) {
  2607. return;
  2608. }
  2609. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2610. this.operatorListIdx,
  2611. this._continueBound,
  2612. this.stepper);
  2613. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2614. this.running = false;
  2615. if (this.operatorList.lastChunk) {
  2616. this.gfx.endDrawing();
  2617. this.callback();
  2618. }
  2619. }
  2620. }
  2621. };
  2622. return InternalRenderTask;
  2623. })();
  2624. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2625. function fixMetadata(meta) {
  2626. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2627. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2628. function(code, d1, d2, d3) {
  2629. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2630. });
  2631. var chars = '';
  2632. for (var i = 0; i < bytes.length; i += 2) {
  2633. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2634. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2635. code !== 38 && false ? String.fromCharCode(code) :
  2636. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2637. }
  2638. return '>' + chars;
  2639. });
  2640. }
  2641. function Metadata(meta) {
  2642. if (typeof meta === 'string') {
  2643. // Ghostscript produces invalid metadata
  2644. meta = fixMetadata(meta);
  2645. var parser = new DOMParser();
  2646. meta = parser.parseFromString(meta, 'application/xml');
  2647. } else if (!(meta instanceof Document)) {
  2648. error('Metadata: Invalid metadata object');
  2649. }
  2650. this.metaDocument = meta;
  2651. this.metadata = {};
  2652. this.parse();
  2653. }
  2654. Metadata.prototype = {
  2655. parse: function Metadata_parse() {
  2656. var doc = this.metaDocument;
  2657. var rdf = doc.documentElement;
  2658. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2659. rdf = rdf.firstChild;
  2660. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2661. rdf = rdf.nextSibling;
  2662. }
  2663. }
  2664. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2665. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2666. return;
  2667. }
  2668. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2669. for (i = 0, length = children.length; i < length; i++) {
  2670. desc = children[i];
  2671. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2672. continue;
  2673. }
  2674. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2675. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2676. entry = desc.childNodes[ii];
  2677. name = entry.nodeName.toLowerCase();
  2678. this.metadata[name] = entry.textContent.trim();
  2679. }
  2680. }
  2681. }
  2682. },
  2683. get: function Metadata_get(name) {
  2684. return this.metadata[name] || null;
  2685. },
  2686. has: function Metadata_has(name) {
  2687. return typeof this.metadata[name] !== 'undefined';
  2688. }
  2689. };
  2690. return Metadata;
  2691. })();
  2692. // <canvas> contexts store most of the state we need natively.
  2693. // However, PDF needs a bit more state, which we store here.
  2694. // Minimal font size that would be used during canvas fillText operations.
  2695. var MIN_FONT_SIZE = 16;
  2696. var MAX_GROUP_SIZE = 4096;
  2697. var COMPILE_TYPE3_GLYPHS = true;
  2698. function createScratchCanvas(width, height) {
  2699. var canvas = document.createElement('canvas');
  2700. canvas.width = width;
  2701. canvas.height = height;
  2702. return canvas;
  2703. }
  2704. function addContextCurrentTransform(ctx) {
  2705. // If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
  2706. if (!ctx.mozCurrentTransform) {
  2707. // Store the original context
  2708. ctx._scaleX = ctx._scaleX || 1.0;
  2709. ctx._scaleY = ctx._scaleY || 1.0;
  2710. ctx._originalSave = ctx.save;
  2711. ctx._originalRestore = ctx.restore;
  2712. ctx._originalRotate = ctx.rotate;
  2713. ctx._originalScale = ctx.scale;
  2714. ctx._originalTranslate = ctx.translate;
  2715. ctx._originalTransform = ctx.transform;
  2716. ctx._originalSetTransform = ctx.setTransform;
  2717. ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
  2718. ctx._transformStack = [];
  2719. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2720. get: function getCurrentTransform() {
  2721. return this._transformMatrix;
  2722. }
  2723. });
  2724. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2725. get: function getCurrentTransformInverse() {
  2726. // Calculation done using WolframAlpha:
  2727. // http://www.wolframalpha.com/input/?
  2728. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2729. var m = this._transformMatrix;
  2730. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2731. var ad_bc = a * d - b * c;
  2732. var bc_ad = b * c - a * d;
  2733. return [
  2734. d / ad_bc,
  2735. b / bc_ad,
  2736. c / bc_ad,
  2737. a / ad_bc,
  2738. (d * e - c * f) / bc_ad,
  2739. (b * e - a * f) / ad_bc
  2740. ];
  2741. }
  2742. });
  2743. ctx.save = function ctxSave() {
  2744. var old = this._transformMatrix;
  2745. this._transformStack.push(old);
  2746. this._transformMatrix = old.slice(0, 6);
  2747. this._originalSave();
  2748. };
  2749. ctx.restore = function ctxRestore() {
  2750. var prev = this._transformStack.pop();
  2751. if (prev) {
  2752. this._transformMatrix = prev;
  2753. this._originalRestore();
  2754. }
  2755. };
  2756. ctx.translate = function ctxTranslate(x, y) {
  2757. var m = this._transformMatrix;
  2758. m[4] = m[0] * x + m[2] * y + m[4];
  2759. m[5] = m[1] * x + m[3] * y + m[5];
  2760. this._originalTranslate(x, y);
  2761. };
  2762. ctx.scale = function ctxScale(x, y) {
  2763. var m = this._transformMatrix;
  2764. m[0] = m[0] * x;
  2765. m[1] = m[1] * x;
  2766. m[2] = m[2] * y;
  2767. m[3] = m[3] * y;
  2768. this._originalScale(x, y);
  2769. };
  2770. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  2771. var m = this._transformMatrix;
  2772. this._transformMatrix = [
  2773. m[0] * a + m[2] * b,
  2774. m[1] * a + m[3] * b,
  2775. m[0] * c + m[2] * d,
  2776. m[1] * c + m[3] * d,
  2777. m[0] * e + m[2] * f + m[4],
  2778. m[1] * e + m[3] * f + m[5]
  2779. ];
  2780. ctx._originalTransform(a, b, c, d, e, f);
  2781. };
  2782. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  2783. this._transformMatrix = [a, b, c, d, e, f];
  2784. ctx._originalSetTransform(a, b, c, d, e, f);
  2785. };
  2786. ctx.rotate = function ctxRotate(angle) {
  2787. var cosValue = Math.cos(angle);
  2788. var sinValue = Math.sin(angle);
  2789. var m = this._transformMatrix;
  2790. this._transformMatrix = [
  2791. m[0] * cosValue + m[2] * sinValue,
  2792. m[1] * cosValue + m[3] * sinValue,
  2793. m[0] * (-sinValue) + m[2] * cosValue,
  2794. m[1] * (-sinValue) + m[3] * cosValue,
  2795. m[4],
  2796. m[5]
  2797. ];
  2798. this._originalRotate(angle);
  2799. };
  2800. }
  2801. }
  2802. var CachedCanvases = (function CachedCanvasesClosure() {
  2803. var cache = {};
  2804. return {
  2805. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  2806. trackTransform) {
  2807. var canvasEntry;
  2808. if (id in cache) {
  2809. canvasEntry = cache[id];
  2810. canvasEntry.canvas.width = width;
  2811. canvasEntry.canvas.height = height;
  2812. // reset canvas transform for emulated mozCurrentTransform, if needed
  2813. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  2814. } else {
  2815. var canvas = createScratchCanvas(width, height);
  2816. var ctx = canvas.getContext('2d');
  2817. if (trackTransform) {
  2818. addContextCurrentTransform(ctx);
  2819. }
  2820. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  2821. }
  2822. return canvasEntry;
  2823. },
  2824. clear: function () {
  2825. for (var id in cache) {
  2826. var canvasEntry = cache[id];
  2827. // Zeroing the width and height causes Firefox to release graphics
  2828. // resources immediately, which can greatly reduce memory consumption.
  2829. canvasEntry.canvas.width = 0;
  2830. canvasEntry.canvas.height = 0;
  2831. delete cache[id];
  2832. }
  2833. }
  2834. };
  2835. })();
  2836. function compileType3Glyph(imgData) {
  2837. var POINT_TO_PROCESS_LIMIT = 1000;
  2838. var width = imgData.width, height = imgData.height;
  2839. var i, j, j0, width1 = width + 1;
  2840. var points = new Uint8Array(width1 * (height + 1));
  2841. var POINT_TYPES =
  2842. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  2843. // decodes bit-packed mask data
  2844. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  2845. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  2846. for (i = 0, ii = data0.length; i < ii; i++) {
  2847. var mask = 128, elem = data0[i];
  2848. while (mask > 0) {
  2849. data[pos++] = (elem & mask) ? 0 : 255;
  2850. mask >>= 1;
  2851. }
  2852. }
  2853. // finding iteresting points: every point is located between mask pixels,
  2854. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  2855. // will have flags assigned based on neighboring mask pixels:
  2856. // 4 | 8
  2857. // --P--
  2858. // 2 | 1
  2859. // We are interested only in points with the flags:
  2860. // - outside corners: 1, 2, 4, 8;
  2861. // - inside corners: 7, 11, 13, 14;
  2862. // - and, intersections: 5, 10.
  2863. var count = 0;
  2864. pos = 0;
  2865. if (data[pos] !== 0) {
  2866. points[0] = 1;
  2867. ++count;
  2868. }
  2869. for (j = 1; j < width; j++) {
  2870. if (data[pos] !== data[pos + 1]) {
  2871. points[j] = data[pos] ? 2 : 1;
  2872. ++count;
  2873. }
  2874. pos++;
  2875. }
  2876. if (data[pos] !== 0) {
  2877. points[j] = 2;
  2878. ++count;
  2879. }
  2880. for (i = 1; i < height; i++) {
  2881. pos = i * lineSize;
  2882. j0 = i * width1;
  2883. if (data[pos - lineSize] !== data[pos]) {
  2884. points[j0] = data[pos] ? 1 : 8;
  2885. ++count;
  2886. }
  2887. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  2888. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  2889. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  2890. for (j = 1; j < width; j++) {
  2891. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  2892. (data[pos - lineSize + 1] ? 8 : 0);
  2893. if (POINT_TYPES[sum]) {
  2894. points[j0 + j] = POINT_TYPES[sum];
  2895. ++count;
  2896. }
  2897. pos++;
  2898. }
  2899. if (data[pos - lineSize] !== data[pos]) {
  2900. points[j0 + j] = data[pos] ? 2 : 4;
  2901. ++count;
  2902. }
  2903. if (count > POINT_TO_PROCESS_LIMIT) {
  2904. return null;
  2905. }
  2906. }
  2907. pos = lineSize * (height - 1);
  2908. j0 = i * width1;
  2909. if (data[pos] !== 0) {
  2910. points[j0] = 8;
  2911. ++count;
  2912. }
  2913. for (j = 1; j < width; j++) {
  2914. if (data[pos] !== data[pos + 1]) {
  2915. points[j0 + j] = data[pos] ? 4 : 8;
  2916. ++count;
  2917. }
  2918. pos++;
  2919. }
  2920. if (data[pos] !== 0) {
  2921. points[j0 + j] = 4;
  2922. ++count;
  2923. }
  2924. if (count > POINT_TO_PROCESS_LIMIT) {
  2925. return null;
  2926. }
  2927. // building outlines
  2928. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  2929. var outlines = [];
  2930. for (i = 0; count && i <= height; i++) {
  2931. var p = i * width1;
  2932. var end = p + width;
  2933. while (p < end && !points[p]) {
  2934. p++;
  2935. }
  2936. if (p === end) {
  2937. continue;
  2938. }
  2939. var coords = [p % width1, i];
  2940. var type = points[p], p0 = p, pp;
  2941. do {
  2942. var step = steps[type];
  2943. do {
  2944. p += step;
  2945. } while (!points[p]);
  2946. pp = points[p];
  2947. if (pp !== 5 && pp !== 10) {
  2948. // set new direction
  2949. type = pp;
  2950. // delete mark
  2951. points[p] = 0;
  2952. } else { // type is 5 or 10, ie, a crossing
  2953. // set new direction
  2954. type = pp & ((0x33 * type) >> 4);
  2955. // set new type for "future hit"
  2956. points[p] &= (type >> 2 | type << 2);
  2957. }
  2958. coords.push(p % width1);
  2959. coords.push((p / width1) | 0);
  2960. --count;
  2961. } while (p0 !== p);
  2962. outlines.push(coords);
  2963. --i;
  2964. }
  2965. var drawOutline = function(c) {
  2966. c.save();
  2967. // the path shall be painted in [0..1]x[0..1] space
  2968. c.scale(1 / width, -1 / height);
  2969. c.translate(0, -height);
  2970. c.beginPath();
  2971. for (var i = 0, ii = outlines.length; i < ii; i++) {
  2972. var o = outlines[i];
  2973. c.moveTo(o[0], o[1]);
  2974. for (var j = 2, jj = o.length; j < jj; j += 2) {
  2975. c.lineTo(o[j], o[j+1]);
  2976. }
  2977. }
  2978. c.fill();
  2979. c.beginPath();
  2980. c.restore();
  2981. };
  2982. return drawOutline;
  2983. }
  2984. var CanvasExtraState = (function CanvasExtraStateClosure() {
  2985. function CanvasExtraState(old) {
  2986. // Are soft masks and alpha values shapes or opacities?
  2987. this.alphaIsShape = false;
  2988. this.fontSize = 0;
  2989. this.fontSizeScale = 1;
  2990. this.textMatrix = IDENTITY_MATRIX;
  2991. this.textMatrixScale = 1;
  2992. this.fontMatrix = FONT_IDENTITY_MATRIX;
  2993. this.leading = 0;
  2994. // Current point (in user coordinates)
  2995. this.x = 0;
  2996. this.y = 0;
  2997. // Start of text line (in text coordinates)
  2998. this.lineX = 0;
  2999. this.lineY = 0;
  3000. // Character and word spacing
  3001. this.charSpacing = 0;
  3002. this.wordSpacing = 0;
  3003. this.textHScale = 1;
  3004. this.textRenderingMode = TextRenderingMode.FILL;
  3005. this.textRise = 0;
  3006. // Default fore and background colors
  3007. this.fillColor = '#000000';
  3008. this.strokeColor = '#000000';
  3009. // Note: fill alpha applies to all non-stroking operations
  3010. this.fillAlpha = 1;
  3011. this.strokeAlpha = 1;
  3012. this.lineWidth = 1;
  3013. this.activeSMask = null; // nonclonable field (see the save method below)
  3014. this.old = old;
  3015. }
  3016. CanvasExtraState.prototype = {
  3017. clone: function CanvasExtraState_clone() {
  3018. return Object.create(this);
  3019. },
  3020. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3021. this.x = x;
  3022. this.y = y;
  3023. }
  3024. };
  3025. return CanvasExtraState;
  3026. })();
  3027. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3028. // Defines the time the executeOperatorList is going to be executing
  3029. // before it stops and shedules a continue of execution.
  3030. var EXECUTION_TIME = 15;
  3031. // Defines the number of steps before checking the execution time
  3032. var EXECUTION_STEPS = 10;
  3033. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3034. this.ctx = canvasCtx;
  3035. this.current = new CanvasExtraState();
  3036. this.stateStack = [];
  3037. this.pendingClip = null;
  3038. this.pendingEOFill = false;
  3039. this.res = null;
  3040. this.xobjs = null;
  3041. this.commonObjs = commonObjs;
  3042. this.objs = objs;
  3043. this.imageLayer = imageLayer;
  3044. this.groupStack = [];
  3045. this.processingType3 = null;
  3046. // Patterns are painted relative to the initial page/form transform, see pdf
  3047. // spec 8.7.2 NOTE 1.
  3048. this.baseTransform = null;
  3049. this.baseTransformStack = [];
  3050. this.groupLevel = 0;
  3051. this.smaskStack = [];
  3052. this.smaskCounter = 0;
  3053. this.tempSMask = null;
  3054. if (canvasCtx) {
  3055. addContextCurrentTransform(canvasCtx);
  3056. }
  3057. }
  3058. function putBinaryImageData(ctx, imgData) {
  3059. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3060. ctx.putImageData(imgData, 0, 0);
  3061. return;
  3062. }
  3063. // Put the image data to the canvas in chunks, rather than putting the
  3064. // whole image at once. This saves JS memory, because the ImageData object
  3065. // is smaller. It also possibly saves C++ memory within the implementation
  3066. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3067. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3068. // because too many putImageData() calls will slow things down.
  3069. //
  3070. // Note: as written, if the last chunk is partial, the putImageData() call
  3071. // will (conceptually) put pixels past the bounds of the canvas. But
  3072. // that's ok; any such pixels are ignored.
  3073. var height = imgData.height, width = imgData.width;
  3074. var fullChunkHeight = 16;
  3075. var fracChunks = height / fullChunkHeight;
  3076. var fullChunks = Math.floor(fracChunks);
  3077. var totalChunks = Math.ceil(fracChunks);
  3078. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3079. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3080. var srcPos = 0, destPos;
  3081. var src = imgData.data;
  3082. var dest = chunkImgData.data;
  3083. var i, j, thisChunkHeight, elemsInThisChunk;
  3084. // There are multiple forms in which the pixel data can be passed, and
  3085. // imgData.kind tells us which one this is.
  3086. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3087. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3088. var srcLength = src.byteLength;
  3089. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3090. new Uint32ArrayView(dest);
  3091. var dest32DataLength = dest32.length;
  3092. var fullSrcDiff = (width + 7) >> 3;
  3093. var white = 0xFFFFFFFF;
  3094. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3095. 0xFF000000 : 0x000000FF;
  3096. for (i = 0; i < totalChunks; i++) {
  3097. thisChunkHeight =
  3098. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3099. destPos = 0;
  3100. for (j = 0; j < thisChunkHeight; j++) {
  3101. var srcDiff = srcLength - srcPos;
  3102. var k = 0;
  3103. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3104. var kEndUnrolled = kEnd & ~7;
  3105. var mask = 0;
  3106. var srcByte = 0;
  3107. for (; k < kEndUnrolled; k += 8) {
  3108. srcByte = src[srcPos++];
  3109. dest32[destPos++] = (srcByte & 128) ? white : black;
  3110. dest32[destPos++] = (srcByte & 64) ? white : black;
  3111. dest32[destPos++] = (srcByte & 32) ? white : black;
  3112. dest32[destPos++] = (srcByte & 16) ? white : black;
  3113. dest32[destPos++] = (srcByte & 8) ? white : black;
  3114. dest32[destPos++] = (srcByte & 4) ? white : black;
  3115. dest32[destPos++] = (srcByte & 2) ? white : black;
  3116. dest32[destPos++] = (srcByte & 1) ? white : black;
  3117. }
  3118. for (; k < kEnd; k++) {
  3119. if (mask === 0) {
  3120. srcByte = src[srcPos++];
  3121. mask = 128;
  3122. }
  3123. dest32[destPos++] = (srcByte & mask) ? white : black;
  3124. mask >>= 1;
  3125. }
  3126. }
  3127. // We ran out of input. Make all remaining pixels transparent.
  3128. while (destPos < dest32DataLength) {
  3129. dest32[destPos++] = 0;
  3130. }
  3131. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3132. }
  3133. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3134. // RGBA, 32-bits per pixel.
  3135. j = 0;
  3136. elemsInThisChunk = width * fullChunkHeight * 4;
  3137. for (i = 0; i < fullChunks; i++) {
  3138. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3139. srcPos += elemsInThisChunk;
  3140. ctx.putImageData(chunkImgData, 0, j);
  3141. j += fullChunkHeight;
  3142. }
  3143. if (i < totalChunks) {
  3144. elemsInThisChunk = width * partialChunkHeight * 4;
  3145. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3146. ctx.putImageData(chunkImgData, 0, j);
  3147. }
  3148. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3149. // RGB, 24-bits per pixel.
  3150. thisChunkHeight = fullChunkHeight;
  3151. elemsInThisChunk = width * thisChunkHeight;
  3152. for (i = 0; i < totalChunks; i++) {
  3153. if (i >= fullChunks) {
  3154. thisChunkHeight =partialChunkHeight;
  3155. elemsInThisChunk = width * thisChunkHeight;
  3156. }
  3157. destPos = 0;
  3158. for (j = elemsInThisChunk; j--;) {
  3159. dest[destPos++] = src[srcPos++];
  3160. dest[destPos++] = src[srcPos++];
  3161. dest[destPos++] = src[srcPos++];
  3162. dest[destPos++] = 255;
  3163. }
  3164. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3165. }
  3166. } else {
  3167. error('bad image kind: ' + imgData.kind);
  3168. }
  3169. }
  3170. function putBinaryImageMask(ctx, imgData) {
  3171. var height = imgData.height, width = imgData.width;
  3172. var fullChunkHeight = 16;
  3173. var fracChunks = height / fullChunkHeight;
  3174. var fullChunks = Math.floor(fracChunks);
  3175. var totalChunks = Math.ceil(fracChunks);
  3176. var partialChunkHeight = height - fullChunks * fullChunkHeight;
  3177. var chunkImgData = ctx.createImageData(width, fullChunkHeight);
  3178. var srcPos = 0;
  3179. var src = imgData.data;
  3180. var dest = chunkImgData.data;
  3181. for (var i = 0; i < totalChunks; i++) {
  3182. var thisChunkHeight =
  3183. (i < fullChunks) ? fullChunkHeight : partialChunkHeight;
  3184. // Expand the mask so it can be used by the canvas. Any required
  3185. // inversion has already been handled.
  3186. var destPos = 3; // alpha component offset
  3187. for (var j = 0; j < thisChunkHeight; j++) {
  3188. var mask = 0;
  3189. for (var k = 0; k < width; k++) {
  3190. if (!mask) {
  3191. var elem = src[srcPos++];
  3192. mask = 128;
  3193. }
  3194. dest[destPos] = (elem & mask) ? 0 : 255;
  3195. destPos += 4;
  3196. mask >>= 1;
  3197. }
  3198. }
  3199. ctx.putImageData(chunkImgData, 0, i * fullChunkHeight);
  3200. }
  3201. }
  3202. function copyCtxState(sourceCtx, destCtx) {
  3203. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3204. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3205. 'globalCompositeOperation', 'font'];
  3206. for (var i = 0, ii = properties.length; i < ii; i++) {
  3207. var property = properties[i];
  3208. if (property in sourceCtx) {
  3209. destCtx[property] = sourceCtx[property];
  3210. }
  3211. }
  3212. if ('setLineDash' in sourceCtx) {
  3213. destCtx.setLineDash(sourceCtx.getLineDash());
  3214. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3215. } else if ('mozDash' in sourceCtx) {
  3216. destCtx.mozDash = sourceCtx.mozDash;
  3217. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3218. }
  3219. }
  3220. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3221. var length = bytes.length;
  3222. for (var i = 3; i < length; i += 4) {
  3223. var alpha = bytes[i];
  3224. if (alpha === 0) {
  3225. bytes[i - 3] = r0;
  3226. bytes[i - 2] = g0;
  3227. bytes[i - 1] = b0;
  3228. } else if (alpha < 255) {
  3229. var alpha_ = 255 - alpha;
  3230. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3231. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3232. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3233. }
  3234. }
  3235. }
  3236. function composeSMaskAlpha(maskData, layerData) {
  3237. var length = maskData.length;
  3238. var scale = 1 / 255;
  3239. for (var i = 3; i < length; i += 4) {
  3240. var alpha = maskData[i];
  3241. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3242. }
  3243. }
  3244. function composeSMaskLuminosity(maskData, layerData) {
  3245. var length = maskData.length;
  3246. for (var i = 3; i < length; i += 4) {
  3247. var y = ((maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3248. (maskData[i - 2] * 152) + // * 0.59 ....
  3249. (maskData[i - 1] * 28)) | 0; // * 0.11 ....
  3250. layerData[i] = (layerData[i] * y) >> 16;
  3251. }
  3252. }
  3253. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3254. subtype, backdrop) {
  3255. var hasBackdrop = !!backdrop;
  3256. var r0 = hasBackdrop ? backdrop[0] : 0;
  3257. var g0 = hasBackdrop ? backdrop[1] : 0;
  3258. var b0 = hasBackdrop ? backdrop[2] : 0;
  3259. var composeFn;
  3260. if (subtype === 'Luminosity') {
  3261. composeFn = composeSMaskLuminosity;
  3262. } else {
  3263. composeFn = composeSMaskAlpha;
  3264. }
  3265. // processing image in chunks to save memory
  3266. var PIXELS_TO_PROCESS = 65536;
  3267. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3268. for (var row = 0; row < height; row += chunkSize) {
  3269. var chunkHeight = Math.min(chunkSize, height - row);
  3270. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3271. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3272. if (hasBackdrop) {
  3273. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3274. }
  3275. composeFn(maskData.data, layerData.data);
  3276. maskCtx.putImageData(layerData, 0, row);
  3277. }
  3278. }
  3279. function composeSMask(ctx, smask, layerCtx) {
  3280. var mask = smask.canvas;
  3281. var maskCtx = smask.context;
  3282. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3283. smask.offsetX, smask.offsetY);
  3284. var backdrop = smask.backdrop || null;
  3285. if (WebGLUtils.isEnabled) {
  3286. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3287. {subtype: smask.subtype, backdrop: backdrop});
  3288. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3289. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3290. return;
  3291. }
  3292. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3293. smask.subtype, backdrop);
  3294. ctx.drawImage(mask, 0, 0);
  3295. }
  3296. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3297. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3298. var NORMAL_CLIP = {};
  3299. var EO_CLIP = {};
  3300. CanvasGraphics.prototype = {
  3301. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3302. // For pdfs that use blend modes we have to clear the canvas else certain
  3303. // blend modes can look wrong since we'd be blending with a white
  3304. // backdrop. The problem with a transparent backdrop though is we then
  3305. // don't get sub pixel anti aliasing on text, so we fill with white if
  3306. // we can.
  3307. var width = this.ctx.canvas.width;
  3308. var height = this.ctx.canvas.height;
  3309. if (transparency) {
  3310. this.ctx.clearRect(0, 0, width, height);
  3311. } else {
  3312. this.ctx.mozOpaque = true;
  3313. this.ctx.save();
  3314. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3315. this.ctx.fillRect(0, 0, width, height);
  3316. this.ctx.restore();
  3317. }
  3318. var transform = viewport.transform;
  3319. this.ctx.save();
  3320. this.ctx.transform.apply(this.ctx, transform);
  3321. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3322. if (this.imageLayer) {
  3323. this.imageLayer.beginLayout();
  3324. }
  3325. },
  3326. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3327. operatorList,
  3328. executionStartIdx, continueCallback,
  3329. stepper) {
  3330. var argsArray = operatorList.argsArray;
  3331. var fnArray = operatorList.fnArray;
  3332. var i = executionStartIdx || 0;
  3333. var argsArrayLen = argsArray.length;
  3334. // Sometimes the OperatorList to execute is empty.
  3335. if (argsArrayLen === i) {
  3336. return i;
  3337. }
  3338. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3339. typeof continueCallback === 'function');
  3340. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3341. var steps = 0;
  3342. var commonObjs = this.commonObjs;
  3343. var objs = this.objs;
  3344. var fnId;
  3345. while (true) {
  3346. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3347. stepper.breakIt(i, continueCallback);
  3348. return i;
  3349. }
  3350. fnId = fnArray[i];
  3351. if (fnId !== OPS.dependency) {
  3352. this[fnId].apply(this, argsArray[i]);
  3353. } else {
  3354. var deps = argsArray[i];
  3355. for (var n = 0, nn = deps.length; n < nn; n++) {
  3356. var depObjId = deps[n];
  3357. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3358. var objsPool = common ? commonObjs : objs;
  3359. // If the promise isn't resolved yet, add the continueCallback
  3360. // to the promise and bail out.
  3361. if (!objsPool.isResolved(depObjId)) {
  3362. objsPool.get(depObjId, continueCallback);
  3363. return i;
  3364. }
  3365. }
  3366. }
  3367. i++;
  3368. // If the entire operatorList was executed, stop as were done.
  3369. if (i === argsArrayLen) {
  3370. return i;
  3371. }
  3372. // If the execution took longer then a certain amount of time and
  3373. // `continueCallback` is specified, interrupt the execution.
  3374. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3375. if (Date.now() > endTime) {
  3376. continueCallback();
  3377. return i;
  3378. }
  3379. steps = 0;
  3380. }
  3381. // If the operatorList isn't executed completely yet OR the execution
  3382. // time was short enough, do another execution round.
  3383. }
  3384. },
  3385. endDrawing: function CanvasGraphics_endDrawing() {
  3386. this.ctx.restore();
  3387. CachedCanvases.clear();
  3388. WebGLUtils.clear();
  3389. if (this.imageLayer) {
  3390. this.imageLayer.endLayout();
  3391. }
  3392. },
  3393. // Graphics state
  3394. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3395. this.current.lineWidth = width;
  3396. this.ctx.lineWidth = width;
  3397. },
  3398. setLineCap: function CanvasGraphics_setLineCap(style) {
  3399. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3400. },
  3401. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3402. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3403. },
  3404. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3405. this.ctx.miterLimit = limit;
  3406. },
  3407. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3408. var ctx = this.ctx;
  3409. if ('setLineDash' in ctx) {
  3410. ctx.setLineDash(dashArray);
  3411. ctx.lineDashOffset = dashPhase;
  3412. } else {
  3413. ctx.mozDash = dashArray;
  3414. ctx.mozDashOffset = dashPhase;
  3415. }
  3416. },
  3417. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3418. // Maybe if we one day fully support color spaces this will be important
  3419. // for now we can ignore.
  3420. // TODO set rendering intent?
  3421. },
  3422. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3423. // There's no way to control this with canvas, but we can safely ignore.
  3424. // TODO set flatness?
  3425. },
  3426. setGState: function CanvasGraphics_setGState(states) {
  3427. for (var i = 0, ii = states.length; i < ii; i++) {
  3428. var state = states[i];
  3429. var key = state[0];
  3430. var value = state[1];
  3431. switch (key) {
  3432. case 'LW':
  3433. this.setLineWidth(value);
  3434. break;
  3435. case 'LC':
  3436. this.setLineCap(value);
  3437. break;
  3438. case 'LJ':
  3439. this.setLineJoin(value);
  3440. break;
  3441. case 'ML':
  3442. this.setMiterLimit(value);
  3443. break;
  3444. case 'D':
  3445. this.setDash(value[0], value[1]);
  3446. break;
  3447. case 'RI':
  3448. this.setRenderingIntent(value);
  3449. break;
  3450. case 'FL':
  3451. this.setFlatness(value);
  3452. break;
  3453. case 'Font':
  3454. this.setFont(value[0], value[1]);
  3455. break;
  3456. case 'CA':
  3457. this.current.strokeAlpha = state[1];
  3458. break;
  3459. case 'ca':
  3460. this.current.fillAlpha = state[1];
  3461. this.ctx.globalAlpha = state[1];
  3462. break;
  3463. case 'BM':
  3464. if (value && value.name && (value.name !== 'Normal')) {
  3465. var mode = value.name.replace(/([A-Z])/g,
  3466. function(c) {
  3467. return '-' + c.toLowerCase();
  3468. }
  3469. ).substring(1);
  3470. this.ctx.globalCompositeOperation = mode;
  3471. if (this.ctx.globalCompositeOperation !== mode) {
  3472. warn('globalCompositeOperation "' + mode +
  3473. '" is not supported');
  3474. }
  3475. } else {
  3476. this.ctx.globalCompositeOperation = 'source-over';
  3477. }
  3478. break;
  3479. case 'SMask':
  3480. if (this.current.activeSMask) {
  3481. this.endSMaskGroup();
  3482. }
  3483. this.current.activeSMask = value ? this.tempSMask : null;
  3484. if (this.current.activeSMask) {
  3485. this.beginSMaskGroup();
  3486. }
  3487. this.tempSMask = null;
  3488. break;
  3489. }
  3490. }
  3491. },
  3492. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3493. var activeSMask = this.current.activeSMask;
  3494. var drawnWidth = activeSMask.canvas.width;
  3495. var drawnHeight = activeSMask.canvas.height;
  3496. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3497. var scratchCanvas = CachedCanvases.getCanvas(
  3498. cacheId, drawnWidth, drawnHeight, true);
  3499. var currentCtx = this.ctx;
  3500. var currentTransform = currentCtx.mozCurrentTransform;
  3501. this.ctx.save();
  3502. var groupCtx = scratchCanvas.context;
  3503. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3504. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3505. groupCtx.transform.apply(groupCtx, currentTransform);
  3506. copyCtxState(currentCtx, groupCtx);
  3507. this.ctx = groupCtx;
  3508. this.setGState([
  3509. ['BM', 'Normal'],
  3510. ['ca', 1],
  3511. ['CA', 1]
  3512. ]);
  3513. this.groupStack.push(currentCtx);
  3514. this.groupLevel++;
  3515. },
  3516. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3517. var groupCtx = this.ctx;
  3518. this.groupLevel--;
  3519. this.ctx = this.groupStack.pop();
  3520. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3521. this.ctx.restore();
  3522. },
  3523. save: function CanvasGraphics_save() {
  3524. this.ctx.save();
  3525. var old = this.current;
  3526. this.stateStack.push(old);
  3527. this.current = old.clone();
  3528. this.current.activeSMask = null;
  3529. },
  3530. restore: function CanvasGraphics_restore() {
  3531. if (this.stateStack.length !== 0) {
  3532. if (this.current.activeSMask !== null) {
  3533. this.endSMaskGroup();
  3534. }
  3535. this.current = this.stateStack.pop();
  3536. this.ctx.restore();
  3537. }
  3538. },
  3539. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3540. this.ctx.transform(a, b, c, d, e, f);
  3541. },
  3542. // Path
  3543. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3544. var ctx = this.ctx;
  3545. var current = this.current;
  3546. var x = current.x, y = current.y;
  3547. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3548. switch (ops[i] | 0) {
  3549. case OPS.rectangle:
  3550. x = args[j++];
  3551. y = args[j++];
  3552. var width = args[j++];
  3553. var height = args[j++];
  3554. if (width === 0) {
  3555. width = this.getSinglePixelWidth();
  3556. }
  3557. if (height === 0) {
  3558. height = this.getSinglePixelWidth();
  3559. }
  3560. var xw = x + width;
  3561. var yh = y + height;
  3562. this.ctx.moveTo(x, y);
  3563. this.ctx.lineTo(xw, y);
  3564. this.ctx.lineTo(xw, yh);
  3565. this.ctx.lineTo(x, yh);
  3566. this.ctx.lineTo(x, y);
  3567. this.ctx.closePath();
  3568. break;
  3569. case OPS.moveTo:
  3570. x = args[j++];
  3571. y = args[j++];
  3572. ctx.moveTo(x, y);
  3573. break;
  3574. case OPS.lineTo:
  3575. x = args[j++];
  3576. y = args[j++];
  3577. ctx.lineTo(x, y);
  3578. break;
  3579. case OPS.curveTo:
  3580. x = args[j + 4];
  3581. y = args[j + 5];
  3582. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3583. x, y);
  3584. j += 6;
  3585. break;
  3586. case OPS.curveTo2:
  3587. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3588. args[j + 2], args[j + 3]);
  3589. x = args[j + 2];
  3590. y = args[j + 3];
  3591. j += 4;
  3592. break;
  3593. case OPS.curveTo3:
  3594. x = args[j + 2];
  3595. y = args[j + 3];
  3596. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3597. j += 4;
  3598. break;
  3599. case OPS.closePath:
  3600. ctx.closePath();
  3601. break;
  3602. }
  3603. }
  3604. current.setCurrentPoint(x, y);
  3605. },
  3606. closePath: function CanvasGraphics_closePath() {
  3607. this.ctx.closePath();
  3608. },
  3609. stroke: function CanvasGraphics_stroke(consumePath) {
  3610. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3611. var ctx = this.ctx;
  3612. var strokeColor = this.current.strokeColor;
  3613. if (this.current.lineWidth === 0) {
  3614. ctx.lineWidth = this.getSinglePixelWidth();
  3615. }
  3616. // For stroke we want to temporarily change the global alpha to the
  3617. // stroking alpha.
  3618. ctx.globalAlpha = this.current.strokeAlpha;
  3619. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3620. strokeColor.type === 'Pattern') {
  3621. // for patterns, we transform to pattern space, calculate
  3622. // the pattern, call stroke, and restore to user space
  3623. ctx.save();
  3624. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3625. ctx.stroke();
  3626. ctx.restore();
  3627. } else {
  3628. ctx.stroke();
  3629. }
  3630. if (consumePath) {
  3631. this.consumePath();
  3632. }
  3633. // Restore the global alpha to the fill alpha
  3634. ctx.globalAlpha = this.current.fillAlpha;
  3635. },
  3636. closeStroke: function CanvasGraphics_closeStroke() {
  3637. this.closePath();
  3638. this.stroke();
  3639. },
  3640. fill: function CanvasGraphics_fill(consumePath) {
  3641. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3642. var ctx = this.ctx;
  3643. var fillColor = this.current.fillColor;
  3644. var needRestore = false;
  3645. if (fillColor && fillColor.hasOwnProperty('type') &&
  3646. fillColor.type === 'Pattern') {
  3647. ctx.save();
  3648. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3649. needRestore = true;
  3650. }
  3651. if (this.pendingEOFill) {
  3652. if (ctx.mozFillRule !== undefined) {
  3653. ctx.mozFillRule = 'evenodd';
  3654. ctx.fill();
  3655. ctx.mozFillRule = 'nonzero';
  3656. } else {
  3657. try {
  3658. ctx.fill('evenodd');
  3659. } catch (ex) {
  3660. // shouldn't really happen, but browsers might think differently
  3661. ctx.fill();
  3662. }
  3663. }
  3664. this.pendingEOFill = false;
  3665. } else {
  3666. ctx.fill();
  3667. }
  3668. if (needRestore) {
  3669. ctx.restore();
  3670. }
  3671. if (consumePath) {
  3672. this.consumePath();
  3673. }
  3674. },
  3675. eoFill: function CanvasGraphics_eoFill() {
  3676. this.pendingEOFill = true;
  3677. this.fill();
  3678. },
  3679. fillStroke: function CanvasGraphics_fillStroke() {
  3680. this.fill(false);
  3681. this.stroke(false);
  3682. this.consumePath();
  3683. },
  3684. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3685. this.pendingEOFill = true;
  3686. this.fillStroke();
  3687. },
  3688. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3689. this.closePath();
  3690. this.fillStroke();
  3691. },
  3692. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3693. this.pendingEOFill = true;
  3694. this.closePath();
  3695. this.fillStroke();
  3696. },
  3697. endPath: function CanvasGraphics_endPath() {
  3698. this.consumePath();
  3699. },
  3700. // Clipping
  3701. clip: function CanvasGraphics_clip() {
  3702. this.pendingClip = NORMAL_CLIP;
  3703. },
  3704. eoClip: function CanvasGraphics_eoClip() {
  3705. this.pendingClip = EO_CLIP;
  3706. },
  3707. // Text
  3708. beginText: function CanvasGraphics_beginText() {
  3709. this.current.textMatrix = IDENTITY_MATRIX;
  3710. this.current.textMatrixScale = 1;
  3711. this.current.x = this.current.lineX = 0;
  3712. this.current.y = this.current.lineY = 0;
  3713. },
  3714. endText: function CanvasGraphics_endText() {
  3715. var paths = this.pendingTextPaths;
  3716. var ctx = this.ctx;
  3717. if (paths === undefined) {
  3718. ctx.beginPath();
  3719. return;
  3720. }
  3721. ctx.save();
  3722. ctx.beginPath();
  3723. for (var i = 0; i < paths.length; i++) {
  3724. var path = paths[i];
  3725. ctx.setTransform.apply(ctx, path.transform);
  3726. ctx.translate(path.x, path.y);
  3727. path.addToPath(ctx, path.fontSize);
  3728. }
  3729. ctx.restore();
  3730. ctx.clip();
  3731. ctx.beginPath();
  3732. delete this.pendingTextPaths;
  3733. },
  3734. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3735. this.current.charSpacing = spacing;
  3736. },
  3737. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3738. this.current.wordSpacing = spacing;
  3739. },
  3740. setHScale: function CanvasGraphics_setHScale(scale) {
  3741. this.current.textHScale = scale / 100;
  3742. },
  3743. setLeading: function CanvasGraphics_setLeading(leading) {
  3744. this.current.leading = -leading;
  3745. },
  3746. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3747. var fontObj = this.commonObjs.get(fontRefName);
  3748. var current = this.current;
  3749. if (!fontObj) {
  3750. error('Can\'t find font for ' + fontRefName);
  3751. }
  3752. current.fontMatrix = (fontObj.fontMatrix ?
  3753. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3754. // A valid matrix needs all main diagonal elements to be non-zero
  3755. // This also ensures we bypass FF bugzilla bug #719844.
  3756. if (current.fontMatrix[0] === 0 ||
  3757. current.fontMatrix[3] === 0) {
  3758. warn('Invalid font matrix for font ' + fontRefName);
  3759. }
  3760. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  3761. // and in some docs this can be negative (inverted x-y axes).
  3762. if (size < 0) {
  3763. size = -size;
  3764. current.fontDirection = -1;
  3765. } else {
  3766. current.fontDirection = 1;
  3767. }
  3768. this.current.font = fontObj;
  3769. this.current.fontSize = size;
  3770. if (fontObj.isType3Font) {
  3771. return; // we don't need ctx.font for Type3 fonts
  3772. }
  3773. var name = fontObj.loadedName || 'sans-serif';
  3774. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  3775. (fontObj.bold ? 'bold' : 'normal');
  3776. var italic = fontObj.italic ? 'italic' : 'normal';
  3777. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  3778. // Some font backends cannot handle fonts below certain size.
  3779. // Keeping the font at minimal size and using the fontSizeScale to change
  3780. // the current transformation matrix before the fillText/strokeText.
  3781. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  3782. var browserFontSize = size >= MIN_FONT_SIZE ? size : MIN_FONT_SIZE;
  3783. this.current.fontSizeScale = browserFontSize !== MIN_FONT_SIZE ? 1.0 :
  3784. size / MIN_FONT_SIZE;
  3785. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  3786. this.ctx.font = rule;
  3787. },
  3788. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  3789. this.current.textRenderingMode = mode;
  3790. },
  3791. setTextRise: function CanvasGraphics_setTextRise(rise) {
  3792. this.current.textRise = rise;
  3793. },
  3794. moveText: function CanvasGraphics_moveText(x, y) {
  3795. this.current.x = this.current.lineX += x;
  3796. this.current.y = this.current.lineY += y;
  3797. },
  3798. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  3799. this.setLeading(-y);
  3800. this.moveText(x, y);
  3801. },
  3802. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  3803. this.current.textMatrix = [a, b, c, d, e, f];
  3804. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  3805. this.current.x = this.current.lineX = 0;
  3806. this.current.y = this.current.lineY = 0;
  3807. },
  3808. nextLine: function CanvasGraphics_nextLine() {
  3809. this.moveText(0, this.current.leading);
  3810. },
  3811. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  3812. var ctx = this.ctx;
  3813. var current = this.current;
  3814. var font = current.font;
  3815. var textRenderingMode = current.textRenderingMode;
  3816. var fontSize = current.fontSize / current.fontSizeScale;
  3817. var fillStrokeMode = textRenderingMode &
  3818. TextRenderingMode.FILL_STROKE_MASK;
  3819. var isAddToPathSet = !!(textRenderingMode &
  3820. TextRenderingMode.ADD_TO_PATH_FLAG);
  3821. var addToPath;
  3822. if (font.disableFontFace || isAddToPathSet) {
  3823. addToPath = font.getPathGenerator(this.commonObjs, character);
  3824. }
  3825. if (font.disableFontFace) {
  3826. ctx.save();
  3827. ctx.translate(x, y);
  3828. ctx.beginPath();
  3829. addToPath(ctx, fontSize);
  3830. if (fillStrokeMode === TextRenderingMode.FILL ||
  3831. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3832. ctx.fill();
  3833. }
  3834. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3835. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3836. ctx.stroke();
  3837. }
  3838. ctx.restore();
  3839. } else {
  3840. if (fillStrokeMode === TextRenderingMode.FILL ||
  3841. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3842. ctx.fillText(character, x, y);
  3843. }
  3844. if (fillStrokeMode === TextRenderingMode.STROKE ||
  3845. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  3846. ctx.strokeText(character, x, y);
  3847. }
  3848. }
  3849. if (isAddToPathSet) {
  3850. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  3851. paths.push({
  3852. transform: ctx.mozCurrentTransform,
  3853. x: x,
  3854. y: y,
  3855. fontSize: fontSize,
  3856. addToPath: addToPath
  3857. });
  3858. }
  3859. },
  3860. get isFontSubpixelAAEnabled() {
  3861. // Checks if anti-aliasing is enabled when scaled text is painted.
  3862. // On Windows GDI scaled fonts looks bad.
  3863. var ctx = document.createElement('canvas').getContext('2d');
  3864. ctx.scale(1.5, 1);
  3865. ctx.fillText('I', 0, 10);
  3866. var data = ctx.getImageData(0, 0, 10, 10).data;
  3867. var enabled = false;
  3868. for (var i = 3; i < data.length; i += 4) {
  3869. if (data[i] > 0 && data[i] < 255) {
  3870. enabled = true;
  3871. break;
  3872. }
  3873. }
  3874. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  3875. },
  3876. showText: function CanvasGraphics_showText(glyphs) {
  3877. var current = this.current;
  3878. var font = current.font;
  3879. if (font.isType3Font) {
  3880. return this.showType3Text(glyphs);
  3881. }
  3882. var fontSize = current.fontSize;
  3883. if (fontSize === 0) {
  3884. return;
  3885. }
  3886. var ctx = this.ctx;
  3887. var fontSizeScale = current.fontSizeScale;
  3888. var charSpacing = current.charSpacing;
  3889. var wordSpacing = current.wordSpacing;
  3890. var fontDirection = current.fontDirection;
  3891. var textHScale = current.textHScale * fontDirection;
  3892. var glyphsLength = glyphs.length;
  3893. var vertical = font.vertical;
  3894. var defaultVMetrics = font.defaultVMetrics;
  3895. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  3896. var simpleFillText =
  3897. current.textRenderingMode === TextRenderingMode.FILL &&
  3898. !font.disableFontFace;
  3899. ctx.save();
  3900. ctx.transform.apply(ctx, current.textMatrix);
  3901. ctx.translate(current.x, current.y + current.textRise);
  3902. if (fontDirection > 0) {
  3903. ctx.scale(textHScale, -1);
  3904. } else {
  3905. ctx.scale(textHScale, 1);
  3906. }
  3907. var lineWidth = current.lineWidth;
  3908. var scale = current.textMatrixScale;
  3909. if (scale === 0 || lineWidth === 0) {
  3910. lineWidth = this.getSinglePixelWidth();
  3911. } else {
  3912. lineWidth /= scale;
  3913. }
  3914. if (fontSizeScale !== 1.0) {
  3915. ctx.scale(fontSizeScale, fontSizeScale);
  3916. lineWidth /= fontSizeScale;
  3917. }
  3918. ctx.lineWidth = lineWidth;
  3919. var x = 0, i;
  3920. for (i = 0; i < glyphsLength; ++i) {
  3921. var glyph = glyphs[i];
  3922. if (glyph === null) {
  3923. // word break
  3924. x += fontDirection * wordSpacing;
  3925. continue;
  3926. } else if (isNum(glyph)) {
  3927. x += -glyph * fontSize * 0.001;
  3928. continue;
  3929. }
  3930. var restoreNeeded = false;
  3931. var character = glyph.fontChar;
  3932. var accent = glyph.accent;
  3933. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  3934. var width = glyph.width;
  3935. if (vertical) {
  3936. var vmetric, vx, vy;
  3937. vmetric = glyph.vmetric || defaultVMetrics;
  3938. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  3939. vx = -vx * widthAdvanceScale;
  3940. vy = vmetric[2] * widthAdvanceScale;
  3941. width = vmetric ? -vmetric[0] : width;
  3942. scaledX = vx / fontSizeScale;
  3943. scaledY = (x + vy) / fontSizeScale;
  3944. } else {
  3945. scaledX = x / fontSizeScale;
  3946. scaledY = 0;
  3947. }
  3948. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  3949. // some standard fonts may not have the exact width, trying to
  3950. // rescale per character
  3951. var measuredWidth = ctx.measureText(character).width * 1000 /
  3952. fontSize * fontSizeScale;
  3953. var characterScaleX = width / measuredWidth;
  3954. restoreNeeded = true;
  3955. ctx.save();
  3956. ctx.scale(characterScaleX, 1);
  3957. scaledX /= characterScaleX;
  3958. }
  3959. if (simpleFillText && !accent) {
  3960. // common case
  3961. ctx.fillText(character, scaledX, scaledY);
  3962. } else {
  3963. this.paintChar(character, scaledX, scaledY);
  3964. if (accent) {
  3965. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  3966. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  3967. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  3968. }
  3969. }
  3970. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  3971. x += charWidth;
  3972. if (restoreNeeded) {
  3973. ctx.restore();
  3974. }
  3975. }
  3976. if (vertical) {
  3977. current.y -= x * textHScale;
  3978. } else {
  3979. current.x += x * textHScale;
  3980. }
  3981. ctx.restore();
  3982. },
  3983. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  3984. // Type3 fonts - each glyph is a "mini-PDF"
  3985. var ctx = this.ctx;
  3986. var current = this.current;
  3987. var font = current.font;
  3988. var fontSize = current.fontSize;
  3989. var fontDirection = current.fontDirection;
  3990. var charSpacing = current.charSpacing;
  3991. var wordSpacing = current.wordSpacing;
  3992. var textHScale = current.textHScale * fontDirection;
  3993. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  3994. var glyphsLength = glyphs.length;
  3995. var i, glyph, width;
  3996. if (fontSize === 0) {
  3997. return;
  3998. }
  3999. ctx.save();
  4000. ctx.transform.apply(ctx, current.textMatrix);
  4001. ctx.translate(current.x, current.y);
  4002. ctx.scale(textHScale, 1);
  4003. for (i = 0; i < glyphsLength; ++i) {
  4004. glyph = glyphs[i];
  4005. if (glyph === null) {
  4006. // word break
  4007. this.ctx.translate(wordSpacing, 0);
  4008. current.x += wordSpacing * textHScale;
  4009. continue;
  4010. } else if (isNum(glyph)) {
  4011. var spacingLength = -glyph * 0.001 * fontSize;
  4012. this.ctx.translate(spacingLength, 0);
  4013. current.x += spacingLength * textHScale;
  4014. continue;
  4015. }
  4016. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4017. if (!operatorList) {
  4018. warn('Type3 character \"' + glyph.operatorListId +
  4019. '\" is not available');
  4020. continue;
  4021. }
  4022. this.processingType3 = glyph;
  4023. this.save();
  4024. ctx.scale(fontSize, fontSize);
  4025. ctx.transform.apply(ctx, fontMatrix);
  4026. this.executeOperatorList(operatorList);
  4027. this.restore();
  4028. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4029. width = ((transformed[0] * fontSize + charSpacing) * fontDirection);
  4030. ctx.translate(width, 0);
  4031. current.x += width * textHScale;
  4032. }
  4033. ctx.restore();
  4034. this.processingType3 = null;
  4035. },
  4036. // Type3 fonts
  4037. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4038. // We can safely ignore this since the width should be the same
  4039. // as the width in the Widths array.
  4040. },
  4041. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4042. yWidth,
  4043. llx,
  4044. lly,
  4045. urx,
  4046. ury) {
  4047. // TODO According to the spec we're also suppose to ignore any operators
  4048. // that set color or include images while processing this type3 font.
  4049. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4050. this.clip();
  4051. this.endPath();
  4052. },
  4053. // Color
  4054. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4055. var pattern;
  4056. if (IR[0] === 'TilingPattern') {
  4057. var color = IR[1];
  4058. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4059. this.commonObjs, this.baseTransform);
  4060. } else {
  4061. pattern = getShadingPatternFromIR(IR);
  4062. }
  4063. return pattern;
  4064. },
  4065. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4066. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4067. },
  4068. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4069. this.current.fillColor = this.getColorN_Pattern(arguments);
  4070. },
  4071. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4072. var color = Util.makeCssRgb(arguments);
  4073. this.ctx.strokeStyle = color;
  4074. this.current.strokeColor = color;
  4075. },
  4076. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4077. var color = Util.makeCssRgb(arguments);
  4078. this.ctx.fillStyle = color;
  4079. this.current.fillColor = color;
  4080. },
  4081. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4082. var ctx = this.ctx;
  4083. this.save();
  4084. var pattern = getShadingPatternFromIR(patternIR);
  4085. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4086. var inv = ctx.mozCurrentTransformInverse;
  4087. if (inv) {
  4088. var canvas = ctx.canvas;
  4089. var width = canvas.width;
  4090. var height = canvas.height;
  4091. var bl = Util.applyTransform([0, 0], inv);
  4092. var br = Util.applyTransform([0, height], inv);
  4093. var ul = Util.applyTransform([width, 0], inv);
  4094. var ur = Util.applyTransform([width, height], inv);
  4095. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4096. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4097. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4098. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4099. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4100. } else {
  4101. // HACK to draw the gradient onto an infinite rectangle.
  4102. // PDF gradients are drawn across the entire image while
  4103. // Canvas only allows gradients to be drawn in a rectangle
  4104. // The following bug should allow us to remove this.
  4105. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4106. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4107. }
  4108. this.restore();
  4109. },
  4110. // Images
  4111. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4112. error('Should not call beginInlineImage');
  4113. },
  4114. beginImageData: function CanvasGraphics_beginImageData() {
  4115. error('Should not call beginImageData');
  4116. },
  4117. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4118. bbox) {
  4119. this.save();
  4120. this.baseTransformStack.push(this.baseTransform);
  4121. if (isArray(matrix) && 6 === matrix.length) {
  4122. this.transform.apply(this, matrix);
  4123. }
  4124. this.baseTransform = this.ctx.mozCurrentTransform;
  4125. if (isArray(bbox) && 4 === bbox.length) {
  4126. var width = bbox[2] - bbox[0];
  4127. var height = bbox[3] - bbox[1];
  4128. this.ctx.rect(bbox[0], bbox[1], width, height);
  4129. this.clip();
  4130. this.endPath();
  4131. }
  4132. },
  4133. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4134. this.restore();
  4135. this.baseTransform = this.baseTransformStack.pop();
  4136. },
  4137. beginGroup: function CanvasGraphics_beginGroup(group) {
  4138. this.save();
  4139. var currentCtx = this.ctx;
  4140. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4141. // group results aren't usually that different and they even have tools
  4142. // that ignore this setting. Notes from Rik on implmenting:
  4143. // - When you encounter an transparency group, create a new canvas with
  4144. // the dimensions of the bbox
  4145. // - copy the content from the previous canvas to the new canvas
  4146. // - draw as usual
  4147. // - remove the backdrop alpha:
  4148. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4149. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4150. // backdrop
  4151. // - remove background color:
  4152. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4153. if (!group.isolated) {
  4154. info('TODO: Support non-isolated groups.');
  4155. }
  4156. // TODO knockout - supposedly possible with the clever use of compositing
  4157. // modes.
  4158. if (group.knockout) {
  4159. warn('Knockout groups not supported.');
  4160. }
  4161. var currentTransform = currentCtx.mozCurrentTransform;
  4162. if (group.matrix) {
  4163. currentCtx.transform.apply(currentCtx, group.matrix);
  4164. }
  4165. assert(group.bbox, 'Bounding box is required.');
  4166. // Based on the current transform figure out how big the bounding box
  4167. // will actually be.
  4168. var bounds = Util.getAxialAlignedBoundingBox(
  4169. group.bbox,
  4170. currentCtx.mozCurrentTransform);
  4171. // Clip the bounding box to the current canvas.
  4172. var canvasBounds = [0,
  4173. 0,
  4174. currentCtx.canvas.width,
  4175. currentCtx.canvas.height];
  4176. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4177. // Use ceil in case we're between sizes so we don't create canvas that is
  4178. // too small and make the canvas at least 1x1 pixels.
  4179. var offsetX = Math.floor(bounds[0]);
  4180. var offsetY = Math.floor(bounds[1]);
  4181. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4182. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4183. var scaleX = 1, scaleY = 1;
  4184. if (drawnWidth > MAX_GROUP_SIZE) {
  4185. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4186. drawnWidth = MAX_GROUP_SIZE;
  4187. }
  4188. if (drawnHeight > MAX_GROUP_SIZE) {
  4189. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4190. drawnHeight = MAX_GROUP_SIZE;
  4191. }
  4192. var cacheId = 'groupAt' + this.groupLevel;
  4193. if (group.smask) {
  4194. // Using two cache entries is case if masks are used one after another.
  4195. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4196. }
  4197. var scratchCanvas = CachedCanvases.getCanvas(
  4198. cacheId, drawnWidth, drawnHeight, true);
  4199. var groupCtx = scratchCanvas.context;
  4200. // Since we created a new canvas that is just the size of the bounding box
  4201. // we have to translate the group ctx.
  4202. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4203. groupCtx.translate(-offsetX, -offsetY);
  4204. groupCtx.transform.apply(groupCtx, currentTransform);
  4205. if (group.smask) {
  4206. // Saving state and cached mask to be used in setGState.
  4207. this.smaskStack.push({
  4208. canvas: scratchCanvas.canvas,
  4209. context: groupCtx,
  4210. offsetX: offsetX,
  4211. offsetY: offsetY,
  4212. scaleX: scaleX,
  4213. scaleY: scaleY,
  4214. subtype: group.smask.subtype,
  4215. backdrop: group.smask.backdrop
  4216. });
  4217. } else {
  4218. // Setup the current ctx so when the group is popped we draw it at the
  4219. // right location.
  4220. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4221. currentCtx.translate(offsetX, offsetY);
  4222. currentCtx.scale(scaleX, scaleY);
  4223. }
  4224. // The transparency group inherits all off the current graphics state
  4225. // except the blend mode, soft mask, and alpha constants.
  4226. copyCtxState(currentCtx, groupCtx);
  4227. this.ctx = groupCtx;
  4228. this.setGState([
  4229. ['BM', 'Normal'],
  4230. ['ca', 1],
  4231. ['CA', 1]
  4232. ]);
  4233. this.groupStack.push(currentCtx);
  4234. this.groupLevel++;
  4235. },
  4236. endGroup: function CanvasGraphics_endGroup(group) {
  4237. this.groupLevel--;
  4238. var groupCtx = this.ctx;
  4239. this.ctx = this.groupStack.pop();
  4240. // Turn off image smoothing to avoid sub pixel interpolation which can
  4241. // look kind of blurry for some pdfs.
  4242. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4243. this.ctx.imageSmoothingEnabled = false;
  4244. } else {
  4245. this.ctx.mozImageSmoothingEnabled = false;
  4246. }
  4247. if (group.smask) {
  4248. this.tempSMask = this.smaskStack.pop();
  4249. } else {
  4250. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4251. }
  4252. this.restore();
  4253. },
  4254. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4255. this.save();
  4256. this.current = new CanvasExtraState();
  4257. },
  4258. endAnnotations: function CanvasGraphics_endAnnotations() {
  4259. this.restore();
  4260. },
  4261. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4262. matrix) {
  4263. this.save();
  4264. if (isArray(rect) && 4 === rect.length) {
  4265. var width = rect[2] - rect[0];
  4266. var height = rect[3] - rect[1];
  4267. this.ctx.rect(rect[0], rect[1], width, height);
  4268. this.clip();
  4269. this.endPath();
  4270. }
  4271. this.transform.apply(this, transform);
  4272. this.transform.apply(this, matrix);
  4273. },
  4274. endAnnotation: function CanvasGraphics_endAnnotation() {
  4275. this.restore();
  4276. },
  4277. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4278. var domImage = this.objs.get(objId);
  4279. if (!domImage) {
  4280. warn('Dependent image isn\'t ready yet');
  4281. return;
  4282. }
  4283. this.save();
  4284. var ctx = this.ctx;
  4285. // scale the image to the unit square
  4286. ctx.scale(1 / w, -1 / h);
  4287. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4288. 0, -h, w, h);
  4289. if (this.imageLayer) {
  4290. var currentTransform = ctx.mozCurrentTransformInverse;
  4291. var position = this.getCanvasPosition(0, 0);
  4292. this.imageLayer.appendImage({
  4293. objId: objId,
  4294. left: position[0],
  4295. top: position[1],
  4296. width: w / currentTransform[0],
  4297. height: h / currentTransform[3]
  4298. });
  4299. }
  4300. this.restore();
  4301. },
  4302. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4303. var ctx = this.ctx;
  4304. var width = img.width, height = img.height;
  4305. var glyph = this.processingType3;
  4306. if (COMPILE_TYPE3_GLYPHS && glyph && !('compiled' in glyph)) {
  4307. var MAX_SIZE_TO_COMPILE = 1000;
  4308. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4309. glyph.compiled =
  4310. compileType3Glyph({data: img.data, width: width, height: height});
  4311. } else {
  4312. glyph.compiled = null;
  4313. }
  4314. }
  4315. if (glyph && glyph.compiled) {
  4316. glyph.compiled(ctx);
  4317. return;
  4318. }
  4319. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4320. var maskCtx = maskCanvas.context;
  4321. maskCtx.save();
  4322. putBinaryImageMask(maskCtx, img);
  4323. maskCtx.globalCompositeOperation = 'source-in';
  4324. var fillColor = this.current.fillColor;
  4325. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4326. fillColor.type === 'Pattern') ?
  4327. fillColor.getPattern(maskCtx, this) : fillColor;
  4328. maskCtx.fillRect(0, 0, width, height);
  4329. maskCtx.restore();
  4330. this.paintInlineImageXObject(maskCanvas.canvas);
  4331. },
  4332. paintImageMaskXObjectRepeat:
  4333. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4334. scaleY, positions) {
  4335. var width = imgData.width;
  4336. var height = imgData.height;
  4337. var ctx = this.ctx;
  4338. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4339. var maskCtx = maskCanvas.context;
  4340. maskCtx.save();
  4341. putBinaryImageMask(maskCtx, imgData);
  4342. maskCtx.globalCompositeOperation = 'source-in';
  4343. var fillColor = this.current.fillColor;
  4344. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4345. fillColor.type === 'Pattern') ?
  4346. fillColor.getPattern(maskCtx, this) : fillColor;
  4347. maskCtx.fillRect(0, 0, width, height);
  4348. maskCtx.restore();
  4349. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4350. ctx.save();
  4351. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4352. ctx.scale(1, -1);
  4353. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4354. 0, -1, 1, 1);
  4355. ctx.restore();
  4356. }
  4357. },
  4358. paintImageMaskXObjectGroup:
  4359. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4360. var ctx = this.ctx;
  4361. for (var i = 0, ii = images.length; i < ii; i++) {
  4362. var image = images[i];
  4363. var width = image.width, height = image.height;
  4364. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4365. var maskCtx = maskCanvas.context;
  4366. maskCtx.save();
  4367. putBinaryImageMask(maskCtx, image);
  4368. maskCtx.globalCompositeOperation = 'source-in';
  4369. var fillColor = this.current.fillColor;
  4370. maskCtx.fillStyle = (fillColor && fillColor.hasOwnProperty('type') &&
  4371. fillColor.type === 'Pattern') ?
  4372. fillColor.getPattern(maskCtx, this) : fillColor;
  4373. maskCtx.fillRect(0, 0, width, height);
  4374. maskCtx.restore();
  4375. ctx.save();
  4376. ctx.transform.apply(ctx, image.transform);
  4377. ctx.scale(1, -1);
  4378. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4379. 0, -1, 1, 1);
  4380. ctx.restore();
  4381. }
  4382. },
  4383. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4384. var imgData = this.objs.get(objId);
  4385. if (!imgData) {
  4386. warn('Dependent image isn\'t ready yet');
  4387. return;
  4388. }
  4389. this.paintInlineImageXObject(imgData);
  4390. },
  4391. paintImageXObjectRepeat:
  4392. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4393. positions) {
  4394. var imgData = this.objs.get(objId);
  4395. if (!imgData) {
  4396. warn('Dependent image isn\'t ready yet');
  4397. return;
  4398. }
  4399. var width = imgData.width;
  4400. var height = imgData.height;
  4401. var map = [];
  4402. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4403. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4404. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4405. }
  4406. this.paintInlineImageXObjectGroup(imgData, map);
  4407. },
  4408. paintInlineImageXObject:
  4409. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4410. var width = imgData.width;
  4411. var height = imgData.height;
  4412. var ctx = this.ctx;
  4413. this.save();
  4414. // scale the image to the unit square
  4415. ctx.scale(1 / width, -1 / height);
  4416. var currentTransform = ctx.mozCurrentTransformInverse;
  4417. var a = currentTransform[0], b = currentTransform[1];
  4418. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4419. var c = currentTransform[2], d = currentTransform[3];
  4420. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4421. var imgToPaint, tmpCanvas;
  4422. // instanceof HTMLElement does not work in jsdom node.js module
  4423. if (imgData instanceof HTMLElement || !imgData.data) {
  4424. imgToPaint = imgData;
  4425. } else {
  4426. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4427. var tmpCtx = tmpCanvas.context;
  4428. putBinaryImageData(tmpCtx, imgData);
  4429. imgToPaint = tmpCanvas.canvas;
  4430. }
  4431. var paintWidth = width, paintHeight = height;
  4432. var tmpCanvasId = 'prescale1';
  4433. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4434. // pixels during drawImage operation, painting on the temporary canvas(es)
  4435. // that are twice smaller in size
  4436. while ((widthScale > 2 && paintWidth > 1) ||
  4437. (heightScale > 2 && paintHeight > 1)) {
  4438. var newWidth = paintWidth, newHeight = paintHeight;
  4439. if (widthScale > 2 && paintWidth > 1) {
  4440. newWidth = Math.ceil(paintWidth / 2);
  4441. widthScale /= paintWidth / newWidth;
  4442. }
  4443. if (heightScale > 2 && paintHeight > 1) {
  4444. newHeight = Math.ceil(paintHeight / 2);
  4445. heightScale /= paintHeight / newHeight;
  4446. }
  4447. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4448. tmpCtx = tmpCanvas.context;
  4449. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4450. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4451. 0, 0, newWidth, newHeight);
  4452. imgToPaint = tmpCanvas.canvas;
  4453. paintWidth = newWidth;
  4454. paintHeight = newHeight;
  4455. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4456. }
  4457. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4458. 0, -height, width, height);
  4459. if (this.imageLayer) {
  4460. var position = this.getCanvasPosition(0, -height);
  4461. this.imageLayer.appendImage({
  4462. imgData: imgData,
  4463. left: position[0],
  4464. top: position[1],
  4465. width: width / currentTransform[0],
  4466. height: height / currentTransform[3]
  4467. });
  4468. }
  4469. this.restore();
  4470. },
  4471. paintInlineImageXObjectGroup:
  4472. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4473. var ctx = this.ctx;
  4474. var w = imgData.width;
  4475. var h = imgData.height;
  4476. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4477. var tmpCtx = tmpCanvas.context;
  4478. putBinaryImageData(tmpCtx, imgData);
  4479. for (var i = 0, ii = map.length; i < ii; i++) {
  4480. var entry = map[i];
  4481. ctx.save();
  4482. ctx.transform.apply(ctx, entry.transform);
  4483. ctx.scale(1, -1);
  4484. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4485. 0, -1, 1, 1);
  4486. if (this.imageLayer) {
  4487. var position = this.getCanvasPosition(entry.x, entry.y);
  4488. this.imageLayer.appendImage({
  4489. imgData: imgData,
  4490. left: position[0],
  4491. top: position[1],
  4492. width: w,
  4493. height: h
  4494. });
  4495. }
  4496. ctx.restore();
  4497. }
  4498. },
  4499. paintSolidColorImageMask:
  4500. function CanvasGraphics_paintSolidColorImageMask() {
  4501. this.ctx.fillRect(0, 0, 1, 1);
  4502. },
  4503. // Marked content
  4504. markPoint: function CanvasGraphics_markPoint(tag) {
  4505. // TODO Marked content.
  4506. },
  4507. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4508. // TODO Marked content.
  4509. },
  4510. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4511. // TODO Marked content.
  4512. },
  4513. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4514. tag, properties) {
  4515. // TODO Marked content.
  4516. },
  4517. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4518. // TODO Marked content.
  4519. },
  4520. // Compatibility
  4521. beginCompat: function CanvasGraphics_beginCompat() {
  4522. // TODO ignore undefined operators (should we do that anyway?)
  4523. },
  4524. endCompat: function CanvasGraphics_endCompat() {
  4525. // TODO stop ignoring undefined operators
  4526. },
  4527. // Helper functions
  4528. consumePath: function CanvasGraphics_consumePath() {
  4529. var ctx = this.ctx;
  4530. if (this.pendingClip) {
  4531. if (this.pendingClip === EO_CLIP) {
  4532. if (ctx.mozFillRule !== undefined) {
  4533. ctx.mozFillRule = 'evenodd';
  4534. ctx.clip();
  4535. ctx.mozFillRule = 'nonzero';
  4536. } else {
  4537. try {
  4538. ctx.clip('evenodd');
  4539. } catch (ex) {
  4540. // shouldn't really happen, but browsers might think differently
  4541. ctx.clip();
  4542. }
  4543. }
  4544. } else {
  4545. ctx.clip();
  4546. }
  4547. this.pendingClip = null;
  4548. }
  4549. ctx.beginPath();
  4550. },
  4551. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4552. var inverse = this.ctx.mozCurrentTransformInverse;
  4553. // max of the current horizontal and vertical scale
  4554. return Math.sqrt(Math.max(
  4555. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4556. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4557. },
  4558. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4559. var transform = this.ctx.mozCurrentTransform;
  4560. return [
  4561. transform[0] * x + transform[2] * y + transform[4],
  4562. transform[1] * x + transform[3] * y + transform[5]
  4563. ];
  4564. }
  4565. };
  4566. for (var op in OPS) {
  4567. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4568. }
  4569. return CanvasGraphics;
  4570. })();
  4571. var WebGLUtils = (function WebGLUtilsClosure() {
  4572. function loadShader(gl, code, shaderType) {
  4573. var shader = gl.createShader(shaderType);
  4574. gl.shaderSource(shader, code);
  4575. gl.compileShader(shader);
  4576. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4577. if (!compiled) {
  4578. var errorMsg = gl.getShaderInfoLog(shader);
  4579. throw new Error('Error during shader compilation: ' + errorMsg);
  4580. }
  4581. return shader;
  4582. }
  4583. function createVertexShader(gl, code) {
  4584. return loadShader(gl, code, gl.VERTEX_SHADER);
  4585. }
  4586. function createFragmentShader(gl, code) {
  4587. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4588. }
  4589. function createProgram(gl, shaders) {
  4590. var program = gl.createProgram();
  4591. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4592. gl.attachShader(program, shaders[i]);
  4593. }
  4594. gl.linkProgram(program);
  4595. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4596. if (!linked) {
  4597. var errorMsg = gl.getProgramInfoLog(program);
  4598. throw new Error('Error during program linking: ' + errorMsg);
  4599. }
  4600. return program;
  4601. }
  4602. function createTexture(gl, image, textureId) {
  4603. gl.activeTexture(textureId);
  4604. var texture = gl.createTexture();
  4605. gl.bindTexture(gl.TEXTURE_2D, texture);
  4606. // Set the parameters so we can render any size image.
  4607. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4608. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4609. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4610. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4611. // Upload the image into the texture.
  4612. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4613. return texture;
  4614. }
  4615. var currentGL, currentCanvas;
  4616. function generageGL() {
  4617. if (currentGL) {
  4618. return;
  4619. }
  4620. currentCanvas = document.createElement('canvas');
  4621. currentGL = currentCanvas.getContext('webgl',
  4622. { premultipliedalpha: false });
  4623. }
  4624. var smaskVertexShaderCode = '\
  4625. attribute vec2 a_position; \
  4626. attribute vec2 a_texCoord; \
  4627. \
  4628. uniform vec2 u_resolution; \
  4629. \
  4630. varying vec2 v_texCoord; \
  4631. \
  4632. void main() { \
  4633. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4634. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4635. \
  4636. v_texCoord = a_texCoord; \
  4637. } ';
  4638. var smaskFragmentShaderCode = '\
  4639. precision mediump float; \
  4640. \
  4641. uniform vec4 u_backdrop; \
  4642. uniform int u_subtype; \
  4643. uniform sampler2D u_image; \
  4644. uniform sampler2D u_mask; \
  4645. \
  4646. varying vec2 v_texCoord; \
  4647. \
  4648. void main() { \
  4649. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4650. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4651. if (u_backdrop.a > 0.0) { \
  4652. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4653. u_backdrop.rgb * (1.0 - maskColor.a); \
  4654. } \
  4655. float lum; \
  4656. if (u_subtype == 0) { \
  4657. lum = maskColor.a; \
  4658. } else { \
  4659. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4660. maskColor.b * 0.11; \
  4661. } \
  4662. imageColor.a *= lum; \
  4663. imageColor.rgb *= imageColor.a; \
  4664. gl_FragColor = imageColor; \
  4665. } ';
  4666. var smaskCache = null;
  4667. function initSmaskGL() {
  4668. var canvas, gl;
  4669. generageGL();
  4670. canvas = currentCanvas;
  4671. currentCanvas = null;
  4672. gl = currentGL;
  4673. currentGL = null;
  4674. // setup a GLSL program
  4675. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4676. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4677. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4678. gl.useProgram(program);
  4679. var cache = {};
  4680. cache.gl = gl;
  4681. cache.canvas = canvas;
  4682. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4683. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4684. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4685. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4686. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4687. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4688. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4689. // provide texture coordinates for the rectangle.
  4690. var texCoordBuffer = gl.createBuffer();
  4691. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4692. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4693. 0.0, 0.0,
  4694. 1.0, 0.0,
  4695. 0.0, 1.0,
  4696. 0.0, 1.0,
  4697. 1.0, 0.0,
  4698. 1.0, 1.0]), gl.STATIC_DRAW);
  4699. gl.enableVertexAttribArray(texCoordLocation);
  4700. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4701. gl.uniform1i(texLayerLocation, 0);
  4702. gl.uniform1i(texMaskLocation, 1);
  4703. smaskCache = cache;
  4704. }
  4705. function composeSMask(layer, mask, properties) {
  4706. var width = layer.width, height = layer.height;
  4707. if (!smaskCache) {
  4708. initSmaskGL();
  4709. }
  4710. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4711. canvas.width = width;
  4712. canvas.height = height;
  4713. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4714. gl.uniform2f(cache.resolutionLocation, width, height);
  4715. if (properties.backdrop) {
  4716. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4717. properties.backdrop[1], properties.backdrop[2], 1);
  4718. } else {
  4719. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4720. }
  4721. gl.uniform1i(cache.subtypeLocation,
  4722. properties.subtype === 'Luminosity' ? 1 : 0);
  4723. // Create a textures
  4724. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4725. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4726. // Create a buffer and put a single clipspace rectangle in
  4727. // it (2 triangles)
  4728. var buffer = gl.createBuffer();
  4729. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4730. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4731. 0, 0,
  4732. width, 0,
  4733. 0, height,
  4734. 0, height,
  4735. width, 0,
  4736. width, height]), gl.STATIC_DRAW);
  4737. gl.enableVertexAttribArray(cache.positionLocation);
  4738. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4739. // draw
  4740. gl.clearColor(0, 0, 0, 0);
  4741. gl.enable(gl.BLEND);
  4742. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4743. gl.clear(gl.COLOR_BUFFER_BIT);
  4744. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4745. gl.flush();
  4746. gl.deleteTexture(texture);
  4747. gl.deleteTexture(maskTexture);
  4748. gl.deleteBuffer(buffer);
  4749. return canvas;
  4750. }
  4751. var figuresVertexShaderCode = '\
  4752. attribute vec2 a_position; \
  4753. attribute vec3 a_color; \
  4754. \
  4755. uniform vec2 u_resolution; \
  4756. uniform vec2 u_scale; \
  4757. uniform vec2 u_offset; \
  4758. \
  4759. varying vec4 v_color; \
  4760. \
  4761. void main() { \
  4762. vec2 position = (a_position + u_offset) * u_scale; \
  4763. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  4764. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4765. \
  4766. v_color = vec4(a_color / 255.0, 1.0); \
  4767. } ';
  4768. var figuresFragmentShaderCode = '\
  4769. precision mediump float; \
  4770. \
  4771. varying vec4 v_color; \
  4772. \
  4773. void main() { \
  4774. gl_FragColor = v_color; \
  4775. } ';
  4776. var figuresCache = null;
  4777. function initFiguresGL() {
  4778. var canvas, gl;
  4779. generageGL();
  4780. canvas = currentCanvas;
  4781. currentCanvas = null;
  4782. gl = currentGL;
  4783. currentGL = null;
  4784. // setup a GLSL program
  4785. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  4786. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  4787. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4788. gl.useProgram(program);
  4789. var cache = {};
  4790. cache.gl = gl;
  4791. cache.canvas = canvas;
  4792. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4793. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  4794. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  4795. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4796. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  4797. figuresCache = cache;
  4798. }
  4799. function drawFigures(width, height, backgroundColor, figures, context) {
  4800. if (!figuresCache) {
  4801. initFiguresGL();
  4802. }
  4803. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  4804. canvas.width = width;
  4805. canvas.height = height;
  4806. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4807. gl.uniform2f(cache.resolutionLocation, width, height);
  4808. // count triangle points
  4809. var count = 0;
  4810. var i, ii, rows;
  4811. for (i = 0, ii = figures.length; i < ii; i++) {
  4812. switch (figures[i].type) {
  4813. case 'lattice':
  4814. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  4815. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  4816. break;
  4817. case 'triangles':
  4818. count += figures[i].coords.length;
  4819. break;
  4820. }
  4821. }
  4822. // transfer data
  4823. var coords = new Float32Array(count * 2);
  4824. var colors = new Uint8Array(count * 3);
  4825. var coordsMap = context.coords, colorsMap = context.colors;
  4826. var pIndex = 0, cIndex = 0;
  4827. for (i = 0, ii = figures.length; i < ii; i++) {
  4828. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  4829. switch (figure.type) {
  4830. case 'lattice':
  4831. var cols = figure.verticesPerRow;
  4832. rows = (ps.length / cols) | 0;
  4833. for (var row = 1; row < rows; row++) {
  4834. var offset = row * cols + 1;
  4835. for (var col = 1; col < cols; col++, offset++) {
  4836. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  4837. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  4838. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  4839. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  4840. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  4841. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  4842. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  4843. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  4844. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  4845. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  4846. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  4847. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  4848. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  4849. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  4850. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  4851. coords[pIndex + 6] = coords[pIndex + 2];
  4852. coords[pIndex + 7] = coords[pIndex + 3];
  4853. coords[pIndex + 8] = coords[pIndex + 4];
  4854. coords[pIndex + 9] = coords[pIndex + 5];
  4855. coords[pIndex + 10] = coordsMap[ps[offset]];
  4856. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  4857. colors[cIndex + 9] = colors[cIndex + 3];
  4858. colors[cIndex + 10] = colors[cIndex + 4];
  4859. colors[cIndex + 11] = colors[cIndex + 5];
  4860. colors[cIndex + 12] = colors[cIndex + 6];
  4861. colors[cIndex + 13] = colors[cIndex + 7];
  4862. colors[cIndex + 14] = colors[cIndex + 8];
  4863. colors[cIndex + 15] = colorsMap[cs[offset]];
  4864. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  4865. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  4866. pIndex += 12;
  4867. cIndex += 18;
  4868. }
  4869. }
  4870. break;
  4871. case 'triangles':
  4872. for (var j = 0, jj = ps.length; j < jj; j++) {
  4873. coords[pIndex] = coordsMap[ps[j]];
  4874. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  4875. colors[cIndex] = colorsMap[cs[i]];
  4876. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  4877. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  4878. pIndex += 2;
  4879. cIndex += 3;
  4880. }
  4881. break;
  4882. }
  4883. }
  4884. // draw
  4885. if (backgroundColor) {
  4886. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  4887. backgroundColor[2] / 255, 1.0);
  4888. } else {
  4889. gl.clearColor(0, 0, 0, 0);
  4890. }
  4891. gl.clear(gl.COLOR_BUFFER_BIT);
  4892. var coordsBuffer = gl.createBuffer();
  4893. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  4894. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  4895. gl.enableVertexAttribArray(cache.positionLocation);
  4896. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4897. var colorsBuffer = gl.createBuffer();
  4898. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  4899. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  4900. gl.enableVertexAttribArray(cache.colorLocation);
  4901. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  4902. 0, 0);
  4903. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  4904. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  4905. gl.drawArrays(gl.TRIANGLES, 0, count);
  4906. gl.flush();
  4907. gl.deleteBuffer(coordsBuffer);
  4908. gl.deleteBuffer(colorsBuffer);
  4909. return canvas;
  4910. }
  4911. function cleanup() {
  4912. if (smaskCache && smaskCache.canvas) {
  4913. smaskCache.canvas.width = 0;
  4914. smaskCache.canvas.height = 0;
  4915. }
  4916. if (figuresCache && figuresCache.canvas) {
  4917. figuresCache.canvas.width = 0;
  4918. figuresCache.canvas.height = 0;
  4919. }
  4920. smaskCache = null;
  4921. figuresCache = null;
  4922. }
  4923. return {
  4924. get isEnabled() {
  4925. if (PDFJS.disableWebGL) {
  4926. return false;
  4927. }
  4928. var enabled = false;
  4929. try {
  4930. generageGL();
  4931. enabled = !!currentGL;
  4932. } catch (e) { }
  4933. return shadow(this, 'isEnabled', enabled);
  4934. },
  4935. composeSMask: composeSMask,
  4936. drawFigures: drawFigures,
  4937. clear: cleanup
  4938. };
  4939. })();
  4940. var ShadingIRs = {};
  4941. ShadingIRs.RadialAxial = {
  4942. fromIR: function RadialAxial_fromIR(raw) {
  4943. var type = raw[1];
  4944. var colorStops = raw[2];
  4945. var p0 = raw[3];
  4946. var p1 = raw[4];
  4947. var r0 = raw[5];
  4948. var r1 = raw[6];
  4949. return {
  4950. type: 'Pattern',
  4951. getPattern: function RadialAxial_getPattern(ctx) {
  4952. var grad;
  4953. if (type === 'axial') {
  4954. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  4955. } else if (type === 'radial') {
  4956. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  4957. }
  4958. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  4959. var c = colorStops[i];
  4960. grad.addColorStop(c[0], c[1]);
  4961. }
  4962. return grad;
  4963. }
  4964. };
  4965. }
  4966. };
  4967. var createMeshCanvas = (function createMeshCanvasClosure() {
  4968. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  4969. // Very basic Gouraud-shaded triangle rasterization algorithm.
  4970. var coords = context.coords, colors = context.colors;
  4971. var bytes = data.data, rowSize = data.width * 4;
  4972. var tmp;
  4973. if (coords[p1 + 1] > coords[p2 + 1]) {
  4974. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  4975. }
  4976. if (coords[p2 + 1] > coords[p3 + 1]) {
  4977. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  4978. }
  4979. if (coords[p1 + 1] > coords[p2 + 1]) {
  4980. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  4981. }
  4982. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  4983. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  4984. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  4985. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  4986. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  4987. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  4988. if (y1 >= y3) {
  4989. return;
  4990. }
  4991. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  4992. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  4993. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  4994. var minY = Math.round(y1), maxY = Math.round(y3);
  4995. var xa, car, cag, cab;
  4996. var xb, cbr, cbg, cbb;
  4997. var k;
  4998. for (var y = minY; y <= maxY; y++) {
  4999. if (y < y2) {
  5000. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5001. xa = x1 - (x1 - x2) * k;
  5002. car = c1r - (c1r - c2r) * k;
  5003. cag = c1g - (c1g - c2g) * k;
  5004. cab = c1b - (c1b - c2b) * k;
  5005. } else {
  5006. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5007. xa = x2 - (x2 - x3) * k;
  5008. car = c2r - (c2r - c3r) * k;
  5009. cag = c2g - (c2g - c3g) * k;
  5010. cab = c2b - (c2b - c3b) * k;
  5011. }
  5012. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5013. xb = x1 - (x1 - x3) * k;
  5014. cbr = c1r - (c1r - c3r) * k;
  5015. cbg = c1g - (c1g - c3g) * k;
  5016. cbb = c1b - (c1b - c3b) * k;
  5017. var x1_ = Math.round(Math.min(xa, xb));
  5018. var x2_ = Math.round(Math.max(xa, xb));
  5019. var j = rowSize * y + x1_ * 4;
  5020. for (var x = x1_; x <= x2_; x++) {
  5021. k = (xa - x) / (xa - xb);
  5022. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5023. bytes[j++] = (car - (car - cbr) * k) | 0;
  5024. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5025. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5026. bytes[j++] = 255;
  5027. }
  5028. }
  5029. }
  5030. function drawFigure(data, figure, context) {
  5031. var ps = figure.coords;
  5032. var cs = figure.colors;
  5033. var i, ii;
  5034. switch (figure.type) {
  5035. case 'lattice':
  5036. var verticesPerRow = figure.verticesPerRow;
  5037. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5038. var cols = verticesPerRow - 1;
  5039. for (i = 0; i < rows; i++) {
  5040. var q = i * verticesPerRow;
  5041. for (var j = 0; j < cols; j++, q++) {
  5042. drawTriangle(data, context,
  5043. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5044. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5045. drawTriangle(data, context,
  5046. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5047. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5048. }
  5049. }
  5050. break;
  5051. case 'triangles':
  5052. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5053. drawTriangle(data, context,
  5054. ps[i], ps[i + 1], ps[i + 2],
  5055. cs[i], cs[i + 1], cs[i + 2]);
  5056. }
  5057. break;
  5058. default:
  5059. error('illigal figure');
  5060. break;
  5061. }
  5062. }
  5063. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5064. backgroundColor) {
  5065. // we will increase scale on some weird factor to let antialiasing take
  5066. // care of "rough" edges
  5067. var EXPECTED_SCALE = 1.1;
  5068. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5069. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5070. var offsetX = Math.floor(bounds[0]);
  5071. var offsetY = Math.floor(bounds[1]);
  5072. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5073. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5074. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5075. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5076. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5077. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5078. var scaleX = boundsWidth / width;
  5079. var scaleY = boundsHeight / height;
  5080. var context = {
  5081. coords: coords,
  5082. colors: colors,
  5083. offsetX: -offsetX,
  5084. offsetY: -offsetY,
  5085. scaleX: 1 / scaleX,
  5086. scaleY: 1 / scaleY
  5087. };
  5088. var canvas, tmpCanvas, i, ii;
  5089. if (WebGLUtils.isEnabled) {
  5090. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5091. figures, context);
  5092. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5093. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5094. tmpCanvas.context.drawImage(canvas, 0, 0);
  5095. canvas = tmpCanvas.canvas;
  5096. } else {
  5097. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5098. var tmpCtx = tmpCanvas.context;
  5099. var data = tmpCtx.createImageData(width, height);
  5100. if (backgroundColor) {
  5101. var bytes = data.data;
  5102. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5103. bytes[i] = backgroundColor[0];
  5104. bytes[i + 1] = backgroundColor[1];
  5105. bytes[i + 2] = backgroundColor[2];
  5106. bytes[i + 3] = 255;
  5107. }
  5108. }
  5109. for (i = 0; i < figures.length; i++) {
  5110. drawFigure(data, figures[i], context);
  5111. }
  5112. tmpCtx.putImageData(data, 0, 0);
  5113. canvas = tmpCanvas.canvas;
  5114. }
  5115. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5116. scaleX: scaleX, scaleY: scaleY};
  5117. }
  5118. return createMeshCanvas;
  5119. })();
  5120. ShadingIRs.Mesh = {
  5121. fromIR: function Mesh_fromIR(raw) {
  5122. //var type = raw[1];
  5123. var coords = raw[2];
  5124. var colors = raw[3];
  5125. var figures = raw[4];
  5126. var bounds = raw[5];
  5127. var matrix = raw[6];
  5128. //var bbox = raw[7];
  5129. var background = raw[8];
  5130. return {
  5131. type: 'Pattern',
  5132. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5133. var scale;
  5134. if (shadingFill) {
  5135. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5136. } else {
  5137. // Obtain scale from matrix and current transformation matrix.
  5138. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5139. if (matrix) {
  5140. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5141. scale = [scale[0] * matrixScale[0],
  5142. scale[1] * matrixScale[1]];
  5143. }
  5144. }
  5145. // Rasterizing on the main thread since sending/queue large canvases
  5146. // might cause OOM.
  5147. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5148. colors, figures, shadingFill ? null : background);
  5149. if (!shadingFill) {
  5150. ctx.setTransform.apply(ctx, owner.baseTransform);
  5151. if (matrix) {
  5152. ctx.transform.apply(ctx, matrix);
  5153. }
  5154. }
  5155. ctx.translate(temporaryPatternCanvas.offsetX,
  5156. temporaryPatternCanvas.offsetY);
  5157. ctx.scale(temporaryPatternCanvas.scaleX,
  5158. temporaryPatternCanvas.scaleY);
  5159. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5160. }
  5161. };
  5162. }
  5163. };
  5164. ShadingIRs.Dummy = {
  5165. fromIR: function Dummy_fromIR() {
  5166. return {
  5167. type: 'Pattern',
  5168. getPattern: function Dummy_fromIR_getPattern() {
  5169. return 'hotpink';
  5170. }
  5171. };
  5172. }
  5173. };
  5174. function getShadingPatternFromIR(raw) {
  5175. var shadingIR = ShadingIRs[raw[0]];
  5176. if (!shadingIR) {
  5177. error('Unknown IR type: ' + raw[0]);
  5178. }
  5179. return shadingIR.fromIR(raw);
  5180. }
  5181. var TilingPattern = (function TilingPatternClosure() {
  5182. var PaintType = {
  5183. COLORED: 1,
  5184. UNCOLORED: 2
  5185. };
  5186. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5187. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5188. this.operatorList = IR[2];
  5189. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5190. this.bbox = IR[4];
  5191. this.xstep = IR[5];
  5192. this.ystep = IR[6];
  5193. this.paintType = IR[7];
  5194. this.tilingType = IR[8];
  5195. this.color = color;
  5196. this.objs = objs;
  5197. this.commonObjs = commonObjs;
  5198. this.baseTransform = baseTransform;
  5199. this.type = 'Pattern';
  5200. this.ctx = ctx;
  5201. }
  5202. TilingPattern.prototype = {
  5203. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5204. var operatorList = this.operatorList;
  5205. var bbox = this.bbox;
  5206. var xstep = this.xstep;
  5207. var ystep = this.ystep;
  5208. var paintType = this.paintType;
  5209. var tilingType = this.tilingType;
  5210. var color = this.color;
  5211. var objs = this.objs;
  5212. var commonObjs = this.commonObjs;
  5213. info('TilingType: ' + tilingType);
  5214. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5215. var topLeft = [x0, y0];
  5216. // we want the canvas to be as large as the step size
  5217. var botRight = [x0 + xstep, y0 + ystep];
  5218. var width = botRight[0] - topLeft[0];
  5219. var height = botRight[1] - topLeft[1];
  5220. // Obtain scale from matrix and current transformation matrix.
  5221. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5222. var curMatrixScale = Util.singularValueDecompose2dScale(
  5223. this.baseTransform);
  5224. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5225. matrixScale[1] * curMatrixScale[1]];
  5226. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5227. // Use width and height values that are as close as possible to the end
  5228. // result when the pattern is used. Too low value makes the pattern look
  5229. // blurry. Too large value makes it look too crispy.
  5230. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5231. MAX_PATTERN_SIZE);
  5232. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5233. MAX_PATTERN_SIZE);
  5234. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5235. var tmpCtx = tmpCanvas.context;
  5236. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5237. graphics.groupLevel = owner.groupLevel;
  5238. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5239. this.setScale(width, height, xstep, ystep);
  5240. this.transformToScale(graphics);
  5241. // transform coordinates to pattern space
  5242. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5243. graphics.transform.apply(graphics, tmpTranslate);
  5244. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5245. graphics.executeOperatorList(operatorList);
  5246. return tmpCanvas.canvas;
  5247. },
  5248. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5249. this.scale = [width / xstep, height / ystep];
  5250. },
  5251. transformToScale: function TilingPattern_transformToScale(graphics) {
  5252. var scale = this.scale;
  5253. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5254. graphics.transform.apply(graphics, tmpScale);
  5255. },
  5256. scaleToContext: function TilingPattern_scaleToContext() {
  5257. var scale = this.scale;
  5258. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5259. },
  5260. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5261. if (bbox && isArray(bbox) && bbox.length === 4) {
  5262. var bboxWidth = x1 - x0;
  5263. var bboxHeight = y1 - y0;
  5264. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5265. graphics.clip();
  5266. graphics.endPath();
  5267. }
  5268. },
  5269. setFillAndStrokeStyleToContext:
  5270. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5271. switch (paintType) {
  5272. case PaintType.COLORED:
  5273. var ctx = this.ctx;
  5274. context.fillStyle = ctx.fillStyle;
  5275. context.strokeStyle = ctx.strokeStyle;
  5276. break;
  5277. case PaintType.UNCOLORED:
  5278. var cssColor = Util.makeCssRgb(color);
  5279. context.fillStyle = cssColor;
  5280. context.strokeStyle = cssColor;
  5281. break;
  5282. default:
  5283. error('Unsupported paint type: ' + paintType);
  5284. }
  5285. },
  5286. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5287. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5288. ctx = this.ctx;
  5289. ctx.setTransform.apply(ctx, this.baseTransform);
  5290. ctx.transform.apply(ctx, this.matrix);
  5291. this.scaleToContext();
  5292. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5293. }
  5294. };
  5295. return TilingPattern;
  5296. })();
  5297. PDFJS.disableFontFace = false;
  5298. var FontLoader = {
  5299. insertRule: function fontLoaderInsertRule(rule) {
  5300. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5301. if (!styleElement) {
  5302. styleElement = document.createElement('style');
  5303. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5304. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5305. styleElement);
  5306. }
  5307. var styleSheet = styleElement.sheet;
  5308. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5309. },
  5310. clear: function fontLoaderClear() {
  5311. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5312. if (styleElement) {
  5313. styleElement.parentNode.removeChild(styleElement);
  5314. }
  5315. },
  5316. get loadTestFont() {
  5317. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5318. // height.
  5319. return shadow(this, 'loadTestFont', atob(
  5320. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5321. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5322. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5323. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5324. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5325. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5326. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5327. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5328. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5329. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5330. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5331. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5332. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5333. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5334. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5335. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5336. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5337. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5338. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5339. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5340. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5341. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5342. ));
  5343. },
  5344. loadTestFontId: 0,
  5345. loadingContext: {
  5346. requests: [],
  5347. nextRequestId: 0
  5348. },
  5349. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5350. if (isWorker) {
  5351. return false;
  5352. }
  5353. // User agent string sniffing is bad, but there is no reliable way to tell
  5354. // if font is fully loaded and ready to be used with canvas.
  5355. var userAgent = window.navigator.userAgent;
  5356. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5357. if (m && m[1] >= 14) {
  5358. return true;
  5359. }
  5360. // TODO other browsers
  5361. return false;
  5362. })(),
  5363. bind: function fontLoaderBind(fonts, callback) {
  5364. assert(!isWorker, 'bind() shall be called from main thread');
  5365. var rules = [], fontsToLoad = [];
  5366. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5367. var font = fonts[i];
  5368. // Add the font to the DOM only once or skip if the font
  5369. // is already loaded.
  5370. if (font.attached || font.loading === false) {
  5371. continue;
  5372. }
  5373. font.attached = true;
  5374. var rule = font.bindDOM();
  5375. if (rule) {
  5376. rules.push(rule);
  5377. fontsToLoad.push(font);
  5378. }
  5379. }
  5380. var request = FontLoader.queueLoadingCallback(callback);
  5381. if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5382. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5383. } else {
  5384. request.complete();
  5385. }
  5386. },
  5387. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5388. function LoadLoader_completeRequest() {
  5389. assert(!request.end, 'completeRequest() cannot be called twice');
  5390. request.end = Date.now();
  5391. // sending all completed requests in order how they were queued
  5392. while (context.requests.length > 0 && context.requests[0].end) {
  5393. var otherRequest = context.requests.shift();
  5394. setTimeout(otherRequest.callback, 0);
  5395. }
  5396. }
  5397. var context = FontLoader.loadingContext;
  5398. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5399. var request = {
  5400. id: requestId,
  5401. complete: LoadLoader_completeRequest,
  5402. callback: callback,
  5403. started: Date.now()
  5404. };
  5405. context.requests.push(request);
  5406. return request;
  5407. },
  5408. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5409. fonts,
  5410. request) {
  5411. /** Hack begin */
  5412. // There's currently no event when a font has finished downloading so the
  5413. // following code is a dirty hack to 'guess' when a font is
  5414. // ready. It's assumed fonts are loaded in order, so add a known test
  5415. // font after the desired fonts and then test for the loading of that
  5416. // test font.
  5417. function int32(data, offset) {
  5418. return (data.charCodeAt(offset) << 24) |
  5419. (data.charCodeAt(offset + 1) << 16) |
  5420. (data.charCodeAt(offset + 2) << 8) |
  5421. (data.charCodeAt(offset + 3) & 0xff);
  5422. }
  5423. function spliceString(s, offset, remove, insert) {
  5424. var chunk1 = s.substr(0, offset);
  5425. var chunk2 = s.substr(offset + remove);
  5426. return chunk1 + insert + chunk2;
  5427. }
  5428. var i, ii;
  5429. var canvas = document.createElement('canvas');
  5430. canvas.width = 1;
  5431. canvas.height = 1;
  5432. var ctx = canvas.getContext('2d');
  5433. var called = 0;
  5434. function isFontReady(name, callback) {
  5435. called++;
  5436. // With setTimeout clamping this gives the font ~100ms to load.
  5437. if(called > 30) {
  5438. warn('Load test font never loaded.');
  5439. callback();
  5440. return;
  5441. }
  5442. ctx.font = '30px ' + name;
  5443. ctx.fillText('.', 0, 20);
  5444. var imageData = ctx.getImageData(0, 0, 1, 1);
  5445. if (imageData.data[3] > 0) {
  5446. callback();
  5447. return;
  5448. }
  5449. setTimeout(isFontReady.bind(null, name, callback));
  5450. }
  5451. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5452. // Chromium seems to cache fonts based on a hash of the actual font data,
  5453. // so the font must be modified for each load test else it will appear to
  5454. // be loaded already.
  5455. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5456. // font by splitting it in chunks before hand and padding the font id.
  5457. var data = this.loadTestFont;
  5458. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5459. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5460. loadTestFontId);
  5461. // CFF checksum is important for IE, adjusting it
  5462. var CFF_CHECKSUM_OFFSET = 16;
  5463. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5464. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5465. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5466. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5467. }
  5468. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5469. checksum = (checksum - XXXX_VALUE +
  5470. int32(loadTestFontId + 'XXX', i)) | 0;
  5471. }
  5472. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5473. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5474. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5475. url + '}';
  5476. FontLoader.insertRule(rule);
  5477. var names = [];
  5478. for (i = 0, ii = fonts.length; i < ii; i++) {
  5479. names.push(fonts[i].loadedName);
  5480. }
  5481. names.push(loadTestFontId);
  5482. var div = document.createElement('div');
  5483. div.setAttribute('style',
  5484. 'visibility: hidden;' +
  5485. 'width: 10px; height: 10px;' +
  5486. 'position: absolute; top: 0px; left: 0px;');
  5487. for (i = 0, ii = names.length; i < ii; ++i) {
  5488. var span = document.createElement('span');
  5489. span.textContent = 'Hi';
  5490. span.style.fontFamily = names[i];
  5491. div.appendChild(span);
  5492. }
  5493. document.body.appendChild(div);
  5494. isFontReady(loadTestFontId, function() {
  5495. document.body.removeChild(div);
  5496. request.complete();
  5497. });
  5498. /** Hack end */
  5499. }
  5500. };
  5501. var FontFace = (function FontFaceClosure() {
  5502. function FontFace(name, file, properties) {
  5503. this.compiledGlyphs = {};
  5504. if (arguments.length === 1) {
  5505. // importing translated data
  5506. var data = arguments[0];
  5507. for (var i in data) {
  5508. this[i] = data[i];
  5509. }
  5510. return;
  5511. }
  5512. }
  5513. FontFace.prototype = {
  5514. bindDOM: function FontFace_bindDOM() {
  5515. if (!this.data) {
  5516. return null;
  5517. }
  5518. if (PDFJS.disableFontFace) {
  5519. this.disableFontFace = true;
  5520. return null;
  5521. }
  5522. var data = bytesToString(new Uint8Array(this.data));
  5523. var fontName = this.loadedName;
  5524. // Add the font-face rule to the document
  5525. var url = ('url(data:' + this.mimetype + ';base64,' +
  5526. window.btoa(data) + ');');
  5527. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5528. FontLoader.insertRule(rule);
  5529. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5530. globalScope['FontInspector'].enabled) {
  5531. globalScope['FontInspector'].fontAdded(this, url);
  5532. }
  5533. return rule;
  5534. },
  5535. getPathGenerator: function (objs, character) {
  5536. if (!(character in this.compiledGlyphs)) {
  5537. var js = objs.get(this.loadedName + '_path_' + character);
  5538. /*jshint -W054 */
  5539. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5540. }
  5541. return this.compiledGlyphs[character];
  5542. }
  5543. };
  5544. return FontFace;
  5545. })();
  5546. var HIGHLIGHT_OFFSET = 4; // px
  5547. var ANNOT_MIN_SIZE = 10; // px
  5548. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5549. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5550. function setTextStyles(element, item, fontObj) {
  5551. var style = element.style;
  5552. style.fontSize = item.fontSize + 'px';
  5553. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5554. if (!fontObj) {
  5555. return;
  5556. }
  5557. style.fontWeight = fontObj.black ?
  5558. (fontObj.bold ? 'bolder' : 'bold') :
  5559. (fontObj.bold ? 'bold' : 'normal');
  5560. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5561. var fontName = fontObj.loadedName;
  5562. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5563. // Use a reasonable default font if the font doesn't specify a fallback
  5564. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5565. style.fontFamily = fontFamily + fallbackName;
  5566. }
  5567. // TODO(mack): Remove this, it's not really that helpful.
  5568. function getEmptyContainer(tagName, rect, borderWidth) {
  5569. var bWidth = borderWidth || 0;
  5570. var element = document.createElement(tagName);
  5571. element.style.borderWidth = bWidth + 'px';
  5572. var width = rect[2] - rect[0] - 2 * bWidth;
  5573. var height = rect[3] - rect[1] - 2 * bWidth;
  5574. element.style.width = width + 'px';
  5575. element.style.height = height + 'px';
  5576. return element;
  5577. }
  5578. function initContainer(item) {
  5579. var container = getEmptyContainer('section', item.rect, item.borderWidth);
  5580. container.style.backgroundColor = item.color;
  5581. var color = item.color;
  5582. var rgb = [];
  5583. for (var i = 0; i < 3; ++i) {
  5584. rgb[i] = Math.round(color[i] * 255);
  5585. }
  5586. item.colorCssRgb = Util.makeCssRgb(rgb);
  5587. var highlight = document.createElement('div');
  5588. highlight.className = 'annotationHighlight';
  5589. highlight.style.left = highlight.style.top = -HIGHLIGHT_OFFSET + 'px';
  5590. highlight.style.right = highlight.style.bottom = -HIGHLIGHT_OFFSET + 'px';
  5591. highlight.setAttribute('hidden', true);
  5592. item.highlightElement = highlight;
  5593. container.appendChild(item.highlightElement);
  5594. return container;
  5595. }
  5596. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5597. var element = getEmptyContainer('div', item.rect, 0);
  5598. element.style.display = 'table';
  5599. var content = document.createElement('div');
  5600. content.textContent = item.fieldValue;
  5601. var textAlignment = item.textAlignment;
  5602. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5603. content.style.verticalAlign = 'middle';
  5604. content.style.display = 'table-cell';
  5605. var fontObj = item.fontRefName ?
  5606. commonObjs.getData(item.fontRefName) : null;
  5607. setTextStyles(content, item, fontObj);
  5608. element.appendChild(content);
  5609. return element;
  5610. }
  5611. function getHtmlElementForTextAnnotation(item) {
  5612. var rect = item.rect;
  5613. // sanity check because of OOo-generated PDFs
  5614. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5615. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5616. }
  5617. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5618. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5619. }
  5620. var container = initContainer(item);
  5621. container.className = 'annotText';
  5622. var image = document.createElement('img');
  5623. image.style.height = container.style.height;
  5624. image.style.width = container.style.width;
  5625. var iconName = item.name;
  5626. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5627. iconName.toLowerCase() + '.svg';
  5628. image.alt = '[{{type}} Annotation]';
  5629. image.dataset.l10nId = 'text_annotation_type';
  5630. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5631. var contentWrapper = document.createElement('div');
  5632. contentWrapper.className = 'annotTextContentWrapper';
  5633. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5634. contentWrapper.style.top = '-10px';
  5635. var content = document.createElement('div');
  5636. content.className = 'annotTextContent';
  5637. content.setAttribute('hidden', true);
  5638. var i, ii;
  5639. if (item.hasBgColor) {
  5640. var color = item.color;
  5641. var rgb = [];
  5642. for (i = 0; i < 3; ++i) {
  5643. // Enlighten the color (70%)
  5644. var c = Math.round(color[i] * 255);
  5645. rgb[i] = Math.round((255 - c) * 0.7) + c;
  5646. }
  5647. content.style.backgroundColor = Util.makeCssRgb(rgb);
  5648. }
  5649. var title = document.createElement('h1');
  5650. var text = document.createElement('p');
  5651. title.textContent = item.title;
  5652. if (!item.content && !item.title) {
  5653. content.setAttribute('hidden', true);
  5654. } else {
  5655. var e = document.createElement('span');
  5656. var lines = item.content.split(/(?:\r\n?|\n)/);
  5657. for (i = 0, ii = lines.length; i < ii; ++i) {
  5658. var line = lines[i];
  5659. e.appendChild(document.createTextNode(line));
  5660. if (i < (ii - 1)) {
  5661. e.appendChild(document.createElement('br'));
  5662. }
  5663. }
  5664. text.appendChild(e);
  5665. var pinned = false;
  5666. var showAnnotation = function showAnnotation(pin) {
  5667. if (pin) {
  5668. pinned = true;
  5669. }
  5670. if (content.hasAttribute('hidden')) {
  5671. container.style.zIndex += 1;
  5672. content.removeAttribute('hidden');
  5673. }
  5674. };
  5675. var hideAnnotation = function hideAnnotation(unpin) {
  5676. if (unpin) {
  5677. pinned = false;
  5678. }
  5679. if (!content.hasAttribute('hidden') && !pinned) {
  5680. container.style.zIndex -= 1;
  5681. content.setAttribute('hidden', true);
  5682. }
  5683. };
  5684. var toggleAnnotation = function toggleAnnotation() {
  5685. if (pinned) {
  5686. hideAnnotation(true);
  5687. } else {
  5688. showAnnotation(true);
  5689. }
  5690. };
  5691. image.addEventListener('click', function image_clickHandler() {
  5692. toggleAnnotation();
  5693. }, false);
  5694. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5695. showAnnotation();
  5696. }, false);
  5697. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5698. hideAnnotation();
  5699. }, false);
  5700. content.addEventListener('click', function content_clickHandler() {
  5701. hideAnnotation(true);
  5702. }, false);
  5703. }
  5704. content.appendChild(title);
  5705. content.appendChild(text);
  5706. contentWrapper.appendChild(content);
  5707. container.appendChild(image);
  5708. container.appendChild(contentWrapper);
  5709. return container;
  5710. }
  5711. function getHtmlElementForLinkAnnotation(item) {
  5712. var container = initContainer(item);
  5713. container.className = 'annotLink';
  5714. container.style.borderColor = item.colorCssRgb;
  5715. container.style.borderStyle = 'solid';
  5716. var link = document.createElement('a');
  5717. link.href = link.title = item.url || '';
  5718. container.appendChild(link);
  5719. return container;
  5720. }
  5721. function getHtmlElement(data, objs) {
  5722. switch (data.annotationType) {
  5723. case AnnotationType.WIDGET:
  5724. return getHtmlElementForTextWidgetAnnotation(data, objs);
  5725. case AnnotationType.TEXT:
  5726. return getHtmlElementForTextAnnotation(data);
  5727. case AnnotationType.LINK:
  5728. return getHtmlElementForLinkAnnotation(data);
  5729. default:
  5730. throw new Error('Unsupported annotationType: ' + data.annotationType);
  5731. }
  5732. }
  5733. return {
  5734. getHtmlElement: getHtmlElement
  5735. };
  5736. })();
  5737. PDFJS.AnnotationUtils = AnnotationUtils;
  5738. var NetworkManager = (function NetworkManagerClosure() {
  5739. var OK_RESPONSE = 200;
  5740. var PARTIAL_CONTENT_RESPONSE = 206;
  5741. function NetworkManager(url, args) {
  5742. this.url = url;
  5743. args = args || {};
  5744. this.isHttp = /^https?:/i.test(url);
  5745. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  5746. this.withCredentials = args.withCredentials || false;
  5747. this.getXhr = args.getXhr ||
  5748. function NetworkManager_getXhr() {
  5749. return new XMLHttpRequest();
  5750. };
  5751. this.currXhrId = 0;
  5752. this.pendingRequests = {};
  5753. this.loadedRequests = {};
  5754. }
  5755. function getArrayBuffer(xhr) {
  5756. var data = xhr.response;
  5757. if (typeof data !== 'string') {
  5758. return data;
  5759. }
  5760. var length = data.length;
  5761. var buffer = new Uint8Array(length);
  5762. for (var i = 0; i < length; i++) {
  5763. buffer[i] = data.charCodeAt(i) & 0xFF;
  5764. }
  5765. return buffer;
  5766. }
  5767. NetworkManager.prototype = {
  5768. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  5769. var args = {
  5770. begin: begin,
  5771. end: end
  5772. };
  5773. for (var prop in listeners) {
  5774. args[prop] = listeners[prop];
  5775. }
  5776. return this.request(args);
  5777. },
  5778. requestFull: function NetworkManager_requestRange(listeners) {
  5779. return this.request(listeners);
  5780. },
  5781. request: function NetworkManager_requestRange(args) {
  5782. var xhr = this.getXhr();
  5783. var xhrId = this.currXhrId++;
  5784. var pendingRequest = this.pendingRequests[xhrId] = {
  5785. xhr: xhr
  5786. };
  5787. xhr.open('GET', this.url);
  5788. xhr.withCredentials = this.withCredentials;
  5789. for (var property in this.httpHeaders) {
  5790. var value = this.httpHeaders[property];
  5791. if (typeof value === 'undefined') {
  5792. continue;
  5793. }
  5794. xhr.setRequestHeader(property, value);
  5795. }
  5796. if (this.isHttp && 'begin' in args && 'end' in args) {
  5797. var rangeStr = args.begin + '-' + (args.end - 1);
  5798. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  5799. pendingRequest.expectedStatus = 206;
  5800. } else {
  5801. pendingRequest.expectedStatus = 200;
  5802. }
  5803. xhr.responseType = 'arraybuffer';
  5804. if (args.onProgress) {
  5805. xhr.onprogress = args.onProgress;
  5806. }
  5807. if (args.onError) {
  5808. xhr.onerror = function(evt) {
  5809. args.onError(xhr.status);
  5810. };
  5811. }
  5812. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  5813. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  5814. pendingRequest.onDone = args.onDone;
  5815. pendingRequest.onError = args.onError;
  5816. xhr.send(null);
  5817. return xhrId;
  5818. },
  5819. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  5820. var pendingRequest = this.pendingRequests[xhrId];
  5821. if (!pendingRequest) {
  5822. // Maybe abortRequest was called...
  5823. return;
  5824. }
  5825. var xhr = pendingRequest.xhr;
  5826. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  5827. pendingRequest.onHeadersReceived();
  5828. delete pendingRequest.onHeadersReceived;
  5829. }
  5830. if (xhr.readyState !== 4) {
  5831. return;
  5832. }
  5833. if (!(xhrId in this.pendingRequests)) {
  5834. // The XHR request might have been aborted in onHeadersReceived()
  5835. // callback, in which case we should abort request
  5836. return;
  5837. }
  5838. delete this.pendingRequests[xhrId];
  5839. // success status == 0 can be on ftp, file and other protocols
  5840. if (xhr.status === 0 && this.isHttp) {
  5841. if (pendingRequest.onError) {
  5842. pendingRequest.onError(xhr.status);
  5843. }
  5844. return;
  5845. }
  5846. var xhrStatus = xhr.status || OK_RESPONSE;
  5847. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  5848. // "A server MAY ignore the Range header". This means it's possible to
  5849. // get a 200 rather than a 206 response from a range request.
  5850. var ok_response_on_range_request =
  5851. xhrStatus === OK_RESPONSE &&
  5852. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  5853. if (!ok_response_on_range_request &&
  5854. xhrStatus !== pendingRequest.expectedStatus) {
  5855. if (pendingRequest.onError) {
  5856. pendingRequest.onError(xhr.status);
  5857. }
  5858. return;
  5859. }
  5860. this.loadedRequests[xhrId] = true;
  5861. var chunk = getArrayBuffer(xhr);
  5862. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  5863. var rangeHeader = xhr.getResponseHeader('Content-Range');
  5864. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  5865. var begin = parseInt(matches[1], 10);
  5866. pendingRequest.onDone({
  5867. begin: begin,
  5868. chunk: chunk
  5869. });
  5870. } else {
  5871. pendingRequest.onDone({
  5872. begin: 0,
  5873. chunk: chunk
  5874. });
  5875. }
  5876. },
  5877. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  5878. for (var xhrId in this.pendingRequests) {
  5879. return true;
  5880. }
  5881. return false;
  5882. },
  5883. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  5884. return this.pendingRequests[xhrId].xhr;
  5885. },
  5886. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  5887. return xhrId in this.pendingRequests;
  5888. },
  5889. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  5890. return xhrId in this.loadedRequests;
  5891. },
  5892. abortAllRequests: function NetworkManager_abortAllRequests() {
  5893. for (var xhrId in this.pendingRequests) {
  5894. this.abortRequest(xhrId | 0);
  5895. }
  5896. },
  5897. abortRequest: function NetworkManager_abortRequest(xhrId) {
  5898. var xhr = this.pendingRequests[xhrId].xhr;
  5899. delete this.pendingRequests[xhrId];
  5900. xhr.abort();
  5901. }
  5902. };
  5903. return NetworkManager;
  5904. })();
  5905. var ChunkedStream = (function ChunkedStreamClosure() {
  5906. function ChunkedStream(length, chunkSize, manager) {
  5907. this.bytes = new Uint8Array(length);
  5908. this.start = 0;
  5909. this.pos = 0;
  5910. this.end = length;
  5911. this.chunkSize = chunkSize;
  5912. this.loadedChunks = [];
  5913. this.numChunksLoaded = 0;
  5914. this.numChunks = Math.ceil(length / chunkSize);
  5915. this.manager = manager;
  5916. this.initialDataLength = 0;
  5917. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  5918. }
  5919. // required methods for a stream. if a particular stream does not
  5920. // implement these, an error should be thrown
  5921. ChunkedStream.prototype = {
  5922. getMissingChunks: function ChunkedStream_getMissingChunks() {
  5923. var chunks = [];
  5924. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  5925. if (!(chunk in this.loadedChunks)) {
  5926. chunks.push(chunk);
  5927. }
  5928. }
  5929. return chunks;
  5930. },
  5931. getBaseStreams: function ChunkedStream_getBaseStreams() {
  5932. return [this];
  5933. },
  5934. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  5935. return this.numChunksLoaded === this.numChunks;
  5936. },
  5937. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  5938. var end = begin + chunk.byteLength;
  5939. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  5940. // Using this.length is inaccurate here since this.start can be moved
  5941. // See ChunkedStream.moveStart()
  5942. var length = this.bytes.length;
  5943. assert(end % this.chunkSize === 0 || end === length,
  5944. 'Bad end offset: ' + end);
  5945. this.bytes.set(new Uint8Array(chunk), begin);
  5946. var chunkSize = this.chunkSize;
  5947. var beginChunk = Math.floor(begin / chunkSize);
  5948. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  5949. var curChunk;
  5950. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  5951. if (!(curChunk in this.loadedChunks)) {
  5952. this.loadedChunks[curChunk] = true;
  5953. ++this.numChunksLoaded;
  5954. }
  5955. }
  5956. },
  5957. onReceiveInitialData: function ChunkedStream_onReceiveInitialData(data) {
  5958. this.bytes.set(data);
  5959. this.initialDataLength = data.length;
  5960. var endChunk = (this.end === data.length ?
  5961. this.numChunks : Math.floor(data.length / this.chunkSize));
  5962. for (var i = 0; i < endChunk; i++) {
  5963. this.loadedChunks[i] = true;
  5964. ++this.numChunksLoaded;
  5965. }
  5966. },
  5967. ensureByte: function ChunkedStream_ensureRange(pos) {
  5968. var chunk = Math.floor(pos / this.chunkSize);
  5969. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  5970. return;
  5971. }
  5972. if (!(chunk in this.loadedChunks)) {
  5973. throw new MissingDataException(pos, pos + 1);
  5974. }
  5975. this.lastSuccessfulEnsureByteChunk = chunk;
  5976. },
  5977. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  5978. if (begin >= end) {
  5979. return;
  5980. }
  5981. if (end <= this.initialDataLength) {
  5982. return;
  5983. }
  5984. var chunkSize = this.chunkSize;
  5985. var beginChunk = Math.floor(begin / chunkSize);
  5986. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  5987. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5988. if (!(chunk in this.loadedChunks)) {
  5989. throw new MissingDataException(begin, end);
  5990. }
  5991. }
  5992. },
  5993. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  5994. var chunk, n;
  5995. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  5996. if (!(chunk in this.loadedChunks)) {
  5997. return chunk;
  5998. }
  5999. }
  6000. // Wrap around to beginning
  6001. for (chunk = 0; chunk < beginChunk; ++chunk) {
  6002. if (!(chunk in this.loadedChunks)) {
  6003. return chunk;
  6004. }
  6005. }
  6006. return null;
  6007. },
  6008. hasChunk: function ChunkedStream_hasChunk(chunk) {
  6009. return chunk in this.loadedChunks;
  6010. },
  6011. get length() {
  6012. return this.end - this.start;
  6013. },
  6014. get isEmpty() {
  6015. return this.length === 0;
  6016. },
  6017. getByte: function ChunkedStream_getByte() {
  6018. var pos = this.pos;
  6019. if (pos >= this.end) {
  6020. return -1;
  6021. }
  6022. var byte = this.bytes[pos];
  6023. if (byte === 0) {
  6024. // |byte| might be zero, because the corresponding chunk has not been
  6025. // loaded yet. In this case, this.ensureByte(pos) will throw an
  6026. // exception and nothing is returned.
  6027. this.ensureByte(pos);
  6028. }
  6029. this.pos++;
  6030. return byte;
  6031. },
  6032. getUint16: function ChunkedStream_getUint16() {
  6033. var b0 = this.getByte();
  6034. var b1 = this.getByte();
  6035. return (b0 << 8) + b1;
  6036. },
  6037. getInt32: function ChunkedStream_getInt32() {
  6038. var b0 = this.getByte();
  6039. var b1 = this.getByte();
  6040. var b2 = this.getByte();
  6041. var b3 = this.getByte();
  6042. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  6043. },
  6044. // returns subarray of original buffer
  6045. // should only be read
  6046. getBytes: function ChunkedStream_getBytes(length) {
  6047. var bytes = this.bytes;
  6048. var pos = this.pos;
  6049. var strEnd = this.end;
  6050. if (!length) {
  6051. this.ensureRange(pos, strEnd);
  6052. return bytes.subarray(pos, strEnd);
  6053. }
  6054. var end = pos + length;
  6055. if (end > strEnd) {
  6056. end = strEnd;
  6057. }
  6058. this.ensureRange(pos, end);
  6059. this.pos = end;
  6060. return bytes.subarray(pos, end);
  6061. },
  6062. peekBytes: function ChunkedStream_peekBytes(length) {
  6063. var bytes = this.getBytes(length);
  6064. this.pos -= bytes.length;
  6065. return bytes;
  6066. },
  6067. getByteRange: function ChunkedStream_getBytes(begin, end) {
  6068. this.ensureRange(begin, end);
  6069. return this.bytes.subarray(begin, end);
  6070. },
  6071. skip: function ChunkedStream_skip(n) {
  6072. if (!n) {
  6073. n = 1;
  6074. }
  6075. this.pos += n;
  6076. },
  6077. reset: function ChunkedStream_reset() {
  6078. this.pos = this.start;
  6079. },
  6080. moveStart: function ChunkedStream_moveStart() {
  6081. this.start = this.pos;
  6082. },
  6083. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  6084. this.ensureRange(start, start + length);
  6085. function ChunkedStreamSubstream() {}
  6086. ChunkedStreamSubstream.prototype = Object.create(this);
  6087. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  6088. var chunkSize = this.chunkSize;
  6089. var beginChunk = Math.floor(this.start / chunkSize);
  6090. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  6091. var missingChunks = [];
  6092. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  6093. if (!(chunk in this.loadedChunks)) {
  6094. missingChunks.push(chunk);
  6095. }
  6096. }
  6097. return missingChunks;
  6098. };
  6099. var subStream = new ChunkedStreamSubstream();
  6100. subStream.pos = subStream.start = start;
  6101. subStream.end = start + length || this.end;
  6102. subStream.dict = dict;
  6103. return subStream;
  6104. },
  6105. isStream: true
  6106. };
  6107. return ChunkedStream;
  6108. })();
  6109. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  6110. function ChunkedStreamManager(length, chunkSize, url, args) {
  6111. this.stream = new ChunkedStream(length, chunkSize, this);
  6112. this.length = length;
  6113. this.chunkSize = chunkSize;
  6114. this.url = url;
  6115. this.disableAutoFetch = args.disableAutoFetch;
  6116. var msgHandler = this.msgHandler = args.msgHandler;
  6117. if (args.chunkedViewerLoading) {
  6118. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  6119. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  6120. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  6121. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  6122. };
  6123. } else {
  6124. var getXhr = function getXhr() {
  6125. return new XMLHttpRequest();
  6126. };
  6127. this.networkManager = new NetworkManager(this.url, {
  6128. getXhr: getXhr,
  6129. httpHeaders: args.httpHeaders,
  6130. withCredentials: args.withCredentials
  6131. });
  6132. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  6133. this.networkManager.requestRange(begin, end, {
  6134. onDone: this.onReceiveData.bind(this),
  6135. onProgress: this.onProgress.bind(this)
  6136. });
  6137. };
  6138. }
  6139. this.currRequestId = 0;
  6140. this.chunksNeededByRequest = {};
  6141. this.requestsByChunk = {};
  6142. this.callbacksByRequest = {};
  6143. this._loadedStreamCapability = createPromiseCapability();
  6144. if (args.initialData) {
  6145. this.setInitialData(args.initialData);
  6146. }
  6147. }
  6148. ChunkedStreamManager.prototype = {
  6149. setInitialData: function ChunkedStreamManager_setInitialData(data) {
  6150. this.stream.onReceiveInitialData(data);
  6151. if (this.stream.allChunksLoaded()) {
  6152. this._loadedStreamCapability.resolve(this.stream);
  6153. } else if (this.msgHandler) {
  6154. this.msgHandler.send('DocProgress', {
  6155. loaded: data.length,
  6156. total: this.length
  6157. });
  6158. }
  6159. },
  6160. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  6161. return this._loadedStreamCapability.promise;
  6162. },
  6163. // Get all the chunks that are not yet loaded and groups them into
  6164. // contiguous ranges to load in as few requests as possible
  6165. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  6166. var missingChunks = this.stream.getMissingChunks();
  6167. this.requestChunks(missingChunks);
  6168. return this._loadedStreamCapability.promise;
  6169. },
  6170. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  6171. callback) {
  6172. var requestId = this.currRequestId++;
  6173. var chunksNeeded;
  6174. var i, ii;
  6175. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  6176. for (i = 0, ii = chunks.length; i < ii; i++) {
  6177. if (!this.stream.hasChunk(chunks[i])) {
  6178. chunksNeeded[chunks[i]] = true;
  6179. }
  6180. }
  6181. if (isEmptyObj(chunksNeeded)) {
  6182. if (callback) {
  6183. callback();
  6184. }
  6185. return;
  6186. }
  6187. this.callbacksByRequest[requestId] = callback;
  6188. var chunksToRequest = [];
  6189. for (var chunk in chunksNeeded) {
  6190. chunk = chunk | 0;
  6191. if (!(chunk in this.requestsByChunk)) {
  6192. this.requestsByChunk[chunk] = [];
  6193. chunksToRequest.push(chunk);
  6194. }
  6195. this.requestsByChunk[chunk].push(requestId);
  6196. }
  6197. if (!chunksToRequest.length) {
  6198. return;
  6199. }
  6200. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  6201. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  6202. var groupedChunk = groupedChunksToRequest[i];
  6203. var begin = groupedChunk.beginChunk * this.chunkSize;
  6204. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  6205. this.sendRequest(begin, end);
  6206. }
  6207. },
  6208. getStream: function ChunkedStreamManager_getStream() {
  6209. return this.stream;
  6210. },
  6211. // Loads any chunks in the requested range that are not yet loaded
  6212. requestRange: function ChunkedStreamManager_requestRange(
  6213. begin, end, callback) {
  6214. end = Math.min(end, this.length);
  6215. var beginChunk = this.getBeginChunk(begin);
  6216. var endChunk = this.getEndChunk(end);
  6217. var chunks = [];
  6218. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  6219. chunks.push(chunk);
  6220. }
  6221. this.requestChunks(chunks, callback);
  6222. },
  6223. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  6224. callback) {
  6225. ranges = ranges || [];
  6226. var chunksToRequest = [];
  6227. for (var i = 0; i < ranges.length; i++) {
  6228. var beginChunk = this.getBeginChunk(ranges[i].begin);
  6229. var endChunk = this.getEndChunk(ranges[i].end);
  6230. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  6231. if (chunksToRequest.indexOf(chunk) < 0) {
  6232. chunksToRequest.push(chunk);
  6233. }
  6234. }
  6235. }
  6236. chunksToRequest.sort(function(a, b) { return a - b; });
  6237. this.requestChunks(chunksToRequest, callback);
  6238. },
  6239. // Groups a sorted array of chunks into as few continguous larger
  6240. // chunks as possible
  6241. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  6242. var groupedChunks = [];
  6243. var beginChunk = -1;
  6244. var prevChunk = -1;
  6245. for (var i = 0; i < chunks.length; ++i) {
  6246. var chunk = chunks[i];
  6247. if (beginChunk < 0) {
  6248. beginChunk = chunk;
  6249. }
  6250. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  6251. groupedChunks.push({ beginChunk: beginChunk,
  6252. endChunk: prevChunk + 1 });
  6253. beginChunk = chunk;
  6254. }
  6255. if (i + 1 === chunks.length) {
  6256. groupedChunks.push({ beginChunk: beginChunk,
  6257. endChunk: chunk + 1 });
  6258. }
  6259. prevChunk = chunk;
  6260. }
  6261. return groupedChunks;
  6262. },
  6263. onProgress: function ChunkedStreamManager_onProgress(args) {
  6264. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  6265. args.loaded);
  6266. this.msgHandler.send('DocProgress', {
  6267. loaded: bytesLoaded,
  6268. total: this.length
  6269. });
  6270. },
  6271. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  6272. var chunk = args.chunk;
  6273. var begin = args.begin;
  6274. var end = begin + chunk.byteLength;
  6275. var beginChunk = this.getBeginChunk(begin);
  6276. var endChunk = this.getEndChunk(end);
  6277. this.stream.onReceiveData(begin, chunk);
  6278. if (this.stream.allChunksLoaded()) {
  6279. this._loadedStreamCapability.resolve(this.stream);
  6280. }
  6281. var loadedRequests = [];
  6282. var i, requestId;
  6283. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  6284. // The server might return more chunks than requested
  6285. var requestIds = this.requestsByChunk[chunk] || [];
  6286. delete this.requestsByChunk[chunk];
  6287. for (i = 0; i < requestIds.length; ++i) {
  6288. requestId = requestIds[i];
  6289. var chunksNeeded = this.chunksNeededByRequest[requestId];
  6290. if (chunk in chunksNeeded) {
  6291. delete chunksNeeded[chunk];
  6292. }
  6293. if (!isEmptyObj(chunksNeeded)) {
  6294. continue;
  6295. }
  6296. loadedRequests.push(requestId);
  6297. }
  6298. }
  6299. // If there are no pending requests, automatically fetch the next
  6300. // unfetched chunk of the PDF
  6301. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  6302. var nextEmptyChunk;
  6303. if (this.stream.numChunksLoaded === 1) {
  6304. // This is a special optimization so that after fetching the first
  6305. // chunk, rather than fetching the second chunk, we fetch the last
  6306. // chunk.
  6307. var lastChunk = this.stream.numChunks - 1;
  6308. if (!this.stream.hasChunk(lastChunk)) {
  6309. nextEmptyChunk = lastChunk;
  6310. }
  6311. } else {
  6312. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  6313. }
  6314. if (isInt(nextEmptyChunk)) {
  6315. this.requestChunks([nextEmptyChunk]);
  6316. }
  6317. }
  6318. for (i = 0; i < loadedRequests.length; ++i) {
  6319. requestId = loadedRequests[i];
  6320. var callback = this.callbacksByRequest[requestId];
  6321. delete this.callbacksByRequest[requestId];
  6322. if (callback) {
  6323. callback();
  6324. }
  6325. }
  6326. this.msgHandler.send('DocProgress', {
  6327. loaded: this.stream.numChunksLoaded * this.chunkSize,
  6328. total: this.length
  6329. });
  6330. },
  6331. onError: function ChunkedStreamManager_onError(err) {
  6332. this._loadedStreamCapability.reject(err);
  6333. },
  6334. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  6335. var chunk = Math.floor(begin / this.chunkSize);
  6336. return chunk;
  6337. },
  6338. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  6339. if (end % this.chunkSize === 0) {
  6340. return end / this.chunkSize;
  6341. }
  6342. // 0 -> 0
  6343. // 1 -> 1
  6344. // 99 -> 1
  6345. // 100 -> 1
  6346. // 101 -> 2
  6347. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  6348. return chunk;
  6349. }
  6350. };
  6351. return ChunkedStreamManager;
  6352. })();
  6353. // The maximum number of bytes fetched per range request
  6354. var RANGE_CHUNK_SIZE = 65536;
  6355. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  6356. var BasePdfManager = (function BasePdfManagerClosure() {
  6357. function BasePdfManager() {
  6358. throw new Error('Cannot initialize BaseManagerManager');
  6359. }
  6360. BasePdfManager.prototype = {
  6361. onLoadedStream: function BasePdfManager_onLoadedStream() {
  6362. throw new NotImplementedException();
  6363. },
  6364. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  6365. return this.ensure(this.pdfDocument, prop, args);
  6366. },
  6367. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  6368. return this.ensure(this.pdfDocument.xref, prop, args);
  6369. },
  6370. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  6371. return this.ensure(this.pdfDocument.catalog, prop, args);
  6372. },
  6373. getPage: function BasePdfManager_pagePage(pageIndex) {
  6374. return this.pdfDocument.getPage(pageIndex);
  6375. },
  6376. cleanup: function BasePdfManager_cleanup() {
  6377. return this.pdfDocument.cleanup();
  6378. },
  6379. ensure: function BasePdfManager_ensure(obj, prop, args) {
  6380. return new NotImplementedException();
  6381. },
  6382. requestRange: function BasePdfManager_ensure(begin, end) {
  6383. return new NotImplementedException();
  6384. },
  6385. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  6386. return new NotImplementedException();
  6387. },
  6388. updatePassword: function BasePdfManager_updatePassword(password) {
  6389. this.pdfDocument.xref.password = this.password = password;
  6390. if (this._passwordChangedCapability) {
  6391. this._passwordChangedCapability.resolve();
  6392. }
  6393. },
  6394. passwordChanged: function BasePdfManager_passwordChanged() {
  6395. this._passwordChangedCapability = createPromiseCapability();
  6396. return this._passwordChangedCapability.promise;
  6397. },
  6398. terminate: function BasePdfManager_terminate() {
  6399. return new NotImplementedException();
  6400. }
  6401. };
  6402. return BasePdfManager;
  6403. })();
  6404. var LocalPdfManager = (function LocalPdfManagerClosure() {
  6405. function LocalPdfManager(data, password) {
  6406. var stream = new Stream(data);
  6407. this.pdfDocument = new PDFDocument(this, stream, password);
  6408. this._loadedStreamCapability = createPromiseCapability();
  6409. this._loadedStreamCapability.resolve(stream);
  6410. }
  6411. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  6412. LocalPdfManager.prototype.constructor = LocalPdfManager;
  6413. LocalPdfManager.prototype.ensure =
  6414. function LocalPdfManager_ensure(obj, prop, args) {
  6415. return new Promise(function (resolve, reject) {
  6416. try {
  6417. var value = obj[prop];
  6418. var result;
  6419. if (typeof value === 'function') {
  6420. result = value.apply(obj, args);
  6421. } else {
  6422. result = value;
  6423. }
  6424. resolve(result);
  6425. } catch (e) {
  6426. reject(e);
  6427. }
  6428. });
  6429. };
  6430. LocalPdfManager.prototype.requestRange =
  6431. function LocalPdfManager_requestRange(begin, end) {
  6432. return Promise.resolve();
  6433. };
  6434. LocalPdfManager.prototype.requestLoadedStream =
  6435. function LocalPdfManager_requestLoadedStream() {
  6436. };
  6437. LocalPdfManager.prototype.onLoadedStream =
  6438. function LocalPdfManager_getLoadedStream() {
  6439. return this._loadedStreamCapability.promise;
  6440. };
  6441. LocalPdfManager.prototype.terminate =
  6442. function LocalPdfManager_terminate() {
  6443. return;
  6444. };
  6445. return LocalPdfManager;
  6446. })();
  6447. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  6448. function NetworkPdfManager(args, msgHandler) {
  6449. this.msgHandler = msgHandler;
  6450. var params = {
  6451. msgHandler: msgHandler,
  6452. httpHeaders: args.httpHeaders,
  6453. withCredentials: args.withCredentials,
  6454. chunkedViewerLoading: args.chunkedViewerLoading,
  6455. disableAutoFetch: args.disableAutoFetch,
  6456. initialData: args.initialData
  6457. };
  6458. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  6459. args.url, params);
  6460. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  6461. args.password);
  6462. }
  6463. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  6464. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  6465. NetworkPdfManager.prototype.ensure =
  6466. function NetworkPdfManager_ensure(obj, prop, args) {
  6467. var pdfManager = this;
  6468. return new Promise(function (resolve, reject) {
  6469. function ensureHelper() {
  6470. try {
  6471. var result;
  6472. var value = obj[prop];
  6473. if (typeof value === 'function') {
  6474. result = value.apply(obj, args);
  6475. } else {
  6476. result = value;
  6477. }
  6478. resolve(result);
  6479. } catch(e) {
  6480. if (!(e instanceof MissingDataException)) {
  6481. reject(e);
  6482. return;
  6483. }
  6484. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  6485. }
  6486. }
  6487. ensureHelper();
  6488. });
  6489. };
  6490. NetworkPdfManager.prototype.requestRange =
  6491. function NetworkPdfManager_requestRange(begin, end) {
  6492. return new Promise(function (resolve) {
  6493. this.streamManager.requestRange(begin, end, function() {
  6494. resolve();
  6495. });
  6496. }.bind(this));
  6497. };
  6498. NetworkPdfManager.prototype.requestLoadedStream =
  6499. function NetworkPdfManager_requestLoadedStream() {
  6500. this.streamManager.requestAllChunks();
  6501. };
  6502. NetworkPdfManager.prototype.onLoadedStream =
  6503. function NetworkPdfManager_getLoadedStream() {
  6504. return this.streamManager.onLoadedStream();
  6505. };
  6506. NetworkPdfManager.prototype.terminate =
  6507. function NetworkPdfManager_terminate() {
  6508. this.streamManager.networkManager.abortAllRequests();
  6509. };
  6510. return NetworkPdfManager;
  6511. })();
  6512. var Page = (function PageClosure() {
  6513. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  6514. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  6515. this.pdfManager = pdfManager;
  6516. this.pageIndex = pageIndex;
  6517. this.pageDict = pageDict;
  6518. this.xref = xref;
  6519. this.ref = ref;
  6520. this.fontCache = fontCache;
  6521. this.idCounters = {
  6522. obj: 0
  6523. };
  6524. this.resourcesPromise = null;
  6525. }
  6526. Page.prototype = {
  6527. getPageProp: function Page_getPageProp(key) {
  6528. return this.pageDict.get(key);
  6529. },
  6530. getInheritedPageProp: function Page_inheritPageProp(key) {
  6531. var dict = this.pageDict;
  6532. var value = dict.get(key);
  6533. while (value === undefined) {
  6534. dict = dict.get('Parent');
  6535. if (!dict) {
  6536. break;
  6537. }
  6538. value = dict.get(key);
  6539. }
  6540. return value;
  6541. },
  6542. get content() {
  6543. return this.getPageProp('Contents');
  6544. },
  6545. get resources() {
  6546. var value = this.getInheritedPageProp('Resources');
  6547. // For robustness: The spec states that a \Resources entry has to be
  6548. // present, but can be empty. Some document omit it still. In this case
  6549. // return an empty dictionary:
  6550. if (value === undefined) {
  6551. value = Dict.empty;
  6552. }
  6553. return shadow(this, 'resources', value);
  6554. },
  6555. get mediaBox() {
  6556. var obj = this.getInheritedPageProp('MediaBox');
  6557. // Reset invalid media box to letter size.
  6558. if (!isArray(obj) || obj.length !== 4) {
  6559. obj = LETTER_SIZE_MEDIABOX;
  6560. }
  6561. return shadow(this, 'mediaBox', obj);
  6562. },
  6563. get view() {
  6564. var mediaBox = this.mediaBox;
  6565. var cropBox = this.getInheritedPageProp('CropBox');
  6566. if (!isArray(cropBox) || cropBox.length !== 4) {
  6567. return shadow(this, 'view', mediaBox);
  6568. }
  6569. // From the spec, 6th ed., p.963:
  6570. // "The crop, bleed, trim, and art boxes should not ordinarily
  6571. // extend beyond the boundaries of the media box. If they do, they are
  6572. // effectively reduced to their intersection with the media box."
  6573. cropBox = Util.intersect(cropBox, mediaBox);
  6574. if (!cropBox) {
  6575. return shadow(this, 'view', mediaBox);
  6576. }
  6577. return shadow(this, 'view', cropBox);
  6578. },
  6579. get annotationRefs() {
  6580. return shadow(this, 'annotationRefs',
  6581. this.getInheritedPageProp('Annots'));
  6582. },
  6583. get rotate() {
  6584. var rotate = this.getInheritedPageProp('Rotate') || 0;
  6585. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  6586. if (rotate % 90 !== 0) {
  6587. rotate = 0;
  6588. } else if (rotate >= 360) {
  6589. rotate = rotate % 360;
  6590. } else if (rotate < 0) {
  6591. // The spec doesn't cover negatives, assume its counterclockwise
  6592. // rotation. The following is the other implementation of modulo.
  6593. rotate = ((rotate % 360) + 360) % 360;
  6594. }
  6595. return shadow(this, 'rotate', rotate);
  6596. },
  6597. getContentStream: function Page_getContentStream() {
  6598. var content = this.content;
  6599. var stream;
  6600. if (isArray(content)) {
  6601. // fetching items
  6602. var xref = this.xref;
  6603. var i, n = content.length;
  6604. var streams = [];
  6605. for (i = 0; i < n; ++i) {
  6606. streams.push(xref.fetchIfRef(content[i]));
  6607. }
  6608. stream = new StreamsSequenceStream(streams);
  6609. } else if (isStream(content)) {
  6610. stream = content;
  6611. } else {
  6612. // replacing non-existent page content with empty one
  6613. stream = new NullStream();
  6614. }
  6615. return stream;
  6616. },
  6617. loadResources: function Page_loadResources(keys) {
  6618. if (!this.resourcesPromise) {
  6619. // TODO: add async getInheritedPageProp and remove this.
  6620. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  6621. }
  6622. return this.resourcesPromise.then(function resourceSuccess() {
  6623. var objectLoader = new ObjectLoader(this.resources.map,
  6624. keys,
  6625. this.xref);
  6626. return objectLoader.load();
  6627. }.bind(this));
  6628. },
  6629. getOperatorList: function Page_getOperatorList(handler, intent) {
  6630. var self = this;
  6631. var pdfManager = this.pdfManager;
  6632. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  6633. []);
  6634. var resourcesPromise = this.loadResources([
  6635. 'ExtGState',
  6636. 'ColorSpace',
  6637. 'Pattern',
  6638. 'Shading',
  6639. 'XObject',
  6640. 'Font'
  6641. // ProcSet
  6642. // Properties
  6643. ]);
  6644. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  6645. handler, this.pageIndex,
  6646. 'p' + this.pageIndex + '_',
  6647. this.idCounters,
  6648. this.fontCache);
  6649. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  6650. var pageListPromise = dataPromises.then(function(data) {
  6651. var contentStream = data[0];
  6652. var opList = new OperatorList(intent, handler, self.pageIndex);
  6653. handler.send('StartRenderPage', {
  6654. transparency: partialEvaluator.hasBlendModes(self.resources),
  6655. pageIndex: self.pageIndex,
  6656. intent: intent
  6657. });
  6658. return partialEvaluator.getOperatorList(contentStream, self.resources,
  6659. opList).then(function () {
  6660. return opList;
  6661. });
  6662. });
  6663. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  6664. return Promise.all([pageListPromise, annotationsPromise]).then(
  6665. function(datas) {
  6666. var pageOpList = datas[0];
  6667. var annotations = datas[1];
  6668. if (annotations.length === 0) {
  6669. pageOpList.flush(true);
  6670. return pageOpList;
  6671. }
  6672. var annotationsReadyPromise = Annotation.appendToOperatorList(
  6673. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  6674. return annotationsReadyPromise.then(function () {
  6675. pageOpList.flush(true);
  6676. return pageOpList;
  6677. });
  6678. });
  6679. },
  6680. extractTextContent: function Page_extractTextContent() {
  6681. var handler = {
  6682. on: function nullHandlerOn() {},
  6683. send: function nullHandlerSend() {}
  6684. };
  6685. var self = this;
  6686. var pdfManager = this.pdfManager;
  6687. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  6688. []);
  6689. var resourcesPromise = this.loadResources([
  6690. 'ExtGState',
  6691. 'XObject',
  6692. 'Font'
  6693. ]);
  6694. var dataPromises = Promise.all([contentStreamPromise,
  6695. resourcesPromise]);
  6696. return dataPromises.then(function(data) {
  6697. var contentStream = data[0];
  6698. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  6699. handler, self.pageIndex,
  6700. 'p' + self.pageIndex + '_',
  6701. self.idCounters,
  6702. self.fontCache);
  6703. return partialEvaluator.getTextContent(contentStream,
  6704. self.resources);
  6705. });
  6706. },
  6707. getAnnotationsData: function Page_getAnnotationsData() {
  6708. var annotations = this.annotations;
  6709. var annotationsData = [];
  6710. for (var i = 0, n = annotations.length; i < n; ++i) {
  6711. annotationsData.push(annotations[i].getData());
  6712. }
  6713. return annotationsData;
  6714. },
  6715. get annotations() {
  6716. var annotations = [];
  6717. var annotationRefs = (this.annotationRefs || []);
  6718. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  6719. var annotationRef = annotationRefs[i];
  6720. var annotation = Annotation.fromRef(this.xref, annotationRef);
  6721. if (annotation) {
  6722. annotations.push(annotation);
  6723. }
  6724. }
  6725. return shadow(this, 'annotations', annotations);
  6726. }
  6727. };
  6728. return Page;
  6729. })();
  6730. /**
  6731. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  6732. * `PDFDoc`, this one doesn't have any job management code.
  6733. * Right now there exists one PDFDocument on the main thread + one object
  6734. * for each worker. If there is no worker support enabled, there are two
  6735. * `PDFDocument` objects on the main thread created.
  6736. */
  6737. var PDFDocument = (function PDFDocumentClosure() {
  6738. function PDFDocument(pdfManager, arg, password) {
  6739. if (isStream(arg)) {
  6740. init.call(this, pdfManager, arg, password);
  6741. } else if (isArrayBuffer(arg)) {
  6742. init.call(this, pdfManager, new Stream(arg), password);
  6743. } else {
  6744. error('PDFDocument: Unknown argument type');
  6745. }
  6746. }
  6747. function init(pdfManager, stream, password) {
  6748. assert(stream.length > 0, 'stream must have data');
  6749. this.pdfManager = pdfManager;
  6750. this.stream = stream;
  6751. var xref = new XRef(this.stream, password, pdfManager);
  6752. this.xref = xref;
  6753. }
  6754. function find(stream, needle, limit, backwards) {
  6755. var pos = stream.pos;
  6756. var end = stream.end;
  6757. var strBuf = [];
  6758. if (pos + limit > end) {
  6759. limit = end - pos;
  6760. }
  6761. for (var n = 0; n < limit; ++n) {
  6762. strBuf.push(String.fromCharCode(stream.getByte()));
  6763. }
  6764. var str = strBuf.join('');
  6765. stream.pos = pos;
  6766. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  6767. if (index === -1) {
  6768. return false; /* not found */
  6769. }
  6770. stream.pos += index;
  6771. return true; /* found */
  6772. }
  6773. var DocumentInfoValidators = {
  6774. get entries() {
  6775. // Lazily build this since all the validation functions below are not
  6776. // defined until after this file loads.
  6777. return shadow(this, 'entries', {
  6778. Title: isString,
  6779. Author: isString,
  6780. Subject: isString,
  6781. Keywords: isString,
  6782. Creator: isString,
  6783. Producer: isString,
  6784. CreationDate: isString,
  6785. ModDate: isString,
  6786. Trapped: isName
  6787. });
  6788. }
  6789. };
  6790. PDFDocument.prototype = {
  6791. parse: function PDFDocument_parse(recoveryMode) {
  6792. this.setup(recoveryMode);
  6793. try {
  6794. // checking if AcroForm is present
  6795. this.acroForm = this.catalog.catDict.get('AcroForm');
  6796. if (this.acroForm) {
  6797. this.xfa = this.acroForm.get('XFA');
  6798. var fields = this.acroForm.get('Fields');
  6799. if ((!fields || !isArray(fields) || fields.length === 0) &&
  6800. !this.xfa) {
  6801. // no fields and no XFA -- not a form (?)
  6802. this.acroForm = null;
  6803. }
  6804. }
  6805. } catch (ex) {
  6806. info('Something wrong with AcroForm entry');
  6807. this.acroForm = null;
  6808. }
  6809. },
  6810. get linearization() {
  6811. var linearization = null;
  6812. if (this.stream.length) {
  6813. try {
  6814. linearization = Linearization.create(this.stream);
  6815. } catch (err) {
  6816. if (err instanceof MissingDataException) {
  6817. throw err;
  6818. }
  6819. info(err);
  6820. }
  6821. }
  6822. // shadow the prototype getter with a data property
  6823. return shadow(this, 'linearization', linearization);
  6824. },
  6825. get startXRef() {
  6826. var stream = this.stream;
  6827. var startXRef = 0;
  6828. var linearization = this.linearization;
  6829. if (linearization) {
  6830. // Find end of first obj.
  6831. stream.reset();
  6832. if (find(stream, 'endobj', 1024)) {
  6833. startXRef = stream.pos + 6;
  6834. }
  6835. } else {
  6836. // Find startxref by jumping backward from the end of the file.
  6837. var step = 1024;
  6838. var found = false, pos = stream.end;
  6839. while (!found && pos > 0) {
  6840. pos -= step - 'startxref'.length;
  6841. if (pos < 0) {
  6842. pos = 0;
  6843. }
  6844. stream.pos = pos;
  6845. found = find(stream, 'startxref', step, true);
  6846. }
  6847. if (found) {
  6848. stream.skip(9);
  6849. var ch;
  6850. do {
  6851. ch = stream.getByte();
  6852. } while (Lexer.isSpace(ch));
  6853. var str = '';
  6854. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  6855. str += String.fromCharCode(ch);
  6856. ch = stream.getByte();
  6857. }
  6858. startXRef = parseInt(str, 10);
  6859. if (isNaN(startXRef)) {
  6860. startXRef = 0;
  6861. }
  6862. }
  6863. }
  6864. // shadow the prototype getter with a data property
  6865. return shadow(this, 'startXRef', startXRef);
  6866. },
  6867. get mainXRefEntriesOffset() {
  6868. var mainXRefEntriesOffset = 0;
  6869. var linearization = this.linearization;
  6870. if (linearization) {
  6871. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  6872. }
  6873. // shadow the prototype getter with a data property
  6874. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  6875. },
  6876. // Find the header, remove leading garbage and setup the stream
  6877. // starting from the header.
  6878. checkHeader: function PDFDocument_checkHeader() {
  6879. var stream = this.stream;
  6880. stream.reset();
  6881. if (find(stream, '%PDF-', 1024)) {
  6882. // Found the header, trim off any garbage before it.
  6883. stream.moveStart();
  6884. // Reading file format version
  6885. var MAX_VERSION_LENGTH = 12;
  6886. var version = '', ch;
  6887. while ((ch = stream.getByte()) > 0x20) { // SPACE
  6888. if (version.length >= MAX_VERSION_LENGTH) {
  6889. break;
  6890. }
  6891. version += String.fromCharCode(ch);
  6892. }
  6893. // removing "%PDF-"-prefix
  6894. this.pdfFormatVersion = version.substring(5);
  6895. return;
  6896. }
  6897. // May not be a PDF file, continue anyway.
  6898. },
  6899. parseStartXRef: function PDFDocument_parseStartXRef() {
  6900. var startXRef = this.startXRef;
  6901. this.xref.setStartXRef(startXRef);
  6902. },
  6903. setup: function PDFDocument_setup(recoveryMode) {
  6904. this.xref.parse(recoveryMode);
  6905. this.catalog = new Catalog(this.pdfManager, this.xref);
  6906. },
  6907. get numPages() {
  6908. var linearization = this.linearization;
  6909. var num = linearization ? linearization.numPages : this.catalog.numPages;
  6910. // shadow the prototype getter
  6911. return shadow(this, 'numPages', num);
  6912. },
  6913. get documentInfo() {
  6914. var docInfo = {
  6915. PDFFormatVersion: this.pdfFormatVersion,
  6916. IsAcroFormPresent: !!this.acroForm,
  6917. IsXFAPresent: !!this.xfa
  6918. };
  6919. var infoDict;
  6920. try {
  6921. infoDict = this.xref.trailer.get('Info');
  6922. } catch (err) {
  6923. info('The document information dictionary is invalid.');
  6924. }
  6925. if (infoDict) {
  6926. var validEntries = DocumentInfoValidators.entries;
  6927. // Only fill the document info with valid entries from the spec.
  6928. for (var key in validEntries) {
  6929. if (infoDict.has(key)) {
  6930. var value = infoDict.get(key);
  6931. // Make sure the value conforms to the spec.
  6932. if (validEntries[key](value)) {
  6933. docInfo[key] = (typeof value !== 'string' ?
  6934. value : stringToPDFString(value));
  6935. } else {
  6936. info('Bad value in document info for "' + key + '"');
  6937. }
  6938. }
  6939. }
  6940. }
  6941. return shadow(this, 'documentInfo', docInfo);
  6942. },
  6943. get fingerprint() {
  6944. var xref = this.xref, hash, fileID = '';
  6945. if (xref.trailer.has('ID')) {
  6946. hash = stringToBytes(xref.trailer.get('ID')[0]);
  6947. } else {
  6948. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  6949. }
  6950. for (var i = 0, n = hash.length; i < n; i++) {
  6951. fileID += hash[i].toString(16);
  6952. }
  6953. return shadow(this, 'fingerprint', fileID);
  6954. },
  6955. getPage: function PDFDocument_getPage(pageIndex) {
  6956. return this.catalog.getPage(pageIndex);
  6957. },
  6958. cleanup: function PDFDocument_cleanup() {
  6959. return this.catalog.cleanup();
  6960. }
  6961. };
  6962. return PDFDocument;
  6963. })();
  6964. var Name = (function NameClosure() {
  6965. function Name(name) {
  6966. this.name = name;
  6967. }
  6968. Name.prototype = {};
  6969. var nameCache = {};
  6970. Name.get = function Name_get(name) {
  6971. var nameValue = nameCache[name];
  6972. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  6973. };
  6974. return Name;
  6975. })();
  6976. var Cmd = (function CmdClosure() {
  6977. function Cmd(cmd) {
  6978. this.cmd = cmd;
  6979. }
  6980. Cmd.prototype = {};
  6981. var cmdCache = {};
  6982. Cmd.get = function Cmd_get(cmd) {
  6983. var cmdValue = cmdCache[cmd];
  6984. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  6985. };
  6986. return Cmd;
  6987. })();
  6988. var Dict = (function DictClosure() {
  6989. var nonSerializable = function nonSerializableClosure() {
  6990. return nonSerializable; // creating closure on some variable
  6991. };
  6992. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  6993. 'Background': true,
  6994. 'ExtGState': true,
  6995. 'Halftone': true,
  6996. 'Layout': true,
  6997. 'Mask': true,
  6998. 'Pagination': true,
  6999. 'Printing': true
  7000. };
  7001. function isRecursionAllowedFor(dict) {
  7002. if (!isName(dict.Type)) {
  7003. return true;
  7004. }
  7005. var dictType = dict.Type.name;
  7006. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  7007. }
  7008. // xref is optional
  7009. function Dict(xref) {
  7010. // Map should only be used internally, use functions below to access.
  7011. this.map = Object.create(null);
  7012. this.xref = xref;
  7013. this.objId = null;
  7014. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  7015. }
  7016. Dict.prototype = {
  7017. assignXref: function Dict_assignXref(newXref) {
  7018. this.xref = newXref;
  7019. },
  7020. // automatically dereferences Ref objects
  7021. get: function Dict_get(key1, key2, key3) {
  7022. var value;
  7023. var xref = this.xref;
  7024. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  7025. typeof key2 === 'undefined') {
  7026. return xref ? xref.fetchIfRef(value) : value;
  7027. }
  7028. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  7029. typeof key3 === 'undefined') {
  7030. return xref ? xref.fetchIfRef(value) : value;
  7031. }
  7032. value = this.map[key3] || null;
  7033. return xref ? xref.fetchIfRef(value) : value;
  7034. },
  7035. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  7036. getAsync: function Dict_getAsync(key1, key2, key3) {
  7037. var value;
  7038. var xref = this.xref;
  7039. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  7040. typeof key2 === 'undefined') {
  7041. if (xref) {
  7042. return xref.fetchIfRefAsync(value);
  7043. }
  7044. return Promise.resolve(value);
  7045. }
  7046. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  7047. typeof key3 === 'undefined') {
  7048. if (xref) {
  7049. return xref.fetchIfRefAsync(value);
  7050. }
  7051. return Promise.resolve(value);
  7052. }
  7053. value = this.map[key3] || null;
  7054. if (xref) {
  7055. return xref.fetchIfRefAsync(value);
  7056. }
  7057. return Promise.resolve(value);
  7058. },
  7059. // no dereferencing
  7060. getRaw: function Dict_getRaw(key) {
  7061. return this.map[key];
  7062. },
  7063. // creates new map and dereferences all Refs
  7064. getAll: function Dict_getAll() {
  7065. var all = Object.create(null);
  7066. var queue = null;
  7067. var key, obj;
  7068. for (key in this.map) {
  7069. obj = this.get(key);
  7070. if (obj instanceof Dict) {
  7071. if (isRecursionAllowedFor(obj)) {
  7072. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  7073. } else {
  7074. all[key] = this.getRaw(key);
  7075. }
  7076. } else {
  7077. all[key] = obj;
  7078. }
  7079. }
  7080. if (!queue) {
  7081. return all;
  7082. }
  7083. // trying to take cyclic references into the account
  7084. var processed = Object.create(null);
  7085. while (queue.length > 0) {
  7086. var item = queue.shift();
  7087. var itemObj = item.obj;
  7088. var objId = itemObj.objId;
  7089. if (objId && objId in processed) {
  7090. item.target[item.key] = processed[objId];
  7091. continue;
  7092. }
  7093. var dereferenced = Object.create(null);
  7094. for (key in itemObj.map) {
  7095. obj = itemObj.get(key);
  7096. if (obj instanceof Dict) {
  7097. if (isRecursionAllowedFor(obj)) {
  7098. queue.push({target: dereferenced, key: key, obj: obj});
  7099. } else {
  7100. dereferenced[key] = itemObj.getRaw(key);
  7101. }
  7102. } else {
  7103. dereferenced[key] = obj;
  7104. }
  7105. }
  7106. if (objId) {
  7107. processed[objId] = dereferenced;
  7108. }
  7109. item.target[item.key] = dereferenced;
  7110. }
  7111. return all;
  7112. },
  7113. set: function Dict_set(key, value) {
  7114. this.map[key] = value;
  7115. },
  7116. has: function Dict_has(key) {
  7117. return key in this.map;
  7118. },
  7119. forEach: function Dict_forEach(callback) {
  7120. for (var key in this.map) {
  7121. callback(key, this.get(key));
  7122. }
  7123. }
  7124. };
  7125. Dict.empty = new Dict(null);
  7126. return Dict;
  7127. })();
  7128. var Ref = (function RefClosure() {
  7129. function Ref(num, gen) {
  7130. this.num = num;
  7131. this.gen = gen;
  7132. }
  7133. Ref.prototype = {
  7134. toString: function Ref_toString() {
  7135. // This function is hot, so we make the string as compact as possible.
  7136. // |this.gen| is almost always zero, so we treat that case specially.
  7137. var str = this.num + 'R';
  7138. if (this.gen !== 0) {
  7139. str += this.gen;
  7140. }
  7141. return str;
  7142. }
  7143. };
  7144. return Ref;
  7145. })();
  7146. // The reference is identified by number and generation.
  7147. // This structure stores only one instance of the reference.
  7148. var RefSet = (function RefSetClosure() {
  7149. function RefSet() {
  7150. this.dict = {};
  7151. }
  7152. RefSet.prototype = {
  7153. has: function RefSet_has(ref) {
  7154. return ref.toString() in this.dict;
  7155. },
  7156. put: function RefSet_put(ref) {
  7157. this.dict[ref.toString()] = true;
  7158. },
  7159. remove: function RefSet_remove(ref) {
  7160. delete this.dict[ref.toString()];
  7161. }
  7162. };
  7163. return RefSet;
  7164. })();
  7165. var RefSetCache = (function RefSetCacheClosure() {
  7166. function RefSetCache() {
  7167. this.dict = Object.create(null);
  7168. }
  7169. RefSetCache.prototype = {
  7170. get: function RefSetCache_get(ref) {
  7171. return this.dict[ref.toString()];
  7172. },
  7173. has: function RefSetCache_has(ref) {
  7174. return ref.toString() in this.dict;
  7175. },
  7176. put: function RefSetCache_put(ref, obj) {
  7177. this.dict[ref.toString()] = obj;
  7178. },
  7179. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  7180. this.dict[ref.toString()] = this.get(aliasRef);
  7181. },
  7182. forEach: function RefSetCache_forEach(fn, thisArg) {
  7183. for (var i in this.dict) {
  7184. fn.call(thisArg, this.dict[i]);
  7185. }
  7186. },
  7187. clear: function RefSetCache_clear() {
  7188. this.dict = Object.create(null);
  7189. }
  7190. };
  7191. return RefSetCache;
  7192. })();
  7193. var Catalog = (function CatalogClosure() {
  7194. function Catalog(pdfManager, xref) {
  7195. this.pdfManager = pdfManager;
  7196. this.xref = xref;
  7197. this.catDict = xref.getCatalogObj();
  7198. this.fontCache = new RefSetCache();
  7199. assert(isDict(this.catDict),
  7200. 'catalog object is not a dictionary');
  7201. this.pagePromises = [];
  7202. }
  7203. Catalog.prototype = {
  7204. get metadata() {
  7205. var streamRef = this.catDict.getRaw('Metadata');
  7206. if (!isRef(streamRef)) {
  7207. return shadow(this, 'metadata', null);
  7208. }
  7209. var encryptMetadata = (!this.xref.encrypt ? false :
  7210. this.xref.encrypt.encryptMetadata);
  7211. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  7212. var metadata;
  7213. if (stream && isDict(stream.dict)) {
  7214. var type = stream.dict.get('Type');
  7215. var subtype = stream.dict.get('Subtype');
  7216. if (isName(type) && isName(subtype) &&
  7217. type.name === 'Metadata' && subtype.name === 'XML') {
  7218. // XXX: This should examine the charset the XML document defines,
  7219. // however since there are currently no real means to decode
  7220. // arbitrary charsets, let's just hope that the author of the PDF
  7221. // was reasonable enough to stick with the XML default charset,
  7222. // which is UTF-8.
  7223. try {
  7224. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  7225. } catch (e) {
  7226. info('Skipping invalid metadata.');
  7227. }
  7228. }
  7229. }
  7230. return shadow(this, 'metadata', metadata);
  7231. },
  7232. get toplevelPagesDict() {
  7233. var pagesObj = this.catDict.get('Pages');
  7234. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  7235. // shadow the prototype getter
  7236. return shadow(this, 'toplevelPagesDict', pagesObj);
  7237. },
  7238. get documentOutline() {
  7239. var obj = null;
  7240. try {
  7241. obj = this.readDocumentOutline();
  7242. } catch (ex) {
  7243. if (ex instanceof MissingDataException) {
  7244. throw ex;
  7245. }
  7246. warn('Unable to read document outline');
  7247. }
  7248. return shadow(this, 'documentOutline', obj);
  7249. },
  7250. readDocumentOutline: function Catalog_readDocumentOutline() {
  7251. var xref = this.xref;
  7252. var obj = this.catDict.get('Outlines');
  7253. var root = { items: [] };
  7254. if (isDict(obj)) {
  7255. obj = obj.getRaw('First');
  7256. var processed = new RefSet();
  7257. if (isRef(obj)) {
  7258. var queue = [{obj: obj, parent: root}];
  7259. // to avoid recursion keeping track of the items
  7260. // in the processed dictionary
  7261. processed.put(obj);
  7262. while (queue.length > 0) {
  7263. var i = queue.shift();
  7264. var outlineDict = xref.fetchIfRef(i.obj);
  7265. if (outlineDict === null) {
  7266. continue;
  7267. }
  7268. if (!outlineDict.has('Title')) {
  7269. error('Invalid outline item');
  7270. }
  7271. var dest = outlineDict.get('A');
  7272. if (dest) {
  7273. dest = dest.get('D');
  7274. } else if (outlineDict.has('Dest')) {
  7275. dest = outlineDict.getRaw('Dest');
  7276. if (isName(dest)) {
  7277. dest = dest.name;
  7278. }
  7279. }
  7280. var title = outlineDict.get('Title');
  7281. var outlineItem = {
  7282. dest: dest,
  7283. title: stringToPDFString(title),
  7284. color: outlineDict.get('C') || [0, 0, 0],
  7285. count: outlineDict.get('Count'),
  7286. bold: !!(outlineDict.get('F') & 2),
  7287. italic: !!(outlineDict.get('F') & 1),
  7288. items: []
  7289. };
  7290. i.parent.items.push(outlineItem);
  7291. obj = outlineDict.getRaw('First');
  7292. if (isRef(obj) && !processed.has(obj)) {
  7293. queue.push({obj: obj, parent: outlineItem});
  7294. processed.put(obj);
  7295. }
  7296. obj = outlineDict.getRaw('Next');
  7297. if (isRef(obj) && !processed.has(obj)) {
  7298. queue.push({obj: obj, parent: i.parent});
  7299. processed.put(obj);
  7300. }
  7301. }
  7302. }
  7303. }
  7304. return (root.items.length > 0 ? root.items : null);
  7305. },
  7306. get numPages() {
  7307. var obj = this.toplevelPagesDict.get('Count');
  7308. assert(
  7309. isInt(obj),
  7310. 'page count in top level pages object is not an integer'
  7311. );
  7312. // shadow the prototype getter
  7313. return shadow(this, 'num', obj);
  7314. },
  7315. get destinations() {
  7316. function fetchDestination(dest) {
  7317. return isDict(dest) ? dest.get('D') : dest;
  7318. }
  7319. var xref = this.xref;
  7320. var dests = {}, nameTreeRef, nameDictionaryRef;
  7321. var obj = this.catDict.get('Names');
  7322. if (obj && obj.has('Dests')) {
  7323. nameTreeRef = obj.getRaw('Dests');
  7324. } else if (this.catDict.has('Dests')) {
  7325. nameDictionaryRef = this.catDict.get('Dests');
  7326. }
  7327. if (nameDictionaryRef) {
  7328. // reading simple destination dictionary
  7329. obj = nameDictionaryRef;
  7330. obj.forEach(function catalogForEach(key, value) {
  7331. if (!value) {
  7332. return;
  7333. }
  7334. dests[key] = fetchDestination(value);
  7335. });
  7336. }
  7337. if (nameTreeRef) {
  7338. var nameTree = new NameTree(nameTreeRef, xref);
  7339. var names = nameTree.getAll();
  7340. for (var name in names) {
  7341. if (!names.hasOwnProperty(name)) {
  7342. continue;
  7343. }
  7344. dests[name] = fetchDestination(names[name]);
  7345. }
  7346. }
  7347. return shadow(this, 'destinations', dests);
  7348. },
  7349. get attachments() {
  7350. var xref = this.xref;
  7351. var attachments = null, nameTreeRef;
  7352. var obj = this.catDict.get('Names');
  7353. if (obj) {
  7354. nameTreeRef = obj.getRaw('EmbeddedFiles');
  7355. }
  7356. if (nameTreeRef) {
  7357. var nameTree = new NameTree(nameTreeRef, xref);
  7358. var names = nameTree.getAll();
  7359. for (var name in names) {
  7360. if (!names.hasOwnProperty(name)) {
  7361. continue;
  7362. }
  7363. var fs = new FileSpec(names[name], xref);
  7364. if (!attachments) {
  7365. attachments = {};
  7366. }
  7367. attachments[stringToPDFString(name)] = fs.serializable;
  7368. }
  7369. }
  7370. return shadow(this, 'attachments', attachments);
  7371. },
  7372. get javaScript() {
  7373. var xref = this.xref;
  7374. var obj = this.catDict.get('Names');
  7375. var javaScript = [];
  7376. if (obj && obj.has('JavaScript')) {
  7377. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  7378. var names = nameTree.getAll();
  7379. for (var name in names) {
  7380. if (!names.hasOwnProperty(name)) {
  7381. continue;
  7382. }
  7383. // We don't really use the JavaScript right now. This code is
  7384. // defensive so we don't cause errors on document load.
  7385. var jsDict = names[name];
  7386. if (!isDict(jsDict)) {
  7387. continue;
  7388. }
  7389. var type = jsDict.get('S');
  7390. if (!isName(type) || type.name !== 'JavaScript') {
  7391. continue;
  7392. }
  7393. var js = jsDict.get('JS');
  7394. if (!isString(js) && !isStream(js)) {
  7395. continue;
  7396. }
  7397. if (isStream(js)) {
  7398. js = bytesToString(js.getBytes());
  7399. }
  7400. javaScript.push(stringToPDFString(js));
  7401. }
  7402. }
  7403. // Append OpenAction actions to javaScript array
  7404. var openactionDict = this.catDict.get('OpenAction');
  7405. if (isDict(openactionDict)) {
  7406. var objType = openactionDict.get('Type');
  7407. var actionType = openactionDict.get('S');
  7408. var action = openactionDict.get('N');
  7409. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  7410. isName(actionType) && actionType.name === 'Named' &&
  7411. isName(action) && action.name === 'Print');
  7412. if (isPrintAction) {
  7413. javaScript.push('print(true);');
  7414. }
  7415. }
  7416. return shadow(this, 'javaScript', javaScript);
  7417. },
  7418. cleanup: function Catalog_cleanup() {
  7419. var promises = [];
  7420. this.fontCache.forEach(function (promise) {
  7421. promises.push(promise);
  7422. });
  7423. return Promise.all(promises).then(function (translatedFonts) {
  7424. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  7425. var font = translatedFonts[i].dict;
  7426. delete font.translated;
  7427. }
  7428. this.fontCache.clear();
  7429. }.bind(this));
  7430. },
  7431. getPage: function Catalog_getPage(pageIndex) {
  7432. if (!(pageIndex in this.pagePromises)) {
  7433. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  7434. function (a) {
  7435. var dict = a[0];
  7436. var ref = a[1];
  7437. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  7438. this.fontCache);
  7439. }.bind(this)
  7440. );
  7441. }
  7442. return this.pagePromises[pageIndex];
  7443. },
  7444. getPageDict: function Catalog_getPageDict(pageIndex) {
  7445. var capability = createPromiseCapability();
  7446. var nodesToVisit = [this.catDict.getRaw('Pages')];
  7447. var currentPageIndex = 0;
  7448. var xref = this.xref;
  7449. function next() {
  7450. while (nodesToVisit.length) {
  7451. var currentNode = nodesToVisit.pop();
  7452. if (isRef(currentNode)) {
  7453. xref.fetchAsync(currentNode).then(function (obj) {
  7454. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  7455. if (pageIndex === currentPageIndex) {
  7456. capability.resolve([obj, currentNode]);
  7457. } else {
  7458. currentPageIndex++;
  7459. next();
  7460. }
  7461. return;
  7462. }
  7463. nodesToVisit.push(obj);
  7464. next();
  7465. }, capability.reject);
  7466. return;
  7467. }
  7468. // must be a child page dictionary
  7469. assert(
  7470. isDict(currentNode),
  7471. 'page dictionary kid reference points to wrong type of object'
  7472. );
  7473. var count = currentNode.get('Count');
  7474. // Skip nodes where the page can't be.
  7475. if (currentPageIndex + count <= pageIndex) {
  7476. currentPageIndex += count;
  7477. continue;
  7478. }
  7479. var kids = currentNode.get('Kids');
  7480. assert(isArray(kids), 'page dictionary kids object is not an array');
  7481. if (count === kids.length) {
  7482. // Nodes that don't have the page have been skipped and this is the
  7483. // bottom of the tree which means the page requested must be a
  7484. // descendant of this pages node. Ideally we would just resolve the
  7485. // promise with the page ref here, but there is the case where more
  7486. // pages nodes could link to single a page (see issue 3666 pdf). To
  7487. // handle this push it back on the queue so if it is a pages node it
  7488. // will be descended into.
  7489. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  7490. currentPageIndex = pageIndex;
  7491. continue;
  7492. } else {
  7493. for (var last = kids.length - 1; last >= 0; last--) {
  7494. nodesToVisit.push(kids[last]);
  7495. }
  7496. }
  7497. }
  7498. capability.reject('Page index ' + pageIndex + ' not found.');
  7499. }
  7500. next();
  7501. return capability.promise;
  7502. },
  7503. getPageIndex: function Catalog_getPageIndex(ref) {
  7504. // The page tree nodes have the count of all the leaves below them. To get
  7505. // how many pages are before we just have to walk up the tree and keep
  7506. // adding the count of siblings to the left of the node.
  7507. var xref = this.xref;
  7508. function pagesBeforeRef(kidRef) {
  7509. var total = 0;
  7510. var parentRef;
  7511. return xref.fetchAsync(kidRef).then(function (node) {
  7512. if (!node) {
  7513. return null;
  7514. }
  7515. parentRef = node.getRaw('Parent');
  7516. return node.getAsync('Parent');
  7517. }).then(function (parent) {
  7518. if (!parent) {
  7519. return null;
  7520. }
  7521. return parent.getAsync('Kids');
  7522. }).then(function (kids) {
  7523. if (!kids) {
  7524. return null;
  7525. }
  7526. var kidPromises = [];
  7527. var found = false;
  7528. for (var i = 0; i < kids.length; i++) {
  7529. var kid = kids[i];
  7530. assert(isRef(kid), 'kids must be a ref');
  7531. if (kid.num === kidRef.num) {
  7532. found = true;
  7533. break;
  7534. }
  7535. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  7536. if (kid.has('Count')) {
  7537. var count = kid.get('Count');
  7538. total += count;
  7539. } else { // page leaf node
  7540. total++;
  7541. }
  7542. }));
  7543. }
  7544. if (!found) {
  7545. error('kid ref not found in parents kids');
  7546. }
  7547. return Promise.all(kidPromises).then(function () {
  7548. return [total, parentRef];
  7549. });
  7550. });
  7551. }
  7552. var total = 0;
  7553. function next(ref) {
  7554. return pagesBeforeRef(ref).then(function (args) {
  7555. if (!args) {
  7556. return total;
  7557. }
  7558. var count = args[0];
  7559. var parentRef = args[1];
  7560. total += count;
  7561. return next(parentRef);
  7562. });
  7563. }
  7564. return next(ref);
  7565. }
  7566. };
  7567. return Catalog;
  7568. })();
  7569. var XRef = (function XRefClosure() {
  7570. function XRef(stream, password) {
  7571. this.stream = stream;
  7572. this.entries = [];
  7573. this.xrefstms = {};
  7574. // prepare the XRef cache
  7575. this.cache = [];
  7576. this.password = password;
  7577. this.stats = {
  7578. streamTypes: [],
  7579. fontTypes: []
  7580. };
  7581. }
  7582. XRef.prototype = {
  7583. setStartXRef: function XRef_setStartXRef(startXRef) {
  7584. // Store the starting positions of xref tables as we process them
  7585. // so we can recover from missing data errors
  7586. this.startXRefQueue = [startXRef];
  7587. },
  7588. parse: function XRef_parse(recoveryMode) {
  7589. var trailerDict;
  7590. if (!recoveryMode) {
  7591. trailerDict = this.readXRef();
  7592. } else {
  7593. warn('Indexing all PDF objects');
  7594. trailerDict = this.indexObjects();
  7595. }
  7596. trailerDict.assignXref(this);
  7597. this.trailer = trailerDict;
  7598. var encrypt = trailerDict.get('Encrypt');
  7599. if (encrypt) {
  7600. var ids = trailerDict.get('ID');
  7601. var fileId = (ids && ids.length) ? ids[0] : '';
  7602. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  7603. this.password);
  7604. }
  7605. // get the root dictionary (catalog) object
  7606. if (!(this.root = trailerDict.get('Root'))) {
  7607. error('Invalid root reference');
  7608. }
  7609. },
  7610. processXRefTable: function XRef_processXRefTable(parser) {
  7611. if (!('tableState' in this)) {
  7612. // Stores state of the table as we process it so we can resume
  7613. // from middle of table in case of missing data error
  7614. this.tableState = {
  7615. entryNum: 0,
  7616. streamPos: parser.lexer.stream.pos,
  7617. parserBuf1: parser.buf1,
  7618. parserBuf2: parser.buf2
  7619. };
  7620. }
  7621. var obj = this.readXRefTable(parser);
  7622. // Sanity check
  7623. if (!isCmd(obj, 'trailer')) {
  7624. error('Invalid XRef table: could not find trailer dictionary');
  7625. }
  7626. // Read trailer dictionary, e.g.
  7627. // trailer
  7628. // << /Size 22
  7629. // /Root 20R
  7630. // /Info 10R
  7631. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  7632. // >>
  7633. // The parser goes through the entire stream << ... >> and provides
  7634. // a getter interface for the key-value table
  7635. var dict = parser.getObj();
  7636. // The pdflib PDF generator can generate a nested trailer dictionary
  7637. if (!isDict(dict) && dict.dict) {
  7638. dict = dict.dict;
  7639. }
  7640. if (!isDict(dict)) {
  7641. error('Invalid XRef table: could not parse trailer dictionary');
  7642. }
  7643. delete this.tableState;
  7644. return dict;
  7645. },
  7646. readXRefTable: function XRef_readXRefTable(parser) {
  7647. // Example of cross-reference table:
  7648. // xref
  7649. // 0 1 <-- subsection header (first obj #, obj count)
  7650. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  7651. // 23 2 <-- subsection header ... and so on ...
  7652. // 0000025518 00002 n
  7653. // 0000025635 00000 n
  7654. // trailer
  7655. // ...
  7656. var stream = parser.lexer.stream;
  7657. var tableState = this.tableState;
  7658. stream.pos = tableState.streamPos;
  7659. parser.buf1 = tableState.parserBuf1;
  7660. parser.buf2 = tableState.parserBuf2;
  7661. // Outer loop is over subsection headers
  7662. var obj;
  7663. while (true) {
  7664. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  7665. if (isCmd(obj = parser.getObj(), 'trailer')) {
  7666. break;
  7667. }
  7668. tableState.firstEntryNum = obj;
  7669. tableState.entryCount = parser.getObj();
  7670. }
  7671. var first = tableState.firstEntryNum;
  7672. var count = tableState.entryCount;
  7673. if (!isInt(first) || !isInt(count)) {
  7674. error('Invalid XRef table: wrong types in subsection header');
  7675. }
  7676. // Inner loop is over objects themselves
  7677. for (var i = tableState.entryNum; i < count; i++) {
  7678. tableState.streamPos = stream.pos;
  7679. tableState.entryNum = i;
  7680. tableState.parserBuf1 = parser.buf1;
  7681. tableState.parserBuf2 = parser.buf2;
  7682. var entry = {};
  7683. entry.offset = parser.getObj();
  7684. entry.gen = parser.getObj();
  7685. var type = parser.getObj();
  7686. if (isCmd(type, 'f')) {
  7687. entry.free = true;
  7688. } else if (isCmd(type, 'n')) {
  7689. entry.uncompressed = true;
  7690. }
  7691. // Validate entry obj
  7692. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  7693. !(entry.free || entry.uncompressed)) {
  7694. console.log(entry.offset, entry.gen, entry.free,
  7695. entry.uncompressed);
  7696. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  7697. }
  7698. if (!this.entries[i + first]) {
  7699. this.entries[i + first] = entry;
  7700. }
  7701. }
  7702. tableState.entryNum = 0;
  7703. tableState.streamPos = stream.pos;
  7704. tableState.parserBuf1 = parser.buf1;
  7705. tableState.parserBuf2 = parser.buf2;
  7706. delete tableState.firstEntryNum;
  7707. delete tableState.entryCount;
  7708. }
  7709. // Per issue 3248: hp scanners generate bad XRef
  7710. if (first === 1 && this.entries[1] && this.entries[1].free) {
  7711. // shifting the entries
  7712. this.entries.shift();
  7713. }
  7714. // Sanity check: as per spec, first object must be free
  7715. if (this.entries[0] && !this.entries[0].free) {
  7716. error('Invalid XRef table: unexpected first object');
  7717. }
  7718. return obj;
  7719. },
  7720. processXRefStream: function XRef_processXRefStream(stream) {
  7721. if (!('streamState' in this)) {
  7722. // Stores state of the stream as we process it so we can resume
  7723. // from middle of stream in case of missing data error
  7724. var streamParameters = stream.dict;
  7725. var byteWidths = streamParameters.get('W');
  7726. var range = streamParameters.get('Index');
  7727. if (!range) {
  7728. range = [0, streamParameters.get('Size')];
  7729. }
  7730. this.streamState = {
  7731. entryRanges: range,
  7732. byteWidths: byteWidths,
  7733. entryNum: 0,
  7734. streamPos: stream.pos
  7735. };
  7736. }
  7737. this.readXRefStream(stream);
  7738. delete this.streamState;
  7739. return stream.dict;
  7740. },
  7741. readXRefStream: function XRef_readXRefStream(stream) {
  7742. var i, j;
  7743. var streamState = this.streamState;
  7744. stream.pos = streamState.streamPos;
  7745. var byteWidths = streamState.byteWidths;
  7746. var typeFieldWidth = byteWidths[0];
  7747. var offsetFieldWidth = byteWidths[1];
  7748. var generationFieldWidth = byteWidths[2];
  7749. var entryRanges = streamState.entryRanges;
  7750. while (entryRanges.length > 0) {
  7751. var first = entryRanges[0];
  7752. var n = entryRanges[1];
  7753. if (!isInt(first) || !isInt(n)) {
  7754. error('Invalid XRef range fields: ' + first + ', ' + n);
  7755. }
  7756. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  7757. !isInt(generationFieldWidth)) {
  7758. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  7759. }
  7760. for (i = streamState.entryNum; i < n; ++i) {
  7761. streamState.entryNum = i;
  7762. streamState.streamPos = stream.pos;
  7763. var type = 0, offset = 0, generation = 0;
  7764. for (j = 0; j < typeFieldWidth; ++j) {
  7765. type = (type << 8) | stream.getByte();
  7766. }
  7767. // if type field is absent, its default value is 1
  7768. if (typeFieldWidth === 0) {
  7769. type = 1;
  7770. }
  7771. for (j = 0; j < offsetFieldWidth; ++j) {
  7772. offset = (offset << 8) | stream.getByte();
  7773. }
  7774. for (j = 0; j < generationFieldWidth; ++j) {
  7775. generation = (generation << 8) | stream.getByte();
  7776. }
  7777. var entry = {};
  7778. entry.offset = offset;
  7779. entry.gen = generation;
  7780. switch (type) {
  7781. case 0:
  7782. entry.free = true;
  7783. break;
  7784. case 1:
  7785. entry.uncompressed = true;
  7786. break;
  7787. case 2:
  7788. break;
  7789. default:
  7790. error('Invalid XRef entry type: ' + type);
  7791. }
  7792. if (!this.entries[first + i]) {
  7793. this.entries[first + i] = entry;
  7794. }
  7795. }
  7796. streamState.entryNum = 0;
  7797. streamState.streamPos = stream.pos;
  7798. entryRanges.splice(0, 2);
  7799. }
  7800. },
  7801. indexObjects: function XRef_indexObjects() {
  7802. // Simple scan through the PDF content to find objects,
  7803. // trailers and XRef streams.
  7804. function readToken(data, offset) {
  7805. var token = '', ch = data[offset];
  7806. while (ch !== 13 && ch !== 10) {
  7807. if (++offset >= data.length) {
  7808. break;
  7809. }
  7810. token += String.fromCharCode(ch);
  7811. ch = data[offset];
  7812. }
  7813. return token;
  7814. }
  7815. function skipUntil(data, offset, what) {
  7816. var length = what.length, dataLength = data.length;
  7817. var skipped = 0;
  7818. // finding byte sequence
  7819. while (offset < dataLength) {
  7820. var i = 0;
  7821. while (i < length && data[offset + i] === what[i]) {
  7822. ++i;
  7823. }
  7824. if (i >= length) {
  7825. break; // sequence found
  7826. }
  7827. offset++;
  7828. skipped++;
  7829. }
  7830. return skipped;
  7831. }
  7832. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  7833. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  7834. 101, 102]);
  7835. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  7836. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  7837. var stream = this.stream;
  7838. stream.pos = 0;
  7839. var buffer = stream.getBytes();
  7840. var position = stream.start, length = buffer.length;
  7841. var trailers = [], xrefStms = [];
  7842. while (position < length) {
  7843. var ch = buffer[position];
  7844. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  7845. ++position;
  7846. continue;
  7847. }
  7848. if (ch === 37) { // %-comment
  7849. do {
  7850. ++position;
  7851. if (position >= length) {
  7852. break;
  7853. }
  7854. ch = buffer[position];
  7855. } while (ch !== 13 && ch !== 10);
  7856. continue;
  7857. }
  7858. var token = readToken(buffer, position);
  7859. var m;
  7860. if (token === 'xref') {
  7861. position += skipUntil(buffer, position, trailerBytes);
  7862. trailers.push(position);
  7863. position += skipUntil(buffer, position, startxrefBytes);
  7864. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  7865. this.entries[m[1]] = {
  7866. offset: position,
  7867. gen: m[2] | 0,
  7868. uncompressed: true
  7869. };
  7870. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  7871. var content = buffer.subarray(position, position + contentLength);
  7872. // checking XRef stream suspect
  7873. // (it shall have '/XRef' and next char is not a letter)
  7874. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  7875. if (xrefTagOffset < contentLength &&
  7876. content[xrefTagOffset + 5] < 64) {
  7877. xrefStms.push(position);
  7878. this.xrefstms[position] = 1; // don't read it recursively
  7879. }
  7880. position += contentLength;
  7881. } else {
  7882. position += token.length + 1;
  7883. }
  7884. }
  7885. // reading XRef streams
  7886. var i, ii;
  7887. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  7888. this.startXRefQueue.push(xrefStms[i]);
  7889. this.readXRef(/* recoveryMode */ true);
  7890. }
  7891. // finding main trailer
  7892. var dict;
  7893. for (i = 0, ii = trailers.length; i < ii; ++i) {
  7894. stream.pos = trailers[i];
  7895. var parser = new Parser(new Lexer(stream), true, this);
  7896. var obj = parser.getObj();
  7897. if (!isCmd(obj, 'trailer')) {
  7898. continue;
  7899. }
  7900. // read the trailer dictionary
  7901. if (!isDict(dict = parser.getObj())) {
  7902. continue;
  7903. }
  7904. // taking the first one with 'ID'
  7905. if (dict.has('ID')) {
  7906. return dict;
  7907. }
  7908. }
  7909. // no tailer with 'ID', taking last one (if exists)
  7910. if (dict) {
  7911. return dict;
  7912. }
  7913. // nothing helps
  7914. // calling error() would reject worker with an UnknownErrorException.
  7915. throw new InvalidPDFException('Invalid PDF structure');
  7916. },
  7917. readXRef: function XRef_readXRef(recoveryMode) {
  7918. var stream = this.stream;
  7919. try {
  7920. while (this.startXRefQueue.length) {
  7921. var startXRef = this.startXRefQueue[0];
  7922. stream.pos = startXRef + stream.start;
  7923. var parser = new Parser(new Lexer(stream), true, this);
  7924. var obj = parser.getObj();
  7925. var dict;
  7926. // Get dictionary
  7927. if (isCmd(obj, 'xref')) {
  7928. // Parse end-of-file XRef
  7929. dict = this.processXRefTable(parser);
  7930. if (!this.topDict) {
  7931. this.topDict = dict;
  7932. }
  7933. // Recursively get other XRefs 'XRefStm', if any
  7934. obj = dict.get('XRefStm');
  7935. if (isInt(obj)) {
  7936. var pos = obj;
  7937. // ignore previously loaded xref streams
  7938. // (possible infinite recursion)
  7939. if (!(pos in this.xrefstms)) {
  7940. this.xrefstms[pos] = 1;
  7941. this.startXRefQueue.push(pos);
  7942. }
  7943. }
  7944. } else if (isInt(obj)) {
  7945. // Parse in-stream XRef
  7946. if (!isInt(parser.getObj()) ||
  7947. !isCmd(parser.getObj(), 'obj') ||
  7948. !isStream(obj = parser.getObj())) {
  7949. error('Invalid XRef stream');
  7950. }
  7951. dict = this.processXRefStream(obj);
  7952. if (!this.topDict) {
  7953. this.topDict = dict;
  7954. }
  7955. if (!dict) {
  7956. error('Failed to read XRef stream');
  7957. }
  7958. } else {
  7959. error('Invalid XRef stream header');
  7960. }
  7961. // Recursively get previous dictionary, if any
  7962. obj = dict.get('Prev');
  7963. if (isInt(obj)) {
  7964. this.startXRefQueue.push(obj);
  7965. } else if (isRef(obj)) {
  7966. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  7967. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  7968. this.startXRefQueue.push(obj.num);
  7969. }
  7970. this.startXRefQueue.shift();
  7971. }
  7972. return this.topDict;
  7973. } catch (e) {
  7974. if (e instanceof MissingDataException) {
  7975. throw e;
  7976. }
  7977. info('(while reading XRef): ' + e);
  7978. }
  7979. if (recoveryMode) {
  7980. return;
  7981. }
  7982. throw new XRefParseException();
  7983. },
  7984. getEntry: function XRef_getEntry(i) {
  7985. var xrefEntry = this.entries[i];
  7986. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  7987. return xrefEntry;
  7988. }
  7989. return null;
  7990. },
  7991. fetchIfRef: function XRef_fetchIfRef(obj) {
  7992. if (!isRef(obj)) {
  7993. return obj;
  7994. }
  7995. return this.fetch(obj);
  7996. },
  7997. fetch: function XRef_fetch(ref, suppressEncryption) {
  7998. assert(isRef(ref), 'ref object is not a reference');
  7999. var num = ref.num;
  8000. if (num in this.cache) {
  8001. var cacheEntry = this.cache[num];
  8002. return cacheEntry;
  8003. }
  8004. var xrefEntry = this.getEntry(num);
  8005. // the referenced entry can be free
  8006. if (xrefEntry === null) {
  8007. return (this.cache[num] = null);
  8008. }
  8009. if (xrefEntry.uncompressed) {
  8010. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  8011. } else {
  8012. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  8013. }
  8014. if (isDict(xrefEntry)){
  8015. xrefEntry.objId = ref.toString();
  8016. } else if (isStream(xrefEntry)) {
  8017. xrefEntry.dict.objId = ref.toString();
  8018. }
  8019. return xrefEntry;
  8020. },
  8021. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  8022. suppressEncryption) {
  8023. var gen = ref.gen;
  8024. var num = ref.num;
  8025. if (xrefEntry.gen !== gen) {
  8026. error('inconsistent generation in XRef');
  8027. }
  8028. var stream = this.stream.makeSubStream(xrefEntry.offset +
  8029. this.stream.start);
  8030. var parser = new Parser(new Lexer(stream), true, this);
  8031. var obj1 = parser.getObj();
  8032. var obj2 = parser.getObj();
  8033. var obj3 = parser.getObj();
  8034. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  8035. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  8036. !isCmd(obj3)) {
  8037. error('bad XRef entry');
  8038. }
  8039. if (!isCmd(obj3, 'obj')) {
  8040. // some bad PDFs use "obj1234" and really mean 1234
  8041. if (obj3.cmd.indexOf('obj') === 0) {
  8042. num = parseInt(obj3.cmd.substring(3), 10);
  8043. if (!isNaN(num)) {
  8044. return num;
  8045. }
  8046. }
  8047. error('bad XRef entry');
  8048. }
  8049. if (this.encrypt && !suppressEncryption) {
  8050. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  8051. } else {
  8052. xrefEntry = parser.getObj();
  8053. }
  8054. if (!isStream(xrefEntry)) {
  8055. this.cache[num] = xrefEntry;
  8056. }
  8057. return xrefEntry;
  8058. },
  8059. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  8060. suppressEncryption) {
  8061. var tableOffset = xrefEntry.offset;
  8062. var stream = this.fetch(new Ref(tableOffset, 0));
  8063. if (!isStream(stream)) {
  8064. error('bad ObjStm stream');
  8065. }
  8066. var first = stream.dict.get('First');
  8067. var n = stream.dict.get('N');
  8068. if (!isInt(first) || !isInt(n)) {
  8069. error('invalid first and n parameters for ObjStm stream');
  8070. }
  8071. var parser = new Parser(new Lexer(stream), false, this);
  8072. parser.allowStreams = true;
  8073. var i, entries = [], num, nums = [];
  8074. // read the object numbers to populate cache
  8075. for (i = 0; i < n; ++i) {
  8076. num = parser.getObj();
  8077. if (!isInt(num)) {
  8078. error('invalid object number in the ObjStm stream: ' + num);
  8079. }
  8080. nums.push(num);
  8081. var offset = parser.getObj();
  8082. if (!isInt(offset)) {
  8083. error('invalid object offset in the ObjStm stream: ' + offset);
  8084. }
  8085. }
  8086. // read stream objects for cache
  8087. for (i = 0; i < n; ++i) {
  8088. entries.push(parser.getObj());
  8089. num = nums[i];
  8090. var entry = this.entries[num];
  8091. if (entry && entry.offset === tableOffset && entry.gen === i) {
  8092. this.cache[num] = entries[i];
  8093. }
  8094. }
  8095. xrefEntry = entries[xrefEntry.gen];
  8096. if (xrefEntry === undefined) {
  8097. error('bad XRef entry for compressed object');
  8098. }
  8099. return xrefEntry;
  8100. },
  8101. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  8102. if (!isRef(obj)) {
  8103. return Promise.resolve(obj);
  8104. }
  8105. return this.fetchAsync(obj);
  8106. },
  8107. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  8108. var streamManager = this.stream.manager;
  8109. var xref = this;
  8110. return new Promise(function tryFetch(resolve, reject) {
  8111. try {
  8112. resolve(xref.fetch(ref, suppressEncryption));
  8113. } catch (e) {
  8114. if (e instanceof MissingDataException) {
  8115. streamManager.requestRange(e.begin, e.end, function () {
  8116. tryFetch(resolve, reject);
  8117. });
  8118. return;
  8119. }
  8120. reject(e);
  8121. }
  8122. });
  8123. },
  8124. getCatalogObj: function XRef_getCatalogObj() {
  8125. return this.root;
  8126. }
  8127. };
  8128. return XRef;
  8129. })();
  8130. /**
  8131. * A NameTree is like a Dict but has some advantageous properties, see the
  8132. * spec (7.9.6) for more details.
  8133. * TODO: implement all the Dict functions and make this more efficent.
  8134. */
  8135. var NameTree = (function NameTreeClosure() {
  8136. function NameTree(root, xref) {
  8137. this.root = root;
  8138. this.xref = xref;
  8139. }
  8140. NameTree.prototype = {
  8141. getAll: function NameTree_getAll() {
  8142. var dict = {};
  8143. if (!this.root) {
  8144. return dict;
  8145. }
  8146. var xref = this.xref;
  8147. // reading name tree
  8148. var processed = new RefSet();
  8149. processed.put(this.root);
  8150. var queue = [this.root];
  8151. while (queue.length > 0) {
  8152. var i, n;
  8153. var obj = xref.fetchIfRef(queue.shift());
  8154. if (!isDict(obj)) {
  8155. continue;
  8156. }
  8157. if (obj.has('Kids')) {
  8158. var kids = obj.get('Kids');
  8159. for (i = 0, n = kids.length; i < n; i++) {
  8160. var kid = kids[i];
  8161. if (processed.has(kid)) {
  8162. error('invalid destinations');
  8163. }
  8164. queue.push(kid);
  8165. processed.put(kid);
  8166. }
  8167. continue;
  8168. }
  8169. var names = obj.get('Names');
  8170. if (names) {
  8171. for (i = 0, n = names.length; i < n; i += 2) {
  8172. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  8173. }
  8174. }
  8175. }
  8176. return dict;
  8177. }
  8178. };
  8179. return NameTree;
  8180. })();
  8181. /**
  8182. * "A PDF file can refer to the contents of another file by using a File
  8183. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  8184. * NOTE: Only embedded files are supported (as part of the attachments support)
  8185. * TODO: support the 'URL' file system (with caching if !/V), portable
  8186. * collections attributes and related files (/RF)
  8187. */
  8188. var FileSpec = (function FileSpecClosure() {
  8189. function FileSpec(root, xref) {
  8190. if (!root || !isDict(root)) {
  8191. return;
  8192. }
  8193. this.xref = xref;
  8194. this.root = root;
  8195. if (root.has('FS')) {
  8196. this.fs = root.get('FS');
  8197. }
  8198. this.description = root.has('Desc') ?
  8199. stringToPDFString(root.get('Desc')) :
  8200. '';
  8201. if (root.has('RF')) {
  8202. warn('Related file specifications are not supported');
  8203. }
  8204. this.contentAvailable = true;
  8205. if (!root.has('EF')) {
  8206. this.contentAvailable = false;
  8207. warn('Non-embedded file specifications are not supported');
  8208. }
  8209. }
  8210. function pickPlatformItem(dict) {
  8211. // Look for the filename in this order:
  8212. // UF, F, Unix, Mac, DOS
  8213. if (dict.has('UF')) {
  8214. return dict.get('UF');
  8215. } else if (dict.has('F')) {
  8216. return dict.get('F');
  8217. } else if (dict.has('Unix')) {
  8218. return dict.get('Unix');
  8219. } else if (dict.has('Mac')) {
  8220. return dict.get('Mac');
  8221. } else if (dict.has('DOS')) {
  8222. return dict.get('DOS');
  8223. } else {
  8224. return null;
  8225. }
  8226. }
  8227. FileSpec.prototype = {
  8228. get filename() {
  8229. if (!this._filename && this.root) {
  8230. var filename = pickPlatformItem(this.root) || 'unnamed';
  8231. this._filename = stringToPDFString(filename).
  8232. replace(/\\\\/g, '\\').
  8233. replace(/\\\//g, '/').
  8234. replace(/\\/g, '/');
  8235. }
  8236. return this._filename;
  8237. },
  8238. get content() {
  8239. if (!this.contentAvailable) {
  8240. return null;
  8241. }
  8242. if (!this.contentRef && this.root) {
  8243. this.contentRef = pickPlatformItem(this.root.get('EF'));
  8244. }
  8245. var content = null;
  8246. if (this.contentRef) {
  8247. var xref = this.xref;
  8248. var fileObj = xref.fetchIfRef(this.contentRef);
  8249. if (fileObj && isStream(fileObj)) {
  8250. content = fileObj.getBytes();
  8251. } else {
  8252. warn('Embedded file specification points to non-existing/invalid ' +
  8253. 'content');
  8254. }
  8255. } else {
  8256. warn('Embedded file specification does not have a content');
  8257. }
  8258. return content;
  8259. },
  8260. get serializable() {
  8261. return {
  8262. filename: this.filename,
  8263. content: this.content
  8264. };
  8265. }
  8266. };
  8267. return FileSpec;
  8268. })();
  8269. /**
  8270. * A helper for loading missing data in object graphs. It traverses the graph
  8271. * depth first and queues up any objects that have missing data. Once it has
  8272. * has traversed as many objects that are available it attempts to bundle the
  8273. * missing data requests and then resume from the nodes that weren't ready.
  8274. *
  8275. * NOTE: It provides protection from circular references by keeping track of
  8276. * of loaded references. However, you must be careful not to load any graphs
  8277. * that have references to the catalog or other pages since that will cause the
  8278. * entire PDF document object graph to be traversed.
  8279. */
  8280. var ObjectLoader = (function() {
  8281. function mayHaveChildren(value) {
  8282. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  8283. }
  8284. function addChildren(node, nodesToVisit) {
  8285. var value;
  8286. if (isDict(node) || isStream(node)) {
  8287. var map;
  8288. if (isDict(node)) {
  8289. map = node.map;
  8290. } else {
  8291. map = node.dict.map;
  8292. }
  8293. for (var key in map) {
  8294. value = map[key];
  8295. if (mayHaveChildren(value)) {
  8296. nodesToVisit.push(value);
  8297. }
  8298. }
  8299. } else if (isArray(node)) {
  8300. for (var i = 0, ii = node.length; i < ii; i++) {
  8301. value = node[i];
  8302. if (mayHaveChildren(value)) {
  8303. nodesToVisit.push(value);
  8304. }
  8305. }
  8306. }
  8307. }
  8308. function ObjectLoader(obj, keys, xref) {
  8309. this.obj = obj;
  8310. this.keys = keys;
  8311. this.xref = xref;
  8312. this.refSet = null;
  8313. }
  8314. ObjectLoader.prototype = {
  8315. load: function ObjectLoader_load() {
  8316. var keys = this.keys;
  8317. this.capability = createPromiseCapability();
  8318. // Don't walk the graph if all the data is already loaded.
  8319. if (!(this.xref.stream instanceof ChunkedStream) ||
  8320. this.xref.stream.getMissingChunks().length === 0) {
  8321. this.capability.resolve();
  8322. return this.capability.promise;
  8323. }
  8324. this.refSet = new RefSet();
  8325. // Setup the initial nodes to visit.
  8326. var nodesToVisit = [];
  8327. for (var i = 0; i < keys.length; i++) {
  8328. nodesToVisit.push(this.obj[keys[i]]);
  8329. }
  8330. this.walk(nodesToVisit);
  8331. return this.capability.promise;
  8332. },
  8333. walk: function ObjectLoader_walk(nodesToVisit) {
  8334. var nodesToRevisit = [];
  8335. var pendingRequests = [];
  8336. // DFS walk of the object graph.
  8337. while (nodesToVisit.length) {
  8338. var currentNode = nodesToVisit.pop();
  8339. // Only references or chunked streams can cause missing data exceptions.
  8340. if (isRef(currentNode)) {
  8341. // Skip nodes that have already been visited.
  8342. if (this.refSet.has(currentNode)) {
  8343. continue;
  8344. }
  8345. try {
  8346. var ref = currentNode;
  8347. this.refSet.put(ref);
  8348. currentNode = this.xref.fetch(currentNode);
  8349. } catch (e) {
  8350. if (!(e instanceof MissingDataException)) {
  8351. throw e;
  8352. }
  8353. nodesToRevisit.push(currentNode);
  8354. pendingRequests.push({ begin: e.begin, end: e.end });
  8355. }
  8356. }
  8357. if (currentNode && currentNode.getBaseStreams) {
  8358. var baseStreams = currentNode.getBaseStreams();
  8359. var foundMissingData = false;
  8360. for (var i = 0; i < baseStreams.length; i++) {
  8361. var stream = baseStreams[i];
  8362. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  8363. foundMissingData = true;
  8364. pendingRequests.push({
  8365. begin: stream.start,
  8366. end: stream.end
  8367. });
  8368. }
  8369. }
  8370. if (foundMissingData) {
  8371. nodesToRevisit.push(currentNode);
  8372. }
  8373. }
  8374. addChildren(currentNode, nodesToVisit);
  8375. }
  8376. if (pendingRequests.length) {
  8377. this.xref.stream.manager.requestRanges(pendingRequests,
  8378. function pendingRequestCallback() {
  8379. nodesToVisit = nodesToRevisit;
  8380. for (var i = 0; i < nodesToRevisit.length; i++) {
  8381. var node = nodesToRevisit[i];
  8382. // Remove any reference nodes from the currrent refset so they
  8383. // aren't skipped when we revist them.
  8384. if (isRef(node)) {
  8385. this.refSet.remove(node);
  8386. }
  8387. }
  8388. this.walk(nodesToVisit);
  8389. }.bind(this));
  8390. return;
  8391. }
  8392. // Everything is loaded.
  8393. this.refSet = null;
  8394. this.capability.resolve();
  8395. }
  8396. };
  8397. return ObjectLoader;
  8398. })();
  8399. var ISOAdobeCharset = [
  8400. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  8401. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  8402. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  8403. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  8404. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  8405. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  8406. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  8407. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  8408. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  8409. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  8410. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  8411. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  8412. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  8413. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  8414. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  8415. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  8416. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  8417. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  8418. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  8419. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  8420. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  8421. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  8422. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  8423. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  8424. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  8425. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  8426. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  8427. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  8428. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  8429. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  8430. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  8431. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  8432. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  8433. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  8434. ];
  8435. var ExpertCharset = [
  8436. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  8437. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  8438. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  8439. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  8440. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  8441. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  8442. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  8443. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  8444. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8445. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8446. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8447. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  8448. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  8449. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  8450. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  8451. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  8452. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  8453. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  8454. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  8455. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  8456. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  8457. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  8458. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8459. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8460. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8461. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8462. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8463. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8464. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  8465. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  8466. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  8467. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  8468. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  8469. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  8470. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  8471. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  8472. 'Ydieresissmall'
  8473. ];
  8474. var ExpertSubsetCharset = [
  8475. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  8476. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  8477. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  8478. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  8479. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  8480. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  8481. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  8482. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  8483. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  8484. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  8485. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  8486. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  8487. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  8488. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  8489. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  8490. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  8491. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  8492. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  8493. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  8494. 'periodinferior', 'commainferior'
  8495. ];
  8496. var DEFAULT_ICON_SIZE = 22; // px
  8497. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  8498. var Annotation = (function AnnotationClosure() {
  8499. // 12.5.5: Algorithm: Appearance streams
  8500. function getTransformMatrix(rect, bbox, matrix) {
  8501. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  8502. var minX = bounds[0];
  8503. var minY = bounds[1];
  8504. var maxX = bounds[2];
  8505. var maxY = bounds[3];
  8506. if (minX === maxX || minY === maxY) {
  8507. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  8508. // just apply the transform for rect
  8509. return [1, 0, 0, 1, rect[0], rect[1]];
  8510. }
  8511. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  8512. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  8513. return [
  8514. xRatio,
  8515. 0,
  8516. 0,
  8517. yRatio,
  8518. rect[0] - minX * xRatio,
  8519. rect[1] - minY * yRatio
  8520. ];
  8521. }
  8522. function getDefaultAppearance(dict) {
  8523. var appearanceState = dict.get('AP');
  8524. if (!isDict(appearanceState)) {
  8525. return;
  8526. }
  8527. var appearance;
  8528. var appearances = appearanceState.get('N');
  8529. if (isDict(appearances)) {
  8530. var as = dict.get('AS');
  8531. if (as && appearances.has(as.name)) {
  8532. appearance = appearances.get(as.name);
  8533. }
  8534. } else {
  8535. appearance = appearances;
  8536. }
  8537. return appearance;
  8538. }
  8539. function Annotation(params) {
  8540. var dict = params.dict;
  8541. var data = this.data = {};
  8542. data.subtype = dict.get('Subtype').name;
  8543. var rect = dict.get('Rect') || [0, 0, 0, 0];
  8544. data.rect = Util.normalizeRect(rect);
  8545. data.annotationFlags = dict.get('F');
  8546. var color = dict.get('C');
  8547. if (isArray(color) && color.length === 3) {
  8548. // TODO(mack): currently only supporting rgb; need support different
  8549. // colorspaces
  8550. data.color = color;
  8551. } else {
  8552. data.color = [0, 0, 0];
  8553. }
  8554. // Some types of annotations have border style dict which has more
  8555. // info than the border array
  8556. if (dict.has('BS')) {
  8557. var borderStyle = dict.get('BS');
  8558. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  8559. } else {
  8560. var borderArray = dict.get('Border') || [0, 0, 1];
  8561. data.borderWidth = borderArray[2] || 0;
  8562. // TODO: implement proper support for annotations with line dash patterns.
  8563. var dashArray = borderArray[3];
  8564. if (data.borderWidth > 0 && dashArray) {
  8565. if (!isArray(dashArray)) {
  8566. // Ignore the border if dashArray is not actually an array,
  8567. // this is consistent with the behaviour in Adobe Reader.
  8568. data.borderWidth = 0;
  8569. } else {
  8570. var dashArrayLength = dashArray.length;
  8571. if (dashArrayLength > 0) {
  8572. // According to the PDF specification: the elements in a dashArray
  8573. // shall be numbers that are nonnegative and not all equal to zero.
  8574. var isInvalid = false;
  8575. var numPositive = 0;
  8576. for (var i = 0; i < dashArrayLength; i++) {
  8577. var validNumber = (+dashArray[i] >= 0);
  8578. if (!validNumber) {
  8579. isInvalid = true;
  8580. break;
  8581. } else if (dashArray[i] > 0) {
  8582. numPositive++;
  8583. }
  8584. }
  8585. if (isInvalid || numPositive === 0) {
  8586. data.borderWidth = 0;
  8587. }
  8588. }
  8589. }
  8590. }
  8591. }
  8592. this.appearance = getDefaultAppearance(dict);
  8593. data.hasAppearance = !!this.appearance;
  8594. data.id = params.ref.num;
  8595. }
  8596. Annotation.prototype = {
  8597. getData: function Annotation_getData() {
  8598. return this.data;
  8599. },
  8600. isInvisible: function Annotation_isInvisible() {
  8601. var data = this.data;
  8602. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  8603. return false;
  8604. } else {
  8605. return !!(data &&
  8606. data.annotationFlags && // Default: not invisible
  8607. data.annotationFlags & 0x1); // Invisible
  8608. }
  8609. },
  8610. isViewable: function Annotation_isViewable() {
  8611. var data = this.data;
  8612. return !!(!this.isInvisible() &&
  8613. data &&
  8614. (!data.annotationFlags ||
  8615. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  8616. data.rect); // rectangle is necessary
  8617. },
  8618. isPrintable: function Annotation_isPrintable() {
  8619. var data = this.data;
  8620. return !!(!this.isInvisible() &&
  8621. data &&
  8622. data.annotationFlags && // Default: not printable
  8623. data.annotationFlags & 0x4 && // Print
  8624. !(data.annotationFlags & 0x2) && // Hidden
  8625. data.rect); // rectangle is necessary
  8626. },
  8627. loadResources: function Annotation_loadResources(keys) {
  8628. return new Promise(function (resolve, reject) {
  8629. this.appearance.dict.getAsync('Resources').then(function (resources) {
  8630. if (!resources) {
  8631. resolve();
  8632. return;
  8633. }
  8634. var objectLoader = new ObjectLoader(resources.map,
  8635. keys,
  8636. resources.xref);
  8637. objectLoader.load().then(function() {
  8638. resolve(resources);
  8639. }, reject);
  8640. }, reject);
  8641. }.bind(this));
  8642. },
  8643. getOperatorList: function Annotation_getOperatorList(evaluator) {
  8644. if (!this.appearance) {
  8645. return Promise.resolve(new OperatorList());
  8646. }
  8647. var data = this.data;
  8648. var appearanceDict = this.appearance.dict;
  8649. var resourcesPromise = this.loadResources([
  8650. 'ExtGState',
  8651. 'ColorSpace',
  8652. 'Pattern',
  8653. 'Shading',
  8654. 'XObject',
  8655. 'Font'
  8656. // ProcSet
  8657. // Properties
  8658. ]);
  8659. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  8660. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  8661. var transform = getTransformMatrix(data.rect, bbox, matrix);
  8662. var self = this;
  8663. return resourcesPromise.then(function(resources) {
  8664. var opList = new OperatorList();
  8665. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  8666. return evaluator.getOperatorList(self.appearance, resources, opList).
  8667. then(function () {
  8668. opList.addOp(OPS.endAnnotation, []);
  8669. self.appearance.reset();
  8670. return opList;
  8671. });
  8672. });
  8673. }
  8674. };
  8675. Annotation.getConstructor =
  8676. function Annotation_getConstructor(subtype, fieldType) {
  8677. if (!subtype) {
  8678. return;
  8679. }
  8680. // TODO(mack): Implement FreeText annotations
  8681. if (subtype === 'Link') {
  8682. return LinkAnnotation;
  8683. } else if (subtype === 'Text') {
  8684. return TextAnnotation;
  8685. } else if (subtype === 'Widget') {
  8686. if (!fieldType) {
  8687. return;
  8688. }
  8689. if (fieldType === 'Tx') {
  8690. return TextWidgetAnnotation;
  8691. } else {
  8692. return WidgetAnnotation;
  8693. }
  8694. } else {
  8695. return Annotation;
  8696. }
  8697. };
  8698. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  8699. var dict = xref.fetchIfRef(ref);
  8700. if (!isDict(dict)) {
  8701. return;
  8702. }
  8703. var subtype = dict.get('Subtype');
  8704. subtype = isName(subtype) ? subtype.name : '';
  8705. if (!subtype) {
  8706. return;
  8707. }
  8708. var fieldType = Util.getInheritableProperty(dict, 'FT');
  8709. fieldType = isName(fieldType) ? fieldType.name : '';
  8710. var Constructor = Annotation.getConstructor(subtype, fieldType);
  8711. if (!Constructor) {
  8712. return;
  8713. }
  8714. var params = {
  8715. dict: dict,
  8716. ref: ref,
  8717. };
  8718. var annotation = new Constructor(params);
  8719. if (annotation.isViewable() || annotation.isPrintable()) {
  8720. return annotation;
  8721. } else {
  8722. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  8723. warn('unimplemented annotation type: ' + subtype);
  8724. }
  8725. }
  8726. };
  8727. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  8728. annotations, opList, pdfManager, partialEvaluator, intent) {
  8729. function reject(e) {
  8730. annotationsReadyCapability.reject(e);
  8731. }
  8732. var annotationsReadyCapability = createPromiseCapability();
  8733. var annotationPromises = [];
  8734. for (var i = 0, n = annotations.length; i < n; ++i) {
  8735. if (intent === 'display' && annotations[i].isViewable() ||
  8736. intent === 'print' && annotations[i].isPrintable()) {
  8737. annotationPromises.push(
  8738. annotations[i].getOperatorList(partialEvaluator));
  8739. }
  8740. }
  8741. Promise.all(annotationPromises).then(function(datas) {
  8742. opList.addOp(OPS.beginAnnotations, []);
  8743. for (var i = 0, n = datas.length; i < n; ++i) {
  8744. var annotOpList = datas[i];
  8745. opList.addOpList(annotOpList);
  8746. }
  8747. opList.addOp(OPS.endAnnotations, []);
  8748. annotationsReadyCapability.resolve();
  8749. }, reject);
  8750. return annotationsReadyCapability.promise;
  8751. };
  8752. return Annotation;
  8753. })();
  8754. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  8755. function WidgetAnnotation(params) {
  8756. Annotation.call(this, params);
  8757. var dict = params.dict;
  8758. var data = this.data;
  8759. data.fieldValue = stringToPDFString(
  8760. Util.getInheritableProperty(dict, 'V') || '');
  8761. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  8762. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  8763. var fieldType = Util.getInheritableProperty(dict, 'FT');
  8764. data.fieldType = isName(fieldType) ? fieldType.name : '';
  8765. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  8766. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  8767. // Building the full field name by collecting the field and
  8768. // its ancestors 'T' data and joining them using '.'.
  8769. var fieldName = [];
  8770. var namedItem = dict;
  8771. var ref = params.ref;
  8772. while (namedItem) {
  8773. var parent = namedItem.get('Parent');
  8774. var parentRef = namedItem.getRaw('Parent');
  8775. var name = namedItem.get('T');
  8776. if (name) {
  8777. fieldName.unshift(stringToPDFString(name));
  8778. } else {
  8779. // The field name is absent, that means more than one field
  8780. // with the same name may exist. Replacing the empty name
  8781. // with the '`' plus index in the parent's 'Kids' array.
  8782. // This is not in the PDF spec but necessary to id the
  8783. // the input controls.
  8784. var kids = parent.get('Kids');
  8785. var j, jj;
  8786. for (j = 0, jj = kids.length; j < jj; j++) {
  8787. var kidRef = kids[j];
  8788. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  8789. break;
  8790. }
  8791. }
  8792. fieldName.unshift('`' + j);
  8793. }
  8794. namedItem = parent;
  8795. ref = parentRef;
  8796. }
  8797. data.fullName = fieldName.join('.');
  8798. }
  8799. var parent = Annotation.prototype;
  8800. Util.inherit(WidgetAnnotation, Annotation, {
  8801. isViewable: function WidgetAnnotation_isViewable() {
  8802. if (this.data.fieldType === 'Sig') {
  8803. warn('unimplemented annotation type: Widget signature');
  8804. return false;
  8805. }
  8806. return parent.isViewable.call(this);
  8807. }
  8808. });
  8809. return WidgetAnnotation;
  8810. })();
  8811. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  8812. function TextWidgetAnnotation(params) {
  8813. WidgetAnnotation.call(this, params);
  8814. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  8815. this.data.annotationType = AnnotationType.WIDGET;
  8816. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  8817. }
  8818. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  8819. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  8820. if (this.appearance) {
  8821. return Annotation.prototype.getOperatorList.call(this, evaluator);
  8822. }
  8823. var opList = new OperatorList();
  8824. var data = this.data;
  8825. // Even if there is an appearance stream, ignore it. This is the
  8826. // behaviour used by Adobe Reader.
  8827. if (!data.defaultAppearance) {
  8828. return Promise.resolve(opList);
  8829. }
  8830. var stream = new Stream(stringToBytes(data.defaultAppearance));
  8831. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  8832. then(function () {
  8833. return opList;
  8834. });
  8835. }
  8836. });
  8837. return TextWidgetAnnotation;
  8838. })();
  8839. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  8840. function InteractiveAnnotation(params) {
  8841. Annotation.call(this, params);
  8842. this.data.hasHtml = true;
  8843. }
  8844. Util.inherit(InteractiveAnnotation, Annotation, { });
  8845. return InteractiveAnnotation;
  8846. })();
  8847. var TextAnnotation = (function TextAnnotationClosure() {
  8848. function TextAnnotation(params) {
  8849. InteractiveAnnotation.call(this, params);
  8850. var dict = params.dict;
  8851. var data = this.data;
  8852. var content = dict.get('Contents');
  8853. var title = dict.get('T');
  8854. data.annotationType = AnnotationType.TEXT;
  8855. data.content = stringToPDFString(content || '');
  8856. data.title = stringToPDFString(title || '');
  8857. if (data.hasAppearance) {
  8858. data.name = 'NoIcon';
  8859. } else {
  8860. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  8861. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  8862. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  8863. }
  8864. if (dict.has('C')) {
  8865. data.hasBgColor = true;
  8866. }
  8867. }
  8868. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  8869. return TextAnnotation;
  8870. })();
  8871. var LinkAnnotation = (function LinkAnnotationClosure() {
  8872. function LinkAnnotation(params) {
  8873. InteractiveAnnotation.call(this, params);
  8874. var dict = params.dict;
  8875. var data = this.data;
  8876. data.annotationType = AnnotationType.LINK;
  8877. var action = dict.get('A');
  8878. if (action) {
  8879. var linkType = action.get('S').name;
  8880. if (linkType === 'URI') {
  8881. var url = action.get('URI');
  8882. if (isName(url)) {
  8883. // Some bad PDFs do not put parentheses around relative URLs.
  8884. url = '/' + url.name;
  8885. } else if (url) {
  8886. url = addDefaultProtocolToUrl(url);
  8887. }
  8888. // TODO: pdf spec mentions urls can be relative to a Base
  8889. // entry in the dictionary.
  8890. if (!isValidUrl(url, false)) {
  8891. url = '';
  8892. }
  8893. data.url = url;
  8894. } else if (linkType === 'GoTo') {
  8895. data.dest = action.get('D');
  8896. } else if (linkType === 'GoToR') {
  8897. var urlDict = action.get('F');
  8898. if (isDict(urlDict)) {
  8899. // We assume that the 'url' is a Filspec dictionary
  8900. // and fetch the url without checking any further
  8901. url = urlDict.get('F') || '';
  8902. }
  8903. // TODO: pdf reference says that GoToR
  8904. // can also have 'NewWindow' attribute
  8905. if (!isValidUrl(url, false)) {
  8906. url = '';
  8907. }
  8908. data.url = url;
  8909. data.dest = action.get('D');
  8910. } else if (linkType === 'Named') {
  8911. data.action = action.get('N').name;
  8912. } else {
  8913. warn('unrecognized link type: ' + linkType);
  8914. }
  8915. } else if (dict.has('Dest')) {
  8916. // simple destination link
  8917. var dest = dict.get('Dest');
  8918. data.dest = isName(dest) ? dest.name : dest;
  8919. }
  8920. }
  8921. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  8922. function addDefaultProtocolToUrl(url) {
  8923. if (url && url.indexOf('www.') === 0) {
  8924. return ('http://' + url);
  8925. }
  8926. return url;
  8927. }
  8928. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  8929. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  8930. return false;
  8931. }
  8932. });
  8933. return LinkAnnotation;
  8934. })();
  8935. var PDFFunction = (function PDFFunctionClosure() {
  8936. var CONSTRUCT_SAMPLED = 0;
  8937. var CONSTRUCT_INTERPOLATED = 2;
  8938. var CONSTRUCT_STICHED = 3;
  8939. var CONSTRUCT_POSTSCRIPT = 4;
  8940. return {
  8941. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  8942. str) {
  8943. var i, ii;
  8944. var length = 1;
  8945. for (i = 0, ii = size.length; i < ii; i++) {
  8946. length *= size[i];
  8947. }
  8948. length *= outputSize;
  8949. var array = [];
  8950. var codeSize = 0;
  8951. var codeBuf = 0;
  8952. // 32 is a valid bps so shifting won't work
  8953. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  8954. var strBytes = str.getBytes((length * bps + 7) / 8);
  8955. var strIdx = 0;
  8956. for (i = 0; i < length; i++) {
  8957. while (codeSize < bps) {
  8958. codeBuf <<= 8;
  8959. codeBuf |= strBytes[strIdx++];
  8960. codeSize += 8;
  8961. }
  8962. codeSize -= bps;
  8963. array.push((codeBuf >> codeSize) * sampleMul);
  8964. codeBuf &= (1 << codeSize) - 1;
  8965. }
  8966. return array;
  8967. },
  8968. getIR: function PDFFunction_getIR(xref, fn) {
  8969. var dict = fn.dict;
  8970. if (!dict) {
  8971. dict = fn;
  8972. }
  8973. var types = [this.constructSampled,
  8974. null,
  8975. this.constructInterpolated,
  8976. this.constructStiched,
  8977. this.constructPostScript];
  8978. var typeNum = dict.get('FunctionType');
  8979. var typeFn = types[typeNum];
  8980. if (!typeFn) {
  8981. error('Unknown type of function');
  8982. }
  8983. return typeFn.call(this, fn, dict, xref);
  8984. },
  8985. fromIR: function PDFFunction_fromIR(IR) {
  8986. var type = IR[0];
  8987. switch (type) {
  8988. case CONSTRUCT_SAMPLED:
  8989. return this.constructSampledFromIR(IR);
  8990. case CONSTRUCT_INTERPOLATED:
  8991. return this.constructInterpolatedFromIR(IR);
  8992. case CONSTRUCT_STICHED:
  8993. return this.constructStichedFromIR(IR);
  8994. //case CONSTRUCT_POSTSCRIPT:
  8995. default:
  8996. return this.constructPostScriptFromIR(IR);
  8997. }
  8998. },
  8999. parse: function PDFFunction_parse(xref, fn) {
  9000. var IR = this.getIR(xref, fn);
  9001. return this.fromIR(IR);
  9002. },
  9003. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  9004. if (!isArray(fnObj)) {
  9005. // not an array -- parsing as regular function
  9006. return this.parse(xref, fnObj);
  9007. }
  9008. var fnArray = [];
  9009. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  9010. var obj = xref.fetchIfRef(fnObj[j]);
  9011. fnArray.push(PDFFunction.parse(xref, obj));
  9012. }
  9013. return function (src, srcOffset, dest, destOffset) {
  9014. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  9015. fnArray[i](src, srcOffset, dest, destOffset + i);
  9016. }
  9017. };
  9018. },
  9019. constructSampled: function PDFFunction_constructSampled(str, dict) {
  9020. function toMultiArray(arr) {
  9021. var inputLength = arr.length;
  9022. var out = [];
  9023. var index = 0;
  9024. for (var i = 0; i < inputLength; i += 2) {
  9025. out[index] = [arr[i], arr[i + 1]];
  9026. ++index;
  9027. }
  9028. return out;
  9029. }
  9030. var domain = dict.get('Domain');
  9031. var range = dict.get('Range');
  9032. if (!domain || !range) {
  9033. error('No domain or range');
  9034. }
  9035. var inputSize = domain.length / 2;
  9036. var outputSize = range.length / 2;
  9037. domain = toMultiArray(domain);
  9038. range = toMultiArray(range);
  9039. var size = dict.get('Size');
  9040. var bps = dict.get('BitsPerSample');
  9041. var order = dict.get('Order') || 1;
  9042. if (order !== 1) {
  9043. // No description how cubic spline interpolation works in PDF32000:2008
  9044. // As in poppler, ignoring order, linear interpolation may work as good
  9045. info('No support for cubic spline interpolation: ' + order);
  9046. }
  9047. var encode = dict.get('Encode');
  9048. if (!encode) {
  9049. encode = [];
  9050. for (var i = 0; i < inputSize; ++i) {
  9051. encode.push(0);
  9052. encode.push(size[i] - 1);
  9053. }
  9054. }
  9055. encode = toMultiArray(encode);
  9056. var decode = dict.get('Decode');
  9057. if (!decode) {
  9058. decode = range;
  9059. } else {
  9060. decode = toMultiArray(decode);
  9061. }
  9062. var samples = this.getSampleArray(size, outputSize, bps, str);
  9063. return [
  9064. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  9065. outputSize, Math.pow(2, bps) - 1, range
  9066. ];
  9067. },
  9068. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  9069. // See chapter 3, page 109 of the PDF reference
  9070. function interpolate(x, xmin, xmax, ymin, ymax) {
  9071. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  9072. }
  9073. return function constructSampledFromIRResult(src, srcOffset,
  9074. dest, destOffset) {
  9075. // See chapter 3, page 110 of the PDF reference.
  9076. var m = IR[1];
  9077. var domain = IR[2];
  9078. var encode = IR[3];
  9079. var decode = IR[4];
  9080. var samples = IR[5];
  9081. var size = IR[6];
  9082. var n = IR[7];
  9083. //var mask = IR[8];
  9084. var range = IR[9];
  9085. // Building the cube vertices: its part and sample index
  9086. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  9087. var cubeVertices = 1 << m;
  9088. var cubeN = new Float64Array(cubeVertices);
  9089. var cubeVertex = new Uint32Array(cubeVertices);
  9090. var i, j;
  9091. for (j = 0; j < cubeVertices; j++) {
  9092. cubeN[j] = 1;
  9093. }
  9094. var k = n, pos = 1;
  9095. // Map x_i to y_j for 0 <= i < m using the sampled function.
  9096. for (i = 0; i < m; ++i) {
  9097. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  9098. var domain_2i = domain[i][0];
  9099. var domain_2i_1 = domain[i][1];
  9100. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  9101. domain_2i_1);
  9102. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  9103. // Encode_2i, Encode_2i+1)
  9104. var e = interpolate(xi, domain_2i, domain_2i_1,
  9105. encode[i][0], encode[i][1]);
  9106. // e_i' = min(max(e_i, 0), Size_i - 1)
  9107. var size_i = size[i];
  9108. e = Math.min(Math.max(e, 0), size_i - 1);
  9109. // Adjusting the cube: N and vertex sample index
  9110. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  9111. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  9112. var n1 = e - e0; // (e - e0) / (e1 - e0);
  9113. var offset0 = e0 * k;
  9114. var offset1 = offset0 + k; // e1 * k
  9115. for (j = 0; j < cubeVertices; j++) {
  9116. if (j & pos) {
  9117. cubeN[j] *= n1;
  9118. cubeVertex[j] += offset1;
  9119. } else {
  9120. cubeN[j] *= n0;
  9121. cubeVertex[j] += offset0;
  9122. }
  9123. }
  9124. k *= size_i;
  9125. pos <<= 1;
  9126. }
  9127. for (j = 0; j < n; ++j) {
  9128. // Sum all cube vertices' samples portions
  9129. var rj = 0;
  9130. for (i = 0; i < cubeVertices; i++) {
  9131. rj += samples[cubeVertex[i] + j] * cubeN[i];
  9132. }
  9133. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  9134. // Decode_2j, Decode_2j+1)
  9135. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  9136. // y_j = min(max(r_j, range_2j), range_2j+1)
  9137. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  9138. range[j][1]);
  9139. }
  9140. };
  9141. },
  9142. constructInterpolated: function PDFFunction_constructInterpolated(str,
  9143. dict) {
  9144. var c0 = dict.get('C0') || [0];
  9145. var c1 = dict.get('C1') || [1];
  9146. var n = dict.get('N');
  9147. if (!isArray(c0) || !isArray(c1)) {
  9148. error('Illegal dictionary for interpolated function');
  9149. }
  9150. var length = c0.length;
  9151. var diff = [];
  9152. for (var i = 0; i < length; ++i) {
  9153. diff.push(c1[i] - c0[i]);
  9154. }
  9155. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  9156. },
  9157. constructInterpolatedFromIR:
  9158. function PDFFunction_constructInterpolatedFromIR(IR) {
  9159. var c0 = IR[1];
  9160. var diff = IR[2];
  9161. var n = IR[3];
  9162. var length = diff.length;
  9163. return function constructInterpolatedFromIRResult(src, srcOffset,
  9164. dest, destOffset) {
  9165. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  9166. for (var j = 0; j < length; ++j) {
  9167. dest[destOffset + j] = c0[j] + (x * diff[j]);
  9168. }
  9169. };
  9170. },
  9171. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  9172. var domain = dict.get('Domain');
  9173. if (!domain) {
  9174. error('No domain');
  9175. }
  9176. var inputSize = domain.length / 2;
  9177. if (inputSize !== 1) {
  9178. error('Bad domain for stiched function');
  9179. }
  9180. var fnRefs = dict.get('Functions');
  9181. var fns = [];
  9182. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  9183. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  9184. }
  9185. var bounds = dict.get('Bounds');
  9186. var encode = dict.get('Encode');
  9187. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  9188. },
  9189. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  9190. var domain = IR[1];
  9191. var bounds = IR[2];
  9192. var encode = IR[3];
  9193. var fnsIR = IR[4];
  9194. var fns = [];
  9195. var tmpBuf = new Float32Array(1);
  9196. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  9197. fns.push(PDFFunction.fromIR(fnsIR[i]));
  9198. }
  9199. return function constructStichedFromIRResult(src, srcOffset,
  9200. dest, destOffset) {
  9201. var clip = function constructStichedFromIRClip(v, min, max) {
  9202. if (v > max) {
  9203. v = max;
  9204. } else if (v < min) {
  9205. v = min;
  9206. }
  9207. return v;
  9208. };
  9209. // clip to domain
  9210. var v = clip(src[srcOffset], domain[0], domain[1]);
  9211. // calulate which bound the value is in
  9212. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  9213. if (v < bounds[i]) {
  9214. break;
  9215. }
  9216. }
  9217. // encode value into domain of function
  9218. var dmin = domain[0];
  9219. if (i > 0) {
  9220. dmin = bounds[i - 1];
  9221. }
  9222. var dmax = domain[1];
  9223. if (i < bounds.length) {
  9224. dmax = bounds[i];
  9225. }
  9226. var rmin = encode[2 * i];
  9227. var rmax = encode[2 * i + 1];
  9228. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  9229. // call the appropriate function
  9230. fns[i](tmpBuf, 0, dest, destOffset);
  9231. };
  9232. },
  9233. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  9234. xref) {
  9235. var domain = dict.get('Domain');
  9236. var range = dict.get('Range');
  9237. if (!domain) {
  9238. error('No domain.');
  9239. }
  9240. if (!range) {
  9241. error('No range.');
  9242. }
  9243. var lexer = new PostScriptLexer(fn);
  9244. var parser = new PostScriptParser(lexer);
  9245. var code = parser.parse();
  9246. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  9247. },
  9248. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  9249. IR) {
  9250. var domain = IR[1];
  9251. var range = IR[2];
  9252. var code = IR[3];
  9253. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  9254. if (compiled) {
  9255. // Compiled function consists of simple expressions such as addition,
  9256. // subtraction, Math.max, and also contains 'var' and 'return'
  9257. // statements. See the generation in the PostScriptCompiler below.
  9258. /*jshint -W054 */
  9259. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  9260. }
  9261. info('Unable to compile PS function');
  9262. var numOutputs = range.length >> 1;
  9263. var numInputs = domain.length >> 1;
  9264. var evaluator = new PostScriptEvaluator(code);
  9265. // Cache the values for a big speed up, the cache size is limited though
  9266. // since the number of possible values can be huge from a PS function.
  9267. var cache = {};
  9268. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  9269. // seen in our tests.
  9270. var MAX_CACHE_SIZE = 2048 * 4;
  9271. var cache_available = MAX_CACHE_SIZE;
  9272. var tmpBuf = new Float32Array(numInputs);
  9273. return function constructPostScriptFromIRResult(src, srcOffset,
  9274. dest, destOffset) {
  9275. var i, value;
  9276. var key = '';
  9277. var input = tmpBuf;
  9278. for (i = 0; i < numInputs; i++) {
  9279. value = src[srcOffset + i];
  9280. input[i] = value;
  9281. key += value + '_';
  9282. }
  9283. var cachedValue = cache[key];
  9284. if (cachedValue !== undefined) {
  9285. cachedValue.set(dest, destOffset);
  9286. return;
  9287. }
  9288. var output = new Float32Array(numOutputs);
  9289. var stack = evaluator.execute(input);
  9290. var stackIndex = stack.length - numOutputs;
  9291. for (i = 0; i < numOutputs; i++) {
  9292. value = stack[stackIndex + i];
  9293. var bound = range[i * 2];
  9294. if (value < bound) {
  9295. value = bound;
  9296. } else {
  9297. bound = range[i * 2 +1];
  9298. if (value > bound) {
  9299. value = bound;
  9300. }
  9301. }
  9302. output[i] = value;
  9303. }
  9304. if (cache_available > 0) {
  9305. cache_available--;
  9306. cache[key] = output;
  9307. }
  9308. output.set(dest, destOffset);
  9309. };
  9310. }
  9311. };
  9312. })();
  9313. function isPDFFunction(v) {
  9314. var fnDict;
  9315. if (typeof v !== 'object') {
  9316. return false;
  9317. } else if (isDict(v)) {
  9318. fnDict = v;
  9319. } else if (isStream(v)) {
  9320. fnDict = v.dict;
  9321. } else {
  9322. return false;
  9323. }
  9324. return fnDict.has('FunctionType');
  9325. }
  9326. var PostScriptStack = (function PostScriptStackClosure() {
  9327. var MAX_STACK_SIZE = 100;
  9328. function PostScriptStack(initialStack) {
  9329. this.stack = !initialStack ? [] :
  9330. Array.prototype.slice.call(initialStack, 0);
  9331. }
  9332. PostScriptStack.prototype = {
  9333. push: function PostScriptStack_push(value) {
  9334. if (this.stack.length >= MAX_STACK_SIZE) {
  9335. error('PostScript function stack overflow.');
  9336. }
  9337. this.stack.push(value);
  9338. },
  9339. pop: function PostScriptStack_pop() {
  9340. if (this.stack.length <= 0) {
  9341. error('PostScript function stack underflow.');
  9342. }
  9343. return this.stack.pop();
  9344. },
  9345. copy: function PostScriptStack_copy(n) {
  9346. if (this.stack.length + n >= MAX_STACK_SIZE) {
  9347. error('PostScript function stack overflow.');
  9348. }
  9349. var stack = this.stack;
  9350. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  9351. stack.push(stack[i]);
  9352. }
  9353. },
  9354. index: function PostScriptStack_index(n) {
  9355. this.push(this.stack[this.stack.length - n - 1]);
  9356. },
  9357. // rotate the last n stack elements p times
  9358. roll: function PostScriptStack_roll(n, p) {
  9359. var stack = this.stack;
  9360. var l = stack.length - n;
  9361. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  9362. for (i = l, j = r; i < j; i++, j--) {
  9363. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  9364. }
  9365. for (i = l, j = c - 1; i < j; i++, j--) {
  9366. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  9367. }
  9368. for (i = c, j = r; i < j; i++, j--) {
  9369. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  9370. }
  9371. }
  9372. };
  9373. return PostScriptStack;
  9374. })();
  9375. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  9376. function PostScriptEvaluator(operators) {
  9377. this.operators = operators;
  9378. }
  9379. PostScriptEvaluator.prototype = {
  9380. execute: function PostScriptEvaluator_execute(initialStack) {
  9381. var stack = new PostScriptStack(initialStack);
  9382. var counter = 0;
  9383. var operators = this.operators;
  9384. var length = operators.length;
  9385. var operator, a, b;
  9386. while (counter < length) {
  9387. operator = operators[counter++];
  9388. if (typeof operator === 'number') {
  9389. // Operator is really an operand and should be pushed to the stack.
  9390. stack.push(operator);
  9391. continue;
  9392. }
  9393. switch (operator) {
  9394. // non standard ps operators
  9395. case 'jz': // jump if false
  9396. b = stack.pop();
  9397. a = stack.pop();
  9398. if (!a) {
  9399. counter = b;
  9400. }
  9401. break;
  9402. case 'j': // jump
  9403. a = stack.pop();
  9404. counter = a;
  9405. break;
  9406. // all ps operators in alphabetical order (excluding if/ifelse)
  9407. case 'abs':
  9408. a = stack.pop();
  9409. stack.push(Math.abs(a));
  9410. break;
  9411. case 'add':
  9412. b = stack.pop();
  9413. a = stack.pop();
  9414. stack.push(a + b);
  9415. break;
  9416. case 'and':
  9417. b = stack.pop();
  9418. a = stack.pop();
  9419. if (isBool(a) && isBool(b)) {
  9420. stack.push(a && b);
  9421. } else {
  9422. stack.push(a & b);
  9423. }
  9424. break;
  9425. case 'atan':
  9426. a = stack.pop();
  9427. stack.push(Math.atan(a));
  9428. break;
  9429. case 'bitshift':
  9430. b = stack.pop();
  9431. a = stack.pop();
  9432. if (a > 0) {
  9433. stack.push(a << b);
  9434. } else {
  9435. stack.push(a >> b);
  9436. }
  9437. break;
  9438. case 'ceiling':
  9439. a = stack.pop();
  9440. stack.push(Math.ceil(a));
  9441. break;
  9442. case 'copy':
  9443. a = stack.pop();
  9444. stack.copy(a);
  9445. break;
  9446. case 'cos':
  9447. a = stack.pop();
  9448. stack.push(Math.cos(a));
  9449. break;
  9450. case 'cvi':
  9451. a = stack.pop() | 0;
  9452. stack.push(a);
  9453. break;
  9454. case 'cvr':
  9455. // noop
  9456. break;
  9457. case 'div':
  9458. b = stack.pop();
  9459. a = stack.pop();
  9460. stack.push(a / b);
  9461. break;
  9462. case 'dup':
  9463. stack.copy(1);
  9464. break;
  9465. case 'eq':
  9466. b = stack.pop();
  9467. a = stack.pop();
  9468. stack.push(a === b);
  9469. break;
  9470. case 'exch':
  9471. stack.roll(2, 1);
  9472. break;
  9473. case 'exp':
  9474. b = stack.pop();
  9475. a = stack.pop();
  9476. stack.push(Math.pow(a, b));
  9477. break;
  9478. case 'false':
  9479. stack.push(false);
  9480. break;
  9481. case 'floor':
  9482. a = stack.pop();
  9483. stack.push(Math.floor(a));
  9484. break;
  9485. case 'ge':
  9486. b = stack.pop();
  9487. a = stack.pop();
  9488. stack.push(a >= b);
  9489. break;
  9490. case 'gt':
  9491. b = stack.pop();
  9492. a = stack.pop();
  9493. stack.push(a > b);
  9494. break;
  9495. case 'idiv':
  9496. b = stack.pop();
  9497. a = stack.pop();
  9498. stack.push((a / b) | 0);
  9499. break;
  9500. case 'index':
  9501. a = stack.pop();
  9502. stack.index(a);
  9503. break;
  9504. case 'le':
  9505. b = stack.pop();
  9506. a = stack.pop();
  9507. stack.push(a <= b);
  9508. break;
  9509. case 'ln':
  9510. a = stack.pop();
  9511. stack.push(Math.log(a));
  9512. break;
  9513. case 'log':
  9514. a = stack.pop();
  9515. stack.push(Math.log(a) / Math.LN10);
  9516. break;
  9517. case 'lt':
  9518. b = stack.pop();
  9519. a = stack.pop();
  9520. stack.push(a < b);
  9521. break;
  9522. case 'mod':
  9523. b = stack.pop();
  9524. a = stack.pop();
  9525. stack.push(a % b);
  9526. break;
  9527. case 'mul':
  9528. b = stack.pop();
  9529. a = stack.pop();
  9530. stack.push(a * b);
  9531. break;
  9532. case 'ne':
  9533. b = stack.pop();
  9534. a = stack.pop();
  9535. stack.push(a !== b);
  9536. break;
  9537. case 'neg':
  9538. a = stack.pop();
  9539. stack.push(-a);
  9540. break;
  9541. case 'not':
  9542. a = stack.pop();
  9543. if (isBool(a)) {
  9544. stack.push(!a);
  9545. } else {
  9546. stack.push(~a);
  9547. }
  9548. break;
  9549. case 'or':
  9550. b = stack.pop();
  9551. a = stack.pop();
  9552. if (isBool(a) && isBool(b)) {
  9553. stack.push(a || b);
  9554. } else {
  9555. stack.push(a | b);
  9556. }
  9557. break;
  9558. case 'pop':
  9559. stack.pop();
  9560. break;
  9561. case 'roll':
  9562. b = stack.pop();
  9563. a = stack.pop();
  9564. stack.roll(a, b);
  9565. break;
  9566. case 'round':
  9567. a = stack.pop();
  9568. stack.push(Math.round(a));
  9569. break;
  9570. case 'sin':
  9571. a = stack.pop();
  9572. stack.push(Math.sin(a));
  9573. break;
  9574. case 'sqrt':
  9575. a = stack.pop();
  9576. stack.push(Math.sqrt(a));
  9577. break;
  9578. case 'sub':
  9579. b = stack.pop();
  9580. a = stack.pop();
  9581. stack.push(a - b);
  9582. break;
  9583. case 'true':
  9584. stack.push(true);
  9585. break;
  9586. case 'truncate':
  9587. a = stack.pop();
  9588. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  9589. stack.push(a);
  9590. break;
  9591. case 'xor':
  9592. b = stack.pop();
  9593. a = stack.pop();
  9594. if (isBool(a) && isBool(b)) {
  9595. stack.push(a !== b);
  9596. } else {
  9597. stack.push(a ^ b);
  9598. }
  9599. break;
  9600. default:
  9601. error('Unknown operator ' + operator);
  9602. break;
  9603. }
  9604. }
  9605. return stack.stack;
  9606. }
  9607. };
  9608. return PostScriptEvaluator;
  9609. })();
  9610. // Most of the PDFs functions consist of simple operations such as:
  9611. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  9612. //
  9613. // We can compile most of such programs, and at the same moment, we can
  9614. // optimize some expressions using basic math properties. Keeping track of
  9615. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  9616. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  9617. function AstNode(type) {
  9618. this.type = type;
  9619. }
  9620. AstNode.prototype.visit = function (visitor) {
  9621. throw new Error('abstract method');
  9622. };
  9623. function AstArgument(index, min, max) {
  9624. AstNode.call(this, 'args');
  9625. this.index = index;
  9626. this.min = min;
  9627. this.max = max;
  9628. }
  9629. AstArgument.prototype = Object.create(AstNode.prototype);
  9630. AstArgument.prototype.visit = function (visitor) {
  9631. visitor.visitArgument(this);
  9632. };
  9633. function AstLiteral(number) {
  9634. AstNode.call(this, 'literal');
  9635. this.number = number;
  9636. this.min = number;
  9637. this.max = number;
  9638. }
  9639. AstLiteral.prototype = Object.create(AstNode.prototype);
  9640. AstLiteral.prototype.visit = function (visitor) {
  9641. visitor.visitLiteral(this);
  9642. };
  9643. function AstBinaryOperation(op, arg1, arg2, min, max) {
  9644. AstNode.call(this, 'binary');
  9645. this.op = op;
  9646. this.arg1 = arg1;
  9647. this.arg2 = arg2;
  9648. this.min = min;
  9649. this.max = max;
  9650. }
  9651. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  9652. AstBinaryOperation.prototype.visit = function (visitor) {
  9653. visitor.visitBinaryOperation(this);
  9654. };
  9655. function AstMin(arg, max) {
  9656. AstNode.call(this, 'max');
  9657. this.arg = arg;
  9658. this.min = arg.min;
  9659. this.max = max;
  9660. }
  9661. AstMin.prototype = Object.create(AstNode.prototype);
  9662. AstMin.prototype.visit = function (visitor) {
  9663. visitor.visitMin(this);
  9664. };
  9665. function AstVariable(index, min, max) {
  9666. AstNode.call(this, 'var');
  9667. this.index = index;
  9668. this.min = min;
  9669. this.max = max;
  9670. }
  9671. AstVariable.prototype = Object.create(AstNode.prototype);
  9672. AstVariable.prototype.visit = function (visitor) {
  9673. visitor.visitVariable(this);
  9674. };
  9675. function AstVariableDefinition(variable, arg) {
  9676. AstNode.call(this, 'definition');
  9677. this.variable = variable;
  9678. this.arg = arg;
  9679. }
  9680. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  9681. AstVariableDefinition.prototype.visit = function (visitor) {
  9682. visitor.visitVariableDefinition(this);
  9683. };
  9684. function ExpressionBuilderVisitor() {
  9685. this.parts = [];
  9686. }
  9687. ExpressionBuilderVisitor.prototype = {
  9688. visitArgument: function (arg) {
  9689. this.parts.push('Math.max(', arg.min, ', Math.min(',
  9690. arg.max, ', src[srcOffset + ', arg.index, ']))');
  9691. },
  9692. visitVariable: function (variable) {
  9693. this.parts.push('v', variable.index);
  9694. },
  9695. visitLiteral: function (literal) {
  9696. this.parts.push(literal.number);
  9697. },
  9698. visitBinaryOperation: function (operation) {
  9699. this.parts.push('(');
  9700. operation.arg1.visit(this);
  9701. this.parts.push(' ', operation.op, ' ');
  9702. operation.arg2.visit(this);
  9703. this.parts.push(')');
  9704. },
  9705. visitVariableDefinition: function (definition) {
  9706. this.parts.push('var ');
  9707. definition.variable.visit(this);
  9708. this.parts.push(' = ');
  9709. definition.arg.visit(this);
  9710. this.parts.push(';');
  9711. },
  9712. visitMin: function (max) {
  9713. this.parts.push('Math.min(');
  9714. max.arg.visit(this);
  9715. this.parts.push(', ', max.max, ')');
  9716. },
  9717. toString: function () {
  9718. return this.parts.join('');
  9719. }
  9720. };
  9721. function buildAddOperation(num1, num2) {
  9722. if (num2.type === 'literal' && num2.number === 0) {
  9723. // optimization: second operand is 0
  9724. return num1;
  9725. }
  9726. if (num1.type === 'literal' && num1.number === 0) {
  9727. // optimization: first operand is 0
  9728. return num2;
  9729. }
  9730. if (num2.type === 'literal' && num1.type === 'literal') {
  9731. // optimization: operands operand are literals
  9732. return new AstLiteral(num1.number + num2.number);
  9733. }
  9734. return new AstBinaryOperation('+', num1, num2,
  9735. num1.min + num2.min, num1.max + num2.max);
  9736. }
  9737. function buildMulOperation(num1, num2) {
  9738. if (num2.type === 'literal') {
  9739. // optimization: second operands is a literal...
  9740. if (num2.number === 0) {
  9741. return new AstLiteral(0); // and it's 0
  9742. } else if (num2.number === 1) {
  9743. return num1; // and it's 1
  9744. } else if (num1.type === 'literal') {
  9745. // ... and first operands is a literal too
  9746. return new AstLiteral(num1.number * num2.number);
  9747. }
  9748. }
  9749. if (num1.type === 'literal') {
  9750. // optimization: first operands is a literal...
  9751. if (num1.number === 0) {
  9752. return new AstLiteral(0); // and it's 0
  9753. } else if (num1.number === 1) {
  9754. return num2; // and it's 1
  9755. }
  9756. }
  9757. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  9758. num1.max * num2.min, num1.max * num2.max);
  9759. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  9760. num1.max * num2.min, num1.max * num2.max);
  9761. return new AstBinaryOperation('*', num1, num2, min, max);
  9762. }
  9763. function buildSubOperation(num1, num2) {
  9764. if (num2.type === 'literal') {
  9765. // optimization: second operands is a literal...
  9766. if (num2.number === 0) {
  9767. return num1; // ... and it's 0
  9768. } else if (num1.type === 'literal') {
  9769. // ... and first operands is a literal too
  9770. return new AstLiteral(num1.number - num2.number);
  9771. }
  9772. }
  9773. if (num2.type === 'binary' && num2.op === '-' &&
  9774. num1.type === 'literal' && num1.number === 1 &&
  9775. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  9776. // optimization for case: 1 - (1 - x)
  9777. return num2.arg2;
  9778. }
  9779. return new AstBinaryOperation('-', num1, num2,
  9780. num1.min - num2.max, num1.max - num2.min);
  9781. }
  9782. function buildMinOperation(num1, max) {
  9783. if (num1.min >= max) {
  9784. // optimization: num1 min value is not less than required max
  9785. return new AstLiteral(max); // just returning max
  9786. } else if (num1.max <= max) {
  9787. // optimization: num1 max value is not greater than required max
  9788. return num1; // just returning an argument
  9789. }
  9790. return new AstMin(num1, max);
  9791. }
  9792. function PostScriptCompiler() {}
  9793. PostScriptCompiler.prototype = {
  9794. compile: function PostScriptCompiler_compile(code, domain, range) {
  9795. var stack = [];
  9796. var i, ii;
  9797. var instructions = [];
  9798. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  9799. var lastRegister = 0;
  9800. var n, j, min, max;
  9801. var num1, num2, ast1, ast2, tmpVar, item;
  9802. for (i = 0; i < inputSize; i++) {
  9803. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  9804. }
  9805. for (i = 0, ii = code.length; i < ii; i++) {
  9806. item = code[i];
  9807. if (typeof item === 'number') {
  9808. stack.push(new AstLiteral(item));
  9809. continue;
  9810. }
  9811. switch (item) {
  9812. case 'add':
  9813. if (stack.length < 2) {
  9814. return null;
  9815. }
  9816. num2 = stack.pop();
  9817. num1 = stack.pop();
  9818. stack.push(buildAddOperation(num1, num2));
  9819. break;
  9820. case 'cvr':
  9821. if (stack.length < 1) {
  9822. return null;
  9823. }
  9824. break;
  9825. case 'mul':
  9826. if (stack.length < 2) {
  9827. return null;
  9828. }
  9829. num2 = stack.pop();
  9830. num1 = stack.pop();
  9831. stack.push(buildMulOperation(num1, num2));
  9832. break;
  9833. case 'sub':
  9834. if (stack.length < 2) {
  9835. return null;
  9836. }
  9837. num2 = stack.pop();
  9838. num1 = stack.pop();
  9839. stack.push(buildSubOperation(num1, num2));
  9840. break;
  9841. case 'exch':
  9842. if (stack.length < 2) {
  9843. return null;
  9844. }
  9845. ast1 = stack.pop(); ast2 = stack.pop();
  9846. stack.push(ast1, ast2);
  9847. break;
  9848. case 'pop':
  9849. if (stack.length < 1) {
  9850. return null;
  9851. }
  9852. stack.pop();
  9853. break;
  9854. case 'index':
  9855. if (stack.length < 1) {
  9856. return null;
  9857. }
  9858. num1 = stack.pop();
  9859. if (num1.type !== 'literal') {
  9860. return null;
  9861. }
  9862. n = num1.number;
  9863. if (n < 0 || (n|0) !== n || stack.length < n) {
  9864. return null;
  9865. }
  9866. ast1 = stack[stack.length - n - 1];
  9867. if (ast1.type === 'literal' || ast1.type === 'var') {
  9868. stack.push(ast1);
  9869. break;
  9870. }
  9871. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  9872. stack[stack.length - n - 1] = tmpVar;
  9873. stack.push(tmpVar);
  9874. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  9875. break;
  9876. case 'dup':
  9877. if (stack.length < 1) {
  9878. return null;
  9879. }
  9880. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  9881. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  9882. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  9883. // special case of the commands sequence for the min operation
  9884. num1 = stack.pop();
  9885. stack.push(buildMinOperation(num1, code[i + 1]));
  9886. i += 6;
  9887. break;
  9888. }
  9889. ast1 = stack[stack.length - 1];
  9890. if (ast1.type === 'literal' || ast1.type === 'var') {
  9891. // we don't have to save into intermediate variable a literal or
  9892. // variable.
  9893. stack.push(ast1);
  9894. break;
  9895. }
  9896. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  9897. stack[stack.length - 1] = tmpVar;
  9898. stack.push(tmpVar);
  9899. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  9900. break;
  9901. case 'roll':
  9902. if (stack.length < 2) {
  9903. return null;
  9904. }
  9905. num2 = stack.pop();
  9906. num1 = stack.pop();
  9907. if (num2.type !== 'literal' || num1.type !== 'literal') {
  9908. // both roll operands must be numbers
  9909. return null;
  9910. }
  9911. j = num2.number;
  9912. n = num1.number;
  9913. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  9914. // ... and integers
  9915. return null;
  9916. }
  9917. j = ((j % n) + n) % n;
  9918. if (j === 0) {
  9919. break; // just skipping -- there are nothing to rotate
  9920. }
  9921. Array.prototype.push.apply(stack,
  9922. stack.splice(stack.length - n, n - j));
  9923. break;
  9924. default:
  9925. return null; // unsupported operator
  9926. }
  9927. }
  9928. if (stack.length !== outputSize) {
  9929. return null;
  9930. }
  9931. var result = [];
  9932. instructions.forEach(function (instruction) {
  9933. var statementBuilder = new ExpressionBuilderVisitor();
  9934. instruction.visit(statementBuilder);
  9935. result.push(statementBuilder.toString());
  9936. });
  9937. stack.forEach(function (expr, i) {
  9938. var statementBuilder = new ExpressionBuilderVisitor();
  9939. expr.visit(statementBuilder);
  9940. var min = range[i * 2], max = range[i * 2 + 1];
  9941. var out = [statementBuilder.toString()];
  9942. if (min > expr.min) {
  9943. out.unshift('Math.max(', min, ', ');
  9944. out.push(')');
  9945. }
  9946. if (max < expr.max) {
  9947. out.unshift('Math.min(', max, ', ');
  9948. out.push(')');
  9949. }
  9950. out.unshift('dest[destOffset + ', i, '] = ');
  9951. out.push(';');
  9952. result.push(out.join(''));
  9953. });
  9954. return result.join('\n');
  9955. }
  9956. };
  9957. return PostScriptCompiler;
  9958. })();
  9959. var ColorSpace = (function ColorSpaceClosure() {
  9960. // Constructor should define this.numComps, this.defaultColor, this.name
  9961. function ColorSpace() {
  9962. error('should not call ColorSpace constructor');
  9963. }
  9964. ColorSpace.prototype = {
  9965. /**
  9966. * Converts the color value to the RGB color. The color components are
  9967. * located in the src array starting from the srcOffset. Returns the array
  9968. * of the rgb components, each value ranging from [0,255].
  9969. */
  9970. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  9971. var rgb = new Uint8Array(3);
  9972. this.getRgbItem(src, srcOffset, rgb, 0);
  9973. return rgb;
  9974. },
  9975. /**
  9976. * Converts the color value to the RGB color, similar to the getRgb method.
  9977. * The result placed into the dest array starting from the destOffset.
  9978. */
  9979. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  9980. dest, destOffset) {
  9981. error('Should not call ColorSpace.getRgbItem');
  9982. },
  9983. /**
  9984. * Converts the specified number of the color values to the RGB colors.
  9985. * The colors are located in the src array starting from the srcOffset.
  9986. * The result is placed into the dest array starting from the destOffset.
  9987. * The src array items shall be in [0,2^bits) range, the dest array items
  9988. * will be in [0,255] range. alpha01 indicates how many alpha components
  9989. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  9990. * array).
  9991. */
  9992. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  9993. dest, destOffset, bits,
  9994. alpha01) {
  9995. error('Should not call ColorSpace.getRgbBuffer');
  9996. },
  9997. /**
  9998. * Determines the number of bytes required to store the result of the
  9999. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  10000. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  10001. */
  10002. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  10003. alpha01) {
  10004. error('Should not call ColorSpace.getOutputLength');
  10005. },
  10006. /**
  10007. * Returns true if source data will be equal the result/output data.
  10008. */
  10009. isPassthrough: function ColorSpace_isPassthrough(bits) {
  10010. return false;
  10011. },
  10012. /**
  10013. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  10014. * how many alpha components there are in the dest array; it will be either
  10015. * 0 (RGB array) or 1 (RGBA array).
  10016. */
  10017. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  10018. originalHeight, width, height,
  10019. actualHeight, bpc, comps, alpha01) {
  10020. var count = originalWidth * originalHeight;
  10021. var rgbBuf = null;
  10022. var numComponentColors = 1 << bpc;
  10023. var needsResizing = originalHeight !== height || originalWidth !== width;
  10024. var i, ii;
  10025. if (this.isPassthrough(bpc)) {
  10026. rgbBuf = comps;
  10027. } else if (this.numComps === 1 && count > numComponentColors &&
  10028. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  10029. // Optimization: create a color map when there is just one component and
  10030. // we are converting more colors than the size of the color map. We
  10031. // don't build the map if the colorspace is gray or rgb since those
  10032. // methods are faster than building a map. This mainly offers big speed
  10033. // ups for indexed and alternate colorspaces.
  10034. //
  10035. // TODO it may be worth while to cache the color map. While running
  10036. // testing I never hit a cache so I will leave that out for now (perhaps
  10037. // we are reparsing colorspaces too much?).
  10038. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  10039. new Uint16Array(numComponentColors);
  10040. var key;
  10041. for (i = 0; i < numComponentColors; i++) {
  10042. allColors[i] = i;
  10043. }
  10044. var colorMap = new Uint8Array(numComponentColors * 3);
  10045. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  10046. /* alpha01 = */ 0);
  10047. var destPos, rgbPos;
  10048. if (!needsResizing) {
  10049. // Fill in the RGB values directly into |dest|.
  10050. destPos = 0;
  10051. for (i = 0; i < count; ++i) {
  10052. key = comps[i] * 3;
  10053. dest[destPos++] = colorMap[key];
  10054. dest[destPos++] = colorMap[key + 1];
  10055. dest[destPos++] = colorMap[key + 2];
  10056. destPos += alpha01;
  10057. }
  10058. } else {
  10059. rgbBuf = new Uint8Array(count * 3);
  10060. rgbPos = 0;
  10061. for (i = 0; i < count; ++i) {
  10062. key = comps[i] * 3;
  10063. rgbBuf[rgbPos++] = colorMap[key];
  10064. rgbBuf[rgbPos++] = colorMap[key + 1];
  10065. rgbBuf[rgbPos++] = colorMap[key + 2];
  10066. }
  10067. }
  10068. } else {
  10069. if (!needsResizing) {
  10070. // Fill in the RGB values directly into |dest|.
  10071. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  10072. alpha01);
  10073. } else {
  10074. rgbBuf = new Uint8Array(count * 3);
  10075. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  10076. /* alpha01 = */ 0);
  10077. }
  10078. }
  10079. if (rgbBuf) {
  10080. if (needsResizing) {
  10081. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  10082. height, dest, alpha01);
  10083. } else {
  10084. rgbPos = 0;
  10085. destPos = 0;
  10086. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  10087. dest[destPos++] = rgbBuf[rgbPos++];
  10088. dest[destPos++] = rgbBuf[rgbPos++];
  10089. dest[destPos++] = rgbBuf[rgbPos++];
  10090. destPos += alpha01;
  10091. }
  10092. }
  10093. }
  10094. },
  10095. /**
  10096. * True if the colorspace has components in the default range of [0, 1].
  10097. * This should be true for all colorspaces except for lab color spaces
  10098. * which are [0,100], [-128, 127], [-128, 127].
  10099. */
  10100. usesZeroToOneRange: true
  10101. };
  10102. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  10103. var IR = ColorSpace.parseToIR(cs, xref, res);
  10104. if (IR instanceof AlternateCS) {
  10105. return IR;
  10106. }
  10107. return ColorSpace.fromIR(IR);
  10108. };
  10109. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  10110. var name = isArray(IR) ? IR[0] : IR;
  10111. var whitePoint, blackPoint;
  10112. switch (name) {
  10113. case 'DeviceGrayCS':
  10114. return this.singletons.gray;
  10115. case 'DeviceRgbCS':
  10116. return this.singletons.rgb;
  10117. case 'DeviceCmykCS':
  10118. return this.singletons.cmyk;
  10119. case 'CalGrayCS':
  10120. whitePoint = IR[1].WhitePoint;
  10121. blackPoint = IR[1].BlackPoint;
  10122. var gamma = IR[1].Gamma;
  10123. return new CalGrayCS(whitePoint, blackPoint, gamma);
  10124. case 'PatternCS':
  10125. var basePatternCS = IR[1];
  10126. if (basePatternCS) {
  10127. basePatternCS = ColorSpace.fromIR(basePatternCS);
  10128. }
  10129. return new PatternCS(basePatternCS);
  10130. case 'IndexedCS':
  10131. var baseIndexedCS = IR[1];
  10132. var hiVal = IR[2];
  10133. var lookup = IR[3];
  10134. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  10135. case 'AlternateCS':
  10136. var numComps = IR[1];
  10137. var alt = IR[2];
  10138. var tintFnIR = IR[3];
  10139. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  10140. PDFFunction.fromIR(tintFnIR));
  10141. case 'LabCS':
  10142. whitePoint = IR[1].WhitePoint;
  10143. blackPoint = IR[1].BlackPoint;
  10144. var range = IR[1].Range;
  10145. return new LabCS(whitePoint, blackPoint, range);
  10146. default:
  10147. error('Unkown name ' + name);
  10148. }
  10149. return null;
  10150. };
  10151. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  10152. if (isName(cs)) {
  10153. var colorSpaces = res.get('ColorSpace');
  10154. if (isDict(colorSpaces)) {
  10155. var refcs = colorSpaces.get(cs.name);
  10156. if (refcs) {
  10157. cs = refcs;
  10158. }
  10159. }
  10160. }
  10161. cs = xref.fetchIfRef(cs);
  10162. var mode;
  10163. if (isName(cs)) {
  10164. mode = cs.name;
  10165. this.mode = mode;
  10166. switch (mode) {
  10167. case 'DeviceGray':
  10168. case 'G':
  10169. return 'DeviceGrayCS';
  10170. case 'DeviceRGB':
  10171. case 'RGB':
  10172. return 'DeviceRgbCS';
  10173. case 'DeviceCMYK':
  10174. case 'CMYK':
  10175. return 'DeviceCmykCS';
  10176. case 'Pattern':
  10177. return ['PatternCS', null];
  10178. default:
  10179. error('unrecognized colorspace ' + mode);
  10180. }
  10181. } else if (isArray(cs)) {
  10182. mode = cs[0].name;
  10183. this.mode = mode;
  10184. var numComps, params;
  10185. switch (mode) {
  10186. case 'DeviceGray':
  10187. case 'G':
  10188. return 'DeviceGrayCS';
  10189. case 'DeviceRGB':
  10190. case 'RGB':
  10191. return 'DeviceRgbCS';
  10192. case 'DeviceCMYK':
  10193. case 'CMYK':
  10194. return 'DeviceCmykCS';
  10195. case 'CalGray':
  10196. params = cs[1].getAll();
  10197. return ['CalGrayCS', params];
  10198. case 'CalRGB':
  10199. return 'DeviceRgbCS';
  10200. case 'ICCBased':
  10201. var stream = xref.fetchIfRef(cs[1]);
  10202. var dict = stream.dict;
  10203. numComps = dict.get('N');
  10204. if (numComps === 1) {
  10205. return 'DeviceGrayCS';
  10206. } else if (numComps === 3) {
  10207. return 'DeviceRgbCS';
  10208. } else if (numComps === 4) {
  10209. return 'DeviceCmykCS';
  10210. }
  10211. break;
  10212. case 'Pattern':
  10213. var basePatternCS = cs[1];
  10214. if (basePatternCS) {
  10215. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  10216. }
  10217. return ['PatternCS', basePatternCS];
  10218. case 'Indexed':
  10219. case 'I':
  10220. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  10221. var hiVal = cs[2] + 1;
  10222. var lookup = xref.fetchIfRef(cs[3]);
  10223. if (isStream(lookup)) {
  10224. lookup = lookup.getBytes();
  10225. }
  10226. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  10227. case 'Separation':
  10228. case 'DeviceN':
  10229. var name = cs[1];
  10230. numComps = 1;
  10231. if (isName(name)) {
  10232. numComps = 1;
  10233. } else if (isArray(name)) {
  10234. numComps = name.length;
  10235. }
  10236. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  10237. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  10238. return ['AlternateCS', numComps, alt, tintFnIR];
  10239. case 'Lab':
  10240. params = cs[1].getAll();
  10241. return ['LabCS', params];
  10242. default:
  10243. error('unimplemented color space object "' + mode + '"');
  10244. }
  10245. } else {
  10246. error('unrecognized color space object: "' + cs + '"');
  10247. }
  10248. return null;
  10249. };
  10250. /**
  10251. * Checks if a decode map matches the default decode map for a color space.
  10252. * This handles the general decode maps where there are two values per
  10253. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  10254. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  10255. * slightly different.
  10256. * @param {Array} decode Decode map (usually from an image).
  10257. * @param {Number} n Number of components the color space has.
  10258. */
  10259. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  10260. if (!decode) {
  10261. return true;
  10262. }
  10263. if (n * 2 !== decode.length) {
  10264. warn('The decode map is not the correct length');
  10265. return true;
  10266. }
  10267. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  10268. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  10269. return false;
  10270. }
  10271. }
  10272. return true;
  10273. };
  10274. ColorSpace.singletons = {
  10275. get gray() {
  10276. return shadow(this, 'gray', new DeviceGrayCS());
  10277. },
  10278. get rgb() {
  10279. return shadow(this, 'rgb', new DeviceRgbCS());
  10280. },
  10281. get cmyk() {
  10282. return shadow(this, 'cmyk', new DeviceCmykCS());
  10283. }
  10284. };
  10285. return ColorSpace;
  10286. })();
  10287. /**
  10288. * Alternate color space handles both Separation and DeviceN color spaces. A
  10289. * Separation color space is actually just a DeviceN with one color component.
  10290. * Both color spaces use a tinting function to convert colors to a base color
  10291. * space.
  10292. */
  10293. var AlternateCS = (function AlternateCSClosure() {
  10294. function AlternateCS(numComps, base, tintFn) {
  10295. this.name = 'Alternate';
  10296. this.numComps = numComps;
  10297. this.defaultColor = new Float32Array(numComps);
  10298. for (var i = 0; i < numComps; ++i) {
  10299. this.defaultColor[i] = 1;
  10300. }
  10301. this.base = base;
  10302. this.tintFn = tintFn;
  10303. this.tmpBuf = new Float32Array(base.numComps);
  10304. }
  10305. AlternateCS.prototype = {
  10306. getRgb: ColorSpace.prototype.getRgb,
  10307. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  10308. dest, destOffset) {
  10309. var tmpBuf = this.tmpBuf;
  10310. this.tintFn(src, srcOffset, tmpBuf, 0);
  10311. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  10312. },
  10313. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  10314. dest, destOffset, bits,
  10315. alpha01) {
  10316. var tintFn = this.tintFn;
  10317. var base = this.base;
  10318. var scale = 1 / ((1 << bits) - 1);
  10319. var baseNumComps = base.numComps;
  10320. var usesZeroToOneRange = base.usesZeroToOneRange;
  10321. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  10322. alpha01 === 0;
  10323. var pos = isPassthrough ? destOffset : 0;
  10324. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  10325. var numComps = this.numComps;
  10326. var scaled = new Float32Array(numComps);
  10327. var tinted = new Float32Array(baseNumComps);
  10328. var i, j;
  10329. if (usesZeroToOneRange) {
  10330. for (i = 0; i < count; i++) {
  10331. for (j = 0; j < numComps; j++) {
  10332. scaled[j] = src[srcOffset++] * scale;
  10333. }
  10334. tintFn(scaled, 0, tinted, 0);
  10335. for (j = 0; j < baseNumComps; j++) {
  10336. baseBuf[pos++] = tinted[j] * 255;
  10337. }
  10338. }
  10339. } else {
  10340. for (i = 0; i < count; i++) {
  10341. for (j = 0; j < numComps; j++) {
  10342. scaled[j] = src[srcOffset++] * scale;
  10343. }
  10344. tintFn(scaled, 0, tinted, 0);
  10345. base.getRgbItem(tinted, 0, baseBuf, pos);
  10346. pos += baseNumComps;
  10347. }
  10348. }
  10349. if (!isPassthrough) {
  10350. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  10351. }
  10352. },
  10353. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  10354. alpha01) {
  10355. return this.base.getOutputLength(inputLength *
  10356. this.base.numComps / this.numComps,
  10357. alpha01);
  10358. },
  10359. isPassthrough: ColorSpace.prototype.isPassthrough,
  10360. fillRgb: ColorSpace.prototype.fillRgb,
  10361. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  10362. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10363. },
  10364. usesZeroToOneRange: true
  10365. };
  10366. return AlternateCS;
  10367. })();
  10368. var PatternCS = (function PatternCSClosure() {
  10369. function PatternCS(baseCS) {
  10370. this.name = 'Pattern';
  10371. this.base = baseCS;
  10372. }
  10373. PatternCS.prototype = {};
  10374. return PatternCS;
  10375. })();
  10376. var IndexedCS = (function IndexedCSClosure() {
  10377. function IndexedCS(base, highVal, lookup) {
  10378. this.name = 'Indexed';
  10379. this.numComps = 1;
  10380. this.defaultColor = new Uint8Array([0]);
  10381. this.base = base;
  10382. this.highVal = highVal;
  10383. var baseNumComps = base.numComps;
  10384. var length = baseNumComps * highVal;
  10385. var lookupArray;
  10386. if (isStream(lookup)) {
  10387. lookupArray = new Uint8Array(length);
  10388. var bytes = lookup.getBytes(length);
  10389. lookupArray.set(bytes);
  10390. } else if (isString(lookup)) {
  10391. lookupArray = new Uint8Array(length);
  10392. for (var i = 0; i < length; ++i) {
  10393. lookupArray[i] = lookup.charCodeAt(i);
  10394. }
  10395. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  10396. lookupArray = lookup;
  10397. } else {
  10398. error('Unrecognized lookup table: ' + lookup);
  10399. }
  10400. this.lookup = lookupArray;
  10401. }
  10402. IndexedCS.prototype = {
  10403. getRgb: ColorSpace.prototype.getRgb,
  10404. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  10405. dest, destOffset) {
  10406. var numComps = this.base.numComps;
  10407. var start = src[srcOffset] * numComps;
  10408. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  10409. },
  10410. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  10411. dest, destOffset, bits,
  10412. alpha01) {
  10413. var base = this.base;
  10414. var numComps = base.numComps;
  10415. var outputDelta = base.getOutputLength(numComps, alpha01);
  10416. var lookup = this.lookup;
  10417. for (var i = 0; i < count; ++i) {
  10418. var lookupPos = src[srcOffset++] * numComps;
  10419. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  10420. destOffset += outputDelta;
  10421. }
  10422. },
  10423. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  10424. return this.base.getOutputLength(inputLength * this.base.numComps,
  10425. alpha01);
  10426. },
  10427. isPassthrough: ColorSpace.prototype.isPassthrough,
  10428. fillRgb: ColorSpace.prototype.fillRgb,
  10429. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  10430. // indexed color maps shouldn't be changed
  10431. return true;
  10432. },
  10433. usesZeroToOneRange: true
  10434. };
  10435. return IndexedCS;
  10436. })();
  10437. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  10438. function DeviceGrayCS() {
  10439. this.name = 'DeviceGray';
  10440. this.numComps = 1;
  10441. this.defaultColor = new Float32Array([0]);
  10442. }
  10443. DeviceGrayCS.prototype = {
  10444. getRgb: ColorSpace.prototype.getRgb,
  10445. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  10446. dest, destOffset) {
  10447. var c = (src[srcOffset] * 255) | 0;
  10448. c = c < 0 ? 0 : c > 255 ? 255 : c;
  10449. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  10450. },
  10451. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  10452. dest, destOffset, bits,
  10453. alpha01) {
  10454. var scale = 255 / ((1 << bits) - 1);
  10455. var j = srcOffset, q = destOffset;
  10456. for (var i = 0; i < count; ++i) {
  10457. var c = (scale * src[j++]) | 0;
  10458. dest[q++] = c;
  10459. dest[q++] = c;
  10460. dest[q++] = c;
  10461. q += alpha01;
  10462. }
  10463. },
  10464. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  10465. alpha01) {
  10466. return inputLength * (3 + alpha01);
  10467. },
  10468. isPassthrough: ColorSpace.prototype.isPassthrough,
  10469. fillRgb: ColorSpace.prototype.fillRgb,
  10470. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  10471. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10472. },
  10473. usesZeroToOneRange: true
  10474. };
  10475. return DeviceGrayCS;
  10476. })();
  10477. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  10478. function DeviceRgbCS() {
  10479. this.name = 'DeviceRGB';
  10480. this.numComps = 3;
  10481. this.defaultColor = new Float32Array([0, 0, 0]);
  10482. }
  10483. DeviceRgbCS.prototype = {
  10484. getRgb: ColorSpace.prototype.getRgb,
  10485. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  10486. dest, destOffset) {
  10487. var r = (src[srcOffset] * 255) | 0;
  10488. var g = (src[srcOffset + 1] * 255) | 0;
  10489. var b = (src[srcOffset + 2] * 255) | 0;
  10490. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  10491. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  10492. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  10493. },
  10494. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  10495. dest, destOffset, bits,
  10496. alpha01) {
  10497. if (bits === 8 && alpha01 === 0) {
  10498. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  10499. return;
  10500. }
  10501. var scale = 255 / ((1 << bits) - 1);
  10502. var j = srcOffset, q = destOffset;
  10503. for (var i = 0; i < count; ++i) {
  10504. dest[q++] = (scale * src[j++]) | 0;
  10505. dest[q++] = (scale * src[j++]) | 0;
  10506. dest[q++] = (scale * src[j++]) | 0;
  10507. q += alpha01;
  10508. }
  10509. },
  10510. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  10511. alpha01) {
  10512. return (inputLength * (3 + alpha01) / 3) | 0;
  10513. },
  10514. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  10515. return bits === 8;
  10516. },
  10517. fillRgb: ColorSpace.prototype.fillRgb,
  10518. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  10519. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10520. },
  10521. usesZeroToOneRange: true
  10522. };
  10523. return DeviceRgbCS;
  10524. })();
  10525. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  10526. // The coefficients below was found using numerical analysis: the method of
  10527. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  10528. // where color_value is the tabular value from the table of sampled RGB colors
  10529. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  10530. // CMYK color conversion using the estimation below:
  10531. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  10532. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  10533. var c = src[srcOffset + 0] * srcScale;
  10534. var m = src[srcOffset + 1] * srcScale;
  10535. var y = src[srcOffset + 2] * srcScale;
  10536. var k = src[srcOffset + 3] * srcScale;
  10537. var r =
  10538. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  10539. 18.82290502165302 * y + 212.25662451639585 * k +
  10540. -285.2331026137004) +
  10541. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  10542. -17.873870861415444 * k - 5.497006427196366) +
  10543. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  10544. 17.5119270841813) +
  10545. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  10546. var g =
  10547. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  10548. 6.871425592049007 * y + 31.159100130055922 * k +
  10549. -79.2970844816548) +
  10550. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  10551. 131.35250912493976 * k - 190.9453302588951) +
  10552. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  10553. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  10554. var b =
  10555. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  10556. 30.89978309703729 * y - 0.23883238689178934 * k +
  10557. -14.183576799673286) +
  10558. m * (10.49593273432072 * m + 63.02378494754052 * y +
  10559. 50.606957656360734 * k - 112.23884253719248) +
  10560. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  10561. -193.58209356861505) +
  10562. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  10563. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  10564. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  10565. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  10566. }
  10567. function DeviceCmykCS() {
  10568. this.name = 'DeviceCMYK';
  10569. this.numComps = 4;
  10570. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  10571. }
  10572. DeviceCmykCS.prototype = {
  10573. getRgb: ColorSpace.prototype.getRgb,
  10574. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  10575. dest, destOffset) {
  10576. convertToRgb(src, srcOffset, 1, dest, destOffset);
  10577. },
  10578. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  10579. dest, destOffset, bits,
  10580. alpha01) {
  10581. var scale = 1 / ((1 << bits) - 1);
  10582. for (var i = 0; i < count; i++) {
  10583. convertToRgb(src, srcOffset, scale, dest, destOffset);
  10584. srcOffset += 4;
  10585. destOffset += 3 + alpha01;
  10586. }
  10587. },
  10588. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  10589. alpha01) {
  10590. return (inputLength / 4 * (3 + alpha01)) | 0;
  10591. },
  10592. isPassthrough: ColorSpace.prototype.isPassthrough,
  10593. fillRgb: ColorSpace.prototype.fillRgb,
  10594. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  10595. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10596. },
  10597. usesZeroToOneRange: true
  10598. };
  10599. return DeviceCmykCS;
  10600. })();
  10601. //
  10602. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  10603. //
  10604. var CalGrayCS = (function CalGrayCSClosure() {
  10605. function CalGrayCS(whitePoint, blackPoint, gamma) {
  10606. this.name = 'CalGray';
  10607. this.numComps = 1;
  10608. this.defaultColor = new Float32Array([0]);
  10609. if (!whitePoint) {
  10610. error('WhitePoint missing - required for color space CalGray');
  10611. }
  10612. blackPoint = blackPoint || [0, 0, 0];
  10613. gamma = gamma || 1;
  10614. // Translate arguments to spec variables.
  10615. this.XW = whitePoint[0];
  10616. this.YW = whitePoint[1];
  10617. this.ZW = whitePoint[2];
  10618. this.XB = blackPoint[0];
  10619. this.YB = blackPoint[1];
  10620. this.ZB = blackPoint[2];
  10621. this.G = gamma;
  10622. // Validate variables as per spec.
  10623. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  10624. error('Invalid WhitePoint components for ' + this.name +
  10625. ', no fallback available');
  10626. }
  10627. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  10628. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  10629. this.XB = this.YB = this.ZB = 0;
  10630. }
  10631. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  10632. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  10633. ', ZB: ' + this.ZB + ', only default values are supported.');
  10634. }
  10635. if (this.G < 1) {
  10636. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  10637. ', falling back to default');
  10638. this.G = 1;
  10639. }
  10640. }
  10641. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  10642. // A represents a gray component of a calibrated gray space.
  10643. // A <---> AG in the spec
  10644. var A = src[srcOffset] * scale;
  10645. var AG = Math.pow(A, cs.G);
  10646. // Computes L as per spec. ( = cs.YW * AG )
  10647. // Except if other than default BlackPoint values are used.
  10648. var L = cs.YW * AG;
  10649. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  10650. // Convert values to rgb range [0, 255].
  10651. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  10652. dest[destOffset] = val;
  10653. dest[destOffset + 1] = val;
  10654. dest[destOffset + 2] = val;
  10655. }
  10656. CalGrayCS.prototype = {
  10657. getRgb: ColorSpace.prototype.getRgb,
  10658. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  10659. dest, destOffset) {
  10660. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  10661. },
  10662. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  10663. dest, destOffset, bits,
  10664. alpha01) {
  10665. var scale = 1 / ((1 << bits) - 1);
  10666. for (var i = 0; i < count; ++i) {
  10667. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  10668. srcOffset += 1;
  10669. destOffset += 3 + alpha01;
  10670. }
  10671. },
  10672. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  10673. return inputLength * (3 + alpha01);
  10674. },
  10675. isPassthrough: ColorSpace.prototype.isPassthrough,
  10676. fillRgb: ColorSpace.prototype.fillRgb,
  10677. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  10678. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  10679. },
  10680. usesZeroToOneRange: true
  10681. };
  10682. return CalGrayCS;
  10683. })();
  10684. //
  10685. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  10686. //
  10687. var LabCS = (function LabCSClosure() {
  10688. function LabCS(whitePoint, blackPoint, range) {
  10689. this.name = 'Lab';
  10690. this.numComps = 3;
  10691. this.defaultColor = new Float32Array([0, 0, 0]);
  10692. if (!whitePoint) {
  10693. error('WhitePoint missing - required for color space Lab');
  10694. }
  10695. blackPoint = blackPoint || [0, 0, 0];
  10696. range = range || [-100, 100, -100, 100];
  10697. // Translate args to spec variables
  10698. this.XW = whitePoint[0];
  10699. this.YW = whitePoint[1];
  10700. this.ZW = whitePoint[2];
  10701. this.amin = range[0];
  10702. this.amax = range[1];
  10703. this.bmin = range[2];
  10704. this.bmax = range[3];
  10705. // These are here just for completeness - the spec doesn't offer any
  10706. // formulas that use BlackPoint in Lab
  10707. this.XB = blackPoint[0];
  10708. this.YB = blackPoint[1];
  10709. this.ZB = blackPoint[2];
  10710. // Validate vars as per spec
  10711. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  10712. error('Invalid WhitePoint components, no fallback available');
  10713. }
  10714. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  10715. info('Invalid BlackPoint, falling back to default');
  10716. this.XB = this.YB = this.ZB = 0;
  10717. }
  10718. if (this.amin > this.amax || this.bmin > this.bmax) {
  10719. info('Invalid Range, falling back to defaults');
  10720. this.amin = -100;
  10721. this.amax = 100;
  10722. this.bmin = -100;
  10723. this.bmax = 100;
  10724. }
  10725. }
  10726. // Function g(x) from spec
  10727. function fn_g(x) {
  10728. if (x >= 6 / 29) {
  10729. return x * x * x;
  10730. } else {
  10731. return (108 / 841) * (x - 4 / 29);
  10732. }
  10733. }
  10734. function decode(value, high1, low2, high2) {
  10735. return low2 + (value) * (high2 - low2) / (high1);
  10736. }
  10737. // If decoding is needed maxVal should be 2^bits per component - 1.
  10738. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  10739. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  10740. // not the usual [0, 1]. If a command like setFillColor is used the src
  10741. // values will already be within the correct range. However, if we are
  10742. // converting an image we have to map the values to the correct range given
  10743. // above.
  10744. // Ls,as,bs <---> L*,a*,b* in the spec
  10745. var Ls = src[srcOffset];
  10746. var as = src[srcOffset + 1];
  10747. var bs = src[srcOffset + 2];
  10748. if (maxVal !== false) {
  10749. Ls = decode(Ls, maxVal, 0, 100);
  10750. as = decode(as, maxVal, cs.amin, cs.amax);
  10751. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  10752. }
  10753. // Adjust limits of 'as' and 'bs'
  10754. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  10755. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  10756. // Computes intermediate variables X,Y,Z as per spec
  10757. var M = (Ls + 16) / 116;
  10758. var L = M + (as / 500);
  10759. var N = M - (bs / 200);
  10760. var X = cs.XW * fn_g(L);
  10761. var Y = cs.YW * fn_g(M);
  10762. var Z = cs.ZW * fn_g(N);
  10763. var r, g, b;
  10764. // Using different conversions for D50 and D65 white points,
  10765. // per http://www.color.org/srgb.pdf
  10766. if (cs.ZW < 1) {
  10767. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  10768. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  10769. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  10770. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  10771. } else {
  10772. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  10773. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  10774. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  10775. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  10776. }
  10777. // clamp color values to [0,1] range then convert to [0,255] range.
  10778. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  10779. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  10780. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  10781. }
  10782. LabCS.prototype = {
  10783. getRgb: ColorSpace.prototype.getRgb,
  10784. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  10785. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  10786. },
  10787. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  10788. dest, destOffset, bits,
  10789. alpha01) {
  10790. var maxVal = (1 << bits) - 1;
  10791. for (var i = 0; i < count; i++) {
  10792. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  10793. srcOffset += 3;
  10794. destOffset += 3 + alpha01;
  10795. }
  10796. },
  10797. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  10798. return (inputLength * (3 + alpha01) / 3) | 0;
  10799. },
  10800. isPassthrough: ColorSpace.prototype.isPassthrough,
  10801. fillRgb: ColorSpace.prototype.fillRgb,
  10802. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  10803. // XXX: Decoding is handled with the lab conversion because of the strange
  10804. // ranges that are used.
  10805. return true;
  10806. },
  10807. usesZeroToOneRange: false
  10808. };
  10809. return LabCS;
  10810. })();
  10811. var ARCFourCipher = (function ARCFourCipherClosure() {
  10812. function ARCFourCipher(key) {
  10813. this.a = 0;
  10814. this.b = 0;
  10815. var s = new Uint8Array(256);
  10816. var i, j = 0, tmp, keyLength = key.length;
  10817. for (i = 0; i < 256; ++i) {
  10818. s[i] = i;
  10819. }
  10820. for (i = 0; i < 256; ++i) {
  10821. tmp = s[i];
  10822. j = (j + tmp + key[i % keyLength]) & 0xFF;
  10823. s[i] = s[j];
  10824. s[j] = tmp;
  10825. }
  10826. this.s = s;
  10827. }
  10828. ARCFourCipher.prototype = {
  10829. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  10830. var i, n = data.length, tmp, tmp2;
  10831. var a = this.a, b = this.b, s = this.s;
  10832. var output = new Uint8Array(n);
  10833. for (i = 0; i < n; ++i) {
  10834. a = (a + 1) & 0xFF;
  10835. tmp = s[a];
  10836. b = (b + tmp) & 0xFF;
  10837. tmp2 = s[b];
  10838. s[a] = tmp2;
  10839. s[b] = tmp;
  10840. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  10841. }
  10842. this.a = a;
  10843. this.b = b;
  10844. return output;
  10845. }
  10846. };
  10847. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  10848. return ARCFourCipher;
  10849. })();
  10850. var calculateMD5 = (function calculateMD5Closure() {
  10851. var r = new Uint8Array([
  10852. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  10853. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  10854. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  10855. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  10856. var k = new Int32Array([
  10857. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  10858. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  10859. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  10860. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  10861. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  10862. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  10863. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  10864. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  10865. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  10866. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  10867. -145523070, -1120210379, 718787259, -343485551]);
  10868. function hash(data, offset, length) {
  10869. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  10870. // pre-processing
  10871. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  10872. var padded = new Uint8Array(paddedLength);
  10873. var i, j, n;
  10874. for (i = 0; i < length; ++i) {
  10875. padded[i] = data[offset++];
  10876. }
  10877. padded[i++] = 0x80;
  10878. n = paddedLength - 8;
  10879. while (i < n) {
  10880. padded[i++] = 0;
  10881. }
  10882. padded[i++] = (length << 3) & 0xFF;
  10883. padded[i++] = (length >> 5) & 0xFF;
  10884. padded[i++] = (length >> 13) & 0xFF;
  10885. padded[i++] = (length >> 21) & 0xFF;
  10886. padded[i++] = (length >>> 29) & 0xFF;
  10887. padded[i++] = 0;
  10888. padded[i++] = 0;
  10889. padded[i++] = 0;
  10890. var w = new Int32Array(16);
  10891. for (i = 0; i < paddedLength;) {
  10892. for (j = 0; j < 16; ++j, i += 4) {
  10893. w[j] = (padded[i] | (padded[i + 1] << 8) |
  10894. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  10895. }
  10896. var a = h0, b = h1, c = h2, d = h3, f, g;
  10897. for (j = 0; j < 64; ++j) {
  10898. if (j < 16) {
  10899. f = (b & c) | ((~b) & d);
  10900. g = j;
  10901. } else if (j < 32) {
  10902. f = (d & b) | ((~d) & c);
  10903. g = (5 * j + 1) & 15;
  10904. } else if (j < 48) {
  10905. f = b ^ c ^ d;
  10906. g = (3 * j + 5) & 15;
  10907. } else {
  10908. f = c ^ (b | (~d));
  10909. g = (7 * j) & 15;
  10910. }
  10911. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  10912. d = c;
  10913. c = b;
  10914. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  10915. a = tmp;
  10916. }
  10917. h0 = (h0 + a) | 0;
  10918. h1 = (h1 + b) | 0;
  10919. h2 = (h2 + c) | 0;
  10920. h3 = (h3 + d) | 0;
  10921. }
  10922. return new Uint8Array([
  10923. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  10924. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  10925. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  10926. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  10927. ]);
  10928. }
  10929. return hash;
  10930. })();
  10931. var Word64 = (function Word64Closure() {
  10932. function Word64(highInteger, lowInteger) {
  10933. this.high = highInteger | 0;
  10934. this.low = lowInteger | 0;
  10935. }
  10936. Word64.prototype = {
  10937. and: function Word64_and(word) {
  10938. this.high &= word.high;
  10939. this.low &= word.low;
  10940. },
  10941. xor: function Word64_xor(word) {
  10942. this.high ^= word.high;
  10943. this.low ^= word.low;
  10944. },
  10945. or: function Word64_or(word) {
  10946. this.high |= word.high;
  10947. this.low |= word.low;
  10948. },
  10949. shiftRight: function Word64_shiftRight(places) {
  10950. if (places >= 32) {
  10951. this.low = (this.high >>> (places - 32)) | 0;
  10952. this.high = 0;
  10953. } else {
  10954. this.low = (this.low >>> places) | (this.high << (32 - places));
  10955. this.high = (this.high >>> places) | 0;
  10956. }
  10957. },
  10958. shiftLeft: function Word64_shiftLeft(places) {
  10959. if (places >= 32) {
  10960. this.high = this.low << (places - 32);
  10961. this.low = 0;
  10962. } else {
  10963. this.high = (this.high << places) | (this.low >>> (32 - places));
  10964. this.low = this.low << places;
  10965. }
  10966. },
  10967. rotateRight: function Word64_rotateRight(places) {
  10968. var low, high;
  10969. if (places & 32) {
  10970. high = this.low;
  10971. low = this.high;
  10972. } else {
  10973. low = this.low;
  10974. high = this.high;
  10975. }
  10976. places &= 31;
  10977. this.low = (low >>> places) | (high << (32 - places));
  10978. this.high = (high >>> places) | (low << (32 - places));
  10979. },
  10980. not: function Word64_not() {
  10981. this.high = ~this.high;
  10982. this.low = ~this.low;
  10983. },
  10984. add: function Word64_add(word) {
  10985. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  10986. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  10987. if (lowAdd > 0xFFFFFFFF) {
  10988. highAdd += 1;
  10989. }
  10990. this.low = lowAdd | 0;
  10991. this.high = highAdd | 0;
  10992. },
  10993. copyTo: function Word64_copyTo(bytes, offset) {
  10994. bytes[offset] = (this.high >>> 24) & 0xFF;
  10995. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  10996. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  10997. bytes[offset + 3] = this.high & 0xFF;
  10998. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  10999. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  11000. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  11001. bytes[offset + 7] = this.low & 0xFF;
  11002. },
  11003. assign: function Word64_assign(word) {
  11004. this.high = word.high;
  11005. this.low = word.low;
  11006. }
  11007. };
  11008. return Word64;
  11009. })();
  11010. var calculateSHA256 = (function calculateSHA256Closure() {
  11011. function rotr(x, n) {
  11012. return (x >>> n) | (x << 32 - n);
  11013. }
  11014. function ch(x, y, z) {
  11015. return (x & y) ^ (~x & z);
  11016. }
  11017. function maj(x, y, z) {
  11018. return (x & y) ^ (x & z) ^ (y & z);
  11019. }
  11020. function sigma(x) {
  11021. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  11022. }
  11023. function sigmaPrime(x) {
  11024. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  11025. }
  11026. function littleSigma(x) {
  11027. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  11028. }
  11029. function littleSigmaPrime(x) {
  11030. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  11031. }
  11032. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  11033. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  11034. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  11035. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  11036. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  11037. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  11038. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  11039. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  11040. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  11041. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  11042. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  11043. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  11044. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  11045. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  11046. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  11047. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  11048. function hash(data, offset, length) {
  11049. // initial hash values
  11050. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  11051. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  11052. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  11053. // pre-processing
  11054. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  11055. var padded = new Uint8Array(paddedLength);
  11056. var i, j, n;
  11057. for (i = 0; i < length; ++i) {
  11058. padded[i] = data[offset++];
  11059. }
  11060. padded[i++] = 0x80;
  11061. n = paddedLength - 8;
  11062. while (i < n) {
  11063. padded[i++] = 0;
  11064. }
  11065. padded[i++] = 0;
  11066. padded[i++] = 0;
  11067. padded[i++] = 0;
  11068. padded[i++] = (length >>> 29) & 0xFF;
  11069. padded[i++] = (length >> 21) & 0xFF;
  11070. padded[i++] = (length >> 13) & 0xFF;
  11071. padded[i++] = (length >> 5) & 0xFF;
  11072. padded[i++] = (length << 3) & 0xFF;
  11073. var w = new Uint32Array(64);
  11074. // for each 512 bit block
  11075. for (i = 0; i < paddedLength;) {
  11076. for (j = 0; j < 16; ++j) {
  11077. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  11078. (padded[i + 2] << 8) | (padded[i + 3]));
  11079. i += 4;
  11080. }
  11081. for (j = 16; j < 64; ++j) {
  11082. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  11083. littleSigma(w[j - 15]) + w[j - 16] | 0;
  11084. }
  11085. var a = h0, b = h1, c = h2, d = h3, e = h4,
  11086. f = h5, g = h6, h = h7, t1, t2;
  11087. for (j = 0; j < 64; ++j) {
  11088. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  11089. t2 = sigma(a) + maj(a, b, c);
  11090. h = g;
  11091. g = f;
  11092. f = e;
  11093. e = (d + t1) | 0;
  11094. d = c;
  11095. c = b;
  11096. b = a;
  11097. a = (t1 + t2) | 0;
  11098. }
  11099. h0 = (h0 + a) | 0;
  11100. h1 = (h1 + b) | 0;
  11101. h2 = (h2 + c) | 0;
  11102. h3 = (h3 + d) | 0;
  11103. h4 = (h4 + e) | 0;
  11104. h5 = (h5 + f) | 0;
  11105. h6 = (h6 + g) | 0;
  11106. h7 = (h7 + h) | 0;
  11107. }
  11108. return new Uint8Array([
  11109. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  11110. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  11111. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  11112. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  11113. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  11114. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  11115. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  11116. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  11117. ]);
  11118. }
  11119. return hash;
  11120. })();
  11121. var calculateSHA512 = (function calculateSHA512Closure() {
  11122. function ch(result, x, y, z, tmp) {
  11123. result.assign(x);
  11124. result.and(y);
  11125. tmp.assign(x);
  11126. tmp.not();
  11127. tmp.and(z);
  11128. result.xor(tmp);
  11129. }
  11130. function maj(result, x, y, z, tmp) {
  11131. result.assign(x);
  11132. result.and(y);
  11133. tmp.assign(x);
  11134. tmp.and(z);
  11135. result.xor(tmp);
  11136. tmp.assign(y);
  11137. tmp.and(z);
  11138. result.xor(tmp);
  11139. }
  11140. function sigma(result, x, tmp) {
  11141. result.assign(x);
  11142. result.rotateRight(28);
  11143. tmp.assign(x);
  11144. tmp.rotateRight(34);
  11145. result.xor(tmp);
  11146. tmp.assign(x);
  11147. tmp.rotateRight(39);
  11148. result.xor(tmp);
  11149. }
  11150. function sigmaPrime(result, x, tmp) {
  11151. result.assign(x);
  11152. result.rotateRight(14);
  11153. tmp.assign(x);
  11154. tmp.rotateRight(18);
  11155. result.xor(tmp);
  11156. tmp.assign(x);
  11157. tmp.rotateRight(41);
  11158. result.xor(tmp);
  11159. }
  11160. function littleSigma(result, x, tmp) {
  11161. result.assign(x);
  11162. result.rotateRight(1);
  11163. tmp.assign(x);
  11164. tmp.rotateRight(8);
  11165. result.xor(tmp);
  11166. tmp.assign(x);
  11167. tmp.shiftRight(7);
  11168. result.xor(tmp);
  11169. }
  11170. function littleSigmaPrime(result, x, tmp) {
  11171. result.assign(x);
  11172. result.rotateRight(19);
  11173. tmp.assign(x);
  11174. tmp.rotateRight(61);
  11175. result.xor(tmp);
  11176. tmp.assign(x);
  11177. tmp.shiftRight(6);
  11178. result.xor(tmp);
  11179. }
  11180. var k = [
  11181. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  11182. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  11183. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  11184. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  11185. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  11186. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  11187. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  11188. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  11189. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  11190. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  11191. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  11192. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  11193. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  11194. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  11195. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  11196. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  11197. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  11198. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  11199. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  11200. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  11201. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  11202. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  11203. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  11204. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  11205. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  11206. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  11207. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  11208. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  11209. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  11210. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  11211. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  11212. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  11213. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  11214. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  11215. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  11216. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  11217. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  11218. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  11219. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  11220. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  11221. function hash(data, offset, length, mode384) {
  11222. mode384 = !!mode384;
  11223. // initial hash values
  11224. var h0, h1, h2, h3, h4, h5, h6, h7;
  11225. if (!mode384) {
  11226. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  11227. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  11228. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  11229. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  11230. h4 = new Word64(0x510e527f, 0xade682d1);
  11231. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  11232. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  11233. h7 = new Word64(0x5be0cd19, 0x137e2179);
  11234. }
  11235. else {
  11236. // SHA384 is exactly the same
  11237. // except with different starting values and a trimmed result
  11238. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  11239. h1 = new Word64(0x629a292a, 0x367cd507);
  11240. h2 = new Word64(0x9159015a, 0x3070dd17);
  11241. h3 = new Word64(0x152fecd8, 0xf70e5939);
  11242. h4 = new Word64(0x67332667, 0xffc00b31);
  11243. h5 = new Word64(0x8eb44a87, 0x68581511);
  11244. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  11245. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  11246. }
  11247. // pre-processing
  11248. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  11249. var padded = new Uint8Array(paddedLength);
  11250. var i, j, n;
  11251. for (i = 0; i < length; ++i) {
  11252. padded[i] = data[offset++];
  11253. }
  11254. padded[i++] = 0x80;
  11255. n = paddedLength - 16;
  11256. while (i < n) {
  11257. padded[i++] = 0;
  11258. }
  11259. padded[i++] = 0;
  11260. padded[i++] = 0;
  11261. padded[i++] = 0;
  11262. padded[i++] = 0;
  11263. padded[i++] = 0;
  11264. padded[i++] = 0;
  11265. padded[i++] = 0;
  11266. padded[i++] = 0;
  11267. padded[i++] = 0;
  11268. padded[i++] = 0;
  11269. padded[i++] = 0;
  11270. padded[i++] = (length >>> 29) & 0xFF;
  11271. padded[i++] = (length >> 21) & 0xFF;
  11272. padded[i++] = (length >> 13) & 0xFF;
  11273. padded[i++] = (length >> 5) & 0xFF;
  11274. padded[i++] = (length << 3) & 0xFF;
  11275. var w = new Array(80);
  11276. for (i = 0; i < 80; i++) {
  11277. w[i] = new Word64(0, 0);
  11278. }
  11279. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  11280. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  11281. var g = new Word64(0, 0), h = new Word64(0, 0);
  11282. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  11283. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  11284. // for each 1024 bit block
  11285. for (i = 0; i < paddedLength;) {
  11286. for (j = 0; j < 16; ++j) {
  11287. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  11288. (padded[i + 2] << 8) | (padded[i + 3]);
  11289. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  11290. (padded[i + 6]) << 8 | (padded[i + 7]);
  11291. i += 8;
  11292. }
  11293. for (j = 16; j < 80; ++j) {
  11294. tmp3 = w[j];
  11295. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  11296. tmp3.add(w[j - 7]);
  11297. littleSigma(tmp1, w[j - 15], tmp2);
  11298. tmp3.add(tmp1);
  11299. tmp3.add(w[j - 16]);
  11300. }
  11301. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  11302. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  11303. for (j = 0; j < 80; ++j) {
  11304. t1.assign(h);
  11305. sigmaPrime(tmp1, e, tmp2);
  11306. t1.add(tmp1);
  11307. ch(tmp1, e, f, g, tmp2);
  11308. t1.add(tmp1);
  11309. t1.add(k[j]);
  11310. t1.add(w[j]);
  11311. sigma(t2, a, tmp2);
  11312. maj(tmp1, a, b, c, tmp2);
  11313. t2.add(tmp1);
  11314. tmp3 = h;
  11315. h = g;
  11316. g = f;
  11317. f = e;
  11318. d.add(t1);
  11319. e = d;
  11320. d = c;
  11321. c = b;
  11322. b = a;
  11323. tmp3.assign(t1);
  11324. tmp3.add(t2);
  11325. a = tmp3;
  11326. }
  11327. h0.add(a);
  11328. h1.add(b);
  11329. h2.add(c);
  11330. h3.add(d);
  11331. h4.add(e);
  11332. h5.add(f);
  11333. h6.add(g);
  11334. h7.add(h);
  11335. }
  11336. var result;
  11337. if (!mode384) {
  11338. result = new Uint8Array(64);
  11339. h0.copyTo(result,0);
  11340. h1.copyTo(result,8);
  11341. h2.copyTo(result,16);
  11342. h3.copyTo(result,24);
  11343. h4.copyTo(result,32);
  11344. h5.copyTo(result,40);
  11345. h6.copyTo(result,48);
  11346. h7.copyTo(result,56);
  11347. }
  11348. else {
  11349. result = new Uint8Array(48);
  11350. h0.copyTo(result,0);
  11351. h1.copyTo(result,8);
  11352. h2.copyTo(result,16);
  11353. h3.copyTo(result,24);
  11354. h4.copyTo(result,32);
  11355. h5.copyTo(result,40);
  11356. }
  11357. return result;
  11358. }
  11359. return hash;
  11360. })();
  11361. var calculateSHA384 = (function calculateSHA384Closure() {
  11362. function hash(data, offset, length) {
  11363. return calculateSHA512(data, offset, length, true);
  11364. }
  11365. return hash;
  11366. })();
  11367. var NullCipher = (function NullCipherClosure() {
  11368. function NullCipher() {
  11369. }
  11370. NullCipher.prototype = {
  11371. decryptBlock: function NullCipher_decryptBlock(data) {
  11372. return data;
  11373. }
  11374. };
  11375. return NullCipher;
  11376. })();
  11377. var AES128Cipher = (function AES128CipherClosure() {
  11378. var rcon = new Uint8Array([
  11379. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11380. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11381. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11382. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11383. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  11384. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  11385. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  11386. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  11387. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  11388. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  11389. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  11390. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  11391. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  11392. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  11393. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  11394. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  11395. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  11396. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11397. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11398. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11399. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11400. 0x74, 0xe8, 0xcb, 0x8d]);
  11401. var s = new Uint8Array([
  11402. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  11403. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  11404. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  11405. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  11406. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  11407. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  11408. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  11409. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  11410. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  11411. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  11412. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  11413. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  11414. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  11415. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  11416. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  11417. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  11418. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  11419. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  11420. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  11421. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  11422. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  11423. 0xb0, 0x54, 0xbb, 0x16]);
  11424. var inv_s = new Uint8Array([
  11425. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  11426. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  11427. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  11428. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  11429. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  11430. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  11431. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  11432. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  11433. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  11434. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  11435. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  11436. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  11437. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  11438. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  11439. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  11440. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  11441. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  11442. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  11443. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  11444. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  11445. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  11446. 0x55, 0x21, 0x0c, 0x7d]);
  11447. var mixCol = new Uint8Array(256);
  11448. for (var i = 0; i < 256; i++) {
  11449. if (i < 128) {
  11450. mixCol[i] = i << 1;
  11451. } else {
  11452. mixCol[i] = (i << 1) ^ 0x1b;
  11453. }
  11454. }
  11455. var mix = new Uint32Array([
  11456. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  11457. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  11458. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  11459. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  11460. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  11461. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  11462. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  11463. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  11464. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  11465. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  11466. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  11467. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  11468. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  11469. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  11470. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  11471. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  11472. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  11473. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  11474. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  11475. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  11476. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  11477. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  11478. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  11479. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  11480. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  11481. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  11482. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  11483. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  11484. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  11485. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  11486. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  11487. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  11488. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  11489. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  11490. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  11491. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  11492. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  11493. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  11494. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  11495. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  11496. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  11497. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  11498. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  11499. function expandKey128(cipherKey) {
  11500. var b = 176, result = new Uint8Array(b);
  11501. result.set(cipherKey);
  11502. for (var j = 16, i = 1; j < b; ++i) {
  11503. // RotWord
  11504. var t1 = result[j - 3], t2 = result[j - 2],
  11505. t3 = result[j - 1], t4 = result[j - 4];
  11506. // SubWord
  11507. t1 = s[t1];
  11508. t2 = s[t2];
  11509. t3 = s[t3];
  11510. t4 = s[t4];
  11511. // Rcon
  11512. t1 = t1 ^ rcon[i];
  11513. for (var n = 0; n < 4; ++n) {
  11514. result[j] = (t1 ^= result[j - 16]);
  11515. j++;
  11516. result[j] = (t2 ^= result[j - 16]);
  11517. j++;
  11518. result[j] = (t3 ^= result[j - 16]);
  11519. j++;
  11520. result[j] = (t4 ^= result[j - 16]);
  11521. j++;
  11522. }
  11523. }
  11524. return result;
  11525. }
  11526. function decrypt128(input, key) {
  11527. var state = new Uint8Array(16);
  11528. state.set(input);
  11529. var i, j, k;
  11530. var t, u, v;
  11531. // AddRoundKey
  11532. for (j = 0, k = 160; j < 16; ++j, ++k) {
  11533. state[j] ^= key[k];
  11534. }
  11535. for (i = 9; i >= 1; --i) {
  11536. // InvShiftRows
  11537. t = state[13];
  11538. state[13] = state[9];
  11539. state[9] = state[5];
  11540. state[5] = state[1];
  11541. state[1] = t;
  11542. t = state[14];
  11543. u = state[10];
  11544. state[14] = state[6];
  11545. state[10] = state[2];
  11546. state[6] = t;
  11547. state[2] = u;
  11548. t = state[15];
  11549. u = state[11];
  11550. v = state[7];
  11551. state[15] = state[3];
  11552. state[11] = t;
  11553. state[7] = u;
  11554. state[3] = v;
  11555. // InvSubBytes
  11556. for (j = 0; j < 16; ++j) {
  11557. state[j] = inv_s[state[j]];
  11558. }
  11559. // AddRoundKey
  11560. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  11561. state[j] ^= key[k];
  11562. }
  11563. // InvMixColumns
  11564. for (j = 0; j < 16; j += 4) {
  11565. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  11566. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  11567. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  11568. (s3 >>> 24) ^ (s3 << 8));
  11569. state[j] = (t >>> 24) & 0xFF;
  11570. state[j + 1] = (t >> 16) & 0xFF;
  11571. state[j + 2] = (t >> 8) & 0xFF;
  11572. state[j + 3] = t & 0xFF;
  11573. }
  11574. }
  11575. // InvShiftRows
  11576. t = state[13];
  11577. state[13] = state[9];
  11578. state[9] = state[5];
  11579. state[5] = state[1];
  11580. state[1] = t;
  11581. t = state[14];
  11582. u = state[10];
  11583. state[14] = state[6];
  11584. state[10] = state[2];
  11585. state[6] = t;
  11586. state[2] = u;
  11587. t = state[15];
  11588. u = state[11];
  11589. v = state[7];
  11590. state[15] = state[3];
  11591. state[11] = t;
  11592. state[7] = u;
  11593. state[3] = v;
  11594. for (j = 0; j < 16; ++j) {
  11595. // InvSubBytes
  11596. state[j] = inv_s[state[j]];
  11597. // AddRoundKey
  11598. state[j] ^= key[j];
  11599. }
  11600. return state;
  11601. }
  11602. function encrypt128(input, key) {
  11603. var t, u, v, k;
  11604. var state = new Uint8Array(16);
  11605. state.set(input);
  11606. for (j = 0; j < 16; ++j) {
  11607. // AddRoundKey
  11608. state[j] ^= key[j];
  11609. }
  11610. for (i = 1; i < 10; i++) {
  11611. //SubBytes
  11612. for (j = 0; j < 16; ++j) {
  11613. state[j] = s[state[j]];
  11614. }
  11615. //ShiftRows
  11616. v = state[1];
  11617. state[1] = state[5];
  11618. state[5] = state[9];
  11619. state[9] = state[13];
  11620. state[13] = v;
  11621. v = state[2];
  11622. u = state[6];
  11623. state[2] = state[10];
  11624. state[6] = state[14];
  11625. state[10] = v;
  11626. state[14] = u;
  11627. v = state[3];
  11628. u = state[7];
  11629. t = state[11];
  11630. state[3] = state[15];
  11631. state[7] = v;
  11632. state[11] = u;
  11633. state[15] = t;
  11634. //MixColumns
  11635. for (var j = 0; j < 16; j += 4) {
  11636. var s0 = state[j + 0], s1 = state[j + 1];
  11637. var s2 = state[j + 2], s3 = state[j + 3];
  11638. t = s0 ^ s1 ^ s2 ^ s3;
  11639. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  11640. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  11641. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  11642. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  11643. }
  11644. //AddRoundKey
  11645. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  11646. state[j] ^= key[k];
  11647. }
  11648. }
  11649. //SubBytes
  11650. for (j = 0; j < 16; ++j) {
  11651. state[j] = s[state[j]];
  11652. }
  11653. //ShiftRows
  11654. v = state[1];
  11655. state[1] = state[5];
  11656. state[5] = state[9];
  11657. state[9] = state[13];
  11658. state[13] = v;
  11659. v = state[2];
  11660. u = state[6];
  11661. state[2] = state[10];
  11662. state[6] = state[14];
  11663. state[10] = v;
  11664. state[14] = u;
  11665. v = state[3];
  11666. u = state[7];
  11667. t = state[11];
  11668. state[3] = state[15];
  11669. state[7] = v;
  11670. state[11] = u;
  11671. state[15] = t;
  11672. //AddRoundKey
  11673. for (j = 0, k = 160; j < 16; ++j, ++k) {
  11674. state[j] ^= key[k];
  11675. }
  11676. return state;
  11677. }
  11678. function AES128Cipher(key) {
  11679. this.key = expandKey128(key);
  11680. this.buffer = new Uint8Array(16);
  11681. this.bufferPosition = 0;
  11682. }
  11683. function decryptBlock2(data, finalize) {
  11684. var i, j, ii, sourceLength = data.length,
  11685. buffer = this.buffer, bufferLength = this.bufferPosition,
  11686. result = [], iv = this.iv;
  11687. for (i = 0; i < sourceLength; ++i) {
  11688. buffer[bufferLength] = data[i];
  11689. ++bufferLength;
  11690. if (bufferLength < 16) {
  11691. continue;
  11692. }
  11693. // buffer is full, decrypting
  11694. var plain = decrypt128(buffer, this.key);
  11695. // xor-ing the IV vector to get plain text
  11696. for (j = 0; j < 16; ++j) {
  11697. plain[j] ^= iv[j];
  11698. }
  11699. iv = buffer;
  11700. result.push(plain);
  11701. buffer = new Uint8Array(16);
  11702. bufferLength = 0;
  11703. }
  11704. // saving incomplete buffer
  11705. this.buffer = buffer;
  11706. this.bufferLength = bufferLength;
  11707. this.iv = iv;
  11708. if (result.length === 0) {
  11709. return new Uint8Array([]);
  11710. }
  11711. // combining plain text blocks into one
  11712. var outputLength = 16 * result.length;
  11713. if (finalize) {
  11714. // undo a padding that is described in RFC 2898
  11715. var lastBlock = result[result.length - 1];
  11716. outputLength -= lastBlock[15];
  11717. result[result.length - 1] = lastBlock.subarray(0, 16 - lastBlock[15]);
  11718. }
  11719. var output = new Uint8Array(outputLength);
  11720. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  11721. output.set(result[i], j);
  11722. }
  11723. return output;
  11724. }
  11725. AES128Cipher.prototype = {
  11726. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  11727. var i, sourceLength = data.length;
  11728. var buffer = this.buffer, bufferLength = this.bufferPosition;
  11729. // waiting for IV values -- they are at the start of the stream
  11730. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  11731. buffer[bufferLength] = data[i];
  11732. }
  11733. if (bufferLength < 16) {
  11734. // need more data
  11735. this.bufferLength = bufferLength;
  11736. return new Uint8Array([]);
  11737. }
  11738. this.iv = buffer;
  11739. this.buffer = new Uint8Array(16);
  11740. this.bufferLength = 0;
  11741. // starting decryption
  11742. this.decryptBlock = decryptBlock2;
  11743. return this.decryptBlock(data.subarray(16), finalize);
  11744. },
  11745. encrypt: function AES128Cipher_encrypt(data, iv) {
  11746. var i, j, ii, sourceLength = data.length,
  11747. buffer = this.buffer, bufferLength = this.bufferPosition,
  11748. result = [];
  11749. if (!iv) {
  11750. iv = new Uint8Array(16);
  11751. }
  11752. for (i = 0; i < sourceLength; ++i) {
  11753. buffer[bufferLength] = data[i];
  11754. ++bufferLength;
  11755. if (bufferLength < 16) {
  11756. continue;
  11757. }
  11758. for (j = 0; j < 16; ++j) {
  11759. buffer[j] ^= iv[j];
  11760. }
  11761. // buffer is full, encrypting
  11762. var cipher = encrypt128(buffer, this.key);
  11763. iv = cipher;
  11764. result.push(cipher);
  11765. buffer = new Uint8Array(16);
  11766. bufferLength = 0;
  11767. }
  11768. // saving incomplete buffer
  11769. this.buffer = buffer;
  11770. this.bufferLength = bufferLength;
  11771. this.iv = iv;
  11772. if (result.length === 0) {
  11773. return new Uint8Array([]);
  11774. }
  11775. // combining plain text blocks into one
  11776. var outputLength = 16 * result.length;
  11777. var output = new Uint8Array(outputLength);
  11778. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  11779. output.set(result[i], j);
  11780. }
  11781. return output;
  11782. }
  11783. };
  11784. return AES128Cipher;
  11785. })();
  11786. var AES256Cipher = (function AES256CipherClosure() {
  11787. var rcon = new Uint8Array([
  11788. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11789. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11790. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11791. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11792. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  11793. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  11794. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  11795. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  11796. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  11797. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  11798. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  11799. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  11800. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  11801. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  11802. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  11803. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  11804. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  11805. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  11806. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  11807. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  11808. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  11809. 0x74, 0xe8, 0xcb, 0x8d]);
  11810. var s = new Uint8Array([
  11811. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  11812. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  11813. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  11814. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  11815. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  11816. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  11817. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  11818. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  11819. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  11820. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  11821. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  11822. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  11823. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  11824. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  11825. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  11826. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  11827. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  11828. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  11829. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  11830. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  11831. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  11832. 0xb0, 0x54, 0xbb, 0x16]);
  11833. var inv_s = new Uint8Array([
  11834. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  11835. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  11836. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  11837. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  11838. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  11839. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  11840. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  11841. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  11842. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  11843. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  11844. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  11845. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  11846. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  11847. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  11848. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  11849. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  11850. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  11851. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  11852. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  11853. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  11854. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  11855. 0x55, 0x21, 0x0c, 0x7d]);
  11856. var mixCol = new Uint8Array(256);
  11857. for (var i = 0; i < 256; i++) {
  11858. if (i < 128) {
  11859. mixCol[i] = i << 1;
  11860. } else {
  11861. mixCol[i] = (i << 1) ^ 0x1b;
  11862. }
  11863. }
  11864. var mix = new Uint32Array([
  11865. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  11866. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  11867. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  11868. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  11869. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  11870. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  11871. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  11872. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  11873. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  11874. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  11875. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  11876. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  11877. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  11878. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  11879. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  11880. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  11881. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  11882. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  11883. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  11884. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  11885. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  11886. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  11887. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  11888. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  11889. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  11890. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  11891. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  11892. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  11893. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  11894. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  11895. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  11896. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  11897. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  11898. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  11899. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  11900. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  11901. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  11902. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  11903. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  11904. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  11905. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  11906. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  11907. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  11908. function expandKey256(cipherKey) {
  11909. var b = 240, result = new Uint8Array(b);
  11910. var r = 1;
  11911. result.set(cipherKey);
  11912. for (var j = 32, i = 1; j < b; ++i) {
  11913. if (j % 32 === 16) {
  11914. t1 = s[t1];
  11915. t2 = s[t2];
  11916. t3 = s[t3];
  11917. t4 = s[t4];
  11918. } else if (j % 32 === 0) {
  11919. // RotWord
  11920. var t1 = result[j - 3], t2 = result[j - 2],
  11921. t3 = result[j - 1], t4 = result[j - 4];
  11922. // SubWord
  11923. t1 = s[t1];
  11924. t2 = s[t2];
  11925. t3 = s[t3];
  11926. t4 = s[t4];
  11927. // Rcon
  11928. t1 = t1 ^ r;
  11929. if ((r <<= 1) >= 256) {
  11930. r = (r ^ 0x1b) & 0xFF;
  11931. }
  11932. }
  11933. for (var n = 0; n < 4; ++n) {
  11934. result[j] = (t1 ^= result[j - 32]);
  11935. j++;
  11936. result[j] = (t2 ^= result[j - 32]);
  11937. j++;
  11938. result[j] = (t3 ^= result[j - 32]);
  11939. j++;
  11940. result[j] = (t4 ^= result[j - 32]);
  11941. j++;
  11942. }
  11943. }
  11944. return result;
  11945. }
  11946. function decrypt256(input, key) {
  11947. var state = new Uint8Array(16);
  11948. state.set(input);
  11949. var i, j, k;
  11950. var t, u, v;
  11951. // AddRoundKey
  11952. for (j = 0, k = 224; j < 16; ++j, ++k) {
  11953. state[j] ^= key[k];
  11954. }
  11955. for (i = 13; i >= 1; --i) {
  11956. // InvShiftRows
  11957. t = state[13];
  11958. state[13] = state[9];
  11959. state[9] = state[5];
  11960. state[5] = state[1];
  11961. state[1] = t;
  11962. t = state[14];
  11963. u = state[10];
  11964. state[14] = state[6];
  11965. state[10] = state[2];
  11966. state[6] = t;
  11967. state[2] = u;
  11968. t = state[15];
  11969. u = state[11];
  11970. v = state[7];
  11971. state[15] = state[3];
  11972. state[11] = t;
  11973. state[7] = u;
  11974. state[3] = v;
  11975. // InvSubBytes
  11976. for (j = 0; j < 16; ++j) {
  11977. state[j] = inv_s[state[j]];
  11978. }
  11979. // AddRoundKey
  11980. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  11981. state[j] ^= key[k];
  11982. }
  11983. // InvMixColumns
  11984. for (j = 0; j < 16; j += 4) {
  11985. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  11986. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  11987. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  11988. (s3 >>> 24) ^ (s3 << 8));
  11989. state[j] = (t >>> 24) & 0xFF;
  11990. state[j + 1] = (t >> 16) & 0xFF;
  11991. state[j + 2] = (t >> 8) & 0xFF;
  11992. state[j + 3] = t & 0xFF;
  11993. }
  11994. }
  11995. // InvShiftRows
  11996. t = state[13];
  11997. state[13] = state[9];
  11998. state[9] = state[5];
  11999. state[5] = state[1];
  12000. state[1] = t;
  12001. t = state[14];
  12002. u = state[10];
  12003. state[14] = state[6];
  12004. state[10] = state[2];
  12005. state[6] = t;
  12006. state[2] = u;
  12007. t = state[15];
  12008. u = state[11];
  12009. v = state[7];
  12010. state[15] = state[3];
  12011. state[11] = t;
  12012. state[7] = u;
  12013. state[3] = v;
  12014. for (j = 0; j < 16; ++j) {
  12015. // InvSubBytes
  12016. state[j] = inv_s[state[j]];
  12017. // AddRoundKey
  12018. state[j] ^= key[j];
  12019. }
  12020. return state;
  12021. }
  12022. function encrypt256(input, key) {
  12023. var t, u, v, k;
  12024. var state = new Uint8Array(16);
  12025. state.set(input);
  12026. for (j = 0; j < 16; ++j) {
  12027. // AddRoundKey
  12028. state[j] ^= key[j];
  12029. }
  12030. for (i = 1; i < 14; i++) {
  12031. //SubBytes
  12032. for (j = 0; j < 16; ++j) {
  12033. state[j] = s[state[j]];
  12034. }
  12035. //ShiftRows
  12036. v = state[1];
  12037. state[1] = state[5];
  12038. state[5] = state[9];
  12039. state[9] = state[13];
  12040. state[13] = v;
  12041. v = state[2];
  12042. u = state[6];
  12043. state[2] = state[10];
  12044. state[6] = state[14];
  12045. state[10] = v;
  12046. state[14] = u;
  12047. v = state[3];
  12048. u = state[7];
  12049. t = state[11];
  12050. state[3] = state[15];
  12051. state[7] = v;
  12052. state[11] = u;
  12053. state[15] = t;
  12054. //MixColumns
  12055. for (var j = 0; j < 16; j += 4) {
  12056. var s0 = state[j + 0], s1 = state[j + 1];
  12057. var s2 = state[j + 2], s3 = state[j + 3];
  12058. t = s0 ^ s1 ^ s2 ^ s3;
  12059. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  12060. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  12061. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  12062. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  12063. }
  12064. //AddRoundKey
  12065. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  12066. state[j] ^= key[k];
  12067. }
  12068. }
  12069. //SubBytes
  12070. for (j = 0; j < 16; ++j) {
  12071. state[j] = s[state[j]];
  12072. }
  12073. //ShiftRows
  12074. v = state[1];
  12075. state[1] = state[5];
  12076. state[5] = state[9];
  12077. state[9] = state[13];
  12078. state[13] = v;
  12079. v = state[2];
  12080. u = state[6];
  12081. state[2] = state[10];
  12082. state[6] = state[14];
  12083. state[10] = v;
  12084. state[14] = u;
  12085. v = state[3];
  12086. u = state[7];
  12087. t = state[11];
  12088. state[3] = state[15];
  12089. state[7] = v;
  12090. state[11] = u;
  12091. state[15] = t;
  12092. //AddRoundKey
  12093. for (j = 0, k = 224; j < 16; ++j, ++k) {
  12094. state[j] ^= key[k];
  12095. }
  12096. return state;
  12097. }
  12098. function AES256Cipher(key) {
  12099. this.key = expandKey256(key);
  12100. this.buffer = new Uint8Array(16);
  12101. this.bufferPosition = 0;
  12102. }
  12103. function decryptBlock2(data, finalize) {
  12104. var i, j, ii, sourceLength = data.length,
  12105. buffer = this.buffer, bufferLength = this.bufferPosition,
  12106. result = [], iv = this.iv;
  12107. for (i = 0; i < sourceLength; ++i) {
  12108. buffer[bufferLength] = data[i];
  12109. ++bufferLength;
  12110. if (bufferLength < 16) {
  12111. continue;
  12112. }
  12113. // buffer is full, encrypting
  12114. var plain = decrypt256(buffer, this.key);
  12115. // xor-ing the IV vector to get plain text
  12116. for (j = 0; j < 16; ++j) {
  12117. plain[j] ^= iv[j];
  12118. }
  12119. iv = buffer;
  12120. result.push(plain);
  12121. buffer = new Uint8Array(16);
  12122. bufferLength = 0;
  12123. }
  12124. // saving incomplete buffer
  12125. this.buffer = buffer;
  12126. this.bufferLength = bufferLength;
  12127. this.iv = iv;
  12128. if (result.length === 0) {
  12129. return new Uint8Array([]);
  12130. }
  12131. // combining plain text blocks into one
  12132. var outputLength = 16 * result.length;
  12133. if (finalize) {
  12134. // undo a padding that is described in RFC 2898
  12135. var lastBlock = result[result.length - 1];
  12136. outputLength -= lastBlock[15];
  12137. result[result.length - 1] = lastBlock.subarray(0, 16 - lastBlock[15]);
  12138. }
  12139. var output = new Uint8Array(outputLength);
  12140. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  12141. output.set(result[i], j);
  12142. }
  12143. return output;
  12144. }
  12145. AES256Cipher.prototype = {
  12146. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  12147. var i, sourceLength = data.length;
  12148. var buffer = this.buffer, bufferLength = this.bufferPosition;
  12149. // if not supplied an IV wait for IV values
  12150. // they are at the start of the stream
  12151. if (iv) {
  12152. this.iv = iv;
  12153. } else {
  12154. for (i = 0; bufferLength < 16 &&
  12155. i < sourceLength; ++i, ++bufferLength) {
  12156. buffer[bufferLength] = data[i];
  12157. }
  12158. if (bufferLength < 16) {
  12159. //need more data
  12160. this.bufferLength = bufferLength;
  12161. return new Uint8Array([]);
  12162. }
  12163. this.iv = buffer;
  12164. data = data.subarray(16);
  12165. }
  12166. this.buffer = new Uint8Array(16);
  12167. this.bufferLength = 0;
  12168. // starting decryption
  12169. this.decryptBlock = decryptBlock2;
  12170. return this.decryptBlock(data, finalize);
  12171. },
  12172. encrypt: function AES256Cipher_encrypt(data, iv) {
  12173. var i, j, ii, sourceLength = data.length,
  12174. buffer = this.buffer, bufferLength = this.bufferPosition,
  12175. result = [];
  12176. if (!iv) {
  12177. iv = new Uint8Array(16);
  12178. }
  12179. for (i = 0; i < sourceLength; ++i) {
  12180. buffer[bufferLength] = data[i];
  12181. ++bufferLength;
  12182. if (bufferLength < 16) {
  12183. continue;
  12184. }
  12185. for (j = 0; j < 16; ++j) {
  12186. buffer[j] ^= iv[j];
  12187. }
  12188. // buffer is full, encrypting
  12189. var cipher = encrypt256(buffer, this.key);
  12190. this.iv = cipher;
  12191. result.push(cipher);
  12192. buffer = new Uint8Array(16);
  12193. bufferLength = 0;
  12194. }
  12195. // saving incomplete buffer
  12196. this.buffer = buffer;
  12197. this.bufferLength = bufferLength;
  12198. this.iv = iv;
  12199. if (result.length === 0) {
  12200. return new Uint8Array([]);
  12201. }
  12202. // combining plain text blocks into one
  12203. var outputLength = 16 * result.length;
  12204. var output = new Uint8Array(outputLength);
  12205. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  12206. output.set(result[i], j);
  12207. }
  12208. return output;
  12209. }
  12210. };
  12211. return AES256Cipher;
  12212. })();
  12213. var PDF17 = (function PDF17Closure() {
  12214. function compareByteArrays(array1, array2) {
  12215. if (array1.length !== array2.length) {
  12216. return false;
  12217. }
  12218. for (var i = 0; i < array1.length; i++) {
  12219. if (array1[i] !== array2[i]) {
  12220. return false;
  12221. }
  12222. }
  12223. return true;
  12224. }
  12225. function PDF17() {
  12226. }
  12227. PDF17.prototype = {
  12228. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  12229. ownerValidationSalt,
  12230. userBytes,
  12231. ownerPassword) {
  12232. var hashData = new Uint8Array(password.length + 56);
  12233. hashData.set(password, 0);
  12234. hashData.set(ownerValidationSalt, password.length);
  12235. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  12236. var result = calculateSHA256(hashData, 0, hashData.length);
  12237. return compareByteArrays(result, ownerPassword);
  12238. },
  12239. checkUserPassword: function PDF17_checkUserPassword(password,
  12240. userValidationSalt,
  12241. userPassword) {
  12242. var hashData = new Uint8Array(password.length + 8);
  12243. hashData.set(password, 0);
  12244. hashData.set(userValidationSalt, password.length);
  12245. var result = calculateSHA256(hashData, 0, hashData.length);
  12246. return compareByteArrays(result, userPassword);
  12247. },
  12248. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  12249. ownerEncryption) {
  12250. var hashData = new Uint8Array(password.length + 56);
  12251. hashData.set(password, 0);
  12252. hashData.set(ownerKeySalt, password.length);
  12253. hashData.set(userBytes, password.length + ownerKeySalt.length);
  12254. var key = calculateSHA256(hashData, 0, hashData.length);
  12255. var cipher = new AES256Cipher(key);
  12256. return cipher.decryptBlock(ownerEncryption,
  12257. false,
  12258. new Uint8Array(16));
  12259. },
  12260. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  12261. userEncryption) {
  12262. var hashData = new Uint8Array(password.length + 8);
  12263. hashData.set(password, 0);
  12264. hashData.set(userKeySalt, password.length);
  12265. //key is the decryption key for the UE string
  12266. var key = calculateSHA256(hashData, 0, hashData.length);
  12267. var cipher = new AES256Cipher(key);
  12268. return cipher.decryptBlock(userEncryption,
  12269. false,
  12270. new Uint8Array(16));
  12271. }
  12272. };
  12273. return PDF17;
  12274. })();
  12275. var PDF20 = (function PDF20Closure() {
  12276. function concatArrays(array1, array2) {
  12277. var t = new Uint8Array(array1.length + array2.length);
  12278. t.set(array1, 0);
  12279. t.set(array2, array1.length);
  12280. return t;
  12281. }
  12282. function calculatePDF20Hash(password, input, userBytes) {
  12283. //This refers to Algorithm 2.B as defined in ISO 32000-2
  12284. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  12285. var e = [0];
  12286. var i = 0;
  12287. while (i < 64 || e[e.length - 1] > i - 32) {
  12288. var arrayLength = password.length + k.length + userBytes.length;
  12289. var k1 = new Uint8Array(arrayLength * 64);
  12290. var array = concatArrays(password, k);
  12291. array = concatArrays(array, userBytes);
  12292. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  12293. k1.set(array, pos);
  12294. }
  12295. //AES128 CBC NO PADDING with
  12296. //first 16 bytes of k as the key and the second 16 as the iv.
  12297. var cipher = new AES128Cipher(k.subarray(0, 16));
  12298. e = cipher.encrypt(k1, k.subarray(16, 32));
  12299. //Now we have to take the first 16 bytes of an unsigned
  12300. //big endian integer... and compute the remainder
  12301. //modulo 3.... That is a fairly large number and
  12302. //JavaScript isn't going to handle that well...
  12303. //So we're using a trick that allows us to perform
  12304. //modulo math byte by byte
  12305. var remainder = 0;
  12306. for (var z = 0; z < 16; z++) {
  12307. remainder *= (256 % 3);
  12308. remainder %= 3;
  12309. remainder += ((e[z] >>> 0) % 3);
  12310. remainder %= 3;
  12311. }
  12312. if (remainder === 0) {
  12313. k = calculateSHA256(e, 0, e.length);
  12314. }
  12315. else if (remainder === 1) {
  12316. k = calculateSHA384(e, 0, e.length);
  12317. }
  12318. else if (remainder === 2) {
  12319. k = calculateSHA512(e, 0, e.length);
  12320. }
  12321. i++;
  12322. }
  12323. return k.subarray(0, 32);
  12324. }
  12325. function PDF20() {
  12326. }
  12327. function compareByteArrays(array1, array2) {
  12328. if (array1.length !== array2.length) {
  12329. return false;
  12330. }
  12331. for (var i = 0; i < array1.length; i++) {
  12332. if (array1[i] !== array2[i]) {
  12333. return false;
  12334. }
  12335. }
  12336. return true;
  12337. }
  12338. PDF20.prototype = {
  12339. hash: function PDF20_hash(password, concatBytes, userBytes) {
  12340. return calculatePDF20Hash(password, concatBytes, userBytes);
  12341. },
  12342. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  12343. ownerValidationSalt,
  12344. userBytes,
  12345. ownerPassword) {
  12346. var hashData = new Uint8Array(password.length + 56);
  12347. hashData.set(password, 0);
  12348. hashData.set(ownerValidationSalt, password.length);
  12349. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  12350. var result = calculatePDF20Hash(password, hashData, userBytes);
  12351. return compareByteArrays(result, ownerPassword);
  12352. },
  12353. checkUserPassword: function PDF20_checkUserPassword(password,
  12354. userValidationSalt,
  12355. userPassword) {
  12356. var hashData = new Uint8Array(password.length + 8);
  12357. hashData.set(password, 0);
  12358. hashData.set(userValidationSalt, password.length);
  12359. var result = calculatePDF20Hash(password, hashData, []);
  12360. return compareByteArrays(result, userPassword);
  12361. },
  12362. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  12363. ownerEncryption) {
  12364. var hashData = new Uint8Array(password.length + 56);
  12365. hashData.set(password, 0);
  12366. hashData.set(ownerKeySalt, password.length);
  12367. hashData.set(userBytes, password.length + ownerKeySalt.length);
  12368. var key = calculatePDF20Hash(password, hashData, userBytes);
  12369. var cipher = new AES256Cipher(key);
  12370. return cipher.decryptBlock(ownerEncryption,
  12371. false,
  12372. new Uint8Array(16));
  12373. },
  12374. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  12375. userEncryption) {
  12376. var hashData = new Uint8Array(password.length + 8);
  12377. hashData.set(password, 0);
  12378. hashData.set(userKeySalt, password.length);
  12379. //key is the decryption key for the UE string
  12380. var key = calculatePDF20Hash(password, hashData, []);
  12381. var cipher = new AES256Cipher(key);
  12382. return cipher.decryptBlock(userEncryption,
  12383. false,
  12384. new Uint8Array(16));
  12385. }
  12386. };
  12387. return PDF20;
  12388. })();
  12389. var CipherTransform = (function CipherTransformClosure() {
  12390. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  12391. this.stringCipherConstructor = stringCipherConstructor;
  12392. this.streamCipherConstructor = streamCipherConstructor;
  12393. }
  12394. CipherTransform.prototype = {
  12395. createStream: function CipherTransform_createStream(stream, length) {
  12396. var cipher = new this.streamCipherConstructor();
  12397. return new DecryptStream(stream, length,
  12398. function cipherTransformDecryptStream(data, finalize) {
  12399. return cipher.decryptBlock(data, finalize);
  12400. }
  12401. );
  12402. },
  12403. decryptString: function CipherTransform_decryptString(s) {
  12404. var cipher = new this.stringCipherConstructor();
  12405. var data = stringToBytes(s);
  12406. data = cipher.decryptBlock(data, true);
  12407. return bytesToString(data);
  12408. }
  12409. };
  12410. return CipherTransform;
  12411. })();
  12412. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  12413. var defaultPasswordBytes = new Uint8Array([
  12414. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  12415. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  12416. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  12417. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  12418. function createEncryptionKey20(revision, password, ownerPassword,
  12419. ownerValidationSalt, ownerKeySalt, uBytes,
  12420. userPassword, userValidationSalt, userKeySalt,
  12421. ownerEncryption, userEncryption, perms) {
  12422. if (password) {
  12423. var passwordLength = Math.min(127, password.length);
  12424. password = password.subarray(0, passwordLength);
  12425. } else {
  12426. password = [];
  12427. }
  12428. var pdfAlgorithm;
  12429. if (revision === 6) {
  12430. pdfAlgorithm = new PDF20();
  12431. } else {
  12432. pdfAlgorithm = new PDF17();
  12433. }
  12434. if (pdfAlgorithm) {
  12435. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  12436. userPassword)) {
  12437. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  12438. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  12439. uBytes,
  12440. ownerPassword)) {
  12441. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  12442. ownerEncryption);
  12443. }
  12444. }
  12445. return null;
  12446. }
  12447. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  12448. flags, revision, keyLength, encryptMetadata) {
  12449. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  12450. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  12451. if (password) {
  12452. n = Math.min(32, password.length);
  12453. for (; i < n; ++i) {
  12454. hashData[i] = password[i];
  12455. }
  12456. }
  12457. j = 0;
  12458. while (i < 32) {
  12459. hashData[i++] = defaultPasswordBytes[j++];
  12460. }
  12461. // as now the padded password in the hashData[0..i]
  12462. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  12463. hashData[i++] = ownerPassword[j];
  12464. }
  12465. hashData[i++] = flags & 0xFF;
  12466. hashData[i++] = (flags >> 8) & 0xFF;
  12467. hashData[i++] = (flags >> 16) & 0xFF;
  12468. hashData[i++] = (flags >>> 24) & 0xFF;
  12469. for (j = 0, n = fileId.length; j < n; ++j) {
  12470. hashData[i++] = fileId[j];
  12471. }
  12472. if (revision >= 4 && !encryptMetadata) {
  12473. hashData[i++] = 0xFF;
  12474. hashData[i++] = 0xFF;
  12475. hashData[i++] = 0xFF;
  12476. hashData[i++] = 0xFF;
  12477. }
  12478. var hash = calculateMD5(hashData, 0, i);
  12479. var keyLengthInBytes = keyLength >> 3;
  12480. if (revision >= 3) {
  12481. for (j = 0; j < 50; ++j) {
  12482. hash = calculateMD5(hash, 0, keyLengthInBytes);
  12483. }
  12484. }
  12485. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  12486. var cipher, checkData;
  12487. if (revision >= 3) {
  12488. for (i = 0; i < 32; ++i) {
  12489. hashData[i] = defaultPasswordBytes[i];
  12490. }
  12491. for (j = 0, n = fileId.length; j < n; ++j) {
  12492. hashData[i++] = fileId[j];
  12493. }
  12494. cipher = new ARCFourCipher(encryptionKey);
  12495. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  12496. n = encryptionKey.length;
  12497. var derivedKey = new Uint8Array(n), k;
  12498. for (j = 1; j <= 19; ++j) {
  12499. for (k = 0; k < n; ++k) {
  12500. derivedKey[k] = encryptionKey[k] ^ j;
  12501. }
  12502. cipher = new ARCFourCipher(derivedKey);
  12503. checkData = cipher.encryptBlock(checkData);
  12504. }
  12505. for (j = 0, n = checkData.length; j < n; ++j) {
  12506. if (userPassword[j] !== checkData[j]) {
  12507. return null;
  12508. }
  12509. }
  12510. } else {
  12511. cipher = new ARCFourCipher(encryptionKey);
  12512. checkData = cipher.encryptBlock(defaultPasswordBytes);
  12513. for (j = 0, n = checkData.length; j < n; ++j) {
  12514. if (userPassword[j] !== checkData[j]) {
  12515. return null;
  12516. }
  12517. }
  12518. }
  12519. return encryptionKey;
  12520. }
  12521. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  12522. var hashData = new Uint8Array(32), i = 0, j, n;
  12523. n = Math.min(32, password.length);
  12524. for (; i < n; ++i) {
  12525. hashData[i] = password[i];
  12526. }
  12527. j = 0;
  12528. while (i < 32) {
  12529. hashData[i++] = defaultPasswordBytes[j++];
  12530. }
  12531. var hash = calculateMD5(hashData, 0, i);
  12532. var keyLengthInBytes = keyLength >> 3;
  12533. if (revision >= 3) {
  12534. for (j = 0; j < 50; ++j) {
  12535. hash = calculateMD5(hash, 0, hash.length);
  12536. }
  12537. }
  12538. var cipher, userPassword;
  12539. if (revision >= 3) {
  12540. userPassword = ownerPassword;
  12541. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  12542. for (j = 19; j >= 0; j--) {
  12543. for (k = 0; k < keyLengthInBytes; ++k) {
  12544. derivedKey[k] = hash[k] ^ j;
  12545. }
  12546. cipher = new ARCFourCipher(derivedKey);
  12547. userPassword = cipher.encryptBlock(userPassword);
  12548. }
  12549. } else {
  12550. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  12551. userPassword = cipher.encryptBlock(ownerPassword);
  12552. }
  12553. return userPassword;
  12554. }
  12555. var identityName = Name.get('Identity');
  12556. function CipherTransformFactory(dict, fileId, password) {
  12557. var filter = dict.get('Filter');
  12558. if (!isName(filter) || filter.name !== 'Standard') {
  12559. error('unknown encryption method');
  12560. }
  12561. this.dict = dict;
  12562. var algorithm = dict.get('V');
  12563. if (!isInt(algorithm) ||
  12564. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  12565. algorithm !== 5)) {
  12566. error('unsupported encryption algorithm');
  12567. }
  12568. this.algorithm = algorithm;
  12569. var keyLength = dict.get('Length') || 40;
  12570. if (!isInt(keyLength) ||
  12571. keyLength < 40 || (keyLength % 8) !== 0) {
  12572. error('invalid key length');
  12573. }
  12574. // prepare keys
  12575. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  12576. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  12577. var flags = dict.get('P');
  12578. var revision = dict.get('R');
  12579. // meaningful when V is 4 or 5
  12580. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  12581. dict.get('EncryptMetadata') !== false);
  12582. this.encryptMetadata = encryptMetadata;
  12583. var fileIdBytes = stringToBytes(fileId);
  12584. var passwordBytes;
  12585. if (password) {
  12586. passwordBytes = stringToBytes(password);
  12587. }
  12588. var encryptionKey;
  12589. if (algorithm !== 5) {
  12590. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  12591. ownerPassword, userPassword, flags,
  12592. revision, keyLength, encryptMetadata);
  12593. }
  12594. else {
  12595. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  12596. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  12597. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  12598. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  12599. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  12600. var ownerEncryption = stringToBytes(dict.get('OE'));
  12601. var userEncryption = stringToBytes(dict.get('UE'));
  12602. var perms = stringToBytes(dict.get('Perms'));
  12603. encryptionKey =
  12604. createEncryptionKey20(revision, passwordBytes,
  12605. ownerPassword, ownerValidationSalt,
  12606. ownerKeySalt, uBytes,
  12607. userPassword, userValidationSalt,
  12608. userKeySalt, ownerEncryption,
  12609. userEncryption, perms);
  12610. }
  12611. if (!encryptionKey && !password) {
  12612. throw new PasswordException('No password given',
  12613. PasswordResponses.NEED_PASSWORD);
  12614. } else if (!encryptionKey && password) {
  12615. // Attempting use the password as an owner password
  12616. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  12617. revision, keyLength);
  12618. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  12619. ownerPassword, userPassword, flags,
  12620. revision, keyLength, encryptMetadata);
  12621. }
  12622. if (!encryptionKey) {
  12623. throw new PasswordException('Incorrect Password',
  12624. PasswordResponses.INCORRECT_PASSWORD);
  12625. }
  12626. this.encryptionKey = encryptionKey;
  12627. if (algorithm >= 4) {
  12628. this.cf = dict.get('CF');
  12629. this.stmf = dict.get('StmF') || identityName;
  12630. this.strf = dict.get('StrF') || identityName;
  12631. this.eff = dict.get('EFF') || this.strf;
  12632. }
  12633. }
  12634. function buildObjectKey(num, gen, encryptionKey, isAes) {
  12635. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  12636. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  12637. key[i] = encryptionKey[i];
  12638. }
  12639. key[i++] = num & 0xFF;
  12640. key[i++] = (num >> 8) & 0xFF;
  12641. key[i++] = (num >> 16) & 0xFF;
  12642. key[i++] = gen & 0xFF;
  12643. key[i++] = (gen >> 8) & 0xFF;
  12644. if (isAes) {
  12645. key[i++] = 0x73;
  12646. key[i++] = 0x41;
  12647. key[i++] = 0x6C;
  12648. key[i++] = 0x54;
  12649. }
  12650. var hash = calculateMD5(key, 0, i);
  12651. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  12652. }
  12653. function buildCipherConstructor(cf, name, num, gen, key) {
  12654. var cryptFilter = cf.get(name.name);
  12655. var cfm;
  12656. if (cryptFilter !== null && cryptFilter !== undefined) {
  12657. cfm = cryptFilter.get('CFM');
  12658. }
  12659. if (!cfm || cfm.name === 'None') {
  12660. return function cipherTransformFactoryBuildCipherConstructorNone() {
  12661. return new NullCipher();
  12662. };
  12663. }
  12664. if ('V2' === cfm.name) {
  12665. return function cipherTransformFactoryBuildCipherConstructorV2() {
  12666. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  12667. };
  12668. }
  12669. if ('AESV2' === cfm.name) {
  12670. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  12671. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  12672. };
  12673. }
  12674. if ('AESV3' === cfm.name) {
  12675. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  12676. return new AES256Cipher(key);
  12677. };
  12678. }
  12679. error('Unknown crypto method');
  12680. }
  12681. CipherTransformFactory.prototype = {
  12682. createCipherTransform:
  12683. function CipherTransformFactory_createCipherTransform(num, gen) {
  12684. if (this.algorithm === 4 || this.algorithm === 5) {
  12685. return new CipherTransform(
  12686. buildCipherConstructor(this.cf, this.stmf,
  12687. num, gen, this.encryptionKey),
  12688. buildCipherConstructor(this.cf, this.strf,
  12689. num, gen, this.encryptionKey));
  12690. }
  12691. // algorithms 1 and 2
  12692. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  12693. var cipherConstructor = function buildCipherCipherConstructor() {
  12694. return new ARCFourCipher(key);
  12695. };
  12696. return new CipherTransform(cipherConstructor, cipherConstructor);
  12697. }
  12698. };
  12699. return CipherTransformFactory;
  12700. })();
  12701. var PatternType = {
  12702. FUNCTION_BASED: 1,
  12703. AXIAL: 2,
  12704. RADIAL: 3,
  12705. FREE_FORM_MESH: 4,
  12706. LATTICE_FORM_MESH: 5,
  12707. COONS_PATCH_MESH: 6,
  12708. TENSOR_PATCH_MESH: 7
  12709. };
  12710. var Pattern = (function PatternClosure() {
  12711. // Constructor should define this.getPattern
  12712. function Pattern() {
  12713. error('should not call Pattern constructor');
  12714. }
  12715. Pattern.prototype = {
  12716. // Input: current Canvas context
  12717. // Output: the appropriate fillStyle or strokeStyle
  12718. getPattern: function Pattern_getPattern(ctx) {
  12719. error('Should not call Pattern.getStyle: ' + ctx);
  12720. }
  12721. };
  12722. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  12723. res) {
  12724. var dict = isStream(shading) ? shading.dict : shading;
  12725. var type = dict.get('ShadingType');
  12726. switch (type) {
  12727. case PatternType.AXIAL:
  12728. case PatternType.RADIAL:
  12729. // Both radial and axial shadings are handled by RadialAxial shading.
  12730. return new Shadings.RadialAxial(dict, matrix, xref, res);
  12731. case PatternType.FREE_FORM_MESH:
  12732. case PatternType.LATTICE_FORM_MESH:
  12733. case PatternType.COONS_PATCH_MESH:
  12734. case PatternType.TENSOR_PATCH_MESH:
  12735. return new Shadings.Mesh(shading, matrix, xref, res);
  12736. default:
  12737. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  12738. return new Shadings.Dummy();
  12739. }
  12740. };
  12741. return Pattern;
  12742. })();
  12743. var Shadings = {};
  12744. // A small number to offset the first/last color stops so we can insert ones to
  12745. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  12746. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  12747. // internally so we have to go bigger.
  12748. Shadings.SMALL_NUMBER = 1e-2;
  12749. // Radial and axial shading have very similar implementations
  12750. // If needed, the implementations can be broken into two classes
  12751. Shadings.RadialAxial = (function RadialAxialClosure() {
  12752. function RadialAxial(dict, matrix, xref, res) {
  12753. this.matrix = matrix;
  12754. this.coordsArr = dict.get('Coords');
  12755. this.shadingType = dict.get('ShadingType');
  12756. this.type = 'Pattern';
  12757. var cs = dict.get('ColorSpace', 'CS');
  12758. cs = ColorSpace.parse(cs, xref, res);
  12759. this.cs = cs;
  12760. var t0 = 0.0, t1 = 1.0;
  12761. if (dict.has('Domain')) {
  12762. var domainArr = dict.get('Domain');
  12763. t0 = domainArr[0];
  12764. t1 = domainArr[1];
  12765. }
  12766. var extendStart = false, extendEnd = false;
  12767. if (dict.has('Extend')) {
  12768. var extendArr = dict.get('Extend');
  12769. extendStart = extendArr[0];
  12770. extendEnd = extendArr[1];
  12771. }
  12772. if (this.shadingType === PatternType.RADIAL &&
  12773. (!extendStart || !extendEnd)) {
  12774. // Radial gradient only currently works if either circle is fully within
  12775. // the other circle.
  12776. var x1 = this.coordsArr[0];
  12777. var y1 = this.coordsArr[1];
  12778. var r1 = this.coordsArr[2];
  12779. var x2 = this.coordsArr[3];
  12780. var y2 = this.coordsArr[4];
  12781. var r2 = this.coordsArr[5];
  12782. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  12783. if (r1 <= r2 + distance &&
  12784. r2 <= r1 + distance) {
  12785. warn('Unsupported radial gradient.');
  12786. }
  12787. }
  12788. this.extendStart = extendStart;
  12789. this.extendEnd = extendEnd;
  12790. var fnObj = dict.get('Function');
  12791. var fn = PDFFunction.parseArray(xref, fnObj);
  12792. // 10 samples seems good enough for now, but probably won't work
  12793. // if there are sharp color changes. Ideally, we would implement
  12794. // the spec faithfully and add lossless optimizations.
  12795. var diff = t1 - t0;
  12796. var step = diff / 10;
  12797. var colorStops = this.colorStops = [];
  12798. // Protect against bad domains so we don't end up in an infinte loop below.
  12799. if (t0 >= t1 || step <= 0) {
  12800. // Acrobat doesn't seem to handle these cases so we'll ignore for
  12801. // now.
  12802. info('Bad shading domain.');
  12803. return;
  12804. }
  12805. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  12806. var rgbColor;
  12807. for (var i = t0; i <= t1; i += step) {
  12808. ratio[0] = i;
  12809. fn(ratio, 0, color, 0);
  12810. rgbColor = cs.getRgb(color, 0);
  12811. var cssColor = Util.makeCssRgb(rgbColor);
  12812. colorStops.push([(i - t0) / diff, cssColor]);
  12813. }
  12814. var background = 'transparent';
  12815. if (dict.has('Background')) {
  12816. rgbColor = cs.getRgb(dict.get('Background'), 0);
  12817. background = Util.makeCssRgb(rgbColor);
  12818. }
  12819. if (!extendStart) {
  12820. // Insert a color stop at the front and offset the first real color stop
  12821. // so it doesn't conflict with the one we insert.
  12822. colorStops.unshift([0, background]);
  12823. colorStops[1][0] += Shadings.SMALL_NUMBER;
  12824. }
  12825. if (!extendEnd) {
  12826. // Same idea as above in extendStart but for the end.
  12827. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  12828. colorStops.push([1, background]);
  12829. }
  12830. this.colorStops = colorStops;
  12831. }
  12832. RadialAxial.prototype = {
  12833. getIR: function RadialAxial_getIR() {
  12834. var coordsArr = this.coordsArr;
  12835. var shadingType = this.shadingType;
  12836. var type, p0, p1, r0, r1;
  12837. if (shadingType === PatternType.AXIAL) {
  12838. p0 = [coordsArr[0], coordsArr[1]];
  12839. p1 = [coordsArr[2], coordsArr[3]];
  12840. r0 = null;
  12841. r1 = null;
  12842. type = 'axial';
  12843. } else if (shadingType === PatternType.RADIAL) {
  12844. p0 = [coordsArr[0], coordsArr[1]];
  12845. p1 = [coordsArr[3], coordsArr[4]];
  12846. r0 = coordsArr[2];
  12847. r1 = coordsArr[5];
  12848. type = 'radial';
  12849. } else {
  12850. error('getPattern type unknown: ' + shadingType);
  12851. }
  12852. var matrix = this.matrix;
  12853. if (matrix) {
  12854. p0 = Util.applyTransform(p0, matrix);
  12855. p1 = Util.applyTransform(p1, matrix);
  12856. }
  12857. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  12858. }
  12859. };
  12860. return RadialAxial;
  12861. })();
  12862. // All mesh shading. For now, they will be presented as set of the triangles
  12863. // to be drawn on the canvas and rgb color for each vertex.
  12864. Shadings.Mesh = (function MeshClosure() {
  12865. function MeshStreamReader(stream, context) {
  12866. this.stream = stream;
  12867. this.context = context;
  12868. this.buffer = 0;
  12869. this.bufferLength = 0;
  12870. var numComps = context.numComps;
  12871. this.tmpCompsBuf = new Float32Array(numComps);
  12872. var csNumComps = context.colorSpace;
  12873. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  12874. this.tmpCompsBuf;
  12875. }
  12876. MeshStreamReader.prototype = {
  12877. get hasData() {
  12878. if (this.stream.end) {
  12879. return this.stream.pos < this.stream.end;
  12880. }
  12881. if (this.bufferLength > 0) {
  12882. return true;
  12883. }
  12884. var nextByte = this.stream.getByte();
  12885. if (nextByte < 0) {
  12886. return false;
  12887. }
  12888. this.buffer = nextByte;
  12889. this.bufferLength = 8;
  12890. return true;
  12891. },
  12892. readBits: function MeshStreamReader_readBits(n) {
  12893. var buffer = this.buffer;
  12894. var bufferLength = this.bufferLength;
  12895. if (n === 32) {
  12896. if (bufferLength === 0) {
  12897. return ((this.stream.getByte() << 24) |
  12898. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  12899. this.stream.getByte()) >>> 0;
  12900. }
  12901. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  12902. (this.stream.getByte() << 8) | this.stream.getByte();
  12903. var nextByte = this.stream.getByte();
  12904. this.buffer = nextByte & ((1 << bufferLength) - 1);
  12905. return ((buffer << (8 - bufferLength)) |
  12906. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  12907. }
  12908. if (n === 8 && bufferLength === 0) {
  12909. return this.stream.getByte();
  12910. }
  12911. while (bufferLength < n) {
  12912. buffer = (buffer << 8) | this.stream.getByte();
  12913. bufferLength += 8;
  12914. }
  12915. bufferLength -= n;
  12916. this.bufferLength = bufferLength;
  12917. this.buffer = buffer & ((1 << bufferLength) - 1);
  12918. return buffer >> bufferLength;
  12919. },
  12920. align: function MeshStreamReader_align() {
  12921. this.buffer = 0;
  12922. this.bufferLength = 0;
  12923. },
  12924. readFlag: function MeshStreamReader_readFlag() {
  12925. return this.readBits(this.context.bitsPerFlag);
  12926. },
  12927. readCoordinate: function MeshStreamReader_readCoordinate() {
  12928. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  12929. var xi = this.readBits(bitsPerCoordinate);
  12930. var yi = this.readBits(bitsPerCoordinate);
  12931. var decode = this.context.decode;
  12932. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  12933. 2.3283064365386963e-10; // 2 ^ -32
  12934. return [
  12935. xi * scale * (decode[1] - decode[0]) + decode[0],
  12936. yi * scale * (decode[3] - decode[2]) + decode[2]
  12937. ];
  12938. },
  12939. readComponents: function MeshStreamReader_readComponents() {
  12940. var numComps = this.context.numComps;
  12941. var bitsPerComponent = this.context.bitsPerComponent;
  12942. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  12943. 2.3283064365386963e-10; // 2 ^ -32
  12944. var decode = this.context.decode;
  12945. var components = this.tmpCompsBuf;
  12946. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  12947. var ci = this.readBits(bitsPerComponent);
  12948. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  12949. }
  12950. var color = this.tmpCsCompsBuf;
  12951. if (this.context.colorFn) {
  12952. this.context.colorFn(components, 0, color, 0);
  12953. }
  12954. return this.context.colorSpace.getRgb(color, 0);
  12955. }
  12956. };
  12957. function decodeType4Shading(mesh, reader) {
  12958. var coords = mesh.coords;
  12959. var colors = mesh.colors;
  12960. var operators = [];
  12961. var ps = []; // not maintaining cs since that will match ps
  12962. var verticesLeft = 0; // assuming we have all data to start a new triangle
  12963. while (reader.hasData) {
  12964. var f = reader.readFlag();
  12965. var coord = reader.readCoordinate();
  12966. var color = reader.readComponents();
  12967. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  12968. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  12969. switch (f) {
  12970. case 0:
  12971. verticesLeft = 3;
  12972. break;
  12973. case 1:
  12974. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  12975. verticesLeft = 1;
  12976. break;
  12977. case 2:
  12978. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  12979. verticesLeft = 1;
  12980. break;
  12981. }
  12982. operators.push(f);
  12983. }
  12984. ps.push(coords.length);
  12985. coords.push(coord);
  12986. colors.push(color);
  12987. verticesLeft--;
  12988. reader.align();
  12989. }
  12990. var psPacked = new Int32Array(ps);
  12991. mesh.figures.push({
  12992. type: 'triangles',
  12993. coords: psPacked,
  12994. colors: psPacked
  12995. });
  12996. }
  12997. function decodeType5Shading(mesh, reader, verticesPerRow) {
  12998. var coords = mesh.coords;
  12999. var colors = mesh.colors;
  13000. var ps = []; // not maintaining cs since that will match ps
  13001. while (reader.hasData) {
  13002. var coord = reader.readCoordinate();
  13003. var color = reader.readComponents();
  13004. ps.push(coords.length);
  13005. coords.push(coord);
  13006. colors.push(color);
  13007. }
  13008. var psPacked = new Int32Array(ps);
  13009. mesh.figures.push({
  13010. type: 'lattice',
  13011. coords: psPacked,
  13012. colors: psPacked,
  13013. verticesPerRow: verticesPerRow
  13014. });
  13015. }
  13016. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  13017. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  13018. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  13019. var getB = (function getBClosure() {
  13020. function buildB(count) {
  13021. var lut = [];
  13022. for (var i = 0; i <= count; i++) {
  13023. var t = i / count, t_ = 1 - t;
  13024. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  13025. 3 * t * t * t_, t * t * t]));
  13026. }
  13027. return lut;
  13028. }
  13029. var cache = [];
  13030. return function getB(count) {
  13031. if (!cache[count]) {
  13032. cache[count] = buildB(count);
  13033. }
  13034. return cache[count];
  13035. };
  13036. })();
  13037. function buildFigureFromPatch(mesh, index) {
  13038. var figure = mesh.figures[index];
  13039. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  13040. var coords = mesh.coords, colors = mesh.colors;
  13041. var pi = figure.coords;
  13042. var ci = figure.colors;
  13043. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  13044. coords[pi[12]][0], coords[pi[15]][0]);
  13045. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  13046. coords[pi[12]][1], coords[pi[15]][1]);
  13047. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  13048. coords[pi[12]][0], coords[pi[15]][0]);
  13049. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  13050. coords[pi[12]][1], coords[pi[15]][1]);
  13051. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  13052. (mesh.bounds[2] - mesh.bounds[0]));
  13053. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  13054. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  13055. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  13056. (mesh.bounds[3] - mesh.bounds[1]));
  13057. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  13058. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  13059. var verticesPerRow = splitXBy + 1;
  13060. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  13061. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  13062. var k = 0;
  13063. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  13064. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  13065. c2 = colors[ci[2]], c3 = colors[ci[3]];
  13066. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  13067. for (var row = 0; row <= splitYBy; row++) {
  13068. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  13069. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  13070. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  13071. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  13072. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  13073. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  13074. for (var col = 0; col <= splitXBy; col++, k++) {
  13075. if ((row === 0 || row === splitYBy) &&
  13076. (col === 0 || col === splitXBy)) {
  13077. continue;
  13078. }
  13079. var x = 0, y = 0;
  13080. var q = 0;
  13081. for (var i = 0; i <= 3; i++) {
  13082. for (var j = 0; j <= 3; j++, q++) {
  13083. var m = bRow[row][i] * bCol[col][j];
  13084. x += coords[pi[q]][0] * m;
  13085. y += coords[pi[q]][1] * m;
  13086. }
  13087. }
  13088. figureCoords[k] = coords.length;
  13089. coords.push([x, y]);
  13090. figureColors[k] = colors.length;
  13091. var newColor = new Uint8Array(3);
  13092. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  13093. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  13094. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  13095. colors.push(newColor);
  13096. }
  13097. }
  13098. figureCoords[0] = pi[0];
  13099. figureColors[0] = ci[0];
  13100. figureCoords[splitXBy] = pi[3];
  13101. figureColors[splitXBy] = ci[1];
  13102. figureCoords[verticesPerRow * splitYBy] = pi[12];
  13103. figureColors[verticesPerRow * splitYBy] = ci[2];
  13104. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  13105. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  13106. mesh.figures[index] = {
  13107. type: 'lattice',
  13108. coords: figureCoords,
  13109. colors: figureColors,
  13110. verticesPerRow: verticesPerRow
  13111. };
  13112. }
  13113. function decodeType6Shading(mesh, reader) {
  13114. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  13115. var coords = mesh.coords;
  13116. var colors = mesh.colors;
  13117. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  13118. var cs = new Int32Array(4); // c00, c30, c03, c33
  13119. while (reader.hasData) {
  13120. var f = reader.readFlag();
  13121. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  13122. var i, ii;
  13123. var pi = coords.length;
  13124. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  13125. coords.push(reader.readCoordinate());
  13126. }
  13127. var ci = colors.length;
  13128. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  13129. colors.push(reader.readComponents());
  13130. }
  13131. var tmp1, tmp2, tmp3, tmp4;
  13132. switch (f) {
  13133. case 0:
  13134. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  13135. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  13136. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  13137. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  13138. cs[2] = ci + 1; cs[3] = ci + 2;
  13139. cs[0] = ci; cs[1] = ci + 3;
  13140. break;
  13141. case 1:
  13142. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  13143. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  13144. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  13145. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  13146. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  13147. tmp1 = cs[2]; tmp2 = cs[3];
  13148. cs[2] = ci + 1; cs[3] = ci;
  13149. cs[0] = tmp1; cs[1] = tmp2;
  13150. break;
  13151. case 2:
  13152. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  13153. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  13154. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  13155. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  13156. cs[2] = cs[3]; cs[3] = ci + 1;
  13157. cs[0] = cs[1]; cs[1] = ci;
  13158. break;
  13159. case 3:
  13160. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  13161. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  13162. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  13163. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  13164. cs[2] = cs[0]; cs[3] = cs[1];
  13165. cs[0] = ci; cs[1] = ci + 1;
  13166. break;
  13167. }
  13168. // set p11, p12, p21, p22
  13169. ps[5] = coords.length;
  13170. coords.push([
  13171. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  13172. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  13173. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  13174. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  13175. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  13176. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  13177. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  13178. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  13179. ]);
  13180. ps[6] = coords.length;
  13181. coords.push([
  13182. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  13183. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  13184. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  13185. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  13186. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  13187. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  13188. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  13189. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  13190. ]);
  13191. ps[9] = coords.length;
  13192. coords.push([
  13193. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  13194. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  13195. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  13196. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  13197. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  13198. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  13199. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  13200. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  13201. ]);
  13202. ps[10] = coords.length;
  13203. coords.push([
  13204. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  13205. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  13206. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  13207. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  13208. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  13209. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  13210. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  13211. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  13212. ]);
  13213. mesh.figures.push({
  13214. type: 'patch',
  13215. coords: new Int32Array(ps), // making copies of ps and cs
  13216. colors: new Int32Array(cs)
  13217. });
  13218. }
  13219. }
  13220. function decodeType7Shading(mesh, reader) {
  13221. var coords = mesh.coords;
  13222. var colors = mesh.colors;
  13223. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  13224. var cs = new Int32Array(4); // c00, c30, c03, c33
  13225. while (reader.hasData) {
  13226. var f = reader.readFlag();
  13227. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  13228. var i, ii;
  13229. var pi = coords.length;
  13230. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  13231. coords.push(reader.readCoordinate());
  13232. }
  13233. var ci = colors.length;
  13234. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  13235. colors.push(reader.readComponents());
  13236. }
  13237. var tmp1, tmp2, tmp3, tmp4;
  13238. switch (f) {
  13239. case 0:
  13240. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  13241. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  13242. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  13243. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  13244. cs[2] = ci + 1; cs[3] = ci + 2;
  13245. cs[0] = ci; cs[1] = ci + 3;
  13246. break;
  13247. case 1:
  13248. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  13249. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  13250. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  13251. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  13252. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  13253. tmp1 = cs[2]; tmp2 = cs[3];
  13254. cs[2] = ci + 1; cs[3] = ci;
  13255. cs[0] = tmp1; cs[1] = tmp2;
  13256. break;
  13257. case 2:
  13258. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  13259. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  13260. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  13261. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  13262. cs[2] = cs[3]; cs[3] = ci + 1;
  13263. cs[0] = cs[1]; cs[1] = ci;
  13264. break;
  13265. case 3:
  13266. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  13267. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  13268. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  13269. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  13270. cs[2] = cs[0]; cs[3] = cs[1];
  13271. cs[0] = ci; cs[1] = ci + 1;
  13272. break;
  13273. }
  13274. mesh.figures.push({
  13275. type: 'patch',
  13276. coords: new Int32Array(ps), // making copies of ps and cs
  13277. colors: new Int32Array(cs)
  13278. });
  13279. }
  13280. }
  13281. function updateBounds(mesh) {
  13282. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  13283. maxX = minX, maxY = minY;
  13284. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  13285. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  13286. minX = minX > x ? x : minX;
  13287. minY = minY > y ? y : minY;
  13288. maxX = maxX < x ? x : maxX;
  13289. maxY = maxY < y ? y : maxY;
  13290. }
  13291. mesh.bounds = [minX, minY, maxX, maxY];
  13292. }
  13293. function packData(mesh) {
  13294. var i, ii, j, jj;
  13295. var coords = mesh.coords;
  13296. var coordsPacked = new Float32Array(coords.length * 2);
  13297. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  13298. var xy = coords[i];
  13299. coordsPacked[j++] = xy[0];
  13300. coordsPacked[j++] = xy[1];
  13301. }
  13302. mesh.coords = coordsPacked;
  13303. var colors = mesh.colors;
  13304. var colorsPacked = new Uint8Array(colors.length * 3);
  13305. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  13306. var c = colors[i];
  13307. colorsPacked[j++] = c[0];
  13308. colorsPacked[j++] = c[1];
  13309. colorsPacked[j++] = c[2];
  13310. }
  13311. mesh.colors = colorsPacked;
  13312. var figures = mesh.figures;
  13313. for (i = 0, ii = figures.length; i < ii; i++) {
  13314. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  13315. for (j = 0, jj = ps.length; j < jj; j++) {
  13316. ps[j] *= 2;
  13317. cs[j] *= 3;
  13318. }
  13319. }
  13320. }
  13321. function Mesh(stream, matrix, xref, res) {
  13322. assert(isStream(stream), 'Mesh data is not a stream');
  13323. var dict = stream.dict;
  13324. this.matrix = matrix;
  13325. this.shadingType = dict.get('ShadingType');
  13326. this.type = 'Pattern';
  13327. this.bbox = dict.get('BBox');
  13328. var cs = dict.get('ColorSpace', 'CS');
  13329. cs = ColorSpace.parse(cs, xref, res);
  13330. this.cs = cs;
  13331. this.background = dict.has('Background') ?
  13332. cs.getRgb(dict.get('Background'), 0) : null;
  13333. var fnObj = dict.get('Function');
  13334. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  13335. this.coords = [];
  13336. this.colors = [];
  13337. this.figures = [];
  13338. var decodeContext = {
  13339. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  13340. bitsPerComponent: dict.get('BitsPerComponent'),
  13341. bitsPerFlag: dict.get('BitsPerFlag'),
  13342. decode: dict.get('Decode'),
  13343. colorFn: fn,
  13344. colorSpace: cs,
  13345. numComps: fn ? 1 : cs.numComps
  13346. };
  13347. var reader = new MeshStreamReader(stream, decodeContext);
  13348. var patchMesh = false;
  13349. switch (this.shadingType) {
  13350. case PatternType.FREE_FORM_MESH:
  13351. decodeType4Shading(this, reader);
  13352. break;
  13353. case PatternType.LATTICE_FORM_MESH:
  13354. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  13355. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  13356. decodeType5Shading(this, reader, verticesPerRow);
  13357. break;
  13358. case PatternType.COONS_PATCH_MESH:
  13359. decodeType6Shading(this, reader);
  13360. patchMesh = true;
  13361. break;
  13362. case PatternType.TENSOR_PATCH_MESH:
  13363. decodeType7Shading(this, reader);
  13364. patchMesh = true;
  13365. break;
  13366. default:
  13367. error('Unsupported mesh type.');
  13368. break;
  13369. }
  13370. if (patchMesh) {
  13371. // dirty bounds calculation for determining, how dense shall be triangles
  13372. updateBounds(this);
  13373. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  13374. buildFigureFromPatch(this, i);
  13375. }
  13376. }
  13377. // calculate bounds
  13378. updateBounds(this);
  13379. packData(this);
  13380. }
  13381. Mesh.prototype = {
  13382. getIR: function Mesh_getIR() {
  13383. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  13384. this.bounds, this.matrix, this.bbox, this.background];
  13385. }
  13386. };
  13387. return Mesh;
  13388. })();
  13389. Shadings.Dummy = (function DummyClosure() {
  13390. function Dummy() {
  13391. this.type = 'Pattern';
  13392. }
  13393. Dummy.prototype = {
  13394. getIR: function Dummy_getIR() {
  13395. return ['Dummy'];
  13396. }
  13397. };
  13398. return Dummy;
  13399. })();
  13400. function getTilingPatternIR(operatorList, dict, args) {
  13401. var matrix = dict.get('Matrix');
  13402. var bbox = dict.get('BBox');
  13403. var xstep = dict.get('XStep');
  13404. var ystep = dict.get('YStep');
  13405. var paintType = dict.get('PaintType');
  13406. var tilingType = dict.get('TilingType');
  13407. return [
  13408. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  13409. paintType, tilingType
  13410. ];
  13411. }
  13412. var PartialEvaluator = (function PartialEvaluatorClosure() {
  13413. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  13414. uniquePrefix, idCounters, fontCache) {
  13415. this.pdfManager = pdfManager;
  13416. this.xref = xref;
  13417. this.handler = handler;
  13418. this.pageIndex = pageIndex;
  13419. this.uniquePrefix = uniquePrefix;
  13420. this.idCounters = idCounters;
  13421. this.fontCache = fontCache;
  13422. }
  13423. // Trying to minimize Date.now() usage and check every 100 time
  13424. var TIME_SLOT_DURATION_MS = 20;
  13425. var CHECK_TIME_EVERY = 100;
  13426. function TimeSlotManager() {
  13427. this.reset();
  13428. }
  13429. TimeSlotManager.prototype = {
  13430. check: function TimeSlotManager_check() {
  13431. if (++this.checked < CHECK_TIME_EVERY) {
  13432. return false;
  13433. }
  13434. this.checked = 0;
  13435. return this.endTime <= Date.now();
  13436. },
  13437. reset: function TimeSlotManager_reset() {
  13438. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  13439. this.checked = 0;
  13440. }
  13441. };
  13442. var deferred = Promise.resolve();
  13443. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  13444. PartialEvaluator.prototype = {
  13445. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  13446. if (!isDict(resources)) {
  13447. return false;
  13448. }
  13449. var processed = Object.create(null);
  13450. if (resources.objId) {
  13451. processed[resources.objId] = true;
  13452. }
  13453. var nodes = [resources];
  13454. while (nodes.length) {
  13455. var key;
  13456. var node = nodes.shift();
  13457. // First check the current resources for blend modes.
  13458. var graphicStates = node.get('ExtGState');
  13459. if (isDict(graphicStates)) {
  13460. graphicStates = graphicStates.getAll();
  13461. for (key in graphicStates) {
  13462. var graphicState = graphicStates[key];
  13463. var bm = graphicState['BM'];
  13464. if (isName(bm) && bm.name !== 'Normal') {
  13465. return true;
  13466. }
  13467. }
  13468. }
  13469. // Descend into the XObjects to look for more resources and blend modes.
  13470. var xObjects = node.get('XObject');
  13471. if (!isDict(xObjects)) {
  13472. continue;
  13473. }
  13474. xObjects = xObjects.getAll();
  13475. for (key in xObjects) {
  13476. var xObject = xObjects[key];
  13477. if (!isStream(xObject)) {
  13478. continue;
  13479. }
  13480. if (xObject.dict.objId) {
  13481. if (processed[xObject.dict.objId]) {
  13482. // stream has objId and is processed already
  13483. continue;
  13484. }
  13485. processed[xObject.dict.objId] = true;
  13486. }
  13487. var xResources = xObject.dict.get('Resources');
  13488. // Checking objId to detect an infinite loop.
  13489. if (isDict(xResources) &&
  13490. (!xResources.objId || !processed[xResources.objId])) {
  13491. nodes.push(xResources);
  13492. if (xResources.objId) {
  13493. processed[xResources.objId] = true;
  13494. }
  13495. }
  13496. }
  13497. }
  13498. return false;
  13499. },
  13500. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  13501. xobj, smask,
  13502. operatorList,
  13503. initialState) {
  13504. var matrix = xobj.dict.get('Matrix');
  13505. var bbox = xobj.dict.get('BBox');
  13506. var group = xobj.dict.get('Group');
  13507. if (group) {
  13508. var groupOptions = {
  13509. matrix: matrix,
  13510. bbox: bbox,
  13511. smask: smask,
  13512. isolated: false,
  13513. knockout: false
  13514. };
  13515. var groupSubtype = group.get('S');
  13516. var colorSpace;
  13517. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  13518. groupOptions.isolated = (group.get('I') || false);
  13519. groupOptions.knockout = (group.get('K') || false);
  13520. colorSpace = (group.has('CS') ?
  13521. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  13522. }
  13523. if (smask && smask.backdrop) {
  13524. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  13525. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  13526. }
  13527. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  13528. }
  13529. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  13530. return this.getOperatorList(xobj,
  13531. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  13532. then(function () {
  13533. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  13534. if (group) {
  13535. operatorList.addOp(OPS.endGroup, [groupOptions]);
  13536. }
  13537. });
  13538. },
  13539. buildPaintImageXObject:
  13540. function PartialEvaluator_buildPaintImageXObject(resources, image,
  13541. inline, operatorList,
  13542. cacheKey, cache) {
  13543. var self = this;
  13544. var dict = image.dict;
  13545. var w = dict.get('Width', 'W');
  13546. var h = dict.get('Height', 'H');
  13547. if (!(w && isNum(w)) || !(h && isNum(h))) {
  13548. warn('Image dimensions are missing, or not numbers.');
  13549. return;
  13550. }
  13551. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  13552. warn('Image exceeded maximum allowed size and was removed.');
  13553. return;
  13554. }
  13555. var imageMask = (dict.get('ImageMask', 'IM') || false);
  13556. var imgData, args;
  13557. if (imageMask) {
  13558. // This depends on a tmpCanvas being filled with the
  13559. // current fillStyle, such that processing the pixel
  13560. // data can't be done here. Instead of creating a
  13561. // complete PDFImage, only read the information needed
  13562. // for later.
  13563. var width = dict.get('Width', 'W');
  13564. var height = dict.get('Height', 'H');
  13565. var bitStrideLength = (width + 7) >> 3;
  13566. var imgArray = image.getBytes(bitStrideLength * height);
  13567. var decode = dict.get('Decode', 'D');
  13568. var inverseDecode = (!!decode && decode[0] > 0);
  13569. imgData = PDFImage.createMask(imgArray, width, height,
  13570. image instanceof DecodeStream,
  13571. inverseDecode);
  13572. imgData.cached = true;
  13573. args = [imgData];
  13574. operatorList.addOp(OPS.paintImageMaskXObject, args);
  13575. if (cacheKey) {
  13576. cache.key = cacheKey;
  13577. cache.fn = OPS.paintImageMaskXObject;
  13578. cache.args = args;
  13579. }
  13580. return;
  13581. }
  13582. var softMask = (dict.get('SMask', 'SM') || false);
  13583. var mask = (dict.get('Mask') || false);
  13584. var SMALL_IMAGE_DIMENSIONS = 200;
  13585. // Inlining small images into the queue as RGB data
  13586. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  13587. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  13588. var imageObj = new PDFImage(this.xref, resources, image,
  13589. inline, null, null);
  13590. // We force the use of RGBA_32BPP images here, because we can't handle
  13591. // any other kind.
  13592. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  13593. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  13594. return;
  13595. }
  13596. // If there is no imageMask, create the PDFImage and a lot
  13597. // of image processing can be done here.
  13598. var uniquePrefix = (this.uniquePrefix || '');
  13599. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  13600. operatorList.addDependency(objId);
  13601. args = [objId, w, h];
  13602. if (!softMask && !mask && image instanceof JpegStream &&
  13603. image.isNativelySupported(this.xref, resources)) {
  13604. // These JPEGs don't need any more processing so we can just send it.
  13605. operatorList.addOp(OPS.paintJpegXObject, args);
  13606. this.handler.send('obj',
  13607. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  13608. return;
  13609. }
  13610. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  13611. then(function(imageObj) {
  13612. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  13613. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  13614. [imgData.data.buffer]);
  13615. }).then(null, function (reason) {
  13616. warn('Unable to decode image: ' + reason);
  13617. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  13618. });
  13619. operatorList.addOp(OPS.paintImageXObject, args);
  13620. if (cacheKey) {
  13621. cache.key = cacheKey;
  13622. cache.fn = OPS.paintImageXObject;
  13623. cache.args = args;
  13624. }
  13625. },
  13626. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  13627. operatorList,
  13628. stateManager) {
  13629. var smaskContent = smask.get('G');
  13630. var smaskOptions = {
  13631. subtype: smask.get('S').name,
  13632. backdrop: smask.get('BC')
  13633. };
  13634. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  13635. operatorList, stateManager.state.clone());
  13636. },
  13637. handleTilingType:
  13638. function PartialEvaluator_handleTilingType(fn, args, resources,
  13639. pattern, patternDict,
  13640. operatorList) {
  13641. // Create an IR of the pattern code.
  13642. var tilingOpList = new OperatorList();
  13643. return this.getOperatorList(pattern,
  13644. (patternDict.get('Resources') || resources), tilingOpList).
  13645. then(function () {
  13646. // Add the dependencies to the parent operator list so they are
  13647. // resolved before sub operator list is executed synchronously.
  13648. operatorList.addDependencies(tilingOpList.dependencies);
  13649. operatorList.addOp(fn, getTilingPatternIR({
  13650. fnArray: tilingOpList.fnArray,
  13651. argsArray: tilingOpList.argsArray
  13652. }, patternDict, args));
  13653. });
  13654. },
  13655. handleSetFont:
  13656. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  13657. operatorList, state) {
  13658. // TODO(mack): Not needed?
  13659. var fontName;
  13660. if (fontArgs) {
  13661. fontArgs = fontArgs.slice();
  13662. fontName = fontArgs[0].name;
  13663. }
  13664. var self = this;
  13665. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  13666. function (translated) {
  13667. if (!translated.font.isType3Font) {
  13668. return translated;
  13669. }
  13670. return translated.loadType3Data(self, resources, operatorList).then(
  13671. function () {
  13672. return translated;
  13673. });
  13674. }).then(function (translated) {
  13675. state.font = translated.font;
  13676. translated.send(self.handler);
  13677. return translated.loadedName;
  13678. });
  13679. },
  13680. handleText: function PartialEvaluator_handleText(chars, state) {
  13681. var font = state.font;
  13682. var glyphs = font.charsToGlyphs(chars);
  13683. var isAddToPathSet = !!(state.textRenderingMode &
  13684. TextRenderingMode.ADD_TO_PATH_FLAG);
  13685. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  13686. var buildPath = function (fontChar) {
  13687. if (!font.renderer.hasBuiltPath(fontChar)) {
  13688. var path = font.renderer.getPathJs(fontChar);
  13689. this.handler.send('commonobj', [
  13690. font.loadedName + '_path_' + fontChar,
  13691. 'FontPath',
  13692. path
  13693. ]);
  13694. }
  13695. }.bind(this);
  13696. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  13697. var glyph = glyphs[i];
  13698. if (glyph === null) {
  13699. continue;
  13700. }
  13701. buildPath(glyph.fontChar);
  13702. // If the glyph has an accent we need to build a path for its
  13703. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  13704. var accent = glyph.accent;
  13705. if (accent && accent.fontChar) {
  13706. buildPath(accent.fontChar);
  13707. }
  13708. }
  13709. }
  13710. return glyphs;
  13711. },
  13712. setGState: function PartialEvaluator_setGState(resources, gState,
  13713. operatorList, xref,
  13714. stateManager) {
  13715. // TODO(mack): This should be rewritten so that this function returns
  13716. // what should be added to the queue during each iteration
  13717. function setGStateForKey(gStateObj, key, value) {
  13718. switch (key) {
  13719. case 'Type':
  13720. break;
  13721. case 'LW':
  13722. case 'LC':
  13723. case 'LJ':
  13724. case 'ML':
  13725. case 'D':
  13726. case 'RI':
  13727. case 'FL':
  13728. case 'CA':
  13729. case 'ca':
  13730. gStateObj.push([key, value]);
  13731. break;
  13732. case 'Font':
  13733. promise = promise.then(function () {
  13734. return self.handleSetFont(resources, null, value[0],
  13735. operatorList, stateManager.state).
  13736. then(function (loadedName) {
  13737. operatorList.addDependency(loadedName);
  13738. gStateObj.push([key, [loadedName, value[1]]]);
  13739. });
  13740. });
  13741. break;
  13742. case 'BM':
  13743. gStateObj.push([key, value]);
  13744. break;
  13745. case 'SMask':
  13746. if (isName(value) && value.name === 'None') {
  13747. gStateObj.push([key, false]);
  13748. break;
  13749. }
  13750. var dict = xref.fetchIfRef(value);
  13751. if (isDict(dict)) {
  13752. promise = promise.then(function () {
  13753. return self.handleSMask(dict, resources, operatorList,
  13754. stateManager);
  13755. });
  13756. gStateObj.push([key, true]);
  13757. } else {
  13758. warn('Unsupported SMask type');
  13759. }
  13760. break;
  13761. // Only generate info log messages for the following since
  13762. // they are unlikey to have a big impact on the rendering.
  13763. case 'OP':
  13764. case 'op':
  13765. case 'OPM':
  13766. case 'BG':
  13767. case 'BG2':
  13768. case 'UCR':
  13769. case 'UCR2':
  13770. case 'TR':
  13771. case 'TR2':
  13772. case 'HT':
  13773. case 'SM':
  13774. case 'SA':
  13775. case 'AIS':
  13776. case 'TK':
  13777. // TODO implement these operators.
  13778. info('graphic state operator ' + key);
  13779. break;
  13780. default:
  13781. info('Unknown graphic state operator ' + key);
  13782. break;
  13783. }
  13784. }
  13785. // This array holds the converted/processed state data.
  13786. var gStateObj = [];
  13787. var gStateMap = gState.map;
  13788. var self = this;
  13789. var promise = Promise.resolve();
  13790. for (var key in gStateMap) {
  13791. var value = gStateMap[key];
  13792. setGStateForKey(gStateObj, key, value);
  13793. }
  13794. return promise.then(function () {
  13795. operatorList.addOp(OPS.setGState, [gStateObj]);
  13796. });
  13797. },
  13798. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  13799. resources) {
  13800. function errorFont() {
  13801. return Promise.resolve(new TranslatedFont('g_font_error',
  13802. new ErrorFont('Font ' + fontName + ' is not available'), font));
  13803. }
  13804. var fontRef;
  13805. if (font) { // Loading by ref.
  13806. assert(isRef(font));
  13807. fontRef = font;
  13808. } else { // Loading by name.
  13809. var fontRes = resources.get('Font');
  13810. if (fontRes) {
  13811. fontRef = fontRes.getRaw(fontName);
  13812. } else {
  13813. warn('fontRes not available');
  13814. return errorFont();
  13815. }
  13816. }
  13817. if (!fontRef) {
  13818. warn('fontRef not available');
  13819. return errorFont();
  13820. }
  13821. if (this.fontCache.has(fontRef)) {
  13822. return this.fontCache.get(fontRef);
  13823. }
  13824. font = xref.fetchIfRef(fontRef);
  13825. if (!isDict(font)) {
  13826. return errorFont();
  13827. }
  13828. // We are holding font.translated references just for fontRef that are not
  13829. // dictionaries (Dict). See explanation below.
  13830. if (font.translated) {
  13831. return font.translated;
  13832. }
  13833. var fontCapability = createPromiseCapability();
  13834. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  13835. var descriptor = preEvaluatedFont.descriptor;
  13836. var fontID = fontRef.num + '_' + fontRef.gen;
  13837. if (isDict(descriptor)) {
  13838. if (!descriptor.fontAliases) {
  13839. descriptor.fontAliases = Object.create(null);
  13840. }
  13841. var fontAliases = descriptor.fontAliases;
  13842. var hash = preEvaluatedFont.hash;
  13843. if (fontAliases[hash]) {
  13844. var aliasFontRef = fontAliases[hash].aliasRef;
  13845. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  13846. this.fontCache.putAlias(fontRef, aliasFontRef);
  13847. return this.fontCache.get(fontRef);
  13848. }
  13849. }
  13850. if (!fontAliases[hash]) {
  13851. fontAliases[hash] = {
  13852. fontID: Font.getFontID()
  13853. };
  13854. }
  13855. fontAliases[hash].aliasRef = fontRef;
  13856. fontID = fontAliases[hash].fontID;
  13857. }
  13858. // Workaround for bad PDF generators that don't reference fonts
  13859. // properly, i.e. by not using an object identifier.
  13860. // Check if the fontRef is a Dict (as opposed to a standard object),
  13861. // in which case we don't cache the font and instead reference it by
  13862. // fontName in font.loadedName below.
  13863. var fontRefIsDict = isDict(fontRef);
  13864. if (!fontRefIsDict) {
  13865. this.fontCache.put(fontRef, fontCapability.promise);
  13866. }
  13867. // Keep track of each font we translated so the caller can
  13868. // load them asynchronously before calling display on a page.
  13869. font.loadedName = 'g_font_' + (fontRefIsDict ?
  13870. fontName.replace(/\W/g, '') : fontID);
  13871. font.translated = fontCapability.promise;
  13872. // TODO move promises into translate font
  13873. var translatedPromise;
  13874. try {
  13875. translatedPromise = Promise.resolve(
  13876. this.translateFont(preEvaluatedFont, xref));
  13877. } catch (e) {
  13878. translatedPromise = Promise.reject(e);
  13879. }
  13880. translatedPromise.then(function (translatedFont) {
  13881. if (translatedFont.fontType !== undefined) {
  13882. var xrefFontStats = xref.stats.fontTypes;
  13883. xrefFontStats[translatedFont.fontType] = true;
  13884. }
  13885. fontCapability.resolve(new TranslatedFont(font.loadedName,
  13886. translatedFont, font));
  13887. }, function (reason) {
  13888. // TODO fontCapability.reject?
  13889. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  13890. try {
  13891. // error, but it's still nice to have font type reported
  13892. var descriptor = preEvaluatedFont.descriptor;
  13893. var fontFile3 = descriptor && descriptor.get('FontFile3');
  13894. var subtype = fontFile3 && fontFile3.get('Subtype');
  13895. var fontType = getFontType(preEvaluatedFont.type,
  13896. subtype && subtype.name);
  13897. var xrefFontStats = xref.stats.fontTypes;
  13898. xrefFontStats[fontType] = true;
  13899. } catch (ex) { }
  13900. fontCapability.resolve(new TranslatedFont(font.loadedName,
  13901. new ErrorFont(reason instanceof Error ? reason.message : reason),
  13902. font));
  13903. });
  13904. return fontCapability.promise;
  13905. },
  13906. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  13907. var lastIndex = operatorList.length - 1;
  13908. if (lastIndex < 0 ||
  13909. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  13910. operatorList.addOp(OPS.constructPath, [[fn], args]);
  13911. } else {
  13912. var opArgs = operatorList.argsArray[lastIndex];
  13913. opArgs[0].push(fn);
  13914. Array.prototype.push.apply(opArgs[1], args);
  13915. }
  13916. },
  13917. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  13918. cs, patterns, resources, xref) {
  13919. // compile tiling patterns
  13920. var patternName = args[args.length - 1];
  13921. // SCN/scn applies patterns along with normal colors
  13922. var pattern;
  13923. if (isName(patternName) &&
  13924. (pattern = patterns.get(patternName.name))) {
  13925. var dict = (isStream(pattern) ? pattern.dict : pattern);
  13926. var typeNum = dict.get('PatternType');
  13927. if (typeNum === TILING_PATTERN) {
  13928. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  13929. return this.handleTilingType(fn, color, resources, pattern,
  13930. dict, operatorList);
  13931. } else if (typeNum === SHADING_PATTERN) {
  13932. var shading = dict.get('Shading');
  13933. var matrix = dict.get('Matrix');
  13934. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  13935. operatorList.addOp(fn, pattern.getIR());
  13936. return Promise.resolve();
  13937. } else {
  13938. return Promise.reject('Unknown PatternType: ' + typeNum);
  13939. }
  13940. }
  13941. // TODO shall we fail here?
  13942. operatorList.addOp(fn, args);
  13943. return Promise.resolve();
  13944. },
  13945. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  13946. resources,
  13947. operatorList,
  13948. initialState) {
  13949. var self = this;
  13950. var xref = this.xref;
  13951. var imageCache = {};
  13952. assert(operatorList);
  13953. resources = (resources || Dict.empty);
  13954. var xobjs = (resources.get('XObject') || Dict.empty);
  13955. var patterns = (resources.get('Pattern') || Dict.empty);
  13956. var stateManager = new StateManager(initialState || new EvalState());
  13957. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  13958. var timeSlotManager = new TimeSlotManager();
  13959. return new Promise(function next(resolve, reject) {
  13960. timeSlotManager.reset();
  13961. var stop, operation = {}, i, ii, cs;
  13962. while (!(stop = timeSlotManager.check()) &&
  13963. preprocessor.read(operation)) {
  13964. var args = operation.args;
  13965. var fn = operation.fn;
  13966. switch (fn | 0) {
  13967. case OPS.paintXObject:
  13968. if (args[0].code) {
  13969. break;
  13970. }
  13971. // eagerly compile XForm objects
  13972. var name = args[0].name;
  13973. if (imageCache.key === name) {
  13974. operatorList.addOp(imageCache.fn, imageCache.args);
  13975. args = null;
  13976. continue;
  13977. }
  13978. var xobj = xobjs.get(name);
  13979. if (xobj) {
  13980. assert(isStream(xobj), 'XObject should be a stream');
  13981. var type = xobj.dict.get('Subtype');
  13982. assert(isName(type),
  13983. 'XObject should have a Name subtype');
  13984. if (type.name === 'Form') {
  13985. stateManager.save();
  13986. return self.buildFormXObject(resources, xobj, null,
  13987. operatorList,
  13988. stateManager.state.clone()).
  13989. then(function () {
  13990. stateManager.restore();
  13991. next(resolve, reject);
  13992. }, reject);
  13993. } else if (type.name === 'Image') {
  13994. self.buildPaintImageXObject(resources, xobj, false,
  13995. operatorList, name, imageCache);
  13996. args = null;
  13997. continue;
  13998. } else if (type.name === 'PS') {
  13999. // PostScript XObjects are unused when viewing documents.
  14000. // See section 4.7.1 of Adobe's PDF reference.
  14001. info('Ignored XObject subtype PS');
  14002. continue;
  14003. } else {
  14004. error('Unhandled XObject subtype ' + type.name);
  14005. }
  14006. }
  14007. break;
  14008. case OPS.setFont:
  14009. var fontSize = args[1];
  14010. // eagerly collect all fonts
  14011. return self.handleSetFont(resources, args, null,
  14012. operatorList, stateManager.state).
  14013. then(function (loadedName) {
  14014. operatorList.addDependency(loadedName);
  14015. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  14016. next(resolve, reject);
  14017. }, reject);
  14018. case OPS.endInlineImage:
  14019. var cacheKey = args[0].cacheKey;
  14020. if (cacheKey && imageCache.key === cacheKey) {
  14021. operatorList.addOp(imageCache.fn, imageCache.args);
  14022. args = null;
  14023. continue;
  14024. }
  14025. self.buildPaintImageXObject(resources, args[0], true,
  14026. operatorList, cacheKey, imageCache);
  14027. args = null;
  14028. continue;
  14029. case OPS.showText:
  14030. args[0] = self.handleText(args[0], stateManager.state);
  14031. break;
  14032. case OPS.showSpacedText:
  14033. var arr = args[0];
  14034. var combinedGlyphs = [];
  14035. var arrLength = arr.length;
  14036. for (i = 0; i < arrLength; ++i) {
  14037. var arrItem = arr[i];
  14038. if (isString(arrItem)) {
  14039. Array.prototype.push.apply(combinedGlyphs,
  14040. self.handleText(arrItem, stateManager.state));
  14041. } else if (isNum(arrItem)) {
  14042. combinedGlyphs.push(arrItem);
  14043. }
  14044. }
  14045. args[0] = combinedGlyphs;
  14046. fn = OPS.showText;
  14047. break;
  14048. case OPS.nextLineShowText:
  14049. operatorList.addOp(OPS.nextLine);
  14050. args[0] = self.handleText(args[0], stateManager.state);
  14051. fn = OPS.showText;
  14052. break;
  14053. case OPS.nextLineSetSpacingShowText:
  14054. operatorList.addOp(OPS.nextLine);
  14055. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  14056. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  14057. args[0] = self.handleText(args[0], stateManager.state);
  14058. fn = OPS.showText;
  14059. break;
  14060. case OPS.setTextRenderingMode:
  14061. stateManager.state.textRenderingMode = args[0];
  14062. break;
  14063. case OPS.setFillColorSpace:
  14064. stateManager.state.fillColorSpace =
  14065. ColorSpace.parse(args[0], xref, resources);
  14066. continue;
  14067. case OPS.setStrokeColorSpace:
  14068. stateManager.state.strokeColorSpace =
  14069. ColorSpace.parse(args[0], xref, resources);
  14070. continue;
  14071. case OPS.setFillColor:
  14072. cs = stateManager.state.fillColorSpace;
  14073. args = cs.getRgb(args, 0);
  14074. fn = OPS.setFillRGBColor;
  14075. break;
  14076. case OPS.setStrokeColor:
  14077. cs = stateManager.state.strokeColorSpace;
  14078. args = cs.getRgb(args, 0);
  14079. fn = OPS.setStrokeRGBColor;
  14080. break;
  14081. case OPS.setFillGray:
  14082. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  14083. args = ColorSpace.singletons.gray.getRgb(args, 0);
  14084. fn = OPS.setFillRGBColor;
  14085. break;
  14086. case OPS.setStrokeGray:
  14087. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  14088. args = ColorSpace.singletons.gray.getRgb(args, 0);
  14089. fn = OPS.setStrokeRGBColor;
  14090. break;
  14091. case OPS.setFillCMYKColor:
  14092. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  14093. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  14094. fn = OPS.setFillRGBColor;
  14095. break;
  14096. case OPS.setStrokeCMYKColor:
  14097. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  14098. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  14099. fn = OPS.setStrokeRGBColor;
  14100. break;
  14101. case OPS.setFillRGBColor:
  14102. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  14103. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  14104. break;
  14105. case OPS.setStrokeRGBColor:
  14106. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  14107. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  14108. break;
  14109. case OPS.setFillColorN:
  14110. cs = stateManager.state.fillColorSpace;
  14111. if (cs.name === 'Pattern') {
  14112. return self.handleColorN(operatorList, OPS.setFillColorN,
  14113. args, cs, patterns, resources, xref).then(function() {
  14114. next(resolve, reject);
  14115. }, reject);
  14116. }
  14117. args = cs.getRgb(args, 0);
  14118. fn = OPS.setFillRGBColor;
  14119. break;
  14120. case OPS.setStrokeColorN:
  14121. cs = stateManager.state.strokeColorSpace;
  14122. if (cs.name === 'Pattern') {
  14123. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  14124. args, cs, patterns, resources, xref).then(function() {
  14125. next(resolve, reject);
  14126. }, reject);
  14127. }
  14128. args = cs.getRgb(args, 0);
  14129. fn = OPS.setStrokeRGBColor;
  14130. break;
  14131. case OPS.shadingFill:
  14132. var shadingRes = resources.get('Shading');
  14133. if (!shadingRes) {
  14134. error('No shading resource found');
  14135. }
  14136. var shading = shadingRes.get(args[0].name);
  14137. if (!shading) {
  14138. error('No shading object found');
  14139. }
  14140. var shadingFill = Pattern.parseShading(shading, null, xref,
  14141. resources);
  14142. var patternIR = shadingFill.getIR();
  14143. args = [patternIR];
  14144. fn = OPS.shadingFill;
  14145. break;
  14146. case OPS.setGState:
  14147. var dictName = args[0];
  14148. var extGState = resources.get('ExtGState');
  14149. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  14150. break;
  14151. }
  14152. var gState = extGState.get(dictName.name);
  14153. return self.setGState(resources, gState, operatorList, xref,
  14154. stateManager).then(function() {
  14155. next(resolve, reject);
  14156. }, reject);
  14157. case OPS.moveTo:
  14158. case OPS.lineTo:
  14159. case OPS.curveTo:
  14160. case OPS.curveTo2:
  14161. case OPS.curveTo3:
  14162. case OPS.closePath:
  14163. self.buildPath(operatorList, fn, args);
  14164. continue;
  14165. case OPS.rectangle:
  14166. self.buildPath(operatorList, fn, args);
  14167. continue;
  14168. }
  14169. operatorList.addOp(fn, args);
  14170. }
  14171. if (stop) {
  14172. deferred.then(function () {
  14173. next(resolve, reject);
  14174. });
  14175. return;
  14176. }
  14177. // Some PDFs don't close all restores inside object/form.
  14178. // Closing those for them.
  14179. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  14180. operatorList.addOp(OPS.restore, []);
  14181. }
  14182. resolve();
  14183. });
  14184. },
  14185. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  14186. stateManager) {
  14187. stateManager = (stateManager || new StateManager(new TextState()));
  14188. var textContent = {
  14189. items: [],
  14190. styles: Object.create(null)
  14191. };
  14192. var bidiTexts = textContent.items;
  14193. var SPACE_FACTOR = 0.35;
  14194. var MULTI_SPACE_FACTOR = 1.5;
  14195. var self = this;
  14196. var xref = this.xref;
  14197. resources = (xref.fetchIfRef(resources) || Dict.empty);
  14198. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  14199. var xobjs = null;
  14200. var xobjsCache = {};
  14201. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  14202. var textState;
  14203. function newTextChunk() {
  14204. var font = textState.font;
  14205. if (!(font.loadedName in textContent.styles)) {
  14206. textContent.styles[font.loadedName] = {
  14207. fontFamily: font.fallbackName,
  14208. ascent: font.ascent,
  14209. descent: font.descent,
  14210. vertical: font.vertical
  14211. };
  14212. }
  14213. return {
  14214. // |str| is initially an array which we push individual chars to, and
  14215. // then runBidi() overwrites it with the final string.
  14216. str: [],
  14217. dir: null,
  14218. width: 0,
  14219. height: 0,
  14220. transform: null,
  14221. fontName: font.loadedName
  14222. };
  14223. }
  14224. function runBidi(textChunk) {
  14225. var str = textChunk.str.join('');
  14226. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  14227. textChunk.str = bidiResult.str;
  14228. textChunk.dir = bidiResult.dir;
  14229. return textChunk;
  14230. }
  14231. function handleSetFont(fontName, fontRef) {
  14232. return self.loadFont(fontName, fontRef, xref, resources).
  14233. then(function (translated) {
  14234. textState.font = translated.font;
  14235. textState.fontMatrix = translated.font.fontMatrix ||
  14236. FONT_IDENTITY_MATRIX;
  14237. });
  14238. }
  14239. function buildTextGeometry(chars, textChunk) {
  14240. var font = textState.font;
  14241. textChunk = textChunk || newTextChunk();
  14242. if (!textChunk.transform) {
  14243. // 9.4.4 Text Space Details
  14244. var tsm = [textState.fontSize * textState.textHScale, 0,
  14245. 0, textState.fontSize,
  14246. 0, textState.textRise];
  14247. var trm = textChunk.transform = Util.transform(textState.ctm,
  14248. Util.transform(textState.textMatrix, tsm));
  14249. if (!font.vertical) {
  14250. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  14251. } else {
  14252. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  14253. }
  14254. }
  14255. var width = 0;
  14256. var height = 0;
  14257. var glyphs = font.charsToGlyphs(chars);
  14258. var defaultVMetrics = font.defaultVMetrics;
  14259. for (var i = 0; i < glyphs.length; i++) {
  14260. var glyph = glyphs[i];
  14261. if (!glyph) { // Previous glyph was a space.
  14262. width += textState.wordSpacing * textState.textHScale;
  14263. continue;
  14264. }
  14265. var vMetricX = null;
  14266. var vMetricY = null;
  14267. var glyphWidth = null;
  14268. if (font.vertical) {
  14269. if (glyph.vmetric) {
  14270. glyphWidth = glyph.vmetric[0];
  14271. vMetricX = glyph.vmetric[1];
  14272. vMetricY = glyph.vmetric[2];
  14273. } else {
  14274. glyphWidth = glyph.width;
  14275. vMetricX = glyph.width * 0.5;
  14276. vMetricY = defaultVMetrics[2];
  14277. }
  14278. } else {
  14279. glyphWidth = glyph.width;
  14280. }
  14281. var glyphUnicode = glyph.unicode;
  14282. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  14283. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  14284. }
  14285. glyphUnicode = reverseIfRtl(glyphUnicode);
  14286. // The following will calculate the x and y of the individual glyphs.
  14287. // if (font.vertical) {
  14288. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  14289. // textState.fontMatrix[0];
  14290. // tsm[5] -= vMetricY * textState.fontSize *
  14291. // textState.fontMatrix[0];
  14292. // }
  14293. // var trm = Util.transform(textState.textMatrix, tsm);
  14294. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  14295. // var x = pt[0];
  14296. // var y = pt[1];
  14297. var tx = 0;
  14298. var ty = 0;
  14299. if (!font.vertical) {
  14300. var w0 = glyphWidth * textState.fontMatrix[0];
  14301. tx = (w0 * textState.fontSize + textState.charSpacing) *
  14302. textState.textHScale;
  14303. width += tx;
  14304. } else {
  14305. var w1 = glyphWidth * textState.fontMatrix[0];
  14306. ty = w1 * textState.fontSize + textState.charSpacing;
  14307. height += ty;
  14308. }
  14309. textState.translateTextMatrix(tx, ty);
  14310. textChunk.str.push(glyphUnicode);
  14311. }
  14312. var a = textState.textLineMatrix[0];
  14313. var b = textState.textLineMatrix[1];
  14314. var scaleLineX = Math.sqrt(a * a + b * b);
  14315. a = textState.ctm[0];
  14316. b = textState.ctm[1];
  14317. var scaleCtmX = Math.sqrt(a * a + b * b);
  14318. if (!font.vertical) {
  14319. textChunk.width += width * scaleCtmX * scaleLineX;
  14320. } else {
  14321. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  14322. }
  14323. return textChunk;
  14324. }
  14325. var timeSlotManager = new TimeSlotManager();
  14326. return new Promise(function next(resolve, reject) {
  14327. timeSlotManager.reset();
  14328. var stop, operation = {};
  14329. while (!(stop = timeSlotManager.check()) &&
  14330. (preprocessor.read(operation))) {
  14331. textState = stateManager.state;
  14332. var fn = operation.fn;
  14333. var args = operation.args;
  14334. switch (fn | 0) {
  14335. case OPS.setFont:
  14336. textState.fontSize = args[1];
  14337. return handleSetFont(args[0].name).then(function() {
  14338. next(resolve, reject);
  14339. }, reject);
  14340. case OPS.setTextRise:
  14341. textState.textRise = args[0];
  14342. break;
  14343. case OPS.setHScale:
  14344. textState.textHScale = args[0] / 100;
  14345. break;
  14346. case OPS.setLeading:
  14347. textState.leading = args[0];
  14348. break;
  14349. case OPS.moveText:
  14350. textState.translateTextLineMatrix(args[0], args[1]);
  14351. textState.textMatrix = textState.textLineMatrix.slice();
  14352. break;
  14353. case OPS.setLeadingMoveText:
  14354. textState.leading = -args[1];
  14355. textState.translateTextLineMatrix(args[0], args[1]);
  14356. textState.textMatrix = textState.textLineMatrix.slice();
  14357. break;
  14358. case OPS.nextLine:
  14359. textState.carriageReturn();
  14360. break;
  14361. case OPS.setTextMatrix:
  14362. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  14363. args[4], args[5]);
  14364. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  14365. args[4], args[5]);
  14366. break;
  14367. case OPS.setCharSpacing:
  14368. textState.charSpacing = args[0];
  14369. break;
  14370. case OPS.setWordSpacing:
  14371. textState.wordSpacing = args[0];
  14372. break;
  14373. case OPS.beginText:
  14374. textState.textMatrix = IDENTITY_MATRIX.slice();
  14375. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  14376. break;
  14377. case OPS.showSpacedText:
  14378. var items = args[0];
  14379. var textChunk = newTextChunk();
  14380. var offset;
  14381. for (var j = 0, jj = items.length; j < jj; j++) {
  14382. if (typeof items[j] === 'string') {
  14383. buildTextGeometry(items[j], textChunk);
  14384. } else {
  14385. var val = items[j] / 1000;
  14386. if (!textState.font.vertical) {
  14387. offset = -val * textState.fontSize * textState.textHScale *
  14388. textState.textMatrix[0];
  14389. textState.translateTextMatrix(offset, 0);
  14390. textChunk.width += offset;
  14391. } else {
  14392. offset = -val * textState.fontSize *
  14393. textState.textMatrix[3];
  14394. textState.translateTextMatrix(0, offset);
  14395. textChunk.height += offset;
  14396. }
  14397. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  14398. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  14399. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  14400. fakeSpaces = Math.round(fakeSpaces);
  14401. while (fakeSpaces--) {
  14402. textChunk.str.push(' ');
  14403. }
  14404. } else if (fakeSpaces > SPACE_FACTOR) {
  14405. textChunk.str.push(' ');
  14406. }
  14407. }
  14408. }
  14409. }
  14410. bidiTexts.push(runBidi(textChunk));
  14411. break;
  14412. case OPS.showText:
  14413. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  14414. break;
  14415. case OPS.nextLineShowText:
  14416. textState.carriageReturn();
  14417. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  14418. break;
  14419. case OPS.nextLineSetSpacingShowText:
  14420. textState.wordSpacing = args[0];
  14421. textState.charSpacing = args[1];
  14422. textState.carriageReturn();
  14423. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  14424. break;
  14425. case OPS.paintXObject:
  14426. if (args[0].code) {
  14427. break;
  14428. }
  14429. if (!xobjs) {
  14430. xobjs = (resources.get('XObject') || Dict.empty);
  14431. }
  14432. var name = args[0].name;
  14433. if (xobjsCache.key === name) {
  14434. if (xobjsCache.texts) {
  14435. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  14436. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  14437. }
  14438. break;
  14439. }
  14440. var xobj = xobjs.get(name);
  14441. if (!xobj) {
  14442. break;
  14443. }
  14444. assert(isStream(xobj), 'XObject should be a stream');
  14445. var type = xobj.dict.get('Subtype');
  14446. assert(isName(type),
  14447. 'XObject should have a Name subtype');
  14448. if ('Form' !== type.name) {
  14449. xobjsCache.key = name;
  14450. xobjsCache.texts = null;
  14451. break;
  14452. }
  14453. stateManager.save();
  14454. var matrix = xobj.dict.get('Matrix');
  14455. if (isArray(matrix) && matrix.length === 6) {
  14456. stateManager.transform(matrix);
  14457. }
  14458. return self.getTextContent(xobj,
  14459. xobj.dict.get('Resources') || resources, stateManager).
  14460. then(function (formTextContent) {
  14461. Util.appendToArray(bidiTexts, formTextContent.items);
  14462. Util.extendObj(textContent.styles, formTextContent.styles);
  14463. stateManager.restore();
  14464. xobjsCache.key = name;
  14465. xobjsCache.texts = formTextContent;
  14466. next(resolve, reject);
  14467. }, reject);
  14468. case OPS.setGState:
  14469. var dictName = args[0];
  14470. var extGState = resources.get('ExtGState');
  14471. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  14472. break;
  14473. }
  14474. var gsStateMap = extGState.get(dictName.name);
  14475. var gsStateFont = null;
  14476. for (var key in gsStateMap) {
  14477. if (key === 'Font') {
  14478. assert(!gsStateFont);
  14479. gsStateFont = gsStateMap[key];
  14480. }
  14481. }
  14482. if (gsStateFont) {
  14483. textState.fontSize = gsStateFont[1];
  14484. return handleSetFont(gsStateFont[0]).then(function() {
  14485. next(resolve, reject);
  14486. }, reject);
  14487. }
  14488. break;
  14489. } // switch
  14490. } // while
  14491. if (stop) {
  14492. deferred.then(function () {
  14493. next(resolve, reject);
  14494. });
  14495. return;
  14496. }
  14497. resolve(textContent);
  14498. });
  14499. },
  14500. extractDataStructures: function
  14501. partialEvaluatorExtractDataStructures(dict, baseDict,
  14502. xref, properties) {
  14503. // 9.10.2
  14504. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  14505. if (toUnicode) {
  14506. properties.toUnicode = this.readToUnicode(toUnicode);
  14507. }
  14508. if (properties.composite) {
  14509. // CIDSystemInfo helps to match CID to glyphs
  14510. var cidSystemInfo = dict.get('CIDSystemInfo');
  14511. if (isDict(cidSystemInfo)) {
  14512. properties.cidSystemInfo = {
  14513. registry: cidSystemInfo.get('Registry'),
  14514. ordering: cidSystemInfo.get('Ordering'),
  14515. supplement: cidSystemInfo.get('Supplement')
  14516. };
  14517. }
  14518. var cidToGidMap = dict.get('CIDToGIDMap');
  14519. if (isStream(cidToGidMap)) {
  14520. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  14521. }
  14522. }
  14523. // Based on 9.6.6 of the spec the encoding can come from multiple places
  14524. // and depends on the font type. The base encoding and differences are
  14525. // read here, but the encoding that is actually used is chosen during
  14526. // glyph mapping in the font.
  14527. // TODO: Loading the built in encoding in the font would allow the
  14528. // differences to be merged in here not require us to hold on to it.
  14529. var differences = [];
  14530. var baseEncodingName = null;
  14531. var encoding;
  14532. if (dict.has('Encoding')) {
  14533. encoding = dict.get('Encoding');
  14534. if (isDict(encoding)) {
  14535. baseEncodingName = encoding.get('BaseEncoding');
  14536. baseEncodingName = (isName(baseEncodingName) ?
  14537. baseEncodingName.name : null);
  14538. // Load the differences between the base and original
  14539. if (encoding.has('Differences')) {
  14540. var diffEncoding = encoding.get('Differences');
  14541. var index = 0;
  14542. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  14543. var data = diffEncoding[j];
  14544. if (isNum(data)) {
  14545. index = data;
  14546. } else {
  14547. differences[index++] = data.name;
  14548. }
  14549. }
  14550. }
  14551. } else if (isName(encoding)) {
  14552. baseEncodingName = encoding.name;
  14553. } else {
  14554. error('Encoding is not a Name nor a Dict');
  14555. }
  14556. // According to table 114 if the encoding is a named encoding it must be
  14557. // one of these predefined encodings.
  14558. if ((baseEncodingName !== 'MacRomanEncoding' &&
  14559. baseEncodingName !== 'MacExpertEncoding' &&
  14560. baseEncodingName !== 'WinAnsiEncoding')) {
  14561. baseEncodingName = null;
  14562. }
  14563. }
  14564. if (baseEncodingName) {
  14565. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  14566. } else {
  14567. encoding = (properties.type === 'TrueType' ?
  14568. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  14569. // The Symbolic attribute can be misused for regular fonts
  14570. // Heuristic: we have to check if the font is a standard one also
  14571. if (!!(properties.flags & FontFlags.Symbolic)) {
  14572. encoding = (!properties.file && /Symbol/i.test(properties.name) ?
  14573. Encodings.SymbolSetEncoding :
  14574. Encodings.MacRomanEncoding);
  14575. }
  14576. properties.defaultEncoding = encoding;
  14577. }
  14578. properties.differences = differences;
  14579. properties.baseEncodingName = baseEncodingName;
  14580. properties.dict = dict;
  14581. },
  14582. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  14583. var cmapObj = toUnicode;
  14584. if (isName(cmapObj)) {
  14585. return CMapFactory.create(cmapObj,
  14586. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  14587. } else if (isStream(cmapObj)) {
  14588. var cmap = CMapFactory.create(cmapObj,
  14589. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  14590. // Convert UTF-16BE
  14591. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  14592. // to iterate over all keys.
  14593. cmap.forEach(function(token, i) {
  14594. var str = [];
  14595. for (var k = 0; k < token.length; k += 2) {
  14596. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  14597. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  14598. str.push(w1);
  14599. continue;
  14600. }
  14601. k += 2;
  14602. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  14603. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  14604. }
  14605. cmap[i] = String.fromCharCode.apply(String, str);
  14606. });
  14607. return cmap;
  14608. }
  14609. return null;
  14610. },
  14611. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  14612. // Extract the encoding from the CIDToGIDMap
  14613. var glyphsData = cidToGidStream.getBytes();
  14614. // Set encoding 0 to later verify the font has an encoding
  14615. var result = [];
  14616. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  14617. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  14618. if (glyphID === 0) {
  14619. continue;
  14620. }
  14621. var code = j >> 1;
  14622. result[code] = glyphID;
  14623. }
  14624. return result;
  14625. },
  14626. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  14627. descriptor,
  14628. properties) {
  14629. var glyphsWidths = [];
  14630. var defaultWidth = 0;
  14631. var glyphsVMetrics = [];
  14632. var defaultVMetrics;
  14633. var i, ii, j, jj, start, code, widths;
  14634. if (properties.composite) {
  14635. defaultWidth = dict.get('DW') || 1000;
  14636. widths = dict.get('W');
  14637. if (widths) {
  14638. for (i = 0, ii = widths.length; i < ii; i++) {
  14639. start = widths[i++];
  14640. code = xref.fetchIfRef(widths[i]);
  14641. if (isArray(code)) {
  14642. for (j = 0, jj = code.length; j < jj; j++) {
  14643. glyphsWidths[start++] = code[j];
  14644. }
  14645. } else {
  14646. var width = widths[++i];
  14647. for (j = start; j <= code; j++) {
  14648. glyphsWidths[j] = width;
  14649. }
  14650. }
  14651. }
  14652. }
  14653. if (properties.vertical) {
  14654. var vmetrics = (dict.get('DW2') || [880, -1000]);
  14655. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  14656. vmetrics = dict.get('W2');
  14657. if (vmetrics) {
  14658. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  14659. start = vmetrics[i++];
  14660. code = xref.fetchIfRef(vmetrics[i]);
  14661. if (isArray(code)) {
  14662. for (j = 0, jj = code.length; j < jj; j++) {
  14663. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  14664. }
  14665. } else {
  14666. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  14667. for (j = start; j <= code; j++) {
  14668. glyphsVMetrics[j] = vmetric;
  14669. }
  14670. }
  14671. }
  14672. }
  14673. }
  14674. } else {
  14675. var firstChar = properties.firstChar;
  14676. widths = dict.get('Widths');
  14677. if (widths) {
  14678. j = firstChar;
  14679. for (i = 0, ii = widths.length; i < ii; i++) {
  14680. glyphsWidths[j++] = widths[i];
  14681. }
  14682. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  14683. } else {
  14684. // Trying get the BaseFont metrics (see comment above).
  14685. var baseFontName = dict.get('BaseFont');
  14686. if (isName(baseFontName)) {
  14687. var metrics = this.getBaseFontMetrics(baseFontName.name);
  14688. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  14689. properties);
  14690. defaultWidth = metrics.defaultWidth;
  14691. }
  14692. }
  14693. }
  14694. // Heuristic: detection of monospace font by checking all non-zero widths
  14695. var isMonospace = true;
  14696. var firstWidth = defaultWidth;
  14697. for (var glyph in glyphsWidths) {
  14698. var glyphWidth = glyphsWidths[glyph];
  14699. if (!glyphWidth) {
  14700. continue;
  14701. }
  14702. if (!firstWidth) {
  14703. firstWidth = glyphWidth;
  14704. continue;
  14705. }
  14706. if (firstWidth !== glyphWidth) {
  14707. isMonospace = false;
  14708. break;
  14709. }
  14710. }
  14711. if (isMonospace) {
  14712. properties.flags |= FontFlags.FixedPitch;
  14713. }
  14714. properties.defaultWidth = defaultWidth;
  14715. properties.widths = glyphsWidths;
  14716. properties.defaultVMetrics = defaultVMetrics;
  14717. properties.vmetrics = glyphsVMetrics;
  14718. },
  14719. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  14720. // Simulating descriptor flags attribute
  14721. var fontNameWoStyle = baseFontName.split('-')[0];
  14722. return (fontNameWoStyle in serifFonts) ||
  14723. (fontNameWoStyle.search(/serif/gi) !== -1);
  14724. },
  14725. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  14726. var defaultWidth = 0;
  14727. var widths = [];
  14728. var monospace = false;
  14729. var lookupName = (stdFontMap[name] || name);
  14730. if (!(lookupName in Metrics)) {
  14731. // Use default fonts for looking up font metrics if the passed
  14732. // font is not a base font
  14733. if (this.isSerifFont(name)) {
  14734. lookupName = 'Times-Roman';
  14735. } else {
  14736. lookupName = 'Helvetica';
  14737. }
  14738. }
  14739. var glyphWidths = Metrics[lookupName];
  14740. if (isNum(glyphWidths)) {
  14741. defaultWidth = glyphWidths;
  14742. monospace = true;
  14743. } else {
  14744. widths = glyphWidths;
  14745. }
  14746. return {
  14747. defaultWidth: defaultWidth,
  14748. monospace: monospace,
  14749. widths: widths
  14750. };
  14751. },
  14752. buildCharCodeToWidth:
  14753. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  14754. properties) {
  14755. var widths = Object.create(null);
  14756. var differences = properties.differences;
  14757. var encoding = properties.defaultEncoding;
  14758. for (var charCode = 0; charCode < 256; charCode++) {
  14759. if (charCode in differences &&
  14760. widthsByGlyphName[differences[charCode]]) {
  14761. widths[charCode] = widthsByGlyphName[differences[charCode]];
  14762. continue;
  14763. }
  14764. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  14765. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  14766. continue;
  14767. }
  14768. }
  14769. return widths;
  14770. },
  14771. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  14772. var baseDict = dict;
  14773. var type = dict.get('Subtype');
  14774. assert(isName(type), 'invalid font Subtype');
  14775. var composite = false;
  14776. var uint8array;
  14777. if (type.name === 'Type0') {
  14778. // If font is a composite
  14779. // - get the descendant font
  14780. // - set the type according to the descendant font
  14781. // - get the FontDescriptor from the descendant font
  14782. var df = dict.get('DescendantFonts');
  14783. if (!df) {
  14784. error('Descendant fonts are not specified');
  14785. }
  14786. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  14787. type = dict.get('Subtype');
  14788. assert(isName(type), 'invalid font Subtype');
  14789. composite = true;
  14790. }
  14791. var descriptor = dict.get('FontDescriptor');
  14792. if (descriptor) {
  14793. var hash = new MurmurHash3_64();
  14794. var encoding = baseDict.getRaw('Encoding');
  14795. if (isName(encoding)) {
  14796. hash.update(encoding.name);
  14797. } else if (isRef(encoding)) {
  14798. hash.update(encoding.num + '_' + encoding.gen);
  14799. }
  14800. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  14801. if (isStream(toUnicode)) {
  14802. var stream = toUnicode.str || toUnicode;
  14803. uint8array = stream.buffer ?
  14804. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  14805. new Uint8Array(stream.bytes.buffer,
  14806. stream.start, stream.end - stream.start);
  14807. hash.update(uint8array);
  14808. } else if (isName(toUnicode)) {
  14809. hash.update(toUnicode.name);
  14810. }
  14811. var widths = dict.get('Widths') || baseDict.get('Widths');
  14812. if (widths) {
  14813. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  14814. hash.update(uint8array);
  14815. }
  14816. }
  14817. return {
  14818. descriptor: descriptor,
  14819. dict: dict,
  14820. baseDict: baseDict,
  14821. composite: composite,
  14822. type: type.name,
  14823. hash: hash ? hash.hexdigest() : ''
  14824. };
  14825. },
  14826. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  14827. xref) {
  14828. var baseDict = preEvaluatedFont.baseDict;
  14829. var dict = preEvaluatedFont.dict;
  14830. var composite = preEvaluatedFont.composite;
  14831. var descriptor = preEvaluatedFont.descriptor;
  14832. var type = preEvaluatedFont.type;
  14833. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  14834. var properties;
  14835. if (!descriptor) {
  14836. if (type === 'Type3') {
  14837. // FontDescriptor is only required for Type3 fonts when the document
  14838. // is a tagged pdf. Create a barbebones one to get by.
  14839. descriptor = new Dict(null);
  14840. descriptor.set('FontName', Name.get(type));
  14841. } else {
  14842. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  14843. // FontDescriptor was not required.
  14844. // This case is here for compatibility.
  14845. var baseFontName = dict.get('BaseFont');
  14846. if (!isName(baseFontName)) {
  14847. error('Base font is not specified');
  14848. }
  14849. // Using base font name as a font name.
  14850. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  14851. var metrics = this.getBaseFontMetrics(baseFontName);
  14852. // Simulating descriptor flags attribute
  14853. var fontNameWoStyle = baseFontName.split('-')[0];
  14854. var flags =
  14855. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  14856. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  14857. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  14858. FontFlags.Nonsymbolic);
  14859. properties = {
  14860. type: type,
  14861. name: baseFontName,
  14862. widths: metrics.widths,
  14863. defaultWidth: metrics.defaultWidth,
  14864. flags: flags,
  14865. firstChar: 0,
  14866. lastChar: maxCharIndex
  14867. };
  14868. this.extractDataStructures(dict, dict, xref, properties);
  14869. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  14870. properties);
  14871. return new Font(baseFontName, null, properties);
  14872. }
  14873. }
  14874. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  14875. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  14876. // to ignore this rule when a variant of a standart font is used.
  14877. // TODO Fill the width array depending on which of the base font this is
  14878. // a variant.
  14879. var firstChar = (dict.get('FirstChar') || 0);
  14880. var lastChar = (dict.get('LastChar') || maxCharIndex);
  14881. var fontName = descriptor.get('FontName');
  14882. var baseFont = dict.get('BaseFont');
  14883. // Some bad PDFs have a string as the font name.
  14884. if (isString(fontName)) {
  14885. fontName = Name.get(fontName);
  14886. }
  14887. if (isString(baseFont)) {
  14888. baseFont = Name.get(baseFont);
  14889. }
  14890. if (type !== 'Type3') {
  14891. var fontNameStr = fontName && fontName.name;
  14892. var baseFontStr = baseFont && baseFont.name;
  14893. if (fontNameStr !== baseFontStr) {
  14894. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  14895. '" but should be the same as the Font\'s BaseFont "' +
  14896. baseFontStr + '"');
  14897. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  14898. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  14899. if (fontNameStr && baseFontStr &&
  14900. baseFontStr.indexOf(fontNameStr) === 0) {
  14901. fontName = baseFont;
  14902. }
  14903. }
  14904. }
  14905. fontName = (fontName || baseFont);
  14906. assert(isName(fontName), 'invalid font name');
  14907. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  14908. if (fontFile) {
  14909. if (fontFile.dict) {
  14910. var subtype = fontFile.dict.get('Subtype');
  14911. if (subtype) {
  14912. subtype = subtype.name;
  14913. }
  14914. var length1 = fontFile.dict.get('Length1');
  14915. var length2 = fontFile.dict.get('Length2');
  14916. }
  14917. }
  14918. properties = {
  14919. type: type,
  14920. name: fontName.name,
  14921. subtype: subtype,
  14922. file: fontFile,
  14923. length1: length1,
  14924. length2: length2,
  14925. loadedName: baseDict.loadedName,
  14926. composite: composite,
  14927. wideChars: composite,
  14928. fixedPitch: false,
  14929. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  14930. firstChar: firstChar || 0,
  14931. lastChar: (lastChar || maxCharIndex),
  14932. bbox: descriptor.get('FontBBox'),
  14933. ascent: descriptor.get('Ascent'),
  14934. descent: descriptor.get('Descent'),
  14935. xHeight: descriptor.get('XHeight'),
  14936. capHeight: descriptor.get('CapHeight'),
  14937. flags: descriptor.get('Flags'),
  14938. italicAngle: descriptor.get('ItalicAngle'),
  14939. coded: false
  14940. };
  14941. if (composite) {
  14942. var cidEncoding = baseDict.get('Encoding');
  14943. if (isName(cidEncoding)) {
  14944. properties.cidEncoding = cidEncoding.name;
  14945. }
  14946. properties.cMap = CMapFactory.create(cidEncoding,
  14947. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  14948. properties.vertical = properties.cMap.vertical;
  14949. }
  14950. this.extractDataStructures(dict, baseDict, xref, properties);
  14951. this.extractWidths(dict, xref, descriptor, properties);
  14952. if (type === 'Type3') {
  14953. properties.isType3Font = true;
  14954. }
  14955. return new Font(fontName.name, fontFile, properties);
  14956. }
  14957. };
  14958. return PartialEvaluator;
  14959. })();
  14960. var TranslatedFont = (function TranslatedFontClosure() {
  14961. function TranslatedFont(loadedName, font, dict) {
  14962. this.loadedName = loadedName;
  14963. this.font = font;
  14964. this.dict = dict;
  14965. this.type3Loaded = null;
  14966. this.sent = false;
  14967. }
  14968. TranslatedFont.prototype = {
  14969. send: function (handler) {
  14970. if (this.sent) {
  14971. return;
  14972. }
  14973. var fontData = this.font.exportData();
  14974. handler.send('commonobj', [
  14975. this.loadedName,
  14976. 'Font',
  14977. fontData
  14978. ]);
  14979. this.sent = true;
  14980. },
  14981. loadType3Data: function (evaluator, resources, parentOperatorList) {
  14982. assert(this.font.isType3Font);
  14983. if (this.type3Loaded) {
  14984. return this.type3Loaded;
  14985. }
  14986. var translatedFont = this.font;
  14987. var loadCharProcsPromise = Promise.resolve();
  14988. var charProcs = this.dict.get('CharProcs').getAll();
  14989. var fontResources = this.dict.get('Resources') || resources;
  14990. var charProcKeys = Object.keys(charProcs);
  14991. var charProcOperatorList = {};
  14992. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  14993. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  14994. var glyphStream = charProcs[key];
  14995. var operatorList = new OperatorList();
  14996. return evaluator.getOperatorList(glyphStream, fontResources,
  14997. operatorList).then(function () {
  14998. charProcOperatorList[key] = operatorList.getIR();
  14999. // Add the dependencies to the parent operator list so they are
  15000. // resolved before sub operator list is executed synchronously.
  15001. parentOperatorList.addDependencies(operatorList.dependencies);
  15002. }, function (reason) {
  15003. warn('Type3 font resource \"' + key + '\" is not available');
  15004. var operatorList = new OperatorList();
  15005. charProcOperatorList[key] = operatorList.getIR();
  15006. });
  15007. }.bind(this, charProcKeys[i]));
  15008. }
  15009. this.type3Loaded = loadCharProcsPromise.then(function () {
  15010. translatedFont.charProcOperatorList = charProcOperatorList;
  15011. });
  15012. return this.type3Loaded;
  15013. }
  15014. };
  15015. return TranslatedFont;
  15016. })();
  15017. var OperatorList = (function OperatorListClosure() {
  15018. var CHUNK_SIZE = 1000;
  15019. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  15020. function getTransfers(queue) {
  15021. var transfers = [];
  15022. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  15023. for (var i = 0, ii = queue.length; i < ii; i++) {
  15024. switch (fnArray[i]) {
  15025. case OPS.paintInlineImageXObject:
  15026. case OPS.paintInlineImageXObjectGroup:
  15027. case OPS.paintImageMaskXObject:
  15028. var arg = argsArray[i][0]; // first param in imgData
  15029. if (!arg.cached) {
  15030. transfers.push(arg.data.buffer);
  15031. }
  15032. break;
  15033. }
  15034. }
  15035. return transfers;
  15036. }
  15037. function OperatorList(intent, messageHandler, pageIndex) {
  15038. this.messageHandler = messageHandler;
  15039. this.fnArray = [];
  15040. this.argsArray = [];
  15041. this.dependencies = {};
  15042. this.pageIndex = pageIndex;
  15043. this.intent = intent;
  15044. }
  15045. OperatorList.prototype = {
  15046. get length() {
  15047. return this.argsArray.length;
  15048. },
  15049. addOp: function(fn, args) {
  15050. this.fnArray.push(fn);
  15051. this.argsArray.push(args);
  15052. if (this.messageHandler) {
  15053. if (this.fnArray.length >= CHUNK_SIZE) {
  15054. this.flush();
  15055. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  15056. (fn === OPS.restore || fn === OPS.endText)) {
  15057. // heuristic to flush on boundary of restore or endText
  15058. this.flush();
  15059. }
  15060. }
  15061. },
  15062. addDependency: function(dependency) {
  15063. if (dependency in this.dependencies) {
  15064. return;
  15065. }
  15066. this.dependencies[dependency] = true;
  15067. this.addOp(OPS.dependency, [dependency]);
  15068. },
  15069. addDependencies: function(dependencies) {
  15070. for (var key in dependencies) {
  15071. this.addDependency(key);
  15072. }
  15073. },
  15074. addOpList: function(opList) {
  15075. Util.extendObj(this.dependencies, opList.dependencies);
  15076. for (var i = 0, ii = opList.length; i < ii; i++) {
  15077. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  15078. }
  15079. },
  15080. getIR: function() {
  15081. return {
  15082. fnArray: this.fnArray,
  15083. argsArray: this.argsArray,
  15084. length: this.length
  15085. };
  15086. },
  15087. flush: function(lastChunk) {
  15088. new QueueOptimizer().optimize(this);
  15089. var transfers = getTransfers(this);
  15090. this.messageHandler.send('RenderPageChunk', {
  15091. operatorList: {
  15092. fnArray: this.fnArray,
  15093. argsArray: this.argsArray,
  15094. lastChunk: lastChunk,
  15095. length: this.length
  15096. },
  15097. pageIndex: this.pageIndex,
  15098. intent: this.intent
  15099. }, transfers);
  15100. this.dependencies = {};
  15101. this.fnArray.length = 0;
  15102. this.argsArray.length = 0;
  15103. }
  15104. };
  15105. return OperatorList;
  15106. })();
  15107. var StateManager = (function StateManagerClosure() {
  15108. function StateManager(initialState) {
  15109. this.state = initialState;
  15110. this.stateStack = [];
  15111. }
  15112. StateManager.prototype = {
  15113. save: function () {
  15114. var old = this.state;
  15115. this.stateStack.push(this.state);
  15116. this.state = old.clone();
  15117. },
  15118. restore: function () {
  15119. var prev = this.stateStack.pop();
  15120. if (prev) {
  15121. this.state = prev;
  15122. }
  15123. },
  15124. transform: function (args) {
  15125. this.state.ctm = Util.transform(this.state.ctm, args);
  15126. }
  15127. };
  15128. return StateManager;
  15129. })();
  15130. var TextState = (function TextStateClosure() {
  15131. function TextState() {
  15132. this.ctm = new Float32Array(IDENTITY_MATRIX);
  15133. this.fontSize = 0;
  15134. this.font = null;
  15135. this.fontMatrix = FONT_IDENTITY_MATRIX;
  15136. this.textMatrix = IDENTITY_MATRIX.slice();
  15137. this.textLineMatrix = IDENTITY_MATRIX.slice();
  15138. this.charSpacing = 0;
  15139. this.wordSpacing = 0;
  15140. this.leading = 0;
  15141. this.textHScale = 1;
  15142. this.textRise = 0;
  15143. }
  15144. TextState.prototype = {
  15145. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  15146. var m = this.textMatrix;
  15147. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  15148. },
  15149. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  15150. var m = this.textLineMatrix;
  15151. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  15152. },
  15153. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  15154. var m = this.textMatrix;
  15155. m[4] = m[0] * x + m[2] * y + m[4];
  15156. m[5] = m[1] * x + m[3] * y + m[5];
  15157. },
  15158. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  15159. var m = this.textLineMatrix;
  15160. m[4] = m[0] * x + m[2] * y + m[4];
  15161. m[5] = m[1] * x + m[3] * y + m[5];
  15162. },
  15163. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  15164. // 9.4.4 Text Space Details
  15165. var tsm = [this.fontSize * this.textHScale, 0,
  15166. 0, this.fontSize,
  15167. 0, this.textRise];
  15168. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  15169. },
  15170. carriageReturn: function TextState_carriageReturn() {
  15171. this.translateTextLineMatrix(0, -this.leading);
  15172. this.textMatrix = this.textLineMatrix.slice();
  15173. },
  15174. clone: function TextState_clone() {
  15175. var clone = Object.create(this);
  15176. clone.textMatrix = this.textMatrix.slice();
  15177. clone.textLineMatrix = this.textLineMatrix.slice();
  15178. clone.fontMatrix = this.fontMatrix.slice();
  15179. return clone;
  15180. }
  15181. };
  15182. return TextState;
  15183. })();
  15184. var EvalState = (function EvalStateClosure() {
  15185. function EvalState() {
  15186. this.ctm = new Float32Array(IDENTITY_MATRIX);
  15187. this.font = null;
  15188. this.textRenderingMode = TextRenderingMode.FILL;
  15189. this.fillColorSpace = ColorSpace.singletons.gray;
  15190. this.strokeColorSpace = ColorSpace.singletons.gray;
  15191. }
  15192. EvalState.prototype = {
  15193. clone: function CanvasExtraState_clone() {
  15194. return Object.create(this);
  15195. },
  15196. };
  15197. return EvalState;
  15198. })();
  15199. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  15200. // Specifies properties for each command
  15201. //
  15202. // If variableArgs === true: [0, `numArgs`] expected
  15203. // If variableArgs === false: exactly `numArgs` expected
  15204. var OP_MAP = {
  15205. // Graphic state
  15206. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  15207. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  15208. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  15209. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  15210. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  15211. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  15212. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  15213. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  15214. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  15215. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  15216. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  15217. // Path
  15218. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  15219. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  15220. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  15221. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  15222. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  15223. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  15224. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  15225. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  15226. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  15227. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  15228. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  15229. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  15230. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  15231. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  15232. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  15233. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  15234. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  15235. // Clipping
  15236. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  15237. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  15238. // Text
  15239. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  15240. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  15241. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  15242. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  15243. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  15244. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  15245. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  15246. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  15247. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  15248. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  15249. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  15250. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  15251. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  15252. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  15253. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  15254. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  15255. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  15256. variableArgs: false },
  15257. // Type3 fonts
  15258. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  15259. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  15260. // Color
  15261. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  15262. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  15263. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  15264. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  15265. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  15266. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  15267. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  15268. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  15269. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  15270. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  15271. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  15272. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  15273. // Shading
  15274. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  15275. // Images
  15276. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  15277. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  15278. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  15279. // XObjects
  15280. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  15281. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  15282. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  15283. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  15284. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  15285. variableArgs: false },
  15286. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  15287. // Compatibility
  15288. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  15289. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  15290. // (reserved partial commands for the lexer)
  15291. BM: null,
  15292. BD: null,
  15293. 'true': null,
  15294. fa: null,
  15295. fal: null,
  15296. fals: null,
  15297. 'false': null,
  15298. nu: null,
  15299. nul: null,
  15300. 'null': null
  15301. };
  15302. function EvaluatorPreprocessor(stream, xref, stateManager) {
  15303. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  15304. // dictionary
  15305. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  15306. this.stateManager = stateManager;
  15307. this.nonProcessedArgs = [];
  15308. }
  15309. EvaluatorPreprocessor.prototype = {
  15310. get savedStatesDepth() {
  15311. return this.stateManager.stateStack.length;
  15312. },
  15313. read: function EvaluatorPreprocessor_read(operation) {
  15314. // We use an array to represent args, except we use |null| to represent
  15315. // no args because it's more compact than an empty array.
  15316. var args = null;
  15317. while (true) {
  15318. var obj = this.parser.getObj();
  15319. if (isCmd(obj)) {
  15320. var cmd = obj.cmd;
  15321. // Check that the command is valid
  15322. var opSpec = OP_MAP[cmd];
  15323. if (!opSpec) {
  15324. warn('Unknown command "' + cmd + '"');
  15325. continue;
  15326. }
  15327. var fn = opSpec.id;
  15328. var numArgs = opSpec.numArgs;
  15329. if (!opSpec.variableArgs) {
  15330. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  15331. var argsLength = args !== null ? args.length : 0;
  15332. if (argsLength !== numArgs) {
  15333. var nonProcessedArgs = this.nonProcessedArgs;
  15334. while (argsLength > numArgs) {
  15335. nonProcessedArgs.push(args.shift());
  15336. argsLength--;
  15337. }
  15338. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  15339. if (!args) {
  15340. args = [];
  15341. }
  15342. args.unshift(nonProcessedArgs.pop());
  15343. argsLength++;
  15344. }
  15345. }
  15346. if (argsLength < numArgs) {
  15347. // If we receive too few args, it's not possible to possible
  15348. // to execute the command, so skip the command
  15349. info('Command ' + fn + ': because expected ' +
  15350. numArgs + ' args, but received ' + argsLength +
  15351. ' args; skipping');
  15352. args = null;
  15353. continue;
  15354. }
  15355. } else if (argsLength > numArgs) {
  15356. info('Command ' + fn + ': expected [0,' + numArgs +
  15357. '] args, but received ' + argsLength + ' args');
  15358. }
  15359. // TODO figure out how to type-check vararg functions
  15360. this.preprocessCommand(fn, args);
  15361. operation.fn = fn;
  15362. operation.args = args;
  15363. return true;
  15364. } else {
  15365. if (isEOF(obj)) {
  15366. return false; // no more commands
  15367. }
  15368. // argument
  15369. if (obj !== null) {
  15370. if (!args) {
  15371. args = [];
  15372. }
  15373. args.push((obj instanceof Dict ? obj.getAll() : obj));
  15374. assert(args.length <= 33, 'Too many arguments');
  15375. }
  15376. }
  15377. }
  15378. },
  15379. preprocessCommand:
  15380. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  15381. switch (fn | 0) {
  15382. case OPS.save:
  15383. this.stateManager.save();
  15384. break;
  15385. case OPS.restore:
  15386. this.stateManager.restore();
  15387. break;
  15388. case OPS.transform:
  15389. this.stateManager.transform(args);
  15390. break;
  15391. }
  15392. }
  15393. };
  15394. return EvaluatorPreprocessor;
  15395. })();
  15396. var QueueOptimizer = (function QueueOptimizerClosure() {
  15397. function addState(parentState, pattern, fn) {
  15398. var state = parentState;
  15399. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  15400. var item = pattern[i];
  15401. state = (state[item] || (state[item] = []));
  15402. }
  15403. state[pattern[pattern.length - 1]] = fn;
  15404. }
  15405. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  15406. argsArray) {
  15407. // Handles special case of mainly LaTeX documents which use image masks to
  15408. // draw lines with the current fill style.
  15409. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  15410. // have been found at iFirstSave.
  15411. var iFirstPIMXO = iFirstSave + 2;
  15412. for (var i = 0; i < count; i++) {
  15413. var arg = argsArray[iFirstPIMXO + 4 * i];
  15414. var imageMask = arg.length === 1 && arg[0];
  15415. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  15416. (!imageMask.data.length ||
  15417. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  15418. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  15419. continue;
  15420. }
  15421. break;
  15422. }
  15423. return count - i;
  15424. }
  15425. var InitialState = [];
  15426. // This replaces (save, transform, paintInlineImageXObject, restore)+
  15427. // sequences with one |paintInlineImageXObjectGroup| operation.
  15428. addState(InitialState,
  15429. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  15430. function foundInlineImageGroup(context) {
  15431. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  15432. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  15433. var MAX_WIDTH = 1000;
  15434. var IMAGE_PADDING = 1;
  15435. var fnArray = context.fnArray, argsArray = context.argsArray;
  15436. var curr = context.iCurr;
  15437. var iFirstSave = curr - 3;
  15438. var iFirstTransform = curr - 2;
  15439. var iFirstPIIXO = curr - 1;
  15440. // Look for the quartets.
  15441. var i = iFirstSave + 4;
  15442. var ii = fnArray.length;
  15443. while (i + 3 < ii) {
  15444. if (fnArray[i] !== OPS.save ||
  15445. fnArray[i + 1] !== OPS.transform ||
  15446. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  15447. fnArray[i + 3] !== OPS.restore) {
  15448. break; // ops don't match
  15449. }
  15450. i += 4;
  15451. }
  15452. // At this point, i is the index of the first op past the last valid
  15453. // quartet.
  15454. var count = Math.min((i - iFirstSave) / 4,
  15455. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  15456. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  15457. return i;
  15458. }
  15459. // assuming that heights of those image is too small (~1 pixel)
  15460. // packing as much as possible by lines
  15461. var maxX = 0;
  15462. var map = [], maxLineHeight = 0;
  15463. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  15464. var q;
  15465. for (q = 0; q < count; q++) {
  15466. var transform = argsArray[iFirstTransform + (q << 2)];
  15467. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  15468. if (currentX + img.width > MAX_WIDTH) {
  15469. // starting new line
  15470. maxX = Math.max(maxX, currentX);
  15471. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  15472. currentX = 0;
  15473. maxLineHeight = 0;
  15474. }
  15475. map.push({
  15476. transform: transform,
  15477. x: currentX, y: currentY,
  15478. w: img.width, h: img.height
  15479. });
  15480. currentX += img.width + 2 * IMAGE_PADDING;
  15481. maxLineHeight = Math.max(maxLineHeight, img.height);
  15482. }
  15483. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  15484. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  15485. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  15486. var imgRowSize = imgWidth << 2;
  15487. for (q = 0; q < count; q++) {
  15488. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  15489. // Copy image by lines and extends pixels into padding.
  15490. var rowSize = map[q].w << 2;
  15491. var dataOffset = 0;
  15492. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  15493. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  15494. for (var k = 0, kk = map[q].h; k < kk; k++) {
  15495. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  15496. dataOffset += rowSize;
  15497. offset += imgRowSize;
  15498. }
  15499. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  15500. while (offset >= 0) {
  15501. data[offset - 4] = data[offset];
  15502. data[offset - 3] = data[offset + 1];
  15503. data[offset - 2] = data[offset + 2];
  15504. data[offset - 1] = data[offset + 3];
  15505. data[offset + rowSize] = data[offset + rowSize - 4];
  15506. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  15507. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  15508. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  15509. offset -= imgRowSize;
  15510. }
  15511. }
  15512. // Replace queue items.
  15513. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  15514. argsArray.splice(iFirstSave, count * 4,
  15515. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  15516. data: imgData }, map]);
  15517. return iFirstSave + 1;
  15518. });
  15519. // This replaces (save, transform, paintImageMaskXObject, restore)+
  15520. // sequences with one |paintImageMaskXObjectGroup| or one
  15521. // |paintImageMaskXObjectRepeat| operation.
  15522. addState(InitialState,
  15523. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  15524. function foundImageMaskGroup(context) {
  15525. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  15526. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  15527. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  15528. var fnArray = context.fnArray, argsArray = context.argsArray;
  15529. var curr = context.iCurr;
  15530. var iFirstSave = curr - 3;
  15531. var iFirstTransform = curr - 2;
  15532. var iFirstPIMXO = curr - 1;
  15533. // Look for the quartets.
  15534. var i = iFirstSave + 4;
  15535. var ii = fnArray.length;
  15536. while (i + 3 < ii) {
  15537. if (fnArray[i] !== OPS.save ||
  15538. fnArray[i + 1] !== OPS.transform ||
  15539. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  15540. fnArray[i + 3] !== OPS.restore) {
  15541. break; // ops don't match
  15542. }
  15543. i += 4;
  15544. }
  15545. // At this point, i is the index of the first op past the last valid
  15546. // quartet.
  15547. var count = (i - iFirstSave) / 4;
  15548. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  15549. argsArray);
  15550. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  15551. return i;
  15552. }
  15553. var q;
  15554. var isSameImage = false;
  15555. var iTransform, transformArgs;
  15556. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  15557. if (argsArray[iFirstTransform][1] === 0 &&
  15558. argsArray[iFirstTransform][2] === 0) {
  15559. isSameImage = true;
  15560. var firstTransformArg0 = argsArray[iFirstTransform][0];
  15561. var firstTransformArg3 = argsArray[iFirstTransform][3];
  15562. iTransform = iFirstTransform + 4;
  15563. var iPIMXO = iFirstPIMXO + 4;
  15564. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  15565. transformArgs = argsArray[iTransform];
  15566. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  15567. transformArgs[0] !== firstTransformArg0 ||
  15568. transformArgs[1] !== 0 ||
  15569. transformArgs[2] !== 0 ||
  15570. transformArgs[3] !== firstTransformArg3) {
  15571. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  15572. isSameImage = false;
  15573. } else {
  15574. count = q;
  15575. }
  15576. break; // different image or transform
  15577. }
  15578. }
  15579. }
  15580. if (isSameImage) {
  15581. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  15582. var positions = new Float32Array(count * 2);
  15583. iTransform = iFirstTransform;
  15584. for (q = 0; q < count; q++, iTransform += 4) {
  15585. transformArgs = argsArray[iTransform];
  15586. positions[(q << 1)] = transformArgs[4];
  15587. positions[(q << 1) + 1] = transformArgs[5];
  15588. }
  15589. // Replace queue items.
  15590. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  15591. argsArray.splice(iFirstSave, count * 4,
  15592. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  15593. } else {
  15594. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  15595. var images = [];
  15596. for (q = 0; q < count; q++) {
  15597. transformArgs = argsArray[iFirstTransform + (q << 2)];
  15598. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  15599. images.push({ data: maskParams.data, width: maskParams.width,
  15600. height: maskParams.height,
  15601. transform: transformArgs });
  15602. }
  15603. // Replace queue items.
  15604. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  15605. argsArray.splice(iFirstSave, count * 4, [images]);
  15606. }
  15607. return iFirstSave + 1;
  15608. });
  15609. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  15610. // with one paintImageXObjectRepeat operation, if the |transform| and
  15611. // |paintImageXObjectRepeat| ops are appropriate.
  15612. addState(InitialState,
  15613. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  15614. function (context) {
  15615. var MIN_IMAGES_IN_BLOCK = 3;
  15616. var MAX_IMAGES_IN_BLOCK = 1000;
  15617. var fnArray = context.fnArray, argsArray = context.argsArray;
  15618. var curr = context.iCurr;
  15619. var iFirstSave = curr - 3;
  15620. var iFirstTransform = curr - 2;
  15621. var iFirstPIXO = curr - 1;
  15622. var iFirstRestore = curr;
  15623. if (argsArray[iFirstTransform][1] !== 0 ||
  15624. argsArray[iFirstTransform][2] !== 0) {
  15625. return iFirstRestore + 1; // transform has the wrong form
  15626. }
  15627. // Look for the quartets.
  15628. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  15629. var firstTransformArg0 = argsArray[iFirstTransform][0];
  15630. var firstTransformArg3 = argsArray[iFirstTransform][3];
  15631. var i = iFirstSave + 4;
  15632. var ii = fnArray.length;
  15633. while (i + 3 < ii) {
  15634. if (fnArray[i] !== OPS.save ||
  15635. fnArray[i + 1] !== OPS.transform ||
  15636. fnArray[i + 2] !== OPS.paintImageXObject ||
  15637. fnArray[i + 3] !== OPS.restore) {
  15638. break; // ops don't match
  15639. }
  15640. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  15641. argsArray[i + 1][1] !== 0 ||
  15642. argsArray[i + 1][2] !== 0 ||
  15643. argsArray[i + 1][3] !== firstTransformArg3) {
  15644. break; // transforms don't match
  15645. }
  15646. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  15647. break; // images don't match
  15648. }
  15649. i += 4;
  15650. }
  15651. // At this point, i is the index of the first op past the last valid
  15652. // quartet.
  15653. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  15654. if (count < MIN_IMAGES_IN_BLOCK) {
  15655. return i;
  15656. }
  15657. // Extract the (x,y) positions from all of the matching transforms.
  15658. var positions = new Float32Array(count * 2);
  15659. var iTransform = iFirstTransform;
  15660. for (var q = 0; q < count; q++, iTransform += 4) {
  15661. var transformArgs = argsArray[iTransform];
  15662. positions[(q << 1)] = transformArgs[4];
  15663. positions[(q << 1) + 1] = transformArgs[5];
  15664. }
  15665. // Replace queue items.
  15666. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  15667. positions];
  15668. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  15669. argsArray.splice(iFirstSave, count * 4, args);
  15670. return iFirstSave + 1;
  15671. });
  15672. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  15673. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  15674. // sequences, if the font for each one is the same.
  15675. addState(InitialState,
  15676. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  15677. function (context) {
  15678. var MIN_CHARS_IN_BLOCK = 3;
  15679. var MAX_CHARS_IN_BLOCK = 1000;
  15680. var fnArray = context.fnArray, argsArray = context.argsArray;
  15681. var curr = context.iCurr;
  15682. var iFirstBeginText = curr - 4;
  15683. var iFirstSetFont = curr - 3;
  15684. var iFirstSetTextMatrix = curr - 2;
  15685. var iFirstShowText = curr - 1;
  15686. var iFirstEndText = curr;
  15687. // Look for the quintets.
  15688. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  15689. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  15690. var i = iFirstBeginText + 5;
  15691. var ii = fnArray.length;
  15692. while (i + 4 < ii) {
  15693. if (fnArray[i] !== OPS.beginText ||
  15694. fnArray[i + 1] !== OPS.setFont ||
  15695. fnArray[i + 2] !== OPS.setTextMatrix ||
  15696. fnArray[i + 3] !== OPS.showText ||
  15697. fnArray[i + 4] !== OPS.endText) {
  15698. break; // ops don't match
  15699. }
  15700. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  15701. argsArray[i + 1][1] !== firstSetFontArg1) {
  15702. break; // fonts don't match
  15703. }
  15704. i += 5;
  15705. }
  15706. // At this point, i is the index of the first op past the last valid
  15707. // quintet.
  15708. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  15709. if (count < MIN_CHARS_IN_BLOCK) {
  15710. return i;
  15711. }
  15712. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  15713. // showText, endText), include that as well. (E.g. <something> might be
  15714. // |dependency|.)
  15715. var iFirst = iFirstBeginText;
  15716. if (iFirstBeginText >= 4 &&
  15717. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  15718. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  15719. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  15720. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  15721. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  15722. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  15723. count++;
  15724. iFirst -= 5;
  15725. }
  15726. // Remove (endText, beginText, setFont) trios.
  15727. var iEndText = iFirst + 4;
  15728. for (var q = 1; q < count; q++) {
  15729. fnArray.splice(iEndText, 3);
  15730. argsArray.splice(iEndText, 3);
  15731. iEndText += 2;
  15732. }
  15733. return iEndText + 1;
  15734. });
  15735. function QueueOptimizer() {}
  15736. QueueOptimizer.prototype = {
  15737. optimize: function QueueOptimizer_optimize(queue) {
  15738. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  15739. var context = {
  15740. iCurr: 0,
  15741. fnArray: fnArray,
  15742. argsArray: argsArray
  15743. };
  15744. var state;
  15745. var i = 0, ii = fnArray.length;
  15746. while (i < ii) {
  15747. state = (state || InitialState)[fnArray[i]];
  15748. if (typeof state === 'function') { // we found some handler
  15749. context.iCurr = i;
  15750. // state() returns the index of the first non-matching op (if we
  15751. // didn't match) or the first op past the modified ops (if we did
  15752. // match and replace).
  15753. i = state(context);
  15754. state = undefined; // reset the state machine
  15755. ii = context.fnArray.length;
  15756. } else {
  15757. i++;
  15758. }
  15759. }
  15760. }
  15761. };
  15762. return QueueOptimizer;
  15763. })();
  15764. var BUILT_IN_CMAPS = [
  15765. // << Start unicode maps.
  15766. 'Adobe-GB1-UCS2',
  15767. 'Adobe-CNS1-UCS2',
  15768. 'Adobe-Japan1-UCS2',
  15769. 'Adobe-Korea1-UCS2',
  15770. // >> End unicode maps.
  15771. '78-EUC-H',
  15772. '78-EUC-V',
  15773. '78-H',
  15774. '78-RKSJ-H',
  15775. '78-RKSJ-V',
  15776. '78-V',
  15777. '78ms-RKSJ-H',
  15778. '78ms-RKSJ-V',
  15779. '83pv-RKSJ-H',
  15780. '90ms-RKSJ-H',
  15781. '90ms-RKSJ-V',
  15782. '90msp-RKSJ-H',
  15783. '90msp-RKSJ-V',
  15784. '90pv-RKSJ-H',
  15785. '90pv-RKSJ-V',
  15786. 'Add-H',
  15787. 'Add-RKSJ-H',
  15788. 'Add-RKSJ-V',
  15789. 'Add-V',
  15790. 'Adobe-CNS1-0',
  15791. 'Adobe-CNS1-1',
  15792. 'Adobe-CNS1-2',
  15793. 'Adobe-CNS1-3',
  15794. 'Adobe-CNS1-4',
  15795. 'Adobe-CNS1-5',
  15796. 'Adobe-CNS1-6',
  15797. 'Adobe-GB1-0',
  15798. 'Adobe-GB1-1',
  15799. 'Adobe-GB1-2',
  15800. 'Adobe-GB1-3',
  15801. 'Adobe-GB1-4',
  15802. 'Adobe-GB1-5',
  15803. 'Adobe-Japan1-0',
  15804. 'Adobe-Japan1-1',
  15805. 'Adobe-Japan1-2',
  15806. 'Adobe-Japan1-3',
  15807. 'Adobe-Japan1-4',
  15808. 'Adobe-Japan1-5',
  15809. 'Adobe-Japan1-6',
  15810. 'Adobe-Korea1-0',
  15811. 'Adobe-Korea1-1',
  15812. 'Adobe-Korea1-2',
  15813. 'B5-H',
  15814. 'B5-V',
  15815. 'B5pc-H',
  15816. 'B5pc-V',
  15817. 'CNS-EUC-H',
  15818. 'CNS-EUC-V',
  15819. 'CNS1-H',
  15820. 'CNS1-V',
  15821. 'CNS2-H',
  15822. 'CNS2-V',
  15823. 'ETHK-B5-H',
  15824. 'ETHK-B5-V',
  15825. 'ETen-B5-H',
  15826. 'ETen-B5-V',
  15827. 'ETenms-B5-H',
  15828. 'ETenms-B5-V',
  15829. 'EUC-H',
  15830. 'EUC-V',
  15831. 'Ext-H',
  15832. 'Ext-RKSJ-H',
  15833. 'Ext-RKSJ-V',
  15834. 'Ext-V',
  15835. 'GB-EUC-H',
  15836. 'GB-EUC-V',
  15837. 'GB-H',
  15838. 'GB-V',
  15839. 'GBK-EUC-H',
  15840. 'GBK-EUC-V',
  15841. 'GBK2K-H',
  15842. 'GBK2K-V',
  15843. 'GBKp-EUC-H',
  15844. 'GBKp-EUC-V',
  15845. 'GBT-EUC-H',
  15846. 'GBT-EUC-V',
  15847. 'GBT-H',
  15848. 'GBT-V',
  15849. 'GBTpc-EUC-H',
  15850. 'GBTpc-EUC-V',
  15851. 'GBpc-EUC-H',
  15852. 'GBpc-EUC-V',
  15853. 'H',
  15854. 'HKdla-B5-H',
  15855. 'HKdla-B5-V',
  15856. 'HKdlb-B5-H',
  15857. 'HKdlb-B5-V',
  15858. 'HKgccs-B5-H',
  15859. 'HKgccs-B5-V',
  15860. 'HKm314-B5-H',
  15861. 'HKm314-B5-V',
  15862. 'HKm471-B5-H',
  15863. 'HKm471-B5-V',
  15864. 'HKscs-B5-H',
  15865. 'HKscs-B5-V',
  15866. 'Hankaku',
  15867. 'Hiragana',
  15868. 'KSC-EUC-H',
  15869. 'KSC-EUC-V',
  15870. 'KSC-H',
  15871. 'KSC-Johab-H',
  15872. 'KSC-Johab-V',
  15873. 'KSC-V',
  15874. 'KSCms-UHC-H',
  15875. 'KSCms-UHC-HW-H',
  15876. 'KSCms-UHC-HW-V',
  15877. 'KSCms-UHC-V',
  15878. 'KSCpc-EUC-H',
  15879. 'KSCpc-EUC-V',
  15880. 'Katakana',
  15881. 'NWP-H',
  15882. 'NWP-V',
  15883. 'RKSJ-H',
  15884. 'RKSJ-V',
  15885. 'Roman',
  15886. 'UniCNS-UCS2-H',
  15887. 'UniCNS-UCS2-V',
  15888. 'UniCNS-UTF16-H',
  15889. 'UniCNS-UTF16-V',
  15890. 'UniCNS-UTF32-H',
  15891. 'UniCNS-UTF32-V',
  15892. 'UniCNS-UTF8-H',
  15893. 'UniCNS-UTF8-V',
  15894. 'UniGB-UCS2-H',
  15895. 'UniGB-UCS2-V',
  15896. 'UniGB-UTF16-H',
  15897. 'UniGB-UTF16-V',
  15898. 'UniGB-UTF32-H',
  15899. 'UniGB-UTF32-V',
  15900. 'UniGB-UTF8-H',
  15901. 'UniGB-UTF8-V',
  15902. 'UniJIS-UCS2-H',
  15903. 'UniJIS-UCS2-HW-H',
  15904. 'UniJIS-UCS2-HW-V',
  15905. 'UniJIS-UCS2-V',
  15906. 'UniJIS-UTF16-H',
  15907. 'UniJIS-UTF16-V',
  15908. 'UniJIS-UTF32-H',
  15909. 'UniJIS-UTF32-V',
  15910. 'UniJIS-UTF8-H',
  15911. 'UniJIS-UTF8-V',
  15912. 'UniJIS2004-UTF16-H',
  15913. 'UniJIS2004-UTF16-V',
  15914. 'UniJIS2004-UTF32-H',
  15915. 'UniJIS2004-UTF32-V',
  15916. 'UniJIS2004-UTF8-H',
  15917. 'UniJIS2004-UTF8-V',
  15918. 'UniJISPro-UCS2-HW-V',
  15919. 'UniJISPro-UCS2-V',
  15920. 'UniJISPro-UTF8-V',
  15921. 'UniJISX0213-UTF32-H',
  15922. 'UniJISX0213-UTF32-V',
  15923. 'UniJISX02132004-UTF32-H',
  15924. 'UniJISX02132004-UTF32-V',
  15925. 'UniKS-UCS2-H',
  15926. 'UniKS-UCS2-V',
  15927. 'UniKS-UTF16-H',
  15928. 'UniKS-UTF16-V',
  15929. 'UniKS-UTF32-H',
  15930. 'UniKS-UTF32-V',
  15931. 'UniKS-UTF8-H',
  15932. 'UniKS-UTF8-V',
  15933. 'V',
  15934. 'WP-Symbol'];
  15935. // CMap, not to be confused with TrueType's cmap.
  15936. var CMap = (function CMapClosure() {
  15937. function CMap(builtInCMap) {
  15938. // Codespace ranges are stored as follows:
  15939. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  15940. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  15941. this.codespaceRanges = [[], [], [], []];
  15942. this.numCodespaceRanges = 0;
  15943. // Map entries have one of two forms.
  15944. // - cid chars are 16-bit unsigned integers, stored as integers.
  15945. // - bf chars are variable-length byte sequences, stored as strings, with
  15946. // one byte per character.
  15947. this._map = [];
  15948. this.vertical = false;
  15949. this.useCMap = null;
  15950. this.builtInCMap = builtInCMap;
  15951. }
  15952. CMap.prototype = {
  15953. addCodespaceRange: function(n, low, high) {
  15954. this.codespaceRanges[n - 1].push(low, high);
  15955. this.numCodespaceRanges++;
  15956. },
  15957. mapCidRange: function(low, high, dstLow) {
  15958. while (low <= high) {
  15959. this._map[low++] = dstLow++;
  15960. }
  15961. },
  15962. mapBfRange: function(low, high, dstLow) {
  15963. var lastByte = dstLow.length - 1;
  15964. while (low <= high) {
  15965. this._map[low++] = dstLow;
  15966. // Only the last byte has to be incremented.
  15967. dstLow = dstLow.substr(0, lastByte) +
  15968. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  15969. }
  15970. },
  15971. mapBfRangeToArray: function(low, high, array) {
  15972. var i = 0, ii = array.length;
  15973. while (low <= high && i < ii) {
  15974. this._map[low] = array[i++];
  15975. ++low;
  15976. }
  15977. },
  15978. // This is used for both bf and cid chars.
  15979. mapOne: function(src, dst) {
  15980. this._map[src] = dst;
  15981. },
  15982. lookup: function(code) {
  15983. return this._map[code];
  15984. },
  15985. contains: function(code) {
  15986. return this._map[code] !== undefined;
  15987. },
  15988. forEach: function(callback) {
  15989. // Most maps have fewer than 65536 entries, and for those we use normal
  15990. // array iteration. But really sparse tables are possible -- e.g. with
  15991. // indices in the *billions*. For such tables we use for..in, which isn't
  15992. // ideal because it stringifies the indices for all present elements, but
  15993. // it does avoid iterating over every undefined entry.
  15994. var map = this._map;
  15995. var length = map.length;
  15996. var i;
  15997. if (length <= 0x10000) {
  15998. for (i = 0; i < length; i++) {
  15999. if (map[i] !== undefined) {
  16000. callback(i, map[i]);
  16001. }
  16002. }
  16003. } else {
  16004. for (i in this._map) {
  16005. callback(i, map[i]);
  16006. }
  16007. }
  16008. },
  16009. charCodeOf: function(value) {
  16010. return this._map.indexOf(value);
  16011. },
  16012. getMap: function() {
  16013. return this._map;
  16014. },
  16015. readCharCode: function(str, offset) {
  16016. var c = 0;
  16017. var codespaceRanges = this.codespaceRanges;
  16018. var codespaceRangesLen = this.codespaceRanges.length;
  16019. // 9.7.6.2 CMap Mapping
  16020. // The code length is at most 4.
  16021. for (var n = 0; n < codespaceRangesLen; n++) {
  16022. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  16023. // Check each codespace range to see if it falls within.
  16024. var codespaceRange = codespaceRanges[n];
  16025. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  16026. var low = codespaceRange[k++];
  16027. var high = codespaceRange[k++];
  16028. if (c >= low && c <= high) {
  16029. return [c, n + 1];
  16030. }
  16031. }
  16032. }
  16033. return [0, 1];
  16034. }
  16035. };
  16036. return CMap;
  16037. })();
  16038. var IdentityCMap = (function IdentityCMapClosure() {
  16039. function IdentityCMap(vertical, n) {
  16040. CMap.call(this);
  16041. this.vertical = vertical;
  16042. this.addCodespaceRange(n, 0, 0xffff);
  16043. this.mapCidRange(0, 0xffff, 0);
  16044. }
  16045. Util.inherit(IdentityCMap, CMap, {});
  16046. return IdentityCMap;
  16047. })();
  16048. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  16049. function fetchBinaryData(url) {
  16050. var nonBinaryRequest = PDFJS.disableWorker;
  16051. var request = new XMLHttpRequest();
  16052. request.open('GET', url, false);
  16053. if (!nonBinaryRequest) {
  16054. try {
  16055. request.responseType = 'arraybuffer';
  16056. nonBinaryRequest = request.responseType !== 'arraybuffer';
  16057. } catch (e) {
  16058. nonBinaryRequest = true;
  16059. }
  16060. }
  16061. if (nonBinaryRequest && request.overrideMimeType) {
  16062. request.overrideMimeType('text/plain; charset=x-user-defined');
  16063. }
  16064. request.send(null);
  16065. if (request.status === 0 && /^https?:/i.test(url)) {
  16066. error('Unable to get binary cMap at: ' + url);
  16067. }
  16068. if (nonBinaryRequest) {
  16069. var data = Array.prototype.map.call(request.responseText, function (ch) {
  16070. return ch.charCodeAt(0) & 255;
  16071. });
  16072. return new Uint8Array(data);
  16073. }
  16074. return new Uint8Array(request.response);
  16075. }
  16076. function hexToInt(a, size) {
  16077. var n = 0;
  16078. for (var i = 0; i <= size; i++) {
  16079. n = (n << 8) | a[i];
  16080. }
  16081. return n >>> 0;
  16082. }
  16083. function hexToStr(a, size) {
  16084. // This code is hot. Special-case some common values to avoid creating an
  16085. // object with subarray().
  16086. if (size === 1) {
  16087. return String.fromCharCode(a[0], a[1]);
  16088. }
  16089. if (size === 3) {
  16090. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  16091. }
  16092. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  16093. }
  16094. function addHex(a, b, size) {
  16095. var c = 0;
  16096. for (var i = size; i >= 0; i--) {
  16097. c += a[i] + b[i];
  16098. a[i] = c & 255;
  16099. c >>= 8;
  16100. }
  16101. }
  16102. function incHex(a, size) {
  16103. var c = 1;
  16104. for (var i = size; i >= 0 && c > 0; i--) {
  16105. c += a[i];
  16106. a[i] = c & 255;
  16107. c >>= 8;
  16108. }
  16109. }
  16110. var MAX_NUM_SIZE = 16;
  16111. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  16112. function BinaryCMapStream(data) {
  16113. this.buffer = data;
  16114. this.pos = 0;
  16115. this.end = data.length;
  16116. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  16117. }
  16118. BinaryCMapStream.prototype = {
  16119. readByte: function () {
  16120. if (this.pos >= this.end) {
  16121. return -1;
  16122. }
  16123. return this.buffer[this.pos++];
  16124. },
  16125. readNumber: function () {
  16126. var n = 0;
  16127. var last;
  16128. do {
  16129. var b = this.readByte();
  16130. if (b < 0) {
  16131. error('unexpected EOF in bcmap');
  16132. }
  16133. last = !(b & 0x80);
  16134. n = (n << 7) | (b & 0x7F);
  16135. } while (!last);
  16136. return n;
  16137. },
  16138. readSigned: function () {
  16139. var n = this.readNumber();
  16140. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  16141. },
  16142. readHex: function (num, size) {
  16143. num.set(this.buffer.subarray(this.pos,
  16144. this.pos + size + 1));
  16145. this.pos += size + 1;
  16146. },
  16147. readHexNumber: function (num, size) {
  16148. var last;
  16149. var stack = this.tmpBuf, sp = 0;
  16150. do {
  16151. var b = this.readByte();
  16152. if (b < 0) {
  16153. error('unexpected EOF in bcmap');
  16154. }
  16155. last = !(b & 0x80);
  16156. stack[sp++] = b & 0x7F;
  16157. } while (!last);
  16158. var i = size, buffer = 0, bufferSize = 0;
  16159. while (i >= 0) {
  16160. while (bufferSize < 8 && stack.length > 0) {
  16161. buffer = (stack[--sp] << bufferSize) | buffer;
  16162. bufferSize += 7;
  16163. }
  16164. num[i] = buffer & 255;
  16165. i--;
  16166. buffer >>= 8;
  16167. bufferSize -= 8;
  16168. }
  16169. },
  16170. readHexSigned: function (num, size) {
  16171. this.readHexNumber(num, size);
  16172. var sign = num[size] & 1 ? 255 : 0;
  16173. var c = 0;
  16174. for (var i = 0; i <= size; i++) {
  16175. c = ((c & 1) << 8) | num[i];
  16176. num[i] = (c >> 1) ^ sign;
  16177. }
  16178. },
  16179. readString: function () {
  16180. var len = this.readNumber();
  16181. var s = '';
  16182. for (var i = 0; i < len; i++) {
  16183. s += String.fromCharCode(this.readNumber());
  16184. }
  16185. return s;
  16186. }
  16187. };
  16188. function processBinaryCMap(url, cMap, extend) {
  16189. var data = fetchBinaryData(url);
  16190. var stream = new BinaryCMapStream(data);
  16191. var header = stream.readByte();
  16192. cMap.vertical = !!(header & 1);
  16193. var useCMap = null;
  16194. var start = new Uint8Array(MAX_NUM_SIZE);
  16195. var end = new Uint8Array(MAX_NUM_SIZE);
  16196. var char = new Uint8Array(MAX_NUM_SIZE);
  16197. var charCode = new Uint8Array(MAX_NUM_SIZE);
  16198. var tmp = new Uint8Array(MAX_NUM_SIZE);
  16199. var code;
  16200. var b;
  16201. while ((b = stream.readByte()) >= 0) {
  16202. var type = b >> 5;
  16203. if (type === 7) { // metadata, e.g. comment or usecmap
  16204. switch (b & 0x1F) {
  16205. case 0:
  16206. stream.readString(); // skipping comment
  16207. break;
  16208. case 1:
  16209. useCMap = stream.readString();
  16210. break;
  16211. }
  16212. continue;
  16213. }
  16214. var sequence = !!(b & 0x10);
  16215. var dataSize = b & 15;
  16216. assert(dataSize + 1 <= MAX_NUM_SIZE);
  16217. var ucs2DataSize = 1;
  16218. var subitemsCount = stream.readNumber();
  16219. var i;
  16220. switch (type) {
  16221. case 0: // codespacerange
  16222. stream.readHex(start, dataSize);
  16223. stream.readHexNumber(end, dataSize);
  16224. addHex(end, start, dataSize);
  16225. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  16226. hexToInt(end, dataSize));
  16227. for (i = 1; i < subitemsCount; i++) {
  16228. incHex(end, dataSize);
  16229. stream.readHexNumber(start, dataSize);
  16230. addHex(start, end, dataSize);
  16231. stream.readHexNumber(end, dataSize);
  16232. addHex(end, start, dataSize);
  16233. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  16234. hexToInt(end, dataSize));
  16235. }
  16236. break;
  16237. case 1: // notdefrange
  16238. stream.readHex(start, dataSize);
  16239. stream.readHexNumber(end, dataSize);
  16240. addHex(end, start, dataSize);
  16241. code = stream.readNumber();
  16242. // undefined range, skipping
  16243. for (i = 1; i < subitemsCount; i++) {
  16244. incHex(end, dataSize);
  16245. stream.readHexNumber(start, dataSize);
  16246. addHex(start, end, dataSize);
  16247. stream.readHexNumber(end, dataSize);
  16248. addHex(end, start, dataSize);
  16249. code = stream.readNumber();
  16250. // nop
  16251. }
  16252. break;
  16253. case 2: // cidchar
  16254. stream.readHex(char, dataSize);
  16255. code = stream.readNumber();
  16256. cMap.mapOne(hexToInt(char, dataSize), code);
  16257. for (i = 1; i < subitemsCount; i++) {
  16258. incHex(char, dataSize);
  16259. if (!sequence) {
  16260. stream.readHexNumber(tmp, dataSize);
  16261. addHex(char, tmp, dataSize);
  16262. }
  16263. code = stream.readSigned() + (code + 1);
  16264. cMap.mapOne(hexToInt(char, dataSize), code);
  16265. }
  16266. break;
  16267. case 3: // cidrange
  16268. stream.readHex(start, dataSize);
  16269. stream.readHexNumber(end, dataSize);
  16270. addHex(end, start, dataSize);
  16271. code = stream.readNumber();
  16272. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  16273. code);
  16274. for (i = 1; i < subitemsCount; i++) {
  16275. incHex(end, dataSize);
  16276. if (!sequence) {
  16277. stream.readHexNumber(start, dataSize);
  16278. addHex(start, end, dataSize);
  16279. } else {
  16280. start.set(end);
  16281. }
  16282. stream.readHexNumber(end, dataSize);
  16283. addHex(end, start, dataSize);
  16284. code = stream.readNumber();
  16285. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  16286. code);
  16287. }
  16288. break;
  16289. case 4: // bfchar
  16290. stream.readHex(char, ucs2DataSize);
  16291. stream.readHex(charCode, dataSize);
  16292. cMap.mapOne(hexToInt(char, ucs2DataSize),
  16293. hexToStr(charCode, dataSize));
  16294. for (i = 1; i < subitemsCount; i++) {
  16295. incHex(char, ucs2DataSize);
  16296. if (!sequence) {
  16297. stream.readHexNumber(tmp, ucs2DataSize);
  16298. addHex(char, tmp, ucs2DataSize);
  16299. }
  16300. incHex(charCode, dataSize);
  16301. stream.readHexSigned(tmp, dataSize);
  16302. addHex(charCode, tmp, dataSize);
  16303. cMap.mapOne(hexToInt(char, ucs2DataSize),
  16304. hexToStr(charCode, dataSize));
  16305. }
  16306. break;
  16307. case 5: // bfrange
  16308. stream.readHex(start, ucs2DataSize);
  16309. stream.readHexNumber(end, ucs2DataSize);
  16310. addHex(end, start, ucs2DataSize);
  16311. stream.readHex(charCode, dataSize);
  16312. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  16313. hexToInt(end, ucs2DataSize),
  16314. hexToStr(charCode, dataSize));
  16315. for (i = 1; i < subitemsCount; i++) {
  16316. incHex(end, ucs2DataSize);
  16317. if (!sequence) {
  16318. stream.readHexNumber(start, ucs2DataSize);
  16319. addHex(start, end, ucs2DataSize);
  16320. } else {
  16321. start.set(end);
  16322. }
  16323. stream.readHexNumber(end, ucs2DataSize);
  16324. addHex(end, start, ucs2DataSize);
  16325. stream.readHex(charCode, dataSize);
  16326. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  16327. hexToInt(end, ucs2DataSize),
  16328. hexToStr(charCode, dataSize));
  16329. }
  16330. break;
  16331. default:
  16332. error('Unknown type: ' + type);
  16333. break;
  16334. }
  16335. }
  16336. if (useCMap) {
  16337. extend(useCMap);
  16338. }
  16339. return cMap;
  16340. }
  16341. function BinaryCMapReader() {}
  16342. BinaryCMapReader.prototype = {
  16343. read: processBinaryCMap
  16344. };
  16345. return BinaryCMapReader;
  16346. })();
  16347. var CMapFactory = (function CMapFactoryClosure() {
  16348. function strToInt(str) {
  16349. var a = 0;
  16350. for (var i = 0; i < str.length; i++) {
  16351. a = (a << 8) | str.charCodeAt(i);
  16352. }
  16353. return a >>> 0;
  16354. }
  16355. function expectString(obj) {
  16356. if (!isString(obj)) {
  16357. error('Malformed CMap: expected string.');
  16358. }
  16359. }
  16360. function expectInt(obj) {
  16361. if (!isInt(obj)) {
  16362. error('Malformed CMap: expected int.');
  16363. }
  16364. }
  16365. function parseBfChar(cMap, lexer) {
  16366. while (true) {
  16367. var obj = lexer.getObj();
  16368. if (isEOF(obj)) {
  16369. break;
  16370. }
  16371. if (isCmd(obj, 'endbfchar')) {
  16372. return;
  16373. }
  16374. expectString(obj);
  16375. var src = strToInt(obj);
  16376. obj = lexer.getObj();
  16377. // TODO are /dstName used?
  16378. expectString(obj);
  16379. var dst = obj;
  16380. cMap.mapOne(src, dst);
  16381. }
  16382. }
  16383. function parseBfRange(cMap, lexer) {
  16384. while (true) {
  16385. var obj = lexer.getObj();
  16386. if (isEOF(obj)) {
  16387. break;
  16388. }
  16389. if (isCmd(obj, 'endbfrange')) {
  16390. return;
  16391. }
  16392. expectString(obj);
  16393. var low = strToInt(obj);
  16394. obj = lexer.getObj();
  16395. expectString(obj);
  16396. var high = strToInt(obj);
  16397. obj = lexer.getObj();
  16398. if (isInt(obj) || isString(obj)) {
  16399. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  16400. cMap.mapBfRange(low, high, dstLow);
  16401. } else if (isCmd(obj, '[')) {
  16402. obj = lexer.getObj();
  16403. var array = [];
  16404. while (!isCmd(obj, ']') && !isEOF(obj)) {
  16405. array.push(obj);
  16406. obj = lexer.getObj();
  16407. }
  16408. cMap.mapBfRangeToArray(low, high, array);
  16409. } else {
  16410. break;
  16411. }
  16412. }
  16413. error('Invalid bf range.');
  16414. }
  16415. function parseCidChar(cMap, lexer) {
  16416. while (true) {
  16417. var obj = lexer.getObj();
  16418. if (isEOF(obj)) {
  16419. break;
  16420. }
  16421. if (isCmd(obj, 'endcidchar')) {
  16422. return;
  16423. }
  16424. expectString(obj);
  16425. var src = strToInt(obj);
  16426. obj = lexer.getObj();
  16427. expectInt(obj);
  16428. var dst = obj;
  16429. cMap.mapOne(src, dst);
  16430. }
  16431. }
  16432. function parseCidRange(cMap, lexer) {
  16433. while (true) {
  16434. var obj = lexer.getObj();
  16435. if (isEOF(obj)) {
  16436. break;
  16437. }
  16438. if (isCmd(obj, 'endcidrange')) {
  16439. return;
  16440. }
  16441. expectString(obj);
  16442. var low = strToInt(obj);
  16443. obj = lexer.getObj();
  16444. expectString(obj);
  16445. var high = strToInt(obj);
  16446. obj = lexer.getObj();
  16447. expectInt(obj);
  16448. var dstLow = obj;
  16449. cMap.mapCidRange(low, high, dstLow);
  16450. }
  16451. }
  16452. function parseCodespaceRange(cMap, lexer) {
  16453. while (true) {
  16454. var obj = lexer.getObj();
  16455. if (isEOF(obj)) {
  16456. break;
  16457. }
  16458. if (isCmd(obj, 'endcodespacerange')) {
  16459. return;
  16460. }
  16461. if (!isString(obj)) {
  16462. break;
  16463. }
  16464. var low = strToInt(obj);
  16465. obj = lexer.getObj();
  16466. if (!isString(obj)) {
  16467. break;
  16468. }
  16469. var high = strToInt(obj);
  16470. cMap.addCodespaceRange(obj.length, low, high);
  16471. }
  16472. error('Invalid codespace range.');
  16473. }
  16474. function parseWMode(cMap, lexer) {
  16475. var obj = lexer.getObj();
  16476. if (isInt(obj)) {
  16477. cMap.vertical = !!obj;
  16478. }
  16479. }
  16480. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  16481. var previous;
  16482. var embededUseCMap;
  16483. objLoop: while (true) {
  16484. var obj = lexer.getObj();
  16485. if (isEOF(obj)) {
  16486. break;
  16487. } else if (isName(obj)) {
  16488. if (obj.name === 'WMode') {
  16489. parseWMode(cMap, lexer);
  16490. }
  16491. previous = obj;
  16492. } else if (isCmd(obj)) {
  16493. switch (obj.cmd) {
  16494. case 'endcmap':
  16495. break objLoop;
  16496. case 'usecmap':
  16497. if (isName(previous)) {
  16498. embededUseCMap = previous.name;
  16499. }
  16500. break;
  16501. case 'begincodespacerange':
  16502. parseCodespaceRange(cMap, lexer);
  16503. break;
  16504. case 'beginbfchar':
  16505. parseBfChar(cMap, lexer);
  16506. break;
  16507. case 'begincidchar':
  16508. parseCidChar(cMap, lexer);
  16509. break;
  16510. case 'beginbfrange':
  16511. parseBfRange(cMap, lexer);
  16512. break;
  16513. case 'begincidrange':
  16514. parseCidRange(cMap, lexer);
  16515. break;
  16516. }
  16517. }
  16518. }
  16519. if (!useCMap && embededUseCMap) {
  16520. // Load the usecmap definition from the file only if there wasn't one
  16521. // specified.
  16522. useCMap = embededUseCMap;
  16523. }
  16524. if (useCMap) {
  16525. extendCMap(cMap, builtInCMapParams, useCMap);
  16526. }
  16527. }
  16528. function extendCMap(cMap, builtInCMapParams, useCMap) {
  16529. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  16530. // If there aren't any code space ranges defined clone all the parent ones
  16531. // into this cMap.
  16532. if (cMap.numCodespaceRanges === 0) {
  16533. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  16534. for (var i = 0; i < useCodespaceRanges.length; i++) {
  16535. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  16536. }
  16537. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  16538. }
  16539. // Merge the map into the current one, making sure not to override
  16540. // any previously defined entries.
  16541. cMap.useCMap.forEach(function(key, value) {
  16542. if (!cMap.contains(key)) {
  16543. cMap.mapOne(key, cMap.useCMap.lookup(key));
  16544. }
  16545. });
  16546. }
  16547. function parseBinaryCMap(name, builtInCMapParams) {
  16548. var url = builtInCMapParams.url + name + '.bcmap';
  16549. var cMap = new CMap(true);
  16550. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  16551. extendCMap(cMap, builtInCMapParams, useCMap);
  16552. });
  16553. return cMap;
  16554. }
  16555. function createBuiltInCMap(name, builtInCMapParams) {
  16556. if (name === 'Identity-H') {
  16557. return new IdentityCMap(false, 2);
  16558. } else if (name === 'Identity-V') {
  16559. return new IdentityCMap(true, 2);
  16560. }
  16561. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  16562. error('Unknown cMap name: ' + name);
  16563. }
  16564. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  16565. if (builtInCMapParams.packed) {
  16566. return parseBinaryCMap(name, builtInCMapParams);
  16567. }
  16568. var request = new XMLHttpRequest();
  16569. var url = builtInCMapParams.url + name;
  16570. request.open('GET', url, false);
  16571. request.send(null);
  16572. if (request.status === 0 && /^https?:/i.test(url)) {
  16573. error('Unable to get cMap at: ' + url);
  16574. }
  16575. var cMap = new CMap(true);
  16576. var lexer = new Lexer(new StringStream(request.responseText));
  16577. parseCMap(cMap, lexer, builtInCMapParams, null);
  16578. return cMap;
  16579. }
  16580. return {
  16581. create: function (encoding, builtInCMapParams, useCMap) {
  16582. if (isName(encoding)) {
  16583. return createBuiltInCMap(encoding.name, builtInCMapParams);
  16584. } else if (isStream(encoding)) {
  16585. var cMap = new CMap();
  16586. var lexer = new Lexer(encoding);
  16587. try {
  16588. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  16589. } catch (e) {
  16590. warn('Invalid CMap data. ' + e);
  16591. }
  16592. return cMap;
  16593. }
  16594. error('Encoding required.');
  16595. }
  16596. };
  16597. })();
  16598. // Unicode Private Use Area
  16599. var PRIVATE_USE_OFFSET_START = 0xE000;
  16600. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  16601. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  16602. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  16603. // except for Type 3 fonts
  16604. var PDF_GLYPH_SPACE_UNITS = 1000;
  16605. // Hinting is currently disabled due to unknown problems on windows
  16606. // in tracemonkey and various other pdfs with type1 fonts.
  16607. var HINTING_ENABLED = false;
  16608. // Accented charactars are not displayed properly on windows, using this flag
  16609. // to control analysis of seac charstrings.
  16610. var SEAC_ANALYSIS_ENABLED = false;
  16611. var FontFlags = {
  16612. FixedPitch: 1,
  16613. Serif: 2,
  16614. Symbolic: 4,
  16615. Script: 8,
  16616. Nonsymbolic: 32,
  16617. Italic: 64,
  16618. AllCap: 65536,
  16619. SmallCap: 131072,
  16620. ForceBold: 262144
  16621. };
  16622. var Encodings = {
  16623. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16624. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16625. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  16626. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  16627. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  16628. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  16629. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  16630. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  16631. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  16632. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  16633. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  16634. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  16635. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  16636. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  16637. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  16638. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  16639. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  16640. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  16641. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  16642. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16643. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  16644. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  16645. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  16646. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  16647. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  16648. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  16649. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  16650. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  16651. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  16652. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  16653. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  16654. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  16655. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  16656. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  16657. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  16658. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  16659. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  16660. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  16661. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  16662. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  16663. 'Ydieresissmall'],
  16664. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16665. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16666. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  16667. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  16668. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  16669. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  16670. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  16671. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  16672. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  16673. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  16674. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  16675. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  16676. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  16677. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  16678. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  16679. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  16680. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  16681. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  16682. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  16683. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  16684. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  16685. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  16686. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  16687. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  16688. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  16689. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  16690. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  16691. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  16692. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  16693. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  16694. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  16695. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  16696. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  16697. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  16698. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  16699. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  16700. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  16701. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  16702. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  16703. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  16704. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16705. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16706. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  16707. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  16708. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  16709. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  16710. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  16711. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  16712. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  16713. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  16714. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  16715. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  16716. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  16717. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  16718. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  16719. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  16720. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  16721. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  16722. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  16723. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  16724. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  16725. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  16726. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  16727. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  16728. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  16729. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  16730. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  16731. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  16732. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  16733. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  16734. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  16735. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  16736. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  16737. 'ogonek', 'caron'],
  16738. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16739. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16740. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  16741. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  16742. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  16743. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  16744. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  16745. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  16746. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  16747. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  16748. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  16749. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  16750. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16751. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  16752. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  16753. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  16754. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  16755. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  16756. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  16757. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  16758. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  16759. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  16760. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  16761. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  16762. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  16763. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16764. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16765. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  16766. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  16767. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  16768. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  16769. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  16770. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  16771. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  16772. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  16773. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  16774. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  16775. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  16776. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  16777. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  16778. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  16779. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  16780. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  16781. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  16782. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  16783. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  16784. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  16785. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  16786. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  16787. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  16788. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  16789. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  16790. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  16791. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  16792. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  16793. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  16794. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  16795. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  16796. 'ydieresis'],
  16797. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16798. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16799. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  16800. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  16801. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  16802. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  16803. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  16804. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  16805. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  16806. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  16807. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  16808. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  16809. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  16810. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  16811. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  16812. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16813. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  16814. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  16815. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  16816. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  16817. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  16818. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  16819. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  16820. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  16821. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  16822. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  16823. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  16824. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  16825. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  16826. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  16827. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  16828. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  16829. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  16830. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  16831. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  16832. 'bracerightbt'],
  16833. zapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16834. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16835. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  16836. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  16837. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  16838. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  16839. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  16840. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  16841. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  16842. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  16843. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  16844. 'a98', 'a99', 'a100', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16845. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  16846. '', '', 'a101', 'a102', 'a103', 'a104', 'a106', 'a107', 'a108', 'a112',
  16847. 'a111', 'a110', 'a109', 'a120', 'a121', 'a122', 'a123', 'a124', 'a125',
  16848. 'a126', 'a127', 'a128', 'a129', 'a130', 'a131', 'a132', 'a133', 'a134',
  16849. 'a135', 'a136', 'a137', 'a138', 'a139', 'a140', 'a141', 'a142', 'a143',
  16850. 'a144', 'a145', 'a146', 'a147', 'a148', 'a149', 'a150', 'a151', 'a152',
  16851. 'a153', 'a154', 'a155', 'a156', 'a157', 'a158', 'a159', 'a160', 'a161',
  16852. 'a163', 'a164', 'a196', 'a165', 'a192', 'a166', 'a167', 'a168', 'a169',
  16853. 'a170', 'a171', 'a172', 'a173', 'a162', 'a174', 'a175', 'a176', 'a177',
  16854. 'a178', 'a179', 'a193', 'a180', 'a199', 'a181', 'a200', 'a182', '', 'a201',
  16855. 'a183', 'a184', 'a197', 'a185', 'a194', 'a198', 'a186', 'a195', 'a187',
  16856. 'a188', 'a189', 'a190', 'a191']
  16857. };
  16858. /**
  16859. * Hold a map of decoded fonts and of the standard fourteen Type1
  16860. * fonts and their acronyms.
  16861. */
  16862. var stdFontMap = {
  16863. 'ArialNarrow': 'Helvetica',
  16864. 'ArialNarrow-Bold': 'Helvetica-Bold',
  16865. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  16866. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  16867. 'ArialBlack': 'Helvetica',
  16868. 'ArialBlack-Bold': 'Helvetica-Bold',
  16869. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  16870. 'ArialBlack-Italic': 'Helvetica-Oblique',
  16871. 'Arial': 'Helvetica',
  16872. 'Arial-Bold': 'Helvetica-Bold',
  16873. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  16874. 'Arial-Italic': 'Helvetica-Oblique',
  16875. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  16876. 'Arial-BoldMT': 'Helvetica-Bold',
  16877. 'Arial-ItalicMT': 'Helvetica-Oblique',
  16878. 'ArialMT': 'Helvetica',
  16879. 'Courier-Bold': 'Courier-Bold',
  16880. 'Courier-BoldItalic': 'Courier-BoldOblique',
  16881. 'Courier-Italic': 'Courier-Oblique',
  16882. 'CourierNew': 'Courier',
  16883. 'CourierNew-Bold': 'Courier-Bold',
  16884. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  16885. 'CourierNew-Italic': 'Courier-Oblique',
  16886. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  16887. 'CourierNewPS-BoldMT': 'Courier-Bold',
  16888. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  16889. 'CourierNewPSMT': 'Courier',
  16890. 'Helvetica-Bold': 'Helvetica-Bold',
  16891. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  16892. 'Helvetica-Italic': 'Helvetica-Oblique',
  16893. 'Symbol-Bold': 'Symbol',
  16894. 'Symbol-BoldItalic': 'Symbol',
  16895. 'Symbol-Italic': 'Symbol',
  16896. 'TimesNewRoman': 'Times-Roman',
  16897. 'TimesNewRoman-Bold': 'Times-Bold',
  16898. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  16899. 'TimesNewRoman-Italic': 'Times-Italic',
  16900. 'TimesNewRomanPS': 'Times-Roman',
  16901. 'TimesNewRomanPS-Bold': 'Times-Bold',
  16902. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  16903. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  16904. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  16905. 'TimesNewRomanPS-Italic': 'Times-Italic',
  16906. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  16907. 'TimesNewRomanPSMT': 'Times-Roman',
  16908. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  16909. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  16910. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  16911. };
  16912. /**
  16913. * Holds the map of the non-standard fonts that might be included as a standard
  16914. * fonts without glyph data.
  16915. */
  16916. var nonStdFontMap = {
  16917. 'ComicSansMS': 'Comic Sans MS',
  16918. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  16919. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  16920. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  16921. 'LucidaConsole': 'Courier',
  16922. 'LucidaConsole-Bold': 'Courier-Bold',
  16923. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  16924. 'LucidaConsole-Italic': 'Courier-Oblique',
  16925. 'MS-Gothic': 'MS Gothic',
  16926. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  16927. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  16928. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  16929. 'MS-Mincho': 'MS Mincho',
  16930. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  16931. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  16932. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  16933. 'MS-PGothic': 'MS PGothic',
  16934. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  16935. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  16936. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  16937. 'MS-PMincho': 'MS PMincho',
  16938. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  16939. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  16940. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  16941. };
  16942. var serifFonts = {
  16943. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  16944. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  16945. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  16946. 'Arno': true, 'Aster': true, 'Aurora': true,
  16947. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  16948. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  16949. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  16950. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  16951. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  16952. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  16953. 'Cartier': true, 'Caslon': true, 'Catull': true,
  16954. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  16955. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  16956. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  16957. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  16958. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  16959. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  16960. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  16961. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  16962. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  16963. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  16964. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  16965. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  16966. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  16967. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  16968. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  16969. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  16970. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  16971. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  16972. 'Miller': true, 'Minion': true, 'Modern': true,
  16973. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  16974. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  16975. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  16976. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  16977. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  16978. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  16979. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  16980. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  16981. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  16982. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  16983. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  16984. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  16985. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  16986. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  16987. };
  16988. var symbolsFonts = {
  16989. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  16990. };
  16991. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  16992. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  16993. // glyphs, but common for some set of the standard fonts.
  16994. var GlyphMapForStandardFonts = {
  16995. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  16996. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  16997. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  16998. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  16999. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  17000. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  17001. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  17002. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  17003. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  17004. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  17005. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  17006. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  17007. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  17008. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  17009. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  17010. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  17011. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  17012. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  17013. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  17014. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  17015. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  17016. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  17017. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  17018. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  17019. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  17020. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  17021. '227': 353, '229': 382, '234': 253, '253': 268, '254': 269, '258': 258,
  17022. '268': 283, '269': 313, '278': 328, '284': 345, '292': 367, '305': 963,
  17023. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  17024. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  17025. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  17026. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  17027. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  17028. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  17029. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  17030. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  17031. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  17032. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  17033. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  17034. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  17035. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  17036. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  17037. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  17038. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  17039. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  17040. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  17041. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  17042. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  17043. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  17044. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  17045. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  17046. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  17047. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  17048. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  17049. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  17050. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  17051. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  17052. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  17053. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  17054. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  17055. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  17056. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  17057. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  17058. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  17059. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  17060. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  17061. };
  17062. // Some characters, e.g. copyrightserif, mapped to the private use area and
  17063. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  17064. // to the similar equivalents in the normal characters range.
  17065. function mapSpecialUnicodeValues(code) {
  17066. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17067. return 0;
  17068. }
  17069. switch (code) {
  17070. case 0xF8E9: // copyrightsans
  17071. case 0xF6D9: // copyrightserif
  17072. return 0x00A9; // copyright
  17073. case 0xF8E8: // registersans
  17074. case 0xF6DA: // registerserif
  17075. return 0x00AE; // registered
  17076. case 0xF8EA: // trademarksans
  17077. case 0xF6DB: // trademarkserif
  17078. return 0x2122; // trademark
  17079. default:
  17080. return code;
  17081. }
  17082. }
  17083. var UnicodeRanges = [
  17084. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17085. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17086. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17087. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17088. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17089. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17090. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17091. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17092. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17093. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17094. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17095. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17096. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17097. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17098. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17099. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17100. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17101. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17102. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17103. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17104. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17105. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17106. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17107. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17108. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17109. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17110. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17111. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17112. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17113. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17114. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17115. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17116. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17117. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17118. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  17119. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17120. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17121. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17122. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17123. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17124. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17125. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17126. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17127. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17128. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17129. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17130. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17131. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17132. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17133. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17134. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17135. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17136. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17137. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17138. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17139. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17140. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17141. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17142. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17143. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17144. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17145. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17146. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17147. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17148. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17149. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17150. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17151. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17152. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17153. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17154. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17155. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17156. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17157. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17158. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17159. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17160. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17161. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17162. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17163. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17164. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17165. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17166. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17167. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17168. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17169. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17170. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17171. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17172. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17173. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17174. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17175. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17176. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17177. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17178. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17179. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17180. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17181. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17182. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17183. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17184. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17185. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17186. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17187. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17188. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17189. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17190. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17191. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17192. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17193. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17194. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17195. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17196. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17197. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17198. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17199. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17200. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17201. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17202. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17203. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17204. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17205. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17206. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17207. ];
  17208. var MacStandardGlyphOrdering = [
  17209. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  17210. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  17211. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  17212. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  17213. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  17214. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  17215. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  17216. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  17217. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  17218. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  17219. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  17220. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  17221. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  17222. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  17223. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  17224. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  17225. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  17226. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  17227. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  17228. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  17229. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  17230. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  17231. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  17232. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  17233. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  17234. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  17235. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  17236. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  17237. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  17238. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  17239. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  17240. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  17241. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  17242. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  17243. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  17244. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  17245. function getUnicodeRangeFor(value) {
  17246. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17247. var range = UnicodeRanges[i];
  17248. if (value >= range.begin && value < range.end) {
  17249. return i;
  17250. }
  17251. }
  17252. return -1;
  17253. }
  17254. function isRTLRangeFor(value) {
  17255. var range = UnicodeRanges[13];
  17256. if (value >= range.begin && value < range.end) {
  17257. return true;
  17258. }
  17259. range = UnicodeRanges[11];
  17260. if (value >= range.begin && value < range.end) {
  17261. return true;
  17262. }
  17263. return false;
  17264. }
  17265. // The normalization table is obtained by filtering the Unicode characters
  17266. // database with <compat> entries.
  17267. var NormalizedUnicodes = {
  17268. '\u00A8': '\u0020\u0308',
  17269. '\u00AF': '\u0020\u0304',
  17270. '\u00B4': '\u0020\u0301',
  17271. '\u00B5': '\u03BC',
  17272. '\u00B8': '\u0020\u0327',
  17273. '\u0132': '\u0049\u004A',
  17274. '\u0133': '\u0069\u006A',
  17275. '\u013F': '\u004C\u00B7',
  17276. '\u0140': '\u006C\u00B7',
  17277. '\u0149': '\u02BC\u006E',
  17278. '\u017F': '\u0073',
  17279. '\u01C4': '\u0044\u017D',
  17280. '\u01C5': '\u0044\u017E',
  17281. '\u01C6': '\u0064\u017E',
  17282. '\u01C7': '\u004C\u004A',
  17283. '\u01C8': '\u004C\u006A',
  17284. '\u01C9': '\u006C\u006A',
  17285. '\u01CA': '\u004E\u004A',
  17286. '\u01CB': '\u004E\u006A',
  17287. '\u01CC': '\u006E\u006A',
  17288. '\u01F1': '\u0044\u005A',
  17289. '\u01F2': '\u0044\u007A',
  17290. '\u01F3': '\u0064\u007A',
  17291. '\u02D8': '\u0020\u0306',
  17292. '\u02D9': '\u0020\u0307',
  17293. '\u02DA': '\u0020\u030A',
  17294. '\u02DB': '\u0020\u0328',
  17295. '\u02DC': '\u0020\u0303',
  17296. '\u02DD': '\u0020\u030B',
  17297. '\u037A': '\u0020\u0345',
  17298. '\u0384': '\u0020\u0301',
  17299. '\u03D0': '\u03B2',
  17300. '\u03D1': '\u03B8',
  17301. '\u03D2': '\u03A5',
  17302. '\u03D5': '\u03C6',
  17303. '\u03D6': '\u03C0',
  17304. '\u03F0': '\u03BA',
  17305. '\u03F1': '\u03C1',
  17306. '\u03F2': '\u03C2',
  17307. '\u03F4': '\u0398',
  17308. '\u03F5': '\u03B5',
  17309. '\u03F9': '\u03A3',
  17310. '\u0587': '\u0565\u0582',
  17311. '\u0675': '\u0627\u0674',
  17312. '\u0676': '\u0648\u0674',
  17313. '\u0677': '\u06C7\u0674',
  17314. '\u0678': '\u064A\u0674',
  17315. '\u0E33': '\u0E4D\u0E32',
  17316. '\u0EB3': '\u0ECD\u0EB2',
  17317. '\u0EDC': '\u0EAB\u0E99',
  17318. '\u0EDD': '\u0EAB\u0EA1',
  17319. '\u0F77': '\u0FB2\u0F81',
  17320. '\u0F79': '\u0FB3\u0F81',
  17321. '\u1E9A': '\u0061\u02BE',
  17322. '\u1FBD': '\u0020\u0313',
  17323. '\u1FBF': '\u0020\u0313',
  17324. '\u1FC0': '\u0020\u0342',
  17325. '\u1FFE': '\u0020\u0314',
  17326. '\u2002': '\u0020',
  17327. '\u2003': '\u0020',
  17328. '\u2004': '\u0020',
  17329. '\u2005': '\u0020',
  17330. '\u2006': '\u0020',
  17331. '\u2008': '\u0020',
  17332. '\u2009': '\u0020',
  17333. '\u200A': '\u0020',
  17334. '\u2017': '\u0020\u0333',
  17335. '\u2024': '\u002E',
  17336. '\u2025': '\u002E\u002E',
  17337. '\u2026': '\u002E\u002E\u002E',
  17338. '\u2033': '\u2032\u2032',
  17339. '\u2034': '\u2032\u2032\u2032',
  17340. '\u2036': '\u2035\u2035',
  17341. '\u2037': '\u2035\u2035\u2035',
  17342. '\u203C': '\u0021\u0021',
  17343. '\u203E': '\u0020\u0305',
  17344. '\u2047': '\u003F\u003F',
  17345. '\u2048': '\u003F\u0021',
  17346. '\u2049': '\u0021\u003F',
  17347. '\u2057': '\u2032\u2032\u2032\u2032',
  17348. '\u205F': '\u0020',
  17349. '\u20A8': '\u0052\u0073',
  17350. '\u2100': '\u0061\u002F\u0063',
  17351. '\u2101': '\u0061\u002F\u0073',
  17352. '\u2103': '\u00B0\u0043',
  17353. '\u2105': '\u0063\u002F\u006F',
  17354. '\u2106': '\u0063\u002F\u0075',
  17355. '\u2107': '\u0190',
  17356. '\u2109': '\u00B0\u0046',
  17357. '\u2116': '\u004E\u006F',
  17358. '\u2121': '\u0054\u0045\u004C',
  17359. '\u2135': '\u05D0',
  17360. '\u2136': '\u05D1',
  17361. '\u2137': '\u05D2',
  17362. '\u2138': '\u05D3',
  17363. '\u213B': '\u0046\u0041\u0058',
  17364. '\u2160': '\u0049',
  17365. '\u2161': '\u0049\u0049',
  17366. '\u2162': '\u0049\u0049\u0049',
  17367. '\u2163': '\u0049\u0056',
  17368. '\u2164': '\u0056',
  17369. '\u2165': '\u0056\u0049',
  17370. '\u2166': '\u0056\u0049\u0049',
  17371. '\u2167': '\u0056\u0049\u0049\u0049',
  17372. '\u2168': '\u0049\u0058',
  17373. '\u2169': '\u0058',
  17374. '\u216A': '\u0058\u0049',
  17375. '\u216B': '\u0058\u0049\u0049',
  17376. '\u216C': '\u004C',
  17377. '\u216D': '\u0043',
  17378. '\u216E': '\u0044',
  17379. '\u216F': '\u004D',
  17380. '\u2170': '\u0069',
  17381. '\u2171': '\u0069\u0069',
  17382. '\u2172': '\u0069\u0069\u0069',
  17383. '\u2173': '\u0069\u0076',
  17384. '\u2174': '\u0076',
  17385. '\u2175': '\u0076\u0069',
  17386. '\u2176': '\u0076\u0069\u0069',
  17387. '\u2177': '\u0076\u0069\u0069\u0069',
  17388. '\u2178': '\u0069\u0078',
  17389. '\u2179': '\u0078',
  17390. '\u217A': '\u0078\u0069',
  17391. '\u217B': '\u0078\u0069\u0069',
  17392. '\u217C': '\u006C',
  17393. '\u217D': '\u0063',
  17394. '\u217E': '\u0064',
  17395. '\u217F': '\u006D',
  17396. '\u222C': '\u222B\u222B',
  17397. '\u222D': '\u222B\u222B\u222B',
  17398. '\u222F': '\u222E\u222E',
  17399. '\u2230': '\u222E\u222E\u222E',
  17400. '\u2474': '\u0028\u0031\u0029',
  17401. '\u2475': '\u0028\u0032\u0029',
  17402. '\u2476': '\u0028\u0033\u0029',
  17403. '\u2477': '\u0028\u0034\u0029',
  17404. '\u2478': '\u0028\u0035\u0029',
  17405. '\u2479': '\u0028\u0036\u0029',
  17406. '\u247A': '\u0028\u0037\u0029',
  17407. '\u247B': '\u0028\u0038\u0029',
  17408. '\u247C': '\u0028\u0039\u0029',
  17409. '\u247D': '\u0028\u0031\u0030\u0029',
  17410. '\u247E': '\u0028\u0031\u0031\u0029',
  17411. '\u247F': '\u0028\u0031\u0032\u0029',
  17412. '\u2480': '\u0028\u0031\u0033\u0029',
  17413. '\u2481': '\u0028\u0031\u0034\u0029',
  17414. '\u2482': '\u0028\u0031\u0035\u0029',
  17415. '\u2483': '\u0028\u0031\u0036\u0029',
  17416. '\u2484': '\u0028\u0031\u0037\u0029',
  17417. '\u2485': '\u0028\u0031\u0038\u0029',
  17418. '\u2486': '\u0028\u0031\u0039\u0029',
  17419. '\u2487': '\u0028\u0032\u0030\u0029',
  17420. '\u2488': '\u0031\u002E',
  17421. '\u2489': '\u0032\u002E',
  17422. '\u248A': '\u0033\u002E',
  17423. '\u248B': '\u0034\u002E',
  17424. '\u248C': '\u0035\u002E',
  17425. '\u248D': '\u0036\u002E',
  17426. '\u248E': '\u0037\u002E',
  17427. '\u248F': '\u0038\u002E',
  17428. '\u2490': '\u0039\u002E',
  17429. '\u2491': '\u0031\u0030\u002E',
  17430. '\u2492': '\u0031\u0031\u002E',
  17431. '\u2493': '\u0031\u0032\u002E',
  17432. '\u2494': '\u0031\u0033\u002E',
  17433. '\u2495': '\u0031\u0034\u002E',
  17434. '\u2496': '\u0031\u0035\u002E',
  17435. '\u2497': '\u0031\u0036\u002E',
  17436. '\u2498': '\u0031\u0037\u002E',
  17437. '\u2499': '\u0031\u0038\u002E',
  17438. '\u249A': '\u0031\u0039\u002E',
  17439. '\u249B': '\u0032\u0030\u002E',
  17440. '\u249C': '\u0028\u0061\u0029',
  17441. '\u249D': '\u0028\u0062\u0029',
  17442. '\u249E': '\u0028\u0063\u0029',
  17443. '\u249F': '\u0028\u0064\u0029',
  17444. '\u24A0': '\u0028\u0065\u0029',
  17445. '\u24A1': '\u0028\u0066\u0029',
  17446. '\u24A2': '\u0028\u0067\u0029',
  17447. '\u24A3': '\u0028\u0068\u0029',
  17448. '\u24A4': '\u0028\u0069\u0029',
  17449. '\u24A5': '\u0028\u006A\u0029',
  17450. '\u24A6': '\u0028\u006B\u0029',
  17451. '\u24A7': '\u0028\u006C\u0029',
  17452. '\u24A8': '\u0028\u006D\u0029',
  17453. '\u24A9': '\u0028\u006E\u0029',
  17454. '\u24AA': '\u0028\u006F\u0029',
  17455. '\u24AB': '\u0028\u0070\u0029',
  17456. '\u24AC': '\u0028\u0071\u0029',
  17457. '\u24AD': '\u0028\u0072\u0029',
  17458. '\u24AE': '\u0028\u0073\u0029',
  17459. '\u24AF': '\u0028\u0074\u0029',
  17460. '\u24B0': '\u0028\u0075\u0029',
  17461. '\u24B1': '\u0028\u0076\u0029',
  17462. '\u24B2': '\u0028\u0077\u0029',
  17463. '\u24B3': '\u0028\u0078\u0029',
  17464. '\u24B4': '\u0028\u0079\u0029',
  17465. '\u24B5': '\u0028\u007A\u0029',
  17466. '\u2A0C': '\u222B\u222B\u222B\u222B',
  17467. '\u2A74': '\u003A\u003A\u003D',
  17468. '\u2A75': '\u003D\u003D',
  17469. '\u2A76': '\u003D\u003D\u003D',
  17470. '\u2E9F': '\u6BCD',
  17471. '\u2EF3': '\u9F9F',
  17472. '\u2F00': '\u4E00',
  17473. '\u2F01': '\u4E28',
  17474. '\u2F02': '\u4E36',
  17475. '\u2F03': '\u4E3F',
  17476. '\u2F04': '\u4E59',
  17477. '\u2F05': '\u4E85',
  17478. '\u2F06': '\u4E8C',
  17479. '\u2F07': '\u4EA0',
  17480. '\u2F08': '\u4EBA',
  17481. '\u2F09': '\u513F',
  17482. '\u2F0A': '\u5165',
  17483. '\u2F0B': '\u516B',
  17484. '\u2F0C': '\u5182',
  17485. '\u2F0D': '\u5196',
  17486. '\u2F0E': '\u51AB',
  17487. '\u2F0F': '\u51E0',
  17488. '\u2F10': '\u51F5',
  17489. '\u2F11': '\u5200',
  17490. '\u2F12': '\u529B',
  17491. '\u2F13': '\u52F9',
  17492. '\u2F14': '\u5315',
  17493. '\u2F15': '\u531A',
  17494. '\u2F16': '\u5338',
  17495. '\u2F17': '\u5341',
  17496. '\u2F18': '\u535C',
  17497. '\u2F19': '\u5369',
  17498. '\u2F1A': '\u5382',
  17499. '\u2F1B': '\u53B6',
  17500. '\u2F1C': '\u53C8',
  17501. '\u2F1D': '\u53E3',
  17502. '\u2F1E': '\u56D7',
  17503. '\u2F1F': '\u571F',
  17504. '\u2F20': '\u58EB',
  17505. '\u2F21': '\u5902',
  17506. '\u2F22': '\u590A',
  17507. '\u2F23': '\u5915',
  17508. '\u2F24': '\u5927',
  17509. '\u2F25': '\u5973',
  17510. '\u2F26': '\u5B50',
  17511. '\u2F27': '\u5B80',
  17512. '\u2F28': '\u5BF8',
  17513. '\u2F29': '\u5C0F',
  17514. '\u2F2A': '\u5C22',
  17515. '\u2F2B': '\u5C38',
  17516. '\u2F2C': '\u5C6E',
  17517. '\u2F2D': '\u5C71',
  17518. '\u2F2E': '\u5DDB',
  17519. '\u2F2F': '\u5DE5',
  17520. '\u2F30': '\u5DF1',
  17521. '\u2F31': '\u5DFE',
  17522. '\u2F32': '\u5E72',
  17523. '\u2F33': '\u5E7A',
  17524. '\u2F34': '\u5E7F',
  17525. '\u2F35': '\u5EF4',
  17526. '\u2F36': '\u5EFE',
  17527. '\u2F37': '\u5F0B',
  17528. '\u2F38': '\u5F13',
  17529. '\u2F39': '\u5F50',
  17530. '\u2F3A': '\u5F61',
  17531. '\u2F3B': '\u5F73',
  17532. '\u2F3C': '\u5FC3',
  17533. '\u2F3D': '\u6208',
  17534. '\u2F3E': '\u6236',
  17535. '\u2F3F': '\u624B',
  17536. '\u2F40': '\u652F',
  17537. '\u2F41': '\u6534',
  17538. '\u2F42': '\u6587',
  17539. '\u2F43': '\u6597',
  17540. '\u2F44': '\u65A4',
  17541. '\u2F45': '\u65B9',
  17542. '\u2F46': '\u65E0',
  17543. '\u2F47': '\u65E5',
  17544. '\u2F48': '\u66F0',
  17545. '\u2F49': '\u6708',
  17546. '\u2F4A': '\u6728',
  17547. '\u2F4B': '\u6B20',
  17548. '\u2F4C': '\u6B62',
  17549. '\u2F4D': '\u6B79',
  17550. '\u2F4E': '\u6BB3',
  17551. '\u2F4F': '\u6BCB',
  17552. '\u2F50': '\u6BD4',
  17553. '\u2F51': '\u6BDB',
  17554. '\u2F52': '\u6C0F',
  17555. '\u2F53': '\u6C14',
  17556. '\u2F54': '\u6C34',
  17557. '\u2F55': '\u706B',
  17558. '\u2F56': '\u722A',
  17559. '\u2F57': '\u7236',
  17560. '\u2F58': '\u723B',
  17561. '\u2F59': '\u723F',
  17562. '\u2F5A': '\u7247',
  17563. '\u2F5B': '\u7259',
  17564. '\u2F5C': '\u725B',
  17565. '\u2F5D': '\u72AC',
  17566. '\u2F5E': '\u7384',
  17567. '\u2F5F': '\u7389',
  17568. '\u2F60': '\u74DC',
  17569. '\u2F61': '\u74E6',
  17570. '\u2F62': '\u7518',
  17571. '\u2F63': '\u751F',
  17572. '\u2F64': '\u7528',
  17573. '\u2F65': '\u7530',
  17574. '\u2F66': '\u758B',
  17575. '\u2F67': '\u7592',
  17576. '\u2F68': '\u7676',
  17577. '\u2F69': '\u767D',
  17578. '\u2F6A': '\u76AE',
  17579. '\u2F6B': '\u76BF',
  17580. '\u2F6C': '\u76EE',
  17581. '\u2F6D': '\u77DB',
  17582. '\u2F6E': '\u77E2',
  17583. '\u2F6F': '\u77F3',
  17584. '\u2F70': '\u793A',
  17585. '\u2F71': '\u79B8',
  17586. '\u2F72': '\u79BE',
  17587. '\u2F73': '\u7A74',
  17588. '\u2F74': '\u7ACB',
  17589. '\u2F75': '\u7AF9',
  17590. '\u2F76': '\u7C73',
  17591. '\u2F77': '\u7CF8',
  17592. '\u2F78': '\u7F36',
  17593. '\u2F79': '\u7F51',
  17594. '\u2F7A': '\u7F8A',
  17595. '\u2F7B': '\u7FBD',
  17596. '\u2F7C': '\u8001',
  17597. '\u2F7D': '\u800C',
  17598. '\u2F7E': '\u8012',
  17599. '\u2F7F': '\u8033',
  17600. '\u2F80': '\u807F',
  17601. '\u2F81': '\u8089',
  17602. '\u2F82': '\u81E3',
  17603. '\u2F83': '\u81EA',
  17604. '\u2F84': '\u81F3',
  17605. '\u2F85': '\u81FC',
  17606. '\u2F86': '\u820C',
  17607. '\u2F87': '\u821B',
  17608. '\u2F88': '\u821F',
  17609. '\u2F89': '\u826E',
  17610. '\u2F8A': '\u8272',
  17611. '\u2F8B': '\u8278',
  17612. '\u2F8C': '\u864D',
  17613. '\u2F8D': '\u866B',
  17614. '\u2F8E': '\u8840',
  17615. '\u2F8F': '\u884C',
  17616. '\u2F90': '\u8863',
  17617. '\u2F91': '\u897E',
  17618. '\u2F92': '\u898B',
  17619. '\u2F93': '\u89D2',
  17620. '\u2F94': '\u8A00',
  17621. '\u2F95': '\u8C37',
  17622. '\u2F96': '\u8C46',
  17623. '\u2F97': '\u8C55',
  17624. '\u2F98': '\u8C78',
  17625. '\u2F99': '\u8C9D',
  17626. '\u2F9A': '\u8D64',
  17627. '\u2F9B': '\u8D70',
  17628. '\u2F9C': '\u8DB3',
  17629. '\u2F9D': '\u8EAB',
  17630. '\u2F9E': '\u8ECA',
  17631. '\u2F9F': '\u8F9B',
  17632. '\u2FA0': '\u8FB0',
  17633. '\u2FA1': '\u8FB5',
  17634. '\u2FA2': '\u9091',
  17635. '\u2FA3': '\u9149',
  17636. '\u2FA4': '\u91C6',
  17637. '\u2FA5': '\u91CC',
  17638. '\u2FA6': '\u91D1',
  17639. '\u2FA7': '\u9577',
  17640. '\u2FA8': '\u9580',
  17641. '\u2FA9': '\u961C',
  17642. '\u2FAA': '\u96B6',
  17643. '\u2FAB': '\u96B9',
  17644. '\u2FAC': '\u96E8',
  17645. '\u2FAD': '\u9751',
  17646. '\u2FAE': '\u975E',
  17647. '\u2FAF': '\u9762',
  17648. '\u2FB0': '\u9769',
  17649. '\u2FB1': '\u97CB',
  17650. '\u2FB2': '\u97ED',
  17651. '\u2FB3': '\u97F3',
  17652. '\u2FB4': '\u9801',
  17653. '\u2FB5': '\u98A8',
  17654. '\u2FB6': '\u98DB',
  17655. '\u2FB7': '\u98DF',
  17656. '\u2FB8': '\u9996',
  17657. '\u2FB9': '\u9999',
  17658. '\u2FBA': '\u99AC',
  17659. '\u2FBB': '\u9AA8',
  17660. '\u2FBC': '\u9AD8',
  17661. '\u2FBD': '\u9ADF',
  17662. '\u2FBE': '\u9B25',
  17663. '\u2FBF': '\u9B2F',
  17664. '\u2FC0': '\u9B32',
  17665. '\u2FC1': '\u9B3C',
  17666. '\u2FC2': '\u9B5A',
  17667. '\u2FC3': '\u9CE5',
  17668. '\u2FC4': '\u9E75',
  17669. '\u2FC5': '\u9E7F',
  17670. '\u2FC6': '\u9EA5',
  17671. '\u2FC7': '\u9EBB',
  17672. '\u2FC8': '\u9EC3',
  17673. '\u2FC9': '\u9ECD',
  17674. '\u2FCA': '\u9ED1',
  17675. '\u2FCB': '\u9EF9',
  17676. '\u2FCC': '\u9EFD',
  17677. '\u2FCD': '\u9F0E',
  17678. '\u2FCE': '\u9F13',
  17679. '\u2FCF': '\u9F20',
  17680. '\u2FD0': '\u9F3B',
  17681. '\u2FD1': '\u9F4A',
  17682. '\u2FD2': '\u9F52',
  17683. '\u2FD3': '\u9F8D',
  17684. '\u2FD4': '\u9F9C',
  17685. '\u2FD5': '\u9FA0',
  17686. '\u3036': '\u3012',
  17687. '\u3038': '\u5341',
  17688. '\u3039': '\u5344',
  17689. '\u303A': '\u5345',
  17690. '\u309B': '\u0020\u3099',
  17691. '\u309C': '\u0020\u309A',
  17692. '\u3131': '\u1100',
  17693. '\u3132': '\u1101',
  17694. '\u3133': '\u11AA',
  17695. '\u3134': '\u1102',
  17696. '\u3135': '\u11AC',
  17697. '\u3136': '\u11AD',
  17698. '\u3137': '\u1103',
  17699. '\u3138': '\u1104',
  17700. '\u3139': '\u1105',
  17701. '\u313A': '\u11B0',
  17702. '\u313B': '\u11B1',
  17703. '\u313C': '\u11B2',
  17704. '\u313D': '\u11B3',
  17705. '\u313E': '\u11B4',
  17706. '\u313F': '\u11B5',
  17707. '\u3140': '\u111A',
  17708. '\u3141': '\u1106',
  17709. '\u3142': '\u1107',
  17710. '\u3143': '\u1108',
  17711. '\u3144': '\u1121',
  17712. '\u3145': '\u1109',
  17713. '\u3146': '\u110A',
  17714. '\u3147': '\u110B',
  17715. '\u3148': '\u110C',
  17716. '\u3149': '\u110D',
  17717. '\u314A': '\u110E',
  17718. '\u314B': '\u110F',
  17719. '\u314C': '\u1110',
  17720. '\u314D': '\u1111',
  17721. '\u314E': '\u1112',
  17722. '\u314F': '\u1161',
  17723. '\u3150': '\u1162',
  17724. '\u3151': '\u1163',
  17725. '\u3152': '\u1164',
  17726. '\u3153': '\u1165',
  17727. '\u3154': '\u1166',
  17728. '\u3155': '\u1167',
  17729. '\u3156': '\u1168',
  17730. '\u3157': '\u1169',
  17731. '\u3158': '\u116A',
  17732. '\u3159': '\u116B',
  17733. '\u315A': '\u116C',
  17734. '\u315B': '\u116D',
  17735. '\u315C': '\u116E',
  17736. '\u315D': '\u116F',
  17737. '\u315E': '\u1170',
  17738. '\u315F': '\u1171',
  17739. '\u3160': '\u1172',
  17740. '\u3161': '\u1173',
  17741. '\u3162': '\u1174',
  17742. '\u3163': '\u1175',
  17743. '\u3164': '\u1160',
  17744. '\u3165': '\u1114',
  17745. '\u3166': '\u1115',
  17746. '\u3167': '\u11C7',
  17747. '\u3168': '\u11C8',
  17748. '\u3169': '\u11CC',
  17749. '\u316A': '\u11CE',
  17750. '\u316B': '\u11D3',
  17751. '\u316C': '\u11D7',
  17752. '\u316D': '\u11D9',
  17753. '\u316E': '\u111C',
  17754. '\u316F': '\u11DD',
  17755. '\u3170': '\u11DF',
  17756. '\u3171': '\u111D',
  17757. '\u3172': '\u111E',
  17758. '\u3173': '\u1120',
  17759. '\u3174': '\u1122',
  17760. '\u3175': '\u1123',
  17761. '\u3176': '\u1127',
  17762. '\u3177': '\u1129',
  17763. '\u3178': '\u112B',
  17764. '\u3179': '\u112C',
  17765. '\u317A': '\u112D',
  17766. '\u317B': '\u112E',
  17767. '\u317C': '\u112F',
  17768. '\u317D': '\u1132',
  17769. '\u317E': '\u1136',
  17770. '\u317F': '\u1140',
  17771. '\u3180': '\u1147',
  17772. '\u3181': '\u114C',
  17773. '\u3182': '\u11F1',
  17774. '\u3183': '\u11F2',
  17775. '\u3184': '\u1157',
  17776. '\u3185': '\u1158',
  17777. '\u3186': '\u1159',
  17778. '\u3187': '\u1184',
  17779. '\u3188': '\u1185',
  17780. '\u3189': '\u1188',
  17781. '\u318A': '\u1191',
  17782. '\u318B': '\u1192',
  17783. '\u318C': '\u1194',
  17784. '\u318D': '\u119E',
  17785. '\u318E': '\u11A1',
  17786. '\u3200': '\u0028\u1100\u0029',
  17787. '\u3201': '\u0028\u1102\u0029',
  17788. '\u3202': '\u0028\u1103\u0029',
  17789. '\u3203': '\u0028\u1105\u0029',
  17790. '\u3204': '\u0028\u1106\u0029',
  17791. '\u3205': '\u0028\u1107\u0029',
  17792. '\u3206': '\u0028\u1109\u0029',
  17793. '\u3207': '\u0028\u110B\u0029',
  17794. '\u3208': '\u0028\u110C\u0029',
  17795. '\u3209': '\u0028\u110E\u0029',
  17796. '\u320A': '\u0028\u110F\u0029',
  17797. '\u320B': '\u0028\u1110\u0029',
  17798. '\u320C': '\u0028\u1111\u0029',
  17799. '\u320D': '\u0028\u1112\u0029',
  17800. '\u320E': '\u0028\u1100\u1161\u0029',
  17801. '\u320F': '\u0028\u1102\u1161\u0029',
  17802. '\u3210': '\u0028\u1103\u1161\u0029',
  17803. '\u3211': '\u0028\u1105\u1161\u0029',
  17804. '\u3212': '\u0028\u1106\u1161\u0029',
  17805. '\u3213': '\u0028\u1107\u1161\u0029',
  17806. '\u3214': '\u0028\u1109\u1161\u0029',
  17807. '\u3215': '\u0028\u110B\u1161\u0029',
  17808. '\u3216': '\u0028\u110C\u1161\u0029',
  17809. '\u3217': '\u0028\u110E\u1161\u0029',
  17810. '\u3218': '\u0028\u110F\u1161\u0029',
  17811. '\u3219': '\u0028\u1110\u1161\u0029',
  17812. '\u321A': '\u0028\u1111\u1161\u0029',
  17813. '\u321B': '\u0028\u1112\u1161\u0029',
  17814. '\u321C': '\u0028\u110C\u116E\u0029',
  17815. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  17816. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  17817. '\u3220': '\u0028\u4E00\u0029',
  17818. '\u3221': '\u0028\u4E8C\u0029',
  17819. '\u3222': '\u0028\u4E09\u0029',
  17820. '\u3223': '\u0028\u56DB\u0029',
  17821. '\u3224': '\u0028\u4E94\u0029',
  17822. '\u3225': '\u0028\u516D\u0029',
  17823. '\u3226': '\u0028\u4E03\u0029',
  17824. '\u3227': '\u0028\u516B\u0029',
  17825. '\u3228': '\u0028\u4E5D\u0029',
  17826. '\u3229': '\u0028\u5341\u0029',
  17827. '\u322A': '\u0028\u6708\u0029',
  17828. '\u322B': '\u0028\u706B\u0029',
  17829. '\u322C': '\u0028\u6C34\u0029',
  17830. '\u322D': '\u0028\u6728\u0029',
  17831. '\u322E': '\u0028\u91D1\u0029',
  17832. '\u322F': '\u0028\u571F\u0029',
  17833. '\u3230': '\u0028\u65E5\u0029',
  17834. '\u3231': '\u0028\u682A\u0029',
  17835. '\u3232': '\u0028\u6709\u0029',
  17836. '\u3233': '\u0028\u793E\u0029',
  17837. '\u3234': '\u0028\u540D\u0029',
  17838. '\u3235': '\u0028\u7279\u0029',
  17839. '\u3236': '\u0028\u8CA1\u0029',
  17840. '\u3237': '\u0028\u795D\u0029',
  17841. '\u3238': '\u0028\u52B4\u0029',
  17842. '\u3239': '\u0028\u4EE3\u0029',
  17843. '\u323A': '\u0028\u547C\u0029',
  17844. '\u323B': '\u0028\u5B66\u0029',
  17845. '\u323C': '\u0028\u76E3\u0029',
  17846. '\u323D': '\u0028\u4F01\u0029',
  17847. '\u323E': '\u0028\u8CC7\u0029',
  17848. '\u323F': '\u0028\u5354\u0029',
  17849. '\u3240': '\u0028\u796D\u0029',
  17850. '\u3241': '\u0028\u4F11\u0029',
  17851. '\u3242': '\u0028\u81EA\u0029',
  17852. '\u3243': '\u0028\u81F3\u0029',
  17853. '\u32C0': '\u0031\u6708',
  17854. '\u32C1': '\u0032\u6708',
  17855. '\u32C2': '\u0033\u6708',
  17856. '\u32C3': '\u0034\u6708',
  17857. '\u32C4': '\u0035\u6708',
  17858. '\u32C5': '\u0036\u6708',
  17859. '\u32C6': '\u0037\u6708',
  17860. '\u32C7': '\u0038\u6708',
  17861. '\u32C8': '\u0039\u6708',
  17862. '\u32C9': '\u0031\u0030\u6708',
  17863. '\u32CA': '\u0031\u0031\u6708',
  17864. '\u32CB': '\u0031\u0032\u6708',
  17865. '\u3358': '\u0030\u70B9',
  17866. '\u3359': '\u0031\u70B9',
  17867. '\u335A': '\u0032\u70B9',
  17868. '\u335B': '\u0033\u70B9',
  17869. '\u335C': '\u0034\u70B9',
  17870. '\u335D': '\u0035\u70B9',
  17871. '\u335E': '\u0036\u70B9',
  17872. '\u335F': '\u0037\u70B9',
  17873. '\u3360': '\u0038\u70B9',
  17874. '\u3361': '\u0039\u70B9',
  17875. '\u3362': '\u0031\u0030\u70B9',
  17876. '\u3363': '\u0031\u0031\u70B9',
  17877. '\u3364': '\u0031\u0032\u70B9',
  17878. '\u3365': '\u0031\u0033\u70B9',
  17879. '\u3366': '\u0031\u0034\u70B9',
  17880. '\u3367': '\u0031\u0035\u70B9',
  17881. '\u3368': '\u0031\u0036\u70B9',
  17882. '\u3369': '\u0031\u0037\u70B9',
  17883. '\u336A': '\u0031\u0038\u70B9',
  17884. '\u336B': '\u0031\u0039\u70B9',
  17885. '\u336C': '\u0032\u0030\u70B9',
  17886. '\u336D': '\u0032\u0031\u70B9',
  17887. '\u336E': '\u0032\u0032\u70B9',
  17888. '\u336F': '\u0032\u0033\u70B9',
  17889. '\u3370': '\u0032\u0034\u70B9',
  17890. '\u33E0': '\u0031\u65E5',
  17891. '\u33E1': '\u0032\u65E5',
  17892. '\u33E2': '\u0033\u65E5',
  17893. '\u33E3': '\u0034\u65E5',
  17894. '\u33E4': '\u0035\u65E5',
  17895. '\u33E5': '\u0036\u65E5',
  17896. '\u33E6': '\u0037\u65E5',
  17897. '\u33E7': '\u0038\u65E5',
  17898. '\u33E8': '\u0039\u65E5',
  17899. '\u33E9': '\u0031\u0030\u65E5',
  17900. '\u33EA': '\u0031\u0031\u65E5',
  17901. '\u33EB': '\u0031\u0032\u65E5',
  17902. '\u33EC': '\u0031\u0033\u65E5',
  17903. '\u33ED': '\u0031\u0034\u65E5',
  17904. '\u33EE': '\u0031\u0035\u65E5',
  17905. '\u33EF': '\u0031\u0036\u65E5',
  17906. '\u33F0': '\u0031\u0037\u65E5',
  17907. '\u33F1': '\u0031\u0038\u65E5',
  17908. '\u33F2': '\u0031\u0039\u65E5',
  17909. '\u33F3': '\u0032\u0030\u65E5',
  17910. '\u33F4': '\u0032\u0031\u65E5',
  17911. '\u33F5': '\u0032\u0032\u65E5',
  17912. '\u33F6': '\u0032\u0033\u65E5',
  17913. '\u33F7': '\u0032\u0034\u65E5',
  17914. '\u33F8': '\u0032\u0035\u65E5',
  17915. '\u33F9': '\u0032\u0036\u65E5',
  17916. '\u33FA': '\u0032\u0037\u65E5',
  17917. '\u33FB': '\u0032\u0038\u65E5',
  17918. '\u33FC': '\u0032\u0039\u65E5',
  17919. '\u33FD': '\u0033\u0030\u65E5',
  17920. '\u33FE': '\u0033\u0031\u65E5',
  17921. '\uFB00': '\u0066\u0066',
  17922. '\uFB01': '\u0066\u0069',
  17923. '\uFB02': '\u0066\u006C',
  17924. '\uFB03': '\u0066\u0066\u0069',
  17925. '\uFB04': '\u0066\u0066\u006C',
  17926. '\uFB05': '\u017F\u0074',
  17927. '\uFB06': '\u0073\u0074',
  17928. '\uFB13': '\u0574\u0576',
  17929. '\uFB14': '\u0574\u0565',
  17930. '\uFB15': '\u0574\u056B',
  17931. '\uFB16': '\u057E\u0576',
  17932. '\uFB17': '\u0574\u056D',
  17933. '\uFB4F': '\u05D0\u05DC',
  17934. '\uFB50': '\u0671',
  17935. '\uFB51': '\u0671',
  17936. '\uFB52': '\u067B',
  17937. '\uFB53': '\u067B',
  17938. '\uFB54': '\u067B',
  17939. '\uFB55': '\u067B',
  17940. '\uFB56': '\u067E',
  17941. '\uFB57': '\u067E',
  17942. '\uFB58': '\u067E',
  17943. '\uFB59': '\u067E',
  17944. '\uFB5A': '\u0680',
  17945. '\uFB5B': '\u0680',
  17946. '\uFB5C': '\u0680',
  17947. '\uFB5D': '\u0680',
  17948. '\uFB5E': '\u067A',
  17949. '\uFB5F': '\u067A',
  17950. '\uFB60': '\u067A',
  17951. '\uFB61': '\u067A',
  17952. '\uFB62': '\u067F',
  17953. '\uFB63': '\u067F',
  17954. '\uFB64': '\u067F',
  17955. '\uFB65': '\u067F',
  17956. '\uFB66': '\u0679',
  17957. '\uFB67': '\u0679',
  17958. '\uFB68': '\u0679',
  17959. '\uFB69': '\u0679',
  17960. '\uFB6A': '\u06A4',
  17961. '\uFB6B': '\u06A4',
  17962. '\uFB6C': '\u06A4',
  17963. '\uFB6D': '\u06A4',
  17964. '\uFB6E': '\u06A6',
  17965. '\uFB6F': '\u06A6',
  17966. '\uFB70': '\u06A6',
  17967. '\uFB71': '\u06A6',
  17968. '\uFB72': '\u0684',
  17969. '\uFB73': '\u0684',
  17970. '\uFB74': '\u0684',
  17971. '\uFB75': '\u0684',
  17972. '\uFB76': '\u0683',
  17973. '\uFB77': '\u0683',
  17974. '\uFB78': '\u0683',
  17975. '\uFB79': '\u0683',
  17976. '\uFB7A': '\u0686',
  17977. '\uFB7B': '\u0686',
  17978. '\uFB7C': '\u0686',
  17979. '\uFB7D': '\u0686',
  17980. '\uFB7E': '\u0687',
  17981. '\uFB7F': '\u0687',
  17982. '\uFB80': '\u0687',
  17983. '\uFB81': '\u0687',
  17984. '\uFB82': '\u068D',
  17985. '\uFB83': '\u068D',
  17986. '\uFB84': '\u068C',
  17987. '\uFB85': '\u068C',
  17988. '\uFB86': '\u068E',
  17989. '\uFB87': '\u068E',
  17990. '\uFB88': '\u0688',
  17991. '\uFB89': '\u0688',
  17992. '\uFB8A': '\u0698',
  17993. '\uFB8B': '\u0698',
  17994. '\uFB8C': '\u0691',
  17995. '\uFB8D': '\u0691',
  17996. '\uFB8E': '\u06A9',
  17997. '\uFB8F': '\u06A9',
  17998. '\uFB90': '\u06A9',
  17999. '\uFB91': '\u06A9',
  18000. '\uFB92': '\u06AF',
  18001. '\uFB93': '\u06AF',
  18002. '\uFB94': '\u06AF',
  18003. '\uFB95': '\u06AF',
  18004. '\uFB96': '\u06B3',
  18005. '\uFB97': '\u06B3',
  18006. '\uFB98': '\u06B3',
  18007. '\uFB99': '\u06B3',
  18008. '\uFB9A': '\u06B1',
  18009. '\uFB9B': '\u06B1',
  18010. '\uFB9C': '\u06B1',
  18011. '\uFB9D': '\u06B1',
  18012. '\uFB9E': '\u06BA',
  18013. '\uFB9F': '\u06BA',
  18014. '\uFBA0': '\u06BB',
  18015. '\uFBA1': '\u06BB',
  18016. '\uFBA2': '\u06BB',
  18017. '\uFBA3': '\u06BB',
  18018. '\uFBA4': '\u06C0',
  18019. '\uFBA5': '\u06C0',
  18020. '\uFBA6': '\u06C1',
  18021. '\uFBA7': '\u06C1',
  18022. '\uFBA8': '\u06C1',
  18023. '\uFBA9': '\u06C1',
  18024. '\uFBAA': '\u06BE',
  18025. '\uFBAB': '\u06BE',
  18026. '\uFBAC': '\u06BE',
  18027. '\uFBAD': '\u06BE',
  18028. '\uFBAE': '\u06D2',
  18029. '\uFBAF': '\u06D2',
  18030. '\uFBB0': '\u06D3',
  18031. '\uFBB1': '\u06D3',
  18032. '\uFBD3': '\u06AD',
  18033. '\uFBD4': '\u06AD',
  18034. '\uFBD5': '\u06AD',
  18035. '\uFBD6': '\u06AD',
  18036. '\uFBD7': '\u06C7',
  18037. '\uFBD8': '\u06C7',
  18038. '\uFBD9': '\u06C6',
  18039. '\uFBDA': '\u06C6',
  18040. '\uFBDB': '\u06C8',
  18041. '\uFBDC': '\u06C8',
  18042. '\uFBDD': '\u0677',
  18043. '\uFBDE': '\u06CB',
  18044. '\uFBDF': '\u06CB',
  18045. '\uFBE0': '\u06C5',
  18046. '\uFBE1': '\u06C5',
  18047. '\uFBE2': '\u06C9',
  18048. '\uFBE3': '\u06C9',
  18049. '\uFBE4': '\u06D0',
  18050. '\uFBE5': '\u06D0',
  18051. '\uFBE6': '\u06D0',
  18052. '\uFBE7': '\u06D0',
  18053. '\uFBE8': '\u0649',
  18054. '\uFBE9': '\u0649',
  18055. '\uFBEA': '\u0626\u0627',
  18056. '\uFBEB': '\u0626\u0627',
  18057. '\uFBEC': '\u0626\u06D5',
  18058. '\uFBED': '\u0626\u06D5',
  18059. '\uFBEE': '\u0626\u0648',
  18060. '\uFBEF': '\u0626\u0648',
  18061. '\uFBF0': '\u0626\u06C7',
  18062. '\uFBF1': '\u0626\u06C7',
  18063. '\uFBF2': '\u0626\u06C6',
  18064. '\uFBF3': '\u0626\u06C6',
  18065. '\uFBF4': '\u0626\u06C8',
  18066. '\uFBF5': '\u0626\u06C8',
  18067. '\uFBF6': '\u0626\u06D0',
  18068. '\uFBF7': '\u0626\u06D0',
  18069. '\uFBF8': '\u0626\u06D0',
  18070. '\uFBF9': '\u0626\u0649',
  18071. '\uFBFA': '\u0626\u0649',
  18072. '\uFBFB': '\u0626\u0649',
  18073. '\uFBFC': '\u06CC',
  18074. '\uFBFD': '\u06CC',
  18075. '\uFBFE': '\u06CC',
  18076. '\uFBFF': '\u06CC',
  18077. '\uFC00': '\u0626\u062C',
  18078. '\uFC01': '\u0626\u062D',
  18079. '\uFC02': '\u0626\u0645',
  18080. '\uFC03': '\u0626\u0649',
  18081. '\uFC04': '\u0626\u064A',
  18082. '\uFC05': '\u0628\u062C',
  18083. '\uFC06': '\u0628\u062D',
  18084. '\uFC07': '\u0628\u062E',
  18085. '\uFC08': '\u0628\u0645',
  18086. '\uFC09': '\u0628\u0649',
  18087. '\uFC0A': '\u0628\u064A',
  18088. '\uFC0B': '\u062A\u062C',
  18089. '\uFC0C': '\u062A\u062D',
  18090. '\uFC0D': '\u062A\u062E',
  18091. '\uFC0E': '\u062A\u0645',
  18092. '\uFC0F': '\u062A\u0649',
  18093. '\uFC10': '\u062A\u064A',
  18094. '\uFC11': '\u062B\u062C',
  18095. '\uFC12': '\u062B\u0645',
  18096. '\uFC13': '\u062B\u0649',
  18097. '\uFC14': '\u062B\u064A',
  18098. '\uFC15': '\u062C\u062D',
  18099. '\uFC16': '\u062C\u0645',
  18100. '\uFC17': '\u062D\u062C',
  18101. '\uFC18': '\u062D\u0645',
  18102. '\uFC19': '\u062E\u062C',
  18103. '\uFC1A': '\u062E\u062D',
  18104. '\uFC1B': '\u062E\u0645',
  18105. '\uFC1C': '\u0633\u062C',
  18106. '\uFC1D': '\u0633\u062D',
  18107. '\uFC1E': '\u0633\u062E',
  18108. '\uFC1F': '\u0633\u0645',
  18109. '\uFC20': '\u0635\u062D',
  18110. '\uFC21': '\u0635\u0645',
  18111. '\uFC22': '\u0636\u062C',
  18112. '\uFC23': '\u0636\u062D',
  18113. '\uFC24': '\u0636\u062E',
  18114. '\uFC25': '\u0636\u0645',
  18115. '\uFC26': '\u0637\u062D',
  18116. '\uFC27': '\u0637\u0645',
  18117. '\uFC28': '\u0638\u0645',
  18118. '\uFC29': '\u0639\u062C',
  18119. '\uFC2A': '\u0639\u0645',
  18120. '\uFC2B': '\u063A\u062C',
  18121. '\uFC2C': '\u063A\u0645',
  18122. '\uFC2D': '\u0641\u062C',
  18123. '\uFC2E': '\u0641\u062D',
  18124. '\uFC2F': '\u0641\u062E',
  18125. '\uFC30': '\u0641\u0645',
  18126. '\uFC31': '\u0641\u0649',
  18127. '\uFC32': '\u0641\u064A',
  18128. '\uFC33': '\u0642\u062D',
  18129. '\uFC34': '\u0642\u0645',
  18130. '\uFC35': '\u0642\u0649',
  18131. '\uFC36': '\u0642\u064A',
  18132. '\uFC37': '\u0643\u0627',
  18133. '\uFC38': '\u0643\u062C',
  18134. '\uFC39': '\u0643\u062D',
  18135. '\uFC3A': '\u0643\u062E',
  18136. '\uFC3B': '\u0643\u0644',
  18137. '\uFC3C': '\u0643\u0645',
  18138. '\uFC3D': '\u0643\u0649',
  18139. '\uFC3E': '\u0643\u064A',
  18140. '\uFC3F': '\u0644\u062C',
  18141. '\uFC40': '\u0644\u062D',
  18142. '\uFC41': '\u0644\u062E',
  18143. '\uFC42': '\u0644\u0645',
  18144. '\uFC43': '\u0644\u0649',
  18145. '\uFC44': '\u0644\u064A',
  18146. '\uFC45': '\u0645\u062C',
  18147. '\uFC46': '\u0645\u062D',
  18148. '\uFC47': '\u0645\u062E',
  18149. '\uFC48': '\u0645\u0645',
  18150. '\uFC49': '\u0645\u0649',
  18151. '\uFC4A': '\u0645\u064A',
  18152. '\uFC4B': '\u0646\u062C',
  18153. '\uFC4C': '\u0646\u062D',
  18154. '\uFC4D': '\u0646\u062E',
  18155. '\uFC4E': '\u0646\u0645',
  18156. '\uFC4F': '\u0646\u0649',
  18157. '\uFC50': '\u0646\u064A',
  18158. '\uFC51': '\u0647\u062C',
  18159. '\uFC52': '\u0647\u0645',
  18160. '\uFC53': '\u0647\u0649',
  18161. '\uFC54': '\u0647\u064A',
  18162. '\uFC55': '\u064A\u062C',
  18163. '\uFC56': '\u064A\u062D',
  18164. '\uFC57': '\u064A\u062E',
  18165. '\uFC58': '\u064A\u0645',
  18166. '\uFC59': '\u064A\u0649',
  18167. '\uFC5A': '\u064A\u064A',
  18168. '\uFC5B': '\u0630\u0670',
  18169. '\uFC5C': '\u0631\u0670',
  18170. '\uFC5D': '\u0649\u0670',
  18171. '\uFC5E': '\u0020\u064C\u0651',
  18172. '\uFC5F': '\u0020\u064D\u0651',
  18173. '\uFC60': '\u0020\u064E\u0651',
  18174. '\uFC61': '\u0020\u064F\u0651',
  18175. '\uFC62': '\u0020\u0650\u0651',
  18176. '\uFC63': '\u0020\u0651\u0670',
  18177. '\uFC64': '\u0626\u0631',
  18178. '\uFC65': '\u0626\u0632',
  18179. '\uFC66': '\u0626\u0645',
  18180. '\uFC67': '\u0626\u0646',
  18181. '\uFC68': '\u0626\u0649',
  18182. '\uFC69': '\u0626\u064A',
  18183. '\uFC6A': '\u0628\u0631',
  18184. '\uFC6B': '\u0628\u0632',
  18185. '\uFC6C': '\u0628\u0645',
  18186. '\uFC6D': '\u0628\u0646',
  18187. '\uFC6E': '\u0628\u0649',
  18188. '\uFC6F': '\u0628\u064A',
  18189. '\uFC70': '\u062A\u0631',
  18190. '\uFC71': '\u062A\u0632',
  18191. '\uFC72': '\u062A\u0645',
  18192. '\uFC73': '\u062A\u0646',
  18193. '\uFC74': '\u062A\u0649',
  18194. '\uFC75': '\u062A\u064A',
  18195. '\uFC76': '\u062B\u0631',
  18196. '\uFC77': '\u062B\u0632',
  18197. '\uFC78': '\u062B\u0645',
  18198. '\uFC79': '\u062B\u0646',
  18199. '\uFC7A': '\u062B\u0649',
  18200. '\uFC7B': '\u062B\u064A',
  18201. '\uFC7C': '\u0641\u0649',
  18202. '\uFC7D': '\u0641\u064A',
  18203. '\uFC7E': '\u0642\u0649',
  18204. '\uFC7F': '\u0642\u064A',
  18205. '\uFC80': '\u0643\u0627',
  18206. '\uFC81': '\u0643\u0644',
  18207. '\uFC82': '\u0643\u0645',
  18208. '\uFC83': '\u0643\u0649',
  18209. '\uFC84': '\u0643\u064A',
  18210. '\uFC85': '\u0644\u0645',
  18211. '\uFC86': '\u0644\u0649',
  18212. '\uFC87': '\u0644\u064A',
  18213. '\uFC88': '\u0645\u0627',
  18214. '\uFC89': '\u0645\u0645',
  18215. '\uFC8A': '\u0646\u0631',
  18216. '\uFC8B': '\u0646\u0632',
  18217. '\uFC8C': '\u0646\u0645',
  18218. '\uFC8D': '\u0646\u0646',
  18219. '\uFC8E': '\u0646\u0649',
  18220. '\uFC8F': '\u0646\u064A',
  18221. '\uFC90': '\u0649\u0670',
  18222. '\uFC91': '\u064A\u0631',
  18223. '\uFC92': '\u064A\u0632',
  18224. '\uFC93': '\u064A\u0645',
  18225. '\uFC94': '\u064A\u0646',
  18226. '\uFC95': '\u064A\u0649',
  18227. '\uFC96': '\u064A\u064A',
  18228. '\uFC97': '\u0626\u062C',
  18229. '\uFC98': '\u0626\u062D',
  18230. '\uFC99': '\u0626\u062E',
  18231. '\uFC9A': '\u0626\u0645',
  18232. '\uFC9B': '\u0626\u0647',
  18233. '\uFC9C': '\u0628\u062C',
  18234. '\uFC9D': '\u0628\u062D',
  18235. '\uFC9E': '\u0628\u062E',
  18236. '\uFC9F': '\u0628\u0645',
  18237. '\uFCA0': '\u0628\u0647',
  18238. '\uFCA1': '\u062A\u062C',
  18239. '\uFCA2': '\u062A\u062D',
  18240. '\uFCA3': '\u062A\u062E',
  18241. '\uFCA4': '\u062A\u0645',
  18242. '\uFCA5': '\u062A\u0647',
  18243. '\uFCA6': '\u062B\u0645',
  18244. '\uFCA7': '\u062C\u062D',
  18245. '\uFCA8': '\u062C\u0645',
  18246. '\uFCA9': '\u062D\u062C',
  18247. '\uFCAA': '\u062D\u0645',
  18248. '\uFCAB': '\u062E\u062C',
  18249. '\uFCAC': '\u062E\u0645',
  18250. '\uFCAD': '\u0633\u062C',
  18251. '\uFCAE': '\u0633\u062D',
  18252. '\uFCAF': '\u0633\u062E',
  18253. '\uFCB0': '\u0633\u0645',
  18254. '\uFCB1': '\u0635\u062D',
  18255. '\uFCB2': '\u0635\u062E',
  18256. '\uFCB3': '\u0635\u0645',
  18257. '\uFCB4': '\u0636\u062C',
  18258. '\uFCB5': '\u0636\u062D',
  18259. '\uFCB6': '\u0636\u062E',
  18260. '\uFCB7': '\u0636\u0645',
  18261. '\uFCB8': '\u0637\u062D',
  18262. '\uFCB9': '\u0638\u0645',
  18263. '\uFCBA': '\u0639\u062C',
  18264. '\uFCBB': '\u0639\u0645',
  18265. '\uFCBC': '\u063A\u062C',
  18266. '\uFCBD': '\u063A\u0645',
  18267. '\uFCBE': '\u0641\u062C',
  18268. '\uFCBF': '\u0641\u062D',
  18269. '\uFCC0': '\u0641\u062E',
  18270. '\uFCC1': '\u0641\u0645',
  18271. '\uFCC2': '\u0642\u062D',
  18272. '\uFCC3': '\u0642\u0645',
  18273. '\uFCC4': '\u0643\u062C',
  18274. '\uFCC5': '\u0643\u062D',
  18275. '\uFCC6': '\u0643\u062E',
  18276. '\uFCC7': '\u0643\u0644',
  18277. '\uFCC8': '\u0643\u0645',
  18278. '\uFCC9': '\u0644\u062C',
  18279. '\uFCCA': '\u0644\u062D',
  18280. '\uFCCB': '\u0644\u062E',
  18281. '\uFCCC': '\u0644\u0645',
  18282. '\uFCCD': '\u0644\u0647',
  18283. '\uFCCE': '\u0645\u062C',
  18284. '\uFCCF': '\u0645\u062D',
  18285. '\uFCD0': '\u0645\u062E',
  18286. '\uFCD1': '\u0645\u0645',
  18287. '\uFCD2': '\u0646\u062C',
  18288. '\uFCD3': '\u0646\u062D',
  18289. '\uFCD4': '\u0646\u062E',
  18290. '\uFCD5': '\u0646\u0645',
  18291. '\uFCD6': '\u0646\u0647',
  18292. '\uFCD7': '\u0647\u062C',
  18293. '\uFCD8': '\u0647\u0645',
  18294. '\uFCD9': '\u0647\u0670',
  18295. '\uFCDA': '\u064A\u062C',
  18296. '\uFCDB': '\u064A\u062D',
  18297. '\uFCDC': '\u064A\u062E',
  18298. '\uFCDD': '\u064A\u0645',
  18299. '\uFCDE': '\u064A\u0647',
  18300. '\uFCDF': '\u0626\u0645',
  18301. '\uFCE0': '\u0626\u0647',
  18302. '\uFCE1': '\u0628\u0645',
  18303. '\uFCE2': '\u0628\u0647',
  18304. '\uFCE3': '\u062A\u0645',
  18305. '\uFCE4': '\u062A\u0647',
  18306. '\uFCE5': '\u062B\u0645',
  18307. '\uFCE6': '\u062B\u0647',
  18308. '\uFCE7': '\u0633\u0645',
  18309. '\uFCE8': '\u0633\u0647',
  18310. '\uFCE9': '\u0634\u0645',
  18311. '\uFCEA': '\u0634\u0647',
  18312. '\uFCEB': '\u0643\u0644',
  18313. '\uFCEC': '\u0643\u0645',
  18314. '\uFCED': '\u0644\u0645',
  18315. '\uFCEE': '\u0646\u0645',
  18316. '\uFCEF': '\u0646\u0647',
  18317. '\uFCF0': '\u064A\u0645',
  18318. '\uFCF1': '\u064A\u0647',
  18319. '\uFCF2': '\u0640\u064E\u0651',
  18320. '\uFCF3': '\u0640\u064F\u0651',
  18321. '\uFCF4': '\u0640\u0650\u0651',
  18322. '\uFCF5': '\u0637\u0649',
  18323. '\uFCF6': '\u0637\u064A',
  18324. '\uFCF7': '\u0639\u0649',
  18325. '\uFCF8': '\u0639\u064A',
  18326. '\uFCF9': '\u063A\u0649',
  18327. '\uFCFA': '\u063A\u064A',
  18328. '\uFCFB': '\u0633\u0649',
  18329. '\uFCFC': '\u0633\u064A',
  18330. '\uFCFD': '\u0634\u0649',
  18331. '\uFCFE': '\u0634\u064A',
  18332. '\uFCFF': '\u062D\u0649',
  18333. '\uFD00': '\u062D\u064A',
  18334. '\uFD01': '\u062C\u0649',
  18335. '\uFD02': '\u062C\u064A',
  18336. '\uFD03': '\u062E\u0649',
  18337. '\uFD04': '\u062E\u064A',
  18338. '\uFD05': '\u0635\u0649',
  18339. '\uFD06': '\u0635\u064A',
  18340. '\uFD07': '\u0636\u0649',
  18341. '\uFD08': '\u0636\u064A',
  18342. '\uFD09': '\u0634\u062C',
  18343. '\uFD0A': '\u0634\u062D',
  18344. '\uFD0B': '\u0634\u062E',
  18345. '\uFD0C': '\u0634\u0645',
  18346. '\uFD0D': '\u0634\u0631',
  18347. '\uFD0E': '\u0633\u0631',
  18348. '\uFD0F': '\u0635\u0631',
  18349. '\uFD10': '\u0636\u0631',
  18350. '\uFD11': '\u0637\u0649',
  18351. '\uFD12': '\u0637\u064A',
  18352. '\uFD13': '\u0639\u0649',
  18353. '\uFD14': '\u0639\u064A',
  18354. '\uFD15': '\u063A\u0649',
  18355. '\uFD16': '\u063A\u064A',
  18356. '\uFD17': '\u0633\u0649',
  18357. '\uFD18': '\u0633\u064A',
  18358. '\uFD19': '\u0634\u0649',
  18359. '\uFD1A': '\u0634\u064A',
  18360. '\uFD1B': '\u062D\u0649',
  18361. '\uFD1C': '\u062D\u064A',
  18362. '\uFD1D': '\u062C\u0649',
  18363. '\uFD1E': '\u062C\u064A',
  18364. '\uFD1F': '\u062E\u0649',
  18365. '\uFD20': '\u062E\u064A',
  18366. '\uFD21': '\u0635\u0649',
  18367. '\uFD22': '\u0635\u064A',
  18368. '\uFD23': '\u0636\u0649',
  18369. '\uFD24': '\u0636\u064A',
  18370. '\uFD25': '\u0634\u062C',
  18371. '\uFD26': '\u0634\u062D',
  18372. '\uFD27': '\u0634\u062E',
  18373. '\uFD28': '\u0634\u0645',
  18374. '\uFD29': '\u0634\u0631',
  18375. '\uFD2A': '\u0633\u0631',
  18376. '\uFD2B': '\u0635\u0631',
  18377. '\uFD2C': '\u0636\u0631',
  18378. '\uFD2D': '\u0634\u062C',
  18379. '\uFD2E': '\u0634\u062D',
  18380. '\uFD2F': '\u0634\u062E',
  18381. '\uFD30': '\u0634\u0645',
  18382. '\uFD31': '\u0633\u0647',
  18383. '\uFD32': '\u0634\u0647',
  18384. '\uFD33': '\u0637\u0645',
  18385. '\uFD34': '\u0633\u062C',
  18386. '\uFD35': '\u0633\u062D',
  18387. '\uFD36': '\u0633\u062E',
  18388. '\uFD37': '\u0634\u062C',
  18389. '\uFD38': '\u0634\u062D',
  18390. '\uFD39': '\u0634\u062E',
  18391. '\uFD3A': '\u0637\u0645',
  18392. '\uFD3B': '\u0638\u0645',
  18393. '\uFD3C': '\u0627\u064B',
  18394. '\uFD3D': '\u0627\u064B',
  18395. '\uFD50': '\u062A\u062C\u0645',
  18396. '\uFD51': '\u062A\u062D\u062C',
  18397. '\uFD52': '\u062A\u062D\u062C',
  18398. '\uFD53': '\u062A\u062D\u0645',
  18399. '\uFD54': '\u062A\u062E\u0645',
  18400. '\uFD55': '\u062A\u0645\u062C',
  18401. '\uFD56': '\u062A\u0645\u062D',
  18402. '\uFD57': '\u062A\u0645\u062E',
  18403. '\uFD58': '\u062C\u0645\u062D',
  18404. '\uFD59': '\u062C\u0645\u062D',
  18405. '\uFD5A': '\u062D\u0645\u064A',
  18406. '\uFD5B': '\u062D\u0645\u0649',
  18407. '\uFD5C': '\u0633\u062D\u062C',
  18408. '\uFD5D': '\u0633\u062C\u062D',
  18409. '\uFD5E': '\u0633\u062C\u0649',
  18410. '\uFD5F': '\u0633\u0645\u062D',
  18411. '\uFD60': '\u0633\u0645\u062D',
  18412. '\uFD61': '\u0633\u0645\u062C',
  18413. '\uFD62': '\u0633\u0645\u0645',
  18414. '\uFD63': '\u0633\u0645\u0645',
  18415. '\uFD64': '\u0635\u062D\u062D',
  18416. '\uFD65': '\u0635\u062D\u062D',
  18417. '\uFD66': '\u0635\u0645\u0645',
  18418. '\uFD67': '\u0634\u062D\u0645',
  18419. '\uFD68': '\u0634\u062D\u0645',
  18420. '\uFD69': '\u0634\u062C\u064A',
  18421. '\uFD6A': '\u0634\u0645\u062E',
  18422. '\uFD6B': '\u0634\u0645\u062E',
  18423. '\uFD6C': '\u0634\u0645\u0645',
  18424. '\uFD6D': '\u0634\u0645\u0645',
  18425. '\uFD6E': '\u0636\u062D\u0649',
  18426. '\uFD6F': '\u0636\u062E\u0645',
  18427. '\uFD70': '\u0636\u062E\u0645',
  18428. '\uFD71': '\u0637\u0645\u062D',
  18429. '\uFD72': '\u0637\u0645\u062D',
  18430. '\uFD73': '\u0637\u0645\u0645',
  18431. '\uFD74': '\u0637\u0645\u064A',
  18432. '\uFD75': '\u0639\u062C\u0645',
  18433. '\uFD76': '\u0639\u0645\u0645',
  18434. '\uFD77': '\u0639\u0645\u0645',
  18435. '\uFD78': '\u0639\u0645\u0649',
  18436. '\uFD79': '\u063A\u0645\u0645',
  18437. '\uFD7A': '\u063A\u0645\u064A',
  18438. '\uFD7B': '\u063A\u0645\u0649',
  18439. '\uFD7C': '\u0641\u062E\u0645',
  18440. '\uFD7D': '\u0641\u062E\u0645',
  18441. '\uFD7E': '\u0642\u0645\u062D',
  18442. '\uFD7F': '\u0642\u0645\u0645',
  18443. '\uFD80': '\u0644\u062D\u0645',
  18444. '\uFD81': '\u0644\u062D\u064A',
  18445. '\uFD82': '\u0644\u062D\u0649',
  18446. '\uFD83': '\u0644\u062C\u062C',
  18447. '\uFD84': '\u0644\u062C\u062C',
  18448. '\uFD85': '\u0644\u062E\u0645',
  18449. '\uFD86': '\u0644\u062E\u0645',
  18450. '\uFD87': '\u0644\u0645\u062D',
  18451. '\uFD88': '\u0644\u0645\u062D',
  18452. '\uFD89': '\u0645\u062D\u062C',
  18453. '\uFD8A': '\u0645\u062D\u0645',
  18454. '\uFD8B': '\u0645\u062D\u064A',
  18455. '\uFD8C': '\u0645\u062C\u062D',
  18456. '\uFD8D': '\u0645\u062C\u0645',
  18457. '\uFD8E': '\u0645\u062E\u062C',
  18458. '\uFD8F': '\u0645\u062E\u0645',
  18459. '\uFD92': '\u0645\u062C\u062E',
  18460. '\uFD93': '\u0647\u0645\u062C',
  18461. '\uFD94': '\u0647\u0645\u0645',
  18462. '\uFD95': '\u0646\u062D\u0645',
  18463. '\uFD96': '\u0646\u062D\u0649',
  18464. '\uFD97': '\u0646\u062C\u0645',
  18465. '\uFD98': '\u0646\u062C\u0645',
  18466. '\uFD99': '\u0646\u062C\u0649',
  18467. '\uFD9A': '\u0646\u0645\u064A',
  18468. '\uFD9B': '\u0646\u0645\u0649',
  18469. '\uFD9C': '\u064A\u0645\u0645',
  18470. '\uFD9D': '\u064A\u0645\u0645',
  18471. '\uFD9E': '\u0628\u062E\u064A',
  18472. '\uFD9F': '\u062A\u062C\u064A',
  18473. '\uFDA0': '\u062A\u062C\u0649',
  18474. '\uFDA1': '\u062A\u062E\u064A',
  18475. '\uFDA2': '\u062A\u062E\u0649',
  18476. '\uFDA3': '\u062A\u0645\u064A',
  18477. '\uFDA4': '\u062A\u0645\u0649',
  18478. '\uFDA5': '\u062C\u0645\u064A',
  18479. '\uFDA6': '\u062C\u062D\u0649',
  18480. '\uFDA7': '\u062C\u0645\u0649',
  18481. '\uFDA8': '\u0633\u062E\u0649',
  18482. '\uFDA9': '\u0635\u062D\u064A',
  18483. '\uFDAA': '\u0634\u062D\u064A',
  18484. '\uFDAB': '\u0636\u062D\u064A',
  18485. '\uFDAC': '\u0644\u062C\u064A',
  18486. '\uFDAD': '\u0644\u0645\u064A',
  18487. '\uFDAE': '\u064A\u062D\u064A',
  18488. '\uFDAF': '\u064A\u062C\u064A',
  18489. '\uFDB0': '\u064A\u0645\u064A',
  18490. '\uFDB1': '\u0645\u0645\u064A',
  18491. '\uFDB2': '\u0642\u0645\u064A',
  18492. '\uFDB3': '\u0646\u062D\u064A',
  18493. '\uFDB4': '\u0642\u0645\u062D',
  18494. '\uFDB5': '\u0644\u062D\u0645',
  18495. '\uFDB6': '\u0639\u0645\u064A',
  18496. '\uFDB7': '\u0643\u0645\u064A',
  18497. '\uFDB8': '\u0646\u062C\u062D',
  18498. '\uFDB9': '\u0645\u062E\u064A',
  18499. '\uFDBA': '\u0644\u062C\u0645',
  18500. '\uFDBB': '\u0643\u0645\u0645',
  18501. '\uFDBC': '\u0644\u062C\u0645',
  18502. '\uFDBD': '\u0646\u062C\u062D',
  18503. '\uFDBE': '\u062C\u062D\u064A',
  18504. '\uFDBF': '\u062D\u062C\u064A',
  18505. '\uFDC0': '\u0645\u062C\u064A',
  18506. '\uFDC1': '\u0641\u0645\u064A',
  18507. '\uFDC2': '\u0628\u062D\u064A',
  18508. '\uFDC3': '\u0643\u0645\u0645',
  18509. '\uFDC4': '\u0639\u062C\u0645',
  18510. '\uFDC5': '\u0635\u0645\u0645',
  18511. '\uFDC6': '\u0633\u062E\u064A',
  18512. '\uFDC7': '\u0646\u062C\u064A',
  18513. '\uFE49': '\u203E',
  18514. '\uFE4A': '\u203E',
  18515. '\uFE4B': '\u203E',
  18516. '\uFE4C': '\u203E',
  18517. '\uFE4D': '\u005F',
  18518. '\uFE4E': '\u005F',
  18519. '\uFE4F': '\u005F',
  18520. '\uFE80': '\u0621',
  18521. '\uFE81': '\u0622',
  18522. '\uFE82': '\u0622',
  18523. '\uFE83': '\u0623',
  18524. '\uFE84': '\u0623',
  18525. '\uFE85': '\u0624',
  18526. '\uFE86': '\u0624',
  18527. '\uFE87': '\u0625',
  18528. '\uFE88': '\u0625',
  18529. '\uFE89': '\u0626',
  18530. '\uFE8A': '\u0626',
  18531. '\uFE8B': '\u0626',
  18532. '\uFE8C': '\u0626',
  18533. '\uFE8D': '\u0627',
  18534. '\uFE8E': '\u0627',
  18535. '\uFE8F': '\u0628',
  18536. '\uFE90': '\u0628',
  18537. '\uFE91': '\u0628',
  18538. '\uFE92': '\u0628',
  18539. '\uFE93': '\u0629',
  18540. '\uFE94': '\u0629',
  18541. '\uFE95': '\u062A',
  18542. '\uFE96': '\u062A',
  18543. '\uFE97': '\u062A',
  18544. '\uFE98': '\u062A',
  18545. '\uFE99': '\u062B',
  18546. '\uFE9A': '\u062B',
  18547. '\uFE9B': '\u062B',
  18548. '\uFE9C': '\u062B',
  18549. '\uFE9D': '\u062C',
  18550. '\uFE9E': '\u062C',
  18551. '\uFE9F': '\u062C',
  18552. '\uFEA0': '\u062C',
  18553. '\uFEA1': '\u062D',
  18554. '\uFEA2': '\u062D',
  18555. '\uFEA3': '\u062D',
  18556. '\uFEA4': '\u062D',
  18557. '\uFEA5': '\u062E',
  18558. '\uFEA6': '\u062E',
  18559. '\uFEA7': '\u062E',
  18560. '\uFEA8': '\u062E',
  18561. '\uFEA9': '\u062F',
  18562. '\uFEAA': '\u062F',
  18563. '\uFEAB': '\u0630',
  18564. '\uFEAC': '\u0630',
  18565. '\uFEAD': '\u0631',
  18566. '\uFEAE': '\u0631',
  18567. '\uFEAF': '\u0632',
  18568. '\uFEB0': '\u0632',
  18569. '\uFEB1': '\u0633',
  18570. '\uFEB2': '\u0633',
  18571. '\uFEB3': '\u0633',
  18572. '\uFEB4': '\u0633',
  18573. '\uFEB5': '\u0634',
  18574. '\uFEB6': '\u0634',
  18575. '\uFEB7': '\u0634',
  18576. '\uFEB8': '\u0634',
  18577. '\uFEB9': '\u0635',
  18578. '\uFEBA': '\u0635',
  18579. '\uFEBB': '\u0635',
  18580. '\uFEBC': '\u0635',
  18581. '\uFEBD': '\u0636',
  18582. '\uFEBE': '\u0636',
  18583. '\uFEBF': '\u0636',
  18584. '\uFEC0': '\u0636',
  18585. '\uFEC1': '\u0637',
  18586. '\uFEC2': '\u0637',
  18587. '\uFEC3': '\u0637',
  18588. '\uFEC4': '\u0637',
  18589. '\uFEC5': '\u0638',
  18590. '\uFEC6': '\u0638',
  18591. '\uFEC7': '\u0638',
  18592. '\uFEC8': '\u0638',
  18593. '\uFEC9': '\u0639',
  18594. '\uFECA': '\u0639',
  18595. '\uFECB': '\u0639',
  18596. '\uFECC': '\u0639',
  18597. '\uFECD': '\u063A',
  18598. '\uFECE': '\u063A',
  18599. '\uFECF': '\u063A',
  18600. '\uFED0': '\u063A',
  18601. '\uFED1': '\u0641',
  18602. '\uFED2': '\u0641',
  18603. '\uFED3': '\u0641',
  18604. '\uFED4': '\u0641',
  18605. '\uFED5': '\u0642',
  18606. '\uFED6': '\u0642',
  18607. '\uFED7': '\u0642',
  18608. '\uFED8': '\u0642',
  18609. '\uFED9': '\u0643',
  18610. '\uFEDA': '\u0643',
  18611. '\uFEDB': '\u0643',
  18612. '\uFEDC': '\u0643',
  18613. '\uFEDD': '\u0644',
  18614. '\uFEDE': '\u0644',
  18615. '\uFEDF': '\u0644',
  18616. '\uFEE0': '\u0644',
  18617. '\uFEE1': '\u0645',
  18618. '\uFEE2': '\u0645',
  18619. '\uFEE3': '\u0645',
  18620. '\uFEE4': '\u0645',
  18621. '\uFEE5': '\u0646',
  18622. '\uFEE6': '\u0646',
  18623. '\uFEE7': '\u0646',
  18624. '\uFEE8': '\u0646',
  18625. '\uFEE9': '\u0647',
  18626. '\uFEEA': '\u0647',
  18627. '\uFEEB': '\u0647',
  18628. '\uFEEC': '\u0647',
  18629. '\uFEED': '\u0648',
  18630. '\uFEEE': '\u0648',
  18631. '\uFEEF': '\u0649',
  18632. '\uFEF0': '\u0649',
  18633. '\uFEF1': '\u064A',
  18634. '\uFEF2': '\u064A',
  18635. '\uFEF3': '\u064A',
  18636. '\uFEF4': '\u064A',
  18637. '\uFEF5': '\u0644\u0622',
  18638. '\uFEF6': '\u0644\u0622',
  18639. '\uFEF7': '\u0644\u0623',
  18640. '\uFEF8': '\u0644\u0623',
  18641. '\uFEF9': '\u0644\u0625',
  18642. '\uFEFA': '\u0644\u0625',
  18643. '\uFEFB': '\u0644\u0627',
  18644. '\uFEFC': '\u0644\u0627'
  18645. };
  18646. function reverseIfRtl(chars) {
  18647. var charsLength = chars.length;
  18648. //reverse an arabic ligature
  18649. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18650. return chars;
  18651. }
  18652. var s = '';
  18653. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18654. s += chars[ii];
  18655. }
  18656. return s;
  18657. }
  18658. function adjustWidths(properties) {
  18659. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  18660. return;
  18661. }
  18662. // adjusting width to fontMatrix scale
  18663. var scale = 0.001 / properties.fontMatrix[0];
  18664. var glyphsWidths = properties.widths;
  18665. for (var glyph in glyphsWidths) {
  18666. glyphsWidths[glyph] *= scale;
  18667. }
  18668. properties.defaultWidth *= scale;
  18669. }
  18670. function getFontType(type, subtype) {
  18671. switch (type) {
  18672. case 'Type1':
  18673. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  18674. case 'CIDFontType0':
  18675. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  18676. FontType.CIDFONTTYPE0;
  18677. case 'OpenType':
  18678. return FontType.OPENTYPE;
  18679. case 'TrueType':
  18680. return FontType.TRUETYPE;
  18681. case 'CIDFontType2':
  18682. return FontType.CIDFONTTYPE2;
  18683. case 'MMType1':
  18684. return FontType.MMTYPE1;
  18685. case 'Type0':
  18686. return FontType.TYPE0;
  18687. default:
  18688. return FontType.UNKNOWN;
  18689. }
  18690. }
  18691. var Glyph = (function GlyphClosure() {
  18692. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  18693. this.fontChar = fontChar;
  18694. this.unicode = unicode;
  18695. this.accent = accent;
  18696. this.width = width;
  18697. this.vmetric = vmetric;
  18698. this.operatorListId = operatorListId;
  18699. }
  18700. Glyph.prototype.matchesForCache =
  18701. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  18702. return this.fontChar === fontChar &&
  18703. this.unicode === unicode &&
  18704. this.accent === accent &&
  18705. this.width === width &&
  18706. this.vmetric === vmetric &&
  18707. this.operatorListId === operatorListId;
  18708. };
  18709. return Glyph;
  18710. })();
  18711. /**
  18712. * 'Font' is the class the outside world should use, it encapsulate all the font
  18713. * decoding logics whatever type it is (assuming the font type is supported).
  18714. *
  18715. * For example to read a Type1 font and to attach it to the document:
  18716. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  18717. * type1Font.bind();
  18718. */
  18719. var Font = (function FontClosure() {
  18720. function Font(name, file, properties) {
  18721. var charCode, glyphName;
  18722. this.name = name;
  18723. this.loadedName = properties.loadedName;
  18724. this.isType3Font = properties.isType3Font;
  18725. this.sizes = [];
  18726. this.glyphCache = {};
  18727. var names = name.split('+');
  18728. names = names.length > 1 ? names[1] : names[0];
  18729. names = names.split(/[-,_]/g)[0];
  18730. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  18731. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  18732. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  18733. var type = properties.type;
  18734. var subtype = properties.subtype;
  18735. this.type = type;
  18736. this.fallbackName = (this.isMonospace ? 'monospace' :
  18737. (this.isSerifFont ? 'serif' : 'sans-serif'));
  18738. this.differences = properties.differences;
  18739. this.widths = properties.widths;
  18740. this.defaultWidth = properties.defaultWidth;
  18741. this.composite = properties.composite;
  18742. this.wideChars = properties.wideChars;
  18743. this.cMap = properties.cMap;
  18744. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  18745. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  18746. this.fontMatrix = properties.fontMatrix;
  18747. var unicode = this.buildToUnicode(properties);
  18748. this.toUnicode = properties.toUnicode = unicode.toUnicode;
  18749. this.isIdentityUnicode = properties.isIdentityUnicode = unicode.isIdentity;
  18750. this.toFontChar = [];
  18751. if (properties.type === 'Type3') {
  18752. for (charCode = 0; charCode < 256; charCode++) {
  18753. this.toFontChar[charCode] = (this.differences[charCode] ||
  18754. properties.defaultEncoding[charCode]);
  18755. }
  18756. this.fontType = FontType.TYPE3;
  18757. return;
  18758. }
  18759. this.cidEncoding = properties.cidEncoding;
  18760. this.vertical = properties.vertical;
  18761. if (this.vertical) {
  18762. this.vmetrics = properties.vmetrics;
  18763. this.defaultVMetrics = properties.defaultVMetrics;
  18764. }
  18765. if (!file || file.isEmpty) {
  18766. if (file) {
  18767. // Some bad PDF generators will include empty font files,
  18768. // attempting to recover by assuming that no file exists.
  18769. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  18770. }
  18771. this.missingFile = true;
  18772. // The file data is not specified. Trying to fix the font name
  18773. // to be used with the canvas.font.
  18774. var fontName = name.replace(/[,_]/g, '-');
  18775. var isStandardFont = fontName in stdFontMap;
  18776. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  18777. this.bold = (fontName.search(/bold/gi) !== -1);
  18778. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  18779. (fontName.search(/italic/gi) !== -1));
  18780. // Use 'name' instead of 'fontName' here because the original
  18781. // name ArialBlack for example will be replaced by Helvetica.
  18782. this.black = (name.search(/Black/g) !== -1);
  18783. // if at least one width is present, remeasure all chars when exists
  18784. this.remeasure = Object.keys(this.widths).length > 0;
  18785. if (isStandardFont && type === 'CIDFontType2' &&
  18786. properties.cidEncoding.indexOf('Identity-') === 0) {
  18787. // Standard fonts might be embedded as CID font without glyph mapping.
  18788. // Building one based on GlyphMapForStandardFonts.
  18789. var map = [];
  18790. for (var code in GlyphMapForStandardFonts) {
  18791. map[+code] = GlyphMapForStandardFonts[code];
  18792. }
  18793. this.toFontChar = map;
  18794. this.toUnicode = map;
  18795. } else if (/Symbol/i.test(fontName)) {
  18796. var symbols = Encodings.SymbolSetEncoding;
  18797. for (charCode in symbols) {
  18798. var fontChar = GlyphsUnicode[symbols[charCode]];
  18799. if (!fontChar) {
  18800. continue;
  18801. }
  18802. this.toFontChar[charCode] = fontChar;
  18803. }
  18804. } else if (isStandardFont) {
  18805. this.toFontChar = [];
  18806. for (charCode in properties.defaultEncoding) {
  18807. glyphName = (properties.differences[charCode] ||
  18808. properties.defaultEncoding[charCode]);
  18809. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  18810. }
  18811. } else {
  18812. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  18813. for (charCode in this.toUnicode) {
  18814. unicodeCharCode = this.toUnicode[charCode].charCodeAt(0);
  18815. if (notCidFont) {
  18816. glyphName = (properties.differences[charCode] ||
  18817. properties.defaultEncoding[charCode]);
  18818. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  18819. }
  18820. this.toFontChar[charCode] = unicodeCharCode;
  18821. }
  18822. }
  18823. this.loadedName = fontName.split('-')[0];
  18824. this.loading = false;
  18825. this.fontType = getFontType(type, subtype);
  18826. return;
  18827. }
  18828. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  18829. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  18830. // Some TrueType fonts by mistake claim Type1C
  18831. if (isTrueTypeFile(file)) {
  18832. subtype = 'TrueType';
  18833. } else {
  18834. type = 'Type1';
  18835. }
  18836. }
  18837. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  18838. type = 'CIDFontType0';
  18839. }
  18840. // XXX: Temporarily change the type for open type so we trigger a warning.
  18841. // This should be removed when we add support for open type.
  18842. if (subtype === 'OpenType') {
  18843. type = 'OpenType';
  18844. }
  18845. var data;
  18846. switch (type) {
  18847. case 'Type1':
  18848. case 'CIDFontType0':
  18849. this.mimetype = 'font/opentype';
  18850. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  18851. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  18852. adjustWidths(properties);
  18853. // Wrap the CFF data inside an OTF font file
  18854. data = this.convert(name, cff, properties);
  18855. break;
  18856. case 'OpenType':
  18857. case 'TrueType':
  18858. case 'CIDFontType2':
  18859. this.mimetype = 'font/opentype';
  18860. // Repair the TrueType file. It is can be damaged in the point of
  18861. // view of the sanitizer
  18862. data = this.checkAndRepair(name, file, properties);
  18863. if (this.isOpenType) {
  18864. type = 'OpenType';
  18865. }
  18866. break;
  18867. default:
  18868. error('Font ' + type + ' is not supported');
  18869. break;
  18870. }
  18871. this.data = data;
  18872. this.fontType = getFontType(type, subtype);
  18873. // Transfer some properties again that could change during font conversion
  18874. this.fontMatrix = properties.fontMatrix;
  18875. this.widths = properties.widths;
  18876. this.defaultWidth = properties.defaultWidth;
  18877. this.encoding = properties.baseEncoding;
  18878. this.seacMap = properties.seacMap;
  18879. this.loading = true;
  18880. }
  18881. Font.getFontID = (function () {
  18882. var ID = 1;
  18883. return function Font_getFontID() {
  18884. return String(ID++);
  18885. };
  18886. })();
  18887. function int16(b0, b1) {
  18888. return (b0 << 8) + b1;
  18889. }
  18890. function int32(b0, b1, b2, b3) {
  18891. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  18892. }
  18893. function getMaxPower2(number) {
  18894. var maxPower = 0;
  18895. var value = number;
  18896. while (value >= 2) {
  18897. value /= 2;
  18898. maxPower++;
  18899. }
  18900. value = 2;
  18901. for (var i = 1; i < maxPower; i++) {
  18902. value *= 2;
  18903. }
  18904. return value;
  18905. }
  18906. function string16(value) {
  18907. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  18908. }
  18909. function safeString16(value) {
  18910. // clamp value to the 16-bit int range
  18911. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  18912. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  18913. }
  18914. function createOpenTypeHeader(sfnt, file, numTables) {
  18915. // Windows hates the Mac TrueType sfnt version number
  18916. if (sfnt === 'true') {
  18917. sfnt = string32(0x00010000);
  18918. }
  18919. // sfnt version (4 bytes)
  18920. var header = sfnt;
  18921. // numTables (2 bytes)
  18922. header += string16(numTables);
  18923. // searchRange (2 bytes)
  18924. var tablesMaxPower2 = getMaxPower2(numTables);
  18925. var searchRange = tablesMaxPower2 * 16;
  18926. header += string16(searchRange);
  18927. // entrySelector (2 bytes)
  18928. header += string16(Math.log(tablesMaxPower2) / Math.log(2));
  18929. // rangeShift (2 bytes)
  18930. header += string16(numTables * 16 - searchRange);
  18931. file.file += header;
  18932. file.virtualOffset += header.length;
  18933. }
  18934. function createTableEntry(file, tag, data) {
  18935. // offset
  18936. var offset = file.virtualOffset;
  18937. // length
  18938. var length = data.length;
  18939. // Per spec tables must be 4-bytes align so add padding as needed.
  18940. var paddedLength = length;
  18941. while (paddedLength & 3) {
  18942. paddedLength++;
  18943. }
  18944. var i;
  18945. var padding = paddedLength - length;
  18946. if (padding !== 0) {
  18947. // Padding is required. |data| can be an Array, Uint8Array, or
  18948. // Uint16Array. In the latter two cases we need to create slightly larger
  18949. // typed arrays and copy the old contents in. Fortunately that's not a
  18950. // common case.
  18951. var data2;
  18952. if (data instanceof Array) {
  18953. for (i = 0; i < padding; i++) {
  18954. data.push(0);
  18955. }
  18956. } else if (data instanceof Uint8Array) {
  18957. data2 = new Uint8Array(paddedLength);
  18958. data2.set(data);
  18959. data = data2;
  18960. } else if (data instanceof Uint16Array) {
  18961. data2 = new Uint16Array(paddedLength);
  18962. data2.set(data);
  18963. data = data2;
  18964. } else {
  18965. error('bad array kind in createTableEntry');
  18966. }
  18967. }
  18968. while (file.virtualOffset & 3) {
  18969. file.virtualOffset++;
  18970. }
  18971. // checksum
  18972. var checksum = 0, n = data.length;
  18973. for (i = 0; i < n; i += 4) {
  18974. checksum = (checksum + int32(data[i], data[i + 1], data[i + 2],
  18975. data[i + 3])) | 0;
  18976. }
  18977. var tableEntry = (tag + string32(checksum) +
  18978. string32(offset) + string32(length));
  18979. file.file += tableEntry;
  18980. file.virtualOffset += data.length;
  18981. return data;
  18982. }
  18983. function isTrueTypeFile(file) {
  18984. var header = file.peekBytes(4);
  18985. return readUint32(header, 0) === 0x00010000;
  18986. }
  18987. /**
  18988. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  18989. * with their unicode value. It also moves char codes that are in known
  18990. * problematic locations.
  18991. * @return {Object} Two properties:
  18992. * 'toFontChar' - maps original char codes(the value that will be read
  18993. * from commands such as show text) to the char codes that will be used in the
  18994. * font that we build
  18995. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  18996. */
  18997. function adjustMapping(charCodeToGlyphId, properties) {
  18998. var toUnicode = properties.toUnicode;
  18999. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  19000. var isIdentityUnicode = properties.isIdentityUnicode;
  19001. var isCidFontType2 = (properties.type === 'CIDFontType2');
  19002. var newMap = Object.create(null);
  19003. var toFontChar = [];
  19004. var usedFontCharCodes = [];
  19005. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  19006. for (var originalCharCode in charCodeToGlyphId) {
  19007. originalCharCode |= 0;
  19008. var glyphId = charCodeToGlyphId[originalCharCode];
  19009. var fontCharCode = originalCharCode;
  19010. // First try to map the value to a unicode position if a non identity map
  19011. // was created.
  19012. if (!isIdentityUnicode) {
  19013. if (toUnicode[originalCharCode] !== undefined) {
  19014. var unicode = toUnicode[fontCharCode];
  19015. // TODO: Try to map ligatures to the correct spot.
  19016. if (unicode.length === 1) {
  19017. fontCharCode = unicode.charCodeAt(0);
  19018. }
  19019. } else if (isCidFontType2) {
  19020. // For CIDFontType2, move characters not present in toUnicode
  19021. // to the private use area (fixes bug 1028735 and issue 4881).
  19022. fontCharCode = nextAvailableFontCharCode;
  19023. }
  19024. }
  19025. // Try to move control characters, special characters and already mapped
  19026. // characters to the private use area since they will not be drawn by
  19027. // canvas if left in their current position. Also, move characters if the
  19028. // font was symbolic and there is only an identity unicode map since the
  19029. // characters probably aren't in the correct position (fixes an issue
  19030. // with firefox and thuluthfont).
  19031. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  19032. fontCharCode <= 0x1f || // Control chars
  19033. fontCharCode === 0x7F || // Control char
  19034. fontCharCode === 0xAD || // Soft hyphen
  19035. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  19036. // Prevent drawing characters in the specials unicode block.
  19037. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  19038. (isSymbolic && isIdentityUnicode)) &&
  19039. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  19040. // Loop to try and find a free spot in the private use area.
  19041. do {
  19042. fontCharCode = nextAvailableFontCharCode++;
  19043. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  19044. fontCharCode = 0xF020;
  19045. nextAvailableFontCharCode = fontCharCode + 1;
  19046. }
  19047. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  19048. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  19049. }
  19050. newMap[fontCharCode] = glyphId;
  19051. toFontChar[originalCharCode] = fontCharCode;
  19052. usedFontCharCodes[fontCharCode] = true;
  19053. }
  19054. return {
  19055. toFontChar: toFontChar,
  19056. charCodeToGlyphId: newMap,
  19057. nextAvailableFontCharCode: nextAvailableFontCharCode
  19058. };
  19059. }
  19060. function getRanges(glyphs) {
  19061. // Array.sort() sorts by characters, not numerically, so convert to an
  19062. // array of characters.
  19063. var codes = [];
  19064. for (var charCode in glyphs) {
  19065. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  19066. }
  19067. codes.sort(function fontGetRangesSort(a, b) {
  19068. return a.fontCharCode - b.fontCharCode;
  19069. });
  19070. // Split the sorted codes into ranges.
  19071. var ranges = [];
  19072. var length = codes.length;
  19073. for (var n = 0; n < length; ) {
  19074. var start = codes[n].fontCharCode;
  19075. var codeIndices = [codes[n].glyphId];
  19076. ++n;
  19077. var end = start;
  19078. while (n < length && end + 1 === codes[n].fontCharCode) {
  19079. codeIndices.push(codes[n].glyphId);
  19080. ++end;
  19081. ++n;
  19082. if (end === 0xFFFF) {
  19083. break;
  19084. }
  19085. }
  19086. ranges.push([start, end, codeIndices]);
  19087. }
  19088. return ranges;
  19089. }
  19090. function createCmapTable(glyphs) {
  19091. var ranges = getRanges(glyphs);
  19092. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  19093. var cmap = '\x00\x00' + // version
  19094. string16(numTables) + // numTables
  19095. '\x00\x03' + // platformID
  19096. '\x00\x01' + // encodingID
  19097. string32(4 + numTables * 8); // start of the table record
  19098. var i, ii, j, jj;
  19099. for (i = ranges.length - 1; i >= 0; --i) {
  19100. if (ranges[i][0] <= 0xFFFF) { break; }
  19101. }
  19102. var bmpLength = i + 1;
  19103. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  19104. ranges[i][1] = 0xFFFE;
  19105. }
  19106. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  19107. var segCount = bmpLength + trailingRangesCount;
  19108. var segCount2 = segCount * 2;
  19109. var searchRange = getMaxPower2(segCount) * 2;
  19110. var searchEntry = Math.log(segCount) / Math.log(2);
  19111. var rangeShift = 2 * segCount - searchRange;
  19112. // Fill up the 4 parallel arrays describing the segments.
  19113. var startCount = '';
  19114. var endCount = '';
  19115. var idDeltas = '';
  19116. var idRangeOffsets = '';
  19117. var glyphsIds = '';
  19118. var bias = 0;
  19119. var range, start, end, codes;
  19120. for (i = 0, ii = bmpLength; i < ii; i++) {
  19121. range = ranges[i];
  19122. start = range[0];
  19123. end = range[1];
  19124. startCount += string16(start);
  19125. endCount += string16(end);
  19126. codes = range[2];
  19127. var contiguous = true;
  19128. for (j = 1, jj = codes.length; j < jj; ++j) {
  19129. if (codes[j] !== codes[j - 1] + 1) {
  19130. contiguous = false;
  19131. break;
  19132. }
  19133. }
  19134. if (!contiguous) {
  19135. var offset = (segCount - i) * 2 + bias * 2;
  19136. bias += (end - start + 1);
  19137. idDeltas += string16(0);
  19138. idRangeOffsets += string16(offset);
  19139. for (j = 0, jj = codes.length; j < jj; ++j) {
  19140. glyphsIds += string16(codes[j]);
  19141. }
  19142. } else {
  19143. var startCode = codes[0];
  19144. idDeltas += string16((startCode - start) & 0xFFFF);
  19145. idRangeOffsets += string16(0);
  19146. }
  19147. }
  19148. if (trailingRangesCount > 0) {
  19149. endCount += '\xFF\xFF';
  19150. startCount += '\xFF\xFF';
  19151. idDeltas += '\x00\x01';
  19152. idRangeOffsets += '\x00\x00';
  19153. }
  19154. var format314 = '\x00\x00' + // language
  19155. string16(segCount2) +
  19156. string16(searchRange) +
  19157. string16(searchEntry) +
  19158. string16(rangeShift) +
  19159. endCount + '\x00\x00' + startCount +
  19160. idDeltas + idRangeOffsets + glyphsIds;
  19161. var format31012 = '';
  19162. var header31012 = '';
  19163. if (numTables > 1) {
  19164. cmap += '\x00\x03' + // platformID
  19165. '\x00\x0A' + // encodingID
  19166. string32(4 + numTables * 8 +
  19167. 4 + format314.length); // start of the table record
  19168. format31012 = '';
  19169. for (i = 0, ii = ranges.length; i < ii; i++) {
  19170. range = ranges[i];
  19171. start = range[0];
  19172. codes = range[2];
  19173. var code = codes[0];
  19174. for (j = 1, jj = codes.length; j < jj; ++j) {
  19175. if (codes[j] !== codes[j - 1] + 1) {
  19176. end = range[0] + j - 1;
  19177. format31012 += string32(start) + // startCharCode
  19178. string32(end) + // endCharCode
  19179. string32(code); // startGlyphID
  19180. start = end + 1;
  19181. code = codes[j];
  19182. }
  19183. }
  19184. format31012 += string32(start) + // startCharCode
  19185. string32(range[1]) + // endCharCode
  19186. string32(code); // startGlyphID
  19187. }
  19188. header31012 = '\x00\x0C' + // format
  19189. '\x00\x00' + // reserved
  19190. string32(format31012.length + 16) + // length
  19191. '\x00\x00\x00\x00' + // language
  19192. string32(format31012.length / 12); // nGroups
  19193. }
  19194. return stringToArray(cmap +
  19195. '\x00\x04' + // format
  19196. string16(format314.length + 4) + // length
  19197. format314 + header31012 + format31012);
  19198. }
  19199. function validateOS2Table(os2) {
  19200. var stream = new Stream(os2.data);
  19201. var version = stream.getUint16();
  19202. // TODO verify all OS/2 tables fields, but currently we validate only those
  19203. // that give us issues
  19204. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  19205. var selection = stream.getUint16();
  19206. if (version < 4 && (selection & 0x0300)) {
  19207. return false;
  19208. }
  19209. var firstChar = stream.getUint16();
  19210. var lastChar = stream.getUint16();
  19211. if (firstChar > lastChar) {
  19212. return false;
  19213. }
  19214. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  19215. var usWinAscent = stream.getUint16();
  19216. if (usWinAscent === 0) { // makes font unreadable by windows
  19217. return false;
  19218. }
  19219. // OS/2 appears to be valid, resetting some fields
  19220. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  19221. return true;
  19222. }
  19223. function createOS2Table(properties, charstrings, override) {
  19224. override = override || {
  19225. unitsPerEm: 0,
  19226. yMax: 0,
  19227. yMin: 0,
  19228. ascent: 0,
  19229. descent: 0
  19230. };
  19231. var ulUnicodeRange1 = 0;
  19232. var ulUnicodeRange2 = 0;
  19233. var ulUnicodeRange3 = 0;
  19234. var ulUnicodeRange4 = 0;
  19235. var firstCharIndex = null;
  19236. var lastCharIndex = 0;
  19237. if (charstrings) {
  19238. for (var code in charstrings) {
  19239. code |= 0;
  19240. if (firstCharIndex > code || !firstCharIndex) {
  19241. firstCharIndex = code;
  19242. }
  19243. if (lastCharIndex < code) {
  19244. lastCharIndex = code;
  19245. }
  19246. var position = getUnicodeRangeFor(code);
  19247. if (position < 32) {
  19248. ulUnicodeRange1 |= 1 << position;
  19249. } else if (position < 64) {
  19250. ulUnicodeRange2 |= 1 << position - 32;
  19251. } else if (position < 96) {
  19252. ulUnicodeRange3 |= 1 << position - 64;
  19253. } else if (position < 123) {
  19254. ulUnicodeRange4 |= 1 << position - 96;
  19255. } else {
  19256. error('Unicode ranges Bits > 123 are reserved for internal usage');
  19257. }
  19258. }
  19259. } else {
  19260. // TODO
  19261. firstCharIndex = 0;
  19262. lastCharIndex = 255;
  19263. }
  19264. var bbox = properties.bbox || [0, 0, 0, 0];
  19265. var unitsPerEm = (override.unitsPerEm ||
  19266. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  19267. // if the font units differ to the PDF glyph space units
  19268. // then scale up the values
  19269. var scale = (properties.ascentScaled ? 1.0 :
  19270. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  19271. var typoAscent = (override.ascent ||
  19272. Math.round(scale * (properties.ascent || bbox[3])));
  19273. var typoDescent = (override.descent ||
  19274. Math.round(scale * (properties.descent || bbox[1])));
  19275. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  19276. typoDescent = -typoDescent; // fixing incorrect descent
  19277. }
  19278. var winAscent = override.yMax || typoAscent;
  19279. var winDescent = -override.yMin || -typoDescent;
  19280. return '\x00\x03' + // version
  19281. '\x02\x24' + // xAvgCharWidth
  19282. '\x01\xF4' + // usWeightClass
  19283. '\x00\x05' + // usWidthClass
  19284. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  19285. '\x02\x8A' + // ySubscriptXSize
  19286. '\x02\xBB' + // ySubscriptYSize
  19287. '\x00\x00' + // ySubscriptXOffset
  19288. '\x00\x8C' + // ySubscriptYOffset
  19289. '\x02\x8A' + // ySuperScriptXSize
  19290. '\x02\xBB' + // ySuperScriptYSize
  19291. '\x00\x00' + // ySuperScriptXOffset
  19292. '\x01\xDF' + // ySuperScriptYOffset
  19293. '\x00\x31' + // yStrikeOutSize
  19294. '\x01\x02' + // yStrikeOutPosition
  19295. '\x00\x00' + // sFamilyClass
  19296. '\x00\x00\x06' +
  19297. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  19298. '\x00\x00\x00\x00\x00\x00' + // Panose
  19299. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  19300. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  19301. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  19302. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  19303. '\x2A\x32\x31\x2A' + // achVendID
  19304. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  19305. string16(firstCharIndex ||
  19306. properties.firstChar) + // usFirstCharIndex
  19307. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  19308. string16(typoAscent) + // sTypoAscender
  19309. string16(typoDescent) + // sTypoDescender
  19310. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  19311. string16(winAscent) + // usWinAscent
  19312. string16(winDescent) + // usWinDescent
  19313. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  19314. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  19315. string16(properties.xHeight) + // sxHeight
  19316. string16(properties.capHeight) + // sCapHeight
  19317. string16(0) + // usDefaultChar
  19318. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  19319. '\x00\x03'; // usMaxContext
  19320. }
  19321. function createPostTable(properties) {
  19322. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  19323. return ('\x00\x03\x00\x00' + // Version number
  19324. string32(angle) + // italicAngle
  19325. '\x00\x00' + // underlinePosition
  19326. '\x00\x00' + // underlineThickness
  19327. string32(properties.fixedPitch) + // isFixedPitch
  19328. '\x00\x00\x00\x00' + // minMemType42
  19329. '\x00\x00\x00\x00' + // maxMemType42
  19330. '\x00\x00\x00\x00' + // minMemType1
  19331. '\x00\x00\x00\x00'); // maxMemType1
  19332. }
  19333. function createNameTable(name, proto) {
  19334. if (!proto) {
  19335. proto = [[], []]; // no strings and unicode strings
  19336. }
  19337. var strings = [
  19338. proto[0][0] || 'Original licence', // 0.Copyright
  19339. proto[0][1] || name, // 1.Font family
  19340. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  19341. proto[0][3] || 'uniqueID', // 3.Unique ID
  19342. proto[0][4] || name, // 4.Full font name
  19343. proto[0][5] || 'Version 0.11', // 5.Version
  19344. proto[0][6] || '', // 6.Postscript name
  19345. proto[0][7] || 'Unknown', // 7.Trademark
  19346. proto[0][8] || 'Unknown', // 8.Manufacturer
  19347. proto[0][9] || 'Unknown' // 9.Designer
  19348. ];
  19349. // Mac want 1-byte per character strings while Windows want
  19350. // 2-bytes per character, so duplicate the names table
  19351. var stringsUnicode = [];
  19352. var i, ii, j, jj, str;
  19353. for (i = 0, ii = strings.length; i < ii; i++) {
  19354. str = proto[1][i] || strings[i];
  19355. var strBufUnicode = [];
  19356. for (j = 0, jj = str.length; j < jj; j++) {
  19357. strBufUnicode.push(string16(str.charCodeAt(j)));
  19358. }
  19359. stringsUnicode.push(strBufUnicode.join(''));
  19360. }
  19361. var names = [strings, stringsUnicode];
  19362. var platforms = ['\x00\x01', '\x00\x03'];
  19363. var encodings = ['\x00\x00', '\x00\x01'];
  19364. var languages = ['\x00\x00', '\x04\x09'];
  19365. var namesRecordCount = strings.length * platforms.length;
  19366. var nameTable =
  19367. '\x00\x00' + // format
  19368. string16(namesRecordCount) + // Number of names Record
  19369. string16(namesRecordCount * 12 + 6); // Storage
  19370. // Build the name records field
  19371. var strOffset = 0;
  19372. for (i = 0, ii = platforms.length; i < ii; i++) {
  19373. var strs = names[i];
  19374. for (j = 0, jj = strs.length; j < jj; j++) {
  19375. str = strs[j];
  19376. var nameRecord =
  19377. platforms[i] + // platform ID
  19378. encodings[i] + // encoding ID
  19379. languages[i] + // language ID
  19380. string16(j) + // name ID
  19381. string16(str.length) +
  19382. string16(strOffset);
  19383. nameTable += nameRecord;
  19384. strOffset += str.length;
  19385. }
  19386. }
  19387. nameTable += strings.join('') + stringsUnicode.join('');
  19388. return nameTable;
  19389. }
  19390. Font.prototype = {
  19391. name: null,
  19392. font: null,
  19393. mimetype: null,
  19394. encoding: null,
  19395. get renderer() {
  19396. var renderer = FontRendererFactory.create(this);
  19397. return shadow(this, 'renderer', renderer);
  19398. },
  19399. exportData: function Font_exportData() {
  19400. var data = {};
  19401. for (var i in this) {
  19402. if (this.hasOwnProperty(i)) {
  19403. data[i] = this[i];
  19404. }
  19405. }
  19406. return data;
  19407. },
  19408. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  19409. function readTableEntry(file) {
  19410. var tag = bytesToString(file.getBytes(4));
  19411. var checksum = file.getInt32();
  19412. var offset = file.getInt32() >>> 0;
  19413. var length = file.getInt32() >>> 0;
  19414. // Read the table associated data
  19415. var previousPosition = file.pos;
  19416. file.pos = file.start ? file.start : 0;
  19417. file.skip(offset);
  19418. var data = file.getBytes(length);
  19419. file.pos = previousPosition;
  19420. if (tag === 'head') {
  19421. // clearing checksum adjustment
  19422. data[8] = data[9] = data[10] = data[11] = 0;
  19423. data[17] |= 0x20; //Set font optimized for cleartype flag
  19424. }
  19425. return {
  19426. tag: tag,
  19427. checksum: checksum,
  19428. length: length,
  19429. offset: offset,
  19430. data: data
  19431. };
  19432. }
  19433. function readOpenTypeHeader(ttf) {
  19434. return {
  19435. version: bytesToString(ttf.getBytes(4)),
  19436. numTables: ttf.getUint16(),
  19437. searchRange: ttf.getUint16(),
  19438. entrySelector: ttf.getUint16(),
  19439. rangeShift: ttf.getUint16()
  19440. };
  19441. }
  19442. /**
  19443. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  19444. * PDF spec
  19445. */
  19446. function readCmapTable(cmap, font, isSymbolicFont) {
  19447. var segment;
  19448. var start = (font.start ? font.start : 0) + cmap.offset;
  19449. font.pos = start;
  19450. var version = font.getUint16();
  19451. var numTables = font.getUint16();
  19452. var potentialTable;
  19453. var canBreak = false;
  19454. // There's an order of preference in terms of which cmap subtable to
  19455. // use:
  19456. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  19457. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  19458. // The following takes advantage of the fact that the tables are sorted
  19459. // to work.
  19460. for (var i = 0; i < numTables; i++) {
  19461. var platformId = font.getUint16();
  19462. var encodingId = font.getUint16();
  19463. var offset = font.getInt32() >>> 0;
  19464. var useTable = false;
  19465. if (platformId === 1 && encodingId === 0) {
  19466. useTable = true;
  19467. // Continue the loop since there still may be a higher priority
  19468. // table.
  19469. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  19470. useTable = true;
  19471. canBreak = true;
  19472. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  19473. useTable = true;
  19474. canBreak = true;
  19475. }
  19476. if (useTable) {
  19477. potentialTable = {
  19478. platformId: platformId,
  19479. encodingId: encodingId,
  19480. offset: offset
  19481. };
  19482. }
  19483. if (canBreak) {
  19484. break;
  19485. }
  19486. }
  19487. if (!potentialTable) {
  19488. warn('Could not find a preferred cmap table.');
  19489. return {
  19490. platformId: -1,
  19491. encodingId: -1,
  19492. mappings: [],
  19493. hasShortCmap: false
  19494. };
  19495. }
  19496. font.pos = start + potentialTable.offset;
  19497. var format = font.getUint16();
  19498. var length = font.getUint16();
  19499. var language = font.getUint16();
  19500. var hasShortCmap = false;
  19501. var mappings = [];
  19502. var j, glyphId;
  19503. // TODO(mack): refactor this cmap subtable reading logic out
  19504. if (format === 0) {
  19505. for (j = 0; j < 256; j++) {
  19506. var index = font.getByte();
  19507. if (!index) {
  19508. continue;
  19509. }
  19510. mappings.push({
  19511. charCode: j,
  19512. glyphId: index
  19513. });
  19514. }
  19515. hasShortCmap = true;
  19516. } else if (format === 4) {
  19517. // re-creating the table in format 4 since the encoding
  19518. // might be changed
  19519. var segCount = (font.getUint16() >> 1);
  19520. font.getBytes(6); // skipping range fields
  19521. var segIndex, segments = [];
  19522. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19523. segments.push({ end: font.getUint16() });
  19524. }
  19525. font.getUint16();
  19526. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19527. segments[segIndex].start = font.getUint16();
  19528. }
  19529. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19530. segments[segIndex].delta = font.getUint16();
  19531. }
  19532. var offsetsCount = 0;
  19533. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19534. segment = segments[segIndex];
  19535. var rangeOffset = font.getUint16();
  19536. if (!rangeOffset) {
  19537. segment.offsetIndex = -1;
  19538. continue;
  19539. }
  19540. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  19541. segment.offsetIndex = offsetIndex;
  19542. offsetsCount = Math.max(offsetsCount, offsetIndex +
  19543. segment.end - segment.start + 1);
  19544. }
  19545. var offsets = [];
  19546. for (j = 0; j < offsetsCount; j++) {
  19547. offsets.push(font.getUint16());
  19548. }
  19549. for (segIndex = 0; segIndex < segCount; segIndex++) {
  19550. segment = segments[segIndex];
  19551. start = segment.start;
  19552. var end = segment.end;
  19553. var delta = segment.delta;
  19554. offsetIndex = segment.offsetIndex;
  19555. for (j = start; j <= end; j++) {
  19556. if (j === 0xFFFF) {
  19557. continue;
  19558. }
  19559. glyphId = (offsetIndex < 0 ?
  19560. j : offsets[offsetIndex + j - start]);
  19561. glyphId = (glyphId + delta) & 0xFFFF;
  19562. if (glyphId === 0) {
  19563. continue;
  19564. }
  19565. mappings.push({
  19566. charCode: j,
  19567. glyphId: glyphId
  19568. });
  19569. }
  19570. }
  19571. } else if (format === 6) {
  19572. // Format 6 is a 2-bytes dense mapping, which means the font data
  19573. // lives glue together even if they are pretty far in the unicode
  19574. // table. (This looks weird, so I can have missed something), this
  19575. // works on Linux but seems to fails on Mac so let's rewrite the
  19576. // cmap table to a 3-1-4 style
  19577. var firstCode = font.getUint16();
  19578. var entryCount = font.getUint16();
  19579. for (j = 0; j < entryCount; j++) {
  19580. glyphId = font.getUint16();
  19581. var charCode = firstCode + j;
  19582. mappings.push({
  19583. charCode: charCode,
  19584. glyphId: glyphId
  19585. });
  19586. }
  19587. } else {
  19588. error('cmap table has unsupported format: ' + format);
  19589. }
  19590. // removing duplicate entries
  19591. mappings.sort(function (a, b) {
  19592. return a.charCode - b.charCode;
  19593. });
  19594. for (i = 1; i < mappings.length; i++) {
  19595. if (mappings[i - 1].charCode === mappings[i].charCode) {
  19596. mappings.splice(i, 1);
  19597. i--;
  19598. }
  19599. }
  19600. return {
  19601. platformId: potentialTable.platformId,
  19602. encodingId: potentialTable.encodingId,
  19603. mappings: mappings,
  19604. hasShortCmap: hasShortCmap
  19605. };
  19606. }
  19607. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  19608. if (!header) {
  19609. if (metrics) {
  19610. metrics.data = null;
  19611. }
  19612. return;
  19613. }
  19614. font.pos = (font.start ? font.start : 0) + header.offset;
  19615. font.pos += header.length - 2;
  19616. var numOfMetrics = font.getUint16();
  19617. if (numOfMetrics > numGlyphs) {
  19618. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  19619. 'greater than the numGlyphs (' + numGlyphs + ')');
  19620. // Reduce numOfMetrics if it is greater than numGlyphs
  19621. numOfMetrics = numGlyphs;
  19622. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  19623. header.data[35] = numOfMetrics & 0x00ff;
  19624. }
  19625. var numOfSidebearings = numGlyphs - numOfMetrics;
  19626. var numMissing = numOfSidebearings -
  19627. ((metrics.length - numOfMetrics * 4) >> 1);
  19628. var i, ii;
  19629. if (numMissing > 0) {
  19630. font.pos = (font.start ? font.start : 0) + metrics.offset;
  19631. var entries = '';
  19632. for (i = 0, ii = metrics.length; i < ii; i++) {
  19633. entries += String.fromCharCode(font.getByte());
  19634. }
  19635. for (i = 0; i < numMissing; i++) {
  19636. entries += '\x00\x00';
  19637. }
  19638. metrics.data = stringToArray(entries);
  19639. }
  19640. }
  19641. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  19642. hintsValid) {
  19643. if (sourceEnd - sourceStart <= 12) {
  19644. // glyph with data less than 12 is invalid one
  19645. return 0;
  19646. }
  19647. var glyf = source.subarray(sourceStart, sourceEnd);
  19648. var contoursCount = (glyf[0] << 8) | glyf[1];
  19649. if (contoursCount & 0x8000) {
  19650. // complex glyph, writing as is
  19651. dest.set(glyf, destStart);
  19652. return glyf.length;
  19653. }
  19654. var i, j = 10, flagsCount = 0;
  19655. for (i = 0; i < contoursCount; i++) {
  19656. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  19657. flagsCount = endPoint + 1;
  19658. j += 2;
  19659. }
  19660. // skipping instructions
  19661. var instructionsStart = j;
  19662. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  19663. j += 2 + instructionsLength;
  19664. var instructionsEnd = j;
  19665. // validating flags
  19666. var coordinatesLength = 0;
  19667. for (i = 0; i < flagsCount; i++) {
  19668. var flag = glyf[j++];
  19669. if (flag & 0xC0) {
  19670. // reserved flags must be zero, cleaning up
  19671. glyf[j - 1] = flag & 0x3F;
  19672. }
  19673. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  19674. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  19675. coordinatesLength += xyLength;
  19676. if (flag & 8) {
  19677. var repeat = glyf[j++];
  19678. i += repeat;
  19679. coordinatesLength += repeat * xyLength;
  19680. }
  19681. }
  19682. // glyph without coordinates will be rejected
  19683. if (coordinatesLength === 0) {
  19684. return 0;
  19685. }
  19686. var glyphDataLength = j + coordinatesLength;
  19687. if (glyphDataLength > glyf.length) {
  19688. // not enough data for coordinates
  19689. return 0;
  19690. }
  19691. if (!hintsValid && instructionsLength > 0) {
  19692. dest.set(glyf.subarray(0, instructionsStart), destStart);
  19693. dest.set([0, 0], destStart + instructionsStart);
  19694. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  19695. destStart + instructionsStart + 2);
  19696. glyphDataLength -= instructionsLength;
  19697. if (glyf.length - glyphDataLength > 3) {
  19698. glyphDataLength = (glyphDataLength + 3) & ~3;
  19699. }
  19700. return glyphDataLength;
  19701. }
  19702. if (glyf.length - glyphDataLength > 3) {
  19703. // truncating and aligning to 4 bytes the long glyph data
  19704. glyphDataLength = (glyphDataLength + 3) & ~3;
  19705. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  19706. return glyphDataLength;
  19707. }
  19708. // glyph data is fine
  19709. dest.set(glyf, destStart);
  19710. return glyf.length;
  19711. }
  19712. function sanitizeHead(head, numGlyphs, locaLength) {
  19713. var data = head.data;
  19714. // Validate version:
  19715. // Should always be 0x00010000
  19716. var version = int32(data[0], data[1], data[2], data[3]);
  19717. if (version >> 16 !== 1) {
  19718. info('Attempting to fix invalid version in head table: ' + version);
  19719. data[0] = 0;
  19720. data[1] = 1;
  19721. data[2] = 0;
  19722. data[3] = 0;
  19723. }
  19724. var indexToLocFormat = int16(data[50], data[51]);
  19725. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  19726. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  19727. indexToLocFormat);
  19728. // The value of indexToLocFormat should be 0 if the loca table
  19729. // consists of short offsets, and should be 1 if the loca table
  19730. // consists of long offsets.
  19731. //
  19732. // The number of entries in the loca table should be numGlyphs + 1.
  19733. //
  19734. // Using this information, we can work backwards to deduce if the
  19735. // size of each offset in the loca table, and thus figure out the
  19736. // appropriate value for indexToLocFormat.
  19737. var numGlyphsPlusOne = numGlyphs + 1;
  19738. if (locaLength === numGlyphsPlusOne << 1) {
  19739. // 0x0000 indicates the loca table consists of short offsets
  19740. data[50] = 0;
  19741. data[51] = 0;
  19742. } else if (locaLength === numGlyphsPlusOne << 2) {
  19743. // 0x0001 indicates the loca table consists of long offsets
  19744. data[50] = 0;
  19745. data[51] = 1;
  19746. } else {
  19747. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  19748. }
  19749. }
  19750. }
  19751. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  19752. isGlyphLocationsLong, hintsValid,
  19753. dupFirstEntry) {
  19754. var itemSize, itemDecode, itemEncode;
  19755. if (isGlyphLocationsLong) {
  19756. itemSize = 4;
  19757. itemDecode = function fontItemDecodeLong(data, offset) {
  19758. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19759. (data[offset + 2] << 8) | data[offset + 3];
  19760. };
  19761. itemEncode = function fontItemEncodeLong(data, offset, value) {
  19762. data[offset] = (value >>> 24) & 0xFF;
  19763. data[offset + 1] = (value >> 16) & 0xFF;
  19764. data[offset + 2] = (value >> 8) & 0xFF;
  19765. data[offset + 3] = value & 0xFF;
  19766. };
  19767. } else {
  19768. itemSize = 2;
  19769. itemDecode = function fontItemDecode(data, offset) {
  19770. return (data[offset] << 9) | (data[offset + 1] << 1);
  19771. };
  19772. itemEncode = function fontItemEncode(data, offset, value) {
  19773. data[offset] = (value >> 9) & 0xFF;
  19774. data[offset + 1] = (value >> 1) & 0xFF;
  19775. };
  19776. }
  19777. var locaData = loca.data;
  19778. var locaDataSize = itemSize * (1 + numGlyphs);
  19779. // is loca.data too short or long?
  19780. if (locaData.length !== locaDataSize) {
  19781. locaData = new Uint8Array(locaDataSize);
  19782. locaData.set(loca.data.subarray(0, locaDataSize));
  19783. loca.data = locaData;
  19784. }
  19785. // removing the invalid glyphs
  19786. var oldGlyfData = glyf.data;
  19787. var oldGlyfDataLength = oldGlyfData.length;
  19788. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  19789. var startOffset = itemDecode(locaData, 0);
  19790. var writeOffset = 0;
  19791. itemEncode(locaData, 0, writeOffset);
  19792. var i, j;
  19793. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  19794. var endOffset = itemDecode(locaData, j);
  19795. if (endOffset > oldGlyfDataLength &&
  19796. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  19797. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  19798. // the glyf table size, which makes last glyph out of range.
  19799. endOffset = oldGlyfDataLength;
  19800. }
  19801. if (endOffset > oldGlyfDataLength) {
  19802. // glyph end offset points outside glyf data, rejecting the glyph
  19803. itemEncode(locaData, j, writeOffset);
  19804. startOffset = endOffset;
  19805. continue;
  19806. }
  19807. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  19808. newGlyfData, writeOffset, hintsValid);
  19809. writeOffset += newLength;
  19810. itemEncode(locaData, j, writeOffset);
  19811. startOffset = endOffset;
  19812. }
  19813. if (writeOffset === 0) {
  19814. // glyf table cannot be empty -- redoing the glyf and loca tables
  19815. // to have single glyph with one point
  19816. var simpleGlyph = new Uint8Array(
  19817. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  19818. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  19819. itemEncode(locaData, j, simpleGlyph.length);
  19820. }
  19821. glyf.data = simpleGlyph;
  19822. return;
  19823. }
  19824. if (dupFirstEntry) {
  19825. var firstEntryLength = itemDecode(locaData, itemSize);
  19826. if (newGlyfData.length > firstEntryLength + writeOffset) {
  19827. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  19828. } else {
  19829. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  19830. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  19831. }
  19832. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  19833. itemEncode(loca.data, locaData.length - itemSize,
  19834. writeOffset + firstEntryLength);
  19835. } else {
  19836. glyf.data = newGlyfData.subarray(0, writeOffset);
  19837. }
  19838. }
  19839. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  19840. var start = (font.start ? font.start : 0) + post.offset;
  19841. font.pos = start;
  19842. var length = post.length, end = start + length;
  19843. var version = font.getInt32();
  19844. // skip rest to the tables
  19845. font.getBytes(28);
  19846. var glyphNames;
  19847. var valid = true;
  19848. var i;
  19849. switch (version) {
  19850. case 0x00010000:
  19851. glyphNames = MacStandardGlyphOrdering;
  19852. break;
  19853. case 0x00020000:
  19854. var numGlyphs = font.getUint16();
  19855. if (numGlyphs !== maxpNumGlyphs) {
  19856. valid = false;
  19857. break;
  19858. }
  19859. var glyphNameIndexes = [];
  19860. for (i = 0; i < numGlyphs; ++i) {
  19861. var index = font.getUint16();
  19862. if (index >= 32768) {
  19863. valid = false;
  19864. break;
  19865. }
  19866. glyphNameIndexes.push(index);
  19867. }
  19868. if (!valid) {
  19869. break;
  19870. }
  19871. var customNames = [];
  19872. var strBuf = [];
  19873. while (font.pos < end) {
  19874. var stringLength = font.getByte();
  19875. strBuf.length = stringLength;
  19876. for (i = 0; i < stringLength; ++i) {
  19877. strBuf[i] = String.fromCharCode(font.getByte());
  19878. }
  19879. customNames.push(strBuf.join(''));
  19880. }
  19881. glyphNames = [];
  19882. for (i = 0; i < numGlyphs; ++i) {
  19883. var j = glyphNameIndexes[i];
  19884. if (j < 258) {
  19885. glyphNames.push(MacStandardGlyphOrdering[j]);
  19886. continue;
  19887. }
  19888. glyphNames.push(customNames[j - 258]);
  19889. }
  19890. break;
  19891. case 0x00030000:
  19892. break;
  19893. default:
  19894. warn('Unknown/unsupported post table version ' + version);
  19895. valid = false;
  19896. break;
  19897. }
  19898. properties.glyphNames = glyphNames;
  19899. return valid;
  19900. }
  19901. function readNameTable(nameTable) {
  19902. var start = (font.start ? font.start : 0) + nameTable.offset;
  19903. font.pos = start;
  19904. var names = [[], []];
  19905. var length = nameTable.length, end = start + length;
  19906. var format = font.getUint16();
  19907. var FORMAT_0_HEADER_LENGTH = 6;
  19908. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  19909. // unsupported name table format or table "too" small
  19910. return names;
  19911. }
  19912. var numRecords = font.getUint16();
  19913. var stringsStart = font.getUint16();
  19914. var records = [];
  19915. var NAME_RECORD_LENGTH = 12;
  19916. var i, ii;
  19917. for (i = 0; i < numRecords &&
  19918. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  19919. var r = {
  19920. platform: font.getUint16(),
  19921. encoding: font.getUint16(),
  19922. language: font.getUint16(),
  19923. name: font.getUint16(),
  19924. length: font.getUint16(),
  19925. offset: font.getUint16()
  19926. };
  19927. // using only Macintosh and Windows platform/encoding names
  19928. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  19929. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  19930. records.push(r);
  19931. }
  19932. }
  19933. for (i = 0, ii = records.length; i < ii; i++) {
  19934. var record = records[i];
  19935. var pos = start + stringsStart + record.offset;
  19936. if (pos + record.length > end) {
  19937. continue; // outside of name table, ignoring
  19938. }
  19939. font.pos = pos;
  19940. var nameIndex = record.name;
  19941. if (record.encoding) {
  19942. // unicode
  19943. var str = '';
  19944. for (var j = 0, jj = record.length; j < jj; j += 2) {
  19945. str += String.fromCharCode(font.getUint16());
  19946. }
  19947. names[1][nameIndex] = str;
  19948. } else {
  19949. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  19950. }
  19951. }
  19952. return names;
  19953. }
  19954. var TTOpsStackDeltas = [
  19955. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  19956. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  19957. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  19958. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  19959. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  19960. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  19961. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  19962. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  19963. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  19964. // 0xC0-DF == -1 and 0xE0-FF == -2
  19965. function sanitizeTTProgram(table, ttContext) {
  19966. var data = table.data;
  19967. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  19968. var stack = [];
  19969. var callstack = [];
  19970. var functionsCalled = [];
  19971. var tooComplexToFollowFunctions =
  19972. ttContext.tooComplexToFollowFunctions;
  19973. var inFDEF = false, ifLevel = 0, inELSE = 0;
  19974. for (var ii = data.length; i < ii;) {
  19975. var op = data[i++];
  19976. // The TrueType instruction set docs can be found at
  19977. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  19978. if (op === 0x40) { // NPUSHB - pushes n bytes
  19979. n = data[i++];
  19980. if (inFDEF || inELSE) {
  19981. i += n;
  19982. } else {
  19983. for (j = 0; j < n; j++) {
  19984. stack.push(data[i++]);
  19985. }
  19986. }
  19987. } else if (op === 0x41) { // NPUSHW - pushes n words
  19988. n = data[i++];
  19989. if (inFDEF || inELSE) {
  19990. i += n * 2;
  19991. } else {
  19992. for (j = 0; j < n; j++) {
  19993. b = data[i++];
  19994. stack.push((b << 8) | data[i++]);
  19995. }
  19996. }
  19997. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  19998. n = op - 0xB0 + 1;
  19999. if (inFDEF || inELSE) {
  20000. i += n;
  20001. } else {
  20002. for (j = 0; j < n; j++) {
  20003. stack.push(data[i++]);
  20004. }
  20005. }
  20006. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  20007. n = op - 0xB8 + 1;
  20008. if (inFDEF || inELSE) {
  20009. i += n * 2;
  20010. } else {
  20011. for (j = 0; j < n; j++) {
  20012. b = data[i++];
  20013. stack.push((b << 8) | data[i++]);
  20014. }
  20015. }
  20016. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  20017. if (!inFDEF && !inELSE) {
  20018. // collecting inforamtion about which functions are used
  20019. funcId = stack[stack.length - 1];
  20020. ttContext.functionsUsed[funcId] = true;
  20021. if (funcId in ttContext.functionsStackDeltas) {
  20022. stack.length += ttContext.functionsStackDeltas[funcId];
  20023. } else if (funcId in ttContext.functionsDefined &&
  20024. functionsCalled.indexOf(funcId) < 0) {
  20025. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  20026. functionsCalled.push(funcId);
  20027. pc = ttContext.functionsDefined[funcId];
  20028. if (!pc) {
  20029. warn('TT: CALL non-existent function');
  20030. ttContext.hintsValid = false;
  20031. return;
  20032. }
  20033. data = pc.data;
  20034. i = pc.i;
  20035. }
  20036. }
  20037. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  20038. if (inFDEF || inELSE) {
  20039. warn('TT: nested FDEFs not allowed');
  20040. tooComplexToFollowFunctions = true;
  20041. }
  20042. inFDEF = true;
  20043. // collecting inforamtion about which functions are defined
  20044. lastDeff = i;
  20045. funcId = stack.pop();
  20046. ttContext.functionsDefined[funcId] = {data: data, i: i};
  20047. } else if (op === 0x2D) { // ENDF - end of function
  20048. if (inFDEF) {
  20049. inFDEF = false;
  20050. lastEndf = i;
  20051. } else {
  20052. pc = callstack.pop();
  20053. if (!pc) {
  20054. warn('TT: ENDF bad stack');
  20055. ttContext.hintsValid = false;
  20056. return;
  20057. }
  20058. funcId = functionsCalled.pop();
  20059. data = pc.data;
  20060. i = pc.i;
  20061. ttContext.functionsStackDeltas[funcId] =
  20062. stack.length - pc.stackTop;
  20063. }
  20064. } else if (op === 0x89) { // IDEF - instruction definition
  20065. if (inFDEF || inELSE) {
  20066. warn('TT: nested IDEFs not allowed');
  20067. tooComplexToFollowFunctions = true;
  20068. }
  20069. inFDEF = true;
  20070. // recording it as a function to track ENDF
  20071. lastDeff = i;
  20072. } else if (op === 0x58) { // IF
  20073. ++ifLevel;
  20074. } else if (op === 0x1B) { // ELSE
  20075. inELSE = ifLevel;
  20076. } else if (op === 0x59) { // EIF
  20077. if (inELSE === ifLevel) {
  20078. inELSE = 0;
  20079. }
  20080. --ifLevel;
  20081. } else if (op === 0x1C) { // JMPR
  20082. if (!inFDEF && !inELSE) {
  20083. var offset = stack[stack.length - 1];
  20084. // only jumping forward to prevent infinite loop
  20085. if (offset > 0) {
  20086. i += offset - 1;
  20087. }
  20088. }
  20089. }
  20090. // Adjusting stack not extactly, but just enough to get function id
  20091. if (!inFDEF && !inELSE) {
  20092. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  20093. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  20094. if (op >= 0x71 && op <= 0x75) {
  20095. n = stack.pop();
  20096. if (n === n) {
  20097. stackDelta = -n * 2;
  20098. }
  20099. }
  20100. while (stackDelta < 0 && stack.length > 0) {
  20101. stack.pop();
  20102. stackDelta++;
  20103. }
  20104. while (stackDelta > 0) {
  20105. stack.push(NaN); // pushing any number into stack
  20106. stackDelta--;
  20107. }
  20108. }
  20109. }
  20110. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  20111. var content = [data];
  20112. if (i > data.length) {
  20113. content.push(new Uint8Array(i - data.length));
  20114. }
  20115. if (lastDeff > lastEndf) {
  20116. warn('TT: complementing a missing function tail');
  20117. // new function definition started, but not finished
  20118. // complete function by [CLEAR, ENDF]
  20119. content.push(new Uint8Array([0x22, 0x2D]));
  20120. }
  20121. foldTTTable(table, content);
  20122. }
  20123. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  20124. if (ttContext.tooComplexToFollowFunctions) {
  20125. return;
  20126. }
  20127. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  20128. warn('TT: more functions defined than expected');
  20129. ttContext.hintsValid = false;
  20130. return;
  20131. }
  20132. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  20133. if (j > maxFunctionDefs) {
  20134. warn('TT: invalid function id: ' + j);
  20135. ttContext.hintsValid = false;
  20136. return;
  20137. }
  20138. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  20139. warn('TT: undefined function: ' + j);
  20140. ttContext.hintsValid = false;
  20141. return;
  20142. }
  20143. }
  20144. }
  20145. function foldTTTable(table, content) {
  20146. if (content.length > 1) {
  20147. // concatenating the content items
  20148. var newLength = 0;
  20149. var j, jj;
  20150. for (j = 0, jj = content.length; j < jj; j++) {
  20151. newLength += content[j].length;
  20152. }
  20153. newLength = (newLength + 3) & ~3;
  20154. var result = new Uint8Array(newLength);
  20155. var pos = 0;
  20156. for (j = 0, jj = content.length; j < jj; j++) {
  20157. result.set(content[j], pos);
  20158. pos += content[j].length;
  20159. }
  20160. table.data = result;
  20161. table.length = newLength;
  20162. }
  20163. }
  20164. function sanitizeTTPrograms(fpgm, prep, cvt) {
  20165. var ttContext = {
  20166. functionsDefined: [],
  20167. functionsUsed: [],
  20168. functionsStackDeltas: [],
  20169. tooComplexToFollowFunctions: false,
  20170. hintsValid: true
  20171. };
  20172. if (fpgm) {
  20173. sanitizeTTProgram(fpgm, ttContext);
  20174. }
  20175. if (prep) {
  20176. sanitizeTTProgram(prep, ttContext);
  20177. }
  20178. if (fpgm) {
  20179. checkInvalidFunctions(ttContext, maxFunctionDefs);
  20180. }
  20181. if (cvt && (cvt.length & 1)) {
  20182. var cvtData = new Uint8Array(cvt.length + 1);
  20183. cvtData.set(cvt.data);
  20184. cvt.data = cvtData;
  20185. }
  20186. return ttContext.hintsValid;
  20187. }
  20188. // The following steps modify the original font data, making copy
  20189. font = new Stream(new Uint8Array(font.getBytes()));
  20190. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  20191. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  20192. var header = readOpenTypeHeader(font);
  20193. var numTables = header.numTables;
  20194. var cff, cffFile;
  20195. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  20196. hmtx: null, maxp: null, name: null, post: null };
  20197. var table, tableData;
  20198. for (var i = 0; i < numTables; i++) {
  20199. table = readTableEntry(font);
  20200. if (VALID_TABLES.indexOf(table.tag) < 0) {
  20201. continue; // skipping table if it's not a required or optional table
  20202. }
  20203. if (table.length === 0) {
  20204. continue; // skipping empty tables
  20205. }
  20206. tables[table.tag] = table;
  20207. }
  20208. var isTrueType = !tables['CFF '];
  20209. if (!isTrueType) {
  20210. // OpenType font
  20211. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  20212. // no major tables: throwing everything at CFFFont
  20213. cffFile = new Stream(tables['CFF '].data);
  20214. cff = new CFFFont(cffFile, properties);
  20215. return this.convert(name, cff, properties);
  20216. }
  20217. delete tables.glyf;
  20218. delete tables.loca;
  20219. delete tables.fpgm;
  20220. delete tables.prep;
  20221. delete tables['cvt '];
  20222. this.isOpenType = true;
  20223. } else {
  20224. if (!tables.glyf || !tables.loca) {
  20225. error('Required "glyf" or "loca" tables are not found');
  20226. }
  20227. this.isOpenType = false;
  20228. }
  20229. if (!tables.maxp) {
  20230. error('Required "maxp" table is not found');
  20231. }
  20232. font.pos = (font.start || 0) + tables.maxp.offset;
  20233. var version = font.getInt32();
  20234. var numGlyphs = font.getUint16();
  20235. var maxFunctionDefs = 0;
  20236. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  20237. // maxZones can be invalid
  20238. font.pos += 8;
  20239. var maxZones = font.getUint16();
  20240. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  20241. tables.maxp.data[14] = 0;
  20242. tables.maxp.data[15] = 2;
  20243. }
  20244. font.pos += 4;
  20245. maxFunctionDefs = font.getUint16();
  20246. }
  20247. var dupFirstEntry = false;
  20248. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  20249. properties.toUnicode[0] > '\u0000') {
  20250. // oracle's defect (see 3427), duplicating first entry
  20251. dupFirstEntry = true;
  20252. numGlyphs++;
  20253. tables.maxp.data[4] = numGlyphs >> 8;
  20254. tables.maxp.data[5] = numGlyphs & 255;
  20255. }
  20256. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  20257. tables['cvt '], maxFunctionDefs);
  20258. if (!hintsValid) {
  20259. delete tables.fpgm;
  20260. delete tables.prep;
  20261. delete tables['cvt '];
  20262. }
  20263. // Tables needs to be written by ascendant alphabetic order
  20264. var tablesNames = Object.keys(tables);
  20265. tablesNames.sort();
  20266. numTables = tablesNames.length;
  20267. // header and new offsets. Table entry information is appended to the
  20268. // end of file. The virtualOffset represents where to put the actual
  20269. // data of a particular table;
  20270. var ttf = {
  20271. file: '',
  20272. virtualOffset: numTables * (4 * 4)
  20273. };
  20274. // The new numbers of tables will be the last one plus the num
  20275. // of missing tables
  20276. createOpenTypeHeader(header.version, ttf, numTables);
  20277. // Ensure the hmtx table contains the advance width and
  20278. // sidebearings information for numGlyphs in the maxp table
  20279. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  20280. if (!tables.head) {
  20281. error('Required "head" table is not found');
  20282. }
  20283. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  20284. if (isTrueType) {
  20285. var isGlyphLocationsLong = int16(tables.head.data[50],
  20286. tables.head.data[51]);
  20287. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  20288. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  20289. }
  20290. if (!tables.hhea) {
  20291. error('Required "hhea" table is not found');
  20292. }
  20293. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  20294. // Sometimes it's 0. That needs to be fixed
  20295. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  20296. tables.hhea.data[10] = 0xFF;
  20297. tables.hhea.data[11] = 0xFF;
  20298. }
  20299. // The 'post' table has glyphs names.
  20300. if (tables.post) {
  20301. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  20302. if (!valid) {
  20303. tables.post = null;
  20304. }
  20305. }
  20306. var charCodeToGlyphId = [], charCode;
  20307. if (properties.type === 'CIDFontType2') {
  20308. var cidToGidMap = properties.cidToGidMap || [];
  20309. var cidToGidMapLength = cidToGidMap.length;
  20310. properties.cMap.forEach(function(charCode, cid) {
  20311. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  20312. var glyphId = -1;
  20313. if (cidToGidMapLength === 0) {
  20314. glyphId = charCode;
  20315. } else if (cidToGidMap[cid] !== undefined) {
  20316. glyphId = cidToGidMap[cid];
  20317. }
  20318. if (glyphId >= 0 && glyphId < numGlyphs) {
  20319. charCodeToGlyphId[charCode] = glyphId;
  20320. }
  20321. });
  20322. if (dupFirstEntry) {
  20323. charCodeToGlyphId[0] = numGlyphs - 1;
  20324. }
  20325. } else {
  20326. // Most of the following logic in this code branch is based on the
  20327. // 9.6.6.4 of the PDF spec.
  20328. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  20329. var cmapPlatformId = cmapTable.platformId;
  20330. var cmapEncodingId = cmapTable.encodingId;
  20331. var cmapMappings = cmapTable.mappings;
  20332. var cmapMappingsLength = cmapMappings.length;
  20333. var hasEncoding = properties.differences.length ||
  20334. !!properties.baseEncodingName;
  20335. // The spec seems to imply that if the font is symbolic the encoding
  20336. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  20337. // where the the font is symbolic and it has an encoding.
  20338. if (hasEncoding &&
  20339. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  20340. cmapPlatformId === 1 && cmapEncodingId === 0)) {
  20341. var baseEncoding = [];
  20342. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  20343. properties.baseEncodingName === 'WinAnsiEncoding') {
  20344. baseEncoding = Encodings[properties.baseEncodingName];
  20345. }
  20346. for (charCode = 0; charCode < 256; charCode++) {
  20347. var glyphName;
  20348. if (this.differences && charCode in this.differences) {
  20349. glyphName = this.differences[charCode];
  20350. } else if (charCode in baseEncoding &&
  20351. baseEncoding[charCode] !== '') {
  20352. glyphName = baseEncoding[charCode];
  20353. } else {
  20354. glyphName = Encodings.StandardEncoding[charCode];
  20355. }
  20356. if (!glyphName) {
  20357. continue;
  20358. }
  20359. var unicodeOrCharCode;
  20360. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  20361. unicodeOrCharCode = GlyphsUnicode[glyphName];
  20362. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  20363. // TODO: the encoding needs to be updated with mac os table.
  20364. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  20365. }
  20366. var found = false;
  20367. for (i = 0; i < cmapMappingsLength; ++i) {
  20368. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  20369. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  20370. found = true;
  20371. break;
  20372. }
  20373. }
  20374. if (!found && properties.glyphNames) {
  20375. // Try to map using the post table. There are currently no known
  20376. // pdfs that this fixes.
  20377. var glyphId = properties.glyphNames.indexOf(glyphName);
  20378. if (glyphId > 0) {
  20379. charCodeToGlyphId[charCode] = glyphId;
  20380. }
  20381. }
  20382. }
  20383. } else {
  20384. // For (3, 0) cmap tables:
  20385. // The charcode key being stored in charCodeToGlyphId is the lower
  20386. // byte of the two-byte charcodes of the cmap table since according to
  20387. // the spec: 'each byte from the string shall be prepended with the
  20388. // high byte of the range [of charcodes in the cmap table], to form
  20389. // a two-byte character, which shall be used to select the
  20390. // associated glyph description from the subtable'.
  20391. //
  20392. // For (1, 0) cmap tables:
  20393. // 'single bytes from the string shall be used to look up the
  20394. // associated glyph descriptions from the subtable'. This means
  20395. // charcodes in the cmap will be single bytes, so no-op since
  20396. // glyph.charCode & 0xFF === glyph.charCode
  20397. for (i = 0; i < cmapMappingsLength; ++i) {
  20398. charCode = cmapMappings[i].charCode & 0xFF;
  20399. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  20400. }
  20401. }
  20402. }
  20403. if (charCodeToGlyphId.length === 0) {
  20404. // defines at least one glyph
  20405. charCodeToGlyphId[0] = 0;
  20406. }
  20407. // Converting glyphs and ids into font's cmap table
  20408. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  20409. this.toFontChar = newMapping.toFontChar;
  20410. tables.cmap = {
  20411. tag: 'cmap',
  20412. data: createCmapTable(newMapping.charCodeToGlyphId)
  20413. };
  20414. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  20415. // extract some more font properties from the OpenType head and
  20416. // hhea tables; yMin and descent value are always negative
  20417. var override = {
  20418. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  20419. yMax: int16(tables.head.data[42], tables.head.data[43]),
  20420. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  20421. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  20422. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  20423. };
  20424. tables['OS/2'] = {
  20425. tag: 'OS/2',
  20426. data: stringToArray(createOS2Table(properties,
  20427. newMapping.charCodeToGlyphId,
  20428. override))
  20429. };
  20430. }
  20431. // Rewrite the 'post' table if needed
  20432. if (!tables.post) {
  20433. tables.post = {
  20434. tag: 'post',
  20435. data: stringToArray(createPostTable(properties))
  20436. };
  20437. }
  20438. if (!isTrueType) {
  20439. try {
  20440. // Trying to repair CFF file
  20441. cffFile = new Stream(tables['CFF '].data);
  20442. var parser = new CFFParser(cffFile, properties);
  20443. cff = parser.parse();
  20444. var compiler = new CFFCompiler(cff);
  20445. tables['CFF '].data = compiler.compile();
  20446. } catch (e) {
  20447. warn('Failed to compile font ' + properties.loadedName);
  20448. }
  20449. }
  20450. // Re-creating 'name' table
  20451. if (!tables.name) {
  20452. tables.name = {
  20453. tag: 'name',
  20454. data: stringToArray(createNameTable(this.name))
  20455. };
  20456. } else {
  20457. // ... using existing 'name' table as prototype
  20458. var namePrototype = readNameTable(tables.name);
  20459. tables.name.data = stringToArray(createNameTable(name, namePrototype));
  20460. }
  20461. // rewrite the tables but tweak offsets
  20462. for (i = 0; i < numTables; i++) {
  20463. table = tables[tablesNames[i]];
  20464. table.data = createTableEntry(ttf, table.tag, table.data);
  20465. }
  20466. // Add the table datas
  20467. for (i = 0; i < numTables; i++) {
  20468. table = tables[tablesNames[i]];
  20469. tableData = table.data;
  20470. ttf.file += bytesToString(new Uint8Array(tableData));
  20471. // 4-byte aligned data
  20472. while (ttf.file.length & 3) {
  20473. ttf.file += String.fromCharCode(0);
  20474. }
  20475. }
  20476. return stringToArray(ttf.file);
  20477. },
  20478. convert: function Font_convert(fontName, font, properties) {
  20479. // The offsets object holds at the same time a representation of where
  20480. // to write the table entry information about a table and another offset
  20481. // representing the offset where to draw the actual data of a particular
  20482. // table
  20483. var otf = {
  20484. file: '',
  20485. virtualOffset: 9 * (4 * 4)
  20486. };
  20487. createOpenTypeHeader('\x4F\x54\x54\x4F', otf, 9);
  20488. // TODO: Check the charstring widths to determine this.
  20489. properties.fixedPitch = false;
  20490. var mapping = font.getGlyphMapping(properties);
  20491. var newMapping = adjustMapping(mapping, properties);
  20492. this.toFontChar = newMapping.toFontChar;
  20493. var numGlyphs = font.numGlyphs;
  20494. function getCharCodes(charCodeToGlyphId, glyphId) {
  20495. var charCodes = null;
  20496. for (var charCode in charCodeToGlyphId) {
  20497. if (glyphId === charCodeToGlyphId[charCode]) {
  20498. if (!charCodes) {
  20499. charCodes = [];
  20500. }
  20501. charCodes.push(charCode | 0);
  20502. }
  20503. }
  20504. return charCodes;
  20505. }
  20506. function createCharCode(charCodeToGlyphId, glyphId) {
  20507. for (var charCode in charCodeToGlyphId) {
  20508. if (glyphId === charCodeToGlyphId[charCode]) {
  20509. return charCode | 0;
  20510. }
  20511. }
  20512. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  20513. glyphId;
  20514. return newMapping.nextAvailableFontCharCode++;
  20515. }
  20516. var seacs = font.seacs;
  20517. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  20518. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  20519. var charset = font.getCharset();
  20520. var seacMap = Object.create(null);
  20521. for (var glyphId in seacs) {
  20522. glyphId |= 0;
  20523. var seac = seacs[glyphId];
  20524. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  20525. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  20526. var baseGlyphId = charset.indexOf(baseGlyphName);
  20527. var accentGlyphId = charset.indexOf(accentGlyphName);
  20528. if (baseGlyphId < 0 || accentGlyphId < 0) {
  20529. continue;
  20530. }
  20531. var accentOffset = {
  20532. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  20533. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  20534. };
  20535. var charCodes = getCharCodes(mapping, glyphId);
  20536. if (!charCodes) {
  20537. // There's no point in mapping it if the char code was never mapped
  20538. // to begin with.
  20539. continue;
  20540. }
  20541. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  20542. var charCode = charCodes[i];
  20543. // Find a fontCharCode that maps to the base and accent glyphs.
  20544. // If one doesn't exists, create it.
  20545. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  20546. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  20547. baseGlyphId);
  20548. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  20549. accentGlyphId);
  20550. seacMap[charCode] = {
  20551. baseFontCharCode: baseFontCharCode,
  20552. accentFontCharCode: accentFontCharCode,
  20553. accentOffset: accentOffset
  20554. };
  20555. }
  20556. }
  20557. properties.seacMap = seacMap;
  20558. }
  20559. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  20560. var fields = {
  20561. // PostScript Font Program
  20562. 'CFF ': font.data,
  20563. // OS/2 and Windows Specific metrics
  20564. 'OS/2': stringToArray(createOS2Table(properties,
  20565. newMapping.charCodeToGlyphId)),
  20566. // Character to glyphs mapping
  20567. 'cmap': createCmapTable(newMapping.charCodeToGlyphId),
  20568. // Font header
  20569. 'head': (function fontFieldsHead() {
  20570. return stringToArray(
  20571. '\x00\x01\x00\x00' + // Version number
  20572. '\x00\x00\x10\x00' + // fontRevision
  20573. '\x00\x00\x00\x00' + // checksumAdjustement
  20574. '\x5F\x0F\x3C\xF5' + // magicNumber
  20575. '\x00\x00' + // Flags
  20576. safeString16(unitsPerEm) + // unitsPerEM
  20577. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  20578. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  20579. '\x00\x00' + // xMin
  20580. safeString16(properties.descent) + // yMin
  20581. '\x0F\xFF' + // xMax
  20582. safeString16(properties.ascent) + // yMax
  20583. string16(properties.italicAngle ? 2 : 0) + // macStyle
  20584. '\x00\x11' + // lowestRecPPEM
  20585. '\x00\x00' + // fontDirectionHint
  20586. '\x00\x00' + // indexToLocFormat
  20587. '\x00\x00'); // glyphDataFormat
  20588. })(),
  20589. // Horizontal header
  20590. 'hhea': (function fontFieldsHhea() {
  20591. return stringToArray(
  20592. '\x00\x01\x00\x00' + // Version number
  20593. safeString16(properties.ascent) + // Typographic Ascent
  20594. safeString16(properties.descent) + // Typographic Descent
  20595. '\x00\x00' + // Line Gap
  20596. '\xFF\xFF' + // advanceWidthMax
  20597. '\x00\x00' + // minLeftSidebearing
  20598. '\x00\x00' + // minRightSidebearing
  20599. '\x00\x00' + // xMaxExtent
  20600. safeString16(properties.capHeight) + // caretSlopeRise
  20601. safeString16(Math.tan(properties.italicAngle) *
  20602. properties.xHeight) + // caretSlopeRun
  20603. '\x00\x00' + // caretOffset
  20604. '\x00\x00' + // -reserved-
  20605. '\x00\x00' + // -reserved-
  20606. '\x00\x00' + // -reserved-
  20607. '\x00\x00' + // -reserved-
  20608. '\x00\x00' + // metricDataFormat
  20609. string16(numGlyphs)); // Number of HMetrics
  20610. })(),
  20611. // Horizontal metrics
  20612. 'hmtx': (function fontFieldsHmtx() {
  20613. var charstrings = font.charstrings;
  20614. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  20615. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  20616. // TODO: For CFF fonts the width should technically match th x in
  20617. // the glyph, but it doesn't seem to matter.
  20618. var charstring = charstrings ? charstrings[i - 1] : {};
  20619. var width = 'width' in charstring ? charstring.width : 0;
  20620. hmtx += string16(width) + string16(0);
  20621. }
  20622. return stringToArray(hmtx);
  20623. })(),
  20624. // Maximum profile
  20625. 'maxp': (function fontFieldsMaxp() {
  20626. return stringToArray(
  20627. '\x00\x00\x50\x00' + // Version number
  20628. string16(numGlyphs)); // Num of glyphs
  20629. })(),
  20630. // Naming tables
  20631. 'name': stringToArray(createNameTable(fontName)),
  20632. // PostScript informations
  20633. 'post': stringToArray(createPostTable(properties))
  20634. };
  20635. var field;
  20636. for (field in fields) {
  20637. fields[field] = createTableEntry(otf, field, fields[field]);
  20638. }
  20639. for (field in fields) {
  20640. var table = fields[field];
  20641. otf.file += bytesToString(new Uint8Array(table));
  20642. }
  20643. return stringToArray(otf.file);
  20644. },
  20645. /**
  20646. * Builds a char code to unicode map based on section 9.10 of the spec.
  20647. * @param {Object} properties Font properties object.
  20648. * @return {Object} Has two properties: 'toUnicode' which maps char codes to
  20649. * unicode (string) values and 'isIdentity' which is true if an identity map
  20650. * is used.
  20651. */
  20652. buildToUnicode: function Font_buildToUnicode(properties) {
  20653. var map = {
  20654. isIdentity: false,
  20655. toUnicode: null
  20656. };
  20657. // Section 9.10.2 Mapping Character Codes to Unicode Values
  20658. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  20659. map.toUnicode = properties.toUnicode;
  20660. return map;
  20661. }
  20662. // According to the spec if the font is a simple font we should only map
  20663. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  20664. // the differences array only contains adobe standard or symbol set names,
  20665. // in pratice it seems better to always try to create a toUnicode
  20666. // map based of the default encoding.
  20667. var toUnicode, charcode;
  20668. if (!properties.composite /* is simple font */) {
  20669. toUnicode = [];
  20670. var encoding = properties.defaultEncoding.slice();
  20671. var baseEncodingName = properties.baseEncodingName;
  20672. // Merge in the differences array.
  20673. var differences = properties.differences;
  20674. for (charcode in differences) {
  20675. encoding[charcode] = differences[charcode];
  20676. }
  20677. for (charcode in encoding) {
  20678. // a) Map the character code to a character name.
  20679. var glyphName = encoding[charcode];
  20680. // b) Look up the character name in the Adobe Glyph List (see the
  20681. // Bibliography) to obtain the corresponding Unicode value.
  20682. if (glyphName === '') {
  20683. continue;
  20684. } else if (GlyphsUnicode[glyphName] === undefined) {
  20685. // (undocumented) c) Few heuristics to recognize unknown glyphs
  20686. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  20687. var code = 0;
  20688. switch (glyphName[0]) {
  20689. case 'G': // Gxx glyph
  20690. if (glyphName.length === 3) {
  20691. code = parseInt(glyphName.substr(1), 16);
  20692. }
  20693. break;
  20694. case 'g': // g00xx glyph
  20695. if (glyphName.length === 5) {
  20696. code = parseInt(glyphName.substr(1), 16);
  20697. }
  20698. break;
  20699. case 'C': // Cddd glyph
  20700. case 'c': // cddd glyph
  20701. if (glyphName.length >= 3) {
  20702. code = +glyphName.substr(1);
  20703. }
  20704. break;
  20705. }
  20706. if (code) {
  20707. // If |baseEncodingName| is one the predefined encodings,
  20708. // and |code| equals |charcode|, using the glyph defined in the
  20709. // baseEncoding seems to yield a better |toUnicode| mapping
  20710. // (fixes issue 5070).
  20711. if (baseEncodingName && code === +charcode) {
  20712. var baseEncoding = Encodings[baseEncodingName];
  20713. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  20714. toUnicode[charcode] =
  20715. String.fromCharCode(GlyphsUnicode[glyphName]);
  20716. continue;
  20717. }
  20718. }
  20719. toUnicode[charcode] = String.fromCharCode(code);
  20720. }
  20721. continue;
  20722. }
  20723. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  20724. }
  20725. map.toUnicode = toUnicode;
  20726. return map;
  20727. }
  20728. // If the font is a composite font that uses one of the predefined CMaps
  20729. // listed in Table 118 (except Identity–H and Identity–V) or whose
  20730. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  20731. // Adobe-Korea1 character collection:
  20732. if (properties.composite && (
  20733. (properties.cMap.builtInCMap &&
  20734. !(properties.cMap instanceof IdentityCMap)) ||
  20735. (properties.cidSystemInfo.registry === 'Adobe' &&
  20736. (properties.cidSystemInfo.ordering === 'GB1' ||
  20737. properties.cidSystemInfo.ordering === 'CNS1' ||
  20738. properties.cidSystemInfo.ordering === 'Japan1' ||
  20739. properties.cidSystemInfo.ordering === 'Korea1')))) {
  20740. // Then:
  20741. // a) Map the character code to a character identifier (CID) according
  20742. // to the font’s CMap.
  20743. // b) Obtain the registry and ordering of the character collection used
  20744. // by the font’s CMap (for example, Adobe and Japan1) from its
  20745. // CIDSystemInfo dictionary.
  20746. var registry = properties.cidSystemInfo.registry;
  20747. var ordering = properties.cidSystemInfo.ordering;
  20748. // c) Construct a second CMap name by concatenating the registry and
  20749. // ordering obtained in step (b) in the format registry–ordering–UCS2
  20750. // (for example, Adobe–Japan1–UCS2).
  20751. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  20752. // d) Obtain the CMap with the name constructed in step (c) (available
  20753. // from the ASN Web site; see the Bibliography).
  20754. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  20755. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  20756. var cMap = properties.cMap;
  20757. toUnicode = [];
  20758. cMap.forEach(function(charcode, cid) {
  20759. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  20760. // e) Map the CID obtained in step (a) according to the CMap obtained
  20761. // in step (d), producing a Unicode value.
  20762. var ucs2 = ucs2CMap.lookup(cid);
  20763. if (ucs2) {
  20764. toUnicode[charcode] =
  20765. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  20766. ucs2.charCodeAt(1));
  20767. }
  20768. });
  20769. map.toUnicode = toUnicode;
  20770. return map;
  20771. }
  20772. // The viewer's choice, just use an identity map.
  20773. toUnicode = [];
  20774. var firstChar = properties.firstChar, lastChar = properties.lastChar;
  20775. for (var i = firstChar; i <= lastChar; i++) {
  20776. toUnicode[i] = String.fromCharCode(i);
  20777. }
  20778. map.isIdentity = true;
  20779. map.toUnicode = toUnicode;
  20780. return map;
  20781. },
  20782. get spaceWidth() {
  20783. if ('_shadowWidth' in this) {
  20784. return this._shadowWidth;
  20785. }
  20786. // trying to estimate space character width
  20787. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  20788. var width;
  20789. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  20790. var glyphName = possibleSpaceReplacements[i];
  20791. // if possible, getting width by glyph name
  20792. if (glyphName in this.widths) {
  20793. width = this.widths[glyphName];
  20794. break;
  20795. }
  20796. var glyphUnicode = GlyphsUnicode[glyphName];
  20797. // finding the charcode via unicodeToCID map
  20798. var charcode = 0;
  20799. if (this.composite) {
  20800. if (this.cMap.contains(glyphUnicode)) {
  20801. charcode = this.cMap.lookup(glyphUnicode);
  20802. }
  20803. }
  20804. // ... via toUnicode map
  20805. if (!charcode && 'toUnicode' in this) {
  20806. charcode = this.toUnicode.indexOf(glyphUnicode);
  20807. }
  20808. // setting it to unicode if negative or undefined
  20809. if (charcode <= 0) {
  20810. charcode = glyphUnicode;
  20811. }
  20812. // trying to get width via charcode
  20813. width = this.widths[charcode];
  20814. if (width) {
  20815. break; // the non-zero width found
  20816. }
  20817. }
  20818. width = width || this.defaultWidth;
  20819. // Do not shadow the property here. See discussion:
  20820. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  20821. this._shadowWidth = width;
  20822. return width;
  20823. },
  20824. charToGlyph: function Font_charToGlyph(charcode) {
  20825. var fontCharCode, width, operatorListId;
  20826. var widthCode = charcode;
  20827. if (this.cMap && this.cMap.contains(charcode)) {
  20828. widthCode = this.cMap.lookup(charcode);
  20829. }
  20830. width = this.widths[widthCode];
  20831. width = isNum(width) ? width : this.defaultWidth;
  20832. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  20833. var unicode = this.toUnicode[charcode] || charcode;
  20834. if (typeof unicode === 'number') {
  20835. unicode = String.fromCharCode(unicode);
  20836. }
  20837. // First try the toFontChar map, if it's not there then try falling
  20838. // back to the char code.
  20839. fontCharCode = this.toFontChar[charcode] || charcode;
  20840. if (this.missingFile) {
  20841. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  20842. }
  20843. if (this.isType3Font) {
  20844. // Font char code in this case is actually a glyph name.
  20845. operatorListId = fontCharCode;
  20846. }
  20847. var accent = null;
  20848. if (this.seacMap && this.seacMap[charcode]) {
  20849. var seac = this.seacMap[charcode];
  20850. fontCharCode = seac.baseFontCharCode;
  20851. accent = {
  20852. fontChar: String.fromCharCode(seac.accentFontCharCode),
  20853. offset: seac.accentOffset
  20854. };
  20855. }
  20856. var fontChar = String.fromCharCode(fontCharCode);
  20857. var glyph = this.glyphCache[charcode];
  20858. if (!glyph ||
  20859. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  20860. operatorListId)) {
  20861. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  20862. operatorListId);
  20863. this.glyphCache[charcode] = glyph;
  20864. }
  20865. return glyph;
  20866. },
  20867. charsToGlyphs: function Font_charsToGlyphs(chars) {
  20868. var charsCache = this.charsCache;
  20869. var glyphs, glyph, charcode;
  20870. // if we translated this string before, just grab it from the cache
  20871. if (charsCache) {
  20872. glyphs = charsCache[chars];
  20873. if (glyphs) {
  20874. return glyphs;
  20875. }
  20876. }
  20877. // lazily create the translation cache
  20878. if (!charsCache) {
  20879. charsCache = this.charsCache = Object.create(null);
  20880. }
  20881. glyphs = [];
  20882. var charsCacheKey = chars;
  20883. var i = 0, ii;
  20884. if (this.cMap) {
  20885. // composite fonts have multi-byte strings convert the string from
  20886. // single-byte to multi-byte
  20887. while (i < chars.length) {
  20888. var c = this.cMap.readCharCode(chars, i);
  20889. charcode = c[0];
  20890. var length = c[1];
  20891. i += length;
  20892. glyph = this.charToGlyph(charcode);
  20893. glyphs.push(glyph);
  20894. // placing null after each word break charcode (ASCII SPACE)
  20895. // Ignore occurences of 0x20 in multiple-byte codes.
  20896. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  20897. glyphs.push(null);
  20898. }
  20899. }
  20900. } else {
  20901. for (i = 0, ii = chars.length; i < ii; ++i) {
  20902. charcode = chars.charCodeAt(i);
  20903. glyph = this.charToGlyph(charcode);
  20904. glyphs.push(glyph);
  20905. if (charcode === 0x20) {
  20906. glyphs.push(null);
  20907. }
  20908. }
  20909. }
  20910. // Enter the translated string into the cache
  20911. return (charsCache[charsCacheKey] = glyphs);
  20912. }
  20913. };
  20914. return Font;
  20915. })();
  20916. var ErrorFont = (function ErrorFontClosure() {
  20917. function ErrorFont(error) {
  20918. this.error = error;
  20919. this.loadedName = 'g_font_error';
  20920. this.loading = false;
  20921. }
  20922. ErrorFont.prototype = {
  20923. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  20924. return [];
  20925. },
  20926. exportData: function ErrorFont_exportData() {
  20927. return {error: this.error};
  20928. }
  20929. };
  20930. return ErrorFont;
  20931. })();
  20932. /**
  20933. * Shared logic for building a char code to glyph id mapping for Type1 and
  20934. * simple CFF fonts. See section 9.6.6.2 of the spec.
  20935. * @param {Object} properties Font properties object.
  20936. * @param {Object} builtInEncoding The encoding contained within the actual font
  20937. * data.
  20938. * @param {Array} Array of glyph names where the index is the glyph ID.
  20939. * @returns {Object} A char code to glyph ID map.
  20940. */
  20941. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  20942. var charCodeToGlyphId = Object.create(null);
  20943. var glyphId, charCode, baseEncoding;
  20944. if (properties.baseEncodingName) {
  20945. // If a valid base encoding name was used, the mapping is initialized with
  20946. // that.
  20947. baseEncoding = Encodings[properties.baseEncodingName];
  20948. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  20949. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  20950. if (glyphId >= 0) {
  20951. charCodeToGlyphId[charCode] = glyphId;
  20952. }
  20953. }
  20954. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  20955. // For a symbolic font the encoding should be the fonts built-in
  20956. // encoding.
  20957. for (charCode in builtInEncoding) {
  20958. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  20959. }
  20960. } else {
  20961. // For non-symbolic fonts that don't have a base encoding the standard
  20962. // encoding should be used.
  20963. baseEncoding = Encodings.StandardEncoding;
  20964. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  20965. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  20966. if (glyphId >= 0) {
  20967. charCodeToGlyphId[charCode] = glyphId;
  20968. }
  20969. }
  20970. }
  20971. // Lastly, merge in the differences.
  20972. var differences = properties.differences;
  20973. if (differences) {
  20974. for (charCode in differences) {
  20975. var glyphName = differences[charCode];
  20976. glyphId = glyphNames.indexOf(glyphName);
  20977. if (glyphId >= 0) {
  20978. charCodeToGlyphId[charCode] = glyphId;
  20979. }
  20980. }
  20981. }
  20982. return charCodeToGlyphId;
  20983. }
  20984. /*
  20985. * CharStrings are encoded following the the CharString Encoding sequence
  20986. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  20987. * The value in a byte indicates a command, a number, or subsequent bytes
  20988. * that are to be interpreted in a special way.
  20989. *
  20990. * CharString Number Encoding:
  20991. * A CharString byte containing the values from 32 through 255 inclusive
  20992. * indicate an integer. These values are decoded in four ranges.
  20993. *
  20994. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  20995. * indicate the integer v - 139. Thus, the integer values from -107 through
  20996. * 107 inclusive may be encoded in single byte.
  20997. *
  20998. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  20999. * indicates an integer involving the next byte, w, according to the formula:
  21000. * [(v - 247) x 256] + w + 108
  21001. *
  21002. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  21003. * indicates an integer involving the next byte, w, according to the formula:
  21004. * -[(v - 251) * 256] - w - 108
  21005. *
  21006. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  21007. * are a two complement signed integer. The first of these bytes contains the
  21008. * highest order bits, the second byte contains the next higher order bits
  21009. * and the fourth byte contain the lowest order bits.
  21010. *
  21011. *
  21012. * CharString Command Encoding:
  21013. * CharStrings commands are encoded in 1 or 2 bytes.
  21014. *
  21015. * Single byte commands are encoded in 1 byte that contains a value between
  21016. * 0 and 31 inclusive.
  21017. * If a command byte contains the value 12, then the value in the next byte
  21018. * indicates a command. This "escape" mechanism allows many extra commands
  21019. * to be encoded and this encoding technique helps to minimize the length of
  21020. * the charStrings.
  21021. */
  21022. var Type1CharString = (function Type1CharStringClosure() {
  21023. var COMMAND_MAP = {
  21024. 'hstem': [1],
  21025. 'vstem': [3],
  21026. 'vmoveto': [4],
  21027. 'rlineto': [5],
  21028. 'hlineto': [6],
  21029. 'vlineto': [7],
  21030. 'rrcurveto': [8],
  21031. 'callsubr': [10],
  21032. 'flex': [12, 35],
  21033. 'drop' : [12, 18],
  21034. 'endchar': [14],
  21035. 'rmoveto': [21],
  21036. 'hmoveto': [22],
  21037. 'vhcurveto': [30],
  21038. 'hvcurveto': [31]
  21039. };
  21040. function Type1CharString() {
  21041. this.width = 0;
  21042. this.lsb = 0;
  21043. this.flexing = false;
  21044. this.output = [];
  21045. this.stack = [];
  21046. }
  21047. Type1CharString.prototype = {
  21048. convert: function Type1CharString_convert(encoded, subrs) {
  21049. var count = encoded.length;
  21050. var error = false;
  21051. var wx, sbx, subrNumber;
  21052. for (var i = 0; i < count; i++) {
  21053. var value = encoded[i];
  21054. if (value < 32) {
  21055. if (value === 12) {
  21056. value = (value << 8) + encoded[++i];
  21057. }
  21058. switch (value) {
  21059. case 1: // hstem
  21060. if (!HINTING_ENABLED) {
  21061. this.stack = [];
  21062. break;
  21063. }
  21064. error = this.executeCommand(2, COMMAND_MAP.hstem);
  21065. break;
  21066. case 3: // vstem
  21067. if (!HINTING_ENABLED) {
  21068. this.stack = [];
  21069. break;
  21070. }
  21071. error = this.executeCommand(2, COMMAND_MAP.vstem);
  21072. break;
  21073. case 4: // vmoveto
  21074. if (this.flexing) {
  21075. if (this.stack.length < 1) {
  21076. error = true;
  21077. break;
  21078. }
  21079. // Add the dx for flex and but also swap the values so they are
  21080. // the right order.
  21081. var dy = this.stack.pop();
  21082. this.stack.push(0, dy);
  21083. break;
  21084. }
  21085. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  21086. break;
  21087. case 5: // rlineto
  21088. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  21089. break;
  21090. case 6: // hlineto
  21091. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  21092. break;
  21093. case 7: // vlineto
  21094. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  21095. break;
  21096. case 8: // rrcurveto
  21097. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  21098. break;
  21099. case 9: // closepath
  21100. // closepath is a Type1 command that does not take argument and is
  21101. // useless in Type2 and it can simply be ignored.
  21102. this.stack = [];
  21103. break;
  21104. case 10: // callsubr
  21105. if (this.stack.length < 1) {
  21106. error = true;
  21107. break;
  21108. }
  21109. subrNumber = this.stack.pop();
  21110. error = this.convert(subrs[subrNumber], subrs);
  21111. break;
  21112. case 11: // return
  21113. return error;
  21114. case 13: // hsbw
  21115. if (this.stack.length < 2) {
  21116. error = true;
  21117. break;
  21118. }
  21119. // To convert to type2 we have to move the width value to the
  21120. // first part of the charstring and then use hmoveto with lsb.
  21121. wx = this.stack.pop();
  21122. sbx = this.stack.pop();
  21123. this.lsb = sbx;
  21124. this.width = wx;
  21125. this.stack.push(sbx);
  21126. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  21127. break;
  21128. case 14: // endchar
  21129. this.output.push(COMMAND_MAP.endchar[0]);
  21130. break;
  21131. case 21: // rmoveto
  21132. if (this.flexing) {
  21133. break;
  21134. }
  21135. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  21136. break;
  21137. case 22: // hmoveto
  21138. if (this.flexing) {
  21139. // Add the dy for flex.
  21140. this.stack.push(0);
  21141. break;
  21142. }
  21143. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  21144. break;
  21145. case 30: // vhcurveto
  21146. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  21147. break;
  21148. case 31: // hvcurveto
  21149. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  21150. break;
  21151. case (12 << 8) + 0: // dotsection
  21152. // dotsection is a Type1 command to specify some hinting feature
  21153. // for dots that do not take a parameter and it can safely be
  21154. // ignored for Type2.
  21155. this.stack = [];
  21156. break;
  21157. case (12 << 8) + 1: // vstem3
  21158. if (!HINTING_ENABLED) {
  21159. this.stack = [];
  21160. break;
  21161. }
  21162. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  21163. // multiple parameters, so instead of returning [vh]stem3 take a
  21164. // shortcut and return [vhstem] instead.
  21165. error = this.executeCommand(2, COMMAND_MAP.vstem);
  21166. break;
  21167. case (12 << 8) + 2: // hstem3
  21168. if (!HINTING_ENABLED) {
  21169. this.stack = [];
  21170. break;
  21171. }
  21172. // See vstem3.
  21173. error = this.executeCommand(2, COMMAND_MAP.hstem);
  21174. break;
  21175. case (12 << 8) + 6: // seac
  21176. // seac is like type 2's special endchar but it doesn't use the
  21177. // first argument asb, so remove it.
  21178. if (SEAC_ANALYSIS_ENABLED) {
  21179. this.seac = this.stack.splice(-4, 4);
  21180. error = this.executeCommand(0, COMMAND_MAP.endchar);
  21181. } else {
  21182. error = this.executeCommand(4, COMMAND_MAP.endchar);
  21183. }
  21184. break;
  21185. case (12 << 8) + 7: // sbw
  21186. if (this.stack.length < 4) {
  21187. error = true;
  21188. break;
  21189. }
  21190. // To convert to type2 we have to move the width value to the
  21191. // first part of the charstring and then use rmoveto with
  21192. // (dx, dy). The height argument will not be used for vmtx and
  21193. // vhea tables reconstruction -- ignoring it.
  21194. var wy = this.stack.pop();
  21195. wx = this.stack.pop();
  21196. var sby = this.stack.pop();
  21197. sbx = this.stack.pop();
  21198. this.lsb = sbx;
  21199. this.width = wx;
  21200. this.stack.push(sbx, sby);
  21201. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  21202. break;
  21203. case (12 << 8) + 12: // div
  21204. if (this.stack.length < 2) {
  21205. error = true;
  21206. break;
  21207. }
  21208. var num2 = this.stack.pop();
  21209. var num1 = this.stack.pop();
  21210. this.stack.push(num1 / num2);
  21211. break;
  21212. case (12 << 8) + 16: // callothersubr
  21213. if (this.stack.length < 2) {
  21214. error = true;
  21215. break;
  21216. }
  21217. subrNumber = this.stack.pop();
  21218. var numArgs = this.stack.pop();
  21219. if (subrNumber === 0 && numArgs === 3) {
  21220. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  21221. this.stack.push(
  21222. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  21223. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  21224. flexArgs[4], // bcp2x
  21225. flexArgs[5], // bcp2y
  21226. flexArgs[6], // p2x
  21227. flexArgs[7], // p2y
  21228. flexArgs[8], // bcp3x
  21229. flexArgs[9], // bcp3y
  21230. flexArgs[10], // bcp4x
  21231. flexArgs[11], // bcp4y
  21232. flexArgs[12], // p3x
  21233. flexArgs[13], // p3y
  21234. flexArgs[14] // flexDepth
  21235. // 15 = finalx unused by flex
  21236. // 16 = finaly unused by flex
  21237. );
  21238. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  21239. this.flexing = false;
  21240. this.stack.push(flexArgs[15], flexArgs[16]);
  21241. } else if (subrNumber === 1 && numArgs === 0) {
  21242. this.flexing = true;
  21243. }
  21244. break;
  21245. case (12 << 8) + 17: // pop
  21246. // Ignore this since it is only used with othersubr.
  21247. break;
  21248. case (12 << 8) + 33: // setcurrentpoint
  21249. // Ignore for now.
  21250. this.stack = [];
  21251. break;
  21252. default:
  21253. warn('Unknown type 1 charstring command of "' + value + '"');
  21254. break;
  21255. }
  21256. if (error) {
  21257. break;
  21258. }
  21259. continue;
  21260. } else if (value <= 246) {
  21261. value = value - 139;
  21262. } else if (value <= 250) {
  21263. value = ((value - 247) * 256) + encoded[++i] + 108;
  21264. } else if (value <= 254) {
  21265. value = -((value - 251) * 256) - encoded[++i] - 108;
  21266. } else {
  21267. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  21268. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  21269. }
  21270. this.stack.push(value);
  21271. }
  21272. return error;
  21273. },
  21274. executeCommand: function(howManyArgs, command, keepStack) {
  21275. var stackLength = this.stack.length;
  21276. if (howManyArgs > stackLength) {
  21277. return true;
  21278. }
  21279. var start = stackLength - howManyArgs;
  21280. for (var i = start; i < stackLength; i++) {
  21281. var value = this.stack[i];
  21282. if (value === (value | 0)) { // int
  21283. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  21284. } else { // fixed point
  21285. value = (65536 * value) | 0;
  21286. this.output.push(255,
  21287. (value >> 24) & 0xFF,
  21288. (value >> 16) & 0xFF,
  21289. (value >> 8) & 0xFF,
  21290. value & 0xFF);
  21291. }
  21292. }
  21293. this.output.push.apply(this.output, command);
  21294. if (keepStack) {
  21295. this.stack.splice(start, howManyArgs);
  21296. } else {
  21297. this.stack.length = 0;
  21298. }
  21299. return false;
  21300. }
  21301. };
  21302. return Type1CharString;
  21303. })();
  21304. /*
  21305. * Type1Parser encapsulate the needed code for parsing a Type1 font
  21306. * program. Some of its logic depends on the Type2 charstrings
  21307. * structure.
  21308. * Note: this doesn't really parse the font since that would require evaluation
  21309. * of PostScript, but it is possible in most cases to extract what we need
  21310. * without a full parse.
  21311. */
  21312. var Type1Parser = (function Type1ParserClosure() {
  21313. /*
  21314. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  21315. * of Plaintext Bytes. The function took a key as a parameter which can be
  21316. * for decrypting the eexec block of for decoding charStrings.
  21317. */
  21318. var EEXEC_ENCRYPT_KEY = 55665;
  21319. var CHAR_STRS_ENCRYPT_KEY = 4330;
  21320. function isHexDigit(code) {
  21321. return code >= 48 && code <= 57 || // '0'-'9'
  21322. code >= 65 && code <= 70 || // 'A'-'F'
  21323. code >= 97 && code <= 102; // 'a'-'f'
  21324. }
  21325. function decrypt(data, key, discardNumber) {
  21326. var r = key | 0, c1 = 52845, c2 = 22719;
  21327. var count = data.length;
  21328. var decrypted = new Uint8Array(count);
  21329. for (var i = 0; i < count; i++) {
  21330. var value = data[i];
  21331. decrypted[i] = value ^ (r >> 8);
  21332. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  21333. }
  21334. return Array.prototype.slice.call(decrypted, discardNumber);
  21335. }
  21336. function decryptAscii(data, key, discardNumber) {
  21337. var r = key | 0, c1 = 52845, c2 = 22719;
  21338. var count = data.length, maybeLength = count >>> 1;
  21339. var decrypted = new Uint8Array(maybeLength);
  21340. var i, j;
  21341. for (i = 0, j = 0; i < count; i++) {
  21342. var digit1 = data[i];
  21343. if (!isHexDigit(digit1)) {
  21344. continue;
  21345. }
  21346. i++;
  21347. var digit2;
  21348. while (i < count && !isHexDigit(digit2 = data[i])) {
  21349. i++;
  21350. }
  21351. if (i < count) {
  21352. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  21353. decrypted[j++] = value ^ (r >> 8);
  21354. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  21355. }
  21356. }
  21357. return Array.prototype.slice.call(decrypted, discardNumber, j);
  21358. }
  21359. function isSpecial(c) {
  21360. return c === 0x2F || // '/'
  21361. c === 0x5B || c === 0x5D || // '[', ']'
  21362. c === 0x7B || c === 0x7D || // '{', '}'
  21363. c === 0x28 || c === 0x29; // '(', ')'
  21364. }
  21365. function Type1Parser(stream, encrypted) {
  21366. if (encrypted) {
  21367. var data = stream.getBytes();
  21368. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  21369. isHexDigit(data[2]) && isHexDigit(data[3]));
  21370. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  21371. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  21372. }
  21373. this.stream = stream;
  21374. this.nextChar();
  21375. }
  21376. Type1Parser.prototype = {
  21377. readNumberArray: function Type1Parser_readNumberArray() {
  21378. this.getToken(); // read '[' or '{' (arrays can start with either)
  21379. var array = [];
  21380. while (true) {
  21381. var token = this.getToken();
  21382. if (token === null || token === ']' || token === '}') {
  21383. break;
  21384. }
  21385. array.push(parseFloat(token || 0));
  21386. }
  21387. return array;
  21388. },
  21389. readNumber: function Type1Parser_readNumber() {
  21390. var token = this.getToken();
  21391. return parseFloat(token || 0);
  21392. },
  21393. readInt: function Type1Parser_readInt() {
  21394. // Use '| 0' to prevent setting a double into length such as the double
  21395. // does not flow into the loop variable.
  21396. var token = this.getToken();
  21397. return parseInt(token || 0, 10) | 0;
  21398. },
  21399. readBoolean: function Type1Parser_readBoolean() {
  21400. var token = this.getToken();
  21401. // Use 1 and 0 since that's what type2 charstrings use.
  21402. return token === 'true' ? 1 : 0;
  21403. },
  21404. nextChar : function Type1_nextChar() {
  21405. return (this.currentChar = this.stream.getByte());
  21406. },
  21407. getToken: function Type1Parser_getToken() {
  21408. // Eat whitespace and comments.
  21409. var comment = false;
  21410. var ch = this.currentChar;
  21411. while (true) {
  21412. if (ch === -1) {
  21413. return null;
  21414. }
  21415. if (comment) {
  21416. if (ch === 0x0A || ch === 0x0D) {
  21417. comment = false;
  21418. }
  21419. } else if (ch === 0x25) { // '%'
  21420. comment = true;
  21421. } else if (!Lexer.isSpace(ch)) {
  21422. break;
  21423. }
  21424. ch = this.nextChar();
  21425. }
  21426. if (isSpecial(ch)) {
  21427. this.nextChar();
  21428. return String.fromCharCode(ch);
  21429. }
  21430. var token = '';
  21431. do {
  21432. token += String.fromCharCode(ch);
  21433. ch = this.nextChar();
  21434. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  21435. return token;
  21436. },
  21437. /*
  21438. * Returns an object containing a Subrs array and a CharStrings
  21439. * array extracted from and eexec encrypted block of data
  21440. */
  21441. extractFontProgram: function Type1Parser_extractFontProgram() {
  21442. var stream = this.stream;
  21443. var subrs = [], charstrings = [];
  21444. var program = {
  21445. subrs: [],
  21446. charstrings: [],
  21447. properties: {
  21448. 'privateData': {
  21449. 'lenIV': 4
  21450. }
  21451. }
  21452. };
  21453. var token, length, data, lenIV, encoded;
  21454. while ((token = this.getToken()) !== null) {
  21455. if (token !== '/') {
  21456. continue;
  21457. }
  21458. token = this.getToken();
  21459. switch (token) {
  21460. case 'CharStrings':
  21461. // The number immediately following CharStrings must be greater or
  21462. // equal to the number of CharStrings.
  21463. this.getToken();
  21464. this.getToken(); // read in 'dict'
  21465. this.getToken(); // read in 'dup'
  21466. this.getToken(); // read in 'begin'
  21467. while(true) {
  21468. token = this.getToken();
  21469. if (token === null || token === 'end') {
  21470. break;
  21471. }
  21472. if (token !== '/') {
  21473. continue;
  21474. }
  21475. var glyph = this.getToken();
  21476. length = this.readInt();
  21477. this.getToken(); // read in 'RD' or '-|'
  21478. data = stream.makeSubStream(stream.pos, length);
  21479. lenIV = program.properties.privateData['lenIV'];
  21480. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  21481. // Skip past the required space and binary data.
  21482. stream.skip(length);
  21483. this.nextChar();
  21484. token = this.getToken(); // read in 'ND' or '|-'
  21485. if (token === 'noaccess') {
  21486. this.getToken(); // read in 'def'
  21487. }
  21488. charstrings.push({
  21489. glyph: glyph,
  21490. encoded: encoded
  21491. });
  21492. }
  21493. break;
  21494. case 'Subrs':
  21495. var num = this.readInt();
  21496. this.getToken(); // read in 'array'
  21497. while ((token = this.getToken()) === 'dup') {
  21498. var index = this.readInt();
  21499. length = this.readInt();
  21500. this.getToken(); // read in 'RD' or '-|'
  21501. data = stream.makeSubStream(stream.pos, length);
  21502. lenIV = program.properties.privateData['lenIV'];
  21503. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  21504. // Skip past the required space and binary data.
  21505. stream.skip(length);
  21506. this.nextChar();
  21507. token = this.getToken(); // read in 'NP' or '|'
  21508. if (token === 'noaccess') {
  21509. this.getToken(); // read in 'put'
  21510. }
  21511. subrs[index] = encoded;
  21512. }
  21513. break;
  21514. case 'BlueValues':
  21515. case 'OtherBlues':
  21516. case 'FamilyBlues':
  21517. case 'FamilyOtherBlues':
  21518. var blueArray = this.readNumberArray();
  21519. // *Blue* values may contain invalid data: disables reading of
  21520. // those values when hinting is disabled.
  21521. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  21522. HINTING_ENABLED) {
  21523. program.properties.privateData[token] = blueArray;
  21524. }
  21525. break;
  21526. case 'StemSnapH':
  21527. case 'StemSnapV':
  21528. program.properties.privateData[token] = this.readNumberArray();
  21529. break;
  21530. case 'StdHW':
  21531. case 'StdVW':
  21532. program.properties.privateData[token] =
  21533. this.readNumberArray()[0];
  21534. break;
  21535. case 'BlueShift':
  21536. case 'lenIV':
  21537. case 'BlueFuzz':
  21538. case 'BlueScale':
  21539. case 'LanguageGroup':
  21540. case 'ExpansionFactor':
  21541. program.properties.privateData[token] = this.readNumber();
  21542. break;
  21543. case 'ForceBold':
  21544. program.properties.privateData[token] = this.readBoolean();
  21545. break;
  21546. }
  21547. }
  21548. for (var i = 0; i < charstrings.length; i++) {
  21549. glyph = charstrings[i].glyph;
  21550. encoded = charstrings[i].encoded;
  21551. var charString = new Type1CharString();
  21552. var error = charString.convert(encoded, subrs);
  21553. var output = charString.output;
  21554. if (error) {
  21555. // It seems when FreeType encounters an error while evaluating a glyph
  21556. // that it completely ignores the glyph so we'll mimic that behaviour
  21557. // here and put an endchar to make the validator happy.
  21558. output = [14];
  21559. }
  21560. program.charstrings.push({
  21561. glyphName: glyph,
  21562. charstring: output,
  21563. width: charString.width,
  21564. lsb: charString.lsb,
  21565. seac: charString.seac
  21566. });
  21567. }
  21568. return program;
  21569. },
  21570. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  21571. var token;
  21572. while ((token = this.getToken()) !== null) {
  21573. if (token !== '/') {
  21574. continue;
  21575. }
  21576. token = this.getToken();
  21577. switch (token) {
  21578. case 'FontMatrix':
  21579. var matrix = this.readNumberArray();
  21580. properties.fontMatrix = matrix;
  21581. break;
  21582. case 'Encoding':
  21583. var encodingArg = this.getToken();
  21584. var encoding;
  21585. if (!/^\d+$/.test(encodingArg)) {
  21586. // encoding name is specified
  21587. encoding = Encodings[encodingArg];
  21588. } else {
  21589. encoding = [];
  21590. var size = parseInt(encodingArg, 10) | 0;
  21591. this.getToken(); // read in 'array'
  21592. for (var j = 0; j < size; j++) {
  21593. token = this.getToken();
  21594. // skipping till first dup or def (e.g. ignoring for statement)
  21595. while (token !== 'dup' && token !== 'def') {
  21596. token = this.getToken();
  21597. if (token === null) {
  21598. return; // invalid header
  21599. }
  21600. }
  21601. if (token === 'def') {
  21602. break; // read all array data
  21603. }
  21604. var index = this.readInt();
  21605. this.getToken(); // read in '/'
  21606. var glyph = this.getToken();
  21607. encoding[index] = glyph;
  21608. this.getToken(); // read the in 'put'
  21609. }
  21610. }
  21611. properties.builtInEncoding = encoding;
  21612. break;
  21613. case 'FontBBox':
  21614. var fontBBox = this.readNumberArray();
  21615. // adjusting ascent/descent
  21616. properties.ascent = fontBBox[3];
  21617. properties.descent = fontBBox[1];
  21618. properties.ascentScaled = true;
  21619. break;
  21620. }
  21621. }
  21622. }
  21623. };
  21624. return Type1Parser;
  21625. })();
  21626. /**
  21627. * The CFF class takes a Type1 file and wrap it into a
  21628. * 'Compact Font Format' which itself embed Type2 charstrings.
  21629. */
  21630. var CFFStandardStrings = [
  21631. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  21632. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  21633. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  21634. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  21635. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  21636. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  21637. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  21638. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  21639. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  21640. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  21641. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  21642. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  21643. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  21644. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  21645. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  21646. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  21647. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  21648. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  21649. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  21650. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  21651. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  21652. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  21653. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  21654. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  21655. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  21656. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  21657. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  21658. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  21659. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  21660. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  21661. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  21662. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  21663. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  21664. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  21665. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  21666. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  21667. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  21668. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  21669. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  21670. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  21671. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  21672. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  21673. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  21674. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  21675. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  21676. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  21677. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  21678. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  21679. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  21680. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  21681. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  21682. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  21683. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  21684. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  21685. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  21686. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  21687. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  21688. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  21689. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  21690. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  21691. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  21692. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  21693. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  21694. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  21695. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  21696. ];
  21697. // Type1Font is also a CIDFontType0.
  21698. var Type1Font = function Type1Font(name, file, properties) {
  21699. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  21700. // Also, length1 and length2 might be off by 6 bytes as well.
  21701. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  21702. var PFB_HEADER_SIZE = 6;
  21703. var headerBlockLength = properties.length1;
  21704. var eexecBlockLength = properties.length2;
  21705. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  21706. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  21707. if (pfbHeaderPresent) {
  21708. file.skip(PFB_HEADER_SIZE);
  21709. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  21710. (pfbHeader[3] << 8) | pfbHeader[2];
  21711. }
  21712. // Get the data block containing glyphs and subrs informations
  21713. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  21714. var headerBlockParser = new Type1Parser(headerBlock);
  21715. headerBlockParser.extractFontHeader(properties);
  21716. if (pfbHeaderPresent) {
  21717. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  21718. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  21719. (pfbHeader[3] << 8) | pfbHeader[2];
  21720. }
  21721. // Decrypt the data blocks and retrieve it's content
  21722. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  21723. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  21724. var data = eexecBlockParser.extractFontProgram();
  21725. for (var info in data.properties) {
  21726. properties[info] = data.properties[info];
  21727. }
  21728. var charstrings = data.charstrings;
  21729. var type2Charstrings = this.getType2Charstrings(charstrings);
  21730. var subrs = this.getType2Subrs(data.subrs);
  21731. this.charstrings = charstrings;
  21732. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  21733. subrs, properties);
  21734. this.seacs = this.getSeacs(data.charstrings);
  21735. };
  21736. Type1Font.prototype = {
  21737. get numGlyphs() {
  21738. return this.charstrings.length + 1;
  21739. },
  21740. getCharset: function Type1Font_getCharset() {
  21741. var charset = ['.notdef'];
  21742. var charstrings = this.charstrings;
  21743. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  21744. charset.push(charstrings[glyphId].glyphName);
  21745. }
  21746. return charset;
  21747. },
  21748. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  21749. var charstrings = this.charstrings;
  21750. var glyphNames = ['.notdef'], glyphId;
  21751. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  21752. glyphNames.push(charstrings[glyphId].glyphName);
  21753. }
  21754. var encoding = properties.builtInEncoding;
  21755. if (encoding) {
  21756. var builtInEncoding = {};
  21757. for (var charCode in encoding) {
  21758. glyphId = glyphNames.indexOf(encoding[charCode]);
  21759. if (glyphId >= 0) {
  21760. builtInEncoding[charCode] = glyphId;
  21761. }
  21762. }
  21763. }
  21764. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  21765. },
  21766. getSeacs: function Type1Font_getSeacs(charstrings) {
  21767. var i, ii;
  21768. var seacMap = [];
  21769. for (i = 0, ii = charstrings.length; i < ii; i++) {
  21770. var charstring = charstrings[i];
  21771. if (charstring.seac) {
  21772. // Offset by 1 for .notdef
  21773. seacMap[i + 1] = charstring.seac;
  21774. }
  21775. }
  21776. return seacMap;
  21777. },
  21778. getType2Charstrings: function Type1Font_getType2Charstrings(
  21779. type1Charstrings) {
  21780. var type2Charstrings = [];
  21781. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  21782. type2Charstrings.push(type1Charstrings[i].charstring);
  21783. }
  21784. return type2Charstrings;
  21785. },
  21786. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  21787. var bias = 0;
  21788. var count = type1Subrs.length;
  21789. if (count < 1133) {
  21790. bias = 107;
  21791. } else if (count < 33769) {
  21792. bias = 1131;
  21793. } else {
  21794. bias = 32768;
  21795. }
  21796. // Add a bunch of empty subrs to deal with the Type2 bias
  21797. var type2Subrs = [];
  21798. var i;
  21799. for (i = 0; i < bias; i++) {
  21800. type2Subrs.push([0x0B]);
  21801. }
  21802. for (i = 0; i < count; i++) {
  21803. type2Subrs.push(type1Subrs[i]);
  21804. }
  21805. return type2Subrs;
  21806. },
  21807. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  21808. var cff = new CFF();
  21809. cff.header = new CFFHeader(1, 0, 4, 4);
  21810. cff.names = [name];
  21811. var topDict = new CFFTopDict();
  21812. // CFF strings IDs 0...390 are predefined names, so refering
  21813. // to entries in our own String INDEX starts at SID 391.
  21814. topDict.setByName('version', 391);
  21815. topDict.setByName('Notice', 392);
  21816. topDict.setByName('FullName', 393);
  21817. topDict.setByName('FamilyName', 394);
  21818. topDict.setByName('Weight', 395);
  21819. topDict.setByName('Encoding', null); // placeholder
  21820. topDict.setByName('FontMatrix', properties.fontMatrix);
  21821. topDict.setByName('FontBBox', properties.bbox);
  21822. topDict.setByName('charset', null); // placeholder
  21823. topDict.setByName('CharStrings', null); // placeholder
  21824. topDict.setByName('Private', null); // placeholder
  21825. cff.topDict = topDict;
  21826. var strings = new CFFStrings();
  21827. strings.add('Version 0.11'); // Version
  21828. strings.add('See original notice'); // Notice
  21829. strings.add(name); // FullName
  21830. strings.add(name); // FamilyName
  21831. strings.add('Medium'); // Weight
  21832. cff.strings = strings;
  21833. cff.globalSubrIndex = new CFFIndex();
  21834. var count = glyphs.length;
  21835. var charsetArray = [0];
  21836. var i, ii;
  21837. for (i = 0; i < count; i++) {
  21838. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  21839. // TODO: Insert the string and correctly map it. Previously it was
  21840. // thought mapping names that aren't in the standard strings to .notdef
  21841. // was fine, however in issue818 when mapping them all to .notdef the
  21842. // adieresis glyph no longer worked.
  21843. if (index === -1) {
  21844. index = 0;
  21845. }
  21846. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  21847. }
  21848. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  21849. var charStringsIndex = new CFFIndex();
  21850. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  21851. for (i = 0; i < count; i++) {
  21852. charStringsIndex.add(glyphs[i]);
  21853. }
  21854. cff.charStrings = charStringsIndex;
  21855. var privateDict = new CFFPrivateDict();
  21856. privateDict.setByName('Subrs', null); // placeholder
  21857. var fields = [
  21858. 'BlueValues',
  21859. 'OtherBlues',
  21860. 'FamilyBlues',
  21861. 'FamilyOtherBlues',
  21862. 'StemSnapH',
  21863. 'StemSnapV',
  21864. 'BlueShift',
  21865. 'BlueFuzz',
  21866. 'BlueScale',
  21867. 'LanguageGroup',
  21868. 'ExpansionFactor',
  21869. 'ForceBold',
  21870. 'StdHW',
  21871. 'StdVW'
  21872. ];
  21873. for (i = 0, ii = fields.length; i < ii; i++) {
  21874. var field = fields[i];
  21875. if (!properties.privateData.hasOwnProperty(field)) {
  21876. continue;
  21877. }
  21878. var value = properties.privateData[field];
  21879. if (isArray(value)) {
  21880. // All of the private dictionary array data in CFF must be stored as
  21881. // "delta-encoded" numbers.
  21882. for (var j = value.length - 1; j > 0; j--) {
  21883. value[j] -= value[j - 1]; // ... difference from previous value
  21884. }
  21885. }
  21886. privateDict.setByName(field, value);
  21887. }
  21888. cff.topDict.privateDict = privateDict;
  21889. var subrIndex = new CFFIndex();
  21890. for (i = 0, ii = subrs.length; i < ii; i++) {
  21891. subrIndex.add(subrs[i]);
  21892. }
  21893. privateDict.subrsIndex = subrIndex;
  21894. var compiler = new CFFCompiler(cff);
  21895. return compiler.compile();
  21896. }
  21897. };
  21898. var CFFFont = (function CFFFontClosure() {
  21899. function CFFFont(file, properties) {
  21900. this.properties = properties;
  21901. var parser = new CFFParser(file, properties);
  21902. this.cff = parser.parse();
  21903. var compiler = new CFFCompiler(this.cff);
  21904. this.seacs = this.cff.seacs;
  21905. try {
  21906. this.data = compiler.compile();
  21907. } catch (e) {
  21908. warn('Failed to compile font ' + properties.loadedName);
  21909. // There may have just been an issue with the compiler, set the data
  21910. // anyway and hope the font loaded.
  21911. this.data = file;
  21912. }
  21913. }
  21914. CFFFont.prototype = {
  21915. get numGlyphs() {
  21916. return this.cff.charStrings.count;
  21917. },
  21918. getCharset: function CFFFont_getCharset() {
  21919. return this.cff.charset.charset;
  21920. },
  21921. getGlyphMapping: function CFFFont_getGlyphMapping() {
  21922. var cff = this.cff;
  21923. var properties = this.properties;
  21924. var charsets = cff.charset.charset;
  21925. var charCodeToGlyphId;
  21926. var glyphId;
  21927. if (properties.composite) {
  21928. charCodeToGlyphId = Object.create(null);
  21929. if (cff.isCIDFont) {
  21930. // If the font is actually a CID font then we should use the charset
  21931. // to map CIDs to GIDs.
  21932. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  21933. var cid = charsets[glyphId];
  21934. var charCode = properties.cMap.charCodeOf(cid);
  21935. charCodeToGlyphId[charCode] = glyphId;
  21936. }
  21937. } else {
  21938. // If it is NOT actually a CID font then CIDs should be mapped
  21939. // directly to GIDs.
  21940. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  21941. charCodeToGlyphId[glyphId] = glyphId;
  21942. }
  21943. }
  21944. return charCodeToGlyphId;
  21945. }
  21946. var encoding = cff.encoding ? cff.encoding.encoding : null;
  21947. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  21948. return charCodeToGlyphId;
  21949. }
  21950. };
  21951. return CFFFont;
  21952. })();
  21953. var CFFParser = (function CFFParserClosure() {
  21954. var CharstringValidationData = [
  21955. null,
  21956. { id: 'hstem', min: 2, resetStack: true, stem: true },
  21957. null,
  21958. { id: 'vstem', min: 2, resetStack: true, stem: true },
  21959. { id: 'vmoveto', min: 1, resetStack: true },
  21960. { id: 'rlineto', min: 2, resetStack: true },
  21961. { id: 'hlineto', min: 1, resetStack: true },
  21962. { id: 'vlineto', min: 1, resetStack: true },
  21963. { id: 'rrcurveto', min: 6, resetStack: true },
  21964. null,
  21965. { id: 'callsubr', min: 1, undefStack: true },
  21966. { id: 'return', min: 0, undefStack: true },
  21967. null, // 12
  21968. null,
  21969. null, // endchar
  21970. null,
  21971. null,
  21972. null,
  21973. { id: 'hstemhm', min: 2, resetStack: true, stem: true },
  21974. null, // hintmask
  21975. null, // cntrmask
  21976. { id: 'rmoveto', min: 2, resetStack: true },
  21977. { id: 'hmoveto', min: 1, resetStack: true },
  21978. { id: 'vstemhm', min: 2, resetStack: true, stem: true },
  21979. { id: 'rcurveline', min: 8, resetStack: true },
  21980. { id: 'rlinecurve', min: 8, resetStack: true },
  21981. { id: 'vvcurveto', min: 4, resetStack: true },
  21982. { id: 'hhcurveto', min: 4, resetStack: true },
  21983. null, // shortint
  21984. { id: 'callgsubr', min: 1, undefStack: true },
  21985. { id: 'vhcurveto', min: 4, resetStack: true },
  21986. { id: 'hvcurveto', min: 4, resetStack: true }
  21987. ];
  21988. var CharstringValidationData12 = [
  21989. null,
  21990. null,
  21991. null,
  21992. { id: 'and', min: 2, stackDelta: -1 },
  21993. { id: 'or', min: 2, stackDelta: -1 },
  21994. { id: 'not', min: 1, stackDelta: 0 },
  21995. null,
  21996. null,
  21997. null,
  21998. { id: 'abs', min: 1, stackDelta: 0 },
  21999. { id: 'add', min: 2, stackDelta: -1,
  22000. stackFn: function stack_div(stack, index) {
  22001. stack[index - 2] = stack[index - 2] + stack[index - 1];
  22002. }
  22003. },
  22004. { id: 'sub', min: 2, stackDelta: -1,
  22005. stackFn: function stack_div(stack, index) {
  22006. stack[index - 2] = stack[index - 2] - stack[index - 1];
  22007. }
  22008. },
  22009. { id: 'div', min: 2, stackDelta: -1,
  22010. stackFn: function stack_div(stack, index) {
  22011. stack[index - 2] = stack[index - 2] / stack[index - 1];
  22012. }
  22013. },
  22014. null,
  22015. { id: 'neg', min: 1, stackDelta: 0,
  22016. stackFn: function stack_div(stack, index) {
  22017. stack[index - 1] = -stack[index - 1];
  22018. }
  22019. },
  22020. { id: 'eq', min: 2, stackDelta: -1 },
  22021. null,
  22022. null,
  22023. { id: 'drop', min: 1, stackDelta: -1 },
  22024. null,
  22025. { id: 'put', min: 2, stackDelta: -2 },
  22026. { id: 'get', min: 1, stackDelta: 0 },
  22027. { id: 'ifelse', min: 4, stackDelta: -3 },
  22028. { id: 'random', min: 0, stackDelta: 1 },
  22029. { id: 'mul', min: 2, stackDelta: -1,
  22030. stackFn: function stack_div(stack, index) {
  22031. stack[index - 2] = stack[index - 2] * stack[index - 1];
  22032. }
  22033. },
  22034. null,
  22035. { id: 'sqrt', min: 1, stackDelta: 0 },
  22036. { id: 'dup', min: 1, stackDelta: 1 },
  22037. { id: 'exch', min: 2, stackDelta: 0 },
  22038. { id: 'index', min: 2, stackDelta: 0 },
  22039. { id: 'roll', min: 3, stackDelta: -2 },
  22040. null,
  22041. null,
  22042. null,
  22043. { id: 'hflex', min: 7, resetStack: true },
  22044. { id: 'flex', min: 13, resetStack: true },
  22045. { id: 'hflex1', min: 9, resetStack: true },
  22046. { id: 'flex1', min: 11, resetStack: true }
  22047. ];
  22048. function CFFParser(file, properties) {
  22049. this.bytes = file.getBytes();
  22050. this.properties = properties;
  22051. }
  22052. CFFParser.prototype = {
  22053. parse: function CFFParser_parse() {
  22054. var properties = this.properties;
  22055. var cff = new CFF();
  22056. this.cff = cff;
  22057. // The first five sections must be in order, all the others are reached
  22058. // via offsets contained in one of the below.
  22059. var header = this.parseHeader();
  22060. var nameIndex = this.parseIndex(header.endPos);
  22061. var topDictIndex = this.parseIndex(nameIndex.endPos);
  22062. var stringIndex = this.parseIndex(topDictIndex.endPos);
  22063. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  22064. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  22065. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  22066. cff.header = header.obj;
  22067. cff.names = this.parseNameIndex(nameIndex.obj);
  22068. cff.strings = this.parseStringIndex(stringIndex.obj);
  22069. cff.topDict = topDict;
  22070. cff.globalSubrIndex = globalSubrIndex.obj;
  22071. this.parsePrivateDict(cff.topDict);
  22072. cff.isCIDFont = topDict.hasName('ROS');
  22073. var charStringOffset = topDict.getByName('CharStrings');
  22074. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  22075. cff.charStrings = charStringsAndSeacs.charStrings;
  22076. cff.seacs = charStringsAndSeacs.seacs;
  22077. var fontMatrix = topDict.getByName('FontMatrix');
  22078. if (fontMatrix) {
  22079. properties.fontMatrix = fontMatrix;
  22080. }
  22081. var fontBBox = topDict.getByName('FontBBox');
  22082. if (fontBBox) {
  22083. // adjusting ascent/descent
  22084. properties.ascent = fontBBox[3];
  22085. properties.descent = fontBBox[1];
  22086. properties.ascentScaled = true;
  22087. }
  22088. var charset, encoding;
  22089. if (cff.isCIDFont) {
  22090. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  22091. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  22092. var dictRaw = fdArrayIndex.get(i);
  22093. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  22094. cff.strings);
  22095. this.parsePrivateDict(fontDict);
  22096. cff.fdArray.push(fontDict);
  22097. }
  22098. // cid fonts don't have an encoding
  22099. encoding = null;
  22100. charset = this.parseCharsets(topDict.getByName('charset'),
  22101. cff.charStrings.count, cff.strings, true);
  22102. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  22103. cff.charStrings.count);
  22104. } else {
  22105. charset = this.parseCharsets(topDict.getByName('charset'),
  22106. cff.charStrings.count, cff.strings, false);
  22107. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  22108. properties,
  22109. cff.strings, charset.charset);
  22110. }
  22111. cff.charset = charset;
  22112. cff.encoding = encoding;
  22113. return cff;
  22114. },
  22115. parseHeader: function CFFParser_parseHeader() {
  22116. var bytes = this.bytes;
  22117. var bytesLength = bytes.length;
  22118. var offset = 0;
  22119. // Prevent an infinite loop, by checking that the offset is within the
  22120. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  22121. while (offset < bytesLength && bytes[offset] !== 1) {
  22122. ++offset;
  22123. }
  22124. if (offset >= bytesLength) {
  22125. error('Invalid CFF header');
  22126. } else if (offset !== 0) {
  22127. info('cff data is shifted');
  22128. bytes = bytes.subarray(offset);
  22129. this.bytes = bytes;
  22130. }
  22131. var major = bytes[0];
  22132. var minor = bytes[1];
  22133. var hdrSize = bytes[2];
  22134. var offSize = bytes[3];
  22135. var header = new CFFHeader(major, minor, hdrSize, offSize);
  22136. return { obj: header, endPos: hdrSize };
  22137. },
  22138. parseDict: function CFFParser_parseDict(dict) {
  22139. var pos = 0;
  22140. function parseOperand() {
  22141. var value = dict[pos++];
  22142. if (value === 30) {
  22143. return parseFloatOperand(pos);
  22144. } else if (value === 28) {
  22145. value = dict[pos++];
  22146. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  22147. return value;
  22148. } else if (value === 29) {
  22149. value = dict[pos++];
  22150. value = (value << 8) | dict[pos++];
  22151. value = (value << 8) | dict[pos++];
  22152. value = (value << 8) | dict[pos++];
  22153. return value;
  22154. } else if (value >= 32 && value <= 246) {
  22155. return value - 139;
  22156. } else if (value >= 247 && value <= 250) {
  22157. return ((value - 247) * 256) + dict[pos++] + 108;
  22158. } else if (value >= 251 && value <= 254) {
  22159. return -((value - 251) * 256) - dict[pos++] - 108;
  22160. } else {
  22161. error('255 is not a valid DICT command');
  22162. }
  22163. return -1;
  22164. }
  22165. function parseFloatOperand() {
  22166. var str = '';
  22167. var eof = 15;
  22168. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  22169. '9', '.', 'E', 'E-', null, '-'];
  22170. var length = dict.length;
  22171. while (pos < length) {
  22172. var b = dict[pos++];
  22173. var b1 = b >> 4;
  22174. var b2 = b & 15;
  22175. if (b1 === eof) {
  22176. break;
  22177. }
  22178. str += lookup[b1];
  22179. if (b2 === eof) {
  22180. break;
  22181. }
  22182. str += lookup[b2];
  22183. }
  22184. return parseFloat(str);
  22185. }
  22186. var operands = [];
  22187. var entries = [];
  22188. pos = 0;
  22189. var end = dict.length;
  22190. while (pos < end) {
  22191. var b = dict[pos];
  22192. if (b <= 21) {
  22193. if (b === 12) {
  22194. b = (b << 8) | dict[++pos];
  22195. }
  22196. entries.push([b, operands]);
  22197. operands = [];
  22198. ++pos;
  22199. } else {
  22200. operands.push(parseOperand());
  22201. }
  22202. }
  22203. return entries;
  22204. },
  22205. parseIndex: function CFFParser_parseIndex(pos) {
  22206. var cffIndex = new CFFIndex();
  22207. var bytes = this.bytes;
  22208. var count = (bytes[pos++] << 8) | bytes[pos++];
  22209. var offsets = [];
  22210. var end = pos;
  22211. var i, ii;
  22212. if (count !== 0) {
  22213. var offsetSize = bytes[pos++];
  22214. // add 1 for offset to determine size of last object
  22215. var startPos = pos + ((count + 1) * offsetSize) - 1;
  22216. for (i = 0, ii = count + 1; i < ii; ++i) {
  22217. var offset = 0;
  22218. for (var j = 0; j < offsetSize; ++j) {
  22219. offset <<= 8;
  22220. offset += bytes[pos++];
  22221. }
  22222. offsets.push(startPos + offset);
  22223. }
  22224. end = offsets[count];
  22225. }
  22226. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  22227. var offsetStart = offsets[i];
  22228. var offsetEnd = offsets[i + 1];
  22229. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  22230. }
  22231. return {obj: cffIndex, endPos: end};
  22232. },
  22233. parseNameIndex: function CFFParser_parseNameIndex(index) {
  22234. var names = [];
  22235. for (var i = 0, ii = index.count; i < ii; ++i) {
  22236. var name = index.get(i);
  22237. // OTS doesn't allow names to be over 127 characters.
  22238. var length = Math.min(name.length, 127);
  22239. var data = [];
  22240. // OTS also only permits certain characters in the name.
  22241. for (var j = 0; j < length; ++j) {
  22242. var c = name[j];
  22243. if (j === 0 && c === 0) {
  22244. data[j] = c;
  22245. continue;
  22246. }
  22247. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  22248. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  22249. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  22250. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  22251. data[j] = 95;
  22252. continue;
  22253. }
  22254. data[j] = c;
  22255. }
  22256. names.push(bytesToString(data));
  22257. }
  22258. return names;
  22259. },
  22260. parseStringIndex: function CFFParser_parseStringIndex(index) {
  22261. var strings = new CFFStrings();
  22262. for (var i = 0, ii = index.count; i < ii; ++i) {
  22263. var data = index.get(i);
  22264. strings.add(bytesToString(data));
  22265. }
  22266. return strings;
  22267. },
  22268. createDict: function CFFParser_createDict(Type, dict, strings) {
  22269. var cffDict = new Type(strings);
  22270. for (var i = 0, ii = dict.length; i < ii; ++i) {
  22271. var pair = dict[i];
  22272. var key = pair[0];
  22273. var value = pair[1];
  22274. cffDict.setByKey(key, value);
  22275. }
  22276. return cffDict;
  22277. },
  22278. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  22279. var charStrings = this.parseIndex(charStringOffset).obj;
  22280. var seacs = [];
  22281. var count = charStrings.count;
  22282. for (var i = 0; i < count; i++) {
  22283. var charstring = charStrings.get(i);
  22284. var stackSize = 0;
  22285. var stack = [];
  22286. var undefStack = true;
  22287. var hints = 0;
  22288. var valid = true;
  22289. var data = charstring;
  22290. var length = data.length;
  22291. for (var j = 0; j < length;) {
  22292. var value = data[j++];
  22293. var validationCommand = null;
  22294. if (value === 12) {
  22295. var q = data[j++];
  22296. if (q === 0) {
  22297. // The CFF specification state that the 'dotsection' command
  22298. // (12, 0) is deprecated and treated as a no-op, but all Type2
  22299. // charstrings processors should support them. Unfortunately
  22300. // the font sanitizer don't. As a workaround the sequence (12, 0)
  22301. // is replaced by a useless (0, hmoveto).
  22302. data[j - 2] = 139;
  22303. data[j - 1] = 22;
  22304. stackSize = 0;
  22305. } else {
  22306. validationCommand = CharstringValidationData12[q];
  22307. }
  22308. } else if (value === 28) { // number (16 bit)
  22309. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  22310. j += 2;
  22311. stackSize++;
  22312. } else if (value === 14) {
  22313. if (stackSize >= 4) {
  22314. stackSize -= 4;
  22315. if (SEAC_ANALYSIS_ENABLED) {
  22316. seacs[i] = stack.slice(stackSize, stackSize + 4);
  22317. valid = false;
  22318. }
  22319. }
  22320. } else if (value >= 32 && value <= 246) { // number
  22321. stack[stackSize] = value - 139;
  22322. stackSize++;
  22323. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  22324. stack[stackSize] = (value < 251 ?
  22325. ((value - 247) << 8) + data[j] + 108 :
  22326. -((value - 251) << 8) - data[j] - 108);
  22327. j++;
  22328. stackSize++;
  22329. } else if (value === 255) { // number (32 bit)
  22330. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  22331. (data[j + 2] << 8) | data[j + 3]) / 65536;
  22332. j += 4;
  22333. stackSize++;
  22334. } else if (value === 19 || value === 20) {
  22335. hints += stackSize >> 1;
  22336. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  22337. stackSize = 0;
  22338. } else {
  22339. validationCommand = CharstringValidationData[value];
  22340. }
  22341. if (validationCommand) {
  22342. if (validationCommand.stem) {
  22343. hints += stackSize >> 1;
  22344. }
  22345. if ('min' in validationCommand) {
  22346. if (!undefStack && stackSize < validationCommand.min) {
  22347. warn('Not enough parameters for ' + validationCommand.id +
  22348. '; actual: ' + stackSize +
  22349. ', expected: ' + validationCommand.min);
  22350. valid = false;
  22351. break;
  22352. }
  22353. }
  22354. if ('stackDelta' in validationCommand) {
  22355. if ('stackFn' in validationCommand) {
  22356. validationCommand.stackFn(stack, stackSize);
  22357. }
  22358. stackSize += validationCommand.stackDelta;
  22359. } else if (validationCommand.resetStack) {
  22360. stackSize = 0;
  22361. undefStack = false;
  22362. } else if (validationCommand.undefStack) {
  22363. stackSize = 0;
  22364. undefStack = true;
  22365. }
  22366. }
  22367. }
  22368. if (!valid) {
  22369. // resetting invalid charstring to single 'endchar'
  22370. charStrings.set(i, new Uint8Array([14]));
  22371. }
  22372. }
  22373. return { charStrings: charStrings, seacs: seacs };
  22374. },
  22375. emptyPrivateDictionary:
  22376. function CFFParser_emptyPrivateDictionary(parentDict) {
  22377. var privateDict = this.createDict(CFFPrivateDict, [],
  22378. parentDict.strings);
  22379. parentDict.setByKey(18, [0, 0]);
  22380. parentDict.privateDict = privateDict;
  22381. },
  22382. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  22383. // no private dict, do nothing
  22384. if (!parentDict.hasName('Private')) {
  22385. this.emptyPrivateDictionary(parentDict);
  22386. return;
  22387. }
  22388. var privateOffset = parentDict.getByName('Private');
  22389. // make sure the params are formatted correctly
  22390. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  22391. parentDict.removeByName('Private');
  22392. return;
  22393. }
  22394. var size = privateOffset[0];
  22395. var offset = privateOffset[1];
  22396. // remove empty dicts or ones that refer to invalid location
  22397. if (size === 0 || offset >= this.bytes.length) {
  22398. this.emptyPrivateDictionary(parentDict);
  22399. return;
  22400. }
  22401. var privateDictEnd = offset + size;
  22402. var dictData = this.bytes.subarray(offset, privateDictEnd);
  22403. var dict = this.parseDict(dictData);
  22404. var privateDict = this.createDict(CFFPrivateDict, dict,
  22405. parentDict.strings);
  22406. parentDict.privateDict = privateDict;
  22407. // Parse the Subrs index also since it's relative to the private dict.
  22408. if (!privateDict.getByName('Subrs')) {
  22409. return;
  22410. }
  22411. var subrsOffset = privateDict.getByName('Subrs');
  22412. var relativeOffset = offset + subrsOffset;
  22413. // Validate the offset.
  22414. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  22415. this.emptyPrivateDictionary(parentDict);
  22416. return;
  22417. }
  22418. var subrsIndex = this.parseIndex(relativeOffset);
  22419. privateDict.subrsIndex = subrsIndex.obj;
  22420. },
  22421. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  22422. if (pos === 0) {
  22423. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  22424. ISOAdobeCharset);
  22425. } else if (pos === 1) {
  22426. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  22427. ExpertCharset);
  22428. } else if (pos === 2) {
  22429. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  22430. ExpertSubsetCharset);
  22431. }
  22432. var bytes = this.bytes;
  22433. var start = pos;
  22434. var format = bytes[pos++];
  22435. var charset = ['.notdef'];
  22436. var id, count, i;
  22437. // subtract 1 for the .notdef glyph
  22438. length -= 1;
  22439. switch (format) {
  22440. case 0:
  22441. for (i = 0; i < length; i++) {
  22442. id = (bytes[pos++] << 8) | bytes[pos++];
  22443. charset.push(cid ? id : strings.get(id));
  22444. }
  22445. break;
  22446. case 1:
  22447. while (charset.length <= length) {
  22448. id = (bytes[pos++] << 8) | bytes[pos++];
  22449. count = bytes[pos++];
  22450. for (i = 0; i <= count; i++) {
  22451. charset.push(cid ? id++ : strings.get(id++));
  22452. }
  22453. }
  22454. break;
  22455. case 2:
  22456. while (charset.length <= length) {
  22457. id = (bytes[pos++] << 8) | bytes[pos++];
  22458. count = (bytes[pos++] << 8) | bytes[pos++];
  22459. for (i = 0; i <= count; i++) {
  22460. charset.push(cid ? id++ : strings.get(id++));
  22461. }
  22462. }
  22463. break;
  22464. default:
  22465. error('Unknown charset format');
  22466. }
  22467. // Raw won't be needed if we actually compile the charset.
  22468. var end = pos;
  22469. var raw = bytes.subarray(start, end);
  22470. return new CFFCharset(false, format, charset, raw);
  22471. },
  22472. parseEncoding: function CFFParser_parseEncoding(pos,
  22473. properties,
  22474. strings,
  22475. charset) {
  22476. var encoding = {};
  22477. var bytes = this.bytes;
  22478. var predefined = false;
  22479. var hasSupplement = false;
  22480. var format, i, ii;
  22481. var raw = null;
  22482. function readSupplement() {
  22483. var supplementsCount = bytes[pos++];
  22484. for (i = 0; i < supplementsCount; i++) {
  22485. var code = bytes[pos++];
  22486. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  22487. encoding[code] = charset.indexOf(strings.get(sid));
  22488. }
  22489. }
  22490. if (pos === 0 || pos === 1) {
  22491. predefined = true;
  22492. format = pos;
  22493. var baseEncoding = pos ? Encodings.ExpertEncoding :
  22494. Encodings.StandardEncoding;
  22495. for (i = 0, ii = charset.length; i < ii; i++) {
  22496. var index = baseEncoding.indexOf(charset[i]);
  22497. if (index !== -1) {
  22498. encoding[index] = i;
  22499. }
  22500. }
  22501. } else {
  22502. var dataStart = pos;
  22503. format = bytes[pos++];
  22504. switch (format & 0x7f) {
  22505. case 0:
  22506. var glyphsCount = bytes[pos++];
  22507. for (i = 1; i <= glyphsCount; i++) {
  22508. encoding[bytes[pos++]] = i;
  22509. }
  22510. break;
  22511. case 1:
  22512. var rangesCount = bytes[pos++];
  22513. var gid = 1;
  22514. for (i = 0; i < rangesCount; i++) {
  22515. var start = bytes[pos++];
  22516. var left = bytes[pos++];
  22517. for (var j = start; j <= start + left; j++) {
  22518. encoding[j] = gid++;
  22519. }
  22520. }
  22521. break;
  22522. default:
  22523. error('Unknow encoding format: ' + format + ' in CFF');
  22524. break;
  22525. }
  22526. var dataEnd = pos;
  22527. if (format & 0x80) {
  22528. // The font sanitizer does not support CFF encoding with a
  22529. // supplement, since the encoding is not really used to map
  22530. // between gid to glyph, let's overwrite what is declared in
  22531. // the top dictionary to let the sanitizer think the font use
  22532. // StandardEncoding, that's a lie but that's ok.
  22533. bytes[dataStart] &= 0x7f;
  22534. readSupplement();
  22535. hasSupplement = true;
  22536. }
  22537. raw = bytes.subarray(dataStart, dataEnd);
  22538. }
  22539. format = format & 0x7f;
  22540. return new CFFEncoding(predefined, format, encoding, raw);
  22541. },
  22542. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  22543. var start = pos;
  22544. var bytes = this.bytes;
  22545. var format = bytes[pos++];
  22546. var fdSelect = [];
  22547. var i;
  22548. switch (format) {
  22549. case 0:
  22550. for (i = 0; i < length; ++i) {
  22551. var id = bytes[pos++];
  22552. fdSelect.push(id);
  22553. }
  22554. break;
  22555. case 3:
  22556. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  22557. for (i = 0; i < rangesCount; ++i) {
  22558. var first = (bytes[pos++] << 8) | bytes[pos++];
  22559. var fdIndex = bytes[pos++];
  22560. var next = (bytes[pos] << 8) | bytes[pos + 1];
  22561. for (var j = first; j < next; ++j) {
  22562. fdSelect.push(fdIndex);
  22563. }
  22564. }
  22565. // Advance past the sentinel(next).
  22566. pos += 2;
  22567. break;
  22568. default:
  22569. error('Unknown fdselect format ' + format);
  22570. break;
  22571. }
  22572. var end = pos;
  22573. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  22574. }
  22575. };
  22576. return CFFParser;
  22577. })();
  22578. // Compact Font Format
  22579. var CFF = (function CFFClosure() {
  22580. function CFF() {
  22581. this.header = null;
  22582. this.names = [];
  22583. this.topDict = null;
  22584. this.strings = new CFFStrings();
  22585. this.globalSubrIndex = null;
  22586. // The following could really be per font, but since we only have one font
  22587. // store them here.
  22588. this.encoding = null;
  22589. this.charset = null;
  22590. this.charStrings = null;
  22591. this.fdArray = [];
  22592. this.fdSelect = null;
  22593. this.isCIDFont = false;
  22594. }
  22595. return CFF;
  22596. })();
  22597. var CFFHeader = (function CFFHeaderClosure() {
  22598. function CFFHeader(major, minor, hdrSize, offSize) {
  22599. this.major = major;
  22600. this.minor = minor;
  22601. this.hdrSize = hdrSize;
  22602. this.offSize = offSize;
  22603. }
  22604. return CFFHeader;
  22605. })();
  22606. var CFFStrings = (function CFFStringsClosure() {
  22607. function CFFStrings() {
  22608. this.strings = [];
  22609. }
  22610. CFFStrings.prototype = {
  22611. get: function CFFStrings_get(index) {
  22612. if (index >= 0 && index <= 390) {
  22613. return CFFStandardStrings[index];
  22614. }
  22615. if (index - 391 <= this.strings.length) {
  22616. return this.strings[index - 391];
  22617. }
  22618. return CFFStandardStrings[0];
  22619. },
  22620. add: function CFFStrings_add(value) {
  22621. this.strings.push(value);
  22622. },
  22623. get count() {
  22624. return this.strings.length;
  22625. }
  22626. };
  22627. return CFFStrings;
  22628. })();
  22629. var CFFIndex = (function CFFIndexClosure() {
  22630. function CFFIndex() {
  22631. this.objects = [];
  22632. this.length = 0;
  22633. }
  22634. CFFIndex.prototype = {
  22635. add: function CFFIndex_add(data) {
  22636. this.length += data.length;
  22637. this.objects.push(data);
  22638. },
  22639. set: function CFFIndex_set(index, data) {
  22640. this.length += data.length - this.objects[index].length;
  22641. this.objects[index] = data;
  22642. },
  22643. get: function CFFIndex_get(index) {
  22644. return this.objects[index];
  22645. },
  22646. get count() {
  22647. return this.objects.length;
  22648. }
  22649. };
  22650. return CFFIndex;
  22651. })();
  22652. var CFFDict = (function CFFDictClosure() {
  22653. function CFFDict(tables, strings) {
  22654. this.keyToNameMap = tables.keyToNameMap;
  22655. this.nameToKeyMap = tables.nameToKeyMap;
  22656. this.defaults = tables.defaults;
  22657. this.types = tables.types;
  22658. this.opcodes = tables.opcodes;
  22659. this.order = tables.order;
  22660. this.strings = strings;
  22661. this.values = {};
  22662. }
  22663. CFFDict.prototype = {
  22664. // value should always be an array
  22665. setByKey: function CFFDict_setByKey(key, value) {
  22666. if (!(key in this.keyToNameMap)) {
  22667. return false;
  22668. }
  22669. // ignore empty values
  22670. if (value.length === 0) {
  22671. return true;
  22672. }
  22673. var type = this.types[key];
  22674. // remove the array wrapping these types of values
  22675. if (type === 'num' || type === 'sid' || type === 'offset') {
  22676. value = value[0];
  22677. }
  22678. this.values[key] = value;
  22679. return true;
  22680. },
  22681. setByName: function CFFDict_setByName(name, value) {
  22682. if (!(name in this.nameToKeyMap)) {
  22683. error('Invalid dictionary name "' + name + '"');
  22684. }
  22685. this.values[this.nameToKeyMap[name]] = value;
  22686. },
  22687. hasName: function CFFDict_hasName(name) {
  22688. return this.nameToKeyMap[name] in this.values;
  22689. },
  22690. getByName: function CFFDict_getByName(name) {
  22691. if (!(name in this.nameToKeyMap)) {
  22692. error('Invalid dictionary name "' + name + '"');
  22693. }
  22694. var key = this.nameToKeyMap[name];
  22695. if (!(key in this.values)) {
  22696. return this.defaults[key];
  22697. }
  22698. return this.values[key];
  22699. },
  22700. removeByName: function CFFDict_removeByName(name) {
  22701. delete this.values[this.nameToKeyMap[name]];
  22702. }
  22703. };
  22704. CFFDict.createTables = function CFFDict_createTables(layout) {
  22705. var tables = {
  22706. keyToNameMap: {},
  22707. nameToKeyMap: {},
  22708. defaults: {},
  22709. types: {},
  22710. opcodes: {},
  22711. order: []
  22712. };
  22713. for (var i = 0, ii = layout.length; i < ii; ++i) {
  22714. var entry = layout[i];
  22715. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  22716. tables.keyToNameMap[key] = entry[1];
  22717. tables.nameToKeyMap[entry[1]] = key;
  22718. tables.types[key] = entry[2];
  22719. tables.defaults[key] = entry[3];
  22720. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  22721. tables.order.push(key);
  22722. }
  22723. return tables;
  22724. };
  22725. return CFFDict;
  22726. })();
  22727. var CFFTopDict = (function CFFTopDictClosure() {
  22728. var layout = [
  22729. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  22730. [[12, 20], 'SyntheticBase', 'num', null],
  22731. [0, 'version', 'sid', null],
  22732. [1, 'Notice', 'sid', null],
  22733. [[12, 0], 'Copyright', 'sid', null],
  22734. [2, 'FullName', 'sid', null],
  22735. [3, 'FamilyName', 'sid', null],
  22736. [4, 'Weight', 'sid', null],
  22737. [[12, 1], 'isFixedPitch', 'num', 0],
  22738. [[12, 2], 'ItalicAngle', 'num', 0],
  22739. [[12, 3], 'UnderlinePosition', 'num', -100],
  22740. [[12, 4], 'UnderlineThickness', 'num', 50],
  22741. [[12, 5], 'PaintType', 'num', 0],
  22742. [[12, 6], 'CharstringType', 'num', 2],
  22743. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  22744. [0.001, 0, 0, 0.001, 0, 0]],
  22745. [13, 'UniqueID', 'num', null],
  22746. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  22747. [[12, 8], 'StrokeWidth', 'num', 0],
  22748. [14, 'XUID', 'array', null],
  22749. [15, 'charset', 'offset', 0],
  22750. [16, 'Encoding', 'offset', 0],
  22751. [17, 'CharStrings', 'offset', 0],
  22752. [18, 'Private', ['offset', 'offset'], null],
  22753. [[12, 21], 'PostScript', 'sid', null],
  22754. [[12, 22], 'BaseFontName', 'sid', null],
  22755. [[12, 23], 'BaseFontBlend', 'delta', null],
  22756. [[12, 31], 'CIDFontVersion', 'num', 0],
  22757. [[12, 32], 'CIDFontRevision', 'num', 0],
  22758. [[12, 33], 'CIDFontType', 'num', 0],
  22759. [[12, 34], 'CIDCount', 'num', 8720],
  22760. [[12, 35], 'UIDBase', 'num', null],
  22761. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  22762. // before FDArray.
  22763. [[12, 37], 'FDSelect', 'offset', null],
  22764. [[12, 36], 'FDArray', 'offset', null],
  22765. [[12, 38], 'FontName', 'sid', null]
  22766. ];
  22767. var tables = null;
  22768. function CFFTopDict(strings) {
  22769. if (tables === null) {
  22770. tables = CFFDict.createTables(layout);
  22771. }
  22772. CFFDict.call(this, tables, strings);
  22773. this.privateDict = null;
  22774. }
  22775. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  22776. return CFFTopDict;
  22777. })();
  22778. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  22779. var layout = [
  22780. [6, 'BlueValues', 'delta', null],
  22781. [7, 'OtherBlues', 'delta', null],
  22782. [8, 'FamilyBlues', 'delta', null],
  22783. [9, 'FamilyOtherBlues', 'delta', null],
  22784. [[12, 9], 'BlueScale', 'num', 0.039625],
  22785. [[12, 10], 'BlueShift', 'num', 7],
  22786. [[12, 11], 'BlueFuzz', 'num', 1],
  22787. [10, 'StdHW', 'num', null],
  22788. [11, 'StdVW', 'num', null],
  22789. [[12, 12], 'StemSnapH', 'delta', null],
  22790. [[12, 13], 'StemSnapV', 'delta', null],
  22791. [[12, 14], 'ForceBold', 'num', 0],
  22792. [[12, 17], 'LanguageGroup', 'num', 0],
  22793. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  22794. [[12, 19], 'initialRandomSeed', 'num', 0],
  22795. [20, 'defaultWidthX', 'num', 0],
  22796. [21, 'nominalWidthX', 'num', 0],
  22797. [19, 'Subrs', 'offset', null]
  22798. ];
  22799. var tables = null;
  22800. function CFFPrivateDict(strings) {
  22801. if (tables === null) {
  22802. tables = CFFDict.createTables(layout);
  22803. }
  22804. CFFDict.call(this, tables, strings);
  22805. this.subrsIndex = null;
  22806. }
  22807. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  22808. return CFFPrivateDict;
  22809. })();
  22810. var CFFCharsetPredefinedTypes = {
  22811. ISO_ADOBE: 0,
  22812. EXPERT: 1,
  22813. EXPERT_SUBSET: 2
  22814. };
  22815. var CFFCharset = (function CFFCharsetClosure() {
  22816. function CFFCharset(predefined, format, charset, raw) {
  22817. this.predefined = predefined;
  22818. this.format = format;
  22819. this.charset = charset;
  22820. this.raw = raw;
  22821. }
  22822. return CFFCharset;
  22823. })();
  22824. var CFFEncoding = (function CFFEncodingClosure() {
  22825. function CFFEncoding(predefined, format, encoding, raw) {
  22826. this.predefined = predefined;
  22827. this.format = format;
  22828. this.encoding = encoding;
  22829. this.raw = raw;
  22830. }
  22831. return CFFEncoding;
  22832. })();
  22833. var CFFFDSelect = (function CFFFDSelectClosure() {
  22834. function CFFFDSelect(fdSelect, raw) {
  22835. this.fdSelect = fdSelect;
  22836. this.raw = raw;
  22837. }
  22838. return CFFFDSelect;
  22839. })();
  22840. // Helper class to keep track of where an offset is within the data and helps
  22841. // filling in that offset once it's known.
  22842. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  22843. function CFFOffsetTracker() {
  22844. this.offsets = {};
  22845. }
  22846. CFFOffsetTracker.prototype = {
  22847. isTracking: function CFFOffsetTracker_isTracking(key) {
  22848. return key in this.offsets;
  22849. },
  22850. track: function CFFOffsetTracker_track(key, location) {
  22851. if (key in this.offsets) {
  22852. error('Already tracking location of ' + key);
  22853. }
  22854. this.offsets[key] = location;
  22855. },
  22856. offset: function CFFOffsetTracker_offset(value) {
  22857. for (var key in this.offsets) {
  22858. this.offsets[key] += value;
  22859. }
  22860. },
  22861. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  22862. values,
  22863. output) {
  22864. if (!(key in this.offsets)) {
  22865. error('Not tracking location of ' + key);
  22866. }
  22867. var data = output.data;
  22868. var dataOffset = this.offsets[key];
  22869. var size = 5;
  22870. for (var i = 0, ii = values.length; i < ii; ++i) {
  22871. var offset0 = i * size + dataOffset;
  22872. var offset1 = offset0 + 1;
  22873. var offset2 = offset0 + 2;
  22874. var offset3 = offset0 + 3;
  22875. var offset4 = offset0 + 4;
  22876. // It's easy to screw up offsets so perform this sanity check.
  22877. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  22878. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  22879. error('writing to an offset that is not empty');
  22880. }
  22881. var value = values[i];
  22882. data[offset0] = 0x1d;
  22883. data[offset1] = (value >> 24) & 0xFF;
  22884. data[offset2] = (value >> 16) & 0xFF;
  22885. data[offset3] = (value >> 8) & 0xFF;
  22886. data[offset4] = value & 0xFF;
  22887. }
  22888. }
  22889. };
  22890. return CFFOffsetTracker;
  22891. })();
  22892. // Takes a CFF and converts it to the binary representation.
  22893. var CFFCompiler = (function CFFCompilerClosure() {
  22894. function CFFCompiler(cff) {
  22895. this.cff = cff;
  22896. }
  22897. CFFCompiler.prototype = {
  22898. compile: function CFFCompiler_compile() {
  22899. var cff = this.cff;
  22900. var output = {
  22901. data: [],
  22902. length: 0,
  22903. add: function CFFCompiler_add(data) {
  22904. this.data = this.data.concat(data);
  22905. this.length = this.data.length;
  22906. }
  22907. };
  22908. // Compile the five entries that must be in order.
  22909. var header = this.compileHeader(cff.header);
  22910. output.add(header);
  22911. var nameIndex = this.compileNameIndex(cff.names);
  22912. output.add(nameIndex);
  22913. if (cff.isCIDFont) {
  22914. // The spec is unclear on how font matrices should relate to each other
  22915. // when there is one in the main top dict and the sub top dicts.
  22916. // Windows handles this differently than linux and osx so we have to
  22917. // normalize to work on all.
  22918. // Rules based off of some mailing list discussions:
  22919. // - If main font has a matrix and subfont doesn't, use the main matrix.
  22920. // - If no main font matrix and there is a subfont matrix, use the
  22921. // subfont matrix.
  22922. // - If both have matrices, concat together.
  22923. // - If neither have matrices, use default.
  22924. // To make this work on all platforms we move the top matrix into each
  22925. // sub top dict and concat if necessary.
  22926. if (cff.topDict.hasName('FontMatrix')) {
  22927. var base = cff.topDict.getByName('FontMatrix');
  22928. cff.topDict.removeByName('FontMatrix');
  22929. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  22930. var subDict = cff.fdArray[i];
  22931. var matrix = base.slice(0);
  22932. if (subDict.hasName('FontMatrix')) {
  22933. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  22934. }
  22935. subDict.setByName('FontMatrix', matrix);
  22936. }
  22937. }
  22938. }
  22939. var compiled = this.compileTopDicts([cff.topDict],
  22940. output.length,
  22941. cff.isCIDFont);
  22942. output.add(compiled.output);
  22943. var topDictTracker = compiled.trackers[0];
  22944. var stringIndex = this.compileStringIndex(cff.strings.strings);
  22945. output.add(stringIndex);
  22946. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  22947. output.add(globalSubrIndex);
  22948. // Now start on the other entries that have no specfic order.
  22949. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  22950. if (cff.encoding.predefined) {
  22951. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  22952. output);
  22953. } else {
  22954. var encoding = this.compileEncoding(cff.encoding);
  22955. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  22956. output.add(encoding);
  22957. }
  22958. }
  22959. if (cff.charset && cff.topDict.hasName('charset')) {
  22960. if (cff.charset.predefined) {
  22961. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  22962. output);
  22963. } else {
  22964. var charset = this.compileCharset(cff.charset);
  22965. topDictTracker.setEntryLocation('charset', [output.length], output);
  22966. output.add(charset);
  22967. }
  22968. }
  22969. var charStrings = this.compileCharStrings(cff.charStrings);
  22970. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  22971. output.add(charStrings);
  22972. if (cff.isCIDFont) {
  22973. // For some reason FDSelect must be in front of FDArray on windows. OSX
  22974. // and linux don't seem to care.
  22975. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  22976. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  22977. output.add(fdSelect);
  22978. // It is unclear if the sub font dictionary can have CID related
  22979. // dictionary keys, but the sanitizer doesn't like them so remove them.
  22980. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  22981. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  22982. output.add(compiled.output);
  22983. var fontDictTrackers = compiled.trackers;
  22984. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  22985. }
  22986. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  22987. // If the font data ends with INDEX whose object data is zero-length,
  22988. // the sanitizer will bail out. Add a dummy byte to avoid that.
  22989. output.add([0]);
  22990. return output.data;
  22991. },
  22992. encodeNumber: function CFFCompiler_encodeNumber(value) {
  22993. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  22994. return this.encodeInteger(value);
  22995. } else {
  22996. return this.encodeFloat(value);
  22997. }
  22998. },
  22999. encodeFloat: function CFFCompiler_encodeFloat(num) {
  23000. var value = num.toString();
  23001. // rounding inaccurate doubles
  23002. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  23003. if (m) {
  23004. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  23005. value = (Math.round(num * epsilon) / epsilon).toString();
  23006. }
  23007. var nibbles = '';
  23008. var i, ii;
  23009. for (i = 0, ii = value.length; i < ii; ++i) {
  23010. var a = value[i];
  23011. if (a === 'e') {
  23012. nibbles += value[++i] === '-' ? 'c' : 'b';
  23013. } else if (a === '.') {
  23014. nibbles += 'a';
  23015. } else if (a === '-') {
  23016. nibbles += 'e';
  23017. } else {
  23018. nibbles += a;
  23019. }
  23020. }
  23021. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  23022. var out = [30];
  23023. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  23024. out.push(parseInt(nibbles.substr(i, 2), 16));
  23025. }
  23026. return out;
  23027. },
  23028. encodeInteger: function CFFCompiler_encodeInteger(value) {
  23029. var code;
  23030. if (value >= -107 && value <= 107) {
  23031. code = [value + 139];
  23032. } else if (value >= 108 && value <= 1131) {
  23033. value = [value - 108];
  23034. code = [(value >> 8) + 247, value & 0xFF];
  23035. } else if (value >= -1131 && value <= -108) {
  23036. value = -value - 108;
  23037. code = [(value >> 8) + 251, value & 0xFF];
  23038. } else if (value >= -32768 && value <= 32767) {
  23039. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  23040. } else {
  23041. code = [0x1d,
  23042. (value >> 24) & 0xFF,
  23043. (value >> 16) & 0xFF,
  23044. (value >> 8) & 0xFF,
  23045. value & 0xFF];
  23046. }
  23047. return code;
  23048. },
  23049. compileHeader: function CFFCompiler_compileHeader(header) {
  23050. return [
  23051. header.major,
  23052. header.minor,
  23053. header.hdrSize,
  23054. header.offSize
  23055. ];
  23056. },
  23057. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  23058. var nameIndex = new CFFIndex();
  23059. for (var i = 0, ii = names.length; i < ii; ++i) {
  23060. nameIndex.add(stringToArray(names[i]));
  23061. }
  23062. return this.compileIndex(nameIndex);
  23063. },
  23064. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  23065. length,
  23066. removeCidKeys) {
  23067. var fontDictTrackers = [];
  23068. var fdArrayIndex = new CFFIndex();
  23069. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  23070. var fontDict = dicts[i];
  23071. if (removeCidKeys) {
  23072. fontDict.removeByName('CIDFontVersion');
  23073. fontDict.removeByName('CIDFontRevision');
  23074. fontDict.removeByName('CIDFontType');
  23075. fontDict.removeByName('CIDCount');
  23076. fontDict.removeByName('UIDBase');
  23077. }
  23078. var fontDictTracker = new CFFOffsetTracker();
  23079. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  23080. fontDictTrackers.push(fontDictTracker);
  23081. fdArrayIndex.add(fontDictData);
  23082. fontDictTracker.offset(length);
  23083. }
  23084. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  23085. return {
  23086. trackers: fontDictTrackers,
  23087. output: fdArrayIndex
  23088. };
  23089. },
  23090. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  23091. trackers,
  23092. output) {
  23093. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  23094. var fontDict = dicts[i];
  23095. assert(fontDict.privateDict && fontDict.hasName('Private'),
  23096. 'There must be an private dictionary.');
  23097. var privateDict = fontDict.privateDict;
  23098. var privateDictTracker = new CFFOffsetTracker();
  23099. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  23100. var outputLength = output.length;
  23101. privateDictTracker.offset(outputLength);
  23102. if (!privateDictData.length) {
  23103. // The private dictionary was empty, set the output length to zero to
  23104. // ensure the offset length isn't out of bounds in the eyes of the
  23105. // sanitizer.
  23106. outputLength = 0;
  23107. }
  23108. trackers[i].setEntryLocation('Private',
  23109. [privateDictData.length, outputLength],
  23110. output);
  23111. output.add(privateDictData);
  23112. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  23113. var subrs = this.compileIndex(privateDict.subrsIndex);
  23114. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  23115. output);
  23116. output.add(subrs);
  23117. }
  23118. }
  23119. },
  23120. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  23121. var out = [];
  23122. // The dictionary keys must be in a certain order.
  23123. var order = dict.order;
  23124. for (var i = 0; i < order.length; ++i) {
  23125. var key = order[i];
  23126. if (!(key in dict.values)) {
  23127. continue;
  23128. }
  23129. var values = dict.values[key];
  23130. var types = dict.types[key];
  23131. if (!isArray(types)) {
  23132. types = [types];
  23133. }
  23134. if (!isArray(values)) {
  23135. values = [values];
  23136. }
  23137. // Remove any empty dict values.
  23138. if (values.length === 0) {
  23139. continue;
  23140. }
  23141. for (var j = 0, jj = types.length; j < jj; ++j) {
  23142. var type = types[j];
  23143. var value = values[j];
  23144. switch (type) {
  23145. case 'num':
  23146. case 'sid':
  23147. out = out.concat(this.encodeNumber(value));
  23148. break;
  23149. case 'offset':
  23150. // For offsets we just insert a 32bit integer so we don't have to
  23151. // deal with figuring out the length of the offset when it gets
  23152. // replaced later on by the compiler.
  23153. var name = dict.keyToNameMap[key];
  23154. // Some offsets have the offset and the length, so just record the
  23155. // position of the first one.
  23156. if (!offsetTracker.isTracking(name)) {
  23157. offsetTracker.track(name, out.length);
  23158. }
  23159. out = out.concat([0x1d, 0, 0, 0, 0]);
  23160. break;
  23161. case 'array':
  23162. case 'delta':
  23163. out = out.concat(this.encodeNumber(value));
  23164. for (var k = 1, kk = values.length; k < kk; ++k) {
  23165. out = out.concat(this.encodeNumber(values[k]));
  23166. }
  23167. break;
  23168. default:
  23169. error('Unknown data type of ' + type);
  23170. break;
  23171. }
  23172. }
  23173. out = out.concat(dict.opcodes[key]);
  23174. }
  23175. return out;
  23176. },
  23177. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  23178. var stringIndex = new CFFIndex();
  23179. for (var i = 0, ii = strings.length; i < ii; ++i) {
  23180. stringIndex.add(stringToArray(strings[i]));
  23181. }
  23182. return this.compileIndex(stringIndex);
  23183. },
  23184. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  23185. var globalSubrIndex = this.cff.globalSubrIndex;
  23186. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  23187. },
  23188. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  23189. return this.compileIndex(charStrings);
  23190. },
  23191. compileCharset: function CFFCompiler_compileCharset(charset) {
  23192. return this.compileTypedArray(charset.raw);
  23193. },
  23194. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  23195. return this.compileTypedArray(encoding.raw);
  23196. },
  23197. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  23198. return this.compileTypedArray(fdSelect);
  23199. },
  23200. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  23201. var out = [];
  23202. for (var i = 0, ii = data.length; i < ii; ++i) {
  23203. out[i] = data[i];
  23204. }
  23205. return out;
  23206. },
  23207. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  23208. trackers = trackers || [];
  23209. var objects = index.objects;
  23210. // First 2 bytes contains the number of objects contained into this index
  23211. var count = objects.length;
  23212. // If there is no object, just create an index. This technically
  23213. // should just be [0, 0] but OTS has an issue with that.
  23214. if (count === 0) {
  23215. return [0, 0, 0];
  23216. }
  23217. var data = [(count >> 8) & 0xFF, count & 0xff];
  23218. var lastOffset = 1, i;
  23219. for (i = 0; i < count; ++i) {
  23220. lastOffset += objects[i].length;
  23221. }
  23222. var offsetSize;
  23223. if (lastOffset < 0x100) {
  23224. offsetSize = 1;
  23225. } else if (lastOffset < 0x10000) {
  23226. offsetSize = 2;
  23227. } else if (lastOffset < 0x1000000) {
  23228. offsetSize = 3;
  23229. } else {
  23230. offsetSize = 4;
  23231. }
  23232. // Next byte contains the offset size use to reference object in the file
  23233. data.push(offsetSize);
  23234. // Add another offset after this one because we need a new offset
  23235. var relativeOffset = 1;
  23236. for (i = 0; i < count + 1; i++) {
  23237. if (offsetSize === 1) {
  23238. data.push(relativeOffset & 0xFF);
  23239. } else if (offsetSize === 2) {
  23240. data.push((relativeOffset >> 8) & 0xFF,
  23241. relativeOffset & 0xFF);
  23242. } else if (offsetSize === 3) {
  23243. data.push((relativeOffset >> 16) & 0xFF,
  23244. (relativeOffset >> 8) & 0xFF,
  23245. relativeOffset & 0xFF);
  23246. } else {
  23247. data.push((relativeOffset >>> 24) & 0xFF,
  23248. (relativeOffset >> 16) & 0xFF,
  23249. (relativeOffset >> 8) & 0xFF,
  23250. relativeOffset & 0xFF);
  23251. }
  23252. if (objects[i]) {
  23253. relativeOffset += objects[i].length;
  23254. }
  23255. }
  23256. for (i = 0; i < count; i++) {
  23257. // Notify the tracker where the object will be offset in the data.
  23258. if (trackers[i]) {
  23259. trackers[i].offset(data.length);
  23260. }
  23261. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  23262. data.push(objects[i][j]);
  23263. }
  23264. }
  23265. return data;
  23266. }
  23267. };
  23268. return CFFCompiler;
  23269. })();
  23270. // Workaround for seac on Windows.
  23271. (function checkSeacSupport() {
  23272. if (/Windows/.test(navigator.userAgent)) {
  23273. SEAC_ANALYSIS_ENABLED = true;
  23274. }
  23275. })();
  23276. // Workaround for Private Use Area characters in Chrome on Windows
  23277. // http://code.google.com/p/chromium/issues/detail?id=122465
  23278. // https://github.com/mozilla/pdf.js/issues/1689
  23279. (function checkChromeWindows() {
  23280. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  23281. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  23282. }
  23283. })();
  23284. var FontRendererFactory = (function FontRendererFactoryClosure() {
  23285. function getLong(data, offset) {
  23286. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23287. (data[offset + 2] << 8) | data[offset + 3];
  23288. }
  23289. function getUshort(data, offset) {
  23290. return (data[offset] << 8) | data[offset + 1];
  23291. }
  23292. function parseCmap(data, start, end) {
  23293. var offset = (getUshort(data, start + 2) === 1 ?
  23294. getLong(data, start + 8) : getLong(data, start + 16));
  23295. var format = getUshort(data, start + offset);
  23296. var length, ranges, p, i;
  23297. if (format === 4) {
  23298. length = getUshort(data, start + offset + 2);
  23299. var segCount = getUshort(data, start + offset + 6) >> 1;
  23300. p = start + offset + 14;
  23301. ranges = [];
  23302. for (i = 0; i < segCount; i++, p += 2) {
  23303. ranges[i] = {end: getUshort(data, p)};
  23304. }
  23305. p += 2;
  23306. for (i = 0; i < segCount; i++, p += 2) {
  23307. ranges[i].start = getUshort(data, p);
  23308. }
  23309. for (i = 0; i < segCount; i++, p += 2) {
  23310. ranges[i].idDelta = getUshort(data, p);
  23311. }
  23312. for (i = 0; i < segCount; i++, p += 2) {
  23313. var idOffset = getUshort(data, p);
  23314. if (idOffset === 0) {
  23315. continue;
  23316. }
  23317. ranges[i].ids = [];
  23318. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  23319. ranges[i].ids[j] = getUshort(data, p + idOffset);
  23320. idOffset += 2;
  23321. }
  23322. }
  23323. return ranges;
  23324. } else if (format === 12) {
  23325. length = getLong(data, start + offset + 4);
  23326. var groups = getLong(data, start + offset + 12);
  23327. p = start + offset + 16;
  23328. ranges = [];
  23329. for (i = 0; i < groups; i++) {
  23330. ranges.push({
  23331. start: getLong(data, p),
  23332. end: getLong(data, p + 4),
  23333. idDelta: getLong(data, p + 8) - getLong(data, p)
  23334. });
  23335. p += 12;
  23336. }
  23337. return ranges;
  23338. }
  23339. error('not supported cmap: ' + format);
  23340. }
  23341. function parseCff(data, start, end) {
  23342. var properties = {};
  23343. var parser = new CFFParser(new Stream(data, start, end - start),
  23344. properties);
  23345. var cff = parser.parse();
  23346. return {
  23347. glyphs: cff.charStrings.objects,
  23348. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  23349. cff.topDict.privateDict.subrsIndex.objects),
  23350. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  23351. };
  23352. }
  23353. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  23354. var itemSize, itemDecode;
  23355. if (isGlyphLocationsLong) {
  23356. itemSize = 4;
  23357. itemDecode = function fontItemDecodeLong(data, offset) {
  23358. return (data[offset] << 24) | (data[offset + 1] << 16) |
  23359. (data[offset + 2] << 8) | data[offset + 3];
  23360. };
  23361. } else {
  23362. itemSize = 2;
  23363. itemDecode = function fontItemDecode(data, offset) {
  23364. return (data[offset] << 9) | (data[offset + 1] << 1);
  23365. };
  23366. }
  23367. var glyphs = [];
  23368. var startOffset = itemDecode(loca, 0);
  23369. for (var j = itemSize; j < loca.length; j += itemSize) {
  23370. var endOffset = itemDecode(loca, j);
  23371. glyphs.push(glyf.subarray(startOffset, endOffset));
  23372. startOffset = endOffset;
  23373. }
  23374. return glyphs;
  23375. }
  23376. function lookupCmap(ranges, unicode) {
  23377. var code = unicode.charCodeAt(0);
  23378. var l = 0, r = ranges.length - 1;
  23379. while (l < r) {
  23380. var c = (l + r + 1) >> 1;
  23381. if (code < ranges[c].start) {
  23382. r = c - 1;
  23383. } else {
  23384. l = c;
  23385. }
  23386. }
  23387. if (ranges[l].start <= code && code <= ranges[l].end) {
  23388. return (ranges[l].idDelta + (ranges[l].ids ?
  23389. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  23390. }
  23391. return 0;
  23392. }
  23393. function compileGlyf(code, js, font) {
  23394. function moveTo(x, y) {
  23395. js.push('c.moveTo(' + x + ',' + y + ');');
  23396. }
  23397. function lineTo(x, y) {
  23398. js.push('c.lineTo(' + x + ',' + y + ');');
  23399. }
  23400. function quadraticCurveTo(xa, ya, x, y) {
  23401. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  23402. x + ',' + y + ');');
  23403. }
  23404. var i = 0;
  23405. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23406. var flags;
  23407. var x = 0, y = 0;
  23408. i += 10;
  23409. if (numberOfContours < 0) {
  23410. // composite glyph
  23411. do {
  23412. flags = (code[i] << 8) | code[i + 1];
  23413. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  23414. i += 4;
  23415. var arg1, arg2;
  23416. if ((flags & 0x01)) {
  23417. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23418. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  23419. i += 4;
  23420. } else {
  23421. arg1 = code[i++]; arg2 = code[i++];
  23422. }
  23423. if ((flags & 0x02)) {
  23424. x = arg1;
  23425. y = arg2;
  23426. } else {
  23427. x = 0; y = 0; // TODO "they are points" ?
  23428. }
  23429. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  23430. if ((flags & 0x08)) {
  23431. scaleX =
  23432. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23433. i += 2;
  23434. } else if ((flags & 0x40)) {
  23435. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23436. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23437. i += 4;
  23438. } else if ((flags & 0x80)) {
  23439. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  23440. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  23441. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  23442. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  23443. i += 8;
  23444. }
  23445. var subglyph = font.glyphs[glyphIndex];
  23446. if (subglyph) {
  23447. js.push('c.save();');
  23448. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  23449. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  23450. compileGlyf(subglyph, js, font);
  23451. js.push('c.restore();');
  23452. }
  23453. } while ((flags & 0x20));
  23454. } else {
  23455. // simple glyph
  23456. var endPtsOfContours = [];
  23457. var j, jj;
  23458. for (j = 0; j < numberOfContours; j++) {
  23459. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  23460. i += 2;
  23461. }
  23462. var instructionLength = (code[i] << 8) | code[i + 1];
  23463. i += 2 + instructionLength; // skipping the instructions
  23464. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  23465. var points = [];
  23466. while (points.length < numberOfPoints) {
  23467. flags = code[i++];
  23468. var repeat = 1;
  23469. if ((flags & 0x08)) {
  23470. repeat += code[i++];
  23471. }
  23472. while (repeat-- > 0) {
  23473. points.push({flags: flags});
  23474. }
  23475. }
  23476. for (j = 0; j < numberOfPoints; j++) {
  23477. switch (points[j].flags & 0x12) {
  23478. case 0x00:
  23479. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23480. i += 2;
  23481. break;
  23482. case 0x02:
  23483. x -= code[i++];
  23484. break;
  23485. case 0x12:
  23486. x += code[i++];
  23487. break;
  23488. }
  23489. points[j].x = x;
  23490. }
  23491. for (j = 0; j < numberOfPoints; j++) {
  23492. switch (points[j].flags & 0x24) {
  23493. case 0x00:
  23494. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  23495. i += 2;
  23496. break;
  23497. case 0x04:
  23498. y -= code[i++];
  23499. break;
  23500. case 0x24:
  23501. y += code[i++];
  23502. break;
  23503. }
  23504. points[j].y = y;
  23505. }
  23506. var startPoint = 0;
  23507. for (i = 0; i < numberOfContours; i++) {
  23508. var endPoint = endPtsOfContours[i];
  23509. // contours might have implicit points, which is located in the middle
  23510. // between two neighboring off-curve points
  23511. var contour = points.slice(startPoint, endPoint + 1);
  23512. if ((contour[0].flags & 1)) {
  23513. contour.push(contour[0]); // using start point at the contour end
  23514. } else if ((contour[contour.length - 1].flags & 1)) {
  23515. // first is off-curve point, trying to use one from the end
  23516. contour.unshift(contour[contour.length - 1]);
  23517. } else {
  23518. // start and end are off-curve points, creating implicit one
  23519. var p = {
  23520. flags: 1,
  23521. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  23522. y: (contour[0].y + contour[contour.length - 1].y) / 2
  23523. };
  23524. contour.unshift(p);
  23525. contour.push(p);
  23526. }
  23527. moveTo(contour[0].x, contour[0].y);
  23528. for (j = 1, jj = contour.length; j < jj; j++) {
  23529. if ((contour[j].flags & 1)) {
  23530. lineTo(contour[j].x, contour[j].y);
  23531. } else if ((contour[j + 1].flags & 1)){
  23532. quadraticCurveTo(contour[j].x, contour[j].y,
  23533. contour[j + 1].x, contour[j + 1].y);
  23534. j++;
  23535. } else {
  23536. quadraticCurveTo(contour[j].x, contour[j].y,
  23537. (contour[j].x + contour[j + 1].x) / 2,
  23538. (contour[j].y + contour[j + 1].y) / 2);
  23539. }
  23540. }
  23541. startPoint = endPoint + 1;
  23542. }
  23543. }
  23544. }
  23545. function compileCharString(code, js, font) {
  23546. var stack = [];
  23547. var x = 0, y = 0;
  23548. var stems = 0;
  23549. function moveTo(x, y) {
  23550. js.push('c.moveTo(' + x + ',' + y + ');');
  23551. }
  23552. function lineTo(x, y) {
  23553. js.push('c.lineTo(' + x + ',' + y + ');');
  23554. }
  23555. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  23556. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  23557. x + ',' + y + ');');
  23558. }
  23559. function parse(code) {
  23560. var i = 0;
  23561. while (i < code.length) {
  23562. var stackClean = false;
  23563. var v = code[i++];
  23564. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  23565. switch (v) {
  23566. case 1: // hstem
  23567. stems += stack.length >> 1;
  23568. stackClean = true;
  23569. break;
  23570. case 3: // vstem
  23571. stems += stack.length >> 1;
  23572. stackClean = true;
  23573. break;
  23574. case 4: // vmoveto
  23575. y += stack.pop();
  23576. moveTo(x, y);
  23577. stackClean = true;
  23578. break;
  23579. case 5: // rlineto
  23580. while (stack.length > 0) {
  23581. x += stack.shift();
  23582. y += stack.shift();
  23583. lineTo(x, y);
  23584. }
  23585. break;
  23586. case 6: // hlineto
  23587. while (stack.length > 0) {
  23588. x += stack.shift();
  23589. lineTo(x, y);
  23590. if (stack.length === 0) {
  23591. break;
  23592. }
  23593. y += stack.shift();
  23594. lineTo(x, y);
  23595. }
  23596. break;
  23597. case 7: // vlineto
  23598. while (stack.length > 0) {
  23599. y += stack.shift();
  23600. lineTo(x, y);
  23601. if (stack.length === 0) {
  23602. break;
  23603. }
  23604. x += stack.shift();
  23605. lineTo(x, y);
  23606. }
  23607. break;
  23608. case 8: // rrcurveto
  23609. while (stack.length > 0) {
  23610. xa = x + stack.shift(); ya = y + stack.shift();
  23611. xb = xa + stack.shift(); yb = ya + stack.shift();
  23612. x = xb + stack.shift(); y = yb + stack.shift();
  23613. bezierCurveTo(xa, ya, xb, yb, x, y);
  23614. }
  23615. break;
  23616. case 10: // callsubr
  23617. n = stack.pop() + font.subrsBias;
  23618. subrCode = font.subrs[n];
  23619. if (subrCode) {
  23620. parse(subrCode);
  23621. }
  23622. break;
  23623. case 11: // return
  23624. return;
  23625. case 12:
  23626. v = code[i++];
  23627. switch (v) {
  23628. case 34: // flex
  23629. xa = x + stack.shift();
  23630. xb = xa + stack.shift(); y1 = y + stack.shift();
  23631. x = xb + stack.shift();
  23632. bezierCurveTo(xa, y, xb, y1, x, y1);
  23633. xa = x + stack.shift();
  23634. xb = xa + stack.shift();
  23635. x = xb + stack.shift();
  23636. bezierCurveTo(xa, y1, xb, y, x, y);
  23637. break;
  23638. case 35: // flex
  23639. xa = x + stack.shift(); ya = y + stack.shift();
  23640. xb = xa + stack.shift(); yb = ya + stack.shift();
  23641. x = xb + stack.shift(); y = yb + stack.shift();
  23642. bezierCurveTo(xa, ya, xb, yb, x, y);
  23643. xa = x + stack.shift(); ya = y + stack.shift();
  23644. xb = xa + stack.shift(); yb = ya + stack.shift();
  23645. x = xb + stack.shift(); y = yb + stack.shift();
  23646. bezierCurveTo(xa, ya, xb, yb, x, y);
  23647. stack.pop(); // fd
  23648. break;
  23649. case 36: // hflex1
  23650. xa = x + stack.shift(); y1 = y + stack.shift();
  23651. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  23652. x = xb + stack.shift();
  23653. bezierCurveTo(xa, y1, xb, y2, x, y2);
  23654. xa = x + stack.shift();
  23655. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  23656. x = xb + stack.shift();
  23657. bezierCurveTo(xa, y2, xb, y3, x, y);
  23658. break;
  23659. case 37: // flex1
  23660. var x0 = x, y0 = y;
  23661. xa = x + stack.shift(); ya = y + stack.shift();
  23662. xb = xa + stack.shift(); yb = ya + stack.shift();
  23663. x = xb + stack.shift(); y = yb + stack.shift();
  23664. bezierCurveTo(xa, ya, xb, yb, x, y);
  23665. xa = x + stack.shift(); ya = y + stack.shift();
  23666. xb = xa + stack.shift(); yb = ya + stack.shift();
  23667. x = xb; y = yb;
  23668. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  23669. x += stack.shift();
  23670. } else {
  23671. y += stack.shift();
  23672. }
  23673. bezierCurveTo(xa, ya, xb, yb, x, y);
  23674. break;
  23675. default:
  23676. error('unknown operator: 12 ' + v);
  23677. }
  23678. break;
  23679. case 14: // endchar
  23680. if (stack.length >= 4) {
  23681. var achar = stack.pop();
  23682. var bchar = stack.pop();
  23683. y = stack.pop();
  23684. x = stack.pop();
  23685. js.push('c.save();');
  23686. js.push('c.translate('+ x + ',' + y + ');');
  23687. var gid = lookupCmap(font.cmap, String.fromCharCode(
  23688. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  23689. compileCharString(font.glyphs[gid], js, font);
  23690. js.push('c.restore();');
  23691. gid = lookupCmap(font.cmap, String.fromCharCode(
  23692. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  23693. compileCharString(font.glyphs[gid], js, font);
  23694. }
  23695. return;
  23696. case 18: // hstemhm
  23697. stems += stack.length >> 1;
  23698. stackClean = true;
  23699. break;
  23700. case 19: // hintmask
  23701. stems += stack.length >> 1;
  23702. i += (stems + 7) >> 3;
  23703. stackClean = true;
  23704. break;
  23705. case 20: // cntrmask
  23706. stems += stack.length >> 1;
  23707. i += (stems + 7) >> 3;
  23708. stackClean = true;
  23709. break;
  23710. case 21: // rmoveto
  23711. y += stack.pop();
  23712. x += stack.pop();
  23713. moveTo(x, y);
  23714. stackClean = true;
  23715. break;
  23716. case 22: // hmoveto
  23717. x += stack.pop();
  23718. moveTo(x, y);
  23719. stackClean = true;
  23720. break;
  23721. case 23: // vstemhm
  23722. stems += stack.length >> 1;
  23723. stackClean = true;
  23724. break;
  23725. case 24: // rcurveline
  23726. while (stack.length > 2) {
  23727. xa = x + stack.shift(); ya = y + stack.shift();
  23728. xb = xa + stack.shift(); yb = ya + stack.shift();
  23729. x = xb + stack.shift(); y = yb + stack.shift();
  23730. bezierCurveTo(xa, ya, xb, yb, x, y);
  23731. }
  23732. x += stack.shift();
  23733. y += stack.shift();
  23734. lineTo(x, y);
  23735. break;
  23736. case 25: // rlinecurve
  23737. while (stack.length > 6) {
  23738. x += stack.shift();
  23739. y += stack.shift();
  23740. lineTo(x, y);
  23741. }
  23742. xa = x + stack.shift(); ya = y + stack.shift();
  23743. xb = xa + stack.shift(); yb = ya + stack.shift();
  23744. x = xb + stack.shift(); y = yb + stack.shift();
  23745. bezierCurveTo(xa, ya, xb, yb, x, y);
  23746. break;
  23747. case 26: // vvcurveto
  23748. if (stack.length % 2) {
  23749. x += stack.shift();
  23750. }
  23751. while (stack.length > 0) {
  23752. xa = x; ya = y + stack.shift();
  23753. xb = xa + stack.shift(); yb = ya + stack.shift();
  23754. x = xb; y = yb + stack.shift();
  23755. bezierCurveTo(xa, ya, xb, yb, x, y);
  23756. }
  23757. break;
  23758. case 27: // hhcurveto
  23759. if (stack.length % 2) {
  23760. y += stack.shift();
  23761. }
  23762. while (stack.length > 0) {
  23763. xa = x + stack.shift(); ya = y;
  23764. xb = xa + stack.shift(); yb = ya + stack.shift();
  23765. x = xb + stack.shift(); y = yb;
  23766. bezierCurveTo(xa, ya, xb, yb, x, y);
  23767. }
  23768. break;
  23769. case 28:
  23770. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  23771. i += 2;
  23772. break;
  23773. case 29: // callgsubr
  23774. n = stack.pop() + font.gsubrsBias;
  23775. subrCode = font.gsubrs[n];
  23776. if (subrCode) {
  23777. parse(subrCode);
  23778. }
  23779. break;
  23780. case 30: // vhcurveto
  23781. while (stack.length > 0) {
  23782. xa = x; ya = y + stack.shift();
  23783. xb = xa + stack.shift(); yb = ya + stack.shift();
  23784. x = xb + stack.shift();
  23785. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23786. bezierCurveTo(xa, ya, xb, yb, x, y);
  23787. if (stack.length === 0) {
  23788. break;
  23789. }
  23790. xa = x + stack.shift(); ya = y;
  23791. xb = xa + stack.shift(); yb = ya + stack.shift();
  23792. y = yb + stack.shift();
  23793. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23794. bezierCurveTo(xa, ya, xb, yb, x, y);
  23795. }
  23796. break;
  23797. case 31: // hvcurveto
  23798. while (stack.length > 0) {
  23799. xa = x + stack.shift(); ya = y;
  23800. xb = xa + stack.shift(); yb = ya + stack.shift();
  23801. y = yb + stack.shift();
  23802. x = xb + (stack.length === 1 ? stack.shift() : 0);
  23803. bezierCurveTo(xa, ya, xb, yb, x, y);
  23804. if (stack.length === 0) {
  23805. break;
  23806. }
  23807. xa = x; ya = y + stack.shift();
  23808. xb = xa + stack.shift(); yb = ya + stack.shift();
  23809. x = xb + stack.shift();
  23810. y = yb + (stack.length === 1 ? stack.shift() : 0);
  23811. bezierCurveTo(xa, ya, xb, yb, x, y);
  23812. }
  23813. break;
  23814. default:
  23815. if (v < 32) {
  23816. error('unknown operator: ' + v);
  23817. }
  23818. if (v < 247) {
  23819. stack.push(v - 139);
  23820. } else if (v < 251) {
  23821. stack.push((v - 247) * 256 + code[i++] + 108);
  23822. } else if (v < 255) {
  23823. stack.push(-(v - 251) * 256 - code[i++] - 108);
  23824. } else {
  23825. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  23826. (code[i + 2] << 8) | code[i + 3]) / 65536);
  23827. i += 4;
  23828. }
  23829. break;
  23830. }
  23831. if (stackClean) {
  23832. stack.length = 0;
  23833. }
  23834. }
  23835. }
  23836. parse(code);
  23837. }
  23838. var noop = '';
  23839. function CompiledFont(fontMatrix) {
  23840. this.compiledGlyphs = {};
  23841. this.fontMatrix = fontMatrix;
  23842. }
  23843. CompiledFont.prototype = {
  23844. getPathJs: function (unicode) {
  23845. var gid = lookupCmap(this.cmap, unicode);
  23846. var fn = this.compiledGlyphs[gid];
  23847. if (!fn) {
  23848. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  23849. }
  23850. return fn;
  23851. },
  23852. compileGlyph: function (code) {
  23853. if (!code || code.length === 0 || code[0] === 14) {
  23854. return noop;
  23855. }
  23856. var js = [];
  23857. js.push('c.save();');
  23858. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  23859. js.push('c.scale(size, -size);');
  23860. this.compileGlyphImpl(code, js);
  23861. js.push('c.restore();');
  23862. return js.join('\n');
  23863. },
  23864. compileGlyphImpl: function () {
  23865. error('Children classes should implement this.');
  23866. },
  23867. hasBuiltPath: function (unicode) {
  23868. var gid = lookupCmap(this.cmap, unicode);
  23869. return gid in this.compiledGlyphs;
  23870. }
  23871. };
  23872. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  23873. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  23874. CompiledFont.call(this, fontMatrix);
  23875. this.glyphs = glyphs;
  23876. this.cmap = cmap;
  23877. this.compiledGlyphs = [];
  23878. }
  23879. Util.inherit(TrueTypeCompiled, CompiledFont, {
  23880. compileGlyphImpl: function (code, js) {
  23881. compileGlyf(code, js, this);
  23882. }
  23883. });
  23884. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  23885. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  23886. CompiledFont.call(this, fontMatrix);
  23887. this.glyphs = cffInfo.glyphs;
  23888. this.gsubrs = cffInfo.gsubrs || [];
  23889. this.subrs = cffInfo.subrs || [];
  23890. this.cmap = cmap;
  23891. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  23892. this.compiledGlyphs = [];
  23893. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  23894. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  23895. this.subrsBias = (this.subrs.length < 1240 ?
  23896. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  23897. }
  23898. Util.inherit(Type2Compiled, CompiledFont, {
  23899. compileGlyphImpl: function (code, js) {
  23900. compileCharString(code, js, this);
  23901. }
  23902. });
  23903. return {
  23904. create: function FontRendererFactory_create(font) {
  23905. var data = new Uint8Array(font.data);
  23906. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  23907. var numTables = getUshort(data, 4);
  23908. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  23909. var tag = bytesToString(data.subarray(p, p + 4));
  23910. var offset = getLong(data, p + 8);
  23911. var length = getLong(data, p + 12);
  23912. switch (tag) {
  23913. case 'cmap':
  23914. cmap = parseCmap(data, offset, offset + length);
  23915. break;
  23916. case 'glyf':
  23917. glyf = data.subarray(offset, offset + length);
  23918. break;
  23919. case 'loca':
  23920. loca = data.subarray(offset, offset + length);
  23921. break;
  23922. case 'head':
  23923. unitsPerEm = getUshort(data, offset + 18);
  23924. indexToLocFormat = getUshort(data, offset + 50);
  23925. break;
  23926. case 'CFF ':
  23927. cff = parseCff(data, offset, offset + length);
  23928. break;
  23929. }
  23930. }
  23931. if (glyf) {
  23932. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  23933. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  23934. return new TrueTypeCompiled(
  23935. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  23936. } else {
  23937. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  23938. }
  23939. }
  23940. };
  23941. })();
  23942. var GlyphsUnicode = {
  23943. A: 0x0041,
  23944. AE: 0x00C6,
  23945. AEacute: 0x01FC,
  23946. AEmacron: 0x01E2,
  23947. AEsmall: 0xF7E6,
  23948. Aacute: 0x00C1,
  23949. Aacutesmall: 0xF7E1,
  23950. Abreve: 0x0102,
  23951. Abreveacute: 0x1EAE,
  23952. Abrevecyrillic: 0x04D0,
  23953. Abrevedotbelow: 0x1EB6,
  23954. Abrevegrave: 0x1EB0,
  23955. Abrevehookabove: 0x1EB2,
  23956. Abrevetilde: 0x1EB4,
  23957. Acaron: 0x01CD,
  23958. Acircle: 0x24B6,
  23959. Acircumflex: 0x00C2,
  23960. Acircumflexacute: 0x1EA4,
  23961. Acircumflexdotbelow: 0x1EAC,
  23962. Acircumflexgrave: 0x1EA6,
  23963. Acircumflexhookabove: 0x1EA8,
  23964. Acircumflexsmall: 0xF7E2,
  23965. Acircumflextilde: 0x1EAA,
  23966. Acute: 0xF6C9,
  23967. Acutesmall: 0xF7B4,
  23968. Acyrillic: 0x0410,
  23969. Adblgrave: 0x0200,
  23970. Adieresis: 0x00C4,
  23971. Adieresiscyrillic: 0x04D2,
  23972. Adieresismacron: 0x01DE,
  23973. Adieresissmall: 0xF7E4,
  23974. Adotbelow: 0x1EA0,
  23975. Adotmacron: 0x01E0,
  23976. Agrave: 0x00C0,
  23977. Agravesmall: 0xF7E0,
  23978. Ahookabove: 0x1EA2,
  23979. Aiecyrillic: 0x04D4,
  23980. Ainvertedbreve: 0x0202,
  23981. Alpha: 0x0391,
  23982. Alphatonos: 0x0386,
  23983. Amacron: 0x0100,
  23984. Amonospace: 0xFF21,
  23985. Aogonek: 0x0104,
  23986. Aring: 0x00C5,
  23987. Aringacute: 0x01FA,
  23988. Aringbelow: 0x1E00,
  23989. Aringsmall: 0xF7E5,
  23990. Asmall: 0xF761,
  23991. Atilde: 0x00C3,
  23992. Atildesmall: 0xF7E3,
  23993. Aybarmenian: 0x0531,
  23994. B: 0x0042,
  23995. Bcircle: 0x24B7,
  23996. Bdotaccent: 0x1E02,
  23997. Bdotbelow: 0x1E04,
  23998. Becyrillic: 0x0411,
  23999. Benarmenian: 0x0532,
  24000. Beta: 0x0392,
  24001. Bhook: 0x0181,
  24002. Blinebelow: 0x1E06,
  24003. Bmonospace: 0xFF22,
  24004. Brevesmall: 0xF6F4,
  24005. Bsmall: 0xF762,
  24006. Btopbar: 0x0182,
  24007. C: 0x0043,
  24008. Caarmenian: 0x053E,
  24009. Cacute: 0x0106,
  24010. Caron: 0xF6CA,
  24011. Caronsmall: 0xF6F5,
  24012. Ccaron: 0x010C,
  24013. Ccedilla: 0x00C7,
  24014. Ccedillaacute: 0x1E08,
  24015. Ccedillasmall: 0xF7E7,
  24016. Ccircle: 0x24B8,
  24017. Ccircumflex: 0x0108,
  24018. Cdot: 0x010A,
  24019. Cdotaccent: 0x010A,
  24020. Cedillasmall: 0xF7B8,
  24021. Chaarmenian: 0x0549,
  24022. Cheabkhasiancyrillic: 0x04BC,
  24023. Checyrillic: 0x0427,
  24024. Chedescenderabkhasiancyrillic: 0x04BE,
  24025. Chedescendercyrillic: 0x04B6,
  24026. Chedieresiscyrillic: 0x04F4,
  24027. Cheharmenian: 0x0543,
  24028. Chekhakassiancyrillic: 0x04CB,
  24029. Cheverticalstrokecyrillic: 0x04B8,
  24030. Chi: 0x03A7,
  24031. Chook: 0x0187,
  24032. Circumflexsmall: 0xF6F6,
  24033. Cmonospace: 0xFF23,
  24034. Coarmenian: 0x0551,
  24035. Csmall: 0xF763,
  24036. D: 0x0044,
  24037. DZ: 0x01F1,
  24038. DZcaron: 0x01C4,
  24039. Daarmenian: 0x0534,
  24040. Dafrican: 0x0189,
  24041. Dcaron: 0x010E,
  24042. Dcedilla: 0x1E10,
  24043. Dcircle: 0x24B9,
  24044. Dcircumflexbelow: 0x1E12,
  24045. Dcroat: 0x0110,
  24046. Ddotaccent: 0x1E0A,
  24047. Ddotbelow: 0x1E0C,
  24048. Decyrillic: 0x0414,
  24049. Deicoptic: 0x03EE,
  24050. Delta: 0x2206,
  24051. Deltagreek: 0x0394,
  24052. Dhook: 0x018A,
  24053. Dieresis: 0xF6CB,
  24054. DieresisAcute: 0xF6CC,
  24055. DieresisGrave: 0xF6CD,
  24056. Dieresissmall: 0xF7A8,
  24057. Digammagreek: 0x03DC,
  24058. Djecyrillic: 0x0402,
  24059. Dlinebelow: 0x1E0E,
  24060. Dmonospace: 0xFF24,
  24061. Dotaccentsmall: 0xF6F7,
  24062. Dslash: 0x0110,
  24063. Dsmall: 0xF764,
  24064. Dtopbar: 0x018B,
  24065. Dz: 0x01F2,
  24066. Dzcaron: 0x01C5,
  24067. Dzeabkhasiancyrillic: 0x04E0,
  24068. Dzecyrillic: 0x0405,
  24069. Dzhecyrillic: 0x040F,
  24070. E: 0x0045,
  24071. Eacute: 0x00C9,
  24072. Eacutesmall: 0xF7E9,
  24073. Ebreve: 0x0114,
  24074. Ecaron: 0x011A,
  24075. Ecedillabreve: 0x1E1C,
  24076. Echarmenian: 0x0535,
  24077. Ecircle: 0x24BA,
  24078. Ecircumflex: 0x00CA,
  24079. Ecircumflexacute: 0x1EBE,
  24080. Ecircumflexbelow: 0x1E18,
  24081. Ecircumflexdotbelow: 0x1EC6,
  24082. Ecircumflexgrave: 0x1EC0,
  24083. Ecircumflexhookabove: 0x1EC2,
  24084. Ecircumflexsmall: 0xF7EA,
  24085. Ecircumflextilde: 0x1EC4,
  24086. Ecyrillic: 0x0404,
  24087. Edblgrave: 0x0204,
  24088. Edieresis: 0x00CB,
  24089. Edieresissmall: 0xF7EB,
  24090. Edot: 0x0116,
  24091. Edotaccent: 0x0116,
  24092. Edotbelow: 0x1EB8,
  24093. Efcyrillic: 0x0424,
  24094. Egrave: 0x00C8,
  24095. Egravesmall: 0xF7E8,
  24096. Eharmenian: 0x0537,
  24097. Ehookabove: 0x1EBA,
  24098. Eightroman: 0x2167,
  24099. Einvertedbreve: 0x0206,
  24100. Eiotifiedcyrillic: 0x0464,
  24101. Elcyrillic: 0x041B,
  24102. Elevenroman: 0x216A,
  24103. Emacron: 0x0112,
  24104. Emacronacute: 0x1E16,
  24105. Emacrongrave: 0x1E14,
  24106. Emcyrillic: 0x041C,
  24107. Emonospace: 0xFF25,
  24108. Encyrillic: 0x041D,
  24109. Endescendercyrillic: 0x04A2,
  24110. Eng: 0x014A,
  24111. Enghecyrillic: 0x04A4,
  24112. Enhookcyrillic: 0x04C7,
  24113. Eogonek: 0x0118,
  24114. Eopen: 0x0190,
  24115. Epsilon: 0x0395,
  24116. Epsilontonos: 0x0388,
  24117. Ercyrillic: 0x0420,
  24118. Ereversed: 0x018E,
  24119. Ereversedcyrillic: 0x042D,
  24120. Escyrillic: 0x0421,
  24121. Esdescendercyrillic: 0x04AA,
  24122. Esh: 0x01A9,
  24123. Esmall: 0xF765,
  24124. Eta: 0x0397,
  24125. Etarmenian: 0x0538,
  24126. Etatonos: 0x0389,
  24127. Eth: 0x00D0,
  24128. Ethsmall: 0xF7F0,
  24129. Etilde: 0x1EBC,
  24130. Etildebelow: 0x1E1A,
  24131. Euro: 0x20AC,
  24132. Ezh: 0x01B7,
  24133. Ezhcaron: 0x01EE,
  24134. Ezhreversed: 0x01B8,
  24135. F: 0x0046,
  24136. Fcircle: 0x24BB,
  24137. Fdotaccent: 0x1E1E,
  24138. Feharmenian: 0x0556,
  24139. Feicoptic: 0x03E4,
  24140. Fhook: 0x0191,
  24141. Fitacyrillic: 0x0472,
  24142. Fiveroman: 0x2164,
  24143. Fmonospace: 0xFF26,
  24144. Fourroman: 0x2163,
  24145. Fsmall: 0xF766,
  24146. G: 0x0047,
  24147. GBsquare: 0x3387,
  24148. Gacute: 0x01F4,
  24149. Gamma: 0x0393,
  24150. Gammaafrican: 0x0194,
  24151. Gangiacoptic: 0x03EA,
  24152. Gbreve: 0x011E,
  24153. Gcaron: 0x01E6,
  24154. Gcedilla: 0x0122,
  24155. Gcircle: 0x24BC,
  24156. Gcircumflex: 0x011C,
  24157. Gcommaaccent: 0x0122,
  24158. Gdot: 0x0120,
  24159. Gdotaccent: 0x0120,
  24160. Gecyrillic: 0x0413,
  24161. Ghadarmenian: 0x0542,
  24162. Ghemiddlehookcyrillic: 0x0494,
  24163. Ghestrokecyrillic: 0x0492,
  24164. Gheupturncyrillic: 0x0490,
  24165. Ghook: 0x0193,
  24166. Gimarmenian: 0x0533,
  24167. Gjecyrillic: 0x0403,
  24168. Gmacron: 0x1E20,
  24169. Gmonospace: 0xFF27,
  24170. Grave: 0xF6CE,
  24171. Gravesmall: 0xF760,
  24172. Gsmall: 0xF767,
  24173. Gsmallhook: 0x029B,
  24174. Gstroke: 0x01E4,
  24175. H: 0x0048,
  24176. H18533: 0x25CF,
  24177. H18543: 0x25AA,
  24178. H18551: 0x25AB,
  24179. H22073: 0x25A1,
  24180. HPsquare: 0x33CB,
  24181. Haabkhasiancyrillic: 0x04A8,
  24182. Hadescendercyrillic: 0x04B2,
  24183. Hardsigncyrillic: 0x042A,
  24184. Hbar: 0x0126,
  24185. Hbrevebelow: 0x1E2A,
  24186. Hcedilla: 0x1E28,
  24187. Hcircle: 0x24BD,
  24188. Hcircumflex: 0x0124,
  24189. Hdieresis: 0x1E26,
  24190. Hdotaccent: 0x1E22,
  24191. Hdotbelow: 0x1E24,
  24192. Hmonospace: 0xFF28,
  24193. Hoarmenian: 0x0540,
  24194. Horicoptic: 0x03E8,
  24195. Hsmall: 0xF768,
  24196. Hungarumlaut: 0xF6CF,
  24197. Hungarumlautsmall: 0xF6F8,
  24198. Hzsquare: 0x3390,
  24199. I: 0x0049,
  24200. IAcyrillic: 0x042F,
  24201. IJ: 0x0132,
  24202. IUcyrillic: 0x042E,
  24203. Iacute: 0x00CD,
  24204. Iacutesmall: 0xF7ED,
  24205. Ibreve: 0x012C,
  24206. Icaron: 0x01CF,
  24207. Icircle: 0x24BE,
  24208. Icircumflex: 0x00CE,
  24209. Icircumflexsmall: 0xF7EE,
  24210. Icyrillic: 0x0406,
  24211. Idblgrave: 0x0208,
  24212. Idieresis: 0x00CF,
  24213. Idieresisacute: 0x1E2E,
  24214. Idieresiscyrillic: 0x04E4,
  24215. Idieresissmall: 0xF7EF,
  24216. Idot: 0x0130,
  24217. Idotaccent: 0x0130,
  24218. Idotbelow: 0x1ECA,
  24219. Iebrevecyrillic: 0x04D6,
  24220. Iecyrillic: 0x0415,
  24221. Ifraktur: 0x2111,
  24222. Igrave: 0x00CC,
  24223. Igravesmall: 0xF7EC,
  24224. Ihookabove: 0x1EC8,
  24225. Iicyrillic: 0x0418,
  24226. Iinvertedbreve: 0x020A,
  24227. Iishortcyrillic: 0x0419,
  24228. Imacron: 0x012A,
  24229. Imacroncyrillic: 0x04E2,
  24230. Imonospace: 0xFF29,
  24231. Iniarmenian: 0x053B,
  24232. Iocyrillic: 0x0401,
  24233. Iogonek: 0x012E,
  24234. Iota: 0x0399,
  24235. Iotaafrican: 0x0196,
  24236. Iotadieresis: 0x03AA,
  24237. Iotatonos: 0x038A,
  24238. Ismall: 0xF769,
  24239. Istroke: 0x0197,
  24240. Itilde: 0x0128,
  24241. Itildebelow: 0x1E2C,
  24242. Izhitsacyrillic: 0x0474,
  24243. Izhitsadblgravecyrillic: 0x0476,
  24244. J: 0x004A,
  24245. Jaarmenian: 0x0541,
  24246. Jcircle: 0x24BF,
  24247. Jcircumflex: 0x0134,
  24248. Jecyrillic: 0x0408,
  24249. Jheharmenian: 0x054B,
  24250. Jmonospace: 0xFF2A,
  24251. Jsmall: 0xF76A,
  24252. K: 0x004B,
  24253. KBsquare: 0x3385,
  24254. KKsquare: 0x33CD,
  24255. Kabashkircyrillic: 0x04A0,
  24256. Kacute: 0x1E30,
  24257. Kacyrillic: 0x041A,
  24258. Kadescendercyrillic: 0x049A,
  24259. Kahookcyrillic: 0x04C3,
  24260. Kappa: 0x039A,
  24261. Kastrokecyrillic: 0x049E,
  24262. Kaverticalstrokecyrillic: 0x049C,
  24263. Kcaron: 0x01E8,
  24264. Kcedilla: 0x0136,
  24265. Kcircle: 0x24C0,
  24266. Kcommaaccent: 0x0136,
  24267. Kdotbelow: 0x1E32,
  24268. Keharmenian: 0x0554,
  24269. Kenarmenian: 0x053F,
  24270. Khacyrillic: 0x0425,
  24271. Kheicoptic: 0x03E6,
  24272. Khook: 0x0198,
  24273. Kjecyrillic: 0x040C,
  24274. Klinebelow: 0x1E34,
  24275. Kmonospace: 0xFF2B,
  24276. Koppacyrillic: 0x0480,
  24277. Koppagreek: 0x03DE,
  24278. Ksicyrillic: 0x046E,
  24279. Ksmall: 0xF76B,
  24280. L: 0x004C,
  24281. LJ: 0x01C7,
  24282. LL: 0xF6BF,
  24283. Lacute: 0x0139,
  24284. Lambda: 0x039B,
  24285. Lcaron: 0x013D,
  24286. Lcedilla: 0x013B,
  24287. Lcircle: 0x24C1,
  24288. Lcircumflexbelow: 0x1E3C,
  24289. Lcommaaccent: 0x013B,
  24290. Ldot: 0x013F,
  24291. Ldotaccent: 0x013F,
  24292. Ldotbelow: 0x1E36,
  24293. Ldotbelowmacron: 0x1E38,
  24294. Liwnarmenian: 0x053C,
  24295. Lj: 0x01C8,
  24296. Ljecyrillic: 0x0409,
  24297. Llinebelow: 0x1E3A,
  24298. Lmonospace: 0xFF2C,
  24299. Lslash: 0x0141,
  24300. Lslashsmall: 0xF6F9,
  24301. Lsmall: 0xF76C,
  24302. M: 0x004D,
  24303. MBsquare: 0x3386,
  24304. Macron: 0xF6D0,
  24305. Macronsmall: 0xF7AF,
  24306. Macute: 0x1E3E,
  24307. Mcircle: 0x24C2,
  24308. Mdotaccent: 0x1E40,
  24309. Mdotbelow: 0x1E42,
  24310. Menarmenian: 0x0544,
  24311. Mmonospace: 0xFF2D,
  24312. Msmall: 0xF76D,
  24313. Mturned: 0x019C,
  24314. Mu: 0x039C,
  24315. N: 0x004E,
  24316. NJ: 0x01CA,
  24317. Nacute: 0x0143,
  24318. Ncaron: 0x0147,
  24319. Ncedilla: 0x0145,
  24320. Ncircle: 0x24C3,
  24321. Ncircumflexbelow: 0x1E4A,
  24322. Ncommaaccent: 0x0145,
  24323. Ndotaccent: 0x1E44,
  24324. Ndotbelow: 0x1E46,
  24325. Nhookleft: 0x019D,
  24326. Nineroman: 0x2168,
  24327. Nj: 0x01CB,
  24328. Njecyrillic: 0x040A,
  24329. Nlinebelow: 0x1E48,
  24330. Nmonospace: 0xFF2E,
  24331. Nowarmenian: 0x0546,
  24332. Nsmall: 0xF76E,
  24333. Ntilde: 0x00D1,
  24334. Ntildesmall: 0xF7F1,
  24335. Nu: 0x039D,
  24336. O: 0x004F,
  24337. OE: 0x0152,
  24338. OEsmall: 0xF6FA,
  24339. Oacute: 0x00D3,
  24340. Oacutesmall: 0xF7F3,
  24341. Obarredcyrillic: 0x04E8,
  24342. Obarreddieresiscyrillic: 0x04EA,
  24343. Obreve: 0x014E,
  24344. Ocaron: 0x01D1,
  24345. Ocenteredtilde: 0x019F,
  24346. Ocircle: 0x24C4,
  24347. Ocircumflex: 0x00D4,
  24348. Ocircumflexacute: 0x1ED0,
  24349. Ocircumflexdotbelow: 0x1ED8,
  24350. Ocircumflexgrave: 0x1ED2,
  24351. Ocircumflexhookabove: 0x1ED4,
  24352. Ocircumflexsmall: 0xF7F4,
  24353. Ocircumflextilde: 0x1ED6,
  24354. Ocyrillic: 0x041E,
  24355. Odblacute: 0x0150,
  24356. Odblgrave: 0x020C,
  24357. Odieresis: 0x00D6,
  24358. Odieresiscyrillic: 0x04E6,
  24359. Odieresissmall: 0xF7F6,
  24360. Odotbelow: 0x1ECC,
  24361. Ogoneksmall: 0xF6FB,
  24362. Ograve: 0x00D2,
  24363. Ogravesmall: 0xF7F2,
  24364. Oharmenian: 0x0555,
  24365. Ohm: 0x2126,
  24366. Ohookabove: 0x1ECE,
  24367. Ohorn: 0x01A0,
  24368. Ohornacute: 0x1EDA,
  24369. Ohorndotbelow: 0x1EE2,
  24370. Ohorngrave: 0x1EDC,
  24371. Ohornhookabove: 0x1EDE,
  24372. Ohorntilde: 0x1EE0,
  24373. Ohungarumlaut: 0x0150,
  24374. Oi: 0x01A2,
  24375. Oinvertedbreve: 0x020E,
  24376. Omacron: 0x014C,
  24377. Omacronacute: 0x1E52,
  24378. Omacrongrave: 0x1E50,
  24379. Omega: 0x2126,
  24380. Omegacyrillic: 0x0460,
  24381. Omegagreek: 0x03A9,
  24382. Omegaroundcyrillic: 0x047A,
  24383. Omegatitlocyrillic: 0x047C,
  24384. Omegatonos: 0x038F,
  24385. Omicron: 0x039F,
  24386. Omicrontonos: 0x038C,
  24387. Omonospace: 0xFF2F,
  24388. Oneroman: 0x2160,
  24389. Oogonek: 0x01EA,
  24390. Oogonekmacron: 0x01EC,
  24391. Oopen: 0x0186,
  24392. Oslash: 0x00D8,
  24393. Oslashacute: 0x01FE,
  24394. Oslashsmall: 0xF7F8,
  24395. Osmall: 0xF76F,
  24396. Ostrokeacute: 0x01FE,
  24397. Otcyrillic: 0x047E,
  24398. Otilde: 0x00D5,
  24399. Otildeacute: 0x1E4C,
  24400. Otildedieresis: 0x1E4E,
  24401. Otildesmall: 0xF7F5,
  24402. P: 0x0050,
  24403. Pacute: 0x1E54,
  24404. Pcircle: 0x24C5,
  24405. Pdotaccent: 0x1E56,
  24406. Pecyrillic: 0x041F,
  24407. Peharmenian: 0x054A,
  24408. Pemiddlehookcyrillic: 0x04A6,
  24409. Phi: 0x03A6,
  24410. Phook: 0x01A4,
  24411. Pi: 0x03A0,
  24412. Piwrarmenian: 0x0553,
  24413. Pmonospace: 0xFF30,
  24414. Psi: 0x03A8,
  24415. Psicyrillic: 0x0470,
  24416. Psmall: 0xF770,
  24417. Q: 0x0051,
  24418. Qcircle: 0x24C6,
  24419. Qmonospace: 0xFF31,
  24420. Qsmall: 0xF771,
  24421. R: 0x0052,
  24422. Raarmenian: 0x054C,
  24423. Racute: 0x0154,
  24424. Rcaron: 0x0158,
  24425. Rcedilla: 0x0156,
  24426. Rcircle: 0x24C7,
  24427. Rcommaaccent: 0x0156,
  24428. Rdblgrave: 0x0210,
  24429. Rdotaccent: 0x1E58,
  24430. Rdotbelow: 0x1E5A,
  24431. Rdotbelowmacron: 0x1E5C,
  24432. Reharmenian: 0x0550,
  24433. Rfraktur: 0x211C,
  24434. Rho: 0x03A1,
  24435. Ringsmall: 0xF6FC,
  24436. Rinvertedbreve: 0x0212,
  24437. Rlinebelow: 0x1E5E,
  24438. Rmonospace: 0xFF32,
  24439. Rsmall: 0xF772,
  24440. Rsmallinverted: 0x0281,
  24441. Rsmallinvertedsuperior: 0x02B6,
  24442. S: 0x0053,
  24443. SF010000: 0x250C,
  24444. SF020000: 0x2514,
  24445. SF030000: 0x2510,
  24446. SF040000: 0x2518,
  24447. SF050000: 0x253C,
  24448. SF060000: 0x252C,
  24449. SF070000: 0x2534,
  24450. SF080000: 0x251C,
  24451. SF090000: 0x2524,
  24452. SF100000: 0x2500,
  24453. SF110000: 0x2502,
  24454. SF190000: 0x2561,
  24455. SF200000: 0x2562,
  24456. SF210000: 0x2556,
  24457. SF220000: 0x2555,
  24458. SF230000: 0x2563,
  24459. SF240000: 0x2551,
  24460. SF250000: 0x2557,
  24461. SF260000: 0x255D,
  24462. SF270000: 0x255C,
  24463. SF280000: 0x255B,
  24464. SF360000: 0x255E,
  24465. SF370000: 0x255F,
  24466. SF380000: 0x255A,
  24467. SF390000: 0x2554,
  24468. SF400000: 0x2569,
  24469. SF410000: 0x2566,
  24470. SF420000: 0x2560,
  24471. SF430000: 0x2550,
  24472. SF440000: 0x256C,
  24473. SF450000: 0x2567,
  24474. SF460000: 0x2568,
  24475. SF470000: 0x2564,
  24476. SF480000: 0x2565,
  24477. SF490000: 0x2559,
  24478. SF500000: 0x2558,
  24479. SF510000: 0x2552,
  24480. SF520000: 0x2553,
  24481. SF530000: 0x256B,
  24482. SF540000: 0x256A,
  24483. Sacute: 0x015A,
  24484. Sacutedotaccent: 0x1E64,
  24485. Sampigreek: 0x03E0,
  24486. Scaron: 0x0160,
  24487. Scarondotaccent: 0x1E66,
  24488. Scaronsmall: 0xF6FD,
  24489. Scedilla: 0x015E,
  24490. Schwa: 0x018F,
  24491. Schwacyrillic: 0x04D8,
  24492. Schwadieresiscyrillic: 0x04DA,
  24493. Scircle: 0x24C8,
  24494. Scircumflex: 0x015C,
  24495. Scommaaccent: 0x0218,
  24496. Sdotaccent: 0x1E60,
  24497. Sdotbelow: 0x1E62,
  24498. Sdotbelowdotaccent: 0x1E68,
  24499. Seharmenian: 0x054D,
  24500. Sevenroman: 0x2166,
  24501. Shaarmenian: 0x0547,
  24502. Shacyrillic: 0x0428,
  24503. Shchacyrillic: 0x0429,
  24504. Sheicoptic: 0x03E2,
  24505. Shhacyrillic: 0x04BA,
  24506. Shimacoptic: 0x03EC,
  24507. Sigma: 0x03A3,
  24508. Sixroman: 0x2165,
  24509. Smonospace: 0xFF33,
  24510. Softsigncyrillic: 0x042C,
  24511. Ssmall: 0xF773,
  24512. Stigmagreek: 0x03DA,
  24513. T: 0x0054,
  24514. Tau: 0x03A4,
  24515. Tbar: 0x0166,
  24516. Tcaron: 0x0164,
  24517. Tcedilla: 0x0162,
  24518. Tcircle: 0x24C9,
  24519. Tcircumflexbelow: 0x1E70,
  24520. Tcommaaccent: 0x0162,
  24521. Tdotaccent: 0x1E6A,
  24522. Tdotbelow: 0x1E6C,
  24523. Tecyrillic: 0x0422,
  24524. Tedescendercyrillic: 0x04AC,
  24525. Tenroman: 0x2169,
  24526. Tetsecyrillic: 0x04B4,
  24527. Theta: 0x0398,
  24528. Thook: 0x01AC,
  24529. Thorn: 0x00DE,
  24530. Thornsmall: 0xF7FE,
  24531. Threeroman: 0x2162,
  24532. Tildesmall: 0xF6FE,
  24533. Tiwnarmenian: 0x054F,
  24534. Tlinebelow: 0x1E6E,
  24535. Tmonospace: 0xFF34,
  24536. Toarmenian: 0x0539,
  24537. Tonefive: 0x01BC,
  24538. Tonesix: 0x0184,
  24539. Tonetwo: 0x01A7,
  24540. Tretroflexhook: 0x01AE,
  24541. Tsecyrillic: 0x0426,
  24542. Tshecyrillic: 0x040B,
  24543. Tsmall: 0xF774,
  24544. Twelveroman: 0x216B,
  24545. Tworoman: 0x2161,
  24546. U: 0x0055,
  24547. Uacute: 0x00DA,
  24548. Uacutesmall: 0xF7FA,
  24549. Ubreve: 0x016C,
  24550. Ucaron: 0x01D3,
  24551. Ucircle: 0x24CA,
  24552. Ucircumflex: 0x00DB,
  24553. Ucircumflexbelow: 0x1E76,
  24554. Ucircumflexsmall: 0xF7FB,
  24555. Ucyrillic: 0x0423,
  24556. Udblacute: 0x0170,
  24557. Udblgrave: 0x0214,
  24558. Udieresis: 0x00DC,
  24559. Udieresisacute: 0x01D7,
  24560. Udieresisbelow: 0x1E72,
  24561. Udieresiscaron: 0x01D9,
  24562. Udieresiscyrillic: 0x04F0,
  24563. Udieresisgrave: 0x01DB,
  24564. Udieresismacron: 0x01D5,
  24565. Udieresissmall: 0xF7FC,
  24566. Udotbelow: 0x1EE4,
  24567. Ugrave: 0x00D9,
  24568. Ugravesmall: 0xF7F9,
  24569. Uhookabove: 0x1EE6,
  24570. Uhorn: 0x01AF,
  24571. Uhornacute: 0x1EE8,
  24572. Uhorndotbelow: 0x1EF0,
  24573. Uhorngrave: 0x1EEA,
  24574. Uhornhookabove: 0x1EEC,
  24575. Uhorntilde: 0x1EEE,
  24576. Uhungarumlaut: 0x0170,
  24577. Uhungarumlautcyrillic: 0x04F2,
  24578. Uinvertedbreve: 0x0216,
  24579. Ukcyrillic: 0x0478,
  24580. Umacron: 0x016A,
  24581. Umacroncyrillic: 0x04EE,
  24582. Umacrondieresis: 0x1E7A,
  24583. Umonospace: 0xFF35,
  24584. Uogonek: 0x0172,
  24585. Upsilon: 0x03A5,
  24586. Upsilon1: 0x03D2,
  24587. Upsilonacutehooksymbolgreek: 0x03D3,
  24588. Upsilonafrican: 0x01B1,
  24589. Upsilondieresis: 0x03AB,
  24590. Upsilondieresishooksymbolgreek: 0x03D4,
  24591. Upsilonhooksymbol: 0x03D2,
  24592. Upsilontonos: 0x038E,
  24593. Uring: 0x016E,
  24594. Ushortcyrillic: 0x040E,
  24595. Usmall: 0xF775,
  24596. Ustraightcyrillic: 0x04AE,
  24597. Ustraightstrokecyrillic: 0x04B0,
  24598. Utilde: 0x0168,
  24599. Utildeacute: 0x1E78,
  24600. Utildebelow: 0x1E74,
  24601. V: 0x0056,
  24602. Vcircle: 0x24CB,
  24603. Vdotbelow: 0x1E7E,
  24604. Vecyrillic: 0x0412,
  24605. Vewarmenian: 0x054E,
  24606. Vhook: 0x01B2,
  24607. Vmonospace: 0xFF36,
  24608. Voarmenian: 0x0548,
  24609. Vsmall: 0xF776,
  24610. Vtilde: 0x1E7C,
  24611. W: 0x0057,
  24612. Wacute: 0x1E82,
  24613. Wcircle: 0x24CC,
  24614. Wcircumflex: 0x0174,
  24615. Wdieresis: 0x1E84,
  24616. Wdotaccent: 0x1E86,
  24617. Wdotbelow: 0x1E88,
  24618. Wgrave: 0x1E80,
  24619. Wmonospace: 0xFF37,
  24620. Wsmall: 0xF777,
  24621. X: 0x0058,
  24622. Xcircle: 0x24CD,
  24623. Xdieresis: 0x1E8C,
  24624. Xdotaccent: 0x1E8A,
  24625. Xeharmenian: 0x053D,
  24626. Xi: 0x039E,
  24627. Xmonospace: 0xFF38,
  24628. Xsmall: 0xF778,
  24629. Y: 0x0059,
  24630. Yacute: 0x00DD,
  24631. Yacutesmall: 0xF7FD,
  24632. Yatcyrillic: 0x0462,
  24633. Ycircle: 0x24CE,
  24634. Ycircumflex: 0x0176,
  24635. Ydieresis: 0x0178,
  24636. Ydieresissmall: 0xF7FF,
  24637. Ydotaccent: 0x1E8E,
  24638. Ydotbelow: 0x1EF4,
  24639. Yericyrillic: 0x042B,
  24640. Yerudieresiscyrillic: 0x04F8,
  24641. Ygrave: 0x1EF2,
  24642. Yhook: 0x01B3,
  24643. Yhookabove: 0x1EF6,
  24644. Yiarmenian: 0x0545,
  24645. Yicyrillic: 0x0407,
  24646. Yiwnarmenian: 0x0552,
  24647. Ymonospace: 0xFF39,
  24648. Ysmall: 0xF779,
  24649. Ytilde: 0x1EF8,
  24650. Yusbigcyrillic: 0x046A,
  24651. Yusbigiotifiedcyrillic: 0x046C,
  24652. Yuslittlecyrillic: 0x0466,
  24653. Yuslittleiotifiedcyrillic: 0x0468,
  24654. Z: 0x005A,
  24655. Zaarmenian: 0x0536,
  24656. Zacute: 0x0179,
  24657. Zcaron: 0x017D,
  24658. Zcaronsmall: 0xF6FF,
  24659. Zcircle: 0x24CF,
  24660. Zcircumflex: 0x1E90,
  24661. Zdot: 0x017B,
  24662. Zdotaccent: 0x017B,
  24663. Zdotbelow: 0x1E92,
  24664. Zecyrillic: 0x0417,
  24665. Zedescendercyrillic: 0x0498,
  24666. Zedieresiscyrillic: 0x04DE,
  24667. Zeta: 0x0396,
  24668. Zhearmenian: 0x053A,
  24669. Zhebrevecyrillic: 0x04C1,
  24670. Zhecyrillic: 0x0416,
  24671. Zhedescendercyrillic: 0x0496,
  24672. Zhedieresiscyrillic: 0x04DC,
  24673. Zlinebelow: 0x1E94,
  24674. Zmonospace: 0xFF3A,
  24675. Zsmall: 0xF77A,
  24676. Zstroke: 0x01B5,
  24677. a: 0x0061,
  24678. aabengali: 0x0986,
  24679. aacute: 0x00E1,
  24680. aadeva: 0x0906,
  24681. aagujarati: 0x0A86,
  24682. aagurmukhi: 0x0A06,
  24683. aamatragurmukhi: 0x0A3E,
  24684. aarusquare: 0x3303,
  24685. aavowelsignbengali: 0x09BE,
  24686. aavowelsigndeva: 0x093E,
  24687. aavowelsigngujarati: 0x0ABE,
  24688. abbreviationmarkarmenian: 0x055F,
  24689. abbreviationsigndeva: 0x0970,
  24690. abengali: 0x0985,
  24691. abopomofo: 0x311A,
  24692. abreve: 0x0103,
  24693. abreveacute: 0x1EAF,
  24694. abrevecyrillic: 0x04D1,
  24695. abrevedotbelow: 0x1EB7,
  24696. abrevegrave: 0x1EB1,
  24697. abrevehookabove: 0x1EB3,
  24698. abrevetilde: 0x1EB5,
  24699. acaron: 0x01CE,
  24700. acircle: 0x24D0,
  24701. acircumflex: 0x00E2,
  24702. acircumflexacute: 0x1EA5,
  24703. acircumflexdotbelow: 0x1EAD,
  24704. acircumflexgrave: 0x1EA7,
  24705. acircumflexhookabove: 0x1EA9,
  24706. acircumflextilde: 0x1EAB,
  24707. acute: 0x00B4,
  24708. acutebelowcmb: 0x0317,
  24709. acutecmb: 0x0301,
  24710. acutecomb: 0x0301,
  24711. acutedeva: 0x0954,
  24712. acutelowmod: 0x02CF,
  24713. acutetonecmb: 0x0341,
  24714. acyrillic: 0x0430,
  24715. adblgrave: 0x0201,
  24716. addakgurmukhi: 0x0A71,
  24717. adeva: 0x0905,
  24718. adieresis: 0x00E4,
  24719. adieresiscyrillic: 0x04D3,
  24720. adieresismacron: 0x01DF,
  24721. adotbelow: 0x1EA1,
  24722. adotmacron: 0x01E1,
  24723. ae: 0x00E6,
  24724. aeacute: 0x01FD,
  24725. aekorean: 0x3150,
  24726. aemacron: 0x01E3,
  24727. afii00208: 0x2015,
  24728. afii08941: 0x20A4,
  24729. afii10017: 0x0410,
  24730. afii10018: 0x0411,
  24731. afii10019: 0x0412,
  24732. afii10020: 0x0413,
  24733. afii10021: 0x0414,
  24734. afii10022: 0x0415,
  24735. afii10023: 0x0401,
  24736. afii10024: 0x0416,
  24737. afii10025: 0x0417,
  24738. afii10026: 0x0418,
  24739. afii10027: 0x0419,
  24740. afii10028: 0x041A,
  24741. afii10029: 0x041B,
  24742. afii10030: 0x041C,
  24743. afii10031: 0x041D,
  24744. afii10032: 0x041E,
  24745. afii10033: 0x041F,
  24746. afii10034: 0x0420,
  24747. afii10035: 0x0421,
  24748. afii10036: 0x0422,
  24749. afii10037: 0x0423,
  24750. afii10038: 0x0424,
  24751. afii10039: 0x0425,
  24752. afii10040: 0x0426,
  24753. afii10041: 0x0427,
  24754. afii10042: 0x0428,
  24755. afii10043: 0x0429,
  24756. afii10044: 0x042A,
  24757. afii10045: 0x042B,
  24758. afii10046: 0x042C,
  24759. afii10047: 0x042D,
  24760. afii10048: 0x042E,
  24761. afii10049: 0x042F,
  24762. afii10050: 0x0490,
  24763. afii10051: 0x0402,
  24764. afii10052: 0x0403,
  24765. afii10053: 0x0404,
  24766. afii10054: 0x0405,
  24767. afii10055: 0x0406,
  24768. afii10056: 0x0407,
  24769. afii10057: 0x0408,
  24770. afii10058: 0x0409,
  24771. afii10059: 0x040A,
  24772. afii10060: 0x040B,
  24773. afii10061: 0x040C,
  24774. afii10062: 0x040E,
  24775. afii10063: 0xF6C4,
  24776. afii10064: 0xF6C5,
  24777. afii10065: 0x0430,
  24778. afii10066: 0x0431,
  24779. afii10067: 0x0432,
  24780. afii10068: 0x0433,
  24781. afii10069: 0x0434,
  24782. afii10070: 0x0435,
  24783. afii10071: 0x0451,
  24784. afii10072: 0x0436,
  24785. afii10073: 0x0437,
  24786. afii10074: 0x0438,
  24787. afii10075: 0x0439,
  24788. afii10076: 0x043A,
  24789. afii10077: 0x043B,
  24790. afii10078: 0x043C,
  24791. afii10079: 0x043D,
  24792. afii10080: 0x043E,
  24793. afii10081: 0x043F,
  24794. afii10082: 0x0440,
  24795. afii10083: 0x0441,
  24796. afii10084: 0x0442,
  24797. afii10085: 0x0443,
  24798. afii10086: 0x0444,
  24799. afii10087: 0x0445,
  24800. afii10088: 0x0446,
  24801. afii10089: 0x0447,
  24802. afii10090: 0x0448,
  24803. afii10091: 0x0449,
  24804. afii10092: 0x044A,
  24805. afii10093: 0x044B,
  24806. afii10094: 0x044C,
  24807. afii10095: 0x044D,
  24808. afii10096: 0x044E,
  24809. afii10097: 0x044F,
  24810. afii10098: 0x0491,
  24811. afii10099: 0x0452,
  24812. afii10100: 0x0453,
  24813. afii10101: 0x0454,
  24814. afii10102: 0x0455,
  24815. afii10103: 0x0456,
  24816. afii10104: 0x0457,
  24817. afii10105: 0x0458,
  24818. afii10106: 0x0459,
  24819. afii10107: 0x045A,
  24820. afii10108: 0x045B,
  24821. afii10109: 0x045C,
  24822. afii10110: 0x045E,
  24823. afii10145: 0x040F,
  24824. afii10146: 0x0462,
  24825. afii10147: 0x0472,
  24826. afii10148: 0x0474,
  24827. afii10192: 0xF6C6,
  24828. afii10193: 0x045F,
  24829. afii10194: 0x0463,
  24830. afii10195: 0x0473,
  24831. afii10196: 0x0475,
  24832. afii10831: 0xF6C7,
  24833. afii10832: 0xF6C8,
  24834. afii10846: 0x04D9,
  24835. afii299: 0x200E,
  24836. afii300: 0x200F,
  24837. afii301: 0x200D,
  24838. afii57381: 0x066A,
  24839. afii57388: 0x060C,
  24840. afii57392: 0x0660,
  24841. afii57393: 0x0661,
  24842. afii57394: 0x0662,
  24843. afii57395: 0x0663,
  24844. afii57396: 0x0664,
  24845. afii57397: 0x0665,
  24846. afii57398: 0x0666,
  24847. afii57399: 0x0667,
  24848. afii57400: 0x0668,
  24849. afii57401: 0x0669,
  24850. afii57403: 0x061B,
  24851. afii57407: 0x061F,
  24852. afii57409: 0x0621,
  24853. afii57410: 0x0622,
  24854. afii57411: 0x0623,
  24855. afii57412: 0x0624,
  24856. afii57413: 0x0625,
  24857. afii57414: 0x0626,
  24858. afii57415: 0x0627,
  24859. afii57416: 0x0628,
  24860. afii57417: 0x0629,
  24861. afii57418: 0x062A,
  24862. afii57419: 0x062B,
  24863. afii57420: 0x062C,
  24864. afii57421: 0x062D,
  24865. afii57422: 0x062E,
  24866. afii57423: 0x062F,
  24867. afii57424: 0x0630,
  24868. afii57425: 0x0631,
  24869. afii57426: 0x0632,
  24870. afii57427: 0x0633,
  24871. afii57428: 0x0634,
  24872. afii57429: 0x0635,
  24873. afii57430: 0x0636,
  24874. afii57431: 0x0637,
  24875. afii57432: 0x0638,
  24876. afii57433: 0x0639,
  24877. afii57434: 0x063A,
  24878. afii57440: 0x0640,
  24879. afii57441: 0x0641,
  24880. afii57442: 0x0642,
  24881. afii57443: 0x0643,
  24882. afii57444: 0x0644,
  24883. afii57445: 0x0645,
  24884. afii57446: 0x0646,
  24885. afii57448: 0x0648,
  24886. afii57449: 0x0649,
  24887. afii57450: 0x064A,
  24888. afii57451: 0x064B,
  24889. afii57452: 0x064C,
  24890. afii57453: 0x064D,
  24891. afii57454: 0x064E,
  24892. afii57455: 0x064F,
  24893. afii57456: 0x0650,
  24894. afii57457: 0x0651,
  24895. afii57458: 0x0652,
  24896. afii57470: 0x0647,
  24897. afii57505: 0x06A4,
  24898. afii57506: 0x067E,
  24899. afii57507: 0x0686,
  24900. afii57508: 0x0698,
  24901. afii57509: 0x06AF,
  24902. afii57511: 0x0679,
  24903. afii57512: 0x0688,
  24904. afii57513: 0x0691,
  24905. afii57514: 0x06BA,
  24906. afii57519: 0x06D2,
  24907. afii57534: 0x06D5,
  24908. afii57636: 0x20AA,
  24909. afii57645: 0x05BE,
  24910. afii57658: 0x05C3,
  24911. afii57664: 0x05D0,
  24912. afii57665: 0x05D1,
  24913. afii57666: 0x05D2,
  24914. afii57667: 0x05D3,
  24915. afii57668: 0x05D4,
  24916. afii57669: 0x05D5,
  24917. afii57670: 0x05D6,
  24918. afii57671: 0x05D7,
  24919. afii57672: 0x05D8,
  24920. afii57673: 0x05D9,
  24921. afii57674: 0x05DA,
  24922. afii57675: 0x05DB,
  24923. afii57676: 0x05DC,
  24924. afii57677: 0x05DD,
  24925. afii57678: 0x05DE,
  24926. afii57679: 0x05DF,
  24927. afii57680: 0x05E0,
  24928. afii57681: 0x05E1,
  24929. afii57682: 0x05E2,
  24930. afii57683: 0x05E3,
  24931. afii57684: 0x05E4,
  24932. afii57685: 0x05E5,
  24933. afii57686: 0x05E6,
  24934. afii57687: 0x05E7,
  24935. afii57688: 0x05E8,
  24936. afii57689: 0x05E9,
  24937. afii57690: 0x05EA,
  24938. afii57694: 0xFB2A,
  24939. afii57695: 0xFB2B,
  24940. afii57700: 0xFB4B,
  24941. afii57705: 0xFB1F,
  24942. afii57716: 0x05F0,
  24943. afii57717: 0x05F1,
  24944. afii57718: 0x05F2,
  24945. afii57723: 0xFB35,
  24946. afii57793: 0x05B4,
  24947. afii57794: 0x05B5,
  24948. afii57795: 0x05B6,
  24949. afii57796: 0x05BB,
  24950. afii57797: 0x05B8,
  24951. afii57798: 0x05B7,
  24952. afii57799: 0x05B0,
  24953. afii57800: 0x05B2,
  24954. afii57801: 0x05B1,
  24955. afii57802: 0x05B3,
  24956. afii57803: 0x05C2,
  24957. afii57804: 0x05C1,
  24958. afii57806: 0x05B9,
  24959. afii57807: 0x05BC,
  24960. afii57839: 0x05BD,
  24961. afii57841: 0x05BF,
  24962. afii57842: 0x05C0,
  24963. afii57929: 0x02BC,
  24964. afii61248: 0x2105,
  24965. afii61289: 0x2113,
  24966. afii61352: 0x2116,
  24967. afii61573: 0x202C,
  24968. afii61574: 0x202D,
  24969. afii61575: 0x202E,
  24970. afii61664: 0x200C,
  24971. afii63167: 0x066D,
  24972. afii64937: 0x02BD,
  24973. agrave: 0x00E0,
  24974. agujarati: 0x0A85,
  24975. agurmukhi: 0x0A05,
  24976. ahiragana: 0x3042,
  24977. ahookabove: 0x1EA3,
  24978. aibengali: 0x0990,
  24979. aibopomofo: 0x311E,
  24980. aideva: 0x0910,
  24981. aiecyrillic: 0x04D5,
  24982. aigujarati: 0x0A90,
  24983. aigurmukhi: 0x0A10,
  24984. aimatragurmukhi: 0x0A48,
  24985. ainarabic: 0x0639,
  24986. ainfinalarabic: 0xFECA,
  24987. aininitialarabic: 0xFECB,
  24988. ainmedialarabic: 0xFECC,
  24989. ainvertedbreve: 0x0203,
  24990. aivowelsignbengali: 0x09C8,
  24991. aivowelsigndeva: 0x0948,
  24992. aivowelsigngujarati: 0x0AC8,
  24993. akatakana: 0x30A2,
  24994. akatakanahalfwidth: 0xFF71,
  24995. akorean: 0x314F,
  24996. alef: 0x05D0,
  24997. alefarabic: 0x0627,
  24998. alefdageshhebrew: 0xFB30,
  24999. aleffinalarabic: 0xFE8E,
  25000. alefhamzaabovearabic: 0x0623,
  25001. alefhamzaabovefinalarabic: 0xFE84,
  25002. alefhamzabelowarabic: 0x0625,
  25003. alefhamzabelowfinalarabic: 0xFE88,
  25004. alefhebrew: 0x05D0,
  25005. aleflamedhebrew: 0xFB4F,
  25006. alefmaddaabovearabic: 0x0622,
  25007. alefmaddaabovefinalarabic: 0xFE82,
  25008. alefmaksuraarabic: 0x0649,
  25009. alefmaksurafinalarabic: 0xFEF0,
  25010. alefmaksurainitialarabic: 0xFEF3,
  25011. alefmaksuramedialarabic: 0xFEF4,
  25012. alefpatahhebrew: 0xFB2E,
  25013. alefqamatshebrew: 0xFB2F,
  25014. aleph: 0x2135,
  25015. allequal: 0x224C,
  25016. alpha: 0x03B1,
  25017. alphatonos: 0x03AC,
  25018. amacron: 0x0101,
  25019. amonospace: 0xFF41,
  25020. ampersand: 0x0026,
  25021. ampersandmonospace: 0xFF06,
  25022. ampersandsmall: 0xF726,
  25023. amsquare: 0x33C2,
  25024. anbopomofo: 0x3122,
  25025. angbopomofo: 0x3124,
  25026. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  25027. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  25028. angkhankhuthai: 0x0E5A,
  25029. angle: 0x2220,
  25030. anglebracketleft: 0x3008,
  25031. anglebracketleftvertical: 0xFE3F,
  25032. anglebracketright: 0x3009,
  25033. anglebracketrightvertical: 0xFE40,
  25034. angleleft: 0x2329,
  25035. angleright: 0x232A,
  25036. angstrom: 0x212B,
  25037. anoteleia: 0x0387,
  25038. anudattadeva: 0x0952,
  25039. anusvarabengali: 0x0982,
  25040. anusvaradeva: 0x0902,
  25041. anusvaragujarati: 0x0A82,
  25042. aogonek: 0x0105,
  25043. apaatosquare: 0x3300,
  25044. aparen: 0x249C,
  25045. apostrophearmenian: 0x055A,
  25046. apostrophemod: 0x02BC,
  25047. apple: 0xF8FF,
  25048. approaches: 0x2250,
  25049. approxequal: 0x2248,
  25050. approxequalorimage: 0x2252,
  25051. approximatelyequal: 0x2245,
  25052. araeaekorean: 0x318E,
  25053. araeakorean: 0x318D,
  25054. arc: 0x2312,
  25055. arighthalfring: 0x1E9A,
  25056. aring: 0x00E5,
  25057. aringacute: 0x01FB,
  25058. aringbelow: 0x1E01,
  25059. arrowboth: 0x2194,
  25060. arrowdashdown: 0x21E3,
  25061. arrowdashleft: 0x21E0,
  25062. arrowdashright: 0x21E2,
  25063. arrowdashup: 0x21E1,
  25064. arrowdblboth: 0x21D4,
  25065. arrowdbldown: 0x21D3,
  25066. arrowdblleft: 0x21D0,
  25067. arrowdblright: 0x21D2,
  25068. arrowdblup: 0x21D1,
  25069. arrowdown: 0x2193,
  25070. arrowdownleft: 0x2199,
  25071. arrowdownright: 0x2198,
  25072. arrowdownwhite: 0x21E9,
  25073. arrowheaddownmod: 0x02C5,
  25074. arrowheadleftmod: 0x02C2,
  25075. arrowheadrightmod: 0x02C3,
  25076. arrowheadupmod: 0x02C4,
  25077. arrowhorizex: 0xF8E7,
  25078. arrowleft: 0x2190,
  25079. arrowleftdbl: 0x21D0,
  25080. arrowleftdblstroke: 0x21CD,
  25081. arrowleftoverright: 0x21C6,
  25082. arrowleftwhite: 0x21E6,
  25083. arrowright: 0x2192,
  25084. arrowrightdblstroke: 0x21CF,
  25085. arrowrightheavy: 0x279E,
  25086. arrowrightoverleft: 0x21C4,
  25087. arrowrightwhite: 0x21E8,
  25088. arrowtableft: 0x21E4,
  25089. arrowtabright: 0x21E5,
  25090. arrowup: 0x2191,
  25091. arrowupdn: 0x2195,
  25092. arrowupdnbse: 0x21A8,
  25093. arrowupdownbase: 0x21A8,
  25094. arrowupleft: 0x2196,
  25095. arrowupleftofdown: 0x21C5,
  25096. arrowupright: 0x2197,
  25097. arrowupwhite: 0x21E7,
  25098. arrowvertex: 0xF8E6,
  25099. asciicircum: 0x005E,
  25100. asciicircummonospace: 0xFF3E,
  25101. asciitilde: 0x007E,
  25102. asciitildemonospace: 0xFF5E,
  25103. ascript: 0x0251,
  25104. ascriptturned: 0x0252,
  25105. asmallhiragana: 0x3041,
  25106. asmallkatakana: 0x30A1,
  25107. asmallkatakanahalfwidth: 0xFF67,
  25108. asterisk: 0x002A,
  25109. asteriskaltonearabic: 0x066D,
  25110. asteriskarabic: 0x066D,
  25111. asteriskmath: 0x2217,
  25112. asteriskmonospace: 0xFF0A,
  25113. asterisksmall: 0xFE61,
  25114. asterism: 0x2042,
  25115. asuperior: 0xF6E9,
  25116. asymptoticallyequal: 0x2243,
  25117. at: 0x0040,
  25118. atilde: 0x00E3,
  25119. atmonospace: 0xFF20,
  25120. atsmall: 0xFE6B,
  25121. aturned: 0x0250,
  25122. aubengali: 0x0994,
  25123. aubopomofo: 0x3120,
  25124. audeva: 0x0914,
  25125. augujarati: 0x0A94,
  25126. augurmukhi: 0x0A14,
  25127. aulengthmarkbengali: 0x09D7,
  25128. aumatragurmukhi: 0x0A4C,
  25129. auvowelsignbengali: 0x09CC,
  25130. auvowelsigndeva: 0x094C,
  25131. auvowelsigngujarati: 0x0ACC,
  25132. avagrahadeva: 0x093D,
  25133. aybarmenian: 0x0561,
  25134. ayin: 0x05E2,
  25135. ayinaltonehebrew: 0xFB20,
  25136. ayinhebrew: 0x05E2,
  25137. b: 0x0062,
  25138. babengali: 0x09AC,
  25139. backslash: 0x005C,
  25140. backslashmonospace: 0xFF3C,
  25141. badeva: 0x092C,
  25142. bagujarati: 0x0AAC,
  25143. bagurmukhi: 0x0A2C,
  25144. bahiragana: 0x3070,
  25145. bahtthai: 0x0E3F,
  25146. bakatakana: 0x30D0,
  25147. bar: 0x007C,
  25148. barmonospace: 0xFF5C,
  25149. bbopomofo: 0x3105,
  25150. bcircle: 0x24D1,
  25151. bdotaccent: 0x1E03,
  25152. bdotbelow: 0x1E05,
  25153. beamedsixteenthnotes: 0x266C,
  25154. because: 0x2235,
  25155. becyrillic: 0x0431,
  25156. beharabic: 0x0628,
  25157. behfinalarabic: 0xFE90,
  25158. behinitialarabic: 0xFE91,
  25159. behiragana: 0x3079,
  25160. behmedialarabic: 0xFE92,
  25161. behmeeminitialarabic: 0xFC9F,
  25162. behmeemisolatedarabic: 0xFC08,
  25163. behnoonfinalarabic: 0xFC6D,
  25164. bekatakana: 0x30D9,
  25165. benarmenian: 0x0562,
  25166. bet: 0x05D1,
  25167. beta: 0x03B2,
  25168. betasymbolgreek: 0x03D0,
  25169. betdagesh: 0xFB31,
  25170. betdageshhebrew: 0xFB31,
  25171. bethebrew: 0x05D1,
  25172. betrafehebrew: 0xFB4C,
  25173. bhabengali: 0x09AD,
  25174. bhadeva: 0x092D,
  25175. bhagujarati: 0x0AAD,
  25176. bhagurmukhi: 0x0A2D,
  25177. bhook: 0x0253,
  25178. bihiragana: 0x3073,
  25179. bikatakana: 0x30D3,
  25180. bilabialclick: 0x0298,
  25181. bindigurmukhi: 0x0A02,
  25182. birusquare: 0x3331,
  25183. blackcircle: 0x25CF,
  25184. blackdiamond: 0x25C6,
  25185. blackdownpointingtriangle: 0x25BC,
  25186. blackleftpointingpointer: 0x25C4,
  25187. blackleftpointingtriangle: 0x25C0,
  25188. blacklenticularbracketleft: 0x3010,
  25189. blacklenticularbracketleftvertical: 0xFE3B,
  25190. blacklenticularbracketright: 0x3011,
  25191. blacklenticularbracketrightvertical: 0xFE3C,
  25192. blacklowerlefttriangle: 0x25E3,
  25193. blacklowerrighttriangle: 0x25E2,
  25194. blackrectangle: 0x25AC,
  25195. blackrightpointingpointer: 0x25BA,
  25196. blackrightpointingtriangle: 0x25B6,
  25197. blacksmallsquare: 0x25AA,
  25198. blacksmilingface: 0x263B,
  25199. blacksquare: 0x25A0,
  25200. blackstar: 0x2605,
  25201. blackupperlefttriangle: 0x25E4,
  25202. blackupperrighttriangle: 0x25E5,
  25203. blackuppointingsmalltriangle: 0x25B4,
  25204. blackuppointingtriangle: 0x25B2,
  25205. blank: 0x2423,
  25206. blinebelow: 0x1E07,
  25207. block: 0x2588,
  25208. bmonospace: 0xFF42,
  25209. bobaimaithai: 0x0E1A,
  25210. bohiragana: 0x307C,
  25211. bokatakana: 0x30DC,
  25212. bparen: 0x249D,
  25213. bqsquare: 0x33C3,
  25214. braceex: 0xF8F4,
  25215. braceleft: 0x007B,
  25216. braceleftbt: 0xF8F3,
  25217. braceleftmid: 0xF8F2,
  25218. braceleftmonospace: 0xFF5B,
  25219. braceleftsmall: 0xFE5B,
  25220. bracelefttp: 0xF8F1,
  25221. braceleftvertical: 0xFE37,
  25222. braceright: 0x007D,
  25223. bracerightbt: 0xF8FE,
  25224. bracerightmid: 0xF8FD,
  25225. bracerightmonospace: 0xFF5D,
  25226. bracerightsmall: 0xFE5C,
  25227. bracerighttp: 0xF8FC,
  25228. bracerightvertical: 0xFE38,
  25229. bracketleft: 0x005B,
  25230. bracketleftbt: 0xF8F0,
  25231. bracketleftex: 0xF8EF,
  25232. bracketleftmonospace: 0xFF3B,
  25233. bracketlefttp: 0xF8EE,
  25234. bracketright: 0x005D,
  25235. bracketrightbt: 0xF8FB,
  25236. bracketrightex: 0xF8FA,
  25237. bracketrightmonospace: 0xFF3D,
  25238. bracketrighttp: 0xF8F9,
  25239. breve: 0x02D8,
  25240. brevebelowcmb: 0x032E,
  25241. brevecmb: 0x0306,
  25242. breveinvertedbelowcmb: 0x032F,
  25243. breveinvertedcmb: 0x0311,
  25244. breveinverteddoublecmb: 0x0361,
  25245. bridgebelowcmb: 0x032A,
  25246. bridgeinvertedbelowcmb: 0x033A,
  25247. brokenbar: 0x00A6,
  25248. bstroke: 0x0180,
  25249. bsuperior: 0xF6EA,
  25250. btopbar: 0x0183,
  25251. buhiragana: 0x3076,
  25252. bukatakana: 0x30D6,
  25253. bullet: 0x2022,
  25254. bulletinverse: 0x25D8,
  25255. bulletoperator: 0x2219,
  25256. bullseye: 0x25CE,
  25257. c: 0x0063,
  25258. caarmenian: 0x056E,
  25259. cabengali: 0x099A,
  25260. cacute: 0x0107,
  25261. cadeva: 0x091A,
  25262. cagujarati: 0x0A9A,
  25263. cagurmukhi: 0x0A1A,
  25264. calsquare: 0x3388,
  25265. candrabindubengali: 0x0981,
  25266. candrabinducmb: 0x0310,
  25267. candrabindudeva: 0x0901,
  25268. candrabindugujarati: 0x0A81,
  25269. capslock: 0x21EA,
  25270. careof: 0x2105,
  25271. caron: 0x02C7,
  25272. caronbelowcmb: 0x032C,
  25273. caroncmb: 0x030C,
  25274. carriagereturn: 0x21B5,
  25275. cbopomofo: 0x3118,
  25276. ccaron: 0x010D,
  25277. ccedilla: 0x00E7,
  25278. ccedillaacute: 0x1E09,
  25279. ccircle: 0x24D2,
  25280. ccircumflex: 0x0109,
  25281. ccurl: 0x0255,
  25282. cdot: 0x010B,
  25283. cdotaccent: 0x010B,
  25284. cdsquare: 0x33C5,
  25285. cedilla: 0x00B8,
  25286. cedillacmb: 0x0327,
  25287. cent: 0x00A2,
  25288. centigrade: 0x2103,
  25289. centinferior: 0xF6DF,
  25290. centmonospace: 0xFFE0,
  25291. centoldstyle: 0xF7A2,
  25292. centsuperior: 0xF6E0,
  25293. chaarmenian: 0x0579,
  25294. chabengali: 0x099B,
  25295. chadeva: 0x091B,
  25296. chagujarati: 0x0A9B,
  25297. chagurmukhi: 0x0A1B,
  25298. chbopomofo: 0x3114,
  25299. cheabkhasiancyrillic: 0x04BD,
  25300. checkmark: 0x2713,
  25301. checyrillic: 0x0447,
  25302. chedescenderabkhasiancyrillic: 0x04BF,
  25303. chedescendercyrillic: 0x04B7,
  25304. chedieresiscyrillic: 0x04F5,
  25305. cheharmenian: 0x0573,
  25306. chekhakassiancyrillic: 0x04CC,
  25307. cheverticalstrokecyrillic: 0x04B9,
  25308. chi: 0x03C7,
  25309. chieuchacirclekorean: 0x3277,
  25310. chieuchaparenkorean: 0x3217,
  25311. chieuchcirclekorean: 0x3269,
  25312. chieuchkorean: 0x314A,
  25313. chieuchparenkorean: 0x3209,
  25314. chochangthai: 0x0E0A,
  25315. chochanthai: 0x0E08,
  25316. chochingthai: 0x0E09,
  25317. chochoethai: 0x0E0C,
  25318. chook: 0x0188,
  25319. cieucacirclekorean: 0x3276,
  25320. cieucaparenkorean: 0x3216,
  25321. cieuccirclekorean: 0x3268,
  25322. cieuckorean: 0x3148,
  25323. cieucparenkorean: 0x3208,
  25324. cieucuparenkorean: 0x321C,
  25325. circle: 0x25CB,
  25326. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  25327. circlemultiply: 0x2297,
  25328. circleot: 0x2299,
  25329. circleplus: 0x2295,
  25330. circlepostalmark: 0x3036,
  25331. circlewithlefthalfblack: 0x25D0,
  25332. circlewithrighthalfblack: 0x25D1,
  25333. circumflex: 0x02C6,
  25334. circumflexbelowcmb: 0x032D,
  25335. circumflexcmb: 0x0302,
  25336. clear: 0x2327,
  25337. clickalveolar: 0x01C2,
  25338. clickdental: 0x01C0,
  25339. clicklateral: 0x01C1,
  25340. clickretroflex: 0x01C3,
  25341. club: 0x2663,
  25342. clubsuitblack: 0x2663,
  25343. clubsuitwhite: 0x2667,
  25344. cmcubedsquare: 0x33A4,
  25345. cmonospace: 0xFF43,
  25346. cmsquaredsquare: 0x33A0,
  25347. coarmenian: 0x0581,
  25348. colon: 0x003A,
  25349. colonmonetary: 0x20A1,
  25350. colonmonospace: 0xFF1A,
  25351. colonsign: 0x20A1,
  25352. colonsmall: 0xFE55,
  25353. colontriangularhalfmod: 0x02D1,
  25354. colontriangularmod: 0x02D0,
  25355. comma: 0x002C,
  25356. commaabovecmb: 0x0313,
  25357. commaaboverightcmb: 0x0315,
  25358. commaaccent: 0xF6C3,
  25359. commaarabic: 0x060C,
  25360. commaarmenian: 0x055D,
  25361. commainferior: 0xF6E1,
  25362. commamonospace: 0xFF0C,
  25363. commareversedabovecmb: 0x0314,
  25364. commareversedmod: 0x02BD,
  25365. commasmall: 0xFE50,
  25366. commasuperior: 0xF6E2,
  25367. commaturnedabovecmb: 0x0312,
  25368. commaturnedmod: 0x02BB,
  25369. compass: 0x263C,
  25370. congruent: 0x2245,
  25371. contourintegral: 0x222E,
  25372. control: 0x2303,
  25373. controlACK: 0x0006,
  25374. controlBEL: 0x0007,
  25375. controlBS: 0x0008,
  25376. controlCAN: 0x0018,
  25377. controlCR: 0x000D,
  25378. controlDC1: 0x0011,
  25379. controlDC2: 0x0012,
  25380. controlDC3: 0x0013,
  25381. controlDC4: 0x0014,
  25382. controlDEL: 0x007F,
  25383. controlDLE: 0x0010,
  25384. controlEM: 0x0019,
  25385. controlENQ: 0x0005,
  25386. controlEOT: 0x0004,
  25387. controlESC: 0x001B,
  25388. controlETB: 0x0017,
  25389. controlETX: 0x0003,
  25390. controlFF: 0x000C,
  25391. controlFS: 0x001C,
  25392. controlGS: 0x001D,
  25393. controlHT: 0x0009,
  25394. controlLF: 0x000A,
  25395. controlNAK: 0x0015,
  25396. controlRS: 0x001E,
  25397. controlSI: 0x000F,
  25398. controlSO: 0x000E,
  25399. controlSOT: 0x0002,
  25400. controlSTX: 0x0001,
  25401. controlSUB: 0x001A,
  25402. controlSYN: 0x0016,
  25403. controlUS: 0x001F,
  25404. controlVT: 0x000B,
  25405. copyright: 0x00A9,
  25406. copyrightsans: 0xF8E9,
  25407. copyrightserif: 0xF6D9,
  25408. cornerbracketleft: 0x300C,
  25409. cornerbracketlefthalfwidth: 0xFF62,
  25410. cornerbracketleftvertical: 0xFE41,
  25411. cornerbracketright: 0x300D,
  25412. cornerbracketrighthalfwidth: 0xFF63,
  25413. cornerbracketrightvertical: 0xFE42,
  25414. corporationsquare: 0x337F,
  25415. cosquare: 0x33C7,
  25416. coverkgsquare: 0x33C6,
  25417. cparen: 0x249E,
  25418. cruzeiro: 0x20A2,
  25419. cstretched: 0x0297,
  25420. curlyand: 0x22CF,
  25421. curlyor: 0x22CE,
  25422. currency: 0x00A4,
  25423. cyrBreve: 0xF6D1,
  25424. cyrFlex: 0xF6D2,
  25425. cyrbreve: 0xF6D4,
  25426. cyrflex: 0xF6D5,
  25427. d: 0x0064,
  25428. daarmenian: 0x0564,
  25429. dabengali: 0x09A6,
  25430. dadarabic: 0x0636,
  25431. dadeva: 0x0926,
  25432. dadfinalarabic: 0xFEBE,
  25433. dadinitialarabic: 0xFEBF,
  25434. dadmedialarabic: 0xFEC0,
  25435. dagesh: 0x05BC,
  25436. dageshhebrew: 0x05BC,
  25437. dagger: 0x2020,
  25438. daggerdbl: 0x2021,
  25439. dagujarati: 0x0AA6,
  25440. dagurmukhi: 0x0A26,
  25441. dahiragana: 0x3060,
  25442. dakatakana: 0x30C0,
  25443. dalarabic: 0x062F,
  25444. dalet: 0x05D3,
  25445. daletdagesh: 0xFB33,
  25446. daletdageshhebrew: 0xFB33,
  25447. dalethebrew: 0x05D3,
  25448. dalfinalarabic: 0xFEAA,
  25449. dammaarabic: 0x064F,
  25450. dammalowarabic: 0x064F,
  25451. dammatanaltonearabic: 0x064C,
  25452. dammatanarabic: 0x064C,
  25453. danda: 0x0964,
  25454. dargahebrew: 0x05A7,
  25455. dargalefthebrew: 0x05A7,
  25456. dasiapneumatacyrilliccmb: 0x0485,
  25457. dblGrave: 0xF6D3,
  25458. dblanglebracketleft: 0x300A,
  25459. dblanglebracketleftvertical: 0xFE3D,
  25460. dblanglebracketright: 0x300B,
  25461. dblanglebracketrightvertical: 0xFE3E,
  25462. dblarchinvertedbelowcmb: 0x032B,
  25463. dblarrowleft: 0x21D4,
  25464. dblarrowright: 0x21D2,
  25465. dbldanda: 0x0965,
  25466. dblgrave: 0xF6D6,
  25467. dblgravecmb: 0x030F,
  25468. dblintegral: 0x222C,
  25469. dbllowline: 0x2017,
  25470. dbllowlinecmb: 0x0333,
  25471. dbloverlinecmb: 0x033F,
  25472. dblprimemod: 0x02BA,
  25473. dblverticalbar: 0x2016,
  25474. dblverticallineabovecmb: 0x030E,
  25475. dbopomofo: 0x3109,
  25476. dbsquare: 0x33C8,
  25477. dcaron: 0x010F,
  25478. dcedilla: 0x1E11,
  25479. dcircle: 0x24D3,
  25480. dcircumflexbelow: 0x1E13,
  25481. dcroat: 0x0111,
  25482. ddabengali: 0x09A1,
  25483. ddadeva: 0x0921,
  25484. ddagujarati: 0x0AA1,
  25485. ddagurmukhi: 0x0A21,
  25486. ddalarabic: 0x0688,
  25487. ddalfinalarabic: 0xFB89,
  25488. dddhadeva: 0x095C,
  25489. ddhabengali: 0x09A2,
  25490. ddhadeva: 0x0922,
  25491. ddhagujarati: 0x0AA2,
  25492. ddhagurmukhi: 0x0A22,
  25493. ddotaccent: 0x1E0B,
  25494. ddotbelow: 0x1E0D,
  25495. decimalseparatorarabic: 0x066B,
  25496. decimalseparatorpersian: 0x066B,
  25497. decyrillic: 0x0434,
  25498. degree: 0x00B0,
  25499. dehihebrew: 0x05AD,
  25500. dehiragana: 0x3067,
  25501. deicoptic: 0x03EF,
  25502. dekatakana: 0x30C7,
  25503. deleteleft: 0x232B,
  25504. deleteright: 0x2326,
  25505. delta: 0x03B4,
  25506. deltaturned: 0x018D,
  25507. denominatorminusonenumeratorbengali: 0x09F8,
  25508. dezh: 0x02A4,
  25509. dhabengali: 0x09A7,
  25510. dhadeva: 0x0927,
  25511. dhagujarati: 0x0AA7,
  25512. dhagurmukhi: 0x0A27,
  25513. dhook: 0x0257,
  25514. dialytikatonos: 0x0385,
  25515. dialytikatonoscmb: 0x0344,
  25516. diamond: 0x2666,
  25517. diamondsuitwhite: 0x2662,
  25518. dieresis: 0x00A8,
  25519. dieresisacute: 0xF6D7,
  25520. dieresisbelowcmb: 0x0324,
  25521. dieresiscmb: 0x0308,
  25522. dieresisgrave: 0xF6D8,
  25523. dieresistonos: 0x0385,
  25524. dihiragana: 0x3062,
  25525. dikatakana: 0x30C2,
  25526. dittomark: 0x3003,
  25527. divide: 0x00F7,
  25528. divides: 0x2223,
  25529. divisionslash: 0x2215,
  25530. djecyrillic: 0x0452,
  25531. dkshade: 0x2593,
  25532. dlinebelow: 0x1E0F,
  25533. dlsquare: 0x3397,
  25534. dmacron: 0x0111,
  25535. dmonospace: 0xFF44,
  25536. dnblock: 0x2584,
  25537. dochadathai: 0x0E0E,
  25538. dodekthai: 0x0E14,
  25539. dohiragana: 0x3069,
  25540. dokatakana: 0x30C9,
  25541. dollar: 0x0024,
  25542. dollarinferior: 0xF6E3,
  25543. dollarmonospace: 0xFF04,
  25544. dollaroldstyle: 0xF724,
  25545. dollarsmall: 0xFE69,
  25546. dollarsuperior: 0xF6E4,
  25547. dong: 0x20AB,
  25548. dorusquare: 0x3326,
  25549. dotaccent: 0x02D9,
  25550. dotaccentcmb: 0x0307,
  25551. dotbelowcmb: 0x0323,
  25552. dotbelowcomb: 0x0323,
  25553. dotkatakana: 0x30FB,
  25554. dotlessi: 0x0131,
  25555. dotlessj: 0xF6BE,
  25556. dotlessjstrokehook: 0x0284,
  25557. dotmath: 0x22C5,
  25558. dottedcircle: 0x25CC,
  25559. doubleyodpatah: 0xFB1F,
  25560. doubleyodpatahhebrew: 0xFB1F,
  25561. downtackbelowcmb: 0x031E,
  25562. downtackmod: 0x02D5,
  25563. dparen: 0x249F,
  25564. dsuperior: 0xF6EB,
  25565. dtail: 0x0256,
  25566. dtopbar: 0x018C,
  25567. duhiragana: 0x3065,
  25568. dukatakana: 0x30C5,
  25569. dz: 0x01F3,
  25570. dzaltone: 0x02A3,
  25571. dzcaron: 0x01C6,
  25572. dzcurl: 0x02A5,
  25573. dzeabkhasiancyrillic: 0x04E1,
  25574. dzecyrillic: 0x0455,
  25575. dzhecyrillic: 0x045F,
  25576. e: 0x0065,
  25577. eacute: 0x00E9,
  25578. earth: 0x2641,
  25579. ebengali: 0x098F,
  25580. ebopomofo: 0x311C,
  25581. ebreve: 0x0115,
  25582. ecandradeva: 0x090D,
  25583. ecandragujarati: 0x0A8D,
  25584. ecandravowelsigndeva: 0x0945,
  25585. ecandravowelsigngujarati: 0x0AC5,
  25586. ecaron: 0x011B,
  25587. ecedillabreve: 0x1E1D,
  25588. echarmenian: 0x0565,
  25589. echyiwnarmenian: 0x0587,
  25590. ecircle: 0x24D4,
  25591. ecircumflex: 0x00EA,
  25592. ecircumflexacute: 0x1EBF,
  25593. ecircumflexbelow: 0x1E19,
  25594. ecircumflexdotbelow: 0x1EC7,
  25595. ecircumflexgrave: 0x1EC1,
  25596. ecircumflexhookabove: 0x1EC3,
  25597. ecircumflextilde: 0x1EC5,
  25598. ecyrillic: 0x0454,
  25599. edblgrave: 0x0205,
  25600. edeva: 0x090F,
  25601. edieresis: 0x00EB,
  25602. edot: 0x0117,
  25603. edotaccent: 0x0117,
  25604. edotbelow: 0x1EB9,
  25605. eegurmukhi: 0x0A0F,
  25606. eematragurmukhi: 0x0A47,
  25607. efcyrillic: 0x0444,
  25608. egrave: 0x00E8,
  25609. egujarati: 0x0A8F,
  25610. eharmenian: 0x0567,
  25611. ehbopomofo: 0x311D,
  25612. ehiragana: 0x3048,
  25613. ehookabove: 0x1EBB,
  25614. eibopomofo: 0x311F,
  25615. eight: 0x0038,
  25616. eightarabic: 0x0668,
  25617. eightbengali: 0x09EE,
  25618. eightcircle: 0x2467,
  25619. eightcircleinversesansserif: 0x2791,
  25620. eightdeva: 0x096E,
  25621. eighteencircle: 0x2471,
  25622. eighteenparen: 0x2485,
  25623. eighteenperiod: 0x2499,
  25624. eightgujarati: 0x0AEE,
  25625. eightgurmukhi: 0x0A6E,
  25626. eighthackarabic: 0x0668,
  25627. eighthangzhou: 0x3028,
  25628. eighthnotebeamed: 0x266B,
  25629. eightideographicparen: 0x3227,
  25630. eightinferior: 0x2088,
  25631. eightmonospace: 0xFF18,
  25632. eightoldstyle: 0xF738,
  25633. eightparen: 0x247B,
  25634. eightperiod: 0x248F,
  25635. eightpersian: 0x06F8,
  25636. eightroman: 0x2177,
  25637. eightsuperior: 0x2078,
  25638. eightthai: 0x0E58,
  25639. einvertedbreve: 0x0207,
  25640. eiotifiedcyrillic: 0x0465,
  25641. ekatakana: 0x30A8,
  25642. ekatakanahalfwidth: 0xFF74,
  25643. ekonkargurmukhi: 0x0A74,
  25644. ekorean: 0x3154,
  25645. elcyrillic: 0x043B,
  25646. element: 0x2208,
  25647. elevencircle: 0x246A,
  25648. elevenparen: 0x247E,
  25649. elevenperiod: 0x2492,
  25650. elevenroman: 0x217A,
  25651. ellipsis: 0x2026,
  25652. ellipsisvertical: 0x22EE,
  25653. emacron: 0x0113,
  25654. emacronacute: 0x1E17,
  25655. emacrongrave: 0x1E15,
  25656. emcyrillic: 0x043C,
  25657. emdash: 0x2014,
  25658. emdashvertical: 0xFE31,
  25659. emonospace: 0xFF45,
  25660. emphasismarkarmenian: 0x055B,
  25661. emptyset: 0x2205,
  25662. enbopomofo: 0x3123,
  25663. encyrillic: 0x043D,
  25664. endash: 0x2013,
  25665. endashvertical: 0xFE32,
  25666. endescendercyrillic: 0x04A3,
  25667. eng: 0x014B,
  25668. engbopomofo: 0x3125,
  25669. enghecyrillic: 0x04A5,
  25670. enhookcyrillic: 0x04C8,
  25671. enspace: 0x2002,
  25672. eogonek: 0x0119,
  25673. eokorean: 0x3153,
  25674. eopen: 0x025B,
  25675. eopenclosed: 0x029A,
  25676. eopenreversed: 0x025C,
  25677. eopenreversedclosed: 0x025E,
  25678. eopenreversedhook: 0x025D,
  25679. eparen: 0x24A0,
  25680. epsilon: 0x03B5,
  25681. epsilontonos: 0x03AD,
  25682. equal: 0x003D,
  25683. equalmonospace: 0xFF1D,
  25684. equalsmall: 0xFE66,
  25685. equalsuperior: 0x207C,
  25686. equivalence: 0x2261,
  25687. erbopomofo: 0x3126,
  25688. ercyrillic: 0x0440,
  25689. ereversed: 0x0258,
  25690. ereversedcyrillic: 0x044D,
  25691. escyrillic: 0x0441,
  25692. esdescendercyrillic: 0x04AB,
  25693. esh: 0x0283,
  25694. eshcurl: 0x0286,
  25695. eshortdeva: 0x090E,
  25696. eshortvowelsigndeva: 0x0946,
  25697. eshreversedloop: 0x01AA,
  25698. eshsquatreversed: 0x0285,
  25699. esmallhiragana: 0x3047,
  25700. esmallkatakana: 0x30A7,
  25701. esmallkatakanahalfwidth: 0xFF6A,
  25702. estimated: 0x212E,
  25703. esuperior: 0xF6EC,
  25704. eta: 0x03B7,
  25705. etarmenian: 0x0568,
  25706. etatonos: 0x03AE,
  25707. eth: 0x00F0,
  25708. etilde: 0x1EBD,
  25709. etildebelow: 0x1E1B,
  25710. etnahtafoukhhebrew: 0x0591,
  25711. etnahtafoukhlefthebrew: 0x0591,
  25712. etnahtahebrew: 0x0591,
  25713. etnahtalefthebrew: 0x0591,
  25714. eturned: 0x01DD,
  25715. eukorean: 0x3161,
  25716. euro: 0x20AC,
  25717. evowelsignbengali: 0x09C7,
  25718. evowelsigndeva: 0x0947,
  25719. evowelsigngujarati: 0x0AC7,
  25720. exclam: 0x0021,
  25721. exclamarmenian: 0x055C,
  25722. exclamdbl: 0x203C,
  25723. exclamdown: 0x00A1,
  25724. exclamdownsmall: 0xF7A1,
  25725. exclammonospace: 0xFF01,
  25726. exclamsmall: 0xF721,
  25727. existential: 0x2203,
  25728. ezh: 0x0292,
  25729. ezhcaron: 0x01EF,
  25730. ezhcurl: 0x0293,
  25731. ezhreversed: 0x01B9,
  25732. ezhtail: 0x01BA,
  25733. f: 0x0066,
  25734. fadeva: 0x095E,
  25735. fagurmukhi: 0x0A5E,
  25736. fahrenheit: 0x2109,
  25737. fathaarabic: 0x064E,
  25738. fathalowarabic: 0x064E,
  25739. fathatanarabic: 0x064B,
  25740. fbopomofo: 0x3108,
  25741. fcircle: 0x24D5,
  25742. fdotaccent: 0x1E1F,
  25743. feharabic: 0x0641,
  25744. feharmenian: 0x0586,
  25745. fehfinalarabic: 0xFED2,
  25746. fehinitialarabic: 0xFED3,
  25747. fehmedialarabic: 0xFED4,
  25748. feicoptic: 0x03E5,
  25749. female: 0x2640,
  25750. ff: 0xFB00,
  25751. ffi: 0xFB03,
  25752. ffl: 0xFB04,
  25753. fi: 0xFB01,
  25754. fifteencircle: 0x246E,
  25755. fifteenparen: 0x2482,
  25756. fifteenperiod: 0x2496,
  25757. figuredash: 0x2012,
  25758. filledbox: 0x25A0,
  25759. filledrect: 0x25AC,
  25760. finalkaf: 0x05DA,
  25761. finalkafdagesh: 0xFB3A,
  25762. finalkafdageshhebrew: 0xFB3A,
  25763. finalkafhebrew: 0x05DA,
  25764. finalmem: 0x05DD,
  25765. finalmemhebrew: 0x05DD,
  25766. finalnun: 0x05DF,
  25767. finalnunhebrew: 0x05DF,
  25768. finalpe: 0x05E3,
  25769. finalpehebrew: 0x05E3,
  25770. finaltsadi: 0x05E5,
  25771. finaltsadihebrew: 0x05E5,
  25772. firsttonechinese: 0x02C9,
  25773. fisheye: 0x25C9,
  25774. fitacyrillic: 0x0473,
  25775. five: 0x0035,
  25776. fivearabic: 0x0665,
  25777. fivebengali: 0x09EB,
  25778. fivecircle: 0x2464,
  25779. fivecircleinversesansserif: 0x278E,
  25780. fivedeva: 0x096B,
  25781. fiveeighths: 0x215D,
  25782. fivegujarati: 0x0AEB,
  25783. fivegurmukhi: 0x0A6B,
  25784. fivehackarabic: 0x0665,
  25785. fivehangzhou: 0x3025,
  25786. fiveideographicparen: 0x3224,
  25787. fiveinferior: 0x2085,
  25788. fivemonospace: 0xFF15,
  25789. fiveoldstyle: 0xF735,
  25790. fiveparen: 0x2478,
  25791. fiveperiod: 0x248C,
  25792. fivepersian: 0x06F5,
  25793. fiveroman: 0x2174,
  25794. fivesuperior: 0x2075,
  25795. fivethai: 0x0E55,
  25796. fl: 0xFB02,
  25797. florin: 0x0192,
  25798. fmonospace: 0xFF46,
  25799. fmsquare: 0x3399,
  25800. fofanthai: 0x0E1F,
  25801. fofathai: 0x0E1D,
  25802. fongmanthai: 0x0E4F,
  25803. forall: 0x2200,
  25804. four: 0x0034,
  25805. fourarabic: 0x0664,
  25806. fourbengali: 0x09EA,
  25807. fourcircle: 0x2463,
  25808. fourcircleinversesansserif: 0x278D,
  25809. fourdeva: 0x096A,
  25810. fourgujarati: 0x0AEA,
  25811. fourgurmukhi: 0x0A6A,
  25812. fourhackarabic: 0x0664,
  25813. fourhangzhou: 0x3024,
  25814. fourideographicparen: 0x3223,
  25815. fourinferior: 0x2084,
  25816. fourmonospace: 0xFF14,
  25817. fournumeratorbengali: 0x09F7,
  25818. fouroldstyle: 0xF734,
  25819. fourparen: 0x2477,
  25820. fourperiod: 0x248B,
  25821. fourpersian: 0x06F4,
  25822. fourroman: 0x2173,
  25823. foursuperior: 0x2074,
  25824. fourteencircle: 0x246D,
  25825. fourteenparen: 0x2481,
  25826. fourteenperiod: 0x2495,
  25827. fourthai: 0x0E54,
  25828. fourthtonechinese: 0x02CB,
  25829. fparen: 0x24A1,
  25830. fraction: 0x2044,
  25831. franc: 0x20A3,
  25832. g: 0x0067,
  25833. gabengali: 0x0997,
  25834. gacute: 0x01F5,
  25835. gadeva: 0x0917,
  25836. gafarabic: 0x06AF,
  25837. gaffinalarabic: 0xFB93,
  25838. gafinitialarabic: 0xFB94,
  25839. gafmedialarabic: 0xFB95,
  25840. gagujarati: 0x0A97,
  25841. gagurmukhi: 0x0A17,
  25842. gahiragana: 0x304C,
  25843. gakatakana: 0x30AC,
  25844. gamma: 0x03B3,
  25845. gammalatinsmall: 0x0263,
  25846. gammasuperior: 0x02E0,
  25847. gangiacoptic: 0x03EB,
  25848. gbopomofo: 0x310D,
  25849. gbreve: 0x011F,
  25850. gcaron: 0x01E7,
  25851. gcedilla: 0x0123,
  25852. gcircle: 0x24D6,
  25853. gcircumflex: 0x011D,
  25854. gcommaaccent: 0x0123,
  25855. gdot: 0x0121,
  25856. gdotaccent: 0x0121,
  25857. gecyrillic: 0x0433,
  25858. gehiragana: 0x3052,
  25859. gekatakana: 0x30B2,
  25860. geometricallyequal: 0x2251,
  25861. gereshaccenthebrew: 0x059C,
  25862. gereshhebrew: 0x05F3,
  25863. gereshmuqdamhebrew: 0x059D,
  25864. germandbls: 0x00DF,
  25865. gershayimaccenthebrew: 0x059E,
  25866. gershayimhebrew: 0x05F4,
  25867. getamark: 0x3013,
  25868. ghabengali: 0x0998,
  25869. ghadarmenian: 0x0572,
  25870. ghadeva: 0x0918,
  25871. ghagujarati: 0x0A98,
  25872. ghagurmukhi: 0x0A18,
  25873. ghainarabic: 0x063A,
  25874. ghainfinalarabic: 0xFECE,
  25875. ghaininitialarabic: 0xFECF,
  25876. ghainmedialarabic: 0xFED0,
  25877. ghemiddlehookcyrillic: 0x0495,
  25878. ghestrokecyrillic: 0x0493,
  25879. gheupturncyrillic: 0x0491,
  25880. ghhadeva: 0x095A,
  25881. ghhagurmukhi: 0x0A5A,
  25882. ghook: 0x0260,
  25883. ghzsquare: 0x3393,
  25884. gihiragana: 0x304E,
  25885. gikatakana: 0x30AE,
  25886. gimarmenian: 0x0563,
  25887. gimel: 0x05D2,
  25888. gimeldagesh: 0xFB32,
  25889. gimeldageshhebrew: 0xFB32,
  25890. gimelhebrew: 0x05D2,
  25891. gjecyrillic: 0x0453,
  25892. glottalinvertedstroke: 0x01BE,
  25893. glottalstop: 0x0294,
  25894. glottalstopinverted: 0x0296,
  25895. glottalstopmod: 0x02C0,
  25896. glottalstopreversed: 0x0295,
  25897. glottalstopreversedmod: 0x02C1,
  25898. glottalstopreversedsuperior: 0x02E4,
  25899. glottalstopstroke: 0x02A1,
  25900. glottalstopstrokereversed: 0x02A2,
  25901. gmacron: 0x1E21,
  25902. gmonospace: 0xFF47,
  25903. gohiragana: 0x3054,
  25904. gokatakana: 0x30B4,
  25905. gparen: 0x24A2,
  25906. gpasquare: 0x33AC,
  25907. gradient: 0x2207,
  25908. grave: 0x0060,
  25909. gravebelowcmb: 0x0316,
  25910. gravecmb: 0x0300,
  25911. gravecomb: 0x0300,
  25912. gravedeva: 0x0953,
  25913. gravelowmod: 0x02CE,
  25914. gravemonospace: 0xFF40,
  25915. gravetonecmb: 0x0340,
  25916. greater: 0x003E,
  25917. greaterequal: 0x2265,
  25918. greaterequalorless: 0x22DB,
  25919. greatermonospace: 0xFF1E,
  25920. greaterorequivalent: 0x2273,
  25921. greaterorless: 0x2277,
  25922. greateroverequal: 0x2267,
  25923. greatersmall: 0xFE65,
  25924. gscript: 0x0261,
  25925. gstroke: 0x01E5,
  25926. guhiragana: 0x3050,
  25927. guillemotleft: 0x00AB,
  25928. guillemotright: 0x00BB,
  25929. guilsinglleft: 0x2039,
  25930. guilsinglright: 0x203A,
  25931. gukatakana: 0x30B0,
  25932. guramusquare: 0x3318,
  25933. gysquare: 0x33C9,
  25934. h: 0x0068,
  25935. haabkhasiancyrillic: 0x04A9,
  25936. haaltonearabic: 0x06C1,
  25937. habengali: 0x09B9,
  25938. hadescendercyrillic: 0x04B3,
  25939. hadeva: 0x0939,
  25940. hagujarati: 0x0AB9,
  25941. hagurmukhi: 0x0A39,
  25942. haharabic: 0x062D,
  25943. hahfinalarabic: 0xFEA2,
  25944. hahinitialarabic: 0xFEA3,
  25945. hahiragana: 0x306F,
  25946. hahmedialarabic: 0xFEA4,
  25947. haitusquare: 0x332A,
  25948. hakatakana: 0x30CF,
  25949. hakatakanahalfwidth: 0xFF8A,
  25950. halantgurmukhi: 0x0A4D,
  25951. hamzaarabic: 0x0621,
  25952. hamzalowarabic: 0x0621,
  25953. hangulfiller: 0x3164,
  25954. hardsigncyrillic: 0x044A,
  25955. harpoonleftbarbup: 0x21BC,
  25956. harpoonrightbarbup: 0x21C0,
  25957. hasquare: 0x33CA,
  25958. hatafpatah: 0x05B2,
  25959. hatafpatah16: 0x05B2,
  25960. hatafpatah23: 0x05B2,
  25961. hatafpatah2f: 0x05B2,
  25962. hatafpatahhebrew: 0x05B2,
  25963. hatafpatahnarrowhebrew: 0x05B2,
  25964. hatafpatahquarterhebrew: 0x05B2,
  25965. hatafpatahwidehebrew: 0x05B2,
  25966. hatafqamats: 0x05B3,
  25967. hatafqamats1b: 0x05B3,
  25968. hatafqamats28: 0x05B3,
  25969. hatafqamats34: 0x05B3,
  25970. hatafqamatshebrew: 0x05B3,
  25971. hatafqamatsnarrowhebrew: 0x05B3,
  25972. hatafqamatsquarterhebrew: 0x05B3,
  25973. hatafqamatswidehebrew: 0x05B3,
  25974. hatafsegol: 0x05B1,
  25975. hatafsegol17: 0x05B1,
  25976. hatafsegol24: 0x05B1,
  25977. hatafsegol30: 0x05B1,
  25978. hatafsegolhebrew: 0x05B1,
  25979. hatafsegolnarrowhebrew: 0x05B1,
  25980. hatafsegolquarterhebrew: 0x05B1,
  25981. hatafsegolwidehebrew: 0x05B1,
  25982. hbar: 0x0127,
  25983. hbopomofo: 0x310F,
  25984. hbrevebelow: 0x1E2B,
  25985. hcedilla: 0x1E29,
  25986. hcircle: 0x24D7,
  25987. hcircumflex: 0x0125,
  25988. hdieresis: 0x1E27,
  25989. hdotaccent: 0x1E23,
  25990. hdotbelow: 0x1E25,
  25991. he: 0x05D4,
  25992. heart: 0x2665,
  25993. heartsuitblack: 0x2665,
  25994. heartsuitwhite: 0x2661,
  25995. hedagesh: 0xFB34,
  25996. hedageshhebrew: 0xFB34,
  25997. hehaltonearabic: 0x06C1,
  25998. heharabic: 0x0647,
  25999. hehebrew: 0x05D4,
  26000. hehfinalaltonearabic: 0xFBA7,
  26001. hehfinalalttwoarabic: 0xFEEA,
  26002. hehfinalarabic: 0xFEEA,
  26003. hehhamzaabovefinalarabic: 0xFBA5,
  26004. hehhamzaaboveisolatedarabic: 0xFBA4,
  26005. hehinitialaltonearabic: 0xFBA8,
  26006. hehinitialarabic: 0xFEEB,
  26007. hehiragana: 0x3078,
  26008. hehmedialaltonearabic: 0xFBA9,
  26009. hehmedialarabic: 0xFEEC,
  26010. heiseierasquare: 0x337B,
  26011. hekatakana: 0x30D8,
  26012. hekatakanahalfwidth: 0xFF8D,
  26013. hekutaarusquare: 0x3336,
  26014. henghook: 0x0267,
  26015. herutusquare: 0x3339,
  26016. het: 0x05D7,
  26017. hethebrew: 0x05D7,
  26018. hhook: 0x0266,
  26019. hhooksuperior: 0x02B1,
  26020. hieuhacirclekorean: 0x327B,
  26021. hieuhaparenkorean: 0x321B,
  26022. hieuhcirclekorean: 0x326D,
  26023. hieuhkorean: 0x314E,
  26024. hieuhparenkorean: 0x320D,
  26025. hihiragana: 0x3072,
  26026. hikatakana: 0x30D2,
  26027. hikatakanahalfwidth: 0xFF8B,
  26028. hiriq: 0x05B4,
  26029. hiriq14: 0x05B4,
  26030. hiriq21: 0x05B4,
  26031. hiriq2d: 0x05B4,
  26032. hiriqhebrew: 0x05B4,
  26033. hiriqnarrowhebrew: 0x05B4,
  26034. hiriqquarterhebrew: 0x05B4,
  26035. hiriqwidehebrew: 0x05B4,
  26036. hlinebelow: 0x1E96,
  26037. hmonospace: 0xFF48,
  26038. hoarmenian: 0x0570,
  26039. hohipthai: 0x0E2B,
  26040. hohiragana: 0x307B,
  26041. hokatakana: 0x30DB,
  26042. hokatakanahalfwidth: 0xFF8E,
  26043. holam: 0x05B9,
  26044. holam19: 0x05B9,
  26045. holam26: 0x05B9,
  26046. holam32: 0x05B9,
  26047. holamhebrew: 0x05B9,
  26048. holamnarrowhebrew: 0x05B9,
  26049. holamquarterhebrew: 0x05B9,
  26050. holamwidehebrew: 0x05B9,
  26051. honokhukthai: 0x0E2E,
  26052. hookabovecomb: 0x0309,
  26053. hookcmb: 0x0309,
  26054. hookpalatalizedbelowcmb: 0x0321,
  26055. hookretroflexbelowcmb: 0x0322,
  26056. hoonsquare: 0x3342,
  26057. horicoptic: 0x03E9,
  26058. horizontalbar: 0x2015,
  26059. horncmb: 0x031B,
  26060. hotsprings: 0x2668,
  26061. house: 0x2302,
  26062. hparen: 0x24A3,
  26063. hsuperior: 0x02B0,
  26064. hturned: 0x0265,
  26065. huhiragana: 0x3075,
  26066. huiitosquare: 0x3333,
  26067. hukatakana: 0x30D5,
  26068. hukatakanahalfwidth: 0xFF8C,
  26069. hungarumlaut: 0x02DD,
  26070. hungarumlautcmb: 0x030B,
  26071. hv: 0x0195,
  26072. hyphen: 0x002D,
  26073. hypheninferior: 0xF6E5,
  26074. hyphenmonospace: 0xFF0D,
  26075. hyphensmall: 0xFE63,
  26076. hyphensuperior: 0xF6E6,
  26077. hyphentwo: 0x2010,
  26078. i: 0x0069,
  26079. iacute: 0x00ED,
  26080. iacyrillic: 0x044F,
  26081. ibengali: 0x0987,
  26082. ibopomofo: 0x3127,
  26083. ibreve: 0x012D,
  26084. icaron: 0x01D0,
  26085. icircle: 0x24D8,
  26086. icircumflex: 0x00EE,
  26087. icyrillic: 0x0456,
  26088. idblgrave: 0x0209,
  26089. ideographearthcircle: 0x328F,
  26090. ideographfirecircle: 0x328B,
  26091. ideographicallianceparen: 0x323F,
  26092. ideographiccallparen: 0x323A,
  26093. ideographiccentrecircle: 0x32A5,
  26094. ideographicclose: 0x3006,
  26095. ideographiccomma: 0x3001,
  26096. ideographiccommaleft: 0xFF64,
  26097. ideographiccongratulationparen: 0x3237,
  26098. ideographiccorrectcircle: 0x32A3,
  26099. ideographicearthparen: 0x322F,
  26100. ideographicenterpriseparen: 0x323D,
  26101. ideographicexcellentcircle: 0x329D,
  26102. ideographicfestivalparen: 0x3240,
  26103. ideographicfinancialcircle: 0x3296,
  26104. ideographicfinancialparen: 0x3236,
  26105. ideographicfireparen: 0x322B,
  26106. ideographichaveparen: 0x3232,
  26107. ideographichighcircle: 0x32A4,
  26108. ideographiciterationmark: 0x3005,
  26109. ideographiclaborcircle: 0x3298,
  26110. ideographiclaborparen: 0x3238,
  26111. ideographicleftcircle: 0x32A7,
  26112. ideographiclowcircle: 0x32A6,
  26113. ideographicmedicinecircle: 0x32A9,
  26114. ideographicmetalparen: 0x322E,
  26115. ideographicmoonparen: 0x322A,
  26116. ideographicnameparen: 0x3234,
  26117. ideographicperiod: 0x3002,
  26118. ideographicprintcircle: 0x329E,
  26119. ideographicreachparen: 0x3243,
  26120. ideographicrepresentparen: 0x3239,
  26121. ideographicresourceparen: 0x323E,
  26122. ideographicrightcircle: 0x32A8,
  26123. ideographicsecretcircle: 0x3299,
  26124. ideographicselfparen: 0x3242,
  26125. ideographicsocietyparen: 0x3233,
  26126. ideographicspace: 0x3000,
  26127. ideographicspecialparen: 0x3235,
  26128. ideographicstockparen: 0x3231,
  26129. ideographicstudyparen: 0x323B,
  26130. ideographicsunparen: 0x3230,
  26131. ideographicsuperviseparen: 0x323C,
  26132. ideographicwaterparen: 0x322C,
  26133. ideographicwoodparen: 0x322D,
  26134. ideographiczero: 0x3007,
  26135. ideographmetalcircle: 0x328E,
  26136. ideographmooncircle: 0x328A,
  26137. ideographnamecircle: 0x3294,
  26138. ideographsuncircle: 0x3290,
  26139. ideographwatercircle: 0x328C,
  26140. ideographwoodcircle: 0x328D,
  26141. ideva: 0x0907,
  26142. idieresis: 0x00EF,
  26143. idieresisacute: 0x1E2F,
  26144. idieresiscyrillic: 0x04E5,
  26145. idotbelow: 0x1ECB,
  26146. iebrevecyrillic: 0x04D7,
  26147. iecyrillic: 0x0435,
  26148. ieungacirclekorean: 0x3275,
  26149. ieungaparenkorean: 0x3215,
  26150. ieungcirclekorean: 0x3267,
  26151. ieungkorean: 0x3147,
  26152. ieungparenkorean: 0x3207,
  26153. igrave: 0x00EC,
  26154. igujarati: 0x0A87,
  26155. igurmukhi: 0x0A07,
  26156. ihiragana: 0x3044,
  26157. ihookabove: 0x1EC9,
  26158. iibengali: 0x0988,
  26159. iicyrillic: 0x0438,
  26160. iideva: 0x0908,
  26161. iigujarati: 0x0A88,
  26162. iigurmukhi: 0x0A08,
  26163. iimatragurmukhi: 0x0A40,
  26164. iinvertedbreve: 0x020B,
  26165. iishortcyrillic: 0x0439,
  26166. iivowelsignbengali: 0x09C0,
  26167. iivowelsigndeva: 0x0940,
  26168. iivowelsigngujarati: 0x0AC0,
  26169. ij: 0x0133,
  26170. ikatakana: 0x30A4,
  26171. ikatakanahalfwidth: 0xFF72,
  26172. ikorean: 0x3163,
  26173. ilde: 0x02DC,
  26174. iluyhebrew: 0x05AC,
  26175. imacron: 0x012B,
  26176. imacroncyrillic: 0x04E3,
  26177. imageorapproximatelyequal: 0x2253,
  26178. imatragurmukhi: 0x0A3F,
  26179. imonospace: 0xFF49,
  26180. increment: 0x2206,
  26181. infinity: 0x221E,
  26182. iniarmenian: 0x056B,
  26183. integral: 0x222B,
  26184. integralbottom: 0x2321,
  26185. integralbt: 0x2321,
  26186. integralex: 0xF8F5,
  26187. integraltop: 0x2320,
  26188. integraltp: 0x2320,
  26189. intersection: 0x2229,
  26190. intisquare: 0x3305,
  26191. invbullet: 0x25D8,
  26192. invcircle: 0x25D9,
  26193. invsmileface: 0x263B,
  26194. iocyrillic: 0x0451,
  26195. iogonek: 0x012F,
  26196. iota: 0x03B9,
  26197. iotadieresis: 0x03CA,
  26198. iotadieresistonos: 0x0390,
  26199. iotalatin: 0x0269,
  26200. iotatonos: 0x03AF,
  26201. iparen: 0x24A4,
  26202. irigurmukhi: 0x0A72,
  26203. ismallhiragana: 0x3043,
  26204. ismallkatakana: 0x30A3,
  26205. ismallkatakanahalfwidth: 0xFF68,
  26206. issharbengali: 0x09FA,
  26207. istroke: 0x0268,
  26208. isuperior: 0xF6ED,
  26209. iterationhiragana: 0x309D,
  26210. iterationkatakana: 0x30FD,
  26211. itilde: 0x0129,
  26212. itildebelow: 0x1E2D,
  26213. iubopomofo: 0x3129,
  26214. iucyrillic: 0x044E,
  26215. ivowelsignbengali: 0x09BF,
  26216. ivowelsigndeva: 0x093F,
  26217. ivowelsigngujarati: 0x0ABF,
  26218. izhitsacyrillic: 0x0475,
  26219. izhitsadblgravecyrillic: 0x0477,
  26220. j: 0x006A,
  26221. jaarmenian: 0x0571,
  26222. jabengali: 0x099C,
  26223. jadeva: 0x091C,
  26224. jagujarati: 0x0A9C,
  26225. jagurmukhi: 0x0A1C,
  26226. jbopomofo: 0x3110,
  26227. jcaron: 0x01F0,
  26228. jcircle: 0x24D9,
  26229. jcircumflex: 0x0135,
  26230. jcrossedtail: 0x029D,
  26231. jdotlessstroke: 0x025F,
  26232. jecyrillic: 0x0458,
  26233. jeemarabic: 0x062C,
  26234. jeemfinalarabic: 0xFE9E,
  26235. jeeminitialarabic: 0xFE9F,
  26236. jeemmedialarabic: 0xFEA0,
  26237. jeharabic: 0x0698,
  26238. jehfinalarabic: 0xFB8B,
  26239. jhabengali: 0x099D,
  26240. jhadeva: 0x091D,
  26241. jhagujarati: 0x0A9D,
  26242. jhagurmukhi: 0x0A1D,
  26243. jheharmenian: 0x057B,
  26244. jis: 0x3004,
  26245. jmonospace: 0xFF4A,
  26246. jparen: 0x24A5,
  26247. jsuperior: 0x02B2,
  26248. k: 0x006B,
  26249. kabashkircyrillic: 0x04A1,
  26250. kabengali: 0x0995,
  26251. kacute: 0x1E31,
  26252. kacyrillic: 0x043A,
  26253. kadescendercyrillic: 0x049B,
  26254. kadeva: 0x0915,
  26255. kaf: 0x05DB,
  26256. kafarabic: 0x0643,
  26257. kafdagesh: 0xFB3B,
  26258. kafdageshhebrew: 0xFB3B,
  26259. kaffinalarabic: 0xFEDA,
  26260. kafhebrew: 0x05DB,
  26261. kafinitialarabic: 0xFEDB,
  26262. kafmedialarabic: 0xFEDC,
  26263. kafrafehebrew: 0xFB4D,
  26264. kagujarati: 0x0A95,
  26265. kagurmukhi: 0x0A15,
  26266. kahiragana: 0x304B,
  26267. kahookcyrillic: 0x04C4,
  26268. kakatakana: 0x30AB,
  26269. kakatakanahalfwidth: 0xFF76,
  26270. kappa: 0x03BA,
  26271. kappasymbolgreek: 0x03F0,
  26272. kapyeounmieumkorean: 0x3171,
  26273. kapyeounphieuphkorean: 0x3184,
  26274. kapyeounpieupkorean: 0x3178,
  26275. kapyeounssangpieupkorean: 0x3179,
  26276. karoriisquare: 0x330D,
  26277. kashidaautoarabic: 0x0640,
  26278. kashidaautonosidebearingarabic: 0x0640,
  26279. kasmallkatakana: 0x30F5,
  26280. kasquare: 0x3384,
  26281. kasraarabic: 0x0650,
  26282. kasratanarabic: 0x064D,
  26283. kastrokecyrillic: 0x049F,
  26284. katahiraprolongmarkhalfwidth: 0xFF70,
  26285. kaverticalstrokecyrillic: 0x049D,
  26286. kbopomofo: 0x310E,
  26287. kcalsquare: 0x3389,
  26288. kcaron: 0x01E9,
  26289. kcedilla: 0x0137,
  26290. kcircle: 0x24DA,
  26291. kcommaaccent: 0x0137,
  26292. kdotbelow: 0x1E33,
  26293. keharmenian: 0x0584,
  26294. kehiragana: 0x3051,
  26295. kekatakana: 0x30B1,
  26296. kekatakanahalfwidth: 0xFF79,
  26297. kenarmenian: 0x056F,
  26298. kesmallkatakana: 0x30F6,
  26299. kgreenlandic: 0x0138,
  26300. khabengali: 0x0996,
  26301. khacyrillic: 0x0445,
  26302. khadeva: 0x0916,
  26303. khagujarati: 0x0A96,
  26304. khagurmukhi: 0x0A16,
  26305. khaharabic: 0x062E,
  26306. khahfinalarabic: 0xFEA6,
  26307. khahinitialarabic: 0xFEA7,
  26308. khahmedialarabic: 0xFEA8,
  26309. kheicoptic: 0x03E7,
  26310. khhadeva: 0x0959,
  26311. khhagurmukhi: 0x0A59,
  26312. khieukhacirclekorean: 0x3278,
  26313. khieukhaparenkorean: 0x3218,
  26314. khieukhcirclekorean: 0x326A,
  26315. khieukhkorean: 0x314B,
  26316. khieukhparenkorean: 0x320A,
  26317. khokhaithai: 0x0E02,
  26318. khokhonthai: 0x0E05,
  26319. khokhuatthai: 0x0E03,
  26320. khokhwaithai: 0x0E04,
  26321. khomutthai: 0x0E5B,
  26322. khook: 0x0199,
  26323. khorakhangthai: 0x0E06,
  26324. khzsquare: 0x3391,
  26325. kihiragana: 0x304D,
  26326. kikatakana: 0x30AD,
  26327. kikatakanahalfwidth: 0xFF77,
  26328. kiroguramusquare: 0x3315,
  26329. kiromeetorusquare: 0x3316,
  26330. kirosquare: 0x3314,
  26331. kiyeokacirclekorean: 0x326E,
  26332. kiyeokaparenkorean: 0x320E,
  26333. kiyeokcirclekorean: 0x3260,
  26334. kiyeokkorean: 0x3131,
  26335. kiyeokparenkorean: 0x3200,
  26336. kiyeoksioskorean: 0x3133,
  26337. kjecyrillic: 0x045C,
  26338. klinebelow: 0x1E35,
  26339. klsquare: 0x3398,
  26340. kmcubedsquare: 0x33A6,
  26341. kmonospace: 0xFF4B,
  26342. kmsquaredsquare: 0x33A2,
  26343. kohiragana: 0x3053,
  26344. kohmsquare: 0x33C0,
  26345. kokaithai: 0x0E01,
  26346. kokatakana: 0x30B3,
  26347. kokatakanahalfwidth: 0xFF7A,
  26348. kooposquare: 0x331E,
  26349. koppacyrillic: 0x0481,
  26350. koreanstandardsymbol: 0x327F,
  26351. koroniscmb: 0x0343,
  26352. kparen: 0x24A6,
  26353. kpasquare: 0x33AA,
  26354. ksicyrillic: 0x046F,
  26355. ktsquare: 0x33CF,
  26356. kturned: 0x029E,
  26357. kuhiragana: 0x304F,
  26358. kukatakana: 0x30AF,
  26359. kukatakanahalfwidth: 0xFF78,
  26360. kvsquare: 0x33B8,
  26361. kwsquare: 0x33BE,
  26362. l: 0x006C,
  26363. labengali: 0x09B2,
  26364. lacute: 0x013A,
  26365. ladeva: 0x0932,
  26366. lagujarati: 0x0AB2,
  26367. lagurmukhi: 0x0A32,
  26368. lakkhangyaothai: 0x0E45,
  26369. lamaleffinalarabic: 0xFEFC,
  26370. lamalefhamzaabovefinalarabic: 0xFEF8,
  26371. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  26372. lamalefhamzabelowfinalarabic: 0xFEFA,
  26373. lamalefhamzabelowisolatedarabic: 0xFEF9,
  26374. lamalefisolatedarabic: 0xFEFB,
  26375. lamalefmaddaabovefinalarabic: 0xFEF6,
  26376. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  26377. lamarabic: 0x0644,
  26378. lambda: 0x03BB,
  26379. lambdastroke: 0x019B,
  26380. lamed: 0x05DC,
  26381. lameddagesh: 0xFB3C,
  26382. lameddageshhebrew: 0xFB3C,
  26383. lamedhebrew: 0x05DC,
  26384. lamfinalarabic: 0xFEDE,
  26385. lamhahinitialarabic: 0xFCCA,
  26386. laminitialarabic: 0xFEDF,
  26387. lamjeeminitialarabic: 0xFCC9,
  26388. lamkhahinitialarabic: 0xFCCB,
  26389. lamlamhehisolatedarabic: 0xFDF2,
  26390. lammedialarabic: 0xFEE0,
  26391. lammeemhahinitialarabic: 0xFD88,
  26392. lammeeminitialarabic: 0xFCCC,
  26393. largecircle: 0x25EF,
  26394. lbar: 0x019A,
  26395. lbelt: 0x026C,
  26396. lbopomofo: 0x310C,
  26397. lcaron: 0x013E,
  26398. lcedilla: 0x013C,
  26399. lcircle: 0x24DB,
  26400. lcircumflexbelow: 0x1E3D,
  26401. lcommaaccent: 0x013C,
  26402. ldot: 0x0140,
  26403. ldotaccent: 0x0140,
  26404. ldotbelow: 0x1E37,
  26405. ldotbelowmacron: 0x1E39,
  26406. leftangleabovecmb: 0x031A,
  26407. lefttackbelowcmb: 0x0318,
  26408. less: 0x003C,
  26409. lessequal: 0x2264,
  26410. lessequalorgreater: 0x22DA,
  26411. lessmonospace: 0xFF1C,
  26412. lessorequivalent: 0x2272,
  26413. lessorgreater: 0x2276,
  26414. lessoverequal: 0x2266,
  26415. lesssmall: 0xFE64,
  26416. lezh: 0x026E,
  26417. lfblock: 0x258C,
  26418. lhookretroflex: 0x026D,
  26419. lira: 0x20A4,
  26420. liwnarmenian: 0x056C,
  26421. lj: 0x01C9,
  26422. ljecyrillic: 0x0459,
  26423. ll: 0xF6C0,
  26424. lladeva: 0x0933,
  26425. llagujarati: 0x0AB3,
  26426. llinebelow: 0x1E3B,
  26427. llladeva: 0x0934,
  26428. llvocalicbengali: 0x09E1,
  26429. llvocalicdeva: 0x0961,
  26430. llvocalicvowelsignbengali: 0x09E3,
  26431. llvocalicvowelsigndeva: 0x0963,
  26432. lmiddletilde: 0x026B,
  26433. lmonospace: 0xFF4C,
  26434. lmsquare: 0x33D0,
  26435. lochulathai: 0x0E2C,
  26436. logicaland: 0x2227,
  26437. logicalnot: 0x00AC,
  26438. logicalnotreversed: 0x2310,
  26439. logicalor: 0x2228,
  26440. lolingthai: 0x0E25,
  26441. longs: 0x017F,
  26442. lowlinecenterline: 0xFE4E,
  26443. lowlinecmb: 0x0332,
  26444. lowlinedashed: 0xFE4D,
  26445. lozenge: 0x25CA,
  26446. lparen: 0x24A7,
  26447. lslash: 0x0142,
  26448. lsquare: 0x2113,
  26449. lsuperior: 0xF6EE,
  26450. ltshade: 0x2591,
  26451. luthai: 0x0E26,
  26452. lvocalicbengali: 0x098C,
  26453. lvocalicdeva: 0x090C,
  26454. lvocalicvowelsignbengali: 0x09E2,
  26455. lvocalicvowelsigndeva: 0x0962,
  26456. lxsquare: 0x33D3,
  26457. m: 0x006D,
  26458. mabengali: 0x09AE,
  26459. macron: 0x00AF,
  26460. macronbelowcmb: 0x0331,
  26461. macroncmb: 0x0304,
  26462. macronlowmod: 0x02CD,
  26463. macronmonospace: 0xFFE3,
  26464. macute: 0x1E3F,
  26465. madeva: 0x092E,
  26466. magujarati: 0x0AAE,
  26467. magurmukhi: 0x0A2E,
  26468. mahapakhhebrew: 0x05A4,
  26469. mahapakhlefthebrew: 0x05A4,
  26470. mahiragana: 0x307E,
  26471. maichattawalowleftthai: 0xF895,
  26472. maichattawalowrightthai: 0xF894,
  26473. maichattawathai: 0x0E4B,
  26474. maichattawaupperleftthai: 0xF893,
  26475. maieklowleftthai: 0xF88C,
  26476. maieklowrightthai: 0xF88B,
  26477. maiekthai: 0x0E48,
  26478. maiekupperleftthai: 0xF88A,
  26479. maihanakatleftthai: 0xF884,
  26480. maihanakatthai: 0x0E31,
  26481. maitaikhuleftthai: 0xF889,
  26482. maitaikhuthai: 0x0E47,
  26483. maitholowleftthai: 0xF88F,
  26484. maitholowrightthai: 0xF88E,
  26485. maithothai: 0x0E49,
  26486. maithoupperleftthai: 0xF88D,
  26487. maitrilowleftthai: 0xF892,
  26488. maitrilowrightthai: 0xF891,
  26489. maitrithai: 0x0E4A,
  26490. maitriupperleftthai: 0xF890,
  26491. maiyamokthai: 0x0E46,
  26492. makatakana: 0x30DE,
  26493. makatakanahalfwidth: 0xFF8F,
  26494. male: 0x2642,
  26495. mansyonsquare: 0x3347,
  26496. maqafhebrew: 0x05BE,
  26497. mars: 0x2642,
  26498. masoracirclehebrew: 0x05AF,
  26499. masquare: 0x3383,
  26500. mbopomofo: 0x3107,
  26501. mbsquare: 0x33D4,
  26502. mcircle: 0x24DC,
  26503. mcubedsquare: 0x33A5,
  26504. mdotaccent: 0x1E41,
  26505. mdotbelow: 0x1E43,
  26506. meemarabic: 0x0645,
  26507. meemfinalarabic: 0xFEE2,
  26508. meeminitialarabic: 0xFEE3,
  26509. meemmedialarabic: 0xFEE4,
  26510. meemmeeminitialarabic: 0xFCD1,
  26511. meemmeemisolatedarabic: 0xFC48,
  26512. meetorusquare: 0x334D,
  26513. mehiragana: 0x3081,
  26514. meizierasquare: 0x337E,
  26515. mekatakana: 0x30E1,
  26516. mekatakanahalfwidth: 0xFF92,
  26517. mem: 0x05DE,
  26518. memdagesh: 0xFB3E,
  26519. memdageshhebrew: 0xFB3E,
  26520. memhebrew: 0x05DE,
  26521. menarmenian: 0x0574,
  26522. merkhahebrew: 0x05A5,
  26523. merkhakefulahebrew: 0x05A6,
  26524. merkhakefulalefthebrew: 0x05A6,
  26525. merkhalefthebrew: 0x05A5,
  26526. mhook: 0x0271,
  26527. mhzsquare: 0x3392,
  26528. middledotkatakanahalfwidth: 0xFF65,
  26529. middot: 0x00B7,
  26530. mieumacirclekorean: 0x3272,
  26531. mieumaparenkorean: 0x3212,
  26532. mieumcirclekorean: 0x3264,
  26533. mieumkorean: 0x3141,
  26534. mieumpansioskorean: 0x3170,
  26535. mieumparenkorean: 0x3204,
  26536. mieumpieupkorean: 0x316E,
  26537. mieumsioskorean: 0x316F,
  26538. mihiragana: 0x307F,
  26539. mikatakana: 0x30DF,
  26540. mikatakanahalfwidth: 0xFF90,
  26541. minus: 0x2212,
  26542. minusbelowcmb: 0x0320,
  26543. minuscircle: 0x2296,
  26544. minusmod: 0x02D7,
  26545. minusplus: 0x2213,
  26546. minute: 0x2032,
  26547. miribaarusquare: 0x334A,
  26548. mirisquare: 0x3349,
  26549. mlonglegturned: 0x0270,
  26550. mlsquare: 0x3396,
  26551. mmcubedsquare: 0x33A3,
  26552. mmonospace: 0xFF4D,
  26553. mmsquaredsquare: 0x339F,
  26554. mohiragana: 0x3082,
  26555. mohmsquare: 0x33C1,
  26556. mokatakana: 0x30E2,
  26557. mokatakanahalfwidth: 0xFF93,
  26558. molsquare: 0x33D6,
  26559. momathai: 0x0E21,
  26560. moverssquare: 0x33A7,
  26561. moverssquaredsquare: 0x33A8,
  26562. mparen: 0x24A8,
  26563. mpasquare: 0x33AB,
  26564. mssquare: 0x33B3,
  26565. msuperior: 0xF6EF,
  26566. mturned: 0x026F,
  26567. mu: 0x00B5,
  26568. mu1: 0x00B5,
  26569. muasquare: 0x3382,
  26570. muchgreater: 0x226B,
  26571. muchless: 0x226A,
  26572. mufsquare: 0x338C,
  26573. mugreek: 0x03BC,
  26574. mugsquare: 0x338D,
  26575. muhiragana: 0x3080,
  26576. mukatakana: 0x30E0,
  26577. mukatakanahalfwidth: 0xFF91,
  26578. mulsquare: 0x3395,
  26579. multiply: 0x00D7,
  26580. mumsquare: 0x339B,
  26581. munahhebrew: 0x05A3,
  26582. munahlefthebrew: 0x05A3,
  26583. musicalnote: 0x266A,
  26584. musicalnotedbl: 0x266B,
  26585. musicflatsign: 0x266D,
  26586. musicsharpsign: 0x266F,
  26587. mussquare: 0x33B2,
  26588. muvsquare: 0x33B6,
  26589. muwsquare: 0x33BC,
  26590. mvmegasquare: 0x33B9,
  26591. mvsquare: 0x33B7,
  26592. mwmegasquare: 0x33BF,
  26593. mwsquare: 0x33BD,
  26594. n: 0x006E,
  26595. nabengali: 0x09A8,
  26596. nabla: 0x2207,
  26597. nacute: 0x0144,
  26598. nadeva: 0x0928,
  26599. nagujarati: 0x0AA8,
  26600. nagurmukhi: 0x0A28,
  26601. nahiragana: 0x306A,
  26602. nakatakana: 0x30CA,
  26603. nakatakanahalfwidth: 0xFF85,
  26604. napostrophe: 0x0149,
  26605. nasquare: 0x3381,
  26606. nbopomofo: 0x310B,
  26607. nbspace: 0x00A0,
  26608. ncaron: 0x0148,
  26609. ncedilla: 0x0146,
  26610. ncircle: 0x24DD,
  26611. ncircumflexbelow: 0x1E4B,
  26612. ncommaaccent: 0x0146,
  26613. ndotaccent: 0x1E45,
  26614. ndotbelow: 0x1E47,
  26615. nehiragana: 0x306D,
  26616. nekatakana: 0x30CD,
  26617. nekatakanahalfwidth: 0xFF88,
  26618. newsheqelsign: 0x20AA,
  26619. nfsquare: 0x338B,
  26620. ngabengali: 0x0999,
  26621. ngadeva: 0x0919,
  26622. ngagujarati: 0x0A99,
  26623. ngagurmukhi: 0x0A19,
  26624. ngonguthai: 0x0E07,
  26625. nhiragana: 0x3093,
  26626. nhookleft: 0x0272,
  26627. nhookretroflex: 0x0273,
  26628. nieunacirclekorean: 0x326F,
  26629. nieunaparenkorean: 0x320F,
  26630. nieuncieuckorean: 0x3135,
  26631. nieuncirclekorean: 0x3261,
  26632. nieunhieuhkorean: 0x3136,
  26633. nieunkorean: 0x3134,
  26634. nieunpansioskorean: 0x3168,
  26635. nieunparenkorean: 0x3201,
  26636. nieunsioskorean: 0x3167,
  26637. nieuntikeutkorean: 0x3166,
  26638. nihiragana: 0x306B,
  26639. nikatakana: 0x30CB,
  26640. nikatakanahalfwidth: 0xFF86,
  26641. nikhahitleftthai: 0xF899,
  26642. nikhahitthai: 0x0E4D,
  26643. nine: 0x0039,
  26644. ninearabic: 0x0669,
  26645. ninebengali: 0x09EF,
  26646. ninecircle: 0x2468,
  26647. ninecircleinversesansserif: 0x2792,
  26648. ninedeva: 0x096F,
  26649. ninegujarati: 0x0AEF,
  26650. ninegurmukhi: 0x0A6F,
  26651. ninehackarabic: 0x0669,
  26652. ninehangzhou: 0x3029,
  26653. nineideographicparen: 0x3228,
  26654. nineinferior: 0x2089,
  26655. ninemonospace: 0xFF19,
  26656. nineoldstyle: 0xF739,
  26657. nineparen: 0x247C,
  26658. nineperiod: 0x2490,
  26659. ninepersian: 0x06F9,
  26660. nineroman: 0x2178,
  26661. ninesuperior: 0x2079,
  26662. nineteencircle: 0x2472,
  26663. nineteenparen: 0x2486,
  26664. nineteenperiod: 0x249A,
  26665. ninethai: 0x0E59,
  26666. nj: 0x01CC,
  26667. njecyrillic: 0x045A,
  26668. nkatakana: 0x30F3,
  26669. nkatakanahalfwidth: 0xFF9D,
  26670. nlegrightlong: 0x019E,
  26671. nlinebelow: 0x1E49,
  26672. nmonospace: 0xFF4E,
  26673. nmsquare: 0x339A,
  26674. nnabengali: 0x09A3,
  26675. nnadeva: 0x0923,
  26676. nnagujarati: 0x0AA3,
  26677. nnagurmukhi: 0x0A23,
  26678. nnnadeva: 0x0929,
  26679. nohiragana: 0x306E,
  26680. nokatakana: 0x30CE,
  26681. nokatakanahalfwidth: 0xFF89,
  26682. nonbreakingspace: 0x00A0,
  26683. nonenthai: 0x0E13,
  26684. nonuthai: 0x0E19,
  26685. noonarabic: 0x0646,
  26686. noonfinalarabic: 0xFEE6,
  26687. noonghunnaarabic: 0x06BA,
  26688. noonghunnafinalarabic: 0xFB9F,
  26689. nooninitialarabic: 0xFEE7,
  26690. noonjeeminitialarabic: 0xFCD2,
  26691. noonjeemisolatedarabic: 0xFC4B,
  26692. noonmedialarabic: 0xFEE8,
  26693. noonmeeminitialarabic: 0xFCD5,
  26694. noonmeemisolatedarabic: 0xFC4E,
  26695. noonnoonfinalarabic: 0xFC8D,
  26696. notcontains: 0x220C,
  26697. notelement: 0x2209,
  26698. notelementof: 0x2209,
  26699. notequal: 0x2260,
  26700. notgreater: 0x226F,
  26701. notgreaternorequal: 0x2271,
  26702. notgreaternorless: 0x2279,
  26703. notidentical: 0x2262,
  26704. notless: 0x226E,
  26705. notlessnorequal: 0x2270,
  26706. notparallel: 0x2226,
  26707. notprecedes: 0x2280,
  26708. notsubset: 0x2284,
  26709. notsucceeds: 0x2281,
  26710. notsuperset: 0x2285,
  26711. nowarmenian: 0x0576,
  26712. nparen: 0x24A9,
  26713. nssquare: 0x33B1,
  26714. nsuperior: 0x207F,
  26715. ntilde: 0x00F1,
  26716. nu: 0x03BD,
  26717. nuhiragana: 0x306C,
  26718. nukatakana: 0x30CC,
  26719. nukatakanahalfwidth: 0xFF87,
  26720. nuktabengali: 0x09BC,
  26721. nuktadeva: 0x093C,
  26722. nuktagujarati: 0x0ABC,
  26723. nuktagurmukhi: 0x0A3C,
  26724. numbersign: 0x0023,
  26725. numbersignmonospace: 0xFF03,
  26726. numbersignsmall: 0xFE5F,
  26727. numeralsigngreek: 0x0374,
  26728. numeralsignlowergreek: 0x0375,
  26729. numero: 0x2116,
  26730. nun: 0x05E0,
  26731. nundagesh: 0xFB40,
  26732. nundageshhebrew: 0xFB40,
  26733. nunhebrew: 0x05E0,
  26734. nvsquare: 0x33B5,
  26735. nwsquare: 0x33BB,
  26736. nyabengali: 0x099E,
  26737. nyadeva: 0x091E,
  26738. nyagujarati: 0x0A9E,
  26739. nyagurmukhi: 0x0A1E,
  26740. o: 0x006F,
  26741. oacute: 0x00F3,
  26742. oangthai: 0x0E2D,
  26743. obarred: 0x0275,
  26744. obarredcyrillic: 0x04E9,
  26745. obarreddieresiscyrillic: 0x04EB,
  26746. obengali: 0x0993,
  26747. obopomofo: 0x311B,
  26748. obreve: 0x014F,
  26749. ocandradeva: 0x0911,
  26750. ocandragujarati: 0x0A91,
  26751. ocandravowelsigndeva: 0x0949,
  26752. ocandravowelsigngujarati: 0x0AC9,
  26753. ocaron: 0x01D2,
  26754. ocircle: 0x24DE,
  26755. ocircumflex: 0x00F4,
  26756. ocircumflexacute: 0x1ED1,
  26757. ocircumflexdotbelow: 0x1ED9,
  26758. ocircumflexgrave: 0x1ED3,
  26759. ocircumflexhookabove: 0x1ED5,
  26760. ocircumflextilde: 0x1ED7,
  26761. ocyrillic: 0x043E,
  26762. odblacute: 0x0151,
  26763. odblgrave: 0x020D,
  26764. odeva: 0x0913,
  26765. odieresis: 0x00F6,
  26766. odieresiscyrillic: 0x04E7,
  26767. odotbelow: 0x1ECD,
  26768. oe: 0x0153,
  26769. oekorean: 0x315A,
  26770. ogonek: 0x02DB,
  26771. ogonekcmb: 0x0328,
  26772. ograve: 0x00F2,
  26773. ogujarati: 0x0A93,
  26774. oharmenian: 0x0585,
  26775. ohiragana: 0x304A,
  26776. ohookabove: 0x1ECF,
  26777. ohorn: 0x01A1,
  26778. ohornacute: 0x1EDB,
  26779. ohorndotbelow: 0x1EE3,
  26780. ohorngrave: 0x1EDD,
  26781. ohornhookabove: 0x1EDF,
  26782. ohorntilde: 0x1EE1,
  26783. ohungarumlaut: 0x0151,
  26784. oi: 0x01A3,
  26785. oinvertedbreve: 0x020F,
  26786. okatakana: 0x30AA,
  26787. okatakanahalfwidth: 0xFF75,
  26788. okorean: 0x3157,
  26789. olehebrew: 0x05AB,
  26790. omacron: 0x014D,
  26791. omacronacute: 0x1E53,
  26792. omacrongrave: 0x1E51,
  26793. omdeva: 0x0950,
  26794. omega: 0x03C9,
  26795. omega1: 0x03D6,
  26796. omegacyrillic: 0x0461,
  26797. omegalatinclosed: 0x0277,
  26798. omegaroundcyrillic: 0x047B,
  26799. omegatitlocyrillic: 0x047D,
  26800. omegatonos: 0x03CE,
  26801. omgujarati: 0x0AD0,
  26802. omicron: 0x03BF,
  26803. omicrontonos: 0x03CC,
  26804. omonospace: 0xFF4F,
  26805. one: 0x0031,
  26806. onearabic: 0x0661,
  26807. onebengali: 0x09E7,
  26808. onecircle: 0x2460,
  26809. onecircleinversesansserif: 0x278A,
  26810. onedeva: 0x0967,
  26811. onedotenleader: 0x2024,
  26812. oneeighth: 0x215B,
  26813. onefitted: 0xF6DC,
  26814. onegujarati: 0x0AE7,
  26815. onegurmukhi: 0x0A67,
  26816. onehackarabic: 0x0661,
  26817. onehalf: 0x00BD,
  26818. onehangzhou: 0x3021,
  26819. oneideographicparen: 0x3220,
  26820. oneinferior: 0x2081,
  26821. onemonospace: 0xFF11,
  26822. onenumeratorbengali: 0x09F4,
  26823. oneoldstyle: 0xF731,
  26824. oneparen: 0x2474,
  26825. oneperiod: 0x2488,
  26826. onepersian: 0x06F1,
  26827. onequarter: 0x00BC,
  26828. oneroman: 0x2170,
  26829. onesuperior: 0x00B9,
  26830. onethai: 0x0E51,
  26831. onethird: 0x2153,
  26832. oogonek: 0x01EB,
  26833. oogonekmacron: 0x01ED,
  26834. oogurmukhi: 0x0A13,
  26835. oomatragurmukhi: 0x0A4B,
  26836. oopen: 0x0254,
  26837. oparen: 0x24AA,
  26838. openbullet: 0x25E6,
  26839. option: 0x2325,
  26840. ordfeminine: 0x00AA,
  26841. ordmasculine: 0x00BA,
  26842. orthogonal: 0x221F,
  26843. oshortdeva: 0x0912,
  26844. oshortvowelsigndeva: 0x094A,
  26845. oslash: 0x00F8,
  26846. oslashacute: 0x01FF,
  26847. osmallhiragana: 0x3049,
  26848. osmallkatakana: 0x30A9,
  26849. osmallkatakanahalfwidth: 0xFF6B,
  26850. ostrokeacute: 0x01FF,
  26851. osuperior: 0xF6F0,
  26852. otcyrillic: 0x047F,
  26853. otilde: 0x00F5,
  26854. otildeacute: 0x1E4D,
  26855. otildedieresis: 0x1E4F,
  26856. oubopomofo: 0x3121,
  26857. overline: 0x203E,
  26858. overlinecenterline: 0xFE4A,
  26859. overlinecmb: 0x0305,
  26860. overlinedashed: 0xFE49,
  26861. overlinedblwavy: 0xFE4C,
  26862. overlinewavy: 0xFE4B,
  26863. overscore: 0x00AF,
  26864. ovowelsignbengali: 0x09CB,
  26865. ovowelsigndeva: 0x094B,
  26866. ovowelsigngujarati: 0x0ACB,
  26867. p: 0x0070,
  26868. paampssquare: 0x3380,
  26869. paasentosquare: 0x332B,
  26870. pabengali: 0x09AA,
  26871. pacute: 0x1E55,
  26872. padeva: 0x092A,
  26873. pagedown: 0x21DF,
  26874. pageup: 0x21DE,
  26875. pagujarati: 0x0AAA,
  26876. pagurmukhi: 0x0A2A,
  26877. pahiragana: 0x3071,
  26878. paiyannoithai: 0x0E2F,
  26879. pakatakana: 0x30D1,
  26880. palatalizationcyrilliccmb: 0x0484,
  26881. palochkacyrillic: 0x04C0,
  26882. pansioskorean: 0x317F,
  26883. paragraph: 0x00B6,
  26884. parallel: 0x2225,
  26885. parenleft: 0x0028,
  26886. parenleftaltonearabic: 0xFD3E,
  26887. parenleftbt: 0xF8ED,
  26888. parenleftex: 0xF8EC,
  26889. parenleftinferior: 0x208D,
  26890. parenleftmonospace: 0xFF08,
  26891. parenleftsmall: 0xFE59,
  26892. parenleftsuperior: 0x207D,
  26893. parenlefttp: 0xF8EB,
  26894. parenleftvertical: 0xFE35,
  26895. parenright: 0x0029,
  26896. parenrightaltonearabic: 0xFD3F,
  26897. parenrightbt: 0xF8F8,
  26898. parenrightex: 0xF8F7,
  26899. parenrightinferior: 0x208E,
  26900. parenrightmonospace: 0xFF09,
  26901. parenrightsmall: 0xFE5A,
  26902. parenrightsuperior: 0x207E,
  26903. parenrighttp: 0xF8F6,
  26904. parenrightvertical: 0xFE36,
  26905. partialdiff: 0x2202,
  26906. paseqhebrew: 0x05C0,
  26907. pashtahebrew: 0x0599,
  26908. pasquare: 0x33A9,
  26909. patah: 0x05B7,
  26910. patah11: 0x05B7,
  26911. patah1d: 0x05B7,
  26912. patah2a: 0x05B7,
  26913. patahhebrew: 0x05B7,
  26914. patahnarrowhebrew: 0x05B7,
  26915. patahquarterhebrew: 0x05B7,
  26916. patahwidehebrew: 0x05B7,
  26917. pazerhebrew: 0x05A1,
  26918. pbopomofo: 0x3106,
  26919. pcircle: 0x24DF,
  26920. pdotaccent: 0x1E57,
  26921. pe: 0x05E4,
  26922. pecyrillic: 0x043F,
  26923. pedagesh: 0xFB44,
  26924. pedageshhebrew: 0xFB44,
  26925. peezisquare: 0x333B,
  26926. pefinaldageshhebrew: 0xFB43,
  26927. peharabic: 0x067E,
  26928. peharmenian: 0x057A,
  26929. pehebrew: 0x05E4,
  26930. pehfinalarabic: 0xFB57,
  26931. pehinitialarabic: 0xFB58,
  26932. pehiragana: 0x307A,
  26933. pehmedialarabic: 0xFB59,
  26934. pekatakana: 0x30DA,
  26935. pemiddlehookcyrillic: 0x04A7,
  26936. perafehebrew: 0xFB4E,
  26937. percent: 0x0025,
  26938. percentarabic: 0x066A,
  26939. percentmonospace: 0xFF05,
  26940. percentsmall: 0xFE6A,
  26941. period: 0x002E,
  26942. periodarmenian: 0x0589,
  26943. periodcentered: 0x00B7,
  26944. periodhalfwidth: 0xFF61,
  26945. periodinferior: 0xF6E7,
  26946. periodmonospace: 0xFF0E,
  26947. periodsmall: 0xFE52,
  26948. periodsuperior: 0xF6E8,
  26949. perispomenigreekcmb: 0x0342,
  26950. perpendicular: 0x22A5,
  26951. perthousand: 0x2030,
  26952. peseta: 0x20A7,
  26953. pfsquare: 0x338A,
  26954. phabengali: 0x09AB,
  26955. phadeva: 0x092B,
  26956. phagujarati: 0x0AAB,
  26957. phagurmukhi: 0x0A2B,
  26958. phi: 0x03C6,
  26959. phi1: 0x03D5,
  26960. phieuphacirclekorean: 0x327A,
  26961. phieuphaparenkorean: 0x321A,
  26962. phieuphcirclekorean: 0x326C,
  26963. phieuphkorean: 0x314D,
  26964. phieuphparenkorean: 0x320C,
  26965. philatin: 0x0278,
  26966. phinthuthai: 0x0E3A,
  26967. phisymbolgreek: 0x03D5,
  26968. phook: 0x01A5,
  26969. phophanthai: 0x0E1E,
  26970. phophungthai: 0x0E1C,
  26971. phosamphaothai: 0x0E20,
  26972. pi: 0x03C0,
  26973. pieupacirclekorean: 0x3273,
  26974. pieupaparenkorean: 0x3213,
  26975. pieupcieuckorean: 0x3176,
  26976. pieupcirclekorean: 0x3265,
  26977. pieupkiyeokkorean: 0x3172,
  26978. pieupkorean: 0x3142,
  26979. pieupparenkorean: 0x3205,
  26980. pieupsioskiyeokkorean: 0x3174,
  26981. pieupsioskorean: 0x3144,
  26982. pieupsiostikeutkorean: 0x3175,
  26983. pieupthieuthkorean: 0x3177,
  26984. pieuptikeutkorean: 0x3173,
  26985. pihiragana: 0x3074,
  26986. pikatakana: 0x30D4,
  26987. pisymbolgreek: 0x03D6,
  26988. piwrarmenian: 0x0583,
  26989. plus: 0x002B,
  26990. plusbelowcmb: 0x031F,
  26991. pluscircle: 0x2295,
  26992. plusminus: 0x00B1,
  26993. plusmod: 0x02D6,
  26994. plusmonospace: 0xFF0B,
  26995. plussmall: 0xFE62,
  26996. plussuperior: 0x207A,
  26997. pmonospace: 0xFF50,
  26998. pmsquare: 0x33D8,
  26999. pohiragana: 0x307D,
  27000. pointingindexdownwhite: 0x261F,
  27001. pointingindexleftwhite: 0x261C,
  27002. pointingindexrightwhite: 0x261E,
  27003. pointingindexupwhite: 0x261D,
  27004. pokatakana: 0x30DD,
  27005. poplathai: 0x0E1B,
  27006. postalmark: 0x3012,
  27007. postalmarkface: 0x3020,
  27008. pparen: 0x24AB,
  27009. precedes: 0x227A,
  27010. prescription: 0x211E,
  27011. primemod: 0x02B9,
  27012. primereversed: 0x2035,
  27013. product: 0x220F,
  27014. projective: 0x2305,
  27015. prolongedkana: 0x30FC,
  27016. propellor: 0x2318,
  27017. propersubset: 0x2282,
  27018. propersuperset: 0x2283,
  27019. proportion: 0x2237,
  27020. proportional: 0x221D,
  27021. psi: 0x03C8,
  27022. psicyrillic: 0x0471,
  27023. psilipneumatacyrilliccmb: 0x0486,
  27024. pssquare: 0x33B0,
  27025. puhiragana: 0x3077,
  27026. pukatakana: 0x30D7,
  27027. pvsquare: 0x33B4,
  27028. pwsquare: 0x33BA,
  27029. q: 0x0071,
  27030. qadeva: 0x0958,
  27031. qadmahebrew: 0x05A8,
  27032. qafarabic: 0x0642,
  27033. qaffinalarabic: 0xFED6,
  27034. qafinitialarabic: 0xFED7,
  27035. qafmedialarabic: 0xFED8,
  27036. qamats: 0x05B8,
  27037. qamats10: 0x05B8,
  27038. qamats1a: 0x05B8,
  27039. qamats1c: 0x05B8,
  27040. qamats27: 0x05B8,
  27041. qamats29: 0x05B8,
  27042. qamats33: 0x05B8,
  27043. qamatsde: 0x05B8,
  27044. qamatshebrew: 0x05B8,
  27045. qamatsnarrowhebrew: 0x05B8,
  27046. qamatsqatanhebrew: 0x05B8,
  27047. qamatsqatannarrowhebrew: 0x05B8,
  27048. qamatsqatanquarterhebrew: 0x05B8,
  27049. qamatsqatanwidehebrew: 0x05B8,
  27050. qamatsquarterhebrew: 0x05B8,
  27051. qamatswidehebrew: 0x05B8,
  27052. qarneyparahebrew: 0x059F,
  27053. qbopomofo: 0x3111,
  27054. qcircle: 0x24E0,
  27055. qhook: 0x02A0,
  27056. qmonospace: 0xFF51,
  27057. qof: 0x05E7,
  27058. qofdagesh: 0xFB47,
  27059. qofdageshhebrew: 0xFB47,
  27060. qofhebrew: 0x05E7,
  27061. qparen: 0x24AC,
  27062. quarternote: 0x2669,
  27063. qubuts: 0x05BB,
  27064. qubuts18: 0x05BB,
  27065. qubuts25: 0x05BB,
  27066. qubuts31: 0x05BB,
  27067. qubutshebrew: 0x05BB,
  27068. qubutsnarrowhebrew: 0x05BB,
  27069. qubutsquarterhebrew: 0x05BB,
  27070. qubutswidehebrew: 0x05BB,
  27071. question: 0x003F,
  27072. questionarabic: 0x061F,
  27073. questionarmenian: 0x055E,
  27074. questiondown: 0x00BF,
  27075. questiondownsmall: 0xF7BF,
  27076. questiongreek: 0x037E,
  27077. questionmonospace: 0xFF1F,
  27078. questionsmall: 0xF73F,
  27079. quotedbl: 0x0022,
  27080. quotedblbase: 0x201E,
  27081. quotedblleft: 0x201C,
  27082. quotedblmonospace: 0xFF02,
  27083. quotedblprime: 0x301E,
  27084. quotedblprimereversed: 0x301D,
  27085. quotedblright: 0x201D,
  27086. quoteleft: 0x2018,
  27087. quoteleftreversed: 0x201B,
  27088. quotereversed: 0x201B,
  27089. quoteright: 0x2019,
  27090. quoterightn: 0x0149,
  27091. quotesinglbase: 0x201A,
  27092. quotesingle: 0x0027,
  27093. quotesinglemonospace: 0xFF07,
  27094. r: 0x0072,
  27095. raarmenian: 0x057C,
  27096. rabengali: 0x09B0,
  27097. racute: 0x0155,
  27098. radeva: 0x0930,
  27099. radical: 0x221A,
  27100. radicalex: 0xF8E5,
  27101. radoverssquare: 0x33AE,
  27102. radoverssquaredsquare: 0x33AF,
  27103. radsquare: 0x33AD,
  27104. rafe: 0x05BF,
  27105. rafehebrew: 0x05BF,
  27106. ragujarati: 0x0AB0,
  27107. ragurmukhi: 0x0A30,
  27108. rahiragana: 0x3089,
  27109. rakatakana: 0x30E9,
  27110. rakatakanahalfwidth: 0xFF97,
  27111. ralowerdiagonalbengali: 0x09F1,
  27112. ramiddlediagonalbengali: 0x09F0,
  27113. ramshorn: 0x0264,
  27114. ratio: 0x2236,
  27115. rbopomofo: 0x3116,
  27116. rcaron: 0x0159,
  27117. rcedilla: 0x0157,
  27118. rcircle: 0x24E1,
  27119. rcommaaccent: 0x0157,
  27120. rdblgrave: 0x0211,
  27121. rdotaccent: 0x1E59,
  27122. rdotbelow: 0x1E5B,
  27123. rdotbelowmacron: 0x1E5D,
  27124. referencemark: 0x203B,
  27125. reflexsubset: 0x2286,
  27126. reflexsuperset: 0x2287,
  27127. registered: 0x00AE,
  27128. registersans: 0xF8E8,
  27129. registerserif: 0xF6DA,
  27130. reharabic: 0x0631,
  27131. reharmenian: 0x0580,
  27132. rehfinalarabic: 0xFEAE,
  27133. rehiragana: 0x308C,
  27134. rekatakana: 0x30EC,
  27135. rekatakanahalfwidth: 0xFF9A,
  27136. resh: 0x05E8,
  27137. reshdageshhebrew: 0xFB48,
  27138. reshhebrew: 0x05E8,
  27139. reversedtilde: 0x223D,
  27140. reviahebrew: 0x0597,
  27141. reviamugrashhebrew: 0x0597,
  27142. revlogicalnot: 0x2310,
  27143. rfishhook: 0x027E,
  27144. rfishhookreversed: 0x027F,
  27145. rhabengali: 0x09DD,
  27146. rhadeva: 0x095D,
  27147. rho: 0x03C1,
  27148. rhook: 0x027D,
  27149. rhookturned: 0x027B,
  27150. rhookturnedsuperior: 0x02B5,
  27151. rhosymbolgreek: 0x03F1,
  27152. rhotichookmod: 0x02DE,
  27153. rieulacirclekorean: 0x3271,
  27154. rieulaparenkorean: 0x3211,
  27155. rieulcirclekorean: 0x3263,
  27156. rieulhieuhkorean: 0x3140,
  27157. rieulkiyeokkorean: 0x313A,
  27158. rieulkiyeoksioskorean: 0x3169,
  27159. rieulkorean: 0x3139,
  27160. rieulmieumkorean: 0x313B,
  27161. rieulpansioskorean: 0x316C,
  27162. rieulparenkorean: 0x3203,
  27163. rieulphieuphkorean: 0x313F,
  27164. rieulpieupkorean: 0x313C,
  27165. rieulpieupsioskorean: 0x316B,
  27166. rieulsioskorean: 0x313D,
  27167. rieulthieuthkorean: 0x313E,
  27168. rieultikeutkorean: 0x316A,
  27169. rieulyeorinhieuhkorean: 0x316D,
  27170. rightangle: 0x221F,
  27171. righttackbelowcmb: 0x0319,
  27172. righttriangle: 0x22BF,
  27173. rihiragana: 0x308A,
  27174. rikatakana: 0x30EA,
  27175. rikatakanahalfwidth: 0xFF98,
  27176. ring: 0x02DA,
  27177. ringbelowcmb: 0x0325,
  27178. ringcmb: 0x030A,
  27179. ringhalfleft: 0x02BF,
  27180. ringhalfleftarmenian: 0x0559,
  27181. ringhalfleftbelowcmb: 0x031C,
  27182. ringhalfleftcentered: 0x02D3,
  27183. ringhalfright: 0x02BE,
  27184. ringhalfrightbelowcmb: 0x0339,
  27185. ringhalfrightcentered: 0x02D2,
  27186. rinvertedbreve: 0x0213,
  27187. rittorusquare: 0x3351,
  27188. rlinebelow: 0x1E5F,
  27189. rlongleg: 0x027C,
  27190. rlonglegturned: 0x027A,
  27191. rmonospace: 0xFF52,
  27192. rohiragana: 0x308D,
  27193. rokatakana: 0x30ED,
  27194. rokatakanahalfwidth: 0xFF9B,
  27195. roruathai: 0x0E23,
  27196. rparen: 0x24AD,
  27197. rrabengali: 0x09DC,
  27198. rradeva: 0x0931,
  27199. rragurmukhi: 0x0A5C,
  27200. rreharabic: 0x0691,
  27201. rrehfinalarabic: 0xFB8D,
  27202. rrvocalicbengali: 0x09E0,
  27203. rrvocalicdeva: 0x0960,
  27204. rrvocalicgujarati: 0x0AE0,
  27205. rrvocalicvowelsignbengali: 0x09C4,
  27206. rrvocalicvowelsigndeva: 0x0944,
  27207. rrvocalicvowelsigngujarati: 0x0AC4,
  27208. rsuperior: 0xF6F1,
  27209. rtblock: 0x2590,
  27210. rturned: 0x0279,
  27211. rturnedsuperior: 0x02B4,
  27212. ruhiragana: 0x308B,
  27213. rukatakana: 0x30EB,
  27214. rukatakanahalfwidth: 0xFF99,
  27215. rupeemarkbengali: 0x09F2,
  27216. rupeesignbengali: 0x09F3,
  27217. rupiah: 0xF6DD,
  27218. ruthai: 0x0E24,
  27219. rvocalicbengali: 0x098B,
  27220. rvocalicdeva: 0x090B,
  27221. rvocalicgujarati: 0x0A8B,
  27222. rvocalicvowelsignbengali: 0x09C3,
  27223. rvocalicvowelsigndeva: 0x0943,
  27224. rvocalicvowelsigngujarati: 0x0AC3,
  27225. s: 0x0073,
  27226. sabengali: 0x09B8,
  27227. sacute: 0x015B,
  27228. sacutedotaccent: 0x1E65,
  27229. sadarabic: 0x0635,
  27230. sadeva: 0x0938,
  27231. sadfinalarabic: 0xFEBA,
  27232. sadinitialarabic: 0xFEBB,
  27233. sadmedialarabic: 0xFEBC,
  27234. sagujarati: 0x0AB8,
  27235. sagurmukhi: 0x0A38,
  27236. sahiragana: 0x3055,
  27237. sakatakana: 0x30B5,
  27238. sakatakanahalfwidth: 0xFF7B,
  27239. sallallahoualayhewasallamarabic: 0xFDFA,
  27240. samekh: 0x05E1,
  27241. samekhdagesh: 0xFB41,
  27242. samekhdageshhebrew: 0xFB41,
  27243. samekhhebrew: 0x05E1,
  27244. saraaathai: 0x0E32,
  27245. saraaethai: 0x0E41,
  27246. saraaimaimalaithai: 0x0E44,
  27247. saraaimaimuanthai: 0x0E43,
  27248. saraamthai: 0x0E33,
  27249. saraathai: 0x0E30,
  27250. saraethai: 0x0E40,
  27251. saraiileftthai: 0xF886,
  27252. saraiithai: 0x0E35,
  27253. saraileftthai: 0xF885,
  27254. saraithai: 0x0E34,
  27255. saraothai: 0x0E42,
  27256. saraueeleftthai: 0xF888,
  27257. saraueethai: 0x0E37,
  27258. saraueleftthai: 0xF887,
  27259. sarauethai: 0x0E36,
  27260. sarauthai: 0x0E38,
  27261. sarauuthai: 0x0E39,
  27262. sbopomofo: 0x3119,
  27263. scaron: 0x0161,
  27264. scarondotaccent: 0x1E67,
  27265. scedilla: 0x015F,
  27266. schwa: 0x0259,
  27267. schwacyrillic: 0x04D9,
  27268. schwadieresiscyrillic: 0x04DB,
  27269. schwahook: 0x025A,
  27270. scircle: 0x24E2,
  27271. scircumflex: 0x015D,
  27272. scommaaccent: 0x0219,
  27273. sdotaccent: 0x1E61,
  27274. sdotbelow: 0x1E63,
  27275. sdotbelowdotaccent: 0x1E69,
  27276. seagullbelowcmb: 0x033C,
  27277. second: 0x2033,
  27278. secondtonechinese: 0x02CA,
  27279. section: 0x00A7,
  27280. seenarabic: 0x0633,
  27281. seenfinalarabic: 0xFEB2,
  27282. seeninitialarabic: 0xFEB3,
  27283. seenmedialarabic: 0xFEB4,
  27284. segol: 0x05B6,
  27285. segol13: 0x05B6,
  27286. segol1f: 0x05B6,
  27287. segol2c: 0x05B6,
  27288. segolhebrew: 0x05B6,
  27289. segolnarrowhebrew: 0x05B6,
  27290. segolquarterhebrew: 0x05B6,
  27291. segoltahebrew: 0x0592,
  27292. segolwidehebrew: 0x05B6,
  27293. seharmenian: 0x057D,
  27294. sehiragana: 0x305B,
  27295. sekatakana: 0x30BB,
  27296. sekatakanahalfwidth: 0xFF7E,
  27297. semicolon: 0x003B,
  27298. semicolonarabic: 0x061B,
  27299. semicolonmonospace: 0xFF1B,
  27300. semicolonsmall: 0xFE54,
  27301. semivoicedmarkkana: 0x309C,
  27302. semivoicedmarkkanahalfwidth: 0xFF9F,
  27303. sentisquare: 0x3322,
  27304. sentosquare: 0x3323,
  27305. seven: 0x0037,
  27306. sevenarabic: 0x0667,
  27307. sevenbengali: 0x09ED,
  27308. sevencircle: 0x2466,
  27309. sevencircleinversesansserif: 0x2790,
  27310. sevendeva: 0x096D,
  27311. seveneighths: 0x215E,
  27312. sevengujarati: 0x0AED,
  27313. sevengurmukhi: 0x0A6D,
  27314. sevenhackarabic: 0x0667,
  27315. sevenhangzhou: 0x3027,
  27316. sevenideographicparen: 0x3226,
  27317. seveninferior: 0x2087,
  27318. sevenmonospace: 0xFF17,
  27319. sevenoldstyle: 0xF737,
  27320. sevenparen: 0x247A,
  27321. sevenperiod: 0x248E,
  27322. sevenpersian: 0x06F7,
  27323. sevenroman: 0x2176,
  27324. sevensuperior: 0x2077,
  27325. seventeencircle: 0x2470,
  27326. seventeenparen: 0x2484,
  27327. seventeenperiod: 0x2498,
  27328. seventhai: 0x0E57,
  27329. sfthyphen: 0x00AD,
  27330. shaarmenian: 0x0577,
  27331. shabengali: 0x09B6,
  27332. shacyrillic: 0x0448,
  27333. shaddaarabic: 0x0651,
  27334. shaddadammaarabic: 0xFC61,
  27335. shaddadammatanarabic: 0xFC5E,
  27336. shaddafathaarabic: 0xFC60,
  27337. shaddakasraarabic: 0xFC62,
  27338. shaddakasratanarabic: 0xFC5F,
  27339. shade: 0x2592,
  27340. shadedark: 0x2593,
  27341. shadelight: 0x2591,
  27342. shademedium: 0x2592,
  27343. shadeva: 0x0936,
  27344. shagujarati: 0x0AB6,
  27345. shagurmukhi: 0x0A36,
  27346. shalshelethebrew: 0x0593,
  27347. shbopomofo: 0x3115,
  27348. shchacyrillic: 0x0449,
  27349. sheenarabic: 0x0634,
  27350. sheenfinalarabic: 0xFEB6,
  27351. sheeninitialarabic: 0xFEB7,
  27352. sheenmedialarabic: 0xFEB8,
  27353. sheicoptic: 0x03E3,
  27354. sheqel: 0x20AA,
  27355. sheqelhebrew: 0x20AA,
  27356. sheva: 0x05B0,
  27357. sheva115: 0x05B0,
  27358. sheva15: 0x05B0,
  27359. sheva22: 0x05B0,
  27360. sheva2e: 0x05B0,
  27361. shevahebrew: 0x05B0,
  27362. shevanarrowhebrew: 0x05B0,
  27363. shevaquarterhebrew: 0x05B0,
  27364. shevawidehebrew: 0x05B0,
  27365. shhacyrillic: 0x04BB,
  27366. shimacoptic: 0x03ED,
  27367. shin: 0x05E9,
  27368. shindagesh: 0xFB49,
  27369. shindageshhebrew: 0xFB49,
  27370. shindageshshindot: 0xFB2C,
  27371. shindageshshindothebrew: 0xFB2C,
  27372. shindageshsindot: 0xFB2D,
  27373. shindageshsindothebrew: 0xFB2D,
  27374. shindothebrew: 0x05C1,
  27375. shinhebrew: 0x05E9,
  27376. shinshindot: 0xFB2A,
  27377. shinshindothebrew: 0xFB2A,
  27378. shinsindot: 0xFB2B,
  27379. shinsindothebrew: 0xFB2B,
  27380. shook: 0x0282,
  27381. sigma: 0x03C3,
  27382. sigma1: 0x03C2,
  27383. sigmafinal: 0x03C2,
  27384. sigmalunatesymbolgreek: 0x03F2,
  27385. sihiragana: 0x3057,
  27386. sikatakana: 0x30B7,
  27387. sikatakanahalfwidth: 0xFF7C,
  27388. siluqhebrew: 0x05BD,
  27389. siluqlefthebrew: 0x05BD,
  27390. similar: 0x223C,
  27391. sindothebrew: 0x05C2,
  27392. siosacirclekorean: 0x3274,
  27393. siosaparenkorean: 0x3214,
  27394. sioscieuckorean: 0x317E,
  27395. sioscirclekorean: 0x3266,
  27396. sioskiyeokkorean: 0x317A,
  27397. sioskorean: 0x3145,
  27398. siosnieunkorean: 0x317B,
  27399. siosparenkorean: 0x3206,
  27400. siospieupkorean: 0x317D,
  27401. siostikeutkorean: 0x317C,
  27402. six: 0x0036,
  27403. sixarabic: 0x0666,
  27404. sixbengali: 0x09EC,
  27405. sixcircle: 0x2465,
  27406. sixcircleinversesansserif: 0x278F,
  27407. sixdeva: 0x096C,
  27408. sixgujarati: 0x0AEC,
  27409. sixgurmukhi: 0x0A6C,
  27410. sixhackarabic: 0x0666,
  27411. sixhangzhou: 0x3026,
  27412. sixideographicparen: 0x3225,
  27413. sixinferior: 0x2086,
  27414. sixmonospace: 0xFF16,
  27415. sixoldstyle: 0xF736,
  27416. sixparen: 0x2479,
  27417. sixperiod: 0x248D,
  27418. sixpersian: 0x06F6,
  27419. sixroman: 0x2175,
  27420. sixsuperior: 0x2076,
  27421. sixteencircle: 0x246F,
  27422. sixteencurrencydenominatorbengali: 0x09F9,
  27423. sixteenparen: 0x2483,
  27424. sixteenperiod: 0x2497,
  27425. sixthai: 0x0E56,
  27426. slash: 0x002F,
  27427. slashmonospace: 0xFF0F,
  27428. slong: 0x017F,
  27429. slongdotaccent: 0x1E9B,
  27430. smileface: 0x263A,
  27431. smonospace: 0xFF53,
  27432. sofpasuqhebrew: 0x05C3,
  27433. softhyphen: 0x00AD,
  27434. softsigncyrillic: 0x044C,
  27435. sohiragana: 0x305D,
  27436. sokatakana: 0x30BD,
  27437. sokatakanahalfwidth: 0xFF7F,
  27438. soliduslongoverlaycmb: 0x0338,
  27439. solidusshortoverlaycmb: 0x0337,
  27440. sorusithai: 0x0E29,
  27441. sosalathai: 0x0E28,
  27442. sosothai: 0x0E0B,
  27443. sosuathai: 0x0E2A,
  27444. space: 0x0020,
  27445. spacehackarabic: 0x0020,
  27446. spade: 0x2660,
  27447. spadesuitblack: 0x2660,
  27448. spadesuitwhite: 0x2664,
  27449. sparen: 0x24AE,
  27450. squarebelowcmb: 0x033B,
  27451. squarecc: 0x33C4,
  27452. squarecm: 0x339D,
  27453. squarediagonalcrosshatchfill: 0x25A9,
  27454. squarehorizontalfill: 0x25A4,
  27455. squarekg: 0x338F,
  27456. squarekm: 0x339E,
  27457. squarekmcapital: 0x33CE,
  27458. squareln: 0x33D1,
  27459. squarelog: 0x33D2,
  27460. squaremg: 0x338E,
  27461. squaremil: 0x33D5,
  27462. squaremm: 0x339C,
  27463. squaremsquared: 0x33A1,
  27464. squareorthogonalcrosshatchfill: 0x25A6,
  27465. squareupperlefttolowerrightfill: 0x25A7,
  27466. squareupperrighttolowerleftfill: 0x25A8,
  27467. squareverticalfill: 0x25A5,
  27468. squarewhitewithsmallblack: 0x25A3,
  27469. srsquare: 0x33DB,
  27470. ssabengali: 0x09B7,
  27471. ssadeva: 0x0937,
  27472. ssagujarati: 0x0AB7,
  27473. ssangcieuckorean: 0x3149,
  27474. ssanghieuhkorean: 0x3185,
  27475. ssangieungkorean: 0x3180,
  27476. ssangkiyeokkorean: 0x3132,
  27477. ssangnieunkorean: 0x3165,
  27478. ssangpieupkorean: 0x3143,
  27479. ssangsioskorean: 0x3146,
  27480. ssangtikeutkorean: 0x3138,
  27481. ssuperior: 0xF6F2,
  27482. sterling: 0x00A3,
  27483. sterlingmonospace: 0xFFE1,
  27484. strokelongoverlaycmb: 0x0336,
  27485. strokeshortoverlaycmb: 0x0335,
  27486. subset: 0x2282,
  27487. subsetnotequal: 0x228A,
  27488. subsetorequal: 0x2286,
  27489. succeeds: 0x227B,
  27490. suchthat: 0x220B,
  27491. suhiragana: 0x3059,
  27492. sukatakana: 0x30B9,
  27493. sukatakanahalfwidth: 0xFF7D,
  27494. sukunarabic: 0x0652,
  27495. summation: 0x2211,
  27496. sun: 0x263C,
  27497. superset: 0x2283,
  27498. supersetnotequal: 0x228B,
  27499. supersetorequal: 0x2287,
  27500. svsquare: 0x33DC,
  27501. syouwaerasquare: 0x337C,
  27502. t: 0x0074,
  27503. tabengali: 0x09A4,
  27504. tackdown: 0x22A4,
  27505. tackleft: 0x22A3,
  27506. tadeva: 0x0924,
  27507. tagujarati: 0x0AA4,
  27508. tagurmukhi: 0x0A24,
  27509. taharabic: 0x0637,
  27510. tahfinalarabic: 0xFEC2,
  27511. tahinitialarabic: 0xFEC3,
  27512. tahiragana: 0x305F,
  27513. tahmedialarabic: 0xFEC4,
  27514. taisyouerasquare: 0x337D,
  27515. takatakana: 0x30BF,
  27516. takatakanahalfwidth: 0xFF80,
  27517. tatweelarabic: 0x0640,
  27518. tau: 0x03C4,
  27519. tav: 0x05EA,
  27520. tavdages: 0xFB4A,
  27521. tavdagesh: 0xFB4A,
  27522. tavdageshhebrew: 0xFB4A,
  27523. tavhebrew: 0x05EA,
  27524. tbar: 0x0167,
  27525. tbopomofo: 0x310A,
  27526. tcaron: 0x0165,
  27527. tccurl: 0x02A8,
  27528. tcedilla: 0x0163,
  27529. tcheharabic: 0x0686,
  27530. tchehfinalarabic: 0xFB7B,
  27531. tchehinitialarabic: 0xFB7C,
  27532. tchehmedialarabic: 0xFB7D,
  27533. tcircle: 0x24E3,
  27534. tcircumflexbelow: 0x1E71,
  27535. tcommaaccent: 0x0163,
  27536. tdieresis: 0x1E97,
  27537. tdotaccent: 0x1E6B,
  27538. tdotbelow: 0x1E6D,
  27539. tecyrillic: 0x0442,
  27540. tedescendercyrillic: 0x04AD,
  27541. teharabic: 0x062A,
  27542. tehfinalarabic: 0xFE96,
  27543. tehhahinitialarabic: 0xFCA2,
  27544. tehhahisolatedarabic: 0xFC0C,
  27545. tehinitialarabic: 0xFE97,
  27546. tehiragana: 0x3066,
  27547. tehjeeminitialarabic: 0xFCA1,
  27548. tehjeemisolatedarabic: 0xFC0B,
  27549. tehmarbutaarabic: 0x0629,
  27550. tehmarbutafinalarabic: 0xFE94,
  27551. tehmedialarabic: 0xFE98,
  27552. tehmeeminitialarabic: 0xFCA4,
  27553. tehmeemisolatedarabic: 0xFC0E,
  27554. tehnoonfinalarabic: 0xFC73,
  27555. tekatakana: 0x30C6,
  27556. tekatakanahalfwidth: 0xFF83,
  27557. telephone: 0x2121,
  27558. telephoneblack: 0x260E,
  27559. telishagedolahebrew: 0x05A0,
  27560. telishaqetanahebrew: 0x05A9,
  27561. tencircle: 0x2469,
  27562. tenideographicparen: 0x3229,
  27563. tenparen: 0x247D,
  27564. tenperiod: 0x2491,
  27565. tenroman: 0x2179,
  27566. tesh: 0x02A7,
  27567. tet: 0x05D8,
  27568. tetdagesh: 0xFB38,
  27569. tetdageshhebrew: 0xFB38,
  27570. tethebrew: 0x05D8,
  27571. tetsecyrillic: 0x04B5,
  27572. tevirhebrew: 0x059B,
  27573. tevirlefthebrew: 0x059B,
  27574. thabengali: 0x09A5,
  27575. thadeva: 0x0925,
  27576. thagujarati: 0x0AA5,
  27577. thagurmukhi: 0x0A25,
  27578. thalarabic: 0x0630,
  27579. thalfinalarabic: 0xFEAC,
  27580. thanthakhatlowleftthai: 0xF898,
  27581. thanthakhatlowrightthai: 0xF897,
  27582. thanthakhatthai: 0x0E4C,
  27583. thanthakhatupperleftthai: 0xF896,
  27584. theharabic: 0x062B,
  27585. thehfinalarabic: 0xFE9A,
  27586. thehinitialarabic: 0xFE9B,
  27587. thehmedialarabic: 0xFE9C,
  27588. thereexists: 0x2203,
  27589. therefore: 0x2234,
  27590. theta: 0x03B8,
  27591. theta1: 0x03D1,
  27592. thetasymbolgreek: 0x03D1,
  27593. thieuthacirclekorean: 0x3279,
  27594. thieuthaparenkorean: 0x3219,
  27595. thieuthcirclekorean: 0x326B,
  27596. thieuthkorean: 0x314C,
  27597. thieuthparenkorean: 0x320B,
  27598. thirteencircle: 0x246C,
  27599. thirteenparen: 0x2480,
  27600. thirteenperiod: 0x2494,
  27601. thonangmonthothai: 0x0E11,
  27602. thook: 0x01AD,
  27603. thophuthaothai: 0x0E12,
  27604. thorn: 0x00FE,
  27605. thothahanthai: 0x0E17,
  27606. thothanthai: 0x0E10,
  27607. thothongthai: 0x0E18,
  27608. thothungthai: 0x0E16,
  27609. thousandcyrillic: 0x0482,
  27610. thousandsseparatorarabic: 0x066C,
  27611. thousandsseparatorpersian: 0x066C,
  27612. three: 0x0033,
  27613. threearabic: 0x0663,
  27614. threebengali: 0x09E9,
  27615. threecircle: 0x2462,
  27616. threecircleinversesansserif: 0x278C,
  27617. threedeva: 0x0969,
  27618. threeeighths: 0x215C,
  27619. threegujarati: 0x0AE9,
  27620. threegurmukhi: 0x0A69,
  27621. threehackarabic: 0x0663,
  27622. threehangzhou: 0x3023,
  27623. threeideographicparen: 0x3222,
  27624. threeinferior: 0x2083,
  27625. threemonospace: 0xFF13,
  27626. threenumeratorbengali: 0x09F6,
  27627. threeoldstyle: 0xF733,
  27628. threeparen: 0x2476,
  27629. threeperiod: 0x248A,
  27630. threepersian: 0x06F3,
  27631. threequarters: 0x00BE,
  27632. threequartersemdash: 0xF6DE,
  27633. threeroman: 0x2172,
  27634. threesuperior: 0x00B3,
  27635. threethai: 0x0E53,
  27636. thzsquare: 0x3394,
  27637. tihiragana: 0x3061,
  27638. tikatakana: 0x30C1,
  27639. tikatakanahalfwidth: 0xFF81,
  27640. tikeutacirclekorean: 0x3270,
  27641. tikeutaparenkorean: 0x3210,
  27642. tikeutcirclekorean: 0x3262,
  27643. tikeutkorean: 0x3137,
  27644. tikeutparenkorean: 0x3202,
  27645. tilde: 0x02DC,
  27646. tildebelowcmb: 0x0330,
  27647. tildecmb: 0x0303,
  27648. tildecomb: 0x0303,
  27649. tildedoublecmb: 0x0360,
  27650. tildeoperator: 0x223C,
  27651. tildeoverlaycmb: 0x0334,
  27652. tildeverticalcmb: 0x033E,
  27653. timescircle: 0x2297,
  27654. tipehahebrew: 0x0596,
  27655. tipehalefthebrew: 0x0596,
  27656. tippigurmukhi: 0x0A70,
  27657. titlocyrilliccmb: 0x0483,
  27658. tiwnarmenian: 0x057F,
  27659. tlinebelow: 0x1E6F,
  27660. tmonospace: 0xFF54,
  27661. toarmenian: 0x0569,
  27662. tohiragana: 0x3068,
  27663. tokatakana: 0x30C8,
  27664. tokatakanahalfwidth: 0xFF84,
  27665. tonebarextrahighmod: 0x02E5,
  27666. tonebarextralowmod: 0x02E9,
  27667. tonebarhighmod: 0x02E6,
  27668. tonebarlowmod: 0x02E8,
  27669. tonebarmidmod: 0x02E7,
  27670. tonefive: 0x01BD,
  27671. tonesix: 0x0185,
  27672. tonetwo: 0x01A8,
  27673. tonos: 0x0384,
  27674. tonsquare: 0x3327,
  27675. topatakthai: 0x0E0F,
  27676. tortoiseshellbracketleft: 0x3014,
  27677. tortoiseshellbracketleftsmall: 0xFE5D,
  27678. tortoiseshellbracketleftvertical: 0xFE39,
  27679. tortoiseshellbracketright: 0x3015,
  27680. tortoiseshellbracketrightsmall: 0xFE5E,
  27681. tortoiseshellbracketrightvertical: 0xFE3A,
  27682. totaothai: 0x0E15,
  27683. tpalatalhook: 0x01AB,
  27684. tparen: 0x24AF,
  27685. trademark: 0x2122,
  27686. trademarksans: 0xF8EA,
  27687. trademarkserif: 0xF6DB,
  27688. tretroflexhook: 0x0288,
  27689. triagdn: 0x25BC,
  27690. triaglf: 0x25C4,
  27691. triagrt: 0x25BA,
  27692. triagup: 0x25B2,
  27693. ts: 0x02A6,
  27694. tsadi: 0x05E6,
  27695. tsadidagesh: 0xFB46,
  27696. tsadidageshhebrew: 0xFB46,
  27697. tsadihebrew: 0x05E6,
  27698. tsecyrillic: 0x0446,
  27699. tsere: 0x05B5,
  27700. tsere12: 0x05B5,
  27701. tsere1e: 0x05B5,
  27702. tsere2b: 0x05B5,
  27703. tserehebrew: 0x05B5,
  27704. tserenarrowhebrew: 0x05B5,
  27705. tserequarterhebrew: 0x05B5,
  27706. tserewidehebrew: 0x05B5,
  27707. tshecyrillic: 0x045B,
  27708. tsuperior: 0xF6F3,
  27709. ttabengali: 0x099F,
  27710. ttadeva: 0x091F,
  27711. ttagujarati: 0x0A9F,
  27712. ttagurmukhi: 0x0A1F,
  27713. tteharabic: 0x0679,
  27714. ttehfinalarabic: 0xFB67,
  27715. ttehinitialarabic: 0xFB68,
  27716. ttehmedialarabic: 0xFB69,
  27717. tthabengali: 0x09A0,
  27718. tthadeva: 0x0920,
  27719. tthagujarati: 0x0AA0,
  27720. tthagurmukhi: 0x0A20,
  27721. tturned: 0x0287,
  27722. tuhiragana: 0x3064,
  27723. tukatakana: 0x30C4,
  27724. tukatakanahalfwidth: 0xFF82,
  27725. tusmallhiragana: 0x3063,
  27726. tusmallkatakana: 0x30C3,
  27727. tusmallkatakanahalfwidth: 0xFF6F,
  27728. twelvecircle: 0x246B,
  27729. twelveparen: 0x247F,
  27730. twelveperiod: 0x2493,
  27731. twelveroman: 0x217B,
  27732. twentycircle: 0x2473,
  27733. twentyhangzhou: 0x5344,
  27734. twentyparen: 0x2487,
  27735. twentyperiod: 0x249B,
  27736. two: 0x0032,
  27737. twoarabic: 0x0662,
  27738. twobengali: 0x09E8,
  27739. twocircle: 0x2461,
  27740. twocircleinversesansserif: 0x278B,
  27741. twodeva: 0x0968,
  27742. twodotenleader: 0x2025,
  27743. twodotleader: 0x2025,
  27744. twodotleadervertical: 0xFE30,
  27745. twogujarati: 0x0AE8,
  27746. twogurmukhi: 0x0A68,
  27747. twohackarabic: 0x0662,
  27748. twohangzhou: 0x3022,
  27749. twoideographicparen: 0x3221,
  27750. twoinferior: 0x2082,
  27751. twomonospace: 0xFF12,
  27752. twonumeratorbengali: 0x09F5,
  27753. twooldstyle: 0xF732,
  27754. twoparen: 0x2475,
  27755. twoperiod: 0x2489,
  27756. twopersian: 0x06F2,
  27757. tworoman: 0x2171,
  27758. twostroke: 0x01BB,
  27759. twosuperior: 0x00B2,
  27760. twothai: 0x0E52,
  27761. twothirds: 0x2154,
  27762. u: 0x0075,
  27763. uacute: 0x00FA,
  27764. ubar: 0x0289,
  27765. ubengali: 0x0989,
  27766. ubopomofo: 0x3128,
  27767. ubreve: 0x016D,
  27768. ucaron: 0x01D4,
  27769. ucircle: 0x24E4,
  27770. ucircumflex: 0x00FB,
  27771. ucircumflexbelow: 0x1E77,
  27772. ucyrillic: 0x0443,
  27773. udattadeva: 0x0951,
  27774. udblacute: 0x0171,
  27775. udblgrave: 0x0215,
  27776. udeva: 0x0909,
  27777. udieresis: 0x00FC,
  27778. udieresisacute: 0x01D8,
  27779. udieresisbelow: 0x1E73,
  27780. udieresiscaron: 0x01DA,
  27781. udieresiscyrillic: 0x04F1,
  27782. udieresisgrave: 0x01DC,
  27783. udieresismacron: 0x01D6,
  27784. udotbelow: 0x1EE5,
  27785. ugrave: 0x00F9,
  27786. ugujarati: 0x0A89,
  27787. ugurmukhi: 0x0A09,
  27788. uhiragana: 0x3046,
  27789. uhookabove: 0x1EE7,
  27790. uhorn: 0x01B0,
  27791. uhornacute: 0x1EE9,
  27792. uhorndotbelow: 0x1EF1,
  27793. uhorngrave: 0x1EEB,
  27794. uhornhookabove: 0x1EED,
  27795. uhorntilde: 0x1EEF,
  27796. uhungarumlaut: 0x0171,
  27797. uhungarumlautcyrillic: 0x04F3,
  27798. uinvertedbreve: 0x0217,
  27799. ukatakana: 0x30A6,
  27800. ukatakanahalfwidth: 0xFF73,
  27801. ukcyrillic: 0x0479,
  27802. ukorean: 0x315C,
  27803. umacron: 0x016B,
  27804. umacroncyrillic: 0x04EF,
  27805. umacrondieresis: 0x1E7B,
  27806. umatragurmukhi: 0x0A41,
  27807. umonospace: 0xFF55,
  27808. underscore: 0x005F,
  27809. underscoredbl: 0x2017,
  27810. underscoremonospace: 0xFF3F,
  27811. underscorevertical: 0xFE33,
  27812. underscorewavy: 0xFE4F,
  27813. union: 0x222A,
  27814. universal: 0x2200,
  27815. uogonek: 0x0173,
  27816. uparen: 0x24B0,
  27817. upblock: 0x2580,
  27818. upperdothebrew: 0x05C4,
  27819. upsilon: 0x03C5,
  27820. upsilondieresis: 0x03CB,
  27821. upsilondieresistonos: 0x03B0,
  27822. upsilonlatin: 0x028A,
  27823. upsilontonos: 0x03CD,
  27824. uptackbelowcmb: 0x031D,
  27825. uptackmod: 0x02D4,
  27826. uragurmukhi: 0x0A73,
  27827. uring: 0x016F,
  27828. ushortcyrillic: 0x045E,
  27829. usmallhiragana: 0x3045,
  27830. usmallkatakana: 0x30A5,
  27831. usmallkatakanahalfwidth: 0xFF69,
  27832. ustraightcyrillic: 0x04AF,
  27833. ustraightstrokecyrillic: 0x04B1,
  27834. utilde: 0x0169,
  27835. utildeacute: 0x1E79,
  27836. utildebelow: 0x1E75,
  27837. uubengali: 0x098A,
  27838. uudeva: 0x090A,
  27839. uugujarati: 0x0A8A,
  27840. uugurmukhi: 0x0A0A,
  27841. uumatragurmukhi: 0x0A42,
  27842. uuvowelsignbengali: 0x09C2,
  27843. uuvowelsigndeva: 0x0942,
  27844. uuvowelsigngujarati: 0x0AC2,
  27845. uvowelsignbengali: 0x09C1,
  27846. uvowelsigndeva: 0x0941,
  27847. uvowelsigngujarati: 0x0AC1,
  27848. v: 0x0076,
  27849. vadeva: 0x0935,
  27850. vagujarati: 0x0AB5,
  27851. vagurmukhi: 0x0A35,
  27852. vakatakana: 0x30F7,
  27853. vav: 0x05D5,
  27854. vavdagesh: 0xFB35,
  27855. vavdagesh65: 0xFB35,
  27856. vavdageshhebrew: 0xFB35,
  27857. vavhebrew: 0x05D5,
  27858. vavholam: 0xFB4B,
  27859. vavholamhebrew: 0xFB4B,
  27860. vavvavhebrew: 0x05F0,
  27861. vavyodhebrew: 0x05F1,
  27862. vcircle: 0x24E5,
  27863. vdotbelow: 0x1E7F,
  27864. vecyrillic: 0x0432,
  27865. veharabic: 0x06A4,
  27866. vehfinalarabic: 0xFB6B,
  27867. vehinitialarabic: 0xFB6C,
  27868. vehmedialarabic: 0xFB6D,
  27869. vekatakana: 0x30F9,
  27870. venus: 0x2640,
  27871. verticalbar: 0x007C,
  27872. verticallineabovecmb: 0x030D,
  27873. verticallinebelowcmb: 0x0329,
  27874. verticallinelowmod: 0x02CC,
  27875. verticallinemod: 0x02C8,
  27876. vewarmenian: 0x057E,
  27877. vhook: 0x028B,
  27878. vikatakana: 0x30F8,
  27879. viramabengali: 0x09CD,
  27880. viramadeva: 0x094D,
  27881. viramagujarati: 0x0ACD,
  27882. visargabengali: 0x0983,
  27883. visargadeva: 0x0903,
  27884. visargagujarati: 0x0A83,
  27885. vmonospace: 0xFF56,
  27886. voarmenian: 0x0578,
  27887. voicediterationhiragana: 0x309E,
  27888. voicediterationkatakana: 0x30FE,
  27889. voicedmarkkana: 0x309B,
  27890. voicedmarkkanahalfwidth: 0xFF9E,
  27891. vokatakana: 0x30FA,
  27892. vparen: 0x24B1,
  27893. vtilde: 0x1E7D,
  27894. vturned: 0x028C,
  27895. vuhiragana: 0x3094,
  27896. vukatakana: 0x30F4,
  27897. w: 0x0077,
  27898. wacute: 0x1E83,
  27899. waekorean: 0x3159,
  27900. wahiragana: 0x308F,
  27901. wakatakana: 0x30EF,
  27902. wakatakanahalfwidth: 0xFF9C,
  27903. wakorean: 0x3158,
  27904. wasmallhiragana: 0x308E,
  27905. wasmallkatakana: 0x30EE,
  27906. wattosquare: 0x3357,
  27907. wavedash: 0x301C,
  27908. wavyunderscorevertical: 0xFE34,
  27909. wawarabic: 0x0648,
  27910. wawfinalarabic: 0xFEEE,
  27911. wawhamzaabovearabic: 0x0624,
  27912. wawhamzaabovefinalarabic: 0xFE86,
  27913. wbsquare: 0x33DD,
  27914. wcircle: 0x24E6,
  27915. wcircumflex: 0x0175,
  27916. wdieresis: 0x1E85,
  27917. wdotaccent: 0x1E87,
  27918. wdotbelow: 0x1E89,
  27919. wehiragana: 0x3091,
  27920. weierstrass: 0x2118,
  27921. wekatakana: 0x30F1,
  27922. wekorean: 0x315E,
  27923. weokorean: 0x315D,
  27924. wgrave: 0x1E81,
  27925. whitebullet: 0x25E6,
  27926. whitecircle: 0x25CB,
  27927. whitecircleinverse: 0x25D9,
  27928. whitecornerbracketleft: 0x300E,
  27929. whitecornerbracketleftvertical: 0xFE43,
  27930. whitecornerbracketright: 0x300F,
  27931. whitecornerbracketrightvertical: 0xFE44,
  27932. whitediamond: 0x25C7,
  27933. whitediamondcontainingblacksmalldiamond: 0x25C8,
  27934. whitedownpointingsmalltriangle: 0x25BF,
  27935. whitedownpointingtriangle: 0x25BD,
  27936. whiteleftpointingsmalltriangle: 0x25C3,
  27937. whiteleftpointingtriangle: 0x25C1,
  27938. whitelenticularbracketleft: 0x3016,
  27939. whitelenticularbracketright: 0x3017,
  27940. whiterightpointingsmalltriangle: 0x25B9,
  27941. whiterightpointingtriangle: 0x25B7,
  27942. whitesmallsquare: 0x25AB,
  27943. whitesmilingface: 0x263A,
  27944. whitesquare: 0x25A1,
  27945. whitestar: 0x2606,
  27946. whitetelephone: 0x260F,
  27947. whitetortoiseshellbracketleft: 0x3018,
  27948. whitetortoiseshellbracketright: 0x3019,
  27949. whiteuppointingsmalltriangle: 0x25B5,
  27950. whiteuppointingtriangle: 0x25B3,
  27951. wihiragana: 0x3090,
  27952. wikatakana: 0x30F0,
  27953. wikorean: 0x315F,
  27954. wmonospace: 0xFF57,
  27955. wohiragana: 0x3092,
  27956. wokatakana: 0x30F2,
  27957. wokatakanahalfwidth: 0xFF66,
  27958. won: 0x20A9,
  27959. wonmonospace: 0xFFE6,
  27960. wowaenthai: 0x0E27,
  27961. wparen: 0x24B2,
  27962. wring: 0x1E98,
  27963. wsuperior: 0x02B7,
  27964. wturned: 0x028D,
  27965. wynn: 0x01BF,
  27966. x: 0x0078,
  27967. xabovecmb: 0x033D,
  27968. xbopomofo: 0x3112,
  27969. xcircle: 0x24E7,
  27970. xdieresis: 0x1E8D,
  27971. xdotaccent: 0x1E8B,
  27972. xeharmenian: 0x056D,
  27973. xi: 0x03BE,
  27974. xmonospace: 0xFF58,
  27975. xparen: 0x24B3,
  27976. xsuperior: 0x02E3,
  27977. y: 0x0079,
  27978. yaadosquare: 0x334E,
  27979. yabengali: 0x09AF,
  27980. yacute: 0x00FD,
  27981. yadeva: 0x092F,
  27982. yaekorean: 0x3152,
  27983. yagujarati: 0x0AAF,
  27984. yagurmukhi: 0x0A2F,
  27985. yahiragana: 0x3084,
  27986. yakatakana: 0x30E4,
  27987. yakatakanahalfwidth: 0xFF94,
  27988. yakorean: 0x3151,
  27989. yamakkanthai: 0x0E4E,
  27990. yasmallhiragana: 0x3083,
  27991. yasmallkatakana: 0x30E3,
  27992. yasmallkatakanahalfwidth: 0xFF6C,
  27993. yatcyrillic: 0x0463,
  27994. ycircle: 0x24E8,
  27995. ycircumflex: 0x0177,
  27996. ydieresis: 0x00FF,
  27997. ydotaccent: 0x1E8F,
  27998. ydotbelow: 0x1EF5,
  27999. yeharabic: 0x064A,
  28000. yehbarreearabic: 0x06D2,
  28001. yehbarreefinalarabic: 0xFBAF,
  28002. yehfinalarabic: 0xFEF2,
  28003. yehhamzaabovearabic: 0x0626,
  28004. yehhamzaabovefinalarabic: 0xFE8A,
  28005. yehhamzaaboveinitialarabic: 0xFE8B,
  28006. yehhamzaabovemedialarabic: 0xFE8C,
  28007. yehinitialarabic: 0xFEF3,
  28008. yehmedialarabic: 0xFEF4,
  28009. yehmeeminitialarabic: 0xFCDD,
  28010. yehmeemisolatedarabic: 0xFC58,
  28011. yehnoonfinalarabic: 0xFC94,
  28012. yehthreedotsbelowarabic: 0x06D1,
  28013. yekorean: 0x3156,
  28014. yen: 0x00A5,
  28015. yenmonospace: 0xFFE5,
  28016. yeokorean: 0x3155,
  28017. yeorinhieuhkorean: 0x3186,
  28018. yerahbenyomohebrew: 0x05AA,
  28019. yerahbenyomolefthebrew: 0x05AA,
  28020. yericyrillic: 0x044B,
  28021. yerudieresiscyrillic: 0x04F9,
  28022. yesieungkorean: 0x3181,
  28023. yesieungpansioskorean: 0x3183,
  28024. yesieungsioskorean: 0x3182,
  28025. yetivhebrew: 0x059A,
  28026. ygrave: 0x1EF3,
  28027. yhook: 0x01B4,
  28028. yhookabove: 0x1EF7,
  28029. yiarmenian: 0x0575,
  28030. yicyrillic: 0x0457,
  28031. yikorean: 0x3162,
  28032. yinyang: 0x262F,
  28033. yiwnarmenian: 0x0582,
  28034. ymonospace: 0xFF59,
  28035. yod: 0x05D9,
  28036. yoddagesh: 0xFB39,
  28037. yoddageshhebrew: 0xFB39,
  28038. yodhebrew: 0x05D9,
  28039. yodyodhebrew: 0x05F2,
  28040. yodyodpatahhebrew: 0xFB1F,
  28041. yohiragana: 0x3088,
  28042. yoikorean: 0x3189,
  28043. yokatakana: 0x30E8,
  28044. yokatakanahalfwidth: 0xFF96,
  28045. yokorean: 0x315B,
  28046. yosmallhiragana: 0x3087,
  28047. yosmallkatakana: 0x30E7,
  28048. yosmallkatakanahalfwidth: 0xFF6E,
  28049. yotgreek: 0x03F3,
  28050. yoyaekorean: 0x3188,
  28051. yoyakorean: 0x3187,
  28052. yoyakthai: 0x0E22,
  28053. yoyingthai: 0x0E0D,
  28054. yparen: 0x24B4,
  28055. ypogegrammeni: 0x037A,
  28056. ypogegrammenigreekcmb: 0x0345,
  28057. yr: 0x01A6,
  28058. yring: 0x1E99,
  28059. ysuperior: 0x02B8,
  28060. ytilde: 0x1EF9,
  28061. yturned: 0x028E,
  28062. yuhiragana: 0x3086,
  28063. yuikorean: 0x318C,
  28064. yukatakana: 0x30E6,
  28065. yukatakanahalfwidth: 0xFF95,
  28066. yukorean: 0x3160,
  28067. yusbigcyrillic: 0x046B,
  28068. yusbigiotifiedcyrillic: 0x046D,
  28069. yuslittlecyrillic: 0x0467,
  28070. yuslittleiotifiedcyrillic: 0x0469,
  28071. yusmallhiragana: 0x3085,
  28072. yusmallkatakana: 0x30E5,
  28073. yusmallkatakanahalfwidth: 0xFF6D,
  28074. yuyekorean: 0x318B,
  28075. yuyeokorean: 0x318A,
  28076. yyabengali: 0x09DF,
  28077. yyadeva: 0x095F,
  28078. z: 0x007A,
  28079. zaarmenian: 0x0566,
  28080. zacute: 0x017A,
  28081. zadeva: 0x095B,
  28082. zagurmukhi: 0x0A5B,
  28083. zaharabic: 0x0638,
  28084. zahfinalarabic: 0xFEC6,
  28085. zahinitialarabic: 0xFEC7,
  28086. zahiragana: 0x3056,
  28087. zahmedialarabic: 0xFEC8,
  28088. zainarabic: 0x0632,
  28089. zainfinalarabic: 0xFEB0,
  28090. zakatakana: 0x30B6,
  28091. zaqefgadolhebrew: 0x0595,
  28092. zaqefqatanhebrew: 0x0594,
  28093. zarqahebrew: 0x0598,
  28094. zayin: 0x05D6,
  28095. zayindagesh: 0xFB36,
  28096. zayindageshhebrew: 0xFB36,
  28097. zayinhebrew: 0x05D6,
  28098. zbopomofo: 0x3117,
  28099. zcaron: 0x017E,
  28100. zcircle: 0x24E9,
  28101. zcircumflex: 0x1E91,
  28102. zcurl: 0x0291,
  28103. zdot: 0x017C,
  28104. zdotaccent: 0x017C,
  28105. zdotbelow: 0x1E93,
  28106. zecyrillic: 0x0437,
  28107. zedescendercyrillic: 0x0499,
  28108. zedieresiscyrillic: 0x04DF,
  28109. zehiragana: 0x305C,
  28110. zekatakana: 0x30BC,
  28111. zero: 0x0030,
  28112. zeroarabic: 0x0660,
  28113. zerobengali: 0x09E6,
  28114. zerodeva: 0x0966,
  28115. zerogujarati: 0x0AE6,
  28116. zerogurmukhi: 0x0A66,
  28117. zerohackarabic: 0x0660,
  28118. zeroinferior: 0x2080,
  28119. zeromonospace: 0xFF10,
  28120. zerooldstyle: 0xF730,
  28121. zeropersian: 0x06F0,
  28122. zerosuperior: 0x2070,
  28123. zerothai: 0x0E50,
  28124. zerowidthjoiner: 0xFEFF,
  28125. zerowidthnonjoiner: 0x200C,
  28126. zerowidthspace: 0x200B,
  28127. zeta: 0x03B6,
  28128. zhbopomofo: 0x3113,
  28129. zhearmenian: 0x056A,
  28130. zhebrevecyrillic: 0x04C2,
  28131. zhecyrillic: 0x0436,
  28132. zhedescendercyrillic: 0x0497,
  28133. zhedieresiscyrillic: 0x04DD,
  28134. zihiragana: 0x3058,
  28135. zikatakana: 0x30B8,
  28136. zinorhebrew: 0x05AE,
  28137. zlinebelow: 0x1E95,
  28138. zmonospace: 0xFF5A,
  28139. zohiragana: 0x305E,
  28140. zokatakana: 0x30BE,
  28141. zparen: 0x24B5,
  28142. zretroflexhook: 0x0290,
  28143. zstroke: 0x01B6,
  28144. zuhiragana: 0x305A,
  28145. zukatakana: 0x30BA,
  28146. '.notdef': 0x0000
  28147. };
  28148. var PDFImage = (function PDFImageClosure() {
  28149. /**
  28150. * Decode the image in the main thread if it supported. Resovles the promise
  28151. * when the image data is ready.
  28152. */
  28153. function handleImageData(handler, xref, res, image) {
  28154. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  28155. // For natively supported jpegs send them to the main thread for decoding.
  28156. var dict = image.dict;
  28157. var colorSpace = dict.get('ColorSpace', 'CS');
  28158. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  28159. var numComps = colorSpace.numComps;
  28160. var decodePromise = handler.sendWithPromise('JpegDecode',
  28161. [image.getIR(), numComps]);
  28162. return decodePromise.then(function (message) {
  28163. var data = message.data;
  28164. return new Stream(data, 0, data.length, image.dict);
  28165. });
  28166. } else {
  28167. return Promise.resolve(image);
  28168. }
  28169. }
  28170. /**
  28171. * Decode and clamp a value. The formula is different from the spec because we
  28172. * don't decode to float range [0,1], we decode it in the [0,max] range.
  28173. */
  28174. function decodeAndClamp(value, addend, coefficient, max) {
  28175. value = addend + value * coefficient;
  28176. // Clamp the value to the range
  28177. return (value < 0 ? 0 : (value > max ? max : value));
  28178. }
  28179. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  28180. this.image = image;
  28181. var dict = image.dict;
  28182. if (dict.has('Filter')) {
  28183. var filter = dict.get('Filter').name;
  28184. if (filter === 'JPXDecode') {
  28185. var jpxImage = new JpxImage();
  28186. jpxImage.parseImageProperties(image.stream);
  28187. image.stream.reset();
  28188. image.bitsPerComponent = jpxImage.bitsPerComponent;
  28189. image.numComps = jpxImage.componentsCount;
  28190. } else if (filter === 'JBIG2Decode') {
  28191. image.bitsPerComponent = 1;
  28192. image.numComps = 1;
  28193. }
  28194. }
  28195. // TODO cache rendered images?
  28196. this.width = dict.get('Width', 'W');
  28197. this.height = dict.get('Height', 'H');
  28198. if (this.width < 1 || this.height < 1) {
  28199. error('Invalid image width: ' + this.width + ' or height: ' +
  28200. this.height);
  28201. }
  28202. this.interpolate = dict.get('Interpolate', 'I') || false;
  28203. this.imageMask = dict.get('ImageMask', 'IM') || false;
  28204. this.matte = dict.get('Matte') || false;
  28205. var bitsPerComponent = image.bitsPerComponent;
  28206. if (!bitsPerComponent) {
  28207. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  28208. if (!bitsPerComponent) {
  28209. if (this.imageMask) {
  28210. bitsPerComponent = 1;
  28211. } else {
  28212. error('Bits per component missing in image: ' + this.imageMask);
  28213. }
  28214. }
  28215. }
  28216. this.bpc = bitsPerComponent;
  28217. if (!this.imageMask) {
  28218. var colorSpace = dict.get('ColorSpace', 'CS');
  28219. if (!colorSpace) {
  28220. info('JPX images (which do not require color spaces)');
  28221. switch (image.numComps) {
  28222. case 1:
  28223. colorSpace = Name.get('DeviceGray');
  28224. break;
  28225. case 3:
  28226. colorSpace = Name.get('DeviceRGB');
  28227. break;
  28228. case 4:
  28229. colorSpace = Name.get('DeviceCMYK');
  28230. break;
  28231. default:
  28232. error('JPX images with ' + this.numComps +
  28233. ' color components not supported.');
  28234. }
  28235. }
  28236. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  28237. this.numComps = this.colorSpace.numComps;
  28238. }
  28239. this.decode = dict.get('Decode', 'D');
  28240. this.needsDecode = false;
  28241. if (this.decode &&
  28242. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  28243. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  28244. this.needsDecode = true;
  28245. // Do some preprocessing to avoid more math.
  28246. var max = (1 << bitsPerComponent) - 1;
  28247. this.decodeCoefficients = [];
  28248. this.decodeAddends = [];
  28249. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  28250. var dmin = this.decode[i];
  28251. var dmax = this.decode[i + 1];
  28252. this.decodeCoefficients[j] = dmax - dmin;
  28253. this.decodeAddends[j] = max * dmin;
  28254. }
  28255. }
  28256. if (smask) {
  28257. this.smask = new PDFImage(xref, res, smask, false);
  28258. } else if (mask) {
  28259. if (isStream(mask)) {
  28260. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  28261. } else {
  28262. // Color key mask (just an array).
  28263. this.mask = mask;
  28264. }
  28265. }
  28266. }
  28267. /**
  28268. * Handles processing of image data and returns the Promise that is resolved
  28269. * with a PDFImage when the image is ready to be used.
  28270. */
  28271. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  28272. res, image, inline) {
  28273. var imagePromise = handleImageData(handler, xref, res, image);
  28274. var smaskPromise;
  28275. var maskPromise;
  28276. var smask = image.dict.get('SMask');
  28277. var mask = image.dict.get('Mask');
  28278. if (smask) {
  28279. smaskPromise = handleImageData(handler, xref, res, smask);
  28280. maskPromise = Promise.resolve(null);
  28281. } else {
  28282. smaskPromise = Promise.resolve(null);
  28283. if (mask) {
  28284. if (isStream(mask)) {
  28285. maskPromise = handleImageData(handler, xref, res, mask);
  28286. } else if (isArray(mask)) {
  28287. maskPromise = Promise.resolve(mask);
  28288. } else {
  28289. warn('Unsupported mask format.');
  28290. maskPromise = Promise.resolve(null);
  28291. }
  28292. } else {
  28293. maskPromise = Promise.resolve(null);
  28294. }
  28295. }
  28296. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  28297. function(results) {
  28298. var imageData = results[0];
  28299. var smaskData = results[1];
  28300. var maskData = results[2];
  28301. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  28302. });
  28303. };
  28304. /**
  28305. * Resize an image using the nearest neighbor algorithm. Currently only
  28306. * supports one and three component images.
  28307. * @param {TypedArray} pixels The original image with one component.
  28308. * @param {Number} bpc Number of bits per component.
  28309. * @param {Number} components Number of color components, 1 or 3 is supported.
  28310. * @param {Number} w1 Original width.
  28311. * @param {Number} h1 Original height.
  28312. * @param {Number} w2 New width.
  28313. * @param {Number} h2 New height.
  28314. * @param {TypedArray} dest (Optional) The destination buffer.
  28315. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  28316. * @return {TypedArray} Resized image data.
  28317. */
  28318. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  28319. w1, h1, w2, h2, dest, alpha01) {
  28320. if (components !== 1 && components !== 3) {
  28321. error('Unsupported component count for resizing.');
  28322. }
  28323. var length = w2 * h2 * components;
  28324. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  28325. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  28326. var xRatio = w1 / w2;
  28327. var yRatio = h1 / h2;
  28328. var i, j, py, newIndex = 0, oldIndex;
  28329. var xScaled = new Uint16Array(w2);
  28330. var w1Scanline = w1 * components;
  28331. if (alpha01 !== 1) {
  28332. alpha01 = 0;
  28333. }
  28334. for (j = 0; j < w2; j++) {
  28335. xScaled[j] = Math.floor(j * xRatio) * components;
  28336. }
  28337. if (components === 1) {
  28338. for (i = 0; i < h2; i++) {
  28339. py = Math.floor(i * yRatio) * w1Scanline;
  28340. for (j = 0; j < w2; j++) {
  28341. oldIndex = py + xScaled[j];
  28342. temp[newIndex++] = pixels[oldIndex];
  28343. }
  28344. }
  28345. } else if (components === 3) {
  28346. for (i = 0; i < h2; i++) {
  28347. py = Math.floor(i * yRatio) * w1Scanline;
  28348. for (j = 0; j < w2; j++) {
  28349. oldIndex = py + xScaled[j];
  28350. temp[newIndex++] = pixels[oldIndex++];
  28351. temp[newIndex++] = pixels[oldIndex++];
  28352. temp[newIndex++] = pixels[oldIndex++];
  28353. newIndex += alpha01;
  28354. }
  28355. }
  28356. }
  28357. return temp;
  28358. };
  28359. PDFImage.createMask =
  28360. function PDFImage_createMask(imgArray, width, height,
  28361. imageIsFromDecodeStream, inverseDecode) {
  28362. // |imgArray| might not contain full data for every pixel of the mask, so
  28363. // we need to distinguish between |computedLength| and |actualLength|.
  28364. // In particular, if inverseDecode is true, then the array we return must
  28365. // have a length of |computedLength|.
  28366. var computedLength = ((width + 7) >> 3) * height;
  28367. var actualLength = imgArray.byteLength;
  28368. var haveFullData = computedLength === actualLength;
  28369. var data, i;
  28370. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  28371. // imgArray came from a DecodeStream and its data is in an appropriate
  28372. // form, so we can just transfer it.
  28373. data = imgArray;
  28374. } else if (!inverseDecode) {
  28375. data = new Uint8Array(actualLength);
  28376. data.set(imgArray);
  28377. } else {
  28378. data = new Uint8Array(computedLength);
  28379. data.set(imgArray);
  28380. for (i = actualLength; i < computedLength; i++) {
  28381. data[i] = 0xff;
  28382. }
  28383. }
  28384. // If necessary, invert the original mask data (but not any extra we might
  28385. // have added above). It's safe to modify the array -- whether it's the
  28386. // original or a copy, we're about to transfer it anyway, so nothing else
  28387. // in this thread can be relying on its contents.
  28388. if (inverseDecode) {
  28389. for (i = 0; i < actualLength; i++) {
  28390. data[i] = ~data[i];
  28391. }
  28392. }
  28393. return {data: data, width: width, height: height};
  28394. };
  28395. PDFImage.prototype = {
  28396. get drawWidth() {
  28397. return Math.max(this.width,
  28398. this.smask && this.smask.width || 0,
  28399. this.mask && this.mask.width || 0);
  28400. },
  28401. get drawHeight() {
  28402. return Math.max(this.height,
  28403. this.smask && this.smask.height || 0,
  28404. this.mask && this.mask.height || 0);
  28405. },
  28406. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  28407. var bpc = this.bpc;
  28408. var numComps = this.numComps;
  28409. var decodeAddends = this.decodeAddends;
  28410. var decodeCoefficients = this.decodeCoefficients;
  28411. var max = (1 << bpc) - 1;
  28412. var i, ii;
  28413. if (bpc === 1) {
  28414. // If the buffer needed decode that means it just needs to be inverted.
  28415. for (i = 0, ii = buffer.length; i < ii; i++) {
  28416. buffer[i] = +!(buffer[i]);
  28417. }
  28418. return;
  28419. }
  28420. var index = 0;
  28421. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  28422. for (var j = 0; j < numComps; j++) {
  28423. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  28424. decodeCoefficients[j], max);
  28425. index++;
  28426. }
  28427. }
  28428. },
  28429. getComponents: function PDFImage_getComponents(buffer) {
  28430. var bpc = this.bpc;
  28431. // This image doesn't require any extra work.
  28432. if (bpc === 8) {
  28433. return buffer;
  28434. }
  28435. var width = this.width;
  28436. var height = this.height;
  28437. var numComps = this.numComps;
  28438. var length = width * height * numComps;
  28439. var bufferPos = 0;
  28440. var output = (bpc <= 8 ? new Uint8Array(length) :
  28441. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  28442. var rowComps = width * numComps;
  28443. var max = (1 << bpc) - 1;
  28444. var i = 0, ii, buf;
  28445. if (bpc === 1) {
  28446. // Optimization for reading 1 bpc images.
  28447. var mask, loop1End, loop2End;
  28448. for (var j = 0; j < height; j++) {
  28449. loop1End = i + (rowComps & ~7);
  28450. loop2End = i + rowComps;
  28451. // unroll loop for all full bytes
  28452. while (i < loop1End) {
  28453. buf = buffer[bufferPos++];
  28454. output[i] = (buf >> 7) & 1;
  28455. output[i + 1] = (buf >> 6) & 1;
  28456. output[i + 2] = (buf >> 5) & 1;
  28457. output[i + 3] = (buf >> 4) & 1;
  28458. output[i + 4] = (buf >> 3) & 1;
  28459. output[i + 5] = (buf >> 2) & 1;
  28460. output[i + 6] = (buf >> 1) & 1;
  28461. output[i + 7] = buf & 1;
  28462. i += 8;
  28463. }
  28464. // handle remaing bits
  28465. if (i < loop2End) {
  28466. buf = buffer[bufferPos++];
  28467. mask = 128;
  28468. while (i < loop2End) {
  28469. output[i++] = +!!(buf & mask);
  28470. mask >>= 1;
  28471. }
  28472. }
  28473. }
  28474. } else {
  28475. // The general case that handles all other bpc values.
  28476. var bits = 0;
  28477. buf = 0;
  28478. for (i = 0, ii = length; i < ii; ++i) {
  28479. if (i % rowComps === 0) {
  28480. buf = 0;
  28481. bits = 0;
  28482. }
  28483. while (bits < bpc) {
  28484. buf = (buf << 8) | buffer[bufferPos++];
  28485. bits += 8;
  28486. }
  28487. var remainingBits = bits - bpc;
  28488. var value = buf >> remainingBits;
  28489. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  28490. buf = buf & ((1 << remainingBits) - 1);
  28491. bits = remainingBits;
  28492. }
  28493. }
  28494. return output;
  28495. },
  28496. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  28497. actualHeight, image) {
  28498. var smask = this.smask;
  28499. var mask = this.mask;
  28500. var alphaBuf, sw, sh, i, ii, j;
  28501. if (smask) {
  28502. sw = smask.width;
  28503. sh = smask.height;
  28504. alphaBuf = new Uint8Array(sw * sh);
  28505. smask.fillGrayBuffer(alphaBuf);
  28506. if (sw !== width || sh !== height) {
  28507. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  28508. height);
  28509. }
  28510. } else if (mask) {
  28511. if (mask instanceof PDFImage) {
  28512. sw = mask.width;
  28513. sh = mask.height;
  28514. alphaBuf = new Uint8Array(sw * sh);
  28515. mask.numComps = 1;
  28516. mask.fillGrayBuffer(alphaBuf);
  28517. // Need to invert values in rgbaBuf
  28518. for (i = 0, ii = sw * sh; i < ii; ++i) {
  28519. alphaBuf[i] = 255 - alphaBuf[i];
  28520. }
  28521. if (sw !== width || sh !== height) {
  28522. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  28523. height);
  28524. }
  28525. } else if (isArray(mask)) {
  28526. // Color key mask: if any of the compontents are outside the range
  28527. // then they should be painted.
  28528. alphaBuf = new Uint8Array(width * height);
  28529. var numComps = this.numComps;
  28530. for (i = 0, ii = width * height; i < ii; ++i) {
  28531. var opacity = 0;
  28532. var imageOffset = i * numComps;
  28533. for (j = 0; j < numComps; ++j) {
  28534. var color = image[imageOffset + j];
  28535. var maskOffset = j * 2;
  28536. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  28537. opacity = 255;
  28538. break;
  28539. }
  28540. }
  28541. alphaBuf[i] = opacity;
  28542. }
  28543. } else {
  28544. error('Unknown mask format.');
  28545. }
  28546. }
  28547. if (alphaBuf) {
  28548. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  28549. rgbaBuf[j] = alphaBuf[i];
  28550. }
  28551. } else {
  28552. // No mask.
  28553. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  28554. rgbaBuf[j] = 255;
  28555. }
  28556. }
  28557. },
  28558. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  28559. var matte = this.smask && this.smask.matte;
  28560. if (!matte) {
  28561. return;
  28562. }
  28563. var matteRgb = this.colorSpace.getRgb(matte, 0);
  28564. var matteR = matteRgb[0];
  28565. var matteG = matteRgb[1];
  28566. var matteB = matteRgb[2];
  28567. var length = width * height * 4;
  28568. var r, g, b;
  28569. for (var i = 0; i < length; i += 4) {
  28570. var alpha = buffer[i + 3];
  28571. if (alpha === 0) {
  28572. // according formula we have to get Infinity in all components
  28573. // making it white (typical paper color) should be okay
  28574. buffer[i] = 255;
  28575. buffer[i + 1] = 255;
  28576. buffer[i + 2] = 255;
  28577. continue;
  28578. }
  28579. var k = 255 / alpha;
  28580. r = (buffer[i] - matteR) * k + matteR;
  28581. g = (buffer[i + 1] - matteG) * k + matteG;
  28582. b = (buffer[i + 2] - matteB) * k + matteB;
  28583. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  28584. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  28585. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  28586. }
  28587. },
  28588. createImageData: function PDFImage_createImageData(forceRGBA) {
  28589. var drawWidth = this.drawWidth;
  28590. var drawHeight = this.drawHeight;
  28591. var imgData = { // other fields are filled in below
  28592. width: drawWidth,
  28593. height: drawHeight
  28594. };
  28595. var numComps = this.numComps;
  28596. var originalWidth = this.width;
  28597. var originalHeight = this.height;
  28598. var bpc = this.bpc;
  28599. // Rows start at byte boundary.
  28600. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  28601. var imgArray;
  28602. if (!forceRGBA) {
  28603. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  28604. // without any complications, we pass a same-sized copy to the main
  28605. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  28606. // of memory for many scanned documents. It's also much faster.
  28607. //
  28608. // Similarly, if it is a 24-bit-per pixel RGB image without any
  28609. // complications, we avoid expanding by 1.333x to RGBA form.
  28610. var kind;
  28611. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  28612. kind = ImageKind.GRAYSCALE_1BPP;
  28613. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8) {
  28614. kind = ImageKind.RGB_24BPP;
  28615. }
  28616. if (kind && !this.smask && !this.mask && !this.needsDecode &&
  28617. drawWidth === originalWidth && drawHeight === originalHeight) {
  28618. imgData.kind = kind;
  28619. imgArray = this.getImageBytes(originalHeight * rowBytes);
  28620. // If imgArray came from a DecodeStream, we're safe to transfer it
  28621. // (and thus neuter it) because it will constitute the entire
  28622. // DecodeStream's data. But if it came from a Stream, we need to
  28623. // copy it because it'll only be a portion of the Stream's data, and
  28624. // the rest will be read later on.
  28625. if (this.image instanceof DecodeStream) {
  28626. imgData.data = imgArray;
  28627. } else {
  28628. var newArray = new Uint8Array(imgArray.length);
  28629. newArray.set(imgArray);
  28630. imgData.data = newArray;
  28631. }
  28632. return imgData;
  28633. }
  28634. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  28635. imgData.kind = ImageKind.RGB_24BPP;
  28636. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  28637. drawWidth, drawHeight, true);
  28638. return imgData;
  28639. }
  28640. }
  28641. imgArray = this.getImageBytes(originalHeight * rowBytes);
  28642. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  28643. var actualHeight = 0 | (imgArray.length / rowBytes *
  28644. drawHeight / originalHeight);
  28645. var comps = this.getComponents(imgArray);
  28646. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  28647. // more compact RGB_24BPP form if allowable.
  28648. var alpha01, maybeUndoPreblend;
  28649. if (!forceRGBA && !this.smask && !this.mask) {
  28650. imgData.kind = ImageKind.RGB_24BPP;
  28651. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  28652. alpha01 = 0;
  28653. maybeUndoPreblend = false;
  28654. } else {
  28655. imgData.kind = ImageKind.RGBA_32BPP;
  28656. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  28657. alpha01 = 1;
  28658. maybeUndoPreblend = true;
  28659. // Color key masking (opacity) must be performed before decoding.
  28660. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  28661. comps);
  28662. }
  28663. if (this.needsDecode) {
  28664. this.decodeBuffer(comps);
  28665. }
  28666. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  28667. drawWidth, drawHeight, actualHeight, bpc, comps,
  28668. alpha01);
  28669. if (maybeUndoPreblend) {
  28670. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  28671. }
  28672. return imgData;
  28673. },
  28674. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  28675. var numComps = this.numComps;
  28676. if (numComps !== 1) {
  28677. error('Reading gray scale from a color image: ' + numComps);
  28678. }
  28679. var width = this.width;
  28680. var height = this.height;
  28681. var bpc = this.bpc;
  28682. // rows start at byte boundary
  28683. var rowBytes = (width * numComps * bpc + 7) >> 3;
  28684. var imgArray = this.getImageBytes(height * rowBytes);
  28685. var comps = this.getComponents(imgArray);
  28686. var i, length;
  28687. if (bpc === 1) {
  28688. // inline decoding (= inversion) for 1 bpc images
  28689. length = width * height;
  28690. if (this.needsDecode) {
  28691. // invert and scale to {0, 255}
  28692. for (i = 0; i < length; ++i) {
  28693. buffer[i] = (comps[i] - 1) & 255;
  28694. }
  28695. } else {
  28696. // scale to {0, 255}
  28697. for (i = 0; i < length; ++i) {
  28698. buffer[i] = (-comps[i]) & 255;
  28699. }
  28700. }
  28701. return;
  28702. }
  28703. if (this.needsDecode) {
  28704. this.decodeBuffer(comps);
  28705. }
  28706. length = width * height;
  28707. // we aren't using a colorspace so we need to scale the value
  28708. var scale = 255 / ((1 << bpc) - 1);
  28709. for (i = 0; i < length; ++i) {
  28710. buffer[i] = (scale * comps[i]) | 0;
  28711. }
  28712. },
  28713. getImageBytes: function PDFImage_getImageBytes(length,
  28714. drawWidth, drawHeight,
  28715. forceRGB) {
  28716. this.image.reset();
  28717. this.image.drawWidth = drawWidth || this.width;
  28718. this.image.drawHeight = drawHeight || this.height;
  28719. this.image.forceRGB = !!forceRGB;
  28720. return this.image.getBytes(length);
  28721. }
  28722. };
  28723. return PDFImage;
  28724. })();
  28725. // The Metrics object contains glyph widths (in glyph space units).
  28726. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  28727. // space unit corresponds to 1/1000th of text space unit.
  28728. var Metrics = {
  28729. 'Courier': 600,
  28730. 'Courier-Bold': 600,
  28731. 'Courier-BoldOblique': 600,
  28732. 'Courier-Oblique': 600,
  28733. 'Helvetica' : {
  28734. 'space': 278,
  28735. 'exclam': 278,
  28736. 'quotedbl': 355,
  28737. 'numbersign': 556,
  28738. 'dollar': 556,
  28739. 'percent': 889,
  28740. 'ampersand': 667,
  28741. 'quoteright': 222,
  28742. 'parenleft': 333,
  28743. 'parenright': 333,
  28744. 'asterisk': 389,
  28745. 'plus': 584,
  28746. 'comma': 278,
  28747. 'hyphen': 333,
  28748. 'period': 278,
  28749. 'slash': 278,
  28750. 'zero': 556,
  28751. 'one': 556,
  28752. 'two': 556,
  28753. 'three': 556,
  28754. 'four': 556,
  28755. 'five': 556,
  28756. 'six': 556,
  28757. 'seven': 556,
  28758. 'eight': 556,
  28759. 'nine': 556,
  28760. 'colon': 278,
  28761. 'semicolon': 278,
  28762. 'less': 584,
  28763. 'equal': 584,
  28764. 'greater': 584,
  28765. 'question': 556,
  28766. 'at': 1015,
  28767. 'A': 667,
  28768. 'B': 667,
  28769. 'C': 722,
  28770. 'D': 722,
  28771. 'E': 667,
  28772. 'F': 611,
  28773. 'G': 778,
  28774. 'H': 722,
  28775. 'I': 278,
  28776. 'J': 500,
  28777. 'K': 667,
  28778. 'L': 556,
  28779. 'M': 833,
  28780. 'N': 722,
  28781. 'O': 778,
  28782. 'P': 667,
  28783. 'Q': 778,
  28784. 'R': 722,
  28785. 'S': 667,
  28786. 'T': 611,
  28787. 'U': 722,
  28788. 'V': 667,
  28789. 'W': 944,
  28790. 'X': 667,
  28791. 'Y': 667,
  28792. 'Z': 611,
  28793. 'bracketleft': 278,
  28794. 'backslash': 278,
  28795. 'bracketright': 278,
  28796. 'asciicircum': 469,
  28797. 'underscore': 556,
  28798. 'quoteleft': 222,
  28799. 'a': 556,
  28800. 'b': 556,
  28801. 'c': 500,
  28802. 'd': 556,
  28803. 'e': 556,
  28804. 'f': 278,
  28805. 'g': 556,
  28806. 'h': 556,
  28807. 'i': 222,
  28808. 'j': 222,
  28809. 'k': 500,
  28810. 'l': 222,
  28811. 'm': 833,
  28812. 'n': 556,
  28813. 'o': 556,
  28814. 'p': 556,
  28815. 'q': 556,
  28816. 'r': 333,
  28817. 's': 500,
  28818. 't': 278,
  28819. 'u': 556,
  28820. 'v': 500,
  28821. 'w': 722,
  28822. 'x': 500,
  28823. 'y': 500,
  28824. 'z': 500,
  28825. 'braceleft': 334,
  28826. 'bar': 260,
  28827. 'braceright': 334,
  28828. 'asciitilde': 584,
  28829. 'exclamdown': 333,
  28830. 'cent': 556,
  28831. 'sterling': 556,
  28832. 'fraction': 167,
  28833. 'yen': 556,
  28834. 'florin': 556,
  28835. 'section': 556,
  28836. 'currency': 556,
  28837. 'quotesingle': 191,
  28838. 'quotedblleft': 333,
  28839. 'guillemotleft': 556,
  28840. 'guilsinglleft': 333,
  28841. 'guilsinglright': 333,
  28842. 'fi': 500,
  28843. 'fl': 500,
  28844. 'endash': 556,
  28845. 'dagger': 556,
  28846. 'daggerdbl': 556,
  28847. 'periodcentered': 278,
  28848. 'paragraph': 537,
  28849. 'bullet': 350,
  28850. 'quotesinglbase': 222,
  28851. 'quotedblbase': 333,
  28852. 'quotedblright': 333,
  28853. 'guillemotright': 556,
  28854. 'ellipsis': 1000,
  28855. 'perthousand': 1000,
  28856. 'questiondown': 611,
  28857. 'grave': 333,
  28858. 'acute': 333,
  28859. 'circumflex': 333,
  28860. 'tilde': 333,
  28861. 'macron': 333,
  28862. 'breve': 333,
  28863. 'dotaccent': 333,
  28864. 'dieresis': 333,
  28865. 'ring': 333,
  28866. 'cedilla': 333,
  28867. 'hungarumlaut': 333,
  28868. 'ogonek': 333,
  28869. 'caron': 333,
  28870. 'emdash': 1000,
  28871. 'AE': 1000,
  28872. 'ordfeminine': 370,
  28873. 'Lslash': 556,
  28874. 'Oslash': 778,
  28875. 'OE': 1000,
  28876. 'ordmasculine': 365,
  28877. 'ae': 889,
  28878. 'dotlessi': 278,
  28879. 'lslash': 222,
  28880. 'oslash': 611,
  28881. 'oe': 944,
  28882. 'germandbls': 611,
  28883. 'Idieresis': 278,
  28884. 'eacute': 556,
  28885. 'abreve': 556,
  28886. 'uhungarumlaut': 556,
  28887. 'ecaron': 556,
  28888. 'Ydieresis': 667,
  28889. 'divide': 584,
  28890. 'Yacute': 667,
  28891. 'Acircumflex': 667,
  28892. 'aacute': 556,
  28893. 'Ucircumflex': 722,
  28894. 'yacute': 500,
  28895. 'scommaaccent': 500,
  28896. 'ecircumflex': 556,
  28897. 'Uring': 722,
  28898. 'Udieresis': 722,
  28899. 'aogonek': 556,
  28900. 'Uacute': 722,
  28901. 'uogonek': 556,
  28902. 'Edieresis': 667,
  28903. 'Dcroat': 722,
  28904. 'commaaccent': 250,
  28905. 'copyright': 737,
  28906. 'Emacron': 667,
  28907. 'ccaron': 500,
  28908. 'aring': 556,
  28909. 'Ncommaaccent': 722,
  28910. 'lacute': 222,
  28911. 'agrave': 556,
  28912. 'Tcommaaccent': 611,
  28913. 'Cacute': 722,
  28914. 'atilde': 556,
  28915. 'Edotaccent': 667,
  28916. 'scaron': 500,
  28917. 'scedilla': 500,
  28918. 'iacute': 278,
  28919. 'lozenge': 471,
  28920. 'Rcaron': 722,
  28921. 'Gcommaaccent': 778,
  28922. 'ucircumflex': 556,
  28923. 'acircumflex': 556,
  28924. 'Amacron': 667,
  28925. 'rcaron': 333,
  28926. 'ccedilla': 500,
  28927. 'Zdotaccent': 611,
  28928. 'Thorn': 667,
  28929. 'Omacron': 778,
  28930. 'Racute': 722,
  28931. 'Sacute': 667,
  28932. 'dcaron': 643,
  28933. 'Umacron': 722,
  28934. 'uring': 556,
  28935. 'threesuperior': 333,
  28936. 'Ograve': 778,
  28937. 'Agrave': 667,
  28938. 'Abreve': 667,
  28939. 'multiply': 584,
  28940. 'uacute': 556,
  28941. 'Tcaron': 611,
  28942. 'partialdiff': 476,
  28943. 'ydieresis': 500,
  28944. 'Nacute': 722,
  28945. 'icircumflex': 278,
  28946. 'Ecircumflex': 667,
  28947. 'adieresis': 556,
  28948. 'edieresis': 556,
  28949. 'cacute': 500,
  28950. 'nacute': 556,
  28951. 'umacron': 556,
  28952. 'Ncaron': 722,
  28953. 'Iacute': 278,
  28954. 'plusminus': 584,
  28955. 'brokenbar': 260,
  28956. 'registered': 737,
  28957. 'Gbreve': 778,
  28958. 'Idotaccent': 278,
  28959. 'summation': 600,
  28960. 'Egrave': 667,
  28961. 'racute': 333,
  28962. 'omacron': 556,
  28963. 'Zacute': 611,
  28964. 'Zcaron': 611,
  28965. 'greaterequal': 549,
  28966. 'Eth': 722,
  28967. 'Ccedilla': 722,
  28968. 'lcommaaccent': 222,
  28969. 'tcaron': 317,
  28970. 'eogonek': 556,
  28971. 'Uogonek': 722,
  28972. 'Aacute': 667,
  28973. 'Adieresis': 667,
  28974. 'egrave': 556,
  28975. 'zacute': 500,
  28976. 'iogonek': 222,
  28977. 'Oacute': 778,
  28978. 'oacute': 556,
  28979. 'amacron': 556,
  28980. 'sacute': 500,
  28981. 'idieresis': 278,
  28982. 'Ocircumflex': 778,
  28983. 'Ugrave': 722,
  28984. 'Delta': 612,
  28985. 'thorn': 556,
  28986. 'twosuperior': 333,
  28987. 'Odieresis': 778,
  28988. 'mu': 556,
  28989. 'igrave': 278,
  28990. 'ohungarumlaut': 556,
  28991. 'Eogonek': 667,
  28992. 'dcroat': 556,
  28993. 'threequarters': 834,
  28994. 'Scedilla': 667,
  28995. 'lcaron': 299,
  28996. 'Kcommaaccent': 667,
  28997. 'Lacute': 556,
  28998. 'trademark': 1000,
  28999. 'edotaccent': 556,
  29000. 'Igrave': 278,
  29001. 'Imacron': 278,
  29002. 'Lcaron': 556,
  29003. 'onehalf': 834,
  29004. 'lessequal': 549,
  29005. 'ocircumflex': 556,
  29006. 'ntilde': 556,
  29007. 'Uhungarumlaut': 722,
  29008. 'Eacute': 667,
  29009. 'emacron': 556,
  29010. 'gbreve': 556,
  29011. 'onequarter': 834,
  29012. 'Scaron': 667,
  29013. 'Scommaaccent': 667,
  29014. 'Ohungarumlaut': 778,
  29015. 'degree': 400,
  29016. 'ograve': 556,
  29017. 'Ccaron': 722,
  29018. 'ugrave': 556,
  29019. 'radical': 453,
  29020. 'Dcaron': 722,
  29021. 'rcommaaccent': 333,
  29022. 'Ntilde': 722,
  29023. 'otilde': 556,
  29024. 'Rcommaaccent': 722,
  29025. 'Lcommaaccent': 556,
  29026. 'Atilde': 667,
  29027. 'Aogonek': 667,
  29028. 'Aring': 667,
  29029. 'Otilde': 778,
  29030. 'zdotaccent': 500,
  29031. 'Ecaron': 667,
  29032. 'Iogonek': 278,
  29033. 'kcommaaccent': 500,
  29034. 'minus': 584,
  29035. 'Icircumflex': 278,
  29036. 'ncaron': 556,
  29037. 'tcommaaccent': 278,
  29038. 'logicalnot': 584,
  29039. 'odieresis': 556,
  29040. 'udieresis': 556,
  29041. 'notequal': 549,
  29042. 'gcommaaccent': 556,
  29043. 'eth': 556,
  29044. 'zcaron': 500,
  29045. 'ncommaaccent': 556,
  29046. 'onesuperior': 333,
  29047. 'imacron': 278,
  29048. 'Euro': 556
  29049. },
  29050. 'Helvetica-Bold': {
  29051. 'space': 278,
  29052. 'exclam': 333,
  29053. 'quotedbl': 474,
  29054. 'numbersign': 556,
  29055. 'dollar': 556,
  29056. 'percent': 889,
  29057. 'ampersand': 722,
  29058. 'quoteright': 278,
  29059. 'parenleft': 333,
  29060. 'parenright': 333,
  29061. 'asterisk': 389,
  29062. 'plus': 584,
  29063. 'comma': 278,
  29064. 'hyphen': 333,
  29065. 'period': 278,
  29066. 'slash': 278,
  29067. 'zero': 556,
  29068. 'one': 556,
  29069. 'two': 556,
  29070. 'three': 556,
  29071. 'four': 556,
  29072. 'five': 556,
  29073. 'six': 556,
  29074. 'seven': 556,
  29075. 'eight': 556,
  29076. 'nine': 556,
  29077. 'colon': 333,
  29078. 'semicolon': 333,
  29079. 'less': 584,
  29080. 'equal': 584,
  29081. 'greater': 584,
  29082. 'question': 611,
  29083. 'at': 975,
  29084. 'A': 722,
  29085. 'B': 722,
  29086. 'C': 722,
  29087. 'D': 722,
  29088. 'E': 667,
  29089. 'F': 611,
  29090. 'G': 778,
  29091. 'H': 722,
  29092. 'I': 278,
  29093. 'J': 556,
  29094. 'K': 722,
  29095. 'L': 611,
  29096. 'M': 833,
  29097. 'N': 722,
  29098. 'O': 778,
  29099. 'P': 667,
  29100. 'Q': 778,
  29101. 'R': 722,
  29102. 'S': 667,
  29103. 'T': 611,
  29104. 'U': 722,
  29105. 'V': 667,
  29106. 'W': 944,
  29107. 'X': 667,
  29108. 'Y': 667,
  29109. 'Z': 611,
  29110. 'bracketleft': 333,
  29111. 'backslash': 278,
  29112. 'bracketright': 333,
  29113. 'asciicircum': 584,
  29114. 'underscore': 556,
  29115. 'quoteleft': 278,
  29116. 'a': 556,
  29117. 'b': 611,
  29118. 'c': 556,
  29119. 'd': 611,
  29120. 'e': 556,
  29121. 'f': 333,
  29122. 'g': 611,
  29123. 'h': 611,
  29124. 'i': 278,
  29125. 'j': 278,
  29126. 'k': 556,
  29127. 'l': 278,
  29128. 'm': 889,
  29129. 'n': 611,
  29130. 'o': 611,
  29131. 'p': 611,
  29132. 'q': 611,
  29133. 'r': 389,
  29134. 's': 556,
  29135. 't': 333,
  29136. 'u': 611,
  29137. 'v': 556,
  29138. 'w': 778,
  29139. 'x': 556,
  29140. 'y': 556,
  29141. 'z': 500,
  29142. 'braceleft': 389,
  29143. 'bar': 280,
  29144. 'braceright': 389,
  29145. 'asciitilde': 584,
  29146. 'exclamdown': 333,
  29147. 'cent': 556,
  29148. 'sterling': 556,
  29149. 'fraction': 167,
  29150. 'yen': 556,
  29151. 'florin': 556,
  29152. 'section': 556,
  29153. 'currency': 556,
  29154. 'quotesingle': 238,
  29155. 'quotedblleft': 500,
  29156. 'guillemotleft': 556,
  29157. 'guilsinglleft': 333,
  29158. 'guilsinglright': 333,
  29159. 'fi': 611,
  29160. 'fl': 611,
  29161. 'endash': 556,
  29162. 'dagger': 556,
  29163. 'daggerdbl': 556,
  29164. 'periodcentered': 278,
  29165. 'paragraph': 556,
  29166. 'bullet': 350,
  29167. 'quotesinglbase': 278,
  29168. 'quotedblbase': 500,
  29169. 'quotedblright': 500,
  29170. 'guillemotright': 556,
  29171. 'ellipsis': 1000,
  29172. 'perthousand': 1000,
  29173. 'questiondown': 611,
  29174. 'grave': 333,
  29175. 'acute': 333,
  29176. 'circumflex': 333,
  29177. 'tilde': 333,
  29178. 'macron': 333,
  29179. 'breve': 333,
  29180. 'dotaccent': 333,
  29181. 'dieresis': 333,
  29182. 'ring': 333,
  29183. 'cedilla': 333,
  29184. 'hungarumlaut': 333,
  29185. 'ogonek': 333,
  29186. 'caron': 333,
  29187. 'emdash': 1000,
  29188. 'AE': 1000,
  29189. 'ordfeminine': 370,
  29190. 'Lslash': 611,
  29191. 'Oslash': 778,
  29192. 'OE': 1000,
  29193. 'ordmasculine': 365,
  29194. 'ae': 889,
  29195. 'dotlessi': 278,
  29196. 'lslash': 278,
  29197. 'oslash': 611,
  29198. 'oe': 944,
  29199. 'germandbls': 611,
  29200. 'Idieresis': 278,
  29201. 'eacute': 556,
  29202. 'abreve': 556,
  29203. 'uhungarumlaut': 611,
  29204. 'ecaron': 556,
  29205. 'Ydieresis': 667,
  29206. 'divide': 584,
  29207. 'Yacute': 667,
  29208. 'Acircumflex': 722,
  29209. 'aacute': 556,
  29210. 'Ucircumflex': 722,
  29211. 'yacute': 556,
  29212. 'scommaaccent': 556,
  29213. 'ecircumflex': 556,
  29214. 'Uring': 722,
  29215. 'Udieresis': 722,
  29216. 'aogonek': 556,
  29217. 'Uacute': 722,
  29218. 'uogonek': 611,
  29219. 'Edieresis': 667,
  29220. 'Dcroat': 722,
  29221. 'commaaccent': 250,
  29222. 'copyright': 737,
  29223. 'Emacron': 667,
  29224. 'ccaron': 556,
  29225. 'aring': 556,
  29226. 'Ncommaaccent': 722,
  29227. 'lacute': 278,
  29228. 'agrave': 556,
  29229. 'Tcommaaccent': 611,
  29230. 'Cacute': 722,
  29231. 'atilde': 556,
  29232. 'Edotaccent': 667,
  29233. 'scaron': 556,
  29234. 'scedilla': 556,
  29235. 'iacute': 278,
  29236. 'lozenge': 494,
  29237. 'Rcaron': 722,
  29238. 'Gcommaaccent': 778,
  29239. 'ucircumflex': 611,
  29240. 'acircumflex': 556,
  29241. 'Amacron': 722,
  29242. 'rcaron': 389,
  29243. 'ccedilla': 556,
  29244. 'Zdotaccent': 611,
  29245. 'Thorn': 667,
  29246. 'Omacron': 778,
  29247. 'Racute': 722,
  29248. 'Sacute': 667,
  29249. 'dcaron': 743,
  29250. 'Umacron': 722,
  29251. 'uring': 611,
  29252. 'threesuperior': 333,
  29253. 'Ograve': 778,
  29254. 'Agrave': 722,
  29255. 'Abreve': 722,
  29256. 'multiply': 584,
  29257. 'uacute': 611,
  29258. 'Tcaron': 611,
  29259. 'partialdiff': 494,
  29260. 'ydieresis': 556,
  29261. 'Nacute': 722,
  29262. 'icircumflex': 278,
  29263. 'Ecircumflex': 667,
  29264. 'adieresis': 556,
  29265. 'edieresis': 556,
  29266. 'cacute': 556,
  29267. 'nacute': 611,
  29268. 'umacron': 611,
  29269. 'Ncaron': 722,
  29270. 'Iacute': 278,
  29271. 'plusminus': 584,
  29272. 'brokenbar': 280,
  29273. 'registered': 737,
  29274. 'Gbreve': 778,
  29275. 'Idotaccent': 278,
  29276. 'summation': 600,
  29277. 'Egrave': 667,
  29278. 'racute': 389,
  29279. 'omacron': 611,
  29280. 'Zacute': 611,
  29281. 'Zcaron': 611,
  29282. 'greaterequal': 549,
  29283. 'Eth': 722,
  29284. 'Ccedilla': 722,
  29285. 'lcommaaccent': 278,
  29286. 'tcaron': 389,
  29287. 'eogonek': 556,
  29288. 'Uogonek': 722,
  29289. 'Aacute': 722,
  29290. 'Adieresis': 722,
  29291. 'egrave': 556,
  29292. 'zacute': 500,
  29293. 'iogonek': 278,
  29294. 'Oacute': 778,
  29295. 'oacute': 611,
  29296. 'amacron': 556,
  29297. 'sacute': 556,
  29298. 'idieresis': 278,
  29299. 'Ocircumflex': 778,
  29300. 'Ugrave': 722,
  29301. 'Delta': 612,
  29302. 'thorn': 611,
  29303. 'twosuperior': 333,
  29304. 'Odieresis': 778,
  29305. 'mu': 611,
  29306. 'igrave': 278,
  29307. 'ohungarumlaut': 611,
  29308. 'Eogonek': 667,
  29309. 'dcroat': 611,
  29310. 'threequarters': 834,
  29311. 'Scedilla': 667,
  29312. 'lcaron': 400,
  29313. 'Kcommaaccent': 722,
  29314. 'Lacute': 611,
  29315. 'trademark': 1000,
  29316. 'edotaccent': 556,
  29317. 'Igrave': 278,
  29318. 'Imacron': 278,
  29319. 'Lcaron': 611,
  29320. 'onehalf': 834,
  29321. 'lessequal': 549,
  29322. 'ocircumflex': 611,
  29323. 'ntilde': 611,
  29324. 'Uhungarumlaut': 722,
  29325. 'Eacute': 667,
  29326. 'emacron': 556,
  29327. 'gbreve': 611,
  29328. 'onequarter': 834,
  29329. 'Scaron': 667,
  29330. 'Scommaaccent': 667,
  29331. 'Ohungarumlaut': 778,
  29332. 'degree': 400,
  29333. 'ograve': 611,
  29334. 'Ccaron': 722,
  29335. 'ugrave': 611,
  29336. 'radical': 549,
  29337. 'Dcaron': 722,
  29338. 'rcommaaccent': 389,
  29339. 'Ntilde': 722,
  29340. 'otilde': 611,
  29341. 'Rcommaaccent': 722,
  29342. 'Lcommaaccent': 611,
  29343. 'Atilde': 722,
  29344. 'Aogonek': 722,
  29345. 'Aring': 722,
  29346. 'Otilde': 778,
  29347. 'zdotaccent': 500,
  29348. 'Ecaron': 667,
  29349. 'Iogonek': 278,
  29350. 'kcommaaccent': 556,
  29351. 'minus': 584,
  29352. 'Icircumflex': 278,
  29353. 'ncaron': 611,
  29354. 'tcommaaccent': 333,
  29355. 'logicalnot': 584,
  29356. 'odieresis': 611,
  29357. 'udieresis': 611,
  29358. 'notequal': 549,
  29359. 'gcommaaccent': 611,
  29360. 'eth': 611,
  29361. 'zcaron': 500,
  29362. 'ncommaaccent': 611,
  29363. 'onesuperior': 333,
  29364. 'imacron': 278,
  29365. 'Euro': 556
  29366. },
  29367. 'Helvetica-BoldOblique': {
  29368. 'space': 278,
  29369. 'exclam': 333,
  29370. 'quotedbl': 474,
  29371. 'numbersign': 556,
  29372. 'dollar': 556,
  29373. 'percent': 889,
  29374. 'ampersand': 722,
  29375. 'quoteright': 278,
  29376. 'parenleft': 333,
  29377. 'parenright': 333,
  29378. 'asterisk': 389,
  29379. 'plus': 584,
  29380. 'comma': 278,
  29381. 'hyphen': 333,
  29382. 'period': 278,
  29383. 'slash': 278,
  29384. 'zero': 556,
  29385. 'one': 556,
  29386. 'two': 556,
  29387. 'three': 556,
  29388. 'four': 556,
  29389. 'five': 556,
  29390. 'six': 556,
  29391. 'seven': 556,
  29392. 'eight': 556,
  29393. 'nine': 556,
  29394. 'colon': 333,
  29395. 'semicolon': 333,
  29396. 'less': 584,
  29397. 'equal': 584,
  29398. 'greater': 584,
  29399. 'question': 611,
  29400. 'at': 975,
  29401. 'A': 722,
  29402. 'B': 722,
  29403. 'C': 722,
  29404. 'D': 722,
  29405. 'E': 667,
  29406. 'F': 611,
  29407. 'G': 778,
  29408. 'H': 722,
  29409. 'I': 278,
  29410. 'J': 556,
  29411. 'K': 722,
  29412. 'L': 611,
  29413. 'M': 833,
  29414. 'N': 722,
  29415. 'O': 778,
  29416. 'P': 667,
  29417. 'Q': 778,
  29418. 'R': 722,
  29419. 'S': 667,
  29420. 'T': 611,
  29421. 'U': 722,
  29422. 'V': 667,
  29423. 'W': 944,
  29424. 'X': 667,
  29425. 'Y': 667,
  29426. 'Z': 611,
  29427. 'bracketleft': 333,
  29428. 'backslash': 278,
  29429. 'bracketright': 333,
  29430. 'asciicircum': 584,
  29431. 'underscore': 556,
  29432. 'quoteleft': 278,
  29433. 'a': 556,
  29434. 'b': 611,
  29435. 'c': 556,
  29436. 'd': 611,
  29437. 'e': 556,
  29438. 'f': 333,
  29439. 'g': 611,
  29440. 'h': 611,
  29441. 'i': 278,
  29442. 'j': 278,
  29443. 'k': 556,
  29444. 'l': 278,
  29445. 'm': 889,
  29446. 'n': 611,
  29447. 'o': 611,
  29448. 'p': 611,
  29449. 'q': 611,
  29450. 'r': 389,
  29451. 's': 556,
  29452. 't': 333,
  29453. 'u': 611,
  29454. 'v': 556,
  29455. 'w': 778,
  29456. 'x': 556,
  29457. 'y': 556,
  29458. 'z': 500,
  29459. 'braceleft': 389,
  29460. 'bar': 280,
  29461. 'braceright': 389,
  29462. 'asciitilde': 584,
  29463. 'exclamdown': 333,
  29464. 'cent': 556,
  29465. 'sterling': 556,
  29466. 'fraction': 167,
  29467. 'yen': 556,
  29468. 'florin': 556,
  29469. 'section': 556,
  29470. 'currency': 556,
  29471. 'quotesingle': 238,
  29472. 'quotedblleft': 500,
  29473. 'guillemotleft': 556,
  29474. 'guilsinglleft': 333,
  29475. 'guilsinglright': 333,
  29476. 'fi': 611,
  29477. 'fl': 611,
  29478. 'endash': 556,
  29479. 'dagger': 556,
  29480. 'daggerdbl': 556,
  29481. 'periodcentered': 278,
  29482. 'paragraph': 556,
  29483. 'bullet': 350,
  29484. 'quotesinglbase': 278,
  29485. 'quotedblbase': 500,
  29486. 'quotedblright': 500,
  29487. 'guillemotright': 556,
  29488. 'ellipsis': 1000,
  29489. 'perthousand': 1000,
  29490. 'questiondown': 611,
  29491. 'grave': 333,
  29492. 'acute': 333,
  29493. 'circumflex': 333,
  29494. 'tilde': 333,
  29495. 'macron': 333,
  29496. 'breve': 333,
  29497. 'dotaccent': 333,
  29498. 'dieresis': 333,
  29499. 'ring': 333,
  29500. 'cedilla': 333,
  29501. 'hungarumlaut': 333,
  29502. 'ogonek': 333,
  29503. 'caron': 333,
  29504. 'emdash': 1000,
  29505. 'AE': 1000,
  29506. 'ordfeminine': 370,
  29507. 'Lslash': 611,
  29508. 'Oslash': 778,
  29509. 'OE': 1000,
  29510. 'ordmasculine': 365,
  29511. 'ae': 889,
  29512. 'dotlessi': 278,
  29513. 'lslash': 278,
  29514. 'oslash': 611,
  29515. 'oe': 944,
  29516. 'germandbls': 611,
  29517. 'Idieresis': 278,
  29518. 'eacute': 556,
  29519. 'abreve': 556,
  29520. 'uhungarumlaut': 611,
  29521. 'ecaron': 556,
  29522. 'Ydieresis': 667,
  29523. 'divide': 584,
  29524. 'Yacute': 667,
  29525. 'Acircumflex': 722,
  29526. 'aacute': 556,
  29527. 'Ucircumflex': 722,
  29528. 'yacute': 556,
  29529. 'scommaaccent': 556,
  29530. 'ecircumflex': 556,
  29531. 'Uring': 722,
  29532. 'Udieresis': 722,
  29533. 'aogonek': 556,
  29534. 'Uacute': 722,
  29535. 'uogonek': 611,
  29536. 'Edieresis': 667,
  29537. 'Dcroat': 722,
  29538. 'commaaccent': 250,
  29539. 'copyright': 737,
  29540. 'Emacron': 667,
  29541. 'ccaron': 556,
  29542. 'aring': 556,
  29543. 'Ncommaaccent': 722,
  29544. 'lacute': 278,
  29545. 'agrave': 556,
  29546. 'Tcommaaccent': 611,
  29547. 'Cacute': 722,
  29548. 'atilde': 556,
  29549. 'Edotaccent': 667,
  29550. 'scaron': 556,
  29551. 'scedilla': 556,
  29552. 'iacute': 278,
  29553. 'lozenge': 494,
  29554. 'Rcaron': 722,
  29555. 'Gcommaaccent': 778,
  29556. 'ucircumflex': 611,
  29557. 'acircumflex': 556,
  29558. 'Amacron': 722,
  29559. 'rcaron': 389,
  29560. 'ccedilla': 556,
  29561. 'Zdotaccent': 611,
  29562. 'Thorn': 667,
  29563. 'Omacron': 778,
  29564. 'Racute': 722,
  29565. 'Sacute': 667,
  29566. 'dcaron': 743,
  29567. 'Umacron': 722,
  29568. 'uring': 611,
  29569. 'threesuperior': 333,
  29570. 'Ograve': 778,
  29571. 'Agrave': 722,
  29572. 'Abreve': 722,
  29573. 'multiply': 584,
  29574. 'uacute': 611,
  29575. 'Tcaron': 611,
  29576. 'partialdiff': 494,
  29577. 'ydieresis': 556,
  29578. 'Nacute': 722,
  29579. 'icircumflex': 278,
  29580. 'Ecircumflex': 667,
  29581. 'adieresis': 556,
  29582. 'edieresis': 556,
  29583. 'cacute': 556,
  29584. 'nacute': 611,
  29585. 'umacron': 611,
  29586. 'Ncaron': 722,
  29587. 'Iacute': 278,
  29588. 'plusminus': 584,
  29589. 'brokenbar': 280,
  29590. 'registered': 737,
  29591. 'Gbreve': 778,
  29592. 'Idotaccent': 278,
  29593. 'summation': 600,
  29594. 'Egrave': 667,
  29595. 'racute': 389,
  29596. 'omacron': 611,
  29597. 'Zacute': 611,
  29598. 'Zcaron': 611,
  29599. 'greaterequal': 549,
  29600. 'Eth': 722,
  29601. 'Ccedilla': 722,
  29602. 'lcommaaccent': 278,
  29603. 'tcaron': 389,
  29604. 'eogonek': 556,
  29605. 'Uogonek': 722,
  29606. 'Aacute': 722,
  29607. 'Adieresis': 722,
  29608. 'egrave': 556,
  29609. 'zacute': 500,
  29610. 'iogonek': 278,
  29611. 'Oacute': 778,
  29612. 'oacute': 611,
  29613. 'amacron': 556,
  29614. 'sacute': 556,
  29615. 'idieresis': 278,
  29616. 'Ocircumflex': 778,
  29617. 'Ugrave': 722,
  29618. 'Delta': 612,
  29619. 'thorn': 611,
  29620. 'twosuperior': 333,
  29621. 'Odieresis': 778,
  29622. 'mu': 611,
  29623. 'igrave': 278,
  29624. 'ohungarumlaut': 611,
  29625. 'Eogonek': 667,
  29626. 'dcroat': 611,
  29627. 'threequarters': 834,
  29628. 'Scedilla': 667,
  29629. 'lcaron': 400,
  29630. 'Kcommaaccent': 722,
  29631. 'Lacute': 611,
  29632. 'trademark': 1000,
  29633. 'edotaccent': 556,
  29634. 'Igrave': 278,
  29635. 'Imacron': 278,
  29636. 'Lcaron': 611,
  29637. 'onehalf': 834,
  29638. 'lessequal': 549,
  29639. 'ocircumflex': 611,
  29640. 'ntilde': 611,
  29641. 'Uhungarumlaut': 722,
  29642. 'Eacute': 667,
  29643. 'emacron': 556,
  29644. 'gbreve': 611,
  29645. 'onequarter': 834,
  29646. 'Scaron': 667,
  29647. 'Scommaaccent': 667,
  29648. 'Ohungarumlaut': 778,
  29649. 'degree': 400,
  29650. 'ograve': 611,
  29651. 'Ccaron': 722,
  29652. 'ugrave': 611,
  29653. 'radical': 549,
  29654. 'Dcaron': 722,
  29655. 'rcommaaccent': 389,
  29656. 'Ntilde': 722,
  29657. 'otilde': 611,
  29658. 'Rcommaaccent': 722,
  29659. 'Lcommaaccent': 611,
  29660. 'Atilde': 722,
  29661. 'Aogonek': 722,
  29662. 'Aring': 722,
  29663. 'Otilde': 778,
  29664. 'zdotaccent': 500,
  29665. 'Ecaron': 667,
  29666. 'Iogonek': 278,
  29667. 'kcommaaccent': 556,
  29668. 'minus': 584,
  29669. 'Icircumflex': 278,
  29670. 'ncaron': 611,
  29671. 'tcommaaccent': 333,
  29672. 'logicalnot': 584,
  29673. 'odieresis': 611,
  29674. 'udieresis': 611,
  29675. 'notequal': 549,
  29676. 'gcommaaccent': 611,
  29677. 'eth': 611,
  29678. 'zcaron': 500,
  29679. 'ncommaaccent': 611,
  29680. 'onesuperior': 333,
  29681. 'imacron': 278,
  29682. 'Euro': 556
  29683. },
  29684. 'Helvetica-Oblique' : {
  29685. 'space': 278,
  29686. 'exclam': 278,
  29687. 'quotedbl': 355,
  29688. 'numbersign': 556,
  29689. 'dollar': 556,
  29690. 'percent': 889,
  29691. 'ampersand': 667,
  29692. 'quoteright': 222,
  29693. 'parenleft': 333,
  29694. 'parenright': 333,
  29695. 'asterisk': 389,
  29696. 'plus': 584,
  29697. 'comma': 278,
  29698. 'hyphen': 333,
  29699. 'period': 278,
  29700. 'slash': 278,
  29701. 'zero': 556,
  29702. 'one': 556,
  29703. 'two': 556,
  29704. 'three': 556,
  29705. 'four': 556,
  29706. 'five': 556,
  29707. 'six': 556,
  29708. 'seven': 556,
  29709. 'eight': 556,
  29710. 'nine': 556,
  29711. 'colon': 278,
  29712. 'semicolon': 278,
  29713. 'less': 584,
  29714. 'equal': 584,
  29715. 'greater': 584,
  29716. 'question': 556,
  29717. 'at': 1015,
  29718. 'A': 667,
  29719. 'B': 667,
  29720. 'C': 722,
  29721. 'D': 722,
  29722. 'E': 667,
  29723. 'F': 611,
  29724. 'G': 778,
  29725. 'H': 722,
  29726. 'I': 278,
  29727. 'J': 500,
  29728. 'K': 667,
  29729. 'L': 556,
  29730. 'M': 833,
  29731. 'N': 722,
  29732. 'O': 778,
  29733. 'P': 667,
  29734. 'Q': 778,
  29735. 'R': 722,
  29736. 'S': 667,
  29737. 'T': 611,
  29738. 'U': 722,
  29739. 'V': 667,
  29740. 'W': 944,
  29741. 'X': 667,
  29742. 'Y': 667,
  29743. 'Z': 611,
  29744. 'bracketleft': 278,
  29745. 'backslash': 278,
  29746. 'bracketright': 278,
  29747. 'asciicircum': 469,
  29748. 'underscore': 556,
  29749. 'quoteleft': 222,
  29750. 'a': 556,
  29751. 'b': 556,
  29752. 'c': 500,
  29753. 'd': 556,
  29754. 'e': 556,
  29755. 'f': 278,
  29756. 'g': 556,
  29757. 'h': 556,
  29758. 'i': 222,
  29759. 'j': 222,
  29760. 'k': 500,
  29761. 'l': 222,
  29762. 'm': 833,
  29763. 'n': 556,
  29764. 'o': 556,
  29765. 'p': 556,
  29766. 'q': 556,
  29767. 'r': 333,
  29768. 's': 500,
  29769. 't': 278,
  29770. 'u': 556,
  29771. 'v': 500,
  29772. 'w': 722,
  29773. 'x': 500,
  29774. 'y': 500,
  29775. 'z': 500,
  29776. 'braceleft': 334,
  29777. 'bar': 260,
  29778. 'braceright': 334,
  29779. 'asciitilde': 584,
  29780. 'exclamdown': 333,
  29781. 'cent': 556,
  29782. 'sterling': 556,
  29783. 'fraction': 167,
  29784. 'yen': 556,
  29785. 'florin': 556,
  29786. 'section': 556,
  29787. 'currency': 556,
  29788. 'quotesingle': 191,
  29789. 'quotedblleft': 333,
  29790. 'guillemotleft': 556,
  29791. 'guilsinglleft': 333,
  29792. 'guilsinglright': 333,
  29793. 'fi': 500,
  29794. 'fl': 500,
  29795. 'endash': 556,
  29796. 'dagger': 556,
  29797. 'daggerdbl': 556,
  29798. 'periodcentered': 278,
  29799. 'paragraph': 537,
  29800. 'bullet': 350,
  29801. 'quotesinglbase': 222,
  29802. 'quotedblbase': 333,
  29803. 'quotedblright': 333,
  29804. 'guillemotright': 556,
  29805. 'ellipsis': 1000,
  29806. 'perthousand': 1000,
  29807. 'questiondown': 611,
  29808. 'grave': 333,
  29809. 'acute': 333,
  29810. 'circumflex': 333,
  29811. 'tilde': 333,
  29812. 'macron': 333,
  29813. 'breve': 333,
  29814. 'dotaccent': 333,
  29815. 'dieresis': 333,
  29816. 'ring': 333,
  29817. 'cedilla': 333,
  29818. 'hungarumlaut': 333,
  29819. 'ogonek': 333,
  29820. 'caron': 333,
  29821. 'emdash': 1000,
  29822. 'AE': 1000,
  29823. 'ordfeminine': 370,
  29824. 'Lslash': 556,
  29825. 'Oslash': 778,
  29826. 'OE': 1000,
  29827. 'ordmasculine': 365,
  29828. 'ae': 889,
  29829. 'dotlessi': 278,
  29830. 'lslash': 222,
  29831. 'oslash': 611,
  29832. 'oe': 944,
  29833. 'germandbls': 611,
  29834. 'Idieresis': 278,
  29835. 'eacute': 556,
  29836. 'abreve': 556,
  29837. 'uhungarumlaut': 556,
  29838. 'ecaron': 556,
  29839. 'Ydieresis': 667,
  29840. 'divide': 584,
  29841. 'Yacute': 667,
  29842. 'Acircumflex': 667,
  29843. 'aacute': 556,
  29844. 'Ucircumflex': 722,
  29845. 'yacute': 500,
  29846. 'scommaaccent': 500,
  29847. 'ecircumflex': 556,
  29848. 'Uring': 722,
  29849. 'Udieresis': 722,
  29850. 'aogonek': 556,
  29851. 'Uacute': 722,
  29852. 'uogonek': 556,
  29853. 'Edieresis': 667,
  29854. 'Dcroat': 722,
  29855. 'commaaccent': 250,
  29856. 'copyright': 737,
  29857. 'Emacron': 667,
  29858. 'ccaron': 500,
  29859. 'aring': 556,
  29860. 'Ncommaaccent': 722,
  29861. 'lacute': 222,
  29862. 'agrave': 556,
  29863. 'Tcommaaccent': 611,
  29864. 'Cacute': 722,
  29865. 'atilde': 556,
  29866. 'Edotaccent': 667,
  29867. 'scaron': 500,
  29868. 'scedilla': 500,
  29869. 'iacute': 278,
  29870. 'lozenge': 471,
  29871. 'Rcaron': 722,
  29872. 'Gcommaaccent': 778,
  29873. 'ucircumflex': 556,
  29874. 'acircumflex': 556,
  29875. 'Amacron': 667,
  29876. 'rcaron': 333,
  29877. 'ccedilla': 500,
  29878. 'Zdotaccent': 611,
  29879. 'Thorn': 667,
  29880. 'Omacron': 778,
  29881. 'Racute': 722,
  29882. 'Sacute': 667,
  29883. 'dcaron': 643,
  29884. 'Umacron': 722,
  29885. 'uring': 556,
  29886. 'threesuperior': 333,
  29887. 'Ograve': 778,
  29888. 'Agrave': 667,
  29889. 'Abreve': 667,
  29890. 'multiply': 584,
  29891. 'uacute': 556,
  29892. 'Tcaron': 611,
  29893. 'partialdiff': 476,
  29894. 'ydieresis': 500,
  29895. 'Nacute': 722,
  29896. 'icircumflex': 278,
  29897. 'Ecircumflex': 667,
  29898. 'adieresis': 556,
  29899. 'edieresis': 556,
  29900. 'cacute': 500,
  29901. 'nacute': 556,
  29902. 'umacron': 556,
  29903. 'Ncaron': 722,
  29904. 'Iacute': 278,
  29905. 'plusminus': 584,
  29906. 'brokenbar': 260,
  29907. 'registered': 737,
  29908. 'Gbreve': 778,
  29909. 'Idotaccent': 278,
  29910. 'summation': 600,
  29911. 'Egrave': 667,
  29912. 'racute': 333,
  29913. 'omacron': 556,
  29914. 'Zacute': 611,
  29915. 'Zcaron': 611,
  29916. 'greaterequal': 549,
  29917. 'Eth': 722,
  29918. 'Ccedilla': 722,
  29919. 'lcommaaccent': 222,
  29920. 'tcaron': 317,
  29921. 'eogonek': 556,
  29922. 'Uogonek': 722,
  29923. 'Aacute': 667,
  29924. 'Adieresis': 667,
  29925. 'egrave': 556,
  29926. 'zacute': 500,
  29927. 'iogonek': 222,
  29928. 'Oacute': 778,
  29929. 'oacute': 556,
  29930. 'amacron': 556,
  29931. 'sacute': 500,
  29932. 'idieresis': 278,
  29933. 'Ocircumflex': 778,
  29934. 'Ugrave': 722,
  29935. 'Delta': 612,
  29936. 'thorn': 556,
  29937. 'twosuperior': 333,
  29938. 'Odieresis': 778,
  29939. 'mu': 556,
  29940. 'igrave': 278,
  29941. 'ohungarumlaut': 556,
  29942. 'Eogonek': 667,
  29943. 'dcroat': 556,
  29944. 'threequarters': 834,
  29945. 'Scedilla': 667,
  29946. 'lcaron': 299,
  29947. 'Kcommaaccent': 667,
  29948. 'Lacute': 556,
  29949. 'trademark': 1000,
  29950. 'edotaccent': 556,
  29951. 'Igrave': 278,
  29952. 'Imacron': 278,
  29953. 'Lcaron': 556,
  29954. 'onehalf': 834,
  29955. 'lessequal': 549,
  29956. 'ocircumflex': 556,
  29957. 'ntilde': 556,
  29958. 'Uhungarumlaut': 722,
  29959. 'Eacute': 667,
  29960. 'emacron': 556,
  29961. 'gbreve': 556,
  29962. 'onequarter': 834,
  29963. 'Scaron': 667,
  29964. 'Scommaaccent': 667,
  29965. 'Ohungarumlaut': 778,
  29966. 'degree': 400,
  29967. 'ograve': 556,
  29968. 'Ccaron': 722,
  29969. 'ugrave': 556,
  29970. 'radical': 453,
  29971. 'Dcaron': 722,
  29972. 'rcommaaccent': 333,
  29973. 'Ntilde': 722,
  29974. 'otilde': 556,
  29975. 'Rcommaaccent': 722,
  29976. 'Lcommaaccent': 556,
  29977. 'Atilde': 667,
  29978. 'Aogonek': 667,
  29979. 'Aring': 667,
  29980. 'Otilde': 778,
  29981. 'zdotaccent': 500,
  29982. 'Ecaron': 667,
  29983. 'Iogonek': 278,
  29984. 'kcommaaccent': 500,
  29985. 'minus': 584,
  29986. 'Icircumflex': 278,
  29987. 'ncaron': 556,
  29988. 'tcommaaccent': 278,
  29989. 'logicalnot': 584,
  29990. 'odieresis': 556,
  29991. 'udieresis': 556,
  29992. 'notequal': 549,
  29993. 'gcommaaccent': 556,
  29994. 'eth': 556,
  29995. 'zcaron': 500,
  29996. 'ncommaaccent': 556,
  29997. 'onesuperior': 333,
  29998. 'imacron': 278,
  29999. 'Euro': 556
  30000. },
  30001. 'Symbol': {
  30002. 'space': 250,
  30003. 'exclam': 333,
  30004. 'universal': 713,
  30005. 'numbersign': 500,
  30006. 'existential': 549,
  30007. 'percent': 833,
  30008. 'ampersand': 778,
  30009. 'suchthat': 439,
  30010. 'parenleft': 333,
  30011. 'parenright': 333,
  30012. 'asteriskmath': 500,
  30013. 'plus': 549,
  30014. 'comma': 250,
  30015. 'minus': 549,
  30016. 'period': 250,
  30017. 'slash': 278,
  30018. 'zero': 500,
  30019. 'one': 500,
  30020. 'two': 500,
  30021. 'three': 500,
  30022. 'four': 500,
  30023. 'five': 500,
  30024. 'six': 500,
  30025. 'seven': 500,
  30026. 'eight': 500,
  30027. 'nine': 500,
  30028. 'colon': 278,
  30029. 'semicolon': 278,
  30030. 'less': 549,
  30031. 'equal': 549,
  30032. 'greater': 549,
  30033. 'question': 444,
  30034. 'congruent': 549,
  30035. 'Alpha': 722,
  30036. 'Beta': 667,
  30037. 'Chi': 722,
  30038. 'Delta': 612,
  30039. 'Epsilon': 611,
  30040. 'Phi': 763,
  30041. 'Gamma': 603,
  30042. 'Eta': 722,
  30043. 'Iota': 333,
  30044. 'theta1': 631,
  30045. 'Kappa': 722,
  30046. 'Lambda': 686,
  30047. 'Mu': 889,
  30048. 'Nu': 722,
  30049. 'Omicron': 722,
  30050. 'Pi': 768,
  30051. 'Theta': 741,
  30052. 'Rho': 556,
  30053. 'Sigma': 592,
  30054. 'Tau': 611,
  30055. 'Upsilon': 690,
  30056. 'sigma1': 439,
  30057. 'Omega': 768,
  30058. 'Xi': 645,
  30059. 'Psi': 795,
  30060. 'Zeta': 611,
  30061. 'bracketleft': 333,
  30062. 'therefore': 863,
  30063. 'bracketright': 333,
  30064. 'perpendicular': 658,
  30065. 'underscore': 500,
  30066. 'radicalex': 500,
  30067. 'alpha': 631,
  30068. 'beta': 549,
  30069. 'chi': 549,
  30070. 'delta': 494,
  30071. 'epsilon': 439,
  30072. 'phi': 521,
  30073. 'gamma': 411,
  30074. 'eta': 603,
  30075. 'iota': 329,
  30076. 'phi1': 603,
  30077. 'kappa': 549,
  30078. 'lambda': 549,
  30079. 'mu': 576,
  30080. 'nu': 521,
  30081. 'omicron': 549,
  30082. 'pi': 549,
  30083. 'theta': 521,
  30084. 'rho': 549,
  30085. 'sigma': 603,
  30086. 'tau': 439,
  30087. 'upsilon': 576,
  30088. 'omega1': 713,
  30089. 'omega': 686,
  30090. 'xi': 493,
  30091. 'psi': 686,
  30092. 'zeta': 494,
  30093. 'braceleft': 480,
  30094. 'bar': 200,
  30095. 'braceright': 480,
  30096. 'similar': 549,
  30097. 'Euro': 750,
  30098. 'Upsilon1': 620,
  30099. 'minute': 247,
  30100. 'lessequal': 549,
  30101. 'fraction': 167,
  30102. 'infinity': 713,
  30103. 'florin': 500,
  30104. 'club': 753,
  30105. 'diamond': 753,
  30106. 'heart': 753,
  30107. 'spade': 753,
  30108. 'arrowboth': 1042,
  30109. 'arrowleft': 987,
  30110. 'arrowup': 603,
  30111. 'arrowright': 987,
  30112. 'arrowdown': 603,
  30113. 'degree': 400,
  30114. 'plusminus': 549,
  30115. 'second': 411,
  30116. 'greaterequal': 549,
  30117. 'multiply': 549,
  30118. 'proportional': 713,
  30119. 'partialdiff': 494,
  30120. 'bullet': 460,
  30121. 'divide': 549,
  30122. 'notequal': 549,
  30123. 'equivalence': 549,
  30124. 'approxequal': 549,
  30125. 'ellipsis': 1000,
  30126. 'arrowvertex': 603,
  30127. 'arrowhorizex': 1000,
  30128. 'carriagereturn': 658,
  30129. 'aleph': 823,
  30130. 'Ifraktur': 686,
  30131. 'Rfraktur': 795,
  30132. 'weierstrass': 987,
  30133. 'circlemultiply': 768,
  30134. 'circleplus': 768,
  30135. 'emptyset': 823,
  30136. 'intersection': 768,
  30137. 'union': 768,
  30138. 'propersuperset': 713,
  30139. 'reflexsuperset': 713,
  30140. 'notsubset': 713,
  30141. 'propersubset': 713,
  30142. 'reflexsubset': 713,
  30143. 'element': 713,
  30144. 'notelement': 713,
  30145. 'angle': 768,
  30146. 'gradient': 713,
  30147. 'registerserif': 790,
  30148. 'copyrightserif': 790,
  30149. 'trademarkserif': 890,
  30150. 'product': 823,
  30151. 'radical': 549,
  30152. 'dotmath': 250,
  30153. 'logicalnot': 713,
  30154. 'logicaland': 603,
  30155. 'logicalor': 603,
  30156. 'arrowdblboth': 1042,
  30157. 'arrowdblleft': 987,
  30158. 'arrowdblup': 603,
  30159. 'arrowdblright': 987,
  30160. 'arrowdbldown': 603,
  30161. 'lozenge': 494,
  30162. 'angleleft': 329,
  30163. 'registersans': 790,
  30164. 'copyrightsans': 790,
  30165. 'trademarksans': 786,
  30166. 'summation': 713,
  30167. 'parenlefttp': 384,
  30168. 'parenleftex': 384,
  30169. 'parenleftbt': 384,
  30170. 'bracketlefttp': 384,
  30171. 'bracketleftex': 384,
  30172. 'bracketleftbt': 384,
  30173. 'bracelefttp': 494,
  30174. 'braceleftmid': 494,
  30175. 'braceleftbt': 494,
  30176. 'braceex': 494,
  30177. 'angleright': 329,
  30178. 'integral': 274,
  30179. 'integraltp': 686,
  30180. 'integralex': 686,
  30181. 'integralbt': 686,
  30182. 'parenrighttp': 384,
  30183. 'parenrightex': 384,
  30184. 'parenrightbt': 384,
  30185. 'bracketrighttp': 384,
  30186. 'bracketrightex': 384,
  30187. 'bracketrightbt': 384,
  30188. 'bracerighttp': 494,
  30189. 'bracerightmid': 494,
  30190. 'bracerightbt': 494,
  30191. 'apple': 790
  30192. },
  30193. 'Times-Roman': {
  30194. 'space': 250,
  30195. 'exclam': 333,
  30196. 'quotedbl': 408,
  30197. 'numbersign': 500,
  30198. 'dollar': 500,
  30199. 'percent': 833,
  30200. 'ampersand': 778,
  30201. 'quoteright': 333,
  30202. 'parenleft': 333,
  30203. 'parenright': 333,
  30204. 'asterisk': 500,
  30205. 'plus': 564,
  30206. 'comma': 250,
  30207. 'hyphen': 333,
  30208. 'period': 250,
  30209. 'slash': 278,
  30210. 'zero': 500,
  30211. 'one': 500,
  30212. 'two': 500,
  30213. 'three': 500,
  30214. 'four': 500,
  30215. 'five': 500,
  30216. 'six': 500,
  30217. 'seven': 500,
  30218. 'eight': 500,
  30219. 'nine': 500,
  30220. 'colon': 278,
  30221. 'semicolon': 278,
  30222. 'less': 564,
  30223. 'equal': 564,
  30224. 'greater': 564,
  30225. 'question': 444,
  30226. 'at': 921,
  30227. 'A': 722,
  30228. 'B': 667,
  30229. 'C': 667,
  30230. 'D': 722,
  30231. 'E': 611,
  30232. 'F': 556,
  30233. 'G': 722,
  30234. 'H': 722,
  30235. 'I': 333,
  30236. 'J': 389,
  30237. 'K': 722,
  30238. 'L': 611,
  30239. 'M': 889,
  30240. 'N': 722,
  30241. 'O': 722,
  30242. 'P': 556,
  30243. 'Q': 722,
  30244. 'R': 667,
  30245. 'S': 556,
  30246. 'T': 611,
  30247. 'U': 722,
  30248. 'V': 722,
  30249. 'W': 944,
  30250. 'X': 722,
  30251. 'Y': 722,
  30252. 'Z': 611,
  30253. 'bracketleft': 333,
  30254. 'backslash': 278,
  30255. 'bracketright': 333,
  30256. 'asciicircum': 469,
  30257. 'underscore': 500,
  30258. 'quoteleft': 333,
  30259. 'a': 444,
  30260. 'b': 500,
  30261. 'c': 444,
  30262. 'd': 500,
  30263. 'e': 444,
  30264. 'f': 333,
  30265. 'g': 500,
  30266. 'h': 500,
  30267. 'i': 278,
  30268. 'j': 278,
  30269. 'k': 500,
  30270. 'l': 278,
  30271. 'm': 778,
  30272. 'n': 500,
  30273. 'o': 500,
  30274. 'p': 500,
  30275. 'q': 500,
  30276. 'r': 333,
  30277. 's': 389,
  30278. 't': 278,
  30279. 'u': 500,
  30280. 'v': 500,
  30281. 'w': 722,
  30282. 'x': 500,
  30283. 'y': 500,
  30284. 'z': 444,
  30285. 'braceleft': 480,
  30286. 'bar': 200,
  30287. 'braceright': 480,
  30288. 'asciitilde': 541,
  30289. 'exclamdown': 333,
  30290. 'cent': 500,
  30291. 'sterling': 500,
  30292. 'fraction': 167,
  30293. 'yen': 500,
  30294. 'florin': 500,
  30295. 'section': 500,
  30296. 'currency': 500,
  30297. 'quotesingle': 180,
  30298. 'quotedblleft': 444,
  30299. 'guillemotleft': 500,
  30300. 'guilsinglleft': 333,
  30301. 'guilsinglright': 333,
  30302. 'fi': 556,
  30303. 'fl': 556,
  30304. 'endash': 500,
  30305. 'dagger': 500,
  30306. 'daggerdbl': 500,
  30307. 'periodcentered': 250,
  30308. 'paragraph': 453,
  30309. 'bullet': 350,
  30310. 'quotesinglbase': 333,
  30311. 'quotedblbase': 444,
  30312. 'quotedblright': 444,
  30313. 'guillemotright': 500,
  30314. 'ellipsis': 1000,
  30315. 'perthousand': 1000,
  30316. 'questiondown': 444,
  30317. 'grave': 333,
  30318. 'acute': 333,
  30319. 'circumflex': 333,
  30320. 'tilde': 333,
  30321. 'macron': 333,
  30322. 'breve': 333,
  30323. 'dotaccent': 333,
  30324. 'dieresis': 333,
  30325. 'ring': 333,
  30326. 'cedilla': 333,
  30327. 'hungarumlaut': 333,
  30328. 'ogonek': 333,
  30329. 'caron': 333,
  30330. 'emdash': 1000,
  30331. 'AE': 889,
  30332. 'ordfeminine': 276,
  30333. 'Lslash': 611,
  30334. 'Oslash': 722,
  30335. 'OE': 889,
  30336. 'ordmasculine': 310,
  30337. 'ae': 667,
  30338. 'dotlessi': 278,
  30339. 'lslash': 278,
  30340. 'oslash': 500,
  30341. 'oe': 722,
  30342. 'germandbls': 500,
  30343. 'Idieresis': 333,
  30344. 'eacute': 444,
  30345. 'abreve': 444,
  30346. 'uhungarumlaut': 500,
  30347. 'ecaron': 444,
  30348. 'Ydieresis': 722,
  30349. 'divide': 564,
  30350. 'Yacute': 722,
  30351. 'Acircumflex': 722,
  30352. 'aacute': 444,
  30353. 'Ucircumflex': 722,
  30354. 'yacute': 500,
  30355. 'scommaaccent': 389,
  30356. 'ecircumflex': 444,
  30357. 'Uring': 722,
  30358. 'Udieresis': 722,
  30359. 'aogonek': 444,
  30360. 'Uacute': 722,
  30361. 'uogonek': 500,
  30362. 'Edieresis': 611,
  30363. 'Dcroat': 722,
  30364. 'commaaccent': 250,
  30365. 'copyright': 760,
  30366. 'Emacron': 611,
  30367. 'ccaron': 444,
  30368. 'aring': 444,
  30369. 'Ncommaaccent': 722,
  30370. 'lacute': 278,
  30371. 'agrave': 444,
  30372. 'Tcommaaccent': 611,
  30373. 'Cacute': 667,
  30374. 'atilde': 444,
  30375. 'Edotaccent': 611,
  30376. 'scaron': 389,
  30377. 'scedilla': 389,
  30378. 'iacute': 278,
  30379. 'lozenge': 471,
  30380. 'Rcaron': 667,
  30381. 'Gcommaaccent': 722,
  30382. 'ucircumflex': 500,
  30383. 'acircumflex': 444,
  30384. 'Amacron': 722,
  30385. 'rcaron': 333,
  30386. 'ccedilla': 444,
  30387. 'Zdotaccent': 611,
  30388. 'Thorn': 556,
  30389. 'Omacron': 722,
  30390. 'Racute': 667,
  30391. 'Sacute': 556,
  30392. 'dcaron': 588,
  30393. 'Umacron': 722,
  30394. 'uring': 500,
  30395. 'threesuperior': 300,
  30396. 'Ograve': 722,
  30397. 'Agrave': 722,
  30398. 'Abreve': 722,
  30399. 'multiply': 564,
  30400. 'uacute': 500,
  30401. 'Tcaron': 611,
  30402. 'partialdiff': 476,
  30403. 'ydieresis': 500,
  30404. 'Nacute': 722,
  30405. 'icircumflex': 278,
  30406. 'Ecircumflex': 611,
  30407. 'adieresis': 444,
  30408. 'edieresis': 444,
  30409. 'cacute': 444,
  30410. 'nacute': 500,
  30411. 'umacron': 500,
  30412. 'Ncaron': 722,
  30413. 'Iacute': 333,
  30414. 'plusminus': 564,
  30415. 'brokenbar': 200,
  30416. 'registered': 760,
  30417. 'Gbreve': 722,
  30418. 'Idotaccent': 333,
  30419. 'summation': 600,
  30420. 'Egrave': 611,
  30421. 'racute': 333,
  30422. 'omacron': 500,
  30423. 'Zacute': 611,
  30424. 'Zcaron': 611,
  30425. 'greaterequal': 549,
  30426. 'Eth': 722,
  30427. 'Ccedilla': 667,
  30428. 'lcommaaccent': 278,
  30429. 'tcaron': 326,
  30430. 'eogonek': 444,
  30431. 'Uogonek': 722,
  30432. 'Aacute': 722,
  30433. 'Adieresis': 722,
  30434. 'egrave': 444,
  30435. 'zacute': 444,
  30436. 'iogonek': 278,
  30437. 'Oacute': 722,
  30438. 'oacute': 500,
  30439. 'amacron': 444,
  30440. 'sacute': 389,
  30441. 'idieresis': 278,
  30442. 'Ocircumflex': 722,
  30443. 'Ugrave': 722,
  30444. 'Delta': 612,
  30445. 'thorn': 500,
  30446. 'twosuperior': 300,
  30447. 'Odieresis': 722,
  30448. 'mu': 500,
  30449. 'igrave': 278,
  30450. 'ohungarumlaut': 500,
  30451. 'Eogonek': 611,
  30452. 'dcroat': 500,
  30453. 'threequarters': 750,
  30454. 'Scedilla': 556,
  30455. 'lcaron': 344,
  30456. 'Kcommaaccent': 722,
  30457. 'Lacute': 611,
  30458. 'trademark': 980,
  30459. 'edotaccent': 444,
  30460. 'Igrave': 333,
  30461. 'Imacron': 333,
  30462. 'Lcaron': 611,
  30463. 'onehalf': 750,
  30464. 'lessequal': 549,
  30465. 'ocircumflex': 500,
  30466. 'ntilde': 500,
  30467. 'Uhungarumlaut': 722,
  30468. 'Eacute': 611,
  30469. 'emacron': 444,
  30470. 'gbreve': 500,
  30471. 'onequarter': 750,
  30472. 'Scaron': 556,
  30473. 'Scommaaccent': 556,
  30474. 'Ohungarumlaut': 722,
  30475. 'degree': 400,
  30476. 'ograve': 500,
  30477. 'Ccaron': 667,
  30478. 'ugrave': 500,
  30479. 'radical': 453,
  30480. 'Dcaron': 722,
  30481. 'rcommaaccent': 333,
  30482. 'Ntilde': 722,
  30483. 'otilde': 500,
  30484. 'Rcommaaccent': 667,
  30485. 'Lcommaaccent': 611,
  30486. 'Atilde': 722,
  30487. 'Aogonek': 722,
  30488. 'Aring': 722,
  30489. 'Otilde': 722,
  30490. 'zdotaccent': 444,
  30491. 'Ecaron': 611,
  30492. 'Iogonek': 333,
  30493. 'kcommaaccent': 500,
  30494. 'minus': 564,
  30495. 'Icircumflex': 333,
  30496. 'ncaron': 500,
  30497. 'tcommaaccent': 278,
  30498. 'logicalnot': 564,
  30499. 'odieresis': 500,
  30500. 'udieresis': 500,
  30501. 'notequal': 549,
  30502. 'gcommaaccent': 500,
  30503. 'eth': 500,
  30504. 'zcaron': 444,
  30505. 'ncommaaccent': 500,
  30506. 'onesuperior': 300,
  30507. 'imacron': 278,
  30508. 'Euro': 500
  30509. },
  30510. 'Times-Bold': {
  30511. 'space': 250,
  30512. 'exclam': 333,
  30513. 'quotedbl': 555,
  30514. 'numbersign': 500,
  30515. 'dollar': 500,
  30516. 'percent': 1000,
  30517. 'ampersand': 833,
  30518. 'quoteright': 333,
  30519. 'parenleft': 333,
  30520. 'parenright': 333,
  30521. 'asterisk': 500,
  30522. 'plus': 570,
  30523. 'comma': 250,
  30524. 'hyphen': 333,
  30525. 'period': 250,
  30526. 'slash': 278,
  30527. 'zero': 500,
  30528. 'one': 500,
  30529. 'two': 500,
  30530. 'three': 500,
  30531. 'four': 500,
  30532. 'five': 500,
  30533. 'six': 500,
  30534. 'seven': 500,
  30535. 'eight': 500,
  30536. 'nine': 500,
  30537. 'colon': 333,
  30538. 'semicolon': 333,
  30539. 'less': 570,
  30540. 'equal': 570,
  30541. 'greater': 570,
  30542. 'question': 500,
  30543. 'at': 930,
  30544. 'A': 722,
  30545. 'B': 667,
  30546. 'C': 722,
  30547. 'D': 722,
  30548. 'E': 667,
  30549. 'F': 611,
  30550. 'G': 778,
  30551. 'H': 778,
  30552. 'I': 389,
  30553. 'J': 500,
  30554. 'K': 778,
  30555. 'L': 667,
  30556. 'M': 944,
  30557. 'N': 722,
  30558. 'O': 778,
  30559. 'P': 611,
  30560. 'Q': 778,
  30561. 'R': 722,
  30562. 'S': 556,
  30563. 'T': 667,
  30564. 'U': 722,
  30565. 'V': 722,
  30566. 'W': 1000,
  30567. 'X': 722,
  30568. 'Y': 722,
  30569. 'Z': 667,
  30570. 'bracketleft': 333,
  30571. 'backslash': 278,
  30572. 'bracketright': 333,
  30573. 'asciicircum': 581,
  30574. 'underscore': 500,
  30575. 'quoteleft': 333,
  30576. 'a': 500,
  30577. 'b': 556,
  30578. 'c': 444,
  30579. 'd': 556,
  30580. 'e': 444,
  30581. 'f': 333,
  30582. 'g': 500,
  30583. 'h': 556,
  30584. 'i': 278,
  30585. 'j': 333,
  30586. 'k': 556,
  30587. 'l': 278,
  30588. 'm': 833,
  30589. 'n': 556,
  30590. 'o': 500,
  30591. 'p': 556,
  30592. 'q': 556,
  30593. 'r': 444,
  30594. 's': 389,
  30595. 't': 333,
  30596. 'u': 556,
  30597. 'v': 500,
  30598. 'w': 722,
  30599. 'x': 500,
  30600. 'y': 500,
  30601. 'z': 444,
  30602. 'braceleft': 394,
  30603. 'bar': 220,
  30604. 'braceright': 394,
  30605. 'asciitilde': 520,
  30606. 'exclamdown': 333,
  30607. 'cent': 500,
  30608. 'sterling': 500,
  30609. 'fraction': 167,
  30610. 'yen': 500,
  30611. 'florin': 500,
  30612. 'section': 500,
  30613. 'currency': 500,
  30614. 'quotesingle': 278,
  30615. 'quotedblleft': 500,
  30616. 'guillemotleft': 500,
  30617. 'guilsinglleft': 333,
  30618. 'guilsinglright': 333,
  30619. 'fi': 556,
  30620. 'fl': 556,
  30621. 'endash': 500,
  30622. 'dagger': 500,
  30623. 'daggerdbl': 500,
  30624. 'periodcentered': 250,
  30625. 'paragraph': 540,
  30626. 'bullet': 350,
  30627. 'quotesinglbase': 333,
  30628. 'quotedblbase': 500,
  30629. 'quotedblright': 500,
  30630. 'guillemotright': 500,
  30631. 'ellipsis': 1000,
  30632. 'perthousand': 1000,
  30633. 'questiondown': 500,
  30634. 'grave': 333,
  30635. 'acute': 333,
  30636. 'circumflex': 333,
  30637. 'tilde': 333,
  30638. 'macron': 333,
  30639. 'breve': 333,
  30640. 'dotaccent': 333,
  30641. 'dieresis': 333,
  30642. 'ring': 333,
  30643. 'cedilla': 333,
  30644. 'hungarumlaut': 333,
  30645. 'ogonek': 333,
  30646. 'caron': 333,
  30647. 'emdash': 1000,
  30648. 'AE': 1000,
  30649. 'ordfeminine': 300,
  30650. 'Lslash': 667,
  30651. 'Oslash': 778,
  30652. 'OE': 1000,
  30653. 'ordmasculine': 330,
  30654. 'ae': 722,
  30655. 'dotlessi': 278,
  30656. 'lslash': 278,
  30657. 'oslash': 500,
  30658. 'oe': 722,
  30659. 'germandbls': 556,
  30660. 'Idieresis': 389,
  30661. 'eacute': 444,
  30662. 'abreve': 500,
  30663. 'uhungarumlaut': 556,
  30664. 'ecaron': 444,
  30665. 'Ydieresis': 722,
  30666. 'divide': 570,
  30667. 'Yacute': 722,
  30668. 'Acircumflex': 722,
  30669. 'aacute': 500,
  30670. 'Ucircumflex': 722,
  30671. 'yacute': 500,
  30672. 'scommaaccent': 389,
  30673. 'ecircumflex': 444,
  30674. 'Uring': 722,
  30675. 'Udieresis': 722,
  30676. 'aogonek': 500,
  30677. 'Uacute': 722,
  30678. 'uogonek': 556,
  30679. 'Edieresis': 667,
  30680. 'Dcroat': 722,
  30681. 'commaaccent': 250,
  30682. 'copyright': 747,
  30683. 'Emacron': 667,
  30684. 'ccaron': 444,
  30685. 'aring': 500,
  30686. 'Ncommaaccent': 722,
  30687. 'lacute': 278,
  30688. 'agrave': 500,
  30689. 'Tcommaaccent': 667,
  30690. 'Cacute': 722,
  30691. 'atilde': 500,
  30692. 'Edotaccent': 667,
  30693. 'scaron': 389,
  30694. 'scedilla': 389,
  30695. 'iacute': 278,
  30696. 'lozenge': 494,
  30697. 'Rcaron': 722,
  30698. 'Gcommaaccent': 778,
  30699. 'ucircumflex': 556,
  30700. 'acircumflex': 500,
  30701. 'Amacron': 722,
  30702. 'rcaron': 444,
  30703. 'ccedilla': 444,
  30704. 'Zdotaccent': 667,
  30705. 'Thorn': 611,
  30706. 'Omacron': 778,
  30707. 'Racute': 722,
  30708. 'Sacute': 556,
  30709. 'dcaron': 672,
  30710. 'Umacron': 722,
  30711. 'uring': 556,
  30712. 'threesuperior': 300,
  30713. 'Ograve': 778,
  30714. 'Agrave': 722,
  30715. 'Abreve': 722,
  30716. 'multiply': 570,
  30717. 'uacute': 556,
  30718. 'Tcaron': 667,
  30719. 'partialdiff': 494,
  30720. 'ydieresis': 500,
  30721. 'Nacute': 722,
  30722. 'icircumflex': 278,
  30723. 'Ecircumflex': 667,
  30724. 'adieresis': 500,
  30725. 'edieresis': 444,
  30726. 'cacute': 444,
  30727. 'nacute': 556,
  30728. 'umacron': 556,
  30729. 'Ncaron': 722,
  30730. 'Iacute': 389,
  30731. 'plusminus': 570,
  30732. 'brokenbar': 220,
  30733. 'registered': 747,
  30734. 'Gbreve': 778,
  30735. 'Idotaccent': 389,
  30736. 'summation': 600,
  30737. 'Egrave': 667,
  30738. 'racute': 444,
  30739. 'omacron': 500,
  30740. 'Zacute': 667,
  30741. 'Zcaron': 667,
  30742. 'greaterequal': 549,
  30743. 'Eth': 722,
  30744. 'Ccedilla': 722,
  30745. 'lcommaaccent': 278,
  30746. 'tcaron': 416,
  30747. 'eogonek': 444,
  30748. 'Uogonek': 722,
  30749. 'Aacute': 722,
  30750. 'Adieresis': 722,
  30751. 'egrave': 444,
  30752. 'zacute': 444,
  30753. 'iogonek': 278,
  30754. 'Oacute': 778,
  30755. 'oacute': 500,
  30756. 'amacron': 500,
  30757. 'sacute': 389,
  30758. 'idieresis': 278,
  30759. 'Ocircumflex': 778,
  30760. 'Ugrave': 722,
  30761. 'Delta': 612,
  30762. 'thorn': 556,
  30763. 'twosuperior': 300,
  30764. 'Odieresis': 778,
  30765. 'mu': 556,
  30766. 'igrave': 278,
  30767. 'ohungarumlaut': 500,
  30768. 'Eogonek': 667,
  30769. 'dcroat': 556,
  30770. 'threequarters': 750,
  30771. 'Scedilla': 556,
  30772. 'lcaron': 394,
  30773. 'Kcommaaccent': 778,
  30774. 'Lacute': 667,
  30775. 'trademark': 1000,
  30776. 'edotaccent': 444,
  30777. 'Igrave': 389,
  30778. 'Imacron': 389,
  30779. 'Lcaron': 667,
  30780. 'onehalf': 750,
  30781. 'lessequal': 549,
  30782. 'ocircumflex': 500,
  30783. 'ntilde': 556,
  30784. 'Uhungarumlaut': 722,
  30785. 'Eacute': 667,
  30786. 'emacron': 444,
  30787. 'gbreve': 500,
  30788. 'onequarter': 750,
  30789. 'Scaron': 556,
  30790. 'Scommaaccent': 556,
  30791. 'Ohungarumlaut': 778,
  30792. 'degree': 400,
  30793. 'ograve': 500,
  30794. 'Ccaron': 722,
  30795. 'ugrave': 556,
  30796. 'radical': 549,
  30797. 'Dcaron': 722,
  30798. 'rcommaaccent': 444,
  30799. 'Ntilde': 722,
  30800. 'otilde': 500,
  30801. 'Rcommaaccent': 722,
  30802. 'Lcommaaccent': 667,
  30803. 'Atilde': 722,
  30804. 'Aogonek': 722,
  30805. 'Aring': 722,
  30806. 'Otilde': 778,
  30807. 'zdotaccent': 444,
  30808. 'Ecaron': 667,
  30809. 'Iogonek': 389,
  30810. 'kcommaaccent': 556,
  30811. 'minus': 570,
  30812. 'Icircumflex': 389,
  30813. 'ncaron': 556,
  30814. 'tcommaaccent': 333,
  30815. 'logicalnot': 570,
  30816. 'odieresis': 500,
  30817. 'udieresis': 556,
  30818. 'notequal': 549,
  30819. 'gcommaaccent': 500,
  30820. 'eth': 500,
  30821. 'zcaron': 444,
  30822. 'ncommaaccent': 556,
  30823. 'onesuperior': 300,
  30824. 'imacron': 278,
  30825. 'Euro': 500
  30826. },
  30827. 'Times-BoldItalic': {
  30828. 'space': 250,
  30829. 'exclam': 389,
  30830. 'quotedbl': 555,
  30831. 'numbersign': 500,
  30832. 'dollar': 500,
  30833. 'percent': 833,
  30834. 'ampersand': 778,
  30835. 'quoteright': 333,
  30836. 'parenleft': 333,
  30837. 'parenright': 333,
  30838. 'asterisk': 500,
  30839. 'plus': 570,
  30840. 'comma': 250,
  30841. 'hyphen': 333,
  30842. 'period': 250,
  30843. 'slash': 278,
  30844. 'zero': 500,
  30845. 'one': 500,
  30846. 'two': 500,
  30847. 'three': 500,
  30848. 'four': 500,
  30849. 'five': 500,
  30850. 'six': 500,
  30851. 'seven': 500,
  30852. 'eight': 500,
  30853. 'nine': 500,
  30854. 'colon': 333,
  30855. 'semicolon': 333,
  30856. 'less': 570,
  30857. 'equal': 570,
  30858. 'greater': 570,
  30859. 'question': 500,
  30860. 'at': 832,
  30861. 'A': 667,
  30862. 'B': 667,
  30863. 'C': 667,
  30864. 'D': 722,
  30865. 'E': 667,
  30866. 'F': 667,
  30867. 'G': 722,
  30868. 'H': 778,
  30869. 'I': 389,
  30870. 'J': 500,
  30871. 'K': 667,
  30872. 'L': 611,
  30873. 'M': 889,
  30874. 'N': 722,
  30875. 'O': 722,
  30876. 'P': 611,
  30877. 'Q': 722,
  30878. 'R': 667,
  30879. 'S': 556,
  30880. 'T': 611,
  30881. 'U': 722,
  30882. 'V': 667,
  30883. 'W': 889,
  30884. 'X': 667,
  30885. 'Y': 611,
  30886. 'Z': 611,
  30887. 'bracketleft': 333,
  30888. 'backslash': 278,
  30889. 'bracketright': 333,
  30890. 'asciicircum': 570,
  30891. 'underscore': 500,
  30892. 'quoteleft': 333,
  30893. 'a': 500,
  30894. 'b': 500,
  30895. 'c': 444,
  30896. 'd': 500,
  30897. 'e': 444,
  30898. 'f': 333,
  30899. 'g': 500,
  30900. 'h': 556,
  30901. 'i': 278,
  30902. 'j': 278,
  30903. 'k': 500,
  30904. 'l': 278,
  30905. 'm': 778,
  30906. 'n': 556,
  30907. 'o': 500,
  30908. 'p': 500,
  30909. 'q': 500,
  30910. 'r': 389,
  30911. 's': 389,
  30912. 't': 278,
  30913. 'u': 556,
  30914. 'v': 444,
  30915. 'w': 667,
  30916. 'x': 500,
  30917. 'y': 444,
  30918. 'z': 389,
  30919. 'braceleft': 348,
  30920. 'bar': 220,
  30921. 'braceright': 348,
  30922. 'asciitilde': 570,
  30923. 'exclamdown': 389,
  30924. 'cent': 500,
  30925. 'sterling': 500,
  30926. 'fraction': 167,
  30927. 'yen': 500,
  30928. 'florin': 500,
  30929. 'section': 500,
  30930. 'currency': 500,
  30931. 'quotesingle': 278,
  30932. 'quotedblleft': 500,
  30933. 'guillemotleft': 500,
  30934. 'guilsinglleft': 333,
  30935. 'guilsinglright': 333,
  30936. 'fi': 556,
  30937. 'fl': 556,
  30938. 'endash': 500,
  30939. 'dagger': 500,
  30940. 'daggerdbl': 500,
  30941. 'periodcentered': 250,
  30942. 'paragraph': 500,
  30943. 'bullet': 350,
  30944. 'quotesinglbase': 333,
  30945. 'quotedblbase': 500,
  30946. 'quotedblright': 500,
  30947. 'guillemotright': 500,
  30948. 'ellipsis': 1000,
  30949. 'perthousand': 1000,
  30950. 'questiondown': 500,
  30951. 'grave': 333,
  30952. 'acute': 333,
  30953. 'circumflex': 333,
  30954. 'tilde': 333,
  30955. 'macron': 333,
  30956. 'breve': 333,
  30957. 'dotaccent': 333,
  30958. 'dieresis': 333,
  30959. 'ring': 333,
  30960. 'cedilla': 333,
  30961. 'hungarumlaut': 333,
  30962. 'ogonek': 333,
  30963. 'caron': 333,
  30964. 'emdash': 1000,
  30965. 'AE': 944,
  30966. 'ordfeminine': 266,
  30967. 'Lslash': 611,
  30968. 'Oslash': 722,
  30969. 'OE': 944,
  30970. 'ordmasculine': 300,
  30971. 'ae': 722,
  30972. 'dotlessi': 278,
  30973. 'lslash': 278,
  30974. 'oslash': 500,
  30975. 'oe': 722,
  30976. 'germandbls': 500,
  30977. 'Idieresis': 389,
  30978. 'eacute': 444,
  30979. 'abreve': 500,
  30980. 'uhungarumlaut': 556,
  30981. 'ecaron': 444,
  30982. 'Ydieresis': 611,
  30983. 'divide': 570,
  30984. 'Yacute': 611,
  30985. 'Acircumflex': 667,
  30986. 'aacute': 500,
  30987. 'Ucircumflex': 722,
  30988. 'yacute': 444,
  30989. 'scommaaccent': 389,
  30990. 'ecircumflex': 444,
  30991. 'Uring': 722,
  30992. 'Udieresis': 722,
  30993. 'aogonek': 500,
  30994. 'Uacute': 722,
  30995. 'uogonek': 556,
  30996. 'Edieresis': 667,
  30997. 'Dcroat': 722,
  30998. 'commaaccent': 250,
  30999. 'copyright': 747,
  31000. 'Emacron': 667,
  31001. 'ccaron': 444,
  31002. 'aring': 500,
  31003. 'Ncommaaccent': 722,
  31004. 'lacute': 278,
  31005. 'agrave': 500,
  31006. 'Tcommaaccent': 611,
  31007. 'Cacute': 667,
  31008. 'atilde': 500,
  31009. 'Edotaccent': 667,
  31010. 'scaron': 389,
  31011. 'scedilla': 389,
  31012. 'iacute': 278,
  31013. 'lozenge': 494,
  31014. 'Rcaron': 667,
  31015. 'Gcommaaccent': 722,
  31016. 'ucircumflex': 556,
  31017. 'acircumflex': 500,
  31018. 'Amacron': 667,
  31019. 'rcaron': 389,
  31020. 'ccedilla': 444,
  31021. 'Zdotaccent': 611,
  31022. 'Thorn': 611,
  31023. 'Omacron': 722,
  31024. 'Racute': 667,
  31025. 'Sacute': 556,
  31026. 'dcaron': 608,
  31027. 'Umacron': 722,
  31028. 'uring': 556,
  31029. 'threesuperior': 300,
  31030. 'Ograve': 722,
  31031. 'Agrave': 667,
  31032. 'Abreve': 667,
  31033. 'multiply': 570,
  31034. 'uacute': 556,
  31035. 'Tcaron': 611,
  31036. 'partialdiff': 494,
  31037. 'ydieresis': 444,
  31038. 'Nacute': 722,
  31039. 'icircumflex': 278,
  31040. 'Ecircumflex': 667,
  31041. 'adieresis': 500,
  31042. 'edieresis': 444,
  31043. 'cacute': 444,
  31044. 'nacute': 556,
  31045. 'umacron': 556,
  31046. 'Ncaron': 722,
  31047. 'Iacute': 389,
  31048. 'plusminus': 570,
  31049. 'brokenbar': 220,
  31050. 'registered': 747,
  31051. 'Gbreve': 722,
  31052. 'Idotaccent': 389,
  31053. 'summation': 600,
  31054. 'Egrave': 667,
  31055. 'racute': 389,
  31056. 'omacron': 500,
  31057. 'Zacute': 611,
  31058. 'Zcaron': 611,
  31059. 'greaterequal': 549,
  31060. 'Eth': 722,
  31061. 'Ccedilla': 667,
  31062. 'lcommaaccent': 278,
  31063. 'tcaron': 366,
  31064. 'eogonek': 444,
  31065. 'Uogonek': 722,
  31066. 'Aacute': 667,
  31067. 'Adieresis': 667,
  31068. 'egrave': 444,
  31069. 'zacute': 389,
  31070. 'iogonek': 278,
  31071. 'Oacute': 722,
  31072. 'oacute': 500,
  31073. 'amacron': 500,
  31074. 'sacute': 389,
  31075. 'idieresis': 278,
  31076. 'Ocircumflex': 722,
  31077. 'Ugrave': 722,
  31078. 'Delta': 612,
  31079. 'thorn': 500,
  31080. 'twosuperior': 300,
  31081. 'Odieresis': 722,
  31082. 'mu': 576,
  31083. 'igrave': 278,
  31084. 'ohungarumlaut': 500,
  31085. 'Eogonek': 667,
  31086. 'dcroat': 500,
  31087. 'threequarters': 750,
  31088. 'Scedilla': 556,
  31089. 'lcaron': 382,
  31090. 'Kcommaaccent': 667,
  31091. 'Lacute': 611,
  31092. 'trademark': 1000,
  31093. 'edotaccent': 444,
  31094. 'Igrave': 389,
  31095. 'Imacron': 389,
  31096. 'Lcaron': 611,
  31097. 'onehalf': 750,
  31098. 'lessequal': 549,
  31099. 'ocircumflex': 500,
  31100. 'ntilde': 556,
  31101. 'Uhungarumlaut': 722,
  31102. 'Eacute': 667,
  31103. 'emacron': 444,
  31104. 'gbreve': 500,
  31105. 'onequarter': 750,
  31106. 'Scaron': 556,
  31107. 'Scommaaccent': 556,
  31108. 'Ohungarumlaut': 722,
  31109. 'degree': 400,
  31110. 'ograve': 500,
  31111. 'Ccaron': 667,
  31112. 'ugrave': 556,
  31113. 'radical': 549,
  31114. 'Dcaron': 722,
  31115. 'rcommaaccent': 389,
  31116. 'Ntilde': 722,
  31117. 'otilde': 500,
  31118. 'Rcommaaccent': 667,
  31119. 'Lcommaaccent': 611,
  31120. 'Atilde': 667,
  31121. 'Aogonek': 667,
  31122. 'Aring': 667,
  31123. 'Otilde': 722,
  31124. 'zdotaccent': 389,
  31125. 'Ecaron': 667,
  31126. 'Iogonek': 389,
  31127. 'kcommaaccent': 500,
  31128. 'minus': 606,
  31129. 'Icircumflex': 389,
  31130. 'ncaron': 556,
  31131. 'tcommaaccent': 278,
  31132. 'logicalnot': 606,
  31133. 'odieresis': 500,
  31134. 'udieresis': 556,
  31135. 'notequal': 549,
  31136. 'gcommaaccent': 500,
  31137. 'eth': 500,
  31138. 'zcaron': 389,
  31139. 'ncommaaccent': 556,
  31140. 'onesuperior': 300,
  31141. 'imacron': 278,
  31142. 'Euro': 500
  31143. },
  31144. 'Times-Italic': {
  31145. 'space': 250,
  31146. 'exclam': 333,
  31147. 'quotedbl': 420,
  31148. 'numbersign': 500,
  31149. 'dollar': 500,
  31150. 'percent': 833,
  31151. 'ampersand': 778,
  31152. 'quoteright': 333,
  31153. 'parenleft': 333,
  31154. 'parenright': 333,
  31155. 'asterisk': 500,
  31156. 'plus': 675,
  31157. 'comma': 250,
  31158. 'hyphen': 333,
  31159. 'period': 250,
  31160. 'slash': 278,
  31161. 'zero': 500,
  31162. 'one': 500,
  31163. 'two': 500,
  31164. 'three': 500,
  31165. 'four': 500,
  31166. 'five': 500,
  31167. 'six': 500,
  31168. 'seven': 500,
  31169. 'eight': 500,
  31170. 'nine': 500,
  31171. 'colon': 333,
  31172. 'semicolon': 333,
  31173. 'less': 675,
  31174. 'equal': 675,
  31175. 'greater': 675,
  31176. 'question': 500,
  31177. 'at': 920,
  31178. 'A': 611,
  31179. 'B': 611,
  31180. 'C': 667,
  31181. 'D': 722,
  31182. 'E': 611,
  31183. 'F': 611,
  31184. 'G': 722,
  31185. 'H': 722,
  31186. 'I': 333,
  31187. 'J': 444,
  31188. 'K': 667,
  31189. 'L': 556,
  31190. 'M': 833,
  31191. 'N': 667,
  31192. 'O': 722,
  31193. 'P': 611,
  31194. 'Q': 722,
  31195. 'R': 611,
  31196. 'S': 500,
  31197. 'T': 556,
  31198. 'U': 722,
  31199. 'V': 611,
  31200. 'W': 833,
  31201. 'X': 611,
  31202. 'Y': 556,
  31203. 'Z': 556,
  31204. 'bracketleft': 389,
  31205. 'backslash': 278,
  31206. 'bracketright': 389,
  31207. 'asciicircum': 422,
  31208. 'underscore': 500,
  31209. 'quoteleft': 333,
  31210. 'a': 500,
  31211. 'b': 500,
  31212. 'c': 444,
  31213. 'd': 500,
  31214. 'e': 444,
  31215. 'f': 278,
  31216. 'g': 500,
  31217. 'h': 500,
  31218. 'i': 278,
  31219. 'j': 278,
  31220. 'k': 444,
  31221. 'l': 278,
  31222. 'm': 722,
  31223. 'n': 500,
  31224. 'o': 500,
  31225. 'p': 500,
  31226. 'q': 500,
  31227. 'r': 389,
  31228. 's': 389,
  31229. 't': 278,
  31230. 'u': 500,
  31231. 'v': 444,
  31232. 'w': 667,
  31233. 'x': 444,
  31234. 'y': 444,
  31235. 'z': 389,
  31236. 'braceleft': 400,
  31237. 'bar': 275,
  31238. 'braceright': 400,
  31239. 'asciitilde': 541,
  31240. 'exclamdown': 389,
  31241. 'cent': 500,
  31242. 'sterling': 500,
  31243. 'fraction': 167,
  31244. 'yen': 500,
  31245. 'florin': 500,
  31246. 'section': 500,
  31247. 'currency': 500,
  31248. 'quotesingle': 214,
  31249. 'quotedblleft': 556,
  31250. 'guillemotleft': 500,
  31251. 'guilsinglleft': 333,
  31252. 'guilsinglright': 333,
  31253. 'fi': 500,
  31254. 'fl': 500,
  31255. 'endash': 500,
  31256. 'dagger': 500,
  31257. 'daggerdbl': 500,
  31258. 'periodcentered': 250,
  31259. 'paragraph': 523,
  31260. 'bullet': 350,
  31261. 'quotesinglbase': 333,
  31262. 'quotedblbase': 556,
  31263. 'quotedblright': 556,
  31264. 'guillemotright': 500,
  31265. 'ellipsis': 889,
  31266. 'perthousand': 1000,
  31267. 'questiondown': 500,
  31268. 'grave': 333,
  31269. 'acute': 333,
  31270. 'circumflex': 333,
  31271. 'tilde': 333,
  31272. 'macron': 333,
  31273. 'breve': 333,
  31274. 'dotaccent': 333,
  31275. 'dieresis': 333,
  31276. 'ring': 333,
  31277. 'cedilla': 333,
  31278. 'hungarumlaut': 333,
  31279. 'ogonek': 333,
  31280. 'caron': 333,
  31281. 'emdash': 889,
  31282. 'AE': 889,
  31283. 'ordfeminine': 276,
  31284. 'Lslash': 556,
  31285. 'Oslash': 722,
  31286. 'OE': 944,
  31287. 'ordmasculine': 310,
  31288. 'ae': 667,
  31289. 'dotlessi': 278,
  31290. 'lslash': 278,
  31291. 'oslash': 500,
  31292. 'oe': 667,
  31293. 'germandbls': 500,
  31294. 'Idieresis': 333,
  31295. 'eacute': 444,
  31296. 'abreve': 500,
  31297. 'uhungarumlaut': 500,
  31298. 'ecaron': 444,
  31299. 'Ydieresis': 556,
  31300. 'divide': 675,
  31301. 'Yacute': 556,
  31302. 'Acircumflex': 611,
  31303. 'aacute': 500,
  31304. 'Ucircumflex': 722,
  31305. 'yacute': 444,
  31306. 'scommaaccent': 389,
  31307. 'ecircumflex': 444,
  31308. 'Uring': 722,
  31309. 'Udieresis': 722,
  31310. 'aogonek': 500,
  31311. 'Uacute': 722,
  31312. 'uogonek': 500,
  31313. 'Edieresis': 611,
  31314. 'Dcroat': 722,
  31315. 'commaaccent': 250,
  31316. 'copyright': 760,
  31317. 'Emacron': 611,
  31318. 'ccaron': 444,
  31319. 'aring': 500,
  31320. 'Ncommaaccent': 667,
  31321. 'lacute': 278,
  31322. 'agrave': 500,
  31323. 'Tcommaaccent': 556,
  31324. 'Cacute': 667,
  31325. 'atilde': 500,
  31326. 'Edotaccent': 611,
  31327. 'scaron': 389,
  31328. 'scedilla': 389,
  31329. 'iacute': 278,
  31330. 'lozenge': 471,
  31331. 'Rcaron': 611,
  31332. 'Gcommaaccent': 722,
  31333. 'ucircumflex': 500,
  31334. 'acircumflex': 500,
  31335. 'Amacron': 611,
  31336. 'rcaron': 389,
  31337. 'ccedilla': 444,
  31338. 'Zdotaccent': 556,
  31339. 'Thorn': 611,
  31340. 'Omacron': 722,
  31341. 'Racute': 611,
  31342. 'Sacute': 500,
  31343. 'dcaron': 544,
  31344. 'Umacron': 722,
  31345. 'uring': 500,
  31346. 'threesuperior': 300,
  31347. 'Ograve': 722,
  31348. 'Agrave': 611,
  31349. 'Abreve': 611,
  31350. 'multiply': 675,
  31351. 'uacute': 500,
  31352. 'Tcaron': 556,
  31353. 'partialdiff': 476,
  31354. 'ydieresis': 444,
  31355. 'Nacute': 667,
  31356. 'icircumflex': 278,
  31357. 'Ecircumflex': 611,
  31358. 'adieresis': 500,
  31359. 'edieresis': 444,
  31360. 'cacute': 444,
  31361. 'nacute': 500,
  31362. 'umacron': 500,
  31363. 'Ncaron': 667,
  31364. 'Iacute': 333,
  31365. 'plusminus': 675,
  31366. 'brokenbar': 275,
  31367. 'registered': 760,
  31368. 'Gbreve': 722,
  31369. 'Idotaccent': 333,
  31370. 'summation': 600,
  31371. 'Egrave': 611,
  31372. 'racute': 389,
  31373. 'omacron': 500,
  31374. 'Zacute': 556,
  31375. 'Zcaron': 556,
  31376. 'greaterequal': 549,
  31377. 'Eth': 722,
  31378. 'Ccedilla': 667,
  31379. 'lcommaaccent': 278,
  31380. 'tcaron': 300,
  31381. 'eogonek': 444,
  31382. 'Uogonek': 722,
  31383. 'Aacute': 611,
  31384. 'Adieresis': 611,
  31385. 'egrave': 444,
  31386. 'zacute': 389,
  31387. 'iogonek': 278,
  31388. 'Oacute': 722,
  31389. 'oacute': 500,
  31390. 'amacron': 500,
  31391. 'sacute': 389,
  31392. 'idieresis': 278,
  31393. 'Ocircumflex': 722,
  31394. 'Ugrave': 722,
  31395. 'Delta': 612,
  31396. 'thorn': 500,
  31397. 'twosuperior': 300,
  31398. 'Odieresis': 722,
  31399. 'mu': 500,
  31400. 'igrave': 278,
  31401. 'ohungarumlaut': 500,
  31402. 'Eogonek': 611,
  31403. 'dcroat': 500,
  31404. 'threequarters': 750,
  31405. 'Scedilla': 500,
  31406. 'lcaron': 300,
  31407. 'Kcommaaccent': 667,
  31408. 'Lacute': 556,
  31409. 'trademark': 980,
  31410. 'edotaccent': 444,
  31411. 'Igrave': 333,
  31412. 'Imacron': 333,
  31413. 'Lcaron': 611,
  31414. 'onehalf': 750,
  31415. 'lessequal': 549,
  31416. 'ocircumflex': 500,
  31417. 'ntilde': 500,
  31418. 'Uhungarumlaut': 722,
  31419. 'Eacute': 611,
  31420. 'emacron': 444,
  31421. 'gbreve': 500,
  31422. 'onequarter': 750,
  31423. 'Scaron': 500,
  31424. 'Scommaaccent': 500,
  31425. 'Ohungarumlaut': 722,
  31426. 'degree': 400,
  31427. 'ograve': 500,
  31428. 'Ccaron': 667,
  31429. 'ugrave': 500,
  31430. 'radical': 453,
  31431. 'Dcaron': 722,
  31432. 'rcommaaccent': 389,
  31433. 'Ntilde': 667,
  31434. 'otilde': 500,
  31435. 'Rcommaaccent': 611,
  31436. 'Lcommaaccent': 556,
  31437. 'Atilde': 611,
  31438. 'Aogonek': 611,
  31439. 'Aring': 611,
  31440. 'Otilde': 722,
  31441. 'zdotaccent': 389,
  31442. 'Ecaron': 611,
  31443. 'Iogonek': 333,
  31444. 'kcommaaccent': 444,
  31445. 'minus': 675,
  31446. 'Icircumflex': 333,
  31447. 'ncaron': 500,
  31448. 'tcommaaccent': 278,
  31449. 'logicalnot': 675,
  31450. 'odieresis': 500,
  31451. 'udieresis': 500,
  31452. 'notequal': 549,
  31453. 'gcommaaccent': 500,
  31454. 'eth': 500,
  31455. 'zcaron': 389,
  31456. 'ncommaaccent': 500,
  31457. 'onesuperior': 300,
  31458. 'imacron': 278,
  31459. 'Euro': 500
  31460. },
  31461. 'ZapfDingbats': {
  31462. 'space': 278,
  31463. 'a1': 974,
  31464. 'a2': 961,
  31465. 'a202': 974,
  31466. 'a3': 980,
  31467. 'a4': 719,
  31468. 'a5': 789,
  31469. 'a119': 790,
  31470. 'a118': 791,
  31471. 'a117': 690,
  31472. 'a11': 960,
  31473. 'a12': 939,
  31474. 'a13': 549,
  31475. 'a14': 855,
  31476. 'a15': 911,
  31477. 'a16': 933,
  31478. 'a105': 911,
  31479. 'a17': 945,
  31480. 'a18': 974,
  31481. 'a19': 755,
  31482. 'a20': 846,
  31483. 'a21': 762,
  31484. 'a22': 761,
  31485. 'a23': 571,
  31486. 'a24': 677,
  31487. 'a25': 763,
  31488. 'a26': 760,
  31489. 'a27': 759,
  31490. 'a28': 754,
  31491. 'a6': 494,
  31492. 'a7': 552,
  31493. 'a8': 537,
  31494. 'a9': 577,
  31495. 'a10': 692,
  31496. 'a29': 786,
  31497. 'a30': 788,
  31498. 'a31': 788,
  31499. 'a32': 790,
  31500. 'a33': 793,
  31501. 'a34': 794,
  31502. 'a35': 816,
  31503. 'a36': 823,
  31504. 'a37': 789,
  31505. 'a38': 841,
  31506. 'a39': 823,
  31507. 'a40': 833,
  31508. 'a41': 816,
  31509. 'a42': 831,
  31510. 'a43': 923,
  31511. 'a44': 744,
  31512. 'a45': 723,
  31513. 'a46': 749,
  31514. 'a47': 790,
  31515. 'a48': 792,
  31516. 'a49': 695,
  31517. 'a50': 776,
  31518. 'a51': 768,
  31519. 'a52': 792,
  31520. 'a53': 759,
  31521. 'a54': 707,
  31522. 'a55': 708,
  31523. 'a56': 682,
  31524. 'a57': 701,
  31525. 'a58': 826,
  31526. 'a59': 815,
  31527. 'a60': 789,
  31528. 'a61': 789,
  31529. 'a62': 707,
  31530. 'a63': 687,
  31531. 'a64': 696,
  31532. 'a65': 689,
  31533. 'a66': 786,
  31534. 'a67': 787,
  31535. 'a68': 713,
  31536. 'a69': 791,
  31537. 'a70': 785,
  31538. 'a71': 791,
  31539. 'a72': 873,
  31540. 'a73': 761,
  31541. 'a74': 762,
  31542. 'a203': 762,
  31543. 'a75': 759,
  31544. 'a204': 759,
  31545. 'a76': 892,
  31546. 'a77': 892,
  31547. 'a78': 788,
  31548. 'a79': 784,
  31549. 'a81': 438,
  31550. 'a82': 138,
  31551. 'a83': 277,
  31552. 'a84': 415,
  31553. 'a97': 392,
  31554. 'a98': 392,
  31555. 'a99': 668,
  31556. 'a100': 668,
  31557. 'a89': 390,
  31558. 'a90': 390,
  31559. 'a93': 317,
  31560. 'a94': 317,
  31561. 'a91': 276,
  31562. 'a92': 276,
  31563. 'a205': 509,
  31564. 'a85': 509,
  31565. 'a206': 410,
  31566. 'a86': 410,
  31567. 'a87': 234,
  31568. 'a88': 234,
  31569. 'a95': 334,
  31570. 'a96': 334,
  31571. 'a101': 732,
  31572. 'a102': 544,
  31573. 'a103': 544,
  31574. 'a104': 910,
  31575. 'a106': 667,
  31576. 'a107': 760,
  31577. 'a108': 760,
  31578. 'a112': 776,
  31579. 'a111': 595,
  31580. 'a110': 694,
  31581. 'a109': 626,
  31582. 'a120': 788,
  31583. 'a121': 788,
  31584. 'a122': 788,
  31585. 'a123': 788,
  31586. 'a124': 788,
  31587. 'a125': 788,
  31588. 'a126': 788,
  31589. 'a127': 788,
  31590. 'a128': 788,
  31591. 'a129': 788,
  31592. 'a130': 788,
  31593. 'a131': 788,
  31594. 'a132': 788,
  31595. 'a133': 788,
  31596. 'a134': 788,
  31597. 'a135': 788,
  31598. 'a136': 788,
  31599. 'a137': 788,
  31600. 'a138': 788,
  31601. 'a139': 788,
  31602. 'a140': 788,
  31603. 'a141': 788,
  31604. 'a142': 788,
  31605. 'a143': 788,
  31606. 'a144': 788,
  31607. 'a145': 788,
  31608. 'a146': 788,
  31609. 'a147': 788,
  31610. 'a148': 788,
  31611. 'a149': 788,
  31612. 'a150': 788,
  31613. 'a151': 788,
  31614. 'a152': 788,
  31615. 'a153': 788,
  31616. 'a154': 788,
  31617. 'a155': 788,
  31618. 'a156': 788,
  31619. 'a157': 788,
  31620. 'a158': 788,
  31621. 'a159': 788,
  31622. 'a160': 894,
  31623. 'a161': 838,
  31624. 'a163': 1016,
  31625. 'a164': 458,
  31626. 'a196': 748,
  31627. 'a165': 924,
  31628. 'a192': 748,
  31629. 'a166': 918,
  31630. 'a167': 927,
  31631. 'a168': 928,
  31632. 'a169': 928,
  31633. 'a170': 834,
  31634. 'a171': 873,
  31635. 'a172': 828,
  31636. 'a173': 924,
  31637. 'a162': 924,
  31638. 'a174': 917,
  31639. 'a175': 930,
  31640. 'a176': 931,
  31641. 'a177': 463,
  31642. 'a178': 883,
  31643. 'a179': 836,
  31644. 'a193': 836,
  31645. 'a180': 867,
  31646. 'a199': 867,
  31647. 'a181': 696,
  31648. 'a200': 696,
  31649. 'a182': 874,
  31650. 'a201': 874,
  31651. 'a183': 760,
  31652. 'a184': 946,
  31653. 'a197': 771,
  31654. 'a185': 865,
  31655. 'a194': 771,
  31656. 'a198': 888,
  31657. 'a186': 967,
  31658. 'a195': 888,
  31659. 'a187': 831,
  31660. 'a188': 873,
  31661. 'a189': 927,
  31662. 'a190': 970,
  31663. 'a191': 918
  31664. }
  31665. };
  31666. var EOF = {};
  31667. function isEOF(v) {
  31668. return (v === EOF);
  31669. }
  31670. var Parser = (function ParserClosure() {
  31671. function Parser(lexer, allowStreams, xref) {
  31672. this.lexer = lexer;
  31673. this.allowStreams = allowStreams;
  31674. this.xref = xref;
  31675. this.imageCache = {
  31676. length: 0,
  31677. adler32: 0,
  31678. stream: null
  31679. };
  31680. this.refill();
  31681. }
  31682. Parser.prototype = {
  31683. refill: function Parser_refill() {
  31684. this.buf1 = this.lexer.getObj();
  31685. this.buf2 = this.lexer.getObj();
  31686. },
  31687. shift: function Parser_shift() {
  31688. if (isCmd(this.buf2, 'ID')) {
  31689. this.buf1 = this.buf2;
  31690. this.buf2 = null;
  31691. } else {
  31692. this.buf1 = this.buf2;
  31693. this.buf2 = this.lexer.getObj();
  31694. }
  31695. },
  31696. getObj: function Parser_getObj(cipherTransform) {
  31697. var buf1 = this.buf1;
  31698. this.shift();
  31699. if (buf1 instanceof Cmd) {
  31700. switch (buf1.cmd) {
  31701. case 'BI': // inline image
  31702. return this.makeInlineImage(cipherTransform);
  31703. case '[': // array
  31704. var array = [];
  31705. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  31706. array.push(this.getObj(cipherTransform));
  31707. }
  31708. if (isEOF(this.buf1)) {
  31709. error('End of file inside array');
  31710. }
  31711. this.shift();
  31712. return array;
  31713. case '<<': // dictionary or stream
  31714. var dict = new Dict(this.xref);
  31715. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  31716. if (!isName(this.buf1)) {
  31717. info('Malformed dictionary: key must be a name object');
  31718. this.shift();
  31719. continue;
  31720. }
  31721. var key = this.buf1.name;
  31722. this.shift();
  31723. if (isEOF(this.buf1)) {
  31724. break;
  31725. }
  31726. dict.set(key, this.getObj(cipherTransform));
  31727. }
  31728. if (isEOF(this.buf1)) {
  31729. error('End of file inside dictionary');
  31730. }
  31731. // Stream objects are not allowed inside content streams or
  31732. // object streams.
  31733. if (isCmd(this.buf2, 'stream')) {
  31734. return (this.allowStreams ?
  31735. this.makeStream(dict, cipherTransform) : dict);
  31736. }
  31737. this.shift();
  31738. return dict;
  31739. default: // simple object
  31740. return buf1;
  31741. }
  31742. }
  31743. if (isInt(buf1)) { // indirect reference or integer
  31744. var num = buf1;
  31745. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  31746. var ref = new Ref(num, this.buf1);
  31747. this.shift();
  31748. this.shift();
  31749. return ref;
  31750. }
  31751. return num;
  31752. }
  31753. if (isString(buf1)) { // string
  31754. var str = buf1;
  31755. if (cipherTransform) {
  31756. str = cipherTransform.decryptString(str);
  31757. }
  31758. return str;
  31759. }
  31760. // simple object
  31761. return buf1;
  31762. },
  31763. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  31764. var lexer = this.lexer;
  31765. var stream = lexer.stream;
  31766. // parse dictionary
  31767. var dict = new Dict(null);
  31768. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  31769. if (!isName(this.buf1)) {
  31770. error('Dictionary key must be a name object');
  31771. }
  31772. var key = this.buf1.name;
  31773. this.shift();
  31774. if (isEOF(this.buf1)) {
  31775. break;
  31776. }
  31777. dict.set(key, this.getObj(cipherTransform));
  31778. }
  31779. // parse image stream
  31780. var startPos = stream.pos;
  31781. // searching for the /EI\s/
  31782. var state = 0, ch, i, ii;
  31783. while (state !== 4 && (ch = stream.getByte()) !== -1) {
  31784. switch (ch | 0) {
  31785. case 0x20:
  31786. case 0x0D:
  31787. case 0x0A:
  31788. // let's check next five bytes to be ASCII... just be sure
  31789. var followingBytes = stream.peekBytes(5);
  31790. for (i = 0, ii = followingBytes.length; i < ii; i++) {
  31791. ch = followingBytes[i];
  31792. if (ch !== 0x0A && ch !== 0x0D && (ch < 0x20 || ch > 0x7F)) {
  31793. // not a LF, CR, SPACE or any visible ASCII character
  31794. state = 0;
  31795. break; // some binary stuff found, resetting the state
  31796. }
  31797. }
  31798. state = (state === 3 ? 4 : 0);
  31799. break;
  31800. case 0x45:
  31801. state = 2;
  31802. break;
  31803. case 0x49:
  31804. state = (state === 2 ? 3 : 0);
  31805. break;
  31806. default:
  31807. state = 0;
  31808. break;
  31809. }
  31810. }
  31811. var length = (stream.pos - 4) - startPos;
  31812. var imageStream = stream.makeSubStream(startPos, length, dict);
  31813. // trying to cache repeat images, first we are trying to "warm up" caching
  31814. // using length, then comparing adler32
  31815. var MAX_LENGTH_TO_CACHE = 1000;
  31816. var cacheImage = false, adler32;
  31817. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  31818. var imageBytes = imageStream.getBytes();
  31819. imageStream.reset();
  31820. var a = 1;
  31821. var b = 0;
  31822. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  31823. a = (a + (imageBytes[i] & 0xff)) % 65521;
  31824. b = (b + a) % 65521;
  31825. }
  31826. adler32 = (b << 16) | a;
  31827. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  31828. this.buf2 = Cmd.get('EI');
  31829. this.shift();
  31830. this.imageCache.stream.reset();
  31831. return this.imageCache.stream;
  31832. }
  31833. cacheImage = true;
  31834. }
  31835. if (!cacheImage && !this.imageCache.stream) {
  31836. this.imageCache.length = length;
  31837. this.imageCache.stream = null;
  31838. }
  31839. if (cipherTransform) {
  31840. imageStream = cipherTransform.createStream(imageStream, length);
  31841. }
  31842. imageStream = this.filter(imageStream, dict, length);
  31843. imageStream.dict = dict;
  31844. if (cacheImage) {
  31845. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  31846. this.imageCache.adler32 = adler32;
  31847. this.imageCache.stream = imageStream;
  31848. }
  31849. this.buf2 = Cmd.get('EI');
  31850. this.shift();
  31851. return imageStream;
  31852. },
  31853. fetchIfRef: function Parser_fetchIfRef(obj) {
  31854. // not relying on the xref.fetchIfRef -- xref might not be set
  31855. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  31856. },
  31857. makeStream: function Parser_makeStream(dict, cipherTransform) {
  31858. var lexer = this.lexer;
  31859. var stream = lexer.stream;
  31860. // get stream start position
  31861. lexer.skipToNextLine();
  31862. var pos = stream.pos - 1;
  31863. // get length
  31864. var length = this.fetchIfRef(dict.get('Length'));
  31865. if (!isInt(length)) {
  31866. info('Bad ' + length + ' attribute in stream');
  31867. length = 0;
  31868. }
  31869. // skip over the stream data
  31870. stream.pos = pos + length;
  31871. lexer.nextChar();
  31872. this.shift(); // '>>'
  31873. this.shift(); // 'stream'
  31874. if (!isCmd(this.buf1, 'endstream')) {
  31875. // bad stream length, scanning for endstream
  31876. stream.pos = pos;
  31877. var SCAN_BLOCK_SIZE = 2048;
  31878. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  31879. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  31880. 0x61, 0x6D];
  31881. var skipped = 0, found = false, i, j;
  31882. while (stream.pos < stream.end) {
  31883. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  31884. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  31885. if (scanLength <= 0) {
  31886. break;
  31887. }
  31888. found = false;
  31889. for (i = 0, j = 0; i < scanLength; i++) {
  31890. var b = scanBytes[i];
  31891. if (b !== ENDSTREAM_SIGNATURE[j]) {
  31892. i -= j;
  31893. j = 0;
  31894. } else {
  31895. j++;
  31896. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  31897. i++;
  31898. found = true;
  31899. break;
  31900. }
  31901. }
  31902. }
  31903. if (found) {
  31904. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  31905. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  31906. break;
  31907. }
  31908. skipped += scanLength;
  31909. stream.pos += scanLength;
  31910. }
  31911. if (!found) {
  31912. error('Missing endstream');
  31913. }
  31914. length = skipped;
  31915. lexer.nextChar();
  31916. this.shift();
  31917. this.shift();
  31918. }
  31919. this.shift(); // 'endstream'
  31920. stream = stream.makeSubStream(pos, length, dict);
  31921. if (cipherTransform) {
  31922. stream = cipherTransform.createStream(stream, length);
  31923. }
  31924. stream = this.filter(stream, dict, length);
  31925. stream.dict = dict;
  31926. return stream;
  31927. },
  31928. filter: function Parser_filter(stream, dict, length) {
  31929. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  31930. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  31931. if (isName(filter)) {
  31932. return this.makeFilter(stream, filter.name, length, params);
  31933. }
  31934. var maybeLength = length;
  31935. if (isArray(filter)) {
  31936. var filterArray = filter;
  31937. var paramsArray = params;
  31938. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  31939. filter = filterArray[i];
  31940. if (!isName(filter)) {
  31941. error('Bad filter name: ' + filter);
  31942. }
  31943. params = null;
  31944. if (isArray(paramsArray) && (i in paramsArray)) {
  31945. params = paramsArray[i];
  31946. }
  31947. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  31948. // after the first stream the length variable is invalid
  31949. maybeLength = null;
  31950. }
  31951. }
  31952. return stream;
  31953. },
  31954. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  31955. if (stream.dict.get('Length') === 0) {
  31956. return new NullStream(stream);
  31957. }
  31958. try {
  31959. var xrefStreamStats = this.xref.stats.streamTypes;
  31960. if (name === 'FlateDecode' || name === 'Fl') {
  31961. xrefStreamStats[StreamType.FLATE] = true;
  31962. if (params) {
  31963. return new PredictorStream(new FlateStream(stream, maybeLength),
  31964. maybeLength, params);
  31965. }
  31966. return new FlateStream(stream, maybeLength);
  31967. }
  31968. if (name === 'LZWDecode' || name === 'LZW') {
  31969. xrefStreamStats[StreamType.LZW] = true;
  31970. var earlyChange = 1;
  31971. if (params) {
  31972. if (params.has('EarlyChange')) {
  31973. earlyChange = params.get('EarlyChange');
  31974. }
  31975. return new PredictorStream(
  31976. new LZWStream(stream, maybeLength, earlyChange),
  31977. maybeLength, params);
  31978. }
  31979. return new LZWStream(stream, maybeLength, earlyChange);
  31980. }
  31981. if (name === 'DCTDecode' || name === 'DCT') {
  31982. xrefStreamStats[StreamType.DCT] = true;
  31983. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  31984. }
  31985. if (name === 'JPXDecode' || name === 'JPX') {
  31986. xrefStreamStats[StreamType.JPX] = true;
  31987. return new JpxStream(stream, maybeLength, stream.dict);
  31988. }
  31989. if (name === 'ASCII85Decode' || name === 'A85') {
  31990. xrefStreamStats[StreamType.A85] = true;
  31991. return new Ascii85Stream(stream, maybeLength);
  31992. }
  31993. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  31994. xrefStreamStats[StreamType.AHX] = true;
  31995. return new AsciiHexStream(stream, maybeLength);
  31996. }
  31997. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  31998. xrefStreamStats[StreamType.CCF] = true;
  31999. return new CCITTFaxStream(stream, maybeLength, params);
  32000. }
  32001. if (name === 'RunLengthDecode' || name === 'RL') {
  32002. xrefStreamStats[StreamType.RL] = true;
  32003. return new RunLengthStream(stream, maybeLength);
  32004. }
  32005. if (name === 'JBIG2Decode') {
  32006. xrefStreamStats[StreamType.JBIG] = true;
  32007. return new Jbig2Stream(stream, maybeLength, stream.dict);
  32008. }
  32009. warn('filter "' + name + '" not supported yet');
  32010. return stream;
  32011. } catch (ex) {
  32012. if (ex instanceof MissingDataException) {
  32013. throw ex;
  32014. }
  32015. warn('Invalid stream: \"' + ex + '\"');
  32016. return new NullStream(stream);
  32017. }
  32018. }
  32019. };
  32020. return Parser;
  32021. })();
  32022. var Lexer = (function LexerClosure() {
  32023. function Lexer(stream, knownCommands) {
  32024. this.stream = stream;
  32025. this.nextChar();
  32026. // While lexing, we build up many strings one char at a time. Using += for
  32027. // this can result in lots of garbage strings. It's better to build an
  32028. // array of single-char strings and then join() them together at the end.
  32029. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  32030. // purpose uses less memory than using a new array for each string.
  32031. this.strBuf = [];
  32032. // The PDFs might have "glued" commands with other commands, operands or
  32033. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  32034. // commands and their prefixes. The prefixes are built the following way:
  32035. // if there a command that is a prefix of the other valid command or
  32036. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  32037. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  32038. // other commands or literals as a prefix. The knowCommands is optional.
  32039. this.knownCommands = knownCommands;
  32040. }
  32041. Lexer.isSpace = function Lexer_isSpace(ch) {
  32042. // Space is one of the following characters: SPACE, TAB, CR or LF.
  32043. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  32044. };
  32045. // A '1' in this array means the character is white space. A '1' or
  32046. // '2' means the character ends a name or command.
  32047. var specialChars = [
  32048. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  32049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  32050. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  32051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  32052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  32053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  32054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  32055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  32056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  32057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  32058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  32059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  32060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  32061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  32062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  32063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  32064. ];
  32065. function toHexDigit(ch) {
  32066. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  32067. return ch & 0x0F;
  32068. }
  32069. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  32070. // 'A'-'F', 'a'-'f'
  32071. return (ch & 0x0F) + 9;
  32072. }
  32073. return -1;
  32074. }
  32075. Lexer.prototype = {
  32076. nextChar: function Lexer_nextChar() {
  32077. return (this.currentChar = this.stream.getByte());
  32078. },
  32079. peekChar: function Lexer_peekChar() {
  32080. return this.stream.peekBytes(1)[0];
  32081. },
  32082. getNumber: function Lexer_getNumber() {
  32083. var ch = this.currentChar;
  32084. var eNotation = false;
  32085. var divideBy = 0; // different from 0 if it's a floating point value
  32086. var sign = 1;
  32087. if (ch === 0x2D) { // '-'
  32088. sign = -1;
  32089. ch = this.nextChar();
  32090. } else if (ch === 0x2B) { // '+'
  32091. ch = this.nextChar();
  32092. }
  32093. if (ch === 0x2E) { // '.'
  32094. divideBy = 10;
  32095. ch = this.nextChar();
  32096. }
  32097. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  32098. error('Invalid number: ' + String.fromCharCode(ch));
  32099. return 0;
  32100. }
  32101. var baseValue = ch - 0x30; // '0'
  32102. var powerValue = 0;
  32103. var powerValueSign = 1;
  32104. while ((ch = this.nextChar()) >= 0) {
  32105. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  32106. var currentDigit = ch - 0x30; // '0'
  32107. if (eNotation) { // We are after an 'e' or 'E'
  32108. powerValue = powerValue * 10 + currentDigit;
  32109. } else {
  32110. if (divideBy !== 0) { // We are after a point
  32111. divideBy *= 10;
  32112. }
  32113. baseValue = baseValue * 10 + currentDigit;
  32114. }
  32115. } else if (ch === 0x2E) { // '.'
  32116. if (divideBy === 0) {
  32117. divideBy = 1;
  32118. } else {
  32119. // A number can have only one '.'
  32120. break;
  32121. }
  32122. } else if (ch === 0x2D) { // '-'
  32123. // ignore minus signs in the middle of numbers to match
  32124. // Adobe's behavior
  32125. warn('Badly formated number');
  32126. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  32127. // 'E' can be either a scientific notation or the beginning of a new
  32128. // operator
  32129. ch = this.peekChar();
  32130. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  32131. powerValueSign = (ch === 0x2D) ? -1 : 1;
  32132. this.nextChar(); // Consume the sign character
  32133. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  32134. // The 'E' must be the beginning of a new operator
  32135. break;
  32136. }
  32137. eNotation = true;
  32138. } else {
  32139. // the last character doesn't belong to us
  32140. break;
  32141. }
  32142. }
  32143. if (divideBy !== 0) {
  32144. baseValue /= divideBy;
  32145. }
  32146. if (eNotation) {
  32147. baseValue *= Math.pow(10, powerValueSign * powerValue);
  32148. }
  32149. return sign * baseValue;
  32150. },
  32151. getString: function Lexer_getString() {
  32152. var numParen = 1;
  32153. var done = false;
  32154. var strBuf = this.strBuf;
  32155. strBuf.length = 0;
  32156. var ch = this.nextChar();
  32157. while (true) {
  32158. var charBuffered = false;
  32159. switch (ch | 0) {
  32160. case -1:
  32161. warn('Unterminated string');
  32162. done = true;
  32163. break;
  32164. case 0x28: // '('
  32165. ++numParen;
  32166. strBuf.push('(');
  32167. break;
  32168. case 0x29: // ')'
  32169. if (--numParen === 0) {
  32170. this.nextChar(); // consume strings ')'
  32171. done = true;
  32172. } else {
  32173. strBuf.push(')');
  32174. }
  32175. break;
  32176. case 0x5C: // '\\'
  32177. ch = this.nextChar();
  32178. switch (ch) {
  32179. case -1:
  32180. warn('Unterminated string');
  32181. done = true;
  32182. break;
  32183. case 0x6E: // 'n'
  32184. strBuf.push('\n');
  32185. break;
  32186. case 0x72: // 'r'
  32187. strBuf.push('\r');
  32188. break;
  32189. case 0x74: // 't'
  32190. strBuf.push('\t');
  32191. break;
  32192. case 0x62: // 'b'
  32193. strBuf.push('\b');
  32194. break;
  32195. case 0x66: // 'f'
  32196. strBuf.push('\f');
  32197. break;
  32198. case 0x5C: // '\'
  32199. case 0x28: // '('
  32200. case 0x29: // ')'
  32201. strBuf.push(String.fromCharCode(ch));
  32202. break;
  32203. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  32204. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  32205. var x = ch & 0x0F;
  32206. ch = this.nextChar();
  32207. charBuffered = true;
  32208. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  32209. x = (x << 3) + (ch & 0x0F);
  32210. ch = this.nextChar();
  32211. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  32212. charBuffered = false;
  32213. x = (x << 3) + (ch & 0x0F);
  32214. }
  32215. }
  32216. strBuf.push(String.fromCharCode(x));
  32217. break;
  32218. case 0x0D: // CR
  32219. if (this.peekChar() === 0x0A) { // LF
  32220. this.nextChar();
  32221. }
  32222. break;
  32223. case 0x0A: // LF
  32224. break;
  32225. default:
  32226. strBuf.push(String.fromCharCode(ch));
  32227. break;
  32228. }
  32229. break;
  32230. default:
  32231. strBuf.push(String.fromCharCode(ch));
  32232. break;
  32233. }
  32234. if (done) {
  32235. break;
  32236. }
  32237. if (!charBuffered) {
  32238. ch = this.nextChar();
  32239. }
  32240. }
  32241. return strBuf.join('');
  32242. },
  32243. getName: function Lexer_getName() {
  32244. var ch;
  32245. var strBuf = this.strBuf;
  32246. strBuf.length = 0;
  32247. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  32248. if (ch === 0x23) { // '#'
  32249. ch = this.nextChar();
  32250. var x = toHexDigit(ch);
  32251. if (x !== -1) {
  32252. var x2 = toHexDigit(this.nextChar());
  32253. if (x2 === -1) {
  32254. error('Illegal digit in hex char in name: ' + x2);
  32255. }
  32256. strBuf.push(String.fromCharCode((x << 4) | x2));
  32257. } else {
  32258. strBuf.push('#', String.fromCharCode(ch));
  32259. }
  32260. } else {
  32261. strBuf.push(String.fromCharCode(ch));
  32262. }
  32263. }
  32264. if (strBuf.length > 128) {
  32265. error('Warning: name token is longer than allowed by the spec: ' +
  32266. strBuf.length);
  32267. }
  32268. return Name.get(strBuf.join(''));
  32269. },
  32270. getHexString: function Lexer_getHexString() {
  32271. var strBuf = this.strBuf;
  32272. strBuf.length = 0;
  32273. var ch = this.currentChar;
  32274. var isFirstHex = true;
  32275. var firstDigit;
  32276. var secondDigit;
  32277. while (true) {
  32278. if (ch < 0) {
  32279. warn('Unterminated hex string');
  32280. break;
  32281. } else if (ch === 0x3E) { // '>'
  32282. this.nextChar();
  32283. break;
  32284. } else if (specialChars[ch] === 1) {
  32285. ch = this.nextChar();
  32286. continue;
  32287. } else {
  32288. if (isFirstHex) {
  32289. firstDigit = toHexDigit(ch);
  32290. if (firstDigit === -1) {
  32291. warn('Ignoring invalid character "' + ch + '" in hex string');
  32292. ch = this.nextChar();
  32293. continue;
  32294. }
  32295. } else {
  32296. secondDigit = toHexDigit(ch);
  32297. if (secondDigit === -1) {
  32298. warn('Ignoring invalid character "' + ch + '" in hex string');
  32299. ch = this.nextChar();
  32300. continue;
  32301. }
  32302. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  32303. }
  32304. isFirstHex = !isFirstHex;
  32305. ch = this.nextChar();
  32306. }
  32307. }
  32308. return strBuf.join('');
  32309. },
  32310. getObj: function Lexer_getObj() {
  32311. // skip whitespace and comments
  32312. var comment = false;
  32313. var ch = this.currentChar;
  32314. while (true) {
  32315. if (ch < 0) {
  32316. return EOF;
  32317. }
  32318. if (comment) {
  32319. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  32320. comment = false;
  32321. }
  32322. } else if (ch === 0x25) { // '%'
  32323. comment = true;
  32324. } else if (specialChars[ch] !== 1) {
  32325. break;
  32326. }
  32327. ch = this.nextChar();
  32328. }
  32329. // start reading token
  32330. switch (ch | 0) {
  32331. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  32332. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  32333. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  32334. return this.getNumber();
  32335. case 0x28: // '('
  32336. return this.getString();
  32337. case 0x2F: // '/'
  32338. return this.getName();
  32339. // array punctuation
  32340. case 0x5B: // '['
  32341. this.nextChar();
  32342. return Cmd.get('[');
  32343. case 0x5D: // ']'
  32344. this.nextChar();
  32345. return Cmd.get(']');
  32346. // hex string or dict punctuation
  32347. case 0x3C: // '<'
  32348. ch = this.nextChar();
  32349. if (ch === 0x3C) {
  32350. // dict punctuation
  32351. this.nextChar();
  32352. return Cmd.get('<<');
  32353. }
  32354. return this.getHexString();
  32355. // dict punctuation
  32356. case 0x3E: // '>'
  32357. ch = this.nextChar();
  32358. if (ch === 0x3E) {
  32359. this.nextChar();
  32360. return Cmd.get('>>');
  32361. }
  32362. return Cmd.get('>');
  32363. case 0x7B: // '{'
  32364. this.nextChar();
  32365. return Cmd.get('{');
  32366. case 0x7D: // '}'
  32367. this.nextChar();
  32368. return Cmd.get('}');
  32369. case 0x29: // ')'
  32370. error('Illegal character: ' + ch);
  32371. break;
  32372. }
  32373. // command
  32374. var str = String.fromCharCode(ch);
  32375. var knownCommands = this.knownCommands;
  32376. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  32377. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  32378. // stop if known command is found and next character does not make
  32379. // the str a command
  32380. var possibleCommand = str + String.fromCharCode(ch);
  32381. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  32382. break;
  32383. }
  32384. if (str.length === 128) {
  32385. error('Command token too long: ' + str.length);
  32386. }
  32387. str = possibleCommand;
  32388. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  32389. }
  32390. if (str === 'true') {
  32391. return true;
  32392. }
  32393. if (str === 'false') {
  32394. return false;
  32395. }
  32396. if (str === 'null') {
  32397. return null;
  32398. }
  32399. return Cmd.get(str);
  32400. },
  32401. skipToNextLine: function Lexer_skipToNextLine() {
  32402. var ch = this.currentChar;
  32403. while (ch >= 0) {
  32404. if (ch === 0x0D) { // CR
  32405. ch = this.nextChar();
  32406. if (ch === 0x0A) { // LF
  32407. this.nextChar();
  32408. }
  32409. break;
  32410. } else if (ch === 0x0A) { // LF
  32411. this.nextChar();
  32412. break;
  32413. }
  32414. ch = this.nextChar();
  32415. }
  32416. }
  32417. };
  32418. return Lexer;
  32419. })();
  32420. var Linearization = {
  32421. create: function LinearizationCreate(stream) {
  32422. function getInt(name, allowZeroValue) {
  32423. var obj = linDict.get(name);
  32424. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  32425. return obj;
  32426. }
  32427. throw new Error('The "' + name + '" parameter in the linearization ' +
  32428. 'dictionary is invalid.');
  32429. }
  32430. function getHints() {
  32431. var hints = linDict.get('H'), hintsLength, item;
  32432. if (isArray(hints) &&
  32433. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  32434. for (var index = 0; index < hintsLength; index++) {
  32435. if (!(isInt(item = hints[index]) && item > 0)) {
  32436. throw new Error('Hint (' + index +
  32437. ') in the linearization dictionary is invalid.');
  32438. }
  32439. }
  32440. return hints;
  32441. }
  32442. throw new Error('Hint array in the linearization dictionary is invalid.');
  32443. }
  32444. var parser = new Parser(new Lexer(stream), false, null);
  32445. var obj1 = parser.getObj();
  32446. var obj2 = parser.getObj();
  32447. var obj3 = parser.getObj();
  32448. var linDict = parser.getObj();
  32449. var obj, length;
  32450. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  32451. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  32452. return null; // No valid linearization dictionary found.
  32453. } else if ((length = getInt('L')) !== stream.length) {
  32454. throw new Error('The "L" parameter in the linearization dictionary ' +
  32455. 'does not equal the stream length.');
  32456. }
  32457. return {
  32458. length: length,
  32459. hints: getHints(),
  32460. objectNumberFirst: getInt('O'),
  32461. endFirst: getInt('E'),
  32462. numPages: getInt('N'),
  32463. mainXRefEntriesOffset: getInt('T'),
  32464. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  32465. };
  32466. }
  32467. };
  32468. var PostScriptParser = (function PostScriptParserClosure() {
  32469. function PostScriptParser(lexer) {
  32470. this.lexer = lexer;
  32471. this.operators = [];
  32472. this.token = null;
  32473. this.prev = null;
  32474. }
  32475. PostScriptParser.prototype = {
  32476. nextToken: function PostScriptParser_nextToken() {
  32477. this.prev = this.token;
  32478. this.token = this.lexer.getToken();
  32479. },
  32480. accept: function PostScriptParser_accept(type) {
  32481. if (this.token.type === type) {
  32482. this.nextToken();
  32483. return true;
  32484. }
  32485. return false;
  32486. },
  32487. expect: function PostScriptParser_expect(type) {
  32488. if (this.accept(type)) {
  32489. return true;
  32490. }
  32491. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  32492. type + '.');
  32493. },
  32494. parse: function PostScriptParser_parse() {
  32495. this.nextToken();
  32496. this.expect(PostScriptTokenTypes.LBRACE);
  32497. this.parseBlock();
  32498. this.expect(PostScriptTokenTypes.RBRACE);
  32499. return this.operators;
  32500. },
  32501. parseBlock: function PostScriptParser_parseBlock() {
  32502. while (true) {
  32503. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  32504. this.operators.push(this.prev.value);
  32505. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  32506. this.operators.push(this.prev.value);
  32507. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  32508. this.parseCondition();
  32509. } else {
  32510. return;
  32511. }
  32512. }
  32513. },
  32514. parseCondition: function PostScriptParser_parseCondition() {
  32515. // Add two place holders that will be updated later
  32516. var conditionLocation = this.operators.length;
  32517. this.operators.push(null, null);
  32518. this.parseBlock();
  32519. this.expect(PostScriptTokenTypes.RBRACE);
  32520. if (this.accept(PostScriptTokenTypes.IF)) {
  32521. // The true block is right after the 'if' so it just falls through on
  32522. // true else it jumps and skips the true block.
  32523. this.operators[conditionLocation] = this.operators.length;
  32524. this.operators[conditionLocation + 1] = 'jz';
  32525. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  32526. var jumpLocation = this.operators.length;
  32527. this.operators.push(null, null);
  32528. var endOfTrue = this.operators.length;
  32529. this.parseBlock();
  32530. this.expect(PostScriptTokenTypes.RBRACE);
  32531. this.expect(PostScriptTokenTypes.IFELSE);
  32532. // The jump is added at the end of the true block to skip the false
  32533. // block.
  32534. this.operators[jumpLocation] = this.operators.length;
  32535. this.operators[jumpLocation + 1] = 'j';
  32536. this.operators[conditionLocation] = endOfTrue;
  32537. this.operators[conditionLocation + 1] = 'jz';
  32538. } else {
  32539. error('PS Function: error parsing conditional.');
  32540. }
  32541. }
  32542. };
  32543. return PostScriptParser;
  32544. })();
  32545. var PostScriptTokenTypes = {
  32546. LBRACE: 0,
  32547. RBRACE: 1,
  32548. NUMBER: 2,
  32549. OPERATOR: 3,
  32550. IF: 4,
  32551. IFELSE: 5
  32552. };
  32553. var PostScriptToken = (function PostScriptTokenClosure() {
  32554. function PostScriptToken(type, value) {
  32555. this.type = type;
  32556. this.value = value;
  32557. }
  32558. var opCache = {};
  32559. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  32560. var opValue = opCache[op];
  32561. if (opValue) {
  32562. return opValue;
  32563. }
  32564. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  32565. };
  32566. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  32567. '{');
  32568. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  32569. '}');
  32570. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  32571. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  32572. 'IFELSE');
  32573. return PostScriptToken;
  32574. })();
  32575. var PostScriptLexer = (function PostScriptLexerClosure() {
  32576. function PostScriptLexer(stream) {
  32577. this.stream = stream;
  32578. this.nextChar();
  32579. this.strBuf = [];
  32580. }
  32581. PostScriptLexer.prototype = {
  32582. nextChar: function PostScriptLexer_nextChar() {
  32583. return (this.currentChar = this.stream.getByte());
  32584. },
  32585. getToken: function PostScriptLexer_getToken() {
  32586. var comment = false;
  32587. var ch = this.currentChar;
  32588. // skip comments
  32589. while (true) {
  32590. if (ch < 0) {
  32591. return EOF;
  32592. }
  32593. if (comment) {
  32594. if (ch === 0x0A || ch === 0x0D) {
  32595. comment = false;
  32596. }
  32597. } else if (ch === 0x25) { // '%'
  32598. comment = true;
  32599. } else if (!Lexer.isSpace(ch)) {
  32600. break;
  32601. }
  32602. ch = this.nextChar();
  32603. }
  32604. switch (ch | 0) {
  32605. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  32606. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  32607. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  32608. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  32609. this.getNumber());
  32610. case 0x7B: // '{'
  32611. this.nextChar();
  32612. return PostScriptToken.LBRACE;
  32613. case 0x7D: // '}'
  32614. this.nextChar();
  32615. return PostScriptToken.RBRACE;
  32616. }
  32617. // operator
  32618. var strBuf = this.strBuf;
  32619. strBuf.length = 0;
  32620. strBuf[0] = String.fromCharCode(ch);
  32621. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  32622. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  32623. strBuf.push(String.fromCharCode(ch));
  32624. }
  32625. var str = strBuf.join('');
  32626. switch (str.toLowerCase()) {
  32627. case 'if':
  32628. return PostScriptToken.IF;
  32629. case 'ifelse':
  32630. return PostScriptToken.IFELSE;
  32631. default:
  32632. return PostScriptToken.getOperator(str);
  32633. }
  32634. },
  32635. getNumber: function PostScriptLexer_getNumber() {
  32636. var ch = this.currentChar;
  32637. var strBuf = this.strBuf;
  32638. strBuf.length = 0;
  32639. strBuf[0] = String.fromCharCode(ch);
  32640. while ((ch = this.nextChar()) >= 0) {
  32641. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  32642. ch === 0x2D || ch === 0x2E) { // '-', '.'
  32643. strBuf.push(String.fromCharCode(ch));
  32644. } else {
  32645. break;
  32646. }
  32647. }
  32648. var value = parseFloat(strBuf.join(''));
  32649. if (isNaN(value)) {
  32650. error('Invalid floating point number: ' + value);
  32651. }
  32652. return value;
  32653. }
  32654. };
  32655. return PostScriptLexer;
  32656. })();
  32657. var Stream = (function StreamClosure() {
  32658. function Stream(arrayBuffer, start, length, dict) {
  32659. this.bytes = (arrayBuffer instanceof Uint8Array ?
  32660. arrayBuffer : new Uint8Array(arrayBuffer));
  32661. this.start = start || 0;
  32662. this.pos = this.start;
  32663. this.end = (start + length) || this.bytes.length;
  32664. this.dict = dict;
  32665. }
  32666. // required methods for a stream. if a particular stream does not
  32667. // implement these, an error should be thrown
  32668. Stream.prototype = {
  32669. get length() {
  32670. return this.end - this.start;
  32671. },
  32672. get isEmpty() {
  32673. return this.length === 0;
  32674. },
  32675. getByte: function Stream_getByte() {
  32676. if (this.pos >= this.end) {
  32677. return -1;
  32678. }
  32679. return this.bytes[this.pos++];
  32680. },
  32681. getUint16: function Stream_getUint16() {
  32682. var b0 = this.getByte();
  32683. var b1 = this.getByte();
  32684. return (b0 << 8) + b1;
  32685. },
  32686. getInt32: function Stream_getInt32() {
  32687. var b0 = this.getByte();
  32688. var b1 = this.getByte();
  32689. var b2 = this.getByte();
  32690. var b3 = this.getByte();
  32691. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32692. },
  32693. // returns subarray of original buffer
  32694. // should only be read
  32695. getBytes: function Stream_getBytes(length) {
  32696. var bytes = this.bytes;
  32697. var pos = this.pos;
  32698. var strEnd = this.end;
  32699. if (!length) {
  32700. return bytes.subarray(pos, strEnd);
  32701. }
  32702. var end = pos + length;
  32703. if (end > strEnd) {
  32704. end = strEnd;
  32705. }
  32706. this.pos = end;
  32707. return bytes.subarray(pos, end);
  32708. },
  32709. peekBytes: function Stream_peekBytes(length) {
  32710. var bytes = this.getBytes(length);
  32711. this.pos -= bytes.length;
  32712. return bytes;
  32713. },
  32714. skip: function Stream_skip(n) {
  32715. if (!n) {
  32716. n = 1;
  32717. }
  32718. this.pos += n;
  32719. },
  32720. reset: function Stream_reset() {
  32721. this.pos = this.start;
  32722. },
  32723. moveStart: function Stream_moveStart() {
  32724. this.start = this.pos;
  32725. },
  32726. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  32727. return new Stream(this.bytes.buffer, start, length, dict);
  32728. },
  32729. isStream: true
  32730. };
  32731. return Stream;
  32732. })();
  32733. var StringStream = (function StringStreamClosure() {
  32734. function StringStream(str) {
  32735. var length = str.length;
  32736. var bytes = new Uint8Array(length);
  32737. for (var n = 0; n < length; ++n) {
  32738. bytes[n] = str.charCodeAt(n);
  32739. }
  32740. Stream.call(this, bytes);
  32741. }
  32742. StringStream.prototype = Stream.prototype;
  32743. return StringStream;
  32744. })();
  32745. // super class for the decoding streams
  32746. var DecodeStream = (function DecodeStreamClosure() {
  32747. // Lots of DecodeStreams are created whose buffers are never used. For these
  32748. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  32749. // having special cases that would be required if we used |null| for an empty
  32750. // buffer.
  32751. var emptyBuffer = new Uint8Array(0);
  32752. function DecodeStream(maybeMinBufferLength) {
  32753. this.pos = 0;
  32754. this.bufferLength = 0;
  32755. this.eof = false;
  32756. this.buffer = emptyBuffer;
  32757. this.minBufferLength = 512;
  32758. if (maybeMinBufferLength) {
  32759. // Compute the first power of two that is as big as maybeMinBufferLength.
  32760. while (this.minBufferLength < maybeMinBufferLength) {
  32761. this.minBufferLength *= 2;
  32762. }
  32763. }
  32764. }
  32765. DecodeStream.prototype = {
  32766. get isEmpty() {
  32767. while (!this.eof && this.bufferLength === 0) {
  32768. this.readBlock();
  32769. }
  32770. return this.bufferLength === 0;
  32771. },
  32772. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  32773. var buffer = this.buffer;
  32774. if (requested <= buffer.byteLength) {
  32775. return buffer;
  32776. }
  32777. var size = this.minBufferLength;
  32778. while (size < requested) {
  32779. size *= 2;
  32780. }
  32781. var buffer2 = new Uint8Array(size);
  32782. buffer2.set(buffer);
  32783. return (this.buffer = buffer2);
  32784. },
  32785. getByte: function DecodeStream_getByte() {
  32786. var pos = this.pos;
  32787. while (this.bufferLength <= pos) {
  32788. if (this.eof) {
  32789. return -1;
  32790. }
  32791. this.readBlock();
  32792. }
  32793. return this.buffer[this.pos++];
  32794. },
  32795. getUint16: function DecodeStream_getUint16() {
  32796. var b0 = this.getByte();
  32797. var b1 = this.getByte();
  32798. return (b0 << 8) + b1;
  32799. },
  32800. getInt32: function DecodeStream_getInt32() {
  32801. var b0 = this.getByte();
  32802. var b1 = this.getByte();
  32803. var b2 = this.getByte();
  32804. var b3 = this.getByte();
  32805. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32806. },
  32807. getBytes: function DecodeStream_getBytes(length) {
  32808. var end, pos = this.pos;
  32809. if (length) {
  32810. this.ensureBuffer(pos + length);
  32811. end = pos + length;
  32812. while (!this.eof && this.bufferLength < end) {
  32813. this.readBlock();
  32814. }
  32815. var bufEnd = this.bufferLength;
  32816. if (end > bufEnd) {
  32817. end = bufEnd;
  32818. }
  32819. } else {
  32820. while (!this.eof) {
  32821. this.readBlock();
  32822. }
  32823. end = this.bufferLength;
  32824. }
  32825. this.pos = end;
  32826. return this.buffer.subarray(pos, end);
  32827. },
  32828. peekBytes: function DecodeStream_peekBytes(length) {
  32829. var bytes = this.getBytes(length);
  32830. this.pos -= bytes.length;
  32831. return bytes;
  32832. },
  32833. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  32834. var end = start + length;
  32835. while (this.bufferLength <= end && !this.eof) {
  32836. this.readBlock();
  32837. }
  32838. return new Stream(this.buffer, start, length, dict);
  32839. },
  32840. skip: function DecodeStream_skip(n) {
  32841. if (!n) {
  32842. n = 1;
  32843. }
  32844. this.pos += n;
  32845. },
  32846. reset: function DecodeStream_reset() {
  32847. this.pos = 0;
  32848. },
  32849. getBaseStreams: function DecodeStream_getBaseStreams() {
  32850. if (this.str && this.str.getBaseStreams) {
  32851. return this.str.getBaseStreams();
  32852. }
  32853. return [];
  32854. }
  32855. };
  32856. return DecodeStream;
  32857. })();
  32858. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  32859. function StreamsSequenceStream(streams) {
  32860. this.streams = streams;
  32861. DecodeStream.call(this, /* maybeLength = */ null);
  32862. }
  32863. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  32864. StreamsSequenceStream.prototype.readBlock =
  32865. function streamSequenceStreamReadBlock() {
  32866. var streams = this.streams;
  32867. if (streams.length === 0) {
  32868. this.eof = true;
  32869. return;
  32870. }
  32871. var stream = streams.shift();
  32872. var chunk = stream.getBytes();
  32873. var bufferLength = this.bufferLength;
  32874. var newLength = bufferLength + chunk.length;
  32875. var buffer = this.ensureBuffer(newLength);
  32876. buffer.set(chunk, bufferLength);
  32877. this.bufferLength = newLength;
  32878. };
  32879. StreamsSequenceStream.prototype.getBaseStreams =
  32880. function StreamsSequenceStream_getBaseStreams() {
  32881. var baseStreams = [];
  32882. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  32883. var stream = this.streams[i];
  32884. if (stream.getBaseStreams) {
  32885. Util.appendToArray(baseStreams, stream.getBaseStreams());
  32886. }
  32887. }
  32888. return baseStreams;
  32889. };
  32890. return StreamsSequenceStream;
  32891. })();
  32892. var FlateStream = (function FlateStreamClosure() {
  32893. var codeLenCodeMap = new Uint32Array([
  32894. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  32895. ]);
  32896. var lengthDecode = new Uint32Array([
  32897. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  32898. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  32899. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  32900. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  32901. ]);
  32902. var distDecode = new Uint32Array([
  32903. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  32904. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  32905. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  32906. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  32907. ]);
  32908. var fixedLitCodeTab = [new Uint32Array([
  32909. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  32910. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  32911. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  32912. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  32913. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  32914. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  32915. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  32916. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  32917. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  32918. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  32919. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  32920. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  32921. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  32922. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  32923. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  32924. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  32925. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  32926. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  32927. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  32928. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  32929. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  32930. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  32931. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  32932. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  32933. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  32934. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  32935. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  32936. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  32937. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  32938. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  32939. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  32940. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  32941. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  32942. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  32943. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  32944. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  32945. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  32946. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  32947. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  32948. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  32949. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  32950. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  32951. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  32952. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  32953. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  32954. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  32955. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  32956. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  32957. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  32958. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  32959. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  32960. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  32961. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  32962. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  32963. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  32964. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  32965. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  32966. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  32967. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  32968. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  32969. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  32970. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  32971. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  32972. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  32973. ]), 9];
  32974. var fixedDistCodeTab = [new Uint32Array([
  32975. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  32976. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  32977. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  32978. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  32979. ]), 5];
  32980. function FlateStream(str, maybeLength) {
  32981. this.str = str;
  32982. this.dict = str.dict;
  32983. var cmf = str.getByte();
  32984. var flg = str.getByte();
  32985. if (cmf === -1 || flg === -1) {
  32986. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  32987. }
  32988. if ((cmf & 0x0f) !== 0x08) {
  32989. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  32990. }
  32991. if ((((cmf << 8) + flg) % 31) !== 0) {
  32992. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  32993. }
  32994. if (flg & 0x20) {
  32995. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  32996. }
  32997. this.codeSize = 0;
  32998. this.codeBuf = 0;
  32999. DecodeStream.call(this, maybeLength);
  33000. }
  33001. FlateStream.prototype = Object.create(DecodeStream.prototype);
  33002. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  33003. var str = this.str;
  33004. var codeSize = this.codeSize;
  33005. var codeBuf = this.codeBuf;
  33006. var b;
  33007. while (codeSize < bits) {
  33008. if ((b = str.getByte()) === -1) {
  33009. error('Bad encoding in flate stream');
  33010. }
  33011. codeBuf |= b << codeSize;
  33012. codeSize += 8;
  33013. }
  33014. b = codeBuf & ((1 << bits) - 1);
  33015. this.codeBuf = codeBuf >> bits;
  33016. this.codeSize = codeSize -= bits;
  33017. return b;
  33018. };
  33019. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  33020. var str = this.str;
  33021. var codes = table[0];
  33022. var maxLen = table[1];
  33023. var codeSize = this.codeSize;
  33024. var codeBuf = this.codeBuf;
  33025. var b;
  33026. while (codeSize < maxLen) {
  33027. if ((b = str.getByte()) === -1) {
  33028. // premature end of stream. code might however still be valid.
  33029. // codeSize < codeLen check below guards against incomplete codeVal.
  33030. break;
  33031. }
  33032. codeBuf |= (b << codeSize);
  33033. codeSize += 8;
  33034. }
  33035. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  33036. var codeLen = code >> 16;
  33037. var codeVal = code & 0xffff;
  33038. if (codeLen < 1 || codeSize < codeLen) {
  33039. error('Bad encoding in flate stream');
  33040. }
  33041. this.codeBuf = (codeBuf >> codeLen);
  33042. this.codeSize = (codeSize - codeLen);
  33043. return codeVal;
  33044. };
  33045. FlateStream.prototype.generateHuffmanTable =
  33046. function flateStreamGenerateHuffmanTable(lengths) {
  33047. var n = lengths.length;
  33048. // find max code length
  33049. var maxLen = 0;
  33050. var i;
  33051. for (i = 0; i < n; ++i) {
  33052. if (lengths[i] > maxLen) {
  33053. maxLen = lengths[i];
  33054. }
  33055. }
  33056. // build the table
  33057. var size = 1 << maxLen;
  33058. var codes = new Uint32Array(size);
  33059. for (var len = 1, code = 0, skip = 2;
  33060. len <= maxLen;
  33061. ++len, code <<= 1, skip <<= 1) {
  33062. for (var val = 0; val < n; ++val) {
  33063. if (lengths[val] === len) {
  33064. // bit-reverse the code
  33065. var code2 = 0;
  33066. var t = code;
  33067. for (i = 0; i < len; ++i) {
  33068. code2 = (code2 << 1) | (t & 1);
  33069. t >>= 1;
  33070. }
  33071. // fill the table entries
  33072. for (i = code2; i < size; i += skip) {
  33073. codes[i] = (len << 16) | val;
  33074. }
  33075. ++code;
  33076. }
  33077. }
  33078. }
  33079. return [codes, maxLen];
  33080. };
  33081. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  33082. var buffer, len;
  33083. var str = this.str;
  33084. // read block header
  33085. var hdr = this.getBits(3);
  33086. if (hdr & 1) {
  33087. this.eof = true;
  33088. }
  33089. hdr >>= 1;
  33090. if (hdr === 0) { // uncompressed block
  33091. var b;
  33092. if ((b = str.getByte()) === -1) {
  33093. error('Bad block header in flate stream');
  33094. }
  33095. var blockLen = b;
  33096. if ((b = str.getByte()) === -1) {
  33097. error('Bad block header in flate stream');
  33098. }
  33099. blockLen |= (b << 8);
  33100. if ((b = str.getByte()) === -1) {
  33101. error('Bad block header in flate stream');
  33102. }
  33103. var check = b;
  33104. if ((b = str.getByte()) === -1) {
  33105. error('Bad block header in flate stream');
  33106. }
  33107. check |= (b << 8);
  33108. if (check !== (~blockLen & 0xffff) &&
  33109. (blockLen !== 0 || check !== 0)) {
  33110. // Ignoring error for bad "empty" block (see issue 1277)
  33111. error('Bad uncompressed block length in flate stream');
  33112. }
  33113. this.codeBuf = 0;
  33114. this.codeSize = 0;
  33115. var bufferLength = this.bufferLength;
  33116. buffer = this.ensureBuffer(bufferLength + blockLen);
  33117. var end = bufferLength + blockLen;
  33118. this.bufferLength = end;
  33119. if (blockLen === 0) {
  33120. if (str.peekBytes(1).length === 0) {
  33121. this.eof = true;
  33122. }
  33123. } else {
  33124. for (var n = bufferLength; n < end; ++n) {
  33125. if ((b = str.getByte()) === -1) {
  33126. this.eof = true;
  33127. break;
  33128. }
  33129. buffer[n] = b;
  33130. }
  33131. }
  33132. return;
  33133. }
  33134. var litCodeTable;
  33135. var distCodeTable;
  33136. if (hdr === 1) { // compressed block, fixed codes
  33137. litCodeTable = fixedLitCodeTab;
  33138. distCodeTable = fixedDistCodeTab;
  33139. } else if (hdr === 2) { // compressed block, dynamic codes
  33140. var numLitCodes = this.getBits(5) + 257;
  33141. var numDistCodes = this.getBits(5) + 1;
  33142. var numCodeLenCodes = this.getBits(4) + 4;
  33143. // build the code lengths code table
  33144. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  33145. var i;
  33146. for (i = 0; i < numCodeLenCodes; ++i) {
  33147. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  33148. }
  33149. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  33150. // build the literal and distance code tables
  33151. len = 0;
  33152. i = 0;
  33153. var codes = numLitCodes + numDistCodes;
  33154. var codeLengths = new Uint8Array(codes);
  33155. var bitsLength, bitsOffset, what;
  33156. while (i < codes) {
  33157. var code = this.getCode(codeLenCodeTab);
  33158. if (code === 16) {
  33159. bitsLength = 2; bitsOffset = 3; what = len;
  33160. } else if (code === 17) {
  33161. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  33162. } else if (code === 18) {
  33163. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  33164. } else {
  33165. codeLengths[i++] = len = code;
  33166. continue;
  33167. }
  33168. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  33169. while (repeatLength-- > 0) {
  33170. codeLengths[i++] = what;
  33171. }
  33172. }
  33173. litCodeTable =
  33174. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  33175. distCodeTable =
  33176. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  33177. } else {
  33178. error('Unknown block type in flate stream');
  33179. }
  33180. buffer = this.buffer;
  33181. var limit = buffer ? buffer.length : 0;
  33182. var pos = this.bufferLength;
  33183. while (true) {
  33184. var code1 = this.getCode(litCodeTable);
  33185. if (code1 < 256) {
  33186. if (pos + 1 >= limit) {
  33187. buffer = this.ensureBuffer(pos + 1);
  33188. limit = buffer.length;
  33189. }
  33190. buffer[pos++] = code1;
  33191. continue;
  33192. }
  33193. if (code1 === 256) {
  33194. this.bufferLength = pos;
  33195. return;
  33196. }
  33197. code1 -= 257;
  33198. code1 = lengthDecode[code1];
  33199. var code2 = code1 >> 16;
  33200. if (code2 > 0) {
  33201. code2 = this.getBits(code2);
  33202. }
  33203. len = (code1 & 0xffff) + code2;
  33204. code1 = this.getCode(distCodeTable);
  33205. code1 = distDecode[code1];
  33206. code2 = code1 >> 16;
  33207. if (code2 > 0) {
  33208. code2 = this.getBits(code2);
  33209. }
  33210. var dist = (code1 & 0xffff) + code2;
  33211. if (pos + len >= limit) {
  33212. buffer = this.ensureBuffer(pos + len);
  33213. limit = buffer.length;
  33214. }
  33215. for (var k = 0; k < len; ++k, ++pos) {
  33216. buffer[pos] = buffer[pos - dist];
  33217. }
  33218. }
  33219. };
  33220. return FlateStream;
  33221. })();
  33222. var PredictorStream = (function PredictorStreamClosure() {
  33223. function PredictorStream(str, maybeLength, params) {
  33224. var predictor = this.predictor = params.get('Predictor') || 1;
  33225. if (predictor <= 1) {
  33226. return str; // no prediction
  33227. }
  33228. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  33229. error('Unsupported predictor: ' + predictor);
  33230. }
  33231. if (predictor === 2) {
  33232. this.readBlock = this.readBlockTiff;
  33233. } else {
  33234. this.readBlock = this.readBlockPng;
  33235. }
  33236. this.str = str;
  33237. this.dict = str.dict;
  33238. var colors = this.colors = params.get('Colors') || 1;
  33239. var bits = this.bits = params.get('BitsPerComponent') || 8;
  33240. var columns = this.columns = params.get('Columns') || 1;
  33241. this.pixBytes = (colors * bits + 7) >> 3;
  33242. this.rowBytes = (columns * colors * bits + 7) >> 3;
  33243. DecodeStream.call(this, maybeLength);
  33244. return this;
  33245. }
  33246. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  33247. PredictorStream.prototype.readBlockTiff =
  33248. function predictorStreamReadBlockTiff() {
  33249. var rowBytes = this.rowBytes;
  33250. var bufferLength = this.bufferLength;
  33251. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  33252. var bits = this.bits;
  33253. var colors = this.colors;
  33254. var rawBytes = this.str.getBytes(rowBytes);
  33255. this.eof = !rawBytes.length;
  33256. if (this.eof) {
  33257. return;
  33258. }
  33259. var inbuf = 0, outbuf = 0;
  33260. var inbits = 0, outbits = 0;
  33261. var pos = bufferLength;
  33262. var i;
  33263. if (bits === 1) {
  33264. for (i = 0; i < rowBytes; ++i) {
  33265. var c = rawBytes[i];
  33266. inbuf = (inbuf << 8) | c;
  33267. // bitwise addition is exclusive or
  33268. // first shift inbuf and then add
  33269. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  33270. // truncate inbuf (assumes colors < 16)
  33271. inbuf &= 0xFFFF;
  33272. }
  33273. } else if (bits === 8) {
  33274. for (i = 0; i < colors; ++i) {
  33275. buffer[pos++] = rawBytes[i];
  33276. }
  33277. for (; i < rowBytes; ++i) {
  33278. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  33279. pos++;
  33280. }
  33281. } else {
  33282. var compArray = new Uint8Array(colors + 1);
  33283. var bitMask = (1 << bits) - 1;
  33284. var j = 0, k = bufferLength;
  33285. var columns = this.columns;
  33286. for (i = 0; i < columns; ++i) {
  33287. for (var kk = 0; kk < colors; ++kk) {
  33288. if (inbits < bits) {
  33289. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  33290. inbits += 8;
  33291. }
  33292. compArray[kk] = (compArray[kk] +
  33293. (inbuf >> (inbits - bits))) & bitMask;
  33294. inbits -= bits;
  33295. outbuf = (outbuf << bits) | compArray[kk];
  33296. outbits += bits;
  33297. if (outbits >= 8) {
  33298. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  33299. outbits -= 8;
  33300. }
  33301. }
  33302. }
  33303. if (outbits > 0) {
  33304. buffer[k++] = (outbuf << (8 - outbits)) +
  33305. (inbuf & ((1 << (8 - outbits)) - 1));
  33306. }
  33307. }
  33308. this.bufferLength += rowBytes;
  33309. };
  33310. PredictorStream.prototype.readBlockPng =
  33311. function predictorStreamReadBlockPng() {
  33312. var rowBytes = this.rowBytes;
  33313. var pixBytes = this.pixBytes;
  33314. var predictor = this.str.getByte();
  33315. var rawBytes = this.str.getBytes(rowBytes);
  33316. this.eof = !rawBytes.length;
  33317. if (this.eof) {
  33318. return;
  33319. }
  33320. var bufferLength = this.bufferLength;
  33321. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  33322. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  33323. if (prevRow.length === 0) {
  33324. prevRow = new Uint8Array(rowBytes);
  33325. }
  33326. var i, j = bufferLength, up, c;
  33327. switch (predictor) {
  33328. case 0:
  33329. for (i = 0; i < rowBytes; ++i) {
  33330. buffer[j++] = rawBytes[i];
  33331. }
  33332. break;
  33333. case 1:
  33334. for (i = 0; i < pixBytes; ++i) {
  33335. buffer[j++] = rawBytes[i];
  33336. }
  33337. for (; i < rowBytes; ++i) {
  33338. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  33339. j++;
  33340. }
  33341. break;
  33342. case 2:
  33343. for (i = 0; i < rowBytes; ++i) {
  33344. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  33345. }
  33346. break;
  33347. case 3:
  33348. for (i = 0; i < pixBytes; ++i) {
  33349. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  33350. }
  33351. for (; i < rowBytes; ++i) {
  33352. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  33353. rawBytes[i]) & 0xFF;
  33354. j++;
  33355. }
  33356. break;
  33357. case 4:
  33358. // we need to save the up left pixels values. the simplest way
  33359. // is to create a new buffer
  33360. for (i = 0; i < pixBytes; ++i) {
  33361. up = prevRow[i];
  33362. c = rawBytes[i];
  33363. buffer[j++] = up + c;
  33364. }
  33365. for (; i < rowBytes; ++i) {
  33366. up = prevRow[i];
  33367. var upLeft = prevRow[i - pixBytes];
  33368. var left = buffer[j - pixBytes];
  33369. var p = left + up - upLeft;
  33370. var pa = p - left;
  33371. if (pa < 0) {
  33372. pa = -pa;
  33373. }
  33374. var pb = p - up;
  33375. if (pb < 0) {
  33376. pb = -pb;
  33377. }
  33378. var pc = p - upLeft;
  33379. if (pc < 0) {
  33380. pc = -pc;
  33381. }
  33382. c = rawBytes[i];
  33383. if (pa <= pb && pa <= pc) {
  33384. buffer[j++] = left + c;
  33385. } else if (pb <= pc) {
  33386. buffer[j++] = up + c;
  33387. } else {
  33388. buffer[j++] = upLeft + c;
  33389. }
  33390. }
  33391. break;
  33392. default:
  33393. error('Unsupported predictor: ' + predictor);
  33394. }
  33395. this.bufferLength += rowBytes;
  33396. };
  33397. return PredictorStream;
  33398. })();
  33399. /**
  33400. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  33401. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  33402. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  33403. * a library to decode these images and the stream behaves like all the other
  33404. * DecodeStreams.
  33405. */
  33406. var JpegStream = (function JpegStreamClosure() {
  33407. function JpegStream(stream, maybeLength, dict, xref) {
  33408. // TODO: per poppler, some images may have 'junk' before that
  33409. // need to be removed
  33410. this.stream = stream;
  33411. this.maybeLength = maybeLength;
  33412. this.dict = dict;
  33413. DecodeStream.call(this, maybeLength);
  33414. }
  33415. JpegStream.prototype = Object.create(DecodeStream.prototype);
  33416. Object.defineProperty(JpegStream.prototype, 'bytes', {
  33417. get: function JpegStream_bytes() {
  33418. // If this.maybeLength is null, we'll get the entire stream.
  33419. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  33420. },
  33421. configurable: true
  33422. });
  33423. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  33424. if (this.bufferLength) {
  33425. return;
  33426. }
  33427. try {
  33428. var jpegImage = new JpegImage();
  33429. // checking if values needs to be transformed before conversion
  33430. if (this.dict && isArray(this.dict.get('Decode'))) {
  33431. var decodeArr = this.dict.get('Decode');
  33432. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  33433. var decodeArrLength = decodeArr.length;
  33434. var transform = new Int32Array(decodeArrLength);
  33435. var transformNeeded = false;
  33436. var maxValue = (1 << bitsPerComponent) - 1;
  33437. for (var i = 0; i < decodeArrLength; i += 2) {
  33438. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  33439. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  33440. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  33441. transformNeeded = true;
  33442. }
  33443. }
  33444. if (transformNeeded) {
  33445. jpegImage.decodeTransform = transform;
  33446. }
  33447. }
  33448. jpegImage.parse(this.bytes);
  33449. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  33450. this.forceRGB);
  33451. this.buffer = data;
  33452. this.bufferLength = data.length;
  33453. this.eof = true;
  33454. } catch (e) {
  33455. error('JPEG error: ' + e);
  33456. }
  33457. };
  33458. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  33459. this.ensureBuffer();
  33460. return this.buffer;
  33461. };
  33462. JpegStream.prototype.getIR = function JpegStream_getIR() {
  33463. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  33464. };
  33465. /**
  33466. * Checks if the image can be decoded and displayed by the browser without any
  33467. * further processing such as color space conversions.
  33468. */
  33469. JpegStream.prototype.isNativelySupported =
  33470. function JpegStream_isNativelySupported(xref, res) {
  33471. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  33472. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  33473. };
  33474. /**
  33475. * Checks if the image can be decoded by the browser.
  33476. */
  33477. JpegStream.prototype.isNativelyDecodable =
  33478. function JpegStream_isNativelyDecodable(xref, res) {
  33479. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  33480. var numComps = cs.numComps;
  33481. return numComps === 1 || numComps === 3;
  33482. };
  33483. return JpegStream;
  33484. })();
  33485. /**
  33486. * For JPEG 2000's we use a library to decode these images and
  33487. * the stream behaves like all the other DecodeStreams.
  33488. */
  33489. var JpxStream = (function JpxStreamClosure() {
  33490. function JpxStream(stream, maybeLength, dict) {
  33491. this.stream = stream;
  33492. this.maybeLength = maybeLength;
  33493. this.dict = dict;
  33494. DecodeStream.call(this, maybeLength);
  33495. }
  33496. JpxStream.prototype = Object.create(DecodeStream.prototype);
  33497. Object.defineProperty(JpxStream.prototype, 'bytes', {
  33498. get: function JpxStream_bytes() {
  33499. // If this.maybeLength is null, we'll get the entire stream.
  33500. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  33501. },
  33502. configurable: true
  33503. });
  33504. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  33505. if (this.bufferLength) {
  33506. return;
  33507. }
  33508. var jpxImage = new JpxImage();
  33509. jpxImage.parse(this.bytes);
  33510. var width = jpxImage.width;
  33511. var height = jpxImage.height;
  33512. var componentsCount = jpxImage.componentsCount;
  33513. var tileCount = jpxImage.tiles.length;
  33514. if (tileCount === 1) {
  33515. this.buffer = jpxImage.tiles[0].items;
  33516. } else {
  33517. var data = new Uint8Array(width * height * componentsCount);
  33518. for (var k = 0; k < tileCount; k++) {
  33519. var tileComponents = jpxImage.tiles[k];
  33520. var tileWidth = tileComponents.width;
  33521. var tileHeight = tileComponents.height;
  33522. var tileLeft = tileComponents.left;
  33523. var tileTop = tileComponents.top;
  33524. var src = tileComponents.items;
  33525. var srcPosition = 0;
  33526. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  33527. var imgRowSize = width * componentsCount;
  33528. var tileRowSize = tileWidth * componentsCount;
  33529. for (var j = 0; j < tileHeight; j++) {
  33530. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  33531. data.set(rowBytes, dataPosition);
  33532. srcPosition += tileRowSize;
  33533. dataPosition += imgRowSize;
  33534. }
  33535. }
  33536. this.buffer = data;
  33537. }
  33538. this.bufferLength = this.buffer.length;
  33539. this.eof = true;
  33540. };
  33541. return JpxStream;
  33542. })();
  33543. /**
  33544. * For JBIG2's we use a library to decode these images and
  33545. * the stream behaves like all the other DecodeStreams.
  33546. */
  33547. var Jbig2Stream = (function Jbig2StreamClosure() {
  33548. function Jbig2Stream(stream, maybeLength, dict) {
  33549. this.stream = stream;
  33550. this.maybeLength = maybeLength;
  33551. this.dict = dict;
  33552. DecodeStream.call(this, maybeLength);
  33553. }
  33554. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  33555. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  33556. get: function Jbig2Stream_bytes() {
  33557. // If this.maybeLength is null, we'll get the entire stream.
  33558. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  33559. },
  33560. configurable: true
  33561. });
  33562. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  33563. if (this.bufferLength) {
  33564. return;
  33565. }
  33566. var jbig2Image = new Jbig2Image();
  33567. var chunks = [], decodeParams = this.dict.get('DecodeParms');
  33568. // According to the PDF specification, DecodeParms can be either
  33569. // a dictionary, or an array whose elements are dictionaries.
  33570. if (isArray(decodeParams)) {
  33571. if (decodeParams.length > 1) {
  33572. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  33573. 'not supported.');
  33574. }
  33575. decodeParams = decodeParams[0];
  33576. }
  33577. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  33578. var globalsStream = decodeParams.get('JBIG2Globals');
  33579. var globals = globalsStream.getBytes();
  33580. chunks.push({data: globals, start: 0, end: globals.length});
  33581. }
  33582. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  33583. var data = jbig2Image.parseChunks(chunks);
  33584. var dataLength = data.length;
  33585. // JBIG2 had black as 1 and white as 0, inverting the colors
  33586. for (var i = 0; i < dataLength; i++) {
  33587. data[i] ^= 0xFF;
  33588. }
  33589. this.buffer = data;
  33590. this.bufferLength = dataLength;
  33591. this.eof = true;
  33592. };
  33593. return Jbig2Stream;
  33594. })();
  33595. var DecryptStream = (function DecryptStreamClosure() {
  33596. function DecryptStream(str, maybeLength, decrypt) {
  33597. this.str = str;
  33598. this.dict = str.dict;
  33599. this.decrypt = decrypt;
  33600. this.nextChunk = null;
  33601. this.initialized = false;
  33602. DecodeStream.call(this, maybeLength);
  33603. }
  33604. var chunkSize = 512;
  33605. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  33606. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  33607. var chunk;
  33608. if (this.initialized) {
  33609. chunk = this.nextChunk;
  33610. } else {
  33611. chunk = this.str.getBytes(chunkSize);
  33612. this.initialized = true;
  33613. }
  33614. if (!chunk || chunk.length === 0) {
  33615. this.eof = true;
  33616. return;
  33617. }
  33618. this.nextChunk = this.str.getBytes(chunkSize);
  33619. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  33620. var decrypt = this.decrypt;
  33621. chunk = decrypt(chunk, !hasMoreData);
  33622. var bufferLength = this.bufferLength;
  33623. var i, n = chunk.length;
  33624. var buffer = this.ensureBuffer(bufferLength + n);
  33625. for (i = 0; i < n; i++) {
  33626. buffer[bufferLength++] = chunk[i];
  33627. }
  33628. this.bufferLength = bufferLength;
  33629. };
  33630. return DecryptStream;
  33631. })();
  33632. var Ascii85Stream = (function Ascii85StreamClosure() {
  33633. function Ascii85Stream(str, maybeLength) {
  33634. this.str = str;
  33635. this.dict = str.dict;
  33636. this.input = new Uint8Array(5);
  33637. // Most streams increase in size when decoded, but Ascii85 streams
  33638. // typically shrink by ~20%.
  33639. if (maybeLength) {
  33640. maybeLength = 0.8 * maybeLength;
  33641. }
  33642. DecodeStream.call(this, maybeLength);
  33643. }
  33644. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  33645. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  33646. var TILDA_CHAR = 0x7E; // '~'
  33647. var Z_LOWER_CHAR = 0x7A; // 'z'
  33648. var EOF = -1;
  33649. var str = this.str;
  33650. var c = str.getByte();
  33651. while (Lexer.isSpace(c)) {
  33652. c = str.getByte();
  33653. }
  33654. if (c === EOF || c === TILDA_CHAR) {
  33655. this.eof = true;
  33656. return;
  33657. }
  33658. var bufferLength = this.bufferLength, buffer;
  33659. var i;
  33660. // special code for z
  33661. if (c === Z_LOWER_CHAR) {
  33662. buffer = this.ensureBuffer(bufferLength + 4);
  33663. for (i = 0; i < 4; ++i) {
  33664. buffer[bufferLength + i] = 0;
  33665. }
  33666. this.bufferLength += 4;
  33667. } else {
  33668. var input = this.input;
  33669. input[0] = c;
  33670. for (i = 1; i < 5; ++i) {
  33671. c = str.getByte();
  33672. while (Lexer.isSpace(c)) {
  33673. c = str.getByte();
  33674. }
  33675. input[i] = c;
  33676. if (c === EOF || c === TILDA_CHAR) {
  33677. break;
  33678. }
  33679. }
  33680. buffer = this.ensureBuffer(bufferLength + i - 1);
  33681. this.bufferLength += i - 1;
  33682. // partial ending;
  33683. if (i < 5) {
  33684. for (; i < 5; ++i) {
  33685. input[i] = 0x21 + 84;
  33686. }
  33687. this.eof = true;
  33688. }
  33689. var t = 0;
  33690. for (i = 0; i < 5; ++i) {
  33691. t = t * 85 + (input[i] - 0x21);
  33692. }
  33693. for (i = 3; i >= 0; --i) {
  33694. buffer[bufferLength + i] = t & 0xFF;
  33695. t >>= 8;
  33696. }
  33697. }
  33698. };
  33699. return Ascii85Stream;
  33700. })();
  33701. var AsciiHexStream = (function AsciiHexStreamClosure() {
  33702. function AsciiHexStream(str, maybeLength) {
  33703. this.str = str;
  33704. this.dict = str.dict;
  33705. this.firstDigit = -1;
  33706. // Most streams increase in size when decoded, but AsciiHex streams shrink
  33707. // by 50%.
  33708. if (maybeLength) {
  33709. maybeLength = 0.5 * maybeLength;
  33710. }
  33711. DecodeStream.call(this, maybeLength);
  33712. }
  33713. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  33714. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  33715. var UPSTREAM_BLOCK_SIZE = 8000;
  33716. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  33717. if (!bytes.length) {
  33718. this.eof = true;
  33719. return;
  33720. }
  33721. var maxDecodeLength = (bytes.length + 1) >> 1;
  33722. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  33723. var bufferLength = this.bufferLength;
  33724. var firstDigit = this.firstDigit;
  33725. for (var i = 0, ii = bytes.length; i < ii; i++) {
  33726. var ch = bytes[i], digit;
  33727. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  33728. digit = ch & 0x0F;
  33729. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  33730. // 'A'-'Z', 'a'-'z'
  33731. digit = (ch & 0x0F) + 9;
  33732. } else if (ch === 0x3E) { // '>'
  33733. this.eof = true;
  33734. break;
  33735. } else { // probably whitespace
  33736. continue; // ignoring
  33737. }
  33738. if (firstDigit < 0) {
  33739. firstDigit = digit;
  33740. } else {
  33741. buffer[bufferLength++] = (firstDigit << 4) | digit;
  33742. firstDigit = -1;
  33743. }
  33744. }
  33745. if (firstDigit >= 0 && this.eof) {
  33746. // incomplete byte
  33747. buffer[bufferLength++] = (firstDigit << 4);
  33748. firstDigit = -1;
  33749. }
  33750. this.firstDigit = firstDigit;
  33751. this.bufferLength = bufferLength;
  33752. };
  33753. return AsciiHexStream;
  33754. })();
  33755. var RunLengthStream = (function RunLengthStreamClosure() {
  33756. function RunLengthStream(str, maybeLength) {
  33757. this.str = str;
  33758. this.dict = str.dict;
  33759. DecodeStream.call(this, maybeLength);
  33760. }
  33761. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  33762. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  33763. // The repeatHeader has following format. The first byte defines type of run
  33764. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  33765. // (in addition to the second byte from the header), n = 129 through 255 -
  33766. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  33767. var repeatHeader = this.str.getBytes(2);
  33768. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  33769. this.eof = true;
  33770. return;
  33771. }
  33772. var buffer;
  33773. var bufferLength = this.bufferLength;
  33774. var n = repeatHeader[0];
  33775. if (n < 128) {
  33776. // copy n bytes
  33777. buffer = this.ensureBuffer(bufferLength + n + 1);
  33778. buffer[bufferLength++] = repeatHeader[1];
  33779. if (n > 0) {
  33780. var source = this.str.getBytes(n);
  33781. buffer.set(source, bufferLength);
  33782. bufferLength += n;
  33783. }
  33784. } else {
  33785. n = 257 - n;
  33786. var b = repeatHeader[1];
  33787. buffer = this.ensureBuffer(bufferLength + n + 1);
  33788. for (var i = 0; i < n; i++) {
  33789. buffer[bufferLength++] = b;
  33790. }
  33791. }
  33792. this.bufferLength = bufferLength;
  33793. };
  33794. return RunLengthStream;
  33795. })();
  33796. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  33797. var ccittEOL = -2;
  33798. var twoDimPass = 0;
  33799. var twoDimHoriz = 1;
  33800. var twoDimVert0 = 2;
  33801. var twoDimVertR1 = 3;
  33802. var twoDimVertL1 = 4;
  33803. var twoDimVertR2 = 5;
  33804. var twoDimVertL2 = 6;
  33805. var twoDimVertR3 = 7;
  33806. var twoDimVertL3 = 8;
  33807. var twoDimTable = [
  33808. [-1, -1], [-1, -1], // 000000x
  33809. [7, twoDimVertL3], // 0000010
  33810. [7, twoDimVertR3], // 0000011
  33811. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  33812. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  33813. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  33814. [4, twoDimPass], [4, twoDimPass],
  33815. [4, twoDimPass], [4, twoDimPass],
  33816. [4, twoDimPass], [4, twoDimPass],
  33817. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  33818. [3, twoDimHoriz], [3, twoDimHoriz],
  33819. [3, twoDimHoriz], [3, twoDimHoriz],
  33820. [3, twoDimHoriz], [3, twoDimHoriz],
  33821. [3, twoDimHoriz], [3, twoDimHoriz],
  33822. [3, twoDimHoriz], [3, twoDimHoriz],
  33823. [3, twoDimHoriz], [3, twoDimHoriz],
  33824. [3, twoDimHoriz], [3, twoDimHoriz],
  33825. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  33826. [3, twoDimVertL1], [3, twoDimVertL1],
  33827. [3, twoDimVertL1], [3, twoDimVertL1],
  33828. [3, twoDimVertL1], [3, twoDimVertL1],
  33829. [3, twoDimVertL1], [3, twoDimVertL1],
  33830. [3, twoDimVertL1], [3, twoDimVertL1],
  33831. [3, twoDimVertL1], [3, twoDimVertL1],
  33832. [3, twoDimVertL1], [3, twoDimVertL1],
  33833. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  33834. [3, twoDimVertR1], [3, twoDimVertR1],
  33835. [3, twoDimVertR1], [3, twoDimVertR1],
  33836. [3, twoDimVertR1], [3, twoDimVertR1],
  33837. [3, twoDimVertR1], [3, twoDimVertR1],
  33838. [3, twoDimVertR1], [3, twoDimVertR1],
  33839. [3, twoDimVertR1], [3, twoDimVertR1],
  33840. [3, twoDimVertR1], [3, twoDimVertR1],
  33841. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  33842. [1, twoDimVert0], [1, twoDimVert0],
  33843. [1, twoDimVert0], [1, twoDimVert0],
  33844. [1, twoDimVert0], [1, twoDimVert0],
  33845. [1, twoDimVert0], [1, twoDimVert0],
  33846. [1, twoDimVert0], [1, twoDimVert0],
  33847. [1, twoDimVert0], [1, twoDimVert0],
  33848. [1, twoDimVert0], [1, twoDimVert0],
  33849. [1, twoDimVert0], [1, twoDimVert0],
  33850. [1, twoDimVert0], [1, twoDimVert0],
  33851. [1, twoDimVert0], [1, twoDimVert0],
  33852. [1, twoDimVert0], [1, twoDimVert0],
  33853. [1, twoDimVert0], [1, twoDimVert0],
  33854. [1, twoDimVert0], [1, twoDimVert0],
  33855. [1, twoDimVert0], [1, twoDimVert0],
  33856. [1, twoDimVert0], [1, twoDimVert0],
  33857. [1, twoDimVert0], [1, twoDimVert0],
  33858. [1, twoDimVert0], [1, twoDimVert0],
  33859. [1, twoDimVert0], [1, twoDimVert0],
  33860. [1, twoDimVert0], [1, twoDimVert0],
  33861. [1, twoDimVert0], [1, twoDimVert0],
  33862. [1, twoDimVert0], [1, twoDimVert0],
  33863. [1, twoDimVert0], [1, twoDimVert0],
  33864. [1, twoDimVert0], [1, twoDimVert0],
  33865. [1, twoDimVert0], [1, twoDimVert0],
  33866. [1, twoDimVert0], [1, twoDimVert0],
  33867. [1, twoDimVert0], [1, twoDimVert0],
  33868. [1, twoDimVert0], [1, twoDimVert0],
  33869. [1, twoDimVert0], [1, twoDimVert0],
  33870. [1, twoDimVert0], [1, twoDimVert0],
  33871. [1, twoDimVert0], [1, twoDimVert0],
  33872. [1, twoDimVert0], [1, twoDimVert0]
  33873. ];
  33874. var whiteTable1 = [
  33875. [-1, -1], // 00000
  33876. [12, ccittEOL], // 00001
  33877. [-1, -1], [-1, -1], // 0001x
  33878. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  33879. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  33880. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  33881. [11, 1792], [11, 1792], // 1000x
  33882. [12, 1984], // 10010
  33883. [12, 2048], // 10011
  33884. [12, 2112], // 10100
  33885. [12, 2176], // 10101
  33886. [12, 2240], // 10110
  33887. [12, 2304], // 10111
  33888. [11, 1856], [11, 1856], // 1100x
  33889. [11, 1920], [11, 1920], // 1101x
  33890. [12, 2368], // 11100
  33891. [12, 2432], // 11101
  33892. [12, 2496], // 11110
  33893. [12, 2560] // 11111
  33894. ];
  33895. var whiteTable2 = [
  33896. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  33897. [8, 29], [8, 29], // 00000010x
  33898. [8, 30], [8, 30], // 00000011x
  33899. [8, 45], [8, 45], // 00000100x
  33900. [8, 46], [8, 46], // 00000101x
  33901. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  33902. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  33903. [8, 47], [8, 47], // 00001010x
  33904. [8, 48], [8, 48], // 00001011x
  33905. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  33906. [6, 13], [6, 13], [6, 13], [6, 13],
  33907. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  33908. [8, 33], [8, 33], // 00010010x
  33909. [8, 34], [8, 34], // 00010011x
  33910. [8, 35], [8, 35], // 00010100x
  33911. [8, 36], [8, 36], // 00010101x
  33912. [8, 37], [8, 37], // 00010110x
  33913. [8, 38], [8, 38], // 00010111x
  33914. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  33915. [8, 31], [8, 31], // 00011010x
  33916. [8, 32], [8, 32], // 00011011x
  33917. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  33918. [6, 1], [6, 1], [6, 1], [6, 1],
  33919. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  33920. [6, 12], [6, 12], [6, 12], [6, 12],
  33921. [8, 53], [8, 53], // 00100100x
  33922. [8, 54], [8, 54], // 00100101x
  33923. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  33924. [8, 39], [8, 39], // 00101000x
  33925. [8, 40], [8, 40], // 00101001x
  33926. [8, 41], [8, 41], // 00101010x
  33927. [8, 42], [8, 42], // 00101011x
  33928. [8, 43], [8, 43], // 00101100x
  33929. [8, 44], [8, 44], // 00101101x
  33930. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  33931. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  33932. [8, 61], [8, 61], // 00110010x
  33933. [8, 62], [8, 62], // 00110011x
  33934. [8, 63], [8, 63], // 00110100x
  33935. [8, 0], [8, 0], // 00110101x
  33936. [8, 320], [8, 320], // 00110110x
  33937. [8, 384], [8, 384], // 00110111x
  33938. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  33939. [5, 10], [5, 10], [5, 10], [5, 10],
  33940. [5, 10], [5, 10], [5, 10], [5, 10],
  33941. [5, 10], [5, 10], [5, 10], [5, 10],
  33942. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  33943. [5, 11], [5, 11], [5, 11], [5, 11],
  33944. [5, 11], [5, 11], [5, 11], [5, 11],
  33945. [5, 11], [5, 11], [5, 11], [5, 11],
  33946. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  33947. [8, 59], [8, 59], // 01001010x
  33948. [8, 60], [8, 60], // 01001011x
  33949. [9, 1472], // 010011000
  33950. [9, 1536], // 010011001
  33951. [9, 1600], // 010011010
  33952. [9, 1728], // 010011011
  33953. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  33954. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  33955. [8, 49], [8, 49], // 01010010x
  33956. [8, 50], [8, 50], // 01010011x
  33957. [8, 51], [8, 51], // 01010100x
  33958. [8, 52], [8, 52], // 01010101x
  33959. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  33960. [8, 55], [8, 55], // 01011000x
  33961. [8, 56], [8, 56], // 01011001x
  33962. [8, 57], [8, 57], // 01011010x
  33963. [8, 58], [8, 58], // 01011011x
  33964. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  33965. [6, 192], [6, 192], [6, 192], [6, 192],
  33966. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  33967. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  33968. [8, 448], [8, 448], // 01100100x
  33969. [8, 512], [8, 512], // 01100101x
  33970. [9, 704], // 011001100
  33971. [9, 768], // 011001101
  33972. [8, 640], [8, 640], // 01100111x
  33973. [8, 576], [8, 576], // 01101000x
  33974. [9, 832], // 011010010
  33975. [9, 896], // 011010011
  33976. [9, 960], // 011010100
  33977. [9, 1024], // 011010101
  33978. [9, 1088], // 011010110
  33979. [9, 1152], // 011010111
  33980. [9, 1216], // 011011000
  33981. [9, 1280], // 011011001
  33982. [9, 1344], // 011011010
  33983. [9, 1408], // 011011011
  33984. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  33985. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  33986. [4, 2], [4, 2], [4, 2], [4, 2],
  33987. [4, 2], [4, 2], [4, 2], [4, 2],
  33988. [4, 2], [4, 2], [4, 2], [4, 2],
  33989. [4, 2], [4, 2], [4, 2], [4, 2],
  33990. [4, 2], [4, 2], [4, 2], [4, 2],
  33991. [4, 2], [4, 2], [4, 2], [4, 2],
  33992. [4, 2], [4, 2], [4, 2], [4, 2],
  33993. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  33994. [4, 3], [4, 3], [4, 3], [4, 3],
  33995. [4, 3], [4, 3], [4, 3], [4, 3],
  33996. [4, 3], [4, 3], [4, 3], [4, 3],
  33997. [4, 3], [4, 3], [4, 3], [4, 3],
  33998. [4, 3], [4, 3], [4, 3], [4, 3],
  33999. [4, 3], [4, 3], [4, 3], [4, 3],
  34000. [4, 3], [4, 3], [4, 3], [4, 3],
  34001. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  34002. [5, 128], [5, 128], [5, 128], [5, 128],
  34003. [5, 128], [5, 128], [5, 128], [5, 128],
  34004. [5, 128], [5, 128], [5, 128], [5, 128],
  34005. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  34006. [5, 8], [5, 8], [5, 8], [5, 8],
  34007. [5, 8], [5, 8], [5, 8], [5, 8],
  34008. [5, 8], [5, 8], [5, 8], [5, 8],
  34009. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  34010. [5, 9], [5, 9], [5, 9], [5, 9],
  34011. [5, 9], [5, 9], [5, 9], [5, 9],
  34012. [5, 9], [5, 9], [5, 9], [5, 9],
  34013. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  34014. [6, 16], [6, 16], [6, 16], [6, 16],
  34015. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  34016. [6, 17], [6, 17], [6, 17], [6, 17],
  34017. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  34018. [4, 4], [4, 4], [4, 4], [4, 4],
  34019. [4, 4], [4, 4], [4, 4], [4, 4],
  34020. [4, 4], [4, 4], [4, 4], [4, 4],
  34021. [4, 4], [4, 4], [4, 4], [4, 4],
  34022. [4, 4], [4, 4], [4, 4], [4, 4],
  34023. [4, 4], [4, 4], [4, 4], [4, 4],
  34024. [4, 4], [4, 4], [4, 4], [4, 4],
  34025. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  34026. [4, 5], [4, 5], [4, 5], [4, 5],
  34027. [4, 5], [4, 5], [4, 5], [4, 5],
  34028. [4, 5], [4, 5], [4, 5], [4, 5],
  34029. [4, 5], [4, 5], [4, 5], [4, 5],
  34030. [4, 5], [4, 5], [4, 5], [4, 5],
  34031. [4, 5], [4, 5], [4, 5], [4, 5],
  34032. [4, 5], [4, 5], [4, 5], [4, 5],
  34033. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  34034. [6, 14], [6, 14], [6, 14], [6, 14],
  34035. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  34036. [6, 15], [6, 15], [6, 15], [6, 15],
  34037. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  34038. [5, 64], [5, 64], [5, 64], [5, 64],
  34039. [5, 64], [5, 64], [5, 64], [5, 64],
  34040. [5, 64], [5, 64], [5, 64], [5, 64],
  34041. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  34042. [4, 6], [4, 6], [4, 6], [4, 6],
  34043. [4, 6], [4, 6], [4, 6], [4, 6],
  34044. [4, 6], [4, 6], [4, 6], [4, 6],
  34045. [4, 6], [4, 6], [4, 6], [4, 6],
  34046. [4, 6], [4, 6], [4, 6], [4, 6],
  34047. [4, 6], [4, 6], [4, 6], [4, 6],
  34048. [4, 6], [4, 6], [4, 6], [4, 6],
  34049. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  34050. [4, 7], [4, 7], [4, 7], [4, 7],
  34051. [4, 7], [4, 7], [4, 7], [4, 7],
  34052. [4, 7], [4, 7], [4, 7], [4, 7],
  34053. [4, 7], [4, 7], [4, 7], [4, 7],
  34054. [4, 7], [4, 7], [4, 7], [4, 7],
  34055. [4, 7], [4, 7], [4, 7], [4, 7],
  34056. [4, 7], [4, 7], [4, 7], [4, 7]
  34057. ];
  34058. var blackTable1 = [
  34059. [-1, -1], [-1, -1], // 000000000000x
  34060. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  34061. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  34062. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  34063. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  34064. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  34065. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  34066. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  34067. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  34068. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  34069. [12, 1984], [12, 1984], // 000000010010x
  34070. [12, 2048], [12, 2048], // 000000010011x
  34071. [12, 2112], [12, 2112], // 000000010100x
  34072. [12, 2176], [12, 2176], // 000000010101x
  34073. [12, 2240], [12, 2240], // 000000010110x
  34074. [12, 2304], [12, 2304], // 000000010111x
  34075. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  34076. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  34077. [12, 2368], [12, 2368], // 000000011100x
  34078. [12, 2432], [12, 2432], // 000000011101x
  34079. [12, 2496], [12, 2496], // 000000011110x
  34080. [12, 2560], [12, 2560], // 000000011111x
  34081. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  34082. [10, 18], [10, 18], [10, 18], [10, 18],
  34083. [12, 52], [12, 52], // 000000100100x
  34084. [13, 640], // 0000001001010
  34085. [13, 704], // 0000001001011
  34086. [13, 768], // 0000001001100
  34087. [13, 832], // 0000001001101
  34088. [12, 55], [12, 55], // 000000100111x
  34089. [12, 56], [12, 56], // 000000101000x
  34090. [13, 1280], // 0000001010010
  34091. [13, 1344], // 0000001010011
  34092. [13, 1408], // 0000001010100
  34093. [13, 1472], // 0000001010101
  34094. [12, 59], [12, 59], // 000000101011x
  34095. [12, 60], [12, 60], // 000000101100x
  34096. [13, 1536], // 0000001011010
  34097. [13, 1600], // 0000001011011
  34098. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  34099. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  34100. [13, 1664], // 0000001100100
  34101. [13, 1728], // 0000001100101
  34102. [12, 320], [12, 320], // 000000110011x
  34103. [12, 384], [12, 384], // 000000110100x
  34104. [12, 448], [12, 448], // 000000110101x
  34105. [13, 512], // 0000001101100
  34106. [13, 576], // 0000001101101
  34107. [12, 53], [12, 53], // 000000110111x
  34108. [12, 54], [12, 54], // 000000111000x
  34109. [13, 896], // 0000001110010
  34110. [13, 960], // 0000001110011
  34111. [13, 1024], // 0000001110100
  34112. [13, 1088], // 0000001110101
  34113. [13, 1152], // 0000001110110
  34114. [13, 1216], // 0000001110111
  34115. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  34116. [10, 64], [10, 64], [10, 64], [10, 64]
  34117. ];
  34118. var blackTable2 = [
  34119. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  34120. [8, 13], [8, 13], [8, 13], [8, 13],
  34121. [8, 13], [8, 13], [8, 13], [8, 13],
  34122. [8, 13], [8, 13], [8, 13], [8, 13],
  34123. [11, 23], [11, 23], // 00000101000x
  34124. [12, 50], // 000001010010
  34125. [12, 51], // 000001010011
  34126. [12, 44], // 000001010100
  34127. [12, 45], // 000001010101
  34128. [12, 46], // 000001010110
  34129. [12, 47], // 000001010111
  34130. [12, 57], // 000001011000
  34131. [12, 58], // 000001011001
  34132. [12, 61], // 000001011010
  34133. [12, 256], // 000001011011
  34134. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  34135. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  34136. [12, 48], // 000001100100
  34137. [12, 49], // 000001100101
  34138. [12, 62], // 000001100110
  34139. [12, 63], // 000001100111
  34140. [12, 30], // 000001101000
  34141. [12, 31], // 000001101001
  34142. [12, 32], // 000001101010
  34143. [12, 33], // 000001101011
  34144. [12, 40], // 000001101100
  34145. [12, 41], // 000001101101
  34146. [11, 22], [11, 22], // 00000110111x
  34147. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  34148. [8, 14], [8, 14], [8, 14], [8, 14],
  34149. [8, 14], [8, 14], [8, 14], [8, 14],
  34150. [8, 14], [8, 14], [8, 14], [8, 14],
  34151. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  34152. [7, 10], [7, 10], [7, 10], [7, 10],
  34153. [7, 10], [7, 10], [7, 10], [7, 10],
  34154. [7, 10], [7, 10], [7, 10], [7, 10],
  34155. [7, 10], [7, 10], [7, 10], [7, 10],
  34156. [7, 10], [7, 10], [7, 10], [7, 10],
  34157. [7, 10], [7, 10], [7, 10], [7, 10],
  34158. [7, 10], [7, 10], [7, 10], [7, 10],
  34159. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  34160. [7, 11], [7, 11], [7, 11], [7, 11],
  34161. [7, 11], [7, 11], [7, 11], [7, 11],
  34162. [7, 11], [7, 11], [7, 11], [7, 11],
  34163. [7, 11], [7, 11], [7, 11], [7, 11],
  34164. [7, 11], [7, 11], [7, 11], [7, 11],
  34165. [7, 11], [7, 11], [7, 11], [7, 11],
  34166. [7, 11], [7, 11], [7, 11], [7, 11],
  34167. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  34168. [9, 15], [9, 15], [9, 15], [9, 15],
  34169. [12, 128], // 000011001000
  34170. [12, 192], // 000011001001
  34171. [12, 26], // 000011001010
  34172. [12, 27], // 000011001011
  34173. [12, 28], // 000011001100
  34174. [12, 29], // 000011001101
  34175. [11, 19], [11, 19], // 00001100111x
  34176. [11, 20], [11, 20], // 00001101000x
  34177. [12, 34], // 000011010010
  34178. [12, 35], // 000011010011
  34179. [12, 36], // 000011010100
  34180. [12, 37], // 000011010101
  34181. [12, 38], // 000011010110
  34182. [12, 39], // 000011010111
  34183. [11, 21], [11, 21], // 00001101100x
  34184. [12, 42], // 000011011010
  34185. [12, 43], // 000011011011
  34186. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  34187. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  34188. [7, 12], [7, 12], [7, 12], [7, 12],
  34189. [7, 12], [7, 12], [7, 12], [7, 12],
  34190. [7, 12], [7, 12], [7, 12], [7, 12],
  34191. [7, 12], [7, 12], [7, 12], [7, 12],
  34192. [7, 12], [7, 12], [7, 12], [7, 12],
  34193. [7, 12], [7, 12], [7, 12], [7, 12],
  34194. [7, 12], [7, 12], [7, 12], [7, 12]
  34195. ];
  34196. var blackTable3 = [
  34197. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  34198. [6, 9], // 000100
  34199. [6, 8], // 000101
  34200. [5, 7], [5, 7], // 00011x
  34201. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  34202. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  34203. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  34204. [3, 1], [3, 1], [3, 1], [3, 1],
  34205. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  34206. [3, 4], [3, 4], [3, 4], [3, 4],
  34207. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  34208. [2, 3], [2, 3], [2, 3], [2, 3],
  34209. [2, 3], [2, 3], [2, 3], [2, 3],
  34210. [2, 3], [2, 3], [2, 3], [2, 3],
  34211. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  34212. [2, 2], [2, 2], [2, 2], [2, 2],
  34213. [2, 2], [2, 2], [2, 2], [2, 2],
  34214. [2, 2], [2, 2], [2, 2], [2, 2]
  34215. ];
  34216. function CCITTFaxStream(str, maybeLength, params) {
  34217. this.str = str;
  34218. this.dict = str.dict;
  34219. params = params || Dict.empty;
  34220. this.encoding = params.get('K') || 0;
  34221. this.eoline = params.get('EndOfLine') || false;
  34222. this.byteAlign = params.get('EncodedByteAlign') || false;
  34223. this.columns = params.get('Columns') || 1728;
  34224. this.rows = params.get('Rows') || 0;
  34225. var eoblock = params.get('EndOfBlock');
  34226. if (eoblock === null || eoblock === undefined) {
  34227. eoblock = true;
  34228. }
  34229. this.eoblock = eoblock;
  34230. this.black = params.get('BlackIs1') || false;
  34231. this.codingLine = new Uint32Array(this.columns + 1);
  34232. this.refLine = new Uint32Array(this.columns + 2);
  34233. this.codingLine[0] = this.columns;
  34234. this.codingPos = 0;
  34235. this.row = 0;
  34236. this.nextLine2D = this.encoding < 0;
  34237. this.inputBits = 0;
  34238. this.inputBuf = 0;
  34239. this.outputBits = 0;
  34240. var code1;
  34241. while ((code1 = this.lookBits(12)) === 0) {
  34242. this.eatBits(1);
  34243. }
  34244. if (code1 === 1) {
  34245. this.eatBits(12);
  34246. }
  34247. if (this.encoding > 0) {
  34248. this.nextLine2D = !this.lookBits(1);
  34249. this.eatBits(1);
  34250. }
  34251. DecodeStream.call(this, maybeLength);
  34252. }
  34253. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  34254. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  34255. while (!this.eof) {
  34256. var c = this.lookChar();
  34257. this.ensureBuffer(this.bufferLength + 1);
  34258. this.buffer[this.bufferLength++] = c;
  34259. }
  34260. };
  34261. CCITTFaxStream.prototype.addPixels =
  34262. function ccittFaxStreamAddPixels(a1, blackPixels) {
  34263. var codingLine = this.codingLine;
  34264. var codingPos = this.codingPos;
  34265. if (a1 > codingLine[codingPos]) {
  34266. if (a1 > this.columns) {
  34267. info('row is wrong length');
  34268. this.err = true;
  34269. a1 = this.columns;
  34270. }
  34271. if ((codingPos & 1) ^ blackPixels) {
  34272. ++codingPos;
  34273. }
  34274. codingLine[codingPos] = a1;
  34275. }
  34276. this.codingPos = codingPos;
  34277. };
  34278. CCITTFaxStream.prototype.addPixelsNeg =
  34279. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  34280. var codingLine = this.codingLine;
  34281. var codingPos = this.codingPos;
  34282. if (a1 > codingLine[codingPos]) {
  34283. if (a1 > this.columns) {
  34284. info('row is wrong length');
  34285. this.err = true;
  34286. a1 = this.columns;
  34287. }
  34288. if ((codingPos & 1) ^ blackPixels) {
  34289. ++codingPos;
  34290. }
  34291. codingLine[codingPos] = a1;
  34292. } else if (a1 < codingLine[codingPos]) {
  34293. if (a1 < 0) {
  34294. info('invalid code');
  34295. this.err = true;
  34296. a1 = 0;
  34297. }
  34298. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  34299. --codingPos;
  34300. }
  34301. codingLine[codingPos] = a1;
  34302. }
  34303. this.codingPos = codingPos;
  34304. };
  34305. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  34306. var refLine = this.refLine;
  34307. var codingLine = this.codingLine;
  34308. var columns = this.columns;
  34309. var refPos, blackPixels, bits, i;
  34310. if (this.outputBits === 0) {
  34311. if (this.eof) {
  34312. return null;
  34313. }
  34314. this.err = false;
  34315. var code1, code2, code3;
  34316. if (this.nextLine2D) {
  34317. for (i = 0; codingLine[i] < columns; ++i) {
  34318. refLine[i] = codingLine[i];
  34319. }
  34320. refLine[i++] = columns;
  34321. refLine[i] = columns;
  34322. codingLine[0] = 0;
  34323. this.codingPos = 0;
  34324. refPos = 0;
  34325. blackPixels = 0;
  34326. while (codingLine[this.codingPos] < columns) {
  34327. code1 = this.getTwoDimCode();
  34328. switch (code1) {
  34329. case twoDimPass:
  34330. this.addPixels(refLine[refPos + 1], blackPixels);
  34331. if (refLine[refPos + 1] < columns) {
  34332. refPos += 2;
  34333. }
  34334. break;
  34335. case twoDimHoriz:
  34336. code1 = code2 = 0;
  34337. if (blackPixels) {
  34338. do {
  34339. code1 += (code3 = this.getBlackCode());
  34340. } while (code3 >= 64);
  34341. do {
  34342. code2 += (code3 = this.getWhiteCode());
  34343. } while (code3 >= 64);
  34344. } else {
  34345. do {
  34346. code1 += (code3 = this.getWhiteCode());
  34347. } while (code3 >= 64);
  34348. do {
  34349. code2 += (code3 = this.getBlackCode());
  34350. } while (code3 >= 64);
  34351. }
  34352. this.addPixels(codingLine[this.codingPos] +
  34353. code1, blackPixels);
  34354. if (codingLine[this.codingPos] < columns) {
  34355. this.addPixels(codingLine[this.codingPos] + code2,
  34356. blackPixels ^ 1);
  34357. }
  34358. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34359. refLine[refPos] < columns) {
  34360. refPos += 2;
  34361. }
  34362. break;
  34363. case twoDimVertR3:
  34364. this.addPixels(refLine[refPos] + 3, blackPixels);
  34365. blackPixels ^= 1;
  34366. if (codingLine[this.codingPos] < columns) {
  34367. ++refPos;
  34368. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34369. refLine[refPos] < columns) {
  34370. refPos += 2;
  34371. }
  34372. }
  34373. break;
  34374. case twoDimVertR2:
  34375. this.addPixels(refLine[refPos] + 2, blackPixels);
  34376. blackPixels ^= 1;
  34377. if (codingLine[this.codingPos] < columns) {
  34378. ++refPos;
  34379. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34380. refLine[refPos] < columns) {
  34381. refPos += 2;
  34382. }
  34383. }
  34384. break;
  34385. case twoDimVertR1:
  34386. this.addPixels(refLine[refPos] + 1, blackPixels);
  34387. blackPixels ^= 1;
  34388. if (codingLine[this.codingPos] < columns) {
  34389. ++refPos;
  34390. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34391. refLine[refPos] < columns) {
  34392. refPos += 2;
  34393. }
  34394. }
  34395. break;
  34396. case twoDimVert0:
  34397. this.addPixels(refLine[refPos], blackPixels);
  34398. blackPixels ^= 1;
  34399. if (codingLine[this.codingPos] < columns) {
  34400. ++refPos;
  34401. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34402. refLine[refPos] < columns) {
  34403. refPos += 2;
  34404. }
  34405. }
  34406. break;
  34407. case twoDimVertL3:
  34408. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  34409. blackPixels ^= 1;
  34410. if (codingLine[this.codingPos] < columns) {
  34411. if (refPos > 0) {
  34412. --refPos;
  34413. } else {
  34414. ++refPos;
  34415. }
  34416. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34417. refLine[refPos] < columns) {
  34418. refPos += 2;
  34419. }
  34420. }
  34421. break;
  34422. case twoDimVertL2:
  34423. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  34424. blackPixels ^= 1;
  34425. if (codingLine[this.codingPos] < columns) {
  34426. if (refPos > 0) {
  34427. --refPos;
  34428. } else {
  34429. ++refPos;
  34430. }
  34431. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34432. refLine[refPos] < columns) {
  34433. refPos += 2;
  34434. }
  34435. }
  34436. break;
  34437. case twoDimVertL1:
  34438. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  34439. blackPixels ^= 1;
  34440. if (codingLine[this.codingPos] < columns) {
  34441. if (refPos > 0) {
  34442. --refPos;
  34443. } else {
  34444. ++refPos;
  34445. }
  34446. while (refLine[refPos] <= codingLine[this.codingPos] &&
  34447. refLine[refPos] < columns) {
  34448. refPos += 2;
  34449. }
  34450. }
  34451. break;
  34452. case EOF:
  34453. this.addPixels(columns, 0);
  34454. this.eof = true;
  34455. break;
  34456. default:
  34457. info('bad 2d code');
  34458. this.addPixels(columns, 0);
  34459. this.err = true;
  34460. }
  34461. }
  34462. } else {
  34463. codingLine[0] = 0;
  34464. this.codingPos = 0;
  34465. blackPixels = 0;
  34466. while (codingLine[this.codingPos] < columns) {
  34467. code1 = 0;
  34468. if (blackPixels) {
  34469. do {
  34470. code1 += (code3 = this.getBlackCode());
  34471. } while (code3 >= 64);
  34472. } else {
  34473. do {
  34474. code1 += (code3 = this.getWhiteCode());
  34475. } while (code3 >= 64);
  34476. }
  34477. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  34478. blackPixels ^= 1;
  34479. }
  34480. }
  34481. var gotEOL = false;
  34482. if (!this.eoblock && this.row === this.rows - 1) {
  34483. this.eof = true;
  34484. } else if (this.eoline || !this.byteAlign) {
  34485. code1 = this.lookBits(12);
  34486. if (this.eoline) {
  34487. while (code1 !== EOF && code1 !== 1) {
  34488. this.eatBits(1);
  34489. code1 = this.lookBits(12);
  34490. }
  34491. } else {
  34492. while (code1 === 0) {
  34493. this.eatBits(1);
  34494. code1 = this.lookBits(12);
  34495. }
  34496. }
  34497. if (code1 === 1) {
  34498. this.eatBits(12);
  34499. gotEOL = true;
  34500. }
  34501. }
  34502. if (this.byteAlign && !gotEOL) {
  34503. this.inputBits &= ~7;
  34504. }
  34505. if (!this.eof && this.encoding > 0) {
  34506. this.nextLine2D = !this.lookBits(1);
  34507. this.eatBits(1);
  34508. }
  34509. if (this.eoblock && !this.eoline && this.byteAlign) {
  34510. code1 = this.lookBits(12);
  34511. if (code1 === 1) {
  34512. this.eatBits(12);
  34513. if (this.encoding > 0) {
  34514. this.lookBits(1);
  34515. this.eatBits(1);
  34516. }
  34517. if (this.encoding >= 0) {
  34518. for (i = 0; i < 4; ++i) {
  34519. code1 = this.lookBits(12);
  34520. if (code1 !== 1) {
  34521. info('bad rtc code: ' + code1);
  34522. }
  34523. this.eatBits(12);
  34524. if (this.encoding > 0) {
  34525. this.lookBits(1);
  34526. this.eatBits(1);
  34527. }
  34528. }
  34529. }
  34530. this.eof = true;
  34531. }
  34532. } else if (this.err && this.eoline) {
  34533. while (true) {
  34534. code1 = this.lookBits(13);
  34535. if (code1 === EOF) {
  34536. this.eof = true;
  34537. return null;
  34538. }
  34539. if ((code1 >> 1) === 1) {
  34540. break;
  34541. }
  34542. this.eatBits(1);
  34543. }
  34544. this.eatBits(12);
  34545. if (this.encoding > 0) {
  34546. this.eatBits(1);
  34547. this.nextLine2D = !(code1 & 1);
  34548. }
  34549. }
  34550. if (codingLine[0] > 0) {
  34551. this.outputBits = codingLine[this.codingPos = 0];
  34552. } else {
  34553. this.outputBits = codingLine[this.codingPos = 1];
  34554. }
  34555. this.row++;
  34556. }
  34557. var c;
  34558. if (this.outputBits >= 8) {
  34559. c = (this.codingPos & 1) ? 0 : 0xFF;
  34560. this.outputBits -= 8;
  34561. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  34562. this.codingPos++;
  34563. this.outputBits = (codingLine[this.codingPos] -
  34564. codingLine[this.codingPos - 1]);
  34565. }
  34566. } else {
  34567. bits = 8;
  34568. c = 0;
  34569. do {
  34570. if (this.outputBits > bits) {
  34571. c <<= bits;
  34572. if (!(this.codingPos & 1)) {
  34573. c |= 0xFF >> (8 - bits);
  34574. }
  34575. this.outputBits -= bits;
  34576. bits = 0;
  34577. } else {
  34578. c <<= this.outputBits;
  34579. if (!(this.codingPos & 1)) {
  34580. c |= 0xFF >> (8 - this.outputBits);
  34581. }
  34582. bits -= this.outputBits;
  34583. this.outputBits = 0;
  34584. if (codingLine[this.codingPos] < columns) {
  34585. this.codingPos++;
  34586. this.outputBits = (codingLine[this.codingPos] -
  34587. codingLine[this.codingPos - 1]);
  34588. } else if (bits > 0) {
  34589. c <<= bits;
  34590. bits = 0;
  34591. }
  34592. }
  34593. } while (bits);
  34594. }
  34595. if (this.black) {
  34596. c ^= 0xFF;
  34597. }
  34598. return c;
  34599. };
  34600. // This functions returns the code found from the table.
  34601. // The start and end parameters set the boundaries for searching the table.
  34602. // The limit parameter is optional. Function returns an array with three
  34603. // values. The first array element indicates whether a valid code is being
  34604. // returned. The second array element is the actual code. The third array
  34605. // element indicates whether EOF was reached.
  34606. CCITTFaxStream.prototype.findTableCode =
  34607. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  34608. var limitValue = limit || 0;
  34609. for (var i = start; i <= end; ++i) {
  34610. var code = this.lookBits(i);
  34611. if (code === EOF) {
  34612. return [true, 1, false];
  34613. }
  34614. if (i < end) {
  34615. code <<= end - i;
  34616. }
  34617. if (!limitValue || code >= limitValue) {
  34618. var p = table[code - limitValue];
  34619. if (p[0] === i) {
  34620. this.eatBits(i);
  34621. return [true, p[1], true];
  34622. }
  34623. }
  34624. }
  34625. return [false, 0, false];
  34626. };
  34627. CCITTFaxStream.prototype.getTwoDimCode =
  34628. function ccittFaxStreamGetTwoDimCode() {
  34629. var code = 0;
  34630. var p;
  34631. if (this.eoblock) {
  34632. code = this.lookBits(7);
  34633. p = twoDimTable[code];
  34634. if (p && p[0] > 0) {
  34635. this.eatBits(p[0]);
  34636. return p[1];
  34637. }
  34638. } else {
  34639. var result = this.findTableCode(1, 7, twoDimTable);
  34640. if (result[0] && result[2]) {
  34641. return result[1];
  34642. }
  34643. }
  34644. info('Bad two dim code');
  34645. return EOF;
  34646. };
  34647. CCITTFaxStream.prototype.getWhiteCode =
  34648. function ccittFaxStreamGetWhiteCode() {
  34649. var code = 0;
  34650. var p;
  34651. if (this.eoblock) {
  34652. code = this.lookBits(12);
  34653. if (code === EOF) {
  34654. return 1;
  34655. }
  34656. if ((code >> 5) === 0) {
  34657. p = whiteTable1[code];
  34658. } else {
  34659. p = whiteTable2[code >> 3];
  34660. }
  34661. if (p[0] > 0) {
  34662. this.eatBits(p[0]);
  34663. return p[1];
  34664. }
  34665. } else {
  34666. var result = this.findTableCode(1, 9, whiteTable2);
  34667. if (result[0]) {
  34668. return result[1];
  34669. }
  34670. result = this.findTableCode(11, 12, whiteTable1);
  34671. if (result[0]) {
  34672. return result[1];
  34673. }
  34674. }
  34675. info('bad white code');
  34676. this.eatBits(1);
  34677. return 1;
  34678. };
  34679. CCITTFaxStream.prototype.getBlackCode =
  34680. function ccittFaxStreamGetBlackCode() {
  34681. var code, p;
  34682. if (this.eoblock) {
  34683. code = this.lookBits(13);
  34684. if (code === EOF) {
  34685. return 1;
  34686. }
  34687. if ((code >> 7) === 0) {
  34688. p = blackTable1[code];
  34689. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  34690. p = blackTable2[(code >> 1) - 64];
  34691. } else {
  34692. p = blackTable3[code >> 7];
  34693. }
  34694. if (p[0] > 0) {
  34695. this.eatBits(p[0]);
  34696. return p[1];
  34697. }
  34698. } else {
  34699. var result = this.findTableCode(2, 6, blackTable3);
  34700. if (result[0]) {
  34701. return result[1];
  34702. }
  34703. result = this.findTableCode(7, 12, blackTable2, 64);
  34704. if (result[0]) {
  34705. return result[1];
  34706. }
  34707. result = this.findTableCode(10, 13, blackTable1);
  34708. if (result[0]) {
  34709. return result[1];
  34710. }
  34711. }
  34712. info('bad black code');
  34713. this.eatBits(1);
  34714. return 1;
  34715. };
  34716. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  34717. var c;
  34718. while (this.inputBits < n) {
  34719. if ((c = this.str.getByte()) === -1) {
  34720. if (this.inputBits === 0) {
  34721. return EOF;
  34722. }
  34723. return ((this.inputBuf << (n - this.inputBits)) &
  34724. (0xFFFF >> (16 - n)));
  34725. }
  34726. this.inputBuf = (this.inputBuf << 8) + c;
  34727. this.inputBits += 8;
  34728. }
  34729. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  34730. };
  34731. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  34732. if ((this.inputBits -= n) < 0) {
  34733. this.inputBits = 0;
  34734. }
  34735. };
  34736. return CCITTFaxStream;
  34737. })();
  34738. var LZWStream = (function LZWStreamClosure() {
  34739. function LZWStream(str, maybeLength, earlyChange) {
  34740. this.str = str;
  34741. this.dict = str.dict;
  34742. this.cachedData = 0;
  34743. this.bitsCached = 0;
  34744. var maxLzwDictionarySize = 4096;
  34745. var lzwState = {
  34746. earlyChange: earlyChange,
  34747. codeLength: 9,
  34748. nextCode: 258,
  34749. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  34750. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  34751. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  34752. currentSequence: new Uint8Array(maxLzwDictionarySize),
  34753. currentSequenceLength: 0
  34754. };
  34755. for (var i = 0; i < 256; ++i) {
  34756. lzwState.dictionaryValues[i] = i;
  34757. lzwState.dictionaryLengths[i] = 1;
  34758. }
  34759. this.lzwState = lzwState;
  34760. DecodeStream.call(this, maybeLength);
  34761. }
  34762. LZWStream.prototype = Object.create(DecodeStream.prototype);
  34763. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  34764. var bitsCached = this.bitsCached;
  34765. var cachedData = this.cachedData;
  34766. while (bitsCached < n) {
  34767. var c = this.str.getByte();
  34768. if (c === -1) {
  34769. this.eof = true;
  34770. return null;
  34771. }
  34772. cachedData = (cachedData << 8) | c;
  34773. bitsCached += 8;
  34774. }
  34775. this.bitsCached = (bitsCached -= n);
  34776. this.cachedData = cachedData;
  34777. this.lastCode = null;
  34778. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  34779. };
  34780. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  34781. var blockSize = 512;
  34782. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  34783. var i, j, q;
  34784. var lzwState = this.lzwState;
  34785. if (!lzwState) {
  34786. return; // eof was found
  34787. }
  34788. var earlyChange = lzwState.earlyChange;
  34789. var nextCode = lzwState.nextCode;
  34790. var dictionaryValues = lzwState.dictionaryValues;
  34791. var dictionaryLengths = lzwState.dictionaryLengths;
  34792. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  34793. var codeLength = lzwState.codeLength;
  34794. var prevCode = lzwState.prevCode;
  34795. var currentSequence = lzwState.currentSequence;
  34796. var currentSequenceLength = lzwState.currentSequenceLength;
  34797. var decodedLength = 0;
  34798. var currentBufferLength = this.bufferLength;
  34799. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  34800. for (i = 0; i < blockSize; i++) {
  34801. var code = this.readBits(codeLength);
  34802. var hasPrev = currentSequenceLength > 0;
  34803. if (code < 256) {
  34804. currentSequence[0] = code;
  34805. currentSequenceLength = 1;
  34806. } else if (code >= 258) {
  34807. if (code < nextCode) {
  34808. currentSequenceLength = dictionaryLengths[code];
  34809. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  34810. currentSequence[j] = dictionaryValues[q];
  34811. q = dictionaryPrevCodes[q];
  34812. }
  34813. } else {
  34814. currentSequence[currentSequenceLength++] = currentSequence[0];
  34815. }
  34816. } else if (code === 256) {
  34817. codeLength = 9;
  34818. nextCode = 258;
  34819. currentSequenceLength = 0;
  34820. continue;
  34821. } else {
  34822. this.eof = true;
  34823. delete this.lzwState;
  34824. break;
  34825. }
  34826. if (hasPrev) {
  34827. dictionaryPrevCodes[nextCode] = prevCode;
  34828. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  34829. dictionaryValues[nextCode] = currentSequence[0];
  34830. nextCode++;
  34831. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  34832. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  34833. 0.6931471805599453 + 1, 12) | 0;
  34834. }
  34835. prevCode = code;
  34836. decodedLength += currentSequenceLength;
  34837. if (estimatedDecodedSize < decodedLength) {
  34838. do {
  34839. estimatedDecodedSize += decodedSizeDelta;
  34840. } while (estimatedDecodedSize < decodedLength);
  34841. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  34842. }
  34843. for (j = 0; j < currentSequenceLength; j++) {
  34844. buffer[currentBufferLength++] = currentSequence[j];
  34845. }
  34846. }
  34847. lzwState.nextCode = nextCode;
  34848. lzwState.codeLength = codeLength;
  34849. lzwState.prevCode = prevCode;
  34850. lzwState.currentSequenceLength = currentSequenceLength;
  34851. this.bufferLength = currentBufferLength;
  34852. };
  34853. return LZWStream;
  34854. })();
  34855. var NullStream = (function NullStreamClosure() {
  34856. function NullStream() {
  34857. Stream.call(this, new Uint8Array(0));
  34858. }
  34859. NullStream.prototype = Stream.prototype;
  34860. return NullStream;
  34861. })();
  34862. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  34863. setup: function wphSetup(handler) {
  34864. var pdfManager;
  34865. function loadDocument(recoveryMode) {
  34866. var loadDocumentCapability = createPromiseCapability();
  34867. var parseSuccess = function parseSuccess() {
  34868. var numPagesPromise = pdfManager.ensureDoc('numPages');
  34869. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  34870. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  34871. Promise.all([numPagesPromise, fingerprintPromise,
  34872. encryptedPromise]).then(function onDocReady(results) {
  34873. var doc = {
  34874. numPages: results[0],
  34875. fingerprint: results[1],
  34876. encrypted: !!results[2],
  34877. };
  34878. loadDocumentCapability.resolve(doc);
  34879. },
  34880. parseFailure);
  34881. };
  34882. var parseFailure = function parseFailure(e) {
  34883. loadDocumentCapability.reject(e);
  34884. };
  34885. pdfManager.ensureDoc('checkHeader', []).then(function() {
  34886. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  34887. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  34888. parseSuccess, parseFailure);
  34889. }, parseFailure);
  34890. }, parseFailure);
  34891. return loadDocumentCapability.promise;
  34892. }
  34893. function getPdfManager(data) {
  34894. var pdfManagerCapability = createPromiseCapability();
  34895. var source = data.source;
  34896. var disableRange = data.disableRange;
  34897. if (source.data) {
  34898. try {
  34899. pdfManager = new LocalPdfManager(source.data, source.password);
  34900. pdfManagerCapability.resolve();
  34901. } catch (ex) {
  34902. pdfManagerCapability.reject(ex);
  34903. }
  34904. return pdfManagerCapability.promise;
  34905. } else if (source.chunkedViewerLoading) {
  34906. try {
  34907. pdfManager = new NetworkPdfManager(source, handler);
  34908. pdfManagerCapability.resolve();
  34909. } catch (ex) {
  34910. pdfManagerCapability.reject(ex);
  34911. }
  34912. return pdfManagerCapability.promise;
  34913. }
  34914. var networkManager = new NetworkManager(source.url, {
  34915. httpHeaders: source.httpHeaders,
  34916. withCredentials: source.withCredentials
  34917. });
  34918. var fullRequestXhrId = networkManager.requestFull({
  34919. onHeadersReceived: function onHeadersReceived() {
  34920. if (disableRange) {
  34921. return;
  34922. }
  34923. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  34924. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  34925. return;
  34926. }
  34927. var contentEncoding =
  34928. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  34929. if (contentEncoding !== 'identity') {
  34930. return;
  34931. }
  34932. var length = fullRequestXhr.getResponseHeader('Content-Length');
  34933. length = parseInt(length, 10);
  34934. if (!isInt(length)) {
  34935. return;
  34936. }
  34937. source.length = length;
  34938. if (length <= 2 * RANGE_CHUNK_SIZE) {
  34939. // The file size is smaller than the size of two chunks, so it does
  34940. // not make any sense to abort the request and retry with a range
  34941. // request.
  34942. return;
  34943. }
  34944. // NOTE: by cancelling the full request, and then issuing range
  34945. // requests, there will be an issue for sites where you can only
  34946. // request the pdf once. However, if this is the case, then the
  34947. // server should not be returning that it can support range requests.
  34948. networkManager.abortRequest(fullRequestXhrId);
  34949. try {
  34950. pdfManager = new NetworkPdfManager(source, handler);
  34951. pdfManagerCapability.resolve(pdfManager);
  34952. } catch (ex) {
  34953. pdfManagerCapability.reject(ex);
  34954. }
  34955. },
  34956. onDone: function onDone(args) {
  34957. // the data is array, instantiating directly from it
  34958. try {
  34959. pdfManager = new LocalPdfManager(args.chunk, source.password);
  34960. pdfManagerCapability.resolve();
  34961. } catch (ex) {
  34962. pdfManagerCapability.reject(ex);
  34963. }
  34964. },
  34965. onError: function onError(status) {
  34966. if (status === 404) {
  34967. var exception = new MissingPDFException('Missing PDF "' +
  34968. source.url + '".');
  34969. handler.send('MissingPDF', { exception: exception });
  34970. } else {
  34971. handler.send('DocError', 'Unexpected server response (' +
  34972. status + ') while retrieving PDF "' +
  34973. source.url + '".');
  34974. }
  34975. },
  34976. onProgress: function onProgress(evt) {
  34977. handler.send('DocProgress', {
  34978. loaded: evt.loaded,
  34979. total: evt.lengthComputable ? evt.total : source.length
  34980. });
  34981. }
  34982. });
  34983. return pdfManagerCapability.promise;
  34984. }
  34985. handler.on('test', function wphSetupTest(data) {
  34986. // check if Uint8Array can be sent to worker
  34987. if (!(data instanceof Uint8Array)) {
  34988. handler.send('test', false);
  34989. return;
  34990. }
  34991. // making sure postMessage transfers are working
  34992. var supportTransfers = data[0] === 255;
  34993. handler.postMessageTransfers = supportTransfers;
  34994. // check if the response property is supported by xhr
  34995. var xhr = new XMLHttpRequest();
  34996. var responseExists = 'response' in xhr;
  34997. // check if the property is actually implemented
  34998. try {
  34999. var dummy = xhr.responseType;
  35000. } catch (e) {
  35001. responseExists = false;
  35002. }
  35003. if (!responseExists) {
  35004. handler.send('test', false);
  35005. return;
  35006. }
  35007. handler.send('test', {
  35008. supportTypedArray: true,
  35009. supportTransfers: supportTransfers
  35010. });
  35011. });
  35012. handler.on('GetDocRequest', function wphSetupDoc(data) {
  35013. var onSuccess = function(doc) {
  35014. handler.send('GetDoc', { pdfInfo: doc });
  35015. };
  35016. var onFailure = function(e) {
  35017. if (e instanceof PasswordException) {
  35018. if (e.code === PasswordResponses.NEED_PASSWORD) {
  35019. handler.send('NeedPassword', {
  35020. exception: e
  35021. });
  35022. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  35023. handler.send('IncorrectPassword', {
  35024. exception: e
  35025. });
  35026. }
  35027. } else if (e instanceof InvalidPDFException) {
  35028. handler.send('InvalidPDF', {
  35029. exception: e
  35030. });
  35031. } else if (e instanceof MissingPDFException) {
  35032. handler.send('MissingPDF', {
  35033. exception: e
  35034. });
  35035. } else {
  35036. handler.send('UnknownError', {
  35037. exception: new UnknownErrorException(e.message, e.toString())
  35038. });
  35039. }
  35040. };
  35041. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  35042. -1 : data.maxImageSize;
  35043. PDFJS.disableFontFace = data.disableFontFace;
  35044. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  35045. PDFJS.verbosity = data.verbosity;
  35046. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  35047. null : data.cMapUrl;
  35048. PDFJS.cMapPacked = data.cMapPacked === true;
  35049. getPdfManager(data).then(function () {
  35050. pdfManager.onLoadedStream().then(function(stream) {
  35051. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  35052. });
  35053. }).then(function pdfManagerReady() {
  35054. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  35055. // Try again with recoveryMode == true
  35056. if (!(ex instanceof XRefParseException)) {
  35057. if (ex instanceof PasswordException) {
  35058. // after password exception prepare to receive a new password
  35059. // to repeat loading
  35060. pdfManager.passwordChanged().then(pdfManagerReady);
  35061. }
  35062. onFailure(ex);
  35063. return;
  35064. }
  35065. pdfManager.requestLoadedStream();
  35066. pdfManager.onLoadedStream().then(function() {
  35067. loadDocument(true).then(onSuccess, onFailure);
  35068. });
  35069. }, onFailure);
  35070. }, onFailure);
  35071. });
  35072. handler.on('GetPage', function wphSetupGetPage(data) {
  35073. return pdfManager.getPage(data.pageIndex).then(function(page) {
  35074. var rotatePromise = pdfManager.ensure(page, 'rotate');
  35075. var refPromise = pdfManager.ensure(page, 'ref');
  35076. var viewPromise = pdfManager.ensure(page, 'view');
  35077. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  35078. function(results) {
  35079. return {
  35080. rotate: results[0],
  35081. ref: results[1],
  35082. view: results[2]
  35083. };
  35084. });
  35085. });
  35086. });
  35087. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  35088. var ref = new Ref(data.ref.num, data.ref.gen);
  35089. var catalog = pdfManager.pdfDocument.catalog;
  35090. return catalog.getPageIndex(ref);
  35091. });
  35092. handler.on('GetDestinations',
  35093. function wphSetupGetDestinations(data) {
  35094. return pdfManager.ensureCatalog('destinations');
  35095. }
  35096. );
  35097. handler.on('GetAttachments',
  35098. function wphSetupGetAttachments(data) {
  35099. return pdfManager.ensureCatalog('attachments');
  35100. }
  35101. );
  35102. handler.on('GetJavaScript',
  35103. function wphSetupGetJavaScript(data) {
  35104. return pdfManager.ensureCatalog('javaScript');
  35105. }
  35106. );
  35107. handler.on('GetOutline',
  35108. function wphSetupGetOutline(data) {
  35109. return pdfManager.ensureCatalog('documentOutline');
  35110. }
  35111. );
  35112. handler.on('GetMetadata',
  35113. function wphSetupGetMetadata(data) {
  35114. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  35115. pdfManager.ensureCatalog('metadata')]);
  35116. }
  35117. );
  35118. handler.on('GetData', function wphSetupGetData(data) {
  35119. pdfManager.requestLoadedStream();
  35120. return pdfManager.onLoadedStream().then(function(stream) {
  35121. return stream.bytes;
  35122. });
  35123. });
  35124. handler.on('GetStats',
  35125. function wphSetupGetStats(data) {
  35126. return pdfManager.pdfDocument.xref.stats;
  35127. }
  35128. );
  35129. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  35130. pdfManager.updatePassword(data);
  35131. });
  35132. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  35133. return pdfManager.getPage(data.pageIndex).then(function(page) {
  35134. return pdfManager.ensure(page, 'getAnnotationsData', []);
  35135. });
  35136. });
  35137. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  35138. pdfManager.getPage(data.pageIndex).then(function(page) {
  35139. var pageNum = data.pageIndex + 1;
  35140. var start = Date.now();
  35141. // Pre compile the pdf page and fetch the fonts/images.
  35142. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  35143. info('page=' + pageNum + ' - getOperatorList: time=' +
  35144. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  35145. }, function(e) {
  35146. var minimumStackMessage =
  35147. 'worker.js: while trying to getPage() and getOperatorList()';
  35148. var wrappedException;
  35149. // Turn the error into an obj that can be serialized
  35150. if (typeof e === 'string') {
  35151. wrappedException = {
  35152. message: e,
  35153. stack: minimumStackMessage
  35154. };
  35155. } else if (typeof e === 'object') {
  35156. wrappedException = {
  35157. message: e.message || e.toString(),
  35158. stack: e.stack || minimumStackMessage
  35159. };
  35160. } else {
  35161. wrappedException = {
  35162. message: 'Unknown exception type: ' + (typeof e),
  35163. stack: minimumStackMessage
  35164. };
  35165. }
  35166. handler.send('PageError', {
  35167. pageNum: pageNum,
  35168. error: wrappedException,
  35169. intent: data.intent
  35170. });
  35171. });
  35172. });
  35173. }, this);
  35174. handler.on('GetTextContent', function wphExtractText(data) {
  35175. return pdfManager.getPage(data.pageIndex).then(function(page) {
  35176. var pageNum = data.pageIndex + 1;
  35177. var start = Date.now();
  35178. return page.extractTextContent().then(function(textContent) {
  35179. info('text indexing: page=' + pageNum + ' - time=' +
  35180. (Date.now() - start) + 'ms');
  35181. return textContent;
  35182. });
  35183. });
  35184. });
  35185. handler.on('Cleanup', function wphCleanup(data) {
  35186. return pdfManager.cleanup();
  35187. });
  35188. handler.on('Terminate', function wphTerminate(data) {
  35189. pdfManager.terminate();
  35190. });
  35191. }
  35192. };
  35193. var consoleTimer = {};
  35194. var workerConsole = {
  35195. log: function log() {
  35196. var args = Array.prototype.slice.call(arguments);
  35197. globalScope.postMessage({
  35198. action: 'console_log',
  35199. data: args
  35200. });
  35201. },
  35202. error: function error() {
  35203. var args = Array.prototype.slice.call(arguments);
  35204. globalScope.postMessage({
  35205. action: 'console_error',
  35206. data: args
  35207. });
  35208. throw 'pdf.js execution error';
  35209. },
  35210. time: function time(name) {
  35211. consoleTimer[name] = Date.now();
  35212. },
  35213. timeEnd: function timeEnd(name) {
  35214. var time = consoleTimer[name];
  35215. if (!time) {
  35216. error('Unknown timer name ' + name);
  35217. }
  35218. this.log('Timer:', name, Date.now() - time);
  35219. }
  35220. };
  35221. // Worker thread?
  35222. if (typeof window === 'undefined') {
  35223. if (!('console' in globalScope)) {
  35224. globalScope.console = workerConsole;
  35225. }
  35226. // Listen for unsupported features so we can pass them on to the main thread.
  35227. PDFJS.UnsupportedManager.listen(function (msg) {
  35228. globalScope.postMessage({
  35229. action: '_unsupported_feature',
  35230. data: msg
  35231. });
  35232. });
  35233. var handler = new MessageHandler('worker_processor', this);
  35234. WorkerMessageHandler.setup(handler);
  35235. }
  35236. /* This class implements the QM Coder decoding as defined in
  35237. * JPEG 2000 Part I Final Committee Draft Version 1.0
  35238. * Annex C.3 Arithmetic decoding procedure
  35239. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  35240. *
  35241. * The arithmetic decoder is used in conjunction with context models to decode
  35242. * JPEG2000 and JBIG2 streams.
  35243. */
  35244. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  35245. // Table C-2
  35246. var QeTable = [
  35247. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  35248. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  35249. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  35250. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  35251. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  35252. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  35253. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  35254. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  35255. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  35256. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  35257. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  35258. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  35259. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  35260. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  35261. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  35262. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  35263. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  35264. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  35265. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  35266. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  35267. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  35268. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  35269. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  35270. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  35271. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  35272. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  35273. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  35274. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  35275. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  35276. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  35277. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  35278. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  35279. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  35280. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  35281. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  35282. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  35283. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  35284. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  35285. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  35286. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  35287. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  35288. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  35289. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  35290. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  35291. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  35292. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  35293. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  35294. ];
  35295. // C.3.5 Initialisation of the decoder (INITDEC)
  35296. function ArithmeticDecoder(data, start, end) {
  35297. this.data = data;
  35298. this.bp = start;
  35299. this.dataEnd = end;
  35300. this.chigh = data[start];
  35301. this.clow = 0;
  35302. this.byteIn();
  35303. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  35304. this.clow = (this.clow << 7) & 0xFFFF;
  35305. this.ct -= 7;
  35306. this.a = 0x8000;
  35307. }
  35308. ArithmeticDecoder.prototype = {
  35309. // C.3.4 Compressed data input (BYTEIN)
  35310. byteIn: function ArithmeticDecoder_byteIn() {
  35311. var data = this.data;
  35312. var bp = this.bp;
  35313. if (data[bp] === 0xFF) {
  35314. var b1 = data[bp + 1];
  35315. if (b1 > 0x8F) {
  35316. this.clow += 0xFF00;
  35317. this.ct = 8;
  35318. } else {
  35319. bp++;
  35320. this.clow += (data[bp] << 9);
  35321. this.ct = 7;
  35322. this.bp = bp;
  35323. }
  35324. } else {
  35325. bp++;
  35326. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  35327. this.ct = 8;
  35328. this.bp = bp;
  35329. }
  35330. if (this.clow > 0xFFFF) {
  35331. this.chigh += (this.clow >> 16);
  35332. this.clow &= 0xFFFF;
  35333. }
  35334. },
  35335. // C.3.2 Decoding a decision (DECODE)
  35336. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  35337. // contexts are packed into 1 byte:
  35338. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  35339. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  35340. var qeTableIcx = QeTable[cx_index];
  35341. var qeIcx = qeTableIcx.qe;
  35342. var d;
  35343. var a = this.a - qeIcx;
  35344. if (this.chigh < qeIcx) {
  35345. // exchangeLps
  35346. if (a < qeIcx) {
  35347. a = qeIcx;
  35348. d = cx_mps;
  35349. cx_index = qeTableIcx.nmps;
  35350. } else {
  35351. a = qeIcx;
  35352. d = 1 ^ cx_mps;
  35353. if (qeTableIcx.switchFlag === 1) {
  35354. cx_mps = d;
  35355. }
  35356. cx_index = qeTableIcx.nlps;
  35357. }
  35358. } else {
  35359. this.chigh -= qeIcx;
  35360. if ((a & 0x8000) !== 0) {
  35361. this.a = a;
  35362. return cx_mps;
  35363. }
  35364. // exchangeMps
  35365. if (a < qeIcx) {
  35366. d = 1 ^ cx_mps;
  35367. if (qeTableIcx.switchFlag === 1) {
  35368. cx_mps = d;
  35369. }
  35370. cx_index = qeTableIcx.nlps;
  35371. } else {
  35372. d = cx_mps;
  35373. cx_index = qeTableIcx.nmps;
  35374. }
  35375. }
  35376. // C.3.3 renormD;
  35377. do {
  35378. if (this.ct === 0) {
  35379. this.byteIn();
  35380. }
  35381. a <<= 1;
  35382. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  35383. this.clow = (this.clow << 1) & 0xFFFF;
  35384. this.ct--;
  35385. } while ((a & 0x8000) === 0);
  35386. this.a = a;
  35387. contexts[pos] = cx_index << 1 | cx_mps;
  35388. return d;
  35389. }
  35390. };
  35391. return ArithmeticDecoder;
  35392. })();
  35393. var JpegImage = (function jpegImage() {
  35394. var dctZigZag = new Uint8Array([
  35395. 0,
  35396. 1, 8,
  35397. 16, 9, 2,
  35398. 3, 10, 17, 24,
  35399. 32, 25, 18, 11, 4,
  35400. 5, 12, 19, 26, 33, 40,
  35401. 48, 41, 34, 27, 20, 13, 6,
  35402. 7, 14, 21, 28, 35, 42, 49, 56,
  35403. 57, 50, 43, 36, 29, 22, 15,
  35404. 23, 30, 37, 44, 51, 58,
  35405. 59, 52, 45, 38, 31,
  35406. 39, 46, 53, 60,
  35407. 61, 54, 47,
  35408. 55, 62,
  35409. 63
  35410. ]);
  35411. var dctCos1 = 4017; // cos(pi/16)
  35412. var dctSin1 = 799; // sin(pi/16)
  35413. var dctCos3 = 3406; // cos(3*pi/16)
  35414. var dctSin3 = 2276; // sin(3*pi/16)
  35415. var dctCos6 = 1567; // cos(6*pi/16)
  35416. var dctSin6 = 3784; // sin(6*pi/16)
  35417. var dctSqrt2 = 5793; // sqrt(2)
  35418. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  35419. function constructor() {
  35420. }
  35421. function buildHuffmanTable(codeLengths, values) {
  35422. var k = 0, code = [], i, j, length = 16;
  35423. while (length > 0 && !codeLengths[length - 1]) {
  35424. length--;
  35425. }
  35426. code.push({children: [], index: 0});
  35427. var p = code[0], q;
  35428. for (i = 0; i < length; i++) {
  35429. for (j = 0; j < codeLengths[i]; j++) {
  35430. p = code.pop();
  35431. p.children[p.index] = values[k];
  35432. while (p.index > 0) {
  35433. p = code.pop();
  35434. }
  35435. p.index++;
  35436. code.push(p);
  35437. while (code.length <= i) {
  35438. code.push(q = {children: [], index: 0});
  35439. p.children[p.index] = q.children;
  35440. p = q;
  35441. }
  35442. k++;
  35443. }
  35444. if (i + 1 < length) {
  35445. // p here points to last code
  35446. code.push(q = {children: [], index: 0});
  35447. p.children[p.index] = q.children;
  35448. p = q;
  35449. }
  35450. }
  35451. return code[0].children;
  35452. }
  35453. function getBlockBufferOffset(component, row, col) {
  35454. return 64 * ((component.blocksPerLine + 1) * row + col);
  35455. }
  35456. function decodeScan(data, offset, frame, components, resetInterval,
  35457. spectralStart, spectralEnd, successivePrev, successive) {
  35458. var precision = frame.precision;
  35459. var samplesPerLine = frame.samplesPerLine;
  35460. var scanLines = frame.scanLines;
  35461. var mcusPerLine = frame.mcusPerLine;
  35462. var progressive = frame.progressive;
  35463. var maxH = frame.maxH, maxV = frame.maxV;
  35464. var startOffset = offset, bitsData = 0, bitsCount = 0;
  35465. function readBit() {
  35466. if (bitsCount > 0) {
  35467. bitsCount--;
  35468. return (bitsData >> bitsCount) & 1;
  35469. }
  35470. bitsData = data[offset++];
  35471. if (bitsData === 0xFF) {
  35472. var nextByte = data[offset++];
  35473. if (nextByte) {
  35474. throw 'unexpected marker: ' +
  35475. ((bitsData << 8) | nextByte).toString(16);
  35476. }
  35477. // unstuff 0
  35478. }
  35479. bitsCount = 7;
  35480. return bitsData >>> 7;
  35481. }
  35482. function decodeHuffman(tree) {
  35483. var node = tree;
  35484. var bit;
  35485. while ((bit = readBit()) !== null) {
  35486. node = node[bit];
  35487. if (typeof node === 'number') {
  35488. return node;
  35489. }
  35490. if (typeof node !== 'object') {
  35491. throw 'invalid huffman sequence';
  35492. }
  35493. }
  35494. return null;
  35495. }
  35496. function receive(length) {
  35497. var n = 0;
  35498. while (length > 0) {
  35499. var bit = readBit();
  35500. if (bit === null) {
  35501. return;
  35502. }
  35503. n = (n << 1) | bit;
  35504. length--;
  35505. }
  35506. return n;
  35507. }
  35508. function receiveAndExtend(length) {
  35509. if (length === 1) {
  35510. return readBit() === 1 ? 1 : -1;
  35511. }
  35512. var n = receive(length);
  35513. if (n >= 1 << (length - 1)) {
  35514. return n;
  35515. }
  35516. return n + (-1 << length) + 1;
  35517. }
  35518. function decodeBaseline(component, offset) {
  35519. var t = decodeHuffman(component.huffmanTableDC);
  35520. var diff = t === 0 ? 0 : receiveAndExtend(t);
  35521. component.blockData[offset] = (component.pred += diff);
  35522. var k = 1;
  35523. while (k < 64) {
  35524. var rs = decodeHuffman(component.huffmanTableAC);
  35525. var s = rs & 15, r = rs >> 4;
  35526. if (s === 0) {
  35527. if (r < 15) {
  35528. break;
  35529. }
  35530. k += 16;
  35531. continue;
  35532. }
  35533. k += r;
  35534. var z = dctZigZag[k];
  35535. component.blockData[offset + z] = receiveAndExtend(s);
  35536. k++;
  35537. }
  35538. }
  35539. function decodeDCFirst(component, offset) {
  35540. var t = decodeHuffman(component.huffmanTableDC);
  35541. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  35542. component.blockData[offset] = (component.pred += diff);
  35543. }
  35544. function decodeDCSuccessive(component, offset) {
  35545. component.blockData[offset] |= readBit() << successive;
  35546. }
  35547. var eobrun = 0;
  35548. function decodeACFirst(component, offset) {
  35549. if (eobrun > 0) {
  35550. eobrun--;
  35551. return;
  35552. }
  35553. var k = spectralStart, e = spectralEnd;
  35554. while (k <= e) {
  35555. var rs = decodeHuffman(component.huffmanTableAC);
  35556. var s = rs & 15, r = rs >> 4;
  35557. if (s === 0) {
  35558. if (r < 15) {
  35559. eobrun = receive(r) + (1 << r) - 1;
  35560. break;
  35561. }
  35562. k += 16;
  35563. continue;
  35564. }
  35565. k += r;
  35566. var z = dctZigZag[k];
  35567. component.blockData[offset + z] =
  35568. receiveAndExtend(s) * (1 << successive);
  35569. k++;
  35570. }
  35571. }
  35572. var successiveACState = 0, successiveACNextValue;
  35573. function decodeACSuccessive(component, offset) {
  35574. var k = spectralStart;
  35575. var e = spectralEnd;
  35576. var r = 0;
  35577. var s;
  35578. var rs;
  35579. while (k <= e) {
  35580. var z = dctZigZag[k];
  35581. switch (successiveACState) {
  35582. case 0: // initial state
  35583. rs = decodeHuffman(component.huffmanTableAC);
  35584. s = rs & 15;
  35585. r = rs >> 4;
  35586. if (s === 0) {
  35587. if (r < 15) {
  35588. eobrun = receive(r) + (1 << r);
  35589. successiveACState = 4;
  35590. } else {
  35591. r = 16;
  35592. successiveACState = 1;
  35593. }
  35594. } else {
  35595. if (s !== 1) {
  35596. throw 'invalid ACn encoding';
  35597. }
  35598. successiveACNextValue = receiveAndExtend(s);
  35599. successiveACState = r ? 2 : 3;
  35600. }
  35601. continue;
  35602. case 1: // skipping r zero items
  35603. case 2:
  35604. if (component.blockData[offset + z]) {
  35605. component.blockData[offset + z] += (readBit() << successive);
  35606. } else {
  35607. r--;
  35608. if (r === 0) {
  35609. successiveACState = successiveACState === 2 ? 3 : 0;
  35610. }
  35611. }
  35612. break;
  35613. case 3: // set value for a zero item
  35614. if (component.blockData[offset + z]) {
  35615. component.blockData[offset + z] += (readBit() << successive);
  35616. } else {
  35617. component.blockData[offset + z] =
  35618. successiveACNextValue << successive;
  35619. successiveACState = 0;
  35620. }
  35621. break;
  35622. case 4: // eob
  35623. if (component.blockData[offset + z]) {
  35624. component.blockData[offset + z] += (readBit() << successive);
  35625. }
  35626. break;
  35627. }
  35628. k++;
  35629. }
  35630. if (successiveACState === 4) {
  35631. eobrun--;
  35632. if (eobrun === 0) {
  35633. successiveACState = 0;
  35634. }
  35635. }
  35636. }
  35637. function decodeMcu(component, decode, mcu, row, col) {
  35638. var mcuRow = (mcu / mcusPerLine) | 0;
  35639. var mcuCol = mcu % mcusPerLine;
  35640. var blockRow = mcuRow * component.v + row;
  35641. var blockCol = mcuCol * component.h + col;
  35642. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  35643. decode(component, offset);
  35644. }
  35645. function decodeBlock(component, decode, mcu) {
  35646. var blockRow = (mcu / component.blocksPerLine) | 0;
  35647. var blockCol = mcu % component.blocksPerLine;
  35648. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  35649. decode(component, offset);
  35650. }
  35651. var componentsLength = components.length;
  35652. var component, i, j, k, n;
  35653. var decodeFn;
  35654. if (progressive) {
  35655. if (spectralStart === 0) {
  35656. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  35657. } else {
  35658. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  35659. }
  35660. } else {
  35661. decodeFn = decodeBaseline;
  35662. }
  35663. var mcu = 0, marker;
  35664. var mcuExpected;
  35665. if (componentsLength === 1) {
  35666. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  35667. } else {
  35668. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  35669. }
  35670. if (!resetInterval) {
  35671. resetInterval = mcuExpected;
  35672. }
  35673. var h, v;
  35674. while (mcu < mcuExpected) {
  35675. // reset interval stuff
  35676. for (i = 0; i < componentsLength; i++) {
  35677. components[i].pred = 0;
  35678. }
  35679. eobrun = 0;
  35680. if (componentsLength === 1) {
  35681. component = components[0];
  35682. for (n = 0; n < resetInterval; n++) {
  35683. decodeBlock(component, decodeFn, mcu);
  35684. mcu++;
  35685. }
  35686. } else {
  35687. for (n = 0; n < resetInterval; n++) {
  35688. for (i = 0; i < componentsLength; i++) {
  35689. component = components[i];
  35690. h = component.h;
  35691. v = component.v;
  35692. for (j = 0; j < v; j++) {
  35693. for (k = 0; k < h; k++) {
  35694. decodeMcu(component, decodeFn, mcu, j, k);
  35695. }
  35696. }
  35697. }
  35698. mcu++;
  35699. }
  35700. }
  35701. // find marker
  35702. bitsCount = 0;
  35703. marker = (data[offset] << 8) | data[offset + 1];
  35704. if (marker <= 0xFF00) {
  35705. throw 'marker was not found';
  35706. }
  35707. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  35708. offset += 2;
  35709. } else {
  35710. break;
  35711. }
  35712. }
  35713. return offset - startOffset;
  35714. }
  35715. // A port of poppler's IDCT method which in turn is taken from:
  35716. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  35717. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  35718. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  35719. // 988-991.
  35720. function quantizeAndInverse(component, blockBufferOffset, p) {
  35721. var qt = component.quantizationTable, blockData = component.blockData;
  35722. var v0, v1, v2, v3, v4, v5, v6, v7;
  35723. var p0, p1, p2, p3, p4, p5, p6, p7;
  35724. var t;
  35725. // inverse DCT on rows
  35726. for (var row = 0; row < 64; row += 8) {
  35727. // gather block data
  35728. p0 = blockData[blockBufferOffset + row];
  35729. p1 = blockData[blockBufferOffset + row + 1];
  35730. p2 = blockData[blockBufferOffset + row + 2];
  35731. p3 = blockData[blockBufferOffset + row + 3];
  35732. p4 = blockData[blockBufferOffset + row + 4];
  35733. p5 = blockData[blockBufferOffset + row + 5];
  35734. p6 = blockData[blockBufferOffset + row + 6];
  35735. p7 = blockData[blockBufferOffset + row + 7];
  35736. // dequant p0
  35737. p0 *= qt[row];
  35738. // check for all-zero AC coefficients
  35739. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  35740. t = (dctSqrt2 * p0 + 512) >> 10;
  35741. p[row] = t;
  35742. p[row + 1] = t;
  35743. p[row + 2] = t;
  35744. p[row + 3] = t;
  35745. p[row + 4] = t;
  35746. p[row + 5] = t;
  35747. p[row + 6] = t;
  35748. p[row + 7] = t;
  35749. continue;
  35750. }
  35751. // dequant p1 ... p7
  35752. p1 *= qt[row + 1];
  35753. p2 *= qt[row + 2];
  35754. p3 *= qt[row + 3];
  35755. p4 *= qt[row + 4];
  35756. p5 *= qt[row + 5];
  35757. p6 *= qt[row + 6];
  35758. p7 *= qt[row + 7];
  35759. // stage 4
  35760. v0 = (dctSqrt2 * p0 + 128) >> 8;
  35761. v1 = (dctSqrt2 * p4 + 128) >> 8;
  35762. v2 = p2;
  35763. v3 = p6;
  35764. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  35765. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  35766. v5 = p3 << 4;
  35767. v6 = p5 << 4;
  35768. // stage 3
  35769. v0 = (v0 + v1 + 1) >> 1;
  35770. v1 = v0 - v1;
  35771. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  35772. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  35773. v3 = t;
  35774. v4 = (v4 + v6 + 1) >> 1;
  35775. v6 = v4 - v6;
  35776. v7 = (v7 + v5 + 1) >> 1;
  35777. v5 = v7 - v5;
  35778. // stage 2
  35779. v0 = (v0 + v3 + 1) >> 1;
  35780. v3 = v0 - v3;
  35781. v1 = (v1 + v2 + 1) >> 1;
  35782. v2 = v1 - v2;
  35783. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  35784. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  35785. v7 = t;
  35786. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  35787. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  35788. v6 = t;
  35789. // stage 1
  35790. p[row] = v0 + v7;
  35791. p[row + 7] = v0 - v7;
  35792. p[row + 1] = v1 + v6;
  35793. p[row + 6] = v1 - v6;
  35794. p[row + 2] = v2 + v5;
  35795. p[row + 5] = v2 - v5;
  35796. p[row + 3] = v3 + v4;
  35797. p[row + 4] = v3 - v4;
  35798. }
  35799. // inverse DCT on columns
  35800. for (var col = 0; col < 8; ++col) {
  35801. p0 = p[col];
  35802. p1 = p[col + 8];
  35803. p2 = p[col + 16];
  35804. p3 = p[col + 24];
  35805. p4 = p[col + 32];
  35806. p5 = p[col + 40];
  35807. p6 = p[col + 48];
  35808. p7 = p[col + 56];
  35809. // check for all-zero AC coefficients
  35810. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  35811. t = (dctSqrt2 * p0 + 8192) >> 14;
  35812. // convert to 8 bit
  35813. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  35814. blockData[blockBufferOffset + col] = t;
  35815. blockData[blockBufferOffset + col + 8] = t;
  35816. blockData[blockBufferOffset + col + 16] = t;
  35817. blockData[blockBufferOffset + col + 24] = t;
  35818. blockData[blockBufferOffset + col + 32] = t;
  35819. blockData[blockBufferOffset + col + 40] = t;
  35820. blockData[blockBufferOffset + col + 48] = t;
  35821. blockData[blockBufferOffset + col + 56] = t;
  35822. continue;
  35823. }
  35824. // stage 4
  35825. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  35826. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  35827. v2 = p2;
  35828. v3 = p6;
  35829. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  35830. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  35831. v5 = p3;
  35832. v6 = p5;
  35833. // stage 3
  35834. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  35835. // converting to UInt8 range later.
  35836. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  35837. v1 = v0 - v1;
  35838. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  35839. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  35840. v3 = t;
  35841. v4 = (v4 + v6 + 1) >> 1;
  35842. v6 = v4 - v6;
  35843. v7 = (v7 + v5 + 1) >> 1;
  35844. v5 = v7 - v5;
  35845. // stage 2
  35846. v0 = (v0 + v3 + 1) >> 1;
  35847. v3 = v0 - v3;
  35848. v1 = (v1 + v2 + 1) >> 1;
  35849. v2 = v1 - v2;
  35850. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  35851. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  35852. v7 = t;
  35853. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  35854. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  35855. v6 = t;
  35856. // stage 1
  35857. p0 = v0 + v7;
  35858. p7 = v0 - v7;
  35859. p1 = v1 + v6;
  35860. p6 = v1 - v6;
  35861. p2 = v2 + v5;
  35862. p5 = v2 - v5;
  35863. p3 = v3 + v4;
  35864. p4 = v3 - v4;
  35865. // convert to 8-bit integers
  35866. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  35867. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  35868. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  35869. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  35870. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  35871. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  35872. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  35873. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  35874. // store block data
  35875. blockData[blockBufferOffset + col] = p0;
  35876. blockData[blockBufferOffset + col + 8] = p1;
  35877. blockData[blockBufferOffset + col + 16] = p2;
  35878. blockData[blockBufferOffset + col + 24] = p3;
  35879. blockData[blockBufferOffset + col + 32] = p4;
  35880. blockData[blockBufferOffset + col + 40] = p5;
  35881. blockData[blockBufferOffset + col + 48] = p6;
  35882. blockData[blockBufferOffset + col + 56] = p7;
  35883. }
  35884. }
  35885. function buildComponentData(frame, component) {
  35886. var blocksPerLine = component.blocksPerLine;
  35887. var blocksPerColumn = component.blocksPerColumn;
  35888. var computationBuffer = new Int16Array(64);
  35889. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  35890. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  35891. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  35892. quantizeAndInverse(component, offset, computationBuffer);
  35893. }
  35894. }
  35895. return component.blockData;
  35896. }
  35897. function clamp0to255(a) {
  35898. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  35899. }
  35900. constructor.prototype = {
  35901. parse: function parse(data) {
  35902. function readUint16() {
  35903. var value = (data[offset] << 8) | data[offset + 1];
  35904. offset += 2;
  35905. return value;
  35906. }
  35907. function readDataBlock() {
  35908. var length = readUint16();
  35909. var array = data.subarray(offset, offset + length - 2);
  35910. offset += array.length;
  35911. return array;
  35912. }
  35913. function prepareComponents(frame) {
  35914. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  35915. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  35916. for (var i = 0; i < frame.components.length; i++) {
  35917. component = frame.components[i];
  35918. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  35919. component.h / frame.maxH);
  35920. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  35921. component.v / frame.maxV);
  35922. var blocksPerLineForMcu = mcusPerLine * component.h;
  35923. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  35924. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  35925. (blocksPerLineForMcu + 1);
  35926. component.blockData = new Int16Array(blocksBufferSize);
  35927. component.blocksPerLine = blocksPerLine;
  35928. component.blocksPerColumn = blocksPerColumn;
  35929. }
  35930. frame.mcusPerLine = mcusPerLine;
  35931. frame.mcusPerColumn = mcusPerColumn;
  35932. }
  35933. var offset = 0, length = data.length;
  35934. var jfif = null;
  35935. var adobe = null;
  35936. var pixels = null;
  35937. var frame, resetInterval;
  35938. var quantizationTables = [];
  35939. var huffmanTablesAC = [], huffmanTablesDC = [];
  35940. var fileMarker = readUint16();
  35941. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  35942. throw 'SOI not found';
  35943. }
  35944. fileMarker = readUint16();
  35945. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  35946. var i, j, l;
  35947. switch(fileMarker) {
  35948. case 0xFFE0: // APP0 (Application Specific)
  35949. case 0xFFE1: // APP1
  35950. case 0xFFE2: // APP2
  35951. case 0xFFE3: // APP3
  35952. case 0xFFE4: // APP4
  35953. case 0xFFE5: // APP5
  35954. case 0xFFE6: // APP6
  35955. case 0xFFE7: // APP7
  35956. case 0xFFE8: // APP8
  35957. case 0xFFE9: // APP9
  35958. case 0xFFEA: // APP10
  35959. case 0xFFEB: // APP11
  35960. case 0xFFEC: // APP12
  35961. case 0xFFED: // APP13
  35962. case 0xFFEE: // APP14
  35963. case 0xFFEF: // APP15
  35964. case 0xFFFE: // COM (Comment)
  35965. var appData = readDataBlock();
  35966. if (fileMarker === 0xFFE0) {
  35967. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  35968. appData[2] === 0x49 && appData[3] === 0x46 &&
  35969. appData[4] === 0) { // 'JFIF\x00'
  35970. jfif = {
  35971. version: { major: appData[5], minor: appData[6] },
  35972. densityUnits: appData[7],
  35973. xDensity: (appData[8] << 8) | appData[9],
  35974. yDensity: (appData[10] << 8) | appData[11],
  35975. thumbWidth: appData[12],
  35976. thumbHeight: appData[13],
  35977. thumbData: appData.subarray(14, 14 +
  35978. 3 * appData[12] * appData[13])
  35979. };
  35980. }
  35981. }
  35982. // TODO APP1 - Exif
  35983. if (fileMarker === 0xFFEE) {
  35984. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  35985. appData[2] === 0x6F && appData[3] === 0x62 &&
  35986. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  35987. adobe = {
  35988. version: appData[6],
  35989. flags0: (appData[7] << 8) | appData[8],
  35990. flags1: (appData[9] << 8) | appData[10],
  35991. transformCode: appData[11]
  35992. };
  35993. }
  35994. }
  35995. break;
  35996. case 0xFFDB: // DQT (Define Quantization Tables)
  35997. var quantizationTablesLength = readUint16();
  35998. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  35999. var z;
  36000. while (offset < quantizationTablesEnd) {
  36001. var quantizationTableSpec = data[offset++];
  36002. var tableData = new Uint16Array(64);
  36003. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  36004. for (j = 0; j < 64; j++) {
  36005. z = dctZigZag[j];
  36006. tableData[z] = data[offset++];
  36007. }
  36008. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  36009. for (j = 0; j < 64; j++) {
  36010. z = dctZigZag[j];
  36011. tableData[z] = readUint16();
  36012. }
  36013. } else {
  36014. throw 'DQT: invalid table spec';
  36015. }
  36016. quantizationTables[quantizationTableSpec & 15] = tableData;
  36017. }
  36018. break;
  36019. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  36020. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  36021. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  36022. if (frame) {
  36023. throw 'Only single frame JPEGs supported';
  36024. }
  36025. readUint16(); // skip data length
  36026. frame = {};
  36027. frame.extended = (fileMarker === 0xFFC1);
  36028. frame.progressive = (fileMarker === 0xFFC2);
  36029. frame.precision = data[offset++];
  36030. frame.scanLines = readUint16();
  36031. frame.samplesPerLine = readUint16();
  36032. frame.components = [];
  36033. frame.componentIds = {};
  36034. var componentsCount = data[offset++], componentId;
  36035. var maxH = 0, maxV = 0;
  36036. for (i = 0; i < componentsCount; i++) {
  36037. componentId = data[offset];
  36038. var h = data[offset + 1] >> 4;
  36039. var v = data[offset + 1] & 15;
  36040. if (maxH < h) {
  36041. maxH = h;
  36042. }
  36043. if (maxV < v) {
  36044. maxV = v;
  36045. }
  36046. var qId = data[offset + 2];
  36047. l = frame.components.push({
  36048. h: h,
  36049. v: v,
  36050. quantizationTable: quantizationTables[qId]
  36051. });
  36052. frame.componentIds[componentId] = l - 1;
  36053. offset += 3;
  36054. }
  36055. frame.maxH = maxH;
  36056. frame.maxV = maxV;
  36057. prepareComponents(frame);
  36058. break;
  36059. case 0xFFC4: // DHT (Define Huffman Tables)
  36060. var huffmanLength = readUint16();
  36061. for (i = 2; i < huffmanLength;) {
  36062. var huffmanTableSpec = data[offset++];
  36063. var codeLengths = new Uint8Array(16);
  36064. var codeLengthSum = 0;
  36065. for (j = 0; j < 16; j++, offset++) {
  36066. codeLengthSum += (codeLengths[j] = data[offset]);
  36067. }
  36068. var huffmanValues = new Uint8Array(codeLengthSum);
  36069. for (j = 0; j < codeLengthSum; j++, offset++) {
  36070. huffmanValues[j] = data[offset];
  36071. }
  36072. i += 17 + codeLengthSum;
  36073. ((huffmanTableSpec >> 4) === 0 ?
  36074. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  36075. buildHuffmanTable(codeLengths, huffmanValues);
  36076. }
  36077. break;
  36078. case 0xFFDD: // DRI (Define Restart Interval)
  36079. readUint16(); // skip data length
  36080. resetInterval = readUint16();
  36081. break;
  36082. case 0xFFDA: // SOS (Start of Scan)
  36083. var scanLength = readUint16();
  36084. var selectorsCount = data[offset++];
  36085. var components = [], component;
  36086. for (i = 0; i < selectorsCount; i++) {
  36087. var componentIndex = frame.componentIds[data[offset++]];
  36088. component = frame.components[componentIndex];
  36089. var tableSpec = data[offset++];
  36090. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  36091. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  36092. components.push(component);
  36093. }
  36094. var spectralStart = data[offset++];
  36095. var spectralEnd = data[offset++];
  36096. var successiveApproximation = data[offset++];
  36097. var processed = decodeScan(data, offset,
  36098. frame, components, resetInterval,
  36099. spectralStart, spectralEnd,
  36100. successiveApproximation >> 4, successiveApproximation & 15);
  36101. offset += processed;
  36102. break;
  36103. default:
  36104. if (data[offset - 3] === 0xFF &&
  36105. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  36106. // could be incorrect encoding -- last 0xFF byte of the previous
  36107. // block was eaten by the encoder
  36108. offset -= 3;
  36109. break;
  36110. }
  36111. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  36112. }
  36113. fileMarker = readUint16();
  36114. }
  36115. this.width = frame.samplesPerLine;
  36116. this.height = frame.scanLines;
  36117. this.jfif = jfif;
  36118. this.adobe = adobe;
  36119. this.components = [];
  36120. for (i = 0; i < frame.components.length; i++) {
  36121. component = frame.components[i];
  36122. this.components.push({
  36123. output: buildComponentData(frame, component),
  36124. scaleX: component.h / frame.maxH,
  36125. scaleY: component.v / frame.maxV,
  36126. blocksPerLine: component.blocksPerLine,
  36127. blocksPerColumn: component.blocksPerColumn
  36128. });
  36129. }
  36130. this.numComponents = this.components.length;
  36131. },
  36132. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  36133. var scaleX = this.width / width, scaleY = this.height / height;
  36134. var component, componentScaleX, componentScaleY, blocksPerScanline;
  36135. var x, y, i, j, k;
  36136. var index;
  36137. var offset = 0;
  36138. var output;
  36139. var numComponents = this.components.length;
  36140. var dataLength = width * height * numComponents;
  36141. var data = new Uint8Array(dataLength);
  36142. var xScaleBlockOffset = new Uint32Array(width);
  36143. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  36144. for (i = 0; i < numComponents; i++) {
  36145. component = this.components[i];
  36146. componentScaleX = component.scaleX * scaleX;
  36147. componentScaleY = component.scaleY * scaleY;
  36148. offset = i;
  36149. output = component.output;
  36150. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  36151. // precalculate the xScaleBlockOffset
  36152. for (x = 0; x < width; x++) {
  36153. j = 0 | (x * componentScaleX);
  36154. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  36155. }
  36156. // linearize the blocks of the component
  36157. for (y = 0; y < height; y++) {
  36158. j = 0 | (y * componentScaleY);
  36159. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  36160. for (x = 0; x < width; x++) {
  36161. data[offset] = output[index + xScaleBlockOffset[x]];
  36162. offset += numComponents;
  36163. }
  36164. }
  36165. }
  36166. // decodeTransform will contains pairs of multiplier (-256..256) and
  36167. // additive
  36168. var transform = this.decodeTransform;
  36169. if (transform) {
  36170. for (i = 0; i < dataLength;) {
  36171. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  36172. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  36173. }
  36174. }
  36175. }
  36176. return data;
  36177. },
  36178. _isColorConversionNeeded: function isColorConversionNeeded() {
  36179. if (this.adobe && this.adobe.transformCode) {
  36180. // The adobe transform marker overrides any previous setting
  36181. return true;
  36182. } else if (this.numComponents === 3) {
  36183. return true;
  36184. } else {
  36185. return false;
  36186. }
  36187. },
  36188. _convertYccToRgb: function convertYccToRgb(data) {
  36189. var Y, Cb, Cr;
  36190. for (var i = 0, length = data.length; i < length; i += 3) {
  36191. Y = data[i ];
  36192. Cb = data[i + 1];
  36193. Cr = data[i + 2];
  36194. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  36195. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  36196. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  36197. }
  36198. return data;
  36199. },
  36200. _convertYcckToRgb: function convertYcckToRgb(data) {
  36201. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  36202. var offset = 0;
  36203. for (var i = 0, length = data.length; i < length; i += 4) {
  36204. Y = data[i];
  36205. Cb = data[i + 1];
  36206. Cr = data[i + 2];
  36207. k = data[i + 3];
  36208. CbCb = Cb * Cb;
  36209. CbCr = Cb * Cr;
  36210. CbY = Cb * Y;
  36211. Cbk = Cb * k;
  36212. CrCr = Cr * Cr;
  36213. Crk = Cr * k;
  36214. CrY = Cr * Y;
  36215. YY = Y * Y;
  36216. Yk = Y * k;
  36217. kk = k * k;
  36218. var r = - 122.67195406894 -
  36219. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  36220. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  36221. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  36222. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  36223. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  36224. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  36225. 0.000336197177618394 * kk + 0.484791561490776 * k;
  36226. var g = 107.268039397724 +
  36227. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  36228. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  36229. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  36230. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  36231. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  36232. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  36233. 0.000318913117588328 * kk - 0.213742400323665 * k;
  36234. var b = - 20.810012546947 -
  36235. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  36236. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  36237. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  36238. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  36239. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  36240. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  36241. 0.000343531996510555 * kk + 0.24165260232407 * k;
  36242. data[offset++] = clamp0to255(r);
  36243. data[offset++] = clamp0to255(g);
  36244. data[offset++] = clamp0to255(b);
  36245. }
  36246. return data;
  36247. },
  36248. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  36249. var Y, Cb, Cr;
  36250. for (var i = 0, length = data.length; i < length; i += 4) {
  36251. Y = data[i];
  36252. Cb = data[i + 1];
  36253. Cr = data[i + 2];
  36254. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  36255. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  36256. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  36257. // K in data[i + 3] is unchanged
  36258. }
  36259. return data;
  36260. },
  36261. _convertCmykToRgb: function convertCmykToRgb(data) {
  36262. var c, m, y, k;
  36263. var offset = 0;
  36264. var min = -255 * 255 * 255;
  36265. var scale = 1 / 255 / 255;
  36266. for (var i = 0, length = data.length; i < length; i += 4) {
  36267. c = data[i];
  36268. m = data[i + 1];
  36269. y = data[i + 2];
  36270. k = data[i + 3];
  36271. var r =
  36272. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  36273. 18.82290502165302 * y + 212.25662451639585 * k -
  36274. 72734.4411664936) +
  36275. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  36276. 17.873870861415444 * k - 1401.7366389350734) +
  36277. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  36278. 4465.541406466231) -
  36279. k * (21.86122147463605 * k + 48317.86113160301);
  36280. var g =
  36281. c * (8.841041422036149 * c + 60.118027045597366 * m +
  36282. 6.871425592049007 * y + 31.159100130055922 * k -
  36283. 20220.756542821975) +
  36284. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  36285. 131.35250912493976 * k - 48691.05921601825) +
  36286. y * (4.444339102852739 * y + 9.8632861493405 * k -
  36287. 6341.191035517494) -
  36288. k * (20.737325471181034 * k + 47890.15695978492);
  36289. var b =
  36290. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  36291. 30.89978309703729 * y - 0.23883238689178934 * k -
  36292. 3616.812083916688) +
  36293. m * (10.49593273432072 * m + 63.02378494754052 * y +
  36294. 50.606957656360734 * k - 28620.90484698408) +
  36295. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  36296. 49363.43385999684) -
  36297. k * (22.33816807309886 * k + 45932.16563550634);
  36298. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  36299. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  36300. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  36301. }
  36302. return data;
  36303. },
  36304. getData: function getData(width, height, forceRGBoutput) {
  36305. if (this.numComponents > 4) {
  36306. throw 'Unsupported color mode';
  36307. }
  36308. // type of data: Uint8Array(width * height * numComponents)
  36309. var data = this._getLinearizedBlockData(width, height);
  36310. if (this.numComponents === 3) {
  36311. return this._convertYccToRgb(data);
  36312. } else if (this.numComponents === 4) {
  36313. if (this._isColorConversionNeeded()) {
  36314. if (forceRGBoutput) {
  36315. return this._convertYcckToRgb(data);
  36316. } else {
  36317. return this._convertYcckToCmyk(data);
  36318. }
  36319. } else if (forceRGBoutput) {
  36320. return this._convertCmykToRgb(data);
  36321. }
  36322. }
  36323. return data;
  36324. }
  36325. };
  36326. return constructor;
  36327. })();
  36328. var JpxImage = (function JpxImageClosure() {
  36329. // Table E.1
  36330. var SubbandsGainLog2 = {
  36331. 'LL': 0,
  36332. 'LH': 1,
  36333. 'HL': 1,
  36334. 'HH': 2
  36335. };
  36336. function JpxImage() {
  36337. this.failOnCorruptedImage = false;
  36338. }
  36339. JpxImage.prototype = {
  36340. parse: function JpxImage_parse(data) {
  36341. var head = readUint16(data, 0);
  36342. // No box header, immediate start of codestream (SOC)
  36343. if (head === 0xFF4F) {
  36344. this.parseCodestream(data, 0, data.length);
  36345. return;
  36346. }
  36347. var position = 0, length = data.length;
  36348. while (position < length) {
  36349. var headerSize = 8;
  36350. var lbox = readUint32(data, position);
  36351. var tbox = readUint32(data, position + 4);
  36352. position += headerSize;
  36353. if (lbox === 1) {
  36354. // XLBox: read UInt64 according to spec.
  36355. // JavaScript's int precision of 53 bit should be sufficient here.
  36356. lbox = readUint32(data, position) * 4294967296 +
  36357. readUint32(data, position + 4);
  36358. position += 8;
  36359. headerSize += 8;
  36360. }
  36361. if (lbox === 0) {
  36362. lbox = length - position + headerSize;
  36363. }
  36364. if (lbox < headerSize) {
  36365. throw new Error('JPX Error: Invalid box field size');
  36366. }
  36367. var dataLength = lbox - headerSize;
  36368. var jumpDataLength = true;
  36369. switch (tbox) {
  36370. case 0x6A501A1A: // 'jP\032\032'
  36371. // TODO
  36372. break;
  36373. case 0x6A703268: // 'jp2h'
  36374. jumpDataLength = false; // parsing child boxes
  36375. break;
  36376. case 0x636F6C72: // 'colr'
  36377. // TODO
  36378. break;
  36379. case 0x6A703263: // 'jp2c'
  36380. this.parseCodestream(data, position, position + dataLength);
  36381. break;
  36382. }
  36383. if (jumpDataLength) {
  36384. position += dataLength;
  36385. }
  36386. }
  36387. },
  36388. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  36389. var newByte = stream.getByte();
  36390. while (newByte >= 0) {
  36391. var oldByte = newByte;
  36392. newByte = stream.getByte();
  36393. var code = (oldByte << 8) | newByte;
  36394. // Image and tile size (SIZ)
  36395. if (code === 0xFF51) {
  36396. stream.skip(4);
  36397. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  36398. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  36399. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  36400. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  36401. stream.skip(16);
  36402. var Csiz = stream.getUint16(); // Byte 36
  36403. this.width = Xsiz - XOsiz;
  36404. this.height = Ysiz - YOsiz;
  36405. this.componentsCount = Csiz;
  36406. // Results are always returned as Uint8Arrays
  36407. this.bitsPerComponent = 8;
  36408. return;
  36409. }
  36410. }
  36411. throw new Error('JPX Error: No size marker found in JPX stream');
  36412. },
  36413. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  36414. var context = {};
  36415. try {
  36416. var doNotRecover = false;
  36417. var position = start;
  36418. while (position + 1 < end) {
  36419. var code = readUint16(data, position);
  36420. position += 2;
  36421. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  36422. switch (code) {
  36423. case 0xFF4F: // Start of codestream (SOC)
  36424. context.mainHeader = true;
  36425. break;
  36426. case 0xFFD9: // End of codestream (EOC)
  36427. break;
  36428. case 0xFF51: // Image and tile size (SIZ)
  36429. length = readUint16(data, position);
  36430. var siz = {};
  36431. siz.Xsiz = readUint32(data, position + 4);
  36432. siz.Ysiz = readUint32(data, position + 8);
  36433. siz.XOsiz = readUint32(data, position + 12);
  36434. siz.YOsiz = readUint32(data, position + 16);
  36435. siz.XTsiz = readUint32(data, position + 20);
  36436. siz.YTsiz = readUint32(data, position + 24);
  36437. siz.XTOsiz = readUint32(data, position + 28);
  36438. siz.YTOsiz = readUint32(data, position + 32);
  36439. var componentsCount = readUint16(data, position + 36);
  36440. siz.Csiz = componentsCount;
  36441. var components = [];
  36442. j = position + 38;
  36443. for (var i = 0; i < componentsCount; i++) {
  36444. var component = {
  36445. precision: (data[j] & 0x7F) + 1,
  36446. isSigned: !!(data[j] & 0x80),
  36447. XRsiz: data[j + 1],
  36448. YRsiz: data[j + 1]
  36449. };
  36450. calculateComponentDimensions(component, siz);
  36451. components.push(component);
  36452. }
  36453. context.SIZ = siz;
  36454. context.components = components;
  36455. calculateTileGrids(context, components);
  36456. context.QCC = [];
  36457. context.COC = [];
  36458. break;
  36459. case 0xFF55: // Tile-part lengths, main header (TLM)
  36460. var Ltlm = readUint16(data, position); // Marker segment length
  36461. // Skip tile length markers
  36462. position += Ltlm;
  36463. break;
  36464. case 0xFF5C: // Quantization default (QCD)
  36465. length = readUint16(data, position);
  36466. var qcd = {};
  36467. j = position + 2;
  36468. sqcd = data[j++];
  36469. switch (sqcd & 0x1F) {
  36470. case 0:
  36471. spqcdSize = 8;
  36472. scalarExpounded = true;
  36473. break;
  36474. case 1:
  36475. spqcdSize = 16;
  36476. scalarExpounded = false;
  36477. break;
  36478. case 2:
  36479. spqcdSize = 16;
  36480. scalarExpounded = true;
  36481. break;
  36482. default:
  36483. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  36484. }
  36485. qcd.noQuantization = (spqcdSize === 8);
  36486. qcd.scalarExpounded = scalarExpounded;
  36487. qcd.guardBits = sqcd >> 5;
  36488. spqcds = [];
  36489. while (j < length + position) {
  36490. var spqcd = {};
  36491. if (spqcdSize === 8) {
  36492. spqcd.epsilon = data[j++] >> 3;
  36493. spqcd.mu = 0;
  36494. } else {
  36495. spqcd.epsilon = data[j] >> 3;
  36496. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  36497. j += 2;
  36498. }
  36499. spqcds.push(spqcd);
  36500. }
  36501. qcd.SPqcds = spqcds;
  36502. if (context.mainHeader) {
  36503. context.QCD = qcd;
  36504. } else {
  36505. context.currentTile.QCD = qcd;
  36506. context.currentTile.QCC = [];
  36507. }
  36508. break;
  36509. case 0xFF5D: // Quantization component (QCC)
  36510. length = readUint16(data, position);
  36511. var qcc = {};
  36512. j = position + 2;
  36513. var cqcc;
  36514. if (context.SIZ.Csiz < 257) {
  36515. cqcc = data[j++];
  36516. } else {
  36517. cqcc = readUint16(data, j);
  36518. j += 2;
  36519. }
  36520. sqcd = data[j++];
  36521. switch (sqcd & 0x1F) {
  36522. case 0:
  36523. spqcdSize = 8;
  36524. scalarExpounded = true;
  36525. break;
  36526. case 1:
  36527. spqcdSize = 16;
  36528. scalarExpounded = false;
  36529. break;
  36530. case 2:
  36531. spqcdSize = 16;
  36532. scalarExpounded = true;
  36533. break;
  36534. default:
  36535. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  36536. }
  36537. qcc.noQuantization = (spqcdSize === 8);
  36538. qcc.scalarExpounded = scalarExpounded;
  36539. qcc.guardBits = sqcd >> 5;
  36540. spqcds = [];
  36541. while (j < (length + position)) {
  36542. spqcd = {};
  36543. if (spqcdSize === 8) {
  36544. spqcd.epsilon = data[j++] >> 3;
  36545. spqcd.mu = 0;
  36546. } else {
  36547. spqcd.epsilon = data[j] >> 3;
  36548. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  36549. j += 2;
  36550. }
  36551. spqcds.push(spqcd);
  36552. }
  36553. qcc.SPqcds = spqcds;
  36554. if (context.mainHeader) {
  36555. context.QCC[cqcc] = qcc;
  36556. } else {
  36557. context.currentTile.QCC[cqcc] = qcc;
  36558. }
  36559. break;
  36560. case 0xFF52: // Coding style default (COD)
  36561. length = readUint16(data, position);
  36562. var cod = {};
  36563. j = position + 2;
  36564. var scod = data[j++];
  36565. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  36566. cod.sopMarkerUsed = !!(scod & 2);
  36567. cod.ephMarkerUsed = !!(scod & 4);
  36568. cod.progressionOrder = data[j++];
  36569. cod.layersCount = readUint16(data, j);
  36570. j += 2;
  36571. cod.multipleComponentTransform = data[j++];
  36572. cod.decompositionLevelsCount = data[j++];
  36573. cod.xcb = (data[j++] & 0xF) + 2;
  36574. cod.ycb = (data[j++] & 0xF) + 2;
  36575. var blockStyle = data[j++];
  36576. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  36577. cod.resetContextProbabilities = !!(blockStyle & 2);
  36578. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  36579. cod.verticalyStripe = !!(blockStyle & 8);
  36580. cod.predictableTermination = !!(blockStyle & 16);
  36581. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  36582. cod.reversibleTransformation = data[j++];
  36583. if (cod.entropyCoderWithCustomPrecincts) {
  36584. var precinctsSizes = [];
  36585. while (j < length + position) {
  36586. var precinctsSize = data[j++];
  36587. precinctsSizes.push({
  36588. PPx: precinctsSize & 0xF,
  36589. PPy: precinctsSize >> 4
  36590. });
  36591. }
  36592. cod.precinctsSizes = precinctsSizes;
  36593. }
  36594. var unsupported = [];
  36595. if (cod.sopMarkerUsed) {
  36596. unsupported.push('sopMarkerUsed');
  36597. }
  36598. if (cod.ephMarkerUsed) {
  36599. unsupported.push('ephMarkerUsed');
  36600. }
  36601. if (cod.selectiveArithmeticCodingBypass) {
  36602. unsupported.push('selectiveArithmeticCodingBypass');
  36603. }
  36604. if (cod.resetContextProbabilities) {
  36605. unsupported.push('resetContextProbabilities');
  36606. }
  36607. if (cod.terminationOnEachCodingPass) {
  36608. unsupported.push('terminationOnEachCodingPass');
  36609. }
  36610. if (cod.verticalyStripe) {
  36611. unsupported.push('verticalyStripe');
  36612. }
  36613. if (cod.predictableTermination) {
  36614. unsupported.push('predictableTermination');
  36615. }
  36616. if (unsupported.length > 0) {
  36617. doNotRecover = true;
  36618. throw new Error('JPX Error: Unsupported COD options (' +
  36619. unsupported.join(', ') + ')');
  36620. }
  36621. if (context.mainHeader) {
  36622. context.COD = cod;
  36623. } else {
  36624. context.currentTile.COD = cod;
  36625. context.currentTile.COC = [];
  36626. }
  36627. break;
  36628. case 0xFF90: // Start of tile-part (SOT)
  36629. length = readUint16(data, position);
  36630. tile = {};
  36631. tile.index = readUint16(data, position + 2);
  36632. tile.length = readUint32(data, position + 4);
  36633. tile.dataEnd = tile.length + position - 2;
  36634. tile.partIndex = data[position + 8];
  36635. tile.partsCount = data[position + 9];
  36636. context.mainHeader = false;
  36637. if (tile.partIndex === 0) {
  36638. // reset component specific settings
  36639. tile.COD = context.COD;
  36640. tile.COC = context.COC.slice(0); // clone of the global COC
  36641. tile.QCD = context.QCD;
  36642. tile.QCC = context.QCC.slice(0); // clone of the global COC
  36643. }
  36644. context.currentTile = tile;
  36645. break;
  36646. case 0xFF93: // Start of data (SOD)
  36647. tile = context.currentTile;
  36648. if (tile.partIndex === 0) {
  36649. initializeTile(context, tile.index);
  36650. buildPackets(context);
  36651. }
  36652. // moving to the end of the data
  36653. length = tile.dataEnd - position;
  36654. parseTilePackets(context, data, position, length);
  36655. break;
  36656. case 0xFF64: // Comment (COM)
  36657. length = readUint16(data, position);
  36658. // skipping content
  36659. break;
  36660. case 0xFF53: // Coding style component (COC)
  36661. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  36662. 'not implemented');
  36663. default:
  36664. throw new Error('JPX Error: Unknown codestream code: ' +
  36665. code.toString(16));
  36666. }
  36667. position += length;
  36668. }
  36669. } catch (e) {
  36670. if (doNotRecover || this.failOnCorruptedImage) {
  36671. throw e;
  36672. } else {
  36673. warn('Trying to recover from ' + e.message);
  36674. }
  36675. }
  36676. this.tiles = transformComponents(context);
  36677. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  36678. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  36679. this.componentsCount = context.SIZ.Csiz;
  36680. }
  36681. };
  36682. function calculateComponentDimensions(component, siz) {
  36683. // Section B.2 Component mapping
  36684. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  36685. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  36686. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  36687. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  36688. component.width = component.x1 - component.x0;
  36689. component.height = component.y1 - component.y0;
  36690. }
  36691. function calculateTileGrids(context, components) {
  36692. var siz = context.SIZ;
  36693. // Section B.3 Division into tile and tile-components
  36694. var tile, tiles = [];
  36695. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  36696. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  36697. for (var q = 0; q < numYtiles; q++) {
  36698. for (var p = 0; p < numXtiles; p++) {
  36699. tile = {};
  36700. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  36701. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  36702. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  36703. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  36704. tile.width = tile.tx1 - tile.tx0;
  36705. tile.height = tile.ty1 - tile.ty0;
  36706. tile.components = [];
  36707. tiles.push(tile);
  36708. }
  36709. }
  36710. context.tiles = tiles;
  36711. var componentsCount = siz.Csiz;
  36712. for (var i = 0, ii = componentsCount; i < ii; i++) {
  36713. var component = components[i];
  36714. for (var j = 0, jj = tiles.length; j < jj; j++) {
  36715. var tileComponent = {};
  36716. tile = tiles[j];
  36717. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  36718. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  36719. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  36720. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  36721. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  36722. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  36723. tile.components[i] = tileComponent;
  36724. }
  36725. }
  36726. }
  36727. function getBlocksDimensions(context, component, r) {
  36728. var codOrCoc = component.codingStyleParameters;
  36729. var result = {};
  36730. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  36731. result.PPx = 15;
  36732. result.PPy = 15;
  36733. } else {
  36734. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  36735. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  36736. }
  36737. // calculate codeblock size as described in section B.7
  36738. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  36739. Math.min(codOrCoc.xcb, result.PPx));
  36740. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  36741. Math.min(codOrCoc.ycb, result.PPy));
  36742. return result;
  36743. }
  36744. function buildPrecincts(context, resolution, dimensions) {
  36745. // Section B.6 Division resolution to precincts
  36746. var precinctWidth = 1 << dimensions.PPx;
  36747. var precinctHeight = 1 << dimensions.PPy;
  36748. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  36749. Math.ceil(resolution.trx1 / precinctWidth) -
  36750. Math.floor(resolution.trx0 / precinctWidth) : 0);
  36751. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  36752. Math.ceil(resolution.try1 / precinctHeight) -
  36753. Math.floor(resolution.try0 / precinctHeight) : 0);
  36754. var numprecincts = numprecinctswide * numprecinctshigh;
  36755. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  36756. precinctWidth;
  36757. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  36758. precinctHeight;
  36759. resolution.precinctParameters = {
  36760. precinctXOffset: precinctXOffset,
  36761. precinctYOffset: precinctYOffset,
  36762. precinctWidth: precinctWidth,
  36763. precinctHeight: precinctHeight,
  36764. numprecinctswide: numprecinctswide,
  36765. numprecinctshigh: numprecinctshigh,
  36766. numprecincts: numprecincts
  36767. };
  36768. }
  36769. function buildCodeblocks(context, subband, dimensions) {
  36770. // Section B.7 Division sub-band into code-blocks
  36771. var xcb_ = dimensions.xcb_;
  36772. var ycb_ = dimensions.ycb_;
  36773. var codeblockWidth = 1 << xcb_;
  36774. var codeblockHeight = 1 << ycb_;
  36775. var cbx0 = subband.tbx0 >> xcb_;
  36776. var cby0 = subband.tby0 >> ycb_;
  36777. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  36778. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  36779. var precinctParameters = subband.resolution.precinctParameters;
  36780. var codeblocks = [];
  36781. var precincts = [];
  36782. var i, j, codeblock, precinctNumber;
  36783. for (j = cby0; j < cby1; j++) {
  36784. for (i = cbx0; i < cbx1; i++) {
  36785. codeblock = {
  36786. cbx: i,
  36787. cby: j,
  36788. tbx0: codeblockWidth * i,
  36789. tby0: codeblockHeight * j,
  36790. tbx1: codeblockWidth * (i + 1),
  36791. tby1: codeblockHeight * (j + 1)
  36792. };
  36793. // calculate precinct number
  36794. var pi = Math.floor((codeblock.tbx0 -
  36795. precinctParameters.precinctXOffset) /
  36796. precinctParameters.precinctWidth);
  36797. var pj = Math.floor((codeblock.tby0 -
  36798. precinctParameters.precinctYOffset) /
  36799. precinctParameters.precinctHeight);
  36800. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  36801. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  36802. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  36803. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  36804. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  36805. codeblock.precinctNumber = precinctNumber;
  36806. codeblock.subbandType = subband.type;
  36807. codeblock.Lblock = 3;
  36808. codeblocks.push(codeblock);
  36809. // building precinct for the sub-band
  36810. var precinct = precincts[precinctNumber];
  36811. if (precinct !== undefined) {
  36812. if (i < precinct.cbxMin) {
  36813. precinct.cbxMin = i;
  36814. } else if (i > precinct.cbxMax) {
  36815. precinct.cbxMax = i;
  36816. }
  36817. if (j < precinct.cbyMin) {
  36818. precinct.cbxMin = j;
  36819. } else if (j > precinct.cbyMax) {
  36820. precinct.cbyMax = j;
  36821. }
  36822. } else {
  36823. precincts[precinctNumber] = precinct = {
  36824. cbxMin: i,
  36825. cbyMin: j,
  36826. cbxMax: i,
  36827. cbyMax: j
  36828. };
  36829. }
  36830. codeblock.precinct = precinct;
  36831. }
  36832. }
  36833. subband.codeblockParameters = {
  36834. codeblockWidth: xcb_,
  36835. codeblockHeight: ycb_,
  36836. numcodeblockwide: cbx1 - cbx0 + 1,
  36837. numcodeblockhigh: cby1 - cby1 + 1
  36838. };
  36839. subband.codeblocks = codeblocks;
  36840. subband.precincts = precincts;
  36841. }
  36842. function createPacket(resolution, precinctNumber, layerNumber) {
  36843. var precinctCodeblocks = [];
  36844. // Section B.10.8 Order of info in packet
  36845. var subbands = resolution.subbands;
  36846. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  36847. for (var i = 0, ii = subbands.length; i < ii; i++) {
  36848. var subband = subbands[i];
  36849. var codeblocks = subband.codeblocks;
  36850. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  36851. var codeblock = codeblocks[j];
  36852. if (codeblock.precinctNumber !== precinctNumber) {
  36853. continue;
  36854. }
  36855. precinctCodeblocks.push(codeblock);
  36856. }
  36857. }
  36858. return {
  36859. layerNumber: layerNumber,
  36860. codeblocks: precinctCodeblocks
  36861. };
  36862. }
  36863. function LayerResolutionComponentPositionIterator(context) {
  36864. var siz = context.SIZ;
  36865. var tileIndex = context.currentTile.index;
  36866. var tile = context.tiles[tileIndex];
  36867. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  36868. var componentsCount = siz.Csiz;
  36869. var maxDecompositionLevelsCount = 0;
  36870. for (var q = 0; q < componentsCount; q++) {
  36871. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  36872. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  36873. }
  36874. var l = 0, r = 0, i = 0, k = 0;
  36875. this.nextPacket = function JpxImage_nextPacket() {
  36876. // Section B.12.1.1 Layer-resolution-component-position
  36877. for (; l < layersCount; l++) {
  36878. for (; r <= maxDecompositionLevelsCount; r++) {
  36879. for (; i < componentsCount; i++) {
  36880. var component = tile.components[i];
  36881. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  36882. continue;
  36883. }
  36884. var resolution = component.resolutions[r];
  36885. var numprecincts = resolution.precinctParameters.numprecincts;
  36886. for (; k < numprecincts;) {
  36887. var packet = createPacket(resolution, k, l);
  36888. k++;
  36889. return packet;
  36890. }
  36891. k = 0;
  36892. }
  36893. i = 0;
  36894. }
  36895. r = 0;
  36896. }
  36897. throw new Error('JPX Error: Out of packets');
  36898. };
  36899. }
  36900. function ResolutionLayerComponentPositionIterator(context) {
  36901. var siz = context.SIZ;
  36902. var tileIndex = context.currentTile.index;
  36903. var tile = context.tiles[tileIndex];
  36904. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  36905. var componentsCount = siz.Csiz;
  36906. var maxDecompositionLevelsCount = 0;
  36907. for (var q = 0; q < componentsCount; q++) {
  36908. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  36909. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  36910. }
  36911. var r = 0, l = 0, i = 0, k = 0;
  36912. this.nextPacket = function JpxImage_nextPacket() {
  36913. // Section B.12.1.2 Resolution-layer-component-position
  36914. for (; r <= maxDecompositionLevelsCount; r++) {
  36915. for (; l < layersCount; l++) {
  36916. for (; i < componentsCount; i++) {
  36917. var component = tile.components[i];
  36918. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  36919. continue;
  36920. }
  36921. var resolution = component.resolutions[r];
  36922. var numprecincts = resolution.precinctParameters.numprecincts;
  36923. for (; k < numprecincts;) {
  36924. var packet = createPacket(resolution, k, l);
  36925. k++;
  36926. return packet;
  36927. }
  36928. k = 0;
  36929. }
  36930. i = 0;
  36931. }
  36932. l = 0;
  36933. }
  36934. throw new Error('JPX Error: Out of packets');
  36935. };
  36936. }
  36937. function buildPackets(context) {
  36938. var siz = context.SIZ;
  36939. var tileIndex = context.currentTile.index;
  36940. var tile = context.tiles[tileIndex];
  36941. var componentsCount = siz.Csiz;
  36942. // Creating resolutions and sub-bands for each component
  36943. for (var c = 0; c < componentsCount; c++) {
  36944. var component = tile.components[c];
  36945. var decompositionLevelsCount =
  36946. component.codingStyleParameters.decompositionLevelsCount;
  36947. // Section B.5 Resolution levels and sub-bands
  36948. var resolutions = [];
  36949. var subbands = [];
  36950. for (var r = 0; r <= decompositionLevelsCount; r++) {
  36951. var blocksDimensions = getBlocksDimensions(context, component, r);
  36952. var resolution = {};
  36953. var scale = 1 << (decompositionLevelsCount - r);
  36954. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  36955. resolution.try0 = Math.ceil(component.tcy0 / scale);
  36956. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  36957. resolution.try1 = Math.ceil(component.tcy1 / scale);
  36958. buildPrecincts(context, resolution, blocksDimensions);
  36959. resolutions.push(resolution);
  36960. var subband;
  36961. if (r === 0) {
  36962. // one sub-band (LL) with last decomposition
  36963. subband = {};
  36964. subband.type = 'LL';
  36965. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  36966. subband.tby0 = Math.ceil(component.tcy0 / scale);
  36967. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  36968. subband.tby1 = Math.ceil(component.tcy1 / scale);
  36969. subband.resolution = resolution;
  36970. buildCodeblocks(context, subband, blocksDimensions);
  36971. subbands.push(subband);
  36972. resolution.subbands = [subband];
  36973. } else {
  36974. var bscale = 1 << (decompositionLevelsCount - r + 1);
  36975. var resolutionSubbands = [];
  36976. // three sub-bands (HL, LH and HH) with rest of decompositions
  36977. subband = {};
  36978. subband.type = 'HL';
  36979. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  36980. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  36981. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  36982. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  36983. subband.resolution = resolution;
  36984. buildCodeblocks(context, subband, blocksDimensions);
  36985. subbands.push(subband);
  36986. resolutionSubbands.push(subband);
  36987. subband = {};
  36988. subband.type = 'LH';
  36989. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  36990. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  36991. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  36992. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  36993. subband.resolution = resolution;
  36994. buildCodeblocks(context, subband, blocksDimensions);
  36995. subbands.push(subband);
  36996. resolutionSubbands.push(subband);
  36997. subband = {};
  36998. subband.type = 'HH';
  36999. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  37000. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  37001. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  37002. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  37003. subband.resolution = resolution;
  37004. buildCodeblocks(context, subband, blocksDimensions);
  37005. subbands.push(subband);
  37006. resolutionSubbands.push(subband);
  37007. resolution.subbands = resolutionSubbands;
  37008. }
  37009. }
  37010. component.resolutions = resolutions;
  37011. component.subbands = subbands;
  37012. }
  37013. // Generate the packets sequence
  37014. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  37015. switch (progressionOrder) {
  37016. case 0:
  37017. tile.packetsIterator =
  37018. new LayerResolutionComponentPositionIterator(context);
  37019. break;
  37020. case 1:
  37021. tile.packetsIterator =
  37022. new ResolutionLayerComponentPositionIterator(context);
  37023. break;
  37024. default:
  37025. throw new Error('JPX Error: Unsupported progression order ' +
  37026. progressionOrder);
  37027. }
  37028. }
  37029. function parseTilePackets(context, data, offset, dataLength) {
  37030. var position = 0;
  37031. var buffer, bufferSize = 0, skipNextBit = false;
  37032. function readBits(count) {
  37033. while (bufferSize < count) {
  37034. var b = data[offset + position];
  37035. position++;
  37036. if (skipNextBit) {
  37037. buffer = (buffer << 7) | b;
  37038. bufferSize += 7;
  37039. skipNextBit = false;
  37040. } else {
  37041. buffer = (buffer << 8) | b;
  37042. bufferSize += 8;
  37043. }
  37044. if (b === 0xFF) {
  37045. skipNextBit = true;
  37046. }
  37047. }
  37048. bufferSize -= count;
  37049. return (buffer >>> bufferSize) & ((1 << count) - 1);
  37050. }
  37051. function alignToByte() {
  37052. bufferSize = 0;
  37053. if (skipNextBit) {
  37054. position++;
  37055. skipNextBit = false;
  37056. }
  37057. }
  37058. function readCodingpasses() {
  37059. if (readBits(1) === 0) {
  37060. return 1;
  37061. }
  37062. if (readBits(1) === 0) {
  37063. return 2;
  37064. }
  37065. var value = readBits(2);
  37066. if (value < 3) {
  37067. return value + 3;
  37068. }
  37069. value = readBits(5);
  37070. if (value < 31) {
  37071. return value + 6;
  37072. }
  37073. value = readBits(7);
  37074. return value + 37;
  37075. }
  37076. var tileIndex = context.currentTile.index;
  37077. var tile = context.tiles[tileIndex];
  37078. var packetsIterator = tile.packetsIterator;
  37079. while (position < dataLength) {
  37080. var packet = packetsIterator.nextPacket();
  37081. if (!readBits(1)) {
  37082. alignToByte();
  37083. continue;
  37084. }
  37085. var layerNumber = packet.layerNumber;
  37086. var queue = [], codeblock;
  37087. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  37088. codeblock = packet.codeblocks[i];
  37089. var precinct = codeblock.precinct;
  37090. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  37091. var codeblockRow = codeblock.cby - precinct.cbyMin;
  37092. var codeblockIncluded = false;
  37093. var firstTimeInclusion = false;
  37094. var valueReady;
  37095. if ('included' in codeblock) {
  37096. codeblockIncluded = !!readBits(1);
  37097. } else {
  37098. // reading inclusion tree
  37099. precinct = codeblock.precinct;
  37100. var inclusionTree, zeroBitPlanesTree;
  37101. if ('inclusionTree' in precinct) {
  37102. inclusionTree = precinct.inclusionTree;
  37103. } else {
  37104. // building inclusion and zero bit-planes trees
  37105. var width = precinct.cbxMax - precinct.cbxMin + 1;
  37106. var height = precinct.cbyMax - precinct.cbyMin + 1;
  37107. inclusionTree = new InclusionTree(width, height, layerNumber);
  37108. zeroBitPlanesTree = new TagTree(width, height);
  37109. precinct.inclusionTree = inclusionTree;
  37110. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  37111. }
  37112. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  37113. while (true) {
  37114. if (readBits(1)) {
  37115. valueReady = !inclusionTree.nextLevel();
  37116. if (valueReady) {
  37117. codeblock.included = true;
  37118. codeblockIncluded = firstTimeInclusion = true;
  37119. break;
  37120. }
  37121. } else {
  37122. inclusionTree.incrementValue(layerNumber);
  37123. break;
  37124. }
  37125. }
  37126. }
  37127. }
  37128. if (!codeblockIncluded) {
  37129. continue;
  37130. }
  37131. if (firstTimeInclusion) {
  37132. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  37133. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  37134. while (true) {
  37135. if (readBits(1)) {
  37136. valueReady = !zeroBitPlanesTree.nextLevel();
  37137. if (valueReady) {
  37138. break;
  37139. }
  37140. } else {
  37141. zeroBitPlanesTree.incrementValue();
  37142. }
  37143. }
  37144. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  37145. }
  37146. var codingpasses = readCodingpasses();
  37147. while (readBits(1)) {
  37148. codeblock.Lblock++;
  37149. }
  37150. var codingpassesLog2 = log2(codingpasses);
  37151. // rounding down log2
  37152. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  37153. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  37154. var codedDataLength = readBits(bits);
  37155. queue.push({
  37156. codeblock: codeblock,
  37157. codingpasses: codingpasses,
  37158. dataLength: codedDataLength
  37159. });
  37160. }
  37161. alignToByte();
  37162. while (queue.length > 0) {
  37163. var packetItem = queue.shift();
  37164. codeblock = packetItem.codeblock;
  37165. if (!('data' in codeblock)) {
  37166. codeblock.data = [];
  37167. }
  37168. codeblock.data.push({
  37169. data: data,
  37170. start: offset + position,
  37171. end: offset + position + packetItem.dataLength,
  37172. codingpasses: packetItem.codingpasses
  37173. });
  37174. position += packetItem.dataLength;
  37175. }
  37176. }
  37177. return position;
  37178. }
  37179. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  37180. delta, mb, reversible, segmentationSymbolUsed) {
  37181. var x0 = subband.tbx0;
  37182. var y0 = subband.tby0;
  37183. var width = subband.tbx1 - subband.tbx0;
  37184. var codeblocks = subband.codeblocks;
  37185. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  37186. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  37187. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  37188. var codeblock = codeblocks[i];
  37189. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  37190. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  37191. if (blockWidth === 0 || blockHeight === 0) {
  37192. continue;
  37193. }
  37194. if (!('data' in codeblock)) {
  37195. continue;
  37196. }
  37197. var bitModel, currentCodingpassType;
  37198. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  37199. codeblock.zeroBitPlanes, mb);
  37200. currentCodingpassType = 2; // first bit plane starts from cleanup
  37201. // collect data
  37202. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  37203. var j, jj, dataItem;
  37204. for (j = 0, jj = data.length; j < jj; j++) {
  37205. dataItem = data[j];
  37206. totalLength += dataItem.end - dataItem.start;
  37207. codingpasses += dataItem.codingpasses;
  37208. }
  37209. var encodedData = new Uint8Array(totalLength);
  37210. var position = 0;
  37211. for (j = 0, jj = data.length; j < jj; j++) {
  37212. dataItem = data[j];
  37213. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  37214. encodedData.set(chunk, position);
  37215. position += chunk.length;
  37216. }
  37217. // decoding the item
  37218. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  37219. bitModel.setDecoder(decoder);
  37220. for (j = 0; j < codingpasses; j++) {
  37221. switch (currentCodingpassType) {
  37222. case 0:
  37223. bitModel.runSignificancePropogationPass();
  37224. break;
  37225. case 1:
  37226. bitModel.runMagnitudeRefinementPass();
  37227. break;
  37228. case 2:
  37229. bitModel.runCleanupPass();
  37230. if (segmentationSymbolUsed) {
  37231. bitModel.checkSegmentationSymbol();
  37232. }
  37233. break;
  37234. }
  37235. currentCodingpassType = (currentCodingpassType + 1) % 3;
  37236. }
  37237. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  37238. var sign = bitModel.coefficentsSign;
  37239. var magnitude = bitModel.coefficentsMagnitude;
  37240. var bitsDecoded = bitModel.bitsDecoded;
  37241. var magnitudeCorrection = reversible ? 0 : 0.5;
  37242. var k, n, nb;
  37243. position = 0;
  37244. // Do the interleaving of Section F.3.3 here, so we do not need
  37245. // to copy later. LL level is not interleaved, just copied.
  37246. var interleave = (subband.type !== 'LL');
  37247. for (j = 0; j < blockHeight; j++) {
  37248. var row = (offset / width) | 0; // row in the non-interleaved subband
  37249. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  37250. for (k = 0; k < blockWidth; k++) {
  37251. n = magnitude[position];
  37252. if (n !== 0) {
  37253. n = (n + magnitudeCorrection) * delta;
  37254. if (sign[position] !== 0) {
  37255. n = -n;
  37256. }
  37257. nb = bitsDecoded[position];
  37258. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  37259. if (reversible && (nb >= mb)) {
  37260. coefficients[pos] = n;
  37261. } else {
  37262. coefficients[pos] = n * (1 << (mb - nb));
  37263. }
  37264. }
  37265. offset++;
  37266. position++;
  37267. }
  37268. offset += width - blockWidth;
  37269. }
  37270. }
  37271. }
  37272. function transformTile(context, tile, c) {
  37273. var component = tile.components[c];
  37274. var codingStyleParameters = component.codingStyleParameters;
  37275. var quantizationParameters = component.quantizationParameters;
  37276. var decompositionLevelsCount =
  37277. codingStyleParameters.decompositionLevelsCount;
  37278. var spqcds = quantizationParameters.SPqcds;
  37279. var scalarExpounded = quantizationParameters.scalarExpounded;
  37280. var guardBits = quantizationParameters.guardBits;
  37281. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  37282. var precision = context.components[c].precision;
  37283. var reversible = codingStyleParameters.reversibleTransformation;
  37284. var transform = (reversible ? new ReversibleTransform() :
  37285. new IrreversibleTransform());
  37286. var subbandCoefficients = [];
  37287. var b = 0;
  37288. for (var i = 0; i <= decompositionLevelsCount; i++) {
  37289. var resolution = component.resolutions[i];
  37290. var width = resolution.trx1 - resolution.trx0;
  37291. var height = resolution.try1 - resolution.try0;
  37292. // Allocate space for the whole sublevel.
  37293. var coefficients = new Float32Array(width * height);
  37294. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  37295. var mu, epsilon;
  37296. if (!scalarExpounded) {
  37297. // formula E-5
  37298. mu = spqcds[0].mu;
  37299. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  37300. } else {
  37301. mu = spqcds[b].mu;
  37302. epsilon = spqcds[b].epsilon;
  37303. b++;
  37304. }
  37305. var subband = resolution.subbands[j];
  37306. var gainLog2 = SubbandsGainLog2[subband.type];
  37307. // calulate quantization coefficient (Section E.1.1.1)
  37308. var delta = (reversible ? 1 :
  37309. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  37310. var mb = (guardBits + epsilon - 1);
  37311. // In the first resolution level, copyCoefficients will fill the
  37312. // whole array with coefficients. In the succeding passes,
  37313. // copyCoefficients will consecutively fill in the values that belong
  37314. // to the interleaved positions of the HL, LH, and HH coefficients.
  37315. // The LL coefficients will then be interleaved in Transform.iterate().
  37316. copyCoefficients(coefficients, width, height, subband, delta, mb,
  37317. reversible, segmentationSymbolUsed);
  37318. }
  37319. subbandCoefficients.push({
  37320. width: width,
  37321. height: height,
  37322. items: coefficients
  37323. });
  37324. }
  37325. var result = transform.calculate(subbandCoefficients,
  37326. component.tcx0, component.tcy0);
  37327. return {
  37328. left: component.tcx0,
  37329. top: component.tcy0,
  37330. width: result.width,
  37331. height: result.height,
  37332. items: result.items
  37333. };
  37334. }
  37335. function transformComponents(context) {
  37336. var siz = context.SIZ;
  37337. var components = context.components;
  37338. var componentsCount = siz.Csiz;
  37339. var resultImages = [];
  37340. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  37341. var tile = context.tiles[i];
  37342. var transformedTiles = [];
  37343. var c;
  37344. for (c = 0; c < componentsCount; c++) {
  37345. transformedTiles[c] = transformTile(context, tile, c);
  37346. }
  37347. var tile0 = transformedTiles[0];
  37348. var out = new Uint8Array(tile0.items.length * componentsCount);
  37349. var result = {
  37350. left: tile0.left,
  37351. top: tile0.top,
  37352. width: tile0.width,
  37353. height: tile0.height,
  37354. items: out
  37355. };
  37356. // Section G.2.2 Inverse multi component transform
  37357. var shift, offset, max, min, maxK;
  37358. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  37359. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  37360. var fourComponents = componentsCount === 4;
  37361. var y0items = transformedTiles[0].items;
  37362. var y1items = transformedTiles[1].items;
  37363. var y2items = transformedTiles[2].items;
  37364. var y3items = fourComponents ? transformedTiles[3].items : null;
  37365. // HACK: The multiple component transform formulas below assume that
  37366. // all components have the same precision. With this in mind, we
  37367. // compute shift and offset only once.
  37368. shift = components[0].precision - 8;
  37369. offset = (128 << shift) + 0.5;
  37370. max = 255 * (1 << shift);
  37371. maxK = max * 0.5;
  37372. min = -maxK;
  37373. var component0 = tile.components[0];
  37374. var alpha01 = componentsCount - 3;
  37375. jj = y0items.length;
  37376. if (!component0.codingStyleParameters.reversibleTransformation) {
  37377. // inverse irreversible multiple component transform
  37378. for (j = 0; j < jj; j++, pos += alpha01) {
  37379. y0 = y0items[j] + offset;
  37380. y1 = y1items[j];
  37381. y2 = y2items[j];
  37382. r = y0 + 1.402 * y2;
  37383. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  37384. b = y0 + 1.772 * y1;
  37385. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  37386. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  37387. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  37388. }
  37389. } else {
  37390. // inverse reversible multiple component transform
  37391. for (j = 0; j < jj; j++, pos += alpha01) {
  37392. y0 = y0items[j] + offset;
  37393. y1 = y1items[j];
  37394. y2 = y2items[j];
  37395. g = y0 - ((y2 + y1) >> 2);
  37396. r = g + y2;
  37397. b = g + y1;
  37398. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  37399. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  37400. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  37401. }
  37402. }
  37403. if (fourComponents) {
  37404. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  37405. k = y3items[j];
  37406. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  37407. }
  37408. }
  37409. } else { // no multi-component transform
  37410. for (c = 0; c < componentsCount; c++) {
  37411. var items = transformedTiles[c].items;
  37412. shift = components[c].precision - 8;
  37413. offset = (128 << shift) + 0.5;
  37414. max = (127.5 * (1 << shift));
  37415. min = -max;
  37416. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  37417. val = items[j];
  37418. out[pos] = val <= min ? 0 :
  37419. val >= max ? 255 : (val + offset) >> shift;
  37420. pos += componentsCount;
  37421. }
  37422. }
  37423. }
  37424. resultImages.push(result);
  37425. }
  37426. return resultImages;
  37427. }
  37428. function initializeTile(context, tileIndex) {
  37429. var siz = context.SIZ;
  37430. var componentsCount = siz.Csiz;
  37431. var tile = context.tiles[tileIndex];
  37432. for (var c = 0; c < componentsCount; c++) {
  37433. var component = tile.components[c];
  37434. var qcdOrQcc = (c in context.currentTile.QCC ?
  37435. context.currentTile.QCC[c] : context.currentTile.QCD);
  37436. component.quantizationParameters = qcdOrQcc;
  37437. var codOrCoc = (c in context.currentTile.COC ?
  37438. context.currentTile.COC[c] : context.currentTile.COD);
  37439. component.codingStyleParameters = codOrCoc;
  37440. }
  37441. tile.codingStyleDefaultParameters = context.currentTile.COD;
  37442. }
  37443. // Section B.10.2 Tag trees
  37444. var TagTree = (function TagTreeClosure() {
  37445. function TagTree(width, height) {
  37446. var levelsLength = log2(Math.max(width, height)) + 1;
  37447. this.levels = [];
  37448. for (var i = 0; i < levelsLength; i++) {
  37449. var level = {
  37450. width: width,
  37451. height: height,
  37452. items: []
  37453. };
  37454. this.levels.push(level);
  37455. width = Math.ceil(width / 2);
  37456. height = Math.ceil(height / 2);
  37457. }
  37458. }
  37459. TagTree.prototype = {
  37460. reset: function TagTree_reset(i, j) {
  37461. var currentLevel = 0, value = 0, level;
  37462. while (currentLevel < this.levels.length) {
  37463. level = this.levels[currentLevel];
  37464. var index = i + j * level.width;
  37465. if (index in level.items) {
  37466. value = level.items[index];
  37467. break;
  37468. }
  37469. level.index = index;
  37470. i >>= 1;
  37471. j >>= 1;
  37472. currentLevel++;
  37473. }
  37474. currentLevel--;
  37475. level = this.levels[currentLevel];
  37476. level.items[level.index] = value;
  37477. this.currentLevel = currentLevel;
  37478. delete this.value;
  37479. },
  37480. incrementValue: function TagTree_incrementValue() {
  37481. var level = this.levels[this.currentLevel];
  37482. level.items[level.index]++;
  37483. },
  37484. nextLevel: function TagTree_nextLevel() {
  37485. var currentLevel = this.currentLevel;
  37486. var level = this.levels[currentLevel];
  37487. var value = level.items[level.index];
  37488. currentLevel--;
  37489. if (currentLevel < 0) {
  37490. this.value = value;
  37491. return false;
  37492. }
  37493. this.currentLevel = currentLevel;
  37494. level = this.levels[currentLevel];
  37495. level.items[level.index] = value;
  37496. return true;
  37497. }
  37498. };
  37499. return TagTree;
  37500. })();
  37501. var InclusionTree = (function InclusionTreeClosure() {
  37502. function InclusionTree(width, height, defaultValue) {
  37503. var levelsLength = log2(Math.max(width, height)) + 1;
  37504. this.levels = [];
  37505. for (var i = 0; i < levelsLength; i++) {
  37506. var items = new Uint8Array(width * height);
  37507. for (var j = 0, jj = items.length; j < jj; j++) {
  37508. items[j] = defaultValue;
  37509. }
  37510. var level = {
  37511. width: width,
  37512. height: height,
  37513. items: items
  37514. };
  37515. this.levels.push(level);
  37516. width = Math.ceil(width / 2);
  37517. height = Math.ceil(height / 2);
  37518. }
  37519. }
  37520. InclusionTree.prototype = {
  37521. reset: function InclusionTree_reset(i, j, stopValue) {
  37522. var currentLevel = 0;
  37523. while (currentLevel < this.levels.length) {
  37524. var level = this.levels[currentLevel];
  37525. var index = i + j * level.width;
  37526. level.index = index;
  37527. var value = level.items[index];
  37528. if (value === 0xFF) {
  37529. break;
  37530. }
  37531. if (value > stopValue) {
  37532. this.currentLevel = currentLevel;
  37533. // already know about this one, propagating the value to top levels
  37534. this.propagateValues();
  37535. return false;
  37536. }
  37537. i >>= 1;
  37538. j >>= 1;
  37539. currentLevel++;
  37540. }
  37541. this.currentLevel = currentLevel - 1;
  37542. return true;
  37543. },
  37544. incrementValue: function InclusionTree_incrementValue(stopValue) {
  37545. var level = this.levels[this.currentLevel];
  37546. level.items[level.index] = stopValue + 1;
  37547. this.propagateValues();
  37548. },
  37549. propagateValues: function InclusionTree_propagateValues() {
  37550. var levelIndex = this.currentLevel;
  37551. var level = this.levels[levelIndex];
  37552. var currentValue = level.items[level.index];
  37553. while (--levelIndex >= 0) {
  37554. level = this.levels[levelIndex];
  37555. level.items[level.index] = currentValue;
  37556. }
  37557. },
  37558. nextLevel: function InclusionTree_nextLevel() {
  37559. var currentLevel = this.currentLevel;
  37560. var level = this.levels[currentLevel];
  37561. var value = level.items[level.index];
  37562. level.items[level.index] = 0xFF;
  37563. currentLevel--;
  37564. if (currentLevel < 0) {
  37565. return false;
  37566. }
  37567. this.currentLevel = currentLevel;
  37568. level = this.levels[currentLevel];
  37569. level.items[level.index] = value;
  37570. return true;
  37571. }
  37572. };
  37573. return InclusionTree;
  37574. })();
  37575. // Section D. Coefficient bit modeling
  37576. var BitModel = (function BitModelClosure() {
  37577. var UNIFORM_CONTEXT = 17;
  37578. var RUNLENGTH_CONTEXT = 18;
  37579. // Table D-1
  37580. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  37581. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  37582. var LLAndLHContextsLabel = new Uint8Array([
  37583. 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,
  37584. 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,
  37585. 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
  37586. ]);
  37587. var HLContextLabel = new Uint8Array([
  37588. 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,
  37589. 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,
  37590. 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
  37591. ]);
  37592. var HHContextLabel = new Uint8Array([
  37593. 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,
  37594. 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,
  37595. 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
  37596. ]);
  37597. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  37598. this.width = width;
  37599. this.height = height;
  37600. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  37601. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  37602. var coefficientCount = width * height;
  37603. // coefficients outside the encoding region treated as insignificant
  37604. // add border state cells for significanceState
  37605. this.neighborsSignificance = new Uint8Array(coefficientCount);
  37606. this.coefficentsSign = new Uint8Array(coefficientCount);
  37607. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  37608. mb > 6 ? new Uint16Array(coefficientCount) :
  37609. new Uint8Array(coefficientCount);
  37610. this.processingFlags = new Uint8Array(coefficientCount);
  37611. var bitsDecoded = new Uint8Array(coefficientCount);
  37612. if (zeroBitPlanes !== 0) {
  37613. for (var i = 0; i < coefficientCount; i++) {
  37614. bitsDecoded[i] = zeroBitPlanes;
  37615. }
  37616. }
  37617. this.bitsDecoded = bitsDecoded;
  37618. this.reset();
  37619. }
  37620. BitModel.prototype = {
  37621. setDecoder: function BitModel_setDecoder(decoder) {
  37622. this.decoder = decoder;
  37623. },
  37624. reset: function BitModel_reset() {
  37625. // We have 17 contexts that are accessed via context labels,
  37626. // plus the uniform and runlength context.
  37627. this.contexts = new Int8Array(19);
  37628. // Contexts are packed into 1 byte:
  37629. // highest 7 bits carry the index, lowest bit carries mps
  37630. this.contexts[0] = (4 << 1) | 0;
  37631. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  37632. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  37633. },
  37634. setNeighborsSignificance:
  37635. function BitModel_setNeighborsSignificance(row, column, index) {
  37636. var neighborsSignificance = this.neighborsSignificance;
  37637. var width = this.width, height = this.height;
  37638. var left = (column > 0);
  37639. var right = (column + 1 < width);
  37640. var i;
  37641. if (row > 0) {
  37642. i = index - width;
  37643. if (left) {
  37644. neighborsSignificance[i - 1] += 0x10;
  37645. }
  37646. if (right) {
  37647. neighborsSignificance[i + 1] += 0x10;
  37648. }
  37649. neighborsSignificance[i] += 0x04;
  37650. }
  37651. if (row + 1 < height) {
  37652. i = index + width;
  37653. if (left) {
  37654. neighborsSignificance[i - 1] += 0x10;
  37655. }
  37656. if (right) {
  37657. neighborsSignificance[i + 1] += 0x10;
  37658. }
  37659. neighborsSignificance[i] += 0x04;
  37660. }
  37661. if (left) {
  37662. neighborsSignificance[index - 1] += 0x01;
  37663. }
  37664. if (right) {
  37665. neighborsSignificance[index + 1] += 0x01;
  37666. }
  37667. neighborsSignificance[index] |= 0x80;
  37668. },
  37669. runSignificancePropogationPass:
  37670. function BitModel_runSignificancePropogationPass() {
  37671. var decoder = this.decoder;
  37672. var width = this.width, height = this.height;
  37673. var coefficentsMagnitude = this.coefficentsMagnitude;
  37674. var coefficentsSign = this.coefficentsSign;
  37675. var neighborsSignificance = this.neighborsSignificance;
  37676. var processingFlags = this.processingFlags;
  37677. var contexts = this.contexts;
  37678. var labels = this.contextLabelTable;
  37679. var bitsDecoded = this.bitsDecoded;
  37680. var processedInverseMask = ~1;
  37681. var processedMask = 1;
  37682. var firstMagnitudeBitMask = 2;
  37683. for (var i0 = 0; i0 < height; i0 += 4) {
  37684. for (var j = 0; j < width; j++) {
  37685. var index = i0 * width + j;
  37686. for (var i1 = 0; i1 < 4; i1++, index += width) {
  37687. var i = i0 + i1;
  37688. if (i >= height) {
  37689. break;
  37690. }
  37691. // clear processed flag first
  37692. processingFlags[index] &= processedInverseMask;
  37693. if (coefficentsMagnitude[index] ||
  37694. !neighborsSignificance[index]) {
  37695. continue;
  37696. }
  37697. var contextLabel = labels[neighborsSignificance[index]];
  37698. var decision = decoder.readBit(contexts, contextLabel);
  37699. if (decision) {
  37700. var sign = this.decodeSignBit(i, j, index);
  37701. coefficentsSign[index] = sign;
  37702. coefficentsMagnitude[index] = 1;
  37703. this.setNeighborsSignificance(i, j, index);
  37704. processingFlags[index] |= firstMagnitudeBitMask;
  37705. }
  37706. bitsDecoded[index]++;
  37707. processingFlags[index] |= processedMask;
  37708. }
  37709. }
  37710. }
  37711. },
  37712. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  37713. var width = this.width, height = this.height;
  37714. var coefficentsMagnitude = this.coefficentsMagnitude;
  37715. var coefficentsSign = this.coefficentsSign;
  37716. var contribution, sign0, sign1, significance1;
  37717. var contextLabel, decoded;
  37718. // calculate horizontal contribution
  37719. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  37720. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  37721. sign1 = coefficentsSign[index + 1];
  37722. if (significance1) {
  37723. sign0 = coefficentsSign[index - 1];
  37724. contribution = 1 - sign1 - sign0;
  37725. } else {
  37726. contribution = 1 - sign1 - sign1;
  37727. }
  37728. } else if (significance1) {
  37729. sign0 = coefficentsSign[index - 1];
  37730. contribution = 1 - sign0 - sign0;
  37731. } else {
  37732. contribution = 0;
  37733. }
  37734. var horizontalContribution = 3 * contribution;
  37735. // calculate vertical contribution and combine with the horizontal
  37736. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  37737. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  37738. sign1 = coefficentsSign[index + width];
  37739. if (significance1) {
  37740. sign0 = coefficentsSign[index - width];
  37741. contribution = 1 - sign1 - sign0 + horizontalContribution;
  37742. } else {
  37743. contribution = 1 - sign1 - sign1 + horizontalContribution;
  37744. }
  37745. } else if (significance1) {
  37746. sign0 = coefficentsSign[index - width];
  37747. contribution = 1 - sign0 - sign0 + horizontalContribution;
  37748. } else {
  37749. contribution = horizontalContribution;
  37750. }
  37751. if (contribution >= 0) {
  37752. contextLabel = 9 + contribution;
  37753. decoded = this.decoder.readBit(this.contexts, contextLabel);
  37754. } else {
  37755. contextLabel = 9 - contribution;
  37756. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  37757. }
  37758. return decoded;
  37759. },
  37760. runMagnitudeRefinementPass:
  37761. function BitModel_runMagnitudeRefinementPass() {
  37762. var decoder = this.decoder;
  37763. var width = this.width, height = this.height;
  37764. var coefficentsMagnitude = this.coefficentsMagnitude;
  37765. var neighborsSignificance = this.neighborsSignificance;
  37766. var contexts = this.contexts;
  37767. var bitsDecoded = this.bitsDecoded;
  37768. var processingFlags = this.processingFlags;
  37769. var processedMask = 1;
  37770. var firstMagnitudeBitMask = 2;
  37771. var length = width * height;
  37772. var width4 = width * 4;
  37773. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  37774. indexNext = Math.min(length, index0 + width4);
  37775. for (var j = 0; j < width; j++) {
  37776. for (var index = index0 + j; index < indexNext; index += width) {
  37777. // significant but not those that have just become
  37778. if (!coefficentsMagnitude[index] ||
  37779. (processingFlags[index] & processedMask) !== 0) {
  37780. continue;
  37781. }
  37782. var contextLabel = 16;
  37783. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  37784. processingFlags[index] ^= firstMagnitudeBitMask;
  37785. // first refinement
  37786. var significance = neighborsSignificance[index] & 127;
  37787. contextLabel = significance === 0 ? 15 : 14;
  37788. }
  37789. var bit = decoder.readBit(contexts, contextLabel);
  37790. coefficentsMagnitude[index] =
  37791. (coefficentsMagnitude[index] << 1) | bit;
  37792. bitsDecoded[index]++;
  37793. processingFlags[index] |= processedMask;
  37794. }
  37795. }
  37796. }
  37797. },
  37798. runCleanupPass: function BitModel_runCleanupPass() {
  37799. var decoder = this.decoder;
  37800. var width = this.width, height = this.height;
  37801. var neighborsSignificance = this.neighborsSignificance;
  37802. var coefficentsMagnitude = this.coefficentsMagnitude;
  37803. var coefficentsSign = this.coefficentsSign;
  37804. var contexts = this.contexts;
  37805. var labels = this.contextLabelTable;
  37806. var bitsDecoded = this.bitsDecoded;
  37807. var processingFlags = this.processingFlags;
  37808. var processedMask = 1;
  37809. var firstMagnitudeBitMask = 2;
  37810. var oneRowDown = width;
  37811. var twoRowsDown = width * 2;
  37812. var threeRowsDown = width * 3;
  37813. var iNext;
  37814. for (var i0 = 0; i0 < height; i0 = iNext) {
  37815. iNext = Math.min(i0 + 4, height);
  37816. var indexBase = i0 * width;
  37817. var checkAllEmpty = i0 + 3 < height;
  37818. for (var j = 0; j < width; j++) {
  37819. var index0 = indexBase + j;
  37820. // using the property: labels[neighborsSignificance[index]] === 0
  37821. // when neighborsSignificance[index] === 0
  37822. var allEmpty = (checkAllEmpty &&
  37823. processingFlags[index0] === 0 &&
  37824. processingFlags[index0 + oneRowDown] === 0 &&
  37825. processingFlags[index0 + twoRowsDown] === 0 &&
  37826. processingFlags[index0 + threeRowsDown] === 0 &&
  37827. neighborsSignificance[index0] === 0 &&
  37828. neighborsSignificance[index0 + oneRowDown] === 0 &&
  37829. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  37830. neighborsSignificance[index0 + threeRowsDown] === 0);
  37831. var i1 = 0, index = index0;
  37832. var i = i0, sign;
  37833. if (allEmpty) {
  37834. var hasSignificantCoefficent =
  37835. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  37836. if (!hasSignificantCoefficent) {
  37837. bitsDecoded[index0]++;
  37838. bitsDecoded[index0 + oneRowDown]++;
  37839. bitsDecoded[index0 + twoRowsDown]++;
  37840. bitsDecoded[index0 + threeRowsDown]++;
  37841. continue; // next column
  37842. }
  37843. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  37844. decoder.readBit(contexts, UNIFORM_CONTEXT);
  37845. if (i1 !== 0) {
  37846. i = i0 + i1;
  37847. index += i1 * width;
  37848. }
  37849. sign = this.decodeSignBit(i, j, index);
  37850. coefficentsSign[index] = sign;
  37851. coefficentsMagnitude[index] = 1;
  37852. this.setNeighborsSignificance(i, j, index);
  37853. processingFlags[index] |= firstMagnitudeBitMask;
  37854. index = index0;
  37855. for (var i2 = i0; i2 <= i; i2++, index += width) {
  37856. bitsDecoded[index]++;
  37857. }
  37858. i1++;
  37859. }
  37860. for (i = i0 + i1; i < iNext; i++, index += width) {
  37861. if (coefficentsMagnitude[index] ||
  37862. (processingFlags[index] & processedMask) !== 0) {
  37863. continue;
  37864. }
  37865. var contextLabel = labels[neighborsSignificance[index]];
  37866. var decision = decoder.readBit(contexts, contextLabel);
  37867. if (decision === 1) {
  37868. sign = this.decodeSignBit(i, j, index);
  37869. coefficentsSign[index] = sign;
  37870. coefficentsMagnitude[index] = 1;
  37871. this.setNeighborsSignificance(i, j, index);
  37872. processingFlags[index] |= firstMagnitudeBitMask;
  37873. }
  37874. bitsDecoded[index]++;
  37875. }
  37876. }
  37877. }
  37878. },
  37879. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  37880. var decoder = this.decoder;
  37881. var contexts = this.contexts;
  37882. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  37883. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  37884. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  37885. decoder.readBit(contexts, UNIFORM_CONTEXT);
  37886. if (symbol !== 0xA) {
  37887. throw new Error('JPX Error: Invalid segmentation symbol');
  37888. }
  37889. }
  37890. };
  37891. return BitModel;
  37892. })();
  37893. // Section F, Discrete wavelet transformation
  37894. var Transform = (function TransformClosure() {
  37895. function Transform() {}
  37896. Transform.prototype.calculate =
  37897. function transformCalculate(subbands, u0, v0) {
  37898. var ll = subbands[0];
  37899. for (var i = 1, ii = subbands.length; i < ii; i++) {
  37900. ll = this.iterate(ll, subbands[i], u0, v0);
  37901. }
  37902. return ll;
  37903. };
  37904. Transform.prototype.extend = function extend(buffer, offset, size) {
  37905. // Section F.3.7 extending... using max extension of 4
  37906. var i1 = offset - 1, j1 = offset + 1;
  37907. var i2 = offset + size - 2, j2 = offset + size;
  37908. buffer[i1--] = buffer[j1++];
  37909. buffer[j2++] = buffer[i2--];
  37910. buffer[i1--] = buffer[j1++];
  37911. buffer[j2++] = buffer[i2--];
  37912. buffer[i1--] = buffer[j1++];
  37913. buffer[j2++] = buffer[i2--];
  37914. buffer[i1] = buffer[j1];
  37915. buffer[j2] = buffer[i2];
  37916. };
  37917. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  37918. u0, v0) {
  37919. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  37920. var width = hl_lh_hh.width;
  37921. var height = hl_lh_hh.height;
  37922. var items = hl_lh_hh.items;
  37923. var i, j, k, l, u, v;
  37924. // Interleave LL according to Section F.3.3
  37925. for (k = 0, i = 0; i < llHeight; i++) {
  37926. l = i * 2 * width;
  37927. for (j = 0; j < llWidth; j++, k++, l += 2) {
  37928. items[l] = llItems[k];
  37929. }
  37930. }
  37931. // The LL band is not needed anymore.
  37932. llItems = ll.items = null;
  37933. var bufferPadding = 4;
  37934. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  37935. // Section F.3.4 HOR_SR
  37936. if (width === 1) {
  37937. // if width = 1, when u0 even keep items as is, when odd divide by 2
  37938. if ((u0 & 1) !== 0) {
  37939. for (v = 0, k = 0; v < height; v++, k += width) {
  37940. items[k] *= 0.5;
  37941. }
  37942. }
  37943. } else {
  37944. for (v = 0, k = 0; v < height; v++, k += width) {
  37945. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  37946. this.extend(rowBuffer, bufferPadding, width);
  37947. this.filter(rowBuffer, bufferPadding, width);
  37948. items.set(
  37949. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  37950. k);
  37951. }
  37952. }
  37953. // Accesses to the items array can take long, because it may not fit into
  37954. // CPU cache and has to be fetched from main memory. Since subsequent
  37955. // accesses to the items array are not local when reading columns, we
  37956. // have a cache miss every time. To reduce cache misses, get up to
  37957. // 'numBuffers' items at a time and store them into the individual
  37958. // buffers. The colBuffers should be small enough to fit into CPU cache.
  37959. var numBuffers = 16;
  37960. var colBuffers = [];
  37961. for (i = 0; i < numBuffers; i++) {
  37962. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  37963. }
  37964. var b, currentBuffer = 0;
  37965. ll = bufferPadding + height;
  37966. // Section F.3.5 VER_SR
  37967. if (height === 1) {
  37968. // if height = 1, when v0 even keep items as is, when odd divide by 2
  37969. if ((v0 & 1) !== 0) {
  37970. for (u = 0; u < width; u++) {
  37971. items[u] *= 0.5;
  37972. }
  37973. }
  37974. } else {
  37975. for (u = 0; u < width; u++) {
  37976. // if we ran out of buffers, copy several image columns at once
  37977. if (currentBuffer === 0) {
  37978. numBuffers = Math.min(width - u, numBuffers);
  37979. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  37980. for (b = 0; b < numBuffers; b++) {
  37981. colBuffers[b][l] = items[k + b];
  37982. }
  37983. }
  37984. currentBuffer = numBuffers;
  37985. }
  37986. currentBuffer--;
  37987. var buffer = colBuffers[currentBuffer];
  37988. this.extend(buffer, bufferPadding, height);
  37989. this.filter(buffer, bufferPadding, height);
  37990. // If this is last buffer in this group of buffers, flush all buffers.
  37991. if (currentBuffer === 0) {
  37992. k = u - numBuffers + 1;
  37993. for (l = bufferPadding; l < ll; k += width, l++) {
  37994. for (b = 0; b < numBuffers; b++) {
  37995. items[k + b] = colBuffers[b][l];
  37996. }
  37997. }
  37998. }
  37999. }
  38000. }
  38001. return {
  38002. width: width,
  38003. height: height,
  38004. items: items
  38005. };
  38006. };
  38007. return Transform;
  38008. })();
  38009. // Section 3.8.2 Irreversible 9-7 filter
  38010. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  38011. function IrreversibleTransform() {
  38012. Transform.call(this);
  38013. }
  38014. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  38015. IrreversibleTransform.prototype.filter =
  38016. function irreversibleTransformFilter(x, offset, length) {
  38017. var len = length >> 1;
  38018. offset = offset | 0;
  38019. var j, n, current, next;
  38020. var alpha = -1.586134342059924;
  38021. var beta = -0.052980118572961;
  38022. var gamma = 0.882911075530934;
  38023. var delta = 0.443506852043971;
  38024. var K = 1.230174104914001;
  38025. var K_ = 1 / K;
  38026. // step 1 is combined with step 3
  38027. // step 2
  38028. j = offset - 3;
  38029. for (n = len + 4; n--; j += 2) {
  38030. x[j] *= K_;
  38031. }
  38032. // step 1 & 3
  38033. j = offset - 2;
  38034. current = delta * x[j -1];
  38035. for (n = len + 3; n--; j += 2) {
  38036. next = delta * x[j + 1];
  38037. x[j] = K * x[j] - current - next;
  38038. if (n--) {
  38039. j += 2;
  38040. current = delta * x[j + 1];
  38041. x[j] = K * x[j] - current - next;
  38042. } else {
  38043. break;
  38044. }
  38045. }
  38046. // step 4
  38047. j = offset - 1;
  38048. current = gamma * x[j - 1];
  38049. for (n = len + 2; n--; j += 2) {
  38050. next = gamma * x[j + 1];
  38051. x[j] -= current + next;
  38052. if (n--) {
  38053. j += 2;
  38054. current = gamma * x[j + 1];
  38055. x[j] -= current + next;
  38056. } else {
  38057. break;
  38058. }
  38059. }
  38060. // step 5
  38061. j = offset;
  38062. current = beta * x[j - 1];
  38063. for (n = len + 1; n--; j += 2) {
  38064. next = beta * x[j + 1];
  38065. x[j] -= current + next;
  38066. if (n--) {
  38067. j += 2;
  38068. current = beta * x[j + 1];
  38069. x[j] -= current + next;
  38070. } else {
  38071. break;
  38072. }
  38073. }
  38074. // step 6
  38075. if (len !== 0) {
  38076. j = offset + 1;
  38077. current = alpha * x[j - 1];
  38078. for (n = len; n--; j += 2) {
  38079. next = alpha * x[j + 1];
  38080. x[j] -= current + next;
  38081. if (n--) {
  38082. j += 2;
  38083. current = alpha * x[j + 1];
  38084. x[j] -= current + next;
  38085. } else {
  38086. break;
  38087. }
  38088. }
  38089. }
  38090. };
  38091. return IrreversibleTransform;
  38092. })();
  38093. // Section 3.8.1 Reversible 5-3 filter
  38094. var ReversibleTransform = (function ReversibleTransformClosure() {
  38095. function ReversibleTransform() {
  38096. Transform.call(this);
  38097. }
  38098. ReversibleTransform.prototype = Object.create(Transform.prototype);
  38099. ReversibleTransform.prototype.filter =
  38100. function reversibleTransformFilter(x, offset, length) {
  38101. var len = length >> 1;
  38102. offset = offset | 0;
  38103. var j, n;
  38104. for (j = offset, n = len + 1; n--; j += 2) {
  38105. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  38106. }
  38107. for (j = offset + 1, n = len; n--; j += 2) {
  38108. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  38109. }
  38110. };
  38111. return ReversibleTransform;
  38112. })();
  38113. return JpxImage;
  38114. })();
  38115. var Jbig2Image = (function Jbig2ImageClosure() {
  38116. // Utility data structures
  38117. function ContextCache() {}
  38118. ContextCache.prototype = {
  38119. getContexts: function(id) {
  38120. if (id in this) {
  38121. return this[id];
  38122. }
  38123. return (this[id] = new Int8Array(1 << 16));
  38124. }
  38125. };
  38126. function DecodingContext(data, start, end) {
  38127. this.data = data;
  38128. this.start = start;
  38129. this.end = end;
  38130. }
  38131. DecodingContext.prototype = {
  38132. get decoder() {
  38133. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  38134. return shadow(this, 'decoder', decoder);
  38135. },
  38136. get contextCache() {
  38137. var cache = new ContextCache();
  38138. return shadow(this, 'contextCache', cache);
  38139. }
  38140. };
  38141. // Annex A. Arithmetic Integer Decoding Procedure
  38142. // A.2 Procedure for decoding values
  38143. function decodeInteger(contextCache, procedure, decoder) {
  38144. var contexts = contextCache.getContexts(procedure);
  38145. var prev = 1;
  38146. function readBits(length) {
  38147. var v = 0;
  38148. for (var i = 0; i < length; i++) {
  38149. var bit = decoder.readBit(contexts, prev);
  38150. prev = (prev < 256 ? (prev << 1) | bit :
  38151. (((prev << 1) | bit) & 511) | 256);
  38152. v = (v << 1) | bit;
  38153. }
  38154. return v >>> 0;
  38155. }
  38156. var sign = readBits(1);
  38157. var value = readBits(1) ?
  38158. (readBits(1) ?
  38159. (readBits(1) ?
  38160. (readBits(1) ?
  38161. (readBits(1) ?
  38162. (readBits(32) + 4436) :
  38163. readBits(12) + 340) :
  38164. readBits(8) + 84) :
  38165. readBits(6) + 20) :
  38166. readBits(4) + 4) :
  38167. readBits(2);
  38168. return (sign === 0 ? value : (value > 0 ? -value : null));
  38169. }
  38170. // A.3 The IAID decoding procedure
  38171. function decodeIAID(contextCache, decoder, codeLength) {
  38172. var contexts = contextCache.getContexts('IAID');
  38173. var prev = 1;
  38174. for (var i = 0; i < codeLength; i++) {
  38175. var bit = decoder.readBit(contexts, prev);
  38176. prev = (prev << 1) | bit;
  38177. }
  38178. if (codeLength < 31) {
  38179. return prev & ((1 << codeLength) - 1);
  38180. }
  38181. return prev & 0x7FFFFFFF;
  38182. }
  38183. // 7.3 Segment types
  38184. var SegmentTypes = [
  38185. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  38186. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  38187. null, null, null, null, null, 'patternDictionary', null, null, null,
  38188. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  38189. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  38190. null, null, null, null, null, 'IntermediateGenericRegion', null,
  38191. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  38192. 'IntermediateGenericRefinementRegion', null,
  38193. 'ImmediateGenericRefinementRegion',
  38194. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  38195. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  38196. 'Tables', null, null, null, null, null, null, null, null,
  38197. 'Extension'
  38198. ];
  38199. var CodingTemplates = [
  38200. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  38201. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  38202. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  38203. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  38204. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  38205. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  38206. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  38207. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  38208. {x: -1, y: 0}],
  38209. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  38210. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  38211. ];
  38212. var RefinementTemplates = [
  38213. {
  38214. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  38215. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  38216. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  38217. },
  38218. {
  38219. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  38220. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  38221. {x: 0, y: 1}, {x: 1, y: 1}]
  38222. }
  38223. ];
  38224. // See 6.2.5.7 Decoding the bitmap.
  38225. var ReusedContexts = [
  38226. 0x9B25, // 10011 0110010 0101
  38227. 0x0795, // 0011 110010 101
  38228. 0x00E5, // 001 11001 01
  38229. 0x0195 // 011001 0101
  38230. ];
  38231. var RefinementReusedContexts = [
  38232. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  38233. 0x0008 // '0000' + '001000'
  38234. ];
  38235. // 6.2 Generic Region Decoding Procedure
  38236. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  38237. decodingContext) {
  38238. if (mmr) {
  38239. error('JBIG2 error: MMR encoding is not supported');
  38240. }
  38241. var useskip = !!skip;
  38242. var template = CodingTemplates[templateIndex].concat(at);
  38243. // Sorting is non-standard, and it is not required. But sorting increases
  38244. // the number of template bits that can be reused from the previous
  38245. // contextLabel in the main loop.
  38246. template.sort(function (a, b) {
  38247. return (a.y - b.y) || (a.x - b.x);
  38248. });
  38249. var templateLength = template.length;
  38250. var templateX = new Int8Array(templateLength);
  38251. var templateY = new Int8Array(templateLength);
  38252. var changingTemplateEntries = [];
  38253. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  38254. var c, k;
  38255. for (k = 0; k < templateLength; k++) {
  38256. templateX[k] = template[k].x;
  38257. templateY[k] = template[k].y;
  38258. minX = Math.min(minX, template[k].x);
  38259. maxX = Math.max(maxX, template[k].x);
  38260. minY = Math.min(minY, template[k].y);
  38261. // Check if the template pixel appears in two consecutive context labels,
  38262. // so it can be reused. Otherwise, we add it to the list of changing
  38263. // template entries.
  38264. if (k < templateLength - 1 &&
  38265. template[k].y === template[k + 1].y &&
  38266. template[k].x === template[k + 1].x - 1) {
  38267. reuseMask |= 1 << (templateLength - 1 - k);
  38268. } else {
  38269. changingTemplateEntries.push(k);
  38270. }
  38271. }
  38272. var changingEntriesLength = changingTemplateEntries.length;
  38273. var changingTemplateX = new Int8Array(changingEntriesLength);
  38274. var changingTemplateY = new Int8Array(changingEntriesLength);
  38275. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  38276. for (c = 0; c < changingEntriesLength; c++) {
  38277. k = changingTemplateEntries[c];
  38278. changingTemplateX[c] = template[k].x;
  38279. changingTemplateY[c] = template[k].y;
  38280. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  38281. }
  38282. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  38283. var sbb_left = -minX;
  38284. var sbb_top = -minY;
  38285. var sbb_right = width - maxX;
  38286. var pseudoPixelContext = ReusedContexts[templateIndex];
  38287. var row = new Uint8Array(width);
  38288. var bitmap = [];
  38289. var decoder = decodingContext.decoder;
  38290. var contexts = decodingContext.contextCache.getContexts('GB');
  38291. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  38292. for (var i = 0; i < height; i++) {
  38293. if (prediction) {
  38294. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  38295. ltp ^= sltp;
  38296. if (ltp) {
  38297. bitmap.push(row); // duplicate previous row
  38298. continue;
  38299. }
  38300. }
  38301. row = new Uint8Array(row);
  38302. bitmap.push(row);
  38303. for (j = 0; j < width; j++) {
  38304. if (useskip && skip[i][j]) {
  38305. row[j] = 0;
  38306. continue;
  38307. }
  38308. // Are we in the middle of a scanline, so we can reuse contextLabel
  38309. // bits?
  38310. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  38311. // If yes, we can just shift the bits that are reusable and only
  38312. // fetch the remaining ones.
  38313. contextLabel = (contextLabel << 1) & reuseMask;
  38314. for (k = 0; k < changingEntriesLength; k++) {
  38315. i0 = i + changingTemplateY[k];
  38316. j0 = j + changingTemplateX[k];
  38317. bit = bitmap[i0][j0];
  38318. if (bit) {
  38319. bit = changingTemplateBit[k];
  38320. contextLabel |= bit;
  38321. }
  38322. }
  38323. } else {
  38324. // compute the contextLabel from scratch
  38325. contextLabel = 0;
  38326. shift = templateLength - 1;
  38327. for (k = 0; k < templateLength; k++, shift--) {
  38328. j0 = j + templateX[k];
  38329. if (j0 >= 0 && j0 < width) {
  38330. i0 = i + templateY[k];
  38331. if (i0 >= 0) {
  38332. bit = bitmap[i0][j0];
  38333. if (bit) {
  38334. contextLabel |= bit << shift;
  38335. }
  38336. }
  38337. }
  38338. }
  38339. }
  38340. var pixel = decoder.readBit(contexts, contextLabel);
  38341. row[j] = pixel;
  38342. }
  38343. }
  38344. return bitmap;
  38345. }
  38346. // 6.3.2 Generic Refinement Region Decoding Procedure
  38347. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  38348. offsetX, offsetY, prediction, at,
  38349. decodingContext) {
  38350. var codingTemplate = RefinementTemplates[templateIndex].coding;
  38351. if (templateIndex === 0) {
  38352. codingTemplate = codingTemplate.concat([at[0]]);
  38353. }
  38354. var codingTemplateLength = codingTemplate.length;
  38355. var codingTemplateX = new Int32Array(codingTemplateLength);
  38356. var codingTemplateY = new Int32Array(codingTemplateLength);
  38357. var k;
  38358. for (k = 0; k < codingTemplateLength; k++) {
  38359. codingTemplateX[k] = codingTemplate[k].x;
  38360. codingTemplateY[k] = codingTemplate[k].y;
  38361. }
  38362. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  38363. if (templateIndex === 0) {
  38364. referenceTemplate = referenceTemplate.concat([at[1]]);
  38365. }
  38366. var referenceTemplateLength = referenceTemplate.length;
  38367. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  38368. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  38369. for (k = 0; k < referenceTemplateLength; k++) {
  38370. referenceTemplateX[k] = referenceTemplate[k].x;
  38371. referenceTemplateY[k] = referenceTemplate[k].y;
  38372. }
  38373. var referenceWidth = referenceBitmap[0].length;
  38374. var referenceHeight = referenceBitmap.length;
  38375. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  38376. var bitmap = [];
  38377. var decoder = decodingContext.decoder;
  38378. var contexts = decodingContext.contextCache.getContexts('GR');
  38379. var ltp = 0;
  38380. for (var i = 0; i < height; i++) {
  38381. if (prediction) {
  38382. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  38383. ltp ^= sltp;
  38384. if (ltp) {
  38385. error('JBIG2 error: prediction is not supported');
  38386. }
  38387. }
  38388. var row = new Uint8Array(width);
  38389. bitmap.push(row);
  38390. for (var j = 0; j < width; j++) {
  38391. var i0, j0;
  38392. var contextLabel = 0;
  38393. for (k = 0; k < codingTemplateLength; k++) {
  38394. i0 = i + codingTemplateY[k];
  38395. j0 = j + codingTemplateX[k];
  38396. if (i0 < 0 || j0 < 0 || j0 >= width) {
  38397. contextLabel <<= 1; // out of bound pixel
  38398. } else {
  38399. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  38400. }
  38401. }
  38402. for (k = 0; k < referenceTemplateLength; k++) {
  38403. i0 = i + referenceTemplateY[k] + offsetY;
  38404. j0 = j + referenceTemplateX[k] + offsetX;
  38405. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  38406. j0 >= referenceWidth) {
  38407. contextLabel <<= 1; // out of bound pixel
  38408. } else {
  38409. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  38410. }
  38411. }
  38412. var pixel = decoder.readBit(contexts, contextLabel);
  38413. row[j] = pixel;
  38414. }
  38415. }
  38416. return bitmap;
  38417. }
  38418. // 6.5.5 Decoding the symbol dictionary
  38419. function decodeSymbolDictionary(huffman, refinement, symbols,
  38420. numberOfNewSymbols, numberOfExportedSymbols,
  38421. huffmanTables, templateIndex, at,
  38422. refinementTemplateIndex, refinementAt,
  38423. decodingContext) {
  38424. if (huffman) {
  38425. error('JBIG2 error: huffman is not supported');
  38426. }
  38427. var newSymbols = [];
  38428. var currentHeight = 0;
  38429. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  38430. var decoder = decodingContext.decoder;
  38431. var contextCache = decodingContext.contextCache;
  38432. while (newSymbols.length < numberOfNewSymbols) {
  38433. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  38434. currentHeight += deltaHeight;
  38435. var currentWidth = 0;
  38436. var totalWidth = 0;
  38437. while (true) {
  38438. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  38439. if (deltaWidth === null) {
  38440. break; // OOB
  38441. }
  38442. currentWidth += deltaWidth;
  38443. totalWidth += currentWidth;
  38444. var bitmap;
  38445. if (refinement) {
  38446. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  38447. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  38448. if (numberOfInstances > 1) {
  38449. bitmap = decodeTextRegion(huffman, refinement,
  38450. currentWidth, currentHeight, 0,
  38451. numberOfInstances, 1, //strip size
  38452. symbols.concat(newSymbols),
  38453. symbolCodeLength,
  38454. 0, //transposed
  38455. 0, //ds offset
  38456. 1, //top left 7.4.3.1.1
  38457. 0, //OR operator
  38458. huffmanTables,
  38459. refinementTemplateIndex, refinementAt,
  38460. decodingContext);
  38461. } else {
  38462. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  38463. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  38464. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  38465. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  38466. newSymbols[symbolId - symbols.length]);
  38467. bitmap = decodeRefinement(currentWidth, currentHeight,
  38468. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  38469. decodingContext);
  38470. }
  38471. } else {
  38472. // 6.5.8.1 Direct-coded symbol bitmap
  38473. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  38474. templateIndex, false, null, at, decodingContext);
  38475. }
  38476. newSymbols.push(bitmap);
  38477. }
  38478. }
  38479. // 6.5.10 Exported symbols
  38480. var exportedSymbols = [];
  38481. var flags = [], currentFlag = false;
  38482. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  38483. while (flags.length < totalSymbolsLength) {
  38484. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  38485. while (runLength--) {
  38486. flags.push(currentFlag);
  38487. }
  38488. currentFlag = !currentFlag;
  38489. }
  38490. for (var i = 0, ii = symbols.length; i < ii; i++) {
  38491. if (flags[i]) {
  38492. exportedSymbols.push(symbols[i]);
  38493. }
  38494. }
  38495. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  38496. if (flags[i]) {
  38497. exportedSymbols.push(newSymbols[j]);
  38498. }
  38499. }
  38500. return exportedSymbols;
  38501. }
  38502. function decodeTextRegion(huffman, refinement, width, height,
  38503. defaultPixelValue, numberOfSymbolInstances,
  38504. stripSize, inputSymbols, symbolCodeLength,
  38505. transposed, dsOffset, referenceCorner,
  38506. combinationOperator, huffmanTables,
  38507. refinementTemplateIndex, refinementAt,
  38508. decodingContext) {
  38509. if (huffman) {
  38510. error('JBIG2 error: huffman is not supported');
  38511. }
  38512. // Prepare bitmap
  38513. var bitmap = [];
  38514. var i, row;
  38515. for (i = 0; i < height; i++) {
  38516. row = new Uint8Array(width);
  38517. if (defaultPixelValue) {
  38518. for (var j = 0; j < width; j++) {
  38519. row[j] = defaultPixelValue;
  38520. }
  38521. }
  38522. bitmap.push(row);
  38523. }
  38524. var decoder = decodingContext.decoder;
  38525. var contextCache = decodingContext.contextCache;
  38526. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  38527. var firstS = 0;
  38528. i = 0;
  38529. while (i < numberOfSymbolInstances) {
  38530. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  38531. stripT += deltaT;
  38532. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  38533. firstS += deltaFirstS;
  38534. var currentS = firstS;
  38535. do {
  38536. var currentT = (stripSize === 1 ? 0 :
  38537. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  38538. var t = stripSize * stripT + currentT;
  38539. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  38540. var applyRefinement = (refinement &&
  38541. decodeInteger(contextCache, 'IARI', decoder));
  38542. var symbolBitmap = inputSymbols[symbolId];
  38543. var symbolWidth = symbolBitmap[0].length;
  38544. var symbolHeight = symbolBitmap.length;
  38545. if (applyRefinement) {
  38546. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  38547. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  38548. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  38549. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  38550. symbolWidth += rdw;
  38551. symbolHeight += rdh;
  38552. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  38553. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  38554. (rdh >> 1) + rdy, false, refinementAt,
  38555. decodingContext);
  38556. }
  38557. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  38558. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  38559. var s2, t2, symbolRow;
  38560. if (transposed) {
  38561. // Place Symbol Bitmap from T1,S1
  38562. for (s2 = 0; s2 < symbolHeight; s2++) {
  38563. row = bitmap[offsetS + s2];
  38564. if (!row) {
  38565. continue;
  38566. }
  38567. symbolRow = symbolBitmap[s2];
  38568. // To ignore Parts of Symbol bitmap which goes
  38569. // outside bitmap region
  38570. var maxWidth = Math.min(width - offsetT, symbolWidth);
  38571. switch (combinationOperator) {
  38572. case 0: // OR
  38573. for (t2 = 0; t2 < maxWidth; t2++) {
  38574. row[offsetT + t2] |= symbolRow[t2];
  38575. }
  38576. break;
  38577. case 2: // XOR
  38578. for (t2 = 0; t2 < maxWidth; t2++) {
  38579. row[offsetT + t2] ^= symbolRow[t2];
  38580. }
  38581. break;
  38582. default:
  38583. error('JBIG2 error: operator ' + combinationOperator +
  38584. ' is not supported');
  38585. }
  38586. }
  38587. currentS += symbolHeight - 1;
  38588. } else {
  38589. for (t2 = 0; t2 < symbolHeight; t2++) {
  38590. row = bitmap[offsetT + t2];
  38591. if (!row) {
  38592. continue;
  38593. }
  38594. symbolRow = symbolBitmap[t2];
  38595. switch (combinationOperator) {
  38596. case 0: // OR
  38597. for (s2 = 0; s2 < symbolWidth; s2++) {
  38598. row[offsetS + s2] |= symbolRow[s2];
  38599. }
  38600. break;
  38601. case 2: // XOR
  38602. for (s2 = 0; s2 < symbolWidth; s2++) {
  38603. row[offsetS + s2] ^= symbolRow[s2];
  38604. }
  38605. break;
  38606. default:
  38607. error('JBIG2 error: operator ' + combinationOperator +
  38608. ' is not supported');
  38609. }
  38610. }
  38611. currentS += symbolWidth - 1;
  38612. }
  38613. i++;
  38614. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  38615. if (deltaS === null) {
  38616. break; // OOB
  38617. }
  38618. currentS += deltaS + dsOffset;
  38619. } while (true);
  38620. }
  38621. return bitmap;
  38622. }
  38623. function readSegmentHeader(data, start) {
  38624. var segmentHeader = {};
  38625. segmentHeader.number = readUint32(data, start);
  38626. var flags = data[start + 4];
  38627. var segmentType = flags & 0x3F;
  38628. if (!SegmentTypes[segmentType]) {
  38629. error('JBIG2 error: invalid segment type: ' + segmentType);
  38630. }
  38631. segmentHeader.type = segmentType;
  38632. segmentHeader.typeName = SegmentTypes[segmentType];
  38633. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  38634. var pageAssociationFieldSize = !!(flags & 0x40);
  38635. var referredFlags = data[start + 5];
  38636. var referredToCount = (referredFlags >> 5) & 7;
  38637. var retainBits = [referredFlags & 31];
  38638. var position = start + 6;
  38639. if (referredFlags === 7) {
  38640. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  38641. position += 3;
  38642. var bytes = (referredToCount + 7) >> 3;
  38643. retainBits[0] = data[position++];
  38644. while (--bytes > 0) {
  38645. retainBits.push(data[position++]);
  38646. }
  38647. } else if (referredFlags === 5 || referredFlags === 6) {
  38648. error('JBIG2 error: invalid referred-to flags');
  38649. }
  38650. segmentHeader.retainBits = retainBits;
  38651. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  38652. (segmentHeader.number <= 65536 ? 2 : 4));
  38653. var referredTo = [];
  38654. var i, ii;
  38655. for (i = 0; i < referredToCount; i++) {
  38656. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  38657. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  38658. readUint32(data, position)));
  38659. referredTo.push(number);
  38660. position += referredToSegmentNumberSize;
  38661. }
  38662. segmentHeader.referredTo = referredTo;
  38663. if (!pageAssociationFieldSize) {
  38664. segmentHeader.pageAssociation = data[position++];
  38665. } else {
  38666. segmentHeader.pageAssociation = readUint32(data, position);
  38667. position += 4;
  38668. }
  38669. segmentHeader.length = readUint32(data, position);
  38670. position += 4;
  38671. if (segmentHeader.length === 0xFFFFFFFF) {
  38672. // 7.2.7 Segment data length, unknown segment length
  38673. if (segmentType === 38) { // ImmediateGenericRegion
  38674. var genericRegionInfo = readRegionSegmentInformation(data, position);
  38675. var genericRegionSegmentFlags = data[position +
  38676. RegionSegmentInformationFieldLength];
  38677. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  38678. // searching for the segment end
  38679. var searchPatternLength = 6;
  38680. var searchPattern = new Uint8Array(searchPatternLength);
  38681. if (!genericRegionMmr) {
  38682. searchPattern[0] = 0xFF;
  38683. searchPattern[1] = 0xAC;
  38684. }
  38685. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  38686. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  38687. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  38688. searchPattern[5] = genericRegionInfo.height & 0xFF;
  38689. for (i = position, ii = data.length; i < ii; i++) {
  38690. var j = 0;
  38691. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  38692. j++;
  38693. }
  38694. if (j === searchPatternLength) {
  38695. segmentHeader.length = i + searchPatternLength;
  38696. break;
  38697. }
  38698. }
  38699. if (segmentHeader.length === 0xFFFFFFFF) {
  38700. error('JBIG2 error: segment end was not found');
  38701. }
  38702. } else {
  38703. error('JBIG2 error: invalid unknown segment length');
  38704. }
  38705. }
  38706. segmentHeader.headerEnd = position;
  38707. return segmentHeader;
  38708. }
  38709. function readSegments(header, data, start, end) {
  38710. var segments = [];
  38711. var position = start;
  38712. while (position < end) {
  38713. var segmentHeader = readSegmentHeader(data, position);
  38714. position = segmentHeader.headerEnd;
  38715. var segment = {
  38716. header: segmentHeader,
  38717. data: data
  38718. };
  38719. if (!header.randomAccess) {
  38720. segment.start = position;
  38721. position += segmentHeader.length;
  38722. segment.end = position;
  38723. }
  38724. segments.push(segment);
  38725. if (segmentHeader.type === 51) {
  38726. break; // end of file is found
  38727. }
  38728. }
  38729. if (header.randomAccess) {
  38730. for (var i = 0, ii = segments.length; i < ii; i++) {
  38731. segments[i].start = position;
  38732. position += segments[i].header.length;
  38733. segments[i].end = position;
  38734. }
  38735. }
  38736. return segments;
  38737. }
  38738. // 7.4.1 Region segment information field
  38739. function readRegionSegmentInformation(data, start) {
  38740. return {
  38741. width: readUint32(data, start),
  38742. height: readUint32(data, start + 4),
  38743. x: readUint32(data, start + 8),
  38744. y: readUint32(data, start + 12),
  38745. combinationOperator: data[start + 16] & 7
  38746. };
  38747. }
  38748. var RegionSegmentInformationFieldLength = 17;
  38749. function processSegment(segment, visitor) {
  38750. var header = segment.header;
  38751. var data = segment.data, position = segment.start, end = segment.end;
  38752. var args, at, i, atLength;
  38753. switch (header.type) {
  38754. case 0: // SymbolDictionary
  38755. // 7.4.2 Symbol dictionary segment syntax
  38756. var dictionary = {};
  38757. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  38758. dictionary.huffman = !!(dictionaryFlags & 1);
  38759. dictionary.refinement = !!(dictionaryFlags & 2);
  38760. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  38761. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  38762. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  38763. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  38764. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  38765. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  38766. dictionary.template = (dictionaryFlags >> 10) & 3;
  38767. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  38768. position += 2;
  38769. if (!dictionary.huffman) {
  38770. atLength = dictionary.template === 0 ? 4 : 1;
  38771. at = [];
  38772. for (i = 0; i < atLength; i++) {
  38773. at.push({
  38774. x: readInt8(data, position),
  38775. y: readInt8(data, position + 1)
  38776. });
  38777. position += 2;
  38778. }
  38779. dictionary.at = at;
  38780. }
  38781. if (dictionary.refinement && !dictionary.refinementTemplate) {
  38782. at = [];
  38783. for (i = 0; i < 2; i++) {
  38784. at.push({
  38785. x: readInt8(data, position),
  38786. y: readInt8(data, position + 1)
  38787. });
  38788. position += 2;
  38789. }
  38790. dictionary.refinementAt = at;
  38791. }
  38792. dictionary.numberOfExportedSymbols = readUint32(data, position);
  38793. position += 4;
  38794. dictionary.numberOfNewSymbols = readUint32(data, position);
  38795. position += 4;
  38796. args = [dictionary, header.number, header.referredTo,
  38797. data, position, end];
  38798. break;
  38799. case 6: // ImmediateTextRegion
  38800. case 7: // ImmediateLosslessTextRegion
  38801. var textRegion = {};
  38802. textRegion.info = readRegionSegmentInformation(data, position);
  38803. position += RegionSegmentInformationFieldLength;
  38804. var textRegionSegmentFlags = readUint16(data, position);
  38805. position += 2;
  38806. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  38807. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  38808. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  38809. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  38810. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  38811. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  38812. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  38813. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  38814. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  38815. if (textRegion.huffman) {
  38816. var textRegionHuffmanFlags = readUint16(data, position);
  38817. position += 2;
  38818. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  38819. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  38820. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  38821. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  38822. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  38823. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  38824. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  38825. textRegion.huffmanRefinementSizeSelector =
  38826. !!(textRegionHuffmanFlags & 14);
  38827. }
  38828. if (textRegion.refinement && !textRegion.refinementTemplate) {
  38829. at = [];
  38830. for (i = 0; i < 2; i++) {
  38831. at.push({
  38832. x: readInt8(data, position),
  38833. y: readInt8(data, position + 1)
  38834. });
  38835. position += 2;
  38836. }
  38837. textRegion.refinementAt = at;
  38838. }
  38839. textRegion.numberOfSymbolInstances = readUint32(data, position);
  38840. position += 4;
  38841. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  38842. if (textRegion.huffman) {
  38843. error('JBIG2 error: huffman is not supported');
  38844. }
  38845. args = [textRegion, header.referredTo, data, position, end];
  38846. break;
  38847. case 38: // ImmediateGenericRegion
  38848. case 39: // ImmediateLosslessGenericRegion
  38849. var genericRegion = {};
  38850. genericRegion.info = readRegionSegmentInformation(data, position);
  38851. position += RegionSegmentInformationFieldLength;
  38852. var genericRegionSegmentFlags = data[position++];
  38853. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  38854. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  38855. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  38856. if (!genericRegion.mmr) {
  38857. atLength = genericRegion.template === 0 ? 4 : 1;
  38858. at = [];
  38859. for (i = 0; i < atLength; i++) {
  38860. at.push({
  38861. x: readInt8(data, position),
  38862. y: readInt8(data, position + 1)
  38863. });
  38864. position += 2;
  38865. }
  38866. genericRegion.at = at;
  38867. }
  38868. args = [genericRegion, data, position, end];
  38869. break;
  38870. case 48: // PageInformation
  38871. var pageInfo = {
  38872. width: readUint32(data, position),
  38873. height: readUint32(data, position + 4),
  38874. resolutionX: readUint32(data, position + 8),
  38875. resolutionY: readUint32(data, position + 12)
  38876. };
  38877. if (pageInfo.height === 0xFFFFFFFF) {
  38878. delete pageInfo.height;
  38879. }
  38880. var pageSegmentFlags = data[position + 16];
  38881. var pageStripingInformatiom = readUint16(data, position + 17);
  38882. pageInfo.lossless = !!(pageSegmentFlags & 1);
  38883. pageInfo.refinement = !!(pageSegmentFlags & 2);
  38884. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  38885. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  38886. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  38887. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  38888. args = [pageInfo];
  38889. break;
  38890. case 49: // EndOfPage
  38891. break;
  38892. case 50: // EndOfStripe
  38893. break;
  38894. case 51: // EndOfFile
  38895. break;
  38896. case 62: // 7.4.15 defines 2 extension types which
  38897. // are comments and can be ignored.
  38898. break;
  38899. default:
  38900. error('JBIG2 error: segment type ' + header.typeName + '(' +
  38901. header.type + ') is not implemented');
  38902. }
  38903. var callbackName = 'on' + header.typeName;
  38904. if (callbackName in visitor) {
  38905. visitor[callbackName].apply(visitor, args);
  38906. }
  38907. }
  38908. function processSegments(segments, visitor) {
  38909. for (var i = 0, ii = segments.length; i < ii; i++) {
  38910. processSegment(segments[i], visitor);
  38911. }
  38912. }
  38913. function parseJbig2(data, start, end) {
  38914. var position = start;
  38915. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  38916. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  38917. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  38918. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  38919. error('JBIG2 error: invalid header');
  38920. }
  38921. var header = {};
  38922. position += 8;
  38923. var flags = data[position++];
  38924. header.randomAccess = !(flags & 1);
  38925. if (!(flags & 2)) {
  38926. header.numberOfPages = readUint32(data, position);
  38927. position += 4;
  38928. }
  38929. var segments = readSegments(header, data, position, end);
  38930. error('Not implemented');
  38931. // processSegments(segments, new SimpleSegmentVisitor());
  38932. }
  38933. function parseJbig2Chunks(chunks) {
  38934. var visitor = new SimpleSegmentVisitor();
  38935. for (var i = 0, ii = chunks.length; i < ii; i++) {
  38936. var chunk = chunks[i];
  38937. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  38938. processSegments(segments, visitor);
  38939. }
  38940. return visitor.buffer;
  38941. }
  38942. function SimpleSegmentVisitor() {}
  38943. SimpleSegmentVisitor.prototype = {
  38944. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  38945. this.currentPageInfo = info;
  38946. var rowSize = (info.width + 7) >> 3;
  38947. var buffer = new Uint8Array(rowSize * info.height);
  38948. // The contents of ArrayBuffers are initialized to 0.
  38949. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  38950. if (info.defaultPixelValue) {
  38951. for (var i = 0, ii = buffer.length; i < ii; i++) {
  38952. buffer[i] = 0xFF;
  38953. }
  38954. }
  38955. this.buffer = buffer;
  38956. },
  38957. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  38958. var pageInfo = this.currentPageInfo;
  38959. var width = regionInfo.width, height = regionInfo.height;
  38960. var rowSize = (pageInfo.width + 7) >> 3;
  38961. var combinationOperator = pageInfo.combinationOperatorOverride ?
  38962. regionInfo.combinationOperator : pageInfo.combinationOperator;
  38963. var buffer = this.buffer;
  38964. var mask0 = 128 >> (regionInfo.x & 7);
  38965. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  38966. var i, j, mask, offset;
  38967. switch (combinationOperator) {
  38968. case 0: // OR
  38969. for (i = 0; i < height; i++) {
  38970. mask = mask0;
  38971. offset = offset0;
  38972. for (j = 0; j < width; j++) {
  38973. if (bitmap[i][j]) {
  38974. buffer[offset] |= mask;
  38975. }
  38976. mask >>= 1;
  38977. if (!mask) {
  38978. mask = 128;
  38979. offset++;
  38980. }
  38981. }
  38982. offset0 += rowSize;
  38983. }
  38984. break;
  38985. case 2: // XOR
  38986. for (i = 0; i < height; i++) {
  38987. mask = mask0;
  38988. offset = offset0;
  38989. for (j = 0; j < width; j++) {
  38990. if (bitmap[i][j]) {
  38991. buffer[offset] ^= mask;
  38992. }
  38993. mask >>= 1;
  38994. if (!mask) {
  38995. mask = 128;
  38996. offset++;
  38997. }
  38998. }
  38999. offset0 += rowSize;
  39000. }
  39001. break;
  39002. default:
  39003. error('JBIG2 error: operator ' + combinationOperator +
  39004. ' is not supported');
  39005. }
  39006. },
  39007. onImmediateGenericRegion:
  39008. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  39009. start, end) {
  39010. var regionInfo = region.info;
  39011. var decodingContext = new DecodingContext(data, start, end);
  39012. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  39013. region.template, region.prediction, null,
  39014. region.at, decodingContext);
  39015. this.drawBitmap(regionInfo, bitmap);
  39016. },
  39017. onImmediateLosslessGenericRegion:
  39018. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  39019. this.onImmediateGenericRegion.apply(this, arguments);
  39020. },
  39021. onSymbolDictionary:
  39022. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  39023. currentSegment,
  39024. referredSegments,
  39025. data, start, end) {
  39026. var huffmanTables;
  39027. if (dictionary.huffman) {
  39028. error('JBIG2 error: huffman is not supported');
  39029. }
  39030. // Combines exported symbols from all referred segments
  39031. var symbols = this.symbols;
  39032. if (!symbols) {
  39033. this.symbols = symbols = {};
  39034. }
  39035. var inputSymbols = [];
  39036. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  39037. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  39038. }
  39039. var decodingContext = new DecodingContext(data, start, end);
  39040. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  39041. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  39042. dictionary.numberOfExportedSymbols, huffmanTables,
  39043. dictionary.template, dictionary.at,
  39044. dictionary.refinementTemplate, dictionary.refinementAt,
  39045. decodingContext);
  39046. },
  39047. onImmediateTextRegion:
  39048. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  39049. referredSegments,
  39050. data, start, end) {
  39051. var regionInfo = region.info;
  39052. var huffmanTables;
  39053. // Combines exported symbols from all referred segments
  39054. var symbols = this.symbols;
  39055. var inputSymbols = [];
  39056. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  39057. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  39058. }
  39059. var symbolCodeLength = log2(inputSymbols.length);
  39060. var decodingContext = new DecodingContext(data, start, end);
  39061. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  39062. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  39063. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  39064. symbolCodeLength, region.transposed, region.dsOffset,
  39065. region.referenceCorner, region.combinationOperator, huffmanTables,
  39066. region.refinementTemplate, region.refinementAt, decodingContext);
  39067. this.drawBitmap(regionInfo, bitmap);
  39068. },
  39069. onImmediateLosslessTextRegion:
  39070. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  39071. this.onImmediateTextRegion.apply(this, arguments);
  39072. }
  39073. };
  39074. function Jbig2Image() {}
  39075. Jbig2Image.prototype = {
  39076. parseChunks: function Jbig2Image_parseChunks(chunks) {
  39077. return parseJbig2Chunks(chunks);
  39078. }
  39079. };
  39080. return Jbig2Image;
  39081. })();
  39082. var bidi = PDFJS.bidi = (function bidiClosure() {
  39083. // Character types for symbols from 0000 to 00FF.
  39084. var baseTypes = [
  39085. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  39086. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  39087. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  39088. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  39089. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  39090. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39091. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  39092. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39093. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39094. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  39095. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  39096. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  39097. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  39098. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  39099. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39100. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39101. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39102. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  39103. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  39104. ];
  39105. // Character types for symbols from 0600 to 06FF
  39106. var arabicTypes = [
  39107. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39108. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  39109. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39110. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39111. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39112. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39113. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  39114. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  39115. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  39116. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  39117. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39118. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39119. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39120. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39121. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39122. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39123. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39124. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39125. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  39126. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  39127. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  39128. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  39129. ];
  39130. function isOdd(i) {
  39131. return (i & 1) !== 0;
  39132. }
  39133. function isEven(i) {
  39134. return (i & 1) === 0;
  39135. }
  39136. function findUnequal(arr, start, value) {
  39137. for (var j = start, jj = arr.length; j < jj; ++j) {
  39138. if (arr[j] !== value) {
  39139. return j;
  39140. }
  39141. }
  39142. return j;
  39143. }
  39144. function setValues(arr, start, end, value) {
  39145. for (var j = start; j < end; ++j) {
  39146. arr[j] = value;
  39147. }
  39148. }
  39149. function reverseValues(arr, start, end) {
  39150. for (var i = start, j = end - 1; i < j; ++i, --j) {
  39151. var temp = arr[i];
  39152. arr[i] = arr[j];
  39153. arr[j] = temp;
  39154. }
  39155. }
  39156. function createBidiText(str, isLTR, vertical) {
  39157. return {
  39158. str: str,
  39159. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  39160. };
  39161. }
  39162. // These are used in bidi(), which is called frequently. We re-use them on
  39163. // each call to avoid unnecessary allocations.
  39164. var chars = [];
  39165. var types = [];
  39166. function bidi(str, startLevel, vertical) {
  39167. var isLTR = true;
  39168. var strLength = str.length;
  39169. if (strLength === 0 || vertical) {
  39170. return createBidiText(str, isLTR, vertical);
  39171. }
  39172. // Get types and fill arrays
  39173. chars.length = strLength;
  39174. types.length = strLength;
  39175. var numBidi = 0;
  39176. var i, ii;
  39177. for (i = 0; i < strLength; ++i) {
  39178. chars[i] = str.charAt(i);
  39179. var charCode = str.charCodeAt(i);
  39180. var charType = 'L';
  39181. if (charCode <= 0x00ff) {
  39182. charType = baseTypes[charCode];
  39183. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  39184. charType = 'R';
  39185. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  39186. charType = arabicTypes[charCode & 0xff];
  39187. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  39188. charType = 'AL';
  39189. }
  39190. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  39191. numBidi++;
  39192. }
  39193. types[i] = charType;
  39194. }
  39195. // Detect the bidi method
  39196. // - If there are no rtl characters then no bidi needed
  39197. // - If less than 30% chars are rtl then string is primarily ltr
  39198. // - If more than 30% chars are rtl then string is primarily rtl
  39199. if (numBidi === 0) {
  39200. isLTR = true;
  39201. return createBidiText(str, isLTR);
  39202. }
  39203. if (startLevel === -1) {
  39204. if ((strLength / numBidi) < 0.3) {
  39205. isLTR = true;
  39206. startLevel = 0;
  39207. } else {
  39208. isLTR = false;
  39209. startLevel = 1;
  39210. }
  39211. }
  39212. var levels = [];
  39213. for (i = 0; i < strLength; ++i) {
  39214. levels[i] = startLevel;
  39215. }
  39216. /*
  39217. X1-X10: skip most of this, since we are NOT doing the embeddings.
  39218. */
  39219. var e = (isOdd(startLevel) ? 'R' : 'L');
  39220. var sor = e;
  39221. var eor = sor;
  39222. /*
  39223. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  39224. type of the NSM to the type of the previous character. If the NSM is at the
  39225. start of the level run, it will get the type of sor.
  39226. */
  39227. var lastType = sor;
  39228. for (i = 0; i < strLength; ++i) {
  39229. if (types[i] === 'NSM') {
  39230. types[i] = lastType;
  39231. } else {
  39232. lastType = types[i];
  39233. }
  39234. }
  39235. /*
  39236. W2. Search backwards from each instance of a European number until the
  39237. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  39238. the type of the European number to Arabic number.
  39239. */
  39240. lastType = sor;
  39241. var t;
  39242. for (i = 0; i < strLength; ++i) {
  39243. t = types[i];
  39244. if (t === 'EN') {
  39245. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  39246. } else if (t === 'R' || t === 'L' || t === 'AL') {
  39247. lastType = t;
  39248. }
  39249. }
  39250. /*
  39251. W3. Change all ALs to R.
  39252. */
  39253. for (i = 0; i < strLength; ++i) {
  39254. t = types[i];
  39255. if (t === 'AL') {
  39256. types[i] = 'R';
  39257. }
  39258. }
  39259. /*
  39260. W4. A single European separator between two European numbers changes to a
  39261. European number. A single common separator between two numbers of the same
  39262. type changes to that type:
  39263. */
  39264. for (i = 1; i < strLength - 1; ++i) {
  39265. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  39266. types[i] = 'EN';
  39267. }
  39268. if (types[i] === 'CS' &&
  39269. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  39270. types[i + 1] === types[i - 1]) {
  39271. types[i] = types[i - 1];
  39272. }
  39273. }
  39274. /*
  39275. W5. A sequence of European terminators adjacent to European numbers changes
  39276. to all European numbers:
  39277. */
  39278. for (i = 0; i < strLength; ++i) {
  39279. if (types[i] === 'EN') {
  39280. // do before
  39281. var j;
  39282. for (j = i - 1; j >= 0; --j) {
  39283. if (types[j] !== 'ET') {
  39284. break;
  39285. }
  39286. types[j] = 'EN';
  39287. }
  39288. // do after
  39289. for (j = i + 1; j < strLength; --j) {
  39290. if (types[j] !== 'ET') {
  39291. break;
  39292. }
  39293. types[j] = 'EN';
  39294. }
  39295. }
  39296. }
  39297. /*
  39298. W6. Otherwise, separators and terminators change to Other Neutral:
  39299. */
  39300. for (i = 0; i < strLength; ++i) {
  39301. t = types[i];
  39302. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  39303. types[i] = 'ON';
  39304. }
  39305. }
  39306. /*
  39307. W7. Search backwards from each instance of a European number until the
  39308. first strong type (R, L, or sor) is found. If an L is found, then change
  39309. the type of the European number to L.
  39310. */
  39311. lastType = sor;
  39312. for (i = 0; i < strLength; ++i) {
  39313. t = types[i];
  39314. if (t === 'EN') {
  39315. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  39316. } else if (t === 'R' || t === 'L') {
  39317. lastType = t;
  39318. }
  39319. }
  39320. /*
  39321. N1. A sequence of neutrals takes the direction of the surrounding strong
  39322. text if the text on both sides has the same direction. European and Arabic
  39323. numbers are treated as though they were R. Start-of-level-run (sor) and
  39324. end-of-level-run (eor) are used at level run boundaries.
  39325. */
  39326. for (i = 0; i < strLength; ++i) {
  39327. if (types[i] === 'ON') {
  39328. var end = findUnequal(types, i + 1, 'ON');
  39329. var before = sor;
  39330. if (i > 0) {
  39331. before = types[i - 1];
  39332. }
  39333. var after = eor;
  39334. if (end + 1 < strLength) {
  39335. after = types[end + 1];
  39336. }
  39337. if (before !== 'L') {
  39338. before = 'R';
  39339. }
  39340. if (after !== 'L') {
  39341. after = 'R';
  39342. }
  39343. if (before === after) {
  39344. setValues(types, i, end, before);
  39345. }
  39346. i = end - 1; // reset to end (-1 so next iteration is ok)
  39347. }
  39348. }
  39349. /*
  39350. N2. Any remaining neutrals take the embedding direction.
  39351. */
  39352. for (i = 0; i < strLength; ++i) {
  39353. if (types[i] === 'ON') {
  39354. types[i] = e;
  39355. }
  39356. }
  39357. /*
  39358. I1. For all characters with an even (left-to-right) embedding direction,
  39359. those of type R go up one level and those of type AN or EN go up two
  39360. levels.
  39361. I2. For all characters with an odd (right-to-left) embedding direction,
  39362. those of type L, EN or AN go up one level.
  39363. */
  39364. for (i = 0; i < strLength; ++i) {
  39365. t = types[i];
  39366. if (isEven(levels[i])) {
  39367. if (t === 'R') {
  39368. levels[i] += 1;
  39369. } else if (t === 'AN' || t === 'EN') {
  39370. levels[i] += 2;
  39371. }
  39372. } else { // isOdd
  39373. if (t === 'L' || t === 'AN' || t === 'EN') {
  39374. levels[i] += 1;
  39375. }
  39376. }
  39377. }
  39378. /*
  39379. L1. On each line, reset the embedding level of the following characters to
  39380. the paragraph embedding level:
  39381. segment separators,
  39382. paragraph separators,
  39383. any sequence of whitespace characters preceding a segment separator or
  39384. paragraph separator, and any sequence of white space characters at the end
  39385. of the line.
  39386. */
  39387. // don't bother as text is only single line
  39388. /*
  39389. L2. From the highest level found in the text to the lowest odd level on
  39390. each line, reverse any contiguous sequence of characters that are at that
  39391. level or higher.
  39392. */
  39393. // find highest level & lowest odd level
  39394. var highestLevel = -1;
  39395. var lowestOddLevel = 99;
  39396. var level;
  39397. for (i = 0, ii = levels.length; i < ii; ++i) {
  39398. level = levels[i];
  39399. if (highestLevel < level) {
  39400. highestLevel = level;
  39401. }
  39402. if (lowestOddLevel > level && isOdd(level)) {
  39403. lowestOddLevel = level;
  39404. }
  39405. }
  39406. // now reverse between those limits
  39407. for (level = highestLevel; level >= lowestOddLevel; --level) {
  39408. // find segments to reverse
  39409. var start = -1;
  39410. for (i = 0, ii = levels.length; i < ii; ++i) {
  39411. if (levels[i] < level) {
  39412. if (start >= 0) {
  39413. reverseValues(chars, start, i);
  39414. start = -1;
  39415. }
  39416. } else if (start < 0) {
  39417. start = i;
  39418. }
  39419. }
  39420. if (start >= 0) {
  39421. reverseValues(chars, start, levels.length);
  39422. }
  39423. }
  39424. /*
  39425. L3. Combining marks applied to a right-to-left base character will at this
  39426. point precede their base character. If the rendering engine expects them to
  39427. follow the base characters in the final display process, then the ordering
  39428. of the marks and the base character must be reversed.
  39429. */
  39430. // don't bother for now
  39431. /*
  39432. L4. A character that possesses the mirrored property as specified by
  39433. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  39434. directionality of that character is R.
  39435. */
  39436. // don't mirror as characters are already mirrored in the pdf
  39437. // Finally, return string
  39438. var result = '';
  39439. for (i = 0, ii = chars.length; i < ii; ++i) {
  39440. var ch = chars[i];
  39441. if (ch !== '<' && ch !== '>') {
  39442. result += ch;
  39443. }
  39444. }
  39445. return createBidiText(result, isLTR);
  39446. }
  39447. return bidi;
  39448. })();
  39449. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  39450. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  39451. /* Copyright 2014 Opera Software ASA
  39452. *
  39453. * Licensed under the Apache License, Version 2.0 (the "License");
  39454. * you may not use this file except in compliance with the License.
  39455. * You may obtain a copy of the License at
  39456. *
  39457. * http://www.apache.org/licenses/LICENSE-2.0
  39458. *
  39459. * Unless required by applicable law or agreed to in writing, software
  39460. * distributed under the License is distributed on an "AS IS" BASIS,
  39461. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  39462. * See the License for the specific language governing permissions and
  39463. * limitations under the License.
  39464. *
  39465. *
  39466. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  39467. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  39468. */
  39469. /* globals Uint32ArrayView */
  39470. 'use strict';
  39471. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  39472. // Workaround for missing math precison in JS.
  39473. var MASK_HIGH = 0xffff0000;
  39474. var MASK_LOW = 0xffff;
  39475. function MurmurHash3_64 (seed) {
  39476. var SEED = 0xc3d2e1f0;
  39477. this.h1 = seed ? seed & 0xffffffff : SEED;
  39478. this.h2 = seed ? seed & 0xffffffff : SEED;
  39479. }
  39480. var alwaysUseUint32ArrayView = false;
  39481. // old webkits have issues with non-aligned arrays
  39482. try {
  39483. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  39484. } catch (e) {
  39485. alwaysUseUint32ArrayView = true;
  39486. }
  39487. MurmurHash3_64.prototype = {
  39488. update: function MurmurHash3_64_update(input) {
  39489. var useUint32ArrayView = alwaysUseUint32ArrayView;
  39490. var i;
  39491. if (typeof input === 'string') {
  39492. var data = new Uint8Array(input.length * 2);
  39493. var length = 0;
  39494. for (i = 0; i < input.length; i++) {
  39495. var code = input.charCodeAt(i);
  39496. if (code <= 0xff) {
  39497. data[length++] = code;
  39498. }
  39499. else {
  39500. data[length++] = code >>> 8;
  39501. data[length++] = code & 0xff;
  39502. }
  39503. }
  39504. } else if (input instanceof Uint8Array) {
  39505. data = input;
  39506. length = data.length;
  39507. } else if (typeof input === 'object' && ('length' in input)) {
  39508. // processing regular arrays as well, e.g. for IE9
  39509. data = input;
  39510. length = data.length;
  39511. useUint32ArrayView = true;
  39512. } else {
  39513. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  39514. 'Input must be a string or array.');
  39515. }
  39516. var blockCounts = length >> 2;
  39517. var tailLength = length - blockCounts * 4;
  39518. // we don't care about endianness here
  39519. var dataUint32 = useUint32ArrayView ?
  39520. new Uint32ArrayView(data, blockCounts) :
  39521. new Uint32Array(data.buffer, 0, blockCounts);
  39522. var k1 = 0;
  39523. var k2 = 0;
  39524. var h1 = this.h1;
  39525. var h2 = this.h2;
  39526. var C1 = 0xcc9e2d51;
  39527. var C2 = 0x1b873593;
  39528. var C1_LOW = C1 & MASK_LOW;
  39529. var C2_LOW = C2 & MASK_LOW;
  39530. for (i = 0; i < blockCounts; i++) {
  39531. if (i & 1) {
  39532. k1 = dataUint32[i];
  39533. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  39534. k1 = k1 << 15 | k1 >>> 17;
  39535. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  39536. h1 ^= k1;
  39537. h1 = h1 << 13 | h1 >>> 19;
  39538. h1 = h1 * 5 + 0xe6546b64;
  39539. } else {
  39540. k2 = dataUint32[i];
  39541. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  39542. k2 = k2 << 15 | k2 >>> 17;
  39543. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  39544. h2 ^= k2;
  39545. h2 = h2 << 13 | h2 >>> 19;
  39546. h2 = h2 * 5 + 0xe6546b64;
  39547. }
  39548. }
  39549. k1 = 0;
  39550. switch (tailLength) {
  39551. case 3:
  39552. k1 ^= data[blockCounts * 4 + 2] << 16;
  39553. /* falls through */
  39554. case 2:
  39555. k1 ^= data[blockCounts * 4 + 1] << 8;
  39556. /* falls through */
  39557. case 1:
  39558. k1 ^= data[blockCounts * 4];
  39559. /* falls through */
  39560. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  39561. k1 = k1 << 15 | k1 >>> 17;
  39562. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  39563. if (blockCounts & 1) {
  39564. h1 ^= k1;
  39565. } else {
  39566. h2 ^= k1;
  39567. }
  39568. }
  39569. this.h1 = h1;
  39570. this.h2 = h2;
  39571. return this;
  39572. },
  39573. hexdigest: function MurmurHash3_64_hexdigest () {
  39574. var h1 = this.h1;
  39575. var h2 = this.h2;
  39576. h1 ^= h2 >>> 1;
  39577. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  39578. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  39579. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  39580. h1 ^= h2 >>> 1;
  39581. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  39582. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  39583. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  39584. h1 ^= h2 >>> 1;
  39585. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  39586. var hex = (arr[i] >>> 0).toString(16);
  39587. while (hex.length < 8) {
  39588. hex = '0' + hex;
  39589. }
  39590. str += hex;
  39591. }
  39592. return str;
  39593. }
  39594. };
  39595. return MurmurHash3_64;
  39596. })();
  39597. }).call((typeof window === 'undefined') ? this : window);
  39598. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  39599. // workerSrc is not set -- using last script url to define default location
  39600. PDFJS.workerSrc = (function () {
  39601. 'use strict';
  39602. var scriptTagContainer = document.body ||
  39603. document.getElementsByTagName('head')[0];
  39604. var pdfjsSrc = scriptTagContainer.lastChild.src;
  39605. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  39606. })();
  39607. }