pdf.combined.js 1.4 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558
  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.1160';
  24. PDFJS.build = '2e14cc7';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) === '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. case 'tel':
  319. return true;
  320. default:
  321. return false;
  322. }
  323. }
  324. PDFJS.isValidUrl = isValidUrl;
  325. function shadow(obj, prop, value) {
  326. Object.defineProperty(obj, prop, { value: value,
  327. enumerable: true,
  328. configurable: true,
  329. writable: false });
  330. return value;
  331. }
  332. PDFJS.shadow = shadow;
  333. var PasswordResponses = PDFJS.PasswordResponses = {
  334. NEED_PASSWORD: 1,
  335. INCORRECT_PASSWORD: 2
  336. };
  337. var PasswordException = (function PasswordExceptionClosure() {
  338. function PasswordException(msg, code) {
  339. this.name = 'PasswordException';
  340. this.message = msg;
  341. this.code = code;
  342. }
  343. PasswordException.prototype = new Error();
  344. PasswordException.constructor = PasswordException;
  345. return PasswordException;
  346. })();
  347. PDFJS.PasswordException = PasswordException;
  348. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  349. function UnknownErrorException(msg, details) {
  350. this.name = 'UnknownErrorException';
  351. this.message = msg;
  352. this.details = details;
  353. }
  354. UnknownErrorException.prototype = new Error();
  355. UnknownErrorException.constructor = UnknownErrorException;
  356. return UnknownErrorException;
  357. })();
  358. PDFJS.UnknownErrorException = UnknownErrorException;
  359. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  360. function InvalidPDFException(msg) {
  361. this.name = 'InvalidPDFException';
  362. this.message = msg;
  363. }
  364. InvalidPDFException.prototype = new Error();
  365. InvalidPDFException.constructor = InvalidPDFException;
  366. return InvalidPDFException;
  367. })();
  368. PDFJS.InvalidPDFException = InvalidPDFException;
  369. var MissingPDFException = (function MissingPDFExceptionClosure() {
  370. function MissingPDFException(msg) {
  371. this.name = 'MissingPDFException';
  372. this.message = msg;
  373. }
  374. MissingPDFException.prototype = new Error();
  375. MissingPDFException.constructor = MissingPDFException;
  376. return MissingPDFException;
  377. })();
  378. PDFJS.MissingPDFException = MissingPDFException;
  379. var UnexpectedResponseException =
  380. (function UnexpectedResponseExceptionClosure() {
  381. function UnexpectedResponseException(msg, status) {
  382. this.name = 'UnexpectedResponseException';
  383. this.message = msg;
  384. this.status = status;
  385. }
  386. UnexpectedResponseException.prototype = new Error();
  387. UnexpectedResponseException.constructor = UnexpectedResponseException;
  388. return UnexpectedResponseException;
  389. })();
  390. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  391. var NotImplementedException = (function NotImplementedExceptionClosure() {
  392. function NotImplementedException(msg) {
  393. this.message = msg;
  394. }
  395. NotImplementedException.prototype = new Error();
  396. NotImplementedException.prototype.name = 'NotImplementedException';
  397. NotImplementedException.constructor = NotImplementedException;
  398. return NotImplementedException;
  399. })();
  400. var MissingDataException = (function MissingDataExceptionClosure() {
  401. function MissingDataException(begin, end) {
  402. this.begin = begin;
  403. this.end = end;
  404. this.message = 'Missing data [' + begin + ', ' + end + ')';
  405. }
  406. MissingDataException.prototype = new Error();
  407. MissingDataException.prototype.name = 'MissingDataException';
  408. MissingDataException.constructor = MissingDataException;
  409. return MissingDataException;
  410. })();
  411. var XRefParseException = (function XRefParseExceptionClosure() {
  412. function XRefParseException(msg) {
  413. this.message = msg;
  414. }
  415. XRefParseException.prototype = new Error();
  416. XRefParseException.prototype.name = 'XRefParseException';
  417. XRefParseException.constructor = XRefParseException;
  418. return XRefParseException;
  419. })();
  420. function bytesToString(bytes) {
  421. assert(bytes !== null && typeof bytes === 'object' &&
  422. bytes.length !== undefined, 'Invalid argument for bytesToString');
  423. var length = bytes.length;
  424. var MAX_ARGUMENT_COUNT = 8192;
  425. if (length < MAX_ARGUMENT_COUNT) {
  426. return String.fromCharCode.apply(null, bytes);
  427. }
  428. var strBuf = [];
  429. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  430. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  431. var chunk = bytes.subarray(i, chunkEnd);
  432. strBuf.push(String.fromCharCode.apply(null, chunk));
  433. }
  434. return strBuf.join('');
  435. }
  436. function stringToBytes(str) {
  437. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  438. var length = str.length;
  439. var bytes = new Uint8Array(length);
  440. for (var i = 0; i < length; ++i) {
  441. bytes[i] = str.charCodeAt(i) & 0xFF;
  442. }
  443. return bytes;
  444. }
  445. function string32(value) {
  446. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  447. (value >> 8) & 0xff, value & 0xff);
  448. }
  449. function log2(x) {
  450. var n = 1, i = 0;
  451. while (x > n) {
  452. n <<= 1;
  453. i++;
  454. }
  455. return i;
  456. }
  457. function readInt8(data, start) {
  458. return (data[start] << 24) >> 24;
  459. }
  460. function readUint16(data, offset) {
  461. return (data[offset] << 8) | data[offset + 1];
  462. }
  463. function readUint32(data, offset) {
  464. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  465. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  466. }
  467. // Lazy test the endianness of the platform
  468. // NOTE: This will be 'true' for simulated TypedArrays
  469. function isLittleEndian() {
  470. var buffer8 = new Uint8Array(2);
  471. buffer8[0] = 1;
  472. var buffer16 = new Uint16Array(buffer8.buffer);
  473. return (buffer16[0] === 1);
  474. }
  475. Object.defineProperty(PDFJS, 'isLittleEndian', {
  476. configurable: true,
  477. get: function PDFJS_isLittleEndian() {
  478. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  479. }
  480. });
  481. // Lazy test if the userAgant support CanvasTypedArrays
  482. function hasCanvasTypedArrays() {
  483. var canvas = document.createElement('canvas');
  484. canvas.width = canvas.height = 1;
  485. var ctx = canvas.getContext('2d');
  486. var imageData = ctx.createImageData(1, 1);
  487. return (typeof imageData.data.buffer !== 'undefined');
  488. }
  489. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  490. configurable: true,
  491. get: function PDFJS_hasCanvasTypedArrays() {
  492. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  493. }
  494. });
  495. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  496. function Uint32ArrayView(buffer, length) {
  497. this.buffer = buffer;
  498. this.byteLength = buffer.length;
  499. this.length = length === undefined ? (this.byteLength >> 2) : length;
  500. ensureUint32ArrayViewProps(this.length);
  501. }
  502. Uint32ArrayView.prototype = Object.create(null);
  503. var uint32ArrayViewSetters = 0;
  504. function createUint32ArrayProp(index) {
  505. return {
  506. get: function () {
  507. var buffer = this.buffer, offset = index << 2;
  508. return (buffer[offset] | (buffer[offset + 1] << 8) |
  509. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  510. },
  511. set: function (value) {
  512. var buffer = this.buffer, offset = index << 2;
  513. buffer[offset] = value & 255;
  514. buffer[offset + 1] = (value >> 8) & 255;
  515. buffer[offset + 2] = (value >> 16) & 255;
  516. buffer[offset + 3] = (value >>> 24) & 255;
  517. }
  518. };
  519. }
  520. function ensureUint32ArrayViewProps(length) {
  521. while (uint32ArrayViewSetters < length) {
  522. Object.defineProperty(Uint32ArrayView.prototype,
  523. uint32ArrayViewSetters,
  524. createUint32ArrayProp(uint32ArrayViewSetters));
  525. uint32ArrayViewSetters++;
  526. }
  527. }
  528. return Uint32ArrayView;
  529. })();
  530. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  531. var Util = PDFJS.Util = (function UtilClosure() {
  532. function Util() {}
  533. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  534. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  535. // creating many intermediate strings.
  536. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  537. rgbBuf[1] = r;
  538. rgbBuf[3] = g;
  539. rgbBuf[5] = b;
  540. return rgbBuf.join('');
  541. };
  542. // Concatenates two transformation matrices together and returns the result.
  543. Util.transform = function Util_transform(m1, m2) {
  544. return [
  545. m1[0] * m2[0] + m1[2] * m2[1],
  546. m1[1] * m2[0] + m1[3] * m2[1],
  547. m1[0] * m2[2] + m1[2] * m2[3],
  548. m1[1] * m2[2] + m1[3] * m2[3],
  549. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  550. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  551. ];
  552. };
  553. // For 2d affine transforms
  554. Util.applyTransform = function Util_applyTransform(p, m) {
  555. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  556. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  557. return [xt, yt];
  558. };
  559. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  560. var d = m[0] * m[3] - m[1] * m[2];
  561. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  562. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  563. return [xt, yt];
  564. };
  565. // Applies the transform to the rectangle and finds the minimum axially
  566. // aligned bounding box.
  567. Util.getAxialAlignedBoundingBox =
  568. function Util_getAxialAlignedBoundingBox(r, m) {
  569. var p1 = Util.applyTransform(r, m);
  570. var p2 = Util.applyTransform(r.slice(2, 4), m);
  571. var p3 = Util.applyTransform([r[0], r[3]], m);
  572. var p4 = Util.applyTransform([r[2], r[1]], m);
  573. return [
  574. Math.min(p1[0], p2[0], p3[0], p4[0]),
  575. Math.min(p1[1], p2[1], p3[1], p4[1]),
  576. Math.max(p1[0], p2[0], p3[0], p4[0]),
  577. Math.max(p1[1], p2[1], p3[1], p4[1])
  578. ];
  579. };
  580. Util.inverseTransform = function Util_inverseTransform(m) {
  581. var d = m[0] * m[3] - m[1] * m[2];
  582. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  583. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  584. };
  585. // Apply a generic 3d matrix M on a 3-vector v:
  586. // | a b c | | X |
  587. // | d e f | x | Y |
  588. // | g h i | | Z |
  589. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  590. // with v as [X,Y,Z]
  591. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  592. return [
  593. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  594. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  595. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  596. ];
  597. };
  598. // This calculation uses Singular Value Decomposition.
  599. // The SVD can be represented with formula A = USV. We are interested in the
  600. // matrix S here because it represents the scale values.
  601. Util.singularValueDecompose2dScale =
  602. function Util_singularValueDecompose2dScale(m) {
  603. var transpose = [m[0], m[2], m[1], m[3]];
  604. // Multiply matrix m with its transpose.
  605. var a = m[0] * transpose[0] + m[1] * transpose[2];
  606. var b = m[0] * transpose[1] + m[1] * transpose[3];
  607. var c = m[2] * transpose[0] + m[3] * transpose[2];
  608. var d = m[2] * transpose[1] + m[3] * transpose[3];
  609. // Solve the second degree polynomial to get roots.
  610. var first = (a + d) / 2;
  611. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  612. var sx = first + second || 1;
  613. var sy = first - second || 1;
  614. // Scale values are the square roots of the eigenvalues.
  615. return [Math.sqrt(sx), Math.sqrt(sy)];
  616. };
  617. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  618. // For coordinate systems whose origin lies in the bottom-left, this
  619. // means normalization to (BL,TR) ordering. For systems with origin in the
  620. // top-left, this means (TL,BR) ordering.
  621. Util.normalizeRect = function Util_normalizeRect(rect) {
  622. var r = rect.slice(0); // clone rect
  623. if (rect[0] > rect[2]) {
  624. r[0] = rect[2];
  625. r[2] = rect[0];
  626. }
  627. if (rect[1] > rect[3]) {
  628. r[1] = rect[3];
  629. r[3] = rect[1];
  630. }
  631. return r;
  632. };
  633. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  634. // intersection of rect1 and rect2. If no intersection, returns 'false'
  635. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  636. Util.intersect = function Util_intersect(rect1, rect2) {
  637. function compare(a, b) {
  638. return a - b;
  639. }
  640. // Order points along the axes
  641. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  642. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  643. result = [];
  644. rect1 = Util.normalizeRect(rect1);
  645. rect2 = Util.normalizeRect(rect2);
  646. // X: first and second points belong to different rectangles?
  647. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  648. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  649. // Intersection must be between second and third points
  650. result[0] = orderedX[1];
  651. result[2] = orderedX[2];
  652. } else {
  653. return false;
  654. }
  655. // Y: first and second points belong to different rectangles?
  656. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  657. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  658. // Intersection must be between second and third points
  659. result[1] = orderedY[1];
  660. result[3] = orderedY[2];
  661. } else {
  662. return false;
  663. }
  664. return result;
  665. };
  666. Util.sign = function Util_sign(num) {
  667. return num < 0 ? -1 : 1;
  668. };
  669. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  670. Array.prototype.push.apply(arr1, arr2);
  671. };
  672. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  673. Array.prototype.unshift.apply(arr1, arr2);
  674. };
  675. Util.extendObj = function extendObj(obj1, obj2) {
  676. for (var key in obj2) {
  677. obj1[key] = obj2[key];
  678. }
  679. };
  680. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  681. name) {
  682. while (dict && !dict.has(name)) {
  683. dict = dict.get('Parent');
  684. }
  685. if (!dict) {
  686. return null;
  687. }
  688. return dict.get(name);
  689. };
  690. Util.inherit = function Util_inherit(sub, base, prototype) {
  691. sub.prototype = Object.create(base.prototype);
  692. sub.prototype.constructor = sub;
  693. for (var prop in prototype) {
  694. sub.prototype[prop] = prototype[prop];
  695. }
  696. };
  697. Util.loadScript = function Util_loadScript(src, callback) {
  698. var script = document.createElement('script');
  699. var loaded = false;
  700. script.setAttribute('src', src);
  701. if (callback) {
  702. script.onload = function() {
  703. if (!loaded) {
  704. callback();
  705. }
  706. loaded = true;
  707. };
  708. }
  709. document.getElementsByTagName('head')[0].appendChild(script);
  710. };
  711. return Util;
  712. })();
  713. /**
  714. * PDF page viewport created based on scale, rotation and offset.
  715. * @class
  716. * @alias PDFJS.PageViewport
  717. */
  718. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  719. /**
  720. * @constructor
  721. * @private
  722. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  723. * @param scale {number} scale of the viewport.
  724. * @param rotation {number} rotations of the viewport in degrees.
  725. * @param offsetX {number} offset X
  726. * @param offsetY {number} offset Y
  727. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  728. */
  729. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  730. this.viewBox = viewBox;
  731. this.scale = scale;
  732. this.rotation = rotation;
  733. this.offsetX = offsetX;
  734. this.offsetY = offsetY;
  735. // creating transform to convert pdf coordinate system to the normal
  736. // canvas like coordinates taking in account scale and rotation
  737. var centerX = (viewBox[2] + viewBox[0]) / 2;
  738. var centerY = (viewBox[3] + viewBox[1]) / 2;
  739. var rotateA, rotateB, rotateC, rotateD;
  740. rotation = rotation % 360;
  741. rotation = rotation < 0 ? rotation + 360 : rotation;
  742. switch (rotation) {
  743. case 180:
  744. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  745. break;
  746. case 90:
  747. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  748. break;
  749. case 270:
  750. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  751. break;
  752. //case 0:
  753. default:
  754. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  755. break;
  756. }
  757. if (dontFlip) {
  758. rotateC = -rotateC; rotateD = -rotateD;
  759. }
  760. var offsetCanvasX, offsetCanvasY;
  761. var width, height;
  762. if (rotateA === 0) {
  763. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  764. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  765. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  766. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  767. } else {
  768. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  769. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  770. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  771. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  772. }
  773. // creating transform for the following operations:
  774. // translate(-centerX, -centerY), rotate and flip vertically,
  775. // scale, and translate(offsetCanvasX, offsetCanvasY)
  776. this.transform = [
  777. rotateA * scale,
  778. rotateB * scale,
  779. rotateC * scale,
  780. rotateD * scale,
  781. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  782. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  783. ];
  784. this.width = width;
  785. this.height = height;
  786. this.fontScale = scale;
  787. }
  788. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  789. /**
  790. * Clones viewport with additional properties.
  791. * @param args {Object} (optional) If specified, may contain the 'scale' or
  792. * 'rotation' properties to override the corresponding properties in
  793. * the cloned viewport.
  794. * @returns {PDFJS.PageViewport} Cloned viewport.
  795. */
  796. clone: function PageViewPort_clone(args) {
  797. args = args || {};
  798. var scale = 'scale' in args ? args.scale : this.scale;
  799. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  800. return new PageViewport(this.viewBox.slice(), scale, rotation,
  801. this.offsetX, this.offsetY, args.dontFlip);
  802. },
  803. /**
  804. * Converts PDF point to the viewport coordinates. For examples, useful for
  805. * converting PDF location into canvas pixel coordinates.
  806. * @param x {number} X coordinate.
  807. * @param y {number} Y coordinate.
  808. * @returns {Object} Object that contains 'x' and 'y' properties of the
  809. * point in the viewport coordinate space.
  810. * @see {@link convertToPdfPoint}
  811. * @see {@link convertToViewportRectangle}
  812. */
  813. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  814. return Util.applyTransform([x, y], this.transform);
  815. },
  816. /**
  817. * Converts PDF rectangle to the viewport coordinates.
  818. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  819. * @returns {Array} Contains corresponding coordinates of the rectangle
  820. * in the viewport coordinate space.
  821. * @see {@link convertToViewportPoint}
  822. */
  823. convertToViewportRectangle:
  824. function PageViewport_convertToViewportRectangle(rect) {
  825. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  826. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  827. return [tl[0], tl[1], br[0], br[1]];
  828. },
  829. /**
  830. * Converts viewport coordinates to the PDF location. For examples, useful
  831. * for converting canvas pixel location into PDF one.
  832. * @param x {number} X coordinate.
  833. * @param y {number} Y coordinate.
  834. * @returns {Object} Object that contains 'x' and 'y' properties of the
  835. * point in the PDF coordinate space.
  836. * @see {@link convertToViewportPoint}
  837. */
  838. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  839. return Util.applyInverseTransform([x, y], this.transform);
  840. }
  841. };
  842. return PageViewport;
  843. })();
  844. var PDFStringTranslateTable = [
  845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  846. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  851. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  852. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  853. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  854. ];
  855. function stringToPDFString(str) {
  856. var i, n = str.length, strBuf = [];
  857. if (str[0] === '\xFE' && str[1] === '\xFF') {
  858. // UTF16BE BOM
  859. for (i = 2; i < n; i += 2) {
  860. strBuf.push(String.fromCharCode(
  861. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  862. }
  863. } else {
  864. for (i = 0; i < n; ++i) {
  865. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  866. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  867. }
  868. }
  869. return strBuf.join('');
  870. }
  871. function stringToUTF8String(str) {
  872. return decodeURIComponent(escape(str));
  873. }
  874. function isEmptyObj(obj) {
  875. for (var key in obj) {
  876. return false;
  877. }
  878. return true;
  879. }
  880. function isBool(v) {
  881. return typeof v === 'boolean';
  882. }
  883. function isInt(v) {
  884. return typeof v === 'number' && ((v | 0) === v);
  885. }
  886. function isNum(v) {
  887. return typeof v === 'number';
  888. }
  889. function isString(v) {
  890. return typeof v === 'string';
  891. }
  892. function isNull(v) {
  893. return v === null;
  894. }
  895. function isName(v) {
  896. return v instanceof Name;
  897. }
  898. function isCmd(v, cmd) {
  899. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  900. }
  901. function isDict(v, type) {
  902. if (!(v instanceof Dict)) {
  903. return false;
  904. }
  905. if (!type) {
  906. return true;
  907. }
  908. var dictType = v.get('Type');
  909. return isName(dictType) && dictType.name === type;
  910. }
  911. function isArray(v) {
  912. return v instanceof Array;
  913. }
  914. function isStream(v) {
  915. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  916. }
  917. function isArrayBuffer(v) {
  918. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  919. }
  920. function isRef(v) {
  921. return v instanceof Ref;
  922. }
  923. /**
  924. * Promise Capability object.
  925. *
  926. * @typedef {Object} PromiseCapability
  927. * @property {Promise} promise - A promise object.
  928. * @property {function} resolve - Fullfills the promise.
  929. * @property {function} reject - Rejects the promise.
  930. */
  931. /**
  932. * Creates a promise capability object.
  933. * @alias PDFJS.createPromiseCapability
  934. *
  935. * @return {PromiseCapability} A capability object contains:
  936. * - a Promise, resolve and reject methods.
  937. */
  938. function createPromiseCapability() {
  939. var capability = {};
  940. capability.promise = new Promise(function (resolve, reject) {
  941. capability.resolve = resolve;
  942. capability.reject = reject;
  943. });
  944. return capability;
  945. }
  946. PDFJS.createPromiseCapability = createPromiseCapability;
  947. /**
  948. * Polyfill for Promises:
  949. * The following promise implementation tries to generally implement the
  950. * Promise/A+ spec. Some notable differences from other promise libaries are:
  951. * - There currently isn't a seperate deferred and promise object.
  952. * - Unhandled rejections eventually show an error if they aren't handled.
  953. *
  954. * Based off of the work in:
  955. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  956. */
  957. (function PromiseClosure() {
  958. if (globalScope.Promise) {
  959. // Promises existing in the DOM/Worker, checking presence of all/resolve
  960. if (typeof globalScope.Promise.all !== 'function') {
  961. globalScope.Promise.all = function (iterable) {
  962. var count = 0, results = [], resolve, reject;
  963. var promise = new globalScope.Promise(function (resolve_, reject_) {
  964. resolve = resolve_;
  965. reject = reject_;
  966. });
  967. iterable.forEach(function (p, i) {
  968. count++;
  969. p.then(function (result) {
  970. results[i] = result;
  971. count--;
  972. if (count === 0) {
  973. resolve(results);
  974. }
  975. }, reject);
  976. });
  977. if (count === 0) {
  978. resolve(results);
  979. }
  980. return promise;
  981. };
  982. }
  983. if (typeof globalScope.Promise.resolve !== 'function') {
  984. globalScope.Promise.resolve = function (value) {
  985. return new globalScope.Promise(function (resolve) { resolve(value); });
  986. };
  987. }
  988. if (typeof globalScope.Promise.reject !== 'function') {
  989. globalScope.Promise.reject = function (reason) {
  990. return new globalScope.Promise(function (resolve, reject) {
  991. reject(reason);
  992. });
  993. };
  994. }
  995. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  996. globalScope.Promise.prototype.catch = function (onReject) {
  997. return globalScope.Promise.prototype.then(undefined, onReject);
  998. };
  999. }
  1000. return;
  1001. }
  1002. var STATUS_PENDING = 0;
  1003. var STATUS_RESOLVED = 1;
  1004. var STATUS_REJECTED = 2;
  1005. // In an attempt to avoid silent exceptions, unhandled rejections are
  1006. // tracked and if they aren't handled in a certain amount of time an
  1007. // error is logged.
  1008. var REJECTION_TIMEOUT = 500;
  1009. var HandlerManager = {
  1010. handlers: [],
  1011. running: false,
  1012. unhandledRejections: [],
  1013. pendingRejectionCheck: false,
  1014. scheduleHandlers: function scheduleHandlers(promise) {
  1015. if (promise._status === STATUS_PENDING) {
  1016. return;
  1017. }
  1018. this.handlers = this.handlers.concat(promise._handlers);
  1019. promise._handlers = [];
  1020. if (this.running) {
  1021. return;
  1022. }
  1023. this.running = true;
  1024. setTimeout(this.runHandlers.bind(this), 0);
  1025. },
  1026. runHandlers: function runHandlers() {
  1027. var RUN_TIMEOUT = 1; // ms
  1028. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1029. while (this.handlers.length > 0) {
  1030. var handler = this.handlers.shift();
  1031. var nextStatus = handler.thisPromise._status;
  1032. var nextValue = handler.thisPromise._value;
  1033. try {
  1034. if (nextStatus === STATUS_RESOLVED) {
  1035. if (typeof handler.onResolve === 'function') {
  1036. nextValue = handler.onResolve(nextValue);
  1037. }
  1038. } else if (typeof handler.onReject === 'function') {
  1039. nextValue = handler.onReject(nextValue);
  1040. nextStatus = STATUS_RESOLVED;
  1041. if (handler.thisPromise._unhandledRejection) {
  1042. this.removeUnhandeledRejection(handler.thisPromise);
  1043. }
  1044. }
  1045. } catch (ex) {
  1046. nextStatus = STATUS_REJECTED;
  1047. nextValue = ex;
  1048. }
  1049. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1050. if (Date.now() >= timeoutAt) {
  1051. break;
  1052. }
  1053. }
  1054. if (this.handlers.length > 0) {
  1055. setTimeout(this.runHandlers.bind(this), 0);
  1056. return;
  1057. }
  1058. this.running = false;
  1059. },
  1060. addUnhandledRejection: function addUnhandledRejection(promise) {
  1061. this.unhandledRejections.push({
  1062. promise: promise,
  1063. time: Date.now()
  1064. });
  1065. this.scheduleRejectionCheck();
  1066. },
  1067. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1068. promise._unhandledRejection = false;
  1069. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1070. if (this.unhandledRejections[i].promise === promise) {
  1071. this.unhandledRejections.splice(i);
  1072. i--;
  1073. }
  1074. }
  1075. },
  1076. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1077. if (this.pendingRejectionCheck) {
  1078. return;
  1079. }
  1080. this.pendingRejectionCheck = true;
  1081. setTimeout(function rejectionCheck() {
  1082. this.pendingRejectionCheck = false;
  1083. var now = Date.now();
  1084. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1085. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1086. var unhandled = this.unhandledRejections[i].promise._value;
  1087. var msg = 'Unhandled rejection: ' + unhandled;
  1088. if (unhandled.stack) {
  1089. msg += '\n' + unhandled.stack;
  1090. }
  1091. warn(msg);
  1092. this.unhandledRejections.splice(i);
  1093. i--;
  1094. }
  1095. }
  1096. if (this.unhandledRejections.length) {
  1097. this.scheduleRejectionCheck();
  1098. }
  1099. }.bind(this), REJECTION_TIMEOUT);
  1100. }
  1101. };
  1102. function Promise(resolver) {
  1103. this._status = STATUS_PENDING;
  1104. this._handlers = [];
  1105. try {
  1106. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1107. } catch (e) {
  1108. this._reject(e);
  1109. }
  1110. }
  1111. /**
  1112. * Builds a promise that is resolved when all the passed in promises are
  1113. * resolved.
  1114. * @param {array} array of data and/or promises to wait for.
  1115. * @return {Promise} New dependant promise.
  1116. */
  1117. Promise.all = function Promise_all(promises) {
  1118. var resolveAll, rejectAll;
  1119. var deferred = new Promise(function (resolve, reject) {
  1120. resolveAll = resolve;
  1121. rejectAll = reject;
  1122. });
  1123. var unresolved = promises.length;
  1124. var results = [];
  1125. if (unresolved === 0) {
  1126. resolveAll(results);
  1127. return deferred;
  1128. }
  1129. function reject(reason) {
  1130. if (deferred._status === STATUS_REJECTED) {
  1131. return;
  1132. }
  1133. results = [];
  1134. rejectAll(reason);
  1135. }
  1136. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1137. var promise = promises[i];
  1138. var resolve = (function(i) {
  1139. return function(value) {
  1140. if (deferred._status === STATUS_REJECTED) {
  1141. return;
  1142. }
  1143. results[i] = value;
  1144. unresolved--;
  1145. if (unresolved === 0) {
  1146. resolveAll(results);
  1147. }
  1148. };
  1149. })(i);
  1150. if (Promise.isPromise(promise)) {
  1151. promise.then(resolve, reject);
  1152. } else {
  1153. resolve(promise);
  1154. }
  1155. }
  1156. return deferred;
  1157. };
  1158. /**
  1159. * Checks if the value is likely a promise (has a 'then' function).
  1160. * @return {boolean} true if value is thenable
  1161. */
  1162. Promise.isPromise = function Promise_isPromise(value) {
  1163. return value && typeof value.then === 'function';
  1164. };
  1165. /**
  1166. * Creates resolved promise
  1167. * @param value resolve value
  1168. * @returns {Promise}
  1169. */
  1170. Promise.resolve = function Promise_resolve(value) {
  1171. return new Promise(function (resolve) { resolve(value); });
  1172. };
  1173. /**
  1174. * Creates rejected promise
  1175. * @param reason rejection value
  1176. * @returns {Promise}
  1177. */
  1178. Promise.reject = function Promise_reject(reason) {
  1179. return new Promise(function (resolve, reject) { reject(reason); });
  1180. };
  1181. Promise.prototype = {
  1182. _status: null,
  1183. _value: null,
  1184. _handlers: null,
  1185. _unhandledRejection: null,
  1186. _updateStatus: function Promise__updateStatus(status, value) {
  1187. if (this._status === STATUS_RESOLVED ||
  1188. this._status === STATUS_REJECTED) {
  1189. return;
  1190. }
  1191. if (status === STATUS_RESOLVED &&
  1192. Promise.isPromise(value)) {
  1193. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1194. this._updateStatus.bind(this, STATUS_REJECTED));
  1195. return;
  1196. }
  1197. this._status = status;
  1198. this._value = value;
  1199. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1200. this._unhandledRejection = true;
  1201. HandlerManager.addUnhandledRejection(this);
  1202. }
  1203. HandlerManager.scheduleHandlers(this);
  1204. },
  1205. _resolve: function Promise_resolve(value) {
  1206. this._updateStatus(STATUS_RESOLVED, value);
  1207. },
  1208. _reject: function Promise_reject(reason) {
  1209. this._updateStatus(STATUS_REJECTED, reason);
  1210. },
  1211. then: function Promise_then(onResolve, onReject) {
  1212. var nextPromise = new Promise(function (resolve, reject) {
  1213. this.resolve = resolve;
  1214. this.reject = reject;
  1215. });
  1216. this._handlers.push({
  1217. thisPromise: this,
  1218. onResolve: onResolve,
  1219. onReject: onReject,
  1220. nextPromise: nextPromise
  1221. });
  1222. HandlerManager.scheduleHandlers(this);
  1223. return nextPromise;
  1224. },
  1225. catch: function Promise_catch(onReject) {
  1226. return this.then(undefined, onReject);
  1227. }
  1228. };
  1229. globalScope.Promise = Promise;
  1230. })();
  1231. var StatTimer = (function StatTimerClosure() {
  1232. function rpad(str, pad, length) {
  1233. while (str.length < length) {
  1234. str += pad;
  1235. }
  1236. return str;
  1237. }
  1238. function StatTimer() {
  1239. this.started = {};
  1240. this.times = [];
  1241. this.enabled = true;
  1242. }
  1243. StatTimer.prototype = {
  1244. time: function StatTimer_time(name) {
  1245. if (!this.enabled) {
  1246. return;
  1247. }
  1248. if (name in this.started) {
  1249. warn('Timer is already running for ' + name);
  1250. }
  1251. this.started[name] = Date.now();
  1252. },
  1253. timeEnd: function StatTimer_timeEnd(name) {
  1254. if (!this.enabled) {
  1255. return;
  1256. }
  1257. if (!(name in this.started)) {
  1258. warn('Timer has not been started for ' + name);
  1259. }
  1260. this.times.push({
  1261. 'name': name,
  1262. 'start': this.started[name],
  1263. 'end': Date.now()
  1264. });
  1265. // Remove timer from started so it can be called again.
  1266. delete this.started[name];
  1267. },
  1268. toString: function StatTimer_toString() {
  1269. var i, ii;
  1270. var times = this.times;
  1271. var out = '';
  1272. // Find the longest name for padding purposes.
  1273. var longest = 0;
  1274. for (i = 0, ii = times.length; i < ii; ++i) {
  1275. var name = times[i]['name'];
  1276. if (name.length > longest) {
  1277. longest = name.length;
  1278. }
  1279. }
  1280. for (i = 0, ii = times.length; i < ii; ++i) {
  1281. var span = times[i];
  1282. var duration = span.end - span.start;
  1283. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1284. }
  1285. return out;
  1286. }
  1287. };
  1288. return StatTimer;
  1289. })();
  1290. PDFJS.createBlob = function createBlob(data, contentType) {
  1291. if (typeof Blob !== 'undefined') {
  1292. return new Blob([data], { type: contentType });
  1293. }
  1294. // Blob builder is deprecated in FF14 and removed in FF18.
  1295. var bb = new MozBlobBuilder();
  1296. bb.append(data);
  1297. return bb.getBlob(contentType);
  1298. };
  1299. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1300. // Blob/createObjectURL is not available, falling back to data schema.
  1301. var digits =
  1302. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1303. return function createObjectURL(data, contentType) {
  1304. if (!PDFJS.disableCreateObjectURL &&
  1305. typeof URL !== 'undefined' && URL.createObjectURL) {
  1306. var blob = PDFJS.createBlob(data, contentType);
  1307. return URL.createObjectURL(blob);
  1308. }
  1309. var buffer = 'data:' + contentType + ';base64,';
  1310. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1311. var b1 = data[i] & 0xFF;
  1312. var b2 = data[i + 1] & 0xFF;
  1313. var b3 = data[i + 2] & 0xFF;
  1314. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1315. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1316. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1317. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1318. }
  1319. return buffer;
  1320. };
  1321. })();
  1322. function MessageHandler(name, comObj) {
  1323. this.name = name;
  1324. this.comObj = comObj;
  1325. this.callbackIndex = 1;
  1326. this.postMessageTransfers = true;
  1327. var callbacksCapabilities = this.callbacksCapabilities = {};
  1328. var ah = this.actionHandler = {};
  1329. ah['console_log'] = [function ahConsoleLog(data) {
  1330. console.log.apply(console, data);
  1331. }];
  1332. ah['console_error'] = [function ahConsoleError(data) {
  1333. console.error.apply(console, data);
  1334. }];
  1335. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1336. UnsupportedManager.notify(data);
  1337. }];
  1338. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1339. var data = event.data;
  1340. if (data.isReply) {
  1341. var callbackId = data.callbackId;
  1342. if (data.callbackId in callbacksCapabilities) {
  1343. var callback = callbacksCapabilities[callbackId];
  1344. delete callbacksCapabilities[callbackId];
  1345. if ('error' in data) {
  1346. callback.reject(data.error);
  1347. } else {
  1348. callback.resolve(data.data);
  1349. }
  1350. } else {
  1351. error('Cannot resolve callback ' + callbackId);
  1352. }
  1353. } else if (data.action in ah) {
  1354. var action = ah[data.action];
  1355. if (data.callbackId) {
  1356. Promise.resolve().then(function () {
  1357. return action[0].call(action[1], data.data);
  1358. }).then(function (result) {
  1359. comObj.postMessage({
  1360. isReply: true,
  1361. callbackId: data.callbackId,
  1362. data: result
  1363. });
  1364. }, function (reason) {
  1365. comObj.postMessage({
  1366. isReply: true,
  1367. callbackId: data.callbackId,
  1368. error: reason
  1369. });
  1370. });
  1371. } else {
  1372. action[0].call(action[1], data.data);
  1373. }
  1374. } else {
  1375. error('Unknown action from worker: ' + data.action);
  1376. }
  1377. };
  1378. }
  1379. MessageHandler.prototype = {
  1380. on: function messageHandlerOn(actionName, handler, scope) {
  1381. var ah = this.actionHandler;
  1382. if (ah[actionName]) {
  1383. error('There is already an actionName called "' + actionName + '"');
  1384. }
  1385. ah[actionName] = [handler, scope];
  1386. },
  1387. /**
  1388. * Sends a message to the comObj to invoke the action with the supplied data.
  1389. * @param {String} actionName Action to call.
  1390. * @param {JSON} data JSON data to send.
  1391. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1392. */
  1393. send: function messageHandlerSend(actionName, data, transfers) {
  1394. var message = {
  1395. action: actionName,
  1396. data: data
  1397. };
  1398. this.postMessage(message, transfers);
  1399. },
  1400. /**
  1401. * Sends a message to the comObj to invoke the action with the supplied data.
  1402. * Expects that other side will callback with the response.
  1403. * @param {String} actionName Action to call.
  1404. * @param {JSON} data JSON data to send.
  1405. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1406. * @returns {Promise} Promise to be resolved with response data.
  1407. */
  1408. sendWithPromise:
  1409. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1410. var callbackId = this.callbackIndex++;
  1411. var message = {
  1412. action: actionName,
  1413. data: data,
  1414. callbackId: callbackId
  1415. };
  1416. var capability = createPromiseCapability();
  1417. this.callbacksCapabilities[callbackId] = capability;
  1418. try {
  1419. this.postMessage(message, transfers);
  1420. } catch (e) {
  1421. capability.reject(e);
  1422. }
  1423. return capability.promise;
  1424. },
  1425. /**
  1426. * Sends raw message to the comObj.
  1427. * @private
  1428. * @param message {Object} Raw message.
  1429. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1430. */
  1431. postMessage: function (message, transfers) {
  1432. if (transfers && this.postMessageTransfers) {
  1433. this.comObj.postMessage(message, transfers);
  1434. } else {
  1435. this.comObj.postMessage(message);
  1436. }
  1437. }
  1438. };
  1439. function loadJpegStream(id, imageUrl, objs) {
  1440. var img = new Image();
  1441. img.onload = (function loadJpegStream_onloadClosure() {
  1442. objs.resolve(id, img);
  1443. });
  1444. img.onerror = (function loadJpegStream_onerrorClosure() {
  1445. objs.resolve(id, null);
  1446. warn('Error during JPEG image loading');
  1447. });
  1448. img.src = imageUrl;
  1449. }
  1450. /**
  1451. * The maximum allowed image size in total pixels e.g. width * height. Images
  1452. * above this value will not be drawn. Use -1 for no limit.
  1453. * @var {number}
  1454. */
  1455. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1456. -1 : PDFJS.maxImageSize);
  1457. /**
  1458. * The url of where the predefined Adobe CMaps are located. Include trailing
  1459. * slash.
  1460. * @var {string}
  1461. */
  1462. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1463. /**
  1464. * Specifies if CMaps are binary packed.
  1465. * @var {boolean}
  1466. */
  1467. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1468. /*
  1469. * By default fonts are converted to OpenType fonts and loaded via font face
  1470. * rules. If disabled, the font will be rendered using a built in font renderer
  1471. * that constructs the glyphs with primitive path commands.
  1472. * @var {boolean}
  1473. */
  1474. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1475. false : PDFJS.disableFontFace);
  1476. /**
  1477. * Path for image resources, mainly for annotation icons. Include trailing
  1478. * slash.
  1479. * @var {string}
  1480. */
  1481. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1482. '' : PDFJS.imageResourcesPath);
  1483. /**
  1484. * Disable the web worker and run all code on the main thread. This will happen
  1485. * automatically if the browser doesn't support workers or sending typed arrays
  1486. * to workers.
  1487. * @var {boolean}
  1488. */
  1489. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1490. false : PDFJS.disableWorker);
  1491. /**
  1492. * Path and filename of the worker file. Required when the worker is enabled in
  1493. * development mode. If unspecified in the production build, the worker will be
  1494. * loaded based on the location of the pdf.js file.
  1495. * @var {string}
  1496. */
  1497. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1498. /**
  1499. * Disable range request loading of PDF files. When enabled and if the server
  1500. * supports partial content requests then the PDF will be fetched in chunks.
  1501. * Enabled (false) by default.
  1502. * @var {boolean}
  1503. */
  1504. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1505. false : PDFJS.disableRange);
  1506. /**
  1507. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  1508. * in chunks. This default behavior can be disabled.
  1509. * @var {boolean}
  1510. */
  1511. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  1512. false : PDFJS.disableStream);
  1513. /**
  1514. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1515. * will automatically keep fetching more data even if it isn't needed to display
  1516. * the current page. This default behavior can be disabled.
  1517. *
  1518. * NOTE: It is also necessary to disable streaming, see above,
  1519. * in order for disabling of pre-fetching to work correctly.
  1520. * @var {boolean}
  1521. */
  1522. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1523. false : PDFJS.disableAutoFetch);
  1524. /**
  1525. * Enables special hooks for debugging PDF.js.
  1526. * @var {boolean}
  1527. */
  1528. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1529. /**
  1530. * Enables transfer usage in postMessage for ArrayBuffers.
  1531. * @var {boolean}
  1532. */
  1533. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1534. true : PDFJS.postMessageTransfers);
  1535. /**
  1536. * Disables URL.createObjectURL usage.
  1537. * @var {boolean}
  1538. */
  1539. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1540. false : PDFJS.disableCreateObjectURL);
  1541. /**
  1542. * Disables WebGL usage.
  1543. * @var {boolean}
  1544. */
  1545. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1546. true : PDFJS.disableWebGL);
  1547. /**
  1548. * Enables CSS only zooming.
  1549. * @var {boolean}
  1550. */
  1551. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1552. false : PDFJS.useOnlyCssZoom);
  1553. /**
  1554. * Controls the logging level.
  1555. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1556. * - errors
  1557. * - warnings [default]
  1558. * - infos
  1559. * @var {number}
  1560. */
  1561. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1562. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1563. /**
  1564. * The maximum supported canvas size in total pixels e.g. width * height.
  1565. * The default value is 4096 * 4096. Use -1 for no limit.
  1566. * @var {number}
  1567. */
  1568. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1569. 16777216 : PDFJS.maxCanvasPixels);
  1570. /**
  1571. * Document initialization / loading parameters object.
  1572. *
  1573. * @typedef {Object} DocumentInitParameters
  1574. * @property {string} url - The URL of the PDF.
  1575. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  1576. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  1577. * use atob() to convert it to a binary string first.
  1578. * @property {Object} httpHeaders - Basic authentication headers.
  1579. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1580. * Access-Control requests should be made using credentials such as cookies
  1581. * or authorization headers. The default is false.
  1582. * @property {string} password - For decrypting password-protected PDFs.
  1583. * @property {TypedArray} initialData - A typed array with the first portion or
  1584. * all of the pdf data. Used by the extension since some data is already
  1585. * loaded before the switch to range requests.
  1586. * @property {number} length - The PDF file length. It's used for progress
  1587. * reports and range requests operations.
  1588. * @property {PDFDataRangeTransport} range
  1589. */
  1590. /**
  1591. * @typedef {Object} PDFDocumentStats
  1592. * @property {Array} streamTypes - Used stream types in the document (an item
  1593. * is set to true if specific stream ID was used in the document).
  1594. * @property {Array} fontTypes - Used font type in the document (an item is set
  1595. * to true if specific font ID was used in the document).
  1596. */
  1597. /**
  1598. * This is the main entry point for loading a PDF and interacting with it.
  1599. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1600. * is used, which means it must follow the same origin rules that any XHR does
  1601. * e.g. No cross domain requests without CORS.
  1602. *
  1603. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  1604. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  1605. * already populated with data or parameter object.
  1606. *
  1607. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  1608. * if you want to manually serve range requests for data in the PDF.
  1609. *
  1610. * @param {function} passwordCallback (deprecated) It is used to request a
  1611. * password if wrong or no password was provided. The callback receives two
  1612. * parameters: function that needs to be called with new password and reason
  1613. * (see {PasswordResponses}).
  1614. *
  1615. * @param {function} progressCallback (deprecated) It is used to be able to
  1616. * monitor the loading progress of the PDF file (necessary to implement e.g.
  1617. * a loading bar). The callback receives an {Object} with the properties:
  1618. * {number} loaded and {number} total.
  1619. *
  1620. * @return {PDFDocumentLoadingTask}
  1621. */
  1622. PDFJS.getDocument = function getDocument(src,
  1623. pdfDataRangeTransport,
  1624. passwordCallback,
  1625. progressCallback) {
  1626. var task = new PDFDocumentLoadingTask();
  1627. // Support of the obsolete arguments (for compatibility with API v1.0)
  1628. if (pdfDataRangeTransport) {
  1629. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  1630. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  1631. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  1632. pdfDataRangeTransport.length = src.length;
  1633. pdfDataRangeTransport.initialData = src.initialData;
  1634. }
  1635. src = Object.create(src);
  1636. src.range = pdfDataRangeTransport;
  1637. }
  1638. task.onPassword = passwordCallback || null;
  1639. task.onProgress = progressCallback || null;
  1640. var workerInitializedCapability, transport;
  1641. var source;
  1642. if (typeof src === 'string') {
  1643. source = { url: src };
  1644. } else if (isArrayBuffer(src)) {
  1645. source = { data: src };
  1646. } else if (src instanceof PDFDataRangeTransport) {
  1647. source = { range: src };
  1648. } else {
  1649. if (typeof src !== 'object') {
  1650. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1651. 'string or a parameter object');
  1652. }
  1653. if (!src.url && !src.data && !src.range) {
  1654. error('Invalid parameter object: need either .data, .range or .url');
  1655. }
  1656. source = src;
  1657. }
  1658. var params = {};
  1659. for (var key in source) {
  1660. if (key === 'url' && typeof window !== 'undefined') {
  1661. // The full path is required in the 'url' field.
  1662. params[key] = combineUrl(window.location.href, source[key]);
  1663. continue;
  1664. } else if (key === 'range') {
  1665. continue;
  1666. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  1667. // Converting string or array-like data to Uint8Array.
  1668. var pdfBytes = source[key];
  1669. if (typeof pdfBytes === 'string') {
  1670. params[key] = stringToBytes(pdfBytes);
  1671. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  1672. !isNaN(pdfBytes.length)) {
  1673. params[key] = new Uint8Array(pdfBytes);
  1674. } else {
  1675. error('Invalid PDF binary data: either typed array, string or ' +
  1676. 'array-like object is expected in the data property.');
  1677. }
  1678. continue;
  1679. }
  1680. params[key] = source[key];
  1681. }
  1682. workerInitializedCapability = createPromiseCapability();
  1683. transport = new WorkerTransport(workerInitializedCapability, source.range);
  1684. workerInitializedCapability.promise.then(function transportInitialized() {
  1685. transport.fetchDocument(task, params);
  1686. });
  1687. return task;
  1688. };
  1689. /**
  1690. * PDF document loading operation.
  1691. * @class
  1692. */
  1693. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  1694. /** @constructs PDFDocumentLoadingTask */
  1695. function PDFDocumentLoadingTask() {
  1696. this._capability = createPromiseCapability();
  1697. /**
  1698. * Callback to request a password if wrong or no password was provided.
  1699. * The callback receives two parameters: function that needs to be called
  1700. * with new password and reason (see {PasswordResponses}).
  1701. */
  1702. this.onPassword = null;
  1703. /**
  1704. * Callback to be able to monitor the loading progress of the PDF file
  1705. * (necessary to implement e.g. a loading bar). The callback receives
  1706. * an {Object} with the properties: {number} loaded and {number} total.
  1707. */
  1708. this.onProgress = null;
  1709. }
  1710. PDFDocumentLoadingTask.prototype =
  1711. /** @lends PDFDocumentLoadingTask.prototype */ {
  1712. /**
  1713. * @return {Promise}
  1714. */
  1715. get promise() {
  1716. return this._capability.promise;
  1717. },
  1718. // TODO add cancel or abort method
  1719. /**
  1720. * Registers callbacks to indicate the document loading completion.
  1721. *
  1722. * @param {function} onFulfilled The callback for the loading completion.
  1723. * @param {function} onRejected The callback for the loading failure.
  1724. * @return {Promise} A promise that is resolved after the onFulfilled or
  1725. * onRejected callback.
  1726. */
  1727. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  1728. return this.promise.then.apply(this.promise, arguments);
  1729. }
  1730. };
  1731. return PDFDocumentLoadingTask;
  1732. })();
  1733. /**
  1734. * Abstract class to support range requests file loading.
  1735. * @class
  1736. */
  1737. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  1738. /**
  1739. * @constructs PDFDataRangeTransport
  1740. * @param {number} length
  1741. * @param {Uint8Array} initialData
  1742. */
  1743. function PDFDataRangeTransport(length, initialData) {
  1744. this.length = length;
  1745. this.initialData = initialData;
  1746. this._rangeListeners = [];
  1747. this._progressListeners = [];
  1748. this._progressiveReadListeners = [];
  1749. this._readyCapability = createPromiseCapability();
  1750. }
  1751. PDFDataRangeTransport.prototype =
  1752. /** @lends PDFDataRangeTransport.prototype */ {
  1753. addRangeListener:
  1754. function PDFDataRangeTransport_addRangeListener(listener) {
  1755. this._rangeListeners.push(listener);
  1756. },
  1757. addProgressListener:
  1758. function PDFDataRangeTransport_addProgressListener(listener) {
  1759. this._progressListeners.push(listener);
  1760. },
  1761. addProgressiveReadListener:
  1762. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  1763. this._progressiveReadListeners.push(listener);
  1764. },
  1765. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  1766. var listeners = this._rangeListeners;
  1767. for (var i = 0, n = listeners.length; i < n; ++i) {
  1768. listeners[i](begin, chunk);
  1769. }
  1770. },
  1771. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  1772. this._readyCapability.promise.then(function () {
  1773. var listeners = this._progressListeners;
  1774. for (var i = 0, n = listeners.length; i < n; ++i) {
  1775. listeners[i](loaded);
  1776. }
  1777. }.bind(this));
  1778. },
  1779. onDataProgressiveRead:
  1780. function PDFDataRangeTransport_onDataProgress(chunk) {
  1781. this._readyCapability.promise.then(function () {
  1782. var listeners = this._progressiveReadListeners;
  1783. for (var i = 0, n = listeners.length; i < n; ++i) {
  1784. listeners[i](chunk);
  1785. }
  1786. }.bind(this));
  1787. },
  1788. transportReady: function PDFDataRangeTransport_transportReady() {
  1789. this._readyCapability.resolve();
  1790. },
  1791. requestDataRange:
  1792. function PDFDataRangeTransport_requestDataRange(begin, end) {
  1793. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  1794. }
  1795. };
  1796. return PDFDataRangeTransport;
  1797. })();
  1798. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  1799. /**
  1800. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1801. * properties that can be read synchronously.
  1802. * @class
  1803. */
  1804. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1805. function PDFDocumentProxy(pdfInfo, transport) {
  1806. this.pdfInfo = pdfInfo;
  1807. this.transport = transport;
  1808. }
  1809. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1810. /**
  1811. * @return {number} Total number of pages the PDF contains.
  1812. */
  1813. get numPages() {
  1814. return this.pdfInfo.numPages;
  1815. },
  1816. /**
  1817. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1818. * unique.
  1819. */
  1820. get fingerprint() {
  1821. return this.pdfInfo.fingerprint;
  1822. },
  1823. /**
  1824. * @param {number} pageNumber The page number to get. The first page is 1.
  1825. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1826. * object.
  1827. */
  1828. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1829. return this.transport.getPage(pageNumber);
  1830. },
  1831. /**
  1832. * @param {{num: number, gen: number}} ref The page reference. Must have
  1833. * the 'num' and 'gen' properties.
  1834. * @return {Promise} A promise that is resolved with the page index that is
  1835. * associated with the reference.
  1836. */
  1837. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1838. return this.transport.getPageIndex(ref);
  1839. },
  1840. /**
  1841. * @return {Promise} A promise that is resolved with a lookup table for
  1842. * mapping named destinations to reference numbers.
  1843. *
  1844. * This can be slow for large documents: use getDestination instead
  1845. */
  1846. getDestinations: function PDFDocumentProxy_getDestinations() {
  1847. return this.transport.getDestinations();
  1848. },
  1849. /**
  1850. * @param {string} id The named destination to get.
  1851. * @return {Promise} A promise that is resolved with all information
  1852. * of the given named destination.
  1853. */
  1854. getDestination: function PDFDocumentProxy_getDestination(id) {
  1855. return this.transport.getDestination(id);
  1856. },
  1857. /**
  1858. * @return {Promise} A promise that is resolved with a lookup table for
  1859. * mapping named attachments to their content.
  1860. */
  1861. getAttachments: function PDFDocumentProxy_getAttachments() {
  1862. return this.transport.getAttachments();
  1863. },
  1864. /**
  1865. * @return {Promise} A promise that is resolved with an array of all the
  1866. * JavaScript strings in the name tree.
  1867. */
  1868. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1869. return this.transport.getJavaScript();
  1870. },
  1871. /**
  1872. * @return {Promise} A promise that is resolved with an {Array} that is a
  1873. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1874. * [
  1875. * {
  1876. * title: string,
  1877. * bold: boolean,
  1878. * italic: boolean,
  1879. * color: rgb array,
  1880. * dest: dest obj,
  1881. * items: array of more items like this
  1882. * },
  1883. * ...
  1884. * ].
  1885. */
  1886. getOutline: function PDFDocumentProxy_getOutline() {
  1887. return this.transport.getOutline();
  1888. },
  1889. /**
  1890. * @return {Promise} A promise that is resolved with an {Object} that has
  1891. * info and metadata properties. Info is an {Object} filled with anything
  1892. * available in the information dictionary and similarly metadata is a
  1893. * {Metadata} object with information from the metadata section of the PDF.
  1894. */
  1895. getMetadata: function PDFDocumentProxy_getMetadata() {
  1896. return this.transport.getMetadata();
  1897. },
  1898. /**
  1899. * @return {Promise} A promise that is resolved with a TypedArray that has
  1900. * the raw data from the PDF.
  1901. */
  1902. getData: function PDFDocumentProxy_getData() {
  1903. return this.transport.getData();
  1904. },
  1905. /**
  1906. * @return {Promise} A promise that is resolved when the document's data
  1907. * is loaded. It is resolved with an {Object} that contains the length
  1908. * property that indicates size of the PDF data in bytes.
  1909. */
  1910. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1911. return this.transport.downloadInfoCapability.promise;
  1912. },
  1913. /**
  1914. * @return {Promise} A promise this is resolved with current stats about
  1915. * document structures (see {@link PDFDocumentStats}).
  1916. */
  1917. getStats: function PDFDocumentProxy_getStats() {
  1918. return this.transport.getStats();
  1919. },
  1920. /**
  1921. * Cleans up resources allocated by the document, e.g. created @font-face.
  1922. */
  1923. cleanup: function PDFDocumentProxy_cleanup() {
  1924. this.transport.startCleanup();
  1925. },
  1926. /**
  1927. * Destroys current document instance and terminates worker.
  1928. */
  1929. destroy: function PDFDocumentProxy_destroy() {
  1930. this.transport.destroy();
  1931. }
  1932. };
  1933. return PDFDocumentProxy;
  1934. })();
  1935. /**
  1936. * Page text content.
  1937. *
  1938. * @typedef {Object} TextContent
  1939. * @property {array} items - array of {@link TextItem}
  1940. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  1941. * name.
  1942. */
  1943. /**
  1944. * Page text content part.
  1945. *
  1946. * @typedef {Object} TextItem
  1947. * @property {string} str - text content.
  1948. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  1949. * @property {array} transform - transformation matrix.
  1950. * @property {number} width - width in device space.
  1951. * @property {number} height - height in device space.
  1952. * @property {string} fontName - font name used by pdf.js for converted font.
  1953. */
  1954. /**
  1955. * Text style.
  1956. *
  1957. * @typedef {Object} TextStyle
  1958. * @property {number} ascent - font ascent.
  1959. * @property {number} descent - font descent.
  1960. * @property {boolean} vertical - text is in vertical mode.
  1961. * @property {string} fontFamily - possible font family
  1962. */
  1963. /**
  1964. * Page render parameters.
  1965. *
  1966. * @typedef {Object} RenderParameters
  1967. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  1968. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  1969. * calling of PDFPage.getViewport method.
  1970. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  1971. * (default value is 'display').
  1972. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  1973. * endLayout and appendImage functions.
  1974. * @property {function} continueCallback - (deprecated) A function that will be
  1975. * called each time the rendering is paused. To continue
  1976. * rendering call the function that is the first argument
  1977. * to the callback.
  1978. */
  1979. /**
  1980. * PDF page operator list.
  1981. *
  1982. * @typedef {Object} PDFOperatorList
  1983. * @property {Array} fnArray - Array containing the operator functions.
  1984. * @property {Array} argsArray - Array containing the arguments of the
  1985. * functions.
  1986. */
  1987. /**
  1988. * Proxy to a PDFPage in the worker thread.
  1989. * @class
  1990. */
  1991. var PDFPageProxy = (function PDFPageProxyClosure() {
  1992. function PDFPageProxy(pageIndex, pageInfo, transport) {
  1993. this.pageIndex = pageIndex;
  1994. this.pageInfo = pageInfo;
  1995. this.transport = transport;
  1996. this.stats = new StatTimer();
  1997. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  1998. this.commonObjs = transport.commonObjs;
  1999. this.objs = new PDFObjects();
  2000. this.cleanupAfterRender = false;
  2001. this.pendingDestroy = false;
  2002. this.intentStates = {};
  2003. }
  2004. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  2005. /**
  2006. * @return {number} Page number of the page. First page is 1.
  2007. */
  2008. get pageNumber() {
  2009. return this.pageIndex + 1;
  2010. },
  2011. /**
  2012. * @return {number} The number of degrees the page is rotated clockwise.
  2013. */
  2014. get rotate() {
  2015. return this.pageInfo.rotate;
  2016. },
  2017. /**
  2018. * @return {Object} The reference that points to this page. It has 'num' and
  2019. * 'gen' properties.
  2020. */
  2021. get ref() {
  2022. return this.pageInfo.ref;
  2023. },
  2024. /**
  2025. * @return {Array} An array of the visible portion of the PDF page in the
  2026. * user space units - [x1, y1, x2, y2].
  2027. */
  2028. get view() {
  2029. return this.pageInfo.view;
  2030. },
  2031. /**
  2032. * @param {number} scale The desired scale of the viewport.
  2033. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  2034. * defaults to the page rotation.
  2035. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  2036. * along with transforms required for rendering.
  2037. */
  2038. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  2039. if (arguments.length < 2) {
  2040. rotate = this.rotate;
  2041. }
  2042. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  2043. },
  2044. /**
  2045. * @return {Promise} A promise that is resolved with an {Array} of the
  2046. * annotation objects.
  2047. */
  2048. getAnnotations: function PDFPageProxy_getAnnotations() {
  2049. if (this.annotationsPromise) {
  2050. return this.annotationsPromise;
  2051. }
  2052. var promise = this.transport.getAnnotations(this.pageIndex);
  2053. this.annotationsPromise = promise;
  2054. return promise;
  2055. },
  2056. /**
  2057. * Begins the process of rendering a page to the desired context.
  2058. * @param {RenderParameters} params Page render parameters.
  2059. * @return {RenderTask} An object that contains the promise, which
  2060. * is resolved when the page finishes rendering.
  2061. */
  2062. render: function PDFPageProxy_render(params) {
  2063. var stats = this.stats;
  2064. stats.time('Overall');
  2065. // If there was a pending destroy cancel it so no cleanup happens during
  2066. // this call to render.
  2067. this.pendingDestroy = false;
  2068. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  2069. if (!this.intentStates[renderingIntent]) {
  2070. this.intentStates[renderingIntent] = {};
  2071. }
  2072. var intentState = this.intentStates[renderingIntent];
  2073. // If there's no displayReadyCapability yet, then the operatorList
  2074. // was never requested before. Make the request and create the promise.
  2075. if (!intentState.displayReadyCapability) {
  2076. intentState.receivingOperatorList = true;
  2077. intentState.displayReadyCapability = createPromiseCapability();
  2078. intentState.operatorList = {
  2079. fnArray: [],
  2080. argsArray: [],
  2081. lastChunk: false
  2082. };
  2083. this.stats.time('Page Request');
  2084. this.transport.messageHandler.send('RenderPageRequest', {
  2085. pageIndex: this.pageNumber - 1,
  2086. intent: renderingIntent
  2087. });
  2088. }
  2089. var internalRenderTask = new InternalRenderTask(complete, params,
  2090. this.objs,
  2091. this.commonObjs,
  2092. intentState.operatorList,
  2093. this.pageNumber);
  2094. if (!intentState.renderTasks) {
  2095. intentState.renderTasks = [];
  2096. }
  2097. intentState.renderTasks.push(internalRenderTask);
  2098. var renderTask = internalRenderTask.task;
  2099. // Obsolete parameter support
  2100. if (params.continueCallback) {
  2101. renderTask.onContinue = params.continueCallback;
  2102. }
  2103. var self = this;
  2104. intentState.displayReadyCapability.promise.then(
  2105. function pageDisplayReadyPromise(transparency) {
  2106. if (self.pendingDestroy) {
  2107. complete();
  2108. return;
  2109. }
  2110. stats.time('Rendering');
  2111. internalRenderTask.initalizeGraphics(transparency);
  2112. internalRenderTask.operatorListChanged();
  2113. },
  2114. function pageDisplayReadPromiseError(reason) {
  2115. complete(reason);
  2116. }
  2117. );
  2118. function complete(error) {
  2119. var i = intentState.renderTasks.indexOf(internalRenderTask);
  2120. if (i >= 0) {
  2121. intentState.renderTasks.splice(i, 1);
  2122. }
  2123. if (self.cleanupAfterRender) {
  2124. self.pendingDestroy = true;
  2125. }
  2126. self._tryDestroy();
  2127. if (error) {
  2128. internalRenderTask.capability.reject(error);
  2129. } else {
  2130. internalRenderTask.capability.resolve();
  2131. }
  2132. stats.timeEnd('Rendering');
  2133. stats.timeEnd('Overall');
  2134. }
  2135. return renderTask;
  2136. },
  2137. /**
  2138. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  2139. * object that represents page's operator list.
  2140. */
  2141. getOperatorList: function PDFPageProxy_getOperatorList() {
  2142. function operatorListChanged() {
  2143. if (intentState.operatorList.lastChunk) {
  2144. intentState.opListReadCapability.resolve(intentState.operatorList);
  2145. }
  2146. }
  2147. var renderingIntent = 'oplist';
  2148. if (!this.intentStates[renderingIntent]) {
  2149. this.intentStates[renderingIntent] = {};
  2150. }
  2151. var intentState = this.intentStates[renderingIntent];
  2152. if (!intentState.opListReadCapability) {
  2153. var opListTask = {};
  2154. opListTask.operatorListChanged = operatorListChanged;
  2155. intentState.receivingOperatorList = true;
  2156. intentState.opListReadCapability = createPromiseCapability();
  2157. intentState.renderTasks = [];
  2158. intentState.renderTasks.push(opListTask);
  2159. intentState.operatorList = {
  2160. fnArray: [],
  2161. argsArray: [],
  2162. lastChunk: false
  2163. };
  2164. this.transport.messageHandler.send('RenderPageRequest', {
  2165. pageIndex: this.pageIndex,
  2166. intent: renderingIntent
  2167. });
  2168. }
  2169. return intentState.opListReadCapability.promise;
  2170. },
  2171. /**
  2172. * @return {Promise} That is resolved a {@link TextContent}
  2173. * object that represent the page text content.
  2174. */
  2175. getTextContent: function PDFPageProxy_getTextContent() {
  2176. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  2177. pageIndex: this.pageNumber - 1
  2178. });
  2179. },
  2180. /**
  2181. * Destroys resources allocated by the page.
  2182. */
  2183. destroy: function PDFPageProxy_destroy() {
  2184. this.pendingDestroy = true;
  2185. this._tryDestroy();
  2186. },
  2187. /**
  2188. * For internal use only. Attempts to clean up if rendering is in a state
  2189. * where that's possible.
  2190. * @ignore
  2191. */
  2192. _tryDestroy: function PDFPageProxy__destroy() {
  2193. if (!this.pendingDestroy ||
  2194. Object.keys(this.intentStates).some(function(intent) {
  2195. var intentState = this.intentStates[intent];
  2196. return (intentState.renderTasks.length !== 0 ||
  2197. intentState.receivingOperatorList);
  2198. }, this)) {
  2199. return;
  2200. }
  2201. Object.keys(this.intentStates).forEach(function(intent) {
  2202. delete this.intentStates[intent];
  2203. }, this);
  2204. this.objs.clear();
  2205. this.annotationsPromise = null;
  2206. this.pendingDestroy = false;
  2207. },
  2208. /**
  2209. * For internal use only.
  2210. * @ignore
  2211. */
  2212. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2213. intent) {
  2214. var intentState = this.intentStates[intent];
  2215. // TODO Refactor RenderPageRequest to separate rendering
  2216. // and operator list logic
  2217. if (intentState.displayReadyCapability) {
  2218. intentState.displayReadyCapability.resolve(transparency);
  2219. }
  2220. },
  2221. /**
  2222. * For internal use only.
  2223. * @ignore
  2224. */
  2225. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2226. intent) {
  2227. var intentState = this.intentStates[intent];
  2228. var i, ii;
  2229. // Add the new chunk to the current operator list.
  2230. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2231. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2232. intentState.operatorList.argsArray.push(
  2233. operatorListChunk.argsArray[i]);
  2234. }
  2235. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2236. // Notify all the rendering tasks there are more operators to be consumed.
  2237. for (i = 0; i < intentState.renderTasks.length; i++) {
  2238. intentState.renderTasks[i].operatorListChanged();
  2239. }
  2240. if (operatorListChunk.lastChunk) {
  2241. intentState.receivingOperatorList = false;
  2242. this._tryDestroy();
  2243. }
  2244. }
  2245. };
  2246. return PDFPageProxy;
  2247. })();
  2248. /**
  2249. * For internal use only.
  2250. * @ignore
  2251. */
  2252. var WorkerTransport = (function WorkerTransportClosure() {
  2253. function WorkerTransport(workerInitializedCapability, pdfDataRangeTransport) {
  2254. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2255. this.workerInitializedCapability = workerInitializedCapability;
  2256. this.commonObjs = new PDFObjects();
  2257. this.loadingTask = null;
  2258. this.pageCache = [];
  2259. this.pagePromises = [];
  2260. this.downloadInfoCapability = createPromiseCapability();
  2261. // If worker support isn't disabled explicit and the browser has worker
  2262. // support, create a new web worker and test if it/the browser fullfills
  2263. // all requirements to run parts of pdf.js in a web worker.
  2264. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2265. // as it arrives on the worker. Chrome added this with version 15.
  2266. // Either workers are disabled, not supported or have thrown an exception.
  2267. // Thus, we fallback to a faked worker.
  2268. this.setupFakeWorker();
  2269. }
  2270. WorkerTransport.prototype = {
  2271. destroy: function WorkerTransport_destroy() {
  2272. this.pageCache = [];
  2273. this.pagePromises = [];
  2274. var self = this;
  2275. this.messageHandler.sendWithPromise('Terminate', null).then(function () {
  2276. FontLoader.clear();
  2277. if (self.worker) {
  2278. self.worker.terminate();
  2279. }
  2280. });
  2281. },
  2282. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2283. globalScope.PDFJS.disableWorker = true;
  2284. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2285. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2286. // In the developer build load worker_loader which in turn loads all the
  2287. // other files and resolves the promise. In production only the
  2288. // pdf.worker.js file is needed.
  2289. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2290. }
  2291. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2292. warn('Setting up fake worker.');
  2293. // If we don't use a worker, just post/sendMessage to the main thread.
  2294. var fakeWorker = {
  2295. postMessage: function WorkerTransport_postMessage(obj) {
  2296. fakeWorker.onmessage({data: obj});
  2297. },
  2298. terminate: function WorkerTransport_terminate() {}
  2299. };
  2300. var messageHandler = new MessageHandler('main', fakeWorker);
  2301. this.setupMessageHandler(messageHandler);
  2302. // If the main thread is our worker, setup the handling for the messages
  2303. // the main thread sends to it self.
  2304. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2305. this.workerInitializedCapability.resolve();
  2306. }.bind(this));
  2307. },
  2308. setupMessageHandler:
  2309. function WorkerTransport_setupMessageHandler(messageHandler) {
  2310. this.messageHandler = messageHandler;
  2311. function updatePassword(password) {
  2312. messageHandler.send('UpdatePassword', password);
  2313. }
  2314. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2315. if (pdfDataRangeTransport) {
  2316. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2317. messageHandler.send('OnDataRange', {
  2318. begin: begin,
  2319. chunk: chunk
  2320. });
  2321. });
  2322. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2323. messageHandler.send('OnDataProgress', {
  2324. loaded: loaded
  2325. });
  2326. });
  2327. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  2328. messageHandler.send('OnDataRange', {
  2329. chunk: chunk
  2330. });
  2331. });
  2332. messageHandler.on('RequestDataRange',
  2333. function transportDataRange(data) {
  2334. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2335. }, this);
  2336. }
  2337. messageHandler.on('GetDoc', function transportDoc(data) {
  2338. var pdfInfo = data.pdfInfo;
  2339. this.numPages = data.pdfInfo.numPages;
  2340. var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
  2341. this.pdfDocument = pdfDocument;
  2342. this.loadingTask._capability.resolve(pdfDocument);
  2343. }, this);
  2344. messageHandler.on('NeedPassword',
  2345. function transportNeedPassword(exception) {
  2346. var loadingTask = this.loadingTask;
  2347. if (loadingTask.onPassword) {
  2348. return loadingTask.onPassword(updatePassword,
  2349. PasswordResponses.NEED_PASSWORD);
  2350. }
  2351. loadingTask._capability.reject(
  2352. new PasswordException(exception.message, exception.code));
  2353. }, this);
  2354. messageHandler.on('IncorrectPassword',
  2355. function transportIncorrectPassword(exception) {
  2356. var loadingTask = this.loadingTask;
  2357. if (loadingTask.onPassword) {
  2358. return loadingTask.onPassword(updatePassword,
  2359. PasswordResponses.INCORRECT_PASSWORD);
  2360. }
  2361. loadingTask._capability.reject(
  2362. new PasswordException(exception.message, exception.code));
  2363. }, this);
  2364. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2365. this.loadingTask._capability.reject(
  2366. new InvalidPDFException(exception.message));
  2367. }, this);
  2368. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2369. this.loadingTask._capability.reject(
  2370. new MissingPDFException(exception.message));
  2371. }, this);
  2372. messageHandler.on('UnexpectedResponse',
  2373. function transportUnexpectedResponse(exception) {
  2374. this.loadingTask._capability.reject(
  2375. new UnexpectedResponseException(exception.message, exception.status));
  2376. }, this);
  2377. messageHandler.on('UnknownError',
  2378. function transportUnknownError(exception) {
  2379. this.loadingTask._capability.reject(
  2380. new UnknownErrorException(exception.message, exception.details));
  2381. }, this);
  2382. messageHandler.on('DataLoaded', function transportPage(data) {
  2383. this.downloadInfoCapability.resolve(data);
  2384. }, this);
  2385. messageHandler.on('PDFManagerReady', function transportPage(data) {
  2386. if (this.pdfDataRangeTransport) {
  2387. this.pdfDataRangeTransport.transportReady();
  2388. }
  2389. }, this);
  2390. messageHandler.on('StartRenderPage', function transportRender(data) {
  2391. var page = this.pageCache[data.pageIndex];
  2392. page.stats.timeEnd('Page Request');
  2393. page._startRenderPage(data.transparency, data.intent);
  2394. }, this);
  2395. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2396. var page = this.pageCache[data.pageIndex];
  2397. page._renderPageChunk(data.operatorList, data.intent);
  2398. }, this);
  2399. messageHandler.on('commonobj', function transportObj(data) {
  2400. var id = data[0];
  2401. var type = data[1];
  2402. if (this.commonObjs.hasData(id)) {
  2403. return;
  2404. }
  2405. switch (type) {
  2406. case 'Font':
  2407. var exportedData = data[2];
  2408. var font;
  2409. if ('error' in exportedData) {
  2410. var error = exportedData.error;
  2411. warn('Error during font loading: ' + error);
  2412. this.commonObjs.resolve(id, error);
  2413. break;
  2414. } else {
  2415. font = new FontFaceObject(exportedData);
  2416. }
  2417. FontLoader.bind(
  2418. [font],
  2419. function fontReady(fontObjs) {
  2420. this.commonObjs.resolve(id, font);
  2421. }.bind(this)
  2422. );
  2423. break;
  2424. case 'FontPath':
  2425. this.commonObjs.resolve(id, data[2]);
  2426. break;
  2427. default:
  2428. error('Got unknown common object type ' + type);
  2429. }
  2430. }, this);
  2431. messageHandler.on('obj', function transportObj(data) {
  2432. var id = data[0];
  2433. var pageIndex = data[1];
  2434. var type = data[2];
  2435. var pageProxy = this.pageCache[pageIndex];
  2436. var imageData;
  2437. if (pageProxy.objs.hasData(id)) {
  2438. return;
  2439. }
  2440. switch (type) {
  2441. case 'JpegStream':
  2442. imageData = data[3];
  2443. loadJpegStream(id, imageData, pageProxy.objs);
  2444. break;
  2445. case 'Image':
  2446. imageData = data[3];
  2447. pageProxy.objs.resolve(id, imageData);
  2448. // heuristics that will allow not to store large data
  2449. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2450. if (imageData && 'data' in imageData &&
  2451. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2452. pageProxy.cleanupAfterRender = true;
  2453. }
  2454. break;
  2455. default:
  2456. error('Got unknown object type ' + type);
  2457. }
  2458. }, this);
  2459. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2460. var loadingTask = this.loadingTask;
  2461. if (loadingTask.onProgress) {
  2462. loadingTask.onProgress({
  2463. loaded: data.loaded,
  2464. total: data.total
  2465. });
  2466. }
  2467. }, this);
  2468. messageHandler.on('PageError', function transportError(data) {
  2469. var page = this.pageCache[data.pageNum - 1];
  2470. var intentState = page.intentStates[data.intent];
  2471. if (intentState.displayReadyCapability) {
  2472. intentState.displayReadyCapability.reject(data.error);
  2473. } else {
  2474. error(data.error);
  2475. }
  2476. }, this);
  2477. messageHandler.on('JpegDecode', function(data) {
  2478. var imageUrl = data[0];
  2479. var components = data[1];
  2480. if (components !== 3 && components !== 1) {
  2481. return Promise.reject(
  2482. new Error('Only 3 components or 1 component can be returned'));
  2483. }
  2484. return new Promise(function (resolve, reject) {
  2485. var img = new Image();
  2486. img.onload = function () {
  2487. var width = img.width;
  2488. var height = img.height;
  2489. var size = width * height;
  2490. var rgbaLength = size * 4;
  2491. var buf = new Uint8Array(size * components);
  2492. var tmpCanvas = createScratchCanvas(width, height);
  2493. var tmpCtx = tmpCanvas.getContext('2d');
  2494. tmpCtx.drawImage(img, 0, 0);
  2495. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2496. var i, j;
  2497. if (components === 3) {
  2498. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2499. buf[j] = data[i];
  2500. buf[j + 1] = data[i + 1];
  2501. buf[j + 2] = data[i + 2];
  2502. }
  2503. } else if (components === 1) {
  2504. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2505. buf[j] = data[i];
  2506. }
  2507. }
  2508. resolve({ data: buf, width: width, height: height});
  2509. };
  2510. img.onerror = function () {
  2511. reject(new Error('JpegDecode failed to load image'));
  2512. };
  2513. img.src = imageUrl;
  2514. });
  2515. });
  2516. },
  2517. fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
  2518. this.loadingTask = loadingTask;
  2519. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2520. source.disableStream = PDFJS.disableStream;
  2521. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2522. if (this.pdfDataRangeTransport) {
  2523. source.length = this.pdfDataRangeTransport.length;
  2524. source.initialData = this.pdfDataRangeTransport.initialData;
  2525. }
  2526. this.messageHandler.send('GetDocRequest', {
  2527. source: source,
  2528. disableRange: PDFJS.disableRange,
  2529. maxImageSize: PDFJS.maxImageSize,
  2530. cMapUrl: PDFJS.cMapUrl,
  2531. cMapPacked: PDFJS.cMapPacked,
  2532. disableFontFace: PDFJS.disableFontFace,
  2533. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2534. verbosity: PDFJS.verbosity
  2535. });
  2536. },
  2537. getData: function WorkerTransport_getData() {
  2538. return this.messageHandler.sendWithPromise('GetData', null);
  2539. },
  2540. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2541. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2542. (pageNumber|0) !== pageNumber) {
  2543. return Promise.reject(new Error('Invalid page request'));
  2544. }
  2545. var pageIndex = pageNumber - 1;
  2546. if (pageIndex in this.pagePromises) {
  2547. return this.pagePromises[pageIndex];
  2548. }
  2549. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2550. pageIndex: pageIndex
  2551. }).then(function (pageInfo) {
  2552. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2553. this.pageCache[pageIndex] = page;
  2554. return page;
  2555. }.bind(this));
  2556. this.pagePromises[pageIndex] = promise;
  2557. return promise;
  2558. },
  2559. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2560. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2561. },
  2562. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2563. return this.messageHandler.sendWithPromise('GetAnnotations',
  2564. { pageIndex: pageIndex });
  2565. },
  2566. getDestinations: function WorkerTransport_getDestinations() {
  2567. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2568. },
  2569. getDestination: function WorkerTransport_getDestination(id) {
  2570. return this.messageHandler.sendWithPromise('GetDestination', { id: id } );
  2571. },
  2572. getAttachments: function WorkerTransport_getAttachments() {
  2573. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2574. },
  2575. getJavaScript: function WorkerTransport_getJavaScript() {
  2576. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2577. },
  2578. getOutline: function WorkerTransport_getOutline() {
  2579. return this.messageHandler.sendWithPromise('GetOutline', null);
  2580. },
  2581. getMetadata: function WorkerTransport_getMetadata() {
  2582. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2583. then(function transportMetadata(results) {
  2584. return {
  2585. info: results[0],
  2586. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2587. };
  2588. });
  2589. },
  2590. getStats: function WorkerTransport_getStats() {
  2591. return this.messageHandler.sendWithPromise('GetStats', null);
  2592. },
  2593. startCleanup: function WorkerTransport_startCleanup() {
  2594. this.messageHandler.sendWithPromise('Cleanup', null).
  2595. then(function endCleanup() {
  2596. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2597. var page = this.pageCache[i];
  2598. if (page) {
  2599. page.destroy();
  2600. }
  2601. }
  2602. this.commonObjs.clear();
  2603. FontLoader.clear();
  2604. }.bind(this));
  2605. }
  2606. };
  2607. return WorkerTransport;
  2608. })();
  2609. /**
  2610. * A PDF document and page is built of many objects. E.g. there are objects
  2611. * for fonts, images, rendering code and such. These objects might get processed
  2612. * inside of a worker. The `PDFObjects` implements some basic functions to
  2613. * manage these objects.
  2614. * @ignore
  2615. */
  2616. var PDFObjects = (function PDFObjectsClosure() {
  2617. function PDFObjects() {
  2618. this.objs = {};
  2619. }
  2620. PDFObjects.prototype = {
  2621. /**
  2622. * Internal function.
  2623. * Ensures there is an object defined for `objId`.
  2624. */
  2625. ensureObj: function PDFObjects_ensureObj(objId) {
  2626. if (this.objs[objId]) {
  2627. return this.objs[objId];
  2628. }
  2629. var obj = {
  2630. capability: createPromiseCapability(),
  2631. data: null,
  2632. resolved: false
  2633. };
  2634. this.objs[objId] = obj;
  2635. return obj;
  2636. },
  2637. /**
  2638. * If called *without* callback, this returns the data of `objId` but the
  2639. * object needs to be resolved. If it isn't, this function throws.
  2640. *
  2641. * If called *with* a callback, the callback is called with the data of the
  2642. * object once the object is resolved. That means, if you call this
  2643. * function and the object is already resolved, the callback gets called
  2644. * right away.
  2645. */
  2646. get: function PDFObjects_get(objId, callback) {
  2647. // If there is a callback, then the get can be async and the object is
  2648. // not required to be resolved right now
  2649. if (callback) {
  2650. this.ensureObj(objId).capability.promise.then(callback);
  2651. return null;
  2652. }
  2653. // If there isn't a callback, the user expects to get the resolved data
  2654. // directly.
  2655. var obj = this.objs[objId];
  2656. // If there isn't an object yet or the object isn't resolved, then the
  2657. // data isn't ready yet!
  2658. if (!obj || !obj.resolved) {
  2659. error('Requesting object that isn\'t resolved yet ' + objId);
  2660. }
  2661. return obj.data;
  2662. },
  2663. /**
  2664. * Resolves the object `objId` with optional `data`.
  2665. */
  2666. resolve: function PDFObjects_resolve(objId, data) {
  2667. var obj = this.ensureObj(objId);
  2668. obj.resolved = true;
  2669. obj.data = data;
  2670. obj.capability.resolve(data);
  2671. },
  2672. isResolved: function PDFObjects_isResolved(objId) {
  2673. var objs = this.objs;
  2674. if (!objs[objId]) {
  2675. return false;
  2676. } else {
  2677. return objs[objId].resolved;
  2678. }
  2679. },
  2680. hasData: function PDFObjects_hasData(objId) {
  2681. return this.isResolved(objId);
  2682. },
  2683. /**
  2684. * Returns the data of `objId` if object exists, null otherwise.
  2685. */
  2686. getData: function PDFObjects_getData(objId) {
  2687. var objs = this.objs;
  2688. if (!objs[objId] || !objs[objId].resolved) {
  2689. return null;
  2690. } else {
  2691. return objs[objId].data;
  2692. }
  2693. },
  2694. clear: function PDFObjects_clear() {
  2695. this.objs = {};
  2696. }
  2697. };
  2698. return PDFObjects;
  2699. })();
  2700. /**
  2701. * Allows controlling of the rendering tasks.
  2702. * @class
  2703. */
  2704. var RenderTask = (function RenderTaskClosure() {
  2705. function RenderTask(internalRenderTask) {
  2706. this._internalRenderTask = internalRenderTask;
  2707. /**
  2708. * Callback for incremental rendering -- a function that will be called
  2709. * each time the rendering is paused. To continue rendering call the
  2710. * function that is the first argument to the callback.
  2711. * @type {function}
  2712. */
  2713. this.onContinue = null;
  2714. }
  2715. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2716. /**
  2717. * Promise for rendering task completion.
  2718. * @return {Promise}
  2719. */
  2720. get promise() {
  2721. return this._internalRenderTask.capability.promise;
  2722. },
  2723. /**
  2724. * Cancels the rendering task. If the task is currently rendering it will
  2725. * not be cancelled until graphics pauses with a timeout. The promise that
  2726. * this object extends will resolved when cancelled.
  2727. */
  2728. cancel: function RenderTask_cancel() {
  2729. this._internalRenderTask.cancel();
  2730. },
  2731. /**
  2732. * Registers callbacks to indicate the rendering task completion.
  2733. *
  2734. * @param {function} onFulfilled The callback for the rendering completion.
  2735. * @param {function} onRejected The callback for the rendering failure.
  2736. * @return {Promise} A promise that is resolved after the onFulfilled or
  2737. * onRejected callback.
  2738. */
  2739. then: function RenderTask_then(onFulfilled, onRejected) {
  2740. return this.promise.then.apply(this.promise, arguments);
  2741. }
  2742. };
  2743. return RenderTask;
  2744. })();
  2745. /**
  2746. * For internal use only.
  2747. * @ignore
  2748. */
  2749. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2750. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2751. pageNumber) {
  2752. this.callback = callback;
  2753. this.params = params;
  2754. this.objs = objs;
  2755. this.commonObjs = commonObjs;
  2756. this.operatorListIdx = null;
  2757. this.operatorList = operatorList;
  2758. this.pageNumber = pageNumber;
  2759. this.running = false;
  2760. this.graphicsReadyCallback = null;
  2761. this.graphicsReady = false;
  2762. this.cancelled = false;
  2763. this.capability = createPromiseCapability();
  2764. this.task = new RenderTask(this);
  2765. // caching this-bound methods
  2766. this._continueBound = this._continue.bind(this);
  2767. this._scheduleNextBound = this._scheduleNext.bind(this);
  2768. this._nextBound = this._next.bind(this);
  2769. }
  2770. InternalRenderTask.prototype = {
  2771. initalizeGraphics:
  2772. function InternalRenderTask_initalizeGraphics(transparency) {
  2773. if (this.cancelled) {
  2774. return;
  2775. }
  2776. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2777. globalScope.StepperManager.enabled) {
  2778. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2779. this.stepper.init(this.operatorList);
  2780. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2781. }
  2782. var params = this.params;
  2783. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2784. this.objs, params.imageLayer);
  2785. this.gfx.beginDrawing(params.viewport, transparency);
  2786. this.operatorListIdx = 0;
  2787. this.graphicsReady = true;
  2788. if (this.graphicsReadyCallback) {
  2789. this.graphicsReadyCallback();
  2790. }
  2791. },
  2792. cancel: function InternalRenderTask_cancel() {
  2793. this.running = false;
  2794. this.cancelled = true;
  2795. this.callback('cancelled');
  2796. },
  2797. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2798. if (!this.graphicsReady) {
  2799. if (!this.graphicsReadyCallback) {
  2800. this.graphicsReadyCallback = this._continueBound;
  2801. }
  2802. return;
  2803. }
  2804. if (this.stepper) {
  2805. this.stepper.updateOperatorList(this.operatorList);
  2806. }
  2807. if (this.running) {
  2808. return;
  2809. }
  2810. this._continue();
  2811. },
  2812. _continue: function InternalRenderTask__continue() {
  2813. this.running = true;
  2814. if (this.cancelled) {
  2815. return;
  2816. }
  2817. if (this.task.onContinue) {
  2818. this.task.onContinue.call(this.task, this._scheduleNextBound);
  2819. } else {
  2820. this._scheduleNext();
  2821. }
  2822. },
  2823. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2824. window.requestAnimationFrame(this._nextBound);
  2825. },
  2826. _next: function InternalRenderTask__next() {
  2827. if (this.cancelled) {
  2828. return;
  2829. }
  2830. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  2831. this.operatorListIdx,
  2832. this._continueBound,
  2833. this.stepper);
  2834. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  2835. this.running = false;
  2836. if (this.operatorList.lastChunk) {
  2837. this.gfx.endDrawing();
  2838. this.callback();
  2839. }
  2840. }
  2841. }
  2842. };
  2843. return InternalRenderTask;
  2844. })();
  2845. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  2846. function fixMetadata(meta) {
  2847. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  2848. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  2849. function(code, d1, d2, d3) {
  2850. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  2851. });
  2852. var chars = '';
  2853. for (var i = 0; i < bytes.length; i += 2) {
  2854. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  2855. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  2856. code !== 38 && false ? String.fromCharCode(code) :
  2857. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  2858. }
  2859. return '>' + chars;
  2860. });
  2861. }
  2862. function Metadata(meta) {
  2863. if (typeof meta === 'string') {
  2864. // Ghostscript produces invalid metadata
  2865. meta = fixMetadata(meta);
  2866. var parser = new DOMParser();
  2867. meta = parser.parseFromString(meta, 'application/xml');
  2868. } else if (!(meta instanceof Document)) {
  2869. error('Metadata: Invalid metadata object');
  2870. }
  2871. this.metaDocument = meta;
  2872. this.metadata = {};
  2873. this.parse();
  2874. }
  2875. Metadata.prototype = {
  2876. parse: function Metadata_parse() {
  2877. var doc = this.metaDocument;
  2878. var rdf = doc.documentElement;
  2879. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  2880. rdf = rdf.firstChild;
  2881. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  2882. rdf = rdf.nextSibling;
  2883. }
  2884. }
  2885. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  2886. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  2887. return;
  2888. }
  2889. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  2890. for (i = 0, length = children.length; i < length; i++) {
  2891. desc = children[i];
  2892. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  2893. continue;
  2894. }
  2895. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  2896. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  2897. entry = desc.childNodes[ii];
  2898. name = entry.nodeName.toLowerCase();
  2899. this.metadata[name] = entry.textContent.trim();
  2900. }
  2901. }
  2902. }
  2903. },
  2904. get: function Metadata_get(name) {
  2905. return this.metadata[name] || null;
  2906. },
  2907. has: function Metadata_has(name) {
  2908. return typeof this.metadata[name] !== 'undefined';
  2909. }
  2910. };
  2911. return Metadata;
  2912. })();
  2913. // <canvas> contexts store most of the state we need natively.
  2914. // However, PDF needs a bit more state, which we store here.
  2915. // Minimal font size that would be used during canvas fillText operations.
  2916. var MIN_FONT_SIZE = 16;
  2917. // Maximum font size that would be used during canvas fillText operations.
  2918. var MAX_FONT_SIZE = 100;
  2919. var MAX_GROUP_SIZE = 4096;
  2920. // Heuristic value used when enforcing minimum line widths.
  2921. var MIN_WIDTH_FACTOR = 0.65;
  2922. var COMPILE_TYPE3_GLYPHS = true;
  2923. var MAX_SIZE_TO_COMPILE = 1000;
  2924. var FULL_CHUNK_HEIGHT = 16;
  2925. function createScratchCanvas(width, height) {
  2926. var canvas = document.createElement('canvas');
  2927. canvas.width = width;
  2928. canvas.height = height;
  2929. return canvas;
  2930. }
  2931. function addContextCurrentTransform(ctx) {
  2932. // If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
  2933. if (!ctx.mozCurrentTransform) {
  2934. // Store the original context
  2935. ctx._scaleX = ctx._scaleX || 1.0;
  2936. ctx._scaleY = ctx._scaleY || 1.0;
  2937. ctx._originalSave = ctx.save;
  2938. ctx._originalRestore = ctx.restore;
  2939. ctx._originalRotate = ctx.rotate;
  2940. ctx._originalScale = ctx.scale;
  2941. ctx._originalTranslate = ctx.translate;
  2942. ctx._originalTransform = ctx.transform;
  2943. ctx._originalSetTransform = ctx.setTransform;
  2944. ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
  2945. ctx._transformStack = [];
  2946. Object.defineProperty(ctx, 'mozCurrentTransform', {
  2947. get: function getCurrentTransform() {
  2948. return this._transformMatrix;
  2949. }
  2950. });
  2951. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  2952. get: function getCurrentTransformInverse() {
  2953. // Calculation done using WolframAlpha:
  2954. // http://www.wolframalpha.com/input/?
  2955. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  2956. var m = this._transformMatrix;
  2957. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  2958. var ad_bc = a * d - b * c;
  2959. var bc_ad = b * c - a * d;
  2960. return [
  2961. d / ad_bc,
  2962. b / bc_ad,
  2963. c / bc_ad,
  2964. a / ad_bc,
  2965. (d * e - c * f) / bc_ad,
  2966. (b * e - a * f) / ad_bc
  2967. ];
  2968. }
  2969. });
  2970. ctx.save = function ctxSave() {
  2971. var old = this._transformMatrix;
  2972. this._transformStack.push(old);
  2973. this._transformMatrix = old.slice(0, 6);
  2974. this._originalSave();
  2975. };
  2976. ctx.restore = function ctxRestore() {
  2977. var prev = this._transformStack.pop();
  2978. if (prev) {
  2979. this._transformMatrix = prev;
  2980. this._originalRestore();
  2981. }
  2982. };
  2983. ctx.translate = function ctxTranslate(x, y) {
  2984. var m = this._transformMatrix;
  2985. m[4] = m[0] * x + m[2] * y + m[4];
  2986. m[5] = m[1] * x + m[3] * y + m[5];
  2987. this._originalTranslate(x, y);
  2988. };
  2989. ctx.scale = function ctxScale(x, y) {
  2990. var m = this._transformMatrix;
  2991. m[0] = m[0] * x;
  2992. m[1] = m[1] * x;
  2993. m[2] = m[2] * y;
  2994. m[3] = m[3] * y;
  2995. this._originalScale(x, y);
  2996. };
  2997. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  2998. var m = this._transformMatrix;
  2999. this._transformMatrix = [
  3000. m[0] * a + m[2] * b,
  3001. m[1] * a + m[3] * b,
  3002. m[0] * c + m[2] * d,
  3003. m[1] * c + m[3] * d,
  3004. m[0] * e + m[2] * f + m[4],
  3005. m[1] * e + m[3] * f + m[5]
  3006. ];
  3007. ctx._originalTransform(a, b, c, d, e, f);
  3008. };
  3009. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3010. this._transformMatrix = [a, b, c, d, e, f];
  3011. ctx._originalSetTransform(a, b, c, d, e, f);
  3012. };
  3013. ctx.rotate = function ctxRotate(angle) {
  3014. var cosValue = Math.cos(angle);
  3015. var sinValue = Math.sin(angle);
  3016. var m = this._transformMatrix;
  3017. this._transformMatrix = [
  3018. m[0] * cosValue + m[2] * sinValue,
  3019. m[1] * cosValue + m[3] * sinValue,
  3020. m[0] * (-sinValue) + m[2] * cosValue,
  3021. m[1] * (-sinValue) + m[3] * cosValue,
  3022. m[4],
  3023. m[5]
  3024. ];
  3025. this._originalRotate(angle);
  3026. };
  3027. }
  3028. }
  3029. var CachedCanvases = (function CachedCanvasesClosure() {
  3030. var cache = {};
  3031. return {
  3032. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3033. trackTransform) {
  3034. var canvasEntry;
  3035. if (cache[id] !== undefined) {
  3036. canvasEntry = cache[id];
  3037. canvasEntry.canvas.width = width;
  3038. canvasEntry.canvas.height = height;
  3039. // reset canvas transform for emulated mozCurrentTransform, if needed
  3040. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3041. } else {
  3042. var canvas = createScratchCanvas(width, height);
  3043. var ctx = canvas.getContext('2d');
  3044. if (trackTransform) {
  3045. addContextCurrentTransform(ctx);
  3046. }
  3047. cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3048. }
  3049. return canvasEntry;
  3050. },
  3051. clear: function () {
  3052. for (var id in cache) {
  3053. var canvasEntry = cache[id];
  3054. // Zeroing the width and height causes Firefox to release graphics
  3055. // resources immediately, which can greatly reduce memory consumption.
  3056. canvasEntry.canvas.width = 0;
  3057. canvasEntry.canvas.height = 0;
  3058. delete cache[id];
  3059. }
  3060. }
  3061. };
  3062. })();
  3063. function compileType3Glyph(imgData) {
  3064. var POINT_TO_PROCESS_LIMIT = 1000;
  3065. var width = imgData.width, height = imgData.height;
  3066. var i, j, j0, width1 = width + 1;
  3067. var points = new Uint8Array(width1 * (height + 1));
  3068. var POINT_TYPES =
  3069. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3070. // decodes bit-packed mask data
  3071. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3072. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3073. for (i = 0, ii = data0.length; i < ii; i++) {
  3074. var mask = 128, elem = data0[i];
  3075. while (mask > 0) {
  3076. data[pos++] = (elem & mask) ? 0 : 255;
  3077. mask >>= 1;
  3078. }
  3079. }
  3080. // finding iteresting points: every point is located between mask pixels,
  3081. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3082. // will have flags assigned based on neighboring mask pixels:
  3083. // 4 | 8
  3084. // --P--
  3085. // 2 | 1
  3086. // We are interested only in points with the flags:
  3087. // - outside corners: 1, 2, 4, 8;
  3088. // - inside corners: 7, 11, 13, 14;
  3089. // - and, intersections: 5, 10.
  3090. var count = 0;
  3091. pos = 0;
  3092. if (data[pos] !== 0) {
  3093. points[0] = 1;
  3094. ++count;
  3095. }
  3096. for (j = 1; j < width; j++) {
  3097. if (data[pos] !== data[pos + 1]) {
  3098. points[j] = data[pos] ? 2 : 1;
  3099. ++count;
  3100. }
  3101. pos++;
  3102. }
  3103. if (data[pos] !== 0) {
  3104. points[j] = 2;
  3105. ++count;
  3106. }
  3107. for (i = 1; i < height; i++) {
  3108. pos = i * lineSize;
  3109. j0 = i * width1;
  3110. if (data[pos - lineSize] !== data[pos]) {
  3111. points[j0] = data[pos] ? 1 : 8;
  3112. ++count;
  3113. }
  3114. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3115. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3116. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3117. for (j = 1; j < width; j++) {
  3118. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3119. (data[pos - lineSize + 1] ? 8 : 0);
  3120. if (POINT_TYPES[sum]) {
  3121. points[j0 + j] = POINT_TYPES[sum];
  3122. ++count;
  3123. }
  3124. pos++;
  3125. }
  3126. if (data[pos - lineSize] !== data[pos]) {
  3127. points[j0 + j] = data[pos] ? 2 : 4;
  3128. ++count;
  3129. }
  3130. if (count > POINT_TO_PROCESS_LIMIT) {
  3131. return null;
  3132. }
  3133. }
  3134. pos = lineSize * (height - 1);
  3135. j0 = i * width1;
  3136. if (data[pos] !== 0) {
  3137. points[j0] = 8;
  3138. ++count;
  3139. }
  3140. for (j = 1; j < width; j++) {
  3141. if (data[pos] !== data[pos + 1]) {
  3142. points[j0 + j] = data[pos] ? 4 : 8;
  3143. ++count;
  3144. }
  3145. pos++;
  3146. }
  3147. if (data[pos] !== 0) {
  3148. points[j0 + j] = 4;
  3149. ++count;
  3150. }
  3151. if (count > POINT_TO_PROCESS_LIMIT) {
  3152. return null;
  3153. }
  3154. // building outlines
  3155. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3156. var outlines = [];
  3157. for (i = 0; count && i <= height; i++) {
  3158. var p = i * width1;
  3159. var end = p + width;
  3160. while (p < end && !points[p]) {
  3161. p++;
  3162. }
  3163. if (p === end) {
  3164. continue;
  3165. }
  3166. var coords = [p % width1, i];
  3167. var type = points[p], p0 = p, pp;
  3168. do {
  3169. var step = steps[type];
  3170. do {
  3171. p += step;
  3172. } while (!points[p]);
  3173. pp = points[p];
  3174. if (pp !== 5 && pp !== 10) {
  3175. // set new direction
  3176. type = pp;
  3177. // delete mark
  3178. points[p] = 0;
  3179. } else { // type is 5 or 10, ie, a crossing
  3180. // set new direction
  3181. type = pp & ((0x33 * type) >> 4);
  3182. // set new type for "future hit"
  3183. points[p] &= (type >> 2 | type << 2);
  3184. }
  3185. coords.push(p % width1);
  3186. coords.push((p / width1) | 0);
  3187. --count;
  3188. } while (p0 !== p);
  3189. outlines.push(coords);
  3190. --i;
  3191. }
  3192. var drawOutline = function(c) {
  3193. c.save();
  3194. // the path shall be painted in [0..1]x[0..1] space
  3195. c.scale(1 / width, -1 / height);
  3196. c.translate(0, -height);
  3197. c.beginPath();
  3198. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3199. var o = outlines[i];
  3200. c.moveTo(o[0], o[1]);
  3201. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3202. c.lineTo(o[j], o[j+1]);
  3203. }
  3204. }
  3205. c.fill();
  3206. c.beginPath();
  3207. c.restore();
  3208. };
  3209. return drawOutline;
  3210. }
  3211. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3212. function CanvasExtraState(old) {
  3213. // Are soft masks and alpha values shapes or opacities?
  3214. this.alphaIsShape = false;
  3215. this.fontSize = 0;
  3216. this.fontSizeScale = 1;
  3217. this.textMatrix = IDENTITY_MATRIX;
  3218. this.textMatrixScale = 1;
  3219. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3220. this.leading = 0;
  3221. // Current point (in user coordinates)
  3222. this.x = 0;
  3223. this.y = 0;
  3224. // Start of text line (in text coordinates)
  3225. this.lineX = 0;
  3226. this.lineY = 0;
  3227. // Character and word spacing
  3228. this.charSpacing = 0;
  3229. this.wordSpacing = 0;
  3230. this.textHScale = 1;
  3231. this.textRenderingMode = TextRenderingMode.FILL;
  3232. this.textRise = 0;
  3233. // Default fore and background colors
  3234. this.fillColor = '#000000';
  3235. this.strokeColor = '#000000';
  3236. this.patternFill = false;
  3237. // Note: fill alpha applies to all non-stroking operations
  3238. this.fillAlpha = 1;
  3239. this.strokeAlpha = 1;
  3240. this.lineWidth = 1;
  3241. this.activeSMask = null; // nonclonable field (see the save method below)
  3242. this.old = old;
  3243. }
  3244. CanvasExtraState.prototype = {
  3245. clone: function CanvasExtraState_clone() {
  3246. return Object.create(this);
  3247. },
  3248. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3249. this.x = x;
  3250. this.y = y;
  3251. }
  3252. };
  3253. return CanvasExtraState;
  3254. })();
  3255. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3256. // Defines the time the executeOperatorList is going to be executing
  3257. // before it stops and shedules a continue of execution.
  3258. var EXECUTION_TIME = 15;
  3259. // Defines the number of steps before checking the execution time
  3260. var EXECUTION_STEPS = 10;
  3261. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3262. this.ctx = canvasCtx;
  3263. this.current = new CanvasExtraState();
  3264. this.stateStack = [];
  3265. this.pendingClip = null;
  3266. this.pendingEOFill = false;
  3267. this.res = null;
  3268. this.xobjs = null;
  3269. this.commonObjs = commonObjs;
  3270. this.objs = objs;
  3271. this.imageLayer = imageLayer;
  3272. this.groupStack = [];
  3273. this.processingType3 = null;
  3274. // Patterns are painted relative to the initial page/form transform, see pdf
  3275. // spec 8.7.2 NOTE 1.
  3276. this.baseTransform = null;
  3277. this.baseTransformStack = [];
  3278. this.groupLevel = 0;
  3279. this.smaskStack = [];
  3280. this.smaskCounter = 0;
  3281. this.tempSMask = null;
  3282. if (canvasCtx) {
  3283. addContextCurrentTransform(canvasCtx);
  3284. }
  3285. this.cachedGetSinglePixelWidth = null;
  3286. }
  3287. function putBinaryImageData(ctx, imgData) {
  3288. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3289. ctx.putImageData(imgData, 0, 0);
  3290. return;
  3291. }
  3292. // Put the image data to the canvas in chunks, rather than putting the
  3293. // whole image at once. This saves JS memory, because the ImageData object
  3294. // is smaller. It also possibly saves C++ memory within the implementation
  3295. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3296. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3297. // because too many putImageData() calls will slow things down.
  3298. //
  3299. // Note: as written, if the last chunk is partial, the putImageData() call
  3300. // will (conceptually) put pixels past the bounds of the canvas. But
  3301. // that's ok; any such pixels are ignored.
  3302. var height = imgData.height, width = imgData.width;
  3303. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3304. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3305. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3306. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3307. var srcPos = 0, destPos;
  3308. var src = imgData.data;
  3309. var dest = chunkImgData.data;
  3310. var i, j, thisChunkHeight, elemsInThisChunk;
  3311. // There are multiple forms in which the pixel data can be passed, and
  3312. // imgData.kind tells us which one this is.
  3313. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3314. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3315. var srcLength = src.byteLength;
  3316. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3317. new Uint32ArrayView(dest);
  3318. var dest32DataLength = dest32.length;
  3319. var fullSrcDiff = (width + 7) >> 3;
  3320. var white = 0xFFFFFFFF;
  3321. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3322. 0xFF000000 : 0x000000FF;
  3323. for (i = 0; i < totalChunks; i++) {
  3324. thisChunkHeight =
  3325. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3326. destPos = 0;
  3327. for (j = 0; j < thisChunkHeight; j++) {
  3328. var srcDiff = srcLength - srcPos;
  3329. var k = 0;
  3330. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3331. var kEndUnrolled = kEnd & ~7;
  3332. var mask = 0;
  3333. var srcByte = 0;
  3334. for (; k < kEndUnrolled; k += 8) {
  3335. srcByte = src[srcPos++];
  3336. dest32[destPos++] = (srcByte & 128) ? white : black;
  3337. dest32[destPos++] = (srcByte & 64) ? white : black;
  3338. dest32[destPos++] = (srcByte & 32) ? white : black;
  3339. dest32[destPos++] = (srcByte & 16) ? white : black;
  3340. dest32[destPos++] = (srcByte & 8) ? white : black;
  3341. dest32[destPos++] = (srcByte & 4) ? white : black;
  3342. dest32[destPos++] = (srcByte & 2) ? white : black;
  3343. dest32[destPos++] = (srcByte & 1) ? white : black;
  3344. }
  3345. for (; k < kEnd; k++) {
  3346. if (mask === 0) {
  3347. srcByte = src[srcPos++];
  3348. mask = 128;
  3349. }
  3350. dest32[destPos++] = (srcByte & mask) ? white : black;
  3351. mask >>= 1;
  3352. }
  3353. }
  3354. // We ran out of input. Make all remaining pixels transparent.
  3355. while (destPos < dest32DataLength) {
  3356. dest32[destPos++] = 0;
  3357. }
  3358. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3359. }
  3360. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3361. // RGBA, 32-bits per pixel.
  3362. j = 0;
  3363. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  3364. for (i = 0; i < fullChunks; i++) {
  3365. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3366. srcPos += elemsInThisChunk;
  3367. ctx.putImageData(chunkImgData, 0, j);
  3368. j += FULL_CHUNK_HEIGHT;
  3369. }
  3370. if (i < totalChunks) {
  3371. elemsInThisChunk = width * partialChunkHeight * 4;
  3372. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3373. ctx.putImageData(chunkImgData, 0, j);
  3374. }
  3375. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3376. // RGB, 24-bits per pixel.
  3377. thisChunkHeight = FULL_CHUNK_HEIGHT;
  3378. elemsInThisChunk = width * thisChunkHeight;
  3379. for (i = 0; i < totalChunks; i++) {
  3380. if (i >= fullChunks) {
  3381. thisChunkHeight = partialChunkHeight;
  3382. elemsInThisChunk = width * thisChunkHeight;
  3383. }
  3384. destPos = 0;
  3385. for (j = elemsInThisChunk; j--;) {
  3386. dest[destPos++] = src[srcPos++];
  3387. dest[destPos++] = src[srcPos++];
  3388. dest[destPos++] = src[srcPos++];
  3389. dest[destPos++] = 255;
  3390. }
  3391. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3392. }
  3393. } else {
  3394. error('bad image kind: ' + imgData.kind);
  3395. }
  3396. }
  3397. function putBinaryImageMask(ctx, imgData) {
  3398. var height = imgData.height, width = imgData.width;
  3399. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3400. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3401. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3402. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3403. var srcPos = 0;
  3404. var src = imgData.data;
  3405. var dest = chunkImgData.data;
  3406. for (var i = 0; i < totalChunks; i++) {
  3407. var thisChunkHeight =
  3408. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3409. // Expand the mask so it can be used by the canvas. Any required
  3410. // inversion has already been handled.
  3411. var destPos = 3; // alpha component offset
  3412. for (var j = 0; j < thisChunkHeight; j++) {
  3413. var mask = 0;
  3414. for (var k = 0; k < width; k++) {
  3415. if (!mask) {
  3416. var elem = src[srcPos++];
  3417. mask = 128;
  3418. }
  3419. dest[destPos] = (elem & mask) ? 0 : 255;
  3420. destPos += 4;
  3421. mask >>= 1;
  3422. }
  3423. }
  3424. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3425. }
  3426. }
  3427. function copyCtxState(sourceCtx, destCtx) {
  3428. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3429. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3430. 'globalCompositeOperation', 'font'];
  3431. for (var i = 0, ii = properties.length; i < ii; i++) {
  3432. var property = properties[i];
  3433. if (sourceCtx[property] !== undefined) {
  3434. destCtx[property] = sourceCtx[property];
  3435. }
  3436. }
  3437. if (sourceCtx.setLineDash !== undefined) {
  3438. destCtx.setLineDash(sourceCtx.getLineDash());
  3439. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3440. } else if (sourceCtx.mozDashOffset !== undefined) {
  3441. destCtx.mozDash = sourceCtx.mozDash;
  3442. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3443. }
  3444. }
  3445. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3446. var length = bytes.length;
  3447. for (var i = 3; i < length; i += 4) {
  3448. var alpha = bytes[i];
  3449. if (alpha === 0) {
  3450. bytes[i - 3] = r0;
  3451. bytes[i - 2] = g0;
  3452. bytes[i - 1] = b0;
  3453. } else if (alpha < 255) {
  3454. var alpha_ = 255 - alpha;
  3455. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3456. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3457. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3458. }
  3459. }
  3460. }
  3461. function composeSMaskAlpha(maskData, layerData) {
  3462. var length = maskData.length;
  3463. var scale = 1 / 255;
  3464. for (var i = 3; i < length; i += 4) {
  3465. var alpha = maskData[i];
  3466. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3467. }
  3468. }
  3469. function composeSMaskLuminosity(maskData, layerData) {
  3470. var length = maskData.length;
  3471. for (var i = 3; i < length; i += 4) {
  3472. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3473. (maskData[i - 2] * 152) + // * 0.59 ....
  3474. (maskData[i - 1] * 28); // * 0.11 ....
  3475. layerData[i] = (layerData[i] * y) >> 16;
  3476. }
  3477. }
  3478. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3479. subtype, backdrop) {
  3480. var hasBackdrop = !!backdrop;
  3481. var r0 = hasBackdrop ? backdrop[0] : 0;
  3482. var g0 = hasBackdrop ? backdrop[1] : 0;
  3483. var b0 = hasBackdrop ? backdrop[2] : 0;
  3484. var composeFn;
  3485. if (subtype === 'Luminosity') {
  3486. composeFn = composeSMaskLuminosity;
  3487. } else {
  3488. composeFn = composeSMaskAlpha;
  3489. }
  3490. // processing image in chunks to save memory
  3491. var PIXELS_TO_PROCESS = 1048576;
  3492. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3493. for (var row = 0; row < height; row += chunkSize) {
  3494. var chunkHeight = Math.min(chunkSize, height - row);
  3495. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3496. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3497. if (hasBackdrop) {
  3498. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3499. }
  3500. composeFn(maskData.data, layerData.data);
  3501. maskCtx.putImageData(layerData, 0, row);
  3502. }
  3503. }
  3504. function composeSMask(ctx, smask, layerCtx) {
  3505. var mask = smask.canvas;
  3506. var maskCtx = smask.context;
  3507. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3508. smask.offsetX, smask.offsetY);
  3509. var backdrop = smask.backdrop || null;
  3510. if (WebGLUtils.isEnabled) {
  3511. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3512. {subtype: smask.subtype, backdrop: backdrop});
  3513. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3514. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3515. return;
  3516. }
  3517. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3518. smask.subtype, backdrop);
  3519. ctx.drawImage(mask, 0, 0);
  3520. }
  3521. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3522. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3523. var NORMAL_CLIP = {};
  3524. var EO_CLIP = {};
  3525. CanvasGraphics.prototype = {
  3526. beginDrawing: function CanvasGraphics_beginDrawing(viewport, transparency) {
  3527. // For pdfs that use blend modes we have to clear the canvas else certain
  3528. // blend modes can look wrong since we'd be blending with a white
  3529. // backdrop. The problem with a transparent backdrop though is we then
  3530. // don't get sub pixel anti aliasing on text, so we fill with white if
  3531. // we can.
  3532. var width = this.ctx.canvas.width;
  3533. var height = this.ctx.canvas.height;
  3534. if (transparency) {
  3535. this.ctx.clearRect(0, 0, width, height);
  3536. } else {
  3537. this.ctx.mozOpaque = true;
  3538. this.ctx.save();
  3539. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3540. this.ctx.fillRect(0, 0, width, height);
  3541. this.ctx.restore();
  3542. }
  3543. var transform = viewport.transform;
  3544. this.ctx.save();
  3545. this.ctx.transform.apply(this.ctx, transform);
  3546. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3547. if (this.imageLayer) {
  3548. this.imageLayer.beginLayout();
  3549. }
  3550. },
  3551. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3552. operatorList,
  3553. executionStartIdx, continueCallback,
  3554. stepper) {
  3555. var argsArray = operatorList.argsArray;
  3556. var fnArray = operatorList.fnArray;
  3557. var i = executionStartIdx || 0;
  3558. var argsArrayLen = argsArray.length;
  3559. // Sometimes the OperatorList to execute is empty.
  3560. if (argsArrayLen === i) {
  3561. return i;
  3562. }
  3563. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3564. typeof continueCallback === 'function');
  3565. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3566. var steps = 0;
  3567. var commonObjs = this.commonObjs;
  3568. var objs = this.objs;
  3569. var fnId;
  3570. while (true) {
  3571. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3572. stepper.breakIt(i, continueCallback);
  3573. return i;
  3574. }
  3575. fnId = fnArray[i];
  3576. if (fnId !== OPS.dependency) {
  3577. this[fnId].apply(this, argsArray[i]);
  3578. } else {
  3579. var deps = argsArray[i];
  3580. for (var n = 0, nn = deps.length; n < nn; n++) {
  3581. var depObjId = deps[n];
  3582. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3583. var objsPool = common ? commonObjs : objs;
  3584. // If the promise isn't resolved yet, add the continueCallback
  3585. // to the promise and bail out.
  3586. if (!objsPool.isResolved(depObjId)) {
  3587. objsPool.get(depObjId, continueCallback);
  3588. return i;
  3589. }
  3590. }
  3591. }
  3592. i++;
  3593. // If the entire operatorList was executed, stop as were done.
  3594. if (i === argsArrayLen) {
  3595. return i;
  3596. }
  3597. // If the execution took longer then a certain amount of time and
  3598. // `continueCallback` is specified, interrupt the execution.
  3599. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3600. if (Date.now() > endTime) {
  3601. continueCallback();
  3602. return i;
  3603. }
  3604. steps = 0;
  3605. }
  3606. // If the operatorList isn't executed completely yet OR the execution
  3607. // time was short enough, do another execution round.
  3608. }
  3609. },
  3610. endDrawing: function CanvasGraphics_endDrawing() {
  3611. this.ctx.restore();
  3612. CachedCanvases.clear();
  3613. WebGLUtils.clear();
  3614. if (this.imageLayer) {
  3615. this.imageLayer.endLayout();
  3616. }
  3617. },
  3618. // Graphics state
  3619. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3620. this.current.lineWidth = width;
  3621. this.ctx.lineWidth = width;
  3622. },
  3623. setLineCap: function CanvasGraphics_setLineCap(style) {
  3624. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3625. },
  3626. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3627. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3628. },
  3629. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3630. this.ctx.miterLimit = limit;
  3631. },
  3632. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3633. var ctx = this.ctx;
  3634. if (ctx.setLineDash !== undefined) {
  3635. ctx.setLineDash(dashArray);
  3636. ctx.lineDashOffset = dashPhase;
  3637. } else {
  3638. ctx.mozDash = dashArray;
  3639. ctx.mozDashOffset = dashPhase;
  3640. }
  3641. },
  3642. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3643. // Maybe if we one day fully support color spaces this will be important
  3644. // for now we can ignore.
  3645. // TODO set rendering intent?
  3646. },
  3647. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3648. // There's no way to control this with canvas, but we can safely ignore.
  3649. // TODO set flatness?
  3650. },
  3651. setGState: function CanvasGraphics_setGState(states) {
  3652. for (var i = 0, ii = states.length; i < ii; i++) {
  3653. var state = states[i];
  3654. var key = state[0];
  3655. var value = state[1];
  3656. switch (key) {
  3657. case 'LW':
  3658. this.setLineWidth(value);
  3659. break;
  3660. case 'LC':
  3661. this.setLineCap(value);
  3662. break;
  3663. case 'LJ':
  3664. this.setLineJoin(value);
  3665. break;
  3666. case 'ML':
  3667. this.setMiterLimit(value);
  3668. break;
  3669. case 'D':
  3670. this.setDash(value[0], value[1]);
  3671. break;
  3672. case 'RI':
  3673. this.setRenderingIntent(value);
  3674. break;
  3675. case 'FL':
  3676. this.setFlatness(value);
  3677. break;
  3678. case 'Font':
  3679. this.setFont(value[0], value[1]);
  3680. break;
  3681. case 'CA':
  3682. this.current.strokeAlpha = state[1];
  3683. break;
  3684. case 'ca':
  3685. this.current.fillAlpha = state[1];
  3686. this.ctx.globalAlpha = state[1];
  3687. break;
  3688. case 'BM':
  3689. if (value && value.name && (value.name !== 'Normal')) {
  3690. var mode = value.name.replace(/([A-Z])/g,
  3691. function(c) {
  3692. return '-' + c.toLowerCase();
  3693. }
  3694. ).substring(1);
  3695. this.ctx.globalCompositeOperation = mode;
  3696. if (this.ctx.globalCompositeOperation !== mode) {
  3697. warn('globalCompositeOperation "' + mode +
  3698. '" is not supported');
  3699. }
  3700. } else {
  3701. this.ctx.globalCompositeOperation = 'source-over';
  3702. }
  3703. break;
  3704. case 'SMask':
  3705. if (this.current.activeSMask) {
  3706. this.endSMaskGroup();
  3707. }
  3708. this.current.activeSMask = value ? this.tempSMask : null;
  3709. if (this.current.activeSMask) {
  3710. this.beginSMaskGroup();
  3711. }
  3712. this.tempSMask = null;
  3713. break;
  3714. }
  3715. }
  3716. },
  3717. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3718. var activeSMask = this.current.activeSMask;
  3719. var drawnWidth = activeSMask.canvas.width;
  3720. var drawnHeight = activeSMask.canvas.height;
  3721. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3722. var scratchCanvas = CachedCanvases.getCanvas(
  3723. cacheId, drawnWidth, drawnHeight, true);
  3724. var currentCtx = this.ctx;
  3725. var currentTransform = currentCtx.mozCurrentTransform;
  3726. this.ctx.save();
  3727. var groupCtx = scratchCanvas.context;
  3728. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3729. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3730. groupCtx.transform.apply(groupCtx, currentTransform);
  3731. copyCtxState(currentCtx, groupCtx);
  3732. this.ctx = groupCtx;
  3733. this.setGState([
  3734. ['BM', 'Normal'],
  3735. ['ca', 1],
  3736. ['CA', 1]
  3737. ]);
  3738. this.groupStack.push(currentCtx);
  3739. this.groupLevel++;
  3740. },
  3741. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3742. var groupCtx = this.ctx;
  3743. this.groupLevel--;
  3744. this.ctx = this.groupStack.pop();
  3745. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3746. this.ctx.restore();
  3747. },
  3748. save: function CanvasGraphics_save() {
  3749. this.ctx.save();
  3750. var old = this.current;
  3751. this.stateStack.push(old);
  3752. this.current = old.clone();
  3753. this.current.activeSMask = null;
  3754. },
  3755. restore: function CanvasGraphics_restore() {
  3756. if (this.stateStack.length !== 0) {
  3757. if (this.current.activeSMask !== null) {
  3758. this.endSMaskGroup();
  3759. }
  3760. this.current = this.stateStack.pop();
  3761. this.ctx.restore();
  3762. this.cachedGetSinglePixelWidth = null;
  3763. }
  3764. },
  3765. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3766. this.ctx.transform(a, b, c, d, e, f);
  3767. this.cachedGetSinglePixelWidth = null;
  3768. },
  3769. // Path
  3770. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3771. var ctx = this.ctx;
  3772. var current = this.current;
  3773. var x = current.x, y = current.y;
  3774. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3775. switch (ops[i] | 0) {
  3776. case OPS.rectangle:
  3777. x = args[j++];
  3778. y = args[j++];
  3779. var width = args[j++];
  3780. var height = args[j++];
  3781. if (width === 0) {
  3782. width = this.getSinglePixelWidth();
  3783. }
  3784. if (height === 0) {
  3785. height = this.getSinglePixelWidth();
  3786. }
  3787. var xw = x + width;
  3788. var yh = y + height;
  3789. this.ctx.moveTo(x, y);
  3790. this.ctx.lineTo(xw, y);
  3791. this.ctx.lineTo(xw, yh);
  3792. this.ctx.lineTo(x, yh);
  3793. this.ctx.lineTo(x, y);
  3794. this.ctx.closePath();
  3795. break;
  3796. case OPS.moveTo:
  3797. x = args[j++];
  3798. y = args[j++];
  3799. ctx.moveTo(x, y);
  3800. break;
  3801. case OPS.lineTo:
  3802. x = args[j++];
  3803. y = args[j++];
  3804. ctx.lineTo(x, y);
  3805. break;
  3806. case OPS.curveTo:
  3807. x = args[j + 4];
  3808. y = args[j + 5];
  3809. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  3810. x, y);
  3811. j += 6;
  3812. break;
  3813. case OPS.curveTo2:
  3814. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  3815. args[j + 2], args[j + 3]);
  3816. x = args[j + 2];
  3817. y = args[j + 3];
  3818. j += 4;
  3819. break;
  3820. case OPS.curveTo3:
  3821. x = args[j + 2];
  3822. y = args[j + 3];
  3823. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  3824. j += 4;
  3825. break;
  3826. case OPS.closePath:
  3827. ctx.closePath();
  3828. break;
  3829. }
  3830. }
  3831. current.setCurrentPoint(x, y);
  3832. },
  3833. closePath: function CanvasGraphics_closePath() {
  3834. this.ctx.closePath();
  3835. },
  3836. stroke: function CanvasGraphics_stroke(consumePath) {
  3837. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3838. var ctx = this.ctx;
  3839. var strokeColor = this.current.strokeColor;
  3840. // Prevent drawing too thin lines by enforcing a minimum line width.
  3841. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  3842. this.current.lineWidth);
  3843. // For stroke we want to temporarily change the global alpha to the
  3844. // stroking alpha.
  3845. ctx.globalAlpha = this.current.strokeAlpha;
  3846. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  3847. strokeColor.type === 'Pattern') {
  3848. // for patterns, we transform to pattern space, calculate
  3849. // the pattern, call stroke, and restore to user space
  3850. ctx.save();
  3851. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  3852. ctx.stroke();
  3853. ctx.restore();
  3854. } else {
  3855. ctx.stroke();
  3856. }
  3857. if (consumePath) {
  3858. this.consumePath();
  3859. }
  3860. // Restore the global alpha to the fill alpha
  3861. ctx.globalAlpha = this.current.fillAlpha;
  3862. },
  3863. closeStroke: function CanvasGraphics_closeStroke() {
  3864. this.closePath();
  3865. this.stroke();
  3866. },
  3867. fill: function CanvasGraphics_fill(consumePath) {
  3868. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  3869. var ctx = this.ctx;
  3870. var fillColor = this.current.fillColor;
  3871. var isPatternFill = this.current.patternFill;
  3872. var needRestore = false;
  3873. if (isPatternFill) {
  3874. ctx.save();
  3875. ctx.fillStyle = fillColor.getPattern(ctx, this);
  3876. needRestore = true;
  3877. }
  3878. if (this.pendingEOFill) {
  3879. if (ctx.mozFillRule !== undefined) {
  3880. ctx.mozFillRule = 'evenodd';
  3881. ctx.fill();
  3882. ctx.mozFillRule = 'nonzero';
  3883. } else {
  3884. try {
  3885. ctx.fill('evenodd');
  3886. } catch (ex) {
  3887. // shouldn't really happen, but browsers might think differently
  3888. ctx.fill();
  3889. }
  3890. }
  3891. this.pendingEOFill = false;
  3892. } else {
  3893. ctx.fill();
  3894. }
  3895. if (needRestore) {
  3896. ctx.restore();
  3897. }
  3898. if (consumePath) {
  3899. this.consumePath();
  3900. }
  3901. },
  3902. eoFill: function CanvasGraphics_eoFill() {
  3903. this.pendingEOFill = true;
  3904. this.fill();
  3905. },
  3906. fillStroke: function CanvasGraphics_fillStroke() {
  3907. this.fill(false);
  3908. this.stroke(false);
  3909. this.consumePath();
  3910. },
  3911. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  3912. this.pendingEOFill = true;
  3913. this.fillStroke();
  3914. },
  3915. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  3916. this.closePath();
  3917. this.fillStroke();
  3918. },
  3919. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  3920. this.pendingEOFill = true;
  3921. this.closePath();
  3922. this.fillStroke();
  3923. },
  3924. endPath: function CanvasGraphics_endPath() {
  3925. this.consumePath();
  3926. },
  3927. // Clipping
  3928. clip: function CanvasGraphics_clip() {
  3929. this.pendingClip = NORMAL_CLIP;
  3930. },
  3931. eoClip: function CanvasGraphics_eoClip() {
  3932. this.pendingClip = EO_CLIP;
  3933. },
  3934. // Text
  3935. beginText: function CanvasGraphics_beginText() {
  3936. this.current.textMatrix = IDENTITY_MATRIX;
  3937. this.current.textMatrixScale = 1;
  3938. this.current.x = this.current.lineX = 0;
  3939. this.current.y = this.current.lineY = 0;
  3940. },
  3941. endText: function CanvasGraphics_endText() {
  3942. var paths = this.pendingTextPaths;
  3943. var ctx = this.ctx;
  3944. if (paths === undefined) {
  3945. ctx.beginPath();
  3946. return;
  3947. }
  3948. ctx.save();
  3949. ctx.beginPath();
  3950. for (var i = 0; i < paths.length; i++) {
  3951. var path = paths[i];
  3952. ctx.setTransform.apply(ctx, path.transform);
  3953. ctx.translate(path.x, path.y);
  3954. path.addToPath(ctx, path.fontSize);
  3955. }
  3956. ctx.restore();
  3957. ctx.clip();
  3958. ctx.beginPath();
  3959. delete this.pendingTextPaths;
  3960. },
  3961. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  3962. this.current.charSpacing = spacing;
  3963. },
  3964. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  3965. this.current.wordSpacing = spacing;
  3966. },
  3967. setHScale: function CanvasGraphics_setHScale(scale) {
  3968. this.current.textHScale = scale / 100;
  3969. },
  3970. setLeading: function CanvasGraphics_setLeading(leading) {
  3971. this.current.leading = -leading;
  3972. },
  3973. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  3974. var fontObj = this.commonObjs.get(fontRefName);
  3975. var current = this.current;
  3976. if (!fontObj) {
  3977. error('Can\'t find font for ' + fontRefName);
  3978. }
  3979. current.fontMatrix = (fontObj.fontMatrix ?
  3980. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  3981. // A valid matrix needs all main diagonal elements to be non-zero
  3982. // This also ensures we bypass FF bugzilla bug #719844.
  3983. if (current.fontMatrix[0] === 0 ||
  3984. current.fontMatrix[3] === 0) {
  3985. warn('Invalid font matrix for font ' + fontRefName);
  3986. }
  3987. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  3988. // and in some docs this can be negative (inverted x-y axes).
  3989. if (size < 0) {
  3990. size = -size;
  3991. current.fontDirection = -1;
  3992. } else {
  3993. current.fontDirection = 1;
  3994. }
  3995. this.current.font = fontObj;
  3996. this.current.fontSize = size;
  3997. if (fontObj.isType3Font) {
  3998. return; // we don't need ctx.font for Type3 fonts
  3999. }
  4000. var name = fontObj.loadedName || 'sans-serif';
  4001. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  4002. (fontObj.bold ? 'bold' : 'normal');
  4003. var italic = fontObj.italic ? 'italic' : 'normal';
  4004. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4005. // Some font backends cannot handle fonts below certain size.
  4006. // Keeping the font at minimal size and using the fontSizeScale to change
  4007. // the current transformation matrix before the fillText/strokeText.
  4008. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4009. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4010. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4011. this.current.fontSizeScale = size / browserFontSize;
  4012. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4013. this.ctx.font = rule;
  4014. },
  4015. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4016. this.current.textRenderingMode = mode;
  4017. },
  4018. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4019. this.current.textRise = rise;
  4020. },
  4021. moveText: function CanvasGraphics_moveText(x, y) {
  4022. this.current.x = this.current.lineX += x;
  4023. this.current.y = this.current.lineY += y;
  4024. },
  4025. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4026. this.setLeading(-y);
  4027. this.moveText(x, y);
  4028. },
  4029. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4030. this.current.textMatrix = [a, b, c, d, e, f];
  4031. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4032. this.current.x = this.current.lineX = 0;
  4033. this.current.y = this.current.lineY = 0;
  4034. },
  4035. nextLine: function CanvasGraphics_nextLine() {
  4036. this.moveText(0, this.current.leading);
  4037. },
  4038. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4039. var ctx = this.ctx;
  4040. var current = this.current;
  4041. var font = current.font;
  4042. var textRenderingMode = current.textRenderingMode;
  4043. var fontSize = current.fontSize / current.fontSizeScale;
  4044. var fillStrokeMode = textRenderingMode &
  4045. TextRenderingMode.FILL_STROKE_MASK;
  4046. var isAddToPathSet = !!(textRenderingMode &
  4047. TextRenderingMode.ADD_TO_PATH_FLAG);
  4048. var addToPath;
  4049. if (font.disableFontFace || isAddToPathSet) {
  4050. addToPath = font.getPathGenerator(this.commonObjs, character);
  4051. }
  4052. if (font.disableFontFace) {
  4053. ctx.save();
  4054. ctx.translate(x, y);
  4055. ctx.beginPath();
  4056. addToPath(ctx, fontSize);
  4057. if (fillStrokeMode === TextRenderingMode.FILL ||
  4058. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4059. ctx.fill();
  4060. }
  4061. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4062. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4063. ctx.stroke();
  4064. }
  4065. ctx.restore();
  4066. } else {
  4067. if (fillStrokeMode === TextRenderingMode.FILL ||
  4068. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4069. ctx.fillText(character, x, y);
  4070. }
  4071. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4072. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4073. ctx.strokeText(character, x, y);
  4074. }
  4075. }
  4076. if (isAddToPathSet) {
  4077. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4078. paths.push({
  4079. transform: ctx.mozCurrentTransform,
  4080. x: x,
  4081. y: y,
  4082. fontSize: fontSize,
  4083. addToPath: addToPath
  4084. });
  4085. }
  4086. },
  4087. get isFontSubpixelAAEnabled() {
  4088. // Checks if anti-aliasing is enabled when scaled text is painted.
  4089. // On Windows GDI scaled fonts looks bad.
  4090. var ctx = document.createElement('canvas').getContext('2d');
  4091. ctx.scale(1.5, 1);
  4092. ctx.fillText('I', 0, 10);
  4093. var data = ctx.getImageData(0, 0, 10, 10).data;
  4094. var enabled = false;
  4095. for (var i = 3; i < data.length; i += 4) {
  4096. if (data[i] > 0 && data[i] < 255) {
  4097. enabled = true;
  4098. break;
  4099. }
  4100. }
  4101. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4102. },
  4103. showText: function CanvasGraphics_showText(glyphs) {
  4104. var current = this.current;
  4105. var font = current.font;
  4106. if (font.isType3Font) {
  4107. return this.showType3Text(glyphs);
  4108. }
  4109. var fontSize = current.fontSize;
  4110. if (fontSize === 0) {
  4111. return;
  4112. }
  4113. var ctx = this.ctx;
  4114. var fontSizeScale = current.fontSizeScale;
  4115. var charSpacing = current.charSpacing;
  4116. var wordSpacing = current.wordSpacing;
  4117. var fontDirection = current.fontDirection;
  4118. var textHScale = current.textHScale * fontDirection;
  4119. var glyphsLength = glyphs.length;
  4120. var vertical = font.vertical;
  4121. var defaultVMetrics = font.defaultVMetrics;
  4122. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4123. var simpleFillText =
  4124. current.textRenderingMode === TextRenderingMode.FILL &&
  4125. !font.disableFontFace;
  4126. ctx.save();
  4127. ctx.transform.apply(ctx, current.textMatrix);
  4128. ctx.translate(current.x, current.y + current.textRise);
  4129. if (fontDirection > 0) {
  4130. ctx.scale(textHScale, -1);
  4131. } else {
  4132. ctx.scale(textHScale, 1);
  4133. }
  4134. var lineWidth = current.lineWidth;
  4135. var scale = current.textMatrixScale;
  4136. if (scale === 0 || lineWidth === 0) {
  4137. var fillStrokeMode = current.textRenderingMode &
  4138. TextRenderingMode.FILL_STROKE_MASK;
  4139. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4140. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4141. this.cachedGetSinglePixelWidth = null;
  4142. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4143. }
  4144. } else {
  4145. lineWidth /= scale;
  4146. }
  4147. if (fontSizeScale !== 1.0) {
  4148. ctx.scale(fontSizeScale, fontSizeScale);
  4149. lineWidth /= fontSizeScale;
  4150. }
  4151. ctx.lineWidth = lineWidth;
  4152. var x = 0, i;
  4153. for (i = 0; i < glyphsLength; ++i) {
  4154. var glyph = glyphs[i];
  4155. if (glyph === null) {
  4156. // word break
  4157. x += fontDirection * wordSpacing;
  4158. continue;
  4159. } else if (isNum(glyph)) {
  4160. x += -glyph * fontSize * 0.001;
  4161. continue;
  4162. }
  4163. var restoreNeeded = false;
  4164. var character = glyph.fontChar;
  4165. var accent = glyph.accent;
  4166. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4167. var width = glyph.width;
  4168. if (vertical) {
  4169. var vmetric, vx, vy;
  4170. vmetric = glyph.vmetric || defaultVMetrics;
  4171. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4172. vx = -vx * widthAdvanceScale;
  4173. vy = vmetric[2] * widthAdvanceScale;
  4174. width = vmetric ? -vmetric[0] : width;
  4175. scaledX = vx / fontSizeScale;
  4176. scaledY = (x + vy) / fontSizeScale;
  4177. } else {
  4178. scaledX = x / fontSizeScale;
  4179. scaledY = 0;
  4180. }
  4181. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  4182. // some standard fonts may not have the exact width, trying to
  4183. // rescale per character
  4184. var measuredWidth = ctx.measureText(character).width * 1000 /
  4185. fontSize * fontSizeScale;
  4186. var characterScaleX = width / measuredWidth;
  4187. restoreNeeded = true;
  4188. ctx.save();
  4189. ctx.scale(characterScaleX, 1);
  4190. scaledX /= characterScaleX;
  4191. }
  4192. if (simpleFillText && !accent) {
  4193. // common case
  4194. ctx.fillText(character, scaledX, scaledY);
  4195. } else {
  4196. this.paintChar(character, scaledX, scaledY);
  4197. if (accent) {
  4198. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4199. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4200. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4201. }
  4202. }
  4203. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  4204. x += charWidth;
  4205. if (restoreNeeded) {
  4206. ctx.restore();
  4207. }
  4208. }
  4209. if (vertical) {
  4210. current.y -= x * textHScale;
  4211. } else {
  4212. current.x += x * textHScale;
  4213. }
  4214. ctx.restore();
  4215. },
  4216. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4217. // Type3 fonts - each glyph is a "mini-PDF"
  4218. var ctx = this.ctx;
  4219. var current = this.current;
  4220. var font = current.font;
  4221. var fontSize = current.fontSize;
  4222. var fontDirection = current.fontDirection;
  4223. var charSpacing = current.charSpacing;
  4224. var wordSpacing = current.wordSpacing;
  4225. var textHScale = current.textHScale * fontDirection;
  4226. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4227. var glyphsLength = glyphs.length;
  4228. var isTextInvisible =
  4229. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4230. var i, glyph, width;
  4231. if (isTextInvisible || fontSize === 0) {
  4232. return;
  4233. }
  4234. ctx.save();
  4235. ctx.transform.apply(ctx, current.textMatrix);
  4236. ctx.translate(current.x, current.y);
  4237. ctx.scale(textHScale, fontDirection);
  4238. for (i = 0; i < glyphsLength; ++i) {
  4239. glyph = glyphs[i];
  4240. if (glyph === null) {
  4241. // word break
  4242. this.ctx.translate(wordSpacing, 0);
  4243. current.x += wordSpacing * textHScale;
  4244. continue;
  4245. } else if (isNum(glyph)) {
  4246. var spacingLength = -glyph * 0.001 * fontSize;
  4247. this.ctx.translate(spacingLength, 0);
  4248. current.x += spacingLength * textHScale;
  4249. continue;
  4250. }
  4251. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4252. if (!operatorList) {
  4253. warn('Type3 character \"' + glyph.operatorListId +
  4254. '\" is not available');
  4255. continue;
  4256. }
  4257. this.processingType3 = glyph;
  4258. this.save();
  4259. ctx.scale(fontSize, fontSize);
  4260. ctx.transform.apply(ctx, fontMatrix);
  4261. this.executeOperatorList(operatorList);
  4262. this.restore();
  4263. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4264. width = transformed[0] * fontSize + charSpacing;
  4265. ctx.translate(width, 0);
  4266. current.x += width * textHScale;
  4267. }
  4268. ctx.restore();
  4269. this.processingType3 = null;
  4270. },
  4271. // Type3 fonts
  4272. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4273. // We can safely ignore this since the width should be the same
  4274. // as the width in the Widths array.
  4275. },
  4276. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4277. yWidth,
  4278. llx,
  4279. lly,
  4280. urx,
  4281. ury) {
  4282. // TODO According to the spec we're also suppose to ignore any operators
  4283. // that set color or include images while processing this type3 font.
  4284. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4285. this.clip();
  4286. this.endPath();
  4287. },
  4288. // Color
  4289. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4290. var pattern;
  4291. if (IR[0] === 'TilingPattern') {
  4292. var color = IR[1];
  4293. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4294. this.commonObjs, this.baseTransform);
  4295. } else {
  4296. pattern = getShadingPatternFromIR(IR);
  4297. }
  4298. return pattern;
  4299. },
  4300. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4301. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4302. },
  4303. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4304. this.current.fillColor = this.getColorN_Pattern(arguments);
  4305. this.current.patternFill = true;
  4306. },
  4307. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4308. var color = Util.makeCssRgb(r, g, b);
  4309. this.ctx.strokeStyle = color;
  4310. this.current.strokeColor = color;
  4311. },
  4312. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4313. var color = Util.makeCssRgb(r, g, b);
  4314. this.ctx.fillStyle = color;
  4315. this.current.fillColor = color;
  4316. this.current.patternFill = false;
  4317. },
  4318. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4319. var ctx = this.ctx;
  4320. this.save();
  4321. var pattern = getShadingPatternFromIR(patternIR);
  4322. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4323. var inv = ctx.mozCurrentTransformInverse;
  4324. if (inv) {
  4325. var canvas = ctx.canvas;
  4326. var width = canvas.width;
  4327. var height = canvas.height;
  4328. var bl = Util.applyTransform([0, 0], inv);
  4329. var br = Util.applyTransform([0, height], inv);
  4330. var ul = Util.applyTransform([width, 0], inv);
  4331. var ur = Util.applyTransform([width, height], inv);
  4332. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4333. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4334. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4335. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4336. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4337. } else {
  4338. // HACK to draw the gradient onto an infinite rectangle.
  4339. // PDF gradients are drawn across the entire image while
  4340. // Canvas only allows gradients to be drawn in a rectangle
  4341. // The following bug should allow us to remove this.
  4342. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4343. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4344. }
  4345. this.restore();
  4346. },
  4347. // Images
  4348. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4349. error('Should not call beginInlineImage');
  4350. },
  4351. beginImageData: function CanvasGraphics_beginImageData() {
  4352. error('Should not call beginImageData');
  4353. },
  4354. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4355. bbox) {
  4356. this.save();
  4357. this.baseTransformStack.push(this.baseTransform);
  4358. if (isArray(matrix) && 6 === matrix.length) {
  4359. this.transform.apply(this, matrix);
  4360. }
  4361. this.baseTransform = this.ctx.mozCurrentTransform;
  4362. if (isArray(bbox) && 4 === bbox.length) {
  4363. var width = bbox[2] - bbox[0];
  4364. var height = bbox[3] - bbox[1];
  4365. this.ctx.rect(bbox[0], bbox[1], width, height);
  4366. this.clip();
  4367. this.endPath();
  4368. }
  4369. },
  4370. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4371. this.restore();
  4372. this.baseTransform = this.baseTransformStack.pop();
  4373. },
  4374. beginGroup: function CanvasGraphics_beginGroup(group) {
  4375. this.save();
  4376. var currentCtx = this.ctx;
  4377. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4378. // group results aren't usually that different and they even have tools
  4379. // that ignore this setting. Notes from Rik on implmenting:
  4380. // - When you encounter an transparency group, create a new canvas with
  4381. // the dimensions of the bbox
  4382. // - copy the content from the previous canvas to the new canvas
  4383. // - draw as usual
  4384. // - remove the backdrop alpha:
  4385. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4386. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4387. // backdrop
  4388. // - remove background color:
  4389. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4390. if (!group.isolated) {
  4391. info('TODO: Support non-isolated groups.');
  4392. }
  4393. // TODO knockout - supposedly possible with the clever use of compositing
  4394. // modes.
  4395. if (group.knockout) {
  4396. warn('Knockout groups not supported.');
  4397. }
  4398. var currentTransform = currentCtx.mozCurrentTransform;
  4399. if (group.matrix) {
  4400. currentCtx.transform.apply(currentCtx, group.matrix);
  4401. }
  4402. assert(group.bbox, 'Bounding box is required.');
  4403. // Based on the current transform figure out how big the bounding box
  4404. // will actually be.
  4405. var bounds = Util.getAxialAlignedBoundingBox(
  4406. group.bbox,
  4407. currentCtx.mozCurrentTransform);
  4408. // Clip the bounding box to the current canvas.
  4409. var canvasBounds = [0,
  4410. 0,
  4411. currentCtx.canvas.width,
  4412. currentCtx.canvas.height];
  4413. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4414. // Use ceil in case we're between sizes so we don't create canvas that is
  4415. // too small and make the canvas at least 1x1 pixels.
  4416. var offsetX = Math.floor(bounds[0]);
  4417. var offsetY = Math.floor(bounds[1]);
  4418. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4419. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4420. var scaleX = 1, scaleY = 1;
  4421. if (drawnWidth > MAX_GROUP_SIZE) {
  4422. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4423. drawnWidth = MAX_GROUP_SIZE;
  4424. }
  4425. if (drawnHeight > MAX_GROUP_SIZE) {
  4426. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4427. drawnHeight = MAX_GROUP_SIZE;
  4428. }
  4429. var cacheId = 'groupAt' + this.groupLevel;
  4430. if (group.smask) {
  4431. // Using two cache entries is case if masks are used one after another.
  4432. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4433. }
  4434. var scratchCanvas = CachedCanvases.getCanvas(
  4435. cacheId, drawnWidth, drawnHeight, true);
  4436. var groupCtx = scratchCanvas.context;
  4437. // Since we created a new canvas that is just the size of the bounding box
  4438. // we have to translate the group ctx.
  4439. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4440. groupCtx.translate(-offsetX, -offsetY);
  4441. groupCtx.transform.apply(groupCtx, currentTransform);
  4442. if (group.smask) {
  4443. // Saving state and cached mask to be used in setGState.
  4444. this.smaskStack.push({
  4445. canvas: scratchCanvas.canvas,
  4446. context: groupCtx,
  4447. offsetX: offsetX,
  4448. offsetY: offsetY,
  4449. scaleX: scaleX,
  4450. scaleY: scaleY,
  4451. subtype: group.smask.subtype,
  4452. backdrop: group.smask.backdrop
  4453. });
  4454. } else {
  4455. // Setup the current ctx so when the group is popped we draw it at the
  4456. // right location.
  4457. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4458. currentCtx.translate(offsetX, offsetY);
  4459. currentCtx.scale(scaleX, scaleY);
  4460. }
  4461. // The transparency group inherits all off the current graphics state
  4462. // except the blend mode, soft mask, and alpha constants.
  4463. copyCtxState(currentCtx, groupCtx);
  4464. this.ctx = groupCtx;
  4465. this.setGState([
  4466. ['BM', 'Normal'],
  4467. ['ca', 1],
  4468. ['CA', 1]
  4469. ]);
  4470. this.groupStack.push(currentCtx);
  4471. this.groupLevel++;
  4472. },
  4473. endGroup: function CanvasGraphics_endGroup(group) {
  4474. this.groupLevel--;
  4475. var groupCtx = this.ctx;
  4476. this.ctx = this.groupStack.pop();
  4477. // Turn off image smoothing to avoid sub pixel interpolation which can
  4478. // look kind of blurry for some pdfs.
  4479. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4480. this.ctx.imageSmoothingEnabled = false;
  4481. } else {
  4482. this.ctx.mozImageSmoothingEnabled = false;
  4483. }
  4484. if (group.smask) {
  4485. this.tempSMask = this.smaskStack.pop();
  4486. } else {
  4487. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4488. }
  4489. this.restore();
  4490. },
  4491. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4492. this.save();
  4493. this.current = new CanvasExtraState();
  4494. },
  4495. endAnnotations: function CanvasGraphics_endAnnotations() {
  4496. this.restore();
  4497. },
  4498. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4499. matrix) {
  4500. this.save();
  4501. if (isArray(rect) && 4 === rect.length) {
  4502. var width = rect[2] - rect[0];
  4503. var height = rect[3] - rect[1];
  4504. this.ctx.rect(rect[0], rect[1], width, height);
  4505. this.clip();
  4506. this.endPath();
  4507. }
  4508. this.transform.apply(this, transform);
  4509. this.transform.apply(this, matrix);
  4510. },
  4511. endAnnotation: function CanvasGraphics_endAnnotation() {
  4512. this.restore();
  4513. },
  4514. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4515. var domImage = this.objs.get(objId);
  4516. if (!domImage) {
  4517. warn('Dependent image isn\'t ready yet');
  4518. return;
  4519. }
  4520. this.save();
  4521. var ctx = this.ctx;
  4522. // scale the image to the unit square
  4523. ctx.scale(1 / w, -1 / h);
  4524. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4525. 0, -h, w, h);
  4526. if (this.imageLayer) {
  4527. var currentTransform = ctx.mozCurrentTransformInverse;
  4528. var position = this.getCanvasPosition(0, 0);
  4529. this.imageLayer.appendImage({
  4530. objId: objId,
  4531. left: position[0],
  4532. top: position[1],
  4533. width: w / currentTransform[0],
  4534. height: h / currentTransform[3]
  4535. });
  4536. }
  4537. this.restore();
  4538. },
  4539. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4540. var ctx = this.ctx;
  4541. var width = img.width, height = img.height;
  4542. var fillColor = this.current.fillColor;
  4543. var isPatternFill = this.current.patternFill;
  4544. var glyph = this.processingType3;
  4545. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  4546. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4547. glyph.compiled =
  4548. compileType3Glyph({data: img.data, width: width, height: height});
  4549. } else {
  4550. glyph.compiled = null;
  4551. }
  4552. }
  4553. if (glyph && glyph.compiled) {
  4554. glyph.compiled(ctx);
  4555. return;
  4556. }
  4557. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4558. var maskCtx = maskCanvas.context;
  4559. maskCtx.save();
  4560. putBinaryImageMask(maskCtx, img);
  4561. maskCtx.globalCompositeOperation = 'source-in';
  4562. maskCtx.fillStyle = isPatternFill ?
  4563. fillColor.getPattern(maskCtx, this) : fillColor;
  4564. maskCtx.fillRect(0, 0, width, height);
  4565. maskCtx.restore();
  4566. this.paintInlineImageXObject(maskCanvas.canvas);
  4567. },
  4568. paintImageMaskXObjectRepeat:
  4569. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4570. scaleY, positions) {
  4571. var width = imgData.width;
  4572. var height = imgData.height;
  4573. var fillColor = this.current.fillColor;
  4574. var isPatternFill = this.current.patternFill;
  4575. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4576. var maskCtx = maskCanvas.context;
  4577. maskCtx.save();
  4578. putBinaryImageMask(maskCtx, imgData);
  4579. maskCtx.globalCompositeOperation = 'source-in';
  4580. maskCtx.fillStyle = isPatternFill ?
  4581. fillColor.getPattern(maskCtx, this) : fillColor;
  4582. maskCtx.fillRect(0, 0, width, height);
  4583. maskCtx.restore();
  4584. var ctx = this.ctx;
  4585. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4586. ctx.save();
  4587. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4588. ctx.scale(1, -1);
  4589. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4590. 0, -1, 1, 1);
  4591. ctx.restore();
  4592. }
  4593. },
  4594. paintImageMaskXObjectGroup:
  4595. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4596. var ctx = this.ctx;
  4597. var fillColor = this.current.fillColor;
  4598. var isPatternFill = this.current.patternFill;
  4599. for (var i = 0, ii = images.length; i < ii; i++) {
  4600. var image = images[i];
  4601. var width = image.width, height = image.height;
  4602. var maskCanvas = CachedCanvases.getCanvas('maskCanvas', width, height);
  4603. var maskCtx = maskCanvas.context;
  4604. maskCtx.save();
  4605. putBinaryImageMask(maskCtx, image);
  4606. maskCtx.globalCompositeOperation = 'source-in';
  4607. maskCtx.fillStyle = isPatternFill ?
  4608. fillColor.getPattern(maskCtx, this) : fillColor;
  4609. maskCtx.fillRect(0, 0, width, height);
  4610. maskCtx.restore();
  4611. ctx.save();
  4612. ctx.transform.apply(ctx, image.transform);
  4613. ctx.scale(1, -1);
  4614. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4615. 0, -1, 1, 1);
  4616. ctx.restore();
  4617. }
  4618. },
  4619. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4620. var imgData = this.objs.get(objId);
  4621. if (!imgData) {
  4622. warn('Dependent image isn\'t ready yet');
  4623. return;
  4624. }
  4625. this.paintInlineImageXObject(imgData);
  4626. },
  4627. paintImageXObjectRepeat:
  4628. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4629. positions) {
  4630. var imgData = this.objs.get(objId);
  4631. if (!imgData) {
  4632. warn('Dependent image isn\'t ready yet');
  4633. return;
  4634. }
  4635. var width = imgData.width;
  4636. var height = imgData.height;
  4637. var map = [];
  4638. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4639. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4640. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4641. }
  4642. this.paintInlineImageXObjectGroup(imgData, map);
  4643. },
  4644. paintInlineImageXObject:
  4645. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4646. var width = imgData.width;
  4647. var height = imgData.height;
  4648. var ctx = this.ctx;
  4649. this.save();
  4650. // scale the image to the unit square
  4651. ctx.scale(1 / width, -1 / height);
  4652. var currentTransform = ctx.mozCurrentTransformInverse;
  4653. var a = currentTransform[0], b = currentTransform[1];
  4654. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4655. var c = currentTransform[2], d = currentTransform[3];
  4656. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4657. var imgToPaint, tmpCanvas;
  4658. // instanceof HTMLElement does not work in jsdom node.js module
  4659. if (imgData instanceof HTMLElement || !imgData.data) {
  4660. imgToPaint = imgData;
  4661. } else {
  4662. tmpCanvas = CachedCanvases.getCanvas('inlineImage', width, height);
  4663. var tmpCtx = tmpCanvas.context;
  4664. putBinaryImageData(tmpCtx, imgData);
  4665. imgToPaint = tmpCanvas.canvas;
  4666. }
  4667. var paintWidth = width, paintHeight = height;
  4668. var tmpCanvasId = 'prescale1';
  4669. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4670. // pixels during drawImage operation, painting on the temporary canvas(es)
  4671. // that are twice smaller in size
  4672. while ((widthScale > 2 && paintWidth > 1) ||
  4673. (heightScale > 2 && paintHeight > 1)) {
  4674. var newWidth = paintWidth, newHeight = paintHeight;
  4675. if (widthScale > 2 && paintWidth > 1) {
  4676. newWidth = Math.ceil(paintWidth / 2);
  4677. widthScale /= paintWidth / newWidth;
  4678. }
  4679. if (heightScale > 2 && paintHeight > 1) {
  4680. newHeight = Math.ceil(paintHeight / 2);
  4681. heightScale /= paintHeight / newHeight;
  4682. }
  4683. tmpCanvas = CachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight);
  4684. tmpCtx = tmpCanvas.context;
  4685. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4686. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4687. 0, 0, newWidth, newHeight);
  4688. imgToPaint = tmpCanvas.canvas;
  4689. paintWidth = newWidth;
  4690. paintHeight = newHeight;
  4691. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4692. }
  4693. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4694. 0, -height, width, height);
  4695. if (this.imageLayer) {
  4696. var position = this.getCanvasPosition(0, -height);
  4697. this.imageLayer.appendImage({
  4698. imgData: imgData,
  4699. left: position[0],
  4700. top: position[1],
  4701. width: width / currentTransform[0],
  4702. height: height / currentTransform[3]
  4703. });
  4704. }
  4705. this.restore();
  4706. },
  4707. paintInlineImageXObjectGroup:
  4708. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4709. var ctx = this.ctx;
  4710. var w = imgData.width;
  4711. var h = imgData.height;
  4712. var tmpCanvas = CachedCanvases.getCanvas('inlineImage', w, h);
  4713. var tmpCtx = tmpCanvas.context;
  4714. putBinaryImageData(tmpCtx, imgData);
  4715. for (var i = 0, ii = map.length; i < ii; i++) {
  4716. var entry = map[i];
  4717. ctx.save();
  4718. ctx.transform.apply(ctx, entry.transform);
  4719. ctx.scale(1, -1);
  4720. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4721. 0, -1, 1, 1);
  4722. if (this.imageLayer) {
  4723. var position = this.getCanvasPosition(entry.x, entry.y);
  4724. this.imageLayer.appendImage({
  4725. imgData: imgData,
  4726. left: position[0],
  4727. top: position[1],
  4728. width: w,
  4729. height: h
  4730. });
  4731. }
  4732. ctx.restore();
  4733. }
  4734. },
  4735. paintSolidColorImageMask:
  4736. function CanvasGraphics_paintSolidColorImageMask() {
  4737. this.ctx.fillRect(0, 0, 1, 1);
  4738. },
  4739. // Marked content
  4740. markPoint: function CanvasGraphics_markPoint(tag) {
  4741. // TODO Marked content.
  4742. },
  4743. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4744. // TODO Marked content.
  4745. },
  4746. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4747. // TODO Marked content.
  4748. },
  4749. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4750. tag, properties) {
  4751. // TODO Marked content.
  4752. },
  4753. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4754. // TODO Marked content.
  4755. },
  4756. // Compatibility
  4757. beginCompat: function CanvasGraphics_beginCompat() {
  4758. // TODO ignore undefined operators (should we do that anyway?)
  4759. },
  4760. endCompat: function CanvasGraphics_endCompat() {
  4761. // TODO stop ignoring undefined operators
  4762. },
  4763. // Helper functions
  4764. consumePath: function CanvasGraphics_consumePath() {
  4765. var ctx = this.ctx;
  4766. if (this.pendingClip) {
  4767. if (this.pendingClip === EO_CLIP) {
  4768. if (ctx.mozFillRule !== undefined) {
  4769. ctx.mozFillRule = 'evenodd';
  4770. ctx.clip();
  4771. ctx.mozFillRule = 'nonzero';
  4772. } else {
  4773. try {
  4774. ctx.clip('evenodd');
  4775. } catch (ex) {
  4776. // shouldn't really happen, but browsers might think differently
  4777. ctx.clip();
  4778. }
  4779. }
  4780. } else {
  4781. ctx.clip();
  4782. }
  4783. this.pendingClip = null;
  4784. }
  4785. ctx.beginPath();
  4786. },
  4787. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4788. if (this.cachedGetSinglePixelWidth === null) {
  4789. var inverse = this.ctx.mozCurrentTransformInverse;
  4790. // max of the current horizontal and vertical scale
  4791. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  4792. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4793. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4794. }
  4795. return this.cachedGetSinglePixelWidth;
  4796. },
  4797. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4798. var transform = this.ctx.mozCurrentTransform;
  4799. return [
  4800. transform[0] * x + transform[2] * y + transform[4],
  4801. transform[1] * x + transform[3] * y + transform[5]
  4802. ];
  4803. }
  4804. };
  4805. for (var op in OPS) {
  4806. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4807. }
  4808. return CanvasGraphics;
  4809. })();
  4810. var WebGLUtils = (function WebGLUtilsClosure() {
  4811. function loadShader(gl, code, shaderType) {
  4812. var shader = gl.createShader(shaderType);
  4813. gl.shaderSource(shader, code);
  4814. gl.compileShader(shader);
  4815. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  4816. if (!compiled) {
  4817. var errorMsg = gl.getShaderInfoLog(shader);
  4818. throw new Error('Error during shader compilation: ' + errorMsg);
  4819. }
  4820. return shader;
  4821. }
  4822. function createVertexShader(gl, code) {
  4823. return loadShader(gl, code, gl.VERTEX_SHADER);
  4824. }
  4825. function createFragmentShader(gl, code) {
  4826. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  4827. }
  4828. function createProgram(gl, shaders) {
  4829. var program = gl.createProgram();
  4830. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  4831. gl.attachShader(program, shaders[i]);
  4832. }
  4833. gl.linkProgram(program);
  4834. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  4835. if (!linked) {
  4836. var errorMsg = gl.getProgramInfoLog(program);
  4837. throw new Error('Error during program linking: ' + errorMsg);
  4838. }
  4839. return program;
  4840. }
  4841. function createTexture(gl, image, textureId) {
  4842. gl.activeTexture(textureId);
  4843. var texture = gl.createTexture();
  4844. gl.bindTexture(gl.TEXTURE_2D, texture);
  4845. // Set the parameters so we can render any size image.
  4846. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  4847. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  4848. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  4849. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  4850. // Upload the image into the texture.
  4851. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  4852. return texture;
  4853. }
  4854. var currentGL, currentCanvas;
  4855. function generateGL() {
  4856. if (currentGL) {
  4857. return;
  4858. }
  4859. currentCanvas = document.createElement('canvas');
  4860. currentGL = currentCanvas.getContext('webgl',
  4861. { premultipliedalpha: false });
  4862. }
  4863. var smaskVertexShaderCode = '\
  4864. attribute vec2 a_position; \
  4865. attribute vec2 a_texCoord; \
  4866. \
  4867. uniform vec2 u_resolution; \
  4868. \
  4869. varying vec2 v_texCoord; \
  4870. \
  4871. void main() { \
  4872. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  4873. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  4874. \
  4875. v_texCoord = a_texCoord; \
  4876. } ';
  4877. var smaskFragmentShaderCode = '\
  4878. precision mediump float; \
  4879. \
  4880. uniform vec4 u_backdrop; \
  4881. uniform int u_subtype; \
  4882. uniform sampler2D u_image; \
  4883. uniform sampler2D u_mask; \
  4884. \
  4885. varying vec2 v_texCoord; \
  4886. \
  4887. void main() { \
  4888. vec4 imageColor = texture2D(u_image, v_texCoord); \
  4889. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  4890. if (u_backdrop.a > 0.0) { \
  4891. maskColor.rgb = maskColor.rgb * maskColor.a + \
  4892. u_backdrop.rgb * (1.0 - maskColor.a); \
  4893. } \
  4894. float lum; \
  4895. if (u_subtype == 0) { \
  4896. lum = maskColor.a; \
  4897. } else { \
  4898. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  4899. maskColor.b * 0.11; \
  4900. } \
  4901. imageColor.a *= lum; \
  4902. imageColor.rgb *= imageColor.a; \
  4903. gl_FragColor = imageColor; \
  4904. } ';
  4905. var smaskCache = null;
  4906. function initSmaskGL() {
  4907. var canvas, gl;
  4908. generateGL();
  4909. canvas = currentCanvas;
  4910. currentCanvas = null;
  4911. gl = currentGL;
  4912. currentGL = null;
  4913. // setup a GLSL program
  4914. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  4915. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  4916. var program = createProgram(gl, [vertexShader, fragmentShader]);
  4917. gl.useProgram(program);
  4918. var cache = {};
  4919. cache.gl = gl;
  4920. cache.canvas = canvas;
  4921. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  4922. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  4923. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  4924. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  4925. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  4926. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  4927. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  4928. // provide texture coordinates for the rectangle.
  4929. var texCoordBuffer = gl.createBuffer();
  4930. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  4931. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4932. 0.0, 0.0,
  4933. 1.0, 0.0,
  4934. 0.0, 1.0,
  4935. 0.0, 1.0,
  4936. 1.0, 0.0,
  4937. 1.0, 1.0]), gl.STATIC_DRAW);
  4938. gl.enableVertexAttribArray(texCoordLocation);
  4939. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  4940. gl.uniform1i(texLayerLocation, 0);
  4941. gl.uniform1i(texMaskLocation, 1);
  4942. smaskCache = cache;
  4943. }
  4944. function composeSMask(layer, mask, properties) {
  4945. var width = layer.width, height = layer.height;
  4946. if (!smaskCache) {
  4947. initSmaskGL();
  4948. }
  4949. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  4950. canvas.width = width;
  4951. canvas.height = height;
  4952. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  4953. gl.uniform2f(cache.resolutionLocation, width, height);
  4954. if (properties.backdrop) {
  4955. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  4956. properties.backdrop[1], properties.backdrop[2], 1);
  4957. } else {
  4958. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  4959. }
  4960. gl.uniform1i(cache.subtypeLocation,
  4961. properties.subtype === 'Luminosity' ? 1 : 0);
  4962. // Create a textures
  4963. var texture = createTexture(gl, layer, gl.TEXTURE0);
  4964. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  4965. // Create a buffer and put a single clipspace rectangle in
  4966. // it (2 triangles)
  4967. var buffer = gl.createBuffer();
  4968. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  4969. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  4970. 0, 0,
  4971. width, 0,
  4972. 0, height,
  4973. 0, height,
  4974. width, 0,
  4975. width, height]), gl.STATIC_DRAW);
  4976. gl.enableVertexAttribArray(cache.positionLocation);
  4977. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  4978. // draw
  4979. gl.clearColor(0, 0, 0, 0);
  4980. gl.enable(gl.BLEND);
  4981. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  4982. gl.clear(gl.COLOR_BUFFER_BIT);
  4983. gl.drawArrays(gl.TRIANGLES, 0, 6);
  4984. gl.flush();
  4985. gl.deleteTexture(texture);
  4986. gl.deleteTexture(maskTexture);
  4987. gl.deleteBuffer(buffer);
  4988. return canvas;
  4989. }
  4990. var figuresVertexShaderCode = '\
  4991. attribute vec2 a_position; \
  4992. attribute vec3 a_color; \
  4993. \
  4994. uniform vec2 u_resolution; \
  4995. uniform vec2 u_scale; \
  4996. uniform vec2 u_offset; \
  4997. \
  4998. varying vec4 v_color; \
  4999. \
  5000. void main() { \
  5001. vec2 position = (a_position + u_offset) * u_scale; \
  5002. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  5003. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5004. \
  5005. v_color = vec4(a_color / 255.0, 1.0); \
  5006. } ';
  5007. var figuresFragmentShaderCode = '\
  5008. precision mediump float; \
  5009. \
  5010. varying vec4 v_color; \
  5011. \
  5012. void main() { \
  5013. gl_FragColor = v_color; \
  5014. } ';
  5015. var figuresCache = null;
  5016. function initFiguresGL() {
  5017. var canvas, gl;
  5018. generateGL();
  5019. canvas = currentCanvas;
  5020. currentCanvas = null;
  5021. gl = currentGL;
  5022. currentGL = null;
  5023. // setup a GLSL program
  5024. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  5025. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  5026. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5027. gl.useProgram(program);
  5028. var cache = {};
  5029. cache.gl = gl;
  5030. cache.canvas = canvas;
  5031. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5032. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  5033. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  5034. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5035. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  5036. figuresCache = cache;
  5037. }
  5038. function drawFigures(width, height, backgroundColor, figures, context) {
  5039. if (!figuresCache) {
  5040. initFiguresGL();
  5041. }
  5042. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  5043. canvas.width = width;
  5044. canvas.height = height;
  5045. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5046. gl.uniform2f(cache.resolutionLocation, width, height);
  5047. // count triangle points
  5048. var count = 0;
  5049. var i, ii, rows;
  5050. for (i = 0, ii = figures.length; i < ii; i++) {
  5051. switch (figures[i].type) {
  5052. case 'lattice':
  5053. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  5054. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  5055. break;
  5056. case 'triangles':
  5057. count += figures[i].coords.length;
  5058. break;
  5059. }
  5060. }
  5061. // transfer data
  5062. var coords = new Float32Array(count * 2);
  5063. var colors = new Uint8Array(count * 3);
  5064. var coordsMap = context.coords, colorsMap = context.colors;
  5065. var pIndex = 0, cIndex = 0;
  5066. for (i = 0, ii = figures.length; i < ii; i++) {
  5067. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  5068. switch (figure.type) {
  5069. case 'lattice':
  5070. var cols = figure.verticesPerRow;
  5071. rows = (ps.length / cols) | 0;
  5072. for (var row = 1; row < rows; row++) {
  5073. var offset = row * cols + 1;
  5074. for (var col = 1; col < cols; col++, offset++) {
  5075. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  5076. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  5077. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  5078. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  5079. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  5080. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  5081. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  5082. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  5083. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  5084. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  5085. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  5086. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  5087. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  5088. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  5089. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  5090. coords[pIndex + 6] = coords[pIndex + 2];
  5091. coords[pIndex + 7] = coords[pIndex + 3];
  5092. coords[pIndex + 8] = coords[pIndex + 4];
  5093. coords[pIndex + 9] = coords[pIndex + 5];
  5094. coords[pIndex + 10] = coordsMap[ps[offset]];
  5095. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  5096. colors[cIndex + 9] = colors[cIndex + 3];
  5097. colors[cIndex + 10] = colors[cIndex + 4];
  5098. colors[cIndex + 11] = colors[cIndex + 5];
  5099. colors[cIndex + 12] = colors[cIndex + 6];
  5100. colors[cIndex + 13] = colors[cIndex + 7];
  5101. colors[cIndex + 14] = colors[cIndex + 8];
  5102. colors[cIndex + 15] = colorsMap[cs[offset]];
  5103. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  5104. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  5105. pIndex += 12;
  5106. cIndex += 18;
  5107. }
  5108. }
  5109. break;
  5110. case 'triangles':
  5111. for (var j = 0, jj = ps.length; j < jj; j++) {
  5112. coords[pIndex] = coordsMap[ps[j]];
  5113. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  5114. colors[cIndex] = colorsMap[cs[i]];
  5115. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  5116. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  5117. pIndex += 2;
  5118. cIndex += 3;
  5119. }
  5120. break;
  5121. }
  5122. }
  5123. // draw
  5124. if (backgroundColor) {
  5125. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  5126. backgroundColor[2] / 255, 1.0);
  5127. } else {
  5128. gl.clearColor(0, 0, 0, 0);
  5129. }
  5130. gl.clear(gl.COLOR_BUFFER_BIT);
  5131. var coordsBuffer = gl.createBuffer();
  5132. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  5133. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  5134. gl.enableVertexAttribArray(cache.positionLocation);
  5135. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5136. var colorsBuffer = gl.createBuffer();
  5137. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  5138. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  5139. gl.enableVertexAttribArray(cache.colorLocation);
  5140. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  5141. 0, 0);
  5142. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  5143. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  5144. gl.drawArrays(gl.TRIANGLES, 0, count);
  5145. gl.flush();
  5146. gl.deleteBuffer(coordsBuffer);
  5147. gl.deleteBuffer(colorsBuffer);
  5148. return canvas;
  5149. }
  5150. function cleanup() {
  5151. if (smaskCache && smaskCache.canvas) {
  5152. smaskCache.canvas.width = 0;
  5153. smaskCache.canvas.height = 0;
  5154. }
  5155. if (figuresCache && figuresCache.canvas) {
  5156. figuresCache.canvas.width = 0;
  5157. figuresCache.canvas.height = 0;
  5158. }
  5159. smaskCache = null;
  5160. figuresCache = null;
  5161. }
  5162. return {
  5163. get isEnabled() {
  5164. if (PDFJS.disableWebGL) {
  5165. return false;
  5166. }
  5167. var enabled = false;
  5168. try {
  5169. generateGL();
  5170. enabled = !!currentGL;
  5171. } catch (e) { }
  5172. return shadow(this, 'isEnabled', enabled);
  5173. },
  5174. composeSMask: composeSMask,
  5175. drawFigures: drawFigures,
  5176. clear: cleanup
  5177. };
  5178. })();
  5179. var ShadingIRs = {};
  5180. ShadingIRs.RadialAxial = {
  5181. fromIR: function RadialAxial_fromIR(raw) {
  5182. var type = raw[1];
  5183. var colorStops = raw[2];
  5184. var p0 = raw[3];
  5185. var p1 = raw[4];
  5186. var r0 = raw[5];
  5187. var r1 = raw[6];
  5188. return {
  5189. type: 'Pattern',
  5190. getPattern: function RadialAxial_getPattern(ctx) {
  5191. var grad;
  5192. if (type === 'axial') {
  5193. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5194. } else if (type === 'radial') {
  5195. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5196. }
  5197. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5198. var c = colorStops[i];
  5199. grad.addColorStop(c[0], c[1]);
  5200. }
  5201. return grad;
  5202. }
  5203. };
  5204. }
  5205. };
  5206. var createMeshCanvas = (function createMeshCanvasClosure() {
  5207. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5208. // Very basic Gouraud-shaded triangle rasterization algorithm.
  5209. var coords = context.coords, colors = context.colors;
  5210. var bytes = data.data, rowSize = data.width * 4;
  5211. var tmp;
  5212. if (coords[p1 + 1] > coords[p2 + 1]) {
  5213. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5214. }
  5215. if (coords[p2 + 1] > coords[p3 + 1]) {
  5216. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  5217. }
  5218. if (coords[p1 + 1] > coords[p2 + 1]) {
  5219. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5220. }
  5221. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5222. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5223. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5224. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5225. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5226. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5227. if (y1 >= y3) {
  5228. return;
  5229. }
  5230. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5231. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5232. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5233. var minY = Math.round(y1), maxY = Math.round(y3);
  5234. var xa, car, cag, cab;
  5235. var xb, cbr, cbg, cbb;
  5236. var k;
  5237. for (var y = minY; y <= maxY; y++) {
  5238. if (y < y2) {
  5239. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5240. xa = x1 - (x1 - x2) * k;
  5241. car = c1r - (c1r - c2r) * k;
  5242. cag = c1g - (c1g - c2g) * k;
  5243. cab = c1b - (c1b - c2b) * k;
  5244. } else {
  5245. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5246. xa = x2 - (x2 - x3) * k;
  5247. car = c2r - (c2r - c3r) * k;
  5248. cag = c2g - (c2g - c3g) * k;
  5249. cab = c2b - (c2b - c3b) * k;
  5250. }
  5251. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5252. xb = x1 - (x1 - x3) * k;
  5253. cbr = c1r - (c1r - c3r) * k;
  5254. cbg = c1g - (c1g - c3g) * k;
  5255. cbb = c1b - (c1b - c3b) * k;
  5256. var x1_ = Math.round(Math.min(xa, xb));
  5257. var x2_ = Math.round(Math.max(xa, xb));
  5258. var j = rowSize * y + x1_ * 4;
  5259. for (var x = x1_; x <= x2_; x++) {
  5260. k = (xa - x) / (xa - xb);
  5261. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5262. bytes[j++] = (car - (car - cbr) * k) | 0;
  5263. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5264. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5265. bytes[j++] = 255;
  5266. }
  5267. }
  5268. }
  5269. function drawFigure(data, figure, context) {
  5270. var ps = figure.coords;
  5271. var cs = figure.colors;
  5272. var i, ii;
  5273. switch (figure.type) {
  5274. case 'lattice':
  5275. var verticesPerRow = figure.verticesPerRow;
  5276. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5277. var cols = verticesPerRow - 1;
  5278. for (i = 0; i < rows; i++) {
  5279. var q = i * verticesPerRow;
  5280. for (var j = 0; j < cols; j++, q++) {
  5281. drawTriangle(data, context,
  5282. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5283. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5284. drawTriangle(data, context,
  5285. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5286. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5287. }
  5288. }
  5289. break;
  5290. case 'triangles':
  5291. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5292. drawTriangle(data, context,
  5293. ps[i], ps[i + 1], ps[i + 2],
  5294. cs[i], cs[i + 1], cs[i + 2]);
  5295. }
  5296. break;
  5297. default:
  5298. error('illigal figure');
  5299. break;
  5300. }
  5301. }
  5302. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5303. backgroundColor) {
  5304. // we will increase scale on some weird factor to let antialiasing take
  5305. // care of "rough" edges
  5306. var EXPECTED_SCALE = 1.1;
  5307. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5308. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5309. var offsetX = Math.floor(bounds[0]);
  5310. var offsetY = Math.floor(bounds[1]);
  5311. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5312. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5313. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5314. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5315. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5316. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5317. var scaleX = boundsWidth / width;
  5318. var scaleY = boundsHeight / height;
  5319. var context = {
  5320. coords: coords,
  5321. colors: colors,
  5322. offsetX: -offsetX,
  5323. offsetY: -offsetY,
  5324. scaleX: 1 / scaleX,
  5325. scaleY: 1 / scaleY
  5326. };
  5327. var canvas, tmpCanvas, i, ii;
  5328. if (WebGLUtils.isEnabled) {
  5329. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5330. figures, context);
  5331. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5332. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5333. tmpCanvas.context.drawImage(canvas, 0, 0);
  5334. canvas = tmpCanvas.canvas;
  5335. } else {
  5336. tmpCanvas = CachedCanvases.getCanvas('mesh', width, height, false);
  5337. var tmpCtx = tmpCanvas.context;
  5338. var data = tmpCtx.createImageData(width, height);
  5339. if (backgroundColor) {
  5340. var bytes = data.data;
  5341. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5342. bytes[i] = backgroundColor[0];
  5343. bytes[i + 1] = backgroundColor[1];
  5344. bytes[i + 2] = backgroundColor[2];
  5345. bytes[i + 3] = 255;
  5346. }
  5347. }
  5348. for (i = 0; i < figures.length; i++) {
  5349. drawFigure(data, figures[i], context);
  5350. }
  5351. tmpCtx.putImageData(data, 0, 0);
  5352. canvas = tmpCanvas.canvas;
  5353. }
  5354. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5355. scaleX: scaleX, scaleY: scaleY};
  5356. }
  5357. return createMeshCanvas;
  5358. })();
  5359. ShadingIRs.Mesh = {
  5360. fromIR: function Mesh_fromIR(raw) {
  5361. //var type = raw[1];
  5362. var coords = raw[2];
  5363. var colors = raw[3];
  5364. var figures = raw[4];
  5365. var bounds = raw[5];
  5366. var matrix = raw[6];
  5367. //var bbox = raw[7];
  5368. var background = raw[8];
  5369. return {
  5370. type: 'Pattern',
  5371. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5372. var scale;
  5373. if (shadingFill) {
  5374. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5375. } else {
  5376. // Obtain scale from matrix and current transformation matrix.
  5377. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5378. if (matrix) {
  5379. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5380. scale = [scale[0] * matrixScale[0],
  5381. scale[1] * matrixScale[1]];
  5382. }
  5383. }
  5384. // Rasterizing on the main thread since sending/queue large canvases
  5385. // might cause OOM.
  5386. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5387. colors, figures, shadingFill ? null : background);
  5388. if (!shadingFill) {
  5389. ctx.setTransform.apply(ctx, owner.baseTransform);
  5390. if (matrix) {
  5391. ctx.transform.apply(ctx, matrix);
  5392. }
  5393. }
  5394. ctx.translate(temporaryPatternCanvas.offsetX,
  5395. temporaryPatternCanvas.offsetY);
  5396. ctx.scale(temporaryPatternCanvas.scaleX,
  5397. temporaryPatternCanvas.scaleY);
  5398. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5399. }
  5400. };
  5401. }
  5402. };
  5403. ShadingIRs.Dummy = {
  5404. fromIR: function Dummy_fromIR() {
  5405. return {
  5406. type: 'Pattern',
  5407. getPattern: function Dummy_fromIR_getPattern() {
  5408. return 'hotpink';
  5409. }
  5410. };
  5411. }
  5412. };
  5413. function getShadingPatternFromIR(raw) {
  5414. var shadingIR = ShadingIRs[raw[0]];
  5415. if (!shadingIR) {
  5416. error('Unknown IR type: ' + raw[0]);
  5417. }
  5418. return shadingIR.fromIR(raw);
  5419. }
  5420. var TilingPattern = (function TilingPatternClosure() {
  5421. var PaintType = {
  5422. COLORED: 1,
  5423. UNCOLORED: 2
  5424. };
  5425. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5426. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5427. this.operatorList = IR[2];
  5428. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5429. this.bbox = IR[4];
  5430. this.xstep = IR[5];
  5431. this.ystep = IR[6];
  5432. this.paintType = IR[7];
  5433. this.tilingType = IR[8];
  5434. this.color = color;
  5435. this.objs = objs;
  5436. this.commonObjs = commonObjs;
  5437. this.baseTransform = baseTransform;
  5438. this.type = 'Pattern';
  5439. this.ctx = ctx;
  5440. }
  5441. TilingPattern.prototype = {
  5442. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5443. var operatorList = this.operatorList;
  5444. var bbox = this.bbox;
  5445. var xstep = this.xstep;
  5446. var ystep = this.ystep;
  5447. var paintType = this.paintType;
  5448. var tilingType = this.tilingType;
  5449. var color = this.color;
  5450. var objs = this.objs;
  5451. var commonObjs = this.commonObjs;
  5452. info('TilingType: ' + tilingType);
  5453. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5454. var topLeft = [x0, y0];
  5455. // we want the canvas to be as large as the step size
  5456. var botRight = [x0 + xstep, y0 + ystep];
  5457. var width = botRight[0] - topLeft[0];
  5458. var height = botRight[1] - topLeft[1];
  5459. // Obtain scale from matrix and current transformation matrix.
  5460. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5461. var curMatrixScale = Util.singularValueDecompose2dScale(
  5462. this.baseTransform);
  5463. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5464. matrixScale[1] * curMatrixScale[1]];
  5465. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5466. // Use width and height values that are as close as possible to the end
  5467. // result when the pattern is used. Too low value makes the pattern look
  5468. // blurry. Too large value makes it look too crispy.
  5469. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5470. MAX_PATTERN_SIZE);
  5471. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5472. MAX_PATTERN_SIZE);
  5473. var tmpCanvas = CachedCanvases.getCanvas('pattern', width, height, true);
  5474. var tmpCtx = tmpCanvas.context;
  5475. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5476. graphics.groupLevel = owner.groupLevel;
  5477. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5478. this.setScale(width, height, xstep, ystep);
  5479. this.transformToScale(graphics);
  5480. // transform coordinates to pattern space
  5481. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5482. graphics.transform.apply(graphics, tmpTranslate);
  5483. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5484. graphics.executeOperatorList(operatorList);
  5485. return tmpCanvas.canvas;
  5486. },
  5487. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5488. this.scale = [width / xstep, height / ystep];
  5489. },
  5490. transformToScale: function TilingPattern_transformToScale(graphics) {
  5491. var scale = this.scale;
  5492. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5493. graphics.transform.apply(graphics, tmpScale);
  5494. },
  5495. scaleToContext: function TilingPattern_scaleToContext() {
  5496. var scale = this.scale;
  5497. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5498. },
  5499. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5500. if (bbox && isArray(bbox) && bbox.length === 4) {
  5501. var bboxWidth = x1 - x0;
  5502. var bboxHeight = y1 - y0;
  5503. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5504. graphics.clip();
  5505. graphics.endPath();
  5506. }
  5507. },
  5508. setFillAndStrokeStyleToContext:
  5509. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5510. switch (paintType) {
  5511. case PaintType.COLORED:
  5512. var ctx = this.ctx;
  5513. context.fillStyle = ctx.fillStyle;
  5514. context.strokeStyle = ctx.strokeStyle;
  5515. break;
  5516. case PaintType.UNCOLORED:
  5517. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  5518. context.fillStyle = cssColor;
  5519. context.strokeStyle = cssColor;
  5520. break;
  5521. default:
  5522. error('Unsupported paint type: ' + paintType);
  5523. }
  5524. },
  5525. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5526. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5527. ctx = this.ctx;
  5528. ctx.setTransform.apply(ctx, this.baseTransform);
  5529. ctx.transform.apply(ctx, this.matrix);
  5530. this.scaleToContext();
  5531. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5532. }
  5533. };
  5534. return TilingPattern;
  5535. })();
  5536. PDFJS.disableFontFace = false;
  5537. var FontLoader = {
  5538. insertRule: function fontLoaderInsertRule(rule) {
  5539. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5540. if (!styleElement) {
  5541. styleElement = document.createElement('style');
  5542. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5543. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5544. styleElement);
  5545. }
  5546. var styleSheet = styleElement.sheet;
  5547. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5548. },
  5549. clear: function fontLoaderClear() {
  5550. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5551. if (styleElement) {
  5552. styleElement.parentNode.removeChild(styleElement);
  5553. }
  5554. this.nativeFontFaces.forEach(function(nativeFontFace) {
  5555. document.fonts.delete(nativeFontFace);
  5556. });
  5557. this.nativeFontFaces.length = 0;
  5558. },
  5559. get loadTestFont() {
  5560. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5561. // height.
  5562. return shadow(this, 'loadTestFont', atob(
  5563. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5564. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5565. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5566. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5567. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5568. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5569. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5570. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5571. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5572. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5573. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5574. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5575. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5576. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5577. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5578. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5579. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5580. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5581. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5582. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5583. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5584. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5585. ));
  5586. },
  5587. loadTestFontId: 0,
  5588. loadingContext: {
  5589. requests: [],
  5590. nextRequestId: 0
  5591. },
  5592. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5593. if (isWorker) {
  5594. return false;
  5595. }
  5596. // User agent string sniffing is bad, but there is no reliable way to tell
  5597. // if font is fully loaded and ready to be used with canvas.
  5598. var userAgent = window.navigator.userAgent;
  5599. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5600. if (m && m[1] >= 14) {
  5601. return true;
  5602. }
  5603. // TODO other browsers
  5604. if (userAgent === 'node') {
  5605. return true;
  5606. }
  5607. return false;
  5608. })(),
  5609. nativeFontFaces: [],
  5610. isFontLoadingAPISupported: !isWorker && !!document.fonts,
  5611. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  5612. this.nativeFontFaces.push(nativeFontFace);
  5613. document.fonts.add(nativeFontFace);
  5614. },
  5615. bind: function fontLoaderBind(fonts, callback) {
  5616. assert(!isWorker, 'bind() shall be called from main thread');
  5617. var rules = [];
  5618. var fontsToLoad = [];
  5619. var fontLoadPromises = [];
  5620. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5621. var font = fonts[i];
  5622. // Add the font to the DOM only once or skip if the font
  5623. // is already loaded.
  5624. if (font.attached || font.loading === false) {
  5625. continue;
  5626. }
  5627. font.attached = true;
  5628. if (this.isFontLoadingAPISupported) {
  5629. var nativeFontFace = font.createNativeFontFace();
  5630. if (nativeFontFace) {
  5631. fontLoadPromises.push(nativeFontFace.loaded);
  5632. }
  5633. } else {
  5634. var rule = font.bindDOM();
  5635. if (rule) {
  5636. rules.push(rule);
  5637. fontsToLoad.push(font);
  5638. }
  5639. }
  5640. }
  5641. var request = FontLoader.queueLoadingCallback(callback);
  5642. if (this.isFontLoadingAPISupported) {
  5643. Promise.all(fontsToLoad).then(function() {
  5644. request.complete();
  5645. });
  5646. } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5647. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5648. } else {
  5649. request.complete();
  5650. }
  5651. },
  5652. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5653. function LoadLoader_completeRequest() {
  5654. assert(!request.end, 'completeRequest() cannot be called twice');
  5655. request.end = Date.now();
  5656. // sending all completed requests in order how they were queued
  5657. while (context.requests.length > 0 && context.requests[0].end) {
  5658. var otherRequest = context.requests.shift();
  5659. setTimeout(otherRequest.callback, 0);
  5660. }
  5661. }
  5662. var context = FontLoader.loadingContext;
  5663. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5664. var request = {
  5665. id: requestId,
  5666. complete: LoadLoader_completeRequest,
  5667. callback: callback,
  5668. started: Date.now()
  5669. };
  5670. context.requests.push(request);
  5671. return request;
  5672. },
  5673. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5674. fonts,
  5675. request) {
  5676. /** Hack begin */
  5677. // There's currently no event when a font has finished downloading so the
  5678. // following code is a dirty hack to 'guess' when a font is
  5679. // ready. It's assumed fonts are loaded in order, so add a known test
  5680. // font after the desired fonts and then test for the loading of that
  5681. // test font.
  5682. function int32(data, offset) {
  5683. return (data.charCodeAt(offset) << 24) |
  5684. (data.charCodeAt(offset + 1) << 16) |
  5685. (data.charCodeAt(offset + 2) << 8) |
  5686. (data.charCodeAt(offset + 3) & 0xff);
  5687. }
  5688. function spliceString(s, offset, remove, insert) {
  5689. var chunk1 = s.substr(0, offset);
  5690. var chunk2 = s.substr(offset + remove);
  5691. return chunk1 + insert + chunk2;
  5692. }
  5693. var i, ii;
  5694. var canvas = document.createElement('canvas');
  5695. canvas.width = 1;
  5696. canvas.height = 1;
  5697. var ctx = canvas.getContext('2d');
  5698. var called = 0;
  5699. function isFontReady(name, callback) {
  5700. called++;
  5701. // With setTimeout clamping this gives the font ~100ms to load.
  5702. if(called > 30) {
  5703. warn('Load test font never loaded.');
  5704. callback();
  5705. return;
  5706. }
  5707. ctx.font = '30px ' + name;
  5708. ctx.fillText('.', 0, 20);
  5709. var imageData = ctx.getImageData(0, 0, 1, 1);
  5710. if (imageData.data[3] > 0) {
  5711. callback();
  5712. return;
  5713. }
  5714. setTimeout(isFontReady.bind(null, name, callback));
  5715. }
  5716. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5717. // Chromium seems to cache fonts based on a hash of the actual font data,
  5718. // so the font must be modified for each load test else it will appear to
  5719. // be loaded already.
  5720. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5721. // font by splitting it in chunks before hand and padding the font id.
  5722. var data = this.loadTestFont;
  5723. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5724. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5725. loadTestFontId);
  5726. // CFF checksum is important for IE, adjusting it
  5727. var CFF_CHECKSUM_OFFSET = 16;
  5728. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5729. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5730. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5731. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5732. }
  5733. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5734. checksum = (checksum - XXXX_VALUE +
  5735. int32(loadTestFontId + 'XXX', i)) | 0;
  5736. }
  5737. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5738. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5739. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5740. url + '}';
  5741. FontLoader.insertRule(rule);
  5742. var names = [];
  5743. for (i = 0, ii = fonts.length; i < ii; i++) {
  5744. names.push(fonts[i].loadedName);
  5745. }
  5746. names.push(loadTestFontId);
  5747. var div = document.createElement('div');
  5748. div.setAttribute('style',
  5749. 'visibility: hidden;' +
  5750. 'width: 10px; height: 10px;' +
  5751. 'position: absolute; top: 0px; left: 0px;');
  5752. for (i = 0, ii = names.length; i < ii; ++i) {
  5753. var span = document.createElement('span');
  5754. span.textContent = 'Hi';
  5755. span.style.fontFamily = names[i];
  5756. div.appendChild(span);
  5757. }
  5758. document.body.appendChild(div);
  5759. isFontReady(loadTestFontId, function() {
  5760. document.body.removeChild(div);
  5761. request.complete();
  5762. });
  5763. /** Hack end */
  5764. }
  5765. };
  5766. var FontFaceObject = (function FontFaceObjectClosure() {
  5767. function FontFaceObject(name, file, properties) {
  5768. this.compiledGlyphs = {};
  5769. if (arguments.length === 1) {
  5770. // importing translated data
  5771. var data = arguments[0];
  5772. for (var i in data) {
  5773. this[i] = data[i];
  5774. }
  5775. return;
  5776. }
  5777. }
  5778. FontFaceObject.prototype = {
  5779. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  5780. if (!this.data) {
  5781. return null;
  5782. }
  5783. if (PDFJS.disableFontFace) {
  5784. this.disableFontFace = true;
  5785. return null;
  5786. }
  5787. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  5788. FontLoader.addNativeFontFace(nativeFontFace);
  5789. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5790. globalScope['FontInspector'].enabled) {
  5791. globalScope['FontInspector'].fontAdded(this);
  5792. }
  5793. return nativeFontFace;
  5794. },
  5795. bindDOM: function FontFaceObject_bindDOM() {
  5796. if (!this.data) {
  5797. return null;
  5798. }
  5799. if (PDFJS.disableFontFace) {
  5800. this.disableFontFace = true;
  5801. return null;
  5802. }
  5803. var data = bytesToString(new Uint8Array(this.data));
  5804. var fontName = this.loadedName;
  5805. // Add the font-face rule to the document
  5806. var url = ('url(data:' + this.mimetype + ';base64,' +
  5807. window.btoa(data) + ');');
  5808. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  5809. FontLoader.insertRule(rule);
  5810. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5811. globalScope['FontInspector'].enabled) {
  5812. globalScope['FontInspector'].fontAdded(this, url);
  5813. }
  5814. return rule;
  5815. },
  5816. getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
  5817. if (!(character in this.compiledGlyphs)) {
  5818. var js = objs.get(this.loadedName + '_path_' + character);
  5819. /*jshint -W054 */
  5820. this.compiledGlyphs[character] = new Function('c', 'size', js);
  5821. }
  5822. return this.compiledGlyphs[character];
  5823. }
  5824. };
  5825. return FontFaceObject;
  5826. })();
  5827. var ANNOT_MIN_SIZE = 10; // px
  5828. var AnnotationUtils = (function AnnotationUtilsClosure() {
  5829. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  5830. function setTextStyles(element, item, fontObj) {
  5831. var style = element.style;
  5832. style.fontSize = item.fontSize + 'px';
  5833. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  5834. if (!fontObj) {
  5835. return;
  5836. }
  5837. style.fontWeight = fontObj.black ?
  5838. (fontObj.bold ? 'bolder' : 'bold') :
  5839. (fontObj.bold ? 'bold' : 'normal');
  5840. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  5841. var fontName = fontObj.loadedName;
  5842. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  5843. // Use a reasonable default font if the font doesn't specify a fallback
  5844. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  5845. style.fontFamily = fontFamily + fallbackName;
  5846. }
  5847. function initContainer(item, drawBorder) {
  5848. var container = document.createElement('section');
  5849. var cstyle = container.style;
  5850. var width = item.rect[2] - item.rect[0];
  5851. var height = item.rect[3] - item.rect[1];
  5852. var bWidth = item.borderWidth || 0;
  5853. if (bWidth) {
  5854. width = width - 2 * bWidth;
  5855. height = height - 2 * bWidth;
  5856. cstyle.borderWidth = bWidth + 'px';
  5857. var color = item.color;
  5858. if (drawBorder && color) {
  5859. cstyle.borderStyle = 'solid';
  5860. cstyle.borderColor = Util.makeCssRgb(Math.round(color[0] * 255),
  5861. Math.round(color[1] * 255),
  5862. Math.round(color[2] * 255));
  5863. }
  5864. }
  5865. cstyle.width = width + 'px';
  5866. cstyle.height = height + 'px';
  5867. return container;
  5868. }
  5869. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  5870. var element = document.createElement('div');
  5871. var width = item.rect[2] - item.rect[0];
  5872. var height = item.rect[3] - item.rect[1];
  5873. element.style.width = width + 'px';
  5874. element.style.height = height + 'px';
  5875. element.style.display = 'table';
  5876. var content = document.createElement('div');
  5877. content.textContent = item.fieldValue;
  5878. var textAlignment = item.textAlignment;
  5879. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  5880. content.style.verticalAlign = 'middle';
  5881. content.style.display = 'table-cell';
  5882. var fontObj = item.fontRefName ?
  5883. commonObjs.getData(item.fontRefName) : null;
  5884. setTextStyles(content, item, fontObj);
  5885. element.appendChild(content);
  5886. return element;
  5887. }
  5888. function getHtmlElementForTextAnnotation(item) {
  5889. var rect = item.rect;
  5890. // sanity check because of OOo-generated PDFs
  5891. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  5892. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  5893. }
  5894. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  5895. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  5896. }
  5897. var container = initContainer(item, false);
  5898. container.className = 'annotText';
  5899. var image = document.createElement('img');
  5900. image.style.height = container.style.height;
  5901. image.style.width = container.style.width;
  5902. var iconName = item.name;
  5903. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  5904. iconName.toLowerCase() + '.svg';
  5905. image.alt = '[{{type}} Annotation]';
  5906. image.dataset.l10nId = 'text_annotation_type';
  5907. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  5908. var contentWrapper = document.createElement('div');
  5909. contentWrapper.className = 'annotTextContentWrapper';
  5910. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  5911. contentWrapper.style.top = '-10px';
  5912. var content = document.createElement('div');
  5913. content.className = 'annotTextContent';
  5914. content.setAttribute('hidden', true);
  5915. var i, ii;
  5916. if (item.hasBgColor) {
  5917. var color = item.color;
  5918. // Enlighten the color (70%)
  5919. var BACKGROUND_ENLIGHT = 0.7;
  5920. var r = BACKGROUND_ENLIGHT * (1.0 - color[0]) + color[0];
  5921. var g = BACKGROUND_ENLIGHT * (1.0 - color[1]) + color[1];
  5922. var b = BACKGROUND_ENLIGHT * (1.0 - color[2]) + color[2];
  5923. content.style.backgroundColor = Util.makeCssRgb((r * 255) | 0,
  5924. (g * 255) | 0,
  5925. (b * 255) | 0);
  5926. }
  5927. var title = document.createElement('h1');
  5928. var text = document.createElement('p');
  5929. title.textContent = item.title;
  5930. if (!item.content && !item.title) {
  5931. content.setAttribute('hidden', true);
  5932. } else {
  5933. var e = document.createElement('span');
  5934. var lines = item.content.split(/(?:\r\n?|\n)/);
  5935. for (i = 0, ii = lines.length; i < ii; ++i) {
  5936. var line = lines[i];
  5937. e.appendChild(document.createTextNode(line));
  5938. if (i < (ii - 1)) {
  5939. e.appendChild(document.createElement('br'));
  5940. }
  5941. }
  5942. text.appendChild(e);
  5943. var pinned = false;
  5944. var showAnnotation = function showAnnotation(pin) {
  5945. if (pin) {
  5946. pinned = true;
  5947. }
  5948. if (content.hasAttribute('hidden')) {
  5949. container.style.zIndex += 1;
  5950. content.removeAttribute('hidden');
  5951. }
  5952. };
  5953. var hideAnnotation = function hideAnnotation(unpin) {
  5954. if (unpin) {
  5955. pinned = false;
  5956. }
  5957. if (!content.hasAttribute('hidden') && !pinned) {
  5958. container.style.zIndex -= 1;
  5959. content.setAttribute('hidden', true);
  5960. }
  5961. };
  5962. var toggleAnnotation = function toggleAnnotation() {
  5963. if (pinned) {
  5964. hideAnnotation(true);
  5965. } else {
  5966. showAnnotation(true);
  5967. }
  5968. };
  5969. image.addEventListener('click', function image_clickHandler() {
  5970. toggleAnnotation();
  5971. }, false);
  5972. image.addEventListener('mouseover', function image_mouseOverHandler() {
  5973. showAnnotation();
  5974. }, false);
  5975. image.addEventListener('mouseout', function image_mouseOutHandler() {
  5976. hideAnnotation();
  5977. }, false);
  5978. content.addEventListener('click', function content_clickHandler() {
  5979. hideAnnotation(true);
  5980. }, false);
  5981. }
  5982. content.appendChild(title);
  5983. content.appendChild(text);
  5984. contentWrapper.appendChild(content);
  5985. container.appendChild(image);
  5986. container.appendChild(contentWrapper);
  5987. return container;
  5988. }
  5989. function getHtmlElementForLinkAnnotation(item) {
  5990. var container = initContainer(item, true);
  5991. container.className = 'annotLink';
  5992. var link = document.createElement('a');
  5993. link.href = link.title = item.url || '';
  5994. container.appendChild(link);
  5995. return container;
  5996. }
  5997. function getHtmlElement(data, objs) {
  5998. switch (data.annotationType) {
  5999. case AnnotationType.WIDGET:
  6000. return getHtmlElementForTextWidgetAnnotation(data, objs);
  6001. case AnnotationType.TEXT:
  6002. return getHtmlElementForTextAnnotation(data);
  6003. case AnnotationType.LINK:
  6004. return getHtmlElementForLinkAnnotation(data);
  6005. default:
  6006. throw new Error('Unsupported annotationType: ' + data.annotationType);
  6007. }
  6008. }
  6009. return {
  6010. getHtmlElement: getHtmlElement
  6011. };
  6012. })();
  6013. PDFJS.AnnotationUtils = AnnotationUtils;
  6014. var SVG_DEFAULTS = {
  6015. fontStyle: 'normal',
  6016. fontWeight: 'normal',
  6017. fillColor: '#000000'
  6018. };
  6019. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  6020. var PNG_HEADER =
  6021. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  6022. var CHUNK_WRAPPER_SIZE = 12;
  6023. var crcTable = new Int32Array(256);
  6024. for (var i = 0; i < 256; i++) {
  6025. var c = i;
  6026. for (var h = 0; h < 8; h++) {
  6027. if (c & 1) {
  6028. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  6029. } else {
  6030. c = (c >> 1) & 0x7fffffff;
  6031. }
  6032. }
  6033. crcTable[i] = c;
  6034. }
  6035. function crc32(data, start, end) {
  6036. var crc = -1;
  6037. for (var i = start; i < end; i++) {
  6038. var a = (crc ^ data[i]) & 0xff;
  6039. var b = crcTable[a];
  6040. crc = (crc >>> 8) ^ b;
  6041. }
  6042. return crc ^ -1;
  6043. }
  6044. function writePngChunk(type, body, data, offset) {
  6045. var p = offset;
  6046. var len = body.length;
  6047. data[p] = len >> 24 & 0xff;
  6048. data[p + 1] = len >> 16 & 0xff;
  6049. data[p + 2] = len >> 8 & 0xff;
  6050. data[p + 3] = len & 0xff;
  6051. p += 4;
  6052. data[p] = type.charCodeAt(0) & 0xff;
  6053. data[p + 1] = type.charCodeAt(1) & 0xff;
  6054. data[p + 2] = type.charCodeAt(2) & 0xff;
  6055. data[p + 3] = type.charCodeAt(3) & 0xff;
  6056. p += 4;
  6057. data.set(body, p);
  6058. p += body.length;
  6059. var crc = crc32(data, offset + 4, p);
  6060. data[p] = crc >> 24 & 0xff;
  6061. data[p + 1] = crc >> 16 & 0xff;
  6062. data[p + 2] = crc >> 8 & 0xff;
  6063. data[p + 3] = crc & 0xff;
  6064. }
  6065. function adler32(data, start, end) {
  6066. var a = 1;
  6067. var b = 0;
  6068. for (var i = start; i < end; ++i) {
  6069. a = (a + (data[i] & 0xff)) % 65521;
  6070. b = (b + a) % 65521;
  6071. }
  6072. return (b << 16) | a;
  6073. }
  6074. function encode(imgData, kind) {
  6075. var width = imgData.width;
  6076. var height = imgData.height;
  6077. var bitDepth, colorType, lineSize;
  6078. var bytes = imgData.data;
  6079. switch (kind) {
  6080. case ImageKind.GRAYSCALE_1BPP:
  6081. colorType = 0;
  6082. bitDepth = 1;
  6083. lineSize = (width + 7) >> 3;
  6084. break;
  6085. case ImageKind.RGB_24BPP:
  6086. colorType = 2;
  6087. bitDepth = 8;
  6088. lineSize = width * 3;
  6089. break;
  6090. case ImageKind.RGBA_32BPP:
  6091. colorType = 6;
  6092. bitDepth = 8;
  6093. lineSize = width * 4;
  6094. break;
  6095. default:
  6096. throw new Error('invalid format');
  6097. }
  6098. // prefix every row with predictor 0
  6099. var literals = new Uint8Array((1 + lineSize) * height);
  6100. var offsetLiterals = 0, offsetBytes = 0;
  6101. var y, i;
  6102. for (y = 0; y < height; ++y) {
  6103. literals[offsetLiterals++] = 0; // no prediction
  6104. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  6105. offsetLiterals);
  6106. offsetBytes += lineSize;
  6107. offsetLiterals += lineSize;
  6108. }
  6109. if (kind === ImageKind.GRAYSCALE_1BPP) {
  6110. // inverting for B/W
  6111. offsetLiterals = 0;
  6112. for (y = 0; y < height; y++) {
  6113. offsetLiterals++; // skipping predictor
  6114. for (i = 0; i < lineSize; i++) {
  6115. literals[offsetLiterals++] ^= 0xFF;
  6116. }
  6117. }
  6118. }
  6119. var ihdr = new Uint8Array([
  6120. width >> 24 & 0xff,
  6121. width >> 16 & 0xff,
  6122. width >> 8 & 0xff,
  6123. width & 0xff,
  6124. height >> 24 & 0xff,
  6125. height >> 16 & 0xff,
  6126. height >> 8 & 0xff,
  6127. height & 0xff,
  6128. bitDepth, // bit depth
  6129. colorType, // color type
  6130. 0x00, // compression method
  6131. 0x00, // filter method
  6132. 0x00 // interlace method
  6133. ]);
  6134. var len = literals.length;
  6135. var maxBlockLength = 0xFFFF;
  6136. var deflateBlocks = Math.ceil(len / maxBlockLength);
  6137. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  6138. var pi = 0;
  6139. idat[pi++] = 0x78; // compression method and flags
  6140. idat[pi++] = 0x9c; // flags
  6141. var pos = 0;
  6142. while (len > maxBlockLength) {
  6143. // writing non-final DEFLATE blocks type 0 and length of 65535
  6144. idat[pi++] = 0x00;
  6145. idat[pi++] = 0xff;
  6146. idat[pi++] = 0xff;
  6147. idat[pi++] = 0x00;
  6148. idat[pi++] = 0x00;
  6149. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  6150. pi += maxBlockLength;
  6151. pos += maxBlockLength;
  6152. len -= maxBlockLength;
  6153. }
  6154. // writing non-final DEFLATE blocks type 0
  6155. idat[pi++] = 0x01;
  6156. idat[pi++] = len & 0xff;
  6157. idat[pi++] = len >> 8 & 0xff;
  6158. idat[pi++] = (~len & 0xffff) & 0xff;
  6159. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  6160. idat.set(literals.subarray(pos), pi);
  6161. pi += literals.length - pos;
  6162. var adler = adler32(literals, 0, literals.length); // checksum
  6163. idat[pi++] = adler >> 24 & 0xff;
  6164. idat[pi++] = adler >> 16 & 0xff;
  6165. idat[pi++] = adler >> 8 & 0xff;
  6166. idat[pi++] = adler & 0xff;
  6167. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  6168. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  6169. ihdr.length + idat.length;
  6170. var data = new Uint8Array(pngLength);
  6171. var offset = 0;
  6172. data.set(PNG_HEADER, offset);
  6173. offset += PNG_HEADER.length;
  6174. writePngChunk('IHDR', ihdr, data, offset);
  6175. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  6176. writePngChunk('IDATA', idat, data, offset);
  6177. offset += CHUNK_WRAPPER_SIZE + idat.length;
  6178. writePngChunk('IEND', new Uint8Array(0), data, offset);
  6179. return PDFJS.createObjectURL(data, 'image/png');
  6180. }
  6181. return function convertImgDataToPng(imgData) {
  6182. var kind = (imgData.kind === undefined ?
  6183. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  6184. return encode(imgData, kind);
  6185. };
  6186. })();
  6187. var SVGExtraState = (function SVGExtraStateClosure() {
  6188. function SVGExtraState() {
  6189. this.fontSizeScale = 1;
  6190. this.fontWeight = SVG_DEFAULTS.fontWeight;
  6191. this.fontSize = 0;
  6192. this.textMatrix = IDENTITY_MATRIX;
  6193. this.fontMatrix = FONT_IDENTITY_MATRIX;
  6194. this.leading = 0;
  6195. // Current point (in user coordinates)
  6196. this.x = 0;
  6197. this.y = 0;
  6198. // Start of text line (in text coordinates)
  6199. this.lineX = 0;
  6200. this.lineY = 0;
  6201. // Character and word spacing
  6202. this.charSpacing = 0;
  6203. this.wordSpacing = 0;
  6204. this.textHScale = 1;
  6205. this.textRise = 0;
  6206. // Default foreground and background colors
  6207. this.fillColor = SVG_DEFAULTS.fillColor;
  6208. this.strokeColor = '#000000';
  6209. this.fillAlpha = 1;
  6210. this.strokeAlpha = 1;
  6211. this.lineWidth = 1;
  6212. this.lineJoin = '';
  6213. this.lineCap = '';
  6214. this.miterLimit = 0;
  6215. this.dashArray = [];
  6216. this.dashPhase = 0;
  6217. this.dependencies = [];
  6218. // Clipping
  6219. this.clipId = '';
  6220. this.pendingClip = false;
  6221. this.maskId = '';
  6222. }
  6223. SVGExtraState.prototype = {
  6224. clone: function SVGExtraState_clone() {
  6225. return Object.create(this);
  6226. },
  6227. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  6228. this.x = x;
  6229. this.y = y;
  6230. }
  6231. };
  6232. return SVGExtraState;
  6233. })();
  6234. var SVGGraphics = (function SVGGraphicsClosure() {
  6235. function createScratchSVG(width, height) {
  6236. var NS = 'http://www.w3.org/2000/svg';
  6237. var svg = document.createElementNS(NS, 'svg:svg');
  6238. svg.setAttributeNS(null, 'version', '1.1');
  6239. svg.setAttributeNS(null, 'width', width + 'px');
  6240. svg.setAttributeNS(null, 'height', height + 'px');
  6241. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  6242. return svg;
  6243. }
  6244. function opListToTree(opList) {
  6245. var opTree = [];
  6246. var tmp = [];
  6247. var opListLen = opList.length;
  6248. for (var x = 0; x < opListLen; x++) {
  6249. if (opList[x].fn === 'save') {
  6250. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  6251. tmp.push(opTree);
  6252. opTree = opTree[opTree.length - 1].items;
  6253. continue;
  6254. }
  6255. if(opList[x].fn === 'restore') {
  6256. opTree = tmp.pop();
  6257. } else {
  6258. opTree.push(opList[x]);
  6259. }
  6260. }
  6261. return opTree;
  6262. }
  6263. /**
  6264. * Formats float number.
  6265. * @param value {number} number to format.
  6266. * @returns {string}
  6267. */
  6268. function pf(value) {
  6269. if (value === (value | 0)) { // integer number
  6270. return value.toString();
  6271. }
  6272. var s = value.toFixed(10);
  6273. var i = s.length - 1;
  6274. if (s[i] !== '0') {
  6275. return s;
  6276. }
  6277. // removing trailing zeros
  6278. do {
  6279. i--;
  6280. } while (s[i] === '0');
  6281. return s.substr(0, s[i] === '.' ? i : i + 1);
  6282. }
  6283. /**
  6284. * Formats transform matrix. The standard rotation, scale and translate
  6285. * matrices are replaced by their shorter forms, and for identity matrix
  6286. * returns empty string to save the memory.
  6287. * @param m {Array} matrix to format.
  6288. * @returns {string}
  6289. */
  6290. function pm(m) {
  6291. if (m[4] === 0 && m[5] === 0) {
  6292. if (m[1] === 0 && m[2] === 0) {
  6293. if (m[0] === 1 && m[3] === 1) {
  6294. return '';
  6295. }
  6296. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6297. }
  6298. if (m[0] === m[3] && m[1] === -m[2]) {
  6299. var a = Math.acos(m[0]) * 180 / Math.PI;
  6300. return 'rotate(' + pf(a) + ')';
  6301. }
  6302. } else {
  6303. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6304. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6305. }
  6306. }
  6307. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6308. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6309. }
  6310. function SVGGraphics(commonObjs, objs) {
  6311. this.current = new SVGExtraState();
  6312. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6313. this.transformStack = [];
  6314. this.extraStack = [];
  6315. this.commonObjs = commonObjs;
  6316. this.objs = objs;
  6317. this.pendingEOFill = false;
  6318. this.embedFonts = false;
  6319. this.embeddedFonts = {};
  6320. this.cssStyle = null;
  6321. }
  6322. var NS = 'http://www.w3.org/2000/svg';
  6323. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6324. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6325. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6326. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6327. var clipCount = 0;
  6328. var maskCount = 0;
  6329. SVGGraphics.prototype = {
  6330. save: function SVGGraphics_save() {
  6331. this.transformStack.push(this.transformMatrix);
  6332. var old = this.current;
  6333. this.extraStack.push(old);
  6334. this.current = old.clone();
  6335. },
  6336. restore: function SVGGraphics_restore() {
  6337. this.transformMatrix = this.transformStack.pop();
  6338. this.current = this.extraStack.pop();
  6339. this.tgrp = document.createElementNS(NS, 'svg:g');
  6340. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6341. this.pgrp.appendChild(this.tgrp);
  6342. },
  6343. group: function SVGGraphics_group(items) {
  6344. this.save();
  6345. this.executeOpTree(items);
  6346. this.restore();
  6347. },
  6348. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6349. var fnArray = operatorList.fnArray;
  6350. var fnArrayLen = fnArray.length;
  6351. var argsArray = operatorList.argsArray;
  6352. var self = this;
  6353. for (var i = 0; i < fnArrayLen; i++) {
  6354. if (OPS.dependency === fnArray[i]) {
  6355. var deps = argsArray[i];
  6356. for (var n = 0, nn = deps.length; n < nn; n++) {
  6357. var obj = deps[n];
  6358. var common = obj.substring(0, 2) === 'g_';
  6359. var promise;
  6360. if (common) {
  6361. promise = new Promise(function(resolve) {
  6362. self.commonObjs.get(obj, resolve);
  6363. });
  6364. } else {
  6365. promise = new Promise(function(resolve) {
  6366. self.objs.get(obj, resolve);
  6367. });
  6368. }
  6369. this.current.dependencies.push(promise);
  6370. }
  6371. }
  6372. }
  6373. return Promise.all(this.current.dependencies);
  6374. },
  6375. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6376. var transformMatrix = [a, b, c, d, e, f];
  6377. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6378. transformMatrix);
  6379. this.tgrp = document.createElementNS(NS, 'svg:g');
  6380. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6381. },
  6382. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6383. this.svg = createScratchSVG(viewport.width, viewport.height);
  6384. this.viewport = viewport;
  6385. return this.loadDependencies(operatorList).then(function () {
  6386. this.transformMatrix = IDENTITY_MATRIX;
  6387. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6388. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6389. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6390. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6391. this.defs = document.createElementNS(NS, 'svg:defs');
  6392. this.pgrp.appendChild(this.defs);
  6393. this.pgrp.appendChild(this.tgrp);
  6394. this.svg.appendChild(this.pgrp);
  6395. var opTree = this.convertOpList(operatorList);
  6396. this.executeOpTree(opTree);
  6397. return this.svg;
  6398. }.bind(this));
  6399. },
  6400. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6401. var argsArray = operatorList.argsArray;
  6402. var fnArray = operatorList.fnArray;
  6403. var fnArrayLen = fnArray.length;
  6404. var REVOPS = [];
  6405. var opList = [];
  6406. for (var op in OPS) {
  6407. REVOPS[OPS[op]] = op;
  6408. }
  6409. for (var x = 0; x < fnArrayLen; x++) {
  6410. var fnId = fnArray[x];
  6411. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6412. }
  6413. return opListToTree(opList);
  6414. },
  6415. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6416. var opTreeLen = opTree.length;
  6417. for(var x = 0; x < opTreeLen; x++) {
  6418. var fn = opTree[x].fn;
  6419. var fnId = opTree[x].fnId;
  6420. var args = opTree[x].args;
  6421. switch (fnId | 0) {
  6422. case OPS.beginText:
  6423. this.beginText();
  6424. break;
  6425. case OPS.setLeading:
  6426. this.setLeading(args);
  6427. break;
  6428. case OPS.setLeadingMoveText:
  6429. this.setLeadingMoveText(args[0], args[1]);
  6430. break;
  6431. case OPS.setFont:
  6432. this.setFont(args);
  6433. break;
  6434. case OPS.showText:
  6435. this.showText(args[0]);
  6436. break;
  6437. case OPS.showSpacedText:
  6438. this.showText(args[0]);
  6439. break;
  6440. case OPS.endText:
  6441. this.endText();
  6442. break;
  6443. case OPS.moveText:
  6444. this.moveText(args[0], args[1]);
  6445. break;
  6446. case OPS.setCharSpacing:
  6447. this.setCharSpacing(args[0]);
  6448. break;
  6449. case OPS.setWordSpacing:
  6450. this.setWordSpacing(args[0]);
  6451. break;
  6452. case OPS.setTextMatrix:
  6453. this.setTextMatrix(args[0], args[1], args[2],
  6454. args[3], args[4], args[5]);
  6455. break;
  6456. case OPS.setLineWidth:
  6457. this.setLineWidth(args[0]);
  6458. break;
  6459. case OPS.setLineJoin:
  6460. this.setLineJoin(args[0]);
  6461. break;
  6462. case OPS.setLineCap:
  6463. this.setLineCap(args[0]);
  6464. break;
  6465. case OPS.setMiterLimit:
  6466. this.setMiterLimit(args[0]);
  6467. break;
  6468. case OPS.setFillRGBColor:
  6469. this.setFillRGBColor(args[0], args[1], args[2]);
  6470. break;
  6471. case OPS.setStrokeRGBColor:
  6472. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6473. break;
  6474. case OPS.setDash:
  6475. this.setDash(args[0], args[1]);
  6476. break;
  6477. case OPS.setGState:
  6478. this.setGState(args[0]);
  6479. break;
  6480. case OPS.fill:
  6481. this.fill();
  6482. break;
  6483. case OPS.eoFill:
  6484. this.eoFill();
  6485. break;
  6486. case OPS.stroke:
  6487. this.stroke();
  6488. break;
  6489. case OPS.fillStroke:
  6490. this.fillStroke();
  6491. break;
  6492. case OPS.eoFillStroke:
  6493. this.eoFillStroke();
  6494. break;
  6495. case OPS.clip:
  6496. this.clip('nonzero');
  6497. break;
  6498. case OPS.eoClip:
  6499. this.clip('evenodd');
  6500. break;
  6501. case OPS.paintSolidColorImageMask:
  6502. this.paintSolidColorImageMask();
  6503. break;
  6504. case OPS.paintJpegXObject:
  6505. this.paintJpegXObject(args[0], args[1], args[2]);
  6506. break;
  6507. case OPS.paintImageXObject:
  6508. this.paintImageXObject(args[0]);
  6509. break;
  6510. case OPS.paintInlineImageXObject:
  6511. this.paintInlineImageXObject(args[0]);
  6512. break;
  6513. case OPS.paintImageMaskXObject:
  6514. this.paintImageMaskXObject(args[0]);
  6515. break;
  6516. case OPS.paintFormXObjectBegin:
  6517. this.paintFormXObjectBegin(args[0], args[1]);
  6518. break;
  6519. case OPS.paintFormXObjectEnd:
  6520. this.paintFormXObjectEnd();
  6521. break;
  6522. case OPS.closePath:
  6523. this.closePath();
  6524. break;
  6525. case OPS.closeStroke:
  6526. this.closeStroke();
  6527. break;
  6528. case OPS.closeFillStroke:
  6529. this.closeFillStroke();
  6530. break;
  6531. case OPS.nextLine:
  6532. this.nextLine();
  6533. break;
  6534. case OPS.transform:
  6535. this.transform(args[0], args[1], args[2], args[3],
  6536. args[4], args[5]);
  6537. break;
  6538. case OPS.constructPath:
  6539. this.constructPath(args[0], args[1]);
  6540. break;
  6541. case OPS.endPath:
  6542. this.endPath();
  6543. break;
  6544. case 92:
  6545. this.group(opTree[x].items);
  6546. break;
  6547. default:
  6548. warn('Unimplemented method '+ fn);
  6549. break;
  6550. }
  6551. }
  6552. },
  6553. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  6554. this.current.wordSpacing = wordSpacing;
  6555. },
  6556. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  6557. this.current.charSpacing = charSpacing;
  6558. },
  6559. nextLine: function SVGGraphics_nextLine() {
  6560. this.moveText(0, this.current.leading);
  6561. },
  6562. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  6563. var current = this.current;
  6564. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  6565. this.current.x = this.current.lineX = 0;
  6566. this.current.y = this.current.lineY = 0;
  6567. current.xcoords = [];
  6568. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6569. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6570. current.tspan.setAttributeNS(null, 'font-size',
  6571. pf(current.fontSize) + 'px');
  6572. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6573. current.txtElement = document.createElementNS(NS, 'svg:text');
  6574. current.txtElement.appendChild(current.tspan);
  6575. },
  6576. beginText: function SVGGraphics_beginText() {
  6577. this.current.x = this.current.lineX = 0;
  6578. this.current.y = this.current.lineY = 0;
  6579. this.current.textMatrix = IDENTITY_MATRIX;
  6580. this.current.lineMatrix = IDENTITY_MATRIX;
  6581. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6582. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  6583. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  6584. this.current.xcoords = [];
  6585. },
  6586. moveText: function SVGGraphics_moveText(x, y) {
  6587. var current = this.current;
  6588. this.current.x = this.current.lineX += x;
  6589. this.current.y = this.current.lineY += y;
  6590. current.xcoords = [];
  6591. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6592. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6593. current.tspan.setAttributeNS(null, 'font-size',
  6594. pf(current.fontSize) + 'px');
  6595. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6596. },
  6597. showText: function SVGGraphics_showText(glyphs) {
  6598. var current = this.current;
  6599. var font = current.font;
  6600. var fontSize = current.fontSize;
  6601. if (fontSize === 0) {
  6602. return;
  6603. }
  6604. var charSpacing = current.charSpacing;
  6605. var wordSpacing = current.wordSpacing;
  6606. var fontDirection = current.fontDirection;
  6607. var textHScale = current.textHScale * fontDirection;
  6608. var glyphsLength = glyphs.length;
  6609. var vertical = font.vertical;
  6610. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  6611. var x = 0, i;
  6612. for (i = 0; i < glyphsLength; ++i) {
  6613. var glyph = glyphs[i];
  6614. if (glyph === null) {
  6615. // word break
  6616. x += fontDirection * wordSpacing;
  6617. continue;
  6618. } else if (isNum(glyph)) {
  6619. x += -glyph * fontSize * 0.001;
  6620. continue;
  6621. }
  6622. current.xcoords.push(current.x + x * textHScale);
  6623. var width = glyph.width;
  6624. var character = glyph.fontChar;
  6625. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  6626. x += charWidth;
  6627. current.tspan.textContent += character;
  6628. }
  6629. if (vertical) {
  6630. current.y -= x * textHScale;
  6631. } else {
  6632. current.x += x * textHScale;
  6633. }
  6634. current.tspan.setAttributeNS(null, 'x',
  6635. current.xcoords.map(pf).join(' '));
  6636. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6637. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  6638. current.tspan.setAttributeNS(null, 'font-size',
  6639. pf(current.fontSize) + 'px');
  6640. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  6641. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  6642. }
  6643. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  6644. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  6645. }
  6646. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  6647. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  6648. }
  6649. current.txtElement.setAttributeNS(null, 'transform',
  6650. pm(current.textMatrix) +
  6651. ' scale(1, -1)' );
  6652. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  6653. current.txtElement.appendChild(current.tspan);
  6654. current.txtgrp.appendChild(current.txtElement);
  6655. this.tgrp.appendChild(current.txtElement);
  6656. },
  6657. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  6658. this.setLeading(-y);
  6659. this.moveText(x, y);
  6660. },
  6661. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  6662. if (!this.cssStyle) {
  6663. this.cssStyle = document.createElementNS(NS, 'svg:style');
  6664. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  6665. this.defs.appendChild(this.cssStyle);
  6666. }
  6667. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  6668. this.cssStyle.textContent +=
  6669. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  6670. ' src: url(' + url + '); }\n';
  6671. },
  6672. setFont: function SVGGraphics_setFont(details) {
  6673. var current = this.current;
  6674. var fontObj = this.commonObjs.get(details[0]);
  6675. var size = details[1];
  6676. this.current.font = fontObj;
  6677. if (this.embedFonts && fontObj.data &&
  6678. !this.embeddedFonts[fontObj.loadedName]) {
  6679. this.addFontStyle(fontObj);
  6680. this.embeddedFonts[fontObj.loadedName] = fontObj;
  6681. }
  6682. current.fontMatrix = (fontObj.fontMatrix ?
  6683. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  6684. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  6685. (fontObj.bold ? 'bold' : 'normal');
  6686. var italic = fontObj.italic ? 'italic' : 'normal';
  6687. if (size < 0) {
  6688. size = -size;
  6689. current.fontDirection = -1;
  6690. } else {
  6691. current.fontDirection = 1;
  6692. }
  6693. current.fontSize = size;
  6694. current.fontFamily = fontObj.loadedName;
  6695. current.fontWeight = bold;
  6696. current.fontStyle = italic;
  6697. current.tspan = document.createElementNS(NS, 'svg:tspan');
  6698. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  6699. current.xcoords = [];
  6700. },
  6701. endText: function SVGGraphics_endText() {
  6702. if (this.current.pendingClip) {
  6703. this.cgrp.appendChild(this.tgrp);
  6704. this.pgrp.appendChild(this.cgrp);
  6705. } else {
  6706. this.pgrp.appendChild(this.tgrp);
  6707. }
  6708. this.tgrp = document.createElementNS(NS, 'svg:g');
  6709. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6710. },
  6711. // Path properties
  6712. setLineWidth: function SVGGraphics_setLineWidth(width) {
  6713. this.current.lineWidth = width;
  6714. },
  6715. setLineCap: function SVGGraphics_setLineCap(style) {
  6716. this.current.lineCap = LINE_CAP_STYLES[style];
  6717. },
  6718. setLineJoin: function SVGGraphics_setLineJoin(style) {
  6719. this.current.lineJoin = LINE_JOIN_STYLES[style];
  6720. },
  6721. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  6722. this.current.miterLimit = limit;
  6723. },
  6724. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  6725. var color = Util.makeCssRgb(r, g, b);
  6726. this.current.strokeColor = color;
  6727. },
  6728. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  6729. var color = Util.makeCssRgb(r, g, b);
  6730. this.current.fillColor = color;
  6731. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  6732. this.current.xcoords = [];
  6733. },
  6734. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  6735. this.current.dashArray = dashArray;
  6736. this.current.dashPhase = dashPhase;
  6737. },
  6738. constructPath: function SVGGraphics_constructPath(ops, args) {
  6739. var current = this.current;
  6740. var x = current.x, y = current.y;
  6741. current.path = document.createElementNS(NS, 'svg:path');
  6742. var d = [];
  6743. var opLength = ops.length;
  6744. for (var i = 0, j = 0; i < opLength; i++) {
  6745. switch (ops[i] | 0) {
  6746. case OPS.rectangle:
  6747. x = args[j++];
  6748. y = args[j++];
  6749. var width = args[j++];
  6750. var height = args[j++];
  6751. var xw = x + width;
  6752. var yh = y + height;
  6753. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  6754. 'L', pf(x), pf(yh), 'Z');
  6755. break;
  6756. case OPS.moveTo:
  6757. x = args[j++];
  6758. y = args[j++];
  6759. d.push('M', pf(x), pf(y));
  6760. break;
  6761. case OPS.lineTo:
  6762. x = args[j++];
  6763. y = args[j++];
  6764. d.push('L', pf(x) , pf(y));
  6765. break;
  6766. case OPS.curveTo:
  6767. x = args[j + 4];
  6768. y = args[j + 5];
  6769. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  6770. pf(args[j + 3]), pf(x), pf(y));
  6771. j += 6;
  6772. break;
  6773. case OPS.curveTo2:
  6774. x = args[j + 2];
  6775. y = args[j + 3];
  6776. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  6777. pf(args[j + 2]), pf(args[j + 3]));
  6778. j += 4;
  6779. break;
  6780. case OPS.curveTo3:
  6781. x = args[j + 2];
  6782. y = args[j + 3];
  6783. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  6784. pf(x), pf(y));
  6785. j += 4;
  6786. break;
  6787. case OPS.closePath:
  6788. d.push('Z');
  6789. break;
  6790. }
  6791. }
  6792. current.path.setAttributeNS(null, 'd', d.join(' '));
  6793. current.path.setAttributeNS(null, 'stroke-miterlimit',
  6794. pf(current.miterLimit));
  6795. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  6796. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  6797. current.path.setAttributeNS(null, 'stroke-width',
  6798. pf(current.lineWidth) + 'px');
  6799. current.path.setAttributeNS(null, 'stroke-dasharray',
  6800. current.dashArray.map(pf).join(' '));
  6801. current.path.setAttributeNS(null, 'stroke-dashoffset',
  6802. pf(current.dashPhase) + 'px');
  6803. current.path.setAttributeNS(null, 'fill', 'none');
  6804. this.tgrp.appendChild(current.path);
  6805. if (current.pendingClip) {
  6806. this.cgrp.appendChild(this.tgrp);
  6807. this.pgrp.appendChild(this.cgrp);
  6808. } else {
  6809. this.pgrp.appendChild(this.tgrp);
  6810. }
  6811. // Saving a reference in current.element so that it can be addressed
  6812. // in 'fill' and 'stroke'
  6813. current.element = current.path;
  6814. current.setCurrentPoint(x, y);
  6815. },
  6816. endPath: function SVGGraphics_endPath() {
  6817. var current = this.current;
  6818. if (current.pendingClip) {
  6819. this.cgrp.appendChild(this.tgrp);
  6820. this.pgrp.appendChild(this.cgrp);
  6821. } else {
  6822. this.pgrp.appendChild(this.tgrp);
  6823. }
  6824. this.tgrp = document.createElementNS(NS, 'svg:g');
  6825. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6826. },
  6827. clip: function SVGGraphics_clip(type) {
  6828. var current = this.current;
  6829. // Add current path to clipping path
  6830. current.clipId = 'clippath' + clipCount;
  6831. clipCount++;
  6832. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  6833. this.clippath.setAttributeNS(null, 'id', current.clipId);
  6834. var clipElement = current.element.cloneNode();
  6835. if (type === 'evenodd') {
  6836. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  6837. } else {
  6838. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  6839. }
  6840. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6841. this.clippath.appendChild(clipElement);
  6842. this.defs.appendChild(this.clippath);
  6843. // Create a new group with that attribute
  6844. current.pendingClip = true;
  6845. this.cgrp = document.createElementNS(NS, 'svg:g');
  6846. this.cgrp.setAttributeNS(null, 'clip-path',
  6847. 'url(#' + current.clipId + ')');
  6848. this.pgrp.appendChild(this.cgrp);
  6849. },
  6850. closePath: function SVGGraphics_closePath() {
  6851. var current = this.current;
  6852. var d = current.path.getAttributeNS(null, 'd');
  6853. d += 'Z';
  6854. current.path.setAttributeNS(null, 'd', d);
  6855. },
  6856. setLeading: function SVGGraphics_setLeading(leading) {
  6857. this.current.leading = -leading;
  6858. },
  6859. setTextRise: function SVGGraphics_setTextRise(textRise) {
  6860. this.current.textRise = textRise;
  6861. },
  6862. setHScale: function SVGGraphics_setHScale(scale) {
  6863. this.current.textHScale = scale / 100;
  6864. },
  6865. setGState: function SVGGraphics_setGState(states) {
  6866. for (var i = 0, ii = states.length; i < ii; i++) {
  6867. var state = states[i];
  6868. var key = state[0];
  6869. var value = state[1];
  6870. switch (key) {
  6871. case 'LW':
  6872. this.setLineWidth(value);
  6873. break;
  6874. case 'LC':
  6875. this.setLineCap(value);
  6876. break;
  6877. case 'LJ':
  6878. this.setLineJoin(value);
  6879. break;
  6880. case 'ML':
  6881. this.setMiterLimit(value);
  6882. break;
  6883. case 'D':
  6884. this.setDash(value[0], value[1]);
  6885. break;
  6886. case 'RI':
  6887. break;
  6888. case 'FL':
  6889. break;
  6890. case 'Font':
  6891. this.setFont(value);
  6892. break;
  6893. case 'CA':
  6894. break;
  6895. case 'ca':
  6896. break;
  6897. case 'BM':
  6898. break;
  6899. case 'SMask':
  6900. break;
  6901. }
  6902. }
  6903. },
  6904. fill: function SVGGraphics_fill() {
  6905. var current = this.current;
  6906. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6907. },
  6908. stroke: function SVGGraphics_stroke() {
  6909. var current = this.current;
  6910. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  6911. current.element.setAttributeNS(null, 'fill', 'none');
  6912. },
  6913. eoFill: function SVGGraphics_eoFill() {
  6914. var current = this.current;
  6915. current.element.setAttributeNS(null, 'fill', current.fillColor);
  6916. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6917. },
  6918. fillStroke: function SVGGraphics_fillStroke() {
  6919. // Order is important since stroke wants fill to be none.
  6920. // First stroke, then if fill needed, it will be overwritten.
  6921. this.stroke();
  6922. this.fill();
  6923. },
  6924. eoFillStroke: function SVGGraphics_eoFillStroke() {
  6925. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  6926. this.fillStroke();
  6927. },
  6928. closeStroke: function SVGGraphics_closeStroke() {
  6929. this.closePath();
  6930. this.stroke();
  6931. },
  6932. closeFillStroke: function SVGGraphics_closeFillStroke() {
  6933. this.closePath();
  6934. this.fillStroke();
  6935. },
  6936. paintSolidColorImageMask:
  6937. function SVGGraphics_paintSolidColorImageMask() {
  6938. var current = this.current;
  6939. var rect = document.createElementNS(NS, 'svg:rect');
  6940. rect.setAttributeNS(null, 'x', '0');
  6941. rect.setAttributeNS(null, 'y', '0');
  6942. rect.setAttributeNS(null, 'width', '1px');
  6943. rect.setAttributeNS(null, 'height', '1px');
  6944. rect.setAttributeNS(null, 'fill', current.fillColor);
  6945. this.tgrp.appendChild(rect);
  6946. },
  6947. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  6948. var current = this.current;
  6949. var imgObj = this.objs.get(objId);
  6950. var imgEl = document.createElementNS(NS, 'svg:image');
  6951. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  6952. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  6953. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  6954. imgEl.setAttributeNS(null, 'x', '0');
  6955. imgEl.setAttributeNS(null, 'y', pf(-h));
  6956. imgEl.setAttributeNS(null, 'transform',
  6957. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  6958. this.tgrp.appendChild(imgEl);
  6959. if (current.pendingClip) {
  6960. this.cgrp.appendChild(this.tgrp);
  6961. this.pgrp.appendChild(this.cgrp);
  6962. } else {
  6963. this.pgrp.appendChild(this.tgrp);
  6964. }
  6965. },
  6966. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  6967. var imgData = this.objs.get(objId);
  6968. if (!imgData) {
  6969. warn('Dependent image isn\'t ready yet');
  6970. return;
  6971. }
  6972. this.paintInlineImageXObject(imgData);
  6973. },
  6974. paintInlineImageXObject:
  6975. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  6976. var current = this.current;
  6977. var width = imgData.width;
  6978. var height = imgData.height;
  6979. var imgSrc = convertImgDataToPng(imgData);
  6980. var cliprect = document.createElementNS(NS, 'svg:rect');
  6981. cliprect.setAttributeNS(null, 'x', '0');
  6982. cliprect.setAttributeNS(null, 'y', '0');
  6983. cliprect.setAttributeNS(null, 'width', pf(width));
  6984. cliprect.setAttributeNS(null, 'height', pf(height));
  6985. current.element = cliprect;
  6986. this.clip('nonzero');
  6987. var imgEl = document.createElementNS(NS, 'svg:image');
  6988. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  6989. imgEl.setAttributeNS(null, 'x', '0');
  6990. imgEl.setAttributeNS(null, 'y', pf(-height));
  6991. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  6992. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  6993. imgEl.setAttributeNS(null, 'transform',
  6994. 'scale(' + pf(1 / width) + ' ' +
  6995. pf(-1 / height) + ')');
  6996. if (mask) {
  6997. mask.appendChild(imgEl);
  6998. } else {
  6999. this.tgrp.appendChild(imgEl);
  7000. }
  7001. if (current.pendingClip) {
  7002. this.cgrp.appendChild(this.tgrp);
  7003. this.pgrp.appendChild(this.cgrp);
  7004. } else {
  7005. this.pgrp.appendChild(this.tgrp);
  7006. }
  7007. },
  7008. paintImageMaskXObject:
  7009. function SVGGraphics_paintImageMaskXObject(imgData) {
  7010. var current = this.current;
  7011. var width = imgData.width;
  7012. var height = imgData.height;
  7013. var fillColor = current.fillColor;
  7014. current.maskId = 'mask' + maskCount++;
  7015. var mask = document.createElementNS(NS, 'svg:mask');
  7016. mask.setAttributeNS(null, 'id', current.maskId);
  7017. var rect = document.createElementNS(NS, 'svg:rect');
  7018. rect.setAttributeNS(null, 'x', '0');
  7019. rect.setAttributeNS(null, 'y', '0');
  7020. rect.setAttributeNS(null, 'width', pf(width));
  7021. rect.setAttributeNS(null, 'height', pf(height));
  7022. rect.setAttributeNS(null, 'fill', fillColor);
  7023. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  7024. this.defs.appendChild(mask);
  7025. this.tgrp.appendChild(rect);
  7026. this.paintInlineImageXObject(imgData, mask);
  7027. },
  7028. paintFormXObjectBegin:
  7029. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  7030. this.save();
  7031. if (isArray(matrix) && matrix.length === 6) {
  7032. this.transform(matrix[0], matrix[1], matrix[2],
  7033. matrix[3], matrix[4], matrix[5]);
  7034. }
  7035. if (isArray(bbox) && bbox.length === 4) {
  7036. var width = bbox[2] - bbox[0];
  7037. var height = bbox[3] - bbox[1];
  7038. var cliprect = document.createElementNS(NS, 'svg:rect');
  7039. cliprect.setAttributeNS(null, 'x', bbox[0]);
  7040. cliprect.setAttributeNS(null, 'y', bbox[1]);
  7041. cliprect.setAttributeNS(null, 'width', pf(width));
  7042. cliprect.setAttributeNS(null, 'height', pf(height));
  7043. this.current.element = cliprect;
  7044. this.clip('nonzero');
  7045. this.endPath();
  7046. }
  7047. },
  7048. paintFormXObjectEnd:
  7049. function SVGGraphics_paintFormXObjectEnd() {
  7050. this.restore();
  7051. }
  7052. };
  7053. return SVGGraphics;
  7054. })();
  7055. PDFJS.SVGGraphics = SVGGraphics;
  7056. var NetworkManager = (function NetworkManagerClosure() {
  7057. var OK_RESPONSE = 200;
  7058. var PARTIAL_CONTENT_RESPONSE = 206;
  7059. function NetworkManager(url, args) {
  7060. this.url = url;
  7061. args = args || {};
  7062. this.isHttp = /^https?:/i.test(url);
  7063. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  7064. this.withCredentials = args.withCredentials || false;
  7065. this.getXhr = args.getXhr ||
  7066. function NetworkManager_getXhr() {
  7067. return new XMLHttpRequest();
  7068. };
  7069. this.currXhrId = 0;
  7070. this.pendingRequests = {};
  7071. this.loadedRequests = {};
  7072. }
  7073. function getArrayBuffer(xhr) {
  7074. var data = xhr.response;
  7075. if (typeof data !== 'string') {
  7076. return data;
  7077. }
  7078. var length = data.length;
  7079. var array = new Uint8Array(length);
  7080. for (var i = 0; i < length; i++) {
  7081. array[i] = data.charCodeAt(i) & 0xFF;
  7082. }
  7083. return array.buffer;
  7084. }
  7085. NetworkManager.prototype = {
  7086. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  7087. var args = {
  7088. begin: begin,
  7089. end: end
  7090. };
  7091. for (var prop in listeners) {
  7092. args[prop] = listeners[prop];
  7093. }
  7094. return this.request(args);
  7095. },
  7096. requestFull: function NetworkManager_requestFull(listeners) {
  7097. return this.request(listeners);
  7098. },
  7099. request: function NetworkManager_request(args) {
  7100. var xhr = this.getXhr();
  7101. var xhrId = this.currXhrId++;
  7102. var pendingRequest = this.pendingRequests[xhrId] = {
  7103. xhr: xhr
  7104. };
  7105. xhr.open('GET', this.url);
  7106. xhr.withCredentials = this.withCredentials;
  7107. for (var property in this.httpHeaders) {
  7108. var value = this.httpHeaders[property];
  7109. if (typeof value === 'undefined') {
  7110. continue;
  7111. }
  7112. xhr.setRequestHeader(property, value);
  7113. }
  7114. if (this.isHttp && 'begin' in args && 'end' in args) {
  7115. var rangeStr = args.begin + '-' + (args.end - 1);
  7116. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  7117. pendingRequest.expectedStatus = 206;
  7118. } else {
  7119. pendingRequest.expectedStatus = 200;
  7120. }
  7121. if (args.onProgressiveData) {
  7122. // Some legacy browsers might throw an exception.
  7123. try {
  7124. xhr.responseType = 'moz-chunked-arraybuffer';
  7125. } catch(e) {}
  7126. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  7127. pendingRequest.onProgressiveData = args.onProgressiveData;
  7128. pendingRequest.mozChunked = true;
  7129. } else {
  7130. xhr.responseType = 'arraybuffer';
  7131. }
  7132. } else {
  7133. xhr.responseType = 'arraybuffer';
  7134. }
  7135. if (args.onError) {
  7136. xhr.onerror = function(evt) {
  7137. args.onError(xhr.status);
  7138. };
  7139. }
  7140. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  7141. xhr.onprogress = this.onProgress.bind(this, xhrId);
  7142. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  7143. pendingRequest.onDone = args.onDone;
  7144. pendingRequest.onError = args.onError;
  7145. pendingRequest.onProgress = args.onProgress;
  7146. xhr.send(null);
  7147. return xhrId;
  7148. },
  7149. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  7150. var pendingRequest = this.pendingRequests[xhrId];
  7151. if (!pendingRequest) {
  7152. // Maybe abortRequest was called...
  7153. return;
  7154. }
  7155. if (pendingRequest.mozChunked) {
  7156. var chunk = getArrayBuffer(pendingRequest.xhr);
  7157. pendingRequest.onProgressiveData(chunk);
  7158. }
  7159. var onProgress = pendingRequest.onProgress;
  7160. if (onProgress) {
  7161. onProgress(evt);
  7162. }
  7163. },
  7164. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  7165. var pendingRequest = this.pendingRequests[xhrId];
  7166. if (!pendingRequest) {
  7167. // Maybe abortRequest was called...
  7168. return;
  7169. }
  7170. var xhr = pendingRequest.xhr;
  7171. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  7172. pendingRequest.onHeadersReceived();
  7173. delete pendingRequest.onHeadersReceived;
  7174. }
  7175. if (xhr.readyState !== 4) {
  7176. return;
  7177. }
  7178. if (!(xhrId in this.pendingRequests)) {
  7179. // The XHR request might have been aborted in onHeadersReceived()
  7180. // callback, in which case we should abort request
  7181. return;
  7182. }
  7183. delete this.pendingRequests[xhrId];
  7184. // success status == 0 can be on ftp, file and other protocols
  7185. if (xhr.status === 0 && this.isHttp) {
  7186. if (pendingRequest.onError) {
  7187. pendingRequest.onError(xhr.status);
  7188. }
  7189. return;
  7190. }
  7191. var xhrStatus = xhr.status || OK_RESPONSE;
  7192. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  7193. // "A server MAY ignore the Range header". This means it's possible to
  7194. // get a 200 rather than a 206 response from a range request.
  7195. var ok_response_on_range_request =
  7196. xhrStatus === OK_RESPONSE &&
  7197. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  7198. if (!ok_response_on_range_request &&
  7199. xhrStatus !== pendingRequest.expectedStatus) {
  7200. if (pendingRequest.onError) {
  7201. pendingRequest.onError(xhr.status);
  7202. }
  7203. return;
  7204. }
  7205. this.loadedRequests[xhrId] = true;
  7206. var chunk = getArrayBuffer(xhr);
  7207. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  7208. var rangeHeader = xhr.getResponseHeader('Content-Range');
  7209. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  7210. var begin = parseInt(matches[1], 10);
  7211. pendingRequest.onDone({
  7212. begin: begin,
  7213. chunk: chunk
  7214. });
  7215. } else if (pendingRequest.onProgressiveData) {
  7216. pendingRequest.onDone(null);
  7217. } else {
  7218. pendingRequest.onDone({
  7219. begin: 0,
  7220. chunk: chunk
  7221. });
  7222. }
  7223. },
  7224. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  7225. for (var xhrId in this.pendingRequests) {
  7226. return true;
  7227. }
  7228. return false;
  7229. },
  7230. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  7231. return this.pendingRequests[xhrId].xhr;
  7232. },
  7233. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  7234. return !!(this.pendingRequests[xhrId].onProgressiveData);
  7235. },
  7236. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  7237. return xhrId in this.pendingRequests;
  7238. },
  7239. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  7240. return xhrId in this.loadedRequests;
  7241. },
  7242. abortAllRequests: function NetworkManager_abortAllRequests() {
  7243. for (var xhrId in this.pendingRequests) {
  7244. this.abortRequest(xhrId | 0);
  7245. }
  7246. },
  7247. abortRequest: function NetworkManager_abortRequest(xhrId) {
  7248. var xhr = this.pendingRequests[xhrId].xhr;
  7249. delete this.pendingRequests[xhrId];
  7250. xhr.abort();
  7251. }
  7252. };
  7253. return NetworkManager;
  7254. })();
  7255. var ChunkedStream = (function ChunkedStreamClosure() {
  7256. function ChunkedStream(length, chunkSize, manager) {
  7257. this.bytes = new Uint8Array(length);
  7258. this.start = 0;
  7259. this.pos = 0;
  7260. this.end = length;
  7261. this.chunkSize = chunkSize;
  7262. this.loadedChunks = [];
  7263. this.numChunksLoaded = 0;
  7264. this.numChunks = Math.ceil(length / chunkSize);
  7265. this.manager = manager;
  7266. this.progressiveDataLength = 0;
  7267. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  7268. }
  7269. // required methods for a stream. if a particular stream does not
  7270. // implement these, an error should be thrown
  7271. ChunkedStream.prototype = {
  7272. getMissingChunks: function ChunkedStream_getMissingChunks() {
  7273. var chunks = [];
  7274. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  7275. if (!this.loadedChunks[chunk]) {
  7276. chunks.push(chunk);
  7277. }
  7278. }
  7279. return chunks;
  7280. },
  7281. getBaseStreams: function ChunkedStream_getBaseStreams() {
  7282. return [this];
  7283. },
  7284. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  7285. return this.numChunksLoaded === this.numChunks;
  7286. },
  7287. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  7288. var end = begin + chunk.byteLength;
  7289. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  7290. // Using this.length is inaccurate here since this.start can be moved
  7291. // See ChunkedStream.moveStart()
  7292. var length = this.bytes.length;
  7293. assert(end % this.chunkSize === 0 || end === length,
  7294. 'Bad end offset: ' + end);
  7295. this.bytes.set(new Uint8Array(chunk), begin);
  7296. var chunkSize = this.chunkSize;
  7297. var beginChunk = Math.floor(begin / chunkSize);
  7298. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7299. var curChunk;
  7300. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7301. if (!this.loadedChunks[curChunk]) {
  7302. this.loadedChunks[curChunk] = true;
  7303. ++this.numChunksLoaded;
  7304. }
  7305. }
  7306. },
  7307. onReceiveProgressiveData:
  7308. function ChunkedStream_onReceiveProgressiveData(data) {
  7309. var position = this.progressiveDataLength;
  7310. var beginChunk = Math.floor(position / this.chunkSize);
  7311. this.bytes.set(new Uint8Array(data), position);
  7312. position += data.byteLength;
  7313. this.progressiveDataLength = position;
  7314. var endChunk = position >= this.end ? this.numChunks :
  7315. Math.floor(position / this.chunkSize);
  7316. var curChunk;
  7317. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7318. if (!this.loadedChunks[curChunk]) {
  7319. this.loadedChunks[curChunk] = true;
  7320. ++this.numChunksLoaded;
  7321. }
  7322. }
  7323. },
  7324. ensureByte: function ChunkedStream_ensureByte(pos) {
  7325. var chunk = Math.floor(pos / this.chunkSize);
  7326. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  7327. return;
  7328. }
  7329. if (!this.loadedChunks[chunk]) {
  7330. throw new MissingDataException(pos, pos + 1);
  7331. }
  7332. this.lastSuccessfulEnsureByteChunk = chunk;
  7333. },
  7334. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  7335. if (begin >= end) {
  7336. return;
  7337. }
  7338. if (end <= this.progressiveDataLength) {
  7339. return;
  7340. }
  7341. var chunkSize = this.chunkSize;
  7342. var beginChunk = Math.floor(begin / chunkSize);
  7343. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7344. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7345. if (!this.loadedChunks[chunk]) {
  7346. throw new MissingDataException(begin, end);
  7347. }
  7348. }
  7349. },
  7350. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  7351. var chunk, n;
  7352. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  7353. if (!this.loadedChunks[chunk]) {
  7354. return chunk;
  7355. }
  7356. }
  7357. // Wrap around to beginning
  7358. for (chunk = 0; chunk < beginChunk; ++chunk) {
  7359. if (!this.loadedChunks[chunk]) {
  7360. return chunk;
  7361. }
  7362. }
  7363. return null;
  7364. },
  7365. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7366. return !!this.loadedChunks[chunk];
  7367. },
  7368. get length() {
  7369. return this.end - this.start;
  7370. },
  7371. get isEmpty() {
  7372. return this.length === 0;
  7373. },
  7374. getByte: function ChunkedStream_getByte() {
  7375. var pos = this.pos;
  7376. if (pos >= this.end) {
  7377. return -1;
  7378. }
  7379. this.ensureByte(pos);
  7380. return this.bytes[this.pos++];
  7381. },
  7382. getUint16: function ChunkedStream_getUint16() {
  7383. var b0 = this.getByte();
  7384. var b1 = this.getByte();
  7385. if (b0 === -1 || b1 === -1) {
  7386. return -1;
  7387. }
  7388. return (b0 << 8) + b1;
  7389. },
  7390. getInt32: function ChunkedStream_getInt32() {
  7391. var b0 = this.getByte();
  7392. var b1 = this.getByte();
  7393. var b2 = this.getByte();
  7394. var b3 = this.getByte();
  7395. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7396. },
  7397. // returns subarray of original buffer
  7398. // should only be read
  7399. getBytes: function ChunkedStream_getBytes(length) {
  7400. var bytes = this.bytes;
  7401. var pos = this.pos;
  7402. var strEnd = this.end;
  7403. if (!length) {
  7404. this.ensureRange(pos, strEnd);
  7405. return bytes.subarray(pos, strEnd);
  7406. }
  7407. var end = pos + length;
  7408. if (end > strEnd) {
  7409. end = strEnd;
  7410. }
  7411. this.ensureRange(pos, end);
  7412. this.pos = end;
  7413. return bytes.subarray(pos, end);
  7414. },
  7415. peekByte: function ChunkedStream_peekByte() {
  7416. var peekedByte = this.getByte();
  7417. this.pos--;
  7418. return peekedByte;
  7419. },
  7420. peekBytes: function ChunkedStream_peekBytes(length) {
  7421. var bytes = this.getBytes(length);
  7422. this.pos -= bytes.length;
  7423. return bytes;
  7424. },
  7425. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7426. this.ensureRange(begin, end);
  7427. return this.bytes.subarray(begin, end);
  7428. },
  7429. skip: function ChunkedStream_skip(n) {
  7430. if (!n) {
  7431. n = 1;
  7432. }
  7433. this.pos += n;
  7434. },
  7435. reset: function ChunkedStream_reset() {
  7436. this.pos = this.start;
  7437. },
  7438. moveStart: function ChunkedStream_moveStart() {
  7439. this.start = this.pos;
  7440. },
  7441. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7442. this.ensureRange(start, start + length);
  7443. function ChunkedStreamSubstream() {}
  7444. ChunkedStreamSubstream.prototype = Object.create(this);
  7445. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7446. var chunkSize = this.chunkSize;
  7447. var beginChunk = Math.floor(this.start / chunkSize);
  7448. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7449. var missingChunks = [];
  7450. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7451. if (!this.loadedChunks[chunk]) {
  7452. missingChunks.push(chunk);
  7453. }
  7454. }
  7455. return missingChunks;
  7456. };
  7457. var subStream = new ChunkedStreamSubstream();
  7458. subStream.pos = subStream.start = start;
  7459. subStream.end = start + length || this.end;
  7460. subStream.dict = dict;
  7461. return subStream;
  7462. },
  7463. isStream: true
  7464. };
  7465. return ChunkedStream;
  7466. })();
  7467. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7468. function ChunkedStreamManager(length, chunkSize, url, args) {
  7469. this.stream = new ChunkedStream(length, chunkSize, this);
  7470. this.length = length;
  7471. this.chunkSize = chunkSize;
  7472. this.url = url;
  7473. this.disableAutoFetch = args.disableAutoFetch;
  7474. var msgHandler = this.msgHandler = args.msgHandler;
  7475. if (args.chunkedViewerLoading) {
  7476. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7477. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  7478. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7479. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  7480. };
  7481. } else {
  7482. var getXhr = function getXhr() {
  7483. return new XMLHttpRequest();
  7484. };
  7485. this.networkManager = new NetworkManager(this.url, {
  7486. getXhr: getXhr,
  7487. httpHeaders: args.httpHeaders,
  7488. withCredentials: args.withCredentials
  7489. });
  7490. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  7491. this.networkManager.requestRange(begin, end, {
  7492. onDone: this.onReceiveData.bind(this),
  7493. onProgress: this.onProgress.bind(this)
  7494. });
  7495. };
  7496. }
  7497. this.currRequestId = 0;
  7498. this.chunksNeededByRequest = {};
  7499. this.requestsByChunk = {};
  7500. this.callbacksByRequest = {};
  7501. this.progressiveDataLength = 0;
  7502. this._loadedStreamCapability = createPromiseCapability();
  7503. if (args.initialData) {
  7504. this.onReceiveData({chunk: args.initialData});
  7505. }
  7506. }
  7507. ChunkedStreamManager.prototype = {
  7508. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  7509. return this._loadedStreamCapability.promise;
  7510. },
  7511. // Get all the chunks that are not yet loaded and groups them into
  7512. // contiguous ranges to load in as few requests as possible
  7513. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  7514. var missingChunks = this.stream.getMissingChunks();
  7515. this.requestChunks(missingChunks);
  7516. return this._loadedStreamCapability.promise;
  7517. },
  7518. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  7519. callback) {
  7520. var requestId = this.currRequestId++;
  7521. var chunksNeeded;
  7522. var i, ii;
  7523. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  7524. for (i = 0, ii = chunks.length; i < ii; i++) {
  7525. if (!this.stream.hasChunk(chunks[i])) {
  7526. chunksNeeded[chunks[i]] = true;
  7527. }
  7528. }
  7529. if (isEmptyObj(chunksNeeded)) {
  7530. if (callback) {
  7531. callback();
  7532. }
  7533. return;
  7534. }
  7535. this.callbacksByRequest[requestId] = callback;
  7536. var chunksToRequest = [];
  7537. for (var chunk in chunksNeeded) {
  7538. chunk = chunk | 0;
  7539. if (!(chunk in this.requestsByChunk)) {
  7540. this.requestsByChunk[chunk] = [];
  7541. chunksToRequest.push(chunk);
  7542. }
  7543. this.requestsByChunk[chunk].push(requestId);
  7544. }
  7545. if (!chunksToRequest.length) {
  7546. return;
  7547. }
  7548. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  7549. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  7550. var groupedChunk = groupedChunksToRequest[i];
  7551. var begin = groupedChunk.beginChunk * this.chunkSize;
  7552. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  7553. this.sendRequest(begin, end);
  7554. }
  7555. },
  7556. getStream: function ChunkedStreamManager_getStream() {
  7557. return this.stream;
  7558. },
  7559. // Loads any chunks in the requested range that are not yet loaded
  7560. requestRange: function ChunkedStreamManager_requestRange(
  7561. begin, end, callback) {
  7562. end = Math.min(end, this.length);
  7563. var beginChunk = this.getBeginChunk(begin);
  7564. var endChunk = this.getEndChunk(end);
  7565. var chunks = [];
  7566. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7567. chunks.push(chunk);
  7568. }
  7569. this.requestChunks(chunks, callback);
  7570. },
  7571. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  7572. callback) {
  7573. ranges = ranges || [];
  7574. var chunksToRequest = [];
  7575. for (var i = 0; i < ranges.length; i++) {
  7576. var beginChunk = this.getBeginChunk(ranges[i].begin);
  7577. var endChunk = this.getEndChunk(ranges[i].end);
  7578. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7579. if (chunksToRequest.indexOf(chunk) < 0) {
  7580. chunksToRequest.push(chunk);
  7581. }
  7582. }
  7583. }
  7584. chunksToRequest.sort(function(a, b) { return a - b; });
  7585. this.requestChunks(chunksToRequest, callback);
  7586. },
  7587. // Groups a sorted array of chunks into as few continguous larger
  7588. // chunks as possible
  7589. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  7590. var groupedChunks = [];
  7591. var beginChunk = -1;
  7592. var prevChunk = -1;
  7593. for (var i = 0; i < chunks.length; ++i) {
  7594. var chunk = chunks[i];
  7595. if (beginChunk < 0) {
  7596. beginChunk = chunk;
  7597. }
  7598. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  7599. groupedChunks.push({ beginChunk: beginChunk,
  7600. endChunk: prevChunk + 1 });
  7601. beginChunk = chunk;
  7602. }
  7603. if (i + 1 === chunks.length) {
  7604. groupedChunks.push({ beginChunk: beginChunk,
  7605. endChunk: chunk + 1 });
  7606. }
  7607. prevChunk = chunk;
  7608. }
  7609. return groupedChunks;
  7610. },
  7611. onProgress: function ChunkedStreamManager_onProgress(args) {
  7612. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  7613. args.loaded);
  7614. this.msgHandler.send('DocProgress', {
  7615. loaded: bytesLoaded,
  7616. total: this.length
  7617. });
  7618. },
  7619. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  7620. var chunk = args.chunk;
  7621. var isProgressive = args.begin === undefined;
  7622. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  7623. var end = begin + chunk.byteLength;
  7624. var beginChunk = Math.floor(begin / this.chunkSize);
  7625. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  7626. Math.ceil(end / this.chunkSize);
  7627. if (isProgressive) {
  7628. this.stream.onReceiveProgressiveData(chunk);
  7629. this.progressiveDataLength = end;
  7630. } else {
  7631. this.stream.onReceiveData(begin, chunk);
  7632. }
  7633. if (this.stream.allChunksLoaded()) {
  7634. this._loadedStreamCapability.resolve(this.stream);
  7635. }
  7636. var loadedRequests = [];
  7637. var i, requestId;
  7638. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  7639. // The server might return more chunks than requested
  7640. var requestIds = this.requestsByChunk[chunk] || [];
  7641. delete this.requestsByChunk[chunk];
  7642. for (i = 0; i < requestIds.length; ++i) {
  7643. requestId = requestIds[i];
  7644. var chunksNeeded = this.chunksNeededByRequest[requestId];
  7645. if (chunk in chunksNeeded) {
  7646. delete chunksNeeded[chunk];
  7647. }
  7648. if (!isEmptyObj(chunksNeeded)) {
  7649. continue;
  7650. }
  7651. loadedRequests.push(requestId);
  7652. }
  7653. }
  7654. // If there are no pending requests, automatically fetch the next
  7655. // unfetched chunk of the PDF
  7656. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  7657. var nextEmptyChunk;
  7658. if (this.stream.numChunksLoaded === 1) {
  7659. // This is a special optimization so that after fetching the first
  7660. // chunk, rather than fetching the second chunk, we fetch the last
  7661. // chunk.
  7662. var lastChunk = this.stream.numChunks - 1;
  7663. if (!this.stream.hasChunk(lastChunk)) {
  7664. nextEmptyChunk = lastChunk;
  7665. }
  7666. } else {
  7667. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  7668. }
  7669. if (isInt(nextEmptyChunk)) {
  7670. this.requestChunks([nextEmptyChunk]);
  7671. }
  7672. }
  7673. for (i = 0; i < loadedRequests.length; ++i) {
  7674. requestId = loadedRequests[i];
  7675. var callback = this.callbacksByRequest[requestId];
  7676. delete this.callbacksByRequest[requestId];
  7677. if (callback) {
  7678. callback();
  7679. }
  7680. }
  7681. this.msgHandler.send('DocProgress', {
  7682. loaded: this.stream.numChunksLoaded * this.chunkSize,
  7683. total: this.length
  7684. });
  7685. },
  7686. onError: function ChunkedStreamManager_onError(err) {
  7687. this._loadedStreamCapability.reject(err);
  7688. },
  7689. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  7690. var chunk = Math.floor(begin / this.chunkSize);
  7691. return chunk;
  7692. },
  7693. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  7694. if (end % this.chunkSize === 0) {
  7695. return end / this.chunkSize;
  7696. }
  7697. // 0 -> 0
  7698. // 1 -> 1
  7699. // 99 -> 1
  7700. // 100 -> 1
  7701. // 101 -> 2
  7702. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  7703. return chunk;
  7704. }
  7705. };
  7706. return ChunkedStreamManager;
  7707. })();
  7708. // The maximum number of bytes fetched per range request
  7709. var RANGE_CHUNK_SIZE = 65536;
  7710. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  7711. var BasePdfManager = (function BasePdfManagerClosure() {
  7712. function BasePdfManager() {
  7713. throw new Error('Cannot initialize BaseManagerManager');
  7714. }
  7715. BasePdfManager.prototype = {
  7716. onLoadedStream: function BasePdfManager_onLoadedStream() {
  7717. throw new NotImplementedException();
  7718. },
  7719. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  7720. return this.ensure(this.pdfDocument, prop, args);
  7721. },
  7722. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  7723. return this.ensure(this.pdfDocument.xref, prop, args);
  7724. },
  7725. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  7726. return this.ensure(this.pdfDocument.catalog, prop, args);
  7727. },
  7728. getPage: function BasePdfManager_pagePage(pageIndex) {
  7729. return this.pdfDocument.getPage(pageIndex);
  7730. },
  7731. cleanup: function BasePdfManager_cleanup() {
  7732. return this.pdfDocument.cleanup();
  7733. },
  7734. ensure: function BasePdfManager_ensure(obj, prop, args) {
  7735. return new NotImplementedException();
  7736. },
  7737. requestRange: function BasePdfManager_ensure(begin, end) {
  7738. return new NotImplementedException();
  7739. },
  7740. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  7741. return new NotImplementedException();
  7742. },
  7743. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  7744. return new NotImplementedException();
  7745. },
  7746. updatePassword: function BasePdfManager_updatePassword(password) {
  7747. this.pdfDocument.xref.password = this.password = password;
  7748. if (this._passwordChangedCapability) {
  7749. this._passwordChangedCapability.resolve();
  7750. }
  7751. },
  7752. passwordChanged: function BasePdfManager_passwordChanged() {
  7753. this._passwordChangedCapability = createPromiseCapability();
  7754. return this._passwordChangedCapability.promise;
  7755. },
  7756. terminate: function BasePdfManager_terminate() {
  7757. return new NotImplementedException();
  7758. }
  7759. };
  7760. return BasePdfManager;
  7761. })();
  7762. var LocalPdfManager = (function LocalPdfManagerClosure() {
  7763. function LocalPdfManager(data, password) {
  7764. var stream = new Stream(data);
  7765. this.pdfDocument = new PDFDocument(this, stream, password);
  7766. this._loadedStreamCapability = createPromiseCapability();
  7767. this._loadedStreamCapability.resolve(stream);
  7768. }
  7769. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7770. LocalPdfManager.prototype.constructor = LocalPdfManager;
  7771. LocalPdfManager.prototype.ensure =
  7772. function LocalPdfManager_ensure(obj, prop, args) {
  7773. return new Promise(function (resolve, reject) {
  7774. try {
  7775. var value = obj[prop];
  7776. var result;
  7777. if (typeof value === 'function') {
  7778. result = value.apply(obj, args);
  7779. } else {
  7780. result = value;
  7781. }
  7782. resolve(result);
  7783. } catch (e) {
  7784. reject(e);
  7785. }
  7786. });
  7787. };
  7788. LocalPdfManager.prototype.requestRange =
  7789. function LocalPdfManager_requestRange(begin, end) {
  7790. return Promise.resolve();
  7791. };
  7792. LocalPdfManager.prototype.requestLoadedStream =
  7793. function LocalPdfManager_requestLoadedStream() {
  7794. };
  7795. LocalPdfManager.prototype.onLoadedStream =
  7796. function LocalPdfManager_getLoadedStream() {
  7797. return this._loadedStreamCapability.promise;
  7798. };
  7799. LocalPdfManager.prototype.terminate =
  7800. function LocalPdfManager_terminate() {
  7801. return;
  7802. };
  7803. return LocalPdfManager;
  7804. })();
  7805. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  7806. function NetworkPdfManager(args, msgHandler) {
  7807. this.msgHandler = msgHandler;
  7808. var params = {
  7809. msgHandler: msgHandler,
  7810. httpHeaders: args.httpHeaders,
  7811. withCredentials: args.withCredentials,
  7812. chunkedViewerLoading: args.chunkedViewerLoading,
  7813. disableAutoFetch: args.disableAutoFetch,
  7814. initialData: args.initialData
  7815. };
  7816. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  7817. args.url, params);
  7818. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  7819. args.password);
  7820. }
  7821. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  7822. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  7823. NetworkPdfManager.prototype.ensure =
  7824. function NetworkPdfManager_ensure(obj, prop, args) {
  7825. var pdfManager = this;
  7826. return new Promise(function (resolve, reject) {
  7827. function ensureHelper() {
  7828. try {
  7829. var result;
  7830. var value = obj[prop];
  7831. if (typeof value === 'function') {
  7832. result = value.apply(obj, args);
  7833. } else {
  7834. result = value;
  7835. }
  7836. resolve(result);
  7837. } catch(e) {
  7838. if (!(e instanceof MissingDataException)) {
  7839. reject(e);
  7840. return;
  7841. }
  7842. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  7843. }
  7844. }
  7845. ensureHelper();
  7846. });
  7847. };
  7848. NetworkPdfManager.prototype.requestRange =
  7849. function NetworkPdfManager_requestRange(begin, end) {
  7850. return new Promise(function (resolve) {
  7851. this.streamManager.requestRange(begin, end, function() {
  7852. resolve();
  7853. });
  7854. }.bind(this));
  7855. };
  7856. NetworkPdfManager.prototype.requestLoadedStream =
  7857. function NetworkPdfManager_requestLoadedStream() {
  7858. this.streamManager.requestAllChunks();
  7859. };
  7860. NetworkPdfManager.prototype.sendProgressiveData =
  7861. function NetworkPdfManager_sendProgressiveData(chunk) {
  7862. this.streamManager.onReceiveData({ chunk: chunk });
  7863. };
  7864. NetworkPdfManager.prototype.onLoadedStream =
  7865. function NetworkPdfManager_getLoadedStream() {
  7866. return this.streamManager.onLoadedStream();
  7867. };
  7868. NetworkPdfManager.prototype.terminate =
  7869. function NetworkPdfManager_terminate() {
  7870. this.streamManager.networkManager.abortAllRequests();
  7871. };
  7872. return NetworkPdfManager;
  7873. })();
  7874. var Page = (function PageClosure() {
  7875. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  7876. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  7877. this.pdfManager = pdfManager;
  7878. this.pageIndex = pageIndex;
  7879. this.pageDict = pageDict;
  7880. this.xref = xref;
  7881. this.ref = ref;
  7882. this.fontCache = fontCache;
  7883. this.idCounters = {
  7884. obj: 0
  7885. };
  7886. this.resourcesPromise = null;
  7887. }
  7888. Page.prototype = {
  7889. getPageProp: function Page_getPageProp(key) {
  7890. return this.pageDict.get(key);
  7891. },
  7892. getInheritedPageProp: function Page_inheritPageProp(key) {
  7893. var dict = this.pageDict;
  7894. var value = dict.get(key);
  7895. while (value === undefined) {
  7896. dict = dict.get('Parent');
  7897. if (!dict) {
  7898. break;
  7899. }
  7900. value = dict.get(key);
  7901. }
  7902. return value;
  7903. },
  7904. get content() {
  7905. return this.getPageProp('Contents');
  7906. },
  7907. get resources() {
  7908. var value = this.getInheritedPageProp('Resources');
  7909. // For robustness: The spec states that a \Resources entry has to be
  7910. // present, but can be empty. Some document omit it still. In this case
  7911. // return an empty dictionary:
  7912. if (value === undefined) {
  7913. value = Dict.empty;
  7914. }
  7915. return shadow(this, 'resources', value);
  7916. },
  7917. get mediaBox() {
  7918. var obj = this.getInheritedPageProp('MediaBox');
  7919. // Reset invalid media box to letter size.
  7920. if (!isArray(obj) || obj.length !== 4) {
  7921. obj = LETTER_SIZE_MEDIABOX;
  7922. }
  7923. return shadow(this, 'mediaBox', obj);
  7924. },
  7925. get view() {
  7926. var mediaBox = this.mediaBox;
  7927. var cropBox = this.getInheritedPageProp('CropBox');
  7928. if (!isArray(cropBox) || cropBox.length !== 4) {
  7929. return shadow(this, 'view', mediaBox);
  7930. }
  7931. // From the spec, 6th ed., p.963:
  7932. // "The crop, bleed, trim, and art boxes should not ordinarily
  7933. // extend beyond the boundaries of the media box. If they do, they are
  7934. // effectively reduced to their intersection with the media box."
  7935. cropBox = Util.intersect(cropBox, mediaBox);
  7936. if (!cropBox) {
  7937. return shadow(this, 'view', mediaBox);
  7938. }
  7939. return shadow(this, 'view', cropBox);
  7940. },
  7941. get annotationRefs() {
  7942. return shadow(this, 'annotationRefs',
  7943. this.getInheritedPageProp('Annots'));
  7944. },
  7945. get rotate() {
  7946. var rotate = this.getInheritedPageProp('Rotate') || 0;
  7947. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  7948. if (rotate % 90 !== 0) {
  7949. rotate = 0;
  7950. } else if (rotate >= 360) {
  7951. rotate = rotate % 360;
  7952. } else if (rotate < 0) {
  7953. // The spec doesn't cover negatives, assume its counterclockwise
  7954. // rotation. The following is the other implementation of modulo.
  7955. rotate = ((rotate % 360) + 360) % 360;
  7956. }
  7957. return shadow(this, 'rotate', rotate);
  7958. },
  7959. getContentStream: function Page_getContentStream() {
  7960. var content = this.content;
  7961. var stream;
  7962. if (isArray(content)) {
  7963. // fetching items
  7964. var xref = this.xref;
  7965. var i, n = content.length;
  7966. var streams = [];
  7967. for (i = 0; i < n; ++i) {
  7968. streams.push(xref.fetchIfRef(content[i]));
  7969. }
  7970. stream = new StreamsSequenceStream(streams);
  7971. } else if (isStream(content)) {
  7972. stream = content;
  7973. } else {
  7974. // replacing non-existent page content with empty one
  7975. stream = new NullStream();
  7976. }
  7977. return stream;
  7978. },
  7979. loadResources: function Page_loadResources(keys) {
  7980. if (!this.resourcesPromise) {
  7981. // TODO: add async getInheritedPageProp and remove this.
  7982. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  7983. }
  7984. return this.resourcesPromise.then(function resourceSuccess() {
  7985. var objectLoader = new ObjectLoader(this.resources.map,
  7986. keys,
  7987. this.xref);
  7988. return objectLoader.load();
  7989. }.bind(this));
  7990. },
  7991. getOperatorList: function Page_getOperatorList(handler, intent) {
  7992. var self = this;
  7993. var pdfManager = this.pdfManager;
  7994. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  7995. []);
  7996. var resourcesPromise = this.loadResources([
  7997. 'ExtGState',
  7998. 'ColorSpace',
  7999. 'Pattern',
  8000. 'Shading',
  8001. 'XObject',
  8002. 'Font'
  8003. // ProcSet
  8004. // Properties
  8005. ]);
  8006. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  8007. handler, this.pageIndex,
  8008. 'p' + this.pageIndex + '_',
  8009. this.idCounters,
  8010. this.fontCache);
  8011. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  8012. var pageListPromise = dataPromises.then(function(data) {
  8013. var contentStream = data[0];
  8014. var opList = new OperatorList(intent, handler, self.pageIndex);
  8015. handler.send('StartRenderPage', {
  8016. transparency: partialEvaluator.hasBlendModes(self.resources),
  8017. pageIndex: self.pageIndex,
  8018. intent: intent
  8019. });
  8020. return partialEvaluator.getOperatorList(contentStream, self.resources,
  8021. opList).then(function () {
  8022. return opList;
  8023. });
  8024. });
  8025. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  8026. return Promise.all([pageListPromise, annotationsPromise]).then(
  8027. function(datas) {
  8028. var pageOpList = datas[0];
  8029. var annotations = datas[1];
  8030. if (annotations.length === 0) {
  8031. pageOpList.flush(true);
  8032. return pageOpList;
  8033. }
  8034. var annotationsReadyPromise = Annotation.appendToOperatorList(
  8035. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  8036. return annotationsReadyPromise.then(function () {
  8037. pageOpList.flush(true);
  8038. return pageOpList;
  8039. });
  8040. });
  8041. },
  8042. extractTextContent: function Page_extractTextContent() {
  8043. var handler = {
  8044. on: function nullHandlerOn() {},
  8045. send: function nullHandlerSend() {}
  8046. };
  8047. var self = this;
  8048. var pdfManager = this.pdfManager;
  8049. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8050. []);
  8051. var resourcesPromise = this.loadResources([
  8052. 'ExtGState',
  8053. 'XObject',
  8054. 'Font'
  8055. ]);
  8056. var dataPromises = Promise.all([contentStreamPromise,
  8057. resourcesPromise]);
  8058. return dataPromises.then(function(data) {
  8059. var contentStream = data[0];
  8060. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  8061. handler, self.pageIndex,
  8062. 'p' + self.pageIndex + '_',
  8063. self.idCounters,
  8064. self.fontCache);
  8065. return partialEvaluator.getTextContent(contentStream,
  8066. self.resources);
  8067. });
  8068. },
  8069. getAnnotationsData: function Page_getAnnotationsData() {
  8070. var annotations = this.annotations;
  8071. var annotationsData = [];
  8072. for (var i = 0, n = annotations.length; i < n; ++i) {
  8073. annotationsData.push(annotations[i].getData());
  8074. }
  8075. return annotationsData;
  8076. },
  8077. get annotations() {
  8078. var annotations = [];
  8079. var annotationRefs = (this.annotationRefs || []);
  8080. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  8081. var annotationRef = annotationRefs[i];
  8082. var annotation = Annotation.fromRef(this.xref, annotationRef);
  8083. if (annotation) {
  8084. annotations.push(annotation);
  8085. }
  8086. }
  8087. return shadow(this, 'annotations', annotations);
  8088. }
  8089. };
  8090. return Page;
  8091. })();
  8092. /**
  8093. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  8094. * `PDFDoc`, this one doesn't have any job management code.
  8095. * Right now there exists one PDFDocument on the main thread + one object
  8096. * for each worker. If there is no worker support enabled, there are two
  8097. * `PDFDocument` objects on the main thread created.
  8098. */
  8099. var PDFDocument = (function PDFDocumentClosure() {
  8100. var FINGERPRINT_FIRST_BYTES = 1024;
  8101. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  8102. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  8103. function PDFDocument(pdfManager, arg, password) {
  8104. if (isStream(arg)) {
  8105. init.call(this, pdfManager, arg, password);
  8106. } else if (isArrayBuffer(arg)) {
  8107. init.call(this, pdfManager, new Stream(arg), password);
  8108. } else {
  8109. error('PDFDocument: Unknown argument type');
  8110. }
  8111. }
  8112. function init(pdfManager, stream, password) {
  8113. assert(stream.length > 0, 'stream must have data');
  8114. this.pdfManager = pdfManager;
  8115. this.stream = stream;
  8116. var xref = new XRef(this.stream, password, pdfManager);
  8117. this.xref = xref;
  8118. }
  8119. function find(stream, needle, limit, backwards) {
  8120. var pos = stream.pos;
  8121. var end = stream.end;
  8122. var strBuf = [];
  8123. if (pos + limit > end) {
  8124. limit = end - pos;
  8125. }
  8126. for (var n = 0; n < limit; ++n) {
  8127. strBuf.push(String.fromCharCode(stream.getByte()));
  8128. }
  8129. var str = strBuf.join('');
  8130. stream.pos = pos;
  8131. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  8132. if (index === -1) {
  8133. return false; /* not found */
  8134. }
  8135. stream.pos += index;
  8136. return true; /* found */
  8137. }
  8138. var DocumentInfoValidators = {
  8139. get entries() {
  8140. // Lazily build this since all the validation functions below are not
  8141. // defined until after this file loads.
  8142. return shadow(this, 'entries', {
  8143. Title: isString,
  8144. Author: isString,
  8145. Subject: isString,
  8146. Keywords: isString,
  8147. Creator: isString,
  8148. Producer: isString,
  8149. CreationDate: isString,
  8150. ModDate: isString,
  8151. Trapped: isName
  8152. });
  8153. }
  8154. };
  8155. PDFDocument.prototype = {
  8156. parse: function PDFDocument_parse(recoveryMode) {
  8157. this.setup(recoveryMode);
  8158. try {
  8159. // checking if AcroForm is present
  8160. this.acroForm = this.catalog.catDict.get('AcroForm');
  8161. if (this.acroForm) {
  8162. this.xfa = this.acroForm.get('XFA');
  8163. var fields = this.acroForm.get('Fields');
  8164. if ((!fields || !isArray(fields) || fields.length === 0) &&
  8165. !this.xfa) {
  8166. // no fields and no XFA -- not a form (?)
  8167. this.acroForm = null;
  8168. }
  8169. }
  8170. } catch (ex) {
  8171. info('Something wrong with AcroForm entry');
  8172. this.acroForm = null;
  8173. }
  8174. },
  8175. get linearization() {
  8176. var linearization = null;
  8177. if (this.stream.length) {
  8178. try {
  8179. linearization = Linearization.create(this.stream);
  8180. } catch (err) {
  8181. if (err instanceof MissingDataException) {
  8182. throw err;
  8183. }
  8184. info(err);
  8185. }
  8186. }
  8187. // shadow the prototype getter with a data property
  8188. return shadow(this, 'linearization', linearization);
  8189. },
  8190. get startXRef() {
  8191. var stream = this.stream;
  8192. var startXRef = 0;
  8193. var linearization = this.linearization;
  8194. if (linearization) {
  8195. // Find end of first obj.
  8196. stream.reset();
  8197. if (find(stream, 'endobj', 1024)) {
  8198. startXRef = stream.pos + 6;
  8199. }
  8200. } else {
  8201. // Find startxref by jumping backward from the end of the file.
  8202. var step = 1024;
  8203. var found = false, pos = stream.end;
  8204. while (!found && pos > 0) {
  8205. pos -= step - 'startxref'.length;
  8206. if (pos < 0) {
  8207. pos = 0;
  8208. }
  8209. stream.pos = pos;
  8210. found = find(stream, 'startxref', step, true);
  8211. }
  8212. if (found) {
  8213. stream.skip(9);
  8214. var ch;
  8215. do {
  8216. ch = stream.getByte();
  8217. } while (Lexer.isSpace(ch));
  8218. var str = '';
  8219. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  8220. str += String.fromCharCode(ch);
  8221. ch = stream.getByte();
  8222. }
  8223. startXRef = parseInt(str, 10);
  8224. if (isNaN(startXRef)) {
  8225. startXRef = 0;
  8226. }
  8227. }
  8228. }
  8229. // shadow the prototype getter with a data property
  8230. return shadow(this, 'startXRef', startXRef);
  8231. },
  8232. get mainXRefEntriesOffset() {
  8233. var mainXRefEntriesOffset = 0;
  8234. var linearization = this.linearization;
  8235. if (linearization) {
  8236. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  8237. }
  8238. // shadow the prototype getter with a data property
  8239. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  8240. },
  8241. // Find the header, remove leading garbage and setup the stream
  8242. // starting from the header.
  8243. checkHeader: function PDFDocument_checkHeader() {
  8244. var stream = this.stream;
  8245. stream.reset();
  8246. if (find(stream, '%PDF-', 1024)) {
  8247. // Found the header, trim off any garbage before it.
  8248. stream.moveStart();
  8249. // Reading file format version
  8250. var MAX_VERSION_LENGTH = 12;
  8251. var version = '', ch;
  8252. while ((ch = stream.getByte()) > 0x20) { // SPACE
  8253. if (version.length >= MAX_VERSION_LENGTH) {
  8254. break;
  8255. }
  8256. version += String.fromCharCode(ch);
  8257. }
  8258. // removing "%PDF-"-prefix
  8259. this.pdfFormatVersion = version.substring(5);
  8260. return;
  8261. }
  8262. // May not be a PDF file, continue anyway.
  8263. },
  8264. parseStartXRef: function PDFDocument_parseStartXRef() {
  8265. var startXRef = this.startXRef;
  8266. this.xref.setStartXRef(startXRef);
  8267. },
  8268. setup: function PDFDocument_setup(recoveryMode) {
  8269. this.xref.parse(recoveryMode);
  8270. this.catalog = new Catalog(this.pdfManager, this.xref);
  8271. },
  8272. get numPages() {
  8273. var linearization = this.linearization;
  8274. var num = linearization ? linearization.numPages : this.catalog.numPages;
  8275. // shadow the prototype getter
  8276. return shadow(this, 'numPages', num);
  8277. },
  8278. get documentInfo() {
  8279. var docInfo = {
  8280. PDFFormatVersion: this.pdfFormatVersion,
  8281. IsAcroFormPresent: !!this.acroForm,
  8282. IsXFAPresent: !!this.xfa
  8283. };
  8284. var infoDict;
  8285. try {
  8286. infoDict = this.xref.trailer.get('Info');
  8287. } catch (err) {
  8288. info('The document information dictionary is invalid.');
  8289. }
  8290. if (infoDict) {
  8291. var validEntries = DocumentInfoValidators.entries;
  8292. // Only fill the document info with valid entries from the spec.
  8293. for (var key in validEntries) {
  8294. if (infoDict.has(key)) {
  8295. var value = infoDict.get(key);
  8296. // Make sure the value conforms to the spec.
  8297. if (validEntries[key](value)) {
  8298. docInfo[key] = (typeof value !== 'string' ?
  8299. value : stringToPDFString(value));
  8300. } else {
  8301. info('Bad value in document info for "' + key + '"');
  8302. }
  8303. }
  8304. }
  8305. }
  8306. return shadow(this, 'documentInfo', docInfo);
  8307. },
  8308. get fingerprint() {
  8309. var xref = this.xref, idArray, hash, fileID = '';
  8310. if (xref.trailer.has('ID')) {
  8311. idArray = xref.trailer.get('ID');
  8312. }
  8313. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  8314. hash = stringToBytes(idArray[0]);
  8315. } else {
  8316. if (this.stream.ensureRange) {
  8317. this.stream.ensureRange(0,
  8318. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  8319. }
  8320. hash = calculateMD5(this.stream.bytes.subarray(0,
  8321. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  8322. }
  8323. for (var i = 0, n = hash.length; i < n; i++) {
  8324. var hex = hash[i].toString(16);
  8325. fileID += hex.length === 1 ? '0' + hex : hex;
  8326. }
  8327. return shadow(this, 'fingerprint', fileID);
  8328. },
  8329. getPage: function PDFDocument_getPage(pageIndex) {
  8330. return this.catalog.getPage(pageIndex);
  8331. },
  8332. cleanup: function PDFDocument_cleanup() {
  8333. return this.catalog.cleanup();
  8334. }
  8335. };
  8336. return PDFDocument;
  8337. })();
  8338. var Name = (function NameClosure() {
  8339. function Name(name) {
  8340. this.name = name;
  8341. }
  8342. Name.prototype = {};
  8343. var nameCache = {};
  8344. Name.get = function Name_get(name) {
  8345. var nameValue = nameCache[name];
  8346. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  8347. };
  8348. return Name;
  8349. })();
  8350. var Cmd = (function CmdClosure() {
  8351. function Cmd(cmd) {
  8352. this.cmd = cmd;
  8353. }
  8354. Cmd.prototype = {};
  8355. var cmdCache = {};
  8356. Cmd.get = function Cmd_get(cmd) {
  8357. var cmdValue = cmdCache[cmd];
  8358. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  8359. };
  8360. return Cmd;
  8361. })();
  8362. var Dict = (function DictClosure() {
  8363. var nonSerializable = function nonSerializableClosure() {
  8364. return nonSerializable; // creating closure on some variable
  8365. };
  8366. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  8367. 'Background': true,
  8368. 'ExtGState': true,
  8369. 'Halftone': true,
  8370. 'Layout': true,
  8371. 'Mask': true,
  8372. 'Pagination': true,
  8373. 'Printing': true
  8374. };
  8375. function isRecursionAllowedFor(dict) {
  8376. if (!isName(dict.Type)) {
  8377. return true;
  8378. }
  8379. var dictType = dict.Type.name;
  8380. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  8381. }
  8382. // xref is optional
  8383. function Dict(xref) {
  8384. // Map should only be used internally, use functions below to access.
  8385. this.map = Object.create(null);
  8386. this.xref = xref;
  8387. this.objId = null;
  8388. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8389. }
  8390. Dict.prototype = {
  8391. assignXref: function Dict_assignXref(newXref) {
  8392. this.xref = newXref;
  8393. },
  8394. // automatically dereferences Ref objects
  8395. get: function Dict_get(key1, key2, key3) {
  8396. var value;
  8397. var xref = this.xref;
  8398. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8399. typeof key2 === 'undefined') {
  8400. return xref ? xref.fetchIfRef(value) : value;
  8401. }
  8402. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8403. typeof key3 === 'undefined') {
  8404. return xref ? xref.fetchIfRef(value) : value;
  8405. }
  8406. value = this.map[key3] || null;
  8407. return xref ? xref.fetchIfRef(value) : value;
  8408. },
  8409. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8410. getAsync: function Dict_getAsync(key1, key2, key3) {
  8411. var value;
  8412. var xref = this.xref;
  8413. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8414. typeof key2 === 'undefined') {
  8415. if (xref) {
  8416. return xref.fetchIfRefAsync(value);
  8417. }
  8418. return Promise.resolve(value);
  8419. }
  8420. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8421. typeof key3 === 'undefined') {
  8422. if (xref) {
  8423. return xref.fetchIfRefAsync(value);
  8424. }
  8425. return Promise.resolve(value);
  8426. }
  8427. value = this.map[key3] || null;
  8428. if (xref) {
  8429. return xref.fetchIfRefAsync(value);
  8430. }
  8431. return Promise.resolve(value);
  8432. },
  8433. // no dereferencing
  8434. getRaw: function Dict_getRaw(key) {
  8435. return this.map[key];
  8436. },
  8437. // creates new map and dereferences all Refs
  8438. getAll: function Dict_getAll() {
  8439. var all = Object.create(null);
  8440. var queue = null;
  8441. var key, obj;
  8442. for (key in this.map) {
  8443. obj = this.get(key);
  8444. if (obj instanceof Dict) {
  8445. if (isRecursionAllowedFor(obj)) {
  8446. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8447. } else {
  8448. all[key] = this.getRaw(key);
  8449. }
  8450. } else {
  8451. all[key] = obj;
  8452. }
  8453. }
  8454. if (!queue) {
  8455. return all;
  8456. }
  8457. // trying to take cyclic references into the account
  8458. var processed = Object.create(null);
  8459. while (queue.length > 0) {
  8460. var item = queue.shift();
  8461. var itemObj = item.obj;
  8462. var objId = itemObj.objId;
  8463. if (objId && objId in processed) {
  8464. item.target[item.key] = processed[objId];
  8465. continue;
  8466. }
  8467. var dereferenced = Object.create(null);
  8468. for (key in itemObj.map) {
  8469. obj = itemObj.get(key);
  8470. if (obj instanceof Dict) {
  8471. if (isRecursionAllowedFor(obj)) {
  8472. queue.push({target: dereferenced, key: key, obj: obj});
  8473. } else {
  8474. dereferenced[key] = itemObj.getRaw(key);
  8475. }
  8476. } else {
  8477. dereferenced[key] = obj;
  8478. }
  8479. }
  8480. if (objId) {
  8481. processed[objId] = dereferenced;
  8482. }
  8483. item.target[item.key] = dereferenced;
  8484. }
  8485. return all;
  8486. },
  8487. set: function Dict_set(key, value) {
  8488. this.map[key] = value;
  8489. },
  8490. has: function Dict_has(key) {
  8491. return key in this.map;
  8492. },
  8493. forEach: function Dict_forEach(callback) {
  8494. for (var key in this.map) {
  8495. callback(key, this.get(key));
  8496. }
  8497. }
  8498. };
  8499. Dict.empty = new Dict(null);
  8500. return Dict;
  8501. })();
  8502. var Ref = (function RefClosure() {
  8503. function Ref(num, gen) {
  8504. this.num = num;
  8505. this.gen = gen;
  8506. }
  8507. Ref.prototype = {
  8508. toString: function Ref_toString() {
  8509. // This function is hot, so we make the string as compact as possible.
  8510. // |this.gen| is almost always zero, so we treat that case specially.
  8511. var str = this.num + 'R';
  8512. if (this.gen !== 0) {
  8513. str += this.gen;
  8514. }
  8515. return str;
  8516. }
  8517. };
  8518. return Ref;
  8519. })();
  8520. // The reference is identified by number and generation.
  8521. // This structure stores only one instance of the reference.
  8522. var RefSet = (function RefSetClosure() {
  8523. function RefSet() {
  8524. this.dict = {};
  8525. }
  8526. RefSet.prototype = {
  8527. has: function RefSet_has(ref) {
  8528. return ref.toString() in this.dict;
  8529. },
  8530. put: function RefSet_put(ref) {
  8531. this.dict[ref.toString()] = true;
  8532. },
  8533. remove: function RefSet_remove(ref) {
  8534. delete this.dict[ref.toString()];
  8535. }
  8536. };
  8537. return RefSet;
  8538. })();
  8539. var RefSetCache = (function RefSetCacheClosure() {
  8540. function RefSetCache() {
  8541. this.dict = Object.create(null);
  8542. }
  8543. RefSetCache.prototype = {
  8544. get: function RefSetCache_get(ref) {
  8545. return this.dict[ref.toString()];
  8546. },
  8547. has: function RefSetCache_has(ref) {
  8548. return ref.toString() in this.dict;
  8549. },
  8550. put: function RefSetCache_put(ref, obj) {
  8551. this.dict[ref.toString()] = obj;
  8552. },
  8553. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  8554. this.dict[ref.toString()] = this.get(aliasRef);
  8555. },
  8556. forEach: function RefSetCache_forEach(fn, thisArg) {
  8557. for (var i in this.dict) {
  8558. fn.call(thisArg, this.dict[i]);
  8559. }
  8560. },
  8561. clear: function RefSetCache_clear() {
  8562. this.dict = Object.create(null);
  8563. }
  8564. };
  8565. return RefSetCache;
  8566. })();
  8567. var Catalog = (function CatalogClosure() {
  8568. function Catalog(pdfManager, xref) {
  8569. this.pdfManager = pdfManager;
  8570. this.xref = xref;
  8571. this.catDict = xref.getCatalogObj();
  8572. this.fontCache = new RefSetCache();
  8573. assert(isDict(this.catDict),
  8574. 'catalog object is not a dictionary');
  8575. this.pagePromises = [];
  8576. }
  8577. Catalog.prototype = {
  8578. get metadata() {
  8579. var streamRef = this.catDict.getRaw('Metadata');
  8580. if (!isRef(streamRef)) {
  8581. return shadow(this, 'metadata', null);
  8582. }
  8583. var encryptMetadata = (!this.xref.encrypt ? false :
  8584. this.xref.encrypt.encryptMetadata);
  8585. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  8586. var metadata;
  8587. if (stream && isDict(stream.dict)) {
  8588. var type = stream.dict.get('Type');
  8589. var subtype = stream.dict.get('Subtype');
  8590. if (isName(type) && isName(subtype) &&
  8591. type.name === 'Metadata' && subtype.name === 'XML') {
  8592. // XXX: This should examine the charset the XML document defines,
  8593. // however since there are currently no real means to decode
  8594. // arbitrary charsets, let's just hope that the author of the PDF
  8595. // was reasonable enough to stick with the XML default charset,
  8596. // which is UTF-8.
  8597. try {
  8598. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  8599. } catch (e) {
  8600. info('Skipping invalid metadata.');
  8601. }
  8602. }
  8603. }
  8604. return shadow(this, 'metadata', metadata);
  8605. },
  8606. get toplevelPagesDict() {
  8607. var pagesObj = this.catDict.get('Pages');
  8608. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  8609. // shadow the prototype getter
  8610. return shadow(this, 'toplevelPagesDict', pagesObj);
  8611. },
  8612. get documentOutline() {
  8613. var obj = null;
  8614. try {
  8615. obj = this.readDocumentOutline();
  8616. } catch (ex) {
  8617. if (ex instanceof MissingDataException) {
  8618. throw ex;
  8619. }
  8620. warn('Unable to read document outline');
  8621. }
  8622. return shadow(this, 'documentOutline', obj);
  8623. },
  8624. readDocumentOutline: function Catalog_readDocumentOutline() {
  8625. var xref = this.xref;
  8626. var obj = this.catDict.get('Outlines');
  8627. var root = { items: [] };
  8628. if (isDict(obj)) {
  8629. obj = obj.getRaw('First');
  8630. var processed = new RefSet();
  8631. if (isRef(obj)) {
  8632. var queue = [{obj: obj, parent: root}];
  8633. // to avoid recursion keeping track of the items
  8634. // in the processed dictionary
  8635. processed.put(obj);
  8636. while (queue.length > 0) {
  8637. var i = queue.shift();
  8638. var outlineDict = xref.fetchIfRef(i.obj);
  8639. if (outlineDict === null) {
  8640. continue;
  8641. }
  8642. if (!outlineDict.has('Title')) {
  8643. error('Invalid outline item');
  8644. }
  8645. var dest = outlineDict.get('A');
  8646. if (dest) {
  8647. dest = dest.get('D');
  8648. } else if (outlineDict.has('Dest')) {
  8649. dest = outlineDict.getRaw('Dest');
  8650. if (isName(dest)) {
  8651. dest = dest.name;
  8652. }
  8653. }
  8654. var title = outlineDict.get('Title');
  8655. var outlineItem = {
  8656. dest: dest,
  8657. title: stringToPDFString(title),
  8658. color: outlineDict.get('C') || [0, 0, 0],
  8659. count: outlineDict.get('Count'),
  8660. bold: !!(outlineDict.get('F') & 2),
  8661. italic: !!(outlineDict.get('F') & 1),
  8662. items: []
  8663. };
  8664. i.parent.items.push(outlineItem);
  8665. obj = outlineDict.getRaw('First');
  8666. if (isRef(obj) && !processed.has(obj)) {
  8667. queue.push({obj: obj, parent: outlineItem});
  8668. processed.put(obj);
  8669. }
  8670. obj = outlineDict.getRaw('Next');
  8671. if (isRef(obj) && !processed.has(obj)) {
  8672. queue.push({obj: obj, parent: i.parent});
  8673. processed.put(obj);
  8674. }
  8675. }
  8676. }
  8677. }
  8678. return (root.items.length > 0 ? root.items : null);
  8679. },
  8680. get numPages() {
  8681. var obj = this.toplevelPagesDict.get('Count');
  8682. assert(
  8683. isInt(obj),
  8684. 'page count in top level pages object is not an integer'
  8685. );
  8686. // shadow the prototype getter
  8687. return shadow(this, 'num', obj);
  8688. },
  8689. get destinations() {
  8690. function fetchDestination(dest) {
  8691. return isDict(dest) ? dest.get('D') : dest;
  8692. }
  8693. var xref = this.xref;
  8694. var dests = {}, nameTreeRef, nameDictionaryRef;
  8695. var obj = this.catDict.get('Names');
  8696. if (obj && obj.has('Dests')) {
  8697. nameTreeRef = obj.getRaw('Dests');
  8698. } else if (this.catDict.has('Dests')) {
  8699. nameDictionaryRef = this.catDict.get('Dests');
  8700. }
  8701. if (nameDictionaryRef) {
  8702. // reading simple destination dictionary
  8703. obj = nameDictionaryRef;
  8704. obj.forEach(function catalogForEach(key, value) {
  8705. if (!value) {
  8706. return;
  8707. }
  8708. dests[key] = fetchDestination(value);
  8709. });
  8710. }
  8711. if (nameTreeRef) {
  8712. var nameTree = new NameTree(nameTreeRef, xref);
  8713. var names = nameTree.getAll();
  8714. for (var name in names) {
  8715. if (!names.hasOwnProperty(name)) {
  8716. continue;
  8717. }
  8718. dests[name] = fetchDestination(names[name]);
  8719. }
  8720. }
  8721. return shadow(this, 'destinations', dests);
  8722. },
  8723. getDestination: function Catalog_getDestination(destinationId) {
  8724. function fetchDestination(dest) {
  8725. return isDict(dest) ? dest.get('D') : dest;
  8726. }
  8727. var xref = this.xref;
  8728. var dest, nameTreeRef, nameDictionaryRef;
  8729. var obj = this.catDict.get('Names');
  8730. if (obj && obj.has('Dests')) {
  8731. nameTreeRef = obj.getRaw('Dests');
  8732. } else if (this.catDict.has('Dests')) {
  8733. nameDictionaryRef = this.catDict.get('Dests');
  8734. }
  8735. if (nameDictionaryRef) {
  8736. // reading simple destination dictionary
  8737. obj = nameDictionaryRef;
  8738. obj.forEach(function catalogForEach(key, value) {
  8739. if (!value) {
  8740. return;
  8741. }
  8742. if (key === destinationId) {
  8743. dest = fetchDestination(value);
  8744. }
  8745. });
  8746. }
  8747. if (nameTreeRef) {
  8748. var nameTree = new NameTree(nameTreeRef, xref);
  8749. dest = fetchDestination(nameTree.get(destinationId));
  8750. }
  8751. return dest;
  8752. },
  8753. get attachments() {
  8754. var xref = this.xref;
  8755. var attachments = null, nameTreeRef;
  8756. var obj = this.catDict.get('Names');
  8757. if (obj) {
  8758. nameTreeRef = obj.getRaw('EmbeddedFiles');
  8759. }
  8760. if (nameTreeRef) {
  8761. var nameTree = new NameTree(nameTreeRef, xref);
  8762. var names = nameTree.getAll();
  8763. for (var name in names) {
  8764. if (!names.hasOwnProperty(name)) {
  8765. continue;
  8766. }
  8767. var fs = new FileSpec(names[name], xref);
  8768. if (!attachments) {
  8769. attachments = {};
  8770. }
  8771. attachments[stringToPDFString(name)] = fs.serializable;
  8772. }
  8773. }
  8774. return shadow(this, 'attachments', attachments);
  8775. },
  8776. get javaScript() {
  8777. var xref = this.xref;
  8778. var obj = this.catDict.get('Names');
  8779. var javaScript = [];
  8780. if (obj && obj.has('JavaScript')) {
  8781. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  8782. var names = nameTree.getAll();
  8783. for (var name in names) {
  8784. if (!names.hasOwnProperty(name)) {
  8785. continue;
  8786. }
  8787. // We don't really use the JavaScript right now. This code is
  8788. // defensive so we don't cause errors on document load.
  8789. var jsDict = names[name];
  8790. if (!isDict(jsDict)) {
  8791. continue;
  8792. }
  8793. var type = jsDict.get('S');
  8794. if (!isName(type) || type.name !== 'JavaScript') {
  8795. continue;
  8796. }
  8797. var js = jsDict.get('JS');
  8798. if (!isString(js) && !isStream(js)) {
  8799. continue;
  8800. }
  8801. if (isStream(js)) {
  8802. js = bytesToString(js.getBytes());
  8803. }
  8804. javaScript.push(stringToPDFString(js));
  8805. }
  8806. }
  8807. // Append OpenAction actions to javaScript array
  8808. var openactionDict = this.catDict.get('OpenAction');
  8809. if (isDict(openactionDict)) {
  8810. var objType = openactionDict.get('Type');
  8811. var actionType = openactionDict.get('S');
  8812. var action = openactionDict.get('N');
  8813. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  8814. isName(actionType) && actionType.name === 'Named' &&
  8815. isName(action) && action.name === 'Print');
  8816. if (isPrintAction) {
  8817. javaScript.push('print(true);');
  8818. }
  8819. }
  8820. return shadow(this, 'javaScript', javaScript);
  8821. },
  8822. cleanup: function Catalog_cleanup() {
  8823. var promises = [];
  8824. this.fontCache.forEach(function (promise) {
  8825. promises.push(promise);
  8826. });
  8827. return Promise.all(promises).then(function (translatedFonts) {
  8828. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  8829. var font = translatedFonts[i].dict;
  8830. delete font.translated;
  8831. }
  8832. this.fontCache.clear();
  8833. }.bind(this));
  8834. },
  8835. getPage: function Catalog_getPage(pageIndex) {
  8836. if (!(pageIndex in this.pagePromises)) {
  8837. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  8838. function (a) {
  8839. var dict = a[0];
  8840. var ref = a[1];
  8841. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  8842. this.fontCache);
  8843. }.bind(this)
  8844. );
  8845. }
  8846. return this.pagePromises[pageIndex];
  8847. },
  8848. getPageDict: function Catalog_getPageDict(pageIndex) {
  8849. var capability = createPromiseCapability();
  8850. var nodesToVisit = [this.catDict.getRaw('Pages')];
  8851. var currentPageIndex = 0;
  8852. var xref = this.xref;
  8853. function next() {
  8854. while (nodesToVisit.length) {
  8855. var currentNode = nodesToVisit.pop();
  8856. if (isRef(currentNode)) {
  8857. xref.fetchAsync(currentNode).then(function (obj) {
  8858. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  8859. if (pageIndex === currentPageIndex) {
  8860. capability.resolve([obj, currentNode]);
  8861. } else {
  8862. currentPageIndex++;
  8863. next();
  8864. }
  8865. return;
  8866. }
  8867. nodesToVisit.push(obj);
  8868. next();
  8869. }, capability.reject);
  8870. return;
  8871. }
  8872. // must be a child page dictionary
  8873. assert(
  8874. isDict(currentNode),
  8875. 'page dictionary kid reference points to wrong type of object'
  8876. );
  8877. var count = currentNode.get('Count');
  8878. // Skip nodes where the page can't be.
  8879. if (currentPageIndex + count <= pageIndex) {
  8880. currentPageIndex += count;
  8881. continue;
  8882. }
  8883. var kids = currentNode.get('Kids');
  8884. assert(isArray(kids), 'page dictionary kids object is not an array');
  8885. if (count === kids.length) {
  8886. // Nodes that don't have the page have been skipped and this is the
  8887. // bottom of the tree which means the page requested must be a
  8888. // descendant of this pages node. Ideally we would just resolve the
  8889. // promise with the page ref here, but there is the case where more
  8890. // pages nodes could link to single a page (see issue 3666 pdf). To
  8891. // handle this push it back on the queue so if it is a pages node it
  8892. // will be descended into.
  8893. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  8894. currentPageIndex = pageIndex;
  8895. continue;
  8896. } else {
  8897. for (var last = kids.length - 1; last >= 0; last--) {
  8898. nodesToVisit.push(kids[last]);
  8899. }
  8900. }
  8901. }
  8902. capability.reject('Page index ' + pageIndex + ' not found.');
  8903. }
  8904. next();
  8905. return capability.promise;
  8906. },
  8907. getPageIndex: function Catalog_getPageIndex(ref) {
  8908. // The page tree nodes have the count of all the leaves below them. To get
  8909. // how many pages are before we just have to walk up the tree and keep
  8910. // adding the count of siblings to the left of the node.
  8911. var xref = this.xref;
  8912. function pagesBeforeRef(kidRef) {
  8913. var total = 0;
  8914. var parentRef;
  8915. return xref.fetchAsync(kidRef).then(function (node) {
  8916. if (!node) {
  8917. return null;
  8918. }
  8919. parentRef = node.getRaw('Parent');
  8920. return node.getAsync('Parent');
  8921. }).then(function (parent) {
  8922. if (!parent) {
  8923. return null;
  8924. }
  8925. return parent.getAsync('Kids');
  8926. }).then(function (kids) {
  8927. if (!kids) {
  8928. return null;
  8929. }
  8930. var kidPromises = [];
  8931. var found = false;
  8932. for (var i = 0; i < kids.length; i++) {
  8933. var kid = kids[i];
  8934. assert(isRef(kid), 'kids must be a ref');
  8935. if (kid.num === kidRef.num) {
  8936. found = true;
  8937. break;
  8938. }
  8939. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  8940. if (kid.has('Count')) {
  8941. var count = kid.get('Count');
  8942. total += count;
  8943. } else { // page leaf node
  8944. total++;
  8945. }
  8946. }));
  8947. }
  8948. if (!found) {
  8949. error('kid ref not found in parents kids');
  8950. }
  8951. return Promise.all(kidPromises).then(function () {
  8952. return [total, parentRef];
  8953. });
  8954. });
  8955. }
  8956. var total = 0;
  8957. function next(ref) {
  8958. return pagesBeforeRef(ref).then(function (args) {
  8959. if (!args) {
  8960. return total;
  8961. }
  8962. var count = args[0];
  8963. var parentRef = args[1];
  8964. total += count;
  8965. return next(parentRef);
  8966. });
  8967. }
  8968. return next(ref);
  8969. }
  8970. };
  8971. return Catalog;
  8972. })();
  8973. var XRef = (function XRefClosure() {
  8974. function XRef(stream, password) {
  8975. this.stream = stream;
  8976. this.entries = [];
  8977. this.xrefstms = {};
  8978. // prepare the XRef cache
  8979. this.cache = [];
  8980. this.password = password;
  8981. this.stats = {
  8982. streamTypes: [],
  8983. fontTypes: []
  8984. };
  8985. }
  8986. XRef.prototype = {
  8987. setStartXRef: function XRef_setStartXRef(startXRef) {
  8988. // Store the starting positions of xref tables as we process them
  8989. // so we can recover from missing data errors
  8990. this.startXRefQueue = [startXRef];
  8991. },
  8992. parse: function XRef_parse(recoveryMode) {
  8993. var trailerDict;
  8994. if (!recoveryMode) {
  8995. trailerDict = this.readXRef();
  8996. } else {
  8997. warn('Indexing all PDF objects');
  8998. trailerDict = this.indexObjects();
  8999. }
  9000. trailerDict.assignXref(this);
  9001. this.trailer = trailerDict;
  9002. var encrypt = trailerDict.get('Encrypt');
  9003. if (encrypt) {
  9004. var ids = trailerDict.get('ID');
  9005. var fileId = (ids && ids.length) ? ids[0] : '';
  9006. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  9007. this.password);
  9008. }
  9009. // get the root dictionary (catalog) object
  9010. if (!(this.root = trailerDict.get('Root'))) {
  9011. error('Invalid root reference');
  9012. }
  9013. },
  9014. processXRefTable: function XRef_processXRefTable(parser) {
  9015. if (!('tableState' in this)) {
  9016. // Stores state of the table as we process it so we can resume
  9017. // from middle of table in case of missing data error
  9018. this.tableState = {
  9019. entryNum: 0,
  9020. streamPos: parser.lexer.stream.pos,
  9021. parserBuf1: parser.buf1,
  9022. parserBuf2: parser.buf2
  9023. };
  9024. }
  9025. var obj = this.readXRefTable(parser);
  9026. // Sanity check
  9027. if (!isCmd(obj, 'trailer')) {
  9028. error('Invalid XRef table: could not find trailer dictionary');
  9029. }
  9030. // Read trailer dictionary, e.g.
  9031. // trailer
  9032. // << /Size 22
  9033. // /Root 20R
  9034. // /Info 10R
  9035. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  9036. // >>
  9037. // The parser goes through the entire stream << ... >> and provides
  9038. // a getter interface for the key-value table
  9039. var dict = parser.getObj();
  9040. // The pdflib PDF generator can generate a nested trailer dictionary
  9041. if (!isDict(dict) && dict.dict) {
  9042. dict = dict.dict;
  9043. }
  9044. if (!isDict(dict)) {
  9045. error('Invalid XRef table: could not parse trailer dictionary');
  9046. }
  9047. delete this.tableState;
  9048. return dict;
  9049. },
  9050. readXRefTable: function XRef_readXRefTable(parser) {
  9051. // Example of cross-reference table:
  9052. // xref
  9053. // 0 1 <-- subsection header (first obj #, obj count)
  9054. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  9055. // 23 2 <-- subsection header ... and so on ...
  9056. // 0000025518 00002 n
  9057. // 0000025635 00000 n
  9058. // trailer
  9059. // ...
  9060. var stream = parser.lexer.stream;
  9061. var tableState = this.tableState;
  9062. stream.pos = tableState.streamPos;
  9063. parser.buf1 = tableState.parserBuf1;
  9064. parser.buf2 = tableState.parserBuf2;
  9065. // Outer loop is over subsection headers
  9066. var obj;
  9067. while (true) {
  9068. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  9069. if (isCmd(obj = parser.getObj(), 'trailer')) {
  9070. break;
  9071. }
  9072. tableState.firstEntryNum = obj;
  9073. tableState.entryCount = parser.getObj();
  9074. }
  9075. var first = tableState.firstEntryNum;
  9076. var count = tableState.entryCount;
  9077. if (!isInt(first) || !isInt(count)) {
  9078. error('Invalid XRef table: wrong types in subsection header');
  9079. }
  9080. // Inner loop is over objects themselves
  9081. for (var i = tableState.entryNum; i < count; i++) {
  9082. tableState.streamPos = stream.pos;
  9083. tableState.entryNum = i;
  9084. tableState.parserBuf1 = parser.buf1;
  9085. tableState.parserBuf2 = parser.buf2;
  9086. var entry = {};
  9087. entry.offset = parser.getObj();
  9088. entry.gen = parser.getObj();
  9089. var type = parser.getObj();
  9090. if (isCmd(type, 'f')) {
  9091. entry.free = true;
  9092. } else if (isCmd(type, 'n')) {
  9093. entry.uncompressed = true;
  9094. }
  9095. // Validate entry obj
  9096. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  9097. !(entry.free || entry.uncompressed)) {
  9098. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  9099. }
  9100. if (!this.entries[i + first]) {
  9101. this.entries[i + first] = entry;
  9102. }
  9103. }
  9104. tableState.entryNum = 0;
  9105. tableState.streamPos = stream.pos;
  9106. tableState.parserBuf1 = parser.buf1;
  9107. tableState.parserBuf2 = parser.buf2;
  9108. delete tableState.firstEntryNum;
  9109. delete tableState.entryCount;
  9110. }
  9111. // Per issue 3248: hp scanners generate bad XRef
  9112. if (first === 1 && this.entries[1] && this.entries[1].free) {
  9113. // shifting the entries
  9114. this.entries.shift();
  9115. }
  9116. // Sanity check: as per spec, first object must be free
  9117. if (this.entries[0] && !this.entries[0].free) {
  9118. error('Invalid XRef table: unexpected first object');
  9119. }
  9120. return obj;
  9121. },
  9122. processXRefStream: function XRef_processXRefStream(stream) {
  9123. if (!('streamState' in this)) {
  9124. // Stores state of the stream as we process it so we can resume
  9125. // from middle of stream in case of missing data error
  9126. var streamParameters = stream.dict;
  9127. var byteWidths = streamParameters.get('W');
  9128. var range = streamParameters.get('Index');
  9129. if (!range) {
  9130. range = [0, streamParameters.get('Size')];
  9131. }
  9132. this.streamState = {
  9133. entryRanges: range,
  9134. byteWidths: byteWidths,
  9135. entryNum: 0,
  9136. streamPos: stream.pos
  9137. };
  9138. }
  9139. this.readXRefStream(stream);
  9140. delete this.streamState;
  9141. return stream.dict;
  9142. },
  9143. readXRefStream: function XRef_readXRefStream(stream) {
  9144. var i, j;
  9145. var streamState = this.streamState;
  9146. stream.pos = streamState.streamPos;
  9147. var byteWidths = streamState.byteWidths;
  9148. var typeFieldWidth = byteWidths[0];
  9149. var offsetFieldWidth = byteWidths[1];
  9150. var generationFieldWidth = byteWidths[2];
  9151. var entryRanges = streamState.entryRanges;
  9152. while (entryRanges.length > 0) {
  9153. var first = entryRanges[0];
  9154. var n = entryRanges[1];
  9155. if (!isInt(first) || !isInt(n)) {
  9156. error('Invalid XRef range fields: ' + first + ', ' + n);
  9157. }
  9158. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  9159. !isInt(generationFieldWidth)) {
  9160. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  9161. }
  9162. for (i = streamState.entryNum; i < n; ++i) {
  9163. streamState.entryNum = i;
  9164. streamState.streamPos = stream.pos;
  9165. var type = 0, offset = 0, generation = 0;
  9166. for (j = 0; j < typeFieldWidth; ++j) {
  9167. type = (type << 8) | stream.getByte();
  9168. }
  9169. // if type field is absent, its default value is 1
  9170. if (typeFieldWidth === 0) {
  9171. type = 1;
  9172. }
  9173. for (j = 0; j < offsetFieldWidth; ++j) {
  9174. offset = (offset << 8) | stream.getByte();
  9175. }
  9176. for (j = 0; j < generationFieldWidth; ++j) {
  9177. generation = (generation << 8) | stream.getByte();
  9178. }
  9179. var entry = {};
  9180. entry.offset = offset;
  9181. entry.gen = generation;
  9182. switch (type) {
  9183. case 0:
  9184. entry.free = true;
  9185. break;
  9186. case 1:
  9187. entry.uncompressed = true;
  9188. break;
  9189. case 2:
  9190. break;
  9191. default:
  9192. error('Invalid XRef entry type: ' + type);
  9193. }
  9194. if (!this.entries[first + i]) {
  9195. this.entries[first + i] = entry;
  9196. }
  9197. }
  9198. streamState.entryNum = 0;
  9199. streamState.streamPos = stream.pos;
  9200. entryRanges.splice(0, 2);
  9201. }
  9202. },
  9203. indexObjects: function XRef_indexObjects() {
  9204. // Simple scan through the PDF content to find objects,
  9205. // trailers and XRef streams.
  9206. function readToken(data, offset) {
  9207. var token = '', ch = data[offset];
  9208. while (ch !== 13 && ch !== 10) {
  9209. if (++offset >= data.length) {
  9210. break;
  9211. }
  9212. token += String.fromCharCode(ch);
  9213. ch = data[offset];
  9214. }
  9215. return token;
  9216. }
  9217. function skipUntil(data, offset, what) {
  9218. var length = what.length, dataLength = data.length;
  9219. var skipped = 0;
  9220. // finding byte sequence
  9221. while (offset < dataLength) {
  9222. var i = 0;
  9223. while (i < length && data[offset + i] === what[i]) {
  9224. ++i;
  9225. }
  9226. if (i >= length) {
  9227. break; // sequence found
  9228. }
  9229. offset++;
  9230. skipped++;
  9231. }
  9232. return skipped;
  9233. }
  9234. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  9235. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  9236. 101, 102]);
  9237. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  9238. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  9239. var stream = this.stream;
  9240. stream.pos = 0;
  9241. var buffer = stream.getBytes();
  9242. var position = stream.start, length = buffer.length;
  9243. var trailers = [], xrefStms = [];
  9244. while (position < length) {
  9245. var ch = buffer[position];
  9246. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  9247. ++position;
  9248. continue;
  9249. }
  9250. if (ch === 37) { // %-comment
  9251. do {
  9252. ++position;
  9253. if (position >= length) {
  9254. break;
  9255. }
  9256. ch = buffer[position];
  9257. } while (ch !== 13 && ch !== 10);
  9258. continue;
  9259. }
  9260. var token = readToken(buffer, position);
  9261. var m;
  9262. if (token === 'xref') {
  9263. position += skipUntil(buffer, position, trailerBytes);
  9264. trailers.push(position);
  9265. position += skipUntil(buffer, position, startxrefBytes);
  9266. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  9267. this.entries[m[1]] = {
  9268. offset: position,
  9269. gen: m[2] | 0,
  9270. uncompressed: true
  9271. };
  9272. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  9273. var content = buffer.subarray(position, position + contentLength);
  9274. // checking XRef stream suspect
  9275. // (it shall have '/XRef' and next char is not a letter)
  9276. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  9277. if (xrefTagOffset < contentLength &&
  9278. content[xrefTagOffset + 5] < 64) {
  9279. xrefStms.push(position);
  9280. this.xrefstms[position] = 1; // don't read it recursively
  9281. }
  9282. position += contentLength;
  9283. } else {
  9284. position += token.length + 1;
  9285. }
  9286. }
  9287. // reading XRef streams
  9288. var i, ii;
  9289. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  9290. this.startXRefQueue.push(xrefStms[i]);
  9291. this.readXRef(/* recoveryMode */ true);
  9292. }
  9293. // finding main trailer
  9294. var dict;
  9295. for (i = 0, ii = trailers.length; i < ii; ++i) {
  9296. stream.pos = trailers[i];
  9297. var parser = new Parser(new Lexer(stream), true, this);
  9298. var obj = parser.getObj();
  9299. if (!isCmd(obj, 'trailer')) {
  9300. continue;
  9301. }
  9302. // read the trailer dictionary
  9303. if (!isDict(dict = parser.getObj())) {
  9304. continue;
  9305. }
  9306. // taking the first one with 'ID'
  9307. if (dict.has('ID')) {
  9308. return dict;
  9309. }
  9310. }
  9311. // no tailer with 'ID', taking last one (if exists)
  9312. if (dict) {
  9313. return dict;
  9314. }
  9315. // nothing helps
  9316. // calling error() would reject worker with an UnknownErrorException.
  9317. throw new InvalidPDFException('Invalid PDF structure');
  9318. },
  9319. readXRef: function XRef_readXRef(recoveryMode) {
  9320. var stream = this.stream;
  9321. try {
  9322. while (this.startXRefQueue.length) {
  9323. var startXRef = this.startXRefQueue[0];
  9324. stream.pos = startXRef + stream.start;
  9325. var parser = new Parser(new Lexer(stream), true, this);
  9326. var obj = parser.getObj();
  9327. var dict;
  9328. // Get dictionary
  9329. if (isCmd(obj, 'xref')) {
  9330. // Parse end-of-file XRef
  9331. dict = this.processXRefTable(parser);
  9332. if (!this.topDict) {
  9333. this.topDict = dict;
  9334. }
  9335. // Recursively get other XRefs 'XRefStm', if any
  9336. obj = dict.get('XRefStm');
  9337. if (isInt(obj)) {
  9338. var pos = obj;
  9339. // ignore previously loaded xref streams
  9340. // (possible infinite recursion)
  9341. if (!(pos in this.xrefstms)) {
  9342. this.xrefstms[pos] = 1;
  9343. this.startXRefQueue.push(pos);
  9344. }
  9345. }
  9346. } else if (isInt(obj)) {
  9347. // Parse in-stream XRef
  9348. if (!isInt(parser.getObj()) ||
  9349. !isCmd(parser.getObj(), 'obj') ||
  9350. !isStream(obj = parser.getObj())) {
  9351. error('Invalid XRef stream');
  9352. }
  9353. dict = this.processXRefStream(obj);
  9354. if (!this.topDict) {
  9355. this.topDict = dict;
  9356. }
  9357. if (!dict) {
  9358. error('Failed to read XRef stream');
  9359. }
  9360. } else {
  9361. error('Invalid XRef stream header');
  9362. }
  9363. // Recursively get previous dictionary, if any
  9364. obj = dict.get('Prev');
  9365. if (isInt(obj)) {
  9366. this.startXRefQueue.push(obj);
  9367. } else if (isRef(obj)) {
  9368. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  9369. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  9370. this.startXRefQueue.push(obj.num);
  9371. }
  9372. this.startXRefQueue.shift();
  9373. }
  9374. return this.topDict;
  9375. } catch (e) {
  9376. if (e instanceof MissingDataException) {
  9377. throw e;
  9378. }
  9379. info('(while reading XRef): ' + e);
  9380. }
  9381. if (recoveryMode) {
  9382. return;
  9383. }
  9384. throw new XRefParseException();
  9385. },
  9386. getEntry: function XRef_getEntry(i) {
  9387. var xrefEntry = this.entries[i];
  9388. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  9389. return xrefEntry;
  9390. }
  9391. return null;
  9392. },
  9393. fetchIfRef: function XRef_fetchIfRef(obj) {
  9394. if (!isRef(obj)) {
  9395. return obj;
  9396. }
  9397. return this.fetch(obj);
  9398. },
  9399. fetch: function XRef_fetch(ref, suppressEncryption) {
  9400. assert(isRef(ref), 'ref object is not a reference');
  9401. var num = ref.num;
  9402. if (num in this.cache) {
  9403. var cacheEntry = this.cache[num];
  9404. return cacheEntry;
  9405. }
  9406. var xrefEntry = this.getEntry(num);
  9407. // the referenced entry can be free
  9408. if (xrefEntry === null) {
  9409. return (this.cache[num] = null);
  9410. }
  9411. if (xrefEntry.uncompressed) {
  9412. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  9413. } else {
  9414. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9415. }
  9416. if (isDict(xrefEntry)){
  9417. xrefEntry.objId = ref.toString();
  9418. } else if (isStream(xrefEntry)) {
  9419. xrefEntry.dict.objId = ref.toString();
  9420. }
  9421. return xrefEntry;
  9422. },
  9423. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  9424. suppressEncryption) {
  9425. var gen = ref.gen;
  9426. var num = ref.num;
  9427. if (xrefEntry.gen !== gen) {
  9428. error('inconsistent generation in XRef');
  9429. }
  9430. var stream = this.stream.makeSubStream(xrefEntry.offset +
  9431. this.stream.start);
  9432. var parser = new Parser(new Lexer(stream), true, this);
  9433. var obj1 = parser.getObj();
  9434. var obj2 = parser.getObj();
  9435. var obj3 = parser.getObj();
  9436. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  9437. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  9438. !isCmd(obj3)) {
  9439. error('bad XRef entry');
  9440. }
  9441. if (!isCmd(obj3, 'obj')) {
  9442. // some bad PDFs use "obj1234" and really mean 1234
  9443. if (obj3.cmd.indexOf('obj') === 0) {
  9444. num = parseInt(obj3.cmd.substring(3), 10);
  9445. if (!isNaN(num)) {
  9446. return num;
  9447. }
  9448. }
  9449. error('bad XRef entry');
  9450. }
  9451. if (this.encrypt && !suppressEncryption) {
  9452. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  9453. } else {
  9454. xrefEntry = parser.getObj();
  9455. }
  9456. if (!isStream(xrefEntry)) {
  9457. this.cache[num] = xrefEntry;
  9458. }
  9459. return xrefEntry;
  9460. },
  9461. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  9462. suppressEncryption) {
  9463. var tableOffset = xrefEntry.offset;
  9464. var stream = this.fetch(new Ref(tableOffset, 0));
  9465. if (!isStream(stream)) {
  9466. error('bad ObjStm stream');
  9467. }
  9468. var first = stream.dict.get('First');
  9469. var n = stream.dict.get('N');
  9470. if (!isInt(first) || !isInt(n)) {
  9471. error('invalid first and n parameters for ObjStm stream');
  9472. }
  9473. var parser = new Parser(new Lexer(stream), false, this);
  9474. parser.allowStreams = true;
  9475. var i, entries = [], num, nums = [];
  9476. // read the object numbers to populate cache
  9477. for (i = 0; i < n; ++i) {
  9478. num = parser.getObj();
  9479. if (!isInt(num)) {
  9480. error('invalid object number in the ObjStm stream: ' + num);
  9481. }
  9482. nums.push(num);
  9483. var offset = parser.getObj();
  9484. if (!isInt(offset)) {
  9485. error('invalid object offset in the ObjStm stream: ' + offset);
  9486. }
  9487. }
  9488. // read stream objects for cache
  9489. for (i = 0; i < n; ++i) {
  9490. entries.push(parser.getObj());
  9491. num = nums[i];
  9492. var entry = this.entries[num];
  9493. if (entry && entry.offset === tableOffset && entry.gen === i) {
  9494. this.cache[num] = entries[i];
  9495. }
  9496. }
  9497. xrefEntry = entries[xrefEntry.gen];
  9498. if (xrefEntry === undefined) {
  9499. error('bad XRef entry for compressed object');
  9500. }
  9501. return xrefEntry;
  9502. },
  9503. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  9504. if (!isRef(obj)) {
  9505. return Promise.resolve(obj);
  9506. }
  9507. return this.fetchAsync(obj);
  9508. },
  9509. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  9510. var streamManager = this.stream.manager;
  9511. var xref = this;
  9512. return new Promise(function tryFetch(resolve, reject) {
  9513. try {
  9514. resolve(xref.fetch(ref, suppressEncryption));
  9515. } catch (e) {
  9516. if (e instanceof MissingDataException) {
  9517. streamManager.requestRange(e.begin, e.end, function () {
  9518. tryFetch(resolve, reject);
  9519. });
  9520. return;
  9521. }
  9522. reject(e);
  9523. }
  9524. });
  9525. },
  9526. getCatalogObj: function XRef_getCatalogObj() {
  9527. return this.root;
  9528. }
  9529. };
  9530. return XRef;
  9531. })();
  9532. /**
  9533. * A NameTree is like a Dict but has some advantageous properties, see the
  9534. * spec (7.9.6) for more details.
  9535. * TODO: implement all the Dict functions and make this more efficent.
  9536. */
  9537. var NameTree = (function NameTreeClosure() {
  9538. function NameTree(root, xref) {
  9539. this.root = root;
  9540. this.xref = xref;
  9541. }
  9542. NameTree.prototype = {
  9543. getAll: function NameTree_getAll() {
  9544. var dict = {};
  9545. if (!this.root) {
  9546. return dict;
  9547. }
  9548. var xref = this.xref;
  9549. // reading name tree
  9550. var processed = new RefSet();
  9551. processed.put(this.root);
  9552. var queue = [this.root];
  9553. while (queue.length > 0) {
  9554. var i, n;
  9555. var obj = xref.fetchIfRef(queue.shift());
  9556. if (!isDict(obj)) {
  9557. continue;
  9558. }
  9559. if (obj.has('Kids')) {
  9560. var kids = obj.get('Kids');
  9561. for (i = 0, n = kids.length; i < n; i++) {
  9562. var kid = kids[i];
  9563. if (processed.has(kid)) {
  9564. error('invalid destinations');
  9565. }
  9566. queue.push(kid);
  9567. processed.put(kid);
  9568. }
  9569. continue;
  9570. }
  9571. var names = obj.get('Names');
  9572. if (names) {
  9573. for (i = 0, n = names.length; i < n; i += 2) {
  9574. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  9575. }
  9576. }
  9577. }
  9578. return dict;
  9579. },
  9580. get: function NameTree_get(destinationId) {
  9581. if (!this.root) {
  9582. return null;
  9583. }
  9584. var xref = this.xref;
  9585. var kidsOrNames = xref.fetchIfRef(this.root);
  9586. var loopCount = 0;
  9587. var MAX_NAMES_LEVELS = 10;
  9588. var l, r, m;
  9589. // Perform a binary search to quickly find the entry that
  9590. // contains the named destination we are looking for.
  9591. while (kidsOrNames.has('Kids')) {
  9592. loopCount++;
  9593. if (loopCount > MAX_NAMES_LEVELS) {
  9594. warn('Search depth limit for named destionations has been reached.');
  9595. return null;
  9596. }
  9597. var kids = kidsOrNames.get('Kids');
  9598. if (!isArray(kids)) {
  9599. return null;
  9600. }
  9601. l = 0;
  9602. r = kids.length - 1;
  9603. while (l <= r) {
  9604. m = (l + r) >> 1;
  9605. var kid = xref.fetchIfRef(kids[m]);
  9606. var limits = kid.get('Limits');
  9607. if (destinationId < limits[0]) {
  9608. r = m - 1;
  9609. } else if (destinationId > limits[1]) {
  9610. l = m + 1;
  9611. } else {
  9612. kidsOrNames = xref.fetchIfRef(kids[m]);
  9613. break;
  9614. }
  9615. }
  9616. if (l > r) {
  9617. return null;
  9618. }
  9619. }
  9620. // If we get here, then we have found the right entry. Now
  9621. // go through the named destinations in the Named dictionary
  9622. // until we find the exact destination we're looking for.
  9623. var names = kidsOrNames.get('Names');
  9624. if (isArray(names)) {
  9625. // Perform a binary search to reduce the lookup time.
  9626. l = 0;
  9627. r = names.length - 2;
  9628. while (l <= r) {
  9629. // Check only even indices (0, 2, 4, ...) because the
  9630. // odd indices contain the actual D array.
  9631. m = (l + r) & ~1;
  9632. if (destinationId < names[m]) {
  9633. r = m - 2;
  9634. } else if (destinationId > names[m]) {
  9635. l = m + 2;
  9636. } else {
  9637. return xref.fetchIfRef(names[m + 1]);
  9638. }
  9639. }
  9640. }
  9641. return null;
  9642. }
  9643. };
  9644. return NameTree;
  9645. })();
  9646. /**
  9647. * "A PDF file can refer to the contents of another file by using a File
  9648. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  9649. * NOTE: Only embedded files are supported (as part of the attachments support)
  9650. * TODO: support the 'URL' file system (with caching if !/V), portable
  9651. * collections attributes and related files (/RF)
  9652. */
  9653. var FileSpec = (function FileSpecClosure() {
  9654. function FileSpec(root, xref) {
  9655. if (!root || !isDict(root)) {
  9656. return;
  9657. }
  9658. this.xref = xref;
  9659. this.root = root;
  9660. if (root.has('FS')) {
  9661. this.fs = root.get('FS');
  9662. }
  9663. this.description = root.has('Desc') ?
  9664. stringToPDFString(root.get('Desc')) :
  9665. '';
  9666. if (root.has('RF')) {
  9667. warn('Related file specifications are not supported');
  9668. }
  9669. this.contentAvailable = true;
  9670. if (!root.has('EF')) {
  9671. this.contentAvailable = false;
  9672. warn('Non-embedded file specifications are not supported');
  9673. }
  9674. }
  9675. function pickPlatformItem(dict) {
  9676. // Look for the filename in this order:
  9677. // UF, F, Unix, Mac, DOS
  9678. if (dict.has('UF')) {
  9679. return dict.get('UF');
  9680. } else if (dict.has('F')) {
  9681. return dict.get('F');
  9682. } else if (dict.has('Unix')) {
  9683. return dict.get('Unix');
  9684. } else if (dict.has('Mac')) {
  9685. return dict.get('Mac');
  9686. } else if (dict.has('DOS')) {
  9687. return dict.get('DOS');
  9688. } else {
  9689. return null;
  9690. }
  9691. }
  9692. FileSpec.prototype = {
  9693. get filename() {
  9694. if (!this._filename && this.root) {
  9695. var filename = pickPlatformItem(this.root) || 'unnamed';
  9696. this._filename = stringToPDFString(filename).
  9697. replace(/\\\\/g, '\\').
  9698. replace(/\\\//g, '/').
  9699. replace(/\\/g, '/');
  9700. }
  9701. return this._filename;
  9702. },
  9703. get content() {
  9704. if (!this.contentAvailable) {
  9705. return null;
  9706. }
  9707. if (!this.contentRef && this.root) {
  9708. this.contentRef = pickPlatformItem(this.root.get('EF'));
  9709. }
  9710. var content = null;
  9711. if (this.contentRef) {
  9712. var xref = this.xref;
  9713. var fileObj = xref.fetchIfRef(this.contentRef);
  9714. if (fileObj && isStream(fileObj)) {
  9715. content = fileObj.getBytes();
  9716. } else {
  9717. warn('Embedded file specification points to non-existing/invalid ' +
  9718. 'content');
  9719. }
  9720. } else {
  9721. warn('Embedded file specification does not have a content');
  9722. }
  9723. return content;
  9724. },
  9725. get serializable() {
  9726. return {
  9727. filename: this.filename,
  9728. content: this.content
  9729. };
  9730. }
  9731. };
  9732. return FileSpec;
  9733. })();
  9734. /**
  9735. * A helper for loading missing data in object graphs. It traverses the graph
  9736. * depth first and queues up any objects that have missing data. Once it has
  9737. * has traversed as many objects that are available it attempts to bundle the
  9738. * missing data requests and then resume from the nodes that weren't ready.
  9739. *
  9740. * NOTE: It provides protection from circular references by keeping track of
  9741. * of loaded references. However, you must be careful not to load any graphs
  9742. * that have references to the catalog or other pages since that will cause the
  9743. * entire PDF document object graph to be traversed.
  9744. */
  9745. var ObjectLoader = (function() {
  9746. function mayHaveChildren(value) {
  9747. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  9748. }
  9749. function addChildren(node, nodesToVisit) {
  9750. var value;
  9751. if (isDict(node) || isStream(node)) {
  9752. var map;
  9753. if (isDict(node)) {
  9754. map = node.map;
  9755. } else {
  9756. map = node.dict.map;
  9757. }
  9758. for (var key in map) {
  9759. value = map[key];
  9760. if (mayHaveChildren(value)) {
  9761. nodesToVisit.push(value);
  9762. }
  9763. }
  9764. } else if (isArray(node)) {
  9765. for (var i = 0, ii = node.length; i < ii; i++) {
  9766. value = node[i];
  9767. if (mayHaveChildren(value)) {
  9768. nodesToVisit.push(value);
  9769. }
  9770. }
  9771. }
  9772. }
  9773. function ObjectLoader(obj, keys, xref) {
  9774. this.obj = obj;
  9775. this.keys = keys;
  9776. this.xref = xref;
  9777. this.refSet = null;
  9778. }
  9779. ObjectLoader.prototype = {
  9780. load: function ObjectLoader_load() {
  9781. var keys = this.keys;
  9782. this.capability = createPromiseCapability();
  9783. // Don't walk the graph if all the data is already loaded.
  9784. if (!(this.xref.stream instanceof ChunkedStream) ||
  9785. this.xref.stream.getMissingChunks().length === 0) {
  9786. this.capability.resolve();
  9787. return this.capability.promise;
  9788. }
  9789. this.refSet = new RefSet();
  9790. // Setup the initial nodes to visit.
  9791. var nodesToVisit = [];
  9792. for (var i = 0; i < keys.length; i++) {
  9793. nodesToVisit.push(this.obj[keys[i]]);
  9794. }
  9795. this.walk(nodesToVisit);
  9796. return this.capability.promise;
  9797. },
  9798. walk: function ObjectLoader_walk(nodesToVisit) {
  9799. var nodesToRevisit = [];
  9800. var pendingRequests = [];
  9801. // DFS walk of the object graph.
  9802. while (nodesToVisit.length) {
  9803. var currentNode = nodesToVisit.pop();
  9804. // Only references or chunked streams can cause missing data exceptions.
  9805. if (isRef(currentNode)) {
  9806. // Skip nodes that have already been visited.
  9807. if (this.refSet.has(currentNode)) {
  9808. continue;
  9809. }
  9810. try {
  9811. var ref = currentNode;
  9812. this.refSet.put(ref);
  9813. currentNode = this.xref.fetch(currentNode);
  9814. } catch (e) {
  9815. if (!(e instanceof MissingDataException)) {
  9816. throw e;
  9817. }
  9818. nodesToRevisit.push(currentNode);
  9819. pendingRequests.push({ begin: e.begin, end: e.end });
  9820. }
  9821. }
  9822. if (currentNode && currentNode.getBaseStreams) {
  9823. var baseStreams = currentNode.getBaseStreams();
  9824. var foundMissingData = false;
  9825. for (var i = 0; i < baseStreams.length; i++) {
  9826. var stream = baseStreams[i];
  9827. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  9828. foundMissingData = true;
  9829. pendingRequests.push({
  9830. begin: stream.start,
  9831. end: stream.end
  9832. });
  9833. }
  9834. }
  9835. if (foundMissingData) {
  9836. nodesToRevisit.push(currentNode);
  9837. }
  9838. }
  9839. addChildren(currentNode, nodesToVisit);
  9840. }
  9841. if (pendingRequests.length) {
  9842. this.xref.stream.manager.requestRanges(pendingRequests,
  9843. function pendingRequestCallback() {
  9844. nodesToVisit = nodesToRevisit;
  9845. for (var i = 0; i < nodesToRevisit.length; i++) {
  9846. var node = nodesToRevisit[i];
  9847. // Remove any reference nodes from the currrent refset so they
  9848. // aren't skipped when we revist them.
  9849. if (isRef(node)) {
  9850. this.refSet.remove(node);
  9851. }
  9852. }
  9853. this.walk(nodesToVisit);
  9854. }.bind(this));
  9855. return;
  9856. }
  9857. // Everything is loaded.
  9858. this.refSet = null;
  9859. this.capability.resolve();
  9860. }
  9861. };
  9862. return ObjectLoader;
  9863. })();
  9864. var ISOAdobeCharset = [
  9865. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  9866. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  9867. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  9868. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  9869. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  9870. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  9871. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  9872. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  9873. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  9874. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  9875. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  9876. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  9877. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  9878. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  9879. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  9880. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  9881. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  9882. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  9883. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  9884. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  9885. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  9886. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  9887. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  9888. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  9889. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  9890. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  9891. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  9892. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  9893. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  9894. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  9895. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  9896. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  9897. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  9898. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  9899. ];
  9900. var ExpertCharset = [
  9901. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  9902. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  9903. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  9904. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  9905. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  9906. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  9907. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  9908. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  9909. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9910. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9911. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9912. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  9913. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  9914. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  9915. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  9916. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  9917. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  9918. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  9919. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  9920. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  9921. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  9922. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  9923. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9924. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9925. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9926. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9927. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9928. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9929. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  9930. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  9931. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  9932. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  9933. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  9934. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  9935. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  9936. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  9937. 'Ydieresissmall'
  9938. ];
  9939. var ExpertSubsetCharset = [
  9940. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  9941. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  9942. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  9943. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  9944. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  9945. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  9946. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  9947. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  9948. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  9949. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  9950. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  9951. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  9952. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  9953. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  9954. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  9955. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  9956. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  9957. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  9958. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  9959. 'periodinferior', 'commainferior'
  9960. ];
  9961. var DEFAULT_ICON_SIZE = 22; // px
  9962. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  9963. var Annotation = (function AnnotationClosure() {
  9964. // 12.5.5: Algorithm: Appearance streams
  9965. function getTransformMatrix(rect, bbox, matrix) {
  9966. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  9967. var minX = bounds[0];
  9968. var minY = bounds[1];
  9969. var maxX = bounds[2];
  9970. var maxY = bounds[3];
  9971. if (minX === maxX || minY === maxY) {
  9972. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  9973. // just apply the transform for rect
  9974. return [1, 0, 0, 1, rect[0], rect[1]];
  9975. }
  9976. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  9977. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  9978. return [
  9979. xRatio,
  9980. 0,
  9981. 0,
  9982. yRatio,
  9983. rect[0] - minX * xRatio,
  9984. rect[1] - minY * yRatio
  9985. ];
  9986. }
  9987. function getDefaultAppearance(dict) {
  9988. var appearanceState = dict.get('AP');
  9989. if (!isDict(appearanceState)) {
  9990. return;
  9991. }
  9992. var appearance;
  9993. var appearances = appearanceState.get('N');
  9994. if (isDict(appearances)) {
  9995. var as = dict.get('AS');
  9996. if (as && appearances.has(as.name)) {
  9997. appearance = appearances.get(as.name);
  9998. }
  9999. } else {
  10000. appearance = appearances;
  10001. }
  10002. return appearance;
  10003. }
  10004. function Annotation(params) {
  10005. var dict = params.dict;
  10006. var data = this.data = {};
  10007. data.subtype = dict.get('Subtype').name;
  10008. var rect = dict.get('Rect') || [0, 0, 0, 0];
  10009. data.rect = Util.normalizeRect(rect);
  10010. data.annotationFlags = dict.get('F');
  10011. var color = dict.get('C');
  10012. if (!color) {
  10013. // The PDF spec does not mention how a missing color array is interpreted.
  10014. // Adobe Reader seems to default to black in this case.
  10015. data.color = [0, 0, 0];
  10016. } else if (isArray(color)) {
  10017. switch (color.length) {
  10018. case 0:
  10019. // Empty array denotes transparent border.
  10020. data.color = null;
  10021. break;
  10022. case 1:
  10023. // TODO: implement DeviceGray
  10024. break;
  10025. case 3:
  10026. data.color = color;
  10027. break;
  10028. case 4:
  10029. // TODO: implement DeviceCMYK
  10030. break;
  10031. }
  10032. }
  10033. // Some types of annotations have border style dict which has more
  10034. // info than the border array
  10035. if (dict.has('BS')) {
  10036. var borderStyle = dict.get('BS');
  10037. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  10038. } else {
  10039. var borderArray = dict.get('Border') || [0, 0, 1];
  10040. data.borderWidth = borderArray[2] || 0;
  10041. // TODO: implement proper support for annotations with line dash patterns.
  10042. var dashArray = borderArray[3];
  10043. if (data.borderWidth > 0 && dashArray) {
  10044. if (!isArray(dashArray)) {
  10045. // Ignore the border if dashArray is not actually an array,
  10046. // this is consistent with the behaviour in Adobe Reader.
  10047. data.borderWidth = 0;
  10048. } else {
  10049. var dashArrayLength = dashArray.length;
  10050. if (dashArrayLength > 0) {
  10051. // According to the PDF specification: the elements in a dashArray
  10052. // shall be numbers that are nonnegative and not all equal to zero.
  10053. var isInvalid = false;
  10054. var numPositive = 0;
  10055. for (var i = 0; i < dashArrayLength; i++) {
  10056. var validNumber = (+dashArray[i] >= 0);
  10057. if (!validNumber) {
  10058. isInvalid = true;
  10059. break;
  10060. } else if (dashArray[i] > 0) {
  10061. numPositive++;
  10062. }
  10063. }
  10064. if (isInvalid || numPositive === 0) {
  10065. data.borderWidth = 0;
  10066. }
  10067. }
  10068. }
  10069. }
  10070. }
  10071. this.appearance = getDefaultAppearance(dict);
  10072. data.hasAppearance = !!this.appearance;
  10073. data.id = params.ref.num;
  10074. }
  10075. Annotation.prototype = {
  10076. getData: function Annotation_getData() {
  10077. return this.data;
  10078. },
  10079. isInvisible: function Annotation_isInvisible() {
  10080. var data = this.data;
  10081. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  10082. return false;
  10083. } else {
  10084. return !!(data &&
  10085. data.annotationFlags && // Default: not invisible
  10086. data.annotationFlags & 0x1); // Invisible
  10087. }
  10088. },
  10089. isViewable: function Annotation_isViewable() {
  10090. var data = this.data;
  10091. return !!(!this.isInvisible() &&
  10092. data &&
  10093. (!data.annotationFlags ||
  10094. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  10095. data.rect); // rectangle is necessary
  10096. },
  10097. isPrintable: function Annotation_isPrintable() {
  10098. var data = this.data;
  10099. return !!(!this.isInvisible() &&
  10100. data &&
  10101. data.annotationFlags && // Default: not printable
  10102. data.annotationFlags & 0x4 && // Print
  10103. !(data.annotationFlags & 0x2) && // Hidden
  10104. data.rect); // rectangle is necessary
  10105. },
  10106. loadResources: function Annotation_loadResources(keys) {
  10107. return new Promise(function (resolve, reject) {
  10108. this.appearance.dict.getAsync('Resources').then(function (resources) {
  10109. if (!resources) {
  10110. resolve();
  10111. return;
  10112. }
  10113. var objectLoader = new ObjectLoader(resources.map,
  10114. keys,
  10115. resources.xref);
  10116. objectLoader.load().then(function() {
  10117. resolve(resources);
  10118. }, reject);
  10119. }, reject);
  10120. }.bind(this));
  10121. },
  10122. getOperatorList: function Annotation_getOperatorList(evaluator) {
  10123. if (!this.appearance) {
  10124. return Promise.resolve(new OperatorList());
  10125. }
  10126. var data = this.data;
  10127. var appearanceDict = this.appearance.dict;
  10128. var resourcesPromise = this.loadResources([
  10129. 'ExtGState',
  10130. 'ColorSpace',
  10131. 'Pattern',
  10132. 'Shading',
  10133. 'XObject',
  10134. 'Font'
  10135. // ProcSet
  10136. // Properties
  10137. ]);
  10138. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  10139. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  10140. var transform = getTransformMatrix(data.rect, bbox, matrix);
  10141. var self = this;
  10142. return resourcesPromise.then(function(resources) {
  10143. var opList = new OperatorList();
  10144. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  10145. return evaluator.getOperatorList(self.appearance, resources, opList).
  10146. then(function () {
  10147. opList.addOp(OPS.endAnnotation, []);
  10148. self.appearance.reset();
  10149. return opList;
  10150. });
  10151. });
  10152. }
  10153. };
  10154. Annotation.getConstructor =
  10155. function Annotation_getConstructor(subtype, fieldType) {
  10156. if (!subtype) {
  10157. return;
  10158. }
  10159. // TODO(mack): Implement FreeText annotations
  10160. if (subtype === 'Link') {
  10161. return LinkAnnotation;
  10162. } else if (subtype === 'Text') {
  10163. return TextAnnotation;
  10164. } else if (subtype === 'Widget') {
  10165. if (!fieldType) {
  10166. return;
  10167. }
  10168. if (fieldType === 'Tx') {
  10169. return TextWidgetAnnotation;
  10170. } else {
  10171. return WidgetAnnotation;
  10172. }
  10173. } else {
  10174. return Annotation;
  10175. }
  10176. };
  10177. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  10178. var dict = xref.fetchIfRef(ref);
  10179. if (!isDict(dict)) {
  10180. return;
  10181. }
  10182. var subtype = dict.get('Subtype');
  10183. subtype = isName(subtype) ? subtype.name : '';
  10184. if (!subtype) {
  10185. return;
  10186. }
  10187. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10188. fieldType = isName(fieldType) ? fieldType.name : '';
  10189. var Constructor = Annotation.getConstructor(subtype, fieldType);
  10190. if (!Constructor) {
  10191. return;
  10192. }
  10193. var params = {
  10194. dict: dict,
  10195. ref: ref,
  10196. };
  10197. var annotation = new Constructor(params);
  10198. if (annotation.isViewable() || annotation.isPrintable()) {
  10199. return annotation;
  10200. } else {
  10201. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  10202. warn('unimplemented annotation type: ' + subtype);
  10203. }
  10204. }
  10205. };
  10206. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  10207. annotations, opList, pdfManager, partialEvaluator, intent) {
  10208. function reject(e) {
  10209. annotationsReadyCapability.reject(e);
  10210. }
  10211. var annotationsReadyCapability = createPromiseCapability();
  10212. var annotationPromises = [];
  10213. for (var i = 0, n = annotations.length; i < n; ++i) {
  10214. if (intent === 'display' && annotations[i].isViewable() ||
  10215. intent === 'print' && annotations[i].isPrintable()) {
  10216. annotationPromises.push(
  10217. annotations[i].getOperatorList(partialEvaluator));
  10218. }
  10219. }
  10220. Promise.all(annotationPromises).then(function(datas) {
  10221. opList.addOp(OPS.beginAnnotations, []);
  10222. for (var i = 0, n = datas.length; i < n; ++i) {
  10223. var annotOpList = datas[i];
  10224. opList.addOpList(annotOpList);
  10225. }
  10226. opList.addOp(OPS.endAnnotations, []);
  10227. annotationsReadyCapability.resolve();
  10228. }, reject);
  10229. return annotationsReadyCapability.promise;
  10230. };
  10231. return Annotation;
  10232. })();
  10233. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  10234. function WidgetAnnotation(params) {
  10235. Annotation.call(this, params);
  10236. var dict = params.dict;
  10237. var data = this.data;
  10238. data.fieldValue = stringToPDFString(
  10239. Util.getInheritableProperty(dict, 'V') || '');
  10240. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  10241. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  10242. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10243. data.fieldType = isName(fieldType) ? fieldType.name : '';
  10244. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  10245. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  10246. // Building the full field name by collecting the field and
  10247. // its ancestors 'T' data and joining them using '.'.
  10248. var fieldName = [];
  10249. var namedItem = dict;
  10250. var ref = params.ref;
  10251. while (namedItem) {
  10252. var parent = namedItem.get('Parent');
  10253. var parentRef = namedItem.getRaw('Parent');
  10254. var name = namedItem.get('T');
  10255. if (name) {
  10256. fieldName.unshift(stringToPDFString(name));
  10257. } else if (parent && ref) {
  10258. // The field name is absent, that means more than one field
  10259. // with the same name may exist. Replacing the empty name
  10260. // with the '`' plus index in the parent's 'Kids' array.
  10261. // This is not in the PDF spec but necessary to id the
  10262. // the input controls.
  10263. var kids = parent.get('Kids');
  10264. var j, jj;
  10265. for (j = 0, jj = kids.length; j < jj; j++) {
  10266. var kidRef = kids[j];
  10267. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  10268. break;
  10269. }
  10270. }
  10271. fieldName.unshift('`' + j);
  10272. }
  10273. namedItem = parent;
  10274. ref = parentRef;
  10275. }
  10276. data.fullName = fieldName.join('.');
  10277. }
  10278. var parent = Annotation.prototype;
  10279. Util.inherit(WidgetAnnotation, Annotation, {
  10280. isViewable: function WidgetAnnotation_isViewable() {
  10281. if (this.data.fieldType === 'Sig') {
  10282. warn('unimplemented annotation type: Widget signature');
  10283. return false;
  10284. }
  10285. return parent.isViewable.call(this);
  10286. }
  10287. });
  10288. return WidgetAnnotation;
  10289. })();
  10290. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  10291. function TextWidgetAnnotation(params) {
  10292. WidgetAnnotation.call(this, params);
  10293. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  10294. this.data.annotationType = AnnotationType.WIDGET;
  10295. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  10296. }
  10297. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  10298. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  10299. if (this.appearance) {
  10300. return Annotation.prototype.getOperatorList.call(this, evaluator);
  10301. }
  10302. var opList = new OperatorList();
  10303. var data = this.data;
  10304. // Even if there is an appearance stream, ignore it. This is the
  10305. // behaviour used by Adobe Reader.
  10306. if (!data.defaultAppearance) {
  10307. return Promise.resolve(opList);
  10308. }
  10309. var stream = new Stream(stringToBytes(data.defaultAppearance));
  10310. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  10311. then(function () {
  10312. return opList;
  10313. });
  10314. }
  10315. });
  10316. return TextWidgetAnnotation;
  10317. })();
  10318. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  10319. function InteractiveAnnotation(params) {
  10320. Annotation.call(this, params);
  10321. this.data.hasHtml = true;
  10322. }
  10323. Util.inherit(InteractiveAnnotation, Annotation, { });
  10324. return InteractiveAnnotation;
  10325. })();
  10326. var TextAnnotation = (function TextAnnotationClosure() {
  10327. function TextAnnotation(params) {
  10328. InteractiveAnnotation.call(this, params);
  10329. var dict = params.dict;
  10330. var data = this.data;
  10331. var content = dict.get('Contents');
  10332. var title = dict.get('T');
  10333. data.annotationType = AnnotationType.TEXT;
  10334. data.content = stringToPDFString(content || '');
  10335. data.title = stringToPDFString(title || '');
  10336. if (data.hasAppearance) {
  10337. data.name = 'NoIcon';
  10338. } else {
  10339. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  10340. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  10341. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  10342. }
  10343. if (dict.has('C')) {
  10344. data.hasBgColor = true;
  10345. }
  10346. }
  10347. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  10348. return TextAnnotation;
  10349. })();
  10350. var LinkAnnotation = (function LinkAnnotationClosure() {
  10351. function LinkAnnotation(params) {
  10352. InteractiveAnnotation.call(this, params);
  10353. var dict = params.dict;
  10354. var data = this.data;
  10355. data.annotationType = AnnotationType.LINK;
  10356. var action = dict.get('A');
  10357. if (action && isDict(action)) {
  10358. var linkType = action.get('S').name;
  10359. if (linkType === 'URI') {
  10360. var url = action.get('URI');
  10361. if (isName(url)) {
  10362. // Some bad PDFs do not put parentheses around relative URLs.
  10363. url = '/' + url.name;
  10364. } else if (url) {
  10365. url = addDefaultProtocolToUrl(url);
  10366. }
  10367. // TODO: pdf spec mentions urls can be relative to a Base
  10368. // entry in the dictionary.
  10369. if (!isValidUrl(url, false)) {
  10370. url = '';
  10371. }
  10372. data.url = url;
  10373. } else if (linkType === 'GoTo') {
  10374. data.dest = action.get('D');
  10375. } else if (linkType === 'GoToR') {
  10376. var urlDict = action.get('F');
  10377. if (isDict(urlDict)) {
  10378. // We assume that the 'url' is a Filspec dictionary
  10379. // and fetch the url without checking any further
  10380. url = urlDict.get('F') || '';
  10381. }
  10382. // TODO: pdf reference says that GoToR
  10383. // can also have 'NewWindow' attribute
  10384. if (!isValidUrl(url, false)) {
  10385. url = '';
  10386. }
  10387. data.url = url;
  10388. data.dest = action.get('D');
  10389. } else if (linkType === 'Named') {
  10390. data.action = action.get('N').name;
  10391. } else {
  10392. warn('unrecognized link type: ' + linkType);
  10393. }
  10394. } else if (dict.has('Dest')) {
  10395. // simple destination link
  10396. var dest = dict.get('Dest');
  10397. data.dest = isName(dest) ? dest.name : dest;
  10398. }
  10399. }
  10400. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  10401. function addDefaultProtocolToUrl(url) {
  10402. if (url && url.indexOf('www.') === 0) {
  10403. return ('http://' + url);
  10404. }
  10405. return url;
  10406. }
  10407. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  10408. return LinkAnnotation;
  10409. })();
  10410. var PDFFunction = (function PDFFunctionClosure() {
  10411. var CONSTRUCT_SAMPLED = 0;
  10412. var CONSTRUCT_INTERPOLATED = 2;
  10413. var CONSTRUCT_STICHED = 3;
  10414. var CONSTRUCT_POSTSCRIPT = 4;
  10415. return {
  10416. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  10417. str) {
  10418. var i, ii;
  10419. var length = 1;
  10420. for (i = 0, ii = size.length; i < ii; i++) {
  10421. length *= size[i];
  10422. }
  10423. length *= outputSize;
  10424. var array = new Array(length);
  10425. var codeSize = 0;
  10426. var codeBuf = 0;
  10427. // 32 is a valid bps so shifting won't work
  10428. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  10429. var strBytes = str.getBytes((length * bps + 7) / 8);
  10430. var strIdx = 0;
  10431. for (i = 0; i < length; i++) {
  10432. while (codeSize < bps) {
  10433. codeBuf <<= 8;
  10434. codeBuf |= strBytes[strIdx++];
  10435. codeSize += 8;
  10436. }
  10437. codeSize -= bps;
  10438. array[i] = (codeBuf >> codeSize) * sampleMul;
  10439. codeBuf &= (1 << codeSize) - 1;
  10440. }
  10441. return array;
  10442. },
  10443. getIR: function PDFFunction_getIR(xref, fn) {
  10444. var dict = fn.dict;
  10445. if (!dict) {
  10446. dict = fn;
  10447. }
  10448. var types = [this.constructSampled,
  10449. null,
  10450. this.constructInterpolated,
  10451. this.constructStiched,
  10452. this.constructPostScript];
  10453. var typeNum = dict.get('FunctionType');
  10454. var typeFn = types[typeNum];
  10455. if (!typeFn) {
  10456. error('Unknown type of function');
  10457. }
  10458. return typeFn.call(this, fn, dict, xref);
  10459. },
  10460. fromIR: function PDFFunction_fromIR(IR) {
  10461. var type = IR[0];
  10462. switch (type) {
  10463. case CONSTRUCT_SAMPLED:
  10464. return this.constructSampledFromIR(IR);
  10465. case CONSTRUCT_INTERPOLATED:
  10466. return this.constructInterpolatedFromIR(IR);
  10467. case CONSTRUCT_STICHED:
  10468. return this.constructStichedFromIR(IR);
  10469. //case CONSTRUCT_POSTSCRIPT:
  10470. default:
  10471. return this.constructPostScriptFromIR(IR);
  10472. }
  10473. },
  10474. parse: function PDFFunction_parse(xref, fn) {
  10475. var IR = this.getIR(xref, fn);
  10476. return this.fromIR(IR);
  10477. },
  10478. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  10479. if (!isArray(fnObj)) {
  10480. // not an array -- parsing as regular function
  10481. return this.parse(xref, fnObj);
  10482. }
  10483. var fnArray = [];
  10484. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  10485. var obj = xref.fetchIfRef(fnObj[j]);
  10486. fnArray.push(PDFFunction.parse(xref, obj));
  10487. }
  10488. return function (src, srcOffset, dest, destOffset) {
  10489. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  10490. fnArray[i](src, srcOffset, dest, destOffset + i);
  10491. }
  10492. };
  10493. },
  10494. constructSampled: function PDFFunction_constructSampled(str, dict) {
  10495. function toMultiArray(arr) {
  10496. var inputLength = arr.length;
  10497. var out = [];
  10498. var index = 0;
  10499. for (var i = 0; i < inputLength; i += 2) {
  10500. out[index] = [arr[i], arr[i + 1]];
  10501. ++index;
  10502. }
  10503. return out;
  10504. }
  10505. var domain = dict.get('Domain');
  10506. var range = dict.get('Range');
  10507. if (!domain || !range) {
  10508. error('No domain or range');
  10509. }
  10510. var inputSize = domain.length / 2;
  10511. var outputSize = range.length / 2;
  10512. domain = toMultiArray(domain);
  10513. range = toMultiArray(range);
  10514. var size = dict.get('Size');
  10515. var bps = dict.get('BitsPerSample');
  10516. var order = dict.get('Order') || 1;
  10517. if (order !== 1) {
  10518. // No description how cubic spline interpolation works in PDF32000:2008
  10519. // As in poppler, ignoring order, linear interpolation may work as good
  10520. info('No support for cubic spline interpolation: ' + order);
  10521. }
  10522. var encode = dict.get('Encode');
  10523. if (!encode) {
  10524. encode = [];
  10525. for (var i = 0; i < inputSize; ++i) {
  10526. encode.push(0);
  10527. encode.push(size[i] - 1);
  10528. }
  10529. }
  10530. encode = toMultiArray(encode);
  10531. var decode = dict.get('Decode');
  10532. if (!decode) {
  10533. decode = range;
  10534. } else {
  10535. decode = toMultiArray(decode);
  10536. }
  10537. var samples = this.getSampleArray(size, outputSize, bps, str);
  10538. return [
  10539. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  10540. outputSize, Math.pow(2, bps) - 1, range
  10541. ];
  10542. },
  10543. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  10544. // See chapter 3, page 109 of the PDF reference
  10545. function interpolate(x, xmin, xmax, ymin, ymax) {
  10546. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  10547. }
  10548. return function constructSampledFromIRResult(src, srcOffset,
  10549. dest, destOffset) {
  10550. // See chapter 3, page 110 of the PDF reference.
  10551. var m = IR[1];
  10552. var domain = IR[2];
  10553. var encode = IR[3];
  10554. var decode = IR[4];
  10555. var samples = IR[5];
  10556. var size = IR[6];
  10557. var n = IR[7];
  10558. //var mask = IR[8];
  10559. var range = IR[9];
  10560. // Building the cube vertices: its part and sample index
  10561. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  10562. var cubeVertices = 1 << m;
  10563. var cubeN = new Float64Array(cubeVertices);
  10564. var cubeVertex = new Uint32Array(cubeVertices);
  10565. var i, j;
  10566. for (j = 0; j < cubeVertices; j++) {
  10567. cubeN[j] = 1;
  10568. }
  10569. var k = n, pos = 1;
  10570. // Map x_i to y_j for 0 <= i < m using the sampled function.
  10571. for (i = 0; i < m; ++i) {
  10572. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  10573. var domain_2i = domain[i][0];
  10574. var domain_2i_1 = domain[i][1];
  10575. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  10576. domain_2i_1);
  10577. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  10578. // Encode_2i, Encode_2i+1)
  10579. var e = interpolate(xi, domain_2i, domain_2i_1,
  10580. encode[i][0], encode[i][1]);
  10581. // e_i' = min(max(e_i, 0), Size_i - 1)
  10582. var size_i = size[i];
  10583. e = Math.min(Math.max(e, 0), size_i - 1);
  10584. // Adjusting the cube: N and vertex sample index
  10585. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  10586. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  10587. var n1 = e - e0; // (e - e0) / (e1 - e0);
  10588. var offset0 = e0 * k;
  10589. var offset1 = offset0 + k; // e1 * k
  10590. for (j = 0; j < cubeVertices; j++) {
  10591. if (j & pos) {
  10592. cubeN[j] *= n1;
  10593. cubeVertex[j] += offset1;
  10594. } else {
  10595. cubeN[j] *= n0;
  10596. cubeVertex[j] += offset0;
  10597. }
  10598. }
  10599. k *= size_i;
  10600. pos <<= 1;
  10601. }
  10602. for (j = 0; j < n; ++j) {
  10603. // Sum all cube vertices' samples portions
  10604. var rj = 0;
  10605. for (i = 0; i < cubeVertices; i++) {
  10606. rj += samples[cubeVertex[i] + j] * cubeN[i];
  10607. }
  10608. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  10609. // Decode_2j, Decode_2j+1)
  10610. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  10611. // y_j = min(max(r_j, range_2j), range_2j+1)
  10612. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  10613. range[j][1]);
  10614. }
  10615. };
  10616. },
  10617. constructInterpolated: function PDFFunction_constructInterpolated(str,
  10618. dict) {
  10619. var c0 = dict.get('C0') || [0];
  10620. var c1 = dict.get('C1') || [1];
  10621. var n = dict.get('N');
  10622. if (!isArray(c0) || !isArray(c1)) {
  10623. error('Illegal dictionary for interpolated function');
  10624. }
  10625. var length = c0.length;
  10626. var diff = [];
  10627. for (var i = 0; i < length; ++i) {
  10628. diff.push(c1[i] - c0[i]);
  10629. }
  10630. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  10631. },
  10632. constructInterpolatedFromIR:
  10633. function PDFFunction_constructInterpolatedFromIR(IR) {
  10634. var c0 = IR[1];
  10635. var diff = IR[2];
  10636. var n = IR[3];
  10637. var length = diff.length;
  10638. return function constructInterpolatedFromIRResult(src, srcOffset,
  10639. dest, destOffset) {
  10640. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  10641. for (var j = 0; j < length; ++j) {
  10642. dest[destOffset + j] = c0[j] + (x * diff[j]);
  10643. }
  10644. };
  10645. },
  10646. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  10647. var domain = dict.get('Domain');
  10648. if (!domain) {
  10649. error('No domain');
  10650. }
  10651. var inputSize = domain.length / 2;
  10652. if (inputSize !== 1) {
  10653. error('Bad domain for stiched function');
  10654. }
  10655. var fnRefs = dict.get('Functions');
  10656. var fns = [];
  10657. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  10658. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  10659. }
  10660. var bounds = dict.get('Bounds');
  10661. var encode = dict.get('Encode');
  10662. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  10663. },
  10664. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  10665. var domain = IR[1];
  10666. var bounds = IR[2];
  10667. var encode = IR[3];
  10668. var fnsIR = IR[4];
  10669. var fns = [];
  10670. var tmpBuf = new Float32Array(1);
  10671. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  10672. fns.push(PDFFunction.fromIR(fnsIR[i]));
  10673. }
  10674. return function constructStichedFromIRResult(src, srcOffset,
  10675. dest, destOffset) {
  10676. var clip = function constructStichedFromIRClip(v, min, max) {
  10677. if (v > max) {
  10678. v = max;
  10679. } else if (v < min) {
  10680. v = min;
  10681. }
  10682. return v;
  10683. };
  10684. // clip to domain
  10685. var v = clip(src[srcOffset], domain[0], domain[1]);
  10686. // calulate which bound the value is in
  10687. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  10688. if (v < bounds[i]) {
  10689. break;
  10690. }
  10691. }
  10692. // encode value into domain of function
  10693. var dmin = domain[0];
  10694. if (i > 0) {
  10695. dmin = bounds[i - 1];
  10696. }
  10697. var dmax = domain[1];
  10698. if (i < bounds.length) {
  10699. dmax = bounds[i];
  10700. }
  10701. var rmin = encode[2 * i];
  10702. var rmax = encode[2 * i + 1];
  10703. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  10704. // call the appropriate function
  10705. fns[i](tmpBuf, 0, dest, destOffset);
  10706. };
  10707. },
  10708. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  10709. xref) {
  10710. var domain = dict.get('Domain');
  10711. var range = dict.get('Range');
  10712. if (!domain) {
  10713. error('No domain.');
  10714. }
  10715. if (!range) {
  10716. error('No range.');
  10717. }
  10718. var lexer = new PostScriptLexer(fn);
  10719. var parser = new PostScriptParser(lexer);
  10720. var code = parser.parse();
  10721. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  10722. },
  10723. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  10724. IR) {
  10725. var domain = IR[1];
  10726. var range = IR[2];
  10727. var code = IR[3];
  10728. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  10729. if (compiled) {
  10730. // Compiled function consists of simple expressions such as addition,
  10731. // subtraction, Math.max, and also contains 'var' and 'return'
  10732. // statements. See the generation in the PostScriptCompiler below.
  10733. /*jshint -W054 */
  10734. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  10735. }
  10736. info('Unable to compile PS function');
  10737. var numOutputs = range.length >> 1;
  10738. var numInputs = domain.length >> 1;
  10739. var evaluator = new PostScriptEvaluator(code);
  10740. // Cache the values for a big speed up, the cache size is limited though
  10741. // since the number of possible values can be huge from a PS function.
  10742. var cache = {};
  10743. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  10744. // seen in our tests.
  10745. var MAX_CACHE_SIZE = 2048 * 4;
  10746. var cache_available = MAX_CACHE_SIZE;
  10747. var tmpBuf = new Float32Array(numInputs);
  10748. return function constructPostScriptFromIRResult(src, srcOffset,
  10749. dest, destOffset) {
  10750. var i, value;
  10751. var key = '';
  10752. var input = tmpBuf;
  10753. for (i = 0; i < numInputs; i++) {
  10754. value = src[srcOffset + i];
  10755. input[i] = value;
  10756. key += value + '_';
  10757. }
  10758. var cachedValue = cache[key];
  10759. if (cachedValue !== undefined) {
  10760. dest.set(cachedValue, destOffset);
  10761. return;
  10762. }
  10763. var output = new Float32Array(numOutputs);
  10764. var stack = evaluator.execute(input);
  10765. var stackIndex = stack.length - numOutputs;
  10766. for (i = 0; i < numOutputs; i++) {
  10767. value = stack[stackIndex + i];
  10768. var bound = range[i * 2];
  10769. if (value < bound) {
  10770. value = bound;
  10771. } else {
  10772. bound = range[i * 2 +1];
  10773. if (value > bound) {
  10774. value = bound;
  10775. }
  10776. }
  10777. output[i] = value;
  10778. }
  10779. if (cache_available > 0) {
  10780. cache_available--;
  10781. cache[key] = output;
  10782. }
  10783. dest.set(output, destOffset);
  10784. };
  10785. }
  10786. };
  10787. })();
  10788. function isPDFFunction(v) {
  10789. var fnDict;
  10790. if (typeof v !== 'object') {
  10791. return false;
  10792. } else if (isDict(v)) {
  10793. fnDict = v;
  10794. } else if (isStream(v)) {
  10795. fnDict = v.dict;
  10796. } else {
  10797. return false;
  10798. }
  10799. return fnDict.has('FunctionType');
  10800. }
  10801. var PostScriptStack = (function PostScriptStackClosure() {
  10802. var MAX_STACK_SIZE = 100;
  10803. function PostScriptStack(initialStack) {
  10804. this.stack = !initialStack ? [] :
  10805. Array.prototype.slice.call(initialStack, 0);
  10806. }
  10807. PostScriptStack.prototype = {
  10808. push: function PostScriptStack_push(value) {
  10809. if (this.stack.length >= MAX_STACK_SIZE) {
  10810. error('PostScript function stack overflow.');
  10811. }
  10812. this.stack.push(value);
  10813. },
  10814. pop: function PostScriptStack_pop() {
  10815. if (this.stack.length <= 0) {
  10816. error('PostScript function stack underflow.');
  10817. }
  10818. return this.stack.pop();
  10819. },
  10820. copy: function PostScriptStack_copy(n) {
  10821. if (this.stack.length + n >= MAX_STACK_SIZE) {
  10822. error('PostScript function stack overflow.');
  10823. }
  10824. var stack = this.stack;
  10825. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  10826. stack.push(stack[i]);
  10827. }
  10828. },
  10829. index: function PostScriptStack_index(n) {
  10830. this.push(this.stack[this.stack.length - n - 1]);
  10831. },
  10832. // rotate the last n stack elements p times
  10833. roll: function PostScriptStack_roll(n, p) {
  10834. var stack = this.stack;
  10835. var l = stack.length - n;
  10836. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  10837. for (i = l, j = r; i < j; i++, j--) {
  10838. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10839. }
  10840. for (i = l, j = c - 1; i < j; i++, j--) {
  10841. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10842. }
  10843. for (i = c, j = r; i < j; i++, j--) {
  10844. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  10845. }
  10846. }
  10847. };
  10848. return PostScriptStack;
  10849. })();
  10850. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  10851. function PostScriptEvaluator(operators) {
  10852. this.operators = operators;
  10853. }
  10854. PostScriptEvaluator.prototype = {
  10855. execute: function PostScriptEvaluator_execute(initialStack) {
  10856. var stack = new PostScriptStack(initialStack);
  10857. var counter = 0;
  10858. var operators = this.operators;
  10859. var length = operators.length;
  10860. var operator, a, b;
  10861. while (counter < length) {
  10862. operator = operators[counter++];
  10863. if (typeof operator === 'number') {
  10864. // Operator is really an operand and should be pushed to the stack.
  10865. stack.push(operator);
  10866. continue;
  10867. }
  10868. switch (operator) {
  10869. // non standard ps operators
  10870. case 'jz': // jump if false
  10871. b = stack.pop();
  10872. a = stack.pop();
  10873. if (!a) {
  10874. counter = b;
  10875. }
  10876. break;
  10877. case 'j': // jump
  10878. a = stack.pop();
  10879. counter = a;
  10880. break;
  10881. // all ps operators in alphabetical order (excluding if/ifelse)
  10882. case 'abs':
  10883. a = stack.pop();
  10884. stack.push(Math.abs(a));
  10885. break;
  10886. case 'add':
  10887. b = stack.pop();
  10888. a = stack.pop();
  10889. stack.push(a + b);
  10890. break;
  10891. case 'and':
  10892. b = stack.pop();
  10893. a = stack.pop();
  10894. if (isBool(a) && isBool(b)) {
  10895. stack.push(a && b);
  10896. } else {
  10897. stack.push(a & b);
  10898. }
  10899. break;
  10900. case 'atan':
  10901. a = stack.pop();
  10902. stack.push(Math.atan(a));
  10903. break;
  10904. case 'bitshift':
  10905. b = stack.pop();
  10906. a = stack.pop();
  10907. if (a > 0) {
  10908. stack.push(a << b);
  10909. } else {
  10910. stack.push(a >> b);
  10911. }
  10912. break;
  10913. case 'ceiling':
  10914. a = stack.pop();
  10915. stack.push(Math.ceil(a));
  10916. break;
  10917. case 'copy':
  10918. a = stack.pop();
  10919. stack.copy(a);
  10920. break;
  10921. case 'cos':
  10922. a = stack.pop();
  10923. stack.push(Math.cos(a));
  10924. break;
  10925. case 'cvi':
  10926. a = stack.pop() | 0;
  10927. stack.push(a);
  10928. break;
  10929. case 'cvr':
  10930. // noop
  10931. break;
  10932. case 'div':
  10933. b = stack.pop();
  10934. a = stack.pop();
  10935. stack.push(a / b);
  10936. break;
  10937. case 'dup':
  10938. stack.copy(1);
  10939. break;
  10940. case 'eq':
  10941. b = stack.pop();
  10942. a = stack.pop();
  10943. stack.push(a === b);
  10944. break;
  10945. case 'exch':
  10946. stack.roll(2, 1);
  10947. break;
  10948. case 'exp':
  10949. b = stack.pop();
  10950. a = stack.pop();
  10951. stack.push(Math.pow(a, b));
  10952. break;
  10953. case 'false':
  10954. stack.push(false);
  10955. break;
  10956. case 'floor':
  10957. a = stack.pop();
  10958. stack.push(Math.floor(a));
  10959. break;
  10960. case 'ge':
  10961. b = stack.pop();
  10962. a = stack.pop();
  10963. stack.push(a >= b);
  10964. break;
  10965. case 'gt':
  10966. b = stack.pop();
  10967. a = stack.pop();
  10968. stack.push(a > b);
  10969. break;
  10970. case 'idiv':
  10971. b = stack.pop();
  10972. a = stack.pop();
  10973. stack.push((a / b) | 0);
  10974. break;
  10975. case 'index':
  10976. a = stack.pop();
  10977. stack.index(a);
  10978. break;
  10979. case 'le':
  10980. b = stack.pop();
  10981. a = stack.pop();
  10982. stack.push(a <= b);
  10983. break;
  10984. case 'ln':
  10985. a = stack.pop();
  10986. stack.push(Math.log(a));
  10987. break;
  10988. case 'log':
  10989. a = stack.pop();
  10990. stack.push(Math.log(a) / Math.LN10);
  10991. break;
  10992. case 'lt':
  10993. b = stack.pop();
  10994. a = stack.pop();
  10995. stack.push(a < b);
  10996. break;
  10997. case 'mod':
  10998. b = stack.pop();
  10999. a = stack.pop();
  11000. stack.push(a % b);
  11001. break;
  11002. case 'mul':
  11003. b = stack.pop();
  11004. a = stack.pop();
  11005. stack.push(a * b);
  11006. break;
  11007. case 'ne':
  11008. b = stack.pop();
  11009. a = stack.pop();
  11010. stack.push(a !== b);
  11011. break;
  11012. case 'neg':
  11013. a = stack.pop();
  11014. stack.push(-a);
  11015. break;
  11016. case 'not':
  11017. a = stack.pop();
  11018. if (isBool(a)) {
  11019. stack.push(!a);
  11020. } else {
  11021. stack.push(~a);
  11022. }
  11023. break;
  11024. case 'or':
  11025. b = stack.pop();
  11026. a = stack.pop();
  11027. if (isBool(a) && isBool(b)) {
  11028. stack.push(a || b);
  11029. } else {
  11030. stack.push(a | b);
  11031. }
  11032. break;
  11033. case 'pop':
  11034. stack.pop();
  11035. break;
  11036. case 'roll':
  11037. b = stack.pop();
  11038. a = stack.pop();
  11039. stack.roll(a, b);
  11040. break;
  11041. case 'round':
  11042. a = stack.pop();
  11043. stack.push(Math.round(a));
  11044. break;
  11045. case 'sin':
  11046. a = stack.pop();
  11047. stack.push(Math.sin(a));
  11048. break;
  11049. case 'sqrt':
  11050. a = stack.pop();
  11051. stack.push(Math.sqrt(a));
  11052. break;
  11053. case 'sub':
  11054. b = stack.pop();
  11055. a = stack.pop();
  11056. stack.push(a - b);
  11057. break;
  11058. case 'true':
  11059. stack.push(true);
  11060. break;
  11061. case 'truncate':
  11062. a = stack.pop();
  11063. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  11064. stack.push(a);
  11065. break;
  11066. case 'xor':
  11067. b = stack.pop();
  11068. a = stack.pop();
  11069. if (isBool(a) && isBool(b)) {
  11070. stack.push(a !== b);
  11071. } else {
  11072. stack.push(a ^ b);
  11073. }
  11074. break;
  11075. default:
  11076. error('Unknown operator ' + operator);
  11077. break;
  11078. }
  11079. }
  11080. return stack.stack;
  11081. }
  11082. };
  11083. return PostScriptEvaluator;
  11084. })();
  11085. // Most of the PDFs functions consist of simple operations such as:
  11086. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  11087. //
  11088. // We can compile most of such programs, and at the same moment, we can
  11089. // optimize some expressions using basic math properties. Keeping track of
  11090. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  11091. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  11092. function AstNode(type) {
  11093. this.type = type;
  11094. }
  11095. AstNode.prototype.visit = function (visitor) {
  11096. throw new Error('abstract method');
  11097. };
  11098. function AstArgument(index, min, max) {
  11099. AstNode.call(this, 'args');
  11100. this.index = index;
  11101. this.min = min;
  11102. this.max = max;
  11103. }
  11104. AstArgument.prototype = Object.create(AstNode.prototype);
  11105. AstArgument.prototype.visit = function (visitor) {
  11106. visitor.visitArgument(this);
  11107. };
  11108. function AstLiteral(number) {
  11109. AstNode.call(this, 'literal');
  11110. this.number = number;
  11111. this.min = number;
  11112. this.max = number;
  11113. }
  11114. AstLiteral.prototype = Object.create(AstNode.prototype);
  11115. AstLiteral.prototype.visit = function (visitor) {
  11116. visitor.visitLiteral(this);
  11117. };
  11118. function AstBinaryOperation(op, arg1, arg2, min, max) {
  11119. AstNode.call(this, 'binary');
  11120. this.op = op;
  11121. this.arg1 = arg1;
  11122. this.arg2 = arg2;
  11123. this.min = min;
  11124. this.max = max;
  11125. }
  11126. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  11127. AstBinaryOperation.prototype.visit = function (visitor) {
  11128. visitor.visitBinaryOperation(this);
  11129. };
  11130. function AstMin(arg, max) {
  11131. AstNode.call(this, 'max');
  11132. this.arg = arg;
  11133. this.min = arg.min;
  11134. this.max = max;
  11135. }
  11136. AstMin.prototype = Object.create(AstNode.prototype);
  11137. AstMin.prototype.visit = function (visitor) {
  11138. visitor.visitMin(this);
  11139. };
  11140. function AstVariable(index, min, max) {
  11141. AstNode.call(this, 'var');
  11142. this.index = index;
  11143. this.min = min;
  11144. this.max = max;
  11145. }
  11146. AstVariable.prototype = Object.create(AstNode.prototype);
  11147. AstVariable.prototype.visit = function (visitor) {
  11148. visitor.visitVariable(this);
  11149. };
  11150. function AstVariableDefinition(variable, arg) {
  11151. AstNode.call(this, 'definition');
  11152. this.variable = variable;
  11153. this.arg = arg;
  11154. }
  11155. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  11156. AstVariableDefinition.prototype.visit = function (visitor) {
  11157. visitor.visitVariableDefinition(this);
  11158. };
  11159. function ExpressionBuilderVisitor() {
  11160. this.parts = [];
  11161. }
  11162. ExpressionBuilderVisitor.prototype = {
  11163. visitArgument: function (arg) {
  11164. this.parts.push('Math.max(', arg.min, ', Math.min(',
  11165. arg.max, ', src[srcOffset + ', arg.index, ']))');
  11166. },
  11167. visitVariable: function (variable) {
  11168. this.parts.push('v', variable.index);
  11169. },
  11170. visitLiteral: function (literal) {
  11171. this.parts.push(literal.number);
  11172. },
  11173. visitBinaryOperation: function (operation) {
  11174. this.parts.push('(');
  11175. operation.arg1.visit(this);
  11176. this.parts.push(' ', operation.op, ' ');
  11177. operation.arg2.visit(this);
  11178. this.parts.push(')');
  11179. },
  11180. visitVariableDefinition: function (definition) {
  11181. this.parts.push('var ');
  11182. definition.variable.visit(this);
  11183. this.parts.push(' = ');
  11184. definition.arg.visit(this);
  11185. this.parts.push(';');
  11186. },
  11187. visitMin: function (max) {
  11188. this.parts.push('Math.min(');
  11189. max.arg.visit(this);
  11190. this.parts.push(', ', max.max, ')');
  11191. },
  11192. toString: function () {
  11193. return this.parts.join('');
  11194. }
  11195. };
  11196. function buildAddOperation(num1, num2) {
  11197. if (num2.type === 'literal' && num2.number === 0) {
  11198. // optimization: second operand is 0
  11199. return num1;
  11200. }
  11201. if (num1.type === 'literal' && num1.number === 0) {
  11202. // optimization: first operand is 0
  11203. return num2;
  11204. }
  11205. if (num2.type === 'literal' && num1.type === 'literal') {
  11206. // optimization: operands operand are literals
  11207. return new AstLiteral(num1.number + num2.number);
  11208. }
  11209. return new AstBinaryOperation('+', num1, num2,
  11210. num1.min + num2.min, num1.max + num2.max);
  11211. }
  11212. function buildMulOperation(num1, num2) {
  11213. if (num2.type === 'literal') {
  11214. // optimization: second operands is a literal...
  11215. if (num2.number === 0) {
  11216. return new AstLiteral(0); // and it's 0
  11217. } else if (num2.number === 1) {
  11218. return num1; // and it's 1
  11219. } else if (num1.type === 'literal') {
  11220. // ... and first operands is a literal too
  11221. return new AstLiteral(num1.number * num2.number);
  11222. }
  11223. }
  11224. if (num1.type === 'literal') {
  11225. // optimization: first operands is a literal...
  11226. if (num1.number === 0) {
  11227. return new AstLiteral(0); // and it's 0
  11228. } else if (num1.number === 1) {
  11229. return num2; // and it's 1
  11230. }
  11231. }
  11232. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  11233. num1.max * num2.min, num1.max * num2.max);
  11234. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  11235. num1.max * num2.min, num1.max * num2.max);
  11236. return new AstBinaryOperation('*', num1, num2, min, max);
  11237. }
  11238. function buildSubOperation(num1, num2) {
  11239. if (num2.type === 'literal') {
  11240. // optimization: second operands is a literal...
  11241. if (num2.number === 0) {
  11242. return num1; // ... and it's 0
  11243. } else if (num1.type === 'literal') {
  11244. // ... and first operands is a literal too
  11245. return new AstLiteral(num1.number - num2.number);
  11246. }
  11247. }
  11248. if (num2.type === 'binary' && num2.op === '-' &&
  11249. num1.type === 'literal' && num1.number === 1 &&
  11250. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  11251. // optimization for case: 1 - (1 - x)
  11252. return num2.arg2;
  11253. }
  11254. return new AstBinaryOperation('-', num1, num2,
  11255. num1.min - num2.max, num1.max - num2.min);
  11256. }
  11257. function buildMinOperation(num1, max) {
  11258. if (num1.min >= max) {
  11259. // optimization: num1 min value is not less than required max
  11260. return new AstLiteral(max); // just returning max
  11261. } else if (num1.max <= max) {
  11262. // optimization: num1 max value is not greater than required max
  11263. return num1; // just returning an argument
  11264. }
  11265. return new AstMin(num1, max);
  11266. }
  11267. function PostScriptCompiler() {}
  11268. PostScriptCompiler.prototype = {
  11269. compile: function PostScriptCompiler_compile(code, domain, range) {
  11270. var stack = [];
  11271. var i, ii;
  11272. var instructions = [];
  11273. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  11274. var lastRegister = 0;
  11275. var n, j, min, max;
  11276. var num1, num2, ast1, ast2, tmpVar, item;
  11277. for (i = 0; i < inputSize; i++) {
  11278. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  11279. }
  11280. for (i = 0, ii = code.length; i < ii; i++) {
  11281. item = code[i];
  11282. if (typeof item === 'number') {
  11283. stack.push(new AstLiteral(item));
  11284. continue;
  11285. }
  11286. switch (item) {
  11287. case 'add':
  11288. if (stack.length < 2) {
  11289. return null;
  11290. }
  11291. num2 = stack.pop();
  11292. num1 = stack.pop();
  11293. stack.push(buildAddOperation(num1, num2));
  11294. break;
  11295. case 'cvr':
  11296. if (stack.length < 1) {
  11297. return null;
  11298. }
  11299. break;
  11300. case 'mul':
  11301. if (stack.length < 2) {
  11302. return null;
  11303. }
  11304. num2 = stack.pop();
  11305. num1 = stack.pop();
  11306. stack.push(buildMulOperation(num1, num2));
  11307. break;
  11308. case 'sub':
  11309. if (stack.length < 2) {
  11310. return null;
  11311. }
  11312. num2 = stack.pop();
  11313. num1 = stack.pop();
  11314. stack.push(buildSubOperation(num1, num2));
  11315. break;
  11316. case 'exch':
  11317. if (stack.length < 2) {
  11318. return null;
  11319. }
  11320. ast1 = stack.pop(); ast2 = stack.pop();
  11321. stack.push(ast1, ast2);
  11322. break;
  11323. case 'pop':
  11324. if (stack.length < 1) {
  11325. return null;
  11326. }
  11327. stack.pop();
  11328. break;
  11329. case 'index':
  11330. if (stack.length < 1) {
  11331. return null;
  11332. }
  11333. num1 = stack.pop();
  11334. if (num1.type !== 'literal') {
  11335. return null;
  11336. }
  11337. n = num1.number;
  11338. if (n < 0 || (n|0) !== n || stack.length < n) {
  11339. return null;
  11340. }
  11341. ast1 = stack[stack.length - n - 1];
  11342. if (ast1.type === 'literal' || ast1.type === 'var') {
  11343. stack.push(ast1);
  11344. break;
  11345. }
  11346. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11347. stack[stack.length - n - 1] = tmpVar;
  11348. stack.push(tmpVar);
  11349. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11350. break;
  11351. case 'dup':
  11352. if (stack.length < 1) {
  11353. return null;
  11354. }
  11355. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  11356. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  11357. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  11358. // special case of the commands sequence for the min operation
  11359. num1 = stack.pop();
  11360. stack.push(buildMinOperation(num1, code[i + 1]));
  11361. i += 6;
  11362. break;
  11363. }
  11364. ast1 = stack[stack.length - 1];
  11365. if (ast1.type === 'literal' || ast1.type === 'var') {
  11366. // we don't have to save into intermediate variable a literal or
  11367. // variable.
  11368. stack.push(ast1);
  11369. break;
  11370. }
  11371. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  11372. stack[stack.length - 1] = tmpVar;
  11373. stack.push(tmpVar);
  11374. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  11375. break;
  11376. case 'roll':
  11377. if (stack.length < 2) {
  11378. return null;
  11379. }
  11380. num2 = stack.pop();
  11381. num1 = stack.pop();
  11382. if (num2.type !== 'literal' || num1.type !== 'literal') {
  11383. // both roll operands must be numbers
  11384. return null;
  11385. }
  11386. j = num2.number;
  11387. n = num1.number;
  11388. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  11389. // ... and integers
  11390. return null;
  11391. }
  11392. j = ((j % n) + n) % n;
  11393. if (j === 0) {
  11394. break; // just skipping -- there are nothing to rotate
  11395. }
  11396. Array.prototype.push.apply(stack,
  11397. stack.splice(stack.length - n, n - j));
  11398. break;
  11399. default:
  11400. return null; // unsupported operator
  11401. }
  11402. }
  11403. if (stack.length !== outputSize) {
  11404. return null;
  11405. }
  11406. var result = [];
  11407. instructions.forEach(function (instruction) {
  11408. var statementBuilder = new ExpressionBuilderVisitor();
  11409. instruction.visit(statementBuilder);
  11410. result.push(statementBuilder.toString());
  11411. });
  11412. stack.forEach(function (expr, i) {
  11413. var statementBuilder = new ExpressionBuilderVisitor();
  11414. expr.visit(statementBuilder);
  11415. var min = range[i * 2], max = range[i * 2 + 1];
  11416. var out = [statementBuilder.toString()];
  11417. if (min > expr.min) {
  11418. out.unshift('Math.max(', min, ', ');
  11419. out.push(')');
  11420. }
  11421. if (max < expr.max) {
  11422. out.unshift('Math.min(', max, ', ');
  11423. out.push(')');
  11424. }
  11425. out.unshift('dest[destOffset + ', i, '] = ');
  11426. out.push(';');
  11427. result.push(out.join(''));
  11428. });
  11429. return result.join('\n');
  11430. }
  11431. };
  11432. return PostScriptCompiler;
  11433. })();
  11434. var ColorSpace = (function ColorSpaceClosure() {
  11435. // Constructor should define this.numComps, this.defaultColor, this.name
  11436. function ColorSpace() {
  11437. error('should not call ColorSpace constructor');
  11438. }
  11439. ColorSpace.prototype = {
  11440. /**
  11441. * Converts the color value to the RGB color. The color components are
  11442. * located in the src array starting from the srcOffset. Returns the array
  11443. * of the rgb components, each value ranging from [0,255].
  11444. */
  11445. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  11446. var rgb = new Uint8Array(3);
  11447. this.getRgbItem(src, srcOffset, rgb, 0);
  11448. return rgb;
  11449. },
  11450. /**
  11451. * Converts the color value to the RGB color, similar to the getRgb method.
  11452. * The result placed into the dest array starting from the destOffset.
  11453. */
  11454. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  11455. dest, destOffset) {
  11456. error('Should not call ColorSpace.getRgbItem');
  11457. },
  11458. /**
  11459. * Converts the specified number of the color values to the RGB colors.
  11460. * The colors are located in the src array starting from the srcOffset.
  11461. * The result is placed into the dest array starting from the destOffset.
  11462. * The src array items shall be in [0,2^bits) range, the dest array items
  11463. * will be in [0,255] range. alpha01 indicates how many alpha components
  11464. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  11465. * array).
  11466. */
  11467. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  11468. dest, destOffset, bits,
  11469. alpha01) {
  11470. error('Should not call ColorSpace.getRgbBuffer');
  11471. },
  11472. /**
  11473. * Determines the number of bytes required to store the result of the
  11474. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  11475. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  11476. */
  11477. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  11478. alpha01) {
  11479. error('Should not call ColorSpace.getOutputLength');
  11480. },
  11481. /**
  11482. * Returns true if source data will be equal the result/output data.
  11483. */
  11484. isPassthrough: function ColorSpace_isPassthrough(bits) {
  11485. return false;
  11486. },
  11487. /**
  11488. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  11489. * how many alpha components there are in the dest array; it will be either
  11490. * 0 (RGB array) or 1 (RGBA array).
  11491. */
  11492. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  11493. originalHeight, width, height,
  11494. actualHeight, bpc, comps, alpha01) {
  11495. var count = originalWidth * originalHeight;
  11496. var rgbBuf = null;
  11497. var numComponentColors = 1 << bpc;
  11498. var needsResizing = originalHeight !== height || originalWidth !== width;
  11499. var i, ii;
  11500. if (this.isPassthrough(bpc)) {
  11501. rgbBuf = comps;
  11502. } else if (this.numComps === 1 && count > numComponentColors &&
  11503. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  11504. // Optimization: create a color map when there is just one component and
  11505. // we are converting more colors than the size of the color map. We
  11506. // don't build the map if the colorspace is gray or rgb since those
  11507. // methods are faster than building a map. This mainly offers big speed
  11508. // ups for indexed and alternate colorspaces.
  11509. //
  11510. // TODO it may be worth while to cache the color map. While running
  11511. // testing I never hit a cache so I will leave that out for now (perhaps
  11512. // we are reparsing colorspaces too much?).
  11513. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  11514. new Uint16Array(numComponentColors);
  11515. var key;
  11516. for (i = 0; i < numComponentColors; i++) {
  11517. allColors[i] = i;
  11518. }
  11519. var colorMap = new Uint8Array(numComponentColors * 3);
  11520. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  11521. /* alpha01 = */ 0);
  11522. var destPos, rgbPos;
  11523. if (!needsResizing) {
  11524. // Fill in the RGB values directly into |dest|.
  11525. destPos = 0;
  11526. for (i = 0; i < count; ++i) {
  11527. key = comps[i] * 3;
  11528. dest[destPos++] = colorMap[key];
  11529. dest[destPos++] = colorMap[key + 1];
  11530. dest[destPos++] = colorMap[key + 2];
  11531. destPos += alpha01;
  11532. }
  11533. } else {
  11534. rgbBuf = new Uint8Array(count * 3);
  11535. rgbPos = 0;
  11536. for (i = 0; i < count; ++i) {
  11537. key = comps[i] * 3;
  11538. rgbBuf[rgbPos++] = colorMap[key];
  11539. rgbBuf[rgbPos++] = colorMap[key + 1];
  11540. rgbBuf[rgbPos++] = colorMap[key + 2];
  11541. }
  11542. }
  11543. } else {
  11544. if (!needsResizing) {
  11545. // Fill in the RGB values directly into |dest|.
  11546. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  11547. alpha01);
  11548. } else {
  11549. rgbBuf = new Uint8Array(count * 3);
  11550. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  11551. /* alpha01 = */ 0);
  11552. }
  11553. }
  11554. if (rgbBuf) {
  11555. if (needsResizing) {
  11556. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  11557. height, dest, alpha01);
  11558. } else {
  11559. rgbPos = 0;
  11560. destPos = 0;
  11561. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  11562. dest[destPos++] = rgbBuf[rgbPos++];
  11563. dest[destPos++] = rgbBuf[rgbPos++];
  11564. dest[destPos++] = rgbBuf[rgbPos++];
  11565. destPos += alpha01;
  11566. }
  11567. }
  11568. }
  11569. },
  11570. /**
  11571. * True if the colorspace has components in the default range of [0, 1].
  11572. * This should be true for all colorspaces except for lab color spaces
  11573. * which are [0,100], [-128, 127], [-128, 127].
  11574. */
  11575. usesZeroToOneRange: true
  11576. };
  11577. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  11578. var IR = ColorSpace.parseToIR(cs, xref, res);
  11579. if (IR instanceof AlternateCS) {
  11580. return IR;
  11581. }
  11582. return ColorSpace.fromIR(IR);
  11583. };
  11584. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  11585. var name = isArray(IR) ? IR[0] : IR;
  11586. var whitePoint, blackPoint, gamma;
  11587. switch (name) {
  11588. case 'DeviceGrayCS':
  11589. return this.singletons.gray;
  11590. case 'DeviceRgbCS':
  11591. return this.singletons.rgb;
  11592. case 'DeviceCmykCS':
  11593. return this.singletons.cmyk;
  11594. case 'CalGrayCS':
  11595. whitePoint = IR[1].WhitePoint;
  11596. blackPoint = IR[1].BlackPoint;
  11597. gamma = IR[1].Gamma;
  11598. return new CalGrayCS(whitePoint, blackPoint, gamma);
  11599. case 'CalRGBCS':
  11600. whitePoint = IR[1].WhitePoint;
  11601. blackPoint = IR[1].BlackPoint;
  11602. gamma = IR[1].Gamma;
  11603. var matrix = IR[1].Matrix;
  11604. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  11605. case 'PatternCS':
  11606. var basePatternCS = IR[1];
  11607. if (basePatternCS) {
  11608. basePatternCS = ColorSpace.fromIR(basePatternCS);
  11609. }
  11610. return new PatternCS(basePatternCS);
  11611. case 'IndexedCS':
  11612. var baseIndexedCS = IR[1];
  11613. var hiVal = IR[2];
  11614. var lookup = IR[3];
  11615. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  11616. case 'AlternateCS':
  11617. var numComps = IR[1];
  11618. var alt = IR[2];
  11619. var tintFnIR = IR[3];
  11620. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  11621. PDFFunction.fromIR(tintFnIR));
  11622. case 'LabCS':
  11623. whitePoint = IR[1].WhitePoint;
  11624. blackPoint = IR[1].BlackPoint;
  11625. var range = IR[1].Range;
  11626. return new LabCS(whitePoint, blackPoint, range);
  11627. default:
  11628. error('Unknown name ' + name);
  11629. }
  11630. return null;
  11631. };
  11632. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  11633. if (isName(cs)) {
  11634. var colorSpaces = res.get('ColorSpace');
  11635. if (isDict(colorSpaces)) {
  11636. var refcs = colorSpaces.get(cs.name);
  11637. if (refcs) {
  11638. cs = refcs;
  11639. }
  11640. }
  11641. }
  11642. cs = xref.fetchIfRef(cs);
  11643. var mode;
  11644. if (isName(cs)) {
  11645. mode = cs.name;
  11646. this.mode = mode;
  11647. switch (mode) {
  11648. case 'DeviceGray':
  11649. case 'G':
  11650. return 'DeviceGrayCS';
  11651. case 'DeviceRGB':
  11652. case 'RGB':
  11653. return 'DeviceRgbCS';
  11654. case 'DeviceCMYK':
  11655. case 'CMYK':
  11656. return 'DeviceCmykCS';
  11657. case 'Pattern':
  11658. return ['PatternCS', null];
  11659. default:
  11660. error('unrecognized colorspace ' + mode);
  11661. }
  11662. } else if (isArray(cs)) {
  11663. mode = cs[0].name;
  11664. this.mode = mode;
  11665. var numComps, params;
  11666. switch (mode) {
  11667. case 'DeviceGray':
  11668. case 'G':
  11669. return 'DeviceGrayCS';
  11670. case 'DeviceRGB':
  11671. case 'RGB':
  11672. return 'DeviceRgbCS';
  11673. case 'DeviceCMYK':
  11674. case 'CMYK':
  11675. return 'DeviceCmykCS';
  11676. case 'CalGray':
  11677. params = xref.fetchIfRef(cs[1]).getAll();
  11678. return ['CalGrayCS', params];
  11679. case 'CalRGB':
  11680. params = xref.fetchIfRef(cs[1]).getAll();
  11681. return ['CalRGBCS', params];
  11682. case 'ICCBased':
  11683. var stream = xref.fetchIfRef(cs[1]);
  11684. var dict = stream.dict;
  11685. numComps = dict.get('N');
  11686. if (numComps === 1) {
  11687. return 'DeviceGrayCS';
  11688. } else if (numComps === 3) {
  11689. return 'DeviceRgbCS';
  11690. } else if (numComps === 4) {
  11691. return 'DeviceCmykCS';
  11692. }
  11693. break;
  11694. case 'Pattern':
  11695. var basePatternCS = cs[1];
  11696. if (basePatternCS) {
  11697. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  11698. }
  11699. return ['PatternCS', basePatternCS];
  11700. case 'Indexed':
  11701. case 'I':
  11702. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  11703. var hiVal = cs[2] + 1;
  11704. var lookup = xref.fetchIfRef(cs[3]);
  11705. if (isStream(lookup)) {
  11706. lookup = lookup.getBytes();
  11707. }
  11708. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  11709. case 'Separation':
  11710. case 'DeviceN':
  11711. var name = cs[1];
  11712. numComps = 1;
  11713. if (isName(name)) {
  11714. numComps = 1;
  11715. } else if (isArray(name)) {
  11716. numComps = name.length;
  11717. }
  11718. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  11719. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  11720. return ['AlternateCS', numComps, alt, tintFnIR];
  11721. case 'Lab':
  11722. params = cs[1].getAll();
  11723. return ['LabCS', params];
  11724. default:
  11725. error('unimplemented color space object "' + mode + '"');
  11726. }
  11727. } else {
  11728. error('unrecognized color space object: "' + cs + '"');
  11729. }
  11730. return null;
  11731. };
  11732. /**
  11733. * Checks if a decode map matches the default decode map for a color space.
  11734. * This handles the general decode maps where there are two values per
  11735. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  11736. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  11737. * slightly different.
  11738. * @param {Array} decode Decode map (usually from an image).
  11739. * @param {Number} n Number of components the color space has.
  11740. */
  11741. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  11742. if (!decode) {
  11743. return true;
  11744. }
  11745. if (n * 2 !== decode.length) {
  11746. warn('The decode map is not the correct length');
  11747. return true;
  11748. }
  11749. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  11750. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  11751. return false;
  11752. }
  11753. }
  11754. return true;
  11755. };
  11756. ColorSpace.singletons = {
  11757. get gray() {
  11758. return shadow(this, 'gray', new DeviceGrayCS());
  11759. },
  11760. get rgb() {
  11761. return shadow(this, 'rgb', new DeviceRgbCS());
  11762. },
  11763. get cmyk() {
  11764. return shadow(this, 'cmyk', new DeviceCmykCS());
  11765. }
  11766. };
  11767. return ColorSpace;
  11768. })();
  11769. /**
  11770. * Alternate color space handles both Separation and DeviceN color spaces. A
  11771. * Separation color space is actually just a DeviceN with one color component.
  11772. * Both color spaces use a tinting function to convert colors to a base color
  11773. * space.
  11774. */
  11775. var AlternateCS = (function AlternateCSClosure() {
  11776. function AlternateCS(numComps, base, tintFn) {
  11777. this.name = 'Alternate';
  11778. this.numComps = numComps;
  11779. this.defaultColor = new Float32Array(numComps);
  11780. for (var i = 0; i < numComps; ++i) {
  11781. this.defaultColor[i] = 1;
  11782. }
  11783. this.base = base;
  11784. this.tintFn = tintFn;
  11785. this.tmpBuf = new Float32Array(base.numComps);
  11786. }
  11787. AlternateCS.prototype = {
  11788. getRgb: ColorSpace.prototype.getRgb,
  11789. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  11790. dest, destOffset) {
  11791. var tmpBuf = this.tmpBuf;
  11792. this.tintFn(src, srcOffset, tmpBuf, 0);
  11793. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  11794. },
  11795. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  11796. dest, destOffset, bits,
  11797. alpha01) {
  11798. var tintFn = this.tintFn;
  11799. var base = this.base;
  11800. var scale = 1 / ((1 << bits) - 1);
  11801. var baseNumComps = base.numComps;
  11802. var usesZeroToOneRange = base.usesZeroToOneRange;
  11803. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  11804. alpha01 === 0;
  11805. var pos = isPassthrough ? destOffset : 0;
  11806. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  11807. var numComps = this.numComps;
  11808. var scaled = new Float32Array(numComps);
  11809. var tinted = new Float32Array(baseNumComps);
  11810. var i, j;
  11811. if (usesZeroToOneRange) {
  11812. for (i = 0; i < count; i++) {
  11813. for (j = 0; j < numComps; j++) {
  11814. scaled[j] = src[srcOffset++] * scale;
  11815. }
  11816. tintFn(scaled, 0, tinted, 0);
  11817. for (j = 0; j < baseNumComps; j++) {
  11818. baseBuf[pos++] = tinted[j] * 255;
  11819. }
  11820. }
  11821. } else {
  11822. for (i = 0; i < count; i++) {
  11823. for (j = 0; j < numComps; j++) {
  11824. scaled[j] = src[srcOffset++] * scale;
  11825. }
  11826. tintFn(scaled, 0, tinted, 0);
  11827. base.getRgbItem(tinted, 0, baseBuf, pos);
  11828. pos += baseNumComps;
  11829. }
  11830. }
  11831. if (!isPassthrough) {
  11832. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  11833. }
  11834. },
  11835. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  11836. alpha01) {
  11837. return this.base.getOutputLength(inputLength *
  11838. this.base.numComps / this.numComps,
  11839. alpha01);
  11840. },
  11841. isPassthrough: ColorSpace.prototype.isPassthrough,
  11842. fillRgb: ColorSpace.prototype.fillRgb,
  11843. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  11844. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11845. },
  11846. usesZeroToOneRange: true
  11847. };
  11848. return AlternateCS;
  11849. })();
  11850. var PatternCS = (function PatternCSClosure() {
  11851. function PatternCS(baseCS) {
  11852. this.name = 'Pattern';
  11853. this.base = baseCS;
  11854. }
  11855. PatternCS.prototype = {};
  11856. return PatternCS;
  11857. })();
  11858. var IndexedCS = (function IndexedCSClosure() {
  11859. function IndexedCS(base, highVal, lookup) {
  11860. this.name = 'Indexed';
  11861. this.numComps = 1;
  11862. this.defaultColor = new Uint8Array([0]);
  11863. this.base = base;
  11864. this.highVal = highVal;
  11865. var baseNumComps = base.numComps;
  11866. var length = baseNumComps * highVal;
  11867. var lookupArray;
  11868. if (isStream(lookup)) {
  11869. lookupArray = new Uint8Array(length);
  11870. var bytes = lookup.getBytes(length);
  11871. lookupArray.set(bytes);
  11872. } else if (isString(lookup)) {
  11873. lookupArray = new Uint8Array(length);
  11874. for (var i = 0; i < length; ++i) {
  11875. lookupArray[i] = lookup.charCodeAt(i);
  11876. }
  11877. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  11878. lookupArray = lookup;
  11879. } else {
  11880. error('Unrecognized lookup table: ' + lookup);
  11881. }
  11882. this.lookup = lookupArray;
  11883. }
  11884. IndexedCS.prototype = {
  11885. getRgb: ColorSpace.prototype.getRgb,
  11886. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  11887. dest, destOffset) {
  11888. var numComps = this.base.numComps;
  11889. var start = src[srcOffset] * numComps;
  11890. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  11891. },
  11892. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  11893. dest, destOffset, bits,
  11894. alpha01) {
  11895. var base = this.base;
  11896. var numComps = base.numComps;
  11897. var outputDelta = base.getOutputLength(numComps, alpha01);
  11898. var lookup = this.lookup;
  11899. for (var i = 0; i < count; ++i) {
  11900. var lookupPos = src[srcOffset++] * numComps;
  11901. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  11902. destOffset += outputDelta;
  11903. }
  11904. },
  11905. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  11906. return this.base.getOutputLength(inputLength * this.base.numComps,
  11907. alpha01);
  11908. },
  11909. isPassthrough: ColorSpace.prototype.isPassthrough,
  11910. fillRgb: ColorSpace.prototype.fillRgb,
  11911. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  11912. // indexed color maps shouldn't be changed
  11913. return true;
  11914. },
  11915. usesZeroToOneRange: true
  11916. };
  11917. return IndexedCS;
  11918. })();
  11919. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  11920. function DeviceGrayCS() {
  11921. this.name = 'DeviceGray';
  11922. this.numComps = 1;
  11923. this.defaultColor = new Float32Array([0]);
  11924. }
  11925. DeviceGrayCS.prototype = {
  11926. getRgb: ColorSpace.prototype.getRgb,
  11927. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  11928. dest, destOffset) {
  11929. var c = (src[srcOffset] * 255) | 0;
  11930. c = c < 0 ? 0 : c > 255 ? 255 : c;
  11931. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  11932. },
  11933. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  11934. dest, destOffset, bits,
  11935. alpha01) {
  11936. var scale = 255 / ((1 << bits) - 1);
  11937. var j = srcOffset, q = destOffset;
  11938. for (var i = 0; i < count; ++i) {
  11939. var c = (scale * src[j++]) | 0;
  11940. dest[q++] = c;
  11941. dest[q++] = c;
  11942. dest[q++] = c;
  11943. q += alpha01;
  11944. }
  11945. },
  11946. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  11947. alpha01) {
  11948. return inputLength * (3 + alpha01);
  11949. },
  11950. isPassthrough: ColorSpace.prototype.isPassthrough,
  11951. fillRgb: ColorSpace.prototype.fillRgb,
  11952. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  11953. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  11954. },
  11955. usesZeroToOneRange: true
  11956. };
  11957. return DeviceGrayCS;
  11958. })();
  11959. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  11960. function DeviceRgbCS() {
  11961. this.name = 'DeviceRGB';
  11962. this.numComps = 3;
  11963. this.defaultColor = new Float32Array([0, 0, 0]);
  11964. }
  11965. DeviceRgbCS.prototype = {
  11966. getRgb: ColorSpace.prototype.getRgb,
  11967. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  11968. dest, destOffset) {
  11969. var r = (src[srcOffset] * 255) | 0;
  11970. var g = (src[srcOffset + 1] * 255) | 0;
  11971. var b = (src[srcOffset + 2] * 255) | 0;
  11972. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  11973. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  11974. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  11975. },
  11976. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  11977. dest, destOffset, bits,
  11978. alpha01) {
  11979. if (bits === 8 && alpha01 === 0) {
  11980. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  11981. return;
  11982. }
  11983. var scale = 255 / ((1 << bits) - 1);
  11984. var j = srcOffset, q = destOffset;
  11985. for (var i = 0; i < count; ++i) {
  11986. dest[q++] = (scale * src[j++]) | 0;
  11987. dest[q++] = (scale * src[j++]) | 0;
  11988. dest[q++] = (scale * src[j++]) | 0;
  11989. q += alpha01;
  11990. }
  11991. },
  11992. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  11993. alpha01) {
  11994. return (inputLength * (3 + alpha01) / 3) | 0;
  11995. },
  11996. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  11997. return bits === 8;
  11998. },
  11999. fillRgb: ColorSpace.prototype.fillRgb,
  12000. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  12001. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12002. },
  12003. usesZeroToOneRange: true
  12004. };
  12005. return DeviceRgbCS;
  12006. })();
  12007. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  12008. // The coefficients below was found using numerical analysis: the method of
  12009. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  12010. // where color_value is the tabular value from the table of sampled RGB colors
  12011. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  12012. // CMYK color conversion using the estimation below:
  12013. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  12014. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  12015. var c = src[srcOffset + 0] * srcScale;
  12016. var m = src[srcOffset + 1] * srcScale;
  12017. var y = src[srcOffset + 2] * srcScale;
  12018. var k = src[srcOffset + 3] * srcScale;
  12019. var r =
  12020. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  12021. 18.82290502165302 * y + 212.25662451639585 * k +
  12022. -285.2331026137004) +
  12023. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  12024. -17.873870861415444 * k - 5.497006427196366) +
  12025. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  12026. 17.5119270841813) +
  12027. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  12028. var g =
  12029. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  12030. 6.871425592049007 * y + 31.159100130055922 * k +
  12031. -79.2970844816548) +
  12032. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  12033. 131.35250912493976 * k - 190.9453302588951) +
  12034. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  12035. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  12036. var b =
  12037. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  12038. 30.89978309703729 * y - 0.23883238689178934 * k +
  12039. -14.183576799673286) +
  12040. m * (10.49593273432072 * m + 63.02378494754052 * y +
  12041. 50.606957656360734 * k - 112.23884253719248) +
  12042. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  12043. -193.58209356861505) +
  12044. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  12045. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  12046. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  12047. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  12048. }
  12049. function DeviceCmykCS() {
  12050. this.name = 'DeviceCMYK';
  12051. this.numComps = 4;
  12052. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  12053. }
  12054. DeviceCmykCS.prototype = {
  12055. getRgb: ColorSpace.prototype.getRgb,
  12056. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  12057. dest, destOffset) {
  12058. convertToRgb(src, srcOffset, 1, dest, destOffset);
  12059. },
  12060. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  12061. dest, destOffset, bits,
  12062. alpha01) {
  12063. var scale = 1 / ((1 << bits) - 1);
  12064. for (var i = 0; i < count; i++) {
  12065. convertToRgb(src, srcOffset, scale, dest, destOffset);
  12066. srcOffset += 4;
  12067. destOffset += 3 + alpha01;
  12068. }
  12069. },
  12070. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  12071. alpha01) {
  12072. return (inputLength / 4 * (3 + alpha01)) | 0;
  12073. },
  12074. isPassthrough: ColorSpace.prototype.isPassthrough,
  12075. fillRgb: ColorSpace.prototype.fillRgb,
  12076. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  12077. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12078. },
  12079. usesZeroToOneRange: true
  12080. };
  12081. return DeviceCmykCS;
  12082. })();
  12083. //
  12084. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  12085. //
  12086. var CalGrayCS = (function CalGrayCSClosure() {
  12087. function CalGrayCS(whitePoint, blackPoint, gamma) {
  12088. this.name = 'CalGray';
  12089. this.numComps = 1;
  12090. this.defaultColor = new Float32Array([0]);
  12091. if (!whitePoint) {
  12092. error('WhitePoint missing - required for color space CalGray');
  12093. }
  12094. blackPoint = blackPoint || [0, 0, 0];
  12095. gamma = gamma || 1;
  12096. // Translate arguments to spec variables.
  12097. this.XW = whitePoint[0];
  12098. this.YW = whitePoint[1];
  12099. this.ZW = whitePoint[2];
  12100. this.XB = blackPoint[0];
  12101. this.YB = blackPoint[1];
  12102. this.ZB = blackPoint[2];
  12103. this.G = gamma;
  12104. // Validate variables as per spec.
  12105. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12106. error('Invalid WhitePoint components for ' + this.name +
  12107. ', no fallback available');
  12108. }
  12109. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12110. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  12111. this.XB = this.YB = this.ZB = 0;
  12112. }
  12113. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  12114. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  12115. ', ZB: ' + this.ZB + ', only default values are supported.');
  12116. }
  12117. if (this.G < 1) {
  12118. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  12119. ', falling back to default');
  12120. this.G = 1;
  12121. }
  12122. }
  12123. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12124. // A represents a gray component of a calibrated gray space.
  12125. // A <---> AG in the spec
  12126. var A = src[srcOffset] * scale;
  12127. var AG = Math.pow(A, cs.G);
  12128. // Computes L as per spec. ( = cs.YW * AG )
  12129. // Except if other than default BlackPoint values are used.
  12130. var L = cs.YW * AG;
  12131. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  12132. // Convert values to rgb range [0, 255].
  12133. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  12134. dest[destOffset] = val;
  12135. dest[destOffset + 1] = val;
  12136. dest[destOffset + 2] = val;
  12137. }
  12138. CalGrayCS.prototype = {
  12139. getRgb: ColorSpace.prototype.getRgb,
  12140. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  12141. dest, destOffset) {
  12142. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12143. },
  12144. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  12145. dest, destOffset, bits,
  12146. alpha01) {
  12147. var scale = 1 / ((1 << bits) - 1);
  12148. for (var i = 0; i < count; ++i) {
  12149. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12150. srcOffset += 1;
  12151. destOffset += 3 + alpha01;
  12152. }
  12153. },
  12154. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  12155. return inputLength * (3 + alpha01);
  12156. },
  12157. isPassthrough: ColorSpace.prototype.isPassthrough,
  12158. fillRgb: ColorSpace.prototype.fillRgb,
  12159. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  12160. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12161. },
  12162. usesZeroToOneRange: true
  12163. };
  12164. return CalGrayCS;
  12165. })();
  12166. //
  12167. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  12168. //
  12169. var CalRGBCS = (function CalRGBCSClosure() {
  12170. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  12171. // matrices.
  12172. var BRADFORD_SCALE_MATRIX = new Float32Array([
  12173. 0.8951, 0.2664, -0.1614,
  12174. -0.7502, 1.7135, 0.0367,
  12175. 0.0389, -0.0685, 1.0296]);
  12176. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  12177. 0.9869929, -0.1470543, 0.1599627,
  12178. 0.4323053, 0.5183603, 0.0492912,
  12179. -0.0085287, 0.0400428, 0.9684867]);
  12180. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  12181. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  12182. 3.2404542, -1.5371385, -0.4985314,
  12183. -0.9692660, 1.8760108, 0.0415560,
  12184. 0.0556434, -0.2040259, 1.0572252]);
  12185. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  12186. var tempNormalizeMatrix = new Float32Array(3);
  12187. var tempConvertMatrix1 = new Float32Array(3);
  12188. var tempConvertMatrix2 = new Float32Array(3);
  12189. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  12190. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  12191. this.name = 'CalRGB';
  12192. this.numComps = 3;
  12193. this.defaultColor = new Float32Array(3);
  12194. if (!whitePoint) {
  12195. error('WhitePoint missing - required for color space CalRGB');
  12196. }
  12197. blackPoint = blackPoint || new Float32Array(3);
  12198. gamma = gamma || new Float32Array([1, 1, 1]);
  12199. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  12200. // Translate arguments to spec variables.
  12201. var XW = whitePoint[0];
  12202. var YW = whitePoint[1];
  12203. var ZW = whitePoint[2];
  12204. this.whitePoint = whitePoint;
  12205. var XB = blackPoint[0];
  12206. var YB = blackPoint[1];
  12207. var ZB = blackPoint[2];
  12208. this.blackPoint = blackPoint;
  12209. this.GR = gamma[0];
  12210. this.GG = gamma[1];
  12211. this.GB = gamma[2];
  12212. this.MXA = matrix[0];
  12213. this.MYA = matrix[1];
  12214. this.MZA = matrix[2];
  12215. this.MXB = matrix[3];
  12216. this.MYB = matrix[4];
  12217. this.MZB = matrix[5];
  12218. this.MXC = matrix[6];
  12219. this.MYC = matrix[7];
  12220. this.MZC = matrix[8];
  12221. // Validate variables as per spec.
  12222. if (XW < 0 || ZW < 0 || YW !== 1) {
  12223. error('Invalid WhitePoint components for ' + this.name +
  12224. ', no fallback available');
  12225. }
  12226. if (XB < 0 || YB < 0 || ZB < 0) {
  12227. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  12228. ', ' + ZB + '], falling back to default');
  12229. this.blackPoint = new Float32Array(3);
  12230. }
  12231. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  12232. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  12233. '] for ' + this.name + ', falling back to default');
  12234. this.GR = this.GG = this.GB = 1;
  12235. }
  12236. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  12237. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  12238. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  12239. info('Invalid Matrix for ' + this.name + ' [' +
  12240. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  12241. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  12242. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  12243. '], falling back to default');
  12244. this.MXA = this.MYB = this.MZC = 1;
  12245. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  12246. }
  12247. }
  12248. function matrixProduct(a, b, result) {
  12249. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  12250. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  12251. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  12252. }
  12253. function convertToFlat(sourceWhitePoint, LMS, result) {
  12254. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  12255. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  12256. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  12257. }
  12258. function convertToD65(sourceWhitePoint, LMS, result) {
  12259. var D65X = 0.95047;
  12260. var D65Y = 1;
  12261. var D65Z = 1.08883;
  12262. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  12263. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  12264. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  12265. }
  12266. function sRGBTransferFunction(color) {
  12267. // See http://en.wikipedia.org/wiki/SRGB.
  12268. if (color <= 0.0031308){
  12269. return adjustToRange(0, 1, 12.92 * color);
  12270. }
  12271. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  12272. }
  12273. function adjustToRange(min, max, value) {
  12274. return Math.max(min, Math.min(max, value));
  12275. }
  12276. function decodeL(L) {
  12277. if (L < 0) {
  12278. return -decodeL(-L);
  12279. }
  12280. if (L > 8.0) {
  12281. return Math.pow(((L + 16) / 116), 3);
  12282. }
  12283. return L * DECODE_L_CONSTANT;
  12284. }
  12285. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  12286. // In case the blackPoint is already the default blackPoint then there is
  12287. // no need to do compensation.
  12288. if (sourceBlackPoint[0] === 0 &&
  12289. sourceBlackPoint[1] === 0 &&
  12290. sourceBlackPoint[2] === 0) {
  12291. result[0] = XYZ_Flat[0];
  12292. result[1] = XYZ_Flat[1];
  12293. result[2] = XYZ_Flat[2];
  12294. return;
  12295. }
  12296. // For the blackPoint calculation details, please see
  12297. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12298. // AdobeBPC.pdf.
  12299. // The destination blackPoint is the default blackPoint [0, 0, 0].
  12300. var zeroDecodeL = decodeL(0);
  12301. var X_DST = zeroDecodeL;
  12302. var X_SRC = decodeL(sourceBlackPoint[0]);
  12303. var Y_DST = zeroDecodeL;
  12304. var Y_SRC = decodeL(sourceBlackPoint[1]);
  12305. var Z_DST = zeroDecodeL;
  12306. var Z_SRC = decodeL(sourceBlackPoint[2]);
  12307. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  12308. var X_Offset = 1 - X_Scale;
  12309. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  12310. var Y_Offset = 1 - Y_Scale;
  12311. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  12312. var Z_Offset = 1 - Z_Scale;
  12313. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  12314. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  12315. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  12316. }
  12317. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  12318. // In case the whitePoint is already flat then there is no need to do
  12319. // normalization.
  12320. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  12321. result[0] = XYZ_In[0];
  12322. result[1] = XYZ_In[1];
  12323. result[2] = XYZ_In[2];
  12324. return;
  12325. }
  12326. var LMS = result;
  12327. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12328. var LMS_Flat = tempNormalizeMatrix;
  12329. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  12330. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  12331. }
  12332. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  12333. var LMS = result;
  12334. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  12335. var LMS_D65 = tempNormalizeMatrix;
  12336. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  12337. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  12338. }
  12339. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12340. // A, B and C represent a red, green and blue components of a calibrated
  12341. // rgb space.
  12342. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  12343. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  12344. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  12345. // A <---> AGR in the spec
  12346. // B <---> BGG in the spec
  12347. // C <---> CGB in the spec
  12348. var AGR = Math.pow(A, cs.GR);
  12349. var BGG = Math.pow(B, cs.GG);
  12350. var CGB = Math.pow(C, cs.GB);
  12351. // Computes intermediate variables L, M, N as per spec.
  12352. // To decode X, Y, Z values map L, M, N directly to them.
  12353. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  12354. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  12355. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  12356. // The following calculations are based on this document:
  12357. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  12358. // AdobeBPC.pdf.
  12359. var XYZ = tempConvertMatrix1;
  12360. XYZ[0] = X;
  12361. XYZ[1] = Y;
  12362. XYZ[2] = Z;
  12363. var XYZ_Flat = tempConvertMatrix2;
  12364. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  12365. var XYZ_Black = tempConvertMatrix1;
  12366. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  12367. var XYZ_D65 = tempConvertMatrix2;
  12368. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  12369. var SRGB = tempConvertMatrix1;
  12370. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  12371. var sR = sRGBTransferFunction(SRGB[0]);
  12372. var sG = sRGBTransferFunction(SRGB[1]);
  12373. var sB = sRGBTransferFunction(SRGB[2]);
  12374. // Convert the values to rgb range [0, 255].
  12375. dest[destOffset] = Math.round(sR * 255);
  12376. dest[destOffset + 1] = Math.round(sG * 255);
  12377. dest[destOffset + 2] = Math.round(sB * 255);
  12378. }
  12379. CalRGBCS.prototype = {
  12380. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  12381. var rgb = new Uint8Array(3);
  12382. this.getRgbItem(src, srcOffset, rgb, 0);
  12383. return rgb;
  12384. },
  12385. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  12386. dest, destOffset) {
  12387. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12388. },
  12389. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  12390. dest, destOffset, bits,
  12391. alpha01) {
  12392. var scale = 1 / ((1 << bits) - 1);
  12393. for (var i = 0; i < count; ++i) {
  12394. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12395. srcOffset += 3;
  12396. destOffset += 3 + alpha01;
  12397. }
  12398. },
  12399. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  12400. return (inputLength * (3 + alpha01) / 3) | 0;
  12401. },
  12402. isPassthrough: ColorSpace.prototype.isPassthrough,
  12403. fillRgb: ColorSpace.prototype.fillRgb,
  12404. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  12405. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12406. },
  12407. usesZeroToOneRange: true
  12408. };
  12409. return CalRGBCS;
  12410. })();
  12411. //
  12412. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  12413. //
  12414. var LabCS = (function LabCSClosure() {
  12415. function LabCS(whitePoint, blackPoint, range) {
  12416. this.name = 'Lab';
  12417. this.numComps = 3;
  12418. this.defaultColor = new Float32Array([0, 0, 0]);
  12419. if (!whitePoint) {
  12420. error('WhitePoint missing - required for color space Lab');
  12421. }
  12422. blackPoint = blackPoint || [0, 0, 0];
  12423. range = range || [-100, 100, -100, 100];
  12424. // Translate args to spec variables
  12425. this.XW = whitePoint[0];
  12426. this.YW = whitePoint[1];
  12427. this.ZW = whitePoint[2];
  12428. this.amin = range[0];
  12429. this.amax = range[1];
  12430. this.bmin = range[2];
  12431. this.bmax = range[3];
  12432. // These are here just for completeness - the spec doesn't offer any
  12433. // formulas that use BlackPoint in Lab
  12434. this.XB = blackPoint[0];
  12435. this.YB = blackPoint[1];
  12436. this.ZB = blackPoint[2];
  12437. // Validate vars as per spec
  12438. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12439. error('Invalid WhitePoint components, no fallback available');
  12440. }
  12441. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12442. info('Invalid BlackPoint, falling back to default');
  12443. this.XB = this.YB = this.ZB = 0;
  12444. }
  12445. if (this.amin > this.amax || this.bmin > this.bmax) {
  12446. info('Invalid Range, falling back to defaults');
  12447. this.amin = -100;
  12448. this.amax = 100;
  12449. this.bmin = -100;
  12450. this.bmax = 100;
  12451. }
  12452. }
  12453. // Function g(x) from spec
  12454. function fn_g(x) {
  12455. if (x >= 6 / 29) {
  12456. return x * x * x;
  12457. } else {
  12458. return (108 / 841) * (x - 4 / 29);
  12459. }
  12460. }
  12461. function decode(value, high1, low2, high2) {
  12462. return low2 + (value) * (high2 - low2) / (high1);
  12463. }
  12464. // If decoding is needed maxVal should be 2^bits per component - 1.
  12465. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  12466. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  12467. // not the usual [0, 1]. If a command like setFillColor is used the src
  12468. // values will already be within the correct range. However, if we are
  12469. // converting an image we have to map the values to the correct range given
  12470. // above.
  12471. // Ls,as,bs <---> L*,a*,b* in the spec
  12472. var Ls = src[srcOffset];
  12473. var as = src[srcOffset + 1];
  12474. var bs = src[srcOffset + 2];
  12475. if (maxVal !== false) {
  12476. Ls = decode(Ls, maxVal, 0, 100);
  12477. as = decode(as, maxVal, cs.amin, cs.amax);
  12478. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  12479. }
  12480. // Adjust limits of 'as' and 'bs'
  12481. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  12482. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  12483. // Computes intermediate variables X,Y,Z as per spec
  12484. var M = (Ls + 16) / 116;
  12485. var L = M + (as / 500);
  12486. var N = M - (bs / 200);
  12487. var X = cs.XW * fn_g(L);
  12488. var Y = cs.YW * fn_g(M);
  12489. var Z = cs.ZW * fn_g(N);
  12490. var r, g, b;
  12491. // Using different conversions for D50 and D65 white points,
  12492. // per http://www.color.org/srgb.pdf
  12493. if (cs.ZW < 1) {
  12494. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  12495. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  12496. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  12497. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  12498. } else {
  12499. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  12500. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  12501. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  12502. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  12503. }
  12504. // clamp color values to [0,1] range then convert to [0,255] range.
  12505. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  12506. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  12507. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  12508. }
  12509. LabCS.prototype = {
  12510. getRgb: ColorSpace.prototype.getRgb,
  12511. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  12512. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  12513. },
  12514. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  12515. dest, destOffset, bits,
  12516. alpha01) {
  12517. var maxVal = (1 << bits) - 1;
  12518. for (var i = 0; i < count; i++) {
  12519. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  12520. srcOffset += 3;
  12521. destOffset += 3 + alpha01;
  12522. }
  12523. },
  12524. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  12525. return (inputLength * (3 + alpha01) / 3) | 0;
  12526. },
  12527. isPassthrough: ColorSpace.prototype.isPassthrough,
  12528. fillRgb: ColorSpace.prototype.fillRgb,
  12529. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  12530. // XXX: Decoding is handled with the lab conversion because of the strange
  12531. // ranges that are used.
  12532. return true;
  12533. },
  12534. usesZeroToOneRange: false
  12535. };
  12536. return LabCS;
  12537. })();
  12538. var ARCFourCipher = (function ARCFourCipherClosure() {
  12539. function ARCFourCipher(key) {
  12540. this.a = 0;
  12541. this.b = 0;
  12542. var s = new Uint8Array(256);
  12543. var i, j = 0, tmp, keyLength = key.length;
  12544. for (i = 0; i < 256; ++i) {
  12545. s[i] = i;
  12546. }
  12547. for (i = 0; i < 256; ++i) {
  12548. tmp = s[i];
  12549. j = (j + tmp + key[i % keyLength]) & 0xFF;
  12550. s[i] = s[j];
  12551. s[j] = tmp;
  12552. }
  12553. this.s = s;
  12554. }
  12555. ARCFourCipher.prototype = {
  12556. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  12557. var i, n = data.length, tmp, tmp2;
  12558. var a = this.a, b = this.b, s = this.s;
  12559. var output = new Uint8Array(n);
  12560. for (i = 0; i < n; ++i) {
  12561. a = (a + 1) & 0xFF;
  12562. tmp = s[a];
  12563. b = (b + tmp) & 0xFF;
  12564. tmp2 = s[b];
  12565. s[a] = tmp2;
  12566. s[b] = tmp;
  12567. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  12568. }
  12569. this.a = a;
  12570. this.b = b;
  12571. return output;
  12572. }
  12573. };
  12574. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  12575. return ARCFourCipher;
  12576. })();
  12577. var calculateMD5 = (function calculateMD5Closure() {
  12578. var r = new Uint8Array([
  12579. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  12580. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  12581. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  12582. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  12583. var k = new Int32Array([
  12584. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  12585. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  12586. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  12587. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  12588. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  12589. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  12590. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  12591. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  12592. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  12593. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  12594. -145523070, -1120210379, 718787259, -343485551]);
  12595. function hash(data, offset, length) {
  12596. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  12597. // pre-processing
  12598. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  12599. var padded = new Uint8Array(paddedLength);
  12600. var i, j, n;
  12601. for (i = 0; i < length; ++i) {
  12602. padded[i] = data[offset++];
  12603. }
  12604. padded[i++] = 0x80;
  12605. n = paddedLength - 8;
  12606. while (i < n) {
  12607. padded[i++] = 0;
  12608. }
  12609. padded[i++] = (length << 3) & 0xFF;
  12610. padded[i++] = (length >> 5) & 0xFF;
  12611. padded[i++] = (length >> 13) & 0xFF;
  12612. padded[i++] = (length >> 21) & 0xFF;
  12613. padded[i++] = (length >>> 29) & 0xFF;
  12614. padded[i++] = 0;
  12615. padded[i++] = 0;
  12616. padded[i++] = 0;
  12617. var w = new Int32Array(16);
  12618. for (i = 0; i < paddedLength;) {
  12619. for (j = 0; j < 16; ++j, i += 4) {
  12620. w[j] = (padded[i] | (padded[i + 1] << 8) |
  12621. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  12622. }
  12623. var a = h0, b = h1, c = h2, d = h3, f, g;
  12624. for (j = 0; j < 64; ++j) {
  12625. if (j < 16) {
  12626. f = (b & c) | ((~b) & d);
  12627. g = j;
  12628. } else if (j < 32) {
  12629. f = (d & b) | ((~d) & c);
  12630. g = (5 * j + 1) & 15;
  12631. } else if (j < 48) {
  12632. f = b ^ c ^ d;
  12633. g = (3 * j + 5) & 15;
  12634. } else {
  12635. f = c ^ (b | (~d));
  12636. g = (7 * j) & 15;
  12637. }
  12638. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  12639. d = c;
  12640. c = b;
  12641. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  12642. a = tmp;
  12643. }
  12644. h0 = (h0 + a) | 0;
  12645. h1 = (h1 + b) | 0;
  12646. h2 = (h2 + c) | 0;
  12647. h3 = (h3 + d) | 0;
  12648. }
  12649. return new Uint8Array([
  12650. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  12651. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  12652. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  12653. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  12654. ]);
  12655. }
  12656. return hash;
  12657. })();
  12658. var Word64 = (function Word64Closure() {
  12659. function Word64(highInteger, lowInteger) {
  12660. this.high = highInteger | 0;
  12661. this.low = lowInteger | 0;
  12662. }
  12663. Word64.prototype = {
  12664. and: function Word64_and(word) {
  12665. this.high &= word.high;
  12666. this.low &= word.low;
  12667. },
  12668. xor: function Word64_xor(word) {
  12669. this.high ^= word.high;
  12670. this.low ^= word.low;
  12671. },
  12672. or: function Word64_or(word) {
  12673. this.high |= word.high;
  12674. this.low |= word.low;
  12675. },
  12676. shiftRight: function Word64_shiftRight(places) {
  12677. if (places >= 32) {
  12678. this.low = (this.high >>> (places - 32)) | 0;
  12679. this.high = 0;
  12680. } else {
  12681. this.low = (this.low >>> places) | (this.high << (32 - places));
  12682. this.high = (this.high >>> places) | 0;
  12683. }
  12684. },
  12685. shiftLeft: function Word64_shiftLeft(places) {
  12686. if (places >= 32) {
  12687. this.high = this.low << (places - 32);
  12688. this.low = 0;
  12689. } else {
  12690. this.high = (this.high << places) | (this.low >>> (32 - places));
  12691. this.low = this.low << places;
  12692. }
  12693. },
  12694. rotateRight: function Word64_rotateRight(places) {
  12695. var low, high;
  12696. if (places & 32) {
  12697. high = this.low;
  12698. low = this.high;
  12699. } else {
  12700. low = this.low;
  12701. high = this.high;
  12702. }
  12703. places &= 31;
  12704. this.low = (low >>> places) | (high << (32 - places));
  12705. this.high = (high >>> places) | (low << (32 - places));
  12706. },
  12707. not: function Word64_not() {
  12708. this.high = ~this.high;
  12709. this.low = ~this.low;
  12710. },
  12711. add: function Word64_add(word) {
  12712. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  12713. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  12714. if (lowAdd > 0xFFFFFFFF) {
  12715. highAdd += 1;
  12716. }
  12717. this.low = lowAdd | 0;
  12718. this.high = highAdd | 0;
  12719. },
  12720. copyTo: function Word64_copyTo(bytes, offset) {
  12721. bytes[offset] = (this.high >>> 24) & 0xFF;
  12722. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  12723. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  12724. bytes[offset + 3] = this.high & 0xFF;
  12725. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  12726. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  12727. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  12728. bytes[offset + 7] = this.low & 0xFF;
  12729. },
  12730. assign: function Word64_assign(word) {
  12731. this.high = word.high;
  12732. this.low = word.low;
  12733. }
  12734. };
  12735. return Word64;
  12736. })();
  12737. var calculateSHA256 = (function calculateSHA256Closure() {
  12738. function rotr(x, n) {
  12739. return (x >>> n) | (x << 32 - n);
  12740. }
  12741. function ch(x, y, z) {
  12742. return (x & y) ^ (~x & z);
  12743. }
  12744. function maj(x, y, z) {
  12745. return (x & y) ^ (x & z) ^ (y & z);
  12746. }
  12747. function sigma(x) {
  12748. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  12749. }
  12750. function sigmaPrime(x) {
  12751. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  12752. }
  12753. function littleSigma(x) {
  12754. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  12755. }
  12756. function littleSigmaPrime(x) {
  12757. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  12758. }
  12759. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  12760. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  12761. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  12762. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  12763. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  12764. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  12765. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  12766. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  12767. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  12768. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  12769. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  12770. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  12771. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  12772. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  12773. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  12774. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  12775. function hash(data, offset, length) {
  12776. // initial hash values
  12777. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  12778. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  12779. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  12780. // pre-processing
  12781. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  12782. var padded = new Uint8Array(paddedLength);
  12783. var i, j, n;
  12784. for (i = 0; i < length; ++i) {
  12785. padded[i] = data[offset++];
  12786. }
  12787. padded[i++] = 0x80;
  12788. n = paddedLength - 8;
  12789. while (i < n) {
  12790. padded[i++] = 0;
  12791. }
  12792. padded[i++] = 0;
  12793. padded[i++] = 0;
  12794. padded[i++] = 0;
  12795. padded[i++] = (length >>> 29) & 0xFF;
  12796. padded[i++] = (length >> 21) & 0xFF;
  12797. padded[i++] = (length >> 13) & 0xFF;
  12798. padded[i++] = (length >> 5) & 0xFF;
  12799. padded[i++] = (length << 3) & 0xFF;
  12800. var w = new Uint32Array(64);
  12801. // for each 512 bit block
  12802. for (i = 0; i < paddedLength;) {
  12803. for (j = 0; j < 16; ++j) {
  12804. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  12805. (padded[i + 2] << 8) | (padded[i + 3]));
  12806. i += 4;
  12807. }
  12808. for (j = 16; j < 64; ++j) {
  12809. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  12810. littleSigma(w[j - 15]) + w[j - 16] | 0;
  12811. }
  12812. var a = h0, b = h1, c = h2, d = h3, e = h4,
  12813. f = h5, g = h6, h = h7, t1, t2;
  12814. for (j = 0; j < 64; ++j) {
  12815. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  12816. t2 = sigma(a) + maj(a, b, c);
  12817. h = g;
  12818. g = f;
  12819. f = e;
  12820. e = (d + t1) | 0;
  12821. d = c;
  12822. c = b;
  12823. b = a;
  12824. a = (t1 + t2) | 0;
  12825. }
  12826. h0 = (h0 + a) | 0;
  12827. h1 = (h1 + b) | 0;
  12828. h2 = (h2 + c) | 0;
  12829. h3 = (h3 + d) | 0;
  12830. h4 = (h4 + e) | 0;
  12831. h5 = (h5 + f) | 0;
  12832. h6 = (h6 + g) | 0;
  12833. h7 = (h7 + h) | 0;
  12834. }
  12835. return new Uint8Array([
  12836. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  12837. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  12838. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  12839. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  12840. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  12841. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  12842. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  12843. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  12844. ]);
  12845. }
  12846. return hash;
  12847. })();
  12848. var calculateSHA512 = (function calculateSHA512Closure() {
  12849. function ch(result, x, y, z, tmp) {
  12850. result.assign(x);
  12851. result.and(y);
  12852. tmp.assign(x);
  12853. tmp.not();
  12854. tmp.and(z);
  12855. result.xor(tmp);
  12856. }
  12857. function maj(result, x, y, z, tmp) {
  12858. result.assign(x);
  12859. result.and(y);
  12860. tmp.assign(x);
  12861. tmp.and(z);
  12862. result.xor(tmp);
  12863. tmp.assign(y);
  12864. tmp.and(z);
  12865. result.xor(tmp);
  12866. }
  12867. function sigma(result, x, tmp) {
  12868. result.assign(x);
  12869. result.rotateRight(28);
  12870. tmp.assign(x);
  12871. tmp.rotateRight(34);
  12872. result.xor(tmp);
  12873. tmp.assign(x);
  12874. tmp.rotateRight(39);
  12875. result.xor(tmp);
  12876. }
  12877. function sigmaPrime(result, x, tmp) {
  12878. result.assign(x);
  12879. result.rotateRight(14);
  12880. tmp.assign(x);
  12881. tmp.rotateRight(18);
  12882. result.xor(tmp);
  12883. tmp.assign(x);
  12884. tmp.rotateRight(41);
  12885. result.xor(tmp);
  12886. }
  12887. function littleSigma(result, x, tmp) {
  12888. result.assign(x);
  12889. result.rotateRight(1);
  12890. tmp.assign(x);
  12891. tmp.rotateRight(8);
  12892. result.xor(tmp);
  12893. tmp.assign(x);
  12894. tmp.shiftRight(7);
  12895. result.xor(tmp);
  12896. }
  12897. function littleSigmaPrime(result, x, tmp) {
  12898. result.assign(x);
  12899. result.rotateRight(19);
  12900. tmp.assign(x);
  12901. tmp.rotateRight(61);
  12902. result.xor(tmp);
  12903. tmp.assign(x);
  12904. tmp.shiftRight(6);
  12905. result.xor(tmp);
  12906. }
  12907. var k = [
  12908. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  12909. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  12910. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  12911. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  12912. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  12913. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  12914. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  12915. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  12916. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  12917. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  12918. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  12919. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  12920. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  12921. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  12922. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  12923. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  12924. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  12925. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  12926. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  12927. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  12928. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  12929. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  12930. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  12931. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  12932. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  12933. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  12934. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  12935. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  12936. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  12937. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  12938. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  12939. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  12940. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  12941. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  12942. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  12943. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  12944. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  12945. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  12946. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  12947. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  12948. function hash(data, offset, length, mode384) {
  12949. mode384 = !!mode384;
  12950. // initial hash values
  12951. var h0, h1, h2, h3, h4, h5, h6, h7;
  12952. if (!mode384) {
  12953. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  12954. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  12955. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  12956. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  12957. h4 = new Word64(0x510e527f, 0xade682d1);
  12958. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  12959. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  12960. h7 = new Word64(0x5be0cd19, 0x137e2179);
  12961. }
  12962. else {
  12963. // SHA384 is exactly the same
  12964. // except with different starting values and a trimmed result
  12965. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  12966. h1 = new Word64(0x629a292a, 0x367cd507);
  12967. h2 = new Word64(0x9159015a, 0x3070dd17);
  12968. h3 = new Word64(0x152fecd8, 0xf70e5939);
  12969. h4 = new Word64(0x67332667, 0xffc00b31);
  12970. h5 = new Word64(0x8eb44a87, 0x68581511);
  12971. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  12972. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  12973. }
  12974. // pre-processing
  12975. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  12976. var padded = new Uint8Array(paddedLength);
  12977. var i, j, n;
  12978. for (i = 0; i < length; ++i) {
  12979. padded[i] = data[offset++];
  12980. }
  12981. padded[i++] = 0x80;
  12982. n = paddedLength - 16;
  12983. while (i < n) {
  12984. padded[i++] = 0;
  12985. }
  12986. padded[i++] = 0;
  12987. padded[i++] = 0;
  12988. padded[i++] = 0;
  12989. padded[i++] = 0;
  12990. padded[i++] = 0;
  12991. padded[i++] = 0;
  12992. padded[i++] = 0;
  12993. padded[i++] = 0;
  12994. padded[i++] = 0;
  12995. padded[i++] = 0;
  12996. padded[i++] = 0;
  12997. padded[i++] = (length >>> 29) & 0xFF;
  12998. padded[i++] = (length >> 21) & 0xFF;
  12999. padded[i++] = (length >> 13) & 0xFF;
  13000. padded[i++] = (length >> 5) & 0xFF;
  13001. padded[i++] = (length << 3) & 0xFF;
  13002. var w = new Array(80);
  13003. for (i = 0; i < 80; i++) {
  13004. w[i] = new Word64(0, 0);
  13005. }
  13006. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  13007. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  13008. var g = new Word64(0, 0), h = new Word64(0, 0);
  13009. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  13010. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  13011. // for each 1024 bit block
  13012. for (i = 0; i < paddedLength;) {
  13013. for (j = 0; j < 16; ++j) {
  13014. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  13015. (padded[i + 2] << 8) | (padded[i + 3]);
  13016. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  13017. (padded[i + 6]) << 8 | (padded[i + 7]);
  13018. i += 8;
  13019. }
  13020. for (j = 16; j < 80; ++j) {
  13021. tmp3 = w[j];
  13022. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  13023. tmp3.add(w[j - 7]);
  13024. littleSigma(tmp1, w[j - 15], tmp2);
  13025. tmp3.add(tmp1);
  13026. tmp3.add(w[j - 16]);
  13027. }
  13028. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  13029. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  13030. for (j = 0; j < 80; ++j) {
  13031. t1.assign(h);
  13032. sigmaPrime(tmp1, e, tmp2);
  13033. t1.add(tmp1);
  13034. ch(tmp1, e, f, g, tmp2);
  13035. t1.add(tmp1);
  13036. t1.add(k[j]);
  13037. t1.add(w[j]);
  13038. sigma(t2, a, tmp2);
  13039. maj(tmp1, a, b, c, tmp2);
  13040. t2.add(tmp1);
  13041. tmp3 = h;
  13042. h = g;
  13043. g = f;
  13044. f = e;
  13045. d.add(t1);
  13046. e = d;
  13047. d = c;
  13048. c = b;
  13049. b = a;
  13050. tmp3.assign(t1);
  13051. tmp3.add(t2);
  13052. a = tmp3;
  13053. }
  13054. h0.add(a);
  13055. h1.add(b);
  13056. h2.add(c);
  13057. h3.add(d);
  13058. h4.add(e);
  13059. h5.add(f);
  13060. h6.add(g);
  13061. h7.add(h);
  13062. }
  13063. var result;
  13064. if (!mode384) {
  13065. result = new Uint8Array(64);
  13066. h0.copyTo(result,0);
  13067. h1.copyTo(result,8);
  13068. h2.copyTo(result,16);
  13069. h3.copyTo(result,24);
  13070. h4.copyTo(result,32);
  13071. h5.copyTo(result,40);
  13072. h6.copyTo(result,48);
  13073. h7.copyTo(result,56);
  13074. }
  13075. else {
  13076. result = new Uint8Array(48);
  13077. h0.copyTo(result,0);
  13078. h1.copyTo(result,8);
  13079. h2.copyTo(result,16);
  13080. h3.copyTo(result,24);
  13081. h4.copyTo(result,32);
  13082. h5.copyTo(result,40);
  13083. }
  13084. return result;
  13085. }
  13086. return hash;
  13087. })();
  13088. var calculateSHA384 = (function calculateSHA384Closure() {
  13089. function hash(data, offset, length) {
  13090. return calculateSHA512(data, offset, length, true);
  13091. }
  13092. return hash;
  13093. })();
  13094. var NullCipher = (function NullCipherClosure() {
  13095. function NullCipher() {
  13096. }
  13097. NullCipher.prototype = {
  13098. decryptBlock: function NullCipher_decryptBlock(data) {
  13099. return data;
  13100. }
  13101. };
  13102. return NullCipher;
  13103. })();
  13104. var AES128Cipher = (function AES128CipherClosure() {
  13105. var rcon = new Uint8Array([
  13106. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13107. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13108. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13109. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13110. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13111. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13112. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13113. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13114. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13115. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13116. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13117. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13118. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13119. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13120. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13121. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13122. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13123. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13124. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13125. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13126. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13127. 0x74, 0xe8, 0xcb, 0x8d]);
  13128. var s = new Uint8Array([
  13129. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13130. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13131. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13132. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13133. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13134. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13135. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13136. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13137. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13138. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13139. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13140. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13141. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13142. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13143. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13144. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13145. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13146. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13147. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13148. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13149. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13150. 0xb0, 0x54, 0xbb, 0x16]);
  13151. var inv_s = new Uint8Array([
  13152. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13153. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13154. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13155. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13156. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13157. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13158. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13159. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13160. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13161. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13162. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13163. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13164. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13165. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13166. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13167. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13168. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13169. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13170. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13171. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13172. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13173. 0x55, 0x21, 0x0c, 0x7d]);
  13174. var mixCol = new Uint8Array(256);
  13175. for (var i = 0; i < 256; i++) {
  13176. if (i < 128) {
  13177. mixCol[i] = i << 1;
  13178. } else {
  13179. mixCol[i] = (i << 1) ^ 0x1b;
  13180. }
  13181. }
  13182. var mix = new Uint32Array([
  13183. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13184. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13185. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13186. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13187. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13188. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13189. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13190. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13191. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13192. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13193. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13194. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13195. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13196. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13197. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13198. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13199. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13200. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13201. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13202. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13203. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13204. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13205. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13206. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13207. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13208. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13209. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13210. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13211. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13212. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13213. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13214. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13215. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13216. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13217. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13218. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13219. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13220. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13221. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13222. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13223. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13224. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13225. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13226. function expandKey128(cipherKey) {
  13227. var b = 176, result = new Uint8Array(b);
  13228. result.set(cipherKey);
  13229. for (var j = 16, i = 1; j < b; ++i) {
  13230. // RotWord
  13231. var t1 = result[j - 3], t2 = result[j - 2],
  13232. t3 = result[j - 1], t4 = result[j - 4];
  13233. // SubWord
  13234. t1 = s[t1];
  13235. t2 = s[t2];
  13236. t3 = s[t3];
  13237. t4 = s[t4];
  13238. // Rcon
  13239. t1 = t1 ^ rcon[i];
  13240. for (var n = 0; n < 4; ++n) {
  13241. result[j] = (t1 ^= result[j - 16]);
  13242. j++;
  13243. result[j] = (t2 ^= result[j - 16]);
  13244. j++;
  13245. result[j] = (t3 ^= result[j - 16]);
  13246. j++;
  13247. result[j] = (t4 ^= result[j - 16]);
  13248. j++;
  13249. }
  13250. }
  13251. return result;
  13252. }
  13253. function decrypt128(input, key) {
  13254. var state = new Uint8Array(16);
  13255. state.set(input);
  13256. var i, j, k;
  13257. var t, u, v;
  13258. // AddRoundKey
  13259. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13260. state[j] ^= key[k];
  13261. }
  13262. for (i = 9; i >= 1; --i) {
  13263. // InvShiftRows
  13264. t = state[13];
  13265. state[13] = state[9];
  13266. state[9] = state[5];
  13267. state[5] = state[1];
  13268. state[1] = t;
  13269. t = state[14];
  13270. u = state[10];
  13271. state[14] = state[6];
  13272. state[10] = state[2];
  13273. state[6] = t;
  13274. state[2] = u;
  13275. t = state[15];
  13276. u = state[11];
  13277. v = state[7];
  13278. state[15] = state[3];
  13279. state[11] = t;
  13280. state[7] = u;
  13281. state[3] = v;
  13282. // InvSubBytes
  13283. for (j = 0; j < 16; ++j) {
  13284. state[j] = inv_s[state[j]];
  13285. }
  13286. // AddRoundKey
  13287. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13288. state[j] ^= key[k];
  13289. }
  13290. // InvMixColumns
  13291. for (j = 0; j < 16; j += 4) {
  13292. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13293. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13294. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13295. (s3 >>> 24) ^ (s3 << 8));
  13296. state[j] = (t >>> 24) & 0xFF;
  13297. state[j + 1] = (t >> 16) & 0xFF;
  13298. state[j + 2] = (t >> 8) & 0xFF;
  13299. state[j + 3] = t & 0xFF;
  13300. }
  13301. }
  13302. // InvShiftRows
  13303. t = state[13];
  13304. state[13] = state[9];
  13305. state[9] = state[5];
  13306. state[5] = state[1];
  13307. state[1] = t;
  13308. t = state[14];
  13309. u = state[10];
  13310. state[14] = state[6];
  13311. state[10] = state[2];
  13312. state[6] = t;
  13313. state[2] = u;
  13314. t = state[15];
  13315. u = state[11];
  13316. v = state[7];
  13317. state[15] = state[3];
  13318. state[11] = t;
  13319. state[7] = u;
  13320. state[3] = v;
  13321. for (j = 0; j < 16; ++j) {
  13322. // InvSubBytes
  13323. state[j] = inv_s[state[j]];
  13324. // AddRoundKey
  13325. state[j] ^= key[j];
  13326. }
  13327. return state;
  13328. }
  13329. function encrypt128(input, key) {
  13330. var t, u, v, k;
  13331. var state = new Uint8Array(16);
  13332. state.set(input);
  13333. for (j = 0; j < 16; ++j) {
  13334. // AddRoundKey
  13335. state[j] ^= key[j];
  13336. }
  13337. for (i = 1; i < 10; i++) {
  13338. //SubBytes
  13339. for (j = 0; j < 16; ++j) {
  13340. state[j] = s[state[j]];
  13341. }
  13342. //ShiftRows
  13343. v = state[1];
  13344. state[1] = state[5];
  13345. state[5] = state[9];
  13346. state[9] = state[13];
  13347. state[13] = v;
  13348. v = state[2];
  13349. u = state[6];
  13350. state[2] = state[10];
  13351. state[6] = state[14];
  13352. state[10] = v;
  13353. state[14] = u;
  13354. v = state[3];
  13355. u = state[7];
  13356. t = state[11];
  13357. state[3] = state[15];
  13358. state[7] = v;
  13359. state[11] = u;
  13360. state[15] = t;
  13361. //MixColumns
  13362. for (var j = 0; j < 16; j += 4) {
  13363. var s0 = state[j + 0], s1 = state[j + 1];
  13364. var s2 = state[j + 2], s3 = state[j + 3];
  13365. t = s0 ^ s1 ^ s2 ^ s3;
  13366. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13367. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13368. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13369. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13370. }
  13371. //AddRoundKey
  13372. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13373. state[j] ^= key[k];
  13374. }
  13375. }
  13376. //SubBytes
  13377. for (j = 0; j < 16; ++j) {
  13378. state[j] = s[state[j]];
  13379. }
  13380. //ShiftRows
  13381. v = state[1];
  13382. state[1] = state[5];
  13383. state[5] = state[9];
  13384. state[9] = state[13];
  13385. state[13] = v;
  13386. v = state[2];
  13387. u = state[6];
  13388. state[2] = state[10];
  13389. state[6] = state[14];
  13390. state[10] = v;
  13391. state[14] = u;
  13392. v = state[3];
  13393. u = state[7];
  13394. t = state[11];
  13395. state[3] = state[15];
  13396. state[7] = v;
  13397. state[11] = u;
  13398. state[15] = t;
  13399. //AddRoundKey
  13400. for (j = 0, k = 160; j < 16; ++j, ++k) {
  13401. state[j] ^= key[k];
  13402. }
  13403. return state;
  13404. }
  13405. function AES128Cipher(key) {
  13406. this.key = expandKey128(key);
  13407. this.buffer = new Uint8Array(16);
  13408. this.bufferPosition = 0;
  13409. }
  13410. function decryptBlock2(data, finalize) {
  13411. var i, j, ii, sourceLength = data.length,
  13412. buffer = this.buffer, bufferLength = this.bufferPosition,
  13413. result = [], iv = this.iv;
  13414. for (i = 0; i < sourceLength; ++i) {
  13415. buffer[bufferLength] = data[i];
  13416. ++bufferLength;
  13417. if (bufferLength < 16) {
  13418. continue;
  13419. }
  13420. // buffer is full, decrypting
  13421. var plain = decrypt128(buffer, this.key);
  13422. // xor-ing the IV vector to get plain text
  13423. for (j = 0; j < 16; ++j) {
  13424. plain[j] ^= iv[j];
  13425. }
  13426. iv = buffer;
  13427. result.push(plain);
  13428. buffer = new Uint8Array(16);
  13429. bufferLength = 0;
  13430. }
  13431. // saving incomplete buffer
  13432. this.buffer = buffer;
  13433. this.bufferLength = bufferLength;
  13434. this.iv = iv;
  13435. if (result.length === 0) {
  13436. return new Uint8Array([]);
  13437. }
  13438. // combining plain text blocks into one
  13439. var outputLength = 16 * result.length;
  13440. if (finalize) {
  13441. // undo a padding that is described in RFC 2898
  13442. var lastBlock = result[result.length - 1];
  13443. var psLen = lastBlock[15];
  13444. if (psLen <= 16) {
  13445. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13446. if (lastBlock[i] !== psLen) {
  13447. // Invalid padding, assume that the block has no padding.
  13448. psLen = 0;
  13449. break;
  13450. }
  13451. }
  13452. outputLength -= psLen;
  13453. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13454. }
  13455. }
  13456. var output = new Uint8Array(outputLength);
  13457. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13458. output.set(result[i], j);
  13459. }
  13460. return output;
  13461. }
  13462. AES128Cipher.prototype = {
  13463. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  13464. var i, sourceLength = data.length;
  13465. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13466. // waiting for IV values -- they are at the start of the stream
  13467. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  13468. buffer[bufferLength] = data[i];
  13469. }
  13470. if (bufferLength < 16) {
  13471. // need more data
  13472. this.bufferLength = bufferLength;
  13473. return new Uint8Array([]);
  13474. }
  13475. this.iv = buffer;
  13476. this.buffer = new Uint8Array(16);
  13477. this.bufferLength = 0;
  13478. // starting decryption
  13479. this.decryptBlock = decryptBlock2;
  13480. return this.decryptBlock(data.subarray(16), finalize);
  13481. },
  13482. encrypt: function AES128Cipher_encrypt(data, iv) {
  13483. var i, j, ii, sourceLength = data.length,
  13484. buffer = this.buffer, bufferLength = this.bufferPosition,
  13485. result = [];
  13486. if (!iv) {
  13487. iv = new Uint8Array(16);
  13488. }
  13489. for (i = 0; i < sourceLength; ++i) {
  13490. buffer[bufferLength] = data[i];
  13491. ++bufferLength;
  13492. if (bufferLength < 16) {
  13493. continue;
  13494. }
  13495. for (j = 0; j < 16; ++j) {
  13496. buffer[j] ^= iv[j];
  13497. }
  13498. // buffer is full, encrypting
  13499. var cipher = encrypt128(buffer, this.key);
  13500. iv = cipher;
  13501. result.push(cipher);
  13502. buffer = new Uint8Array(16);
  13503. bufferLength = 0;
  13504. }
  13505. // saving incomplete buffer
  13506. this.buffer = buffer;
  13507. this.bufferLength = bufferLength;
  13508. this.iv = iv;
  13509. if (result.length === 0) {
  13510. return new Uint8Array([]);
  13511. }
  13512. // combining plain text blocks into one
  13513. var outputLength = 16 * result.length;
  13514. var output = new Uint8Array(outputLength);
  13515. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13516. output.set(result[i], j);
  13517. }
  13518. return output;
  13519. }
  13520. };
  13521. return AES128Cipher;
  13522. })();
  13523. var AES256Cipher = (function AES256CipherClosure() {
  13524. var rcon = new Uint8Array([
  13525. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13526. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13527. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13528. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13529. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13530. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13531. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13532. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13533. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13534. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13535. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13536. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13537. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13538. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13539. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13540. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13541. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13542. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13543. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13544. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13545. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13546. 0x74, 0xe8, 0xcb, 0x8d]);
  13547. var s = new Uint8Array([
  13548. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13549. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13550. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13551. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13552. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13553. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13554. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13555. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13556. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13557. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13558. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13559. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13560. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13561. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13562. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13563. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13564. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13565. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13566. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13567. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13568. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13569. 0xb0, 0x54, 0xbb, 0x16]);
  13570. var inv_s = new Uint8Array([
  13571. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13572. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13573. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13574. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13575. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13576. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13577. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13578. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13579. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13580. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13581. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13582. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13583. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13584. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13585. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13586. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13587. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13588. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13589. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13590. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13591. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13592. 0x55, 0x21, 0x0c, 0x7d]);
  13593. var mixCol = new Uint8Array(256);
  13594. for (var i = 0; i < 256; i++) {
  13595. if (i < 128) {
  13596. mixCol[i] = i << 1;
  13597. } else {
  13598. mixCol[i] = (i << 1) ^ 0x1b;
  13599. }
  13600. }
  13601. var mix = new Uint32Array([
  13602. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13603. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13604. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13605. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13606. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13607. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13608. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13609. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13610. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13611. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13612. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13613. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13614. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13615. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13616. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13617. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13618. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13619. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13620. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13621. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13622. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13623. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13624. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13625. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13626. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13627. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13628. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13629. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13630. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13631. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13632. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13633. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13634. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13635. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13636. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13637. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13638. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13639. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13640. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13641. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13642. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13643. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13644. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13645. function expandKey256(cipherKey) {
  13646. var b = 240, result = new Uint8Array(b);
  13647. var r = 1;
  13648. result.set(cipherKey);
  13649. for (var j = 32, i = 1; j < b; ++i) {
  13650. if (j % 32 === 16) {
  13651. t1 = s[t1];
  13652. t2 = s[t2];
  13653. t3 = s[t3];
  13654. t4 = s[t4];
  13655. } else if (j % 32 === 0) {
  13656. // RotWord
  13657. var t1 = result[j - 3], t2 = result[j - 2],
  13658. t3 = result[j - 1], t4 = result[j - 4];
  13659. // SubWord
  13660. t1 = s[t1];
  13661. t2 = s[t2];
  13662. t3 = s[t3];
  13663. t4 = s[t4];
  13664. // Rcon
  13665. t1 = t1 ^ r;
  13666. if ((r <<= 1) >= 256) {
  13667. r = (r ^ 0x1b) & 0xFF;
  13668. }
  13669. }
  13670. for (var n = 0; n < 4; ++n) {
  13671. result[j] = (t1 ^= result[j - 32]);
  13672. j++;
  13673. result[j] = (t2 ^= result[j - 32]);
  13674. j++;
  13675. result[j] = (t3 ^= result[j - 32]);
  13676. j++;
  13677. result[j] = (t4 ^= result[j - 32]);
  13678. j++;
  13679. }
  13680. }
  13681. return result;
  13682. }
  13683. function decrypt256(input, key) {
  13684. var state = new Uint8Array(16);
  13685. state.set(input);
  13686. var i, j, k;
  13687. var t, u, v;
  13688. // AddRoundKey
  13689. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13690. state[j] ^= key[k];
  13691. }
  13692. for (i = 13; i >= 1; --i) {
  13693. // InvShiftRows
  13694. t = state[13];
  13695. state[13] = state[9];
  13696. state[9] = state[5];
  13697. state[5] = state[1];
  13698. state[1] = t;
  13699. t = state[14];
  13700. u = state[10];
  13701. state[14] = state[6];
  13702. state[10] = state[2];
  13703. state[6] = t;
  13704. state[2] = u;
  13705. t = state[15];
  13706. u = state[11];
  13707. v = state[7];
  13708. state[15] = state[3];
  13709. state[11] = t;
  13710. state[7] = u;
  13711. state[3] = v;
  13712. // InvSubBytes
  13713. for (j = 0; j < 16; ++j) {
  13714. state[j] = inv_s[state[j]];
  13715. }
  13716. // AddRoundKey
  13717. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13718. state[j] ^= key[k];
  13719. }
  13720. // InvMixColumns
  13721. for (j = 0; j < 16; j += 4) {
  13722. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  13723. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  13724. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  13725. (s3 >>> 24) ^ (s3 << 8));
  13726. state[j] = (t >>> 24) & 0xFF;
  13727. state[j + 1] = (t >> 16) & 0xFF;
  13728. state[j + 2] = (t >> 8) & 0xFF;
  13729. state[j + 3] = t & 0xFF;
  13730. }
  13731. }
  13732. // InvShiftRows
  13733. t = state[13];
  13734. state[13] = state[9];
  13735. state[9] = state[5];
  13736. state[5] = state[1];
  13737. state[1] = t;
  13738. t = state[14];
  13739. u = state[10];
  13740. state[14] = state[6];
  13741. state[10] = state[2];
  13742. state[6] = t;
  13743. state[2] = u;
  13744. t = state[15];
  13745. u = state[11];
  13746. v = state[7];
  13747. state[15] = state[3];
  13748. state[11] = t;
  13749. state[7] = u;
  13750. state[3] = v;
  13751. for (j = 0; j < 16; ++j) {
  13752. // InvSubBytes
  13753. state[j] = inv_s[state[j]];
  13754. // AddRoundKey
  13755. state[j] ^= key[j];
  13756. }
  13757. return state;
  13758. }
  13759. function encrypt256(input, key) {
  13760. var t, u, v, k;
  13761. var state = new Uint8Array(16);
  13762. state.set(input);
  13763. for (j = 0; j < 16; ++j) {
  13764. // AddRoundKey
  13765. state[j] ^= key[j];
  13766. }
  13767. for (i = 1; i < 14; i++) {
  13768. //SubBytes
  13769. for (j = 0; j < 16; ++j) {
  13770. state[j] = s[state[j]];
  13771. }
  13772. //ShiftRows
  13773. v = state[1];
  13774. state[1] = state[5];
  13775. state[5] = state[9];
  13776. state[9] = state[13];
  13777. state[13] = v;
  13778. v = state[2];
  13779. u = state[6];
  13780. state[2] = state[10];
  13781. state[6] = state[14];
  13782. state[10] = v;
  13783. state[14] = u;
  13784. v = state[3];
  13785. u = state[7];
  13786. t = state[11];
  13787. state[3] = state[15];
  13788. state[7] = v;
  13789. state[11] = u;
  13790. state[15] = t;
  13791. //MixColumns
  13792. for (var j = 0; j < 16; j += 4) {
  13793. var s0 = state[j + 0], s1 = state[j + 1];
  13794. var s2 = state[j + 2], s3 = state[j + 3];
  13795. t = s0 ^ s1 ^ s2 ^ s3;
  13796. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  13797. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  13798. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  13799. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  13800. }
  13801. //AddRoundKey
  13802. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  13803. state[j] ^= key[k];
  13804. }
  13805. }
  13806. //SubBytes
  13807. for (j = 0; j < 16; ++j) {
  13808. state[j] = s[state[j]];
  13809. }
  13810. //ShiftRows
  13811. v = state[1];
  13812. state[1] = state[5];
  13813. state[5] = state[9];
  13814. state[9] = state[13];
  13815. state[13] = v;
  13816. v = state[2];
  13817. u = state[6];
  13818. state[2] = state[10];
  13819. state[6] = state[14];
  13820. state[10] = v;
  13821. state[14] = u;
  13822. v = state[3];
  13823. u = state[7];
  13824. t = state[11];
  13825. state[3] = state[15];
  13826. state[7] = v;
  13827. state[11] = u;
  13828. state[15] = t;
  13829. //AddRoundKey
  13830. for (j = 0, k = 224; j < 16; ++j, ++k) {
  13831. state[j] ^= key[k];
  13832. }
  13833. return state;
  13834. }
  13835. function AES256Cipher(key) {
  13836. this.key = expandKey256(key);
  13837. this.buffer = new Uint8Array(16);
  13838. this.bufferPosition = 0;
  13839. }
  13840. function decryptBlock2(data, finalize) {
  13841. var i, j, ii, sourceLength = data.length,
  13842. buffer = this.buffer, bufferLength = this.bufferPosition,
  13843. result = [], iv = this.iv;
  13844. for (i = 0; i < sourceLength; ++i) {
  13845. buffer[bufferLength] = data[i];
  13846. ++bufferLength;
  13847. if (bufferLength < 16) {
  13848. continue;
  13849. }
  13850. // buffer is full, decrypting
  13851. var plain = decrypt256(buffer, this.key);
  13852. // xor-ing the IV vector to get plain text
  13853. for (j = 0; j < 16; ++j) {
  13854. plain[j] ^= iv[j];
  13855. }
  13856. iv = buffer;
  13857. result.push(plain);
  13858. buffer = new Uint8Array(16);
  13859. bufferLength = 0;
  13860. }
  13861. // saving incomplete buffer
  13862. this.buffer = buffer;
  13863. this.bufferLength = bufferLength;
  13864. this.iv = iv;
  13865. if (result.length === 0) {
  13866. return new Uint8Array([]);
  13867. }
  13868. // combining plain text blocks into one
  13869. var outputLength = 16 * result.length;
  13870. if (finalize) {
  13871. // undo a padding that is described in RFC 2898
  13872. var lastBlock = result[result.length - 1];
  13873. var psLen = lastBlock[15];
  13874. if (psLen <= 16) {
  13875. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  13876. if (lastBlock[i] !== psLen) {
  13877. // Invalid padding, assume that the block has no padding.
  13878. psLen = 0;
  13879. break;
  13880. }
  13881. }
  13882. outputLength -= psLen;
  13883. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  13884. }
  13885. }
  13886. var output = new Uint8Array(outputLength);
  13887. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13888. output.set(result[i], j);
  13889. }
  13890. return output;
  13891. }
  13892. AES256Cipher.prototype = {
  13893. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  13894. var i, sourceLength = data.length;
  13895. var buffer = this.buffer, bufferLength = this.bufferPosition;
  13896. // if not supplied an IV wait for IV values
  13897. // they are at the start of the stream
  13898. if (iv) {
  13899. this.iv = iv;
  13900. } else {
  13901. for (i = 0; bufferLength < 16 &&
  13902. i < sourceLength; ++i, ++bufferLength) {
  13903. buffer[bufferLength] = data[i];
  13904. }
  13905. if (bufferLength < 16) {
  13906. //need more data
  13907. this.bufferLength = bufferLength;
  13908. return new Uint8Array([]);
  13909. }
  13910. this.iv = buffer;
  13911. data = data.subarray(16);
  13912. }
  13913. this.buffer = new Uint8Array(16);
  13914. this.bufferLength = 0;
  13915. // starting decryption
  13916. this.decryptBlock = decryptBlock2;
  13917. return this.decryptBlock(data, finalize);
  13918. },
  13919. encrypt: function AES256Cipher_encrypt(data, iv) {
  13920. var i, j, ii, sourceLength = data.length,
  13921. buffer = this.buffer, bufferLength = this.bufferPosition,
  13922. result = [];
  13923. if (!iv) {
  13924. iv = new Uint8Array(16);
  13925. }
  13926. for (i = 0; i < sourceLength; ++i) {
  13927. buffer[bufferLength] = data[i];
  13928. ++bufferLength;
  13929. if (bufferLength < 16) {
  13930. continue;
  13931. }
  13932. for (j = 0; j < 16; ++j) {
  13933. buffer[j] ^= iv[j];
  13934. }
  13935. // buffer is full, encrypting
  13936. var cipher = encrypt256(buffer, this.key);
  13937. this.iv = cipher;
  13938. result.push(cipher);
  13939. buffer = new Uint8Array(16);
  13940. bufferLength = 0;
  13941. }
  13942. // saving incomplete buffer
  13943. this.buffer = buffer;
  13944. this.bufferLength = bufferLength;
  13945. this.iv = iv;
  13946. if (result.length === 0) {
  13947. return new Uint8Array([]);
  13948. }
  13949. // combining plain text blocks into one
  13950. var outputLength = 16 * result.length;
  13951. var output = new Uint8Array(outputLength);
  13952. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  13953. output.set(result[i], j);
  13954. }
  13955. return output;
  13956. }
  13957. };
  13958. return AES256Cipher;
  13959. })();
  13960. var PDF17 = (function PDF17Closure() {
  13961. function compareByteArrays(array1, array2) {
  13962. if (array1.length !== array2.length) {
  13963. return false;
  13964. }
  13965. for (var i = 0; i < array1.length; i++) {
  13966. if (array1[i] !== array2[i]) {
  13967. return false;
  13968. }
  13969. }
  13970. return true;
  13971. }
  13972. function PDF17() {
  13973. }
  13974. PDF17.prototype = {
  13975. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  13976. ownerValidationSalt,
  13977. userBytes,
  13978. ownerPassword) {
  13979. var hashData = new Uint8Array(password.length + 56);
  13980. hashData.set(password, 0);
  13981. hashData.set(ownerValidationSalt, password.length);
  13982. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  13983. var result = calculateSHA256(hashData, 0, hashData.length);
  13984. return compareByteArrays(result, ownerPassword);
  13985. },
  13986. checkUserPassword: function PDF17_checkUserPassword(password,
  13987. userValidationSalt,
  13988. userPassword) {
  13989. var hashData = new Uint8Array(password.length + 8);
  13990. hashData.set(password, 0);
  13991. hashData.set(userValidationSalt, password.length);
  13992. var result = calculateSHA256(hashData, 0, hashData.length);
  13993. return compareByteArrays(result, userPassword);
  13994. },
  13995. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  13996. ownerEncryption) {
  13997. var hashData = new Uint8Array(password.length + 56);
  13998. hashData.set(password, 0);
  13999. hashData.set(ownerKeySalt, password.length);
  14000. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14001. var key = calculateSHA256(hashData, 0, hashData.length);
  14002. var cipher = new AES256Cipher(key);
  14003. return cipher.decryptBlock(ownerEncryption,
  14004. false,
  14005. new Uint8Array(16));
  14006. },
  14007. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  14008. userEncryption) {
  14009. var hashData = new Uint8Array(password.length + 8);
  14010. hashData.set(password, 0);
  14011. hashData.set(userKeySalt, password.length);
  14012. //key is the decryption key for the UE string
  14013. var key = calculateSHA256(hashData, 0, hashData.length);
  14014. var cipher = new AES256Cipher(key);
  14015. return cipher.decryptBlock(userEncryption,
  14016. false,
  14017. new Uint8Array(16));
  14018. }
  14019. };
  14020. return PDF17;
  14021. })();
  14022. var PDF20 = (function PDF20Closure() {
  14023. function concatArrays(array1, array2) {
  14024. var t = new Uint8Array(array1.length + array2.length);
  14025. t.set(array1, 0);
  14026. t.set(array2, array1.length);
  14027. return t;
  14028. }
  14029. function calculatePDF20Hash(password, input, userBytes) {
  14030. //This refers to Algorithm 2.B as defined in ISO 32000-2
  14031. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  14032. var e = [0];
  14033. var i = 0;
  14034. while (i < 64 || e[e.length - 1] > i - 32) {
  14035. var arrayLength = password.length + k.length + userBytes.length;
  14036. var k1 = new Uint8Array(arrayLength * 64);
  14037. var array = concatArrays(password, k);
  14038. array = concatArrays(array, userBytes);
  14039. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  14040. k1.set(array, pos);
  14041. }
  14042. //AES128 CBC NO PADDING with
  14043. //first 16 bytes of k as the key and the second 16 as the iv.
  14044. var cipher = new AES128Cipher(k.subarray(0, 16));
  14045. e = cipher.encrypt(k1, k.subarray(16, 32));
  14046. //Now we have to take the first 16 bytes of an unsigned
  14047. //big endian integer... and compute the remainder
  14048. //modulo 3.... That is a fairly large number and
  14049. //JavaScript isn't going to handle that well...
  14050. //So we're using a trick that allows us to perform
  14051. //modulo math byte by byte
  14052. var remainder = 0;
  14053. for (var z = 0; z < 16; z++) {
  14054. remainder *= (256 % 3);
  14055. remainder %= 3;
  14056. remainder += ((e[z] >>> 0) % 3);
  14057. remainder %= 3;
  14058. }
  14059. if (remainder === 0) {
  14060. k = calculateSHA256(e, 0, e.length);
  14061. }
  14062. else if (remainder === 1) {
  14063. k = calculateSHA384(e, 0, e.length);
  14064. }
  14065. else if (remainder === 2) {
  14066. k = calculateSHA512(e, 0, e.length);
  14067. }
  14068. i++;
  14069. }
  14070. return k.subarray(0, 32);
  14071. }
  14072. function PDF20() {
  14073. }
  14074. function compareByteArrays(array1, array2) {
  14075. if (array1.length !== array2.length) {
  14076. return false;
  14077. }
  14078. for (var i = 0; i < array1.length; i++) {
  14079. if (array1[i] !== array2[i]) {
  14080. return false;
  14081. }
  14082. }
  14083. return true;
  14084. }
  14085. PDF20.prototype = {
  14086. hash: function PDF20_hash(password, concatBytes, userBytes) {
  14087. return calculatePDF20Hash(password, concatBytes, userBytes);
  14088. },
  14089. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  14090. ownerValidationSalt,
  14091. userBytes,
  14092. ownerPassword) {
  14093. var hashData = new Uint8Array(password.length + 56);
  14094. hashData.set(password, 0);
  14095. hashData.set(ownerValidationSalt, password.length);
  14096. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14097. var result = calculatePDF20Hash(password, hashData, userBytes);
  14098. return compareByteArrays(result, ownerPassword);
  14099. },
  14100. checkUserPassword: function PDF20_checkUserPassword(password,
  14101. userValidationSalt,
  14102. userPassword) {
  14103. var hashData = new Uint8Array(password.length + 8);
  14104. hashData.set(password, 0);
  14105. hashData.set(userValidationSalt, password.length);
  14106. var result = calculatePDF20Hash(password, hashData, []);
  14107. return compareByteArrays(result, userPassword);
  14108. },
  14109. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  14110. ownerEncryption) {
  14111. var hashData = new Uint8Array(password.length + 56);
  14112. hashData.set(password, 0);
  14113. hashData.set(ownerKeySalt, password.length);
  14114. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14115. var key = calculatePDF20Hash(password, hashData, userBytes);
  14116. var cipher = new AES256Cipher(key);
  14117. return cipher.decryptBlock(ownerEncryption,
  14118. false,
  14119. new Uint8Array(16));
  14120. },
  14121. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  14122. userEncryption) {
  14123. var hashData = new Uint8Array(password.length + 8);
  14124. hashData.set(password, 0);
  14125. hashData.set(userKeySalt, password.length);
  14126. //key is the decryption key for the UE string
  14127. var key = calculatePDF20Hash(password, hashData, []);
  14128. var cipher = new AES256Cipher(key);
  14129. return cipher.decryptBlock(userEncryption,
  14130. false,
  14131. new Uint8Array(16));
  14132. }
  14133. };
  14134. return PDF20;
  14135. })();
  14136. var CipherTransform = (function CipherTransformClosure() {
  14137. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  14138. this.stringCipherConstructor = stringCipherConstructor;
  14139. this.streamCipherConstructor = streamCipherConstructor;
  14140. }
  14141. CipherTransform.prototype = {
  14142. createStream: function CipherTransform_createStream(stream, length) {
  14143. var cipher = new this.streamCipherConstructor();
  14144. return new DecryptStream(stream, length,
  14145. function cipherTransformDecryptStream(data, finalize) {
  14146. return cipher.decryptBlock(data, finalize);
  14147. }
  14148. );
  14149. },
  14150. decryptString: function CipherTransform_decryptString(s) {
  14151. var cipher = new this.stringCipherConstructor();
  14152. var data = stringToBytes(s);
  14153. data = cipher.decryptBlock(data, true);
  14154. return bytesToString(data);
  14155. }
  14156. };
  14157. return CipherTransform;
  14158. })();
  14159. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  14160. var defaultPasswordBytes = new Uint8Array([
  14161. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  14162. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  14163. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  14164. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  14165. function createEncryptionKey20(revision, password, ownerPassword,
  14166. ownerValidationSalt, ownerKeySalt, uBytes,
  14167. userPassword, userValidationSalt, userKeySalt,
  14168. ownerEncryption, userEncryption, perms) {
  14169. if (password) {
  14170. var passwordLength = Math.min(127, password.length);
  14171. password = password.subarray(0, passwordLength);
  14172. } else {
  14173. password = [];
  14174. }
  14175. var pdfAlgorithm;
  14176. if (revision === 6) {
  14177. pdfAlgorithm = new PDF20();
  14178. } else {
  14179. pdfAlgorithm = new PDF17();
  14180. }
  14181. if (pdfAlgorithm) {
  14182. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  14183. userPassword)) {
  14184. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  14185. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  14186. uBytes,
  14187. ownerPassword)) {
  14188. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  14189. ownerEncryption);
  14190. }
  14191. }
  14192. return null;
  14193. }
  14194. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  14195. flags, revision, keyLength, encryptMetadata) {
  14196. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  14197. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  14198. if (password) {
  14199. n = Math.min(32, password.length);
  14200. for (; i < n; ++i) {
  14201. hashData[i] = password[i];
  14202. }
  14203. }
  14204. j = 0;
  14205. while (i < 32) {
  14206. hashData[i++] = defaultPasswordBytes[j++];
  14207. }
  14208. // as now the padded password in the hashData[0..i]
  14209. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  14210. hashData[i++] = ownerPassword[j];
  14211. }
  14212. hashData[i++] = flags & 0xFF;
  14213. hashData[i++] = (flags >> 8) & 0xFF;
  14214. hashData[i++] = (flags >> 16) & 0xFF;
  14215. hashData[i++] = (flags >>> 24) & 0xFF;
  14216. for (j = 0, n = fileId.length; j < n; ++j) {
  14217. hashData[i++] = fileId[j];
  14218. }
  14219. if (revision >= 4 && !encryptMetadata) {
  14220. hashData[i++] = 0xFF;
  14221. hashData[i++] = 0xFF;
  14222. hashData[i++] = 0xFF;
  14223. hashData[i++] = 0xFF;
  14224. }
  14225. var hash = calculateMD5(hashData, 0, i);
  14226. var keyLengthInBytes = keyLength >> 3;
  14227. if (revision >= 3) {
  14228. for (j = 0; j < 50; ++j) {
  14229. hash = calculateMD5(hash, 0, keyLengthInBytes);
  14230. }
  14231. }
  14232. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  14233. var cipher, checkData;
  14234. if (revision >= 3) {
  14235. for (i = 0; i < 32; ++i) {
  14236. hashData[i] = defaultPasswordBytes[i];
  14237. }
  14238. for (j = 0, n = fileId.length; j < n; ++j) {
  14239. hashData[i++] = fileId[j];
  14240. }
  14241. cipher = new ARCFourCipher(encryptionKey);
  14242. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  14243. n = encryptionKey.length;
  14244. var derivedKey = new Uint8Array(n), k;
  14245. for (j = 1; j <= 19; ++j) {
  14246. for (k = 0; k < n; ++k) {
  14247. derivedKey[k] = encryptionKey[k] ^ j;
  14248. }
  14249. cipher = new ARCFourCipher(derivedKey);
  14250. checkData = cipher.encryptBlock(checkData);
  14251. }
  14252. for (j = 0, n = checkData.length; j < n; ++j) {
  14253. if (userPassword[j] !== checkData[j]) {
  14254. return null;
  14255. }
  14256. }
  14257. } else {
  14258. cipher = new ARCFourCipher(encryptionKey);
  14259. checkData = cipher.encryptBlock(defaultPasswordBytes);
  14260. for (j = 0, n = checkData.length; j < n; ++j) {
  14261. if (userPassword[j] !== checkData[j]) {
  14262. return null;
  14263. }
  14264. }
  14265. }
  14266. return encryptionKey;
  14267. }
  14268. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  14269. var hashData = new Uint8Array(32), i = 0, j, n;
  14270. n = Math.min(32, password.length);
  14271. for (; i < n; ++i) {
  14272. hashData[i] = password[i];
  14273. }
  14274. j = 0;
  14275. while (i < 32) {
  14276. hashData[i++] = defaultPasswordBytes[j++];
  14277. }
  14278. var hash = calculateMD5(hashData, 0, i);
  14279. var keyLengthInBytes = keyLength >> 3;
  14280. if (revision >= 3) {
  14281. for (j = 0; j < 50; ++j) {
  14282. hash = calculateMD5(hash, 0, hash.length);
  14283. }
  14284. }
  14285. var cipher, userPassword;
  14286. if (revision >= 3) {
  14287. userPassword = ownerPassword;
  14288. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  14289. for (j = 19; j >= 0; j--) {
  14290. for (k = 0; k < keyLengthInBytes; ++k) {
  14291. derivedKey[k] = hash[k] ^ j;
  14292. }
  14293. cipher = new ARCFourCipher(derivedKey);
  14294. userPassword = cipher.encryptBlock(userPassword);
  14295. }
  14296. } else {
  14297. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  14298. userPassword = cipher.encryptBlock(ownerPassword);
  14299. }
  14300. return userPassword;
  14301. }
  14302. var identityName = Name.get('Identity');
  14303. function CipherTransformFactory(dict, fileId, password) {
  14304. var filter = dict.get('Filter');
  14305. if (!isName(filter) || filter.name !== 'Standard') {
  14306. error('unknown encryption method');
  14307. }
  14308. this.dict = dict;
  14309. var algorithm = dict.get('V');
  14310. if (!isInt(algorithm) ||
  14311. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  14312. algorithm !== 5)) {
  14313. error('unsupported encryption algorithm');
  14314. }
  14315. this.algorithm = algorithm;
  14316. var keyLength = dict.get('Length') || 40;
  14317. if (!isInt(keyLength) ||
  14318. keyLength < 40 || (keyLength % 8) !== 0) {
  14319. error('invalid key length');
  14320. }
  14321. // prepare keys
  14322. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  14323. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  14324. var flags = dict.get('P');
  14325. var revision = dict.get('R');
  14326. // meaningful when V is 4 or 5
  14327. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  14328. dict.get('EncryptMetadata') !== false);
  14329. this.encryptMetadata = encryptMetadata;
  14330. var fileIdBytes = stringToBytes(fileId);
  14331. var passwordBytes;
  14332. if (password) {
  14333. passwordBytes = stringToBytes(password);
  14334. }
  14335. var encryptionKey;
  14336. if (algorithm !== 5) {
  14337. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  14338. ownerPassword, userPassword, flags,
  14339. revision, keyLength, encryptMetadata);
  14340. }
  14341. else {
  14342. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  14343. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  14344. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  14345. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  14346. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  14347. var ownerEncryption = stringToBytes(dict.get('OE'));
  14348. var userEncryption = stringToBytes(dict.get('UE'));
  14349. var perms = stringToBytes(dict.get('Perms'));
  14350. encryptionKey =
  14351. createEncryptionKey20(revision, passwordBytes,
  14352. ownerPassword, ownerValidationSalt,
  14353. ownerKeySalt, uBytes,
  14354. userPassword, userValidationSalt,
  14355. userKeySalt, ownerEncryption,
  14356. userEncryption, perms);
  14357. }
  14358. if (!encryptionKey && !password) {
  14359. throw new PasswordException('No password given',
  14360. PasswordResponses.NEED_PASSWORD);
  14361. } else if (!encryptionKey && password) {
  14362. // Attempting use the password as an owner password
  14363. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  14364. revision, keyLength);
  14365. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  14366. ownerPassword, userPassword, flags,
  14367. revision, keyLength, encryptMetadata);
  14368. }
  14369. if (!encryptionKey) {
  14370. throw new PasswordException('Incorrect Password',
  14371. PasswordResponses.INCORRECT_PASSWORD);
  14372. }
  14373. this.encryptionKey = encryptionKey;
  14374. if (algorithm >= 4) {
  14375. this.cf = dict.get('CF');
  14376. this.stmf = dict.get('StmF') || identityName;
  14377. this.strf = dict.get('StrF') || identityName;
  14378. this.eff = dict.get('EFF') || this.strf;
  14379. }
  14380. }
  14381. function buildObjectKey(num, gen, encryptionKey, isAes) {
  14382. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  14383. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  14384. key[i] = encryptionKey[i];
  14385. }
  14386. key[i++] = num & 0xFF;
  14387. key[i++] = (num >> 8) & 0xFF;
  14388. key[i++] = (num >> 16) & 0xFF;
  14389. key[i++] = gen & 0xFF;
  14390. key[i++] = (gen >> 8) & 0xFF;
  14391. if (isAes) {
  14392. key[i++] = 0x73;
  14393. key[i++] = 0x41;
  14394. key[i++] = 0x6C;
  14395. key[i++] = 0x54;
  14396. }
  14397. var hash = calculateMD5(key, 0, i);
  14398. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  14399. }
  14400. function buildCipherConstructor(cf, name, num, gen, key) {
  14401. var cryptFilter = cf.get(name.name);
  14402. var cfm;
  14403. if (cryptFilter !== null && cryptFilter !== undefined) {
  14404. cfm = cryptFilter.get('CFM');
  14405. }
  14406. if (!cfm || cfm.name === 'None') {
  14407. return function cipherTransformFactoryBuildCipherConstructorNone() {
  14408. return new NullCipher();
  14409. };
  14410. }
  14411. if ('V2' === cfm.name) {
  14412. return function cipherTransformFactoryBuildCipherConstructorV2() {
  14413. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  14414. };
  14415. }
  14416. if ('AESV2' === cfm.name) {
  14417. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  14418. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  14419. };
  14420. }
  14421. if ('AESV3' === cfm.name) {
  14422. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  14423. return new AES256Cipher(key);
  14424. };
  14425. }
  14426. error('Unknown crypto method');
  14427. }
  14428. CipherTransformFactory.prototype = {
  14429. createCipherTransform:
  14430. function CipherTransformFactory_createCipherTransform(num, gen) {
  14431. if (this.algorithm === 4 || this.algorithm === 5) {
  14432. return new CipherTransform(
  14433. buildCipherConstructor(this.cf, this.stmf,
  14434. num, gen, this.encryptionKey),
  14435. buildCipherConstructor(this.cf, this.strf,
  14436. num, gen, this.encryptionKey));
  14437. }
  14438. // algorithms 1 and 2
  14439. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  14440. var cipherConstructor = function buildCipherCipherConstructor() {
  14441. return new ARCFourCipher(key);
  14442. };
  14443. return new CipherTransform(cipherConstructor, cipherConstructor);
  14444. }
  14445. };
  14446. return CipherTransformFactory;
  14447. })();
  14448. var PatternType = {
  14449. FUNCTION_BASED: 1,
  14450. AXIAL: 2,
  14451. RADIAL: 3,
  14452. FREE_FORM_MESH: 4,
  14453. LATTICE_FORM_MESH: 5,
  14454. COONS_PATCH_MESH: 6,
  14455. TENSOR_PATCH_MESH: 7
  14456. };
  14457. var Pattern = (function PatternClosure() {
  14458. // Constructor should define this.getPattern
  14459. function Pattern() {
  14460. error('should not call Pattern constructor');
  14461. }
  14462. Pattern.prototype = {
  14463. // Input: current Canvas context
  14464. // Output: the appropriate fillStyle or strokeStyle
  14465. getPattern: function Pattern_getPattern(ctx) {
  14466. error('Should not call Pattern.getStyle: ' + ctx);
  14467. }
  14468. };
  14469. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  14470. res) {
  14471. var dict = isStream(shading) ? shading.dict : shading;
  14472. var type = dict.get('ShadingType');
  14473. try {
  14474. switch (type) {
  14475. case PatternType.AXIAL:
  14476. case PatternType.RADIAL:
  14477. // Both radial and axial shadings are handled by RadialAxial shading.
  14478. return new Shadings.RadialAxial(dict, matrix, xref, res);
  14479. case PatternType.FREE_FORM_MESH:
  14480. case PatternType.LATTICE_FORM_MESH:
  14481. case PatternType.COONS_PATCH_MESH:
  14482. case PatternType.TENSOR_PATCH_MESH:
  14483. return new Shadings.Mesh(shading, matrix, xref, res);
  14484. default:
  14485. throw new Error('Unknown PatternType: ' + type);
  14486. }
  14487. } catch (ex) {
  14488. if (ex instanceof MissingDataException) {
  14489. throw ex;
  14490. }
  14491. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  14492. warn(ex);
  14493. return new Shadings.Dummy();
  14494. }
  14495. };
  14496. return Pattern;
  14497. })();
  14498. var Shadings = {};
  14499. // A small number to offset the first/last color stops so we can insert ones to
  14500. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  14501. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  14502. // internally so we have to go bigger.
  14503. Shadings.SMALL_NUMBER = 1e-2;
  14504. // Radial and axial shading have very similar implementations
  14505. // If needed, the implementations can be broken into two classes
  14506. Shadings.RadialAxial = (function RadialAxialClosure() {
  14507. function RadialAxial(dict, matrix, xref, res) {
  14508. this.matrix = matrix;
  14509. this.coordsArr = dict.get('Coords');
  14510. this.shadingType = dict.get('ShadingType');
  14511. this.type = 'Pattern';
  14512. var cs = dict.get('ColorSpace', 'CS');
  14513. cs = ColorSpace.parse(cs, xref, res);
  14514. this.cs = cs;
  14515. var t0 = 0.0, t1 = 1.0;
  14516. if (dict.has('Domain')) {
  14517. var domainArr = dict.get('Domain');
  14518. t0 = domainArr[0];
  14519. t1 = domainArr[1];
  14520. }
  14521. var extendStart = false, extendEnd = false;
  14522. if (dict.has('Extend')) {
  14523. var extendArr = dict.get('Extend');
  14524. extendStart = extendArr[0];
  14525. extendEnd = extendArr[1];
  14526. }
  14527. if (this.shadingType === PatternType.RADIAL &&
  14528. (!extendStart || !extendEnd)) {
  14529. // Radial gradient only currently works if either circle is fully within
  14530. // the other circle.
  14531. var x1 = this.coordsArr[0];
  14532. var y1 = this.coordsArr[1];
  14533. var r1 = this.coordsArr[2];
  14534. var x2 = this.coordsArr[3];
  14535. var y2 = this.coordsArr[4];
  14536. var r2 = this.coordsArr[5];
  14537. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  14538. if (r1 <= r2 + distance &&
  14539. r2 <= r1 + distance) {
  14540. warn('Unsupported radial gradient.');
  14541. }
  14542. }
  14543. this.extendStart = extendStart;
  14544. this.extendEnd = extendEnd;
  14545. var fnObj = dict.get('Function');
  14546. var fn = PDFFunction.parseArray(xref, fnObj);
  14547. // 10 samples seems good enough for now, but probably won't work
  14548. // if there are sharp color changes. Ideally, we would implement
  14549. // the spec faithfully and add lossless optimizations.
  14550. var diff = t1 - t0;
  14551. var step = diff / 10;
  14552. var colorStops = this.colorStops = [];
  14553. // Protect against bad domains so we don't end up in an infinte loop below.
  14554. if (t0 >= t1 || step <= 0) {
  14555. // Acrobat doesn't seem to handle these cases so we'll ignore for
  14556. // now.
  14557. info('Bad shading domain.');
  14558. return;
  14559. }
  14560. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  14561. var rgbColor;
  14562. for (var i = t0; i <= t1; i += step) {
  14563. ratio[0] = i;
  14564. fn(ratio, 0, color, 0);
  14565. rgbColor = cs.getRgb(color, 0);
  14566. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14567. colorStops.push([(i - t0) / diff, cssColor]);
  14568. }
  14569. var background = 'transparent';
  14570. if (dict.has('Background')) {
  14571. rgbColor = cs.getRgb(dict.get('Background'), 0);
  14572. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  14573. }
  14574. if (!extendStart) {
  14575. // Insert a color stop at the front and offset the first real color stop
  14576. // so it doesn't conflict with the one we insert.
  14577. colorStops.unshift([0, background]);
  14578. colorStops[1][0] += Shadings.SMALL_NUMBER;
  14579. }
  14580. if (!extendEnd) {
  14581. // Same idea as above in extendStart but for the end.
  14582. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  14583. colorStops.push([1, background]);
  14584. }
  14585. this.colorStops = colorStops;
  14586. }
  14587. RadialAxial.prototype = {
  14588. getIR: function RadialAxial_getIR() {
  14589. var coordsArr = this.coordsArr;
  14590. var shadingType = this.shadingType;
  14591. var type, p0, p1, r0, r1;
  14592. if (shadingType === PatternType.AXIAL) {
  14593. p0 = [coordsArr[0], coordsArr[1]];
  14594. p1 = [coordsArr[2], coordsArr[3]];
  14595. r0 = null;
  14596. r1 = null;
  14597. type = 'axial';
  14598. } else if (shadingType === PatternType.RADIAL) {
  14599. p0 = [coordsArr[0], coordsArr[1]];
  14600. p1 = [coordsArr[3], coordsArr[4]];
  14601. r0 = coordsArr[2];
  14602. r1 = coordsArr[5];
  14603. type = 'radial';
  14604. } else {
  14605. error('getPattern type unknown: ' + shadingType);
  14606. }
  14607. var matrix = this.matrix;
  14608. if (matrix) {
  14609. p0 = Util.applyTransform(p0, matrix);
  14610. p1 = Util.applyTransform(p1, matrix);
  14611. }
  14612. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  14613. }
  14614. };
  14615. return RadialAxial;
  14616. })();
  14617. // All mesh shading. For now, they will be presented as set of the triangles
  14618. // to be drawn on the canvas and rgb color for each vertex.
  14619. Shadings.Mesh = (function MeshClosure() {
  14620. function MeshStreamReader(stream, context) {
  14621. this.stream = stream;
  14622. this.context = context;
  14623. this.buffer = 0;
  14624. this.bufferLength = 0;
  14625. var numComps = context.numComps;
  14626. this.tmpCompsBuf = new Float32Array(numComps);
  14627. var csNumComps = context.colorSpace;
  14628. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  14629. this.tmpCompsBuf;
  14630. }
  14631. MeshStreamReader.prototype = {
  14632. get hasData() {
  14633. if (this.stream.end) {
  14634. return this.stream.pos < this.stream.end;
  14635. }
  14636. if (this.bufferLength > 0) {
  14637. return true;
  14638. }
  14639. var nextByte = this.stream.getByte();
  14640. if (nextByte < 0) {
  14641. return false;
  14642. }
  14643. this.buffer = nextByte;
  14644. this.bufferLength = 8;
  14645. return true;
  14646. },
  14647. readBits: function MeshStreamReader_readBits(n) {
  14648. var buffer = this.buffer;
  14649. var bufferLength = this.bufferLength;
  14650. if (n === 32) {
  14651. if (bufferLength === 0) {
  14652. return ((this.stream.getByte() << 24) |
  14653. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  14654. this.stream.getByte()) >>> 0;
  14655. }
  14656. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  14657. (this.stream.getByte() << 8) | this.stream.getByte();
  14658. var nextByte = this.stream.getByte();
  14659. this.buffer = nextByte & ((1 << bufferLength) - 1);
  14660. return ((buffer << (8 - bufferLength)) |
  14661. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  14662. }
  14663. if (n === 8 && bufferLength === 0) {
  14664. return this.stream.getByte();
  14665. }
  14666. while (bufferLength < n) {
  14667. buffer = (buffer << 8) | this.stream.getByte();
  14668. bufferLength += 8;
  14669. }
  14670. bufferLength -= n;
  14671. this.bufferLength = bufferLength;
  14672. this.buffer = buffer & ((1 << bufferLength) - 1);
  14673. return buffer >> bufferLength;
  14674. },
  14675. align: function MeshStreamReader_align() {
  14676. this.buffer = 0;
  14677. this.bufferLength = 0;
  14678. },
  14679. readFlag: function MeshStreamReader_readFlag() {
  14680. return this.readBits(this.context.bitsPerFlag);
  14681. },
  14682. readCoordinate: function MeshStreamReader_readCoordinate() {
  14683. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  14684. var xi = this.readBits(bitsPerCoordinate);
  14685. var yi = this.readBits(bitsPerCoordinate);
  14686. var decode = this.context.decode;
  14687. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  14688. 2.3283064365386963e-10; // 2 ^ -32
  14689. return [
  14690. xi * scale * (decode[1] - decode[0]) + decode[0],
  14691. yi * scale * (decode[3] - decode[2]) + decode[2]
  14692. ];
  14693. },
  14694. readComponents: function MeshStreamReader_readComponents() {
  14695. var numComps = this.context.numComps;
  14696. var bitsPerComponent = this.context.bitsPerComponent;
  14697. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  14698. 2.3283064365386963e-10; // 2 ^ -32
  14699. var decode = this.context.decode;
  14700. var components = this.tmpCompsBuf;
  14701. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  14702. var ci = this.readBits(bitsPerComponent);
  14703. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  14704. }
  14705. var color = this.tmpCsCompsBuf;
  14706. if (this.context.colorFn) {
  14707. this.context.colorFn(components, 0, color, 0);
  14708. }
  14709. return this.context.colorSpace.getRgb(color, 0);
  14710. }
  14711. };
  14712. function decodeType4Shading(mesh, reader) {
  14713. var coords = mesh.coords;
  14714. var colors = mesh.colors;
  14715. var operators = [];
  14716. var ps = []; // not maintaining cs since that will match ps
  14717. var verticesLeft = 0; // assuming we have all data to start a new triangle
  14718. while (reader.hasData) {
  14719. var f = reader.readFlag();
  14720. var coord = reader.readCoordinate();
  14721. var color = reader.readComponents();
  14722. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  14723. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  14724. switch (f) {
  14725. case 0:
  14726. verticesLeft = 3;
  14727. break;
  14728. case 1:
  14729. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  14730. verticesLeft = 1;
  14731. break;
  14732. case 2:
  14733. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  14734. verticesLeft = 1;
  14735. break;
  14736. }
  14737. operators.push(f);
  14738. }
  14739. ps.push(coords.length);
  14740. coords.push(coord);
  14741. colors.push(color);
  14742. verticesLeft--;
  14743. reader.align();
  14744. }
  14745. var psPacked = new Int32Array(ps);
  14746. mesh.figures.push({
  14747. type: 'triangles',
  14748. coords: psPacked,
  14749. colors: psPacked
  14750. });
  14751. }
  14752. function decodeType5Shading(mesh, reader, verticesPerRow) {
  14753. var coords = mesh.coords;
  14754. var colors = mesh.colors;
  14755. var ps = []; // not maintaining cs since that will match ps
  14756. while (reader.hasData) {
  14757. var coord = reader.readCoordinate();
  14758. var color = reader.readComponents();
  14759. ps.push(coords.length);
  14760. coords.push(coord);
  14761. colors.push(color);
  14762. }
  14763. var psPacked = new Int32Array(ps);
  14764. mesh.figures.push({
  14765. type: 'lattice',
  14766. coords: psPacked,
  14767. colors: psPacked,
  14768. verticesPerRow: verticesPerRow
  14769. });
  14770. }
  14771. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  14772. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  14773. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  14774. var getB = (function getBClosure() {
  14775. function buildB(count) {
  14776. var lut = [];
  14777. for (var i = 0; i <= count; i++) {
  14778. var t = i / count, t_ = 1 - t;
  14779. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  14780. 3 * t * t * t_, t * t * t]));
  14781. }
  14782. return lut;
  14783. }
  14784. var cache = [];
  14785. return function getB(count) {
  14786. if (!cache[count]) {
  14787. cache[count] = buildB(count);
  14788. }
  14789. return cache[count];
  14790. };
  14791. })();
  14792. function buildFigureFromPatch(mesh, index) {
  14793. var figure = mesh.figures[index];
  14794. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  14795. var coords = mesh.coords, colors = mesh.colors;
  14796. var pi = figure.coords;
  14797. var ci = figure.colors;
  14798. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  14799. coords[pi[12]][0], coords[pi[15]][0]);
  14800. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  14801. coords[pi[12]][1], coords[pi[15]][1]);
  14802. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  14803. coords[pi[12]][0], coords[pi[15]][0]);
  14804. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  14805. coords[pi[12]][1], coords[pi[15]][1]);
  14806. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  14807. (mesh.bounds[2] - mesh.bounds[0]));
  14808. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14809. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  14810. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  14811. (mesh.bounds[3] - mesh.bounds[1]));
  14812. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  14813. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  14814. var verticesPerRow = splitXBy + 1;
  14815. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  14816. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  14817. var k = 0;
  14818. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  14819. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  14820. c2 = colors[ci[2]], c3 = colors[ci[3]];
  14821. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  14822. for (var row = 0; row <= splitYBy; row++) {
  14823. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  14824. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  14825. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  14826. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  14827. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  14828. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  14829. for (var col = 0; col <= splitXBy; col++, k++) {
  14830. if ((row === 0 || row === splitYBy) &&
  14831. (col === 0 || col === splitXBy)) {
  14832. continue;
  14833. }
  14834. var x = 0, y = 0;
  14835. var q = 0;
  14836. for (var i = 0; i <= 3; i++) {
  14837. for (var j = 0; j <= 3; j++, q++) {
  14838. var m = bRow[row][i] * bCol[col][j];
  14839. x += coords[pi[q]][0] * m;
  14840. y += coords[pi[q]][1] * m;
  14841. }
  14842. }
  14843. figureCoords[k] = coords.length;
  14844. coords.push([x, y]);
  14845. figureColors[k] = colors.length;
  14846. var newColor = new Uint8Array(3);
  14847. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  14848. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  14849. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  14850. colors.push(newColor);
  14851. }
  14852. }
  14853. figureCoords[0] = pi[0];
  14854. figureColors[0] = ci[0];
  14855. figureCoords[splitXBy] = pi[3];
  14856. figureColors[splitXBy] = ci[1];
  14857. figureCoords[verticesPerRow * splitYBy] = pi[12];
  14858. figureColors[verticesPerRow * splitYBy] = ci[2];
  14859. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  14860. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  14861. mesh.figures[index] = {
  14862. type: 'lattice',
  14863. coords: figureCoords,
  14864. colors: figureColors,
  14865. verticesPerRow: verticesPerRow
  14866. };
  14867. }
  14868. function decodeType6Shading(mesh, reader) {
  14869. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  14870. var coords = mesh.coords;
  14871. var colors = mesh.colors;
  14872. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14873. var cs = new Int32Array(4); // c00, c30, c03, c33
  14874. while (reader.hasData) {
  14875. var f = reader.readFlag();
  14876. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  14877. var i, ii;
  14878. var pi = coords.length;
  14879. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  14880. coords.push(reader.readCoordinate());
  14881. }
  14882. var ci = colors.length;
  14883. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14884. colors.push(reader.readComponents());
  14885. }
  14886. var tmp1, tmp2, tmp3, tmp4;
  14887. switch (f) {
  14888. case 0:
  14889. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14890. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14891. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  14892. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14893. cs[2] = ci + 1; cs[3] = ci + 2;
  14894. cs[0] = ci; cs[1] = ci + 3;
  14895. break;
  14896. case 1:
  14897. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  14898. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  14899. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  14900. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  14901. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  14902. tmp1 = cs[2]; tmp2 = cs[3];
  14903. cs[2] = ci + 1; cs[3] = ci;
  14904. cs[0] = tmp1; cs[1] = tmp2;
  14905. break;
  14906. case 2:
  14907. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  14908. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  14909. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  14910. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  14911. cs[2] = cs[3]; cs[3] = ci + 1;
  14912. cs[0] = cs[1]; cs[1] = ci;
  14913. break;
  14914. case 3:
  14915. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  14916. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  14917. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  14918. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  14919. cs[2] = cs[0]; cs[3] = cs[1];
  14920. cs[0] = ci; cs[1] = ci + 1;
  14921. break;
  14922. }
  14923. // set p11, p12, p21, p22
  14924. ps[5] = coords.length;
  14925. coords.push([
  14926. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  14927. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  14928. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14929. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  14930. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  14931. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  14932. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14933. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  14934. ]);
  14935. ps[6] = coords.length;
  14936. coords.push([
  14937. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  14938. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  14939. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14940. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  14941. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  14942. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  14943. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14944. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  14945. ]);
  14946. ps[9] = coords.length;
  14947. coords.push([
  14948. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  14949. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  14950. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  14951. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  14952. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  14953. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  14954. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  14955. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  14956. ]);
  14957. ps[10] = coords.length;
  14958. coords.push([
  14959. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  14960. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  14961. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  14962. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  14963. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  14964. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  14965. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  14966. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  14967. ]);
  14968. mesh.figures.push({
  14969. type: 'patch',
  14970. coords: new Int32Array(ps), // making copies of ps and cs
  14971. colors: new Int32Array(cs)
  14972. });
  14973. }
  14974. }
  14975. function decodeType7Shading(mesh, reader) {
  14976. var coords = mesh.coords;
  14977. var colors = mesh.colors;
  14978. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  14979. var cs = new Int32Array(4); // c00, c30, c03, c33
  14980. while (reader.hasData) {
  14981. var f = reader.readFlag();
  14982. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  14983. var i, ii;
  14984. var pi = coords.length;
  14985. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  14986. coords.push(reader.readCoordinate());
  14987. }
  14988. var ci = colors.length;
  14989. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  14990. colors.push(reader.readComponents());
  14991. }
  14992. var tmp1, tmp2, tmp3, tmp4;
  14993. switch (f) {
  14994. case 0:
  14995. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  14996. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  14997. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  14998. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  14999. cs[2] = ci + 1; cs[3] = ci + 2;
  15000. cs[0] = ci; cs[1] = ci + 3;
  15001. break;
  15002. case 1:
  15003. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  15004. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  15005. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  15006. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  15007. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  15008. tmp1 = cs[2]; tmp2 = cs[3];
  15009. cs[2] = ci + 1; cs[3] = ci;
  15010. cs[0] = tmp1; cs[1] = tmp2;
  15011. break;
  15012. case 2:
  15013. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  15014. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  15015. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  15016. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  15017. cs[2] = cs[3]; cs[3] = ci + 1;
  15018. cs[0] = cs[1]; cs[1] = ci;
  15019. break;
  15020. case 3:
  15021. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  15022. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  15023. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  15024. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  15025. cs[2] = cs[0]; cs[3] = cs[1];
  15026. cs[0] = ci; cs[1] = ci + 1;
  15027. break;
  15028. }
  15029. mesh.figures.push({
  15030. type: 'patch',
  15031. coords: new Int32Array(ps), // making copies of ps and cs
  15032. colors: new Int32Array(cs)
  15033. });
  15034. }
  15035. }
  15036. function updateBounds(mesh) {
  15037. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  15038. maxX = minX, maxY = minY;
  15039. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  15040. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  15041. minX = minX > x ? x : minX;
  15042. minY = minY > y ? y : minY;
  15043. maxX = maxX < x ? x : maxX;
  15044. maxY = maxY < y ? y : maxY;
  15045. }
  15046. mesh.bounds = [minX, minY, maxX, maxY];
  15047. }
  15048. function packData(mesh) {
  15049. var i, ii, j, jj;
  15050. var coords = mesh.coords;
  15051. var coordsPacked = new Float32Array(coords.length * 2);
  15052. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  15053. var xy = coords[i];
  15054. coordsPacked[j++] = xy[0];
  15055. coordsPacked[j++] = xy[1];
  15056. }
  15057. mesh.coords = coordsPacked;
  15058. var colors = mesh.colors;
  15059. var colorsPacked = new Uint8Array(colors.length * 3);
  15060. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  15061. var c = colors[i];
  15062. colorsPacked[j++] = c[0];
  15063. colorsPacked[j++] = c[1];
  15064. colorsPacked[j++] = c[2];
  15065. }
  15066. mesh.colors = colorsPacked;
  15067. var figures = mesh.figures;
  15068. for (i = 0, ii = figures.length; i < ii; i++) {
  15069. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  15070. for (j = 0, jj = ps.length; j < jj; j++) {
  15071. ps[j] *= 2;
  15072. cs[j] *= 3;
  15073. }
  15074. }
  15075. }
  15076. function Mesh(stream, matrix, xref, res) {
  15077. assert(isStream(stream), 'Mesh data is not a stream');
  15078. var dict = stream.dict;
  15079. this.matrix = matrix;
  15080. this.shadingType = dict.get('ShadingType');
  15081. this.type = 'Pattern';
  15082. this.bbox = dict.get('BBox');
  15083. var cs = dict.get('ColorSpace', 'CS');
  15084. cs = ColorSpace.parse(cs, xref, res);
  15085. this.cs = cs;
  15086. this.background = dict.has('Background') ?
  15087. cs.getRgb(dict.get('Background'), 0) : null;
  15088. var fnObj = dict.get('Function');
  15089. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  15090. this.coords = [];
  15091. this.colors = [];
  15092. this.figures = [];
  15093. var decodeContext = {
  15094. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  15095. bitsPerComponent: dict.get('BitsPerComponent'),
  15096. bitsPerFlag: dict.get('BitsPerFlag'),
  15097. decode: dict.get('Decode'),
  15098. colorFn: fn,
  15099. colorSpace: cs,
  15100. numComps: fn ? 1 : cs.numComps
  15101. };
  15102. var reader = new MeshStreamReader(stream, decodeContext);
  15103. var patchMesh = false;
  15104. switch (this.shadingType) {
  15105. case PatternType.FREE_FORM_MESH:
  15106. decodeType4Shading(this, reader);
  15107. break;
  15108. case PatternType.LATTICE_FORM_MESH:
  15109. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  15110. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  15111. decodeType5Shading(this, reader, verticesPerRow);
  15112. break;
  15113. case PatternType.COONS_PATCH_MESH:
  15114. decodeType6Shading(this, reader);
  15115. patchMesh = true;
  15116. break;
  15117. case PatternType.TENSOR_PATCH_MESH:
  15118. decodeType7Shading(this, reader);
  15119. patchMesh = true;
  15120. break;
  15121. default:
  15122. error('Unsupported mesh type.');
  15123. break;
  15124. }
  15125. if (patchMesh) {
  15126. // dirty bounds calculation for determining, how dense shall be triangles
  15127. updateBounds(this);
  15128. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  15129. buildFigureFromPatch(this, i);
  15130. }
  15131. }
  15132. // calculate bounds
  15133. updateBounds(this);
  15134. packData(this);
  15135. }
  15136. Mesh.prototype = {
  15137. getIR: function Mesh_getIR() {
  15138. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  15139. this.bounds, this.matrix, this.bbox, this.background];
  15140. }
  15141. };
  15142. return Mesh;
  15143. })();
  15144. Shadings.Dummy = (function DummyClosure() {
  15145. function Dummy() {
  15146. this.type = 'Pattern';
  15147. }
  15148. Dummy.prototype = {
  15149. getIR: function Dummy_getIR() {
  15150. return ['Dummy'];
  15151. }
  15152. };
  15153. return Dummy;
  15154. })();
  15155. function getTilingPatternIR(operatorList, dict, args) {
  15156. var matrix = dict.get('Matrix');
  15157. var bbox = dict.get('BBox');
  15158. var xstep = dict.get('XStep');
  15159. var ystep = dict.get('YStep');
  15160. var paintType = dict.get('PaintType');
  15161. var tilingType = dict.get('TilingType');
  15162. return [
  15163. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  15164. paintType, tilingType
  15165. ];
  15166. }
  15167. var PartialEvaluator = (function PartialEvaluatorClosure() {
  15168. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  15169. uniquePrefix, idCounters, fontCache) {
  15170. this.pdfManager = pdfManager;
  15171. this.xref = xref;
  15172. this.handler = handler;
  15173. this.pageIndex = pageIndex;
  15174. this.uniquePrefix = uniquePrefix;
  15175. this.idCounters = idCounters;
  15176. this.fontCache = fontCache;
  15177. }
  15178. // Trying to minimize Date.now() usage and check every 100 time
  15179. var TIME_SLOT_DURATION_MS = 20;
  15180. var CHECK_TIME_EVERY = 100;
  15181. function TimeSlotManager() {
  15182. this.reset();
  15183. }
  15184. TimeSlotManager.prototype = {
  15185. check: function TimeSlotManager_check() {
  15186. if (++this.checked < CHECK_TIME_EVERY) {
  15187. return false;
  15188. }
  15189. this.checked = 0;
  15190. return this.endTime <= Date.now();
  15191. },
  15192. reset: function TimeSlotManager_reset() {
  15193. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  15194. this.checked = 0;
  15195. }
  15196. };
  15197. var deferred = Promise.resolve();
  15198. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  15199. PartialEvaluator.prototype = {
  15200. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  15201. if (!isDict(resources)) {
  15202. return false;
  15203. }
  15204. var processed = Object.create(null);
  15205. if (resources.objId) {
  15206. processed[resources.objId] = true;
  15207. }
  15208. var nodes = [resources];
  15209. while (nodes.length) {
  15210. var key;
  15211. var node = nodes.shift();
  15212. // First check the current resources for blend modes.
  15213. var graphicStates = node.get('ExtGState');
  15214. if (isDict(graphicStates)) {
  15215. graphicStates = graphicStates.getAll();
  15216. for (key in graphicStates) {
  15217. var graphicState = graphicStates[key];
  15218. var bm = graphicState['BM'];
  15219. if (isName(bm) && bm.name !== 'Normal') {
  15220. return true;
  15221. }
  15222. }
  15223. }
  15224. // Descend into the XObjects to look for more resources and blend modes.
  15225. var xObjects = node.get('XObject');
  15226. if (!isDict(xObjects)) {
  15227. continue;
  15228. }
  15229. xObjects = xObjects.getAll();
  15230. for (key in xObjects) {
  15231. var xObject = xObjects[key];
  15232. if (!isStream(xObject)) {
  15233. continue;
  15234. }
  15235. if (xObject.dict.objId) {
  15236. if (processed[xObject.dict.objId]) {
  15237. // stream has objId and is processed already
  15238. continue;
  15239. }
  15240. processed[xObject.dict.objId] = true;
  15241. }
  15242. var xResources = xObject.dict.get('Resources');
  15243. // Checking objId to detect an infinite loop.
  15244. if (isDict(xResources) &&
  15245. (!xResources.objId || !processed[xResources.objId])) {
  15246. nodes.push(xResources);
  15247. if (xResources.objId) {
  15248. processed[xResources.objId] = true;
  15249. }
  15250. }
  15251. }
  15252. }
  15253. return false;
  15254. },
  15255. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  15256. xobj, smask,
  15257. operatorList,
  15258. initialState) {
  15259. var matrix = xobj.dict.get('Matrix');
  15260. var bbox = xobj.dict.get('BBox');
  15261. var group = xobj.dict.get('Group');
  15262. if (group) {
  15263. var groupOptions = {
  15264. matrix: matrix,
  15265. bbox: bbox,
  15266. smask: smask,
  15267. isolated: false,
  15268. knockout: false
  15269. };
  15270. var groupSubtype = group.get('S');
  15271. var colorSpace;
  15272. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  15273. groupOptions.isolated = (group.get('I') || false);
  15274. groupOptions.knockout = (group.get('K') || false);
  15275. colorSpace = (group.has('CS') ?
  15276. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  15277. }
  15278. if (smask && smask.backdrop) {
  15279. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  15280. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  15281. }
  15282. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  15283. }
  15284. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  15285. return this.getOperatorList(xobj,
  15286. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  15287. then(function () {
  15288. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  15289. if (group) {
  15290. operatorList.addOp(OPS.endGroup, [groupOptions]);
  15291. }
  15292. });
  15293. },
  15294. buildPaintImageXObject:
  15295. function PartialEvaluator_buildPaintImageXObject(resources, image,
  15296. inline, operatorList,
  15297. cacheKey, imageCache) {
  15298. var self = this;
  15299. var dict = image.dict;
  15300. var w = dict.get('Width', 'W');
  15301. var h = dict.get('Height', 'H');
  15302. if (!(w && isNum(w)) || !(h && isNum(h))) {
  15303. warn('Image dimensions are missing, or not numbers.');
  15304. return;
  15305. }
  15306. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  15307. warn('Image exceeded maximum allowed size and was removed.');
  15308. return;
  15309. }
  15310. var imageMask = (dict.get('ImageMask', 'IM') || false);
  15311. var imgData, args;
  15312. if (imageMask) {
  15313. // This depends on a tmpCanvas being filled with the
  15314. // current fillStyle, such that processing the pixel
  15315. // data can't be done here. Instead of creating a
  15316. // complete PDFImage, only read the information needed
  15317. // for later.
  15318. var width = dict.get('Width', 'W');
  15319. var height = dict.get('Height', 'H');
  15320. var bitStrideLength = (width + 7) >> 3;
  15321. var imgArray = image.getBytes(bitStrideLength * height);
  15322. var decode = dict.get('Decode', 'D');
  15323. var inverseDecode = (!!decode && decode[0] > 0);
  15324. imgData = PDFImage.createMask(imgArray, width, height,
  15325. image instanceof DecodeStream,
  15326. inverseDecode);
  15327. imgData.cached = true;
  15328. args = [imgData];
  15329. operatorList.addOp(OPS.paintImageMaskXObject, args);
  15330. if (cacheKey) {
  15331. imageCache[cacheKey] = {
  15332. fn: OPS.paintImageMaskXObject,
  15333. args: args
  15334. };
  15335. }
  15336. return;
  15337. }
  15338. var softMask = (dict.get('SMask', 'SM') || false);
  15339. var mask = (dict.get('Mask') || false);
  15340. var SMALL_IMAGE_DIMENSIONS = 200;
  15341. // Inlining small images into the queue as RGB data
  15342. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  15343. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  15344. var imageObj = new PDFImage(this.xref, resources, image,
  15345. inline, null, null);
  15346. // We force the use of RGBA_32BPP images here, because we can't handle
  15347. // any other kind.
  15348. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  15349. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  15350. return;
  15351. }
  15352. // If there is no imageMask, create the PDFImage and a lot
  15353. // of image processing can be done here.
  15354. var uniquePrefix = (this.uniquePrefix || '');
  15355. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  15356. operatorList.addDependency(objId);
  15357. args = [objId, w, h];
  15358. if (!softMask && !mask && image instanceof JpegStream &&
  15359. image.isNativelySupported(this.xref, resources)) {
  15360. // These JPEGs don't need any more processing so we can just send it.
  15361. operatorList.addOp(OPS.paintJpegXObject, args);
  15362. this.handler.send('obj',
  15363. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  15364. return;
  15365. }
  15366. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  15367. then(function(imageObj) {
  15368. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  15369. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  15370. [imgData.data.buffer]);
  15371. }).then(undefined, function (reason) {
  15372. warn('Unable to decode image: ' + reason);
  15373. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  15374. });
  15375. operatorList.addOp(OPS.paintImageXObject, args);
  15376. if (cacheKey) {
  15377. imageCache[cacheKey] = {
  15378. fn: OPS.paintImageXObject,
  15379. args: args
  15380. };
  15381. }
  15382. },
  15383. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  15384. operatorList,
  15385. stateManager) {
  15386. var smaskContent = smask.get('G');
  15387. var smaskOptions = {
  15388. subtype: smask.get('S').name,
  15389. backdrop: smask.get('BC')
  15390. };
  15391. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  15392. operatorList, stateManager.state.clone());
  15393. },
  15394. handleTilingType:
  15395. function PartialEvaluator_handleTilingType(fn, args, resources,
  15396. pattern, patternDict,
  15397. operatorList) {
  15398. // Create an IR of the pattern code.
  15399. var tilingOpList = new OperatorList();
  15400. return this.getOperatorList(pattern,
  15401. (patternDict.get('Resources') || resources), tilingOpList).
  15402. then(function () {
  15403. // Add the dependencies to the parent operator list so they are
  15404. // resolved before sub operator list is executed synchronously.
  15405. operatorList.addDependencies(tilingOpList.dependencies);
  15406. operatorList.addOp(fn, getTilingPatternIR({
  15407. fnArray: tilingOpList.fnArray,
  15408. argsArray: tilingOpList.argsArray
  15409. }, patternDict, args));
  15410. });
  15411. },
  15412. handleSetFont:
  15413. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  15414. operatorList, state) {
  15415. // TODO(mack): Not needed?
  15416. var fontName;
  15417. if (fontArgs) {
  15418. fontArgs = fontArgs.slice();
  15419. fontName = fontArgs[0].name;
  15420. }
  15421. var self = this;
  15422. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  15423. function (translated) {
  15424. if (!translated.font.isType3Font) {
  15425. return translated;
  15426. }
  15427. return translated.loadType3Data(self, resources, operatorList).then(
  15428. function () {
  15429. return translated;
  15430. });
  15431. }).then(function (translated) {
  15432. state.font = translated.font;
  15433. translated.send(self.handler);
  15434. return translated.loadedName;
  15435. });
  15436. },
  15437. handleText: function PartialEvaluator_handleText(chars, state) {
  15438. var font = state.font;
  15439. var glyphs = font.charsToGlyphs(chars);
  15440. var isAddToPathSet = !!(state.textRenderingMode &
  15441. TextRenderingMode.ADD_TO_PATH_FLAG);
  15442. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  15443. var buildPath = function (fontChar) {
  15444. if (!font.renderer.hasBuiltPath(fontChar)) {
  15445. var path = font.renderer.getPathJs(fontChar);
  15446. this.handler.send('commonobj', [
  15447. font.loadedName + '_path_' + fontChar,
  15448. 'FontPath',
  15449. path
  15450. ]);
  15451. }
  15452. }.bind(this);
  15453. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  15454. var glyph = glyphs[i];
  15455. if (glyph === null) {
  15456. continue;
  15457. }
  15458. buildPath(glyph.fontChar);
  15459. // If the glyph has an accent we need to build a path for its
  15460. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  15461. var accent = glyph.accent;
  15462. if (accent && accent.fontChar) {
  15463. buildPath(accent.fontChar);
  15464. }
  15465. }
  15466. }
  15467. return glyphs;
  15468. },
  15469. setGState: function PartialEvaluator_setGState(resources, gState,
  15470. operatorList, xref,
  15471. stateManager) {
  15472. // This array holds the converted/processed state data.
  15473. var gStateObj = [];
  15474. var gStateMap = gState.map;
  15475. var self = this;
  15476. var promise = Promise.resolve();
  15477. for (var key in gStateMap) {
  15478. var value = gStateMap[key];
  15479. switch (key) {
  15480. case 'Type':
  15481. break;
  15482. case 'LW':
  15483. case 'LC':
  15484. case 'LJ':
  15485. case 'ML':
  15486. case 'D':
  15487. case 'RI':
  15488. case 'FL':
  15489. case 'CA':
  15490. case 'ca':
  15491. gStateObj.push([key, value]);
  15492. break;
  15493. case 'Font':
  15494. promise = promise.then(function () {
  15495. return self.handleSetFont(resources, null, value[0],
  15496. operatorList, stateManager.state).
  15497. then(function (loadedName) {
  15498. operatorList.addDependency(loadedName);
  15499. gStateObj.push([key, [loadedName, value[1]]]);
  15500. });
  15501. });
  15502. break;
  15503. case 'BM':
  15504. gStateObj.push([key, value]);
  15505. break;
  15506. case 'SMask':
  15507. if (isName(value) && value.name === 'None') {
  15508. gStateObj.push([key, false]);
  15509. break;
  15510. }
  15511. var dict = xref.fetchIfRef(value);
  15512. if (isDict(dict)) {
  15513. promise = promise.then(function () {
  15514. return self.handleSMask(dict, resources, operatorList,
  15515. stateManager);
  15516. });
  15517. gStateObj.push([key, true]);
  15518. } else {
  15519. warn('Unsupported SMask type');
  15520. }
  15521. break;
  15522. // Only generate info log messages for the following since
  15523. // they are unlikely to have a big impact on the rendering.
  15524. case 'OP':
  15525. case 'op':
  15526. case 'OPM':
  15527. case 'BG':
  15528. case 'BG2':
  15529. case 'UCR':
  15530. case 'UCR2':
  15531. case 'TR':
  15532. case 'TR2':
  15533. case 'HT':
  15534. case 'SM':
  15535. case 'SA':
  15536. case 'AIS':
  15537. case 'TK':
  15538. // TODO implement these operators.
  15539. info('graphic state operator ' + key);
  15540. break;
  15541. default:
  15542. info('Unknown graphic state operator ' + key);
  15543. break;
  15544. }
  15545. }
  15546. return promise.then(function () {
  15547. if (gStateObj.length >= 0) {
  15548. operatorList.addOp(OPS.setGState, [gStateObj]);
  15549. }
  15550. });
  15551. },
  15552. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  15553. resources) {
  15554. function errorFont() {
  15555. return Promise.resolve(new TranslatedFont('g_font_error',
  15556. new ErrorFont('Font ' + fontName + ' is not available'), font));
  15557. }
  15558. var fontRef;
  15559. if (font) { // Loading by ref.
  15560. assert(isRef(font));
  15561. fontRef = font;
  15562. } else { // Loading by name.
  15563. var fontRes = resources.get('Font');
  15564. if (fontRes) {
  15565. fontRef = fontRes.getRaw(fontName);
  15566. } else {
  15567. warn('fontRes not available');
  15568. return errorFont();
  15569. }
  15570. }
  15571. if (!fontRef) {
  15572. warn('fontRef not available');
  15573. return errorFont();
  15574. }
  15575. if (this.fontCache.has(fontRef)) {
  15576. return this.fontCache.get(fontRef);
  15577. }
  15578. font = xref.fetchIfRef(fontRef);
  15579. if (!isDict(font)) {
  15580. return errorFont();
  15581. }
  15582. // We are holding font.translated references just for fontRef that are not
  15583. // dictionaries (Dict). See explanation below.
  15584. if (font.translated) {
  15585. return font.translated;
  15586. }
  15587. var fontCapability = createPromiseCapability();
  15588. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  15589. var descriptor = preEvaluatedFont.descriptor;
  15590. var fontID = fontRef.num + '_' + fontRef.gen;
  15591. if (isDict(descriptor)) {
  15592. if (!descriptor.fontAliases) {
  15593. descriptor.fontAliases = Object.create(null);
  15594. }
  15595. var fontAliases = descriptor.fontAliases;
  15596. var hash = preEvaluatedFont.hash;
  15597. if (fontAliases[hash]) {
  15598. var aliasFontRef = fontAliases[hash].aliasRef;
  15599. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  15600. this.fontCache.putAlias(fontRef, aliasFontRef);
  15601. return this.fontCache.get(fontRef);
  15602. }
  15603. }
  15604. if (!fontAliases[hash]) {
  15605. fontAliases[hash] = {
  15606. fontID: Font.getFontID()
  15607. };
  15608. }
  15609. fontAliases[hash].aliasRef = fontRef;
  15610. fontID = fontAliases[hash].fontID;
  15611. }
  15612. // Workaround for bad PDF generators that don't reference fonts
  15613. // properly, i.e. by not using an object identifier.
  15614. // Check if the fontRef is a Dict (as opposed to a standard object),
  15615. // in which case we don't cache the font and instead reference it by
  15616. // fontName in font.loadedName below.
  15617. var fontRefIsDict = isDict(fontRef);
  15618. if (!fontRefIsDict) {
  15619. this.fontCache.put(fontRef, fontCapability.promise);
  15620. }
  15621. // Keep track of each font we translated so the caller can
  15622. // load them asynchronously before calling display on a page.
  15623. font.loadedName = 'g_font_' + (fontRefIsDict ?
  15624. fontName.replace(/\W/g, '') : fontID);
  15625. font.translated = fontCapability.promise;
  15626. // TODO move promises into translate font
  15627. var translatedPromise;
  15628. try {
  15629. translatedPromise = Promise.resolve(
  15630. this.translateFont(preEvaluatedFont, xref));
  15631. } catch (e) {
  15632. translatedPromise = Promise.reject(e);
  15633. }
  15634. translatedPromise.then(function (translatedFont) {
  15635. if (translatedFont.fontType !== undefined) {
  15636. var xrefFontStats = xref.stats.fontTypes;
  15637. xrefFontStats[translatedFont.fontType] = true;
  15638. }
  15639. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15640. translatedFont, font));
  15641. }, function (reason) {
  15642. // TODO fontCapability.reject?
  15643. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  15644. try {
  15645. // error, but it's still nice to have font type reported
  15646. var descriptor = preEvaluatedFont.descriptor;
  15647. var fontFile3 = descriptor && descriptor.get('FontFile3');
  15648. var subtype = fontFile3 && fontFile3.get('Subtype');
  15649. var fontType = getFontType(preEvaluatedFont.type,
  15650. subtype && subtype.name);
  15651. var xrefFontStats = xref.stats.fontTypes;
  15652. xrefFontStats[fontType] = true;
  15653. } catch (ex) { }
  15654. fontCapability.resolve(new TranslatedFont(font.loadedName,
  15655. new ErrorFont(reason instanceof Error ? reason.message : reason),
  15656. font));
  15657. });
  15658. return fontCapability.promise;
  15659. },
  15660. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  15661. var lastIndex = operatorList.length - 1;
  15662. if (!args) {
  15663. args = [];
  15664. }
  15665. if (lastIndex < 0 ||
  15666. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  15667. operatorList.addOp(OPS.constructPath, [[fn], args]);
  15668. } else {
  15669. var opArgs = operatorList.argsArray[lastIndex];
  15670. opArgs[0].push(fn);
  15671. Array.prototype.push.apply(opArgs[1], args);
  15672. }
  15673. },
  15674. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  15675. cs, patterns, resources, xref) {
  15676. // compile tiling patterns
  15677. var patternName = args[args.length - 1];
  15678. // SCN/scn applies patterns along with normal colors
  15679. var pattern;
  15680. if (isName(patternName) &&
  15681. (pattern = patterns.get(patternName.name))) {
  15682. var dict = (isStream(pattern) ? pattern.dict : pattern);
  15683. var typeNum = dict.get('PatternType');
  15684. if (typeNum === TILING_PATTERN) {
  15685. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  15686. return this.handleTilingType(fn, color, resources, pattern,
  15687. dict, operatorList);
  15688. } else if (typeNum === SHADING_PATTERN) {
  15689. var shading = dict.get('Shading');
  15690. var matrix = dict.get('Matrix');
  15691. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  15692. operatorList.addOp(fn, pattern.getIR());
  15693. return Promise.resolve();
  15694. } else {
  15695. return Promise.reject('Unknown PatternType: ' + typeNum);
  15696. }
  15697. }
  15698. // TODO shall we fail here?
  15699. operatorList.addOp(fn, args);
  15700. return Promise.resolve();
  15701. },
  15702. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  15703. resources,
  15704. operatorList,
  15705. initialState) {
  15706. var self = this;
  15707. var xref = this.xref;
  15708. var imageCache = {};
  15709. assert(operatorList);
  15710. resources = (resources || Dict.empty);
  15711. var xobjs = (resources.get('XObject') || Dict.empty);
  15712. var patterns = (resources.get('Pattern') || Dict.empty);
  15713. var stateManager = new StateManager(initialState || new EvalState());
  15714. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15715. var timeSlotManager = new TimeSlotManager();
  15716. return new Promise(function next(resolve, reject) {
  15717. timeSlotManager.reset();
  15718. var stop, operation = {}, i, ii, cs;
  15719. while (!(stop = timeSlotManager.check())) {
  15720. // The arguments parsed by read() are used beyond this loop, so we
  15721. // cannot reuse the same array on each iteration. Therefore we pass
  15722. // in |null| as the initial value (see the comment on
  15723. // EvaluatorPreprocessor_read() for why).
  15724. operation.args = null;
  15725. if (!(preprocessor.read(operation))) {
  15726. break;
  15727. }
  15728. var args = operation.args;
  15729. var fn = operation.fn;
  15730. switch (fn | 0) {
  15731. case OPS.paintXObject:
  15732. if (args[0].code) {
  15733. break;
  15734. }
  15735. // eagerly compile XForm objects
  15736. var name = args[0].name;
  15737. if (imageCache[name] !== undefined) {
  15738. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  15739. args = null;
  15740. continue;
  15741. }
  15742. var xobj = xobjs.get(name);
  15743. if (xobj) {
  15744. assert(isStream(xobj), 'XObject should be a stream');
  15745. var type = xobj.dict.get('Subtype');
  15746. assert(isName(type),
  15747. 'XObject should have a Name subtype');
  15748. if (type.name === 'Form') {
  15749. stateManager.save();
  15750. return self.buildFormXObject(resources, xobj, null,
  15751. operatorList,
  15752. stateManager.state.clone()).
  15753. then(function () {
  15754. stateManager.restore();
  15755. next(resolve, reject);
  15756. }, reject);
  15757. } else if (type.name === 'Image') {
  15758. self.buildPaintImageXObject(resources, xobj, false,
  15759. operatorList, name, imageCache);
  15760. args = null;
  15761. continue;
  15762. } else if (type.name === 'PS') {
  15763. // PostScript XObjects are unused when viewing documents.
  15764. // See section 4.7.1 of Adobe's PDF reference.
  15765. info('Ignored XObject subtype PS');
  15766. continue;
  15767. } else {
  15768. error('Unhandled XObject subtype ' + type.name);
  15769. }
  15770. }
  15771. break;
  15772. case OPS.setFont:
  15773. var fontSize = args[1];
  15774. // eagerly collect all fonts
  15775. return self.handleSetFont(resources, args, null,
  15776. operatorList, stateManager.state).
  15777. then(function (loadedName) {
  15778. operatorList.addDependency(loadedName);
  15779. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  15780. next(resolve, reject);
  15781. }, reject);
  15782. case OPS.endInlineImage:
  15783. var cacheKey = args[0].cacheKey;
  15784. if (cacheKey) {
  15785. var cacheEntry = imageCache[cacheKey];
  15786. if (cacheEntry !== undefined) {
  15787. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  15788. args = null;
  15789. continue;
  15790. }
  15791. }
  15792. self.buildPaintImageXObject(resources, args[0], true,
  15793. operatorList, cacheKey, imageCache);
  15794. args = null;
  15795. continue;
  15796. case OPS.showText:
  15797. args[0] = self.handleText(args[0], stateManager.state);
  15798. break;
  15799. case OPS.showSpacedText:
  15800. var arr = args[0];
  15801. var combinedGlyphs = [];
  15802. var arrLength = arr.length;
  15803. for (i = 0; i < arrLength; ++i) {
  15804. var arrItem = arr[i];
  15805. if (isString(arrItem)) {
  15806. Array.prototype.push.apply(combinedGlyphs,
  15807. self.handleText(arrItem, stateManager.state));
  15808. } else if (isNum(arrItem)) {
  15809. combinedGlyphs.push(arrItem);
  15810. }
  15811. }
  15812. args[0] = combinedGlyphs;
  15813. fn = OPS.showText;
  15814. break;
  15815. case OPS.nextLineShowText:
  15816. operatorList.addOp(OPS.nextLine);
  15817. args[0] = self.handleText(args[0], stateManager.state);
  15818. fn = OPS.showText;
  15819. break;
  15820. case OPS.nextLineSetSpacingShowText:
  15821. operatorList.addOp(OPS.nextLine);
  15822. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  15823. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  15824. args[0] = self.handleText(args[0], stateManager.state);
  15825. fn = OPS.showText;
  15826. break;
  15827. case OPS.setTextRenderingMode:
  15828. stateManager.state.textRenderingMode = args[0];
  15829. break;
  15830. case OPS.setFillColorSpace:
  15831. stateManager.state.fillColorSpace =
  15832. ColorSpace.parse(args[0], xref, resources);
  15833. continue;
  15834. case OPS.setStrokeColorSpace:
  15835. stateManager.state.strokeColorSpace =
  15836. ColorSpace.parse(args[0], xref, resources);
  15837. continue;
  15838. case OPS.setFillColor:
  15839. cs = stateManager.state.fillColorSpace;
  15840. args = cs.getRgb(args, 0);
  15841. fn = OPS.setFillRGBColor;
  15842. break;
  15843. case OPS.setStrokeColor:
  15844. cs = stateManager.state.strokeColorSpace;
  15845. args = cs.getRgb(args, 0);
  15846. fn = OPS.setStrokeRGBColor;
  15847. break;
  15848. case OPS.setFillGray:
  15849. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  15850. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15851. fn = OPS.setFillRGBColor;
  15852. break;
  15853. case OPS.setStrokeGray:
  15854. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  15855. args = ColorSpace.singletons.gray.getRgb(args, 0);
  15856. fn = OPS.setStrokeRGBColor;
  15857. break;
  15858. case OPS.setFillCMYKColor:
  15859. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  15860. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15861. fn = OPS.setFillRGBColor;
  15862. break;
  15863. case OPS.setStrokeCMYKColor:
  15864. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  15865. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  15866. fn = OPS.setStrokeRGBColor;
  15867. break;
  15868. case OPS.setFillRGBColor:
  15869. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  15870. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15871. break;
  15872. case OPS.setStrokeRGBColor:
  15873. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  15874. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  15875. break;
  15876. case OPS.setFillColorN:
  15877. cs = stateManager.state.fillColorSpace;
  15878. if (cs.name === 'Pattern') {
  15879. return self.handleColorN(operatorList, OPS.setFillColorN,
  15880. args, cs, patterns, resources, xref).then(function() {
  15881. next(resolve, reject);
  15882. }, reject);
  15883. }
  15884. args = cs.getRgb(args, 0);
  15885. fn = OPS.setFillRGBColor;
  15886. break;
  15887. case OPS.setStrokeColorN:
  15888. cs = stateManager.state.strokeColorSpace;
  15889. if (cs.name === 'Pattern') {
  15890. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  15891. args, cs, patterns, resources, xref).then(function() {
  15892. next(resolve, reject);
  15893. }, reject);
  15894. }
  15895. args = cs.getRgb(args, 0);
  15896. fn = OPS.setStrokeRGBColor;
  15897. break;
  15898. case OPS.shadingFill:
  15899. var shadingRes = resources.get('Shading');
  15900. if (!shadingRes) {
  15901. error('No shading resource found');
  15902. }
  15903. var shading = shadingRes.get(args[0].name);
  15904. if (!shading) {
  15905. error('No shading object found');
  15906. }
  15907. var shadingFill = Pattern.parseShading(shading, null, xref,
  15908. resources);
  15909. var patternIR = shadingFill.getIR();
  15910. args = [patternIR];
  15911. fn = OPS.shadingFill;
  15912. break;
  15913. case OPS.setGState:
  15914. var dictName = args[0];
  15915. var extGState = resources.get('ExtGState');
  15916. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  15917. break;
  15918. }
  15919. var gState = extGState.get(dictName.name);
  15920. return self.setGState(resources, gState, operatorList, xref,
  15921. stateManager).then(function() {
  15922. next(resolve, reject);
  15923. }, reject);
  15924. case OPS.moveTo:
  15925. case OPS.lineTo:
  15926. case OPS.curveTo:
  15927. case OPS.curveTo2:
  15928. case OPS.curveTo3:
  15929. case OPS.closePath:
  15930. self.buildPath(operatorList, fn, args);
  15931. continue;
  15932. case OPS.rectangle:
  15933. self.buildPath(operatorList, fn, args);
  15934. continue;
  15935. }
  15936. operatorList.addOp(fn, args);
  15937. }
  15938. if (stop) {
  15939. deferred.then(function () {
  15940. next(resolve, reject);
  15941. });
  15942. return;
  15943. }
  15944. // Some PDFs don't close all restores inside object/form.
  15945. // Closing those for them.
  15946. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  15947. operatorList.addOp(OPS.restore, []);
  15948. }
  15949. resolve();
  15950. });
  15951. },
  15952. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  15953. stateManager) {
  15954. stateManager = (stateManager || new StateManager(new TextState()));
  15955. var textContent = {
  15956. items: [],
  15957. styles: Object.create(null)
  15958. };
  15959. var bidiTexts = textContent.items;
  15960. var SPACE_FACTOR = 0.35;
  15961. var MULTI_SPACE_FACTOR = 1.5;
  15962. var self = this;
  15963. var xref = this.xref;
  15964. resources = (xref.fetchIfRef(resources) || Dict.empty);
  15965. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  15966. var xobjs = null;
  15967. var xobjsCache = {};
  15968. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  15969. var textState;
  15970. function newTextChunk() {
  15971. var font = textState.font;
  15972. if (!(font.loadedName in textContent.styles)) {
  15973. textContent.styles[font.loadedName] = {
  15974. fontFamily: font.fallbackName,
  15975. ascent: font.ascent,
  15976. descent: font.descent,
  15977. vertical: font.vertical
  15978. };
  15979. }
  15980. return {
  15981. // |str| is initially an array which we push individual chars to, and
  15982. // then runBidi() overwrites it with the final string.
  15983. str: [],
  15984. dir: null,
  15985. width: 0,
  15986. height: 0,
  15987. transform: null,
  15988. fontName: font.loadedName
  15989. };
  15990. }
  15991. function runBidi(textChunk) {
  15992. var str = textChunk.str.join('');
  15993. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  15994. textChunk.str = bidiResult.str;
  15995. textChunk.dir = bidiResult.dir;
  15996. return textChunk;
  15997. }
  15998. function handleSetFont(fontName, fontRef) {
  15999. return self.loadFont(fontName, fontRef, xref, resources).
  16000. then(function (translated) {
  16001. textState.font = translated.font;
  16002. textState.fontMatrix = translated.font.fontMatrix ||
  16003. FONT_IDENTITY_MATRIX;
  16004. });
  16005. }
  16006. function buildTextGeometry(chars, textChunk) {
  16007. var font = textState.font;
  16008. textChunk = textChunk || newTextChunk();
  16009. if (!textChunk.transform) {
  16010. // 9.4.4 Text Space Details
  16011. var tsm = [textState.fontSize * textState.textHScale, 0,
  16012. 0, textState.fontSize,
  16013. 0, textState.textRise];
  16014. var trm = textChunk.transform = Util.transform(textState.ctm,
  16015. Util.transform(textState.textMatrix, tsm));
  16016. if (!font.vertical) {
  16017. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  16018. } else {
  16019. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  16020. }
  16021. }
  16022. var width = 0;
  16023. var height = 0;
  16024. var glyphs = font.charsToGlyphs(chars);
  16025. var defaultVMetrics = font.defaultVMetrics;
  16026. for (var i = 0; i < glyphs.length; i++) {
  16027. var glyph = glyphs[i];
  16028. if (!glyph) { // Previous glyph was a space.
  16029. width += textState.wordSpacing * textState.textHScale;
  16030. continue;
  16031. }
  16032. var vMetricX = null;
  16033. var vMetricY = null;
  16034. var glyphWidth = null;
  16035. if (font.vertical) {
  16036. if (glyph.vmetric) {
  16037. glyphWidth = glyph.vmetric[0];
  16038. vMetricX = glyph.vmetric[1];
  16039. vMetricY = glyph.vmetric[2];
  16040. } else {
  16041. glyphWidth = glyph.width;
  16042. vMetricX = glyph.width * 0.5;
  16043. vMetricY = defaultVMetrics[2];
  16044. }
  16045. } else {
  16046. glyphWidth = glyph.width;
  16047. }
  16048. var glyphUnicode = glyph.unicode;
  16049. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  16050. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  16051. }
  16052. glyphUnicode = reverseIfRtl(glyphUnicode);
  16053. // The following will calculate the x and y of the individual glyphs.
  16054. // if (font.vertical) {
  16055. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  16056. // textState.fontMatrix[0];
  16057. // tsm[5] -= vMetricY * textState.fontSize *
  16058. // textState.fontMatrix[0];
  16059. // }
  16060. // var trm = Util.transform(textState.textMatrix, tsm);
  16061. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  16062. // var x = pt[0];
  16063. // var y = pt[1];
  16064. var tx = 0;
  16065. var ty = 0;
  16066. if (!font.vertical) {
  16067. var w0 = glyphWidth * textState.fontMatrix[0];
  16068. tx = (w0 * textState.fontSize + textState.charSpacing) *
  16069. textState.textHScale;
  16070. width += tx;
  16071. } else {
  16072. var w1 = glyphWidth * textState.fontMatrix[0];
  16073. ty = w1 * textState.fontSize + textState.charSpacing;
  16074. height += ty;
  16075. }
  16076. textState.translateTextMatrix(tx, ty);
  16077. textChunk.str.push(glyphUnicode);
  16078. }
  16079. var a = textState.textLineMatrix[0];
  16080. var b = textState.textLineMatrix[1];
  16081. var scaleLineX = Math.sqrt(a * a + b * b);
  16082. a = textState.ctm[0];
  16083. b = textState.ctm[1];
  16084. var scaleCtmX = Math.sqrt(a * a + b * b);
  16085. if (!font.vertical) {
  16086. textChunk.width += width * scaleCtmX * scaleLineX;
  16087. } else {
  16088. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  16089. }
  16090. return textChunk;
  16091. }
  16092. var timeSlotManager = new TimeSlotManager();
  16093. return new Promise(function next(resolve, reject) {
  16094. timeSlotManager.reset();
  16095. var stop, operation = {}, args = [];
  16096. while (!(stop = timeSlotManager.check())) {
  16097. // The arguments parsed by read() are not used beyond this loop, so
  16098. // we can reuse the same array on every iteration, thus avoiding
  16099. // unnecessary allocations.
  16100. args.length = 0;
  16101. operation.args = args;
  16102. if (!(preprocessor.read(operation))) {
  16103. break;
  16104. }
  16105. textState = stateManager.state;
  16106. var fn = operation.fn;
  16107. args = operation.args;
  16108. switch (fn | 0) {
  16109. case OPS.setFont:
  16110. textState.fontSize = args[1];
  16111. return handleSetFont(args[0].name).then(function() {
  16112. next(resolve, reject);
  16113. }, reject);
  16114. case OPS.setTextRise:
  16115. textState.textRise = args[0];
  16116. break;
  16117. case OPS.setHScale:
  16118. textState.textHScale = args[0] / 100;
  16119. break;
  16120. case OPS.setLeading:
  16121. textState.leading = args[0];
  16122. break;
  16123. case OPS.moveText:
  16124. textState.translateTextLineMatrix(args[0], args[1]);
  16125. textState.textMatrix = textState.textLineMatrix.slice();
  16126. break;
  16127. case OPS.setLeadingMoveText:
  16128. textState.leading = -args[1];
  16129. textState.translateTextLineMatrix(args[0], args[1]);
  16130. textState.textMatrix = textState.textLineMatrix.slice();
  16131. break;
  16132. case OPS.nextLine:
  16133. textState.carriageReturn();
  16134. break;
  16135. case OPS.setTextMatrix:
  16136. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  16137. args[4], args[5]);
  16138. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  16139. args[4], args[5]);
  16140. break;
  16141. case OPS.setCharSpacing:
  16142. textState.charSpacing = args[0];
  16143. break;
  16144. case OPS.setWordSpacing:
  16145. textState.wordSpacing = args[0];
  16146. break;
  16147. case OPS.beginText:
  16148. textState.textMatrix = IDENTITY_MATRIX.slice();
  16149. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  16150. break;
  16151. case OPS.showSpacedText:
  16152. var items = args[0];
  16153. var textChunk = newTextChunk();
  16154. var offset;
  16155. for (var j = 0, jj = items.length; j < jj; j++) {
  16156. if (typeof items[j] === 'string') {
  16157. buildTextGeometry(items[j], textChunk);
  16158. } else {
  16159. var val = items[j] / 1000;
  16160. if (!textState.font.vertical) {
  16161. offset = -val * textState.fontSize * textState.textHScale *
  16162. textState.textMatrix[0];
  16163. textState.translateTextMatrix(offset, 0);
  16164. textChunk.width += offset;
  16165. } else {
  16166. offset = -val * textState.fontSize *
  16167. textState.textMatrix[3];
  16168. textState.translateTextMatrix(0, offset);
  16169. textChunk.height += offset;
  16170. }
  16171. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  16172. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  16173. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  16174. fakeSpaces = Math.round(fakeSpaces);
  16175. while (fakeSpaces--) {
  16176. textChunk.str.push(' ');
  16177. }
  16178. } else if (fakeSpaces > SPACE_FACTOR) {
  16179. textChunk.str.push(' ');
  16180. }
  16181. }
  16182. }
  16183. }
  16184. bidiTexts.push(runBidi(textChunk));
  16185. break;
  16186. case OPS.showText:
  16187. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16188. break;
  16189. case OPS.nextLineShowText:
  16190. textState.carriageReturn();
  16191. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  16192. break;
  16193. case OPS.nextLineSetSpacingShowText:
  16194. textState.wordSpacing = args[0];
  16195. textState.charSpacing = args[1];
  16196. textState.carriageReturn();
  16197. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  16198. break;
  16199. case OPS.paintXObject:
  16200. if (args[0].code) {
  16201. break;
  16202. }
  16203. if (!xobjs) {
  16204. xobjs = (resources.get('XObject') || Dict.empty);
  16205. }
  16206. var name = args[0].name;
  16207. if (xobjsCache.key === name) {
  16208. if (xobjsCache.texts) {
  16209. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  16210. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  16211. }
  16212. break;
  16213. }
  16214. var xobj = xobjs.get(name);
  16215. if (!xobj) {
  16216. break;
  16217. }
  16218. assert(isStream(xobj), 'XObject should be a stream');
  16219. var type = xobj.dict.get('Subtype');
  16220. assert(isName(type),
  16221. 'XObject should have a Name subtype');
  16222. if ('Form' !== type.name) {
  16223. xobjsCache.key = name;
  16224. xobjsCache.texts = null;
  16225. break;
  16226. }
  16227. stateManager.save();
  16228. var matrix = xobj.dict.get('Matrix');
  16229. if (isArray(matrix) && matrix.length === 6) {
  16230. stateManager.transform(matrix);
  16231. }
  16232. return self.getTextContent(xobj,
  16233. xobj.dict.get('Resources') || resources, stateManager).
  16234. then(function (formTextContent) {
  16235. Util.appendToArray(bidiTexts, formTextContent.items);
  16236. Util.extendObj(textContent.styles, formTextContent.styles);
  16237. stateManager.restore();
  16238. xobjsCache.key = name;
  16239. xobjsCache.texts = formTextContent;
  16240. next(resolve, reject);
  16241. }, reject);
  16242. case OPS.setGState:
  16243. var dictName = args[0];
  16244. var extGState = resources.get('ExtGState');
  16245. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  16246. break;
  16247. }
  16248. var gsStateMap = extGState.get(dictName.name);
  16249. var gsStateFont = null;
  16250. for (var key in gsStateMap) {
  16251. if (key === 'Font') {
  16252. assert(!gsStateFont);
  16253. gsStateFont = gsStateMap[key];
  16254. }
  16255. }
  16256. if (gsStateFont) {
  16257. textState.fontSize = gsStateFont[1];
  16258. return handleSetFont(gsStateFont[0]).then(function() {
  16259. next(resolve, reject);
  16260. }, reject);
  16261. }
  16262. break;
  16263. } // switch
  16264. } // while
  16265. if (stop) {
  16266. deferred.then(function () {
  16267. next(resolve, reject);
  16268. });
  16269. return;
  16270. }
  16271. resolve(textContent);
  16272. });
  16273. },
  16274. extractDataStructures: function
  16275. partialEvaluatorExtractDataStructures(dict, baseDict,
  16276. xref, properties) {
  16277. // 9.10.2
  16278. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  16279. if (toUnicode) {
  16280. properties.toUnicode = this.readToUnicode(toUnicode);
  16281. }
  16282. if (properties.composite) {
  16283. // CIDSystemInfo helps to match CID to glyphs
  16284. var cidSystemInfo = dict.get('CIDSystemInfo');
  16285. if (isDict(cidSystemInfo)) {
  16286. properties.cidSystemInfo = {
  16287. registry: cidSystemInfo.get('Registry'),
  16288. ordering: cidSystemInfo.get('Ordering'),
  16289. supplement: cidSystemInfo.get('Supplement')
  16290. };
  16291. }
  16292. var cidToGidMap = dict.get('CIDToGIDMap');
  16293. if (isStream(cidToGidMap)) {
  16294. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  16295. }
  16296. }
  16297. // Based on 9.6.6 of the spec the encoding can come from multiple places
  16298. // and depends on the font type. The base encoding and differences are
  16299. // read here, but the encoding that is actually used is chosen during
  16300. // glyph mapping in the font.
  16301. // TODO: Loading the built in encoding in the font would allow the
  16302. // differences to be merged in here not require us to hold on to it.
  16303. var differences = [];
  16304. var baseEncodingName = null;
  16305. var encoding;
  16306. if (dict.has('Encoding')) {
  16307. encoding = dict.get('Encoding');
  16308. if (isDict(encoding)) {
  16309. baseEncodingName = encoding.get('BaseEncoding');
  16310. baseEncodingName = (isName(baseEncodingName) ?
  16311. baseEncodingName.name : null);
  16312. // Load the differences between the base and original
  16313. if (encoding.has('Differences')) {
  16314. var diffEncoding = encoding.get('Differences');
  16315. var index = 0;
  16316. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  16317. var data = diffEncoding[j];
  16318. if (isNum(data)) {
  16319. index = data;
  16320. } else {
  16321. differences[index++] = data.name;
  16322. }
  16323. }
  16324. }
  16325. } else if (isName(encoding)) {
  16326. baseEncodingName = encoding.name;
  16327. } else {
  16328. error('Encoding is not a Name nor a Dict');
  16329. }
  16330. // According to table 114 if the encoding is a named encoding it must be
  16331. // one of these predefined encodings.
  16332. if ((baseEncodingName !== 'MacRomanEncoding' &&
  16333. baseEncodingName !== 'MacExpertEncoding' &&
  16334. baseEncodingName !== 'WinAnsiEncoding')) {
  16335. baseEncodingName = null;
  16336. }
  16337. }
  16338. if (baseEncodingName) {
  16339. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  16340. } else {
  16341. encoding = (properties.type === 'TrueType' ?
  16342. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  16343. // The Symbolic attribute can be misused for regular fonts
  16344. // Heuristic: we have to check if the font is a standard one also
  16345. if (!!(properties.flags & FontFlags.Symbolic)) {
  16346. encoding = Encodings.MacRomanEncoding;
  16347. if (!properties.file) {
  16348. if (/Symbol/i.test(properties.name)) {
  16349. encoding = Encodings.SymbolSetEncoding;
  16350. } else if (/Dingbats/i.test(properties.name)) {
  16351. encoding = Encodings.ZapfDingbatsEncoding;
  16352. }
  16353. }
  16354. }
  16355. properties.defaultEncoding = encoding;
  16356. }
  16357. properties.differences = differences;
  16358. properties.baseEncodingName = baseEncodingName;
  16359. properties.dict = dict;
  16360. },
  16361. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  16362. var cmap, cmapObj = toUnicode;
  16363. if (isName(cmapObj)) {
  16364. cmap = CMapFactory.create(cmapObj,
  16365. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16366. return new ToUnicodeMap(cmap);
  16367. } else if (isStream(cmapObj)) {
  16368. cmap = CMapFactory.create(cmapObj,
  16369. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  16370. // Convert UTF-16BE
  16371. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  16372. // to iterate over all keys.
  16373. cmap.forEach(function(token, i) {
  16374. var str = [];
  16375. for (var k = 0; k < token.length; k += 2) {
  16376. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16377. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  16378. str.push(w1);
  16379. continue;
  16380. }
  16381. k += 2;
  16382. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  16383. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  16384. }
  16385. cmap[i] = String.fromCharCode.apply(String, str);
  16386. });
  16387. return new ToUnicodeMap(cmap);
  16388. }
  16389. return null;
  16390. },
  16391. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  16392. // Extract the encoding from the CIDToGIDMap
  16393. var glyphsData = cidToGidStream.getBytes();
  16394. // Set encoding 0 to later verify the font has an encoding
  16395. var result = [];
  16396. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  16397. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  16398. if (glyphID === 0) {
  16399. continue;
  16400. }
  16401. var code = j >> 1;
  16402. result[code] = glyphID;
  16403. }
  16404. return result;
  16405. },
  16406. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  16407. descriptor,
  16408. properties) {
  16409. var glyphsWidths = [];
  16410. var defaultWidth = 0;
  16411. var glyphsVMetrics = [];
  16412. var defaultVMetrics;
  16413. var i, ii, j, jj, start, code, widths;
  16414. if (properties.composite) {
  16415. defaultWidth = dict.get('DW') || 1000;
  16416. widths = dict.get('W');
  16417. if (widths) {
  16418. for (i = 0, ii = widths.length; i < ii; i++) {
  16419. start = widths[i++];
  16420. code = xref.fetchIfRef(widths[i]);
  16421. if (isArray(code)) {
  16422. for (j = 0, jj = code.length; j < jj; j++) {
  16423. glyphsWidths[start++] = code[j];
  16424. }
  16425. } else {
  16426. var width = widths[++i];
  16427. for (j = start; j <= code; j++) {
  16428. glyphsWidths[j] = width;
  16429. }
  16430. }
  16431. }
  16432. }
  16433. if (properties.vertical) {
  16434. var vmetrics = (dict.get('DW2') || [880, -1000]);
  16435. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  16436. vmetrics = dict.get('W2');
  16437. if (vmetrics) {
  16438. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  16439. start = vmetrics[i++];
  16440. code = xref.fetchIfRef(vmetrics[i]);
  16441. if (isArray(code)) {
  16442. for (j = 0, jj = code.length; j < jj; j++) {
  16443. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  16444. }
  16445. } else {
  16446. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  16447. for (j = start; j <= code; j++) {
  16448. glyphsVMetrics[j] = vmetric;
  16449. }
  16450. }
  16451. }
  16452. }
  16453. }
  16454. } else {
  16455. var firstChar = properties.firstChar;
  16456. widths = dict.get('Widths');
  16457. if (widths) {
  16458. j = firstChar;
  16459. for (i = 0, ii = widths.length; i < ii; i++) {
  16460. glyphsWidths[j++] = widths[i];
  16461. }
  16462. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  16463. } else {
  16464. // Trying get the BaseFont metrics (see comment above).
  16465. var baseFontName = dict.get('BaseFont');
  16466. if (isName(baseFontName)) {
  16467. var metrics = this.getBaseFontMetrics(baseFontName.name);
  16468. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  16469. properties);
  16470. defaultWidth = metrics.defaultWidth;
  16471. }
  16472. }
  16473. }
  16474. // Heuristic: detection of monospace font by checking all non-zero widths
  16475. var isMonospace = true;
  16476. var firstWidth = defaultWidth;
  16477. for (var glyph in glyphsWidths) {
  16478. var glyphWidth = glyphsWidths[glyph];
  16479. if (!glyphWidth) {
  16480. continue;
  16481. }
  16482. if (!firstWidth) {
  16483. firstWidth = glyphWidth;
  16484. continue;
  16485. }
  16486. if (firstWidth !== glyphWidth) {
  16487. isMonospace = false;
  16488. break;
  16489. }
  16490. }
  16491. if (isMonospace) {
  16492. properties.flags |= FontFlags.FixedPitch;
  16493. }
  16494. properties.defaultWidth = defaultWidth;
  16495. properties.widths = glyphsWidths;
  16496. properties.defaultVMetrics = defaultVMetrics;
  16497. properties.vmetrics = glyphsVMetrics;
  16498. },
  16499. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  16500. // Simulating descriptor flags attribute
  16501. var fontNameWoStyle = baseFontName.split('-')[0];
  16502. return (fontNameWoStyle in serifFonts) ||
  16503. (fontNameWoStyle.search(/serif/gi) !== -1);
  16504. },
  16505. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  16506. var defaultWidth = 0;
  16507. var widths = [];
  16508. var monospace = false;
  16509. var lookupName = (stdFontMap[name] || name);
  16510. if (!(lookupName in Metrics)) {
  16511. // Use default fonts for looking up font metrics if the passed
  16512. // font is not a base font
  16513. if (this.isSerifFont(name)) {
  16514. lookupName = 'Times-Roman';
  16515. } else {
  16516. lookupName = 'Helvetica';
  16517. }
  16518. }
  16519. var glyphWidths = Metrics[lookupName];
  16520. if (isNum(glyphWidths)) {
  16521. defaultWidth = glyphWidths;
  16522. monospace = true;
  16523. } else {
  16524. widths = glyphWidths;
  16525. }
  16526. return {
  16527. defaultWidth: defaultWidth,
  16528. monospace: monospace,
  16529. widths: widths
  16530. };
  16531. },
  16532. buildCharCodeToWidth:
  16533. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  16534. properties) {
  16535. var widths = Object.create(null);
  16536. var differences = properties.differences;
  16537. var encoding = properties.defaultEncoding;
  16538. for (var charCode = 0; charCode < 256; charCode++) {
  16539. if (charCode in differences &&
  16540. widthsByGlyphName[differences[charCode]]) {
  16541. widths[charCode] = widthsByGlyphName[differences[charCode]];
  16542. continue;
  16543. }
  16544. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  16545. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  16546. continue;
  16547. }
  16548. }
  16549. return widths;
  16550. },
  16551. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  16552. var baseDict = dict;
  16553. var type = dict.get('Subtype');
  16554. assert(isName(type), 'invalid font Subtype');
  16555. var composite = false;
  16556. var uint8array;
  16557. if (type.name === 'Type0') {
  16558. // If font is a composite
  16559. // - get the descendant font
  16560. // - set the type according to the descendant font
  16561. // - get the FontDescriptor from the descendant font
  16562. var df = dict.get('DescendantFonts');
  16563. if (!df) {
  16564. error('Descendant fonts are not specified');
  16565. }
  16566. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  16567. type = dict.get('Subtype');
  16568. assert(isName(type), 'invalid font Subtype');
  16569. composite = true;
  16570. }
  16571. var descriptor = dict.get('FontDescriptor');
  16572. if (descriptor) {
  16573. var hash = new MurmurHash3_64();
  16574. var encoding = baseDict.getRaw('Encoding');
  16575. if (isName(encoding)) {
  16576. hash.update(encoding.name);
  16577. } else if (isRef(encoding)) {
  16578. hash.update(encoding.num + '_' + encoding.gen);
  16579. }
  16580. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  16581. if (isStream(toUnicode)) {
  16582. var stream = toUnicode.str || toUnicode;
  16583. uint8array = stream.buffer ?
  16584. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  16585. new Uint8Array(stream.bytes.buffer,
  16586. stream.start, stream.end - stream.start);
  16587. hash.update(uint8array);
  16588. } else if (isName(toUnicode)) {
  16589. hash.update(toUnicode.name);
  16590. }
  16591. var widths = dict.get('Widths') || baseDict.get('Widths');
  16592. if (widths) {
  16593. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  16594. hash.update(uint8array);
  16595. }
  16596. }
  16597. return {
  16598. descriptor: descriptor,
  16599. dict: dict,
  16600. baseDict: baseDict,
  16601. composite: composite,
  16602. type: type.name,
  16603. hash: hash ? hash.hexdigest() : ''
  16604. };
  16605. },
  16606. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  16607. xref) {
  16608. var baseDict = preEvaluatedFont.baseDict;
  16609. var dict = preEvaluatedFont.dict;
  16610. var composite = preEvaluatedFont.composite;
  16611. var descriptor = preEvaluatedFont.descriptor;
  16612. var type = preEvaluatedFont.type;
  16613. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  16614. var properties;
  16615. if (!descriptor) {
  16616. if (type === 'Type3') {
  16617. // FontDescriptor is only required for Type3 fonts when the document
  16618. // is a tagged pdf. Create a barbebones one to get by.
  16619. descriptor = new Dict(null);
  16620. descriptor.set('FontName', Name.get(type));
  16621. } else {
  16622. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  16623. // FontDescriptor was not required.
  16624. // This case is here for compatibility.
  16625. var baseFontName = dict.get('BaseFont');
  16626. if (!isName(baseFontName)) {
  16627. error('Base font is not specified');
  16628. }
  16629. // Using base font name as a font name.
  16630. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  16631. var metrics = this.getBaseFontMetrics(baseFontName);
  16632. // Simulating descriptor flags attribute
  16633. var fontNameWoStyle = baseFontName.split('-')[0];
  16634. var flags =
  16635. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  16636. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  16637. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  16638. FontFlags.Nonsymbolic);
  16639. properties = {
  16640. type: type,
  16641. name: baseFontName,
  16642. widths: metrics.widths,
  16643. defaultWidth: metrics.defaultWidth,
  16644. flags: flags,
  16645. firstChar: 0,
  16646. lastChar: maxCharIndex
  16647. };
  16648. this.extractDataStructures(dict, dict, xref, properties);
  16649. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  16650. properties);
  16651. return new Font(baseFontName, null, properties);
  16652. }
  16653. }
  16654. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  16655. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  16656. // to ignore this rule when a variant of a standart font is used.
  16657. // TODO Fill the width array depending on which of the base font this is
  16658. // a variant.
  16659. var firstChar = (dict.get('FirstChar') || 0);
  16660. var lastChar = (dict.get('LastChar') || maxCharIndex);
  16661. var fontName = descriptor.get('FontName');
  16662. var baseFont = dict.get('BaseFont');
  16663. // Some bad PDFs have a string as the font name.
  16664. if (isString(fontName)) {
  16665. fontName = Name.get(fontName);
  16666. }
  16667. if (isString(baseFont)) {
  16668. baseFont = Name.get(baseFont);
  16669. }
  16670. if (type !== 'Type3') {
  16671. var fontNameStr = fontName && fontName.name;
  16672. var baseFontStr = baseFont && baseFont.name;
  16673. if (fontNameStr !== baseFontStr) {
  16674. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  16675. '" but should be the same as the Font\'s BaseFont "' +
  16676. baseFontStr + '"');
  16677. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  16678. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  16679. if (fontNameStr && baseFontStr &&
  16680. baseFontStr.indexOf(fontNameStr) === 0) {
  16681. fontName = baseFont;
  16682. }
  16683. }
  16684. }
  16685. fontName = (fontName || baseFont);
  16686. assert(isName(fontName), 'invalid font name');
  16687. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  16688. if (fontFile) {
  16689. if (fontFile.dict) {
  16690. var subtype = fontFile.dict.get('Subtype');
  16691. if (subtype) {
  16692. subtype = subtype.name;
  16693. }
  16694. var length1 = fontFile.dict.get('Length1');
  16695. var length2 = fontFile.dict.get('Length2');
  16696. }
  16697. }
  16698. properties = {
  16699. type: type,
  16700. name: fontName.name,
  16701. subtype: subtype,
  16702. file: fontFile,
  16703. length1: length1,
  16704. length2: length2,
  16705. loadedName: baseDict.loadedName,
  16706. composite: composite,
  16707. wideChars: composite,
  16708. fixedPitch: false,
  16709. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  16710. firstChar: firstChar || 0,
  16711. lastChar: (lastChar || maxCharIndex),
  16712. bbox: descriptor.get('FontBBox'),
  16713. ascent: descriptor.get('Ascent'),
  16714. descent: descriptor.get('Descent'),
  16715. xHeight: descriptor.get('XHeight'),
  16716. capHeight: descriptor.get('CapHeight'),
  16717. flags: descriptor.get('Flags'),
  16718. italicAngle: descriptor.get('ItalicAngle'),
  16719. coded: false
  16720. };
  16721. if (composite) {
  16722. var cidEncoding = baseDict.get('Encoding');
  16723. if (isName(cidEncoding)) {
  16724. properties.cidEncoding = cidEncoding.name;
  16725. }
  16726. properties.cMap = CMapFactory.create(cidEncoding,
  16727. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16728. properties.vertical = properties.cMap.vertical;
  16729. }
  16730. this.extractDataStructures(dict, baseDict, xref, properties);
  16731. this.extractWidths(dict, xref, descriptor, properties);
  16732. if (type === 'Type3') {
  16733. properties.isType3Font = true;
  16734. }
  16735. return new Font(fontName.name, fontFile, properties);
  16736. }
  16737. };
  16738. return PartialEvaluator;
  16739. })();
  16740. var TranslatedFont = (function TranslatedFontClosure() {
  16741. function TranslatedFont(loadedName, font, dict) {
  16742. this.loadedName = loadedName;
  16743. this.font = font;
  16744. this.dict = dict;
  16745. this.type3Loaded = null;
  16746. this.sent = false;
  16747. }
  16748. TranslatedFont.prototype = {
  16749. send: function (handler) {
  16750. if (this.sent) {
  16751. return;
  16752. }
  16753. var fontData = this.font.exportData();
  16754. handler.send('commonobj', [
  16755. this.loadedName,
  16756. 'Font',
  16757. fontData
  16758. ]);
  16759. this.sent = true;
  16760. },
  16761. loadType3Data: function (evaluator, resources, parentOperatorList) {
  16762. assert(this.font.isType3Font);
  16763. if (this.type3Loaded) {
  16764. return this.type3Loaded;
  16765. }
  16766. var translatedFont = this.font;
  16767. var loadCharProcsPromise = Promise.resolve();
  16768. var charProcs = this.dict.get('CharProcs').getAll();
  16769. var fontResources = this.dict.get('Resources') || resources;
  16770. var charProcKeys = Object.keys(charProcs);
  16771. var charProcOperatorList = {};
  16772. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  16773. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  16774. var glyphStream = charProcs[key];
  16775. var operatorList = new OperatorList();
  16776. return evaluator.getOperatorList(glyphStream, fontResources,
  16777. operatorList).then(function () {
  16778. charProcOperatorList[key] = operatorList.getIR();
  16779. // Add the dependencies to the parent operator list so they are
  16780. // resolved before sub operator list is executed synchronously.
  16781. parentOperatorList.addDependencies(operatorList.dependencies);
  16782. }, function (reason) {
  16783. warn('Type3 font resource \"' + key + '\" is not available');
  16784. var operatorList = new OperatorList();
  16785. charProcOperatorList[key] = operatorList.getIR();
  16786. });
  16787. }.bind(this, charProcKeys[i]));
  16788. }
  16789. this.type3Loaded = loadCharProcsPromise.then(function () {
  16790. translatedFont.charProcOperatorList = charProcOperatorList;
  16791. });
  16792. return this.type3Loaded;
  16793. }
  16794. };
  16795. return TranslatedFont;
  16796. })();
  16797. var OperatorList = (function OperatorListClosure() {
  16798. var CHUNK_SIZE = 1000;
  16799. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  16800. function getTransfers(queue) {
  16801. var transfers = [];
  16802. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  16803. for (var i = 0, ii = queue.length; i < ii; i++) {
  16804. switch (fnArray[i]) {
  16805. case OPS.paintInlineImageXObject:
  16806. case OPS.paintInlineImageXObjectGroup:
  16807. case OPS.paintImageMaskXObject:
  16808. var arg = argsArray[i][0]; // first param in imgData
  16809. if (!arg.cached) {
  16810. transfers.push(arg.data.buffer);
  16811. }
  16812. break;
  16813. }
  16814. }
  16815. return transfers;
  16816. }
  16817. function OperatorList(intent, messageHandler, pageIndex) {
  16818. this.messageHandler = messageHandler;
  16819. this.fnArray = [];
  16820. this.argsArray = [];
  16821. this.dependencies = {};
  16822. this.pageIndex = pageIndex;
  16823. this.intent = intent;
  16824. }
  16825. OperatorList.prototype = {
  16826. get length() {
  16827. return this.argsArray.length;
  16828. },
  16829. addOp: function(fn, args) {
  16830. this.fnArray.push(fn);
  16831. this.argsArray.push(args);
  16832. if (this.messageHandler) {
  16833. if (this.fnArray.length >= CHUNK_SIZE) {
  16834. this.flush();
  16835. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  16836. (fn === OPS.restore || fn === OPS.endText)) {
  16837. // heuristic to flush on boundary of restore or endText
  16838. this.flush();
  16839. }
  16840. }
  16841. },
  16842. addDependency: function(dependency) {
  16843. if (dependency in this.dependencies) {
  16844. return;
  16845. }
  16846. this.dependencies[dependency] = true;
  16847. this.addOp(OPS.dependency, [dependency]);
  16848. },
  16849. addDependencies: function(dependencies) {
  16850. for (var key in dependencies) {
  16851. this.addDependency(key);
  16852. }
  16853. },
  16854. addOpList: function(opList) {
  16855. Util.extendObj(this.dependencies, opList.dependencies);
  16856. for (var i = 0, ii = opList.length; i < ii; i++) {
  16857. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  16858. }
  16859. },
  16860. getIR: function() {
  16861. return {
  16862. fnArray: this.fnArray,
  16863. argsArray: this.argsArray,
  16864. length: this.length
  16865. };
  16866. },
  16867. flush: function(lastChunk) {
  16868. if (this.intent !== 'oplist') {
  16869. new QueueOptimizer().optimize(this);
  16870. }
  16871. var transfers = getTransfers(this);
  16872. this.messageHandler.send('RenderPageChunk', {
  16873. operatorList: {
  16874. fnArray: this.fnArray,
  16875. argsArray: this.argsArray,
  16876. lastChunk: lastChunk,
  16877. length: this.length
  16878. },
  16879. pageIndex: this.pageIndex,
  16880. intent: this.intent
  16881. }, transfers);
  16882. this.dependencies = {};
  16883. this.fnArray.length = 0;
  16884. this.argsArray.length = 0;
  16885. }
  16886. };
  16887. return OperatorList;
  16888. })();
  16889. var StateManager = (function StateManagerClosure() {
  16890. function StateManager(initialState) {
  16891. this.state = initialState;
  16892. this.stateStack = [];
  16893. }
  16894. StateManager.prototype = {
  16895. save: function () {
  16896. var old = this.state;
  16897. this.stateStack.push(this.state);
  16898. this.state = old.clone();
  16899. },
  16900. restore: function () {
  16901. var prev = this.stateStack.pop();
  16902. if (prev) {
  16903. this.state = prev;
  16904. }
  16905. },
  16906. transform: function (args) {
  16907. this.state.ctm = Util.transform(this.state.ctm, args);
  16908. }
  16909. };
  16910. return StateManager;
  16911. })();
  16912. var TextState = (function TextStateClosure() {
  16913. function TextState() {
  16914. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16915. this.fontSize = 0;
  16916. this.font = null;
  16917. this.fontMatrix = FONT_IDENTITY_MATRIX;
  16918. this.textMatrix = IDENTITY_MATRIX.slice();
  16919. this.textLineMatrix = IDENTITY_MATRIX.slice();
  16920. this.charSpacing = 0;
  16921. this.wordSpacing = 0;
  16922. this.leading = 0;
  16923. this.textHScale = 1;
  16924. this.textRise = 0;
  16925. }
  16926. TextState.prototype = {
  16927. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16928. var m = this.textMatrix;
  16929. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16930. },
  16931. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  16932. var m = this.textLineMatrix;
  16933. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  16934. },
  16935. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  16936. var m = this.textMatrix;
  16937. m[4] = m[0] * x + m[2] * y + m[4];
  16938. m[5] = m[1] * x + m[3] * y + m[5];
  16939. },
  16940. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  16941. var m = this.textLineMatrix;
  16942. m[4] = m[0] * x + m[2] * y + m[4];
  16943. m[5] = m[1] * x + m[3] * y + m[5];
  16944. },
  16945. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  16946. // 9.4.4 Text Space Details
  16947. var tsm = [this.fontSize * this.textHScale, 0,
  16948. 0, this.fontSize,
  16949. 0, this.textRise];
  16950. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  16951. },
  16952. carriageReturn: function TextState_carriageReturn() {
  16953. this.translateTextLineMatrix(0, -this.leading);
  16954. this.textMatrix = this.textLineMatrix.slice();
  16955. },
  16956. clone: function TextState_clone() {
  16957. var clone = Object.create(this);
  16958. clone.textMatrix = this.textMatrix.slice();
  16959. clone.textLineMatrix = this.textLineMatrix.slice();
  16960. clone.fontMatrix = this.fontMatrix.slice();
  16961. return clone;
  16962. }
  16963. };
  16964. return TextState;
  16965. })();
  16966. var EvalState = (function EvalStateClosure() {
  16967. function EvalState() {
  16968. this.ctm = new Float32Array(IDENTITY_MATRIX);
  16969. this.font = null;
  16970. this.textRenderingMode = TextRenderingMode.FILL;
  16971. this.fillColorSpace = ColorSpace.singletons.gray;
  16972. this.strokeColorSpace = ColorSpace.singletons.gray;
  16973. }
  16974. EvalState.prototype = {
  16975. clone: function CanvasExtraState_clone() {
  16976. return Object.create(this);
  16977. },
  16978. };
  16979. return EvalState;
  16980. })();
  16981. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  16982. // Specifies properties for each command
  16983. //
  16984. // If variableArgs === true: [0, `numArgs`] expected
  16985. // If variableArgs === false: exactly `numArgs` expected
  16986. var OP_MAP = {
  16987. // Graphic state
  16988. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  16989. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  16990. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  16991. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  16992. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  16993. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  16994. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  16995. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  16996. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  16997. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  16998. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  16999. // Path
  17000. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  17001. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  17002. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  17003. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  17004. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  17005. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  17006. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  17007. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  17008. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  17009. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17010. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17011. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  17012. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  17013. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  17014. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  17015. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  17016. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  17017. // Clipping
  17018. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  17019. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  17020. // Text
  17021. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  17022. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  17023. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  17024. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  17025. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  17026. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  17027. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  17028. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  17029. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  17030. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  17031. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  17032. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  17033. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  17034. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  17035. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  17036. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  17037. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  17038. variableArgs: false },
  17039. // Type3 fonts
  17040. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  17041. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  17042. // Color
  17043. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  17044. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  17045. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  17046. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  17047. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  17048. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  17049. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  17050. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  17051. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  17052. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  17053. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  17054. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  17055. // Shading
  17056. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  17057. // Images
  17058. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  17059. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  17060. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  17061. // XObjects
  17062. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  17063. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  17064. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  17065. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  17066. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  17067. variableArgs: false },
  17068. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  17069. // Compatibility
  17070. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  17071. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  17072. // (reserved partial commands for the lexer)
  17073. BM: null,
  17074. BD: null,
  17075. 'true': null,
  17076. fa: null,
  17077. fal: null,
  17078. fals: null,
  17079. 'false': null,
  17080. nu: null,
  17081. nul: null,
  17082. 'null': null
  17083. };
  17084. function EvaluatorPreprocessor(stream, xref, stateManager) {
  17085. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  17086. // dictionary
  17087. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  17088. this.stateManager = stateManager;
  17089. this.nonProcessedArgs = [];
  17090. }
  17091. EvaluatorPreprocessor.prototype = {
  17092. get savedStatesDepth() {
  17093. return this.stateManager.stateStack.length;
  17094. },
  17095. // |operation| is an object with two fields:
  17096. //
  17097. // - |fn| is an out param.
  17098. //
  17099. // - |args| is an inout param. On entry, it should have one of two values.
  17100. //
  17101. // - An empty array. This indicates that the caller is providing the
  17102. // array in which the args will be stored in. The caller should use
  17103. // this value if it can reuse a single array for each call to read().
  17104. //
  17105. // - |null|. This indicates that the caller needs this function to create
  17106. // the array in which any args are stored in. If there are zero args,
  17107. // this function will leave |operation.args| as |null| (thus avoiding
  17108. // allocations that would occur if we used an empty array to represent
  17109. // zero arguments). Otherwise, it will replace |null| with a new array
  17110. // containing the arguments. The caller should use this value if it
  17111. // cannot reuse an array for each call to read().
  17112. //
  17113. // These two modes are present because this function is very hot and so
  17114. // avoiding allocations where possible is worthwhile.
  17115. //
  17116. read: function EvaluatorPreprocessor_read(operation) {
  17117. var args = operation.args;
  17118. while (true) {
  17119. var obj = this.parser.getObj();
  17120. if (isCmd(obj)) {
  17121. var cmd = obj.cmd;
  17122. // Check that the command is valid
  17123. var opSpec = OP_MAP[cmd];
  17124. if (!opSpec) {
  17125. warn('Unknown command "' + cmd + '"');
  17126. continue;
  17127. }
  17128. var fn = opSpec.id;
  17129. var numArgs = opSpec.numArgs;
  17130. var argsLength = args !== null ? args.length : 0;
  17131. if (!opSpec.variableArgs) {
  17132. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  17133. if (argsLength !== numArgs) {
  17134. var nonProcessedArgs = this.nonProcessedArgs;
  17135. while (argsLength > numArgs) {
  17136. nonProcessedArgs.push(args.shift());
  17137. argsLength--;
  17138. }
  17139. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  17140. if (!args) {
  17141. args = [];
  17142. }
  17143. args.unshift(nonProcessedArgs.pop());
  17144. argsLength++;
  17145. }
  17146. }
  17147. if (argsLength < numArgs) {
  17148. // If we receive too few args, it's not possible to possible
  17149. // to execute the command, so skip the command
  17150. info('Command ' + fn + ': because expected ' +
  17151. numArgs + ' args, but received ' + argsLength +
  17152. ' args; skipping');
  17153. args = null;
  17154. continue;
  17155. }
  17156. } else if (argsLength > numArgs) {
  17157. info('Command ' + fn + ': expected [0,' + numArgs +
  17158. '] args, but received ' + argsLength + ' args');
  17159. }
  17160. // TODO figure out how to type-check vararg functions
  17161. this.preprocessCommand(fn, args);
  17162. operation.fn = fn;
  17163. operation.args = args;
  17164. return true;
  17165. } else {
  17166. if (isEOF(obj)) {
  17167. return false; // no more commands
  17168. }
  17169. // argument
  17170. if (obj !== null) {
  17171. if (!args) {
  17172. args = [];
  17173. }
  17174. args.push((obj instanceof Dict ? obj.getAll() : obj));
  17175. assert(args.length <= 33, 'Too many arguments');
  17176. }
  17177. }
  17178. }
  17179. },
  17180. preprocessCommand:
  17181. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  17182. switch (fn | 0) {
  17183. case OPS.save:
  17184. this.stateManager.save();
  17185. break;
  17186. case OPS.restore:
  17187. this.stateManager.restore();
  17188. break;
  17189. case OPS.transform:
  17190. this.stateManager.transform(args);
  17191. break;
  17192. }
  17193. }
  17194. };
  17195. return EvaluatorPreprocessor;
  17196. })();
  17197. var QueueOptimizer = (function QueueOptimizerClosure() {
  17198. function addState(parentState, pattern, fn) {
  17199. var state = parentState;
  17200. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  17201. var item = pattern[i];
  17202. state = (state[item] || (state[item] = []));
  17203. }
  17204. state[pattern[pattern.length - 1]] = fn;
  17205. }
  17206. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17207. argsArray) {
  17208. // Handles special case of mainly LaTeX documents which use image masks to
  17209. // draw lines with the current fill style.
  17210. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  17211. // have been found at iFirstSave.
  17212. var iFirstPIMXO = iFirstSave + 2;
  17213. for (var i = 0; i < count; i++) {
  17214. var arg = argsArray[iFirstPIMXO + 4 * i];
  17215. var imageMask = arg.length === 1 && arg[0];
  17216. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  17217. (!imageMask.data.length ||
  17218. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  17219. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  17220. continue;
  17221. }
  17222. break;
  17223. }
  17224. return count - i;
  17225. }
  17226. var InitialState = [];
  17227. // This replaces (save, transform, paintInlineImageXObject, restore)+
  17228. // sequences with one |paintInlineImageXObjectGroup| operation.
  17229. addState(InitialState,
  17230. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  17231. function foundInlineImageGroup(context) {
  17232. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  17233. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  17234. var MAX_WIDTH = 1000;
  17235. var IMAGE_PADDING = 1;
  17236. var fnArray = context.fnArray, argsArray = context.argsArray;
  17237. var curr = context.iCurr;
  17238. var iFirstSave = curr - 3;
  17239. var iFirstTransform = curr - 2;
  17240. var iFirstPIIXO = curr - 1;
  17241. // Look for the quartets.
  17242. var i = iFirstSave + 4;
  17243. var ii = fnArray.length;
  17244. while (i + 3 < ii) {
  17245. if (fnArray[i] !== OPS.save ||
  17246. fnArray[i + 1] !== OPS.transform ||
  17247. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  17248. fnArray[i + 3] !== OPS.restore) {
  17249. break; // ops don't match
  17250. }
  17251. i += 4;
  17252. }
  17253. // At this point, i is the index of the first op past the last valid
  17254. // quartet.
  17255. var count = Math.min((i - iFirstSave) / 4,
  17256. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  17257. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  17258. return i;
  17259. }
  17260. // assuming that heights of those image is too small (~1 pixel)
  17261. // packing as much as possible by lines
  17262. var maxX = 0;
  17263. var map = [], maxLineHeight = 0;
  17264. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  17265. var q;
  17266. for (q = 0; q < count; q++) {
  17267. var transform = argsArray[iFirstTransform + (q << 2)];
  17268. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  17269. if (currentX + img.width > MAX_WIDTH) {
  17270. // starting new line
  17271. maxX = Math.max(maxX, currentX);
  17272. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  17273. currentX = 0;
  17274. maxLineHeight = 0;
  17275. }
  17276. map.push({
  17277. transform: transform,
  17278. x: currentX, y: currentY,
  17279. w: img.width, h: img.height
  17280. });
  17281. currentX += img.width + 2 * IMAGE_PADDING;
  17282. maxLineHeight = Math.max(maxLineHeight, img.height);
  17283. }
  17284. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  17285. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  17286. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  17287. var imgRowSize = imgWidth << 2;
  17288. for (q = 0; q < count; q++) {
  17289. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  17290. // Copy image by lines and extends pixels into padding.
  17291. var rowSize = map[q].w << 2;
  17292. var dataOffset = 0;
  17293. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  17294. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  17295. for (var k = 0, kk = map[q].h; k < kk; k++) {
  17296. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  17297. dataOffset += rowSize;
  17298. offset += imgRowSize;
  17299. }
  17300. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  17301. while (offset >= 0) {
  17302. data[offset - 4] = data[offset];
  17303. data[offset - 3] = data[offset + 1];
  17304. data[offset - 2] = data[offset + 2];
  17305. data[offset - 1] = data[offset + 3];
  17306. data[offset + rowSize] = data[offset + rowSize - 4];
  17307. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  17308. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  17309. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  17310. offset -= imgRowSize;
  17311. }
  17312. }
  17313. // Replace queue items.
  17314. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  17315. argsArray.splice(iFirstSave, count * 4,
  17316. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  17317. data: imgData }, map]);
  17318. return iFirstSave + 1;
  17319. });
  17320. // This replaces (save, transform, paintImageMaskXObject, restore)+
  17321. // sequences with one |paintImageMaskXObjectGroup| or one
  17322. // |paintImageMaskXObjectRepeat| operation.
  17323. addState(InitialState,
  17324. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  17325. function foundImageMaskGroup(context) {
  17326. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  17327. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  17328. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  17329. var fnArray = context.fnArray, argsArray = context.argsArray;
  17330. var curr = context.iCurr;
  17331. var iFirstSave = curr - 3;
  17332. var iFirstTransform = curr - 2;
  17333. var iFirstPIMXO = curr - 1;
  17334. // Look for the quartets.
  17335. var i = iFirstSave + 4;
  17336. var ii = fnArray.length;
  17337. while (i + 3 < ii) {
  17338. if (fnArray[i] !== OPS.save ||
  17339. fnArray[i + 1] !== OPS.transform ||
  17340. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  17341. fnArray[i + 3] !== OPS.restore) {
  17342. break; // ops don't match
  17343. }
  17344. i += 4;
  17345. }
  17346. // At this point, i is the index of the first op past the last valid
  17347. // quartet.
  17348. var count = (i - iFirstSave) / 4;
  17349. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  17350. argsArray);
  17351. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  17352. return i;
  17353. }
  17354. var q;
  17355. var isSameImage = false;
  17356. var iTransform, transformArgs;
  17357. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  17358. if (argsArray[iFirstTransform][1] === 0 &&
  17359. argsArray[iFirstTransform][2] === 0) {
  17360. isSameImage = true;
  17361. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17362. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17363. iTransform = iFirstTransform + 4;
  17364. var iPIMXO = iFirstPIMXO + 4;
  17365. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  17366. transformArgs = argsArray[iTransform];
  17367. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  17368. transformArgs[0] !== firstTransformArg0 ||
  17369. transformArgs[1] !== 0 ||
  17370. transformArgs[2] !== 0 ||
  17371. transformArgs[3] !== firstTransformArg3) {
  17372. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  17373. isSameImage = false;
  17374. } else {
  17375. count = q;
  17376. }
  17377. break; // different image or transform
  17378. }
  17379. }
  17380. }
  17381. if (isSameImage) {
  17382. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  17383. var positions = new Float32Array(count * 2);
  17384. iTransform = iFirstTransform;
  17385. for (q = 0; q < count; q++, iTransform += 4) {
  17386. transformArgs = argsArray[iTransform];
  17387. positions[(q << 1)] = transformArgs[4];
  17388. positions[(q << 1) + 1] = transformArgs[5];
  17389. }
  17390. // Replace queue items.
  17391. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  17392. argsArray.splice(iFirstSave, count * 4,
  17393. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  17394. } else {
  17395. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  17396. var images = [];
  17397. for (q = 0; q < count; q++) {
  17398. transformArgs = argsArray[iFirstTransform + (q << 2)];
  17399. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  17400. images.push({ data: maskParams.data, width: maskParams.width,
  17401. height: maskParams.height,
  17402. transform: transformArgs });
  17403. }
  17404. // Replace queue items.
  17405. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  17406. argsArray.splice(iFirstSave, count * 4, [images]);
  17407. }
  17408. return iFirstSave + 1;
  17409. });
  17410. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  17411. // with one paintImageXObjectRepeat operation, if the |transform| and
  17412. // |paintImageXObjectRepeat| ops are appropriate.
  17413. addState(InitialState,
  17414. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  17415. function (context) {
  17416. var MIN_IMAGES_IN_BLOCK = 3;
  17417. var MAX_IMAGES_IN_BLOCK = 1000;
  17418. var fnArray = context.fnArray, argsArray = context.argsArray;
  17419. var curr = context.iCurr;
  17420. var iFirstSave = curr - 3;
  17421. var iFirstTransform = curr - 2;
  17422. var iFirstPIXO = curr - 1;
  17423. var iFirstRestore = curr;
  17424. if (argsArray[iFirstTransform][1] !== 0 ||
  17425. argsArray[iFirstTransform][2] !== 0) {
  17426. return iFirstRestore + 1; // transform has the wrong form
  17427. }
  17428. // Look for the quartets.
  17429. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  17430. var firstTransformArg0 = argsArray[iFirstTransform][0];
  17431. var firstTransformArg3 = argsArray[iFirstTransform][3];
  17432. var i = iFirstSave + 4;
  17433. var ii = fnArray.length;
  17434. while (i + 3 < ii) {
  17435. if (fnArray[i] !== OPS.save ||
  17436. fnArray[i + 1] !== OPS.transform ||
  17437. fnArray[i + 2] !== OPS.paintImageXObject ||
  17438. fnArray[i + 3] !== OPS.restore) {
  17439. break; // ops don't match
  17440. }
  17441. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  17442. argsArray[i + 1][1] !== 0 ||
  17443. argsArray[i + 1][2] !== 0 ||
  17444. argsArray[i + 1][3] !== firstTransformArg3) {
  17445. break; // transforms don't match
  17446. }
  17447. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  17448. break; // images don't match
  17449. }
  17450. i += 4;
  17451. }
  17452. // At this point, i is the index of the first op past the last valid
  17453. // quartet.
  17454. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  17455. if (count < MIN_IMAGES_IN_BLOCK) {
  17456. return i;
  17457. }
  17458. // Extract the (x,y) positions from all of the matching transforms.
  17459. var positions = new Float32Array(count * 2);
  17460. var iTransform = iFirstTransform;
  17461. for (var q = 0; q < count; q++, iTransform += 4) {
  17462. var transformArgs = argsArray[iTransform];
  17463. positions[(q << 1)] = transformArgs[4];
  17464. positions[(q << 1) + 1] = transformArgs[5];
  17465. }
  17466. // Replace queue items.
  17467. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  17468. positions];
  17469. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  17470. argsArray.splice(iFirstSave, count * 4, args);
  17471. return iFirstSave + 1;
  17472. });
  17473. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  17474. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  17475. // sequences, if the font for each one is the same.
  17476. addState(InitialState,
  17477. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  17478. function (context) {
  17479. var MIN_CHARS_IN_BLOCK = 3;
  17480. var MAX_CHARS_IN_BLOCK = 1000;
  17481. var fnArray = context.fnArray, argsArray = context.argsArray;
  17482. var curr = context.iCurr;
  17483. var iFirstBeginText = curr - 4;
  17484. var iFirstSetFont = curr - 3;
  17485. var iFirstSetTextMatrix = curr - 2;
  17486. var iFirstShowText = curr - 1;
  17487. var iFirstEndText = curr;
  17488. // Look for the quintets.
  17489. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  17490. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  17491. var i = iFirstBeginText + 5;
  17492. var ii = fnArray.length;
  17493. while (i + 4 < ii) {
  17494. if (fnArray[i] !== OPS.beginText ||
  17495. fnArray[i + 1] !== OPS.setFont ||
  17496. fnArray[i + 2] !== OPS.setTextMatrix ||
  17497. fnArray[i + 3] !== OPS.showText ||
  17498. fnArray[i + 4] !== OPS.endText) {
  17499. break; // ops don't match
  17500. }
  17501. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  17502. argsArray[i + 1][1] !== firstSetFontArg1) {
  17503. break; // fonts don't match
  17504. }
  17505. i += 5;
  17506. }
  17507. // At this point, i is the index of the first op past the last valid
  17508. // quintet.
  17509. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  17510. if (count < MIN_CHARS_IN_BLOCK) {
  17511. return i;
  17512. }
  17513. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  17514. // showText, endText), include that as well. (E.g. <something> might be
  17515. // |dependency|.)
  17516. var iFirst = iFirstBeginText;
  17517. if (iFirstBeginText >= 4 &&
  17518. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  17519. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  17520. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  17521. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  17522. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  17523. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  17524. count++;
  17525. iFirst -= 5;
  17526. }
  17527. // Remove (endText, beginText, setFont) trios.
  17528. var iEndText = iFirst + 4;
  17529. for (var q = 1; q < count; q++) {
  17530. fnArray.splice(iEndText, 3);
  17531. argsArray.splice(iEndText, 3);
  17532. iEndText += 2;
  17533. }
  17534. return iEndText + 1;
  17535. });
  17536. function QueueOptimizer() {}
  17537. QueueOptimizer.prototype = {
  17538. optimize: function QueueOptimizer_optimize(queue) {
  17539. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17540. var context = {
  17541. iCurr: 0,
  17542. fnArray: fnArray,
  17543. argsArray: argsArray
  17544. };
  17545. var state;
  17546. var i = 0, ii = fnArray.length;
  17547. while (i < ii) {
  17548. state = (state || InitialState)[fnArray[i]];
  17549. if (typeof state === 'function') { // we found some handler
  17550. context.iCurr = i;
  17551. // state() returns the index of the first non-matching op (if we
  17552. // didn't match) or the first op past the modified ops (if we did
  17553. // match and replace).
  17554. i = state(context);
  17555. state = undefined; // reset the state machine
  17556. ii = context.fnArray.length;
  17557. } else {
  17558. i++;
  17559. }
  17560. }
  17561. }
  17562. };
  17563. return QueueOptimizer;
  17564. })();
  17565. var BUILT_IN_CMAPS = [
  17566. // << Start unicode maps.
  17567. 'Adobe-GB1-UCS2',
  17568. 'Adobe-CNS1-UCS2',
  17569. 'Adobe-Japan1-UCS2',
  17570. 'Adobe-Korea1-UCS2',
  17571. // >> End unicode maps.
  17572. '78-EUC-H',
  17573. '78-EUC-V',
  17574. '78-H',
  17575. '78-RKSJ-H',
  17576. '78-RKSJ-V',
  17577. '78-V',
  17578. '78ms-RKSJ-H',
  17579. '78ms-RKSJ-V',
  17580. '83pv-RKSJ-H',
  17581. '90ms-RKSJ-H',
  17582. '90ms-RKSJ-V',
  17583. '90msp-RKSJ-H',
  17584. '90msp-RKSJ-V',
  17585. '90pv-RKSJ-H',
  17586. '90pv-RKSJ-V',
  17587. 'Add-H',
  17588. 'Add-RKSJ-H',
  17589. 'Add-RKSJ-V',
  17590. 'Add-V',
  17591. 'Adobe-CNS1-0',
  17592. 'Adobe-CNS1-1',
  17593. 'Adobe-CNS1-2',
  17594. 'Adobe-CNS1-3',
  17595. 'Adobe-CNS1-4',
  17596. 'Adobe-CNS1-5',
  17597. 'Adobe-CNS1-6',
  17598. 'Adobe-GB1-0',
  17599. 'Adobe-GB1-1',
  17600. 'Adobe-GB1-2',
  17601. 'Adobe-GB1-3',
  17602. 'Adobe-GB1-4',
  17603. 'Adobe-GB1-5',
  17604. 'Adobe-Japan1-0',
  17605. 'Adobe-Japan1-1',
  17606. 'Adobe-Japan1-2',
  17607. 'Adobe-Japan1-3',
  17608. 'Adobe-Japan1-4',
  17609. 'Adobe-Japan1-5',
  17610. 'Adobe-Japan1-6',
  17611. 'Adobe-Korea1-0',
  17612. 'Adobe-Korea1-1',
  17613. 'Adobe-Korea1-2',
  17614. 'B5-H',
  17615. 'B5-V',
  17616. 'B5pc-H',
  17617. 'B5pc-V',
  17618. 'CNS-EUC-H',
  17619. 'CNS-EUC-V',
  17620. 'CNS1-H',
  17621. 'CNS1-V',
  17622. 'CNS2-H',
  17623. 'CNS2-V',
  17624. 'ETHK-B5-H',
  17625. 'ETHK-B5-V',
  17626. 'ETen-B5-H',
  17627. 'ETen-B5-V',
  17628. 'ETenms-B5-H',
  17629. 'ETenms-B5-V',
  17630. 'EUC-H',
  17631. 'EUC-V',
  17632. 'Ext-H',
  17633. 'Ext-RKSJ-H',
  17634. 'Ext-RKSJ-V',
  17635. 'Ext-V',
  17636. 'GB-EUC-H',
  17637. 'GB-EUC-V',
  17638. 'GB-H',
  17639. 'GB-V',
  17640. 'GBK-EUC-H',
  17641. 'GBK-EUC-V',
  17642. 'GBK2K-H',
  17643. 'GBK2K-V',
  17644. 'GBKp-EUC-H',
  17645. 'GBKp-EUC-V',
  17646. 'GBT-EUC-H',
  17647. 'GBT-EUC-V',
  17648. 'GBT-H',
  17649. 'GBT-V',
  17650. 'GBTpc-EUC-H',
  17651. 'GBTpc-EUC-V',
  17652. 'GBpc-EUC-H',
  17653. 'GBpc-EUC-V',
  17654. 'H',
  17655. 'HKdla-B5-H',
  17656. 'HKdla-B5-V',
  17657. 'HKdlb-B5-H',
  17658. 'HKdlb-B5-V',
  17659. 'HKgccs-B5-H',
  17660. 'HKgccs-B5-V',
  17661. 'HKm314-B5-H',
  17662. 'HKm314-B5-V',
  17663. 'HKm471-B5-H',
  17664. 'HKm471-B5-V',
  17665. 'HKscs-B5-H',
  17666. 'HKscs-B5-V',
  17667. 'Hankaku',
  17668. 'Hiragana',
  17669. 'KSC-EUC-H',
  17670. 'KSC-EUC-V',
  17671. 'KSC-H',
  17672. 'KSC-Johab-H',
  17673. 'KSC-Johab-V',
  17674. 'KSC-V',
  17675. 'KSCms-UHC-H',
  17676. 'KSCms-UHC-HW-H',
  17677. 'KSCms-UHC-HW-V',
  17678. 'KSCms-UHC-V',
  17679. 'KSCpc-EUC-H',
  17680. 'KSCpc-EUC-V',
  17681. 'Katakana',
  17682. 'NWP-H',
  17683. 'NWP-V',
  17684. 'RKSJ-H',
  17685. 'RKSJ-V',
  17686. 'Roman',
  17687. 'UniCNS-UCS2-H',
  17688. 'UniCNS-UCS2-V',
  17689. 'UniCNS-UTF16-H',
  17690. 'UniCNS-UTF16-V',
  17691. 'UniCNS-UTF32-H',
  17692. 'UniCNS-UTF32-V',
  17693. 'UniCNS-UTF8-H',
  17694. 'UniCNS-UTF8-V',
  17695. 'UniGB-UCS2-H',
  17696. 'UniGB-UCS2-V',
  17697. 'UniGB-UTF16-H',
  17698. 'UniGB-UTF16-V',
  17699. 'UniGB-UTF32-H',
  17700. 'UniGB-UTF32-V',
  17701. 'UniGB-UTF8-H',
  17702. 'UniGB-UTF8-V',
  17703. 'UniJIS-UCS2-H',
  17704. 'UniJIS-UCS2-HW-H',
  17705. 'UniJIS-UCS2-HW-V',
  17706. 'UniJIS-UCS2-V',
  17707. 'UniJIS-UTF16-H',
  17708. 'UniJIS-UTF16-V',
  17709. 'UniJIS-UTF32-H',
  17710. 'UniJIS-UTF32-V',
  17711. 'UniJIS-UTF8-H',
  17712. 'UniJIS-UTF8-V',
  17713. 'UniJIS2004-UTF16-H',
  17714. 'UniJIS2004-UTF16-V',
  17715. 'UniJIS2004-UTF32-H',
  17716. 'UniJIS2004-UTF32-V',
  17717. 'UniJIS2004-UTF8-H',
  17718. 'UniJIS2004-UTF8-V',
  17719. 'UniJISPro-UCS2-HW-V',
  17720. 'UniJISPro-UCS2-V',
  17721. 'UniJISPro-UTF8-V',
  17722. 'UniJISX0213-UTF32-H',
  17723. 'UniJISX0213-UTF32-V',
  17724. 'UniJISX02132004-UTF32-H',
  17725. 'UniJISX02132004-UTF32-V',
  17726. 'UniKS-UCS2-H',
  17727. 'UniKS-UCS2-V',
  17728. 'UniKS-UTF16-H',
  17729. 'UniKS-UTF16-V',
  17730. 'UniKS-UTF32-H',
  17731. 'UniKS-UTF32-V',
  17732. 'UniKS-UTF8-H',
  17733. 'UniKS-UTF8-V',
  17734. 'V',
  17735. 'WP-Symbol'];
  17736. // CMap, not to be confused with TrueType's cmap.
  17737. var CMap = (function CMapClosure() {
  17738. function CMap(builtInCMap) {
  17739. // Codespace ranges are stored as follows:
  17740. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  17741. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  17742. this.codespaceRanges = [[], [], [], []];
  17743. this.numCodespaceRanges = 0;
  17744. // Map entries have one of two forms.
  17745. // - cid chars are 16-bit unsigned integers, stored as integers.
  17746. // - bf chars are variable-length byte sequences, stored as strings, with
  17747. // one byte per character.
  17748. this._map = [];
  17749. this.vertical = false;
  17750. this.useCMap = null;
  17751. this.builtInCMap = builtInCMap;
  17752. }
  17753. CMap.prototype = {
  17754. addCodespaceRange: function(n, low, high) {
  17755. this.codespaceRanges[n - 1].push(low, high);
  17756. this.numCodespaceRanges++;
  17757. },
  17758. mapCidRange: function(low, high, dstLow) {
  17759. while (low <= high) {
  17760. this._map[low++] = dstLow++;
  17761. }
  17762. },
  17763. mapBfRange: function(low, high, dstLow) {
  17764. var lastByte = dstLow.length - 1;
  17765. while (low <= high) {
  17766. this._map[low++] = dstLow;
  17767. // Only the last byte has to be incremented.
  17768. dstLow = dstLow.substr(0, lastByte) +
  17769. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  17770. }
  17771. },
  17772. mapBfRangeToArray: function(low, high, array) {
  17773. var i = 0, ii = array.length;
  17774. while (low <= high && i < ii) {
  17775. this._map[low] = array[i++];
  17776. ++low;
  17777. }
  17778. },
  17779. // This is used for both bf and cid chars.
  17780. mapOne: function(src, dst) {
  17781. this._map[src] = dst;
  17782. },
  17783. lookup: function(code) {
  17784. return this._map[code];
  17785. },
  17786. contains: function(code) {
  17787. return this._map[code] !== undefined;
  17788. },
  17789. forEach: function(callback) {
  17790. // Most maps have fewer than 65536 entries, and for those we use normal
  17791. // array iteration. But really sparse tables are possible -- e.g. with
  17792. // indices in the *billions*. For such tables we use for..in, which isn't
  17793. // ideal because it stringifies the indices for all present elements, but
  17794. // it does avoid iterating over every undefined entry.
  17795. var map = this._map;
  17796. var length = map.length;
  17797. var i;
  17798. if (length <= 0x10000) {
  17799. for (i = 0; i < length; i++) {
  17800. if (map[i] !== undefined) {
  17801. callback(i, map[i]);
  17802. }
  17803. }
  17804. } else {
  17805. for (i in this._map) {
  17806. callback(i, map[i]);
  17807. }
  17808. }
  17809. },
  17810. charCodeOf: function(value) {
  17811. return this._map.indexOf(value);
  17812. },
  17813. getMap: function() {
  17814. return this._map;
  17815. },
  17816. readCharCode: function(str, offset, out) {
  17817. var c = 0;
  17818. var codespaceRanges = this.codespaceRanges;
  17819. var codespaceRangesLen = this.codespaceRanges.length;
  17820. // 9.7.6.2 CMap Mapping
  17821. // The code length is at most 4.
  17822. for (var n = 0; n < codespaceRangesLen; n++) {
  17823. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  17824. // Check each codespace range to see if it falls within.
  17825. var codespaceRange = codespaceRanges[n];
  17826. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  17827. var low = codespaceRange[k++];
  17828. var high = codespaceRange[k++];
  17829. if (c >= low && c <= high) {
  17830. out.charcode = c;
  17831. out.length = n + 1;
  17832. return;
  17833. }
  17834. }
  17835. }
  17836. out.charcode = 0;
  17837. out.length = 1;
  17838. }
  17839. };
  17840. return CMap;
  17841. })();
  17842. // A special case of CMap, where the _map array implicitly has a length of
  17843. // 65535 and each element is equal to its index.
  17844. var IdentityCMap = (function IdentityCMapClosure() {
  17845. function IdentityCMap(vertical, n) {
  17846. CMap.call(this);
  17847. this.vertical = vertical;
  17848. this.addCodespaceRange(n, 0, 0xffff);
  17849. }
  17850. Util.inherit(IdentityCMap, CMap, {});
  17851. IdentityCMap.prototype = {
  17852. addCodespaceRange: CMap.prototype.addCodespaceRange,
  17853. mapCidRange: function(low, high, dstLow) {
  17854. error('should not call mapCidRange');
  17855. },
  17856. mapBfRange: function(low, high, dstLow) {
  17857. error('should not call mapBfRange');
  17858. },
  17859. mapBfRangeToArray: function(low, high, array) {
  17860. error('should not call mapBfRangeToArray');
  17861. },
  17862. mapOne: function(src, dst) {
  17863. error('should not call mapCidOne');
  17864. },
  17865. lookup: function(code) {
  17866. return (isInt(code) && code <= 0xffff) ? code : undefined;
  17867. },
  17868. contains: function(code) {
  17869. return isInt(code) && code <= 0xffff;
  17870. },
  17871. forEach: function(callback) {
  17872. for (var i = 0; i <= 0xffff; i++) {
  17873. callback(i, i);
  17874. }
  17875. },
  17876. charCodeOf: function(value) {
  17877. return (isInt(value) && value <= 0xffff) ? value : -1;
  17878. },
  17879. getMap: function() {
  17880. // Sometimes identity maps must be instantiated, but it's rare.
  17881. var map = new Array(0x10000);
  17882. for (var i = 0; i <= 0xffff; i++) {
  17883. map[i] = i;
  17884. }
  17885. return map;
  17886. },
  17887. readCharCode: CMap.prototype.readCharCode
  17888. };
  17889. return IdentityCMap;
  17890. })();
  17891. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  17892. function fetchBinaryData(url) {
  17893. var nonBinaryRequest = PDFJS.disableWorker;
  17894. var request = new XMLHttpRequest();
  17895. request.open('GET', url, false);
  17896. if (!nonBinaryRequest) {
  17897. try {
  17898. request.responseType = 'arraybuffer';
  17899. nonBinaryRequest = request.responseType !== 'arraybuffer';
  17900. } catch (e) {
  17901. nonBinaryRequest = true;
  17902. }
  17903. }
  17904. if (nonBinaryRequest && request.overrideMimeType) {
  17905. request.overrideMimeType('text/plain; charset=x-user-defined');
  17906. }
  17907. request.send(null);
  17908. if (nonBinaryRequest ? !request.responseText : !request.response) {
  17909. error('Unable to get binary cMap at: ' + url);
  17910. }
  17911. if (nonBinaryRequest) {
  17912. var data = Array.prototype.map.call(request.responseText, function (ch) {
  17913. return ch.charCodeAt(0) & 255;
  17914. });
  17915. return new Uint8Array(data);
  17916. }
  17917. return new Uint8Array(request.response);
  17918. }
  17919. function hexToInt(a, size) {
  17920. var n = 0;
  17921. for (var i = 0; i <= size; i++) {
  17922. n = (n << 8) | a[i];
  17923. }
  17924. return n >>> 0;
  17925. }
  17926. function hexToStr(a, size) {
  17927. // This code is hot. Special-case some common values to avoid creating an
  17928. // object with subarray().
  17929. if (size === 1) {
  17930. return String.fromCharCode(a[0], a[1]);
  17931. }
  17932. if (size === 3) {
  17933. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  17934. }
  17935. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  17936. }
  17937. function addHex(a, b, size) {
  17938. var c = 0;
  17939. for (var i = size; i >= 0; i--) {
  17940. c += a[i] + b[i];
  17941. a[i] = c & 255;
  17942. c >>= 8;
  17943. }
  17944. }
  17945. function incHex(a, size) {
  17946. var c = 1;
  17947. for (var i = size; i >= 0 && c > 0; i--) {
  17948. c += a[i];
  17949. a[i] = c & 255;
  17950. c >>= 8;
  17951. }
  17952. }
  17953. var MAX_NUM_SIZE = 16;
  17954. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  17955. function BinaryCMapStream(data) {
  17956. this.buffer = data;
  17957. this.pos = 0;
  17958. this.end = data.length;
  17959. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  17960. }
  17961. BinaryCMapStream.prototype = {
  17962. readByte: function () {
  17963. if (this.pos >= this.end) {
  17964. return -1;
  17965. }
  17966. return this.buffer[this.pos++];
  17967. },
  17968. readNumber: function () {
  17969. var n = 0;
  17970. var last;
  17971. do {
  17972. var b = this.readByte();
  17973. if (b < 0) {
  17974. error('unexpected EOF in bcmap');
  17975. }
  17976. last = !(b & 0x80);
  17977. n = (n << 7) | (b & 0x7F);
  17978. } while (!last);
  17979. return n;
  17980. },
  17981. readSigned: function () {
  17982. var n = this.readNumber();
  17983. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  17984. },
  17985. readHex: function (num, size) {
  17986. num.set(this.buffer.subarray(this.pos,
  17987. this.pos + size + 1));
  17988. this.pos += size + 1;
  17989. },
  17990. readHexNumber: function (num, size) {
  17991. var last;
  17992. var stack = this.tmpBuf, sp = 0;
  17993. do {
  17994. var b = this.readByte();
  17995. if (b < 0) {
  17996. error('unexpected EOF in bcmap');
  17997. }
  17998. last = !(b & 0x80);
  17999. stack[sp++] = b & 0x7F;
  18000. } while (!last);
  18001. var i = size, buffer = 0, bufferSize = 0;
  18002. while (i >= 0) {
  18003. while (bufferSize < 8 && stack.length > 0) {
  18004. buffer = (stack[--sp] << bufferSize) | buffer;
  18005. bufferSize += 7;
  18006. }
  18007. num[i] = buffer & 255;
  18008. i--;
  18009. buffer >>= 8;
  18010. bufferSize -= 8;
  18011. }
  18012. },
  18013. readHexSigned: function (num, size) {
  18014. this.readHexNumber(num, size);
  18015. var sign = num[size] & 1 ? 255 : 0;
  18016. var c = 0;
  18017. for (var i = 0; i <= size; i++) {
  18018. c = ((c & 1) << 8) | num[i];
  18019. num[i] = (c >> 1) ^ sign;
  18020. }
  18021. },
  18022. readString: function () {
  18023. var len = this.readNumber();
  18024. var s = '';
  18025. for (var i = 0; i < len; i++) {
  18026. s += String.fromCharCode(this.readNumber());
  18027. }
  18028. return s;
  18029. }
  18030. };
  18031. function processBinaryCMap(url, cMap, extend) {
  18032. var data = fetchBinaryData(url);
  18033. var stream = new BinaryCMapStream(data);
  18034. var header = stream.readByte();
  18035. cMap.vertical = !!(header & 1);
  18036. var useCMap = null;
  18037. var start = new Uint8Array(MAX_NUM_SIZE);
  18038. var end = new Uint8Array(MAX_NUM_SIZE);
  18039. var char = new Uint8Array(MAX_NUM_SIZE);
  18040. var charCode = new Uint8Array(MAX_NUM_SIZE);
  18041. var tmp = new Uint8Array(MAX_NUM_SIZE);
  18042. var code;
  18043. var b;
  18044. while ((b = stream.readByte()) >= 0) {
  18045. var type = b >> 5;
  18046. if (type === 7) { // metadata, e.g. comment or usecmap
  18047. switch (b & 0x1F) {
  18048. case 0:
  18049. stream.readString(); // skipping comment
  18050. break;
  18051. case 1:
  18052. useCMap = stream.readString();
  18053. break;
  18054. }
  18055. continue;
  18056. }
  18057. var sequence = !!(b & 0x10);
  18058. var dataSize = b & 15;
  18059. assert(dataSize + 1 <= MAX_NUM_SIZE);
  18060. var ucs2DataSize = 1;
  18061. var subitemsCount = stream.readNumber();
  18062. var i;
  18063. switch (type) {
  18064. case 0: // codespacerange
  18065. stream.readHex(start, dataSize);
  18066. stream.readHexNumber(end, dataSize);
  18067. addHex(end, start, dataSize);
  18068. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18069. hexToInt(end, dataSize));
  18070. for (i = 1; i < subitemsCount; i++) {
  18071. incHex(end, dataSize);
  18072. stream.readHexNumber(start, dataSize);
  18073. addHex(start, end, dataSize);
  18074. stream.readHexNumber(end, dataSize);
  18075. addHex(end, start, dataSize);
  18076. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  18077. hexToInt(end, dataSize));
  18078. }
  18079. break;
  18080. case 1: // notdefrange
  18081. stream.readHex(start, dataSize);
  18082. stream.readHexNumber(end, dataSize);
  18083. addHex(end, start, dataSize);
  18084. code = stream.readNumber();
  18085. // undefined range, skipping
  18086. for (i = 1; i < subitemsCount; i++) {
  18087. incHex(end, dataSize);
  18088. stream.readHexNumber(start, dataSize);
  18089. addHex(start, end, dataSize);
  18090. stream.readHexNumber(end, dataSize);
  18091. addHex(end, start, dataSize);
  18092. code = stream.readNumber();
  18093. // nop
  18094. }
  18095. break;
  18096. case 2: // cidchar
  18097. stream.readHex(char, dataSize);
  18098. code = stream.readNumber();
  18099. cMap.mapOne(hexToInt(char, dataSize), code);
  18100. for (i = 1; i < subitemsCount; i++) {
  18101. incHex(char, dataSize);
  18102. if (!sequence) {
  18103. stream.readHexNumber(tmp, dataSize);
  18104. addHex(char, tmp, dataSize);
  18105. }
  18106. code = stream.readSigned() + (code + 1);
  18107. cMap.mapOne(hexToInt(char, dataSize), code);
  18108. }
  18109. break;
  18110. case 3: // cidrange
  18111. stream.readHex(start, dataSize);
  18112. stream.readHexNumber(end, dataSize);
  18113. addHex(end, start, dataSize);
  18114. code = stream.readNumber();
  18115. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18116. code);
  18117. for (i = 1; i < subitemsCount; i++) {
  18118. incHex(end, dataSize);
  18119. if (!sequence) {
  18120. stream.readHexNumber(start, dataSize);
  18121. addHex(start, end, dataSize);
  18122. } else {
  18123. start.set(end);
  18124. }
  18125. stream.readHexNumber(end, dataSize);
  18126. addHex(end, start, dataSize);
  18127. code = stream.readNumber();
  18128. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  18129. code);
  18130. }
  18131. break;
  18132. case 4: // bfchar
  18133. stream.readHex(char, ucs2DataSize);
  18134. stream.readHex(charCode, dataSize);
  18135. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18136. hexToStr(charCode, dataSize));
  18137. for (i = 1; i < subitemsCount; i++) {
  18138. incHex(char, ucs2DataSize);
  18139. if (!sequence) {
  18140. stream.readHexNumber(tmp, ucs2DataSize);
  18141. addHex(char, tmp, ucs2DataSize);
  18142. }
  18143. incHex(charCode, dataSize);
  18144. stream.readHexSigned(tmp, dataSize);
  18145. addHex(charCode, tmp, dataSize);
  18146. cMap.mapOne(hexToInt(char, ucs2DataSize),
  18147. hexToStr(charCode, dataSize));
  18148. }
  18149. break;
  18150. case 5: // bfrange
  18151. stream.readHex(start, ucs2DataSize);
  18152. stream.readHexNumber(end, ucs2DataSize);
  18153. addHex(end, start, ucs2DataSize);
  18154. stream.readHex(charCode, dataSize);
  18155. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18156. hexToInt(end, ucs2DataSize),
  18157. hexToStr(charCode, dataSize));
  18158. for (i = 1; i < subitemsCount; i++) {
  18159. incHex(end, ucs2DataSize);
  18160. if (!sequence) {
  18161. stream.readHexNumber(start, ucs2DataSize);
  18162. addHex(start, end, ucs2DataSize);
  18163. } else {
  18164. start.set(end);
  18165. }
  18166. stream.readHexNumber(end, ucs2DataSize);
  18167. addHex(end, start, ucs2DataSize);
  18168. stream.readHex(charCode, dataSize);
  18169. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  18170. hexToInt(end, ucs2DataSize),
  18171. hexToStr(charCode, dataSize));
  18172. }
  18173. break;
  18174. default:
  18175. error('Unknown type: ' + type);
  18176. break;
  18177. }
  18178. }
  18179. if (useCMap) {
  18180. extend(useCMap);
  18181. }
  18182. return cMap;
  18183. }
  18184. function BinaryCMapReader() {}
  18185. BinaryCMapReader.prototype = {
  18186. read: processBinaryCMap
  18187. };
  18188. return BinaryCMapReader;
  18189. })();
  18190. var CMapFactory = (function CMapFactoryClosure() {
  18191. function strToInt(str) {
  18192. var a = 0;
  18193. for (var i = 0; i < str.length; i++) {
  18194. a = (a << 8) | str.charCodeAt(i);
  18195. }
  18196. return a >>> 0;
  18197. }
  18198. function expectString(obj) {
  18199. if (!isString(obj)) {
  18200. error('Malformed CMap: expected string.');
  18201. }
  18202. }
  18203. function expectInt(obj) {
  18204. if (!isInt(obj)) {
  18205. error('Malformed CMap: expected int.');
  18206. }
  18207. }
  18208. function parseBfChar(cMap, lexer) {
  18209. while (true) {
  18210. var obj = lexer.getObj();
  18211. if (isEOF(obj)) {
  18212. break;
  18213. }
  18214. if (isCmd(obj, 'endbfchar')) {
  18215. return;
  18216. }
  18217. expectString(obj);
  18218. var src = strToInt(obj);
  18219. obj = lexer.getObj();
  18220. // TODO are /dstName used?
  18221. expectString(obj);
  18222. var dst = obj;
  18223. cMap.mapOne(src, dst);
  18224. }
  18225. }
  18226. function parseBfRange(cMap, lexer) {
  18227. while (true) {
  18228. var obj = lexer.getObj();
  18229. if (isEOF(obj)) {
  18230. break;
  18231. }
  18232. if (isCmd(obj, 'endbfrange')) {
  18233. return;
  18234. }
  18235. expectString(obj);
  18236. var low = strToInt(obj);
  18237. obj = lexer.getObj();
  18238. expectString(obj);
  18239. var high = strToInt(obj);
  18240. obj = lexer.getObj();
  18241. if (isInt(obj) || isString(obj)) {
  18242. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  18243. cMap.mapBfRange(low, high, dstLow);
  18244. } else if (isCmd(obj, '[')) {
  18245. obj = lexer.getObj();
  18246. var array = [];
  18247. while (!isCmd(obj, ']') && !isEOF(obj)) {
  18248. array.push(obj);
  18249. obj = lexer.getObj();
  18250. }
  18251. cMap.mapBfRangeToArray(low, high, array);
  18252. } else {
  18253. break;
  18254. }
  18255. }
  18256. error('Invalid bf range.');
  18257. }
  18258. function parseCidChar(cMap, lexer) {
  18259. while (true) {
  18260. var obj = lexer.getObj();
  18261. if (isEOF(obj)) {
  18262. break;
  18263. }
  18264. if (isCmd(obj, 'endcidchar')) {
  18265. return;
  18266. }
  18267. expectString(obj);
  18268. var src = strToInt(obj);
  18269. obj = lexer.getObj();
  18270. expectInt(obj);
  18271. var dst = obj;
  18272. cMap.mapOne(src, dst);
  18273. }
  18274. }
  18275. function parseCidRange(cMap, lexer) {
  18276. while (true) {
  18277. var obj = lexer.getObj();
  18278. if (isEOF(obj)) {
  18279. break;
  18280. }
  18281. if (isCmd(obj, 'endcidrange')) {
  18282. return;
  18283. }
  18284. expectString(obj);
  18285. var low = strToInt(obj);
  18286. obj = lexer.getObj();
  18287. expectString(obj);
  18288. var high = strToInt(obj);
  18289. obj = lexer.getObj();
  18290. expectInt(obj);
  18291. var dstLow = obj;
  18292. cMap.mapCidRange(low, high, dstLow);
  18293. }
  18294. }
  18295. function parseCodespaceRange(cMap, lexer) {
  18296. while (true) {
  18297. var obj = lexer.getObj();
  18298. if (isEOF(obj)) {
  18299. break;
  18300. }
  18301. if (isCmd(obj, 'endcodespacerange')) {
  18302. return;
  18303. }
  18304. if (!isString(obj)) {
  18305. break;
  18306. }
  18307. var low = strToInt(obj);
  18308. obj = lexer.getObj();
  18309. if (!isString(obj)) {
  18310. break;
  18311. }
  18312. var high = strToInt(obj);
  18313. cMap.addCodespaceRange(obj.length, low, high);
  18314. }
  18315. error('Invalid codespace range.');
  18316. }
  18317. function parseWMode(cMap, lexer) {
  18318. var obj = lexer.getObj();
  18319. if (isInt(obj)) {
  18320. cMap.vertical = !!obj;
  18321. }
  18322. }
  18323. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  18324. var previous;
  18325. var embededUseCMap;
  18326. objLoop: while (true) {
  18327. var obj = lexer.getObj();
  18328. if (isEOF(obj)) {
  18329. break;
  18330. } else if (isName(obj)) {
  18331. if (obj.name === 'WMode') {
  18332. parseWMode(cMap, lexer);
  18333. }
  18334. previous = obj;
  18335. } else if (isCmd(obj)) {
  18336. switch (obj.cmd) {
  18337. case 'endcmap':
  18338. break objLoop;
  18339. case 'usecmap':
  18340. if (isName(previous)) {
  18341. embededUseCMap = previous.name;
  18342. }
  18343. break;
  18344. case 'begincodespacerange':
  18345. parseCodespaceRange(cMap, lexer);
  18346. break;
  18347. case 'beginbfchar':
  18348. parseBfChar(cMap, lexer);
  18349. break;
  18350. case 'begincidchar':
  18351. parseCidChar(cMap, lexer);
  18352. break;
  18353. case 'beginbfrange':
  18354. parseBfRange(cMap, lexer);
  18355. break;
  18356. case 'begincidrange':
  18357. parseCidRange(cMap, lexer);
  18358. break;
  18359. }
  18360. }
  18361. }
  18362. if (!useCMap && embededUseCMap) {
  18363. // Load the usecmap definition from the file only if there wasn't one
  18364. // specified.
  18365. useCMap = embededUseCMap;
  18366. }
  18367. if (useCMap) {
  18368. extendCMap(cMap, builtInCMapParams, useCMap);
  18369. }
  18370. }
  18371. function extendCMap(cMap, builtInCMapParams, useCMap) {
  18372. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  18373. // If there aren't any code space ranges defined clone all the parent ones
  18374. // into this cMap.
  18375. if (cMap.numCodespaceRanges === 0) {
  18376. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  18377. for (var i = 0; i < useCodespaceRanges.length; i++) {
  18378. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  18379. }
  18380. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  18381. }
  18382. // Merge the map into the current one, making sure not to override
  18383. // any previously defined entries.
  18384. cMap.useCMap.forEach(function(key, value) {
  18385. if (!cMap.contains(key)) {
  18386. cMap.mapOne(key, cMap.useCMap.lookup(key));
  18387. }
  18388. });
  18389. }
  18390. function parseBinaryCMap(name, builtInCMapParams) {
  18391. var url = builtInCMapParams.url + name + '.bcmap';
  18392. var cMap = new CMap(true);
  18393. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  18394. extendCMap(cMap, builtInCMapParams, useCMap);
  18395. });
  18396. return cMap;
  18397. }
  18398. function createBuiltInCMap(name, builtInCMapParams) {
  18399. if (name === 'Identity-H') {
  18400. return new IdentityCMap(false, 2);
  18401. } else if (name === 'Identity-V') {
  18402. return new IdentityCMap(true, 2);
  18403. }
  18404. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  18405. error('Unknown cMap name: ' + name);
  18406. }
  18407. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  18408. if (builtInCMapParams.packed) {
  18409. return parseBinaryCMap(name, builtInCMapParams);
  18410. }
  18411. var request = new XMLHttpRequest();
  18412. var url = builtInCMapParams.url + name;
  18413. request.open('GET', url, false);
  18414. request.send(null);
  18415. if (!request.responseText) {
  18416. error('Unable to get cMap at: ' + url);
  18417. }
  18418. var cMap = new CMap(true);
  18419. var lexer = new Lexer(new StringStream(request.responseText));
  18420. parseCMap(cMap, lexer, builtInCMapParams, null);
  18421. return cMap;
  18422. }
  18423. return {
  18424. create: function (encoding, builtInCMapParams, useCMap) {
  18425. if (isName(encoding)) {
  18426. return createBuiltInCMap(encoding.name, builtInCMapParams);
  18427. } else if (isStream(encoding)) {
  18428. var cMap = new CMap();
  18429. var lexer = new Lexer(encoding);
  18430. try {
  18431. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  18432. } catch (e) {
  18433. warn('Invalid CMap data. ' + e);
  18434. }
  18435. return cMap;
  18436. }
  18437. error('Encoding required.');
  18438. }
  18439. };
  18440. })();
  18441. // Unicode Private Use Area
  18442. var PRIVATE_USE_OFFSET_START = 0xE000;
  18443. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  18444. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  18445. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  18446. // except for Type 3 fonts
  18447. var PDF_GLYPH_SPACE_UNITS = 1000;
  18448. // Hinting is currently disabled due to unknown problems on windows
  18449. // in tracemonkey and various other pdfs with type1 fonts.
  18450. var HINTING_ENABLED = false;
  18451. // Accented charactars are not displayed properly on windows, using this flag
  18452. // to control analysis of seac charstrings.
  18453. var SEAC_ANALYSIS_ENABLED = false;
  18454. var FontFlags = {
  18455. FixedPitch: 1,
  18456. Serif: 2,
  18457. Symbolic: 4,
  18458. Script: 8,
  18459. Nonsymbolic: 32,
  18460. Italic: 64,
  18461. AllCap: 65536,
  18462. SmallCap: 131072,
  18463. ForceBold: 262144
  18464. };
  18465. var Encodings = {
  18466. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18467. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18468. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  18469. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  18470. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  18471. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  18472. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  18473. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  18474. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  18475. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  18476. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  18477. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  18478. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  18479. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  18480. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  18481. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  18482. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  18483. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  18484. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  18485. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18486. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18487. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  18488. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  18489. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  18490. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  18491. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  18492. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  18493. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  18494. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  18495. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  18496. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  18497. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  18498. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  18499. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  18500. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  18501. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  18502. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  18503. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  18504. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  18505. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  18506. 'Ydieresissmall'],
  18507. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18508. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18509. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  18510. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  18511. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18512. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  18513. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  18514. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  18515. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  18516. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  18517. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  18518. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  18519. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  18520. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  18521. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18522. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18523. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18524. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18525. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  18526. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  18527. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  18528. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  18529. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  18530. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  18531. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  18532. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  18533. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  18534. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  18535. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  18536. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  18537. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  18538. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  18539. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  18540. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  18541. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18542. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  18543. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  18544. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  18545. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  18546. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  18547. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18548. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18549. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18550. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18551. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18552. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18553. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18554. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18555. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18556. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18557. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18558. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  18559. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  18560. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  18561. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  18562. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  18563. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  18564. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  18565. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  18566. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  18567. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  18568. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  18569. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  18570. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  18571. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  18572. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  18573. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  18574. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  18575. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  18576. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  18577. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  18578. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  18579. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  18580. 'ogonek', 'caron'],
  18581. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18582. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18583. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18584. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18585. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18586. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18587. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18588. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18589. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18590. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  18591. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  18592. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18593. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18594. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  18595. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18596. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18597. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  18598. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  18599. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  18600. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  18601. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  18602. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  18603. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  18604. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  18605. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  18606. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18607. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18608. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18609. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  18610. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  18611. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  18612. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  18613. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  18614. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  18615. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  18616. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  18617. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  18618. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  18619. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  18620. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  18621. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  18622. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  18623. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  18624. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  18625. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  18626. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  18627. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  18628. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  18629. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  18630. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  18631. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  18632. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  18633. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  18634. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  18635. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  18636. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  18637. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  18638. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  18639. 'ydieresis'],
  18640. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18641. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18642. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  18643. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  18644. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18645. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18646. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  18647. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  18648. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  18649. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  18650. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  18651. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  18652. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  18653. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  18654. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  18655. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18656. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  18657. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  18658. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  18659. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  18660. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  18661. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  18662. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  18663. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  18664. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  18665. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  18666. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  18667. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  18668. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  18669. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  18670. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  18671. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  18672. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  18673. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  18674. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  18675. 'bracerightbt'],
  18676. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18677. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  18678. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  18679. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  18680. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  18681. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  18682. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  18683. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  18684. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  18685. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  18686. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  18687. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  18688. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  18689. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  18690. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  18691. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  18692. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  18693. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  18694. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  18695. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  18696. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  18697. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  18698. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  18699. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  18700. };
  18701. /**
  18702. * Hold a map of decoded fonts and of the standard fourteen Type1
  18703. * fonts and their acronyms.
  18704. */
  18705. var stdFontMap = {
  18706. 'ArialNarrow': 'Helvetica',
  18707. 'ArialNarrow-Bold': 'Helvetica-Bold',
  18708. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  18709. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  18710. 'ArialBlack': 'Helvetica',
  18711. 'ArialBlack-Bold': 'Helvetica-Bold',
  18712. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  18713. 'ArialBlack-Italic': 'Helvetica-Oblique',
  18714. 'Arial': 'Helvetica',
  18715. 'Arial-Bold': 'Helvetica-Bold',
  18716. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  18717. 'Arial-Italic': 'Helvetica-Oblique',
  18718. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  18719. 'Arial-BoldMT': 'Helvetica-Bold',
  18720. 'Arial-ItalicMT': 'Helvetica-Oblique',
  18721. 'ArialMT': 'Helvetica',
  18722. 'Courier-Bold': 'Courier-Bold',
  18723. 'Courier-BoldItalic': 'Courier-BoldOblique',
  18724. 'Courier-Italic': 'Courier-Oblique',
  18725. 'CourierNew': 'Courier',
  18726. 'CourierNew-Bold': 'Courier-Bold',
  18727. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  18728. 'CourierNew-Italic': 'Courier-Oblique',
  18729. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  18730. 'CourierNewPS-BoldMT': 'Courier-Bold',
  18731. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  18732. 'CourierNewPSMT': 'Courier',
  18733. 'Helvetica': 'Helvetica',
  18734. 'Helvetica-Bold': 'Helvetica-Bold',
  18735. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  18736. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  18737. 'Helvetica-Italic': 'Helvetica-Oblique',
  18738. 'Helvetica-Oblique':'Helvetica-Oblique',
  18739. 'Symbol-Bold': 'Symbol',
  18740. 'Symbol-BoldItalic': 'Symbol',
  18741. 'Symbol-Italic': 'Symbol',
  18742. 'TimesNewRoman': 'Times-Roman',
  18743. 'TimesNewRoman-Bold': 'Times-Bold',
  18744. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  18745. 'TimesNewRoman-Italic': 'Times-Italic',
  18746. 'TimesNewRomanPS': 'Times-Roman',
  18747. 'TimesNewRomanPS-Bold': 'Times-Bold',
  18748. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  18749. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  18750. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  18751. 'TimesNewRomanPS-Italic': 'Times-Italic',
  18752. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  18753. 'TimesNewRomanPSMT': 'Times-Roman',
  18754. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  18755. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  18756. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  18757. };
  18758. /**
  18759. * Holds the map of the non-standard fonts that might be included as a standard
  18760. * fonts without glyph data.
  18761. */
  18762. var nonStdFontMap = {
  18763. 'CenturyGothic': 'Helvetica',
  18764. 'CenturyGothic-Bold': 'Helvetica-Bold',
  18765. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  18766. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  18767. 'ComicSansMS': 'Comic Sans MS',
  18768. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  18769. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  18770. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  18771. 'LucidaConsole': 'Courier',
  18772. 'LucidaConsole-Bold': 'Courier-Bold',
  18773. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  18774. 'LucidaConsole-Italic': 'Courier-Oblique',
  18775. 'MS-Gothic': 'MS Gothic',
  18776. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  18777. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  18778. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  18779. 'MS-Mincho': 'MS Mincho',
  18780. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  18781. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  18782. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  18783. 'MS-PGothic': 'MS PGothic',
  18784. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  18785. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  18786. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  18787. 'MS-PMincho': 'MS PMincho',
  18788. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  18789. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  18790. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  18791. 'Wingdings': 'ZapfDingbats'
  18792. };
  18793. var serifFonts = {
  18794. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  18795. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  18796. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  18797. 'Arno': true, 'Aster': true, 'Aurora': true,
  18798. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  18799. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  18800. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  18801. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  18802. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  18803. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  18804. 'Cartier': true, 'Caslon': true, 'Catull': true,
  18805. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  18806. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  18807. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  18808. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  18809. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  18810. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  18811. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  18812. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  18813. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  18814. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  18815. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  18816. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  18817. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  18818. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  18819. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  18820. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  18821. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  18822. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  18823. 'Miller': true, 'Minion': true, 'Modern': true,
  18824. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  18825. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  18826. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  18827. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  18828. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  18829. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  18830. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  18831. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  18832. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  18833. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  18834. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  18835. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  18836. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  18837. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  18838. };
  18839. var symbolsFonts = {
  18840. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  18841. };
  18842. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  18843. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  18844. // glyphs, but common for some set of the standard fonts.
  18845. var GlyphMapForStandardFonts = {
  18846. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  18847. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  18848. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  18849. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  18850. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  18851. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  18852. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  18853. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  18854. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  18855. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  18856. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  18857. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  18858. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  18859. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  18860. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  18861. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  18862. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  18863. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  18864. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  18865. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  18866. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  18867. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  18868. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  18869. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  18870. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  18871. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  18872. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  18873. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  18874. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  18875. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  18876. '298': 380, '305': 963,
  18877. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  18878. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  18879. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  18880. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  18881. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  18882. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  18883. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  18884. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  18885. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  18886. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  18887. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  18888. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  18889. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  18890. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  18891. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  18892. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  18893. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  18894. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  18895. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  18896. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  18897. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  18898. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  18899. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  18900. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  18901. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  18902. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  18903. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  18904. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  18905. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  18906. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  18907. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  18908. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  18909. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  18910. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  18911. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  18912. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  18913. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  18914. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  18915. };
  18916. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  18917. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  18918. // to the similar equivalents in the normal characters range.
  18919. var SpecialPUASymbols = {
  18920. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  18921. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  18922. '63720': 0x00AE, // registersans (0xF8E8) => registered
  18923. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  18924. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  18925. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  18926. '63729': 0x23A7, // bracelefttp (0xF8F1)
  18927. '63730': 0x23A8, // braceleftmid (0xF8F2)
  18928. '63731': 0x23A9, // braceleftbt (0xF8F3)
  18929. '63740': 0x23AB, // bracerighttp (0xF8FC)
  18930. '63741': 0x23AC, // bracerightmid (0xF8FD)
  18931. '63742': 0x23AD, // bracerightbt (0xF8FE)
  18932. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  18933. '63727': 0x23A2, // bracketleftex (0xF8EF)
  18934. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  18935. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  18936. '63738': 0x23A5, // bracketrightex (0xF8FA)
  18937. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  18938. '63723': 0x239B, // parenlefttp (0xF8EB)
  18939. '63724': 0x239C, // parenleftex (0xF8EC)
  18940. '63725': 0x239D, // parenleftbt (0xF8ED)
  18941. '63734': 0x239E, // parenrighttp (0xF8F6)
  18942. '63735': 0x239F, // parenrightex (0xF8F7)
  18943. '63736': 0x23A0, // parenrightbt (0xF8F8)
  18944. };
  18945. function mapSpecialUnicodeValues(code) {
  18946. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  18947. return 0;
  18948. } else if (code >= 0xF600 && code <= 0xF8FF) {
  18949. return (SpecialPUASymbols[code] || code);
  18950. }
  18951. return code;
  18952. }
  18953. var UnicodeRanges = [
  18954. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  18955. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  18956. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  18957. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  18958. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  18959. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  18960. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  18961. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  18962. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  18963. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  18964. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  18965. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  18966. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  18967. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  18968. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  18969. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  18970. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  18971. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  18972. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  18973. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  18974. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  18975. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  18976. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  18977. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  18978. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  18979. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  18980. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  18981. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  18982. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  18983. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  18984. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  18985. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  18986. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  18987. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  18988. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  18989. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  18990. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  18991. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  18992. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  18993. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  18994. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  18995. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  18996. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  18997. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  18998. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  18999. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  19000. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  19001. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  19002. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  19003. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  19004. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  19005. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  19006. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  19007. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  19008. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  19009. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  19010. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  19011. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  19012. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  19013. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  19014. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  19015. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  19016. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  19017. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  19018. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  19019. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  19020. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  19021. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  19022. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  19023. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  19024. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  19025. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  19026. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  19027. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  19028. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  19029. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  19030. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  19031. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  19032. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  19033. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  19034. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  19035. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  19036. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  19037. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  19038. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  19039. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  19040. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  19041. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  19042. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  19043. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  19044. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  19045. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  19046. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  19047. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  19048. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  19049. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  19050. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  19051. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  19052. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  19053. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  19054. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  19055. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  19056. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  19057. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  19058. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  19059. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  19060. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  19061. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  19062. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  19063. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  19064. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  19065. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  19066. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  19067. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  19068. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  19069. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  19070. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  19071. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  19072. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  19073. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  19074. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  19075. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  19076. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  19077. ];
  19078. var MacStandardGlyphOrdering = [
  19079. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  19080. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  19081. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  19082. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  19083. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  19084. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  19085. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  19086. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  19087. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  19088. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  19089. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  19090. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  19091. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  19092. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  19093. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  19094. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  19095. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  19096. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  19097. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  19098. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  19099. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  19100. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  19101. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  19102. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  19103. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  19104. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  19105. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  19106. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  19107. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  19108. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  19109. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  19110. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  19111. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  19112. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  19113. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  19114. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  19115. function getUnicodeRangeFor(value) {
  19116. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  19117. var range = UnicodeRanges[i];
  19118. if (value >= range.begin && value < range.end) {
  19119. return i;
  19120. }
  19121. }
  19122. return -1;
  19123. }
  19124. function isRTLRangeFor(value) {
  19125. var range = UnicodeRanges[13];
  19126. if (value >= range.begin && value < range.end) {
  19127. return true;
  19128. }
  19129. range = UnicodeRanges[11];
  19130. if (value >= range.begin && value < range.end) {
  19131. return true;
  19132. }
  19133. return false;
  19134. }
  19135. // The normalization table is obtained by filtering the Unicode characters
  19136. // database with <compat> entries.
  19137. var NormalizedUnicodes = {
  19138. '\u00A8': '\u0020\u0308',
  19139. '\u00AF': '\u0020\u0304',
  19140. '\u00B4': '\u0020\u0301',
  19141. '\u00B5': '\u03BC',
  19142. '\u00B8': '\u0020\u0327',
  19143. '\u0132': '\u0049\u004A',
  19144. '\u0133': '\u0069\u006A',
  19145. '\u013F': '\u004C\u00B7',
  19146. '\u0140': '\u006C\u00B7',
  19147. '\u0149': '\u02BC\u006E',
  19148. '\u017F': '\u0073',
  19149. '\u01C4': '\u0044\u017D',
  19150. '\u01C5': '\u0044\u017E',
  19151. '\u01C6': '\u0064\u017E',
  19152. '\u01C7': '\u004C\u004A',
  19153. '\u01C8': '\u004C\u006A',
  19154. '\u01C9': '\u006C\u006A',
  19155. '\u01CA': '\u004E\u004A',
  19156. '\u01CB': '\u004E\u006A',
  19157. '\u01CC': '\u006E\u006A',
  19158. '\u01F1': '\u0044\u005A',
  19159. '\u01F2': '\u0044\u007A',
  19160. '\u01F3': '\u0064\u007A',
  19161. '\u02D8': '\u0020\u0306',
  19162. '\u02D9': '\u0020\u0307',
  19163. '\u02DA': '\u0020\u030A',
  19164. '\u02DB': '\u0020\u0328',
  19165. '\u02DC': '\u0020\u0303',
  19166. '\u02DD': '\u0020\u030B',
  19167. '\u037A': '\u0020\u0345',
  19168. '\u0384': '\u0020\u0301',
  19169. '\u03D0': '\u03B2',
  19170. '\u03D1': '\u03B8',
  19171. '\u03D2': '\u03A5',
  19172. '\u03D5': '\u03C6',
  19173. '\u03D6': '\u03C0',
  19174. '\u03F0': '\u03BA',
  19175. '\u03F1': '\u03C1',
  19176. '\u03F2': '\u03C2',
  19177. '\u03F4': '\u0398',
  19178. '\u03F5': '\u03B5',
  19179. '\u03F9': '\u03A3',
  19180. '\u0587': '\u0565\u0582',
  19181. '\u0675': '\u0627\u0674',
  19182. '\u0676': '\u0648\u0674',
  19183. '\u0677': '\u06C7\u0674',
  19184. '\u0678': '\u064A\u0674',
  19185. '\u0E33': '\u0E4D\u0E32',
  19186. '\u0EB3': '\u0ECD\u0EB2',
  19187. '\u0EDC': '\u0EAB\u0E99',
  19188. '\u0EDD': '\u0EAB\u0EA1',
  19189. '\u0F77': '\u0FB2\u0F81',
  19190. '\u0F79': '\u0FB3\u0F81',
  19191. '\u1E9A': '\u0061\u02BE',
  19192. '\u1FBD': '\u0020\u0313',
  19193. '\u1FBF': '\u0020\u0313',
  19194. '\u1FC0': '\u0020\u0342',
  19195. '\u1FFE': '\u0020\u0314',
  19196. '\u2002': '\u0020',
  19197. '\u2003': '\u0020',
  19198. '\u2004': '\u0020',
  19199. '\u2005': '\u0020',
  19200. '\u2006': '\u0020',
  19201. '\u2008': '\u0020',
  19202. '\u2009': '\u0020',
  19203. '\u200A': '\u0020',
  19204. '\u2017': '\u0020\u0333',
  19205. '\u2024': '\u002E',
  19206. '\u2025': '\u002E\u002E',
  19207. '\u2026': '\u002E\u002E\u002E',
  19208. '\u2033': '\u2032\u2032',
  19209. '\u2034': '\u2032\u2032\u2032',
  19210. '\u2036': '\u2035\u2035',
  19211. '\u2037': '\u2035\u2035\u2035',
  19212. '\u203C': '\u0021\u0021',
  19213. '\u203E': '\u0020\u0305',
  19214. '\u2047': '\u003F\u003F',
  19215. '\u2048': '\u003F\u0021',
  19216. '\u2049': '\u0021\u003F',
  19217. '\u2057': '\u2032\u2032\u2032\u2032',
  19218. '\u205F': '\u0020',
  19219. '\u20A8': '\u0052\u0073',
  19220. '\u2100': '\u0061\u002F\u0063',
  19221. '\u2101': '\u0061\u002F\u0073',
  19222. '\u2103': '\u00B0\u0043',
  19223. '\u2105': '\u0063\u002F\u006F',
  19224. '\u2106': '\u0063\u002F\u0075',
  19225. '\u2107': '\u0190',
  19226. '\u2109': '\u00B0\u0046',
  19227. '\u2116': '\u004E\u006F',
  19228. '\u2121': '\u0054\u0045\u004C',
  19229. '\u2135': '\u05D0',
  19230. '\u2136': '\u05D1',
  19231. '\u2137': '\u05D2',
  19232. '\u2138': '\u05D3',
  19233. '\u213B': '\u0046\u0041\u0058',
  19234. '\u2160': '\u0049',
  19235. '\u2161': '\u0049\u0049',
  19236. '\u2162': '\u0049\u0049\u0049',
  19237. '\u2163': '\u0049\u0056',
  19238. '\u2164': '\u0056',
  19239. '\u2165': '\u0056\u0049',
  19240. '\u2166': '\u0056\u0049\u0049',
  19241. '\u2167': '\u0056\u0049\u0049\u0049',
  19242. '\u2168': '\u0049\u0058',
  19243. '\u2169': '\u0058',
  19244. '\u216A': '\u0058\u0049',
  19245. '\u216B': '\u0058\u0049\u0049',
  19246. '\u216C': '\u004C',
  19247. '\u216D': '\u0043',
  19248. '\u216E': '\u0044',
  19249. '\u216F': '\u004D',
  19250. '\u2170': '\u0069',
  19251. '\u2171': '\u0069\u0069',
  19252. '\u2172': '\u0069\u0069\u0069',
  19253. '\u2173': '\u0069\u0076',
  19254. '\u2174': '\u0076',
  19255. '\u2175': '\u0076\u0069',
  19256. '\u2176': '\u0076\u0069\u0069',
  19257. '\u2177': '\u0076\u0069\u0069\u0069',
  19258. '\u2178': '\u0069\u0078',
  19259. '\u2179': '\u0078',
  19260. '\u217A': '\u0078\u0069',
  19261. '\u217B': '\u0078\u0069\u0069',
  19262. '\u217C': '\u006C',
  19263. '\u217D': '\u0063',
  19264. '\u217E': '\u0064',
  19265. '\u217F': '\u006D',
  19266. '\u222C': '\u222B\u222B',
  19267. '\u222D': '\u222B\u222B\u222B',
  19268. '\u222F': '\u222E\u222E',
  19269. '\u2230': '\u222E\u222E\u222E',
  19270. '\u2474': '\u0028\u0031\u0029',
  19271. '\u2475': '\u0028\u0032\u0029',
  19272. '\u2476': '\u0028\u0033\u0029',
  19273. '\u2477': '\u0028\u0034\u0029',
  19274. '\u2478': '\u0028\u0035\u0029',
  19275. '\u2479': '\u0028\u0036\u0029',
  19276. '\u247A': '\u0028\u0037\u0029',
  19277. '\u247B': '\u0028\u0038\u0029',
  19278. '\u247C': '\u0028\u0039\u0029',
  19279. '\u247D': '\u0028\u0031\u0030\u0029',
  19280. '\u247E': '\u0028\u0031\u0031\u0029',
  19281. '\u247F': '\u0028\u0031\u0032\u0029',
  19282. '\u2480': '\u0028\u0031\u0033\u0029',
  19283. '\u2481': '\u0028\u0031\u0034\u0029',
  19284. '\u2482': '\u0028\u0031\u0035\u0029',
  19285. '\u2483': '\u0028\u0031\u0036\u0029',
  19286. '\u2484': '\u0028\u0031\u0037\u0029',
  19287. '\u2485': '\u0028\u0031\u0038\u0029',
  19288. '\u2486': '\u0028\u0031\u0039\u0029',
  19289. '\u2487': '\u0028\u0032\u0030\u0029',
  19290. '\u2488': '\u0031\u002E',
  19291. '\u2489': '\u0032\u002E',
  19292. '\u248A': '\u0033\u002E',
  19293. '\u248B': '\u0034\u002E',
  19294. '\u248C': '\u0035\u002E',
  19295. '\u248D': '\u0036\u002E',
  19296. '\u248E': '\u0037\u002E',
  19297. '\u248F': '\u0038\u002E',
  19298. '\u2490': '\u0039\u002E',
  19299. '\u2491': '\u0031\u0030\u002E',
  19300. '\u2492': '\u0031\u0031\u002E',
  19301. '\u2493': '\u0031\u0032\u002E',
  19302. '\u2494': '\u0031\u0033\u002E',
  19303. '\u2495': '\u0031\u0034\u002E',
  19304. '\u2496': '\u0031\u0035\u002E',
  19305. '\u2497': '\u0031\u0036\u002E',
  19306. '\u2498': '\u0031\u0037\u002E',
  19307. '\u2499': '\u0031\u0038\u002E',
  19308. '\u249A': '\u0031\u0039\u002E',
  19309. '\u249B': '\u0032\u0030\u002E',
  19310. '\u249C': '\u0028\u0061\u0029',
  19311. '\u249D': '\u0028\u0062\u0029',
  19312. '\u249E': '\u0028\u0063\u0029',
  19313. '\u249F': '\u0028\u0064\u0029',
  19314. '\u24A0': '\u0028\u0065\u0029',
  19315. '\u24A1': '\u0028\u0066\u0029',
  19316. '\u24A2': '\u0028\u0067\u0029',
  19317. '\u24A3': '\u0028\u0068\u0029',
  19318. '\u24A4': '\u0028\u0069\u0029',
  19319. '\u24A5': '\u0028\u006A\u0029',
  19320. '\u24A6': '\u0028\u006B\u0029',
  19321. '\u24A7': '\u0028\u006C\u0029',
  19322. '\u24A8': '\u0028\u006D\u0029',
  19323. '\u24A9': '\u0028\u006E\u0029',
  19324. '\u24AA': '\u0028\u006F\u0029',
  19325. '\u24AB': '\u0028\u0070\u0029',
  19326. '\u24AC': '\u0028\u0071\u0029',
  19327. '\u24AD': '\u0028\u0072\u0029',
  19328. '\u24AE': '\u0028\u0073\u0029',
  19329. '\u24AF': '\u0028\u0074\u0029',
  19330. '\u24B0': '\u0028\u0075\u0029',
  19331. '\u24B1': '\u0028\u0076\u0029',
  19332. '\u24B2': '\u0028\u0077\u0029',
  19333. '\u24B3': '\u0028\u0078\u0029',
  19334. '\u24B4': '\u0028\u0079\u0029',
  19335. '\u24B5': '\u0028\u007A\u0029',
  19336. '\u2A0C': '\u222B\u222B\u222B\u222B',
  19337. '\u2A74': '\u003A\u003A\u003D',
  19338. '\u2A75': '\u003D\u003D',
  19339. '\u2A76': '\u003D\u003D\u003D',
  19340. '\u2E9F': '\u6BCD',
  19341. '\u2EF3': '\u9F9F',
  19342. '\u2F00': '\u4E00',
  19343. '\u2F01': '\u4E28',
  19344. '\u2F02': '\u4E36',
  19345. '\u2F03': '\u4E3F',
  19346. '\u2F04': '\u4E59',
  19347. '\u2F05': '\u4E85',
  19348. '\u2F06': '\u4E8C',
  19349. '\u2F07': '\u4EA0',
  19350. '\u2F08': '\u4EBA',
  19351. '\u2F09': '\u513F',
  19352. '\u2F0A': '\u5165',
  19353. '\u2F0B': '\u516B',
  19354. '\u2F0C': '\u5182',
  19355. '\u2F0D': '\u5196',
  19356. '\u2F0E': '\u51AB',
  19357. '\u2F0F': '\u51E0',
  19358. '\u2F10': '\u51F5',
  19359. '\u2F11': '\u5200',
  19360. '\u2F12': '\u529B',
  19361. '\u2F13': '\u52F9',
  19362. '\u2F14': '\u5315',
  19363. '\u2F15': '\u531A',
  19364. '\u2F16': '\u5338',
  19365. '\u2F17': '\u5341',
  19366. '\u2F18': '\u535C',
  19367. '\u2F19': '\u5369',
  19368. '\u2F1A': '\u5382',
  19369. '\u2F1B': '\u53B6',
  19370. '\u2F1C': '\u53C8',
  19371. '\u2F1D': '\u53E3',
  19372. '\u2F1E': '\u56D7',
  19373. '\u2F1F': '\u571F',
  19374. '\u2F20': '\u58EB',
  19375. '\u2F21': '\u5902',
  19376. '\u2F22': '\u590A',
  19377. '\u2F23': '\u5915',
  19378. '\u2F24': '\u5927',
  19379. '\u2F25': '\u5973',
  19380. '\u2F26': '\u5B50',
  19381. '\u2F27': '\u5B80',
  19382. '\u2F28': '\u5BF8',
  19383. '\u2F29': '\u5C0F',
  19384. '\u2F2A': '\u5C22',
  19385. '\u2F2B': '\u5C38',
  19386. '\u2F2C': '\u5C6E',
  19387. '\u2F2D': '\u5C71',
  19388. '\u2F2E': '\u5DDB',
  19389. '\u2F2F': '\u5DE5',
  19390. '\u2F30': '\u5DF1',
  19391. '\u2F31': '\u5DFE',
  19392. '\u2F32': '\u5E72',
  19393. '\u2F33': '\u5E7A',
  19394. '\u2F34': '\u5E7F',
  19395. '\u2F35': '\u5EF4',
  19396. '\u2F36': '\u5EFE',
  19397. '\u2F37': '\u5F0B',
  19398. '\u2F38': '\u5F13',
  19399. '\u2F39': '\u5F50',
  19400. '\u2F3A': '\u5F61',
  19401. '\u2F3B': '\u5F73',
  19402. '\u2F3C': '\u5FC3',
  19403. '\u2F3D': '\u6208',
  19404. '\u2F3E': '\u6236',
  19405. '\u2F3F': '\u624B',
  19406. '\u2F40': '\u652F',
  19407. '\u2F41': '\u6534',
  19408. '\u2F42': '\u6587',
  19409. '\u2F43': '\u6597',
  19410. '\u2F44': '\u65A4',
  19411. '\u2F45': '\u65B9',
  19412. '\u2F46': '\u65E0',
  19413. '\u2F47': '\u65E5',
  19414. '\u2F48': '\u66F0',
  19415. '\u2F49': '\u6708',
  19416. '\u2F4A': '\u6728',
  19417. '\u2F4B': '\u6B20',
  19418. '\u2F4C': '\u6B62',
  19419. '\u2F4D': '\u6B79',
  19420. '\u2F4E': '\u6BB3',
  19421. '\u2F4F': '\u6BCB',
  19422. '\u2F50': '\u6BD4',
  19423. '\u2F51': '\u6BDB',
  19424. '\u2F52': '\u6C0F',
  19425. '\u2F53': '\u6C14',
  19426. '\u2F54': '\u6C34',
  19427. '\u2F55': '\u706B',
  19428. '\u2F56': '\u722A',
  19429. '\u2F57': '\u7236',
  19430. '\u2F58': '\u723B',
  19431. '\u2F59': '\u723F',
  19432. '\u2F5A': '\u7247',
  19433. '\u2F5B': '\u7259',
  19434. '\u2F5C': '\u725B',
  19435. '\u2F5D': '\u72AC',
  19436. '\u2F5E': '\u7384',
  19437. '\u2F5F': '\u7389',
  19438. '\u2F60': '\u74DC',
  19439. '\u2F61': '\u74E6',
  19440. '\u2F62': '\u7518',
  19441. '\u2F63': '\u751F',
  19442. '\u2F64': '\u7528',
  19443. '\u2F65': '\u7530',
  19444. '\u2F66': '\u758B',
  19445. '\u2F67': '\u7592',
  19446. '\u2F68': '\u7676',
  19447. '\u2F69': '\u767D',
  19448. '\u2F6A': '\u76AE',
  19449. '\u2F6B': '\u76BF',
  19450. '\u2F6C': '\u76EE',
  19451. '\u2F6D': '\u77DB',
  19452. '\u2F6E': '\u77E2',
  19453. '\u2F6F': '\u77F3',
  19454. '\u2F70': '\u793A',
  19455. '\u2F71': '\u79B8',
  19456. '\u2F72': '\u79BE',
  19457. '\u2F73': '\u7A74',
  19458. '\u2F74': '\u7ACB',
  19459. '\u2F75': '\u7AF9',
  19460. '\u2F76': '\u7C73',
  19461. '\u2F77': '\u7CF8',
  19462. '\u2F78': '\u7F36',
  19463. '\u2F79': '\u7F51',
  19464. '\u2F7A': '\u7F8A',
  19465. '\u2F7B': '\u7FBD',
  19466. '\u2F7C': '\u8001',
  19467. '\u2F7D': '\u800C',
  19468. '\u2F7E': '\u8012',
  19469. '\u2F7F': '\u8033',
  19470. '\u2F80': '\u807F',
  19471. '\u2F81': '\u8089',
  19472. '\u2F82': '\u81E3',
  19473. '\u2F83': '\u81EA',
  19474. '\u2F84': '\u81F3',
  19475. '\u2F85': '\u81FC',
  19476. '\u2F86': '\u820C',
  19477. '\u2F87': '\u821B',
  19478. '\u2F88': '\u821F',
  19479. '\u2F89': '\u826E',
  19480. '\u2F8A': '\u8272',
  19481. '\u2F8B': '\u8278',
  19482. '\u2F8C': '\u864D',
  19483. '\u2F8D': '\u866B',
  19484. '\u2F8E': '\u8840',
  19485. '\u2F8F': '\u884C',
  19486. '\u2F90': '\u8863',
  19487. '\u2F91': '\u897E',
  19488. '\u2F92': '\u898B',
  19489. '\u2F93': '\u89D2',
  19490. '\u2F94': '\u8A00',
  19491. '\u2F95': '\u8C37',
  19492. '\u2F96': '\u8C46',
  19493. '\u2F97': '\u8C55',
  19494. '\u2F98': '\u8C78',
  19495. '\u2F99': '\u8C9D',
  19496. '\u2F9A': '\u8D64',
  19497. '\u2F9B': '\u8D70',
  19498. '\u2F9C': '\u8DB3',
  19499. '\u2F9D': '\u8EAB',
  19500. '\u2F9E': '\u8ECA',
  19501. '\u2F9F': '\u8F9B',
  19502. '\u2FA0': '\u8FB0',
  19503. '\u2FA1': '\u8FB5',
  19504. '\u2FA2': '\u9091',
  19505. '\u2FA3': '\u9149',
  19506. '\u2FA4': '\u91C6',
  19507. '\u2FA5': '\u91CC',
  19508. '\u2FA6': '\u91D1',
  19509. '\u2FA7': '\u9577',
  19510. '\u2FA8': '\u9580',
  19511. '\u2FA9': '\u961C',
  19512. '\u2FAA': '\u96B6',
  19513. '\u2FAB': '\u96B9',
  19514. '\u2FAC': '\u96E8',
  19515. '\u2FAD': '\u9751',
  19516. '\u2FAE': '\u975E',
  19517. '\u2FAF': '\u9762',
  19518. '\u2FB0': '\u9769',
  19519. '\u2FB1': '\u97CB',
  19520. '\u2FB2': '\u97ED',
  19521. '\u2FB3': '\u97F3',
  19522. '\u2FB4': '\u9801',
  19523. '\u2FB5': '\u98A8',
  19524. '\u2FB6': '\u98DB',
  19525. '\u2FB7': '\u98DF',
  19526. '\u2FB8': '\u9996',
  19527. '\u2FB9': '\u9999',
  19528. '\u2FBA': '\u99AC',
  19529. '\u2FBB': '\u9AA8',
  19530. '\u2FBC': '\u9AD8',
  19531. '\u2FBD': '\u9ADF',
  19532. '\u2FBE': '\u9B25',
  19533. '\u2FBF': '\u9B2F',
  19534. '\u2FC0': '\u9B32',
  19535. '\u2FC1': '\u9B3C',
  19536. '\u2FC2': '\u9B5A',
  19537. '\u2FC3': '\u9CE5',
  19538. '\u2FC4': '\u9E75',
  19539. '\u2FC5': '\u9E7F',
  19540. '\u2FC6': '\u9EA5',
  19541. '\u2FC7': '\u9EBB',
  19542. '\u2FC8': '\u9EC3',
  19543. '\u2FC9': '\u9ECD',
  19544. '\u2FCA': '\u9ED1',
  19545. '\u2FCB': '\u9EF9',
  19546. '\u2FCC': '\u9EFD',
  19547. '\u2FCD': '\u9F0E',
  19548. '\u2FCE': '\u9F13',
  19549. '\u2FCF': '\u9F20',
  19550. '\u2FD0': '\u9F3B',
  19551. '\u2FD1': '\u9F4A',
  19552. '\u2FD2': '\u9F52',
  19553. '\u2FD3': '\u9F8D',
  19554. '\u2FD4': '\u9F9C',
  19555. '\u2FD5': '\u9FA0',
  19556. '\u3036': '\u3012',
  19557. '\u3038': '\u5341',
  19558. '\u3039': '\u5344',
  19559. '\u303A': '\u5345',
  19560. '\u309B': '\u0020\u3099',
  19561. '\u309C': '\u0020\u309A',
  19562. '\u3131': '\u1100',
  19563. '\u3132': '\u1101',
  19564. '\u3133': '\u11AA',
  19565. '\u3134': '\u1102',
  19566. '\u3135': '\u11AC',
  19567. '\u3136': '\u11AD',
  19568. '\u3137': '\u1103',
  19569. '\u3138': '\u1104',
  19570. '\u3139': '\u1105',
  19571. '\u313A': '\u11B0',
  19572. '\u313B': '\u11B1',
  19573. '\u313C': '\u11B2',
  19574. '\u313D': '\u11B3',
  19575. '\u313E': '\u11B4',
  19576. '\u313F': '\u11B5',
  19577. '\u3140': '\u111A',
  19578. '\u3141': '\u1106',
  19579. '\u3142': '\u1107',
  19580. '\u3143': '\u1108',
  19581. '\u3144': '\u1121',
  19582. '\u3145': '\u1109',
  19583. '\u3146': '\u110A',
  19584. '\u3147': '\u110B',
  19585. '\u3148': '\u110C',
  19586. '\u3149': '\u110D',
  19587. '\u314A': '\u110E',
  19588. '\u314B': '\u110F',
  19589. '\u314C': '\u1110',
  19590. '\u314D': '\u1111',
  19591. '\u314E': '\u1112',
  19592. '\u314F': '\u1161',
  19593. '\u3150': '\u1162',
  19594. '\u3151': '\u1163',
  19595. '\u3152': '\u1164',
  19596. '\u3153': '\u1165',
  19597. '\u3154': '\u1166',
  19598. '\u3155': '\u1167',
  19599. '\u3156': '\u1168',
  19600. '\u3157': '\u1169',
  19601. '\u3158': '\u116A',
  19602. '\u3159': '\u116B',
  19603. '\u315A': '\u116C',
  19604. '\u315B': '\u116D',
  19605. '\u315C': '\u116E',
  19606. '\u315D': '\u116F',
  19607. '\u315E': '\u1170',
  19608. '\u315F': '\u1171',
  19609. '\u3160': '\u1172',
  19610. '\u3161': '\u1173',
  19611. '\u3162': '\u1174',
  19612. '\u3163': '\u1175',
  19613. '\u3164': '\u1160',
  19614. '\u3165': '\u1114',
  19615. '\u3166': '\u1115',
  19616. '\u3167': '\u11C7',
  19617. '\u3168': '\u11C8',
  19618. '\u3169': '\u11CC',
  19619. '\u316A': '\u11CE',
  19620. '\u316B': '\u11D3',
  19621. '\u316C': '\u11D7',
  19622. '\u316D': '\u11D9',
  19623. '\u316E': '\u111C',
  19624. '\u316F': '\u11DD',
  19625. '\u3170': '\u11DF',
  19626. '\u3171': '\u111D',
  19627. '\u3172': '\u111E',
  19628. '\u3173': '\u1120',
  19629. '\u3174': '\u1122',
  19630. '\u3175': '\u1123',
  19631. '\u3176': '\u1127',
  19632. '\u3177': '\u1129',
  19633. '\u3178': '\u112B',
  19634. '\u3179': '\u112C',
  19635. '\u317A': '\u112D',
  19636. '\u317B': '\u112E',
  19637. '\u317C': '\u112F',
  19638. '\u317D': '\u1132',
  19639. '\u317E': '\u1136',
  19640. '\u317F': '\u1140',
  19641. '\u3180': '\u1147',
  19642. '\u3181': '\u114C',
  19643. '\u3182': '\u11F1',
  19644. '\u3183': '\u11F2',
  19645. '\u3184': '\u1157',
  19646. '\u3185': '\u1158',
  19647. '\u3186': '\u1159',
  19648. '\u3187': '\u1184',
  19649. '\u3188': '\u1185',
  19650. '\u3189': '\u1188',
  19651. '\u318A': '\u1191',
  19652. '\u318B': '\u1192',
  19653. '\u318C': '\u1194',
  19654. '\u318D': '\u119E',
  19655. '\u318E': '\u11A1',
  19656. '\u3200': '\u0028\u1100\u0029',
  19657. '\u3201': '\u0028\u1102\u0029',
  19658. '\u3202': '\u0028\u1103\u0029',
  19659. '\u3203': '\u0028\u1105\u0029',
  19660. '\u3204': '\u0028\u1106\u0029',
  19661. '\u3205': '\u0028\u1107\u0029',
  19662. '\u3206': '\u0028\u1109\u0029',
  19663. '\u3207': '\u0028\u110B\u0029',
  19664. '\u3208': '\u0028\u110C\u0029',
  19665. '\u3209': '\u0028\u110E\u0029',
  19666. '\u320A': '\u0028\u110F\u0029',
  19667. '\u320B': '\u0028\u1110\u0029',
  19668. '\u320C': '\u0028\u1111\u0029',
  19669. '\u320D': '\u0028\u1112\u0029',
  19670. '\u320E': '\u0028\u1100\u1161\u0029',
  19671. '\u320F': '\u0028\u1102\u1161\u0029',
  19672. '\u3210': '\u0028\u1103\u1161\u0029',
  19673. '\u3211': '\u0028\u1105\u1161\u0029',
  19674. '\u3212': '\u0028\u1106\u1161\u0029',
  19675. '\u3213': '\u0028\u1107\u1161\u0029',
  19676. '\u3214': '\u0028\u1109\u1161\u0029',
  19677. '\u3215': '\u0028\u110B\u1161\u0029',
  19678. '\u3216': '\u0028\u110C\u1161\u0029',
  19679. '\u3217': '\u0028\u110E\u1161\u0029',
  19680. '\u3218': '\u0028\u110F\u1161\u0029',
  19681. '\u3219': '\u0028\u1110\u1161\u0029',
  19682. '\u321A': '\u0028\u1111\u1161\u0029',
  19683. '\u321B': '\u0028\u1112\u1161\u0029',
  19684. '\u321C': '\u0028\u110C\u116E\u0029',
  19685. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  19686. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  19687. '\u3220': '\u0028\u4E00\u0029',
  19688. '\u3221': '\u0028\u4E8C\u0029',
  19689. '\u3222': '\u0028\u4E09\u0029',
  19690. '\u3223': '\u0028\u56DB\u0029',
  19691. '\u3224': '\u0028\u4E94\u0029',
  19692. '\u3225': '\u0028\u516D\u0029',
  19693. '\u3226': '\u0028\u4E03\u0029',
  19694. '\u3227': '\u0028\u516B\u0029',
  19695. '\u3228': '\u0028\u4E5D\u0029',
  19696. '\u3229': '\u0028\u5341\u0029',
  19697. '\u322A': '\u0028\u6708\u0029',
  19698. '\u322B': '\u0028\u706B\u0029',
  19699. '\u322C': '\u0028\u6C34\u0029',
  19700. '\u322D': '\u0028\u6728\u0029',
  19701. '\u322E': '\u0028\u91D1\u0029',
  19702. '\u322F': '\u0028\u571F\u0029',
  19703. '\u3230': '\u0028\u65E5\u0029',
  19704. '\u3231': '\u0028\u682A\u0029',
  19705. '\u3232': '\u0028\u6709\u0029',
  19706. '\u3233': '\u0028\u793E\u0029',
  19707. '\u3234': '\u0028\u540D\u0029',
  19708. '\u3235': '\u0028\u7279\u0029',
  19709. '\u3236': '\u0028\u8CA1\u0029',
  19710. '\u3237': '\u0028\u795D\u0029',
  19711. '\u3238': '\u0028\u52B4\u0029',
  19712. '\u3239': '\u0028\u4EE3\u0029',
  19713. '\u323A': '\u0028\u547C\u0029',
  19714. '\u323B': '\u0028\u5B66\u0029',
  19715. '\u323C': '\u0028\u76E3\u0029',
  19716. '\u323D': '\u0028\u4F01\u0029',
  19717. '\u323E': '\u0028\u8CC7\u0029',
  19718. '\u323F': '\u0028\u5354\u0029',
  19719. '\u3240': '\u0028\u796D\u0029',
  19720. '\u3241': '\u0028\u4F11\u0029',
  19721. '\u3242': '\u0028\u81EA\u0029',
  19722. '\u3243': '\u0028\u81F3\u0029',
  19723. '\u32C0': '\u0031\u6708',
  19724. '\u32C1': '\u0032\u6708',
  19725. '\u32C2': '\u0033\u6708',
  19726. '\u32C3': '\u0034\u6708',
  19727. '\u32C4': '\u0035\u6708',
  19728. '\u32C5': '\u0036\u6708',
  19729. '\u32C6': '\u0037\u6708',
  19730. '\u32C7': '\u0038\u6708',
  19731. '\u32C8': '\u0039\u6708',
  19732. '\u32C9': '\u0031\u0030\u6708',
  19733. '\u32CA': '\u0031\u0031\u6708',
  19734. '\u32CB': '\u0031\u0032\u6708',
  19735. '\u3358': '\u0030\u70B9',
  19736. '\u3359': '\u0031\u70B9',
  19737. '\u335A': '\u0032\u70B9',
  19738. '\u335B': '\u0033\u70B9',
  19739. '\u335C': '\u0034\u70B9',
  19740. '\u335D': '\u0035\u70B9',
  19741. '\u335E': '\u0036\u70B9',
  19742. '\u335F': '\u0037\u70B9',
  19743. '\u3360': '\u0038\u70B9',
  19744. '\u3361': '\u0039\u70B9',
  19745. '\u3362': '\u0031\u0030\u70B9',
  19746. '\u3363': '\u0031\u0031\u70B9',
  19747. '\u3364': '\u0031\u0032\u70B9',
  19748. '\u3365': '\u0031\u0033\u70B9',
  19749. '\u3366': '\u0031\u0034\u70B9',
  19750. '\u3367': '\u0031\u0035\u70B9',
  19751. '\u3368': '\u0031\u0036\u70B9',
  19752. '\u3369': '\u0031\u0037\u70B9',
  19753. '\u336A': '\u0031\u0038\u70B9',
  19754. '\u336B': '\u0031\u0039\u70B9',
  19755. '\u336C': '\u0032\u0030\u70B9',
  19756. '\u336D': '\u0032\u0031\u70B9',
  19757. '\u336E': '\u0032\u0032\u70B9',
  19758. '\u336F': '\u0032\u0033\u70B9',
  19759. '\u3370': '\u0032\u0034\u70B9',
  19760. '\u33E0': '\u0031\u65E5',
  19761. '\u33E1': '\u0032\u65E5',
  19762. '\u33E2': '\u0033\u65E5',
  19763. '\u33E3': '\u0034\u65E5',
  19764. '\u33E4': '\u0035\u65E5',
  19765. '\u33E5': '\u0036\u65E5',
  19766. '\u33E6': '\u0037\u65E5',
  19767. '\u33E7': '\u0038\u65E5',
  19768. '\u33E8': '\u0039\u65E5',
  19769. '\u33E9': '\u0031\u0030\u65E5',
  19770. '\u33EA': '\u0031\u0031\u65E5',
  19771. '\u33EB': '\u0031\u0032\u65E5',
  19772. '\u33EC': '\u0031\u0033\u65E5',
  19773. '\u33ED': '\u0031\u0034\u65E5',
  19774. '\u33EE': '\u0031\u0035\u65E5',
  19775. '\u33EF': '\u0031\u0036\u65E5',
  19776. '\u33F0': '\u0031\u0037\u65E5',
  19777. '\u33F1': '\u0031\u0038\u65E5',
  19778. '\u33F2': '\u0031\u0039\u65E5',
  19779. '\u33F3': '\u0032\u0030\u65E5',
  19780. '\u33F4': '\u0032\u0031\u65E5',
  19781. '\u33F5': '\u0032\u0032\u65E5',
  19782. '\u33F6': '\u0032\u0033\u65E5',
  19783. '\u33F7': '\u0032\u0034\u65E5',
  19784. '\u33F8': '\u0032\u0035\u65E5',
  19785. '\u33F9': '\u0032\u0036\u65E5',
  19786. '\u33FA': '\u0032\u0037\u65E5',
  19787. '\u33FB': '\u0032\u0038\u65E5',
  19788. '\u33FC': '\u0032\u0039\u65E5',
  19789. '\u33FD': '\u0033\u0030\u65E5',
  19790. '\u33FE': '\u0033\u0031\u65E5',
  19791. '\uFB00': '\u0066\u0066',
  19792. '\uFB01': '\u0066\u0069',
  19793. '\uFB02': '\u0066\u006C',
  19794. '\uFB03': '\u0066\u0066\u0069',
  19795. '\uFB04': '\u0066\u0066\u006C',
  19796. '\uFB05': '\u017F\u0074',
  19797. '\uFB06': '\u0073\u0074',
  19798. '\uFB13': '\u0574\u0576',
  19799. '\uFB14': '\u0574\u0565',
  19800. '\uFB15': '\u0574\u056B',
  19801. '\uFB16': '\u057E\u0576',
  19802. '\uFB17': '\u0574\u056D',
  19803. '\uFB4F': '\u05D0\u05DC',
  19804. '\uFB50': '\u0671',
  19805. '\uFB51': '\u0671',
  19806. '\uFB52': '\u067B',
  19807. '\uFB53': '\u067B',
  19808. '\uFB54': '\u067B',
  19809. '\uFB55': '\u067B',
  19810. '\uFB56': '\u067E',
  19811. '\uFB57': '\u067E',
  19812. '\uFB58': '\u067E',
  19813. '\uFB59': '\u067E',
  19814. '\uFB5A': '\u0680',
  19815. '\uFB5B': '\u0680',
  19816. '\uFB5C': '\u0680',
  19817. '\uFB5D': '\u0680',
  19818. '\uFB5E': '\u067A',
  19819. '\uFB5F': '\u067A',
  19820. '\uFB60': '\u067A',
  19821. '\uFB61': '\u067A',
  19822. '\uFB62': '\u067F',
  19823. '\uFB63': '\u067F',
  19824. '\uFB64': '\u067F',
  19825. '\uFB65': '\u067F',
  19826. '\uFB66': '\u0679',
  19827. '\uFB67': '\u0679',
  19828. '\uFB68': '\u0679',
  19829. '\uFB69': '\u0679',
  19830. '\uFB6A': '\u06A4',
  19831. '\uFB6B': '\u06A4',
  19832. '\uFB6C': '\u06A4',
  19833. '\uFB6D': '\u06A4',
  19834. '\uFB6E': '\u06A6',
  19835. '\uFB6F': '\u06A6',
  19836. '\uFB70': '\u06A6',
  19837. '\uFB71': '\u06A6',
  19838. '\uFB72': '\u0684',
  19839. '\uFB73': '\u0684',
  19840. '\uFB74': '\u0684',
  19841. '\uFB75': '\u0684',
  19842. '\uFB76': '\u0683',
  19843. '\uFB77': '\u0683',
  19844. '\uFB78': '\u0683',
  19845. '\uFB79': '\u0683',
  19846. '\uFB7A': '\u0686',
  19847. '\uFB7B': '\u0686',
  19848. '\uFB7C': '\u0686',
  19849. '\uFB7D': '\u0686',
  19850. '\uFB7E': '\u0687',
  19851. '\uFB7F': '\u0687',
  19852. '\uFB80': '\u0687',
  19853. '\uFB81': '\u0687',
  19854. '\uFB82': '\u068D',
  19855. '\uFB83': '\u068D',
  19856. '\uFB84': '\u068C',
  19857. '\uFB85': '\u068C',
  19858. '\uFB86': '\u068E',
  19859. '\uFB87': '\u068E',
  19860. '\uFB88': '\u0688',
  19861. '\uFB89': '\u0688',
  19862. '\uFB8A': '\u0698',
  19863. '\uFB8B': '\u0698',
  19864. '\uFB8C': '\u0691',
  19865. '\uFB8D': '\u0691',
  19866. '\uFB8E': '\u06A9',
  19867. '\uFB8F': '\u06A9',
  19868. '\uFB90': '\u06A9',
  19869. '\uFB91': '\u06A9',
  19870. '\uFB92': '\u06AF',
  19871. '\uFB93': '\u06AF',
  19872. '\uFB94': '\u06AF',
  19873. '\uFB95': '\u06AF',
  19874. '\uFB96': '\u06B3',
  19875. '\uFB97': '\u06B3',
  19876. '\uFB98': '\u06B3',
  19877. '\uFB99': '\u06B3',
  19878. '\uFB9A': '\u06B1',
  19879. '\uFB9B': '\u06B1',
  19880. '\uFB9C': '\u06B1',
  19881. '\uFB9D': '\u06B1',
  19882. '\uFB9E': '\u06BA',
  19883. '\uFB9F': '\u06BA',
  19884. '\uFBA0': '\u06BB',
  19885. '\uFBA1': '\u06BB',
  19886. '\uFBA2': '\u06BB',
  19887. '\uFBA3': '\u06BB',
  19888. '\uFBA4': '\u06C0',
  19889. '\uFBA5': '\u06C0',
  19890. '\uFBA6': '\u06C1',
  19891. '\uFBA7': '\u06C1',
  19892. '\uFBA8': '\u06C1',
  19893. '\uFBA9': '\u06C1',
  19894. '\uFBAA': '\u06BE',
  19895. '\uFBAB': '\u06BE',
  19896. '\uFBAC': '\u06BE',
  19897. '\uFBAD': '\u06BE',
  19898. '\uFBAE': '\u06D2',
  19899. '\uFBAF': '\u06D2',
  19900. '\uFBB0': '\u06D3',
  19901. '\uFBB1': '\u06D3',
  19902. '\uFBD3': '\u06AD',
  19903. '\uFBD4': '\u06AD',
  19904. '\uFBD5': '\u06AD',
  19905. '\uFBD6': '\u06AD',
  19906. '\uFBD7': '\u06C7',
  19907. '\uFBD8': '\u06C7',
  19908. '\uFBD9': '\u06C6',
  19909. '\uFBDA': '\u06C6',
  19910. '\uFBDB': '\u06C8',
  19911. '\uFBDC': '\u06C8',
  19912. '\uFBDD': '\u0677',
  19913. '\uFBDE': '\u06CB',
  19914. '\uFBDF': '\u06CB',
  19915. '\uFBE0': '\u06C5',
  19916. '\uFBE1': '\u06C5',
  19917. '\uFBE2': '\u06C9',
  19918. '\uFBE3': '\u06C9',
  19919. '\uFBE4': '\u06D0',
  19920. '\uFBE5': '\u06D0',
  19921. '\uFBE6': '\u06D0',
  19922. '\uFBE7': '\u06D0',
  19923. '\uFBE8': '\u0649',
  19924. '\uFBE9': '\u0649',
  19925. '\uFBEA': '\u0626\u0627',
  19926. '\uFBEB': '\u0626\u0627',
  19927. '\uFBEC': '\u0626\u06D5',
  19928. '\uFBED': '\u0626\u06D5',
  19929. '\uFBEE': '\u0626\u0648',
  19930. '\uFBEF': '\u0626\u0648',
  19931. '\uFBF0': '\u0626\u06C7',
  19932. '\uFBF1': '\u0626\u06C7',
  19933. '\uFBF2': '\u0626\u06C6',
  19934. '\uFBF3': '\u0626\u06C6',
  19935. '\uFBF4': '\u0626\u06C8',
  19936. '\uFBF5': '\u0626\u06C8',
  19937. '\uFBF6': '\u0626\u06D0',
  19938. '\uFBF7': '\u0626\u06D0',
  19939. '\uFBF8': '\u0626\u06D0',
  19940. '\uFBF9': '\u0626\u0649',
  19941. '\uFBFA': '\u0626\u0649',
  19942. '\uFBFB': '\u0626\u0649',
  19943. '\uFBFC': '\u06CC',
  19944. '\uFBFD': '\u06CC',
  19945. '\uFBFE': '\u06CC',
  19946. '\uFBFF': '\u06CC',
  19947. '\uFC00': '\u0626\u062C',
  19948. '\uFC01': '\u0626\u062D',
  19949. '\uFC02': '\u0626\u0645',
  19950. '\uFC03': '\u0626\u0649',
  19951. '\uFC04': '\u0626\u064A',
  19952. '\uFC05': '\u0628\u062C',
  19953. '\uFC06': '\u0628\u062D',
  19954. '\uFC07': '\u0628\u062E',
  19955. '\uFC08': '\u0628\u0645',
  19956. '\uFC09': '\u0628\u0649',
  19957. '\uFC0A': '\u0628\u064A',
  19958. '\uFC0B': '\u062A\u062C',
  19959. '\uFC0C': '\u062A\u062D',
  19960. '\uFC0D': '\u062A\u062E',
  19961. '\uFC0E': '\u062A\u0645',
  19962. '\uFC0F': '\u062A\u0649',
  19963. '\uFC10': '\u062A\u064A',
  19964. '\uFC11': '\u062B\u062C',
  19965. '\uFC12': '\u062B\u0645',
  19966. '\uFC13': '\u062B\u0649',
  19967. '\uFC14': '\u062B\u064A',
  19968. '\uFC15': '\u062C\u062D',
  19969. '\uFC16': '\u062C\u0645',
  19970. '\uFC17': '\u062D\u062C',
  19971. '\uFC18': '\u062D\u0645',
  19972. '\uFC19': '\u062E\u062C',
  19973. '\uFC1A': '\u062E\u062D',
  19974. '\uFC1B': '\u062E\u0645',
  19975. '\uFC1C': '\u0633\u062C',
  19976. '\uFC1D': '\u0633\u062D',
  19977. '\uFC1E': '\u0633\u062E',
  19978. '\uFC1F': '\u0633\u0645',
  19979. '\uFC20': '\u0635\u062D',
  19980. '\uFC21': '\u0635\u0645',
  19981. '\uFC22': '\u0636\u062C',
  19982. '\uFC23': '\u0636\u062D',
  19983. '\uFC24': '\u0636\u062E',
  19984. '\uFC25': '\u0636\u0645',
  19985. '\uFC26': '\u0637\u062D',
  19986. '\uFC27': '\u0637\u0645',
  19987. '\uFC28': '\u0638\u0645',
  19988. '\uFC29': '\u0639\u062C',
  19989. '\uFC2A': '\u0639\u0645',
  19990. '\uFC2B': '\u063A\u062C',
  19991. '\uFC2C': '\u063A\u0645',
  19992. '\uFC2D': '\u0641\u062C',
  19993. '\uFC2E': '\u0641\u062D',
  19994. '\uFC2F': '\u0641\u062E',
  19995. '\uFC30': '\u0641\u0645',
  19996. '\uFC31': '\u0641\u0649',
  19997. '\uFC32': '\u0641\u064A',
  19998. '\uFC33': '\u0642\u062D',
  19999. '\uFC34': '\u0642\u0645',
  20000. '\uFC35': '\u0642\u0649',
  20001. '\uFC36': '\u0642\u064A',
  20002. '\uFC37': '\u0643\u0627',
  20003. '\uFC38': '\u0643\u062C',
  20004. '\uFC39': '\u0643\u062D',
  20005. '\uFC3A': '\u0643\u062E',
  20006. '\uFC3B': '\u0643\u0644',
  20007. '\uFC3C': '\u0643\u0645',
  20008. '\uFC3D': '\u0643\u0649',
  20009. '\uFC3E': '\u0643\u064A',
  20010. '\uFC3F': '\u0644\u062C',
  20011. '\uFC40': '\u0644\u062D',
  20012. '\uFC41': '\u0644\u062E',
  20013. '\uFC42': '\u0644\u0645',
  20014. '\uFC43': '\u0644\u0649',
  20015. '\uFC44': '\u0644\u064A',
  20016. '\uFC45': '\u0645\u062C',
  20017. '\uFC46': '\u0645\u062D',
  20018. '\uFC47': '\u0645\u062E',
  20019. '\uFC48': '\u0645\u0645',
  20020. '\uFC49': '\u0645\u0649',
  20021. '\uFC4A': '\u0645\u064A',
  20022. '\uFC4B': '\u0646\u062C',
  20023. '\uFC4C': '\u0646\u062D',
  20024. '\uFC4D': '\u0646\u062E',
  20025. '\uFC4E': '\u0646\u0645',
  20026. '\uFC4F': '\u0646\u0649',
  20027. '\uFC50': '\u0646\u064A',
  20028. '\uFC51': '\u0647\u062C',
  20029. '\uFC52': '\u0647\u0645',
  20030. '\uFC53': '\u0647\u0649',
  20031. '\uFC54': '\u0647\u064A',
  20032. '\uFC55': '\u064A\u062C',
  20033. '\uFC56': '\u064A\u062D',
  20034. '\uFC57': '\u064A\u062E',
  20035. '\uFC58': '\u064A\u0645',
  20036. '\uFC59': '\u064A\u0649',
  20037. '\uFC5A': '\u064A\u064A',
  20038. '\uFC5B': '\u0630\u0670',
  20039. '\uFC5C': '\u0631\u0670',
  20040. '\uFC5D': '\u0649\u0670',
  20041. '\uFC5E': '\u0020\u064C\u0651',
  20042. '\uFC5F': '\u0020\u064D\u0651',
  20043. '\uFC60': '\u0020\u064E\u0651',
  20044. '\uFC61': '\u0020\u064F\u0651',
  20045. '\uFC62': '\u0020\u0650\u0651',
  20046. '\uFC63': '\u0020\u0651\u0670',
  20047. '\uFC64': '\u0626\u0631',
  20048. '\uFC65': '\u0626\u0632',
  20049. '\uFC66': '\u0626\u0645',
  20050. '\uFC67': '\u0626\u0646',
  20051. '\uFC68': '\u0626\u0649',
  20052. '\uFC69': '\u0626\u064A',
  20053. '\uFC6A': '\u0628\u0631',
  20054. '\uFC6B': '\u0628\u0632',
  20055. '\uFC6C': '\u0628\u0645',
  20056. '\uFC6D': '\u0628\u0646',
  20057. '\uFC6E': '\u0628\u0649',
  20058. '\uFC6F': '\u0628\u064A',
  20059. '\uFC70': '\u062A\u0631',
  20060. '\uFC71': '\u062A\u0632',
  20061. '\uFC72': '\u062A\u0645',
  20062. '\uFC73': '\u062A\u0646',
  20063. '\uFC74': '\u062A\u0649',
  20064. '\uFC75': '\u062A\u064A',
  20065. '\uFC76': '\u062B\u0631',
  20066. '\uFC77': '\u062B\u0632',
  20067. '\uFC78': '\u062B\u0645',
  20068. '\uFC79': '\u062B\u0646',
  20069. '\uFC7A': '\u062B\u0649',
  20070. '\uFC7B': '\u062B\u064A',
  20071. '\uFC7C': '\u0641\u0649',
  20072. '\uFC7D': '\u0641\u064A',
  20073. '\uFC7E': '\u0642\u0649',
  20074. '\uFC7F': '\u0642\u064A',
  20075. '\uFC80': '\u0643\u0627',
  20076. '\uFC81': '\u0643\u0644',
  20077. '\uFC82': '\u0643\u0645',
  20078. '\uFC83': '\u0643\u0649',
  20079. '\uFC84': '\u0643\u064A',
  20080. '\uFC85': '\u0644\u0645',
  20081. '\uFC86': '\u0644\u0649',
  20082. '\uFC87': '\u0644\u064A',
  20083. '\uFC88': '\u0645\u0627',
  20084. '\uFC89': '\u0645\u0645',
  20085. '\uFC8A': '\u0646\u0631',
  20086. '\uFC8B': '\u0646\u0632',
  20087. '\uFC8C': '\u0646\u0645',
  20088. '\uFC8D': '\u0646\u0646',
  20089. '\uFC8E': '\u0646\u0649',
  20090. '\uFC8F': '\u0646\u064A',
  20091. '\uFC90': '\u0649\u0670',
  20092. '\uFC91': '\u064A\u0631',
  20093. '\uFC92': '\u064A\u0632',
  20094. '\uFC93': '\u064A\u0645',
  20095. '\uFC94': '\u064A\u0646',
  20096. '\uFC95': '\u064A\u0649',
  20097. '\uFC96': '\u064A\u064A',
  20098. '\uFC97': '\u0626\u062C',
  20099. '\uFC98': '\u0626\u062D',
  20100. '\uFC99': '\u0626\u062E',
  20101. '\uFC9A': '\u0626\u0645',
  20102. '\uFC9B': '\u0626\u0647',
  20103. '\uFC9C': '\u0628\u062C',
  20104. '\uFC9D': '\u0628\u062D',
  20105. '\uFC9E': '\u0628\u062E',
  20106. '\uFC9F': '\u0628\u0645',
  20107. '\uFCA0': '\u0628\u0647',
  20108. '\uFCA1': '\u062A\u062C',
  20109. '\uFCA2': '\u062A\u062D',
  20110. '\uFCA3': '\u062A\u062E',
  20111. '\uFCA4': '\u062A\u0645',
  20112. '\uFCA5': '\u062A\u0647',
  20113. '\uFCA6': '\u062B\u0645',
  20114. '\uFCA7': '\u062C\u062D',
  20115. '\uFCA8': '\u062C\u0645',
  20116. '\uFCA9': '\u062D\u062C',
  20117. '\uFCAA': '\u062D\u0645',
  20118. '\uFCAB': '\u062E\u062C',
  20119. '\uFCAC': '\u062E\u0645',
  20120. '\uFCAD': '\u0633\u062C',
  20121. '\uFCAE': '\u0633\u062D',
  20122. '\uFCAF': '\u0633\u062E',
  20123. '\uFCB0': '\u0633\u0645',
  20124. '\uFCB1': '\u0635\u062D',
  20125. '\uFCB2': '\u0635\u062E',
  20126. '\uFCB3': '\u0635\u0645',
  20127. '\uFCB4': '\u0636\u062C',
  20128. '\uFCB5': '\u0636\u062D',
  20129. '\uFCB6': '\u0636\u062E',
  20130. '\uFCB7': '\u0636\u0645',
  20131. '\uFCB8': '\u0637\u062D',
  20132. '\uFCB9': '\u0638\u0645',
  20133. '\uFCBA': '\u0639\u062C',
  20134. '\uFCBB': '\u0639\u0645',
  20135. '\uFCBC': '\u063A\u062C',
  20136. '\uFCBD': '\u063A\u0645',
  20137. '\uFCBE': '\u0641\u062C',
  20138. '\uFCBF': '\u0641\u062D',
  20139. '\uFCC0': '\u0641\u062E',
  20140. '\uFCC1': '\u0641\u0645',
  20141. '\uFCC2': '\u0642\u062D',
  20142. '\uFCC3': '\u0642\u0645',
  20143. '\uFCC4': '\u0643\u062C',
  20144. '\uFCC5': '\u0643\u062D',
  20145. '\uFCC6': '\u0643\u062E',
  20146. '\uFCC7': '\u0643\u0644',
  20147. '\uFCC8': '\u0643\u0645',
  20148. '\uFCC9': '\u0644\u062C',
  20149. '\uFCCA': '\u0644\u062D',
  20150. '\uFCCB': '\u0644\u062E',
  20151. '\uFCCC': '\u0644\u0645',
  20152. '\uFCCD': '\u0644\u0647',
  20153. '\uFCCE': '\u0645\u062C',
  20154. '\uFCCF': '\u0645\u062D',
  20155. '\uFCD0': '\u0645\u062E',
  20156. '\uFCD1': '\u0645\u0645',
  20157. '\uFCD2': '\u0646\u062C',
  20158. '\uFCD3': '\u0646\u062D',
  20159. '\uFCD4': '\u0646\u062E',
  20160. '\uFCD5': '\u0646\u0645',
  20161. '\uFCD6': '\u0646\u0647',
  20162. '\uFCD7': '\u0647\u062C',
  20163. '\uFCD8': '\u0647\u0645',
  20164. '\uFCD9': '\u0647\u0670',
  20165. '\uFCDA': '\u064A\u062C',
  20166. '\uFCDB': '\u064A\u062D',
  20167. '\uFCDC': '\u064A\u062E',
  20168. '\uFCDD': '\u064A\u0645',
  20169. '\uFCDE': '\u064A\u0647',
  20170. '\uFCDF': '\u0626\u0645',
  20171. '\uFCE0': '\u0626\u0647',
  20172. '\uFCE1': '\u0628\u0645',
  20173. '\uFCE2': '\u0628\u0647',
  20174. '\uFCE3': '\u062A\u0645',
  20175. '\uFCE4': '\u062A\u0647',
  20176. '\uFCE5': '\u062B\u0645',
  20177. '\uFCE6': '\u062B\u0647',
  20178. '\uFCE7': '\u0633\u0645',
  20179. '\uFCE8': '\u0633\u0647',
  20180. '\uFCE9': '\u0634\u0645',
  20181. '\uFCEA': '\u0634\u0647',
  20182. '\uFCEB': '\u0643\u0644',
  20183. '\uFCEC': '\u0643\u0645',
  20184. '\uFCED': '\u0644\u0645',
  20185. '\uFCEE': '\u0646\u0645',
  20186. '\uFCEF': '\u0646\u0647',
  20187. '\uFCF0': '\u064A\u0645',
  20188. '\uFCF1': '\u064A\u0647',
  20189. '\uFCF2': '\u0640\u064E\u0651',
  20190. '\uFCF3': '\u0640\u064F\u0651',
  20191. '\uFCF4': '\u0640\u0650\u0651',
  20192. '\uFCF5': '\u0637\u0649',
  20193. '\uFCF6': '\u0637\u064A',
  20194. '\uFCF7': '\u0639\u0649',
  20195. '\uFCF8': '\u0639\u064A',
  20196. '\uFCF9': '\u063A\u0649',
  20197. '\uFCFA': '\u063A\u064A',
  20198. '\uFCFB': '\u0633\u0649',
  20199. '\uFCFC': '\u0633\u064A',
  20200. '\uFCFD': '\u0634\u0649',
  20201. '\uFCFE': '\u0634\u064A',
  20202. '\uFCFF': '\u062D\u0649',
  20203. '\uFD00': '\u062D\u064A',
  20204. '\uFD01': '\u062C\u0649',
  20205. '\uFD02': '\u062C\u064A',
  20206. '\uFD03': '\u062E\u0649',
  20207. '\uFD04': '\u062E\u064A',
  20208. '\uFD05': '\u0635\u0649',
  20209. '\uFD06': '\u0635\u064A',
  20210. '\uFD07': '\u0636\u0649',
  20211. '\uFD08': '\u0636\u064A',
  20212. '\uFD09': '\u0634\u062C',
  20213. '\uFD0A': '\u0634\u062D',
  20214. '\uFD0B': '\u0634\u062E',
  20215. '\uFD0C': '\u0634\u0645',
  20216. '\uFD0D': '\u0634\u0631',
  20217. '\uFD0E': '\u0633\u0631',
  20218. '\uFD0F': '\u0635\u0631',
  20219. '\uFD10': '\u0636\u0631',
  20220. '\uFD11': '\u0637\u0649',
  20221. '\uFD12': '\u0637\u064A',
  20222. '\uFD13': '\u0639\u0649',
  20223. '\uFD14': '\u0639\u064A',
  20224. '\uFD15': '\u063A\u0649',
  20225. '\uFD16': '\u063A\u064A',
  20226. '\uFD17': '\u0633\u0649',
  20227. '\uFD18': '\u0633\u064A',
  20228. '\uFD19': '\u0634\u0649',
  20229. '\uFD1A': '\u0634\u064A',
  20230. '\uFD1B': '\u062D\u0649',
  20231. '\uFD1C': '\u062D\u064A',
  20232. '\uFD1D': '\u062C\u0649',
  20233. '\uFD1E': '\u062C\u064A',
  20234. '\uFD1F': '\u062E\u0649',
  20235. '\uFD20': '\u062E\u064A',
  20236. '\uFD21': '\u0635\u0649',
  20237. '\uFD22': '\u0635\u064A',
  20238. '\uFD23': '\u0636\u0649',
  20239. '\uFD24': '\u0636\u064A',
  20240. '\uFD25': '\u0634\u062C',
  20241. '\uFD26': '\u0634\u062D',
  20242. '\uFD27': '\u0634\u062E',
  20243. '\uFD28': '\u0634\u0645',
  20244. '\uFD29': '\u0634\u0631',
  20245. '\uFD2A': '\u0633\u0631',
  20246. '\uFD2B': '\u0635\u0631',
  20247. '\uFD2C': '\u0636\u0631',
  20248. '\uFD2D': '\u0634\u062C',
  20249. '\uFD2E': '\u0634\u062D',
  20250. '\uFD2F': '\u0634\u062E',
  20251. '\uFD30': '\u0634\u0645',
  20252. '\uFD31': '\u0633\u0647',
  20253. '\uFD32': '\u0634\u0647',
  20254. '\uFD33': '\u0637\u0645',
  20255. '\uFD34': '\u0633\u062C',
  20256. '\uFD35': '\u0633\u062D',
  20257. '\uFD36': '\u0633\u062E',
  20258. '\uFD37': '\u0634\u062C',
  20259. '\uFD38': '\u0634\u062D',
  20260. '\uFD39': '\u0634\u062E',
  20261. '\uFD3A': '\u0637\u0645',
  20262. '\uFD3B': '\u0638\u0645',
  20263. '\uFD3C': '\u0627\u064B',
  20264. '\uFD3D': '\u0627\u064B',
  20265. '\uFD50': '\u062A\u062C\u0645',
  20266. '\uFD51': '\u062A\u062D\u062C',
  20267. '\uFD52': '\u062A\u062D\u062C',
  20268. '\uFD53': '\u062A\u062D\u0645',
  20269. '\uFD54': '\u062A\u062E\u0645',
  20270. '\uFD55': '\u062A\u0645\u062C',
  20271. '\uFD56': '\u062A\u0645\u062D',
  20272. '\uFD57': '\u062A\u0645\u062E',
  20273. '\uFD58': '\u062C\u0645\u062D',
  20274. '\uFD59': '\u062C\u0645\u062D',
  20275. '\uFD5A': '\u062D\u0645\u064A',
  20276. '\uFD5B': '\u062D\u0645\u0649',
  20277. '\uFD5C': '\u0633\u062D\u062C',
  20278. '\uFD5D': '\u0633\u062C\u062D',
  20279. '\uFD5E': '\u0633\u062C\u0649',
  20280. '\uFD5F': '\u0633\u0645\u062D',
  20281. '\uFD60': '\u0633\u0645\u062D',
  20282. '\uFD61': '\u0633\u0645\u062C',
  20283. '\uFD62': '\u0633\u0645\u0645',
  20284. '\uFD63': '\u0633\u0645\u0645',
  20285. '\uFD64': '\u0635\u062D\u062D',
  20286. '\uFD65': '\u0635\u062D\u062D',
  20287. '\uFD66': '\u0635\u0645\u0645',
  20288. '\uFD67': '\u0634\u062D\u0645',
  20289. '\uFD68': '\u0634\u062D\u0645',
  20290. '\uFD69': '\u0634\u062C\u064A',
  20291. '\uFD6A': '\u0634\u0645\u062E',
  20292. '\uFD6B': '\u0634\u0645\u062E',
  20293. '\uFD6C': '\u0634\u0645\u0645',
  20294. '\uFD6D': '\u0634\u0645\u0645',
  20295. '\uFD6E': '\u0636\u062D\u0649',
  20296. '\uFD6F': '\u0636\u062E\u0645',
  20297. '\uFD70': '\u0636\u062E\u0645',
  20298. '\uFD71': '\u0637\u0645\u062D',
  20299. '\uFD72': '\u0637\u0645\u062D',
  20300. '\uFD73': '\u0637\u0645\u0645',
  20301. '\uFD74': '\u0637\u0645\u064A',
  20302. '\uFD75': '\u0639\u062C\u0645',
  20303. '\uFD76': '\u0639\u0645\u0645',
  20304. '\uFD77': '\u0639\u0645\u0645',
  20305. '\uFD78': '\u0639\u0645\u0649',
  20306. '\uFD79': '\u063A\u0645\u0645',
  20307. '\uFD7A': '\u063A\u0645\u064A',
  20308. '\uFD7B': '\u063A\u0645\u0649',
  20309. '\uFD7C': '\u0641\u062E\u0645',
  20310. '\uFD7D': '\u0641\u062E\u0645',
  20311. '\uFD7E': '\u0642\u0645\u062D',
  20312. '\uFD7F': '\u0642\u0645\u0645',
  20313. '\uFD80': '\u0644\u062D\u0645',
  20314. '\uFD81': '\u0644\u062D\u064A',
  20315. '\uFD82': '\u0644\u062D\u0649',
  20316. '\uFD83': '\u0644\u062C\u062C',
  20317. '\uFD84': '\u0644\u062C\u062C',
  20318. '\uFD85': '\u0644\u062E\u0645',
  20319. '\uFD86': '\u0644\u062E\u0645',
  20320. '\uFD87': '\u0644\u0645\u062D',
  20321. '\uFD88': '\u0644\u0645\u062D',
  20322. '\uFD89': '\u0645\u062D\u062C',
  20323. '\uFD8A': '\u0645\u062D\u0645',
  20324. '\uFD8B': '\u0645\u062D\u064A',
  20325. '\uFD8C': '\u0645\u062C\u062D',
  20326. '\uFD8D': '\u0645\u062C\u0645',
  20327. '\uFD8E': '\u0645\u062E\u062C',
  20328. '\uFD8F': '\u0645\u062E\u0645',
  20329. '\uFD92': '\u0645\u062C\u062E',
  20330. '\uFD93': '\u0647\u0645\u062C',
  20331. '\uFD94': '\u0647\u0645\u0645',
  20332. '\uFD95': '\u0646\u062D\u0645',
  20333. '\uFD96': '\u0646\u062D\u0649',
  20334. '\uFD97': '\u0646\u062C\u0645',
  20335. '\uFD98': '\u0646\u062C\u0645',
  20336. '\uFD99': '\u0646\u062C\u0649',
  20337. '\uFD9A': '\u0646\u0645\u064A',
  20338. '\uFD9B': '\u0646\u0645\u0649',
  20339. '\uFD9C': '\u064A\u0645\u0645',
  20340. '\uFD9D': '\u064A\u0645\u0645',
  20341. '\uFD9E': '\u0628\u062E\u064A',
  20342. '\uFD9F': '\u062A\u062C\u064A',
  20343. '\uFDA0': '\u062A\u062C\u0649',
  20344. '\uFDA1': '\u062A\u062E\u064A',
  20345. '\uFDA2': '\u062A\u062E\u0649',
  20346. '\uFDA3': '\u062A\u0645\u064A',
  20347. '\uFDA4': '\u062A\u0645\u0649',
  20348. '\uFDA5': '\u062C\u0645\u064A',
  20349. '\uFDA6': '\u062C\u062D\u0649',
  20350. '\uFDA7': '\u062C\u0645\u0649',
  20351. '\uFDA8': '\u0633\u062E\u0649',
  20352. '\uFDA9': '\u0635\u062D\u064A',
  20353. '\uFDAA': '\u0634\u062D\u064A',
  20354. '\uFDAB': '\u0636\u062D\u064A',
  20355. '\uFDAC': '\u0644\u062C\u064A',
  20356. '\uFDAD': '\u0644\u0645\u064A',
  20357. '\uFDAE': '\u064A\u062D\u064A',
  20358. '\uFDAF': '\u064A\u062C\u064A',
  20359. '\uFDB0': '\u064A\u0645\u064A',
  20360. '\uFDB1': '\u0645\u0645\u064A',
  20361. '\uFDB2': '\u0642\u0645\u064A',
  20362. '\uFDB3': '\u0646\u062D\u064A',
  20363. '\uFDB4': '\u0642\u0645\u062D',
  20364. '\uFDB5': '\u0644\u062D\u0645',
  20365. '\uFDB6': '\u0639\u0645\u064A',
  20366. '\uFDB7': '\u0643\u0645\u064A',
  20367. '\uFDB8': '\u0646\u062C\u062D',
  20368. '\uFDB9': '\u0645\u062E\u064A',
  20369. '\uFDBA': '\u0644\u062C\u0645',
  20370. '\uFDBB': '\u0643\u0645\u0645',
  20371. '\uFDBC': '\u0644\u062C\u0645',
  20372. '\uFDBD': '\u0646\u062C\u062D',
  20373. '\uFDBE': '\u062C\u062D\u064A',
  20374. '\uFDBF': '\u062D\u062C\u064A',
  20375. '\uFDC0': '\u0645\u062C\u064A',
  20376. '\uFDC1': '\u0641\u0645\u064A',
  20377. '\uFDC2': '\u0628\u062D\u064A',
  20378. '\uFDC3': '\u0643\u0645\u0645',
  20379. '\uFDC4': '\u0639\u062C\u0645',
  20380. '\uFDC5': '\u0635\u0645\u0645',
  20381. '\uFDC6': '\u0633\u062E\u064A',
  20382. '\uFDC7': '\u0646\u062C\u064A',
  20383. '\uFE49': '\u203E',
  20384. '\uFE4A': '\u203E',
  20385. '\uFE4B': '\u203E',
  20386. '\uFE4C': '\u203E',
  20387. '\uFE4D': '\u005F',
  20388. '\uFE4E': '\u005F',
  20389. '\uFE4F': '\u005F',
  20390. '\uFE80': '\u0621',
  20391. '\uFE81': '\u0622',
  20392. '\uFE82': '\u0622',
  20393. '\uFE83': '\u0623',
  20394. '\uFE84': '\u0623',
  20395. '\uFE85': '\u0624',
  20396. '\uFE86': '\u0624',
  20397. '\uFE87': '\u0625',
  20398. '\uFE88': '\u0625',
  20399. '\uFE89': '\u0626',
  20400. '\uFE8A': '\u0626',
  20401. '\uFE8B': '\u0626',
  20402. '\uFE8C': '\u0626',
  20403. '\uFE8D': '\u0627',
  20404. '\uFE8E': '\u0627',
  20405. '\uFE8F': '\u0628',
  20406. '\uFE90': '\u0628',
  20407. '\uFE91': '\u0628',
  20408. '\uFE92': '\u0628',
  20409. '\uFE93': '\u0629',
  20410. '\uFE94': '\u0629',
  20411. '\uFE95': '\u062A',
  20412. '\uFE96': '\u062A',
  20413. '\uFE97': '\u062A',
  20414. '\uFE98': '\u062A',
  20415. '\uFE99': '\u062B',
  20416. '\uFE9A': '\u062B',
  20417. '\uFE9B': '\u062B',
  20418. '\uFE9C': '\u062B',
  20419. '\uFE9D': '\u062C',
  20420. '\uFE9E': '\u062C',
  20421. '\uFE9F': '\u062C',
  20422. '\uFEA0': '\u062C',
  20423. '\uFEA1': '\u062D',
  20424. '\uFEA2': '\u062D',
  20425. '\uFEA3': '\u062D',
  20426. '\uFEA4': '\u062D',
  20427. '\uFEA5': '\u062E',
  20428. '\uFEA6': '\u062E',
  20429. '\uFEA7': '\u062E',
  20430. '\uFEA8': '\u062E',
  20431. '\uFEA9': '\u062F',
  20432. '\uFEAA': '\u062F',
  20433. '\uFEAB': '\u0630',
  20434. '\uFEAC': '\u0630',
  20435. '\uFEAD': '\u0631',
  20436. '\uFEAE': '\u0631',
  20437. '\uFEAF': '\u0632',
  20438. '\uFEB0': '\u0632',
  20439. '\uFEB1': '\u0633',
  20440. '\uFEB2': '\u0633',
  20441. '\uFEB3': '\u0633',
  20442. '\uFEB4': '\u0633',
  20443. '\uFEB5': '\u0634',
  20444. '\uFEB6': '\u0634',
  20445. '\uFEB7': '\u0634',
  20446. '\uFEB8': '\u0634',
  20447. '\uFEB9': '\u0635',
  20448. '\uFEBA': '\u0635',
  20449. '\uFEBB': '\u0635',
  20450. '\uFEBC': '\u0635',
  20451. '\uFEBD': '\u0636',
  20452. '\uFEBE': '\u0636',
  20453. '\uFEBF': '\u0636',
  20454. '\uFEC0': '\u0636',
  20455. '\uFEC1': '\u0637',
  20456. '\uFEC2': '\u0637',
  20457. '\uFEC3': '\u0637',
  20458. '\uFEC4': '\u0637',
  20459. '\uFEC5': '\u0638',
  20460. '\uFEC6': '\u0638',
  20461. '\uFEC7': '\u0638',
  20462. '\uFEC8': '\u0638',
  20463. '\uFEC9': '\u0639',
  20464. '\uFECA': '\u0639',
  20465. '\uFECB': '\u0639',
  20466. '\uFECC': '\u0639',
  20467. '\uFECD': '\u063A',
  20468. '\uFECE': '\u063A',
  20469. '\uFECF': '\u063A',
  20470. '\uFED0': '\u063A',
  20471. '\uFED1': '\u0641',
  20472. '\uFED2': '\u0641',
  20473. '\uFED3': '\u0641',
  20474. '\uFED4': '\u0641',
  20475. '\uFED5': '\u0642',
  20476. '\uFED6': '\u0642',
  20477. '\uFED7': '\u0642',
  20478. '\uFED8': '\u0642',
  20479. '\uFED9': '\u0643',
  20480. '\uFEDA': '\u0643',
  20481. '\uFEDB': '\u0643',
  20482. '\uFEDC': '\u0643',
  20483. '\uFEDD': '\u0644',
  20484. '\uFEDE': '\u0644',
  20485. '\uFEDF': '\u0644',
  20486. '\uFEE0': '\u0644',
  20487. '\uFEE1': '\u0645',
  20488. '\uFEE2': '\u0645',
  20489. '\uFEE3': '\u0645',
  20490. '\uFEE4': '\u0645',
  20491. '\uFEE5': '\u0646',
  20492. '\uFEE6': '\u0646',
  20493. '\uFEE7': '\u0646',
  20494. '\uFEE8': '\u0646',
  20495. '\uFEE9': '\u0647',
  20496. '\uFEEA': '\u0647',
  20497. '\uFEEB': '\u0647',
  20498. '\uFEEC': '\u0647',
  20499. '\uFEED': '\u0648',
  20500. '\uFEEE': '\u0648',
  20501. '\uFEEF': '\u0649',
  20502. '\uFEF0': '\u0649',
  20503. '\uFEF1': '\u064A',
  20504. '\uFEF2': '\u064A',
  20505. '\uFEF3': '\u064A',
  20506. '\uFEF4': '\u064A',
  20507. '\uFEF5': '\u0644\u0622',
  20508. '\uFEF6': '\u0644\u0622',
  20509. '\uFEF7': '\u0644\u0623',
  20510. '\uFEF8': '\u0644\u0623',
  20511. '\uFEF9': '\u0644\u0625',
  20512. '\uFEFA': '\u0644\u0625',
  20513. '\uFEFB': '\u0644\u0627',
  20514. '\uFEFC': '\u0644\u0627'
  20515. };
  20516. function reverseIfRtl(chars) {
  20517. var charsLength = chars.length;
  20518. //reverse an arabic ligature
  20519. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  20520. return chars;
  20521. }
  20522. var s = '';
  20523. for (var ii = charsLength - 1; ii >= 0; ii--) {
  20524. s += chars[ii];
  20525. }
  20526. return s;
  20527. }
  20528. function adjustWidths(properties) {
  20529. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  20530. return;
  20531. }
  20532. // adjusting width to fontMatrix scale
  20533. var scale = 0.001 / properties.fontMatrix[0];
  20534. var glyphsWidths = properties.widths;
  20535. for (var glyph in glyphsWidths) {
  20536. glyphsWidths[glyph] *= scale;
  20537. }
  20538. properties.defaultWidth *= scale;
  20539. }
  20540. function getFontType(type, subtype) {
  20541. switch (type) {
  20542. case 'Type1':
  20543. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  20544. case 'CIDFontType0':
  20545. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  20546. FontType.CIDFONTTYPE0;
  20547. case 'OpenType':
  20548. return FontType.OPENTYPE;
  20549. case 'TrueType':
  20550. return FontType.TRUETYPE;
  20551. case 'CIDFontType2':
  20552. return FontType.CIDFONTTYPE2;
  20553. case 'MMType1':
  20554. return FontType.MMTYPE1;
  20555. case 'Type0':
  20556. return FontType.TYPE0;
  20557. default:
  20558. return FontType.UNKNOWN;
  20559. }
  20560. }
  20561. var Glyph = (function GlyphClosure() {
  20562. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20563. this.fontChar = fontChar;
  20564. this.unicode = unicode;
  20565. this.accent = accent;
  20566. this.width = width;
  20567. this.vmetric = vmetric;
  20568. this.operatorListId = operatorListId;
  20569. }
  20570. Glyph.prototype.matchesForCache =
  20571. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  20572. return this.fontChar === fontChar &&
  20573. this.unicode === unicode &&
  20574. this.accent === accent &&
  20575. this.width === width &&
  20576. this.vmetric === vmetric &&
  20577. this.operatorListId === operatorListId;
  20578. };
  20579. return Glyph;
  20580. })();
  20581. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  20582. function ToUnicodeMap(cmap) {
  20583. // The elements of this._map can be integers or strings, depending on how
  20584. // |cmap| was created.
  20585. this._map = cmap;
  20586. }
  20587. ToUnicodeMap.prototype = {
  20588. get length() {
  20589. return this._map.length;
  20590. },
  20591. forEach: function(callback) {
  20592. for (var charCode in this._map) {
  20593. callback(charCode, this._map[charCode].charCodeAt(0));
  20594. }
  20595. },
  20596. has: function(i) {
  20597. return this._map[i] !== undefined;
  20598. },
  20599. get: function(i) {
  20600. return this._map[i];
  20601. },
  20602. charCodeOf: function(v) {
  20603. return this._map.indexOf(v);
  20604. }
  20605. };
  20606. return ToUnicodeMap;
  20607. })();
  20608. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  20609. function IdentityToUnicodeMap(firstChar, lastChar) {
  20610. this.firstChar = firstChar;
  20611. this.lastChar = lastChar;
  20612. }
  20613. IdentityToUnicodeMap.prototype = {
  20614. get length() {
  20615. error('should not access .length');
  20616. },
  20617. forEach: function (callback) {
  20618. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  20619. callback(i, i);
  20620. }
  20621. },
  20622. has: function (i) {
  20623. return this.firstChar <= i && i <= this.lastChar;
  20624. },
  20625. get: function (i) {
  20626. if (this.firstChar <= i && i <= this.lastChar) {
  20627. return String.fromCharCode(i);
  20628. }
  20629. return undefined;
  20630. },
  20631. charCodeOf: function (v) {
  20632. error('should not call .charCodeOf');
  20633. }
  20634. };
  20635. return IdentityToUnicodeMap;
  20636. })();
  20637. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  20638. function writeInt16(dest, offset, num) {
  20639. dest[offset] = (num >> 8) & 0xFF;
  20640. dest[offset + 1] = num & 0xFF;
  20641. }
  20642. function writeInt32(dest, offset, num) {
  20643. dest[offset] = (num >> 24) & 0xFF;
  20644. dest[offset + 1] = (num >> 16) & 0xFF;
  20645. dest[offset + 2] = (num >> 8) & 0xFF;
  20646. dest[offset + 3] = num & 0xFF;
  20647. }
  20648. function writeData(dest, offset, data) {
  20649. var i, ii;
  20650. if (data instanceof Uint8Array) {
  20651. dest.set(data, offset);
  20652. } else if (typeof data === 'string') {
  20653. for (i = 0, ii = data.length; i < ii; i++) {
  20654. dest[offset++] = data.charCodeAt(i) & 0xFF;
  20655. }
  20656. } else {
  20657. // treating everything else as array
  20658. for (i = 0, ii = data.length; i < ii; i++) {
  20659. dest[offset++] = data[i] & 0xFF;
  20660. }
  20661. }
  20662. }
  20663. function OpenTypeFileBuilder(sfnt) {
  20664. this.sfnt = sfnt;
  20665. this.tables = Object.create(null);
  20666. }
  20667. OpenTypeFileBuilder.getSearchParams =
  20668. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  20669. var maxPower2 = 1, log2 = 0;
  20670. while ((maxPower2 ^ entriesCount) > maxPower2) {
  20671. maxPower2 <<= 1;
  20672. log2++;
  20673. }
  20674. var searchRange = maxPower2 * entrySize;
  20675. return {
  20676. range: searchRange,
  20677. entry: log2,
  20678. rangeShift: entrySize * entriesCount - searchRange
  20679. };
  20680. };
  20681. var OTF_HEADER_SIZE = 12;
  20682. var OTF_TABLE_ENTRY_SIZE = 16;
  20683. OpenTypeFileBuilder.prototype = {
  20684. toArray: function OpenTypeFileBuilder_toArray() {
  20685. var sfnt = this.sfnt;
  20686. // Tables needs to be written by ascendant alphabetic order
  20687. var tables = this.tables;
  20688. var tablesNames = Object.keys(tables);
  20689. tablesNames.sort();
  20690. var numTables = tablesNames.length;
  20691. var i, j, jj, table, tableName;
  20692. // layout the tables data
  20693. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  20694. var tableOffsets = [offset];
  20695. for (i = 0; i < numTables; i++) {
  20696. table = tables[tablesNames[i]];
  20697. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  20698. offset += paddedLength;
  20699. tableOffsets.push(offset);
  20700. }
  20701. var file = new Uint8Array(offset);
  20702. // write the table data first (mostly for checksum)
  20703. for (i = 0; i < numTables; i++) {
  20704. table = tables[tablesNames[i]];
  20705. writeData(file, tableOffsets[i], table);
  20706. }
  20707. // sfnt version (4 bytes)
  20708. if (sfnt === 'true') {
  20709. // Windows hates the Mac TrueType sfnt version number
  20710. sfnt = string32(0x00010000);
  20711. }
  20712. file[0] = sfnt.charCodeAt(0) & 0xFF;
  20713. file[1] = sfnt.charCodeAt(1) & 0xFF;
  20714. file[2] = sfnt.charCodeAt(2) & 0xFF;
  20715. file[3] = sfnt.charCodeAt(3) & 0xFF;
  20716. // numTables (2 bytes)
  20717. writeInt16(file, 4, numTables);
  20718. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  20719. // searchRange (2 bytes)
  20720. writeInt16(file, 6, searchParams.range);
  20721. // entrySelector (2 bytes)
  20722. writeInt16(file, 8, searchParams.entry);
  20723. // rangeShift (2 bytes)
  20724. writeInt16(file, 10, searchParams.rangeShift);
  20725. offset = OTF_HEADER_SIZE;
  20726. // writing table entries
  20727. for (i = 0; i < numTables; i++) {
  20728. tableName = tablesNames[i];
  20729. file[offset] = tableName.charCodeAt(0) & 0xFF;
  20730. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  20731. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  20732. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  20733. // checksum
  20734. var checksum = 0;
  20735. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  20736. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  20737. (file[j + 2] << 8) + file[j + 3];
  20738. checksum = (checksum + quad) | 0;
  20739. }
  20740. writeInt32(file, offset + 4, checksum);
  20741. // offset
  20742. writeInt32(file, offset + 8, tableOffsets[i]);
  20743. // length
  20744. writeInt32(file, offset + 12, tables[tableName].length);
  20745. offset += OTF_TABLE_ENTRY_SIZE;
  20746. }
  20747. return file;
  20748. },
  20749. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  20750. if (tag in this.tables) {
  20751. throw new Error('Table ' + tag + ' already exists');
  20752. }
  20753. this.tables[tag] = data;
  20754. }
  20755. };
  20756. return OpenTypeFileBuilder;
  20757. })();
  20758. /**
  20759. * 'Font' is the class the outside world should use, it encapsulate all the font
  20760. * decoding logics whatever type it is (assuming the font type is supported).
  20761. *
  20762. * For example to read a Type1 font and to attach it to the document:
  20763. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  20764. * type1Font.bind();
  20765. */
  20766. var Font = (function FontClosure() {
  20767. function Font(name, file, properties) {
  20768. var charCode, glyphName, fontChar;
  20769. this.name = name;
  20770. this.loadedName = properties.loadedName;
  20771. this.isType3Font = properties.isType3Font;
  20772. this.sizes = [];
  20773. this.glyphCache = {};
  20774. var names = name.split('+');
  20775. names = names.length > 1 ? names[1] : names[0];
  20776. names = names.split(/[-,_]/g)[0];
  20777. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  20778. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  20779. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  20780. var type = properties.type;
  20781. var subtype = properties.subtype;
  20782. this.type = type;
  20783. this.fallbackName = (this.isMonospace ? 'monospace' :
  20784. (this.isSerifFont ? 'serif' : 'sans-serif'));
  20785. this.differences = properties.differences;
  20786. this.widths = properties.widths;
  20787. this.defaultWidth = properties.defaultWidth;
  20788. this.composite = properties.composite;
  20789. this.wideChars = properties.wideChars;
  20790. this.cMap = properties.cMap;
  20791. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  20792. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  20793. this.fontMatrix = properties.fontMatrix;
  20794. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  20795. this.toFontChar = [];
  20796. if (properties.type === 'Type3') {
  20797. for (charCode = 0; charCode < 256; charCode++) {
  20798. this.toFontChar[charCode] = (this.differences[charCode] ||
  20799. properties.defaultEncoding[charCode]);
  20800. }
  20801. this.fontType = FontType.TYPE3;
  20802. return;
  20803. }
  20804. this.cidEncoding = properties.cidEncoding;
  20805. this.vertical = properties.vertical;
  20806. if (this.vertical) {
  20807. this.vmetrics = properties.vmetrics;
  20808. this.defaultVMetrics = properties.defaultVMetrics;
  20809. }
  20810. if (!file || file.isEmpty) {
  20811. if (file) {
  20812. // Some bad PDF generators will include empty font files,
  20813. // attempting to recover by assuming that no file exists.
  20814. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  20815. }
  20816. this.missingFile = true;
  20817. // The file data is not specified. Trying to fix the font name
  20818. // to be used with the canvas.font.
  20819. var fontName = name.replace(/[,_]/g, '-');
  20820. var isStandardFont = !!stdFontMap[fontName] ||
  20821. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  20822. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  20823. this.bold = (fontName.search(/bold/gi) !== -1);
  20824. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  20825. (fontName.search(/italic/gi) !== -1));
  20826. // Use 'name' instead of 'fontName' here because the original
  20827. // name ArialBlack for example will be replaced by Helvetica.
  20828. this.black = (name.search(/Black/g) !== -1);
  20829. // if at least one width is present, remeasure all chars when exists
  20830. this.remeasure = Object.keys(this.widths).length > 0;
  20831. if (isStandardFont && type === 'CIDFontType2' &&
  20832. properties.cidEncoding.indexOf('Identity-') === 0) {
  20833. // Standard fonts might be embedded as CID font without glyph mapping.
  20834. // Building one based on GlyphMapForStandardFonts.
  20835. var map = [];
  20836. for (var code in GlyphMapForStandardFonts) {
  20837. map[+code] = GlyphMapForStandardFonts[code];
  20838. }
  20839. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  20840. if (!isIdentityUnicode) {
  20841. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20842. map[+charCode] = unicodeCharCode;
  20843. });
  20844. }
  20845. this.toFontChar = map;
  20846. this.toUnicode = new ToUnicodeMap(map);
  20847. } else if (/Symbol/i.test(fontName)) {
  20848. var symbols = Encodings.SymbolSetEncoding;
  20849. for (charCode in symbols) {
  20850. fontChar = GlyphsUnicode[symbols[charCode]];
  20851. if (!fontChar) {
  20852. continue;
  20853. }
  20854. this.toFontChar[charCode] = fontChar;
  20855. }
  20856. for (charCode in properties.differences) {
  20857. fontChar = GlyphsUnicode[properties.differences[charCode]];
  20858. if (!fontChar) {
  20859. continue;
  20860. }
  20861. this.toFontChar[charCode] = fontChar;
  20862. }
  20863. } else if (/Dingbats/i.test(fontName)) {
  20864. if (/Wingdings/i.test(name)) {
  20865. warn('Wingdings font without embedded font file, ' +
  20866. 'falling back to the ZapfDingbats encoding.');
  20867. }
  20868. var dingbats = Encodings.ZapfDingbatsEncoding;
  20869. for (charCode in dingbats) {
  20870. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  20871. if (!fontChar) {
  20872. continue;
  20873. }
  20874. this.toFontChar[charCode] = fontChar;
  20875. }
  20876. for (charCode in properties.differences) {
  20877. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  20878. if (!fontChar) {
  20879. continue;
  20880. }
  20881. this.toFontChar[charCode] = fontChar;
  20882. }
  20883. } else if (isStandardFont) {
  20884. this.toFontChar = [];
  20885. for (charCode in properties.defaultEncoding) {
  20886. glyphName = (properties.differences[charCode] ||
  20887. properties.defaultEncoding[charCode]);
  20888. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  20889. }
  20890. } else {
  20891. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  20892. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  20893. if (notCidFont) {
  20894. glyphName = (properties.differences[charCode] ||
  20895. properties.defaultEncoding[charCode]);
  20896. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  20897. }
  20898. this.toFontChar[charCode] = unicodeCharCode;
  20899. }.bind(this));
  20900. }
  20901. this.loadedName = fontName.split('-')[0];
  20902. this.loading = false;
  20903. this.fontType = getFontType(type, subtype);
  20904. return;
  20905. }
  20906. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  20907. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  20908. // Some TrueType fonts by mistake claim Type1C
  20909. if (isTrueTypeFile(file)) {
  20910. subtype = 'TrueType';
  20911. } else {
  20912. type = 'Type1';
  20913. }
  20914. }
  20915. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  20916. type = 'CIDFontType0';
  20917. }
  20918. // XXX: Temporarily change the type for open type so we trigger a warning.
  20919. // This should be removed when we add support for open type.
  20920. if (subtype === 'OpenType') {
  20921. type = 'OpenType';
  20922. }
  20923. var data;
  20924. switch (type) {
  20925. case 'MMType1':
  20926. info('MMType1 font (' + name + '), falling back to Type1.');
  20927. /* falls through */
  20928. case 'Type1':
  20929. case 'CIDFontType0':
  20930. this.mimetype = 'font/opentype';
  20931. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  20932. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  20933. adjustWidths(properties);
  20934. // Wrap the CFF data inside an OTF font file
  20935. data = this.convert(name, cff, properties);
  20936. break;
  20937. case 'OpenType':
  20938. case 'TrueType':
  20939. case 'CIDFontType2':
  20940. this.mimetype = 'font/opentype';
  20941. // Repair the TrueType file. It is can be damaged in the point of
  20942. // view of the sanitizer
  20943. data = this.checkAndRepair(name, file, properties);
  20944. if (this.isOpenType) {
  20945. type = 'OpenType';
  20946. }
  20947. break;
  20948. default:
  20949. error('Font ' + type + ' is not supported');
  20950. break;
  20951. }
  20952. this.data = data;
  20953. this.fontType = getFontType(type, subtype);
  20954. // Transfer some properties again that could change during font conversion
  20955. this.fontMatrix = properties.fontMatrix;
  20956. this.widths = properties.widths;
  20957. this.defaultWidth = properties.defaultWidth;
  20958. this.encoding = properties.baseEncoding;
  20959. this.seacMap = properties.seacMap;
  20960. this.loading = true;
  20961. }
  20962. Font.getFontID = (function () {
  20963. var ID = 1;
  20964. return function Font_getFontID() {
  20965. return String(ID++);
  20966. };
  20967. })();
  20968. function int16(b0, b1) {
  20969. return (b0 << 8) + b1;
  20970. }
  20971. function int32(b0, b1, b2, b3) {
  20972. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20973. }
  20974. function string16(value) {
  20975. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20976. }
  20977. function safeString16(value) {
  20978. // clamp value to the 16-bit int range
  20979. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  20980. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  20981. }
  20982. function isTrueTypeFile(file) {
  20983. var header = file.peekBytes(4);
  20984. return readUint32(header, 0) === 0x00010000;
  20985. }
  20986. /**
  20987. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  20988. * with their unicode value. It also moves char codes that are in known
  20989. * problematic locations.
  20990. * @return {Object} Two properties:
  20991. * 'toFontChar' - maps original char codes(the value that will be read
  20992. * from commands such as show text) to the char codes that will be used in the
  20993. * font that we build
  20994. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  20995. */
  20996. function adjustMapping(charCodeToGlyphId, properties) {
  20997. var toUnicode = properties.toUnicode;
  20998. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  20999. var isIdentityUnicode =
  21000. properties.toUnicode instanceof IdentityToUnicodeMap;
  21001. var newMap = Object.create(null);
  21002. var toFontChar = [];
  21003. var usedFontCharCodes = [];
  21004. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  21005. for (var originalCharCode in charCodeToGlyphId) {
  21006. originalCharCode |= 0;
  21007. var glyphId = charCodeToGlyphId[originalCharCode];
  21008. var fontCharCode = originalCharCode;
  21009. // First try to map the value to a unicode position if a non identity map
  21010. // was created.
  21011. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  21012. var unicode = toUnicode.get(fontCharCode);
  21013. // TODO: Try to map ligatures to the correct spot.
  21014. if (unicode.length === 1) {
  21015. fontCharCode = unicode.charCodeAt(0);
  21016. }
  21017. }
  21018. // Try to move control characters, special characters and already mapped
  21019. // characters to the private use area since they will not be drawn by
  21020. // canvas if left in their current position. Also, move characters if the
  21021. // font was symbolic and there is only an identity unicode map since the
  21022. // characters probably aren't in the correct position (fixes an issue
  21023. // with firefox and thuluthfont).
  21024. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  21025. fontCharCode <= 0x1f || // Control chars
  21026. fontCharCode === 0x7F || // Control char
  21027. fontCharCode === 0xAD || // Soft hyphen
  21028. fontCharCode === 0xA0 || // Non breaking space
  21029. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  21030. // Prevent drawing characters in the specials unicode block.
  21031. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  21032. (isSymbolic && isIdentityUnicode)) &&
  21033. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  21034. // Loop to try and find a free spot in the private use area.
  21035. do {
  21036. fontCharCode = nextAvailableFontCharCode++;
  21037. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  21038. fontCharCode = 0xF020;
  21039. nextAvailableFontCharCode = fontCharCode + 1;
  21040. }
  21041. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  21042. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  21043. }
  21044. newMap[fontCharCode] = glyphId;
  21045. toFontChar[originalCharCode] = fontCharCode;
  21046. usedFontCharCodes[fontCharCode] = true;
  21047. }
  21048. return {
  21049. toFontChar: toFontChar,
  21050. charCodeToGlyphId: newMap,
  21051. nextAvailableFontCharCode: nextAvailableFontCharCode
  21052. };
  21053. }
  21054. function getRanges(glyphs) {
  21055. // Array.sort() sorts by characters, not numerically, so convert to an
  21056. // array of characters.
  21057. var codes = [];
  21058. for (var charCode in glyphs) {
  21059. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  21060. }
  21061. codes.sort(function fontGetRangesSort(a, b) {
  21062. return a.fontCharCode - b.fontCharCode;
  21063. });
  21064. // Split the sorted codes into ranges.
  21065. var ranges = [];
  21066. var length = codes.length;
  21067. for (var n = 0; n < length; ) {
  21068. var start = codes[n].fontCharCode;
  21069. var codeIndices = [codes[n].glyphId];
  21070. ++n;
  21071. var end = start;
  21072. while (n < length && end + 1 === codes[n].fontCharCode) {
  21073. codeIndices.push(codes[n].glyphId);
  21074. ++end;
  21075. ++n;
  21076. if (end === 0xFFFF) {
  21077. break;
  21078. }
  21079. }
  21080. ranges.push([start, end, codeIndices]);
  21081. }
  21082. return ranges;
  21083. }
  21084. function createCmapTable(glyphs) {
  21085. var ranges = getRanges(glyphs);
  21086. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  21087. var cmap = '\x00\x00' + // version
  21088. string16(numTables) + // numTables
  21089. '\x00\x03' + // platformID
  21090. '\x00\x01' + // encodingID
  21091. string32(4 + numTables * 8); // start of the table record
  21092. var i, ii, j, jj;
  21093. for (i = ranges.length - 1; i >= 0; --i) {
  21094. if (ranges[i][0] <= 0xFFFF) { break; }
  21095. }
  21096. var bmpLength = i + 1;
  21097. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  21098. ranges[i][1] = 0xFFFE;
  21099. }
  21100. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  21101. var segCount = bmpLength + trailingRangesCount;
  21102. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  21103. // Fill up the 4 parallel arrays describing the segments.
  21104. var startCount = '';
  21105. var endCount = '';
  21106. var idDeltas = '';
  21107. var idRangeOffsets = '';
  21108. var glyphsIds = '';
  21109. var bias = 0;
  21110. var range, start, end, codes;
  21111. for (i = 0, ii = bmpLength; i < ii; i++) {
  21112. range = ranges[i];
  21113. start = range[0];
  21114. end = range[1];
  21115. startCount += string16(start);
  21116. endCount += string16(end);
  21117. codes = range[2];
  21118. var contiguous = true;
  21119. for (j = 1, jj = codes.length; j < jj; ++j) {
  21120. if (codes[j] !== codes[j - 1] + 1) {
  21121. contiguous = false;
  21122. break;
  21123. }
  21124. }
  21125. if (!contiguous) {
  21126. var offset = (segCount - i) * 2 + bias * 2;
  21127. bias += (end - start + 1);
  21128. idDeltas += string16(0);
  21129. idRangeOffsets += string16(offset);
  21130. for (j = 0, jj = codes.length; j < jj; ++j) {
  21131. glyphsIds += string16(codes[j]);
  21132. }
  21133. } else {
  21134. var startCode = codes[0];
  21135. idDeltas += string16((startCode - start) & 0xFFFF);
  21136. idRangeOffsets += string16(0);
  21137. }
  21138. }
  21139. if (trailingRangesCount > 0) {
  21140. endCount += '\xFF\xFF';
  21141. startCount += '\xFF\xFF';
  21142. idDeltas += '\x00\x01';
  21143. idRangeOffsets += '\x00\x00';
  21144. }
  21145. var format314 = '\x00\x00' + // language
  21146. string16(2 * segCount) +
  21147. string16(searchParams.range) +
  21148. string16(searchParams.entry) +
  21149. string16(searchParams.rangeShift) +
  21150. endCount + '\x00\x00' + startCount +
  21151. idDeltas + idRangeOffsets + glyphsIds;
  21152. var format31012 = '';
  21153. var header31012 = '';
  21154. if (numTables > 1) {
  21155. cmap += '\x00\x03' + // platformID
  21156. '\x00\x0A' + // encodingID
  21157. string32(4 + numTables * 8 +
  21158. 4 + format314.length); // start of the table record
  21159. format31012 = '';
  21160. for (i = 0, ii = ranges.length; i < ii; i++) {
  21161. range = ranges[i];
  21162. start = range[0];
  21163. codes = range[2];
  21164. var code = codes[0];
  21165. for (j = 1, jj = codes.length; j < jj; ++j) {
  21166. if (codes[j] !== codes[j - 1] + 1) {
  21167. end = range[0] + j - 1;
  21168. format31012 += string32(start) + // startCharCode
  21169. string32(end) + // endCharCode
  21170. string32(code); // startGlyphID
  21171. start = end + 1;
  21172. code = codes[j];
  21173. }
  21174. }
  21175. format31012 += string32(start) + // startCharCode
  21176. string32(range[1]) + // endCharCode
  21177. string32(code); // startGlyphID
  21178. }
  21179. header31012 = '\x00\x0C' + // format
  21180. '\x00\x00' + // reserved
  21181. string32(format31012.length + 16) + // length
  21182. '\x00\x00\x00\x00' + // language
  21183. string32(format31012.length / 12); // nGroups
  21184. }
  21185. return cmap + '\x00\x04' + // format
  21186. string16(format314.length + 4) + // length
  21187. format314 + header31012 + format31012;
  21188. }
  21189. function validateOS2Table(os2) {
  21190. var stream = new Stream(os2.data);
  21191. var version = stream.getUint16();
  21192. // TODO verify all OS/2 tables fields, but currently we validate only those
  21193. // that give us issues
  21194. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  21195. var selection = stream.getUint16();
  21196. if (version < 4 && (selection & 0x0300)) {
  21197. return false;
  21198. }
  21199. var firstChar = stream.getUint16();
  21200. var lastChar = stream.getUint16();
  21201. if (firstChar > lastChar) {
  21202. return false;
  21203. }
  21204. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  21205. var usWinAscent = stream.getUint16();
  21206. if (usWinAscent === 0) { // makes font unreadable by windows
  21207. return false;
  21208. }
  21209. // OS/2 appears to be valid, resetting some fields
  21210. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  21211. return true;
  21212. }
  21213. function createOS2Table(properties, charstrings, override) {
  21214. override = override || {
  21215. unitsPerEm: 0,
  21216. yMax: 0,
  21217. yMin: 0,
  21218. ascent: 0,
  21219. descent: 0
  21220. };
  21221. var ulUnicodeRange1 = 0;
  21222. var ulUnicodeRange2 = 0;
  21223. var ulUnicodeRange3 = 0;
  21224. var ulUnicodeRange4 = 0;
  21225. var firstCharIndex = null;
  21226. var lastCharIndex = 0;
  21227. if (charstrings) {
  21228. for (var code in charstrings) {
  21229. code |= 0;
  21230. if (firstCharIndex > code || !firstCharIndex) {
  21231. firstCharIndex = code;
  21232. }
  21233. if (lastCharIndex < code) {
  21234. lastCharIndex = code;
  21235. }
  21236. var position = getUnicodeRangeFor(code);
  21237. if (position < 32) {
  21238. ulUnicodeRange1 |= 1 << position;
  21239. } else if (position < 64) {
  21240. ulUnicodeRange2 |= 1 << position - 32;
  21241. } else if (position < 96) {
  21242. ulUnicodeRange3 |= 1 << position - 64;
  21243. } else if (position < 123) {
  21244. ulUnicodeRange4 |= 1 << position - 96;
  21245. } else {
  21246. error('Unicode ranges Bits > 123 are reserved for internal usage');
  21247. }
  21248. }
  21249. } else {
  21250. // TODO
  21251. firstCharIndex = 0;
  21252. lastCharIndex = 255;
  21253. }
  21254. var bbox = properties.bbox || [0, 0, 0, 0];
  21255. var unitsPerEm = (override.unitsPerEm ||
  21256. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  21257. // if the font units differ to the PDF glyph space units
  21258. // then scale up the values
  21259. var scale = (properties.ascentScaled ? 1.0 :
  21260. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  21261. var typoAscent = (override.ascent ||
  21262. Math.round(scale * (properties.ascent || bbox[3])));
  21263. var typoDescent = (override.descent ||
  21264. Math.round(scale * (properties.descent || bbox[1])));
  21265. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  21266. typoDescent = -typoDescent; // fixing incorrect descent
  21267. }
  21268. var winAscent = override.yMax || typoAscent;
  21269. var winDescent = -override.yMin || -typoDescent;
  21270. return '\x00\x03' + // version
  21271. '\x02\x24' + // xAvgCharWidth
  21272. '\x01\xF4' + // usWeightClass
  21273. '\x00\x05' + // usWidthClass
  21274. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  21275. '\x02\x8A' + // ySubscriptXSize
  21276. '\x02\xBB' + // ySubscriptYSize
  21277. '\x00\x00' + // ySubscriptXOffset
  21278. '\x00\x8C' + // ySubscriptYOffset
  21279. '\x02\x8A' + // ySuperScriptXSize
  21280. '\x02\xBB' + // ySuperScriptYSize
  21281. '\x00\x00' + // ySuperScriptXOffset
  21282. '\x01\xDF' + // ySuperScriptYOffset
  21283. '\x00\x31' + // yStrikeOutSize
  21284. '\x01\x02' + // yStrikeOutPosition
  21285. '\x00\x00' + // sFamilyClass
  21286. '\x00\x00\x06' +
  21287. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  21288. '\x00\x00\x00\x00\x00\x00' + // Panose
  21289. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  21290. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  21291. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  21292. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  21293. '\x2A\x32\x31\x2A' + // achVendID
  21294. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  21295. string16(firstCharIndex ||
  21296. properties.firstChar) + // usFirstCharIndex
  21297. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  21298. string16(typoAscent) + // sTypoAscender
  21299. string16(typoDescent) + // sTypoDescender
  21300. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  21301. string16(winAscent) + // usWinAscent
  21302. string16(winDescent) + // usWinDescent
  21303. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  21304. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  21305. string16(properties.xHeight) + // sxHeight
  21306. string16(properties.capHeight) + // sCapHeight
  21307. string16(0) + // usDefaultChar
  21308. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  21309. '\x00\x03'; // usMaxContext
  21310. }
  21311. function createPostTable(properties) {
  21312. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  21313. return ('\x00\x03\x00\x00' + // Version number
  21314. string32(angle) + // italicAngle
  21315. '\x00\x00' + // underlinePosition
  21316. '\x00\x00' + // underlineThickness
  21317. string32(properties.fixedPitch) + // isFixedPitch
  21318. '\x00\x00\x00\x00' + // minMemType42
  21319. '\x00\x00\x00\x00' + // maxMemType42
  21320. '\x00\x00\x00\x00' + // minMemType1
  21321. '\x00\x00\x00\x00'); // maxMemType1
  21322. }
  21323. function createNameTable(name, proto) {
  21324. if (!proto) {
  21325. proto = [[], []]; // no strings and unicode strings
  21326. }
  21327. var strings = [
  21328. proto[0][0] || 'Original licence', // 0.Copyright
  21329. proto[0][1] || name, // 1.Font family
  21330. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  21331. proto[0][3] || 'uniqueID', // 3.Unique ID
  21332. proto[0][4] || name, // 4.Full font name
  21333. proto[0][5] || 'Version 0.11', // 5.Version
  21334. proto[0][6] || '', // 6.Postscript name
  21335. proto[0][7] || 'Unknown', // 7.Trademark
  21336. proto[0][8] || 'Unknown', // 8.Manufacturer
  21337. proto[0][9] || 'Unknown' // 9.Designer
  21338. ];
  21339. // Mac want 1-byte per character strings while Windows want
  21340. // 2-bytes per character, so duplicate the names table
  21341. var stringsUnicode = [];
  21342. var i, ii, j, jj, str;
  21343. for (i = 0, ii = strings.length; i < ii; i++) {
  21344. str = proto[1][i] || strings[i];
  21345. var strBufUnicode = [];
  21346. for (j = 0, jj = str.length; j < jj; j++) {
  21347. strBufUnicode.push(string16(str.charCodeAt(j)));
  21348. }
  21349. stringsUnicode.push(strBufUnicode.join(''));
  21350. }
  21351. var names = [strings, stringsUnicode];
  21352. var platforms = ['\x00\x01', '\x00\x03'];
  21353. var encodings = ['\x00\x00', '\x00\x01'];
  21354. var languages = ['\x00\x00', '\x04\x09'];
  21355. var namesRecordCount = strings.length * platforms.length;
  21356. var nameTable =
  21357. '\x00\x00' + // format
  21358. string16(namesRecordCount) + // Number of names Record
  21359. string16(namesRecordCount * 12 + 6); // Storage
  21360. // Build the name records field
  21361. var strOffset = 0;
  21362. for (i = 0, ii = platforms.length; i < ii; i++) {
  21363. var strs = names[i];
  21364. for (j = 0, jj = strs.length; j < jj; j++) {
  21365. str = strs[j];
  21366. var nameRecord =
  21367. platforms[i] + // platform ID
  21368. encodings[i] + // encoding ID
  21369. languages[i] + // language ID
  21370. string16(j) + // name ID
  21371. string16(str.length) +
  21372. string16(strOffset);
  21373. nameTable += nameRecord;
  21374. strOffset += str.length;
  21375. }
  21376. }
  21377. nameTable += strings.join('') + stringsUnicode.join('');
  21378. return nameTable;
  21379. }
  21380. Font.prototype = {
  21381. name: null,
  21382. font: null,
  21383. mimetype: null,
  21384. encoding: null,
  21385. get renderer() {
  21386. var renderer = FontRendererFactory.create(this);
  21387. return shadow(this, 'renderer', renderer);
  21388. },
  21389. exportData: function Font_exportData() {
  21390. var data = {};
  21391. for (var i in this) {
  21392. if (this.hasOwnProperty(i)) {
  21393. data[i] = this[i];
  21394. }
  21395. }
  21396. return data;
  21397. },
  21398. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  21399. function readTableEntry(file) {
  21400. var tag = bytesToString(file.getBytes(4));
  21401. var checksum = file.getInt32();
  21402. var offset = file.getInt32() >>> 0;
  21403. var length = file.getInt32() >>> 0;
  21404. // Read the table associated data
  21405. var previousPosition = file.pos;
  21406. file.pos = file.start ? file.start : 0;
  21407. file.skip(offset);
  21408. var data = file.getBytes(length);
  21409. file.pos = previousPosition;
  21410. if (tag === 'head') {
  21411. // clearing checksum adjustment
  21412. data[8] = data[9] = data[10] = data[11] = 0;
  21413. data[17] |= 0x20; //Set font optimized for cleartype flag
  21414. }
  21415. return {
  21416. tag: tag,
  21417. checksum: checksum,
  21418. length: length,
  21419. offset: offset,
  21420. data: data
  21421. };
  21422. }
  21423. function readOpenTypeHeader(ttf) {
  21424. return {
  21425. version: bytesToString(ttf.getBytes(4)),
  21426. numTables: ttf.getUint16(),
  21427. searchRange: ttf.getUint16(),
  21428. entrySelector: ttf.getUint16(),
  21429. rangeShift: ttf.getUint16()
  21430. };
  21431. }
  21432. /**
  21433. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  21434. * PDF spec
  21435. */
  21436. function readCmapTable(cmap, font, isSymbolicFont) {
  21437. var segment;
  21438. var start = (font.start ? font.start : 0) + cmap.offset;
  21439. font.pos = start;
  21440. var version = font.getUint16();
  21441. var numTables = font.getUint16();
  21442. var potentialTable;
  21443. var canBreak = false;
  21444. // There's an order of preference in terms of which cmap subtable to
  21445. // use:
  21446. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  21447. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  21448. // The following takes advantage of the fact that the tables are sorted
  21449. // to work.
  21450. for (var i = 0; i < numTables; i++) {
  21451. var platformId = font.getUint16();
  21452. var encodingId = font.getUint16();
  21453. var offset = font.getInt32() >>> 0;
  21454. var useTable = false;
  21455. if (platformId === 0 && encodingId === 0) {
  21456. useTable = true;
  21457. // Continue the loop since there still may be a higher priority
  21458. // table.
  21459. } else if (platformId === 1 && encodingId === 0) {
  21460. useTable = true;
  21461. // Continue the loop since there still may be a higher priority
  21462. // table.
  21463. } else if (platformId === 3 && encodingId === 1 &&
  21464. (!isSymbolicFont || !potentialTable)) {
  21465. useTable = true;
  21466. if (!isSymbolicFont) {
  21467. canBreak = true;
  21468. }
  21469. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  21470. useTable = true;
  21471. canBreak = true;
  21472. }
  21473. if (useTable) {
  21474. potentialTable = {
  21475. platformId: platformId,
  21476. encodingId: encodingId,
  21477. offset: offset
  21478. };
  21479. }
  21480. if (canBreak) {
  21481. break;
  21482. }
  21483. }
  21484. if (!potentialTable) {
  21485. warn('Could not find a preferred cmap table.');
  21486. return {
  21487. platformId: -1,
  21488. encodingId: -1,
  21489. mappings: [],
  21490. hasShortCmap: false
  21491. };
  21492. }
  21493. font.pos = start + potentialTable.offset;
  21494. var format = font.getUint16();
  21495. var length = font.getUint16();
  21496. var language = font.getUint16();
  21497. var hasShortCmap = false;
  21498. var mappings = [];
  21499. var j, glyphId;
  21500. // TODO(mack): refactor this cmap subtable reading logic out
  21501. if (format === 0) {
  21502. for (j = 0; j < 256; j++) {
  21503. var index = font.getByte();
  21504. if (!index) {
  21505. continue;
  21506. }
  21507. mappings.push({
  21508. charCode: j,
  21509. glyphId: index
  21510. });
  21511. }
  21512. hasShortCmap = true;
  21513. } else if (format === 4) {
  21514. // re-creating the table in format 4 since the encoding
  21515. // might be changed
  21516. var segCount = (font.getUint16() >> 1);
  21517. font.getBytes(6); // skipping range fields
  21518. var segIndex, segments = [];
  21519. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21520. segments.push({ end: font.getUint16() });
  21521. }
  21522. font.getUint16();
  21523. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21524. segments[segIndex].start = font.getUint16();
  21525. }
  21526. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21527. segments[segIndex].delta = font.getUint16();
  21528. }
  21529. var offsetsCount = 0;
  21530. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21531. segment = segments[segIndex];
  21532. var rangeOffset = font.getUint16();
  21533. if (!rangeOffset) {
  21534. segment.offsetIndex = -1;
  21535. continue;
  21536. }
  21537. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  21538. segment.offsetIndex = offsetIndex;
  21539. offsetsCount = Math.max(offsetsCount, offsetIndex +
  21540. segment.end - segment.start + 1);
  21541. }
  21542. var offsets = [];
  21543. for (j = 0; j < offsetsCount; j++) {
  21544. offsets.push(font.getUint16());
  21545. }
  21546. for (segIndex = 0; segIndex < segCount; segIndex++) {
  21547. segment = segments[segIndex];
  21548. start = segment.start;
  21549. var end = segment.end;
  21550. var delta = segment.delta;
  21551. offsetIndex = segment.offsetIndex;
  21552. for (j = start; j <= end; j++) {
  21553. if (j === 0xFFFF) {
  21554. continue;
  21555. }
  21556. glyphId = (offsetIndex < 0 ?
  21557. j : offsets[offsetIndex + j - start]);
  21558. glyphId = (glyphId + delta) & 0xFFFF;
  21559. if (glyphId === 0) {
  21560. continue;
  21561. }
  21562. mappings.push({
  21563. charCode: j,
  21564. glyphId: glyphId
  21565. });
  21566. }
  21567. }
  21568. } else if (format === 6) {
  21569. // Format 6 is a 2-bytes dense mapping, which means the font data
  21570. // lives glue together even if they are pretty far in the unicode
  21571. // table. (This looks weird, so I can have missed something), this
  21572. // works on Linux but seems to fails on Mac so let's rewrite the
  21573. // cmap table to a 3-1-4 style
  21574. var firstCode = font.getUint16();
  21575. var entryCount = font.getUint16();
  21576. for (j = 0; j < entryCount; j++) {
  21577. glyphId = font.getUint16();
  21578. var charCode = firstCode + j;
  21579. mappings.push({
  21580. charCode: charCode,
  21581. glyphId: glyphId
  21582. });
  21583. }
  21584. } else {
  21585. error('cmap table has unsupported format: ' + format);
  21586. }
  21587. // removing duplicate entries
  21588. mappings.sort(function (a, b) {
  21589. return a.charCode - b.charCode;
  21590. });
  21591. for (i = 1; i < mappings.length; i++) {
  21592. if (mappings[i - 1].charCode === mappings[i].charCode) {
  21593. mappings.splice(i, 1);
  21594. i--;
  21595. }
  21596. }
  21597. return {
  21598. platformId: potentialTable.platformId,
  21599. encodingId: potentialTable.encodingId,
  21600. mappings: mappings,
  21601. hasShortCmap: hasShortCmap
  21602. };
  21603. }
  21604. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  21605. if (!header) {
  21606. if (metrics) {
  21607. metrics.data = null;
  21608. }
  21609. return;
  21610. }
  21611. font.pos = (font.start ? font.start : 0) + header.offset;
  21612. font.pos += header.length - 2;
  21613. var numOfMetrics = font.getUint16();
  21614. if (numOfMetrics > numGlyphs) {
  21615. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  21616. 'greater than the numGlyphs (' + numGlyphs + ')');
  21617. // Reduce numOfMetrics if it is greater than numGlyphs
  21618. numOfMetrics = numGlyphs;
  21619. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  21620. header.data[35] = numOfMetrics & 0x00ff;
  21621. }
  21622. var numOfSidebearings = numGlyphs - numOfMetrics;
  21623. var numMissing = numOfSidebearings -
  21624. ((metrics.length - numOfMetrics * 4) >> 1);
  21625. if (numMissing > 0) {
  21626. // For each missing glyph, we set both the width and lsb to 0 (zero).
  21627. // Since we need to add two properties for each glyph, this explains
  21628. // the use of |numMissing * 2| when initializing the typed array.
  21629. var entries = new Uint8Array(metrics.length + numMissing * 2);
  21630. entries.set(metrics.data);
  21631. metrics.data = entries;
  21632. }
  21633. }
  21634. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  21635. hintsValid) {
  21636. if (sourceEnd - sourceStart <= 12) {
  21637. // glyph with data less than 12 is invalid one
  21638. return 0;
  21639. }
  21640. var glyf = source.subarray(sourceStart, sourceEnd);
  21641. var contoursCount = (glyf[0] << 8) | glyf[1];
  21642. if (contoursCount & 0x8000) {
  21643. // complex glyph, writing as is
  21644. dest.set(glyf, destStart);
  21645. return glyf.length;
  21646. }
  21647. var i, j = 10, flagsCount = 0;
  21648. for (i = 0; i < contoursCount; i++) {
  21649. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  21650. flagsCount = endPoint + 1;
  21651. j += 2;
  21652. }
  21653. // skipping instructions
  21654. var instructionsStart = j;
  21655. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  21656. j += 2 + instructionsLength;
  21657. var instructionsEnd = j;
  21658. // validating flags
  21659. var coordinatesLength = 0;
  21660. for (i = 0; i < flagsCount; i++) {
  21661. var flag = glyf[j++];
  21662. if (flag & 0xC0) {
  21663. // reserved flags must be zero, cleaning up
  21664. glyf[j - 1] = flag & 0x3F;
  21665. }
  21666. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  21667. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  21668. coordinatesLength += xyLength;
  21669. if (flag & 8) {
  21670. var repeat = glyf[j++];
  21671. i += repeat;
  21672. coordinatesLength += repeat * xyLength;
  21673. }
  21674. }
  21675. // glyph without coordinates will be rejected
  21676. if (coordinatesLength === 0) {
  21677. return 0;
  21678. }
  21679. var glyphDataLength = j + coordinatesLength;
  21680. if (glyphDataLength > glyf.length) {
  21681. // not enough data for coordinates
  21682. return 0;
  21683. }
  21684. if (!hintsValid && instructionsLength > 0) {
  21685. dest.set(glyf.subarray(0, instructionsStart), destStart);
  21686. dest.set([0, 0], destStart + instructionsStart);
  21687. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  21688. destStart + instructionsStart + 2);
  21689. glyphDataLength -= instructionsLength;
  21690. if (glyf.length - glyphDataLength > 3) {
  21691. glyphDataLength = (glyphDataLength + 3) & ~3;
  21692. }
  21693. return glyphDataLength;
  21694. }
  21695. if (glyf.length - glyphDataLength > 3) {
  21696. // truncating and aligning to 4 bytes the long glyph data
  21697. glyphDataLength = (glyphDataLength + 3) & ~3;
  21698. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  21699. return glyphDataLength;
  21700. }
  21701. // glyph data is fine
  21702. dest.set(glyf, destStart);
  21703. return glyf.length;
  21704. }
  21705. function sanitizeHead(head, numGlyphs, locaLength) {
  21706. var data = head.data;
  21707. // Validate version:
  21708. // Should always be 0x00010000
  21709. var version = int32(data[0], data[1], data[2], data[3]);
  21710. if (version >> 16 !== 1) {
  21711. info('Attempting to fix invalid version in head table: ' + version);
  21712. data[0] = 0;
  21713. data[1] = 1;
  21714. data[2] = 0;
  21715. data[3] = 0;
  21716. }
  21717. var indexToLocFormat = int16(data[50], data[51]);
  21718. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  21719. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  21720. indexToLocFormat);
  21721. // The value of indexToLocFormat should be 0 if the loca table
  21722. // consists of short offsets, and should be 1 if the loca table
  21723. // consists of long offsets.
  21724. //
  21725. // The number of entries in the loca table should be numGlyphs + 1.
  21726. //
  21727. // Using this information, we can work backwards to deduce if the
  21728. // size of each offset in the loca table, and thus figure out the
  21729. // appropriate value for indexToLocFormat.
  21730. var numGlyphsPlusOne = numGlyphs + 1;
  21731. if (locaLength === numGlyphsPlusOne << 1) {
  21732. // 0x0000 indicates the loca table consists of short offsets
  21733. data[50] = 0;
  21734. data[51] = 0;
  21735. } else if (locaLength === numGlyphsPlusOne << 2) {
  21736. // 0x0001 indicates the loca table consists of long offsets
  21737. data[50] = 0;
  21738. data[51] = 1;
  21739. } else {
  21740. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  21741. }
  21742. }
  21743. }
  21744. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  21745. isGlyphLocationsLong, hintsValid,
  21746. dupFirstEntry) {
  21747. var itemSize, itemDecode, itemEncode;
  21748. if (isGlyphLocationsLong) {
  21749. itemSize = 4;
  21750. itemDecode = function fontItemDecodeLong(data, offset) {
  21751. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21752. (data[offset + 2] << 8) | data[offset + 3];
  21753. };
  21754. itemEncode = function fontItemEncodeLong(data, offset, value) {
  21755. data[offset] = (value >>> 24) & 0xFF;
  21756. data[offset + 1] = (value >> 16) & 0xFF;
  21757. data[offset + 2] = (value >> 8) & 0xFF;
  21758. data[offset + 3] = value & 0xFF;
  21759. };
  21760. } else {
  21761. itemSize = 2;
  21762. itemDecode = function fontItemDecode(data, offset) {
  21763. return (data[offset] << 9) | (data[offset + 1] << 1);
  21764. };
  21765. itemEncode = function fontItemEncode(data, offset, value) {
  21766. data[offset] = (value >> 9) & 0xFF;
  21767. data[offset + 1] = (value >> 1) & 0xFF;
  21768. };
  21769. }
  21770. var locaData = loca.data;
  21771. var locaDataSize = itemSize * (1 + numGlyphs);
  21772. // is loca.data too short or long?
  21773. if (locaData.length !== locaDataSize) {
  21774. locaData = new Uint8Array(locaDataSize);
  21775. locaData.set(loca.data.subarray(0, locaDataSize));
  21776. loca.data = locaData;
  21777. }
  21778. // removing the invalid glyphs
  21779. var oldGlyfData = glyf.data;
  21780. var oldGlyfDataLength = oldGlyfData.length;
  21781. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  21782. var startOffset = itemDecode(locaData, 0);
  21783. var writeOffset = 0;
  21784. var missingGlyphData = {};
  21785. itemEncode(locaData, 0, writeOffset);
  21786. var i, j;
  21787. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21788. var endOffset = itemDecode(locaData, j);
  21789. if (endOffset > oldGlyfDataLength &&
  21790. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  21791. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  21792. // the glyf table size, which makes last glyph out of range.
  21793. endOffset = oldGlyfDataLength;
  21794. }
  21795. if (endOffset > oldGlyfDataLength) {
  21796. // glyph end offset points outside glyf data, rejecting the glyph
  21797. itemEncode(locaData, j, writeOffset);
  21798. startOffset = endOffset;
  21799. continue;
  21800. }
  21801. if (startOffset === endOffset) {
  21802. missingGlyphData[i] = true;
  21803. }
  21804. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  21805. newGlyfData, writeOffset, hintsValid);
  21806. writeOffset += newLength;
  21807. itemEncode(locaData, j, writeOffset);
  21808. startOffset = endOffset;
  21809. }
  21810. if (writeOffset === 0) {
  21811. // glyf table cannot be empty -- redoing the glyf and loca tables
  21812. // to have single glyph with one point
  21813. var simpleGlyph = new Uint8Array(
  21814. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  21815. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  21816. itemEncode(locaData, j, simpleGlyph.length);
  21817. }
  21818. glyf.data = simpleGlyph;
  21819. return missingGlyphData;
  21820. }
  21821. if (dupFirstEntry) {
  21822. var firstEntryLength = itemDecode(locaData, itemSize);
  21823. if (newGlyfData.length > firstEntryLength + writeOffset) {
  21824. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  21825. } else {
  21826. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  21827. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  21828. }
  21829. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  21830. itemEncode(loca.data, locaData.length - itemSize,
  21831. writeOffset + firstEntryLength);
  21832. } else {
  21833. glyf.data = newGlyfData.subarray(0, writeOffset);
  21834. }
  21835. return missingGlyphData;
  21836. }
  21837. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  21838. var start = (font.start ? font.start : 0) + post.offset;
  21839. font.pos = start;
  21840. var length = post.length, end = start + length;
  21841. var version = font.getInt32();
  21842. // skip rest to the tables
  21843. font.getBytes(28);
  21844. var glyphNames;
  21845. var valid = true;
  21846. var i;
  21847. switch (version) {
  21848. case 0x00010000:
  21849. glyphNames = MacStandardGlyphOrdering;
  21850. break;
  21851. case 0x00020000:
  21852. var numGlyphs = font.getUint16();
  21853. if (numGlyphs !== maxpNumGlyphs) {
  21854. valid = false;
  21855. break;
  21856. }
  21857. var glyphNameIndexes = [];
  21858. for (i = 0; i < numGlyphs; ++i) {
  21859. var index = font.getUint16();
  21860. if (index >= 32768) {
  21861. valid = false;
  21862. break;
  21863. }
  21864. glyphNameIndexes.push(index);
  21865. }
  21866. if (!valid) {
  21867. break;
  21868. }
  21869. var customNames = [];
  21870. var strBuf = [];
  21871. while (font.pos < end) {
  21872. var stringLength = font.getByte();
  21873. strBuf.length = stringLength;
  21874. for (i = 0; i < stringLength; ++i) {
  21875. strBuf[i] = String.fromCharCode(font.getByte());
  21876. }
  21877. customNames.push(strBuf.join(''));
  21878. }
  21879. glyphNames = [];
  21880. for (i = 0; i < numGlyphs; ++i) {
  21881. var j = glyphNameIndexes[i];
  21882. if (j < 258) {
  21883. glyphNames.push(MacStandardGlyphOrdering[j]);
  21884. continue;
  21885. }
  21886. glyphNames.push(customNames[j - 258]);
  21887. }
  21888. break;
  21889. case 0x00030000:
  21890. break;
  21891. default:
  21892. warn('Unknown/unsupported post table version ' + version);
  21893. valid = false;
  21894. break;
  21895. }
  21896. properties.glyphNames = glyphNames;
  21897. return valid;
  21898. }
  21899. function readNameTable(nameTable) {
  21900. var start = (font.start ? font.start : 0) + nameTable.offset;
  21901. font.pos = start;
  21902. var names = [[], []];
  21903. var length = nameTable.length, end = start + length;
  21904. var format = font.getUint16();
  21905. var FORMAT_0_HEADER_LENGTH = 6;
  21906. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  21907. // unsupported name table format or table "too" small
  21908. return names;
  21909. }
  21910. var numRecords = font.getUint16();
  21911. var stringsStart = font.getUint16();
  21912. var records = [];
  21913. var NAME_RECORD_LENGTH = 12;
  21914. var i, ii;
  21915. for (i = 0; i < numRecords &&
  21916. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  21917. var r = {
  21918. platform: font.getUint16(),
  21919. encoding: font.getUint16(),
  21920. language: font.getUint16(),
  21921. name: font.getUint16(),
  21922. length: font.getUint16(),
  21923. offset: font.getUint16()
  21924. };
  21925. // using only Macintosh and Windows platform/encoding names
  21926. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  21927. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  21928. records.push(r);
  21929. }
  21930. }
  21931. for (i = 0, ii = records.length; i < ii; i++) {
  21932. var record = records[i];
  21933. var pos = start + stringsStart + record.offset;
  21934. if (pos + record.length > end) {
  21935. continue; // outside of name table, ignoring
  21936. }
  21937. font.pos = pos;
  21938. var nameIndex = record.name;
  21939. if (record.encoding) {
  21940. // unicode
  21941. var str = '';
  21942. for (var j = 0, jj = record.length; j < jj; j += 2) {
  21943. str += String.fromCharCode(font.getUint16());
  21944. }
  21945. names[1][nameIndex] = str;
  21946. } else {
  21947. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  21948. }
  21949. }
  21950. return names;
  21951. }
  21952. var TTOpsStackDeltas = [
  21953. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  21954. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  21955. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  21956. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  21957. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  21958. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  21959. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  21960. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  21961. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  21962. // 0xC0-DF == -1 and 0xE0-FF == -2
  21963. function sanitizeTTProgram(table, ttContext) {
  21964. var data = table.data;
  21965. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  21966. var stack = [];
  21967. var callstack = [];
  21968. var functionsCalled = [];
  21969. var tooComplexToFollowFunctions =
  21970. ttContext.tooComplexToFollowFunctions;
  21971. var inFDEF = false, ifLevel = 0, inELSE = 0;
  21972. for (var ii = data.length; i < ii;) {
  21973. var op = data[i++];
  21974. // The TrueType instruction set docs can be found at
  21975. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  21976. if (op === 0x40) { // NPUSHB - pushes n bytes
  21977. n = data[i++];
  21978. if (inFDEF || inELSE) {
  21979. i += n;
  21980. } else {
  21981. for (j = 0; j < n; j++) {
  21982. stack.push(data[i++]);
  21983. }
  21984. }
  21985. } else if (op === 0x41) { // NPUSHW - pushes n words
  21986. n = data[i++];
  21987. if (inFDEF || inELSE) {
  21988. i += n * 2;
  21989. } else {
  21990. for (j = 0; j < n; j++) {
  21991. b = data[i++];
  21992. stack.push((b << 8) | data[i++]);
  21993. }
  21994. }
  21995. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  21996. n = op - 0xB0 + 1;
  21997. if (inFDEF || inELSE) {
  21998. i += n;
  21999. } else {
  22000. for (j = 0; j < n; j++) {
  22001. stack.push(data[i++]);
  22002. }
  22003. }
  22004. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  22005. n = op - 0xB8 + 1;
  22006. if (inFDEF || inELSE) {
  22007. i += n * 2;
  22008. } else {
  22009. for (j = 0; j < n; j++) {
  22010. b = data[i++];
  22011. stack.push((b << 8) | data[i++]);
  22012. }
  22013. }
  22014. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  22015. if (!inFDEF && !inELSE) {
  22016. // collecting inforamtion about which functions are used
  22017. funcId = stack[stack.length - 1];
  22018. ttContext.functionsUsed[funcId] = true;
  22019. if (funcId in ttContext.functionsStackDeltas) {
  22020. stack.length += ttContext.functionsStackDeltas[funcId];
  22021. } else if (funcId in ttContext.functionsDefined &&
  22022. functionsCalled.indexOf(funcId) < 0) {
  22023. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  22024. functionsCalled.push(funcId);
  22025. pc = ttContext.functionsDefined[funcId];
  22026. if (!pc) {
  22027. warn('TT: CALL non-existent function');
  22028. ttContext.hintsValid = false;
  22029. return;
  22030. }
  22031. data = pc.data;
  22032. i = pc.i;
  22033. }
  22034. }
  22035. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  22036. if (inFDEF || inELSE) {
  22037. warn('TT: nested FDEFs not allowed');
  22038. tooComplexToFollowFunctions = true;
  22039. }
  22040. inFDEF = true;
  22041. // collecting inforamtion about which functions are defined
  22042. lastDeff = i;
  22043. funcId = stack.pop();
  22044. ttContext.functionsDefined[funcId] = {data: data, i: i};
  22045. } else if (op === 0x2D) { // ENDF - end of function
  22046. if (inFDEF) {
  22047. inFDEF = false;
  22048. lastEndf = i;
  22049. } else {
  22050. pc = callstack.pop();
  22051. if (!pc) {
  22052. warn('TT: ENDF bad stack');
  22053. ttContext.hintsValid = false;
  22054. return;
  22055. }
  22056. funcId = functionsCalled.pop();
  22057. data = pc.data;
  22058. i = pc.i;
  22059. ttContext.functionsStackDeltas[funcId] =
  22060. stack.length - pc.stackTop;
  22061. }
  22062. } else if (op === 0x89) { // IDEF - instruction definition
  22063. if (inFDEF || inELSE) {
  22064. warn('TT: nested IDEFs not allowed');
  22065. tooComplexToFollowFunctions = true;
  22066. }
  22067. inFDEF = true;
  22068. // recording it as a function to track ENDF
  22069. lastDeff = i;
  22070. } else if (op === 0x58) { // IF
  22071. ++ifLevel;
  22072. } else if (op === 0x1B) { // ELSE
  22073. inELSE = ifLevel;
  22074. } else if (op === 0x59) { // EIF
  22075. if (inELSE === ifLevel) {
  22076. inELSE = 0;
  22077. }
  22078. --ifLevel;
  22079. } else if (op === 0x1C) { // JMPR
  22080. if (!inFDEF && !inELSE) {
  22081. var offset = stack[stack.length - 1];
  22082. // only jumping forward to prevent infinite loop
  22083. if (offset > 0) {
  22084. i += offset - 1;
  22085. }
  22086. }
  22087. }
  22088. // Adjusting stack not extactly, but just enough to get function id
  22089. if (!inFDEF && !inELSE) {
  22090. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  22091. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  22092. if (op >= 0x71 && op <= 0x75) {
  22093. n = stack.pop();
  22094. if (n === n) {
  22095. stackDelta = -n * 2;
  22096. }
  22097. }
  22098. while (stackDelta < 0 && stack.length > 0) {
  22099. stack.pop();
  22100. stackDelta++;
  22101. }
  22102. while (stackDelta > 0) {
  22103. stack.push(NaN); // pushing any number into stack
  22104. stackDelta--;
  22105. }
  22106. }
  22107. }
  22108. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  22109. var content = [data];
  22110. if (i > data.length) {
  22111. content.push(new Uint8Array(i - data.length));
  22112. }
  22113. if (lastDeff > lastEndf) {
  22114. warn('TT: complementing a missing function tail');
  22115. // new function definition started, but not finished
  22116. // complete function by [CLEAR, ENDF]
  22117. content.push(new Uint8Array([0x22, 0x2D]));
  22118. }
  22119. foldTTTable(table, content);
  22120. }
  22121. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  22122. if (ttContext.tooComplexToFollowFunctions) {
  22123. return;
  22124. }
  22125. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  22126. warn('TT: more functions defined than expected');
  22127. ttContext.hintsValid = false;
  22128. return;
  22129. }
  22130. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  22131. if (j > maxFunctionDefs) {
  22132. warn('TT: invalid function id: ' + j);
  22133. ttContext.hintsValid = false;
  22134. return;
  22135. }
  22136. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  22137. warn('TT: undefined function: ' + j);
  22138. ttContext.hintsValid = false;
  22139. return;
  22140. }
  22141. }
  22142. }
  22143. function foldTTTable(table, content) {
  22144. if (content.length > 1) {
  22145. // concatenating the content items
  22146. var newLength = 0;
  22147. var j, jj;
  22148. for (j = 0, jj = content.length; j < jj; j++) {
  22149. newLength += content[j].length;
  22150. }
  22151. newLength = (newLength + 3) & ~3;
  22152. var result = new Uint8Array(newLength);
  22153. var pos = 0;
  22154. for (j = 0, jj = content.length; j < jj; j++) {
  22155. result.set(content[j], pos);
  22156. pos += content[j].length;
  22157. }
  22158. table.data = result;
  22159. table.length = newLength;
  22160. }
  22161. }
  22162. function sanitizeTTPrograms(fpgm, prep, cvt) {
  22163. var ttContext = {
  22164. functionsDefined: [],
  22165. functionsUsed: [],
  22166. functionsStackDeltas: [],
  22167. tooComplexToFollowFunctions: false,
  22168. hintsValid: true
  22169. };
  22170. if (fpgm) {
  22171. sanitizeTTProgram(fpgm, ttContext);
  22172. }
  22173. if (prep) {
  22174. sanitizeTTProgram(prep, ttContext);
  22175. }
  22176. if (fpgm) {
  22177. checkInvalidFunctions(ttContext, maxFunctionDefs);
  22178. }
  22179. if (cvt && (cvt.length & 1)) {
  22180. var cvtData = new Uint8Array(cvt.length + 1);
  22181. cvtData.set(cvt.data);
  22182. cvt.data = cvtData;
  22183. }
  22184. return ttContext.hintsValid;
  22185. }
  22186. // The following steps modify the original font data, making copy
  22187. font = new Stream(new Uint8Array(font.getBytes()));
  22188. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  22189. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  22190. var header = readOpenTypeHeader(font);
  22191. var numTables = header.numTables;
  22192. var cff, cffFile;
  22193. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  22194. hmtx: null, maxp: null, name: null, post: null };
  22195. var table;
  22196. for (var i = 0; i < numTables; i++) {
  22197. table = readTableEntry(font);
  22198. if (VALID_TABLES.indexOf(table.tag) < 0) {
  22199. continue; // skipping table if it's not a required or optional table
  22200. }
  22201. if (table.length === 0) {
  22202. continue; // skipping empty tables
  22203. }
  22204. tables[table.tag] = table;
  22205. }
  22206. var isTrueType = !tables['CFF '];
  22207. if (!isTrueType) {
  22208. // OpenType font
  22209. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  22210. // no major tables: throwing everything at CFFFont
  22211. cffFile = new Stream(tables['CFF '].data);
  22212. cff = new CFFFont(cffFile, properties);
  22213. return this.convert(name, cff, properties);
  22214. }
  22215. delete tables.glyf;
  22216. delete tables.loca;
  22217. delete tables.fpgm;
  22218. delete tables.prep;
  22219. delete tables['cvt '];
  22220. this.isOpenType = true;
  22221. } else {
  22222. if (!tables.glyf || !tables.loca) {
  22223. error('Required "glyf" or "loca" tables are not found');
  22224. }
  22225. this.isOpenType = false;
  22226. }
  22227. if (!tables.maxp) {
  22228. error('Required "maxp" table is not found');
  22229. }
  22230. font.pos = (font.start || 0) + tables.maxp.offset;
  22231. var version = font.getInt32();
  22232. var numGlyphs = font.getUint16();
  22233. var maxFunctionDefs = 0;
  22234. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  22235. // maxZones can be invalid
  22236. font.pos += 8;
  22237. var maxZones = font.getUint16();
  22238. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  22239. tables.maxp.data[14] = 0;
  22240. tables.maxp.data[15] = 2;
  22241. }
  22242. font.pos += 4;
  22243. maxFunctionDefs = font.getUint16();
  22244. }
  22245. var dupFirstEntry = false;
  22246. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  22247. properties.toUnicode.get(0) > '\u0000') {
  22248. // oracle's defect (see 3427), duplicating first entry
  22249. dupFirstEntry = true;
  22250. numGlyphs++;
  22251. tables.maxp.data[4] = numGlyphs >> 8;
  22252. tables.maxp.data[5] = numGlyphs & 255;
  22253. }
  22254. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  22255. tables['cvt '], maxFunctionDefs);
  22256. if (!hintsValid) {
  22257. delete tables.fpgm;
  22258. delete tables.prep;
  22259. delete tables['cvt '];
  22260. }
  22261. // Ensure the hmtx table contains the advance width and
  22262. // sidebearings information for numGlyphs in the maxp table
  22263. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  22264. if (!tables.head) {
  22265. error('Required "head" table is not found');
  22266. }
  22267. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  22268. var missingGlyphs = {};
  22269. if (isTrueType) {
  22270. var isGlyphLocationsLong = int16(tables.head.data[50],
  22271. tables.head.data[51]);
  22272. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  22273. numGlyphs, isGlyphLocationsLong,
  22274. hintsValid, dupFirstEntry);
  22275. }
  22276. if (!tables.hhea) {
  22277. error('Required "hhea" table is not found');
  22278. }
  22279. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  22280. // Sometimes it's 0. That needs to be fixed
  22281. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  22282. tables.hhea.data[10] = 0xFF;
  22283. tables.hhea.data[11] = 0xFF;
  22284. }
  22285. // The 'post' table has glyphs names.
  22286. if (tables.post) {
  22287. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  22288. if (!valid) {
  22289. tables.post = null;
  22290. }
  22291. }
  22292. var charCodeToGlyphId = [], charCode, toUnicode = properties.toUnicode;
  22293. function hasGlyph(glyphId, charCode) {
  22294. if (!missingGlyphs[glyphId]) {
  22295. return true;
  22296. }
  22297. if (charCode >= 0 && toUnicode.has(charCode)) {
  22298. return true;
  22299. }
  22300. return false;
  22301. }
  22302. if (properties.type === 'CIDFontType2') {
  22303. var cidToGidMap = properties.cidToGidMap || [];
  22304. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  22305. properties.cMap.forEach(function(charCode, cid) {
  22306. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22307. var glyphId = -1;
  22308. if (isCidToGidMapEmpty) {
  22309. glyphId = charCode;
  22310. } else if (cidToGidMap[cid] !== undefined) {
  22311. glyphId = cidToGidMap[cid];
  22312. }
  22313. if (glyphId >= 0 && glyphId < numGlyphs &&
  22314. hasGlyph(glyphId, charCode)) {
  22315. charCodeToGlyphId[charCode] = glyphId;
  22316. }
  22317. });
  22318. if (dupFirstEntry) {
  22319. charCodeToGlyphId[0] = numGlyphs - 1;
  22320. }
  22321. } else {
  22322. // Most of the following logic in this code branch is based on the
  22323. // 9.6.6.4 of the PDF spec.
  22324. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  22325. var cmapPlatformId = cmapTable.platformId;
  22326. var cmapEncodingId = cmapTable.encodingId;
  22327. var cmapMappings = cmapTable.mappings;
  22328. var cmapMappingsLength = cmapMappings.length;
  22329. var hasEncoding = properties.differences.length ||
  22330. !!properties.baseEncodingName;
  22331. // The spec seems to imply that if the font is symbolic the encoding
  22332. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  22333. // where the the font is symbolic and it has an encoding.
  22334. if (hasEncoding &&
  22335. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  22336. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  22337. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  22338. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  22339. // When no preferred cmap table was found and |baseEncodingName| is
  22340. // one of the predefined encodings, we seem to obtain a better
  22341. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  22342. // TODO: Note that this is a hack which should be removed as soon as
  22343. // we have proper support for more exotic cmap tables.
  22344. var baseEncoding = [];
  22345. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  22346. properties.baseEncodingName === 'WinAnsiEncoding') {
  22347. baseEncoding = Encodings[properties.baseEncodingName];
  22348. }
  22349. for (charCode = 0; charCode < 256; charCode++) {
  22350. var glyphName;
  22351. if (this.differences && charCode in this.differences) {
  22352. glyphName = this.differences[charCode];
  22353. } else if (charCode in baseEncoding &&
  22354. baseEncoding[charCode] !== '') {
  22355. glyphName = baseEncoding[charCode];
  22356. } else {
  22357. glyphName = Encodings.StandardEncoding[charCode];
  22358. }
  22359. if (!glyphName) {
  22360. continue;
  22361. }
  22362. var unicodeOrCharCode;
  22363. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  22364. unicodeOrCharCode = GlyphsUnicode[glyphName];
  22365. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  22366. // TODO: the encoding needs to be updated with mac os table.
  22367. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  22368. }
  22369. var found = false;
  22370. for (i = 0; i < cmapMappingsLength; ++i) {
  22371. if (cmapMappings[i].charCode === unicodeOrCharCode &&
  22372. hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode)) {
  22373. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22374. found = true;
  22375. break;
  22376. }
  22377. }
  22378. if (!found && properties.glyphNames) {
  22379. // Try to map using the post table. There are currently no known
  22380. // pdfs that this fixes.
  22381. var glyphId = properties.glyphNames.indexOf(glyphName);
  22382. if (glyphId > 0 && hasGlyph(glyphId, -1)) {
  22383. charCodeToGlyphId[charCode] = glyphId;
  22384. }
  22385. }
  22386. }
  22387. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  22388. // Default Unicode semantics, use the charcodes as is.
  22389. for (i = 0; i < cmapMappingsLength; ++i) {
  22390. charCodeToGlyphId[cmapMappings[i].charCode] =
  22391. cmapMappings[i].glyphId;
  22392. }
  22393. } else {
  22394. // For (3, 0) cmap tables:
  22395. // The charcode key being stored in charCodeToGlyphId is the lower
  22396. // byte of the two-byte charcodes of the cmap table since according to
  22397. // the spec: 'each byte from the string shall be prepended with the
  22398. // high byte of the range [of charcodes in the cmap table], to form
  22399. // a two-byte character, which shall be used to select the
  22400. // associated glyph description from the subtable'.
  22401. //
  22402. // For (1, 0) cmap tables:
  22403. // 'single bytes from the string shall be used to look up the
  22404. // associated glyph descriptions from the subtable'. This means
  22405. // charcodes in the cmap will be single bytes, so no-op since
  22406. // glyph.charCode & 0xFF === glyph.charCode
  22407. for (i = 0; i < cmapMappingsLength; ++i) {
  22408. charCode = cmapMappings[i].charCode & 0xFF;
  22409. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  22410. }
  22411. }
  22412. }
  22413. if (charCodeToGlyphId.length === 0) {
  22414. // defines at least one glyph
  22415. charCodeToGlyphId[0] = 0;
  22416. }
  22417. // Converting glyphs and ids into font's cmap table
  22418. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  22419. this.toFontChar = newMapping.toFontChar;
  22420. tables.cmap = {
  22421. tag: 'cmap',
  22422. data: createCmapTable(newMapping.charCodeToGlyphId)
  22423. };
  22424. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  22425. // extract some more font properties from the OpenType head and
  22426. // hhea tables; yMin and descent value are always negative
  22427. var override = {
  22428. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  22429. yMax: int16(tables.head.data[42], tables.head.data[43]),
  22430. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  22431. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  22432. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  22433. };
  22434. tables['OS/2'] = {
  22435. tag: 'OS/2',
  22436. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  22437. override)
  22438. };
  22439. }
  22440. // Rewrite the 'post' table if needed
  22441. if (!tables.post) {
  22442. tables.post = {
  22443. tag: 'post',
  22444. data: createPostTable(properties)
  22445. };
  22446. }
  22447. if (!isTrueType) {
  22448. try {
  22449. // Trying to repair CFF file
  22450. cffFile = new Stream(tables['CFF '].data);
  22451. var parser = new CFFParser(cffFile, properties);
  22452. cff = parser.parse();
  22453. var compiler = new CFFCompiler(cff);
  22454. tables['CFF '].data = compiler.compile();
  22455. } catch (e) {
  22456. warn('Failed to compile font ' + properties.loadedName);
  22457. }
  22458. }
  22459. // Re-creating 'name' table
  22460. if (!tables.name) {
  22461. tables.name = {
  22462. tag: 'name',
  22463. data: createNameTable(this.name)
  22464. };
  22465. } else {
  22466. // ... using existing 'name' table as prototype
  22467. var namePrototype = readNameTable(tables.name);
  22468. tables.name.data = createNameTable(name, namePrototype);
  22469. }
  22470. var builder = new OpenTypeFileBuilder(header.version);
  22471. for (var tableTag in tables) {
  22472. builder.addTable(tableTag, tables[tableTag].data);
  22473. }
  22474. return builder.toArray();
  22475. },
  22476. convert: function Font_convert(fontName, font, properties) {
  22477. // TODO: Check the charstring widths to determine this.
  22478. properties.fixedPitch = false;
  22479. var mapping = font.getGlyphMapping(properties);
  22480. var newMapping = adjustMapping(mapping, properties);
  22481. this.toFontChar = newMapping.toFontChar;
  22482. var numGlyphs = font.numGlyphs;
  22483. function getCharCodes(charCodeToGlyphId, glyphId) {
  22484. var charCodes = null;
  22485. for (var charCode in charCodeToGlyphId) {
  22486. if (glyphId === charCodeToGlyphId[charCode]) {
  22487. if (!charCodes) {
  22488. charCodes = [];
  22489. }
  22490. charCodes.push(charCode | 0);
  22491. }
  22492. }
  22493. return charCodes;
  22494. }
  22495. function createCharCode(charCodeToGlyphId, glyphId) {
  22496. for (var charCode in charCodeToGlyphId) {
  22497. if (glyphId === charCodeToGlyphId[charCode]) {
  22498. return charCode | 0;
  22499. }
  22500. }
  22501. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  22502. glyphId;
  22503. return newMapping.nextAvailableFontCharCode++;
  22504. }
  22505. var seacs = font.seacs;
  22506. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  22507. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  22508. var charset = font.getCharset();
  22509. var seacMap = Object.create(null);
  22510. for (var glyphId in seacs) {
  22511. glyphId |= 0;
  22512. var seac = seacs[glyphId];
  22513. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  22514. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  22515. var baseGlyphId = charset.indexOf(baseGlyphName);
  22516. var accentGlyphId = charset.indexOf(accentGlyphName);
  22517. if (baseGlyphId < 0 || accentGlyphId < 0) {
  22518. continue;
  22519. }
  22520. var accentOffset = {
  22521. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  22522. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  22523. };
  22524. var charCodes = getCharCodes(mapping, glyphId);
  22525. if (!charCodes) {
  22526. // There's no point in mapping it if the char code was never mapped
  22527. // to begin with.
  22528. continue;
  22529. }
  22530. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  22531. var charCode = charCodes[i];
  22532. // Find a fontCharCode that maps to the base and accent glyphs.
  22533. // If one doesn't exists, create it.
  22534. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  22535. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  22536. baseGlyphId);
  22537. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  22538. accentGlyphId);
  22539. seacMap[charCode] = {
  22540. baseFontCharCode: baseFontCharCode,
  22541. accentFontCharCode: accentFontCharCode,
  22542. accentOffset: accentOffset
  22543. };
  22544. }
  22545. }
  22546. properties.seacMap = seacMap;
  22547. }
  22548. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  22549. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  22550. // PostScript Font Program
  22551. builder.addTable('CFF ', font.data);
  22552. // OS/2 and Windows Specific metrics
  22553. builder.addTable('OS/2', createOS2Table(properties,
  22554. newMapping.charCodeToGlyphId));
  22555. // Character to glyphs mapping
  22556. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  22557. // Font header
  22558. builder.addTable('head',
  22559. '\x00\x01\x00\x00' + // Version number
  22560. '\x00\x00\x10\x00' + // fontRevision
  22561. '\x00\x00\x00\x00' + // checksumAdjustement
  22562. '\x5F\x0F\x3C\xF5' + // magicNumber
  22563. '\x00\x00' + // Flags
  22564. safeString16(unitsPerEm) + // unitsPerEM
  22565. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  22566. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  22567. '\x00\x00' + // xMin
  22568. safeString16(properties.descent) + // yMin
  22569. '\x0F\xFF' + // xMax
  22570. safeString16(properties.ascent) + // yMax
  22571. string16(properties.italicAngle ? 2 : 0) + // macStyle
  22572. '\x00\x11' + // lowestRecPPEM
  22573. '\x00\x00' + // fontDirectionHint
  22574. '\x00\x00' + // indexToLocFormat
  22575. '\x00\x00'); // glyphDataFormat
  22576. // Horizontal header
  22577. builder.addTable('hhea',
  22578. '\x00\x01\x00\x00' + // Version number
  22579. safeString16(properties.ascent) + // Typographic Ascent
  22580. safeString16(properties.descent) + // Typographic Descent
  22581. '\x00\x00' + // Line Gap
  22582. '\xFF\xFF' + // advanceWidthMax
  22583. '\x00\x00' + // minLeftSidebearing
  22584. '\x00\x00' + // minRightSidebearing
  22585. '\x00\x00' + // xMaxExtent
  22586. safeString16(properties.capHeight) + // caretSlopeRise
  22587. safeString16(Math.tan(properties.italicAngle) *
  22588. properties.xHeight) + // caretSlopeRun
  22589. '\x00\x00' + // caretOffset
  22590. '\x00\x00' + // -reserved-
  22591. '\x00\x00' + // -reserved-
  22592. '\x00\x00' + // -reserved-
  22593. '\x00\x00' + // -reserved-
  22594. '\x00\x00' + // metricDataFormat
  22595. string16(numGlyphs)); // Number of HMetrics
  22596. // Horizontal metrics
  22597. builder.addTable('hmtx', (function fontFieldsHmtx() {
  22598. var charstrings = font.charstrings;
  22599. var cffWidths = font.cff ? font.cff.widths : null;
  22600. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  22601. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  22602. var width = 0;
  22603. if (charstrings) {
  22604. var charstring = charstrings[i - 1];
  22605. width = 'width' in charstring ? charstring.width : 0;
  22606. } else if (cffWidths) {
  22607. width = Math.ceil(cffWidths[i] || 0);
  22608. }
  22609. hmtx += string16(width) + string16(0);
  22610. }
  22611. return hmtx;
  22612. })());
  22613. // Maximum profile
  22614. builder.addTable('maxp',
  22615. '\x00\x00\x50\x00' + // Version number
  22616. string16(numGlyphs)); // Num of glyphs
  22617. // Naming tables
  22618. builder.addTable('name', createNameTable(fontName));
  22619. // PostScript informations
  22620. builder.addTable('post', createPostTable(properties));
  22621. return builder.toArray();
  22622. },
  22623. /**
  22624. * Builds a char code to unicode map based on section 9.10 of the spec.
  22625. * @param {Object} properties Font properties object.
  22626. * @return {Object} A ToUnicodeMap object.
  22627. */
  22628. buildToUnicode: function Font_buildToUnicode(properties) {
  22629. // Section 9.10.2 Mapping Character Codes to Unicode Values
  22630. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  22631. return properties.toUnicode;
  22632. }
  22633. // According to the spec if the font is a simple font we should only map
  22634. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  22635. // the differences array only contains adobe standard or symbol set names,
  22636. // in pratice it seems better to always try to create a toUnicode
  22637. // map based of the default encoding.
  22638. var toUnicode, charcode;
  22639. if (!properties.composite /* is simple font */) {
  22640. toUnicode = [];
  22641. var encoding = properties.defaultEncoding.slice();
  22642. var baseEncodingName = properties.baseEncodingName;
  22643. // Merge in the differences array.
  22644. var differences = properties.differences;
  22645. for (charcode in differences) {
  22646. encoding[charcode] = differences[charcode];
  22647. }
  22648. for (charcode in encoding) {
  22649. // a) Map the character code to a character name.
  22650. var glyphName = encoding[charcode];
  22651. // b) Look up the character name in the Adobe Glyph List (see the
  22652. // Bibliography) to obtain the corresponding Unicode value.
  22653. if (glyphName === '') {
  22654. continue;
  22655. } else if (GlyphsUnicode[glyphName] === undefined) {
  22656. // (undocumented) c) Few heuristics to recognize unknown glyphs
  22657. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  22658. var code = 0;
  22659. switch (glyphName[0]) {
  22660. case 'G': // Gxx glyph
  22661. if (glyphName.length === 3) {
  22662. code = parseInt(glyphName.substr(1), 16);
  22663. }
  22664. break;
  22665. case 'g': // g00xx glyph
  22666. if (glyphName.length === 5) {
  22667. code = parseInt(glyphName.substr(1), 16);
  22668. }
  22669. break;
  22670. case 'C': // Cddd glyph
  22671. case 'c': // cddd glyph
  22672. if (glyphName.length >= 3) {
  22673. code = +glyphName.substr(1);
  22674. }
  22675. break;
  22676. }
  22677. if (code) {
  22678. // If |baseEncodingName| is one the predefined encodings,
  22679. // and |code| equals |charcode|, using the glyph defined in the
  22680. // baseEncoding seems to yield a better |toUnicode| mapping
  22681. // (fixes issue 5070).
  22682. if (baseEncodingName && code === +charcode) {
  22683. var baseEncoding = Encodings[baseEncodingName];
  22684. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  22685. toUnicode[charcode] =
  22686. String.fromCharCode(GlyphsUnicode[glyphName]);
  22687. continue;
  22688. }
  22689. }
  22690. toUnicode[charcode] = String.fromCharCode(code);
  22691. }
  22692. continue;
  22693. }
  22694. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  22695. }
  22696. return new ToUnicodeMap(toUnicode);
  22697. }
  22698. // If the font is a composite font that uses one of the predefined CMaps
  22699. // listed in Table 118 (except Identity–H and Identity–V) or whose
  22700. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  22701. // Adobe-Korea1 character collection:
  22702. if (properties.composite && (
  22703. (properties.cMap.builtInCMap &&
  22704. !(properties.cMap instanceof IdentityCMap)) ||
  22705. (properties.cidSystemInfo.registry === 'Adobe' &&
  22706. (properties.cidSystemInfo.ordering === 'GB1' ||
  22707. properties.cidSystemInfo.ordering === 'CNS1' ||
  22708. properties.cidSystemInfo.ordering === 'Japan1' ||
  22709. properties.cidSystemInfo.ordering === 'Korea1')))) {
  22710. // Then:
  22711. // a) Map the character code to a character identifier (CID) according
  22712. // to the font’s CMap.
  22713. // b) Obtain the registry and ordering of the character collection used
  22714. // by the font’s CMap (for example, Adobe and Japan1) from its
  22715. // CIDSystemInfo dictionary.
  22716. var registry = properties.cidSystemInfo.registry;
  22717. var ordering = properties.cidSystemInfo.ordering;
  22718. // c) Construct a second CMap name by concatenating the registry and
  22719. // ordering obtained in step (b) in the format registry–ordering–UCS2
  22720. // (for example, Adobe–Japan1–UCS2).
  22721. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  22722. // d) Obtain the CMap with the name constructed in step (c) (available
  22723. // from the ASN Web site; see the Bibliography).
  22724. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  22725. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  22726. var cMap = properties.cMap;
  22727. toUnicode = [];
  22728. cMap.forEach(function(charcode, cid) {
  22729. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  22730. // e) Map the CID obtained in step (a) according to the CMap obtained
  22731. // in step (d), producing a Unicode value.
  22732. var ucs2 = ucs2CMap.lookup(cid);
  22733. if (ucs2) {
  22734. toUnicode[charcode] =
  22735. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  22736. ucs2.charCodeAt(1));
  22737. }
  22738. });
  22739. return new ToUnicodeMap(toUnicode);
  22740. }
  22741. // The viewer's choice, just use an identity map.
  22742. return new IdentityToUnicodeMap(properties.firstChar,
  22743. properties.lastChar);
  22744. },
  22745. get spaceWidth() {
  22746. if ('_shadowWidth' in this) {
  22747. return this._shadowWidth;
  22748. }
  22749. // trying to estimate space character width
  22750. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  22751. var width;
  22752. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  22753. var glyphName = possibleSpaceReplacements[i];
  22754. // if possible, getting width by glyph name
  22755. if (glyphName in this.widths) {
  22756. width = this.widths[glyphName];
  22757. break;
  22758. }
  22759. var glyphUnicode = GlyphsUnicode[glyphName];
  22760. // finding the charcode via unicodeToCID map
  22761. var charcode = 0;
  22762. if (this.composite) {
  22763. if (this.cMap.contains(glyphUnicode)) {
  22764. charcode = this.cMap.lookup(glyphUnicode);
  22765. }
  22766. }
  22767. // ... via toUnicode map
  22768. if (!charcode && 'toUnicode' in this) {
  22769. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  22770. }
  22771. // setting it to unicode if negative or undefined
  22772. if (charcode <= 0) {
  22773. charcode = glyphUnicode;
  22774. }
  22775. // trying to get width via charcode
  22776. width = this.widths[charcode];
  22777. if (width) {
  22778. break; // the non-zero width found
  22779. }
  22780. }
  22781. width = width || this.defaultWidth;
  22782. // Do not shadow the property here. See discussion:
  22783. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  22784. this._shadowWidth = width;
  22785. return width;
  22786. },
  22787. charToGlyph: function Font_charToGlyph(charcode) {
  22788. var fontCharCode, width, operatorListId;
  22789. var widthCode = charcode;
  22790. if (this.cMap && this.cMap.contains(charcode)) {
  22791. widthCode = this.cMap.lookup(charcode);
  22792. }
  22793. width = this.widths[widthCode];
  22794. width = isNum(width) ? width : this.defaultWidth;
  22795. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  22796. var unicode = this.toUnicode.get(charcode) || charcode;
  22797. if (typeof unicode === 'number') {
  22798. unicode = String.fromCharCode(unicode);
  22799. }
  22800. // First try the toFontChar map, if it's not there then try falling
  22801. // back to the char code.
  22802. fontCharCode = this.toFontChar[charcode] || charcode;
  22803. if (this.missingFile) {
  22804. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  22805. }
  22806. if (this.isType3Font) {
  22807. // Font char code in this case is actually a glyph name.
  22808. operatorListId = fontCharCode;
  22809. }
  22810. var accent = null;
  22811. if (this.seacMap && this.seacMap[charcode]) {
  22812. var seac = this.seacMap[charcode];
  22813. fontCharCode = seac.baseFontCharCode;
  22814. accent = {
  22815. fontChar: String.fromCharCode(seac.accentFontCharCode),
  22816. offset: seac.accentOffset
  22817. };
  22818. }
  22819. var fontChar = String.fromCharCode(fontCharCode);
  22820. var glyph = this.glyphCache[charcode];
  22821. if (!glyph ||
  22822. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  22823. operatorListId)) {
  22824. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  22825. operatorListId);
  22826. this.glyphCache[charcode] = glyph;
  22827. }
  22828. return glyph;
  22829. },
  22830. charsToGlyphs: function Font_charsToGlyphs(chars) {
  22831. var charsCache = this.charsCache;
  22832. var glyphs, glyph, charcode;
  22833. // if we translated this string before, just grab it from the cache
  22834. if (charsCache) {
  22835. glyphs = charsCache[chars];
  22836. if (glyphs) {
  22837. return glyphs;
  22838. }
  22839. }
  22840. // lazily create the translation cache
  22841. if (!charsCache) {
  22842. charsCache = this.charsCache = Object.create(null);
  22843. }
  22844. glyphs = [];
  22845. var charsCacheKey = chars;
  22846. var i = 0, ii;
  22847. if (this.cMap) {
  22848. // composite fonts have multi-byte strings convert the string from
  22849. // single-byte to multi-byte
  22850. var c = {};
  22851. while (i < chars.length) {
  22852. this.cMap.readCharCode(chars, i, c);
  22853. charcode = c.charcode;
  22854. var length = c.length;
  22855. i += length;
  22856. glyph = this.charToGlyph(charcode);
  22857. glyphs.push(glyph);
  22858. // placing null after each word break charcode (ASCII SPACE)
  22859. // Ignore occurences of 0x20 in multiple-byte codes.
  22860. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  22861. glyphs.push(null);
  22862. }
  22863. }
  22864. } else {
  22865. for (i = 0, ii = chars.length; i < ii; ++i) {
  22866. charcode = chars.charCodeAt(i);
  22867. glyph = this.charToGlyph(charcode);
  22868. glyphs.push(glyph);
  22869. if (charcode === 0x20) {
  22870. glyphs.push(null);
  22871. }
  22872. }
  22873. }
  22874. // Enter the translated string into the cache
  22875. return (charsCache[charsCacheKey] = glyphs);
  22876. }
  22877. };
  22878. return Font;
  22879. })();
  22880. var ErrorFont = (function ErrorFontClosure() {
  22881. function ErrorFont(error) {
  22882. this.error = error;
  22883. this.loadedName = 'g_font_error';
  22884. this.loading = false;
  22885. }
  22886. ErrorFont.prototype = {
  22887. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  22888. return [];
  22889. },
  22890. exportData: function ErrorFont_exportData() {
  22891. return {error: this.error};
  22892. }
  22893. };
  22894. return ErrorFont;
  22895. })();
  22896. /**
  22897. * Shared logic for building a char code to glyph id mapping for Type1 and
  22898. * simple CFF fonts. See section 9.6.6.2 of the spec.
  22899. * @param {Object} properties Font properties object.
  22900. * @param {Object} builtInEncoding The encoding contained within the actual font
  22901. * data.
  22902. * @param {Array} Array of glyph names where the index is the glyph ID.
  22903. * @returns {Object} A char code to glyph ID map.
  22904. */
  22905. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  22906. var charCodeToGlyphId = Object.create(null);
  22907. var glyphId, charCode, baseEncoding;
  22908. if (properties.baseEncodingName) {
  22909. // If a valid base encoding name was used, the mapping is initialized with
  22910. // that.
  22911. baseEncoding = Encodings[properties.baseEncodingName];
  22912. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22913. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22914. if (glyphId >= 0) {
  22915. charCodeToGlyphId[charCode] = glyphId;
  22916. } else {
  22917. charCodeToGlyphId[charCode] = 0; // notdef
  22918. }
  22919. }
  22920. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  22921. // For a symbolic font the encoding should be the fonts built-in
  22922. // encoding.
  22923. for (charCode in builtInEncoding) {
  22924. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  22925. }
  22926. } else {
  22927. // For non-symbolic fonts that don't have a base encoding the standard
  22928. // encoding should be used.
  22929. baseEncoding = Encodings.StandardEncoding;
  22930. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  22931. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  22932. if (glyphId >= 0) {
  22933. charCodeToGlyphId[charCode] = glyphId;
  22934. } else {
  22935. charCodeToGlyphId[charCode] = 0; // notdef
  22936. }
  22937. }
  22938. }
  22939. // Lastly, merge in the differences.
  22940. var differences = properties.differences;
  22941. if (differences) {
  22942. for (charCode in differences) {
  22943. var glyphName = differences[charCode];
  22944. glyphId = glyphNames.indexOf(glyphName);
  22945. if (glyphId >= 0) {
  22946. charCodeToGlyphId[charCode] = glyphId;
  22947. } else {
  22948. charCodeToGlyphId[charCode] = 0; // notdef
  22949. }
  22950. }
  22951. }
  22952. return charCodeToGlyphId;
  22953. }
  22954. /*
  22955. * CharStrings are encoded following the the CharString Encoding sequence
  22956. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  22957. * The value in a byte indicates a command, a number, or subsequent bytes
  22958. * that are to be interpreted in a special way.
  22959. *
  22960. * CharString Number Encoding:
  22961. * A CharString byte containing the values from 32 through 255 inclusive
  22962. * indicate an integer. These values are decoded in four ranges.
  22963. *
  22964. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  22965. * indicate the integer v - 139. Thus, the integer values from -107 through
  22966. * 107 inclusive may be encoded in single byte.
  22967. *
  22968. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  22969. * indicates an integer involving the next byte, w, according to the formula:
  22970. * [(v - 247) x 256] + w + 108
  22971. *
  22972. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  22973. * indicates an integer involving the next byte, w, according to the formula:
  22974. * -[(v - 251) * 256] - w - 108
  22975. *
  22976. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  22977. * are a two complement signed integer. The first of these bytes contains the
  22978. * highest order bits, the second byte contains the next higher order bits
  22979. * and the fourth byte contain the lowest order bits.
  22980. *
  22981. *
  22982. * CharString Command Encoding:
  22983. * CharStrings commands are encoded in 1 or 2 bytes.
  22984. *
  22985. * Single byte commands are encoded in 1 byte that contains a value between
  22986. * 0 and 31 inclusive.
  22987. * If a command byte contains the value 12, then the value in the next byte
  22988. * indicates a command. This "escape" mechanism allows many extra commands
  22989. * to be encoded and this encoding technique helps to minimize the length of
  22990. * the charStrings.
  22991. */
  22992. var Type1CharString = (function Type1CharStringClosure() {
  22993. var COMMAND_MAP = {
  22994. 'hstem': [1],
  22995. 'vstem': [3],
  22996. 'vmoveto': [4],
  22997. 'rlineto': [5],
  22998. 'hlineto': [6],
  22999. 'vlineto': [7],
  23000. 'rrcurveto': [8],
  23001. 'callsubr': [10],
  23002. 'flex': [12, 35],
  23003. 'drop' : [12, 18],
  23004. 'endchar': [14],
  23005. 'rmoveto': [21],
  23006. 'hmoveto': [22],
  23007. 'vhcurveto': [30],
  23008. 'hvcurveto': [31]
  23009. };
  23010. function Type1CharString() {
  23011. this.width = 0;
  23012. this.lsb = 0;
  23013. this.flexing = false;
  23014. this.output = [];
  23015. this.stack = [];
  23016. }
  23017. Type1CharString.prototype = {
  23018. convert: function Type1CharString_convert(encoded, subrs) {
  23019. var count = encoded.length;
  23020. var error = false;
  23021. var wx, sbx, subrNumber;
  23022. for (var i = 0; i < count; i++) {
  23023. var value = encoded[i];
  23024. if (value < 32) {
  23025. if (value === 12) {
  23026. value = (value << 8) + encoded[++i];
  23027. }
  23028. switch (value) {
  23029. case 1: // hstem
  23030. if (!HINTING_ENABLED) {
  23031. this.stack = [];
  23032. break;
  23033. }
  23034. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23035. break;
  23036. case 3: // vstem
  23037. if (!HINTING_ENABLED) {
  23038. this.stack = [];
  23039. break;
  23040. }
  23041. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23042. break;
  23043. case 4: // vmoveto
  23044. if (this.flexing) {
  23045. if (this.stack.length < 1) {
  23046. error = true;
  23047. break;
  23048. }
  23049. // Add the dx for flex and but also swap the values so they are
  23050. // the right order.
  23051. var dy = this.stack.pop();
  23052. this.stack.push(0, dy);
  23053. break;
  23054. }
  23055. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  23056. break;
  23057. case 5: // rlineto
  23058. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  23059. break;
  23060. case 6: // hlineto
  23061. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  23062. break;
  23063. case 7: // vlineto
  23064. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  23065. break;
  23066. case 8: // rrcurveto
  23067. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  23068. break;
  23069. case 9: // closepath
  23070. // closepath is a Type1 command that does not take argument and is
  23071. // useless in Type2 and it can simply be ignored.
  23072. this.stack = [];
  23073. break;
  23074. case 10: // callsubr
  23075. if (this.stack.length < 1) {
  23076. error = true;
  23077. break;
  23078. }
  23079. subrNumber = this.stack.pop();
  23080. error = this.convert(subrs[subrNumber], subrs);
  23081. break;
  23082. case 11: // return
  23083. return error;
  23084. case 13: // hsbw
  23085. if (this.stack.length < 2) {
  23086. error = true;
  23087. break;
  23088. }
  23089. // To convert to type2 we have to move the width value to the
  23090. // first part of the charstring and then use hmoveto with lsb.
  23091. wx = this.stack.pop();
  23092. sbx = this.stack.pop();
  23093. this.lsb = sbx;
  23094. this.width = wx;
  23095. this.stack.push(wx, sbx);
  23096. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  23097. break;
  23098. case 14: // endchar
  23099. this.output.push(COMMAND_MAP.endchar[0]);
  23100. break;
  23101. case 21: // rmoveto
  23102. if (this.flexing) {
  23103. break;
  23104. }
  23105. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  23106. break;
  23107. case 22: // hmoveto
  23108. if (this.flexing) {
  23109. // Add the dy for flex.
  23110. this.stack.push(0);
  23111. break;
  23112. }
  23113. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  23114. break;
  23115. case 30: // vhcurveto
  23116. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  23117. break;
  23118. case 31: // hvcurveto
  23119. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  23120. break;
  23121. case (12 << 8) + 0: // dotsection
  23122. // dotsection is a Type1 command to specify some hinting feature
  23123. // for dots that do not take a parameter and it can safely be
  23124. // ignored for Type2.
  23125. this.stack = [];
  23126. break;
  23127. case (12 << 8) + 1: // vstem3
  23128. if (!HINTING_ENABLED) {
  23129. this.stack = [];
  23130. break;
  23131. }
  23132. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  23133. // multiple parameters, so instead of returning [vh]stem3 take a
  23134. // shortcut and return [vhstem] instead.
  23135. error = this.executeCommand(2, COMMAND_MAP.vstem);
  23136. break;
  23137. case (12 << 8) + 2: // hstem3
  23138. if (!HINTING_ENABLED) {
  23139. this.stack = [];
  23140. break;
  23141. }
  23142. // See vstem3.
  23143. error = this.executeCommand(2, COMMAND_MAP.hstem);
  23144. break;
  23145. case (12 << 8) + 6: // seac
  23146. // seac is like type 2's special endchar but it doesn't use the
  23147. // first argument asb, so remove it.
  23148. if (SEAC_ANALYSIS_ENABLED) {
  23149. this.seac = this.stack.splice(-4, 4);
  23150. error = this.executeCommand(0, COMMAND_MAP.endchar);
  23151. } else {
  23152. error = this.executeCommand(4, COMMAND_MAP.endchar);
  23153. }
  23154. break;
  23155. case (12 << 8) + 7: // sbw
  23156. if (this.stack.length < 4) {
  23157. error = true;
  23158. break;
  23159. }
  23160. // To convert to type2 we have to move the width value to the
  23161. // first part of the charstring and then use rmoveto with
  23162. // (dx, dy). The height argument will not be used for vmtx and
  23163. // vhea tables reconstruction -- ignoring it.
  23164. var wy = this.stack.pop();
  23165. wx = this.stack.pop();
  23166. var sby = this.stack.pop();
  23167. sbx = this.stack.pop();
  23168. this.lsb = sbx;
  23169. this.width = wx;
  23170. this.stack.push(wx, sbx, sby);
  23171. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  23172. break;
  23173. case (12 << 8) + 12: // div
  23174. if (this.stack.length < 2) {
  23175. error = true;
  23176. break;
  23177. }
  23178. var num2 = this.stack.pop();
  23179. var num1 = this.stack.pop();
  23180. this.stack.push(num1 / num2);
  23181. break;
  23182. case (12 << 8) + 16: // callothersubr
  23183. if (this.stack.length < 2) {
  23184. error = true;
  23185. break;
  23186. }
  23187. subrNumber = this.stack.pop();
  23188. var numArgs = this.stack.pop();
  23189. if (subrNumber === 0 && numArgs === 3) {
  23190. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  23191. this.stack.push(
  23192. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  23193. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  23194. flexArgs[4], // bcp2x
  23195. flexArgs[5], // bcp2y
  23196. flexArgs[6], // p2x
  23197. flexArgs[7], // p2y
  23198. flexArgs[8], // bcp3x
  23199. flexArgs[9], // bcp3y
  23200. flexArgs[10], // bcp4x
  23201. flexArgs[11], // bcp4y
  23202. flexArgs[12], // p3x
  23203. flexArgs[13], // p3y
  23204. flexArgs[14] // flexDepth
  23205. // 15 = finalx unused by flex
  23206. // 16 = finaly unused by flex
  23207. );
  23208. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  23209. this.flexing = false;
  23210. this.stack.push(flexArgs[15], flexArgs[16]);
  23211. } else if (subrNumber === 1 && numArgs === 0) {
  23212. this.flexing = true;
  23213. }
  23214. break;
  23215. case (12 << 8) + 17: // pop
  23216. // Ignore this since it is only used with othersubr.
  23217. break;
  23218. case (12 << 8) + 33: // setcurrentpoint
  23219. // Ignore for now.
  23220. this.stack = [];
  23221. break;
  23222. default:
  23223. warn('Unknown type 1 charstring command of "' + value + '"');
  23224. break;
  23225. }
  23226. if (error) {
  23227. break;
  23228. }
  23229. continue;
  23230. } else if (value <= 246) {
  23231. value = value - 139;
  23232. } else if (value <= 250) {
  23233. value = ((value - 247) * 256) + encoded[++i] + 108;
  23234. } else if (value <= 254) {
  23235. value = -((value - 251) * 256) - encoded[++i] - 108;
  23236. } else {
  23237. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  23238. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  23239. }
  23240. this.stack.push(value);
  23241. }
  23242. return error;
  23243. },
  23244. executeCommand: function(howManyArgs, command, keepStack) {
  23245. var stackLength = this.stack.length;
  23246. if (howManyArgs > stackLength) {
  23247. return true;
  23248. }
  23249. var start = stackLength - howManyArgs;
  23250. for (var i = start; i < stackLength; i++) {
  23251. var value = this.stack[i];
  23252. if (value === (value | 0)) { // int
  23253. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  23254. } else { // fixed point
  23255. value = (65536 * value) | 0;
  23256. this.output.push(255,
  23257. (value >> 24) & 0xFF,
  23258. (value >> 16) & 0xFF,
  23259. (value >> 8) & 0xFF,
  23260. value & 0xFF);
  23261. }
  23262. }
  23263. this.output.push.apply(this.output, command);
  23264. if (keepStack) {
  23265. this.stack.splice(start, howManyArgs);
  23266. } else {
  23267. this.stack.length = 0;
  23268. }
  23269. return false;
  23270. }
  23271. };
  23272. return Type1CharString;
  23273. })();
  23274. /*
  23275. * Type1Parser encapsulate the needed code for parsing a Type1 font
  23276. * program. Some of its logic depends on the Type2 charstrings
  23277. * structure.
  23278. * Note: this doesn't really parse the font since that would require evaluation
  23279. * of PostScript, but it is possible in most cases to extract what we need
  23280. * without a full parse.
  23281. */
  23282. var Type1Parser = (function Type1ParserClosure() {
  23283. /*
  23284. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  23285. * of Plaintext Bytes. The function took a key as a parameter which can be
  23286. * for decrypting the eexec block of for decoding charStrings.
  23287. */
  23288. var EEXEC_ENCRYPT_KEY = 55665;
  23289. var CHAR_STRS_ENCRYPT_KEY = 4330;
  23290. function isHexDigit(code) {
  23291. return code >= 48 && code <= 57 || // '0'-'9'
  23292. code >= 65 && code <= 70 || // 'A'-'F'
  23293. code >= 97 && code <= 102; // 'a'-'f'
  23294. }
  23295. function decrypt(data, key, discardNumber) {
  23296. var r = key | 0, c1 = 52845, c2 = 22719;
  23297. var count = data.length;
  23298. var decrypted = new Uint8Array(count);
  23299. for (var i = 0; i < count; i++) {
  23300. var value = data[i];
  23301. decrypted[i] = value ^ (r >> 8);
  23302. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23303. }
  23304. return Array.prototype.slice.call(decrypted, discardNumber);
  23305. }
  23306. function decryptAscii(data, key, discardNumber) {
  23307. var r = key | 0, c1 = 52845, c2 = 22719;
  23308. var count = data.length, maybeLength = count >>> 1;
  23309. var decrypted = new Uint8Array(maybeLength);
  23310. var i, j;
  23311. for (i = 0, j = 0; i < count; i++) {
  23312. var digit1 = data[i];
  23313. if (!isHexDigit(digit1)) {
  23314. continue;
  23315. }
  23316. i++;
  23317. var digit2;
  23318. while (i < count && !isHexDigit(digit2 = data[i])) {
  23319. i++;
  23320. }
  23321. if (i < count) {
  23322. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  23323. decrypted[j++] = value ^ (r >> 8);
  23324. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  23325. }
  23326. }
  23327. return Array.prototype.slice.call(decrypted, discardNumber, j);
  23328. }
  23329. function isSpecial(c) {
  23330. return c === 0x2F || // '/'
  23331. c === 0x5B || c === 0x5D || // '[', ']'
  23332. c === 0x7B || c === 0x7D || // '{', '}'
  23333. c === 0x28 || c === 0x29; // '(', ')'
  23334. }
  23335. function Type1Parser(stream, encrypted) {
  23336. if (encrypted) {
  23337. var data = stream.getBytes();
  23338. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  23339. isHexDigit(data[2]) && isHexDigit(data[3]));
  23340. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  23341. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  23342. }
  23343. this.stream = stream;
  23344. this.nextChar();
  23345. }
  23346. Type1Parser.prototype = {
  23347. readNumberArray: function Type1Parser_readNumberArray() {
  23348. this.getToken(); // read '[' or '{' (arrays can start with either)
  23349. var array = [];
  23350. while (true) {
  23351. var token = this.getToken();
  23352. if (token === null || token === ']' || token === '}') {
  23353. break;
  23354. }
  23355. array.push(parseFloat(token || 0));
  23356. }
  23357. return array;
  23358. },
  23359. readNumber: function Type1Parser_readNumber() {
  23360. var token = this.getToken();
  23361. return parseFloat(token || 0);
  23362. },
  23363. readInt: function Type1Parser_readInt() {
  23364. // Use '| 0' to prevent setting a double into length such as the double
  23365. // does not flow into the loop variable.
  23366. var token = this.getToken();
  23367. return parseInt(token || 0, 10) | 0;
  23368. },
  23369. readBoolean: function Type1Parser_readBoolean() {
  23370. var token = this.getToken();
  23371. // Use 1 and 0 since that's what type2 charstrings use.
  23372. return token === 'true' ? 1 : 0;
  23373. },
  23374. nextChar : function Type1_nextChar() {
  23375. return (this.currentChar = this.stream.getByte());
  23376. },
  23377. getToken: function Type1Parser_getToken() {
  23378. // Eat whitespace and comments.
  23379. var comment = false;
  23380. var ch = this.currentChar;
  23381. while (true) {
  23382. if (ch === -1) {
  23383. return null;
  23384. }
  23385. if (comment) {
  23386. if (ch === 0x0A || ch === 0x0D) {
  23387. comment = false;
  23388. }
  23389. } else if (ch === 0x25) { // '%'
  23390. comment = true;
  23391. } else if (!Lexer.isSpace(ch)) {
  23392. break;
  23393. }
  23394. ch = this.nextChar();
  23395. }
  23396. if (isSpecial(ch)) {
  23397. this.nextChar();
  23398. return String.fromCharCode(ch);
  23399. }
  23400. var token = '';
  23401. do {
  23402. token += String.fromCharCode(ch);
  23403. ch = this.nextChar();
  23404. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  23405. return token;
  23406. },
  23407. /*
  23408. * Returns an object containing a Subrs array and a CharStrings
  23409. * array extracted from and eexec encrypted block of data
  23410. */
  23411. extractFontProgram: function Type1Parser_extractFontProgram() {
  23412. var stream = this.stream;
  23413. var subrs = [], charstrings = [];
  23414. var program = {
  23415. subrs: [],
  23416. charstrings: [],
  23417. properties: {
  23418. 'privateData': {
  23419. 'lenIV': 4
  23420. }
  23421. }
  23422. };
  23423. var token, length, data, lenIV, encoded;
  23424. while ((token = this.getToken()) !== null) {
  23425. if (token !== '/') {
  23426. continue;
  23427. }
  23428. token = this.getToken();
  23429. switch (token) {
  23430. case 'CharStrings':
  23431. // The number immediately following CharStrings must be greater or
  23432. // equal to the number of CharStrings.
  23433. this.getToken();
  23434. this.getToken(); // read in 'dict'
  23435. this.getToken(); // read in 'dup'
  23436. this.getToken(); // read in 'begin'
  23437. while(true) {
  23438. token = this.getToken();
  23439. if (token === null || token === 'end') {
  23440. break;
  23441. }
  23442. if (token !== '/') {
  23443. continue;
  23444. }
  23445. var glyph = this.getToken();
  23446. length = this.readInt();
  23447. this.getToken(); // read in 'RD' or '-|'
  23448. data = stream.makeSubStream(stream.pos, length);
  23449. lenIV = program.properties.privateData['lenIV'];
  23450. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23451. // Skip past the required space and binary data.
  23452. stream.skip(length);
  23453. this.nextChar();
  23454. token = this.getToken(); // read in 'ND' or '|-'
  23455. if (token === 'noaccess') {
  23456. this.getToken(); // read in 'def'
  23457. }
  23458. charstrings.push({
  23459. glyph: glyph,
  23460. encoded: encoded
  23461. });
  23462. }
  23463. break;
  23464. case 'Subrs':
  23465. var num = this.readInt();
  23466. this.getToken(); // read in 'array'
  23467. while ((token = this.getToken()) === 'dup') {
  23468. var index = this.readInt();
  23469. length = this.readInt();
  23470. this.getToken(); // read in 'RD' or '-|'
  23471. data = stream.makeSubStream(stream.pos, length);
  23472. lenIV = program.properties.privateData['lenIV'];
  23473. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  23474. // Skip past the required space and binary data.
  23475. stream.skip(length);
  23476. this.nextChar();
  23477. token = this.getToken(); // read in 'NP' or '|'
  23478. if (token === 'noaccess') {
  23479. this.getToken(); // read in 'put'
  23480. }
  23481. subrs[index] = encoded;
  23482. }
  23483. break;
  23484. case 'BlueValues':
  23485. case 'OtherBlues':
  23486. case 'FamilyBlues':
  23487. case 'FamilyOtherBlues':
  23488. var blueArray = this.readNumberArray();
  23489. // *Blue* values may contain invalid data: disables reading of
  23490. // those values when hinting is disabled.
  23491. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  23492. HINTING_ENABLED) {
  23493. program.properties.privateData[token] = blueArray;
  23494. }
  23495. break;
  23496. case 'StemSnapH':
  23497. case 'StemSnapV':
  23498. program.properties.privateData[token] = this.readNumberArray();
  23499. break;
  23500. case 'StdHW':
  23501. case 'StdVW':
  23502. program.properties.privateData[token] =
  23503. this.readNumberArray()[0];
  23504. break;
  23505. case 'BlueShift':
  23506. case 'lenIV':
  23507. case 'BlueFuzz':
  23508. case 'BlueScale':
  23509. case 'LanguageGroup':
  23510. case 'ExpansionFactor':
  23511. program.properties.privateData[token] = this.readNumber();
  23512. break;
  23513. case 'ForceBold':
  23514. program.properties.privateData[token] = this.readBoolean();
  23515. break;
  23516. }
  23517. }
  23518. for (var i = 0; i < charstrings.length; i++) {
  23519. glyph = charstrings[i].glyph;
  23520. encoded = charstrings[i].encoded;
  23521. var charString = new Type1CharString();
  23522. var error = charString.convert(encoded, subrs);
  23523. var output = charString.output;
  23524. if (error) {
  23525. // It seems when FreeType encounters an error while evaluating a glyph
  23526. // that it completely ignores the glyph so we'll mimic that behaviour
  23527. // here and put an endchar to make the validator happy.
  23528. output = [14];
  23529. }
  23530. program.charstrings.push({
  23531. glyphName: glyph,
  23532. charstring: output,
  23533. width: charString.width,
  23534. lsb: charString.lsb,
  23535. seac: charString.seac
  23536. });
  23537. }
  23538. return program;
  23539. },
  23540. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  23541. var token;
  23542. while ((token = this.getToken()) !== null) {
  23543. if (token !== '/') {
  23544. continue;
  23545. }
  23546. token = this.getToken();
  23547. switch (token) {
  23548. case 'FontMatrix':
  23549. var matrix = this.readNumberArray();
  23550. properties.fontMatrix = matrix;
  23551. break;
  23552. case 'Encoding':
  23553. var encodingArg = this.getToken();
  23554. var encoding;
  23555. if (!/^\d+$/.test(encodingArg)) {
  23556. // encoding name is specified
  23557. encoding = Encodings[encodingArg];
  23558. } else {
  23559. encoding = [];
  23560. var size = parseInt(encodingArg, 10) | 0;
  23561. this.getToken(); // read in 'array'
  23562. for (var j = 0; j < size; j++) {
  23563. token = this.getToken();
  23564. // skipping till first dup or def (e.g. ignoring for statement)
  23565. while (token !== 'dup' && token !== 'def') {
  23566. token = this.getToken();
  23567. if (token === null) {
  23568. return; // invalid header
  23569. }
  23570. }
  23571. if (token === 'def') {
  23572. break; // read all array data
  23573. }
  23574. var index = this.readInt();
  23575. this.getToken(); // read in '/'
  23576. var glyph = this.getToken();
  23577. encoding[index] = glyph;
  23578. this.getToken(); // read the in 'put'
  23579. }
  23580. }
  23581. properties.builtInEncoding = encoding;
  23582. break;
  23583. case 'FontBBox':
  23584. var fontBBox = this.readNumberArray();
  23585. // adjusting ascent/descent
  23586. properties.ascent = fontBBox[3];
  23587. properties.descent = fontBBox[1];
  23588. properties.ascentScaled = true;
  23589. break;
  23590. }
  23591. }
  23592. }
  23593. };
  23594. return Type1Parser;
  23595. })();
  23596. /**
  23597. * The CFF class takes a Type1 file and wrap it into a
  23598. * 'Compact Font Format' which itself embed Type2 charstrings.
  23599. */
  23600. var CFFStandardStrings = [
  23601. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23602. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23603. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23604. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23605. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  23606. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  23607. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  23608. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  23609. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  23610. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  23611. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23612. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23613. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  23614. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  23615. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  23616. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  23617. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  23618. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  23619. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  23620. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  23621. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  23622. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  23623. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  23624. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  23625. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  23626. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  23627. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  23628. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  23629. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  23630. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  23631. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  23632. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  23633. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  23634. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23635. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  23636. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  23637. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  23638. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  23639. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  23640. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  23641. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  23642. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  23643. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23644. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23645. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23646. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23647. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23648. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  23649. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  23650. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  23651. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  23652. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23653. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  23654. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  23655. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  23656. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  23657. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  23658. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  23659. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  23660. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  23661. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  23662. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  23663. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  23664. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  23665. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  23666. ];
  23667. // Type1Font is also a CIDFontType0.
  23668. var Type1Font = function Type1Font(name, file, properties) {
  23669. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  23670. // Also, length1 and length2 might be off by 6 bytes as well.
  23671. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  23672. var PFB_HEADER_SIZE = 6;
  23673. var headerBlockLength = properties.length1;
  23674. var eexecBlockLength = properties.length2;
  23675. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  23676. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  23677. if (pfbHeaderPresent) {
  23678. file.skip(PFB_HEADER_SIZE);
  23679. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23680. (pfbHeader[3] << 8) | pfbHeader[2];
  23681. }
  23682. // Get the data block containing glyphs and subrs informations
  23683. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  23684. var headerBlockParser = new Type1Parser(headerBlock);
  23685. headerBlockParser.extractFontHeader(properties);
  23686. if (pfbHeaderPresent) {
  23687. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  23688. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  23689. (pfbHeader[3] << 8) | pfbHeader[2];
  23690. }
  23691. // Decrypt the data blocks and retrieve it's content
  23692. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  23693. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  23694. var data = eexecBlockParser.extractFontProgram();
  23695. for (var info in data.properties) {
  23696. properties[info] = data.properties[info];
  23697. }
  23698. var charstrings = data.charstrings;
  23699. var type2Charstrings = this.getType2Charstrings(charstrings);
  23700. var subrs = this.getType2Subrs(data.subrs);
  23701. this.charstrings = charstrings;
  23702. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  23703. subrs, properties);
  23704. this.seacs = this.getSeacs(data.charstrings);
  23705. };
  23706. Type1Font.prototype = {
  23707. get numGlyphs() {
  23708. return this.charstrings.length + 1;
  23709. },
  23710. getCharset: function Type1Font_getCharset() {
  23711. var charset = ['.notdef'];
  23712. var charstrings = this.charstrings;
  23713. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23714. charset.push(charstrings[glyphId].glyphName);
  23715. }
  23716. return charset;
  23717. },
  23718. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  23719. var charstrings = this.charstrings;
  23720. var glyphNames = ['.notdef'], glyphId;
  23721. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  23722. glyphNames.push(charstrings[glyphId].glyphName);
  23723. }
  23724. var encoding = properties.builtInEncoding;
  23725. if (encoding) {
  23726. var builtInEncoding = {};
  23727. for (var charCode in encoding) {
  23728. glyphId = glyphNames.indexOf(encoding[charCode]);
  23729. if (glyphId >= 0) {
  23730. builtInEncoding[charCode] = glyphId;
  23731. }
  23732. }
  23733. }
  23734. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  23735. },
  23736. getSeacs: function Type1Font_getSeacs(charstrings) {
  23737. var i, ii;
  23738. var seacMap = [];
  23739. for (i = 0, ii = charstrings.length; i < ii; i++) {
  23740. var charstring = charstrings[i];
  23741. if (charstring.seac) {
  23742. // Offset by 1 for .notdef
  23743. seacMap[i + 1] = charstring.seac;
  23744. }
  23745. }
  23746. return seacMap;
  23747. },
  23748. getType2Charstrings: function Type1Font_getType2Charstrings(
  23749. type1Charstrings) {
  23750. var type2Charstrings = [];
  23751. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  23752. type2Charstrings.push(type1Charstrings[i].charstring);
  23753. }
  23754. return type2Charstrings;
  23755. },
  23756. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  23757. var bias = 0;
  23758. var count = type1Subrs.length;
  23759. if (count < 1133) {
  23760. bias = 107;
  23761. } else if (count < 33769) {
  23762. bias = 1131;
  23763. } else {
  23764. bias = 32768;
  23765. }
  23766. // Add a bunch of empty subrs to deal with the Type2 bias
  23767. var type2Subrs = [];
  23768. var i;
  23769. for (i = 0; i < bias; i++) {
  23770. type2Subrs.push([0x0B]);
  23771. }
  23772. for (i = 0; i < count; i++) {
  23773. type2Subrs.push(type1Subrs[i]);
  23774. }
  23775. return type2Subrs;
  23776. },
  23777. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  23778. var cff = new CFF();
  23779. cff.header = new CFFHeader(1, 0, 4, 4);
  23780. cff.names = [name];
  23781. var topDict = new CFFTopDict();
  23782. // CFF strings IDs 0...390 are predefined names, so refering
  23783. // to entries in our own String INDEX starts at SID 391.
  23784. topDict.setByName('version', 391);
  23785. topDict.setByName('Notice', 392);
  23786. topDict.setByName('FullName', 393);
  23787. topDict.setByName('FamilyName', 394);
  23788. topDict.setByName('Weight', 395);
  23789. topDict.setByName('Encoding', null); // placeholder
  23790. topDict.setByName('FontMatrix', properties.fontMatrix);
  23791. topDict.setByName('FontBBox', properties.bbox);
  23792. topDict.setByName('charset', null); // placeholder
  23793. topDict.setByName('CharStrings', null); // placeholder
  23794. topDict.setByName('Private', null); // placeholder
  23795. cff.topDict = topDict;
  23796. var strings = new CFFStrings();
  23797. strings.add('Version 0.11'); // Version
  23798. strings.add('See original notice'); // Notice
  23799. strings.add(name); // FullName
  23800. strings.add(name); // FamilyName
  23801. strings.add('Medium'); // Weight
  23802. cff.strings = strings;
  23803. cff.globalSubrIndex = new CFFIndex();
  23804. var count = glyphs.length;
  23805. var charsetArray = [0];
  23806. var i, ii;
  23807. for (i = 0; i < count; i++) {
  23808. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  23809. // TODO: Insert the string and correctly map it. Previously it was
  23810. // thought mapping names that aren't in the standard strings to .notdef
  23811. // was fine, however in issue818 when mapping them all to .notdef the
  23812. // adieresis glyph no longer worked.
  23813. if (index === -1) {
  23814. index = 0;
  23815. }
  23816. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  23817. }
  23818. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  23819. var charStringsIndex = new CFFIndex();
  23820. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  23821. for (i = 0; i < count; i++) {
  23822. charStringsIndex.add(glyphs[i]);
  23823. }
  23824. cff.charStrings = charStringsIndex;
  23825. var privateDict = new CFFPrivateDict();
  23826. privateDict.setByName('Subrs', null); // placeholder
  23827. var fields = [
  23828. 'BlueValues',
  23829. 'OtherBlues',
  23830. 'FamilyBlues',
  23831. 'FamilyOtherBlues',
  23832. 'StemSnapH',
  23833. 'StemSnapV',
  23834. 'BlueShift',
  23835. 'BlueFuzz',
  23836. 'BlueScale',
  23837. 'LanguageGroup',
  23838. 'ExpansionFactor',
  23839. 'ForceBold',
  23840. 'StdHW',
  23841. 'StdVW'
  23842. ];
  23843. for (i = 0, ii = fields.length; i < ii; i++) {
  23844. var field = fields[i];
  23845. if (!properties.privateData.hasOwnProperty(field)) {
  23846. continue;
  23847. }
  23848. var value = properties.privateData[field];
  23849. if (isArray(value)) {
  23850. // All of the private dictionary array data in CFF must be stored as
  23851. // "delta-encoded" numbers.
  23852. for (var j = value.length - 1; j > 0; j--) {
  23853. value[j] -= value[j - 1]; // ... difference from previous value
  23854. }
  23855. }
  23856. privateDict.setByName(field, value);
  23857. }
  23858. cff.topDict.privateDict = privateDict;
  23859. var subrIndex = new CFFIndex();
  23860. for (i = 0, ii = subrs.length; i < ii; i++) {
  23861. subrIndex.add(subrs[i]);
  23862. }
  23863. privateDict.subrsIndex = subrIndex;
  23864. var compiler = new CFFCompiler(cff);
  23865. return compiler.compile();
  23866. }
  23867. };
  23868. var CFFFont = (function CFFFontClosure() {
  23869. function CFFFont(file, properties) {
  23870. this.properties = properties;
  23871. var parser = new CFFParser(file, properties);
  23872. this.cff = parser.parse();
  23873. var compiler = new CFFCompiler(this.cff);
  23874. this.seacs = this.cff.seacs;
  23875. try {
  23876. this.data = compiler.compile();
  23877. } catch (e) {
  23878. warn('Failed to compile font ' + properties.loadedName);
  23879. // There may have just been an issue with the compiler, set the data
  23880. // anyway and hope the font loaded.
  23881. this.data = file;
  23882. }
  23883. }
  23884. CFFFont.prototype = {
  23885. get numGlyphs() {
  23886. return this.cff.charStrings.count;
  23887. },
  23888. getCharset: function CFFFont_getCharset() {
  23889. return this.cff.charset.charset;
  23890. },
  23891. getGlyphMapping: function CFFFont_getGlyphMapping() {
  23892. var cff = this.cff;
  23893. var properties = this.properties;
  23894. var charsets = cff.charset.charset;
  23895. var charCodeToGlyphId;
  23896. var glyphId;
  23897. if (properties.composite) {
  23898. charCodeToGlyphId = Object.create(null);
  23899. if (cff.isCIDFont) {
  23900. // If the font is actually a CID font then we should use the charset
  23901. // to map CIDs to GIDs.
  23902. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  23903. var cid = charsets[glyphId];
  23904. var charCode = properties.cMap.charCodeOf(cid);
  23905. charCodeToGlyphId[charCode] = glyphId;
  23906. }
  23907. } else {
  23908. // If it is NOT actually a CID font then CIDs should be mapped
  23909. // directly to GIDs.
  23910. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  23911. charCodeToGlyphId[glyphId] = glyphId;
  23912. }
  23913. }
  23914. return charCodeToGlyphId;
  23915. }
  23916. var encoding = cff.encoding ? cff.encoding.encoding : null;
  23917. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  23918. return charCodeToGlyphId;
  23919. }
  23920. };
  23921. return CFFFont;
  23922. })();
  23923. var CFFParser = (function CFFParserClosure() {
  23924. var CharstringValidationData = [
  23925. null,
  23926. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  23927. null,
  23928. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  23929. { id: 'vmoveto', min: 1, stackClearing: true },
  23930. { id: 'rlineto', min: 2, resetStack: true },
  23931. { id: 'hlineto', min: 1, resetStack: true },
  23932. { id: 'vlineto', min: 1, resetStack: true },
  23933. { id: 'rrcurveto', min: 6, resetStack: true },
  23934. null,
  23935. { id: 'callsubr', min: 1, undefStack: true },
  23936. { id: 'return', min: 0, undefStack: true },
  23937. null, // 12
  23938. null,
  23939. { id: 'endchar', min: 0, stackClearing: true },
  23940. null,
  23941. null,
  23942. null,
  23943. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  23944. { id: 'hintmask', min: 0, stackClearing: true },
  23945. { id: 'cntrmask', min: 0, stackClearing: true },
  23946. { id: 'rmoveto', min: 2, stackClearing: true },
  23947. { id: 'hmoveto', min: 1, stackClearing: true },
  23948. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  23949. { id: 'rcurveline', min: 8, resetStack: true },
  23950. { id: 'rlinecurve', min: 8, resetStack: true },
  23951. { id: 'vvcurveto', min: 4, resetStack: true },
  23952. { id: 'hhcurveto', min: 4, resetStack: true },
  23953. null, // shortint
  23954. { id: 'callgsubr', min: 1, undefStack: true },
  23955. { id: 'vhcurveto', min: 4, resetStack: true },
  23956. { id: 'hvcurveto', min: 4, resetStack: true }
  23957. ];
  23958. var CharstringValidationData12 = [
  23959. null,
  23960. null,
  23961. null,
  23962. { id: 'and', min: 2, stackDelta: -1 },
  23963. { id: 'or', min: 2, stackDelta: -1 },
  23964. { id: 'not', min: 1, stackDelta: 0 },
  23965. null,
  23966. null,
  23967. null,
  23968. { id: 'abs', min: 1, stackDelta: 0 },
  23969. { id: 'add', min: 2, stackDelta: -1,
  23970. stackFn: function stack_div(stack, index) {
  23971. stack[index - 2] = stack[index - 2] + stack[index - 1];
  23972. }
  23973. },
  23974. { id: 'sub', min: 2, stackDelta: -1,
  23975. stackFn: function stack_div(stack, index) {
  23976. stack[index - 2] = stack[index - 2] - stack[index - 1];
  23977. }
  23978. },
  23979. { id: 'div', min: 2, stackDelta: -1,
  23980. stackFn: function stack_div(stack, index) {
  23981. stack[index - 2] = stack[index - 2] / stack[index - 1];
  23982. }
  23983. },
  23984. null,
  23985. { id: 'neg', min: 1, stackDelta: 0,
  23986. stackFn: function stack_div(stack, index) {
  23987. stack[index - 1] = -stack[index - 1];
  23988. }
  23989. },
  23990. { id: 'eq', min: 2, stackDelta: -1 },
  23991. null,
  23992. null,
  23993. { id: 'drop', min: 1, stackDelta: -1 },
  23994. null,
  23995. { id: 'put', min: 2, stackDelta: -2 },
  23996. { id: 'get', min: 1, stackDelta: 0 },
  23997. { id: 'ifelse', min: 4, stackDelta: -3 },
  23998. { id: 'random', min: 0, stackDelta: 1 },
  23999. { id: 'mul', min: 2, stackDelta: -1,
  24000. stackFn: function stack_div(stack, index) {
  24001. stack[index - 2] = stack[index - 2] * stack[index - 1];
  24002. }
  24003. },
  24004. null,
  24005. { id: 'sqrt', min: 1, stackDelta: 0 },
  24006. { id: 'dup', min: 1, stackDelta: 1 },
  24007. { id: 'exch', min: 2, stackDelta: 0 },
  24008. { id: 'index', min: 2, stackDelta: 0 },
  24009. { id: 'roll', min: 3, stackDelta: -2 },
  24010. null,
  24011. null,
  24012. null,
  24013. { id: 'hflex', min: 7, resetStack: true },
  24014. { id: 'flex', min: 13, resetStack: true },
  24015. { id: 'hflex1', min: 9, resetStack: true },
  24016. { id: 'flex1', min: 11, resetStack: true }
  24017. ];
  24018. function CFFParser(file, properties) {
  24019. this.bytes = file.getBytes();
  24020. this.properties = properties;
  24021. }
  24022. CFFParser.prototype = {
  24023. parse: function CFFParser_parse() {
  24024. var properties = this.properties;
  24025. var cff = new CFF();
  24026. this.cff = cff;
  24027. // The first five sections must be in order, all the others are reached
  24028. // via offsets contained in one of the below.
  24029. var header = this.parseHeader();
  24030. var nameIndex = this.parseIndex(header.endPos);
  24031. var topDictIndex = this.parseIndex(nameIndex.endPos);
  24032. var stringIndex = this.parseIndex(topDictIndex.endPos);
  24033. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  24034. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  24035. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  24036. cff.header = header.obj;
  24037. cff.names = this.parseNameIndex(nameIndex.obj);
  24038. cff.strings = this.parseStringIndex(stringIndex.obj);
  24039. cff.topDict = topDict;
  24040. cff.globalSubrIndex = globalSubrIndex.obj;
  24041. this.parsePrivateDict(cff.topDict);
  24042. cff.isCIDFont = topDict.hasName('ROS');
  24043. var charStringOffset = topDict.getByName('CharStrings');
  24044. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  24045. cff.charStrings = charStringsAndSeacs.charStrings;
  24046. cff.seacs = charStringsAndSeacs.seacs;
  24047. cff.widths = charStringsAndSeacs.widths;
  24048. var fontMatrix = topDict.getByName('FontMatrix');
  24049. if (fontMatrix) {
  24050. properties.fontMatrix = fontMatrix;
  24051. }
  24052. var fontBBox = topDict.getByName('FontBBox');
  24053. if (fontBBox) {
  24054. // adjusting ascent/descent
  24055. properties.ascent = fontBBox[3];
  24056. properties.descent = fontBBox[1];
  24057. properties.ascentScaled = true;
  24058. }
  24059. var charset, encoding;
  24060. if (cff.isCIDFont) {
  24061. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  24062. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  24063. var dictRaw = fdArrayIndex.get(i);
  24064. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  24065. cff.strings);
  24066. this.parsePrivateDict(fontDict);
  24067. cff.fdArray.push(fontDict);
  24068. }
  24069. // cid fonts don't have an encoding
  24070. encoding = null;
  24071. charset = this.parseCharsets(topDict.getByName('charset'),
  24072. cff.charStrings.count, cff.strings, true);
  24073. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  24074. cff.charStrings.count);
  24075. } else {
  24076. charset = this.parseCharsets(topDict.getByName('charset'),
  24077. cff.charStrings.count, cff.strings, false);
  24078. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  24079. properties,
  24080. cff.strings, charset.charset);
  24081. }
  24082. cff.charset = charset;
  24083. cff.encoding = encoding;
  24084. return cff;
  24085. },
  24086. parseHeader: function CFFParser_parseHeader() {
  24087. var bytes = this.bytes;
  24088. var bytesLength = bytes.length;
  24089. var offset = 0;
  24090. // Prevent an infinite loop, by checking that the offset is within the
  24091. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  24092. while (offset < bytesLength && bytes[offset] !== 1) {
  24093. ++offset;
  24094. }
  24095. if (offset >= bytesLength) {
  24096. error('Invalid CFF header');
  24097. } else if (offset !== 0) {
  24098. info('cff data is shifted');
  24099. bytes = bytes.subarray(offset);
  24100. this.bytes = bytes;
  24101. }
  24102. var major = bytes[0];
  24103. var minor = bytes[1];
  24104. var hdrSize = bytes[2];
  24105. var offSize = bytes[3];
  24106. var header = new CFFHeader(major, minor, hdrSize, offSize);
  24107. return { obj: header, endPos: hdrSize };
  24108. },
  24109. parseDict: function CFFParser_parseDict(dict) {
  24110. var pos = 0;
  24111. function parseOperand() {
  24112. var value = dict[pos++];
  24113. if (value === 30) {
  24114. return parseFloatOperand(pos);
  24115. } else if (value === 28) {
  24116. value = dict[pos++];
  24117. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  24118. return value;
  24119. } else if (value === 29) {
  24120. value = dict[pos++];
  24121. value = (value << 8) | dict[pos++];
  24122. value = (value << 8) | dict[pos++];
  24123. value = (value << 8) | dict[pos++];
  24124. return value;
  24125. } else if (value >= 32 && value <= 246) {
  24126. return value - 139;
  24127. } else if (value >= 247 && value <= 250) {
  24128. return ((value - 247) * 256) + dict[pos++] + 108;
  24129. } else if (value >= 251 && value <= 254) {
  24130. return -((value - 251) * 256) - dict[pos++] - 108;
  24131. } else {
  24132. error('255 is not a valid DICT command');
  24133. }
  24134. return -1;
  24135. }
  24136. function parseFloatOperand() {
  24137. var str = '';
  24138. var eof = 15;
  24139. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  24140. '9', '.', 'E', 'E-', null, '-'];
  24141. var length = dict.length;
  24142. while (pos < length) {
  24143. var b = dict[pos++];
  24144. var b1 = b >> 4;
  24145. var b2 = b & 15;
  24146. if (b1 === eof) {
  24147. break;
  24148. }
  24149. str += lookup[b1];
  24150. if (b2 === eof) {
  24151. break;
  24152. }
  24153. str += lookup[b2];
  24154. }
  24155. return parseFloat(str);
  24156. }
  24157. var operands = [];
  24158. var entries = [];
  24159. pos = 0;
  24160. var end = dict.length;
  24161. while (pos < end) {
  24162. var b = dict[pos];
  24163. if (b <= 21) {
  24164. if (b === 12) {
  24165. b = (b << 8) | dict[++pos];
  24166. }
  24167. entries.push([b, operands]);
  24168. operands = [];
  24169. ++pos;
  24170. } else {
  24171. operands.push(parseOperand());
  24172. }
  24173. }
  24174. return entries;
  24175. },
  24176. parseIndex: function CFFParser_parseIndex(pos) {
  24177. var cffIndex = new CFFIndex();
  24178. var bytes = this.bytes;
  24179. var count = (bytes[pos++] << 8) | bytes[pos++];
  24180. var offsets = [];
  24181. var end = pos;
  24182. var i, ii;
  24183. if (count !== 0) {
  24184. var offsetSize = bytes[pos++];
  24185. // add 1 for offset to determine size of last object
  24186. var startPos = pos + ((count + 1) * offsetSize) - 1;
  24187. for (i = 0, ii = count + 1; i < ii; ++i) {
  24188. var offset = 0;
  24189. for (var j = 0; j < offsetSize; ++j) {
  24190. offset <<= 8;
  24191. offset += bytes[pos++];
  24192. }
  24193. offsets.push(startPos + offset);
  24194. }
  24195. end = offsets[count];
  24196. }
  24197. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  24198. var offsetStart = offsets[i];
  24199. var offsetEnd = offsets[i + 1];
  24200. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  24201. }
  24202. return {obj: cffIndex, endPos: end};
  24203. },
  24204. parseNameIndex: function CFFParser_parseNameIndex(index) {
  24205. var names = [];
  24206. for (var i = 0, ii = index.count; i < ii; ++i) {
  24207. var name = index.get(i);
  24208. // OTS doesn't allow names to be over 127 characters.
  24209. var length = Math.min(name.length, 127);
  24210. var data = [];
  24211. // OTS also only permits certain characters in the name.
  24212. for (var j = 0; j < length; ++j) {
  24213. var c = name[j];
  24214. if (j === 0 && c === 0) {
  24215. data[j] = c;
  24216. continue;
  24217. }
  24218. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  24219. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  24220. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  24221. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  24222. data[j] = 95;
  24223. continue;
  24224. }
  24225. data[j] = c;
  24226. }
  24227. names.push(bytesToString(data));
  24228. }
  24229. return names;
  24230. },
  24231. parseStringIndex: function CFFParser_parseStringIndex(index) {
  24232. var strings = new CFFStrings();
  24233. for (var i = 0, ii = index.count; i < ii; ++i) {
  24234. var data = index.get(i);
  24235. strings.add(bytesToString(data));
  24236. }
  24237. return strings;
  24238. },
  24239. createDict: function CFFParser_createDict(Type, dict, strings) {
  24240. var cffDict = new Type(strings);
  24241. for (var i = 0, ii = dict.length; i < ii; ++i) {
  24242. var pair = dict[i];
  24243. var key = pair[0];
  24244. var value = pair[1];
  24245. cffDict.setByKey(key, value);
  24246. }
  24247. return cffDict;
  24248. },
  24249. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  24250. var charStrings = this.parseIndex(charStringOffset).obj;
  24251. var seacs = [];
  24252. var widths = [];
  24253. var count = charStrings.count;
  24254. for (var i = 0; i < count; i++) {
  24255. var charstring = charStrings.get(i);
  24256. var stackSize = 0;
  24257. var stack = [];
  24258. var undefStack = true;
  24259. var hints = 0;
  24260. var valid = true;
  24261. var data = charstring;
  24262. var length = data.length;
  24263. var firstStackClearing = true;
  24264. for (var j = 0; j < length;) {
  24265. var value = data[j++];
  24266. var validationCommand = null;
  24267. if (value === 12) {
  24268. var q = data[j++];
  24269. if (q === 0) {
  24270. // The CFF specification state that the 'dotsection' command
  24271. // (12, 0) is deprecated and treated as a no-op, but all Type2
  24272. // charstrings processors should support them. Unfortunately
  24273. // the font sanitizer don't. As a workaround the sequence (12, 0)
  24274. // is replaced by a useless (0, hmoveto).
  24275. data[j - 2] = 139;
  24276. data[j - 1] = 22;
  24277. stackSize = 0;
  24278. } else {
  24279. validationCommand = CharstringValidationData12[q];
  24280. }
  24281. } else if (value === 28) { // number (16 bit)
  24282. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  24283. j += 2;
  24284. stackSize++;
  24285. } else if (value === 14) {
  24286. if (stackSize >= 4) {
  24287. stackSize -= 4;
  24288. if (SEAC_ANALYSIS_ENABLED) {
  24289. seacs[i] = stack.slice(stackSize, stackSize + 4);
  24290. valid = false;
  24291. }
  24292. }
  24293. validationCommand = CharstringValidationData[value];
  24294. } else if (value >= 32 && value <= 246) { // number
  24295. stack[stackSize] = value - 139;
  24296. stackSize++;
  24297. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  24298. stack[stackSize] = (value < 251 ?
  24299. ((value - 247) << 8) + data[j] + 108 :
  24300. -((value - 251) << 8) - data[j] - 108);
  24301. j++;
  24302. stackSize++;
  24303. } else if (value === 255) { // number (32 bit)
  24304. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  24305. (data[j + 2] << 8) | data[j + 3]) / 65536;
  24306. j += 4;
  24307. stackSize++;
  24308. } else if (value === 19 || value === 20) {
  24309. hints += stackSize >> 1;
  24310. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  24311. stackSize %= 2;
  24312. validationCommand = CharstringValidationData[value];
  24313. } else {
  24314. validationCommand = CharstringValidationData[value];
  24315. }
  24316. if (validationCommand) {
  24317. if (validationCommand.stem) {
  24318. hints += stackSize >> 1;
  24319. }
  24320. if ('min' in validationCommand) {
  24321. if (!undefStack && stackSize < validationCommand.min) {
  24322. warn('Not enough parameters for ' + validationCommand.id +
  24323. '; actual: ' + stackSize +
  24324. ', expected: ' + validationCommand.min);
  24325. valid = false;
  24326. break;
  24327. }
  24328. }
  24329. if (firstStackClearing && validationCommand.stackClearing) {
  24330. firstStackClearing = false;
  24331. // the optional character width can be found before the first
  24332. // stack-clearing command arguments
  24333. stackSize -= validationCommand.min;
  24334. if (stackSize >= 2 && validationCommand.stem) {
  24335. // there are even amount of arguments for stem commands
  24336. stackSize %= 2;
  24337. } else if (stackSize > 1) {
  24338. warn('Found too many parameters for stack-clearing command');
  24339. }
  24340. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  24341. widths[i] = stack[stackSize - 1];
  24342. }
  24343. }
  24344. if ('stackDelta' in validationCommand) {
  24345. if ('stackFn' in validationCommand) {
  24346. validationCommand.stackFn(stack, stackSize);
  24347. }
  24348. stackSize += validationCommand.stackDelta;
  24349. } else if (validationCommand.stackClearing) {
  24350. stackSize = 0;
  24351. } else if (validationCommand.resetStack) {
  24352. stackSize = 0;
  24353. undefStack = false;
  24354. } else if (validationCommand.undefStack) {
  24355. stackSize = 0;
  24356. undefStack = true;
  24357. firstStackClearing = false;
  24358. }
  24359. }
  24360. }
  24361. if (!valid) {
  24362. // resetting invalid charstring to single 'endchar'
  24363. charStrings.set(i, new Uint8Array([14]));
  24364. }
  24365. }
  24366. return { charStrings: charStrings, seacs: seacs, widths: widths };
  24367. },
  24368. emptyPrivateDictionary:
  24369. function CFFParser_emptyPrivateDictionary(parentDict) {
  24370. var privateDict = this.createDict(CFFPrivateDict, [],
  24371. parentDict.strings);
  24372. parentDict.setByKey(18, [0, 0]);
  24373. parentDict.privateDict = privateDict;
  24374. },
  24375. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  24376. // no private dict, do nothing
  24377. if (!parentDict.hasName('Private')) {
  24378. this.emptyPrivateDictionary(parentDict);
  24379. return;
  24380. }
  24381. var privateOffset = parentDict.getByName('Private');
  24382. // make sure the params are formatted correctly
  24383. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  24384. parentDict.removeByName('Private');
  24385. return;
  24386. }
  24387. var size = privateOffset[0];
  24388. var offset = privateOffset[1];
  24389. // remove empty dicts or ones that refer to invalid location
  24390. if (size === 0 || offset >= this.bytes.length) {
  24391. this.emptyPrivateDictionary(parentDict);
  24392. return;
  24393. }
  24394. var privateDictEnd = offset + size;
  24395. var dictData = this.bytes.subarray(offset, privateDictEnd);
  24396. var dict = this.parseDict(dictData);
  24397. var privateDict = this.createDict(CFFPrivateDict, dict,
  24398. parentDict.strings);
  24399. parentDict.privateDict = privateDict;
  24400. // Parse the Subrs index also since it's relative to the private dict.
  24401. if (!privateDict.getByName('Subrs')) {
  24402. return;
  24403. }
  24404. var subrsOffset = privateDict.getByName('Subrs');
  24405. var relativeOffset = offset + subrsOffset;
  24406. // Validate the offset.
  24407. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  24408. this.emptyPrivateDictionary(parentDict);
  24409. return;
  24410. }
  24411. var subrsIndex = this.parseIndex(relativeOffset);
  24412. privateDict.subrsIndex = subrsIndex.obj;
  24413. },
  24414. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  24415. if (pos === 0) {
  24416. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  24417. ISOAdobeCharset);
  24418. } else if (pos === 1) {
  24419. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  24420. ExpertCharset);
  24421. } else if (pos === 2) {
  24422. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  24423. ExpertSubsetCharset);
  24424. }
  24425. var bytes = this.bytes;
  24426. var start = pos;
  24427. var format = bytes[pos++];
  24428. var charset = ['.notdef'];
  24429. var id, count, i;
  24430. // subtract 1 for the .notdef glyph
  24431. length -= 1;
  24432. switch (format) {
  24433. case 0:
  24434. for (i = 0; i < length; i++) {
  24435. id = (bytes[pos++] << 8) | bytes[pos++];
  24436. charset.push(cid ? id : strings.get(id));
  24437. }
  24438. break;
  24439. case 1:
  24440. while (charset.length <= length) {
  24441. id = (bytes[pos++] << 8) | bytes[pos++];
  24442. count = bytes[pos++];
  24443. for (i = 0; i <= count; i++) {
  24444. charset.push(cid ? id++ : strings.get(id++));
  24445. }
  24446. }
  24447. break;
  24448. case 2:
  24449. while (charset.length <= length) {
  24450. id = (bytes[pos++] << 8) | bytes[pos++];
  24451. count = (bytes[pos++] << 8) | bytes[pos++];
  24452. for (i = 0; i <= count; i++) {
  24453. charset.push(cid ? id++ : strings.get(id++));
  24454. }
  24455. }
  24456. break;
  24457. default:
  24458. error('Unknown charset format');
  24459. }
  24460. // Raw won't be needed if we actually compile the charset.
  24461. var end = pos;
  24462. var raw = bytes.subarray(start, end);
  24463. return new CFFCharset(false, format, charset, raw);
  24464. },
  24465. parseEncoding: function CFFParser_parseEncoding(pos,
  24466. properties,
  24467. strings,
  24468. charset) {
  24469. var encoding = {};
  24470. var bytes = this.bytes;
  24471. var predefined = false;
  24472. var hasSupplement = false;
  24473. var format, i, ii;
  24474. var raw = null;
  24475. function readSupplement() {
  24476. var supplementsCount = bytes[pos++];
  24477. for (i = 0; i < supplementsCount; i++) {
  24478. var code = bytes[pos++];
  24479. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  24480. encoding[code] = charset.indexOf(strings.get(sid));
  24481. }
  24482. }
  24483. if (pos === 0 || pos === 1) {
  24484. predefined = true;
  24485. format = pos;
  24486. var baseEncoding = pos ? Encodings.ExpertEncoding :
  24487. Encodings.StandardEncoding;
  24488. for (i = 0, ii = charset.length; i < ii; i++) {
  24489. var index = baseEncoding.indexOf(charset[i]);
  24490. if (index !== -1) {
  24491. encoding[index] = i;
  24492. }
  24493. }
  24494. } else {
  24495. var dataStart = pos;
  24496. format = bytes[pos++];
  24497. switch (format & 0x7f) {
  24498. case 0:
  24499. var glyphsCount = bytes[pos++];
  24500. for (i = 1; i <= glyphsCount; i++) {
  24501. encoding[bytes[pos++]] = i;
  24502. }
  24503. break;
  24504. case 1:
  24505. var rangesCount = bytes[pos++];
  24506. var gid = 1;
  24507. for (i = 0; i < rangesCount; i++) {
  24508. var start = bytes[pos++];
  24509. var left = bytes[pos++];
  24510. for (var j = start; j <= start + left; j++) {
  24511. encoding[j] = gid++;
  24512. }
  24513. }
  24514. break;
  24515. default:
  24516. error('Unknow encoding format: ' + format + ' in CFF');
  24517. break;
  24518. }
  24519. var dataEnd = pos;
  24520. if (format & 0x80) {
  24521. // The font sanitizer does not support CFF encoding with a
  24522. // supplement, since the encoding is not really used to map
  24523. // between gid to glyph, let's overwrite what is declared in
  24524. // the top dictionary to let the sanitizer think the font use
  24525. // StandardEncoding, that's a lie but that's ok.
  24526. bytes[dataStart] &= 0x7f;
  24527. readSupplement();
  24528. hasSupplement = true;
  24529. }
  24530. raw = bytes.subarray(dataStart, dataEnd);
  24531. }
  24532. format = format & 0x7f;
  24533. return new CFFEncoding(predefined, format, encoding, raw);
  24534. },
  24535. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  24536. var start = pos;
  24537. var bytes = this.bytes;
  24538. var format = bytes[pos++];
  24539. var fdSelect = [];
  24540. var i;
  24541. switch (format) {
  24542. case 0:
  24543. for (i = 0; i < length; ++i) {
  24544. var id = bytes[pos++];
  24545. fdSelect.push(id);
  24546. }
  24547. break;
  24548. case 3:
  24549. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  24550. for (i = 0; i < rangesCount; ++i) {
  24551. var first = (bytes[pos++] << 8) | bytes[pos++];
  24552. var fdIndex = bytes[pos++];
  24553. var next = (bytes[pos] << 8) | bytes[pos + 1];
  24554. for (var j = first; j < next; ++j) {
  24555. fdSelect.push(fdIndex);
  24556. }
  24557. }
  24558. // Advance past the sentinel(next).
  24559. pos += 2;
  24560. break;
  24561. default:
  24562. error('Unknown fdselect format ' + format);
  24563. break;
  24564. }
  24565. var end = pos;
  24566. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  24567. }
  24568. };
  24569. return CFFParser;
  24570. })();
  24571. // Compact Font Format
  24572. var CFF = (function CFFClosure() {
  24573. function CFF() {
  24574. this.header = null;
  24575. this.names = [];
  24576. this.topDict = null;
  24577. this.strings = new CFFStrings();
  24578. this.globalSubrIndex = null;
  24579. // The following could really be per font, but since we only have one font
  24580. // store them here.
  24581. this.encoding = null;
  24582. this.charset = null;
  24583. this.charStrings = null;
  24584. this.fdArray = [];
  24585. this.fdSelect = null;
  24586. this.isCIDFont = false;
  24587. }
  24588. return CFF;
  24589. })();
  24590. var CFFHeader = (function CFFHeaderClosure() {
  24591. function CFFHeader(major, minor, hdrSize, offSize) {
  24592. this.major = major;
  24593. this.minor = minor;
  24594. this.hdrSize = hdrSize;
  24595. this.offSize = offSize;
  24596. }
  24597. return CFFHeader;
  24598. })();
  24599. var CFFStrings = (function CFFStringsClosure() {
  24600. function CFFStrings() {
  24601. this.strings = [];
  24602. }
  24603. CFFStrings.prototype = {
  24604. get: function CFFStrings_get(index) {
  24605. if (index >= 0 && index <= 390) {
  24606. return CFFStandardStrings[index];
  24607. }
  24608. if (index - 391 <= this.strings.length) {
  24609. return this.strings[index - 391];
  24610. }
  24611. return CFFStandardStrings[0];
  24612. },
  24613. add: function CFFStrings_add(value) {
  24614. this.strings.push(value);
  24615. },
  24616. get count() {
  24617. return this.strings.length;
  24618. }
  24619. };
  24620. return CFFStrings;
  24621. })();
  24622. var CFFIndex = (function CFFIndexClosure() {
  24623. function CFFIndex() {
  24624. this.objects = [];
  24625. this.length = 0;
  24626. }
  24627. CFFIndex.prototype = {
  24628. add: function CFFIndex_add(data) {
  24629. this.length += data.length;
  24630. this.objects.push(data);
  24631. },
  24632. set: function CFFIndex_set(index, data) {
  24633. this.length += data.length - this.objects[index].length;
  24634. this.objects[index] = data;
  24635. },
  24636. get: function CFFIndex_get(index) {
  24637. return this.objects[index];
  24638. },
  24639. get count() {
  24640. return this.objects.length;
  24641. }
  24642. };
  24643. return CFFIndex;
  24644. })();
  24645. var CFFDict = (function CFFDictClosure() {
  24646. function CFFDict(tables, strings) {
  24647. this.keyToNameMap = tables.keyToNameMap;
  24648. this.nameToKeyMap = tables.nameToKeyMap;
  24649. this.defaults = tables.defaults;
  24650. this.types = tables.types;
  24651. this.opcodes = tables.opcodes;
  24652. this.order = tables.order;
  24653. this.strings = strings;
  24654. this.values = {};
  24655. }
  24656. CFFDict.prototype = {
  24657. // value should always be an array
  24658. setByKey: function CFFDict_setByKey(key, value) {
  24659. if (!(key in this.keyToNameMap)) {
  24660. return false;
  24661. }
  24662. // ignore empty values
  24663. if (value.length === 0) {
  24664. return true;
  24665. }
  24666. var type = this.types[key];
  24667. // remove the array wrapping these types of values
  24668. if (type === 'num' || type === 'sid' || type === 'offset') {
  24669. value = value[0];
  24670. }
  24671. this.values[key] = value;
  24672. return true;
  24673. },
  24674. setByName: function CFFDict_setByName(name, value) {
  24675. if (!(name in this.nameToKeyMap)) {
  24676. error('Invalid dictionary name "' + name + '"');
  24677. }
  24678. this.values[this.nameToKeyMap[name]] = value;
  24679. },
  24680. hasName: function CFFDict_hasName(name) {
  24681. return this.nameToKeyMap[name] in this.values;
  24682. },
  24683. getByName: function CFFDict_getByName(name) {
  24684. if (!(name in this.nameToKeyMap)) {
  24685. error('Invalid dictionary name "' + name + '"');
  24686. }
  24687. var key = this.nameToKeyMap[name];
  24688. if (!(key in this.values)) {
  24689. return this.defaults[key];
  24690. }
  24691. return this.values[key];
  24692. },
  24693. removeByName: function CFFDict_removeByName(name) {
  24694. delete this.values[this.nameToKeyMap[name]];
  24695. }
  24696. };
  24697. CFFDict.createTables = function CFFDict_createTables(layout) {
  24698. var tables = {
  24699. keyToNameMap: {},
  24700. nameToKeyMap: {},
  24701. defaults: {},
  24702. types: {},
  24703. opcodes: {},
  24704. order: []
  24705. };
  24706. for (var i = 0, ii = layout.length; i < ii; ++i) {
  24707. var entry = layout[i];
  24708. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  24709. tables.keyToNameMap[key] = entry[1];
  24710. tables.nameToKeyMap[entry[1]] = key;
  24711. tables.types[key] = entry[2];
  24712. tables.defaults[key] = entry[3];
  24713. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  24714. tables.order.push(key);
  24715. }
  24716. return tables;
  24717. };
  24718. return CFFDict;
  24719. })();
  24720. var CFFTopDict = (function CFFTopDictClosure() {
  24721. var layout = [
  24722. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  24723. [[12, 20], 'SyntheticBase', 'num', null],
  24724. [0, 'version', 'sid', null],
  24725. [1, 'Notice', 'sid', null],
  24726. [[12, 0], 'Copyright', 'sid', null],
  24727. [2, 'FullName', 'sid', null],
  24728. [3, 'FamilyName', 'sid', null],
  24729. [4, 'Weight', 'sid', null],
  24730. [[12, 1], 'isFixedPitch', 'num', 0],
  24731. [[12, 2], 'ItalicAngle', 'num', 0],
  24732. [[12, 3], 'UnderlinePosition', 'num', -100],
  24733. [[12, 4], 'UnderlineThickness', 'num', 50],
  24734. [[12, 5], 'PaintType', 'num', 0],
  24735. [[12, 6], 'CharstringType', 'num', 2],
  24736. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  24737. [0.001, 0, 0, 0.001, 0, 0]],
  24738. [13, 'UniqueID', 'num', null],
  24739. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  24740. [[12, 8], 'StrokeWidth', 'num', 0],
  24741. [14, 'XUID', 'array', null],
  24742. [15, 'charset', 'offset', 0],
  24743. [16, 'Encoding', 'offset', 0],
  24744. [17, 'CharStrings', 'offset', 0],
  24745. [18, 'Private', ['offset', 'offset'], null],
  24746. [[12, 21], 'PostScript', 'sid', null],
  24747. [[12, 22], 'BaseFontName', 'sid', null],
  24748. [[12, 23], 'BaseFontBlend', 'delta', null],
  24749. [[12, 31], 'CIDFontVersion', 'num', 0],
  24750. [[12, 32], 'CIDFontRevision', 'num', 0],
  24751. [[12, 33], 'CIDFontType', 'num', 0],
  24752. [[12, 34], 'CIDCount', 'num', 8720],
  24753. [[12, 35], 'UIDBase', 'num', null],
  24754. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  24755. // before FDArray.
  24756. [[12, 37], 'FDSelect', 'offset', null],
  24757. [[12, 36], 'FDArray', 'offset', null],
  24758. [[12, 38], 'FontName', 'sid', null]
  24759. ];
  24760. var tables = null;
  24761. function CFFTopDict(strings) {
  24762. if (tables === null) {
  24763. tables = CFFDict.createTables(layout);
  24764. }
  24765. CFFDict.call(this, tables, strings);
  24766. this.privateDict = null;
  24767. }
  24768. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  24769. return CFFTopDict;
  24770. })();
  24771. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  24772. var layout = [
  24773. [6, 'BlueValues', 'delta', null],
  24774. [7, 'OtherBlues', 'delta', null],
  24775. [8, 'FamilyBlues', 'delta', null],
  24776. [9, 'FamilyOtherBlues', 'delta', null],
  24777. [[12, 9], 'BlueScale', 'num', 0.039625],
  24778. [[12, 10], 'BlueShift', 'num', 7],
  24779. [[12, 11], 'BlueFuzz', 'num', 1],
  24780. [10, 'StdHW', 'num', null],
  24781. [11, 'StdVW', 'num', null],
  24782. [[12, 12], 'StemSnapH', 'delta', null],
  24783. [[12, 13], 'StemSnapV', 'delta', null],
  24784. [[12, 14], 'ForceBold', 'num', 0],
  24785. [[12, 17], 'LanguageGroup', 'num', 0],
  24786. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  24787. [[12, 19], 'initialRandomSeed', 'num', 0],
  24788. [20, 'defaultWidthX', 'num', 0],
  24789. [21, 'nominalWidthX', 'num', 0],
  24790. [19, 'Subrs', 'offset', null]
  24791. ];
  24792. var tables = null;
  24793. function CFFPrivateDict(strings) {
  24794. if (tables === null) {
  24795. tables = CFFDict.createTables(layout);
  24796. }
  24797. CFFDict.call(this, tables, strings);
  24798. this.subrsIndex = null;
  24799. }
  24800. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  24801. return CFFPrivateDict;
  24802. })();
  24803. var CFFCharsetPredefinedTypes = {
  24804. ISO_ADOBE: 0,
  24805. EXPERT: 1,
  24806. EXPERT_SUBSET: 2
  24807. };
  24808. var CFFCharset = (function CFFCharsetClosure() {
  24809. function CFFCharset(predefined, format, charset, raw) {
  24810. this.predefined = predefined;
  24811. this.format = format;
  24812. this.charset = charset;
  24813. this.raw = raw;
  24814. }
  24815. return CFFCharset;
  24816. })();
  24817. var CFFEncoding = (function CFFEncodingClosure() {
  24818. function CFFEncoding(predefined, format, encoding, raw) {
  24819. this.predefined = predefined;
  24820. this.format = format;
  24821. this.encoding = encoding;
  24822. this.raw = raw;
  24823. }
  24824. return CFFEncoding;
  24825. })();
  24826. var CFFFDSelect = (function CFFFDSelectClosure() {
  24827. function CFFFDSelect(fdSelect, raw) {
  24828. this.fdSelect = fdSelect;
  24829. this.raw = raw;
  24830. }
  24831. return CFFFDSelect;
  24832. })();
  24833. // Helper class to keep track of where an offset is within the data and helps
  24834. // filling in that offset once it's known.
  24835. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  24836. function CFFOffsetTracker() {
  24837. this.offsets = {};
  24838. }
  24839. CFFOffsetTracker.prototype = {
  24840. isTracking: function CFFOffsetTracker_isTracking(key) {
  24841. return key in this.offsets;
  24842. },
  24843. track: function CFFOffsetTracker_track(key, location) {
  24844. if (key in this.offsets) {
  24845. error('Already tracking location of ' + key);
  24846. }
  24847. this.offsets[key] = location;
  24848. },
  24849. offset: function CFFOffsetTracker_offset(value) {
  24850. for (var key in this.offsets) {
  24851. this.offsets[key] += value;
  24852. }
  24853. },
  24854. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  24855. values,
  24856. output) {
  24857. if (!(key in this.offsets)) {
  24858. error('Not tracking location of ' + key);
  24859. }
  24860. var data = output.data;
  24861. var dataOffset = this.offsets[key];
  24862. var size = 5;
  24863. for (var i = 0, ii = values.length; i < ii; ++i) {
  24864. var offset0 = i * size + dataOffset;
  24865. var offset1 = offset0 + 1;
  24866. var offset2 = offset0 + 2;
  24867. var offset3 = offset0 + 3;
  24868. var offset4 = offset0 + 4;
  24869. // It's easy to screw up offsets so perform this sanity check.
  24870. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  24871. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  24872. error('writing to an offset that is not empty');
  24873. }
  24874. var value = values[i];
  24875. data[offset0] = 0x1d;
  24876. data[offset1] = (value >> 24) & 0xFF;
  24877. data[offset2] = (value >> 16) & 0xFF;
  24878. data[offset3] = (value >> 8) & 0xFF;
  24879. data[offset4] = value & 0xFF;
  24880. }
  24881. }
  24882. };
  24883. return CFFOffsetTracker;
  24884. })();
  24885. // Takes a CFF and converts it to the binary representation.
  24886. var CFFCompiler = (function CFFCompilerClosure() {
  24887. function CFFCompiler(cff) {
  24888. this.cff = cff;
  24889. }
  24890. CFFCompiler.prototype = {
  24891. compile: function CFFCompiler_compile() {
  24892. var cff = this.cff;
  24893. var output = {
  24894. data: [],
  24895. length: 0,
  24896. add: function CFFCompiler_add(data) {
  24897. this.data = this.data.concat(data);
  24898. this.length = this.data.length;
  24899. }
  24900. };
  24901. // Compile the five entries that must be in order.
  24902. var header = this.compileHeader(cff.header);
  24903. output.add(header);
  24904. var nameIndex = this.compileNameIndex(cff.names);
  24905. output.add(nameIndex);
  24906. if (cff.isCIDFont) {
  24907. // The spec is unclear on how font matrices should relate to each other
  24908. // when there is one in the main top dict and the sub top dicts.
  24909. // Windows handles this differently than linux and osx so we have to
  24910. // normalize to work on all.
  24911. // Rules based off of some mailing list discussions:
  24912. // - If main font has a matrix and subfont doesn't, use the main matrix.
  24913. // - If no main font matrix and there is a subfont matrix, use the
  24914. // subfont matrix.
  24915. // - If both have matrices, concat together.
  24916. // - If neither have matrices, use default.
  24917. // To make this work on all platforms we move the top matrix into each
  24918. // sub top dict and concat if necessary.
  24919. if (cff.topDict.hasName('FontMatrix')) {
  24920. var base = cff.topDict.getByName('FontMatrix');
  24921. cff.topDict.removeByName('FontMatrix');
  24922. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  24923. var subDict = cff.fdArray[i];
  24924. var matrix = base.slice(0);
  24925. if (subDict.hasName('FontMatrix')) {
  24926. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  24927. }
  24928. subDict.setByName('FontMatrix', matrix);
  24929. }
  24930. }
  24931. }
  24932. var compiled = this.compileTopDicts([cff.topDict],
  24933. output.length,
  24934. cff.isCIDFont);
  24935. output.add(compiled.output);
  24936. var topDictTracker = compiled.trackers[0];
  24937. var stringIndex = this.compileStringIndex(cff.strings.strings);
  24938. output.add(stringIndex);
  24939. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  24940. output.add(globalSubrIndex);
  24941. // Now start on the other entries that have no specfic order.
  24942. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  24943. if (cff.encoding.predefined) {
  24944. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  24945. output);
  24946. } else {
  24947. var encoding = this.compileEncoding(cff.encoding);
  24948. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  24949. output.add(encoding);
  24950. }
  24951. }
  24952. if (cff.charset && cff.topDict.hasName('charset')) {
  24953. if (cff.charset.predefined) {
  24954. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  24955. output);
  24956. } else {
  24957. var charset = this.compileCharset(cff.charset);
  24958. topDictTracker.setEntryLocation('charset', [output.length], output);
  24959. output.add(charset);
  24960. }
  24961. }
  24962. var charStrings = this.compileCharStrings(cff.charStrings);
  24963. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  24964. output.add(charStrings);
  24965. if (cff.isCIDFont) {
  24966. // For some reason FDSelect must be in front of FDArray on windows. OSX
  24967. // and linux don't seem to care.
  24968. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  24969. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  24970. output.add(fdSelect);
  24971. // It is unclear if the sub font dictionary can have CID related
  24972. // dictionary keys, but the sanitizer doesn't like them so remove them.
  24973. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  24974. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  24975. output.add(compiled.output);
  24976. var fontDictTrackers = compiled.trackers;
  24977. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  24978. }
  24979. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  24980. // If the font data ends with INDEX whose object data is zero-length,
  24981. // the sanitizer will bail out. Add a dummy byte to avoid that.
  24982. output.add([0]);
  24983. return output.data;
  24984. },
  24985. encodeNumber: function CFFCompiler_encodeNumber(value) {
  24986. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  24987. return this.encodeInteger(value);
  24988. } else {
  24989. return this.encodeFloat(value);
  24990. }
  24991. },
  24992. encodeFloat: function CFFCompiler_encodeFloat(num) {
  24993. var value = num.toString();
  24994. // rounding inaccurate doubles
  24995. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  24996. if (m) {
  24997. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  24998. value = (Math.round(num * epsilon) / epsilon).toString();
  24999. }
  25000. var nibbles = '';
  25001. var i, ii;
  25002. for (i = 0, ii = value.length; i < ii; ++i) {
  25003. var a = value[i];
  25004. if (a === 'e') {
  25005. nibbles += value[++i] === '-' ? 'c' : 'b';
  25006. } else if (a === '.') {
  25007. nibbles += 'a';
  25008. } else if (a === '-') {
  25009. nibbles += 'e';
  25010. } else {
  25011. nibbles += a;
  25012. }
  25013. }
  25014. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  25015. var out = [30];
  25016. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  25017. out.push(parseInt(nibbles.substr(i, 2), 16));
  25018. }
  25019. return out;
  25020. },
  25021. encodeInteger: function CFFCompiler_encodeInteger(value) {
  25022. var code;
  25023. if (value >= -107 && value <= 107) {
  25024. code = [value + 139];
  25025. } else if (value >= 108 && value <= 1131) {
  25026. value = [value - 108];
  25027. code = [(value >> 8) + 247, value & 0xFF];
  25028. } else if (value >= -1131 && value <= -108) {
  25029. value = -value - 108;
  25030. code = [(value >> 8) + 251, value & 0xFF];
  25031. } else if (value >= -32768 && value <= 32767) {
  25032. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  25033. } else {
  25034. code = [0x1d,
  25035. (value >> 24) & 0xFF,
  25036. (value >> 16) & 0xFF,
  25037. (value >> 8) & 0xFF,
  25038. value & 0xFF];
  25039. }
  25040. return code;
  25041. },
  25042. compileHeader: function CFFCompiler_compileHeader(header) {
  25043. return [
  25044. header.major,
  25045. header.minor,
  25046. header.hdrSize,
  25047. header.offSize
  25048. ];
  25049. },
  25050. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  25051. var nameIndex = new CFFIndex();
  25052. for (var i = 0, ii = names.length; i < ii; ++i) {
  25053. nameIndex.add(stringToBytes(names[i]));
  25054. }
  25055. return this.compileIndex(nameIndex);
  25056. },
  25057. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  25058. length,
  25059. removeCidKeys) {
  25060. var fontDictTrackers = [];
  25061. var fdArrayIndex = new CFFIndex();
  25062. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25063. var fontDict = dicts[i];
  25064. if (removeCidKeys) {
  25065. fontDict.removeByName('CIDFontVersion');
  25066. fontDict.removeByName('CIDFontRevision');
  25067. fontDict.removeByName('CIDFontType');
  25068. fontDict.removeByName('CIDCount');
  25069. fontDict.removeByName('UIDBase');
  25070. }
  25071. var fontDictTracker = new CFFOffsetTracker();
  25072. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  25073. fontDictTrackers.push(fontDictTracker);
  25074. fdArrayIndex.add(fontDictData);
  25075. fontDictTracker.offset(length);
  25076. }
  25077. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  25078. return {
  25079. trackers: fontDictTrackers,
  25080. output: fdArrayIndex
  25081. };
  25082. },
  25083. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  25084. trackers,
  25085. output) {
  25086. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  25087. var fontDict = dicts[i];
  25088. assert(fontDict.privateDict && fontDict.hasName('Private'),
  25089. 'There must be an private dictionary.');
  25090. var privateDict = fontDict.privateDict;
  25091. var privateDictTracker = new CFFOffsetTracker();
  25092. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  25093. var outputLength = output.length;
  25094. privateDictTracker.offset(outputLength);
  25095. if (!privateDictData.length) {
  25096. // The private dictionary was empty, set the output length to zero to
  25097. // ensure the offset length isn't out of bounds in the eyes of the
  25098. // sanitizer.
  25099. outputLength = 0;
  25100. }
  25101. trackers[i].setEntryLocation('Private',
  25102. [privateDictData.length, outputLength],
  25103. output);
  25104. output.add(privateDictData);
  25105. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  25106. var subrs = this.compileIndex(privateDict.subrsIndex);
  25107. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  25108. output);
  25109. output.add(subrs);
  25110. }
  25111. }
  25112. },
  25113. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  25114. var out = [];
  25115. // The dictionary keys must be in a certain order.
  25116. var order = dict.order;
  25117. for (var i = 0; i < order.length; ++i) {
  25118. var key = order[i];
  25119. if (!(key in dict.values)) {
  25120. continue;
  25121. }
  25122. var values = dict.values[key];
  25123. var types = dict.types[key];
  25124. if (!isArray(types)) {
  25125. types = [types];
  25126. }
  25127. if (!isArray(values)) {
  25128. values = [values];
  25129. }
  25130. // Remove any empty dict values.
  25131. if (values.length === 0) {
  25132. continue;
  25133. }
  25134. for (var j = 0, jj = types.length; j < jj; ++j) {
  25135. var type = types[j];
  25136. var value = values[j];
  25137. switch (type) {
  25138. case 'num':
  25139. case 'sid':
  25140. out = out.concat(this.encodeNumber(value));
  25141. break;
  25142. case 'offset':
  25143. // For offsets we just insert a 32bit integer so we don't have to
  25144. // deal with figuring out the length of the offset when it gets
  25145. // replaced later on by the compiler.
  25146. var name = dict.keyToNameMap[key];
  25147. // Some offsets have the offset and the length, so just record the
  25148. // position of the first one.
  25149. if (!offsetTracker.isTracking(name)) {
  25150. offsetTracker.track(name, out.length);
  25151. }
  25152. out = out.concat([0x1d, 0, 0, 0, 0]);
  25153. break;
  25154. case 'array':
  25155. case 'delta':
  25156. out = out.concat(this.encodeNumber(value));
  25157. for (var k = 1, kk = values.length; k < kk; ++k) {
  25158. out = out.concat(this.encodeNumber(values[k]));
  25159. }
  25160. break;
  25161. default:
  25162. error('Unknown data type of ' + type);
  25163. break;
  25164. }
  25165. }
  25166. out = out.concat(dict.opcodes[key]);
  25167. }
  25168. return out;
  25169. },
  25170. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  25171. var stringIndex = new CFFIndex();
  25172. for (var i = 0, ii = strings.length; i < ii; ++i) {
  25173. stringIndex.add(stringToBytes(strings[i]));
  25174. }
  25175. return this.compileIndex(stringIndex);
  25176. },
  25177. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  25178. var globalSubrIndex = this.cff.globalSubrIndex;
  25179. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  25180. },
  25181. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  25182. return this.compileIndex(charStrings);
  25183. },
  25184. compileCharset: function CFFCompiler_compileCharset(charset) {
  25185. return this.compileTypedArray(charset.raw);
  25186. },
  25187. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  25188. return this.compileTypedArray(encoding.raw);
  25189. },
  25190. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  25191. return this.compileTypedArray(fdSelect);
  25192. },
  25193. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  25194. var out = [];
  25195. for (var i = 0, ii = data.length; i < ii; ++i) {
  25196. out[i] = data[i];
  25197. }
  25198. return out;
  25199. },
  25200. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  25201. trackers = trackers || [];
  25202. var objects = index.objects;
  25203. // First 2 bytes contains the number of objects contained into this index
  25204. var count = objects.length;
  25205. // If there is no object, just create an index. This technically
  25206. // should just be [0, 0] but OTS has an issue with that.
  25207. if (count === 0) {
  25208. return [0, 0, 0];
  25209. }
  25210. var data = [(count >> 8) & 0xFF, count & 0xff];
  25211. var lastOffset = 1, i;
  25212. for (i = 0; i < count; ++i) {
  25213. lastOffset += objects[i].length;
  25214. }
  25215. var offsetSize;
  25216. if (lastOffset < 0x100) {
  25217. offsetSize = 1;
  25218. } else if (lastOffset < 0x10000) {
  25219. offsetSize = 2;
  25220. } else if (lastOffset < 0x1000000) {
  25221. offsetSize = 3;
  25222. } else {
  25223. offsetSize = 4;
  25224. }
  25225. // Next byte contains the offset size use to reference object in the file
  25226. data.push(offsetSize);
  25227. // Add another offset after this one because we need a new offset
  25228. var relativeOffset = 1;
  25229. for (i = 0; i < count + 1; i++) {
  25230. if (offsetSize === 1) {
  25231. data.push(relativeOffset & 0xFF);
  25232. } else if (offsetSize === 2) {
  25233. data.push((relativeOffset >> 8) & 0xFF,
  25234. relativeOffset & 0xFF);
  25235. } else if (offsetSize === 3) {
  25236. data.push((relativeOffset >> 16) & 0xFF,
  25237. (relativeOffset >> 8) & 0xFF,
  25238. relativeOffset & 0xFF);
  25239. } else {
  25240. data.push((relativeOffset >>> 24) & 0xFF,
  25241. (relativeOffset >> 16) & 0xFF,
  25242. (relativeOffset >> 8) & 0xFF,
  25243. relativeOffset & 0xFF);
  25244. }
  25245. if (objects[i]) {
  25246. relativeOffset += objects[i].length;
  25247. }
  25248. }
  25249. for (i = 0; i < count; i++) {
  25250. // Notify the tracker where the object will be offset in the data.
  25251. if (trackers[i]) {
  25252. trackers[i].offset(data.length);
  25253. }
  25254. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  25255. data.push(objects[i][j]);
  25256. }
  25257. }
  25258. return data;
  25259. }
  25260. };
  25261. return CFFCompiler;
  25262. })();
  25263. // Workaround for seac on Windows.
  25264. (function checkSeacSupport() {
  25265. if (/Windows/.test(navigator.userAgent)) {
  25266. SEAC_ANALYSIS_ENABLED = true;
  25267. }
  25268. })();
  25269. // Workaround for Private Use Area characters in Chrome on Windows
  25270. // http://code.google.com/p/chromium/issues/detail?id=122465
  25271. // https://github.com/mozilla/pdf.js/issues/1689
  25272. (function checkChromeWindows() {
  25273. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  25274. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  25275. }
  25276. })();
  25277. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25278. function getLong(data, offset) {
  25279. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25280. (data[offset + 2] << 8) | data[offset + 3];
  25281. }
  25282. function getUshort(data, offset) {
  25283. return (data[offset] << 8) | data[offset + 1];
  25284. }
  25285. function parseCmap(data, start, end) {
  25286. var offset = (getUshort(data, start + 2) === 1 ?
  25287. getLong(data, start + 8) : getLong(data, start + 16));
  25288. var format = getUshort(data, start + offset);
  25289. var length, ranges, p, i;
  25290. if (format === 4) {
  25291. length = getUshort(data, start + offset + 2);
  25292. var segCount = getUshort(data, start + offset + 6) >> 1;
  25293. p = start + offset + 14;
  25294. ranges = [];
  25295. for (i = 0; i < segCount; i++, p += 2) {
  25296. ranges[i] = {end: getUshort(data, p)};
  25297. }
  25298. p += 2;
  25299. for (i = 0; i < segCount; i++, p += 2) {
  25300. ranges[i].start = getUshort(data, p);
  25301. }
  25302. for (i = 0; i < segCount; i++, p += 2) {
  25303. ranges[i].idDelta = getUshort(data, p);
  25304. }
  25305. for (i = 0; i < segCount; i++, p += 2) {
  25306. var idOffset = getUshort(data, p);
  25307. if (idOffset === 0) {
  25308. continue;
  25309. }
  25310. ranges[i].ids = [];
  25311. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25312. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25313. idOffset += 2;
  25314. }
  25315. }
  25316. return ranges;
  25317. } else if (format === 12) {
  25318. length = getLong(data, start + offset + 4);
  25319. var groups = getLong(data, start + offset + 12);
  25320. p = start + offset + 16;
  25321. ranges = [];
  25322. for (i = 0; i < groups; i++) {
  25323. ranges.push({
  25324. start: getLong(data, p),
  25325. end: getLong(data, p + 4),
  25326. idDelta: getLong(data, p + 8) - getLong(data, p)
  25327. });
  25328. p += 12;
  25329. }
  25330. return ranges;
  25331. }
  25332. error('not supported cmap: ' + format);
  25333. }
  25334. function parseCff(data, start, end) {
  25335. var properties = {};
  25336. var parser = new CFFParser(new Stream(data, start, end - start),
  25337. properties);
  25338. var cff = parser.parse();
  25339. return {
  25340. glyphs: cff.charStrings.objects,
  25341. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25342. cff.topDict.privateDict.subrsIndex.objects),
  25343. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25344. };
  25345. }
  25346. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25347. var itemSize, itemDecode;
  25348. if (isGlyphLocationsLong) {
  25349. itemSize = 4;
  25350. itemDecode = function fontItemDecodeLong(data, offset) {
  25351. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25352. (data[offset + 2] << 8) | data[offset + 3];
  25353. };
  25354. } else {
  25355. itemSize = 2;
  25356. itemDecode = function fontItemDecode(data, offset) {
  25357. return (data[offset] << 9) | (data[offset + 1] << 1);
  25358. };
  25359. }
  25360. var glyphs = [];
  25361. var startOffset = itemDecode(loca, 0);
  25362. for (var j = itemSize; j < loca.length; j += itemSize) {
  25363. var endOffset = itemDecode(loca, j);
  25364. glyphs.push(glyf.subarray(startOffset, endOffset));
  25365. startOffset = endOffset;
  25366. }
  25367. return glyphs;
  25368. }
  25369. function lookupCmap(ranges, unicode) {
  25370. var code = unicode.charCodeAt(0);
  25371. var l = 0, r = ranges.length - 1;
  25372. while (l < r) {
  25373. var c = (l + r + 1) >> 1;
  25374. if (code < ranges[c].start) {
  25375. r = c - 1;
  25376. } else {
  25377. l = c;
  25378. }
  25379. }
  25380. if (ranges[l].start <= code && code <= ranges[l].end) {
  25381. return (ranges[l].idDelta + (ranges[l].ids ?
  25382. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25383. }
  25384. return 0;
  25385. }
  25386. function compileGlyf(code, js, font) {
  25387. function moveTo(x, y) {
  25388. js.push('c.moveTo(' + x + ',' + y + ');');
  25389. }
  25390. function lineTo(x, y) {
  25391. js.push('c.lineTo(' + x + ',' + y + ');');
  25392. }
  25393. function quadraticCurveTo(xa, ya, x, y) {
  25394. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  25395. x + ',' + y + ');');
  25396. }
  25397. var i = 0;
  25398. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25399. var flags;
  25400. var x = 0, y = 0;
  25401. i += 10;
  25402. if (numberOfContours < 0) {
  25403. // composite glyph
  25404. do {
  25405. flags = (code[i] << 8) | code[i + 1];
  25406. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25407. i += 4;
  25408. var arg1, arg2;
  25409. if ((flags & 0x01)) {
  25410. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25411. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25412. i += 4;
  25413. } else {
  25414. arg1 = code[i++]; arg2 = code[i++];
  25415. }
  25416. if ((flags & 0x02)) {
  25417. x = arg1;
  25418. y = arg2;
  25419. } else {
  25420. x = 0; y = 0; // TODO "they are points" ?
  25421. }
  25422. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25423. if ((flags & 0x08)) {
  25424. scaleX =
  25425. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25426. i += 2;
  25427. } else if ((flags & 0x40)) {
  25428. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25429. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25430. i += 4;
  25431. } else if ((flags & 0x80)) {
  25432. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25433. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25434. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25435. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25436. i += 8;
  25437. }
  25438. var subglyph = font.glyphs[glyphIndex];
  25439. if (subglyph) {
  25440. js.push('c.save();');
  25441. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  25442. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  25443. compileGlyf(subglyph, js, font);
  25444. js.push('c.restore();');
  25445. }
  25446. } while ((flags & 0x20));
  25447. } else {
  25448. // simple glyph
  25449. var endPtsOfContours = [];
  25450. var j, jj;
  25451. for (j = 0; j < numberOfContours; j++) {
  25452. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25453. i += 2;
  25454. }
  25455. var instructionLength = (code[i] << 8) | code[i + 1];
  25456. i += 2 + instructionLength; // skipping the instructions
  25457. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25458. var points = [];
  25459. while (points.length < numberOfPoints) {
  25460. flags = code[i++];
  25461. var repeat = 1;
  25462. if ((flags & 0x08)) {
  25463. repeat += code[i++];
  25464. }
  25465. while (repeat-- > 0) {
  25466. points.push({flags: flags});
  25467. }
  25468. }
  25469. for (j = 0; j < numberOfPoints; j++) {
  25470. switch (points[j].flags & 0x12) {
  25471. case 0x00:
  25472. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25473. i += 2;
  25474. break;
  25475. case 0x02:
  25476. x -= code[i++];
  25477. break;
  25478. case 0x12:
  25479. x += code[i++];
  25480. break;
  25481. }
  25482. points[j].x = x;
  25483. }
  25484. for (j = 0; j < numberOfPoints; j++) {
  25485. switch (points[j].flags & 0x24) {
  25486. case 0x00:
  25487. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25488. i += 2;
  25489. break;
  25490. case 0x04:
  25491. y -= code[i++];
  25492. break;
  25493. case 0x24:
  25494. y += code[i++];
  25495. break;
  25496. }
  25497. points[j].y = y;
  25498. }
  25499. var startPoint = 0;
  25500. for (i = 0; i < numberOfContours; i++) {
  25501. var endPoint = endPtsOfContours[i];
  25502. // contours might have implicit points, which is located in the middle
  25503. // between two neighboring off-curve points
  25504. var contour = points.slice(startPoint, endPoint + 1);
  25505. if ((contour[0].flags & 1)) {
  25506. contour.push(contour[0]); // using start point at the contour end
  25507. } else if ((contour[contour.length - 1].flags & 1)) {
  25508. // first is off-curve point, trying to use one from the end
  25509. contour.unshift(contour[contour.length - 1]);
  25510. } else {
  25511. // start and end are off-curve points, creating implicit one
  25512. var p = {
  25513. flags: 1,
  25514. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25515. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25516. };
  25517. contour.unshift(p);
  25518. contour.push(p);
  25519. }
  25520. moveTo(contour[0].x, contour[0].y);
  25521. for (j = 1, jj = contour.length; j < jj; j++) {
  25522. if ((contour[j].flags & 1)) {
  25523. lineTo(contour[j].x, contour[j].y);
  25524. } else if ((contour[j + 1].flags & 1)){
  25525. quadraticCurveTo(contour[j].x, contour[j].y,
  25526. contour[j + 1].x, contour[j + 1].y);
  25527. j++;
  25528. } else {
  25529. quadraticCurveTo(contour[j].x, contour[j].y,
  25530. (contour[j].x + contour[j + 1].x) / 2,
  25531. (contour[j].y + contour[j + 1].y) / 2);
  25532. }
  25533. }
  25534. startPoint = endPoint + 1;
  25535. }
  25536. }
  25537. }
  25538. function compileCharString(code, js, font) {
  25539. var stack = [];
  25540. var x = 0, y = 0;
  25541. var stems = 0;
  25542. function moveTo(x, y) {
  25543. js.push('c.moveTo(' + x + ',' + y + ');');
  25544. }
  25545. function lineTo(x, y) {
  25546. js.push('c.lineTo(' + x + ',' + y + ');');
  25547. }
  25548. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25549. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  25550. x + ',' + y + ');');
  25551. }
  25552. function parse(code) {
  25553. var i = 0;
  25554. while (i < code.length) {
  25555. var stackClean = false;
  25556. var v = code[i++];
  25557. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25558. switch (v) {
  25559. case 1: // hstem
  25560. stems += stack.length >> 1;
  25561. stackClean = true;
  25562. break;
  25563. case 3: // vstem
  25564. stems += stack.length >> 1;
  25565. stackClean = true;
  25566. break;
  25567. case 4: // vmoveto
  25568. y += stack.pop();
  25569. moveTo(x, y);
  25570. stackClean = true;
  25571. break;
  25572. case 5: // rlineto
  25573. while (stack.length > 0) {
  25574. x += stack.shift();
  25575. y += stack.shift();
  25576. lineTo(x, y);
  25577. }
  25578. break;
  25579. case 6: // hlineto
  25580. while (stack.length > 0) {
  25581. x += stack.shift();
  25582. lineTo(x, y);
  25583. if (stack.length === 0) {
  25584. break;
  25585. }
  25586. y += stack.shift();
  25587. lineTo(x, y);
  25588. }
  25589. break;
  25590. case 7: // vlineto
  25591. while (stack.length > 0) {
  25592. y += stack.shift();
  25593. lineTo(x, y);
  25594. if (stack.length === 0) {
  25595. break;
  25596. }
  25597. x += stack.shift();
  25598. lineTo(x, y);
  25599. }
  25600. break;
  25601. case 8: // rrcurveto
  25602. while (stack.length > 0) {
  25603. xa = x + stack.shift(); ya = y + stack.shift();
  25604. xb = xa + stack.shift(); yb = ya + stack.shift();
  25605. x = xb + stack.shift(); y = yb + stack.shift();
  25606. bezierCurveTo(xa, ya, xb, yb, x, y);
  25607. }
  25608. break;
  25609. case 10: // callsubr
  25610. n = stack.pop() + font.subrsBias;
  25611. subrCode = font.subrs[n];
  25612. if (subrCode) {
  25613. parse(subrCode);
  25614. }
  25615. break;
  25616. case 11: // return
  25617. return;
  25618. case 12:
  25619. v = code[i++];
  25620. switch (v) {
  25621. case 34: // flex
  25622. xa = x + stack.shift();
  25623. xb = xa + stack.shift(); y1 = y + stack.shift();
  25624. x = xb + stack.shift();
  25625. bezierCurveTo(xa, y, xb, y1, x, y1);
  25626. xa = x + stack.shift();
  25627. xb = xa + stack.shift();
  25628. x = xb + stack.shift();
  25629. bezierCurveTo(xa, y1, xb, y, x, y);
  25630. break;
  25631. case 35: // flex
  25632. xa = x + stack.shift(); ya = y + stack.shift();
  25633. xb = xa + stack.shift(); yb = ya + stack.shift();
  25634. x = xb + stack.shift(); y = yb + stack.shift();
  25635. bezierCurveTo(xa, ya, xb, yb, x, y);
  25636. xa = x + stack.shift(); ya = y + stack.shift();
  25637. xb = xa + stack.shift(); yb = ya + stack.shift();
  25638. x = xb + stack.shift(); y = yb + stack.shift();
  25639. bezierCurveTo(xa, ya, xb, yb, x, y);
  25640. stack.pop(); // fd
  25641. break;
  25642. case 36: // hflex1
  25643. xa = x + stack.shift(); y1 = y + stack.shift();
  25644. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25645. x = xb + stack.shift();
  25646. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25647. xa = x + stack.shift();
  25648. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25649. x = xb + stack.shift();
  25650. bezierCurveTo(xa, y2, xb, y3, x, y);
  25651. break;
  25652. case 37: // flex1
  25653. var x0 = x, y0 = y;
  25654. xa = x + stack.shift(); ya = y + stack.shift();
  25655. xb = xa + stack.shift(); yb = ya + stack.shift();
  25656. x = xb + stack.shift(); y = yb + stack.shift();
  25657. bezierCurveTo(xa, ya, xb, yb, x, y);
  25658. xa = x + stack.shift(); ya = y + stack.shift();
  25659. xb = xa + stack.shift(); yb = ya + stack.shift();
  25660. x = xb; y = yb;
  25661. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25662. x += stack.shift();
  25663. } else {
  25664. y += stack.shift();
  25665. }
  25666. bezierCurveTo(xa, ya, xb, yb, x, y);
  25667. break;
  25668. default:
  25669. error('unknown operator: 12 ' + v);
  25670. }
  25671. break;
  25672. case 14: // endchar
  25673. if (stack.length >= 4) {
  25674. var achar = stack.pop();
  25675. var bchar = stack.pop();
  25676. y = stack.pop();
  25677. x = stack.pop();
  25678. js.push('c.save();');
  25679. js.push('c.translate('+ x + ',' + y + ');');
  25680. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25681. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  25682. compileCharString(font.glyphs[gid], js, font);
  25683. js.push('c.restore();');
  25684. gid = lookupCmap(font.cmap, String.fromCharCode(
  25685. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  25686. compileCharString(font.glyphs[gid], js, font);
  25687. }
  25688. return;
  25689. case 18: // hstemhm
  25690. stems += stack.length >> 1;
  25691. stackClean = true;
  25692. break;
  25693. case 19: // hintmask
  25694. stems += stack.length >> 1;
  25695. i += (stems + 7) >> 3;
  25696. stackClean = true;
  25697. break;
  25698. case 20: // cntrmask
  25699. stems += stack.length >> 1;
  25700. i += (stems + 7) >> 3;
  25701. stackClean = true;
  25702. break;
  25703. case 21: // rmoveto
  25704. y += stack.pop();
  25705. x += stack.pop();
  25706. moveTo(x, y);
  25707. stackClean = true;
  25708. break;
  25709. case 22: // hmoveto
  25710. x += stack.pop();
  25711. moveTo(x, y);
  25712. stackClean = true;
  25713. break;
  25714. case 23: // vstemhm
  25715. stems += stack.length >> 1;
  25716. stackClean = true;
  25717. break;
  25718. case 24: // rcurveline
  25719. while (stack.length > 2) {
  25720. xa = x + stack.shift(); ya = y + stack.shift();
  25721. xb = xa + stack.shift(); yb = ya + stack.shift();
  25722. x = xb + stack.shift(); y = yb + stack.shift();
  25723. bezierCurveTo(xa, ya, xb, yb, x, y);
  25724. }
  25725. x += stack.shift();
  25726. y += stack.shift();
  25727. lineTo(x, y);
  25728. break;
  25729. case 25: // rlinecurve
  25730. while (stack.length > 6) {
  25731. x += stack.shift();
  25732. y += stack.shift();
  25733. lineTo(x, y);
  25734. }
  25735. xa = x + stack.shift(); ya = y + stack.shift();
  25736. xb = xa + stack.shift(); yb = ya + stack.shift();
  25737. x = xb + stack.shift(); y = yb + stack.shift();
  25738. bezierCurveTo(xa, ya, xb, yb, x, y);
  25739. break;
  25740. case 26: // vvcurveto
  25741. if (stack.length % 2) {
  25742. x += stack.shift();
  25743. }
  25744. while (stack.length > 0) {
  25745. xa = x; ya = y + stack.shift();
  25746. xb = xa + stack.shift(); yb = ya + stack.shift();
  25747. x = xb; y = yb + stack.shift();
  25748. bezierCurveTo(xa, ya, xb, yb, x, y);
  25749. }
  25750. break;
  25751. case 27: // hhcurveto
  25752. if (stack.length % 2) {
  25753. y += stack.shift();
  25754. }
  25755. while (stack.length > 0) {
  25756. xa = x + stack.shift(); ya = y;
  25757. xb = xa + stack.shift(); yb = ya + stack.shift();
  25758. x = xb + stack.shift(); y = yb;
  25759. bezierCurveTo(xa, ya, xb, yb, x, y);
  25760. }
  25761. break;
  25762. case 28:
  25763. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25764. i += 2;
  25765. break;
  25766. case 29: // callgsubr
  25767. n = stack.pop() + font.gsubrsBias;
  25768. subrCode = font.gsubrs[n];
  25769. if (subrCode) {
  25770. parse(subrCode);
  25771. }
  25772. break;
  25773. case 30: // vhcurveto
  25774. while (stack.length > 0) {
  25775. xa = x; ya = y + stack.shift();
  25776. xb = xa + stack.shift(); yb = ya + stack.shift();
  25777. x = xb + stack.shift();
  25778. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25779. bezierCurveTo(xa, ya, xb, yb, x, y);
  25780. if (stack.length === 0) {
  25781. break;
  25782. }
  25783. xa = x + stack.shift(); ya = y;
  25784. xb = xa + stack.shift(); yb = ya + stack.shift();
  25785. y = yb + stack.shift();
  25786. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25787. bezierCurveTo(xa, ya, xb, yb, x, y);
  25788. }
  25789. break;
  25790. case 31: // hvcurveto
  25791. while (stack.length > 0) {
  25792. xa = x + stack.shift(); ya = y;
  25793. xb = xa + stack.shift(); yb = ya + stack.shift();
  25794. y = yb + stack.shift();
  25795. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25796. bezierCurveTo(xa, ya, xb, yb, x, y);
  25797. if (stack.length === 0) {
  25798. break;
  25799. }
  25800. xa = x; ya = y + stack.shift();
  25801. xb = xa + stack.shift(); yb = ya + stack.shift();
  25802. x = xb + stack.shift();
  25803. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25804. bezierCurveTo(xa, ya, xb, yb, x, y);
  25805. }
  25806. break;
  25807. default:
  25808. if (v < 32) {
  25809. error('unknown operator: ' + v);
  25810. }
  25811. if (v < 247) {
  25812. stack.push(v - 139);
  25813. } else if (v < 251) {
  25814. stack.push((v - 247) * 256 + code[i++] + 108);
  25815. } else if (v < 255) {
  25816. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25817. } else {
  25818. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25819. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25820. i += 4;
  25821. }
  25822. break;
  25823. }
  25824. if (stackClean) {
  25825. stack.length = 0;
  25826. }
  25827. }
  25828. }
  25829. parse(code);
  25830. }
  25831. var noop = '';
  25832. function CompiledFont(fontMatrix) {
  25833. this.compiledGlyphs = {};
  25834. this.fontMatrix = fontMatrix;
  25835. }
  25836. CompiledFont.prototype = {
  25837. getPathJs: function (unicode) {
  25838. var gid = lookupCmap(this.cmap, unicode);
  25839. var fn = this.compiledGlyphs[gid];
  25840. if (!fn) {
  25841. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25842. }
  25843. return fn;
  25844. },
  25845. compileGlyph: function (code) {
  25846. if (!code || code.length === 0 || code[0] === 14) {
  25847. return noop;
  25848. }
  25849. var js = [];
  25850. js.push('c.save();');
  25851. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  25852. js.push('c.scale(size, -size);');
  25853. this.compileGlyphImpl(code, js);
  25854. js.push('c.restore();');
  25855. return js.join('\n');
  25856. },
  25857. compileGlyphImpl: function () {
  25858. error('Children classes should implement this.');
  25859. },
  25860. hasBuiltPath: function (unicode) {
  25861. var gid = lookupCmap(this.cmap, unicode);
  25862. return gid in this.compiledGlyphs;
  25863. }
  25864. };
  25865. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25866. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25867. CompiledFont.call(this, fontMatrix);
  25868. this.glyphs = glyphs;
  25869. this.cmap = cmap;
  25870. this.compiledGlyphs = [];
  25871. }
  25872. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25873. compileGlyphImpl: function (code, js) {
  25874. compileGlyf(code, js, this);
  25875. }
  25876. });
  25877. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25878. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25879. CompiledFont.call(this, fontMatrix);
  25880. this.glyphs = cffInfo.glyphs;
  25881. this.gsubrs = cffInfo.gsubrs || [];
  25882. this.subrs = cffInfo.subrs || [];
  25883. this.cmap = cmap;
  25884. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  25885. this.compiledGlyphs = [];
  25886. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25887. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25888. this.subrsBias = (this.subrs.length < 1240 ?
  25889. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25890. }
  25891. Util.inherit(Type2Compiled, CompiledFont, {
  25892. compileGlyphImpl: function (code, js) {
  25893. compileCharString(code, js, this);
  25894. }
  25895. });
  25896. return {
  25897. create: function FontRendererFactory_create(font) {
  25898. var data = new Uint8Array(font.data);
  25899. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25900. var numTables = getUshort(data, 4);
  25901. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25902. var tag = bytesToString(data.subarray(p, p + 4));
  25903. var offset = getLong(data, p + 8);
  25904. var length = getLong(data, p + 12);
  25905. switch (tag) {
  25906. case 'cmap':
  25907. cmap = parseCmap(data, offset, offset + length);
  25908. break;
  25909. case 'glyf':
  25910. glyf = data.subarray(offset, offset + length);
  25911. break;
  25912. case 'loca':
  25913. loca = data.subarray(offset, offset + length);
  25914. break;
  25915. case 'head':
  25916. unitsPerEm = getUshort(data, offset + 18);
  25917. indexToLocFormat = getUshort(data, offset + 50);
  25918. break;
  25919. case 'CFF ':
  25920. cff = parseCff(data, offset, offset + length);
  25921. break;
  25922. }
  25923. }
  25924. if (glyf) {
  25925. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25926. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25927. return new TrueTypeCompiled(
  25928. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25929. } else {
  25930. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25931. }
  25932. }
  25933. };
  25934. })();
  25935. var GlyphsUnicode = {
  25936. A: 0x0041,
  25937. AE: 0x00C6,
  25938. AEacute: 0x01FC,
  25939. AEmacron: 0x01E2,
  25940. AEsmall: 0xF7E6,
  25941. Aacute: 0x00C1,
  25942. Aacutesmall: 0xF7E1,
  25943. Abreve: 0x0102,
  25944. Abreveacute: 0x1EAE,
  25945. Abrevecyrillic: 0x04D0,
  25946. Abrevedotbelow: 0x1EB6,
  25947. Abrevegrave: 0x1EB0,
  25948. Abrevehookabove: 0x1EB2,
  25949. Abrevetilde: 0x1EB4,
  25950. Acaron: 0x01CD,
  25951. Acircle: 0x24B6,
  25952. Acircumflex: 0x00C2,
  25953. Acircumflexacute: 0x1EA4,
  25954. Acircumflexdotbelow: 0x1EAC,
  25955. Acircumflexgrave: 0x1EA6,
  25956. Acircumflexhookabove: 0x1EA8,
  25957. Acircumflexsmall: 0xF7E2,
  25958. Acircumflextilde: 0x1EAA,
  25959. Acute: 0xF6C9,
  25960. Acutesmall: 0xF7B4,
  25961. Acyrillic: 0x0410,
  25962. Adblgrave: 0x0200,
  25963. Adieresis: 0x00C4,
  25964. Adieresiscyrillic: 0x04D2,
  25965. Adieresismacron: 0x01DE,
  25966. Adieresissmall: 0xF7E4,
  25967. Adotbelow: 0x1EA0,
  25968. Adotmacron: 0x01E0,
  25969. Agrave: 0x00C0,
  25970. Agravesmall: 0xF7E0,
  25971. Ahookabove: 0x1EA2,
  25972. Aiecyrillic: 0x04D4,
  25973. Ainvertedbreve: 0x0202,
  25974. Alpha: 0x0391,
  25975. Alphatonos: 0x0386,
  25976. Amacron: 0x0100,
  25977. Amonospace: 0xFF21,
  25978. Aogonek: 0x0104,
  25979. Aring: 0x00C5,
  25980. Aringacute: 0x01FA,
  25981. Aringbelow: 0x1E00,
  25982. Aringsmall: 0xF7E5,
  25983. Asmall: 0xF761,
  25984. Atilde: 0x00C3,
  25985. Atildesmall: 0xF7E3,
  25986. Aybarmenian: 0x0531,
  25987. B: 0x0042,
  25988. Bcircle: 0x24B7,
  25989. Bdotaccent: 0x1E02,
  25990. Bdotbelow: 0x1E04,
  25991. Becyrillic: 0x0411,
  25992. Benarmenian: 0x0532,
  25993. Beta: 0x0392,
  25994. Bhook: 0x0181,
  25995. Blinebelow: 0x1E06,
  25996. Bmonospace: 0xFF22,
  25997. Brevesmall: 0xF6F4,
  25998. Bsmall: 0xF762,
  25999. Btopbar: 0x0182,
  26000. C: 0x0043,
  26001. Caarmenian: 0x053E,
  26002. Cacute: 0x0106,
  26003. Caron: 0xF6CA,
  26004. Caronsmall: 0xF6F5,
  26005. Ccaron: 0x010C,
  26006. Ccedilla: 0x00C7,
  26007. Ccedillaacute: 0x1E08,
  26008. Ccedillasmall: 0xF7E7,
  26009. Ccircle: 0x24B8,
  26010. Ccircumflex: 0x0108,
  26011. Cdot: 0x010A,
  26012. Cdotaccent: 0x010A,
  26013. Cedillasmall: 0xF7B8,
  26014. Chaarmenian: 0x0549,
  26015. Cheabkhasiancyrillic: 0x04BC,
  26016. Checyrillic: 0x0427,
  26017. Chedescenderabkhasiancyrillic: 0x04BE,
  26018. Chedescendercyrillic: 0x04B6,
  26019. Chedieresiscyrillic: 0x04F4,
  26020. Cheharmenian: 0x0543,
  26021. Chekhakassiancyrillic: 0x04CB,
  26022. Cheverticalstrokecyrillic: 0x04B8,
  26023. Chi: 0x03A7,
  26024. Chook: 0x0187,
  26025. Circumflexsmall: 0xF6F6,
  26026. Cmonospace: 0xFF23,
  26027. Coarmenian: 0x0551,
  26028. Csmall: 0xF763,
  26029. D: 0x0044,
  26030. DZ: 0x01F1,
  26031. DZcaron: 0x01C4,
  26032. Daarmenian: 0x0534,
  26033. Dafrican: 0x0189,
  26034. Dcaron: 0x010E,
  26035. Dcedilla: 0x1E10,
  26036. Dcircle: 0x24B9,
  26037. Dcircumflexbelow: 0x1E12,
  26038. Dcroat: 0x0110,
  26039. Ddotaccent: 0x1E0A,
  26040. Ddotbelow: 0x1E0C,
  26041. Decyrillic: 0x0414,
  26042. Deicoptic: 0x03EE,
  26043. Delta: 0x2206,
  26044. Deltagreek: 0x0394,
  26045. Dhook: 0x018A,
  26046. Dieresis: 0xF6CB,
  26047. DieresisAcute: 0xF6CC,
  26048. DieresisGrave: 0xF6CD,
  26049. Dieresissmall: 0xF7A8,
  26050. Digammagreek: 0x03DC,
  26051. Djecyrillic: 0x0402,
  26052. Dlinebelow: 0x1E0E,
  26053. Dmonospace: 0xFF24,
  26054. Dotaccentsmall: 0xF6F7,
  26055. Dslash: 0x0110,
  26056. Dsmall: 0xF764,
  26057. Dtopbar: 0x018B,
  26058. Dz: 0x01F2,
  26059. Dzcaron: 0x01C5,
  26060. Dzeabkhasiancyrillic: 0x04E0,
  26061. Dzecyrillic: 0x0405,
  26062. Dzhecyrillic: 0x040F,
  26063. E: 0x0045,
  26064. Eacute: 0x00C9,
  26065. Eacutesmall: 0xF7E9,
  26066. Ebreve: 0x0114,
  26067. Ecaron: 0x011A,
  26068. Ecedillabreve: 0x1E1C,
  26069. Echarmenian: 0x0535,
  26070. Ecircle: 0x24BA,
  26071. Ecircumflex: 0x00CA,
  26072. Ecircumflexacute: 0x1EBE,
  26073. Ecircumflexbelow: 0x1E18,
  26074. Ecircumflexdotbelow: 0x1EC6,
  26075. Ecircumflexgrave: 0x1EC0,
  26076. Ecircumflexhookabove: 0x1EC2,
  26077. Ecircumflexsmall: 0xF7EA,
  26078. Ecircumflextilde: 0x1EC4,
  26079. Ecyrillic: 0x0404,
  26080. Edblgrave: 0x0204,
  26081. Edieresis: 0x00CB,
  26082. Edieresissmall: 0xF7EB,
  26083. Edot: 0x0116,
  26084. Edotaccent: 0x0116,
  26085. Edotbelow: 0x1EB8,
  26086. Efcyrillic: 0x0424,
  26087. Egrave: 0x00C8,
  26088. Egravesmall: 0xF7E8,
  26089. Eharmenian: 0x0537,
  26090. Ehookabove: 0x1EBA,
  26091. Eightroman: 0x2167,
  26092. Einvertedbreve: 0x0206,
  26093. Eiotifiedcyrillic: 0x0464,
  26094. Elcyrillic: 0x041B,
  26095. Elevenroman: 0x216A,
  26096. Emacron: 0x0112,
  26097. Emacronacute: 0x1E16,
  26098. Emacrongrave: 0x1E14,
  26099. Emcyrillic: 0x041C,
  26100. Emonospace: 0xFF25,
  26101. Encyrillic: 0x041D,
  26102. Endescendercyrillic: 0x04A2,
  26103. Eng: 0x014A,
  26104. Enghecyrillic: 0x04A4,
  26105. Enhookcyrillic: 0x04C7,
  26106. Eogonek: 0x0118,
  26107. Eopen: 0x0190,
  26108. Epsilon: 0x0395,
  26109. Epsilontonos: 0x0388,
  26110. Ercyrillic: 0x0420,
  26111. Ereversed: 0x018E,
  26112. Ereversedcyrillic: 0x042D,
  26113. Escyrillic: 0x0421,
  26114. Esdescendercyrillic: 0x04AA,
  26115. Esh: 0x01A9,
  26116. Esmall: 0xF765,
  26117. Eta: 0x0397,
  26118. Etarmenian: 0x0538,
  26119. Etatonos: 0x0389,
  26120. Eth: 0x00D0,
  26121. Ethsmall: 0xF7F0,
  26122. Etilde: 0x1EBC,
  26123. Etildebelow: 0x1E1A,
  26124. Euro: 0x20AC,
  26125. Ezh: 0x01B7,
  26126. Ezhcaron: 0x01EE,
  26127. Ezhreversed: 0x01B8,
  26128. F: 0x0046,
  26129. Fcircle: 0x24BB,
  26130. Fdotaccent: 0x1E1E,
  26131. Feharmenian: 0x0556,
  26132. Feicoptic: 0x03E4,
  26133. Fhook: 0x0191,
  26134. Fitacyrillic: 0x0472,
  26135. Fiveroman: 0x2164,
  26136. Fmonospace: 0xFF26,
  26137. Fourroman: 0x2163,
  26138. Fsmall: 0xF766,
  26139. G: 0x0047,
  26140. GBsquare: 0x3387,
  26141. Gacute: 0x01F4,
  26142. Gamma: 0x0393,
  26143. Gammaafrican: 0x0194,
  26144. Gangiacoptic: 0x03EA,
  26145. Gbreve: 0x011E,
  26146. Gcaron: 0x01E6,
  26147. Gcedilla: 0x0122,
  26148. Gcircle: 0x24BC,
  26149. Gcircumflex: 0x011C,
  26150. Gcommaaccent: 0x0122,
  26151. Gdot: 0x0120,
  26152. Gdotaccent: 0x0120,
  26153. Gecyrillic: 0x0413,
  26154. Ghadarmenian: 0x0542,
  26155. Ghemiddlehookcyrillic: 0x0494,
  26156. Ghestrokecyrillic: 0x0492,
  26157. Gheupturncyrillic: 0x0490,
  26158. Ghook: 0x0193,
  26159. Gimarmenian: 0x0533,
  26160. Gjecyrillic: 0x0403,
  26161. Gmacron: 0x1E20,
  26162. Gmonospace: 0xFF27,
  26163. Grave: 0xF6CE,
  26164. Gravesmall: 0xF760,
  26165. Gsmall: 0xF767,
  26166. Gsmallhook: 0x029B,
  26167. Gstroke: 0x01E4,
  26168. H: 0x0048,
  26169. H18533: 0x25CF,
  26170. H18543: 0x25AA,
  26171. H18551: 0x25AB,
  26172. H22073: 0x25A1,
  26173. HPsquare: 0x33CB,
  26174. Haabkhasiancyrillic: 0x04A8,
  26175. Hadescendercyrillic: 0x04B2,
  26176. Hardsigncyrillic: 0x042A,
  26177. Hbar: 0x0126,
  26178. Hbrevebelow: 0x1E2A,
  26179. Hcedilla: 0x1E28,
  26180. Hcircle: 0x24BD,
  26181. Hcircumflex: 0x0124,
  26182. Hdieresis: 0x1E26,
  26183. Hdotaccent: 0x1E22,
  26184. Hdotbelow: 0x1E24,
  26185. Hmonospace: 0xFF28,
  26186. Hoarmenian: 0x0540,
  26187. Horicoptic: 0x03E8,
  26188. Hsmall: 0xF768,
  26189. Hungarumlaut: 0xF6CF,
  26190. Hungarumlautsmall: 0xF6F8,
  26191. Hzsquare: 0x3390,
  26192. I: 0x0049,
  26193. IAcyrillic: 0x042F,
  26194. IJ: 0x0132,
  26195. IUcyrillic: 0x042E,
  26196. Iacute: 0x00CD,
  26197. Iacutesmall: 0xF7ED,
  26198. Ibreve: 0x012C,
  26199. Icaron: 0x01CF,
  26200. Icircle: 0x24BE,
  26201. Icircumflex: 0x00CE,
  26202. Icircumflexsmall: 0xF7EE,
  26203. Icyrillic: 0x0406,
  26204. Idblgrave: 0x0208,
  26205. Idieresis: 0x00CF,
  26206. Idieresisacute: 0x1E2E,
  26207. Idieresiscyrillic: 0x04E4,
  26208. Idieresissmall: 0xF7EF,
  26209. Idot: 0x0130,
  26210. Idotaccent: 0x0130,
  26211. Idotbelow: 0x1ECA,
  26212. Iebrevecyrillic: 0x04D6,
  26213. Iecyrillic: 0x0415,
  26214. Ifraktur: 0x2111,
  26215. Igrave: 0x00CC,
  26216. Igravesmall: 0xF7EC,
  26217. Ihookabove: 0x1EC8,
  26218. Iicyrillic: 0x0418,
  26219. Iinvertedbreve: 0x020A,
  26220. Iishortcyrillic: 0x0419,
  26221. Imacron: 0x012A,
  26222. Imacroncyrillic: 0x04E2,
  26223. Imonospace: 0xFF29,
  26224. Iniarmenian: 0x053B,
  26225. Iocyrillic: 0x0401,
  26226. Iogonek: 0x012E,
  26227. Iota: 0x0399,
  26228. Iotaafrican: 0x0196,
  26229. Iotadieresis: 0x03AA,
  26230. Iotatonos: 0x038A,
  26231. Ismall: 0xF769,
  26232. Istroke: 0x0197,
  26233. Itilde: 0x0128,
  26234. Itildebelow: 0x1E2C,
  26235. Izhitsacyrillic: 0x0474,
  26236. Izhitsadblgravecyrillic: 0x0476,
  26237. J: 0x004A,
  26238. Jaarmenian: 0x0541,
  26239. Jcircle: 0x24BF,
  26240. Jcircumflex: 0x0134,
  26241. Jecyrillic: 0x0408,
  26242. Jheharmenian: 0x054B,
  26243. Jmonospace: 0xFF2A,
  26244. Jsmall: 0xF76A,
  26245. K: 0x004B,
  26246. KBsquare: 0x3385,
  26247. KKsquare: 0x33CD,
  26248. Kabashkircyrillic: 0x04A0,
  26249. Kacute: 0x1E30,
  26250. Kacyrillic: 0x041A,
  26251. Kadescendercyrillic: 0x049A,
  26252. Kahookcyrillic: 0x04C3,
  26253. Kappa: 0x039A,
  26254. Kastrokecyrillic: 0x049E,
  26255. Kaverticalstrokecyrillic: 0x049C,
  26256. Kcaron: 0x01E8,
  26257. Kcedilla: 0x0136,
  26258. Kcircle: 0x24C0,
  26259. Kcommaaccent: 0x0136,
  26260. Kdotbelow: 0x1E32,
  26261. Keharmenian: 0x0554,
  26262. Kenarmenian: 0x053F,
  26263. Khacyrillic: 0x0425,
  26264. Kheicoptic: 0x03E6,
  26265. Khook: 0x0198,
  26266. Kjecyrillic: 0x040C,
  26267. Klinebelow: 0x1E34,
  26268. Kmonospace: 0xFF2B,
  26269. Koppacyrillic: 0x0480,
  26270. Koppagreek: 0x03DE,
  26271. Ksicyrillic: 0x046E,
  26272. Ksmall: 0xF76B,
  26273. L: 0x004C,
  26274. LJ: 0x01C7,
  26275. LL: 0xF6BF,
  26276. Lacute: 0x0139,
  26277. Lambda: 0x039B,
  26278. Lcaron: 0x013D,
  26279. Lcedilla: 0x013B,
  26280. Lcircle: 0x24C1,
  26281. Lcircumflexbelow: 0x1E3C,
  26282. Lcommaaccent: 0x013B,
  26283. Ldot: 0x013F,
  26284. Ldotaccent: 0x013F,
  26285. Ldotbelow: 0x1E36,
  26286. Ldotbelowmacron: 0x1E38,
  26287. Liwnarmenian: 0x053C,
  26288. Lj: 0x01C8,
  26289. Ljecyrillic: 0x0409,
  26290. Llinebelow: 0x1E3A,
  26291. Lmonospace: 0xFF2C,
  26292. Lslash: 0x0141,
  26293. Lslashsmall: 0xF6F9,
  26294. Lsmall: 0xF76C,
  26295. M: 0x004D,
  26296. MBsquare: 0x3386,
  26297. Macron: 0xF6D0,
  26298. Macronsmall: 0xF7AF,
  26299. Macute: 0x1E3E,
  26300. Mcircle: 0x24C2,
  26301. Mdotaccent: 0x1E40,
  26302. Mdotbelow: 0x1E42,
  26303. Menarmenian: 0x0544,
  26304. Mmonospace: 0xFF2D,
  26305. Msmall: 0xF76D,
  26306. Mturned: 0x019C,
  26307. Mu: 0x039C,
  26308. N: 0x004E,
  26309. NJ: 0x01CA,
  26310. Nacute: 0x0143,
  26311. Ncaron: 0x0147,
  26312. Ncedilla: 0x0145,
  26313. Ncircle: 0x24C3,
  26314. Ncircumflexbelow: 0x1E4A,
  26315. Ncommaaccent: 0x0145,
  26316. Ndotaccent: 0x1E44,
  26317. Ndotbelow: 0x1E46,
  26318. Nhookleft: 0x019D,
  26319. Nineroman: 0x2168,
  26320. Nj: 0x01CB,
  26321. Njecyrillic: 0x040A,
  26322. Nlinebelow: 0x1E48,
  26323. Nmonospace: 0xFF2E,
  26324. Nowarmenian: 0x0546,
  26325. Nsmall: 0xF76E,
  26326. Ntilde: 0x00D1,
  26327. Ntildesmall: 0xF7F1,
  26328. Nu: 0x039D,
  26329. O: 0x004F,
  26330. OE: 0x0152,
  26331. OEsmall: 0xF6FA,
  26332. Oacute: 0x00D3,
  26333. Oacutesmall: 0xF7F3,
  26334. Obarredcyrillic: 0x04E8,
  26335. Obarreddieresiscyrillic: 0x04EA,
  26336. Obreve: 0x014E,
  26337. Ocaron: 0x01D1,
  26338. Ocenteredtilde: 0x019F,
  26339. Ocircle: 0x24C4,
  26340. Ocircumflex: 0x00D4,
  26341. Ocircumflexacute: 0x1ED0,
  26342. Ocircumflexdotbelow: 0x1ED8,
  26343. Ocircumflexgrave: 0x1ED2,
  26344. Ocircumflexhookabove: 0x1ED4,
  26345. Ocircumflexsmall: 0xF7F4,
  26346. Ocircumflextilde: 0x1ED6,
  26347. Ocyrillic: 0x041E,
  26348. Odblacute: 0x0150,
  26349. Odblgrave: 0x020C,
  26350. Odieresis: 0x00D6,
  26351. Odieresiscyrillic: 0x04E6,
  26352. Odieresissmall: 0xF7F6,
  26353. Odotbelow: 0x1ECC,
  26354. Ogoneksmall: 0xF6FB,
  26355. Ograve: 0x00D2,
  26356. Ogravesmall: 0xF7F2,
  26357. Oharmenian: 0x0555,
  26358. Ohm: 0x2126,
  26359. Ohookabove: 0x1ECE,
  26360. Ohorn: 0x01A0,
  26361. Ohornacute: 0x1EDA,
  26362. Ohorndotbelow: 0x1EE2,
  26363. Ohorngrave: 0x1EDC,
  26364. Ohornhookabove: 0x1EDE,
  26365. Ohorntilde: 0x1EE0,
  26366. Ohungarumlaut: 0x0150,
  26367. Oi: 0x01A2,
  26368. Oinvertedbreve: 0x020E,
  26369. Omacron: 0x014C,
  26370. Omacronacute: 0x1E52,
  26371. Omacrongrave: 0x1E50,
  26372. Omega: 0x2126,
  26373. Omegacyrillic: 0x0460,
  26374. Omegagreek: 0x03A9,
  26375. Omegaroundcyrillic: 0x047A,
  26376. Omegatitlocyrillic: 0x047C,
  26377. Omegatonos: 0x038F,
  26378. Omicron: 0x039F,
  26379. Omicrontonos: 0x038C,
  26380. Omonospace: 0xFF2F,
  26381. Oneroman: 0x2160,
  26382. Oogonek: 0x01EA,
  26383. Oogonekmacron: 0x01EC,
  26384. Oopen: 0x0186,
  26385. Oslash: 0x00D8,
  26386. Oslashacute: 0x01FE,
  26387. Oslashsmall: 0xF7F8,
  26388. Osmall: 0xF76F,
  26389. Ostrokeacute: 0x01FE,
  26390. Otcyrillic: 0x047E,
  26391. Otilde: 0x00D5,
  26392. Otildeacute: 0x1E4C,
  26393. Otildedieresis: 0x1E4E,
  26394. Otildesmall: 0xF7F5,
  26395. P: 0x0050,
  26396. Pacute: 0x1E54,
  26397. Pcircle: 0x24C5,
  26398. Pdotaccent: 0x1E56,
  26399. Pecyrillic: 0x041F,
  26400. Peharmenian: 0x054A,
  26401. Pemiddlehookcyrillic: 0x04A6,
  26402. Phi: 0x03A6,
  26403. Phook: 0x01A4,
  26404. Pi: 0x03A0,
  26405. Piwrarmenian: 0x0553,
  26406. Pmonospace: 0xFF30,
  26407. Psi: 0x03A8,
  26408. Psicyrillic: 0x0470,
  26409. Psmall: 0xF770,
  26410. Q: 0x0051,
  26411. Qcircle: 0x24C6,
  26412. Qmonospace: 0xFF31,
  26413. Qsmall: 0xF771,
  26414. R: 0x0052,
  26415. Raarmenian: 0x054C,
  26416. Racute: 0x0154,
  26417. Rcaron: 0x0158,
  26418. Rcedilla: 0x0156,
  26419. Rcircle: 0x24C7,
  26420. Rcommaaccent: 0x0156,
  26421. Rdblgrave: 0x0210,
  26422. Rdotaccent: 0x1E58,
  26423. Rdotbelow: 0x1E5A,
  26424. Rdotbelowmacron: 0x1E5C,
  26425. Reharmenian: 0x0550,
  26426. Rfraktur: 0x211C,
  26427. Rho: 0x03A1,
  26428. Ringsmall: 0xF6FC,
  26429. Rinvertedbreve: 0x0212,
  26430. Rlinebelow: 0x1E5E,
  26431. Rmonospace: 0xFF32,
  26432. Rsmall: 0xF772,
  26433. Rsmallinverted: 0x0281,
  26434. Rsmallinvertedsuperior: 0x02B6,
  26435. S: 0x0053,
  26436. SF010000: 0x250C,
  26437. SF020000: 0x2514,
  26438. SF030000: 0x2510,
  26439. SF040000: 0x2518,
  26440. SF050000: 0x253C,
  26441. SF060000: 0x252C,
  26442. SF070000: 0x2534,
  26443. SF080000: 0x251C,
  26444. SF090000: 0x2524,
  26445. SF100000: 0x2500,
  26446. SF110000: 0x2502,
  26447. SF190000: 0x2561,
  26448. SF200000: 0x2562,
  26449. SF210000: 0x2556,
  26450. SF220000: 0x2555,
  26451. SF230000: 0x2563,
  26452. SF240000: 0x2551,
  26453. SF250000: 0x2557,
  26454. SF260000: 0x255D,
  26455. SF270000: 0x255C,
  26456. SF280000: 0x255B,
  26457. SF360000: 0x255E,
  26458. SF370000: 0x255F,
  26459. SF380000: 0x255A,
  26460. SF390000: 0x2554,
  26461. SF400000: 0x2569,
  26462. SF410000: 0x2566,
  26463. SF420000: 0x2560,
  26464. SF430000: 0x2550,
  26465. SF440000: 0x256C,
  26466. SF450000: 0x2567,
  26467. SF460000: 0x2568,
  26468. SF470000: 0x2564,
  26469. SF480000: 0x2565,
  26470. SF490000: 0x2559,
  26471. SF500000: 0x2558,
  26472. SF510000: 0x2552,
  26473. SF520000: 0x2553,
  26474. SF530000: 0x256B,
  26475. SF540000: 0x256A,
  26476. Sacute: 0x015A,
  26477. Sacutedotaccent: 0x1E64,
  26478. Sampigreek: 0x03E0,
  26479. Scaron: 0x0160,
  26480. Scarondotaccent: 0x1E66,
  26481. Scaronsmall: 0xF6FD,
  26482. Scedilla: 0x015E,
  26483. Schwa: 0x018F,
  26484. Schwacyrillic: 0x04D8,
  26485. Schwadieresiscyrillic: 0x04DA,
  26486. Scircle: 0x24C8,
  26487. Scircumflex: 0x015C,
  26488. Scommaaccent: 0x0218,
  26489. Sdotaccent: 0x1E60,
  26490. Sdotbelow: 0x1E62,
  26491. Sdotbelowdotaccent: 0x1E68,
  26492. Seharmenian: 0x054D,
  26493. Sevenroman: 0x2166,
  26494. Shaarmenian: 0x0547,
  26495. Shacyrillic: 0x0428,
  26496. Shchacyrillic: 0x0429,
  26497. Sheicoptic: 0x03E2,
  26498. Shhacyrillic: 0x04BA,
  26499. Shimacoptic: 0x03EC,
  26500. Sigma: 0x03A3,
  26501. Sixroman: 0x2165,
  26502. Smonospace: 0xFF33,
  26503. Softsigncyrillic: 0x042C,
  26504. Ssmall: 0xF773,
  26505. Stigmagreek: 0x03DA,
  26506. T: 0x0054,
  26507. Tau: 0x03A4,
  26508. Tbar: 0x0166,
  26509. Tcaron: 0x0164,
  26510. Tcedilla: 0x0162,
  26511. Tcircle: 0x24C9,
  26512. Tcircumflexbelow: 0x1E70,
  26513. Tcommaaccent: 0x0162,
  26514. Tdotaccent: 0x1E6A,
  26515. Tdotbelow: 0x1E6C,
  26516. Tecyrillic: 0x0422,
  26517. Tedescendercyrillic: 0x04AC,
  26518. Tenroman: 0x2169,
  26519. Tetsecyrillic: 0x04B4,
  26520. Theta: 0x0398,
  26521. Thook: 0x01AC,
  26522. Thorn: 0x00DE,
  26523. Thornsmall: 0xF7FE,
  26524. Threeroman: 0x2162,
  26525. Tildesmall: 0xF6FE,
  26526. Tiwnarmenian: 0x054F,
  26527. Tlinebelow: 0x1E6E,
  26528. Tmonospace: 0xFF34,
  26529. Toarmenian: 0x0539,
  26530. Tonefive: 0x01BC,
  26531. Tonesix: 0x0184,
  26532. Tonetwo: 0x01A7,
  26533. Tretroflexhook: 0x01AE,
  26534. Tsecyrillic: 0x0426,
  26535. Tshecyrillic: 0x040B,
  26536. Tsmall: 0xF774,
  26537. Twelveroman: 0x216B,
  26538. Tworoman: 0x2161,
  26539. U: 0x0055,
  26540. Uacute: 0x00DA,
  26541. Uacutesmall: 0xF7FA,
  26542. Ubreve: 0x016C,
  26543. Ucaron: 0x01D3,
  26544. Ucircle: 0x24CA,
  26545. Ucircumflex: 0x00DB,
  26546. Ucircumflexbelow: 0x1E76,
  26547. Ucircumflexsmall: 0xF7FB,
  26548. Ucyrillic: 0x0423,
  26549. Udblacute: 0x0170,
  26550. Udblgrave: 0x0214,
  26551. Udieresis: 0x00DC,
  26552. Udieresisacute: 0x01D7,
  26553. Udieresisbelow: 0x1E72,
  26554. Udieresiscaron: 0x01D9,
  26555. Udieresiscyrillic: 0x04F0,
  26556. Udieresisgrave: 0x01DB,
  26557. Udieresismacron: 0x01D5,
  26558. Udieresissmall: 0xF7FC,
  26559. Udotbelow: 0x1EE4,
  26560. Ugrave: 0x00D9,
  26561. Ugravesmall: 0xF7F9,
  26562. Uhookabove: 0x1EE6,
  26563. Uhorn: 0x01AF,
  26564. Uhornacute: 0x1EE8,
  26565. Uhorndotbelow: 0x1EF0,
  26566. Uhorngrave: 0x1EEA,
  26567. Uhornhookabove: 0x1EEC,
  26568. Uhorntilde: 0x1EEE,
  26569. Uhungarumlaut: 0x0170,
  26570. Uhungarumlautcyrillic: 0x04F2,
  26571. Uinvertedbreve: 0x0216,
  26572. Ukcyrillic: 0x0478,
  26573. Umacron: 0x016A,
  26574. Umacroncyrillic: 0x04EE,
  26575. Umacrondieresis: 0x1E7A,
  26576. Umonospace: 0xFF35,
  26577. Uogonek: 0x0172,
  26578. Upsilon: 0x03A5,
  26579. Upsilon1: 0x03D2,
  26580. Upsilonacutehooksymbolgreek: 0x03D3,
  26581. Upsilonafrican: 0x01B1,
  26582. Upsilondieresis: 0x03AB,
  26583. Upsilondieresishooksymbolgreek: 0x03D4,
  26584. Upsilonhooksymbol: 0x03D2,
  26585. Upsilontonos: 0x038E,
  26586. Uring: 0x016E,
  26587. Ushortcyrillic: 0x040E,
  26588. Usmall: 0xF775,
  26589. Ustraightcyrillic: 0x04AE,
  26590. Ustraightstrokecyrillic: 0x04B0,
  26591. Utilde: 0x0168,
  26592. Utildeacute: 0x1E78,
  26593. Utildebelow: 0x1E74,
  26594. V: 0x0056,
  26595. Vcircle: 0x24CB,
  26596. Vdotbelow: 0x1E7E,
  26597. Vecyrillic: 0x0412,
  26598. Vewarmenian: 0x054E,
  26599. Vhook: 0x01B2,
  26600. Vmonospace: 0xFF36,
  26601. Voarmenian: 0x0548,
  26602. Vsmall: 0xF776,
  26603. Vtilde: 0x1E7C,
  26604. W: 0x0057,
  26605. Wacute: 0x1E82,
  26606. Wcircle: 0x24CC,
  26607. Wcircumflex: 0x0174,
  26608. Wdieresis: 0x1E84,
  26609. Wdotaccent: 0x1E86,
  26610. Wdotbelow: 0x1E88,
  26611. Wgrave: 0x1E80,
  26612. Wmonospace: 0xFF37,
  26613. Wsmall: 0xF777,
  26614. X: 0x0058,
  26615. Xcircle: 0x24CD,
  26616. Xdieresis: 0x1E8C,
  26617. Xdotaccent: 0x1E8A,
  26618. Xeharmenian: 0x053D,
  26619. Xi: 0x039E,
  26620. Xmonospace: 0xFF38,
  26621. Xsmall: 0xF778,
  26622. Y: 0x0059,
  26623. Yacute: 0x00DD,
  26624. Yacutesmall: 0xF7FD,
  26625. Yatcyrillic: 0x0462,
  26626. Ycircle: 0x24CE,
  26627. Ycircumflex: 0x0176,
  26628. Ydieresis: 0x0178,
  26629. Ydieresissmall: 0xF7FF,
  26630. Ydotaccent: 0x1E8E,
  26631. Ydotbelow: 0x1EF4,
  26632. Yericyrillic: 0x042B,
  26633. Yerudieresiscyrillic: 0x04F8,
  26634. Ygrave: 0x1EF2,
  26635. Yhook: 0x01B3,
  26636. Yhookabove: 0x1EF6,
  26637. Yiarmenian: 0x0545,
  26638. Yicyrillic: 0x0407,
  26639. Yiwnarmenian: 0x0552,
  26640. Ymonospace: 0xFF39,
  26641. Ysmall: 0xF779,
  26642. Ytilde: 0x1EF8,
  26643. Yusbigcyrillic: 0x046A,
  26644. Yusbigiotifiedcyrillic: 0x046C,
  26645. Yuslittlecyrillic: 0x0466,
  26646. Yuslittleiotifiedcyrillic: 0x0468,
  26647. Z: 0x005A,
  26648. Zaarmenian: 0x0536,
  26649. Zacute: 0x0179,
  26650. Zcaron: 0x017D,
  26651. Zcaronsmall: 0xF6FF,
  26652. Zcircle: 0x24CF,
  26653. Zcircumflex: 0x1E90,
  26654. Zdot: 0x017B,
  26655. Zdotaccent: 0x017B,
  26656. Zdotbelow: 0x1E92,
  26657. Zecyrillic: 0x0417,
  26658. Zedescendercyrillic: 0x0498,
  26659. Zedieresiscyrillic: 0x04DE,
  26660. Zeta: 0x0396,
  26661. Zhearmenian: 0x053A,
  26662. Zhebrevecyrillic: 0x04C1,
  26663. Zhecyrillic: 0x0416,
  26664. Zhedescendercyrillic: 0x0496,
  26665. Zhedieresiscyrillic: 0x04DC,
  26666. Zlinebelow: 0x1E94,
  26667. Zmonospace: 0xFF3A,
  26668. Zsmall: 0xF77A,
  26669. Zstroke: 0x01B5,
  26670. a: 0x0061,
  26671. aabengali: 0x0986,
  26672. aacute: 0x00E1,
  26673. aadeva: 0x0906,
  26674. aagujarati: 0x0A86,
  26675. aagurmukhi: 0x0A06,
  26676. aamatragurmukhi: 0x0A3E,
  26677. aarusquare: 0x3303,
  26678. aavowelsignbengali: 0x09BE,
  26679. aavowelsigndeva: 0x093E,
  26680. aavowelsigngujarati: 0x0ABE,
  26681. abbreviationmarkarmenian: 0x055F,
  26682. abbreviationsigndeva: 0x0970,
  26683. abengali: 0x0985,
  26684. abopomofo: 0x311A,
  26685. abreve: 0x0103,
  26686. abreveacute: 0x1EAF,
  26687. abrevecyrillic: 0x04D1,
  26688. abrevedotbelow: 0x1EB7,
  26689. abrevegrave: 0x1EB1,
  26690. abrevehookabove: 0x1EB3,
  26691. abrevetilde: 0x1EB5,
  26692. acaron: 0x01CE,
  26693. acircle: 0x24D0,
  26694. acircumflex: 0x00E2,
  26695. acircumflexacute: 0x1EA5,
  26696. acircumflexdotbelow: 0x1EAD,
  26697. acircumflexgrave: 0x1EA7,
  26698. acircumflexhookabove: 0x1EA9,
  26699. acircumflextilde: 0x1EAB,
  26700. acute: 0x00B4,
  26701. acutebelowcmb: 0x0317,
  26702. acutecmb: 0x0301,
  26703. acutecomb: 0x0301,
  26704. acutedeva: 0x0954,
  26705. acutelowmod: 0x02CF,
  26706. acutetonecmb: 0x0341,
  26707. acyrillic: 0x0430,
  26708. adblgrave: 0x0201,
  26709. addakgurmukhi: 0x0A71,
  26710. adeva: 0x0905,
  26711. adieresis: 0x00E4,
  26712. adieresiscyrillic: 0x04D3,
  26713. adieresismacron: 0x01DF,
  26714. adotbelow: 0x1EA1,
  26715. adotmacron: 0x01E1,
  26716. ae: 0x00E6,
  26717. aeacute: 0x01FD,
  26718. aekorean: 0x3150,
  26719. aemacron: 0x01E3,
  26720. afii00208: 0x2015,
  26721. afii08941: 0x20A4,
  26722. afii10017: 0x0410,
  26723. afii10018: 0x0411,
  26724. afii10019: 0x0412,
  26725. afii10020: 0x0413,
  26726. afii10021: 0x0414,
  26727. afii10022: 0x0415,
  26728. afii10023: 0x0401,
  26729. afii10024: 0x0416,
  26730. afii10025: 0x0417,
  26731. afii10026: 0x0418,
  26732. afii10027: 0x0419,
  26733. afii10028: 0x041A,
  26734. afii10029: 0x041B,
  26735. afii10030: 0x041C,
  26736. afii10031: 0x041D,
  26737. afii10032: 0x041E,
  26738. afii10033: 0x041F,
  26739. afii10034: 0x0420,
  26740. afii10035: 0x0421,
  26741. afii10036: 0x0422,
  26742. afii10037: 0x0423,
  26743. afii10038: 0x0424,
  26744. afii10039: 0x0425,
  26745. afii10040: 0x0426,
  26746. afii10041: 0x0427,
  26747. afii10042: 0x0428,
  26748. afii10043: 0x0429,
  26749. afii10044: 0x042A,
  26750. afii10045: 0x042B,
  26751. afii10046: 0x042C,
  26752. afii10047: 0x042D,
  26753. afii10048: 0x042E,
  26754. afii10049: 0x042F,
  26755. afii10050: 0x0490,
  26756. afii10051: 0x0402,
  26757. afii10052: 0x0403,
  26758. afii10053: 0x0404,
  26759. afii10054: 0x0405,
  26760. afii10055: 0x0406,
  26761. afii10056: 0x0407,
  26762. afii10057: 0x0408,
  26763. afii10058: 0x0409,
  26764. afii10059: 0x040A,
  26765. afii10060: 0x040B,
  26766. afii10061: 0x040C,
  26767. afii10062: 0x040E,
  26768. afii10063: 0xF6C4,
  26769. afii10064: 0xF6C5,
  26770. afii10065: 0x0430,
  26771. afii10066: 0x0431,
  26772. afii10067: 0x0432,
  26773. afii10068: 0x0433,
  26774. afii10069: 0x0434,
  26775. afii10070: 0x0435,
  26776. afii10071: 0x0451,
  26777. afii10072: 0x0436,
  26778. afii10073: 0x0437,
  26779. afii10074: 0x0438,
  26780. afii10075: 0x0439,
  26781. afii10076: 0x043A,
  26782. afii10077: 0x043B,
  26783. afii10078: 0x043C,
  26784. afii10079: 0x043D,
  26785. afii10080: 0x043E,
  26786. afii10081: 0x043F,
  26787. afii10082: 0x0440,
  26788. afii10083: 0x0441,
  26789. afii10084: 0x0442,
  26790. afii10085: 0x0443,
  26791. afii10086: 0x0444,
  26792. afii10087: 0x0445,
  26793. afii10088: 0x0446,
  26794. afii10089: 0x0447,
  26795. afii10090: 0x0448,
  26796. afii10091: 0x0449,
  26797. afii10092: 0x044A,
  26798. afii10093: 0x044B,
  26799. afii10094: 0x044C,
  26800. afii10095: 0x044D,
  26801. afii10096: 0x044E,
  26802. afii10097: 0x044F,
  26803. afii10098: 0x0491,
  26804. afii10099: 0x0452,
  26805. afii10100: 0x0453,
  26806. afii10101: 0x0454,
  26807. afii10102: 0x0455,
  26808. afii10103: 0x0456,
  26809. afii10104: 0x0457,
  26810. afii10105: 0x0458,
  26811. afii10106: 0x0459,
  26812. afii10107: 0x045A,
  26813. afii10108: 0x045B,
  26814. afii10109: 0x045C,
  26815. afii10110: 0x045E,
  26816. afii10145: 0x040F,
  26817. afii10146: 0x0462,
  26818. afii10147: 0x0472,
  26819. afii10148: 0x0474,
  26820. afii10192: 0xF6C6,
  26821. afii10193: 0x045F,
  26822. afii10194: 0x0463,
  26823. afii10195: 0x0473,
  26824. afii10196: 0x0475,
  26825. afii10831: 0xF6C7,
  26826. afii10832: 0xF6C8,
  26827. afii10846: 0x04D9,
  26828. afii299: 0x200E,
  26829. afii300: 0x200F,
  26830. afii301: 0x200D,
  26831. afii57381: 0x066A,
  26832. afii57388: 0x060C,
  26833. afii57392: 0x0660,
  26834. afii57393: 0x0661,
  26835. afii57394: 0x0662,
  26836. afii57395: 0x0663,
  26837. afii57396: 0x0664,
  26838. afii57397: 0x0665,
  26839. afii57398: 0x0666,
  26840. afii57399: 0x0667,
  26841. afii57400: 0x0668,
  26842. afii57401: 0x0669,
  26843. afii57403: 0x061B,
  26844. afii57407: 0x061F,
  26845. afii57409: 0x0621,
  26846. afii57410: 0x0622,
  26847. afii57411: 0x0623,
  26848. afii57412: 0x0624,
  26849. afii57413: 0x0625,
  26850. afii57414: 0x0626,
  26851. afii57415: 0x0627,
  26852. afii57416: 0x0628,
  26853. afii57417: 0x0629,
  26854. afii57418: 0x062A,
  26855. afii57419: 0x062B,
  26856. afii57420: 0x062C,
  26857. afii57421: 0x062D,
  26858. afii57422: 0x062E,
  26859. afii57423: 0x062F,
  26860. afii57424: 0x0630,
  26861. afii57425: 0x0631,
  26862. afii57426: 0x0632,
  26863. afii57427: 0x0633,
  26864. afii57428: 0x0634,
  26865. afii57429: 0x0635,
  26866. afii57430: 0x0636,
  26867. afii57431: 0x0637,
  26868. afii57432: 0x0638,
  26869. afii57433: 0x0639,
  26870. afii57434: 0x063A,
  26871. afii57440: 0x0640,
  26872. afii57441: 0x0641,
  26873. afii57442: 0x0642,
  26874. afii57443: 0x0643,
  26875. afii57444: 0x0644,
  26876. afii57445: 0x0645,
  26877. afii57446: 0x0646,
  26878. afii57448: 0x0648,
  26879. afii57449: 0x0649,
  26880. afii57450: 0x064A,
  26881. afii57451: 0x064B,
  26882. afii57452: 0x064C,
  26883. afii57453: 0x064D,
  26884. afii57454: 0x064E,
  26885. afii57455: 0x064F,
  26886. afii57456: 0x0650,
  26887. afii57457: 0x0651,
  26888. afii57458: 0x0652,
  26889. afii57470: 0x0647,
  26890. afii57505: 0x06A4,
  26891. afii57506: 0x067E,
  26892. afii57507: 0x0686,
  26893. afii57508: 0x0698,
  26894. afii57509: 0x06AF,
  26895. afii57511: 0x0679,
  26896. afii57512: 0x0688,
  26897. afii57513: 0x0691,
  26898. afii57514: 0x06BA,
  26899. afii57519: 0x06D2,
  26900. afii57534: 0x06D5,
  26901. afii57636: 0x20AA,
  26902. afii57645: 0x05BE,
  26903. afii57658: 0x05C3,
  26904. afii57664: 0x05D0,
  26905. afii57665: 0x05D1,
  26906. afii57666: 0x05D2,
  26907. afii57667: 0x05D3,
  26908. afii57668: 0x05D4,
  26909. afii57669: 0x05D5,
  26910. afii57670: 0x05D6,
  26911. afii57671: 0x05D7,
  26912. afii57672: 0x05D8,
  26913. afii57673: 0x05D9,
  26914. afii57674: 0x05DA,
  26915. afii57675: 0x05DB,
  26916. afii57676: 0x05DC,
  26917. afii57677: 0x05DD,
  26918. afii57678: 0x05DE,
  26919. afii57679: 0x05DF,
  26920. afii57680: 0x05E0,
  26921. afii57681: 0x05E1,
  26922. afii57682: 0x05E2,
  26923. afii57683: 0x05E3,
  26924. afii57684: 0x05E4,
  26925. afii57685: 0x05E5,
  26926. afii57686: 0x05E6,
  26927. afii57687: 0x05E7,
  26928. afii57688: 0x05E8,
  26929. afii57689: 0x05E9,
  26930. afii57690: 0x05EA,
  26931. afii57694: 0xFB2A,
  26932. afii57695: 0xFB2B,
  26933. afii57700: 0xFB4B,
  26934. afii57705: 0xFB1F,
  26935. afii57716: 0x05F0,
  26936. afii57717: 0x05F1,
  26937. afii57718: 0x05F2,
  26938. afii57723: 0xFB35,
  26939. afii57793: 0x05B4,
  26940. afii57794: 0x05B5,
  26941. afii57795: 0x05B6,
  26942. afii57796: 0x05BB,
  26943. afii57797: 0x05B8,
  26944. afii57798: 0x05B7,
  26945. afii57799: 0x05B0,
  26946. afii57800: 0x05B2,
  26947. afii57801: 0x05B1,
  26948. afii57802: 0x05B3,
  26949. afii57803: 0x05C2,
  26950. afii57804: 0x05C1,
  26951. afii57806: 0x05B9,
  26952. afii57807: 0x05BC,
  26953. afii57839: 0x05BD,
  26954. afii57841: 0x05BF,
  26955. afii57842: 0x05C0,
  26956. afii57929: 0x02BC,
  26957. afii61248: 0x2105,
  26958. afii61289: 0x2113,
  26959. afii61352: 0x2116,
  26960. afii61573: 0x202C,
  26961. afii61574: 0x202D,
  26962. afii61575: 0x202E,
  26963. afii61664: 0x200C,
  26964. afii63167: 0x066D,
  26965. afii64937: 0x02BD,
  26966. agrave: 0x00E0,
  26967. agujarati: 0x0A85,
  26968. agurmukhi: 0x0A05,
  26969. ahiragana: 0x3042,
  26970. ahookabove: 0x1EA3,
  26971. aibengali: 0x0990,
  26972. aibopomofo: 0x311E,
  26973. aideva: 0x0910,
  26974. aiecyrillic: 0x04D5,
  26975. aigujarati: 0x0A90,
  26976. aigurmukhi: 0x0A10,
  26977. aimatragurmukhi: 0x0A48,
  26978. ainarabic: 0x0639,
  26979. ainfinalarabic: 0xFECA,
  26980. aininitialarabic: 0xFECB,
  26981. ainmedialarabic: 0xFECC,
  26982. ainvertedbreve: 0x0203,
  26983. aivowelsignbengali: 0x09C8,
  26984. aivowelsigndeva: 0x0948,
  26985. aivowelsigngujarati: 0x0AC8,
  26986. akatakana: 0x30A2,
  26987. akatakanahalfwidth: 0xFF71,
  26988. akorean: 0x314F,
  26989. alef: 0x05D0,
  26990. alefarabic: 0x0627,
  26991. alefdageshhebrew: 0xFB30,
  26992. aleffinalarabic: 0xFE8E,
  26993. alefhamzaabovearabic: 0x0623,
  26994. alefhamzaabovefinalarabic: 0xFE84,
  26995. alefhamzabelowarabic: 0x0625,
  26996. alefhamzabelowfinalarabic: 0xFE88,
  26997. alefhebrew: 0x05D0,
  26998. aleflamedhebrew: 0xFB4F,
  26999. alefmaddaabovearabic: 0x0622,
  27000. alefmaddaabovefinalarabic: 0xFE82,
  27001. alefmaksuraarabic: 0x0649,
  27002. alefmaksurafinalarabic: 0xFEF0,
  27003. alefmaksurainitialarabic: 0xFEF3,
  27004. alefmaksuramedialarabic: 0xFEF4,
  27005. alefpatahhebrew: 0xFB2E,
  27006. alefqamatshebrew: 0xFB2F,
  27007. aleph: 0x2135,
  27008. allequal: 0x224C,
  27009. alpha: 0x03B1,
  27010. alphatonos: 0x03AC,
  27011. amacron: 0x0101,
  27012. amonospace: 0xFF41,
  27013. ampersand: 0x0026,
  27014. ampersandmonospace: 0xFF06,
  27015. ampersandsmall: 0xF726,
  27016. amsquare: 0x33C2,
  27017. anbopomofo: 0x3122,
  27018. angbopomofo: 0x3124,
  27019. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  27020. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  27021. angkhankhuthai: 0x0E5A,
  27022. angle: 0x2220,
  27023. anglebracketleft: 0x3008,
  27024. anglebracketleftvertical: 0xFE3F,
  27025. anglebracketright: 0x3009,
  27026. anglebracketrightvertical: 0xFE40,
  27027. angleleft: 0x2329,
  27028. angleright: 0x232A,
  27029. angstrom: 0x212B,
  27030. anoteleia: 0x0387,
  27031. anudattadeva: 0x0952,
  27032. anusvarabengali: 0x0982,
  27033. anusvaradeva: 0x0902,
  27034. anusvaragujarati: 0x0A82,
  27035. aogonek: 0x0105,
  27036. apaatosquare: 0x3300,
  27037. aparen: 0x249C,
  27038. apostrophearmenian: 0x055A,
  27039. apostrophemod: 0x02BC,
  27040. apple: 0xF8FF,
  27041. approaches: 0x2250,
  27042. approxequal: 0x2248,
  27043. approxequalorimage: 0x2252,
  27044. approximatelyequal: 0x2245,
  27045. araeaekorean: 0x318E,
  27046. araeakorean: 0x318D,
  27047. arc: 0x2312,
  27048. arighthalfring: 0x1E9A,
  27049. aring: 0x00E5,
  27050. aringacute: 0x01FB,
  27051. aringbelow: 0x1E01,
  27052. arrowboth: 0x2194,
  27053. arrowdashdown: 0x21E3,
  27054. arrowdashleft: 0x21E0,
  27055. arrowdashright: 0x21E2,
  27056. arrowdashup: 0x21E1,
  27057. arrowdblboth: 0x21D4,
  27058. arrowdbldown: 0x21D3,
  27059. arrowdblleft: 0x21D0,
  27060. arrowdblright: 0x21D2,
  27061. arrowdblup: 0x21D1,
  27062. arrowdown: 0x2193,
  27063. arrowdownleft: 0x2199,
  27064. arrowdownright: 0x2198,
  27065. arrowdownwhite: 0x21E9,
  27066. arrowheaddownmod: 0x02C5,
  27067. arrowheadleftmod: 0x02C2,
  27068. arrowheadrightmod: 0x02C3,
  27069. arrowheadupmod: 0x02C4,
  27070. arrowhorizex: 0xF8E7,
  27071. arrowleft: 0x2190,
  27072. arrowleftdbl: 0x21D0,
  27073. arrowleftdblstroke: 0x21CD,
  27074. arrowleftoverright: 0x21C6,
  27075. arrowleftwhite: 0x21E6,
  27076. arrowright: 0x2192,
  27077. arrowrightdblstroke: 0x21CF,
  27078. arrowrightheavy: 0x279E,
  27079. arrowrightoverleft: 0x21C4,
  27080. arrowrightwhite: 0x21E8,
  27081. arrowtableft: 0x21E4,
  27082. arrowtabright: 0x21E5,
  27083. arrowup: 0x2191,
  27084. arrowupdn: 0x2195,
  27085. arrowupdnbse: 0x21A8,
  27086. arrowupdownbase: 0x21A8,
  27087. arrowupleft: 0x2196,
  27088. arrowupleftofdown: 0x21C5,
  27089. arrowupright: 0x2197,
  27090. arrowupwhite: 0x21E7,
  27091. arrowvertex: 0xF8E6,
  27092. asciicircum: 0x005E,
  27093. asciicircummonospace: 0xFF3E,
  27094. asciitilde: 0x007E,
  27095. asciitildemonospace: 0xFF5E,
  27096. ascript: 0x0251,
  27097. ascriptturned: 0x0252,
  27098. asmallhiragana: 0x3041,
  27099. asmallkatakana: 0x30A1,
  27100. asmallkatakanahalfwidth: 0xFF67,
  27101. asterisk: 0x002A,
  27102. asteriskaltonearabic: 0x066D,
  27103. asteriskarabic: 0x066D,
  27104. asteriskmath: 0x2217,
  27105. asteriskmonospace: 0xFF0A,
  27106. asterisksmall: 0xFE61,
  27107. asterism: 0x2042,
  27108. asuperior: 0xF6E9,
  27109. asymptoticallyequal: 0x2243,
  27110. at: 0x0040,
  27111. atilde: 0x00E3,
  27112. atmonospace: 0xFF20,
  27113. atsmall: 0xFE6B,
  27114. aturned: 0x0250,
  27115. aubengali: 0x0994,
  27116. aubopomofo: 0x3120,
  27117. audeva: 0x0914,
  27118. augujarati: 0x0A94,
  27119. augurmukhi: 0x0A14,
  27120. aulengthmarkbengali: 0x09D7,
  27121. aumatragurmukhi: 0x0A4C,
  27122. auvowelsignbengali: 0x09CC,
  27123. auvowelsigndeva: 0x094C,
  27124. auvowelsigngujarati: 0x0ACC,
  27125. avagrahadeva: 0x093D,
  27126. aybarmenian: 0x0561,
  27127. ayin: 0x05E2,
  27128. ayinaltonehebrew: 0xFB20,
  27129. ayinhebrew: 0x05E2,
  27130. b: 0x0062,
  27131. babengali: 0x09AC,
  27132. backslash: 0x005C,
  27133. backslashmonospace: 0xFF3C,
  27134. badeva: 0x092C,
  27135. bagujarati: 0x0AAC,
  27136. bagurmukhi: 0x0A2C,
  27137. bahiragana: 0x3070,
  27138. bahtthai: 0x0E3F,
  27139. bakatakana: 0x30D0,
  27140. bar: 0x007C,
  27141. barmonospace: 0xFF5C,
  27142. bbopomofo: 0x3105,
  27143. bcircle: 0x24D1,
  27144. bdotaccent: 0x1E03,
  27145. bdotbelow: 0x1E05,
  27146. beamedsixteenthnotes: 0x266C,
  27147. because: 0x2235,
  27148. becyrillic: 0x0431,
  27149. beharabic: 0x0628,
  27150. behfinalarabic: 0xFE90,
  27151. behinitialarabic: 0xFE91,
  27152. behiragana: 0x3079,
  27153. behmedialarabic: 0xFE92,
  27154. behmeeminitialarabic: 0xFC9F,
  27155. behmeemisolatedarabic: 0xFC08,
  27156. behnoonfinalarabic: 0xFC6D,
  27157. bekatakana: 0x30D9,
  27158. benarmenian: 0x0562,
  27159. bet: 0x05D1,
  27160. beta: 0x03B2,
  27161. betasymbolgreek: 0x03D0,
  27162. betdagesh: 0xFB31,
  27163. betdageshhebrew: 0xFB31,
  27164. bethebrew: 0x05D1,
  27165. betrafehebrew: 0xFB4C,
  27166. bhabengali: 0x09AD,
  27167. bhadeva: 0x092D,
  27168. bhagujarati: 0x0AAD,
  27169. bhagurmukhi: 0x0A2D,
  27170. bhook: 0x0253,
  27171. bihiragana: 0x3073,
  27172. bikatakana: 0x30D3,
  27173. bilabialclick: 0x0298,
  27174. bindigurmukhi: 0x0A02,
  27175. birusquare: 0x3331,
  27176. blackcircle: 0x25CF,
  27177. blackdiamond: 0x25C6,
  27178. blackdownpointingtriangle: 0x25BC,
  27179. blackleftpointingpointer: 0x25C4,
  27180. blackleftpointingtriangle: 0x25C0,
  27181. blacklenticularbracketleft: 0x3010,
  27182. blacklenticularbracketleftvertical: 0xFE3B,
  27183. blacklenticularbracketright: 0x3011,
  27184. blacklenticularbracketrightvertical: 0xFE3C,
  27185. blacklowerlefttriangle: 0x25E3,
  27186. blacklowerrighttriangle: 0x25E2,
  27187. blackrectangle: 0x25AC,
  27188. blackrightpointingpointer: 0x25BA,
  27189. blackrightpointingtriangle: 0x25B6,
  27190. blacksmallsquare: 0x25AA,
  27191. blacksmilingface: 0x263B,
  27192. blacksquare: 0x25A0,
  27193. blackstar: 0x2605,
  27194. blackupperlefttriangle: 0x25E4,
  27195. blackupperrighttriangle: 0x25E5,
  27196. blackuppointingsmalltriangle: 0x25B4,
  27197. blackuppointingtriangle: 0x25B2,
  27198. blank: 0x2423,
  27199. blinebelow: 0x1E07,
  27200. block: 0x2588,
  27201. bmonospace: 0xFF42,
  27202. bobaimaithai: 0x0E1A,
  27203. bohiragana: 0x307C,
  27204. bokatakana: 0x30DC,
  27205. bparen: 0x249D,
  27206. bqsquare: 0x33C3,
  27207. braceex: 0xF8F4,
  27208. braceleft: 0x007B,
  27209. braceleftbt: 0xF8F3,
  27210. braceleftmid: 0xF8F2,
  27211. braceleftmonospace: 0xFF5B,
  27212. braceleftsmall: 0xFE5B,
  27213. bracelefttp: 0xF8F1,
  27214. braceleftvertical: 0xFE37,
  27215. braceright: 0x007D,
  27216. bracerightbt: 0xF8FE,
  27217. bracerightmid: 0xF8FD,
  27218. bracerightmonospace: 0xFF5D,
  27219. bracerightsmall: 0xFE5C,
  27220. bracerighttp: 0xF8FC,
  27221. bracerightvertical: 0xFE38,
  27222. bracketleft: 0x005B,
  27223. bracketleftbt: 0xF8F0,
  27224. bracketleftex: 0xF8EF,
  27225. bracketleftmonospace: 0xFF3B,
  27226. bracketlefttp: 0xF8EE,
  27227. bracketright: 0x005D,
  27228. bracketrightbt: 0xF8FB,
  27229. bracketrightex: 0xF8FA,
  27230. bracketrightmonospace: 0xFF3D,
  27231. bracketrighttp: 0xF8F9,
  27232. breve: 0x02D8,
  27233. brevebelowcmb: 0x032E,
  27234. brevecmb: 0x0306,
  27235. breveinvertedbelowcmb: 0x032F,
  27236. breveinvertedcmb: 0x0311,
  27237. breveinverteddoublecmb: 0x0361,
  27238. bridgebelowcmb: 0x032A,
  27239. bridgeinvertedbelowcmb: 0x033A,
  27240. brokenbar: 0x00A6,
  27241. bstroke: 0x0180,
  27242. bsuperior: 0xF6EA,
  27243. btopbar: 0x0183,
  27244. buhiragana: 0x3076,
  27245. bukatakana: 0x30D6,
  27246. bullet: 0x2022,
  27247. bulletinverse: 0x25D8,
  27248. bulletoperator: 0x2219,
  27249. bullseye: 0x25CE,
  27250. c: 0x0063,
  27251. caarmenian: 0x056E,
  27252. cabengali: 0x099A,
  27253. cacute: 0x0107,
  27254. cadeva: 0x091A,
  27255. cagujarati: 0x0A9A,
  27256. cagurmukhi: 0x0A1A,
  27257. calsquare: 0x3388,
  27258. candrabindubengali: 0x0981,
  27259. candrabinducmb: 0x0310,
  27260. candrabindudeva: 0x0901,
  27261. candrabindugujarati: 0x0A81,
  27262. capslock: 0x21EA,
  27263. careof: 0x2105,
  27264. caron: 0x02C7,
  27265. caronbelowcmb: 0x032C,
  27266. caroncmb: 0x030C,
  27267. carriagereturn: 0x21B5,
  27268. cbopomofo: 0x3118,
  27269. ccaron: 0x010D,
  27270. ccedilla: 0x00E7,
  27271. ccedillaacute: 0x1E09,
  27272. ccircle: 0x24D2,
  27273. ccircumflex: 0x0109,
  27274. ccurl: 0x0255,
  27275. cdot: 0x010B,
  27276. cdotaccent: 0x010B,
  27277. cdsquare: 0x33C5,
  27278. cedilla: 0x00B8,
  27279. cedillacmb: 0x0327,
  27280. cent: 0x00A2,
  27281. centigrade: 0x2103,
  27282. centinferior: 0xF6DF,
  27283. centmonospace: 0xFFE0,
  27284. centoldstyle: 0xF7A2,
  27285. centsuperior: 0xF6E0,
  27286. chaarmenian: 0x0579,
  27287. chabengali: 0x099B,
  27288. chadeva: 0x091B,
  27289. chagujarati: 0x0A9B,
  27290. chagurmukhi: 0x0A1B,
  27291. chbopomofo: 0x3114,
  27292. cheabkhasiancyrillic: 0x04BD,
  27293. checkmark: 0x2713,
  27294. checyrillic: 0x0447,
  27295. chedescenderabkhasiancyrillic: 0x04BF,
  27296. chedescendercyrillic: 0x04B7,
  27297. chedieresiscyrillic: 0x04F5,
  27298. cheharmenian: 0x0573,
  27299. chekhakassiancyrillic: 0x04CC,
  27300. cheverticalstrokecyrillic: 0x04B9,
  27301. chi: 0x03C7,
  27302. chieuchacirclekorean: 0x3277,
  27303. chieuchaparenkorean: 0x3217,
  27304. chieuchcirclekorean: 0x3269,
  27305. chieuchkorean: 0x314A,
  27306. chieuchparenkorean: 0x3209,
  27307. chochangthai: 0x0E0A,
  27308. chochanthai: 0x0E08,
  27309. chochingthai: 0x0E09,
  27310. chochoethai: 0x0E0C,
  27311. chook: 0x0188,
  27312. cieucacirclekorean: 0x3276,
  27313. cieucaparenkorean: 0x3216,
  27314. cieuccirclekorean: 0x3268,
  27315. cieuckorean: 0x3148,
  27316. cieucparenkorean: 0x3208,
  27317. cieucuparenkorean: 0x321C,
  27318. circle: 0x25CB,
  27319. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  27320. circlemultiply: 0x2297,
  27321. circleot: 0x2299,
  27322. circleplus: 0x2295,
  27323. circlepostalmark: 0x3036,
  27324. circlewithlefthalfblack: 0x25D0,
  27325. circlewithrighthalfblack: 0x25D1,
  27326. circumflex: 0x02C6,
  27327. circumflexbelowcmb: 0x032D,
  27328. circumflexcmb: 0x0302,
  27329. clear: 0x2327,
  27330. clickalveolar: 0x01C2,
  27331. clickdental: 0x01C0,
  27332. clicklateral: 0x01C1,
  27333. clickretroflex: 0x01C3,
  27334. club: 0x2663,
  27335. clubsuitblack: 0x2663,
  27336. clubsuitwhite: 0x2667,
  27337. cmcubedsquare: 0x33A4,
  27338. cmonospace: 0xFF43,
  27339. cmsquaredsquare: 0x33A0,
  27340. coarmenian: 0x0581,
  27341. colon: 0x003A,
  27342. colonmonetary: 0x20A1,
  27343. colonmonospace: 0xFF1A,
  27344. colonsign: 0x20A1,
  27345. colonsmall: 0xFE55,
  27346. colontriangularhalfmod: 0x02D1,
  27347. colontriangularmod: 0x02D0,
  27348. comma: 0x002C,
  27349. commaabovecmb: 0x0313,
  27350. commaaboverightcmb: 0x0315,
  27351. commaaccent: 0xF6C3,
  27352. commaarabic: 0x060C,
  27353. commaarmenian: 0x055D,
  27354. commainferior: 0xF6E1,
  27355. commamonospace: 0xFF0C,
  27356. commareversedabovecmb: 0x0314,
  27357. commareversedmod: 0x02BD,
  27358. commasmall: 0xFE50,
  27359. commasuperior: 0xF6E2,
  27360. commaturnedabovecmb: 0x0312,
  27361. commaturnedmod: 0x02BB,
  27362. compass: 0x263C,
  27363. congruent: 0x2245,
  27364. contourintegral: 0x222E,
  27365. control: 0x2303,
  27366. controlACK: 0x0006,
  27367. controlBEL: 0x0007,
  27368. controlBS: 0x0008,
  27369. controlCAN: 0x0018,
  27370. controlCR: 0x000D,
  27371. controlDC1: 0x0011,
  27372. controlDC2: 0x0012,
  27373. controlDC3: 0x0013,
  27374. controlDC4: 0x0014,
  27375. controlDEL: 0x007F,
  27376. controlDLE: 0x0010,
  27377. controlEM: 0x0019,
  27378. controlENQ: 0x0005,
  27379. controlEOT: 0x0004,
  27380. controlESC: 0x001B,
  27381. controlETB: 0x0017,
  27382. controlETX: 0x0003,
  27383. controlFF: 0x000C,
  27384. controlFS: 0x001C,
  27385. controlGS: 0x001D,
  27386. controlHT: 0x0009,
  27387. controlLF: 0x000A,
  27388. controlNAK: 0x0015,
  27389. controlRS: 0x001E,
  27390. controlSI: 0x000F,
  27391. controlSO: 0x000E,
  27392. controlSOT: 0x0002,
  27393. controlSTX: 0x0001,
  27394. controlSUB: 0x001A,
  27395. controlSYN: 0x0016,
  27396. controlUS: 0x001F,
  27397. controlVT: 0x000B,
  27398. copyright: 0x00A9,
  27399. copyrightsans: 0xF8E9,
  27400. copyrightserif: 0xF6D9,
  27401. cornerbracketleft: 0x300C,
  27402. cornerbracketlefthalfwidth: 0xFF62,
  27403. cornerbracketleftvertical: 0xFE41,
  27404. cornerbracketright: 0x300D,
  27405. cornerbracketrighthalfwidth: 0xFF63,
  27406. cornerbracketrightvertical: 0xFE42,
  27407. corporationsquare: 0x337F,
  27408. cosquare: 0x33C7,
  27409. coverkgsquare: 0x33C6,
  27410. cparen: 0x249E,
  27411. cruzeiro: 0x20A2,
  27412. cstretched: 0x0297,
  27413. curlyand: 0x22CF,
  27414. curlyor: 0x22CE,
  27415. currency: 0x00A4,
  27416. cyrBreve: 0xF6D1,
  27417. cyrFlex: 0xF6D2,
  27418. cyrbreve: 0xF6D4,
  27419. cyrflex: 0xF6D5,
  27420. d: 0x0064,
  27421. daarmenian: 0x0564,
  27422. dabengali: 0x09A6,
  27423. dadarabic: 0x0636,
  27424. dadeva: 0x0926,
  27425. dadfinalarabic: 0xFEBE,
  27426. dadinitialarabic: 0xFEBF,
  27427. dadmedialarabic: 0xFEC0,
  27428. dagesh: 0x05BC,
  27429. dageshhebrew: 0x05BC,
  27430. dagger: 0x2020,
  27431. daggerdbl: 0x2021,
  27432. dagujarati: 0x0AA6,
  27433. dagurmukhi: 0x0A26,
  27434. dahiragana: 0x3060,
  27435. dakatakana: 0x30C0,
  27436. dalarabic: 0x062F,
  27437. dalet: 0x05D3,
  27438. daletdagesh: 0xFB33,
  27439. daletdageshhebrew: 0xFB33,
  27440. dalethebrew: 0x05D3,
  27441. dalfinalarabic: 0xFEAA,
  27442. dammaarabic: 0x064F,
  27443. dammalowarabic: 0x064F,
  27444. dammatanaltonearabic: 0x064C,
  27445. dammatanarabic: 0x064C,
  27446. danda: 0x0964,
  27447. dargahebrew: 0x05A7,
  27448. dargalefthebrew: 0x05A7,
  27449. dasiapneumatacyrilliccmb: 0x0485,
  27450. dblGrave: 0xF6D3,
  27451. dblanglebracketleft: 0x300A,
  27452. dblanglebracketleftvertical: 0xFE3D,
  27453. dblanglebracketright: 0x300B,
  27454. dblanglebracketrightvertical: 0xFE3E,
  27455. dblarchinvertedbelowcmb: 0x032B,
  27456. dblarrowleft: 0x21D4,
  27457. dblarrowright: 0x21D2,
  27458. dbldanda: 0x0965,
  27459. dblgrave: 0xF6D6,
  27460. dblgravecmb: 0x030F,
  27461. dblintegral: 0x222C,
  27462. dbllowline: 0x2017,
  27463. dbllowlinecmb: 0x0333,
  27464. dbloverlinecmb: 0x033F,
  27465. dblprimemod: 0x02BA,
  27466. dblverticalbar: 0x2016,
  27467. dblverticallineabovecmb: 0x030E,
  27468. dbopomofo: 0x3109,
  27469. dbsquare: 0x33C8,
  27470. dcaron: 0x010F,
  27471. dcedilla: 0x1E11,
  27472. dcircle: 0x24D3,
  27473. dcircumflexbelow: 0x1E13,
  27474. dcroat: 0x0111,
  27475. ddabengali: 0x09A1,
  27476. ddadeva: 0x0921,
  27477. ddagujarati: 0x0AA1,
  27478. ddagurmukhi: 0x0A21,
  27479. ddalarabic: 0x0688,
  27480. ddalfinalarabic: 0xFB89,
  27481. dddhadeva: 0x095C,
  27482. ddhabengali: 0x09A2,
  27483. ddhadeva: 0x0922,
  27484. ddhagujarati: 0x0AA2,
  27485. ddhagurmukhi: 0x0A22,
  27486. ddotaccent: 0x1E0B,
  27487. ddotbelow: 0x1E0D,
  27488. decimalseparatorarabic: 0x066B,
  27489. decimalseparatorpersian: 0x066B,
  27490. decyrillic: 0x0434,
  27491. degree: 0x00B0,
  27492. dehihebrew: 0x05AD,
  27493. dehiragana: 0x3067,
  27494. deicoptic: 0x03EF,
  27495. dekatakana: 0x30C7,
  27496. deleteleft: 0x232B,
  27497. deleteright: 0x2326,
  27498. delta: 0x03B4,
  27499. deltaturned: 0x018D,
  27500. denominatorminusonenumeratorbengali: 0x09F8,
  27501. dezh: 0x02A4,
  27502. dhabengali: 0x09A7,
  27503. dhadeva: 0x0927,
  27504. dhagujarati: 0x0AA7,
  27505. dhagurmukhi: 0x0A27,
  27506. dhook: 0x0257,
  27507. dialytikatonos: 0x0385,
  27508. dialytikatonoscmb: 0x0344,
  27509. diamond: 0x2666,
  27510. diamondsuitwhite: 0x2662,
  27511. dieresis: 0x00A8,
  27512. dieresisacute: 0xF6D7,
  27513. dieresisbelowcmb: 0x0324,
  27514. dieresiscmb: 0x0308,
  27515. dieresisgrave: 0xF6D8,
  27516. dieresistonos: 0x0385,
  27517. dihiragana: 0x3062,
  27518. dikatakana: 0x30C2,
  27519. dittomark: 0x3003,
  27520. divide: 0x00F7,
  27521. divides: 0x2223,
  27522. divisionslash: 0x2215,
  27523. djecyrillic: 0x0452,
  27524. dkshade: 0x2593,
  27525. dlinebelow: 0x1E0F,
  27526. dlsquare: 0x3397,
  27527. dmacron: 0x0111,
  27528. dmonospace: 0xFF44,
  27529. dnblock: 0x2584,
  27530. dochadathai: 0x0E0E,
  27531. dodekthai: 0x0E14,
  27532. dohiragana: 0x3069,
  27533. dokatakana: 0x30C9,
  27534. dollar: 0x0024,
  27535. dollarinferior: 0xF6E3,
  27536. dollarmonospace: 0xFF04,
  27537. dollaroldstyle: 0xF724,
  27538. dollarsmall: 0xFE69,
  27539. dollarsuperior: 0xF6E4,
  27540. dong: 0x20AB,
  27541. dorusquare: 0x3326,
  27542. dotaccent: 0x02D9,
  27543. dotaccentcmb: 0x0307,
  27544. dotbelowcmb: 0x0323,
  27545. dotbelowcomb: 0x0323,
  27546. dotkatakana: 0x30FB,
  27547. dotlessi: 0x0131,
  27548. dotlessj: 0xF6BE,
  27549. dotlessjstrokehook: 0x0284,
  27550. dotmath: 0x22C5,
  27551. dottedcircle: 0x25CC,
  27552. doubleyodpatah: 0xFB1F,
  27553. doubleyodpatahhebrew: 0xFB1F,
  27554. downtackbelowcmb: 0x031E,
  27555. downtackmod: 0x02D5,
  27556. dparen: 0x249F,
  27557. dsuperior: 0xF6EB,
  27558. dtail: 0x0256,
  27559. dtopbar: 0x018C,
  27560. duhiragana: 0x3065,
  27561. dukatakana: 0x30C5,
  27562. dz: 0x01F3,
  27563. dzaltone: 0x02A3,
  27564. dzcaron: 0x01C6,
  27565. dzcurl: 0x02A5,
  27566. dzeabkhasiancyrillic: 0x04E1,
  27567. dzecyrillic: 0x0455,
  27568. dzhecyrillic: 0x045F,
  27569. e: 0x0065,
  27570. eacute: 0x00E9,
  27571. earth: 0x2641,
  27572. ebengali: 0x098F,
  27573. ebopomofo: 0x311C,
  27574. ebreve: 0x0115,
  27575. ecandradeva: 0x090D,
  27576. ecandragujarati: 0x0A8D,
  27577. ecandravowelsigndeva: 0x0945,
  27578. ecandravowelsigngujarati: 0x0AC5,
  27579. ecaron: 0x011B,
  27580. ecedillabreve: 0x1E1D,
  27581. echarmenian: 0x0565,
  27582. echyiwnarmenian: 0x0587,
  27583. ecircle: 0x24D4,
  27584. ecircumflex: 0x00EA,
  27585. ecircumflexacute: 0x1EBF,
  27586. ecircumflexbelow: 0x1E19,
  27587. ecircumflexdotbelow: 0x1EC7,
  27588. ecircumflexgrave: 0x1EC1,
  27589. ecircumflexhookabove: 0x1EC3,
  27590. ecircumflextilde: 0x1EC5,
  27591. ecyrillic: 0x0454,
  27592. edblgrave: 0x0205,
  27593. edeva: 0x090F,
  27594. edieresis: 0x00EB,
  27595. edot: 0x0117,
  27596. edotaccent: 0x0117,
  27597. edotbelow: 0x1EB9,
  27598. eegurmukhi: 0x0A0F,
  27599. eematragurmukhi: 0x0A47,
  27600. efcyrillic: 0x0444,
  27601. egrave: 0x00E8,
  27602. egujarati: 0x0A8F,
  27603. eharmenian: 0x0567,
  27604. ehbopomofo: 0x311D,
  27605. ehiragana: 0x3048,
  27606. ehookabove: 0x1EBB,
  27607. eibopomofo: 0x311F,
  27608. eight: 0x0038,
  27609. eightarabic: 0x0668,
  27610. eightbengali: 0x09EE,
  27611. eightcircle: 0x2467,
  27612. eightcircleinversesansserif: 0x2791,
  27613. eightdeva: 0x096E,
  27614. eighteencircle: 0x2471,
  27615. eighteenparen: 0x2485,
  27616. eighteenperiod: 0x2499,
  27617. eightgujarati: 0x0AEE,
  27618. eightgurmukhi: 0x0A6E,
  27619. eighthackarabic: 0x0668,
  27620. eighthangzhou: 0x3028,
  27621. eighthnotebeamed: 0x266B,
  27622. eightideographicparen: 0x3227,
  27623. eightinferior: 0x2088,
  27624. eightmonospace: 0xFF18,
  27625. eightoldstyle: 0xF738,
  27626. eightparen: 0x247B,
  27627. eightperiod: 0x248F,
  27628. eightpersian: 0x06F8,
  27629. eightroman: 0x2177,
  27630. eightsuperior: 0x2078,
  27631. eightthai: 0x0E58,
  27632. einvertedbreve: 0x0207,
  27633. eiotifiedcyrillic: 0x0465,
  27634. ekatakana: 0x30A8,
  27635. ekatakanahalfwidth: 0xFF74,
  27636. ekonkargurmukhi: 0x0A74,
  27637. ekorean: 0x3154,
  27638. elcyrillic: 0x043B,
  27639. element: 0x2208,
  27640. elevencircle: 0x246A,
  27641. elevenparen: 0x247E,
  27642. elevenperiod: 0x2492,
  27643. elevenroman: 0x217A,
  27644. ellipsis: 0x2026,
  27645. ellipsisvertical: 0x22EE,
  27646. emacron: 0x0113,
  27647. emacronacute: 0x1E17,
  27648. emacrongrave: 0x1E15,
  27649. emcyrillic: 0x043C,
  27650. emdash: 0x2014,
  27651. emdashvertical: 0xFE31,
  27652. emonospace: 0xFF45,
  27653. emphasismarkarmenian: 0x055B,
  27654. emptyset: 0x2205,
  27655. enbopomofo: 0x3123,
  27656. encyrillic: 0x043D,
  27657. endash: 0x2013,
  27658. endashvertical: 0xFE32,
  27659. endescendercyrillic: 0x04A3,
  27660. eng: 0x014B,
  27661. engbopomofo: 0x3125,
  27662. enghecyrillic: 0x04A5,
  27663. enhookcyrillic: 0x04C8,
  27664. enspace: 0x2002,
  27665. eogonek: 0x0119,
  27666. eokorean: 0x3153,
  27667. eopen: 0x025B,
  27668. eopenclosed: 0x029A,
  27669. eopenreversed: 0x025C,
  27670. eopenreversedclosed: 0x025E,
  27671. eopenreversedhook: 0x025D,
  27672. eparen: 0x24A0,
  27673. epsilon: 0x03B5,
  27674. epsilontonos: 0x03AD,
  27675. equal: 0x003D,
  27676. equalmonospace: 0xFF1D,
  27677. equalsmall: 0xFE66,
  27678. equalsuperior: 0x207C,
  27679. equivalence: 0x2261,
  27680. erbopomofo: 0x3126,
  27681. ercyrillic: 0x0440,
  27682. ereversed: 0x0258,
  27683. ereversedcyrillic: 0x044D,
  27684. escyrillic: 0x0441,
  27685. esdescendercyrillic: 0x04AB,
  27686. esh: 0x0283,
  27687. eshcurl: 0x0286,
  27688. eshortdeva: 0x090E,
  27689. eshortvowelsigndeva: 0x0946,
  27690. eshreversedloop: 0x01AA,
  27691. eshsquatreversed: 0x0285,
  27692. esmallhiragana: 0x3047,
  27693. esmallkatakana: 0x30A7,
  27694. esmallkatakanahalfwidth: 0xFF6A,
  27695. estimated: 0x212E,
  27696. esuperior: 0xF6EC,
  27697. eta: 0x03B7,
  27698. etarmenian: 0x0568,
  27699. etatonos: 0x03AE,
  27700. eth: 0x00F0,
  27701. etilde: 0x1EBD,
  27702. etildebelow: 0x1E1B,
  27703. etnahtafoukhhebrew: 0x0591,
  27704. etnahtafoukhlefthebrew: 0x0591,
  27705. etnahtahebrew: 0x0591,
  27706. etnahtalefthebrew: 0x0591,
  27707. eturned: 0x01DD,
  27708. eukorean: 0x3161,
  27709. euro: 0x20AC,
  27710. evowelsignbengali: 0x09C7,
  27711. evowelsigndeva: 0x0947,
  27712. evowelsigngujarati: 0x0AC7,
  27713. exclam: 0x0021,
  27714. exclamarmenian: 0x055C,
  27715. exclamdbl: 0x203C,
  27716. exclamdown: 0x00A1,
  27717. exclamdownsmall: 0xF7A1,
  27718. exclammonospace: 0xFF01,
  27719. exclamsmall: 0xF721,
  27720. existential: 0x2203,
  27721. ezh: 0x0292,
  27722. ezhcaron: 0x01EF,
  27723. ezhcurl: 0x0293,
  27724. ezhreversed: 0x01B9,
  27725. ezhtail: 0x01BA,
  27726. f: 0x0066,
  27727. fadeva: 0x095E,
  27728. fagurmukhi: 0x0A5E,
  27729. fahrenheit: 0x2109,
  27730. fathaarabic: 0x064E,
  27731. fathalowarabic: 0x064E,
  27732. fathatanarabic: 0x064B,
  27733. fbopomofo: 0x3108,
  27734. fcircle: 0x24D5,
  27735. fdotaccent: 0x1E1F,
  27736. feharabic: 0x0641,
  27737. feharmenian: 0x0586,
  27738. fehfinalarabic: 0xFED2,
  27739. fehinitialarabic: 0xFED3,
  27740. fehmedialarabic: 0xFED4,
  27741. feicoptic: 0x03E5,
  27742. female: 0x2640,
  27743. ff: 0xFB00,
  27744. ffi: 0xFB03,
  27745. ffl: 0xFB04,
  27746. fi: 0xFB01,
  27747. fifteencircle: 0x246E,
  27748. fifteenparen: 0x2482,
  27749. fifteenperiod: 0x2496,
  27750. figuredash: 0x2012,
  27751. filledbox: 0x25A0,
  27752. filledrect: 0x25AC,
  27753. finalkaf: 0x05DA,
  27754. finalkafdagesh: 0xFB3A,
  27755. finalkafdageshhebrew: 0xFB3A,
  27756. finalkafhebrew: 0x05DA,
  27757. finalmem: 0x05DD,
  27758. finalmemhebrew: 0x05DD,
  27759. finalnun: 0x05DF,
  27760. finalnunhebrew: 0x05DF,
  27761. finalpe: 0x05E3,
  27762. finalpehebrew: 0x05E3,
  27763. finaltsadi: 0x05E5,
  27764. finaltsadihebrew: 0x05E5,
  27765. firsttonechinese: 0x02C9,
  27766. fisheye: 0x25C9,
  27767. fitacyrillic: 0x0473,
  27768. five: 0x0035,
  27769. fivearabic: 0x0665,
  27770. fivebengali: 0x09EB,
  27771. fivecircle: 0x2464,
  27772. fivecircleinversesansserif: 0x278E,
  27773. fivedeva: 0x096B,
  27774. fiveeighths: 0x215D,
  27775. fivegujarati: 0x0AEB,
  27776. fivegurmukhi: 0x0A6B,
  27777. fivehackarabic: 0x0665,
  27778. fivehangzhou: 0x3025,
  27779. fiveideographicparen: 0x3224,
  27780. fiveinferior: 0x2085,
  27781. fivemonospace: 0xFF15,
  27782. fiveoldstyle: 0xF735,
  27783. fiveparen: 0x2478,
  27784. fiveperiod: 0x248C,
  27785. fivepersian: 0x06F5,
  27786. fiveroman: 0x2174,
  27787. fivesuperior: 0x2075,
  27788. fivethai: 0x0E55,
  27789. fl: 0xFB02,
  27790. florin: 0x0192,
  27791. fmonospace: 0xFF46,
  27792. fmsquare: 0x3399,
  27793. fofanthai: 0x0E1F,
  27794. fofathai: 0x0E1D,
  27795. fongmanthai: 0x0E4F,
  27796. forall: 0x2200,
  27797. four: 0x0034,
  27798. fourarabic: 0x0664,
  27799. fourbengali: 0x09EA,
  27800. fourcircle: 0x2463,
  27801. fourcircleinversesansserif: 0x278D,
  27802. fourdeva: 0x096A,
  27803. fourgujarati: 0x0AEA,
  27804. fourgurmukhi: 0x0A6A,
  27805. fourhackarabic: 0x0664,
  27806. fourhangzhou: 0x3024,
  27807. fourideographicparen: 0x3223,
  27808. fourinferior: 0x2084,
  27809. fourmonospace: 0xFF14,
  27810. fournumeratorbengali: 0x09F7,
  27811. fouroldstyle: 0xF734,
  27812. fourparen: 0x2477,
  27813. fourperiod: 0x248B,
  27814. fourpersian: 0x06F4,
  27815. fourroman: 0x2173,
  27816. foursuperior: 0x2074,
  27817. fourteencircle: 0x246D,
  27818. fourteenparen: 0x2481,
  27819. fourteenperiod: 0x2495,
  27820. fourthai: 0x0E54,
  27821. fourthtonechinese: 0x02CB,
  27822. fparen: 0x24A1,
  27823. fraction: 0x2044,
  27824. franc: 0x20A3,
  27825. g: 0x0067,
  27826. gabengali: 0x0997,
  27827. gacute: 0x01F5,
  27828. gadeva: 0x0917,
  27829. gafarabic: 0x06AF,
  27830. gaffinalarabic: 0xFB93,
  27831. gafinitialarabic: 0xFB94,
  27832. gafmedialarabic: 0xFB95,
  27833. gagujarati: 0x0A97,
  27834. gagurmukhi: 0x0A17,
  27835. gahiragana: 0x304C,
  27836. gakatakana: 0x30AC,
  27837. gamma: 0x03B3,
  27838. gammalatinsmall: 0x0263,
  27839. gammasuperior: 0x02E0,
  27840. gangiacoptic: 0x03EB,
  27841. gbopomofo: 0x310D,
  27842. gbreve: 0x011F,
  27843. gcaron: 0x01E7,
  27844. gcedilla: 0x0123,
  27845. gcircle: 0x24D6,
  27846. gcircumflex: 0x011D,
  27847. gcommaaccent: 0x0123,
  27848. gdot: 0x0121,
  27849. gdotaccent: 0x0121,
  27850. gecyrillic: 0x0433,
  27851. gehiragana: 0x3052,
  27852. gekatakana: 0x30B2,
  27853. geometricallyequal: 0x2251,
  27854. gereshaccenthebrew: 0x059C,
  27855. gereshhebrew: 0x05F3,
  27856. gereshmuqdamhebrew: 0x059D,
  27857. germandbls: 0x00DF,
  27858. gershayimaccenthebrew: 0x059E,
  27859. gershayimhebrew: 0x05F4,
  27860. getamark: 0x3013,
  27861. ghabengali: 0x0998,
  27862. ghadarmenian: 0x0572,
  27863. ghadeva: 0x0918,
  27864. ghagujarati: 0x0A98,
  27865. ghagurmukhi: 0x0A18,
  27866. ghainarabic: 0x063A,
  27867. ghainfinalarabic: 0xFECE,
  27868. ghaininitialarabic: 0xFECF,
  27869. ghainmedialarabic: 0xFED0,
  27870. ghemiddlehookcyrillic: 0x0495,
  27871. ghestrokecyrillic: 0x0493,
  27872. gheupturncyrillic: 0x0491,
  27873. ghhadeva: 0x095A,
  27874. ghhagurmukhi: 0x0A5A,
  27875. ghook: 0x0260,
  27876. ghzsquare: 0x3393,
  27877. gihiragana: 0x304E,
  27878. gikatakana: 0x30AE,
  27879. gimarmenian: 0x0563,
  27880. gimel: 0x05D2,
  27881. gimeldagesh: 0xFB32,
  27882. gimeldageshhebrew: 0xFB32,
  27883. gimelhebrew: 0x05D2,
  27884. gjecyrillic: 0x0453,
  27885. glottalinvertedstroke: 0x01BE,
  27886. glottalstop: 0x0294,
  27887. glottalstopinverted: 0x0296,
  27888. glottalstopmod: 0x02C0,
  27889. glottalstopreversed: 0x0295,
  27890. glottalstopreversedmod: 0x02C1,
  27891. glottalstopreversedsuperior: 0x02E4,
  27892. glottalstopstroke: 0x02A1,
  27893. glottalstopstrokereversed: 0x02A2,
  27894. gmacron: 0x1E21,
  27895. gmonospace: 0xFF47,
  27896. gohiragana: 0x3054,
  27897. gokatakana: 0x30B4,
  27898. gparen: 0x24A2,
  27899. gpasquare: 0x33AC,
  27900. gradient: 0x2207,
  27901. grave: 0x0060,
  27902. gravebelowcmb: 0x0316,
  27903. gravecmb: 0x0300,
  27904. gravecomb: 0x0300,
  27905. gravedeva: 0x0953,
  27906. gravelowmod: 0x02CE,
  27907. gravemonospace: 0xFF40,
  27908. gravetonecmb: 0x0340,
  27909. greater: 0x003E,
  27910. greaterequal: 0x2265,
  27911. greaterequalorless: 0x22DB,
  27912. greatermonospace: 0xFF1E,
  27913. greaterorequivalent: 0x2273,
  27914. greaterorless: 0x2277,
  27915. greateroverequal: 0x2267,
  27916. greatersmall: 0xFE65,
  27917. gscript: 0x0261,
  27918. gstroke: 0x01E5,
  27919. guhiragana: 0x3050,
  27920. guillemotleft: 0x00AB,
  27921. guillemotright: 0x00BB,
  27922. guilsinglleft: 0x2039,
  27923. guilsinglright: 0x203A,
  27924. gukatakana: 0x30B0,
  27925. guramusquare: 0x3318,
  27926. gysquare: 0x33C9,
  27927. h: 0x0068,
  27928. haabkhasiancyrillic: 0x04A9,
  27929. haaltonearabic: 0x06C1,
  27930. habengali: 0x09B9,
  27931. hadescendercyrillic: 0x04B3,
  27932. hadeva: 0x0939,
  27933. hagujarati: 0x0AB9,
  27934. hagurmukhi: 0x0A39,
  27935. haharabic: 0x062D,
  27936. hahfinalarabic: 0xFEA2,
  27937. hahinitialarabic: 0xFEA3,
  27938. hahiragana: 0x306F,
  27939. hahmedialarabic: 0xFEA4,
  27940. haitusquare: 0x332A,
  27941. hakatakana: 0x30CF,
  27942. hakatakanahalfwidth: 0xFF8A,
  27943. halantgurmukhi: 0x0A4D,
  27944. hamzaarabic: 0x0621,
  27945. hamzalowarabic: 0x0621,
  27946. hangulfiller: 0x3164,
  27947. hardsigncyrillic: 0x044A,
  27948. harpoonleftbarbup: 0x21BC,
  27949. harpoonrightbarbup: 0x21C0,
  27950. hasquare: 0x33CA,
  27951. hatafpatah: 0x05B2,
  27952. hatafpatah16: 0x05B2,
  27953. hatafpatah23: 0x05B2,
  27954. hatafpatah2f: 0x05B2,
  27955. hatafpatahhebrew: 0x05B2,
  27956. hatafpatahnarrowhebrew: 0x05B2,
  27957. hatafpatahquarterhebrew: 0x05B2,
  27958. hatafpatahwidehebrew: 0x05B2,
  27959. hatafqamats: 0x05B3,
  27960. hatafqamats1b: 0x05B3,
  27961. hatafqamats28: 0x05B3,
  27962. hatafqamats34: 0x05B3,
  27963. hatafqamatshebrew: 0x05B3,
  27964. hatafqamatsnarrowhebrew: 0x05B3,
  27965. hatafqamatsquarterhebrew: 0x05B3,
  27966. hatafqamatswidehebrew: 0x05B3,
  27967. hatafsegol: 0x05B1,
  27968. hatafsegol17: 0x05B1,
  27969. hatafsegol24: 0x05B1,
  27970. hatafsegol30: 0x05B1,
  27971. hatafsegolhebrew: 0x05B1,
  27972. hatafsegolnarrowhebrew: 0x05B1,
  27973. hatafsegolquarterhebrew: 0x05B1,
  27974. hatafsegolwidehebrew: 0x05B1,
  27975. hbar: 0x0127,
  27976. hbopomofo: 0x310F,
  27977. hbrevebelow: 0x1E2B,
  27978. hcedilla: 0x1E29,
  27979. hcircle: 0x24D7,
  27980. hcircumflex: 0x0125,
  27981. hdieresis: 0x1E27,
  27982. hdotaccent: 0x1E23,
  27983. hdotbelow: 0x1E25,
  27984. he: 0x05D4,
  27985. heart: 0x2665,
  27986. heartsuitblack: 0x2665,
  27987. heartsuitwhite: 0x2661,
  27988. hedagesh: 0xFB34,
  27989. hedageshhebrew: 0xFB34,
  27990. hehaltonearabic: 0x06C1,
  27991. heharabic: 0x0647,
  27992. hehebrew: 0x05D4,
  27993. hehfinalaltonearabic: 0xFBA7,
  27994. hehfinalalttwoarabic: 0xFEEA,
  27995. hehfinalarabic: 0xFEEA,
  27996. hehhamzaabovefinalarabic: 0xFBA5,
  27997. hehhamzaaboveisolatedarabic: 0xFBA4,
  27998. hehinitialaltonearabic: 0xFBA8,
  27999. hehinitialarabic: 0xFEEB,
  28000. hehiragana: 0x3078,
  28001. hehmedialaltonearabic: 0xFBA9,
  28002. hehmedialarabic: 0xFEEC,
  28003. heiseierasquare: 0x337B,
  28004. hekatakana: 0x30D8,
  28005. hekatakanahalfwidth: 0xFF8D,
  28006. hekutaarusquare: 0x3336,
  28007. henghook: 0x0267,
  28008. herutusquare: 0x3339,
  28009. het: 0x05D7,
  28010. hethebrew: 0x05D7,
  28011. hhook: 0x0266,
  28012. hhooksuperior: 0x02B1,
  28013. hieuhacirclekorean: 0x327B,
  28014. hieuhaparenkorean: 0x321B,
  28015. hieuhcirclekorean: 0x326D,
  28016. hieuhkorean: 0x314E,
  28017. hieuhparenkorean: 0x320D,
  28018. hihiragana: 0x3072,
  28019. hikatakana: 0x30D2,
  28020. hikatakanahalfwidth: 0xFF8B,
  28021. hiriq: 0x05B4,
  28022. hiriq14: 0x05B4,
  28023. hiriq21: 0x05B4,
  28024. hiriq2d: 0x05B4,
  28025. hiriqhebrew: 0x05B4,
  28026. hiriqnarrowhebrew: 0x05B4,
  28027. hiriqquarterhebrew: 0x05B4,
  28028. hiriqwidehebrew: 0x05B4,
  28029. hlinebelow: 0x1E96,
  28030. hmonospace: 0xFF48,
  28031. hoarmenian: 0x0570,
  28032. hohipthai: 0x0E2B,
  28033. hohiragana: 0x307B,
  28034. hokatakana: 0x30DB,
  28035. hokatakanahalfwidth: 0xFF8E,
  28036. holam: 0x05B9,
  28037. holam19: 0x05B9,
  28038. holam26: 0x05B9,
  28039. holam32: 0x05B9,
  28040. holamhebrew: 0x05B9,
  28041. holamnarrowhebrew: 0x05B9,
  28042. holamquarterhebrew: 0x05B9,
  28043. holamwidehebrew: 0x05B9,
  28044. honokhukthai: 0x0E2E,
  28045. hookabovecomb: 0x0309,
  28046. hookcmb: 0x0309,
  28047. hookpalatalizedbelowcmb: 0x0321,
  28048. hookretroflexbelowcmb: 0x0322,
  28049. hoonsquare: 0x3342,
  28050. horicoptic: 0x03E9,
  28051. horizontalbar: 0x2015,
  28052. horncmb: 0x031B,
  28053. hotsprings: 0x2668,
  28054. house: 0x2302,
  28055. hparen: 0x24A3,
  28056. hsuperior: 0x02B0,
  28057. hturned: 0x0265,
  28058. huhiragana: 0x3075,
  28059. huiitosquare: 0x3333,
  28060. hukatakana: 0x30D5,
  28061. hukatakanahalfwidth: 0xFF8C,
  28062. hungarumlaut: 0x02DD,
  28063. hungarumlautcmb: 0x030B,
  28064. hv: 0x0195,
  28065. hyphen: 0x002D,
  28066. hypheninferior: 0xF6E5,
  28067. hyphenmonospace: 0xFF0D,
  28068. hyphensmall: 0xFE63,
  28069. hyphensuperior: 0xF6E6,
  28070. hyphentwo: 0x2010,
  28071. i: 0x0069,
  28072. iacute: 0x00ED,
  28073. iacyrillic: 0x044F,
  28074. ibengali: 0x0987,
  28075. ibopomofo: 0x3127,
  28076. ibreve: 0x012D,
  28077. icaron: 0x01D0,
  28078. icircle: 0x24D8,
  28079. icircumflex: 0x00EE,
  28080. icyrillic: 0x0456,
  28081. idblgrave: 0x0209,
  28082. ideographearthcircle: 0x328F,
  28083. ideographfirecircle: 0x328B,
  28084. ideographicallianceparen: 0x323F,
  28085. ideographiccallparen: 0x323A,
  28086. ideographiccentrecircle: 0x32A5,
  28087. ideographicclose: 0x3006,
  28088. ideographiccomma: 0x3001,
  28089. ideographiccommaleft: 0xFF64,
  28090. ideographiccongratulationparen: 0x3237,
  28091. ideographiccorrectcircle: 0x32A3,
  28092. ideographicearthparen: 0x322F,
  28093. ideographicenterpriseparen: 0x323D,
  28094. ideographicexcellentcircle: 0x329D,
  28095. ideographicfestivalparen: 0x3240,
  28096. ideographicfinancialcircle: 0x3296,
  28097. ideographicfinancialparen: 0x3236,
  28098. ideographicfireparen: 0x322B,
  28099. ideographichaveparen: 0x3232,
  28100. ideographichighcircle: 0x32A4,
  28101. ideographiciterationmark: 0x3005,
  28102. ideographiclaborcircle: 0x3298,
  28103. ideographiclaborparen: 0x3238,
  28104. ideographicleftcircle: 0x32A7,
  28105. ideographiclowcircle: 0x32A6,
  28106. ideographicmedicinecircle: 0x32A9,
  28107. ideographicmetalparen: 0x322E,
  28108. ideographicmoonparen: 0x322A,
  28109. ideographicnameparen: 0x3234,
  28110. ideographicperiod: 0x3002,
  28111. ideographicprintcircle: 0x329E,
  28112. ideographicreachparen: 0x3243,
  28113. ideographicrepresentparen: 0x3239,
  28114. ideographicresourceparen: 0x323E,
  28115. ideographicrightcircle: 0x32A8,
  28116. ideographicsecretcircle: 0x3299,
  28117. ideographicselfparen: 0x3242,
  28118. ideographicsocietyparen: 0x3233,
  28119. ideographicspace: 0x3000,
  28120. ideographicspecialparen: 0x3235,
  28121. ideographicstockparen: 0x3231,
  28122. ideographicstudyparen: 0x323B,
  28123. ideographicsunparen: 0x3230,
  28124. ideographicsuperviseparen: 0x323C,
  28125. ideographicwaterparen: 0x322C,
  28126. ideographicwoodparen: 0x322D,
  28127. ideographiczero: 0x3007,
  28128. ideographmetalcircle: 0x328E,
  28129. ideographmooncircle: 0x328A,
  28130. ideographnamecircle: 0x3294,
  28131. ideographsuncircle: 0x3290,
  28132. ideographwatercircle: 0x328C,
  28133. ideographwoodcircle: 0x328D,
  28134. ideva: 0x0907,
  28135. idieresis: 0x00EF,
  28136. idieresisacute: 0x1E2F,
  28137. idieresiscyrillic: 0x04E5,
  28138. idotbelow: 0x1ECB,
  28139. iebrevecyrillic: 0x04D7,
  28140. iecyrillic: 0x0435,
  28141. ieungacirclekorean: 0x3275,
  28142. ieungaparenkorean: 0x3215,
  28143. ieungcirclekorean: 0x3267,
  28144. ieungkorean: 0x3147,
  28145. ieungparenkorean: 0x3207,
  28146. igrave: 0x00EC,
  28147. igujarati: 0x0A87,
  28148. igurmukhi: 0x0A07,
  28149. ihiragana: 0x3044,
  28150. ihookabove: 0x1EC9,
  28151. iibengali: 0x0988,
  28152. iicyrillic: 0x0438,
  28153. iideva: 0x0908,
  28154. iigujarati: 0x0A88,
  28155. iigurmukhi: 0x0A08,
  28156. iimatragurmukhi: 0x0A40,
  28157. iinvertedbreve: 0x020B,
  28158. iishortcyrillic: 0x0439,
  28159. iivowelsignbengali: 0x09C0,
  28160. iivowelsigndeva: 0x0940,
  28161. iivowelsigngujarati: 0x0AC0,
  28162. ij: 0x0133,
  28163. ikatakana: 0x30A4,
  28164. ikatakanahalfwidth: 0xFF72,
  28165. ikorean: 0x3163,
  28166. ilde: 0x02DC,
  28167. iluyhebrew: 0x05AC,
  28168. imacron: 0x012B,
  28169. imacroncyrillic: 0x04E3,
  28170. imageorapproximatelyequal: 0x2253,
  28171. imatragurmukhi: 0x0A3F,
  28172. imonospace: 0xFF49,
  28173. increment: 0x2206,
  28174. infinity: 0x221E,
  28175. iniarmenian: 0x056B,
  28176. integral: 0x222B,
  28177. integralbottom: 0x2321,
  28178. integralbt: 0x2321,
  28179. integralex: 0xF8F5,
  28180. integraltop: 0x2320,
  28181. integraltp: 0x2320,
  28182. intersection: 0x2229,
  28183. intisquare: 0x3305,
  28184. invbullet: 0x25D8,
  28185. invcircle: 0x25D9,
  28186. invsmileface: 0x263B,
  28187. iocyrillic: 0x0451,
  28188. iogonek: 0x012F,
  28189. iota: 0x03B9,
  28190. iotadieresis: 0x03CA,
  28191. iotadieresistonos: 0x0390,
  28192. iotalatin: 0x0269,
  28193. iotatonos: 0x03AF,
  28194. iparen: 0x24A4,
  28195. irigurmukhi: 0x0A72,
  28196. ismallhiragana: 0x3043,
  28197. ismallkatakana: 0x30A3,
  28198. ismallkatakanahalfwidth: 0xFF68,
  28199. issharbengali: 0x09FA,
  28200. istroke: 0x0268,
  28201. isuperior: 0xF6ED,
  28202. iterationhiragana: 0x309D,
  28203. iterationkatakana: 0x30FD,
  28204. itilde: 0x0129,
  28205. itildebelow: 0x1E2D,
  28206. iubopomofo: 0x3129,
  28207. iucyrillic: 0x044E,
  28208. ivowelsignbengali: 0x09BF,
  28209. ivowelsigndeva: 0x093F,
  28210. ivowelsigngujarati: 0x0ABF,
  28211. izhitsacyrillic: 0x0475,
  28212. izhitsadblgravecyrillic: 0x0477,
  28213. j: 0x006A,
  28214. jaarmenian: 0x0571,
  28215. jabengali: 0x099C,
  28216. jadeva: 0x091C,
  28217. jagujarati: 0x0A9C,
  28218. jagurmukhi: 0x0A1C,
  28219. jbopomofo: 0x3110,
  28220. jcaron: 0x01F0,
  28221. jcircle: 0x24D9,
  28222. jcircumflex: 0x0135,
  28223. jcrossedtail: 0x029D,
  28224. jdotlessstroke: 0x025F,
  28225. jecyrillic: 0x0458,
  28226. jeemarabic: 0x062C,
  28227. jeemfinalarabic: 0xFE9E,
  28228. jeeminitialarabic: 0xFE9F,
  28229. jeemmedialarabic: 0xFEA0,
  28230. jeharabic: 0x0698,
  28231. jehfinalarabic: 0xFB8B,
  28232. jhabengali: 0x099D,
  28233. jhadeva: 0x091D,
  28234. jhagujarati: 0x0A9D,
  28235. jhagurmukhi: 0x0A1D,
  28236. jheharmenian: 0x057B,
  28237. jis: 0x3004,
  28238. jmonospace: 0xFF4A,
  28239. jparen: 0x24A5,
  28240. jsuperior: 0x02B2,
  28241. k: 0x006B,
  28242. kabashkircyrillic: 0x04A1,
  28243. kabengali: 0x0995,
  28244. kacute: 0x1E31,
  28245. kacyrillic: 0x043A,
  28246. kadescendercyrillic: 0x049B,
  28247. kadeva: 0x0915,
  28248. kaf: 0x05DB,
  28249. kafarabic: 0x0643,
  28250. kafdagesh: 0xFB3B,
  28251. kafdageshhebrew: 0xFB3B,
  28252. kaffinalarabic: 0xFEDA,
  28253. kafhebrew: 0x05DB,
  28254. kafinitialarabic: 0xFEDB,
  28255. kafmedialarabic: 0xFEDC,
  28256. kafrafehebrew: 0xFB4D,
  28257. kagujarati: 0x0A95,
  28258. kagurmukhi: 0x0A15,
  28259. kahiragana: 0x304B,
  28260. kahookcyrillic: 0x04C4,
  28261. kakatakana: 0x30AB,
  28262. kakatakanahalfwidth: 0xFF76,
  28263. kappa: 0x03BA,
  28264. kappasymbolgreek: 0x03F0,
  28265. kapyeounmieumkorean: 0x3171,
  28266. kapyeounphieuphkorean: 0x3184,
  28267. kapyeounpieupkorean: 0x3178,
  28268. kapyeounssangpieupkorean: 0x3179,
  28269. karoriisquare: 0x330D,
  28270. kashidaautoarabic: 0x0640,
  28271. kashidaautonosidebearingarabic: 0x0640,
  28272. kasmallkatakana: 0x30F5,
  28273. kasquare: 0x3384,
  28274. kasraarabic: 0x0650,
  28275. kasratanarabic: 0x064D,
  28276. kastrokecyrillic: 0x049F,
  28277. katahiraprolongmarkhalfwidth: 0xFF70,
  28278. kaverticalstrokecyrillic: 0x049D,
  28279. kbopomofo: 0x310E,
  28280. kcalsquare: 0x3389,
  28281. kcaron: 0x01E9,
  28282. kcedilla: 0x0137,
  28283. kcircle: 0x24DA,
  28284. kcommaaccent: 0x0137,
  28285. kdotbelow: 0x1E33,
  28286. keharmenian: 0x0584,
  28287. kehiragana: 0x3051,
  28288. kekatakana: 0x30B1,
  28289. kekatakanahalfwidth: 0xFF79,
  28290. kenarmenian: 0x056F,
  28291. kesmallkatakana: 0x30F6,
  28292. kgreenlandic: 0x0138,
  28293. khabengali: 0x0996,
  28294. khacyrillic: 0x0445,
  28295. khadeva: 0x0916,
  28296. khagujarati: 0x0A96,
  28297. khagurmukhi: 0x0A16,
  28298. khaharabic: 0x062E,
  28299. khahfinalarabic: 0xFEA6,
  28300. khahinitialarabic: 0xFEA7,
  28301. khahmedialarabic: 0xFEA8,
  28302. kheicoptic: 0x03E7,
  28303. khhadeva: 0x0959,
  28304. khhagurmukhi: 0x0A59,
  28305. khieukhacirclekorean: 0x3278,
  28306. khieukhaparenkorean: 0x3218,
  28307. khieukhcirclekorean: 0x326A,
  28308. khieukhkorean: 0x314B,
  28309. khieukhparenkorean: 0x320A,
  28310. khokhaithai: 0x0E02,
  28311. khokhonthai: 0x0E05,
  28312. khokhuatthai: 0x0E03,
  28313. khokhwaithai: 0x0E04,
  28314. khomutthai: 0x0E5B,
  28315. khook: 0x0199,
  28316. khorakhangthai: 0x0E06,
  28317. khzsquare: 0x3391,
  28318. kihiragana: 0x304D,
  28319. kikatakana: 0x30AD,
  28320. kikatakanahalfwidth: 0xFF77,
  28321. kiroguramusquare: 0x3315,
  28322. kiromeetorusquare: 0x3316,
  28323. kirosquare: 0x3314,
  28324. kiyeokacirclekorean: 0x326E,
  28325. kiyeokaparenkorean: 0x320E,
  28326. kiyeokcirclekorean: 0x3260,
  28327. kiyeokkorean: 0x3131,
  28328. kiyeokparenkorean: 0x3200,
  28329. kiyeoksioskorean: 0x3133,
  28330. kjecyrillic: 0x045C,
  28331. klinebelow: 0x1E35,
  28332. klsquare: 0x3398,
  28333. kmcubedsquare: 0x33A6,
  28334. kmonospace: 0xFF4B,
  28335. kmsquaredsquare: 0x33A2,
  28336. kohiragana: 0x3053,
  28337. kohmsquare: 0x33C0,
  28338. kokaithai: 0x0E01,
  28339. kokatakana: 0x30B3,
  28340. kokatakanahalfwidth: 0xFF7A,
  28341. kooposquare: 0x331E,
  28342. koppacyrillic: 0x0481,
  28343. koreanstandardsymbol: 0x327F,
  28344. koroniscmb: 0x0343,
  28345. kparen: 0x24A6,
  28346. kpasquare: 0x33AA,
  28347. ksicyrillic: 0x046F,
  28348. ktsquare: 0x33CF,
  28349. kturned: 0x029E,
  28350. kuhiragana: 0x304F,
  28351. kukatakana: 0x30AF,
  28352. kukatakanahalfwidth: 0xFF78,
  28353. kvsquare: 0x33B8,
  28354. kwsquare: 0x33BE,
  28355. l: 0x006C,
  28356. labengali: 0x09B2,
  28357. lacute: 0x013A,
  28358. ladeva: 0x0932,
  28359. lagujarati: 0x0AB2,
  28360. lagurmukhi: 0x0A32,
  28361. lakkhangyaothai: 0x0E45,
  28362. lamaleffinalarabic: 0xFEFC,
  28363. lamalefhamzaabovefinalarabic: 0xFEF8,
  28364. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  28365. lamalefhamzabelowfinalarabic: 0xFEFA,
  28366. lamalefhamzabelowisolatedarabic: 0xFEF9,
  28367. lamalefisolatedarabic: 0xFEFB,
  28368. lamalefmaddaabovefinalarabic: 0xFEF6,
  28369. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  28370. lamarabic: 0x0644,
  28371. lambda: 0x03BB,
  28372. lambdastroke: 0x019B,
  28373. lamed: 0x05DC,
  28374. lameddagesh: 0xFB3C,
  28375. lameddageshhebrew: 0xFB3C,
  28376. lamedhebrew: 0x05DC,
  28377. lamfinalarabic: 0xFEDE,
  28378. lamhahinitialarabic: 0xFCCA,
  28379. laminitialarabic: 0xFEDF,
  28380. lamjeeminitialarabic: 0xFCC9,
  28381. lamkhahinitialarabic: 0xFCCB,
  28382. lamlamhehisolatedarabic: 0xFDF2,
  28383. lammedialarabic: 0xFEE0,
  28384. lammeemhahinitialarabic: 0xFD88,
  28385. lammeeminitialarabic: 0xFCCC,
  28386. largecircle: 0x25EF,
  28387. lbar: 0x019A,
  28388. lbelt: 0x026C,
  28389. lbopomofo: 0x310C,
  28390. lcaron: 0x013E,
  28391. lcedilla: 0x013C,
  28392. lcircle: 0x24DB,
  28393. lcircumflexbelow: 0x1E3D,
  28394. lcommaaccent: 0x013C,
  28395. ldot: 0x0140,
  28396. ldotaccent: 0x0140,
  28397. ldotbelow: 0x1E37,
  28398. ldotbelowmacron: 0x1E39,
  28399. leftangleabovecmb: 0x031A,
  28400. lefttackbelowcmb: 0x0318,
  28401. less: 0x003C,
  28402. lessequal: 0x2264,
  28403. lessequalorgreater: 0x22DA,
  28404. lessmonospace: 0xFF1C,
  28405. lessorequivalent: 0x2272,
  28406. lessorgreater: 0x2276,
  28407. lessoverequal: 0x2266,
  28408. lesssmall: 0xFE64,
  28409. lezh: 0x026E,
  28410. lfblock: 0x258C,
  28411. lhookretroflex: 0x026D,
  28412. lira: 0x20A4,
  28413. liwnarmenian: 0x056C,
  28414. lj: 0x01C9,
  28415. ljecyrillic: 0x0459,
  28416. ll: 0xF6C0,
  28417. lladeva: 0x0933,
  28418. llagujarati: 0x0AB3,
  28419. llinebelow: 0x1E3B,
  28420. llladeva: 0x0934,
  28421. llvocalicbengali: 0x09E1,
  28422. llvocalicdeva: 0x0961,
  28423. llvocalicvowelsignbengali: 0x09E3,
  28424. llvocalicvowelsigndeva: 0x0963,
  28425. lmiddletilde: 0x026B,
  28426. lmonospace: 0xFF4C,
  28427. lmsquare: 0x33D0,
  28428. lochulathai: 0x0E2C,
  28429. logicaland: 0x2227,
  28430. logicalnot: 0x00AC,
  28431. logicalnotreversed: 0x2310,
  28432. logicalor: 0x2228,
  28433. lolingthai: 0x0E25,
  28434. longs: 0x017F,
  28435. lowlinecenterline: 0xFE4E,
  28436. lowlinecmb: 0x0332,
  28437. lowlinedashed: 0xFE4D,
  28438. lozenge: 0x25CA,
  28439. lparen: 0x24A7,
  28440. lslash: 0x0142,
  28441. lsquare: 0x2113,
  28442. lsuperior: 0xF6EE,
  28443. ltshade: 0x2591,
  28444. luthai: 0x0E26,
  28445. lvocalicbengali: 0x098C,
  28446. lvocalicdeva: 0x090C,
  28447. lvocalicvowelsignbengali: 0x09E2,
  28448. lvocalicvowelsigndeva: 0x0962,
  28449. lxsquare: 0x33D3,
  28450. m: 0x006D,
  28451. mabengali: 0x09AE,
  28452. macron: 0x00AF,
  28453. macronbelowcmb: 0x0331,
  28454. macroncmb: 0x0304,
  28455. macronlowmod: 0x02CD,
  28456. macronmonospace: 0xFFE3,
  28457. macute: 0x1E3F,
  28458. madeva: 0x092E,
  28459. magujarati: 0x0AAE,
  28460. magurmukhi: 0x0A2E,
  28461. mahapakhhebrew: 0x05A4,
  28462. mahapakhlefthebrew: 0x05A4,
  28463. mahiragana: 0x307E,
  28464. maichattawalowleftthai: 0xF895,
  28465. maichattawalowrightthai: 0xF894,
  28466. maichattawathai: 0x0E4B,
  28467. maichattawaupperleftthai: 0xF893,
  28468. maieklowleftthai: 0xF88C,
  28469. maieklowrightthai: 0xF88B,
  28470. maiekthai: 0x0E48,
  28471. maiekupperleftthai: 0xF88A,
  28472. maihanakatleftthai: 0xF884,
  28473. maihanakatthai: 0x0E31,
  28474. maitaikhuleftthai: 0xF889,
  28475. maitaikhuthai: 0x0E47,
  28476. maitholowleftthai: 0xF88F,
  28477. maitholowrightthai: 0xF88E,
  28478. maithothai: 0x0E49,
  28479. maithoupperleftthai: 0xF88D,
  28480. maitrilowleftthai: 0xF892,
  28481. maitrilowrightthai: 0xF891,
  28482. maitrithai: 0x0E4A,
  28483. maitriupperleftthai: 0xF890,
  28484. maiyamokthai: 0x0E46,
  28485. makatakana: 0x30DE,
  28486. makatakanahalfwidth: 0xFF8F,
  28487. male: 0x2642,
  28488. mansyonsquare: 0x3347,
  28489. maqafhebrew: 0x05BE,
  28490. mars: 0x2642,
  28491. masoracirclehebrew: 0x05AF,
  28492. masquare: 0x3383,
  28493. mbopomofo: 0x3107,
  28494. mbsquare: 0x33D4,
  28495. mcircle: 0x24DC,
  28496. mcubedsquare: 0x33A5,
  28497. mdotaccent: 0x1E41,
  28498. mdotbelow: 0x1E43,
  28499. meemarabic: 0x0645,
  28500. meemfinalarabic: 0xFEE2,
  28501. meeminitialarabic: 0xFEE3,
  28502. meemmedialarabic: 0xFEE4,
  28503. meemmeeminitialarabic: 0xFCD1,
  28504. meemmeemisolatedarabic: 0xFC48,
  28505. meetorusquare: 0x334D,
  28506. mehiragana: 0x3081,
  28507. meizierasquare: 0x337E,
  28508. mekatakana: 0x30E1,
  28509. mekatakanahalfwidth: 0xFF92,
  28510. mem: 0x05DE,
  28511. memdagesh: 0xFB3E,
  28512. memdageshhebrew: 0xFB3E,
  28513. memhebrew: 0x05DE,
  28514. menarmenian: 0x0574,
  28515. merkhahebrew: 0x05A5,
  28516. merkhakefulahebrew: 0x05A6,
  28517. merkhakefulalefthebrew: 0x05A6,
  28518. merkhalefthebrew: 0x05A5,
  28519. mhook: 0x0271,
  28520. mhzsquare: 0x3392,
  28521. middledotkatakanahalfwidth: 0xFF65,
  28522. middot: 0x00B7,
  28523. mieumacirclekorean: 0x3272,
  28524. mieumaparenkorean: 0x3212,
  28525. mieumcirclekorean: 0x3264,
  28526. mieumkorean: 0x3141,
  28527. mieumpansioskorean: 0x3170,
  28528. mieumparenkorean: 0x3204,
  28529. mieumpieupkorean: 0x316E,
  28530. mieumsioskorean: 0x316F,
  28531. mihiragana: 0x307F,
  28532. mikatakana: 0x30DF,
  28533. mikatakanahalfwidth: 0xFF90,
  28534. minus: 0x2212,
  28535. minusbelowcmb: 0x0320,
  28536. minuscircle: 0x2296,
  28537. minusmod: 0x02D7,
  28538. minusplus: 0x2213,
  28539. minute: 0x2032,
  28540. miribaarusquare: 0x334A,
  28541. mirisquare: 0x3349,
  28542. mlonglegturned: 0x0270,
  28543. mlsquare: 0x3396,
  28544. mmcubedsquare: 0x33A3,
  28545. mmonospace: 0xFF4D,
  28546. mmsquaredsquare: 0x339F,
  28547. mohiragana: 0x3082,
  28548. mohmsquare: 0x33C1,
  28549. mokatakana: 0x30E2,
  28550. mokatakanahalfwidth: 0xFF93,
  28551. molsquare: 0x33D6,
  28552. momathai: 0x0E21,
  28553. moverssquare: 0x33A7,
  28554. moverssquaredsquare: 0x33A8,
  28555. mparen: 0x24A8,
  28556. mpasquare: 0x33AB,
  28557. mssquare: 0x33B3,
  28558. msuperior: 0xF6EF,
  28559. mturned: 0x026F,
  28560. mu: 0x00B5,
  28561. mu1: 0x00B5,
  28562. muasquare: 0x3382,
  28563. muchgreater: 0x226B,
  28564. muchless: 0x226A,
  28565. mufsquare: 0x338C,
  28566. mugreek: 0x03BC,
  28567. mugsquare: 0x338D,
  28568. muhiragana: 0x3080,
  28569. mukatakana: 0x30E0,
  28570. mukatakanahalfwidth: 0xFF91,
  28571. mulsquare: 0x3395,
  28572. multiply: 0x00D7,
  28573. mumsquare: 0x339B,
  28574. munahhebrew: 0x05A3,
  28575. munahlefthebrew: 0x05A3,
  28576. musicalnote: 0x266A,
  28577. musicalnotedbl: 0x266B,
  28578. musicflatsign: 0x266D,
  28579. musicsharpsign: 0x266F,
  28580. mussquare: 0x33B2,
  28581. muvsquare: 0x33B6,
  28582. muwsquare: 0x33BC,
  28583. mvmegasquare: 0x33B9,
  28584. mvsquare: 0x33B7,
  28585. mwmegasquare: 0x33BF,
  28586. mwsquare: 0x33BD,
  28587. n: 0x006E,
  28588. nabengali: 0x09A8,
  28589. nabla: 0x2207,
  28590. nacute: 0x0144,
  28591. nadeva: 0x0928,
  28592. nagujarati: 0x0AA8,
  28593. nagurmukhi: 0x0A28,
  28594. nahiragana: 0x306A,
  28595. nakatakana: 0x30CA,
  28596. nakatakanahalfwidth: 0xFF85,
  28597. napostrophe: 0x0149,
  28598. nasquare: 0x3381,
  28599. nbopomofo: 0x310B,
  28600. nbspace: 0x00A0,
  28601. ncaron: 0x0148,
  28602. ncedilla: 0x0146,
  28603. ncircle: 0x24DD,
  28604. ncircumflexbelow: 0x1E4B,
  28605. ncommaaccent: 0x0146,
  28606. ndotaccent: 0x1E45,
  28607. ndotbelow: 0x1E47,
  28608. nehiragana: 0x306D,
  28609. nekatakana: 0x30CD,
  28610. nekatakanahalfwidth: 0xFF88,
  28611. newsheqelsign: 0x20AA,
  28612. nfsquare: 0x338B,
  28613. ngabengali: 0x0999,
  28614. ngadeva: 0x0919,
  28615. ngagujarati: 0x0A99,
  28616. ngagurmukhi: 0x0A19,
  28617. ngonguthai: 0x0E07,
  28618. nhiragana: 0x3093,
  28619. nhookleft: 0x0272,
  28620. nhookretroflex: 0x0273,
  28621. nieunacirclekorean: 0x326F,
  28622. nieunaparenkorean: 0x320F,
  28623. nieuncieuckorean: 0x3135,
  28624. nieuncirclekorean: 0x3261,
  28625. nieunhieuhkorean: 0x3136,
  28626. nieunkorean: 0x3134,
  28627. nieunpansioskorean: 0x3168,
  28628. nieunparenkorean: 0x3201,
  28629. nieunsioskorean: 0x3167,
  28630. nieuntikeutkorean: 0x3166,
  28631. nihiragana: 0x306B,
  28632. nikatakana: 0x30CB,
  28633. nikatakanahalfwidth: 0xFF86,
  28634. nikhahitleftthai: 0xF899,
  28635. nikhahitthai: 0x0E4D,
  28636. nine: 0x0039,
  28637. ninearabic: 0x0669,
  28638. ninebengali: 0x09EF,
  28639. ninecircle: 0x2468,
  28640. ninecircleinversesansserif: 0x2792,
  28641. ninedeva: 0x096F,
  28642. ninegujarati: 0x0AEF,
  28643. ninegurmukhi: 0x0A6F,
  28644. ninehackarabic: 0x0669,
  28645. ninehangzhou: 0x3029,
  28646. nineideographicparen: 0x3228,
  28647. nineinferior: 0x2089,
  28648. ninemonospace: 0xFF19,
  28649. nineoldstyle: 0xF739,
  28650. nineparen: 0x247C,
  28651. nineperiod: 0x2490,
  28652. ninepersian: 0x06F9,
  28653. nineroman: 0x2178,
  28654. ninesuperior: 0x2079,
  28655. nineteencircle: 0x2472,
  28656. nineteenparen: 0x2486,
  28657. nineteenperiod: 0x249A,
  28658. ninethai: 0x0E59,
  28659. nj: 0x01CC,
  28660. njecyrillic: 0x045A,
  28661. nkatakana: 0x30F3,
  28662. nkatakanahalfwidth: 0xFF9D,
  28663. nlegrightlong: 0x019E,
  28664. nlinebelow: 0x1E49,
  28665. nmonospace: 0xFF4E,
  28666. nmsquare: 0x339A,
  28667. nnabengali: 0x09A3,
  28668. nnadeva: 0x0923,
  28669. nnagujarati: 0x0AA3,
  28670. nnagurmukhi: 0x0A23,
  28671. nnnadeva: 0x0929,
  28672. nohiragana: 0x306E,
  28673. nokatakana: 0x30CE,
  28674. nokatakanahalfwidth: 0xFF89,
  28675. nonbreakingspace: 0x00A0,
  28676. nonenthai: 0x0E13,
  28677. nonuthai: 0x0E19,
  28678. noonarabic: 0x0646,
  28679. noonfinalarabic: 0xFEE6,
  28680. noonghunnaarabic: 0x06BA,
  28681. noonghunnafinalarabic: 0xFB9F,
  28682. nooninitialarabic: 0xFEE7,
  28683. noonjeeminitialarabic: 0xFCD2,
  28684. noonjeemisolatedarabic: 0xFC4B,
  28685. noonmedialarabic: 0xFEE8,
  28686. noonmeeminitialarabic: 0xFCD5,
  28687. noonmeemisolatedarabic: 0xFC4E,
  28688. noonnoonfinalarabic: 0xFC8D,
  28689. notcontains: 0x220C,
  28690. notelement: 0x2209,
  28691. notelementof: 0x2209,
  28692. notequal: 0x2260,
  28693. notgreater: 0x226F,
  28694. notgreaternorequal: 0x2271,
  28695. notgreaternorless: 0x2279,
  28696. notidentical: 0x2262,
  28697. notless: 0x226E,
  28698. notlessnorequal: 0x2270,
  28699. notparallel: 0x2226,
  28700. notprecedes: 0x2280,
  28701. notsubset: 0x2284,
  28702. notsucceeds: 0x2281,
  28703. notsuperset: 0x2285,
  28704. nowarmenian: 0x0576,
  28705. nparen: 0x24A9,
  28706. nssquare: 0x33B1,
  28707. nsuperior: 0x207F,
  28708. ntilde: 0x00F1,
  28709. nu: 0x03BD,
  28710. nuhiragana: 0x306C,
  28711. nukatakana: 0x30CC,
  28712. nukatakanahalfwidth: 0xFF87,
  28713. nuktabengali: 0x09BC,
  28714. nuktadeva: 0x093C,
  28715. nuktagujarati: 0x0ABC,
  28716. nuktagurmukhi: 0x0A3C,
  28717. numbersign: 0x0023,
  28718. numbersignmonospace: 0xFF03,
  28719. numbersignsmall: 0xFE5F,
  28720. numeralsigngreek: 0x0374,
  28721. numeralsignlowergreek: 0x0375,
  28722. numero: 0x2116,
  28723. nun: 0x05E0,
  28724. nundagesh: 0xFB40,
  28725. nundageshhebrew: 0xFB40,
  28726. nunhebrew: 0x05E0,
  28727. nvsquare: 0x33B5,
  28728. nwsquare: 0x33BB,
  28729. nyabengali: 0x099E,
  28730. nyadeva: 0x091E,
  28731. nyagujarati: 0x0A9E,
  28732. nyagurmukhi: 0x0A1E,
  28733. o: 0x006F,
  28734. oacute: 0x00F3,
  28735. oangthai: 0x0E2D,
  28736. obarred: 0x0275,
  28737. obarredcyrillic: 0x04E9,
  28738. obarreddieresiscyrillic: 0x04EB,
  28739. obengali: 0x0993,
  28740. obopomofo: 0x311B,
  28741. obreve: 0x014F,
  28742. ocandradeva: 0x0911,
  28743. ocandragujarati: 0x0A91,
  28744. ocandravowelsigndeva: 0x0949,
  28745. ocandravowelsigngujarati: 0x0AC9,
  28746. ocaron: 0x01D2,
  28747. ocircle: 0x24DE,
  28748. ocircumflex: 0x00F4,
  28749. ocircumflexacute: 0x1ED1,
  28750. ocircumflexdotbelow: 0x1ED9,
  28751. ocircumflexgrave: 0x1ED3,
  28752. ocircumflexhookabove: 0x1ED5,
  28753. ocircumflextilde: 0x1ED7,
  28754. ocyrillic: 0x043E,
  28755. odblacute: 0x0151,
  28756. odblgrave: 0x020D,
  28757. odeva: 0x0913,
  28758. odieresis: 0x00F6,
  28759. odieresiscyrillic: 0x04E7,
  28760. odotbelow: 0x1ECD,
  28761. oe: 0x0153,
  28762. oekorean: 0x315A,
  28763. ogonek: 0x02DB,
  28764. ogonekcmb: 0x0328,
  28765. ograve: 0x00F2,
  28766. ogujarati: 0x0A93,
  28767. oharmenian: 0x0585,
  28768. ohiragana: 0x304A,
  28769. ohookabove: 0x1ECF,
  28770. ohorn: 0x01A1,
  28771. ohornacute: 0x1EDB,
  28772. ohorndotbelow: 0x1EE3,
  28773. ohorngrave: 0x1EDD,
  28774. ohornhookabove: 0x1EDF,
  28775. ohorntilde: 0x1EE1,
  28776. ohungarumlaut: 0x0151,
  28777. oi: 0x01A3,
  28778. oinvertedbreve: 0x020F,
  28779. okatakana: 0x30AA,
  28780. okatakanahalfwidth: 0xFF75,
  28781. okorean: 0x3157,
  28782. olehebrew: 0x05AB,
  28783. omacron: 0x014D,
  28784. omacronacute: 0x1E53,
  28785. omacrongrave: 0x1E51,
  28786. omdeva: 0x0950,
  28787. omega: 0x03C9,
  28788. omega1: 0x03D6,
  28789. omegacyrillic: 0x0461,
  28790. omegalatinclosed: 0x0277,
  28791. omegaroundcyrillic: 0x047B,
  28792. omegatitlocyrillic: 0x047D,
  28793. omegatonos: 0x03CE,
  28794. omgujarati: 0x0AD0,
  28795. omicron: 0x03BF,
  28796. omicrontonos: 0x03CC,
  28797. omonospace: 0xFF4F,
  28798. one: 0x0031,
  28799. onearabic: 0x0661,
  28800. onebengali: 0x09E7,
  28801. onecircle: 0x2460,
  28802. onecircleinversesansserif: 0x278A,
  28803. onedeva: 0x0967,
  28804. onedotenleader: 0x2024,
  28805. oneeighth: 0x215B,
  28806. onefitted: 0xF6DC,
  28807. onegujarati: 0x0AE7,
  28808. onegurmukhi: 0x0A67,
  28809. onehackarabic: 0x0661,
  28810. onehalf: 0x00BD,
  28811. onehangzhou: 0x3021,
  28812. oneideographicparen: 0x3220,
  28813. oneinferior: 0x2081,
  28814. onemonospace: 0xFF11,
  28815. onenumeratorbengali: 0x09F4,
  28816. oneoldstyle: 0xF731,
  28817. oneparen: 0x2474,
  28818. oneperiod: 0x2488,
  28819. onepersian: 0x06F1,
  28820. onequarter: 0x00BC,
  28821. oneroman: 0x2170,
  28822. onesuperior: 0x00B9,
  28823. onethai: 0x0E51,
  28824. onethird: 0x2153,
  28825. oogonek: 0x01EB,
  28826. oogonekmacron: 0x01ED,
  28827. oogurmukhi: 0x0A13,
  28828. oomatragurmukhi: 0x0A4B,
  28829. oopen: 0x0254,
  28830. oparen: 0x24AA,
  28831. openbullet: 0x25E6,
  28832. option: 0x2325,
  28833. ordfeminine: 0x00AA,
  28834. ordmasculine: 0x00BA,
  28835. orthogonal: 0x221F,
  28836. oshortdeva: 0x0912,
  28837. oshortvowelsigndeva: 0x094A,
  28838. oslash: 0x00F8,
  28839. oslashacute: 0x01FF,
  28840. osmallhiragana: 0x3049,
  28841. osmallkatakana: 0x30A9,
  28842. osmallkatakanahalfwidth: 0xFF6B,
  28843. ostrokeacute: 0x01FF,
  28844. osuperior: 0xF6F0,
  28845. otcyrillic: 0x047F,
  28846. otilde: 0x00F5,
  28847. otildeacute: 0x1E4D,
  28848. otildedieresis: 0x1E4F,
  28849. oubopomofo: 0x3121,
  28850. overline: 0x203E,
  28851. overlinecenterline: 0xFE4A,
  28852. overlinecmb: 0x0305,
  28853. overlinedashed: 0xFE49,
  28854. overlinedblwavy: 0xFE4C,
  28855. overlinewavy: 0xFE4B,
  28856. overscore: 0x00AF,
  28857. ovowelsignbengali: 0x09CB,
  28858. ovowelsigndeva: 0x094B,
  28859. ovowelsigngujarati: 0x0ACB,
  28860. p: 0x0070,
  28861. paampssquare: 0x3380,
  28862. paasentosquare: 0x332B,
  28863. pabengali: 0x09AA,
  28864. pacute: 0x1E55,
  28865. padeva: 0x092A,
  28866. pagedown: 0x21DF,
  28867. pageup: 0x21DE,
  28868. pagujarati: 0x0AAA,
  28869. pagurmukhi: 0x0A2A,
  28870. pahiragana: 0x3071,
  28871. paiyannoithai: 0x0E2F,
  28872. pakatakana: 0x30D1,
  28873. palatalizationcyrilliccmb: 0x0484,
  28874. palochkacyrillic: 0x04C0,
  28875. pansioskorean: 0x317F,
  28876. paragraph: 0x00B6,
  28877. parallel: 0x2225,
  28878. parenleft: 0x0028,
  28879. parenleftaltonearabic: 0xFD3E,
  28880. parenleftbt: 0xF8ED,
  28881. parenleftex: 0xF8EC,
  28882. parenleftinferior: 0x208D,
  28883. parenleftmonospace: 0xFF08,
  28884. parenleftsmall: 0xFE59,
  28885. parenleftsuperior: 0x207D,
  28886. parenlefttp: 0xF8EB,
  28887. parenleftvertical: 0xFE35,
  28888. parenright: 0x0029,
  28889. parenrightaltonearabic: 0xFD3F,
  28890. parenrightbt: 0xF8F8,
  28891. parenrightex: 0xF8F7,
  28892. parenrightinferior: 0x208E,
  28893. parenrightmonospace: 0xFF09,
  28894. parenrightsmall: 0xFE5A,
  28895. parenrightsuperior: 0x207E,
  28896. parenrighttp: 0xF8F6,
  28897. parenrightvertical: 0xFE36,
  28898. partialdiff: 0x2202,
  28899. paseqhebrew: 0x05C0,
  28900. pashtahebrew: 0x0599,
  28901. pasquare: 0x33A9,
  28902. patah: 0x05B7,
  28903. patah11: 0x05B7,
  28904. patah1d: 0x05B7,
  28905. patah2a: 0x05B7,
  28906. patahhebrew: 0x05B7,
  28907. patahnarrowhebrew: 0x05B7,
  28908. patahquarterhebrew: 0x05B7,
  28909. patahwidehebrew: 0x05B7,
  28910. pazerhebrew: 0x05A1,
  28911. pbopomofo: 0x3106,
  28912. pcircle: 0x24DF,
  28913. pdotaccent: 0x1E57,
  28914. pe: 0x05E4,
  28915. pecyrillic: 0x043F,
  28916. pedagesh: 0xFB44,
  28917. pedageshhebrew: 0xFB44,
  28918. peezisquare: 0x333B,
  28919. pefinaldageshhebrew: 0xFB43,
  28920. peharabic: 0x067E,
  28921. peharmenian: 0x057A,
  28922. pehebrew: 0x05E4,
  28923. pehfinalarabic: 0xFB57,
  28924. pehinitialarabic: 0xFB58,
  28925. pehiragana: 0x307A,
  28926. pehmedialarabic: 0xFB59,
  28927. pekatakana: 0x30DA,
  28928. pemiddlehookcyrillic: 0x04A7,
  28929. perafehebrew: 0xFB4E,
  28930. percent: 0x0025,
  28931. percentarabic: 0x066A,
  28932. percentmonospace: 0xFF05,
  28933. percentsmall: 0xFE6A,
  28934. period: 0x002E,
  28935. periodarmenian: 0x0589,
  28936. periodcentered: 0x00B7,
  28937. periodhalfwidth: 0xFF61,
  28938. periodinferior: 0xF6E7,
  28939. periodmonospace: 0xFF0E,
  28940. periodsmall: 0xFE52,
  28941. periodsuperior: 0xF6E8,
  28942. perispomenigreekcmb: 0x0342,
  28943. perpendicular: 0x22A5,
  28944. perthousand: 0x2030,
  28945. peseta: 0x20A7,
  28946. pfsquare: 0x338A,
  28947. phabengali: 0x09AB,
  28948. phadeva: 0x092B,
  28949. phagujarati: 0x0AAB,
  28950. phagurmukhi: 0x0A2B,
  28951. phi: 0x03C6,
  28952. phi1: 0x03D5,
  28953. phieuphacirclekorean: 0x327A,
  28954. phieuphaparenkorean: 0x321A,
  28955. phieuphcirclekorean: 0x326C,
  28956. phieuphkorean: 0x314D,
  28957. phieuphparenkorean: 0x320C,
  28958. philatin: 0x0278,
  28959. phinthuthai: 0x0E3A,
  28960. phisymbolgreek: 0x03D5,
  28961. phook: 0x01A5,
  28962. phophanthai: 0x0E1E,
  28963. phophungthai: 0x0E1C,
  28964. phosamphaothai: 0x0E20,
  28965. pi: 0x03C0,
  28966. pieupacirclekorean: 0x3273,
  28967. pieupaparenkorean: 0x3213,
  28968. pieupcieuckorean: 0x3176,
  28969. pieupcirclekorean: 0x3265,
  28970. pieupkiyeokkorean: 0x3172,
  28971. pieupkorean: 0x3142,
  28972. pieupparenkorean: 0x3205,
  28973. pieupsioskiyeokkorean: 0x3174,
  28974. pieupsioskorean: 0x3144,
  28975. pieupsiostikeutkorean: 0x3175,
  28976. pieupthieuthkorean: 0x3177,
  28977. pieuptikeutkorean: 0x3173,
  28978. pihiragana: 0x3074,
  28979. pikatakana: 0x30D4,
  28980. pisymbolgreek: 0x03D6,
  28981. piwrarmenian: 0x0583,
  28982. plus: 0x002B,
  28983. plusbelowcmb: 0x031F,
  28984. pluscircle: 0x2295,
  28985. plusminus: 0x00B1,
  28986. plusmod: 0x02D6,
  28987. plusmonospace: 0xFF0B,
  28988. plussmall: 0xFE62,
  28989. plussuperior: 0x207A,
  28990. pmonospace: 0xFF50,
  28991. pmsquare: 0x33D8,
  28992. pohiragana: 0x307D,
  28993. pointingindexdownwhite: 0x261F,
  28994. pointingindexleftwhite: 0x261C,
  28995. pointingindexrightwhite: 0x261E,
  28996. pointingindexupwhite: 0x261D,
  28997. pokatakana: 0x30DD,
  28998. poplathai: 0x0E1B,
  28999. postalmark: 0x3012,
  29000. postalmarkface: 0x3020,
  29001. pparen: 0x24AB,
  29002. precedes: 0x227A,
  29003. prescription: 0x211E,
  29004. primemod: 0x02B9,
  29005. primereversed: 0x2035,
  29006. product: 0x220F,
  29007. projective: 0x2305,
  29008. prolongedkana: 0x30FC,
  29009. propellor: 0x2318,
  29010. propersubset: 0x2282,
  29011. propersuperset: 0x2283,
  29012. proportion: 0x2237,
  29013. proportional: 0x221D,
  29014. psi: 0x03C8,
  29015. psicyrillic: 0x0471,
  29016. psilipneumatacyrilliccmb: 0x0486,
  29017. pssquare: 0x33B0,
  29018. puhiragana: 0x3077,
  29019. pukatakana: 0x30D7,
  29020. pvsquare: 0x33B4,
  29021. pwsquare: 0x33BA,
  29022. q: 0x0071,
  29023. qadeva: 0x0958,
  29024. qadmahebrew: 0x05A8,
  29025. qafarabic: 0x0642,
  29026. qaffinalarabic: 0xFED6,
  29027. qafinitialarabic: 0xFED7,
  29028. qafmedialarabic: 0xFED8,
  29029. qamats: 0x05B8,
  29030. qamats10: 0x05B8,
  29031. qamats1a: 0x05B8,
  29032. qamats1c: 0x05B8,
  29033. qamats27: 0x05B8,
  29034. qamats29: 0x05B8,
  29035. qamats33: 0x05B8,
  29036. qamatsde: 0x05B8,
  29037. qamatshebrew: 0x05B8,
  29038. qamatsnarrowhebrew: 0x05B8,
  29039. qamatsqatanhebrew: 0x05B8,
  29040. qamatsqatannarrowhebrew: 0x05B8,
  29041. qamatsqatanquarterhebrew: 0x05B8,
  29042. qamatsqatanwidehebrew: 0x05B8,
  29043. qamatsquarterhebrew: 0x05B8,
  29044. qamatswidehebrew: 0x05B8,
  29045. qarneyparahebrew: 0x059F,
  29046. qbopomofo: 0x3111,
  29047. qcircle: 0x24E0,
  29048. qhook: 0x02A0,
  29049. qmonospace: 0xFF51,
  29050. qof: 0x05E7,
  29051. qofdagesh: 0xFB47,
  29052. qofdageshhebrew: 0xFB47,
  29053. qofhebrew: 0x05E7,
  29054. qparen: 0x24AC,
  29055. quarternote: 0x2669,
  29056. qubuts: 0x05BB,
  29057. qubuts18: 0x05BB,
  29058. qubuts25: 0x05BB,
  29059. qubuts31: 0x05BB,
  29060. qubutshebrew: 0x05BB,
  29061. qubutsnarrowhebrew: 0x05BB,
  29062. qubutsquarterhebrew: 0x05BB,
  29063. qubutswidehebrew: 0x05BB,
  29064. question: 0x003F,
  29065. questionarabic: 0x061F,
  29066. questionarmenian: 0x055E,
  29067. questiondown: 0x00BF,
  29068. questiondownsmall: 0xF7BF,
  29069. questiongreek: 0x037E,
  29070. questionmonospace: 0xFF1F,
  29071. questionsmall: 0xF73F,
  29072. quotedbl: 0x0022,
  29073. quotedblbase: 0x201E,
  29074. quotedblleft: 0x201C,
  29075. quotedblmonospace: 0xFF02,
  29076. quotedblprime: 0x301E,
  29077. quotedblprimereversed: 0x301D,
  29078. quotedblright: 0x201D,
  29079. quoteleft: 0x2018,
  29080. quoteleftreversed: 0x201B,
  29081. quotereversed: 0x201B,
  29082. quoteright: 0x2019,
  29083. quoterightn: 0x0149,
  29084. quotesinglbase: 0x201A,
  29085. quotesingle: 0x0027,
  29086. quotesinglemonospace: 0xFF07,
  29087. r: 0x0072,
  29088. raarmenian: 0x057C,
  29089. rabengali: 0x09B0,
  29090. racute: 0x0155,
  29091. radeva: 0x0930,
  29092. radical: 0x221A,
  29093. radicalex: 0xF8E5,
  29094. radoverssquare: 0x33AE,
  29095. radoverssquaredsquare: 0x33AF,
  29096. radsquare: 0x33AD,
  29097. rafe: 0x05BF,
  29098. rafehebrew: 0x05BF,
  29099. ragujarati: 0x0AB0,
  29100. ragurmukhi: 0x0A30,
  29101. rahiragana: 0x3089,
  29102. rakatakana: 0x30E9,
  29103. rakatakanahalfwidth: 0xFF97,
  29104. ralowerdiagonalbengali: 0x09F1,
  29105. ramiddlediagonalbengali: 0x09F0,
  29106. ramshorn: 0x0264,
  29107. ratio: 0x2236,
  29108. rbopomofo: 0x3116,
  29109. rcaron: 0x0159,
  29110. rcedilla: 0x0157,
  29111. rcircle: 0x24E1,
  29112. rcommaaccent: 0x0157,
  29113. rdblgrave: 0x0211,
  29114. rdotaccent: 0x1E59,
  29115. rdotbelow: 0x1E5B,
  29116. rdotbelowmacron: 0x1E5D,
  29117. referencemark: 0x203B,
  29118. reflexsubset: 0x2286,
  29119. reflexsuperset: 0x2287,
  29120. registered: 0x00AE,
  29121. registersans: 0xF8E8,
  29122. registerserif: 0xF6DA,
  29123. reharabic: 0x0631,
  29124. reharmenian: 0x0580,
  29125. rehfinalarabic: 0xFEAE,
  29126. rehiragana: 0x308C,
  29127. rekatakana: 0x30EC,
  29128. rekatakanahalfwidth: 0xFF9A,
  29129. resh: 0x05E8,
  29130. reshdageshhebrew: 0xFB48,
  29131. reshhebrew: 0x05E8,
  29132. reversedtilde: 0x223D,
  29133. reviahebrew: 0x0597,
  29134. reviamugrashhebrew: 0x0597,
  29135. revlogicalnot: 0x2310,
  29136. rfishhook: 0x027E,
  29137. rfishhookreversed: 0x027F,
  29138. rhabengali: 0x09DD,
  29139. rhadeva: 0x095D,
  29140. rho: 0x03C1,
  29141. rhook: 0x027D,
  29142. rhookturned: 0x027B,
  29143. rhookturnedsuperior: 0x02B5,
  29144. rhosymbolgreek: 0x03F1,
  29145. rhotichookmod: 0x02DE,
  29146. rieulacirclekorean: 0x3271,
  29147. rieulaparenkorean: 0x3211,
  29148. rieulcirclekorean: 0x3263,
  29149. rieulhieuhkorean: 0x3140,
  29150. rieulkiyeokkorean: 0x313A,
  29151. rieulkiyeoksioskorean: 0x3169,
  29152. rieulkorean: 0x3139,
  29153. rieulmieumkorean: 0x313B,
  29154. rieulpansioskorean: 0x316C,
  29155. rieulparenkorean: 0x3203,
  29156. rieulphieuphkorean: 0x313F,
  29157. rieulpieupkorean: 0x313C,
  29158. rieulpieupsioskorean: 0x316B,
  29159. rieulsioskorean: 0x313D,
  29160. rieulthieuthkorean: 0x313E,
  29161. rieultikeutkorean: 0x316A,
  29162. rieulyeorinhieuhkorean: 0x316D,
  29163. rightangle: 0x221F,
  29164. righttackbelowcmb: 0x0319,
  29165. righttriangle: 0x22BF,
  29166. rihiragana: 0x308A,
  29167. rikatakana: 0x30EA,
  29168. rikatakanahalfwidth: 0xFF98,
  29169. ring: 0x02DA,
  29170. ringbelowcmb: 0x0325,
  29171. ringcmb: 0x030A,
  29172. ringhalfleft: 0x02BF,
  29173. ringhalfleftarmenian: 0x0559,
  29174. ringhalfleftbelowcmb: 0x031C,
  29175. ringhalfleftcentered: 0x02D3,
  29176. ringhalfright: 0x02BE,
  29177. ringhalfrightbelowcmb: 0x0339,
  29178. ringhalfrightcentered: 0x02D2,
  29179. rinvertedbreve: 0x0213,
  29180. rittorusquare: 0x3351,
  29181. rlinebelow: 0x1E5F,
  29182. rlongleg: 0x027C,
  29183. rlonglegturned: 0x027A,
  29184. rmonospace: 0xFF52,
  29185. rohiragana: 0x308D,
  29186. rokatakana: 0x30ED,
  29187. rokatakanahalfwidth: 0xFF9B,
  29188. roruathai: 0x0E23,
  29189. rparen: 0x24AD,
  29190. rrabengali: 0x09DC,
  29191. rradeva: 0x0931,
  29192. rragurmukhi: 0x0A5C,
  29193. rreharabic: 0x0691,
  29194. rrehfinalarabic: 0xFB8D,
  29195. rrvocalicbengali: 0x09E0,
  29196. rrvocalicdeva: 0x0960,
  29197. rrvocalicgujarati: 0x0AE0,
  29198. rrvocalicvowelsignbengali: 0x09C4,
  29199. rrvocalicvowelsigndeva: 0x0944,
  29200. rrvocalicvowelsigngujarati: 0x0AC4,
  29201. rsuperior: 0xF6F1,
  29202. rtblock: 0x2590,
  29203. rturned: 0x0279,
  29204. rturnedsuperior: 0x02B4,
  29205. ruhiragana: 0x308B,
  29206. rukatakana: 0x30EB,
  29207. rukatakanahalfwidth: 0xFF99,
  29208. rupeemarkbengali: 0x09F2,
  29209. rupeesignbengali: 0x09F3,
  29210. rupiah: 0xF6DD,
  29211. ruthai: 0x0E24,
  29212. rvocalicbengali: 0x098B,
  29213. rvocalicdeva: 0x090B,
  29214. rvocalicgujarati: 0x0A8B,
  29215. rvocalicvowelsignbengali: 0x09C3,
  29216. rvocalicvowelsigndeva: 0x0943,
  29217. rvocalicvowelsigngujarati: 0x0AC3,
  29218. s: 0x0073,
  29219. sabengali: 0x09B8,
  29220. sacute: 0x015B,
  29221. sacutedotaccent: 0x1E65,
  29222. sadarabic: 0x0635,
  29223. sadeva: 0x0938,
  29224. sadfinalarabic: 0xFEBA,
  29225. sadinitialarabic: 0xFEBB,
  29226. sadmedialarabic: 0xFEBC,
  29227. sagujarati: 0x0AB8,
  29228. sagurmukhi: 0x0A38,
  29229. sahiragana: 0x3055,
  29230. sakatakana: 0x30B5,
  29231. sakatakanahalfwidth: 0xFF7B,
  29232. sallallahoualayhewasallamarabic: 0xFDFA,
  29233. samekh: 0x05E1,
  29234. samekhdagesh: 0xFB41,
  29235. samekhdageshhebrew: 0xFB41,
  29236. samekhhebrew: 0x05E1,
  29237. saraaathai: 0x0E32,
  29238. saraaethai: 0x0E41,
  29239. saraaimaimalaithai: 0x0E44,
  29240. saraaimaimuanthai: 0x0E43,
  29241. saraamthai: 0x0E33,
  29242. saraathai: 0x0E30,
  29243. saraethai: 0x0E40,
  29244. saraiileftthai: 0xF886,
  29245. saraiithai: 0x0E35,
  29246. saraileftthai: 0xF885,
  29247. saraithai: 0x0E34,
  29248. saraothai: 0x0E42,
  29249. saraueeleftthai: 0xF888,
  29250. saraueethai: 0x0E37,
  29251. saraueleftthai: 0xF887,
  29252. sarauethai: 0x0E36,
  29253. sarauthai: 0x0E38,
  29254. sarauuthai: 0x0E39,
  29255. sbopomofo: 0x3119,
  29256. scaron: 0x0161,
  29257. scarondotaccent: 0x1E67,
  29258. scedilla: 0x015F,
  29259. schwa: 0x0259,
  29260. schwacyrillic: 0x04D9,
  29261. schwadieresiscyrillic: 0x04DB,
  29262. schwahook: 0x025A,
  29263. scircle: 0x24E2,
  29264. scircumflex: 0x015D,
  29265. scommaaccent: 0x0219,
  29266. sdotaccent: 0x1E61,
  29267. sdotbelow: 0x1E63,
  29268. sdotbelowdotaccent: 0x1E69,
  29269. seagullbelowcmb: 0x033C,
  29270. second: 0x2033,
  29271. secondtonechinese: 0x02CA,
  29272. section: 0x00A7,
  29273. seenarabic: 0x0633,
  29274. seenfinalarabic: 0xFEB2,
  29275. seeninitialarabic: 0xFEB3,
  29276. seenmedialarabic: 0xFEB4,
  29277. segol: 0x05B6,
  29278. segol13: 0x05B6,
  29279. segol1f: 0x05B6,
  29280. segol2c: 0x05B6,
  29281. segolhebrew: 0x05B6,
  29282. segolnarrowhebrew: 0x05B6,
  29283. segolquarterhebrew: 0x05B6,
  29284. segoltahebrew: 0x0592,
  29285. segolwidehebrew: 0x05B6,
  29286. seharmenian: 0x057D,
  29287. sehiragana: 0x305B,
  29288. sekatakana: 0x30BB,
  29289. sekatakanahalfwidth: 0xFF7E,
  29290. semicolon: 0x003B,
  29291. semicolonarabic: 0x061B,
  29292. semicolonmonospace: 0xFF1B,
  29293. semicolonsmall: 0xFE54,
  29294. semivoicedmarkkana: 0x309C,
  29295. semivoicedmarkkanahalfwidth: 0xFF9F,
  29296. sentisquare: 0x3322,
  29297. sentosquare: 0x3323,
  29298. seven: 0x0037,
  29299. sevenarabic: 0x0667,
  29300. sevenbengali: 0x09ED,
  29301. sevencircle: 0x2466,
  29302. sevencircleinversesansserif: 0x2790,
  29303. sevendeva: 0x096D,
  29304. seveneighths: 0x215E,
  29305. sevengujarati: 0x0AED,
  29306. sevengurmukhi: 0x0A6D,
  29307. sevenhackarabic: 0x0667,
  29308. sevenhangzhou: 0x3027,
  29309. sevenideographicparen: 0x3226,
  29310. seveninferior: 0x2087,
  29311. sevenmonospace: 0xFF17,
  29312. sevenoldstyle: 0xF737,
  29313. sevenparen: 0x247A,
  29314. sevenperiod: 0x248E,
  29315. sevenpersian: 0x06F7,
  29316. sevenroman: 0x2176,
  29317. sevensuperior: 0x2077,
  29318. seventeencircle: 0x2470,
  29319. seventeenparen: 0x2484,
  29320. seventeenperiod: 0x2498,
  29321. seventhai: 0x0E57,
  29322. sfthyphen: 0x00AD,
  29323. shaarmenian: 0x0577,
  29324. shabengali: 0x09B6,
  29325. shacyrillic: 0x0448,
  29326. shaddaarabic: 0x0651,
  29327. shaddadammaarabic: 0xFC61,
  29328. shaddadammatanarabic: 0xFC5E,
  29329. shaddafathaarabic: 0xFC60,
  29330. shaddakasraarabic: 0xFC62,
  29331. shaddakasratanarabic: 0xFC5F,
  29332. shade: 0x2592,
  29333. shadedark: 0x2593,
  29334. shadelight: 0x2591,
  29335. shademedium: 0x2592,
  29336. shadeva: 0x0936,
  29337. shagujarati: 0x0AB6,
  29338. shagurmukhi: 0x0A36,
  29339. shalshelethebrew: 0x0593,
  29340. shbopomofo: 0x3115,
  29341. shchacyrillic: 0x0449,
  29342. sheenarabic: 0x0634,
  29343. sheenfinalarabic: 0xFEB6,
  29344. sheeninitialarabic: 0xFEB7,
  29345. sheenmedialarabic: 0xFEB8,
  29346. sheicoptic: 0x03E3,
  29347. sheqel: 0x20AA,
  29348. sheqelhebrew: 0x20AA,
  29349. sheva: 0x05B0,
  29350. sheva115: 0x05B0,
  29351. sheva15: 0x05B0,
  29352. sheva22: 0x05B0,
  29353. sheva2e: 0x05B0,
  29354. shevahebrew: 0x05B0,
  29355. shevanarrowhebrew: 0x05B0,
  29356. shevaquarterhebrew: 0x05B0,
  29357. shevawidehebrew: 0x05B0,
  29358. shhacyrillic: 0x04BB,
  29359. shimacoptic: 0x03ED,
  29360. shin: 0x05E9,
  29361. shindagesh: 0xFB49,
  29362. shindageshhebrew: 0xFB49,
  29363. shindageshshindot: 0xFB2C,
  29364. shindageshshindothebrew: 0xFB2C,
  29365. shindageshsindot: 0xFB2D,
  29366. shindageshsindothebrew: 0xFB2D,
  29367. shindothebrew: 0x05C1,
  29368. shinhebrew: 0x05E9,
  29369. shinshindot: 0xFB2A,
  29370. shinshindothebrew: 0xFB2A,
  29371. shinsindot: 0xFB2B,
  29372. shinsindothebrew: 0xFB2B,
  29373. shook: 0x0282,
  29374. sigma: 0x03C3,
  29375. sigma1: 0x03C2,
  29376. sigmafinal: 0x03C2,
  29377. sigmalunatesymbolgreek: 0x03F2,
  29378. sihiragana: 0x3057,
  29379. sikatakana: 0x30B7,
  29380. sikatakanahalfwidth: 0xFF7C,
  29381. siluqhebrew: 0x05BD,
  29382. siluqlefthebrew: 0x05BD,
  29383. similar: 0x223C,
  29384. sindothebrew: 0x05C2,
  29385. siosacirclekorean: 0x3274,
  29386. siosaparenkorean: 0x3214,
  29387. sioscieuckorean: 0x317E,
  29388. sioscirclekorean: 0x3266,
  29389. sioskiyeokkorean: 0x317A,
  29390. sioskorean: 0x3145,
  29391. siosnieunkorean: 0x317B,
  29392. siosparenkorean: 0x3206,
  29393. siospieupkorean: 0x317D,
  29394. siostikeutkorean: 0x317C,
  29395. six: 0x0036,
  29396. sixarabic: 0x0666,
  29397. sixbengali: 0x09EC,
  29398. sixcircle: 0x2465,
  29399. sixcircleinversesansserif: 0x278F,
  29400. sixdeva: 0x096C,
  29401. sixgujarati: 0x0AEC,
  29402. sixgurmukhi: 0x0A6C,
  29403. sixhackarabic: 0x0666,
  29404. sixhangzhou: 0x3026,
  29405. sixideographicparen: 0x3225,
  29406. sixinferior: 0x2086,
  29407. sixmonospace: 0xFF16,
  29408. sixoldstyle: 0xF736,
  29409. sixparen: 0x2479,
  29410. sixperiod: 0x248D,
  29411. sixpersian: 0x06F6,
  29412. sixroman: 0x2175,
  29413. sixsuperior: 0x2076,
  29414. sixteencircle: 0x246F,
  29415. sixteencurrencydenominatorbengali: 0x09F9,
  29416. sixteenparen: 0x2483,
  29417. sixteenperiod: 0x2497,
  29418. sixthai: 0x0E56,
  29419. slash: 0x002F,
  29420. slashmonospace: 0xFF0F,
  29421. slong: 0x017F,
  29422. slongdotaccent: 0x1E9B,
  29423. smileface: 0x263A,
  29424. smonospace: 0xFF53,
  29425. sofpasuqhebrew: 0x05C3,
  29426. softhyphen: 0x00AD,
  29427. softsigncyrillic: 0x044C,
  29428. sohiragana: 0x305D,
  29429. sokatakana: 0x30BD,
  29430. sokatakanahalfwidth: 0xFF7F,
  29431. soliduslongoverlaycmb: 0x0338,
  29432. solidusshortoverlaycmb: 0x0337,
  29433. sorusithai: 0x0E29,
  29434. sosalathai: 0x0E28,
  29435. sosothai: 0x0E0B,
  29436. sosuathai: 0x0E2A,
  29437. space: 0x0020,
  29438. spacehackarabic: 0x0020,
  29439. spade: 0x2660,
  29440. spadesuitblack: 0x2660,
  29441. spadesuitwhite: 0x2664,
  29442. sparen: 0x24AE,
  29443. squarebelowcmb: 0x033B,
  29444. squarecc: 0x33C4,
  29445. squarecm: 0x339D,
  29446. squarediagonalcrosshatchfill: 0x25A9,
  29447. squarehorizontalfill: 0x25A4,
  29448. squarekg: 0x338F,
  29449. squarekm: 0x339E,
  29450. squarekmcapital: 0x33CE,
  29451. squareln: 0x33D1,
  29452. squarelog: 0x33D2,
  29453. squaremg: 0x338E,
  29454. squaremil: 0x33D5,
  29455. squaremm: 0x339C,
  29456. squaremsquared: 0x33A1,
  29457. squareorthogonalcrosshatchfill: 0x25A6,
  29458. squareupperlefttolowerrightfill: 0x25A7,
  29459. squareupperrighttolowerleftfill: 0x25A8,
  29460. squareverticalfill: 0x25A5,
  29461. squarewhitewithsmallblack: 0x25A3,
  29462. srsquare: 0x33DB,
  29463. ssabengali: 0x09B7,
  29464. ssadeva: 0x0937,
  29465. ssagujarati: 0x0AB7,
  29466. ssangcieuckorean: 0x3149,
  29467. ssanghieuhkorean: 0x3185,
  29468. ssangieungkorean: 0x3180,
  29469. ssangkiyeokkorean: 0x3132,
  29470. ssangnieunkorean: 0x3165,
  29471. ssangpieupkorean: 0x3143,
  29472. ssangsioskorean: 0x3146,
  29473. ssangtikeutkorean: 0x3138,
  29474. ssuperior: 0xF6F2,
  29475. sterling: 0x00A3,
  29476. sterlingmonospace: 0xFFE1,
  29477. strokelongoverlaycmb: 0x0336,
  29478. strokeshortoverlaycmb: 0x0335,
  29479. subset: 0x2282,
  29480. subsetnotequal: 0x228A,
  29481. subsetorequal: 0x2286,
  29482. succeeds: 0x227B,
  29483. suchthat: 0x220B,
  29484. suhiragana: 0x3059,
  29485. sukatakana: 0x30B9,
  29486. sukatakanahalfwidth: 0xFF7D,
  29487. sukunarabic: 0x0652,
  29488. summation: 0x2211,
  29489. sun: 0x263C,
  29490. superset: 0x2283,
  29491. supersetnotequal: 0x228B,
  29492. supersetorequal: 0x2287,
  29493. svsquare: 0x33DC,
  29494. syouwaerasquare: 0x337C,
  29495. t: 0x0074,
  29496. tabengali: 0x09A4,
  29497. tackdown: 0x22A4,
  29498. tackleft: 0x22A3,
  29499. tadeva: 0x0924,
  29500. tagujarati: 0x0AA4,
  29501. tagurmukhi: 0x0A24,
  29502. taharabic: 0x0637,
  29503. tahfinalarabic: 0xFEC2,
  29504. tahinitialarabic: 0xFEC3,
  29505. tahiragana: 0x305F,
  29506. tahmedialarabic: 0xFEC4,
  29507. taisyouerasquare: 0x337D,
  29508. takatakana: 0x30BF,
  29509. takatakanahalfwidth: 0xFF80,
  29510. tatweelarabic: 0x0640,
  29511. tau: 0x03C4,
  29512. tav: 0x05EA,
  29513. tavdages: 0xFB4A,
  29514. tavdagesh: 0xFB4A,
  29515. tavdageshhebrew: 0xFB4A,
  29516. tavhebrew: 0x05EA,
  29517. tbar: 0x0167,
  29518. tbopomofo: 0x310A,
  29519. tcaron: 0x0165,
  29520. tccurl: 0x02A8,
  29521. tcedilla: 0x0163,
  29522. tcheharabic: 0x0686,
  29523. tchehfinalarabic: 0xFB7B,
  29524. tchehinitialarabic: 0xFB7C,
  29525. tchehmedialarabic: 0xFB7D,
  29526. tcircle: 0x24E3,
  29527. tcircumflexbelow: 0x1E71,
  29528. tcommaaccent: 0x0163,
  29529. tdieresis: 0x1E97,
  29530. tdotaccent: 0x1E6B,
  29531. tdotbelow: 0x1E6D,
  29532. tecyrillic: 0x0442,
  29533. tedescendercyrillic: 0x04AD,
  29534. teharabic: 0x062A,
  29535. tehfinalarabic: 0xFE96,
  29536. tehhahinitialarabic: 0xFCA2,
  29537. tehhahisolatedarabic: 0xFC0C,
  29538. tehinitialarabic: 0xFE97,
  29539. tehiragana: 0x3066,
  29540. tehjeeminitialarabic: 0xFCA1,
  29541. tehjeemisolatedarabic: 0xFC0B,
  29542. tehmarbutaarabic: 0x0629,
  29543. tehmarbutafinalarabic: 0xFE94,
  29544. tehmedialarabic: 0xFE98,
  29545. tehmeeminitialarabic: 0xFCA4,
  29546. tehmeemisolatedarabic: 0xFC0E,
  29547. tehnoonfinalarabic: 0xFC73,
  29548. tekatakana: 0x30C6,
  29549. tekatakanahalfwidth: 0xFF83,
  29550. telephone: 0x2121,
  29551. telephoneblack: 0x260E,
  29552. telishagedolahebrew: 0x05A0,
  29553. telishaqetanahebrew: 0x05A9,
  29554. tencircle: 0x2469,
  29555. tenideographicparen: 0x3229,
  29556. tenparen: 0x247D,
  29557. tenperiod: 0x2491,
  29558. tenroman: 0x2179,
  29559. tesh: 0x02A7,
  29560. tet: 0x05D8,
  29561. tetdagesh: 0xFB38,
  29562. tetdageshhebrew: 0xFB38,
  29563. tethebrew: 0x05D8,
  29564. tetsecyrillic: 0x04B5,
  29565. tevirhebrew: 0x059B,
  29566. tevirlefthebrew: 0x059B,
  29567. thabengali: 0x09A5,
  29568. thadeva: 0x0925,
  29569. thagujarati: 0x0AA5,
  29570. thagurmukhi: 0x0A25,
  29571. thalarabic: 0x0630,
  29572. thalfinalarabic: 0xFEAC,
  29573. thanthakhatlowleftthai: 0xF898,
  29574. thanthakhatlowrightthai: 0xF897,
  29575. thanthakhatthai: 0x0E4C,
  29576. thanthakhatupperleftthai: 0xF896,
  29577. theharabic: 0x062B,
  29578. thehfinalarabic: 0xFE9A,
  29579. thehinitialarabic: 0xFE9B,
  29580. thehmedialarabic: 0xFE9C,
  29581. thereexists: 0x2203,
  29582. therefore: 0x2234,
  29583. theta: 0x03B8,
  29584. theta1: 0x03D1,
  29585. thetasymbolgreek: 0x03D1,
  29586. thieuthacirclekorean: 0x3279,
  29587. thieuthaparenkorean: 0x3219,
  29588. thieuthcirclekorean: 0x326B,
  29589. thieuthkorean: 0x314C,
  29590. thieuthparenkorean: 0x320B,
  29591. thirteencircle: 0x246C,
  29592. thirteenparen: 0x2480,
  29593. thirteenperiod: 0x2494,
  29594. thonangmonthothai: 0x0E11,
  29595. thook: 0x01AD,
  29596. thophuthaothai: 0x0E12,
  29597. thorn: 0x00FE,
  29598. thothahanthai: 0x0E17,
  29599. thothanthai: 0x0E10,
  29600. thothongthai: 0x0E18,
  29601. thothungthai: 0x0E16,
  29602. thousandcyrillic: 0x0482,
  29603. thousandsseparatorarabic: 0x066C,
  29604. thousandsseparatorpersian: 0x066C,
  29605. three: 0x0033,
  29606. threearabic: 0x0663,
  29607. threebengali: 0x09E9,
  29608. threecircle: 0x2462,
  29609. threecircleinversesansserif: 0x278C,
  29610. threedeva: 0x0969,
  29611. threeeighths: 0x215C,
  29612. threegujarati: 0x0AE9,
  29613. threegurmukhi: 0x0A69,
  29614. threehackarabic: 0x0663,
  29615. threehangzhou: 0x3023,
  29616. threeideographicparen: 0x3222,
  29617. threeinferior: 0x2083,
  29618. threemonospace: 0xFF13,
  29619. threenumeratorbengali: 0x09F6,
  29620. threeoldstyle: 0xF733,
  29621. threeparen: 0x2476,
  29622. threeperiod: 0x248A,
  29623. threepersian: 0x06F3,
  29624. threequarters: 0x00BE,
  29625. threequartersemdash: 0xF6DE,
  29626. threeroman: 0x2172,
  29627. threesuperior: 0x00B3,
  29628. threethai: 0x0E53,
  29629. thzsquare: 0x3394,
  29630. tihiragana: 0x3061,
  29631. tikatakana: 0x30C1,
  29632. tikatakanahalfwidth: 0xFF81,
  29633. tikeutacirclekorean: 0x3270,
  29634. tikeutaparenkorean: 0x3210,
  29635. tikeutcirclekorean: 0x3262,
  29636. tikeutkorean: 0x3137,
  29637. tikeutparenkorean: 0x3202,
  29638. tilde: 0x02DC,
  29639. tildebelowcmb: 0x0330,
  29640. tildecmb: 0x0303,
  29641. tildecomb: 0x0303,
  29642. tildedoublecmb: 0x0360,
  29643. tildeoperator: 0x223C,
  29644. tildeoverlaycmb: 0x0334,
  29645. tildeverticalcmb: 0x033E,
  29646. timescircle: 0x2297,
  29647. tipehahebrew: 0x0596,
  29648. tipehalefthebrew: 0x0596,
  29649. tippigurmukhi: 0x0A70,
  29650. titlocyrilliccmb: 0x0483,
  29651. tiwnarmenian: 0x057F,
  29652. tlinebelow: 0x1E6F,
  29653. tmonospace: 0xFF54,
  29654. toarmenian: 0x0569,
  29655. tohiragana: 0x3068,
  29656. tokatakana: 0x30C8,
  29657. tokatakanahalfwidth: 0xFF84,
  29658. tonebarextrahighmod: 0x02E5,
  29659. tonebarextralowmod: 0x02E9,
  29660. tonebarhighmod: 0x02E6,
  29661. tonebarlowmod: 0x02E8,
  29662. tonebarmidmod: 0x02E7,
  29663. tonefive: 0x01BD,
  29664. tonesix: 0x0185,
  29665. tonetwo: 0x01A8,
  29666. tonos: 0x0384,
  29667. tonsquare: 0x3327,
  29668. topatakthai: 0x0E0F,
  29669. tortoiseshellbracketleft: 0x3014,
  29670. tortoiseshellbracketleftsmall: 0xFE5D,
  29671. tortoiseshellbracketleftvertical: 0xFE39,
  29672. tortoiseshellbracketright: 0x3015,
  29673. tortoiseshellbracketrightsmall: 0xFE5E,
  29674. tortoiseshellbracketrightvertical: 0xFE3A,
  29675. totaothai: 0x0E15,
  29676. tpalatalhook: 0x01AB,
  29677. tparen: 0x24AF,
  29678. trademark: 0x2122,
  29679. trademarksans: 0xF8EA,
  29680. trademarkserif: 0xF6DB,
  29681. tretroflexhook: 0x0288,
  29682. triagdn: 0x25BC,
  29683. triaglf: 0x25C4,
  29684. triagrt: 0x25BA,
  29685. triagup: 0x25B2,
  29686. ts: 0x02A6,
  29687. tsadi: 0x05E6,
  29688. tsadidagesh: 0xFB46,
  29689. tsadidageshhebrew: 0xFB46,
  29690. tsadihebrew: 0x05E6,
  29691. tsecyrillic: 0x0446,
  29692. tsere: 0x05B5,
  29693. tsere12: 0x05B5,
  29694. tsere1e: 0x05B5,
  29695. tsere2b: 0x05B5,
  29696. tserehebrew: 0x05B5,
  29697. tserenarrowhebrew: 0x05B5,
  29698. tserequarterhebrew: 0x05B5,
  29699. tserewidehebrew: 0x05B5,
  29700. tshecyrillic: 0x045B,
  29701. tsuperior: 0xF6F3,
  29702. ttabengali: 0x099F,
  29703. ttadeva: 0x091F,
  29704. ttagujarati: 0x0A9F,
  29705. ttagurmukhi: 0x0A1F,
  29706. tteharabic: 0x0679,
  29707. ttehfinalarabic: 0xFB67,
  29708. ttehinitialarabic: 0xFB68,
  29709. ttehmedialarabic: 0xFB69,
  29710. tthabengali: 0x09A0,
  29711. tthadeva: 0x0920,
  29712. tthagujarati: 0x0AA0,
  29713. tthagurmukhi: 0x0A20,
  29714. tturned: 0x0287,
  29715. tuhiragana: 0x3064,
  29716. tukatakana: 0x30C4,
  29717. tukatakanahalfwidth: 0xFF82,
  29718. tusmallhiragana: 0x3063,
  29719. tusmallkatakana: 0x30C3,
  29720. tusmallkatakanahalfwidth: 0xFF6F,
  29721. twelvecircle: 0x246B,
  29722. twelveparen: 0x247F,
  29723. twelveperiod: 0x2493,
  29724. twelveroman: 0x217B,
  29725. twentycircle: 0x2473,
  29726. twentyhangzhou: 0x5344,
  29727. twentyparen: 0x2487,
  29728. twentyperiod: 0x249B,
  29729. two: 0x0032,
  29730. twoarabic: 0x0662,
  29731. twobengali: 0x09E8,
  29732. twocircle: 0x2461,
  29733. twocircleinversesansserif: 0x278B,
  29734. twodeva: 0x0968,
  29735. twodotenleader: 0x2025,
  29736. twodotleader: 0x2025,
  29737. twodotleadervertical: 0xFE30,
  29738. twogujarati: 0x0AE8,
  29739. twogurmukhi: 0x0A68,
  29740. twohackarabic: 0x0662,
  29741. twohangzhou: 0x3022,
  29742. twoideographicparen: 0x3221,
  29743. twoinferior: 0x2082,
  29744. twomonospace: 0xFF12,
  29745. twonumeratorbengali: 0x09F5,
  29746. twooldstyle: 0xF732,
  29747. twoparen: 0x2475,
  29748. twoperiod: 0x2489,
  29749. twopersian: 0x06F2,
  29750. tworoman: 0x2171,
  29751. twostroke: 0x01BB,
  29752. twosuperior: 0x00B2,
  29753. twothai: 0x0E52,
  29754. twothirds: 0x2154,
  29755. u: 0x0075,
  29756. uacute: 0x00FA,
  29757. ubar: 0x0289,
  29758. ubengali: 0x0989,
  29759. ubopomofo: 0x3128,
  29760. ubreve: 0x016D,
  29761. ucaron: 0x01D4,
  29762. ucircle: 0x24E4,
  29763. ucircumflex: 0x00FB,
  29764. ucircumflexbelow: 0x1E77,
  29765. ucyrillic: 0x0443,
  29766. udattadeva: 0x0951,
  29767. udblacute: 0x0171,
  29768. udblgrave: 0x0215,
  29769. udeva: 0x0909,
  29770. udieresis: 0x00FC,
  29771. udieresisacute: 0x01D8,
  29772. udieresisbelow: 0x1E73,
  29773. udieresiscaron: 0x01DA,
  29774. udieresiscyrillic: 0x04F1,
  29775. udieresisgrave: 0x01DC,
  29776. udieresismacron: 0x01D6,
  29777. udotbelow: 0x1EE5,
  29778. ugrave: 0x00F9,
  29779. ugujarati: 0x0A89,
  29780. ugurmukhi: 0x0A09,
  29781. uhiragana: 0x3046,
  29782. uhookabove: 0x1EE7,
  29783. uhorn: 0x01B0,
  29784. uhornacute: 0x1EE9,
  29785. uhorndotbelow: 0x1EF1,
  29786. uhorngrave: 0x1EEB,
  29787. uhornhookabove: 0x1EED,
  29788. uhorntilde: 0x1EEF,
  29789. uhungarumlaut: 0x0171,
  29790. uhungarumlautcyrillic: 0x04F3,
  29791. uinvertedbreve: 0x0217,
  29792. ukatakana: 0x30A6,
  29793. ukatakanahalfwidth: 0xFF73,
  29794. ukcyrillic: 0x0479,
  29795. ukorean: 0x315C,
  29796. umacron: 0x016B,
  29797. umacroncyrillic: 0x04EF,
  29798. umacrondieresis: 0x1E7B,
  29799. umatragurmukhi: 0x0A41,
  29800. umonospace: 0xFF55,
  29801. underscore: 0x005F,
  29802. underscoredbl: 0x2017,
  29803. underscoremonospace: 0xFF3F,
  29804. underscorevertical: 0xFE33,
  29805. underscorewavy: 0xFE4F,
  29806. union: 0x222A,
  29807. universal: 0x2200,
  29808. uogonek: 0x0173,
  29809. uparen: 0x24B0,
  29810. upblock: 0x2580,
  29811. upperdothebrew: 0x05C4,
  29812. upsilon: 0x03C5,
  29813. upsilondieresis: 0x03CB,
  29814. upsilondieresistonos: 0x03B0,
  29815. upsilonlatin: 0x028A,
  29816. upsilontonos: 0x03CD,
  29817. uptackbelowcmb: 0x031D,
  29818. uptackmod: 0x02D4,
  29819. uragurmukhi: 0x0A73,
  29820. uring: 0x016F,
  29821. ushortcyrillic: 0x045E,
  29822. usmallhiragana: 0x3045,
  29823. usmallkatakana: 0x30A5,
  29824. usmallkatakanahalfwidth: 0xFF69,
  29825. ustraightcyrillic: 0x04AF,
  29826. ustraightstrokecyrillic: 0x04B1,
  29827. utilde: 0x0169,
  29828. utildeacute: 0x1E79,
  29829. utildebelow: 0x1E75,
  29830. uubengali: 0x098A,
  29831. uudeva: 0x090A,
  29832. uugujarati: 0x0A8A,
  29833. uugurmukhi: 0x0A0A,
  29834. uumatragurmukhi: 0x0A42,
  29835. uuvowelsignbengali: 0x09C2,
  29836. uuvowelsigndeva: 0x0942,
  29837. uuvowelsigngujarati: 0x0AC2,
  29838. uvowelsignbengali: 0x09C1,
  29839. uvowelsigndeva: 0x0941,
  29840. uvowelsigngujarati: 0x0AC1,
  29841. v: 0x0076,
  29842. vadeva: 0x0935,
  29843. vagujarati: 0x0AB5,
  29844. vagurmukhi: 0x0A35,
  29845. vakatakana: 0x30F7,
  29846. vav: 0x05D5,
  29847. vavdagesh: 0xFB35,
  29848. vavdagesh65: 0xFB35,
  29849. vavdageshhebrew: 0xFB35,
  29850. vavhebrew: 0x05D5,
  29851. vavholam: 0xFB4B,
  29852. vavholamhebrew: 0xFB4B,
  29853. vavvavhebrew: 0x05F0,
  29854. vavyodhebrew: 0x05F1,
  29855. vcircle: 0x24E5,
  29856. vdotbelow: 0x1E7F,
  29857. vecyrillic: 0x0432,
  29858. veharabic: 0x06A4,
  29859. vehfinalarabic: 0xFB6B,
  29860. vehinitialarabic: 0xFB6C,
  29861. vehmedialarabic: 0xFB6D,
  29862. vekatakana: 0x30F9,
  29863. venus: 0x2640,
  29864. verticalbar: 0x007C,
  29865. verticallineabovecmb: 0x030D,
  29866. verticallinebelowcmb: 0x0329,
  29867. verticallinelowmod: 0x02CC,
  29868. verticallinemod: 0x02C8,
  29869. vewarmenian: 0x057E,
  29870. vhook: 0x028B,
  29871. vikatakana: 0x30F8,
  29872. viramabengali: 0x09CD,
  29873. viramadeva: 0x094D,
  29874. viramagujarati: 0x0ACD,
  29875. visargabengali: 0x0983,
  29876. visargadeva: 0x0903,
  29877. visargagujarati: 0x0A83,
  29878. vmonospace: 0xFF56,
  29879. voarmenian: 0x0578,
  29880. voicediterationhiragana: 0x309E,
  29881. voicediterationkatakana: 0x30FE,
  29882. voicedmarkkana: 0x309B,
  29883. voicedmarkkanahalfwidth: 0xFF9E,
  29884. vokatakana: 0x30FA,
  29885. vparen: 0x24B1,
  29886. vtilde: 0x1E7D,
  29887. vturned: 0x028C,
  29888. vuhiragana: 0x3094,
  29889. vukatakana: 0x30F4,
  29890. w: 0x0077,
  29891. wacute: 0x1E83,
  29892. waekorean: 0x3159,
  29893. wahiragana: 0x308F,
  29894. wakatakana: 0x30EF,
  29895. wakatakanahalfwidth: 0xFF9C,
  29896. wakorean: 0x3158,
  29897. wasmallhiragana: 0x308E,
  29898. wasmallkatakana: 0x30EE,
  29899. wattosquare: 0x3357,
  29900. wavedash: 0x301C,
  29901. wavyunderscorevertical: 0xFE34,
  29902. wawarabic: 0x0648,
  29903. wawfinalarabic: 0xFEEE,
  29904. wawhamzaabovearabic: 0x0624,
  29905. wawhamzaabovefinalarabic: 0xFE86,
  29906. wbsquare: 0x33DD,
  29907. wcircle: 0x24E6,
  29908. wcircumflex: 0x0175,
  29909. wdieresis: 0x1E85,
  29910. wdotaccent: 0x1E87,
  29911. wdotbelow: 0x1E89,
  29912. wehiragana: 0x3091,
  29913. weierstrass: 0x2118,
  29914. wekatakana: 0x30F1,
  29915. wekorean: 0x315E,
  29916. weokorean: 0x315D,
  29917. wgrave: 0x1E81,
  29918. whitebullet: 0x25E6,
  29919. whitecircle: 0x25CB,
  29920. whitecircleinverse: 0x25D9,
  29921. whitecornerbracketleft: 0x300E,
  29922. whitecornerbracketleftvertical: 0xFE43,
  29923. whitecornerbracketright: 0x300F,
  29924. whitecornerbracketrightvertical: 0xFE44,
  29925. whitediamond: 0x25C7,
  29926. whitediamondcontainingblacksmalldiamond: 0x25C8,
  29927. whitedownpointingsmalltriangle: 0x25BF,
  29928. whitedownpointingtriangle: 0x25BD,
  29929. whiteleftpointingsmalltriangle: 0x25C3,
  29930. whiteleftpointingtriangle: 0x25C1,
  29931. whitelenticularbracketleft: 0x3016,
  29932. whitelenticularbracketright: 0x3017,
  29933. whiterightpointingsmalltriangle: 0x25B9,
  29934. whiterightpointingtriangle: 0x25B7,
  29935. whitesmallsquare: 0x25AB,
  29936. whitesmilingface: 0x263A,
  29937. whitesquare: 0x25A1,
  29938. whitestar: 0x2606,
  29939. whitetelephone: 0x260F,
  29940. whitetortoiseshellbracketleft: 0x3018,
  29941. whitetortoiseshellbracketright: 0x3019,
  29942. whiteuppointingsmalltriangle: 0x25B5,
  29943. whiteuppointingtriangle: 0x25B3,
  29944. wihiragana: 0x3090,
  29945. wikatakana: 0x30F0,
  29946. wikorean: 0x315F,
  29947. wmonospace: 0xFF57,
  29948. wohiragana: 0x3092,
  29949. wokatakana: 0x30F2,
  29950. wokatakanahalfwidth: 0xFF66,
  29951. won: 0x20A9,
  29952. wonmonospace: 0xFFE6,
  29953. wowaenthai: 0x0E27,
  29954. wparen: 0x24B2,
  29955. wring: 0x1E98,
  29956. wsuperior: 0x02B7,
  29957. wturned: 0x028D,
  29958. wynn: 0x01BF,
  29959. x: 0x0078,
  29960. xabovecmb: 0x033D,
  29961. xbopomofo: 0x3112,
  29962. xcircle: 0x24E7,
  29963. xdieresis: 0x1E8D,
  29964. xdotaccent: 0x1E8B,
  29965. xeharmenian: 0x056D,
  29966. xi: 0x03BE,
  29967. xmonospace: 0xFF58,
  29968. xparen: 0x24B3,
  29969. xsuperior: 0x02E3,
  29970. y: 0x0079,
  29971. yaadosquare: 0x334E,
  29972. yabengali: 0x09AF,
  29973. yacute: 0x00FD,
  29974. yadeva: 0x092F,
  29975. yaekorean: 0x3152,
  29976. yagujarati: 0x0AAF,
  29977. yagurmukhi: 0x0A2F,
  29978. yahiragana: 0x3084,
  29979. yakatakana: 0x30E4,
  29980. yakatakanahalfwidth: 0xFF94,
  29981. yakorean: 0x3151,
  29982. yamakkanthai: 0x0E4E,
  29983. yasmallhiragana: 0x3083,
  29984. yasmallkatakana: 0x30E3,
  29985. yasmallkatakanahalfwidth: 0xFF6C,
  29986. yatcyrillic: 0x0463,
  29987. ycircle: 0x24E8,
  29988. ycircumflex: 0x0177,
  29989. ydieresis: 0x00FF,
  29990. ydotaccent: 0x1E8F,
  29991. ydotbelow: 0x1EF5,
  29992. yeharabic: 0x064A,
  29993. yehbarreearabic: 0x06D2,
  29994. yehbarreefinalarabic: 0xFBAF,
  29995. yehfinalarabic: 0xFEF2,
  29996. yehhamzaabovearabic: 0x0626,
  29997. yehhamzaabovefinalarabic: 0xFE8A,
  29998. yehhamzaaboveinitialarabic: 0xFE8B,
  29999. yehhamzaabovemedialarabic: 0xFE8C,
  30000. yehinitialarabic: 0xFEF3,
  30001. yehmedialarabic: 0xFEF4,
  30002. yehmeeminitialarabic: 0xFCDD,
  30003. yehmeemisolatedarabic: 0xFC58,
  30004. yehnoonfinalarabic: 0xFC94,
  30005. yehthreedotsbelowarabic: 0x06D1,
  30006. yekorean: 0x3156,
  30007. yen: 0x00A5,
  30008. yenmonospace: 0xFFE5,
  30009. yeokorean: 0x3155,
  30010. yeorinhieuhkorean: 0x3186,
  30011. yerahbenyomohebrew: 0x05AA,
  30012. yerahbenyomolefthebrew: 0x05AA,
  30013. yericyrillic: 0x044B,
  30014. yerudieresiscyrillic: 0x04F9,
  30015. yesieungkorean: 0x3181,
  30016. yesieungpansioskorean: 0x3183,
  30017. yesieungsioskorean: 0x3182,
  30018. yetivhebrew: 0x059A,
  30019. ygrave: 0x1EF3,
  30020. yhook: 0x01B4,
  30021. yhookabove: 0x1EF7,
  30022. yiarmenian: 0x0575,
  30023. yicyrillic: 0x0457,
  30024. yikorean: 0x3162,
  30025. yinyang: 0x262F,
  30026. yiwnarmenian: 0x0582,
  30027. ymonospace: 0xFF59,
  30028. yod: 0x05D9,
  30029. yoddagesh: 0xFB39,
  30030. yoddageshhebrew: 0xFB39,
  30031. yodhebrew: 0x05D9,
  30032. yodyodhebrew: 0x05F2,
  30033. yodyodpatahhebrew: 0xFB1F,
  30034. yohiragana: 0x3088,
  30035. yoikorean: 0x3189,
  30036. yokatakana: 0x30E8,
  30037. yokatakanahalfwidth: 0xFF96,
  30038. yokorean: 0x315B,
  30039. yosmallhiragana: 0x3087,
  30040. yosmallkatakana: 0x30E7,
  30041. yosmallkatakanahalfwidth: 0xFF6E,
  30042. yotgreek: 0x03F3,
  30043. yoyaekorean: 0x3188,
  30044. yoyakorean: 0x3187,
  30045. yoyakthai: 0x0E22,
  30046. yoyingthai: 0x0E0D,
  30047. yparen: 0x24B4,
  30048. ypogegrammeni: 0x037A,
  30049. ypogegrammenigreekcmb: 0x0345,
  30050. yr: 0x01A6,
  30051. yring: 0x1E99,
  30052. ysuperior: 0x02B8,
  30053. ytilde: 0x1EF9,
  30054. yturned: 0x028E,
  30055. yuhiragana: 0x3086,
  30056. yuikorean: 0x318C,
  30057. yukatakana: 0x30E6,
  30058. yukatakanahalfwidth: 0xFF95,
  30059. yukorean: 0x3160,
  30060. yusbigcyrillic: 0x046B,
  30061. yusbigiotifiedcyrillic: 0x046D,
  30062. yuslittlecyrillic: 0x0467,
  30063. yuslittleiotifiedcyrillic: 0x0469,
  30064. yusmallhiragana: 0x3085,
  30065. yusmallkatakana: 0x30E5,
  30066. yusmallkatakanahalfwidth: 0xFF6D,
  30067. yuyekorean: 0x318B,
  30068. yuyeokorean: 0x318A,
  30069. yyabengali: 0x09DF,
  30070. yyadeva: 0x095F,
  30071. z: 0x007A,
  30072. zaarmenian: 0x0566,
  30073. zacute: 0x017A,
  30074. zadeva: 0x095B,
  30075. zagurmukhi: 0x0A5B,
  30076. zaharabic: 0x0638,
  30077. zahfinalarabic: 0xFEC6,
  30078. zahinitialarabic: 0xFEC7,
  30079. zahiragana: 0x3056,
  30080. zahmedialarabic: 0xFEC8,
  30081. zainarabic: 0x0632,
  30082. zainfinalarabic: 0xFEB0,
  30083. zakatakana: 0x30B6,
  30084. zaqefgadolhebrew: 0x0595,
  30085. zaqefqatanhebrew: 0x0594,
  30086. zarqahebrew: 0x0598,
  30087. zayin: 0x05D6,
  30088. zayindagesh: 0xFB36,
  30089. zayindageshhebrew: 0xFB36,
  30090. zayinhebrew: 0x05D6,
  30091. zbopomofo: 0x3117,
  30092. zcaron: 0x017E,
  30093. zcircle: 0x24E9,
  30094. zcircumflex: 0x1E91,
  30095. zcurl: 0x0291,
  30096. zdot: 0x017C,
  30097. zdotaccent: 0x017C,
  30098. zdotbelow: 0x1E93,
  30099. zecyrillic: 0x0437,
  30100. zedescendercyrillic: 0x0499,
  30101. zedieresiscyrillic: 0x04DF,
  30102. zehiragana: 0x305C,
  30103. zekatakana: 0x30BC,
  30104. zero: 0x0030,
  30105. zeroarabic: 0x0660,
  30106. zerobengali: 0x09E6,
  30107. zerodeva: 0x0966,
  30108. zerogujarati: 0x0AE6,
  30109. zerogurmukhi: 0x0A66,
  30110. zerohackarabic: 0x0660,
  30111. zeroinferior: 0x2080,
  30112. zeromonospace: 0xFF10,
  30113. zerooldstyle: 0xF730,
  30114. zeropersian: 0x06F0,
  30115. zerosuperior: 0x2070,
  30116. zerothai: 0x0E50,
  30117. zerowidthjoiner: 0xFEFF,
  30118. zerowidthnonjoiner: 0x200C,
  30119. zerowidthspace: 0x200B,
  30120. zeta: 0x03B6,
  30121. zhbopomofo: 0x3113,
  30122. zhearmenian: 0x056A,
  30123. zhebrevecyrillic: 0x04C2,
  30124. zhecyrillic: 0x0436,
  30125. zhedescendercyrillic: 0x0497,
  30126. zhedieresiscyrillic: 0x04DD,
  30127. zihiragana: 0x3058,
  30128. zikatakana: 0x30B8,
  30129. zinorhebrew: 0x05AE,
  30130. zlinebelow: 0x1E95,
  30131. zmonospace: 0xFF5A,
  30132. zohiragana: 0x305E,
  30133. zokatakana: 0x30BE,
  30134. zparen: 0x24B5,
  30135. zretroflexhook: 0x0290,
  30136. zstroke: 0x01B6,
  30137. zuhiragana: 0x305A,
  30138. zukatakana: 0x30BA,
  30139. '.notdef': 0x0000
  30140. };
  30141. var DingbatsGlyphsUnicode = {
  30142. space: 0x0020,
  30143. a1: 0x2701,
  30144. a2: 0x2702,
  30145. a202: 0x2703,
  30146. a3: 0x2704,
  30147. a4: 0x260E,
  30148. a5: 0x2706,
  30149. a119: 0x2707,
  30150. a118: 0x2708,
  30151. a117: 0x2709,
  30152. a11: 0x261B,
  30153. a12: 0x261E,
  30154. a13: 0x270C,
  30155. a14: 0x270D,
  30156. a15: 0x270E,
  30157. a16: 0x270F,
  30158. a105: 0x2710,
  30159. a17: 0x2711,
  30160. a18: 0x2712,
  30161. a19: 0x2713,
  30162. a20: 0x2714,
  30163. a21: 0x2715,
  30164. a22: 0x2716,
  30165. a23: 0x2717,
  30166. a24: 0x2718,
  30167. a25: 0x2719,
  30168. a26: 0x271A,
  30169. a27: 0x271B,
  30170. a28: 0x271C,
  30171. a6: 0x271D,
  30172. a7: 0x271E,
  30173. a8: 0x271F,
  30174. a9: 0x2720,
  30175. a10: 0x2721,
  30176. a29: 0x2722,
  30177. a30: 0x2723,
  30178. a31: 0x2724,
  30179. a32: 0x2725,
  30180. a33: 0x2726,
  30181. a34: 0x2727,
  30182. a35: 0x2605,
  30183. a36: 0x2729,
  30184. a37: 0x272A,
  30185. a38: 0x272B,
  30186. a39: 0x272C,
  30187. a40: 0x272D,
  30188. a41: 0x272E,
  30189. a42: 0x272F,
  30190. a43: 0x2730,
  30191. a44: 0x2731,
  30192. a45: 0x2732,
  30193. a46: 0x2733,
  30194. a47: 0x2734,
  30195. a48: 0x2735,
  30196. a49: 0x2736,
  30197. a50: 0x2737,
  30198. a51: 0x2738,
  30199. a52: 0x2739,
  30200. a53: 0x273A,
  30201. a54: 0x273B,
  30202. a55: 0x273C,
  30203. a56: 0x273D,
  30204. a57: 0x273E,
  30205. a58: 0x273F,
  30206. a59: 0x2740,
  30207. a60: 0x2741,
  30208. a61: 0x2742,
  30209. a62: 0x2743,
  30210. a63: 0x2744,
  30211. a64: 0x2745,
  30212. a65: 0x2746,
  30213. a66: 0x2747,
  30214. a67: 0x2748,
  30215. a68: 0x2749,
  30216. a69: 0x274A,
  30217. a70: 0x274B,
  30218. a71: 0x25CF,
  30219. a72: 0x274D,
  30220. a73: 0x25A0,
  30221. a74: 0x274F,
  30222. a203: 0x2750,
  30223. a75: 0x2751,
  30224. a204: 0x2752,
  30225. a76: 0x25B2,
  30226. a77: 0x25BC,
  30227. a78: 0x25C6,
  30228. a79: 0x2756,
  30229. a81: 0x25D7,
  30230. a82: 0x2758,
  30231. a83: 0x2759,
  30232. a84: 0x275A,
  30233. a97: 0x275B,
  30234. a98: 0x275C,
  30235. a99: 0x275D,
  30236. a100: 0x275E,
  30237. a101: 0x2761,
  30238. a102: 0x2762,
  30239. a103: 0x2763,
  30240. a104: 0x2764,
  30241. a106: 0x2765,
  30242. a107: 0x2766,
  30243. a108: 0x2767,
  30244. a112: 0x2663,
  30245. a111: 0x2666,
  30246. a110: 0x2665,
  30247. a109: 0x2660,
  30248. a120: 0x2460,
  30249. a121: 0x2461,
  30250. a122: 0x2462,
  30251. a123: 0x2463,
  30252. a124: 0x2464,
  30253. a125: 0x2465,
  30254. a126: 0x2466,
  30255. a127: 0x2467,
  30256. a128: 0x2468,
  30257. a129: 0x2469,
  30258. a130: 0x2776,
  30259. a131: 0x2777,
  30260. a132: 0x2778,
  30261. a133: 0x2779,
  30262. a134: 0x277A,
  30263. a135: 0x277B,
  30264. a136: 0x277C,
  30265. a137: 0x277D,
  30266. a138: 0x277E,
  30267. a139: 0x277F,
  30268. a140: 0x2780,
  30269. a141: 0x2781,
  30270. a142: 0x2782,
  30271. a143: 0x2783,
  30272. a144: 0x2784,
  30273. a145: 0x2785,
  30274. a146: 0x2786,
  30275. a147: 0x2787,
  30276. a148: 0x2788,
  30277. a149: 0x2789,
  30278. a150: 0x278A,
  30279. a151: 0x278B,
  30280. a152: 0x278C,
  30281. a153: 0x278D,
  30282. a154: 0x278E,
  30283. a155: 0x278F,
  30284. a156: 0x2790,
  30285. a157: 0x2791,
  30286. a158: 0x2792,
  30287. a159: 0x2793,
  30288. a160: 0x2794,
  30289. a161: 0x2192,
  30290. a163: 0x2194,
  30291. a164: 0x2195,
  30292. a196: 0x2798,
  30293. a165: 0x2799,
  30294. a192: 0x279A,
  30295. a166: 0x279B,
  30296. a167: 0x279C,
  30297. a168: 0x279D,
  30298. a169: 0x279E,
  30299. a170: 0x279F,
  30300. a171: 0x27A0,
  30301. a172: 0x27A1,
  30302. a173: 0x27A2,
  30303. a162: 0x27A3,
  30304. a174: 0x27A4,
  30305. a175: 0x27A5,
  30306. a176: 0x27A6,
  30307. a177: 0x27A7,
  30308. a178: 0x27A8,
  30309. a179: 0x27A9,
  30310. a193: 0x27AA,
  30311. a180: 0x27AB,
  30312. a199: 0x27AC,
  30313. a181: 0x27AD,
  30314. a200: 0x27AE,
  30315. a182: 0x27AF,
  30316. a201: 0x27B1,
  30317. a183: 0x27B2,
  30318. a184: 0x27B3,
  30319. a197: 0x27B4,
  30320. a185: 0x27B5,
  30321. a194: 0x27B6,
  30322. a198: 0x27B7,
  30323. a186: 0x27B8,
  30324. a195: 0x27B9,
  30325. a187: 0x27BA,
  30326. a188: 0x27BB,
  30327. a189: 0x27BC,
  30328. a190: 0x27BD,
  30329. a191: 0x27BE,
  30330. a89: 0x2768, // 0xF8D7
  30331. a90: 0x2769, // 0xF8D8
  30332. a93: 0x276A, // 0xF8D9
  30333. a94: 0x276B, // 0xF8DA
  30334. a91: 0x276C, // 0xF8DB
  30335. a92: 0x276D, // 0xF8DC
  30336. a205: 0x276E, // 0xF8DD
  30337. a85: 0x276F, // 0xF8DE
  30338. a206: 0x2770, // 0xF8DF
  30339. a86: 0x2771, // 0xF8E0
  30340. a87: 0x2772, // 0xF8E1
  30341. a88: 0x2773, // 0xF8E2
  30342. a95: 0x2774, // 0xF8E3
  30343. a96: 0x2775, // 0xF8E4
  30344. '.notdef': 0x0000
  30345. };
  30346. var PDFImage = (function PDFImageClosure() {
  30347. /**
  30348. * Decode the image in the main thread if it supported. Resovles the promise
  30349. * when the image data is ready.
  30350. */
  30351. function handleImageData(handler, xref, res, image) {
  30352. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  30353. // For natively supported jpegs send them to the main thread for decoding.
  30354. var dict = image.dict;
  30355. var colorSpace = dict.get('ColorSpace', 'CS');
  30356. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30357. var numComps = colorSpace.numComps;
  30358. var decodePromise = handler.sendWithPromise('JpegDecode',
  30359. [image.getIR(), numComps]);
  30360. return decodePromise.then(function (message) {
  30361. var data = message.data;
  30362. return new Stream(data, 0, data.length, image.dict);
  30363. });
  30364. } else {
  30365. return Promise.resolve(image);
  30366. }
  30367. }
  30368. /**
  30369. * Decode and clamp a value. The formula is different from the spec because we
  30370. * don't decode to float range [0,1], we decode it in the [0,max] range.
  30371. */
  30372. function decodeAndClamp(value, addend, coefficient, max) {
  30373. value = addend + value * coefficient;
  30374. // Clamp the value to the range
  30375. return (value < 0 ? 0 : (value > max ? max : value));
  30376. }
  30377. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  30378. this.image = image;
  30379. var dict = image.dict;
  30380. if (dict.has('Filter')) {
  30381. var filter = dict.get('Filter').name;
  30382. if (filter === 'JPXDecode') {
  30383. var jpxImage = new JpxImage();
  30384. jpxImage.parseImageProperties(image.stream);
  30385. image.stream.reset();
  30386. image.bitsPerComponent = jpxImage.bitsPerComponent;
  30387. image.numComps = jpxImage.componentsCount;
  30388. } else if (filter === 'JBIG2Decode') {
  30389. image.bitsPerComponent = 1;
  30390. image.numComps = 1;
  30391. }
  30392. }
  30393. // TODO cache rendered images?
  30394. this.width = dict.get('Width', 'W');
  30395. this.height = dict.get('Height', 'H');
  30396. if (this.width < 1 || this.height < 1) {
  30397. error('Invalid image width: ' + this.width + ' or height: ' +
  30398. this.height);
  30399. }
  30400. this.interpolate = dict.get('Interpolate', 'I') || false;
  30401. this.imageMask = dict.get('ImageMask', 'IM') || false;
  30402. this.matte = dict.get('Matte') || false;
  30403. var bitsPerComponent = image.bitsPerComponent;
  30404. if (!bitsPerComponent) {
  30405. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  30406. if (!bitsPerComponent) {
  30407. if (this.imageMask) {
  30408. bitsPerComponent = 1;
  30409. } else {
  30410. error('Bits per component missing in image: ' + this.imageMask);
  30411. }
  30412. }
  30413. }
  30414. this.bpc = bitsPerComponent;
  30415. if (!this.imageMask) {
  30416. var colorSpace = dict.get('ColorSpace', 'CS');
  30417. if (!colorSpace) {
  30418. info('JPX images (which do not require color spaces)');
  30419. switch (image.numComps) {
  30420. case 1:
  30421. colorSpace = Name.get('DeviceGray');
  30422. break;
  30423. case 3:
  30424. colorSpace = Name.get('DeviceRGB');
  30425. break;
  30426. case 4:
  30427. colorSpace = Name.get('DeviceCMYK');
  30428. break;
  30429. default:
  30430. error('JPX images with ' + this.numComps +
  30431. ' color components not supported.');
  30432. }
  30433. }
  30434. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  30435. this.numComps = this.colorSpace.numComps;
  30436. }
  30437. this.decode = dict.get('Decode', 'D');
  30438. this.needsDecode = false;
  30439. if (this.decode &&
  30440. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  30441. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  30442. this.needsDecode = true;
  30443. // Do some preprocessing to avoid more math.
  30444. var max = (1 << bitsPerComponent) - 1;
  30445. this.decodeCoefficients = [];
  30446. this.decodeAddends = [];
  30447. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  30448. var dmin = this.decode[i];
  30449. var dmax = this.decode[i + 1];
  30450. this.decodeCoefficients[j] = dmax - dmin;
  30451. this.decodeAddends[j] = max * dmin;
  30452. }
  30453. }
  30454. if (smask) {
  30455. this.smask = new PDFImage(xref, res, smask, false);
  30456. } else if (mask) {
  30457. if (isStream(mask)) {
  30458. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  30459. } else {
  30460. // Color key mask (just an array).
  30461. this.mask = mask;
  30462. }
  30463. }
  30464. }
  30465. /**
  30466. * Handles processing of image data and returns the Promise that is resolved
  30467. * with a PDFImage when the image is ready to be used.
  30468. */
  30469. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  30470. res, image, inline) {
  30471. var imagePromise = handleImageData(handler, xref, res, image);
  30472. var smaskPromise;
  30473. var maskPromise;
  30474. var smask = image.dict.get('SMask');
  30475. var mask = image.dict.get('Mask');
  30476. if (smask) {
  30477. smaskPromise = handleImageData(handler, xref, res, smask);
  30478. maskPromise = Promise.resolve(null);
  30479. } else {
  30480. smaskPromise = Promise.resolve(null);
  30481. if (mask) {
  30482. if (isStream(mask)) {
  30483. maskPromise = handleImageData(handler, xref, res, mask);
  30484. } else if (isArray(mask)) {
  30485. maskPromise = Promise.resolve(mask);
  30486. } else {
  30487. warn('Unsupported mask format.');
  30488. maskPromise = Promise.resolve(null);
  30489. }
  30490. } else {
  30491. maskPromise = Promise.resolve(null);
  30492. }
  30493. }
  30494. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  30495. function(results) {
  30496. var imageData = results[0];
  30497. var smaskData = results[1];
  30498. var maskData = results[2];
  30499. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  30500. });
  30501. };
  30502. /**
  30503. * Resize an image using the nearest neighbor algorithm. Currently only
  30504. * supports one and three component images.
  30505. * @param {TypedArray} pixels The original image with one component.
  30506. * @param {Number} bpc Number of bits per component.
  30507. * @param {Number} components Number of color components, 1 or 3 is supported.
  30508. * @param {Number} w1 Original width.
  30509. * @param {Number} h1 Original height.
  30510. * @param {Number} w2 New width.
  30511. * @param {Number} h2 New height.
  30512. * @param {TypedArray} dest (Optional) The destination buffer.
  30513. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  30514. * @return {TypedArray} Resized image data.
  30515. */
  30516. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  30517. w1, h1, w2, h2, dest, alpha01) {
  30518. if (components !== 1 && components !== 3) {
  30519. error('Unsupported component count for resizing.');
  30520. }
  30521. var length = w2 * h2 * components;
  30522. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  30523. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30524. var xRatio = w1 / w2;
  30525. var yRatio = h1 / h2;
  30526. var i, j, py, newIndex = 0, oldIndex;
  30527. var xScaled = new Uint16Array(w2);
  30528. var w1Scanline = w1 * components;
  30529. if (alpha01 !== 1) {
  30530. alpha01 = 0;
  30531. }
  30532. for (j = 0; j < w2; j++) {
  30533. xScaled[j] = Math.floor(j * xRatio) * components;
  30534. }
  30535. if (components === 1) {
  30536. for (i = 0; i < h2; i++) {
  30537. py = Math.floor(i * yRatio) * w1Scanline;
  30538. for (j = 0; j < w2; j++) {
  30539. oldIndex = py + xScaled[j];
  30540. temp[newIndex++] = pixels[oldIndex];
  30541. }
  30542. }
  30543. } else if (components === 3) {
  30544. for (i = 0; i < h2; i++) {
  30545. py = Math.floor(i * yRatio) * w1Scanline;
  30546. for (j = 0; j < w2; j++) {
  30547. oldIndex = py + xScaled[j];
  30548. temp[newIndex++] = pixels[oldIndex++];
  30549. temp[newIndex++] = pixels[oldIndex++];
  30550. temp[newIndex++] = pixels[oldIndex++];
  30551. newIndex += alpha01;
  30552. }
  30553. }
  30554. }
  30555. return temp;
  30556. };
  30557. PDFImage.createMask =
  30558. function PDFImage_createMask(imgArray, width, height,
  30559. imageIsFromDecodeStream, inverseDecode) {
  30560. // |imgArray| might not contain full data for every pixel of the mask, so
  30561. // we need to distinguish between |computedLength| and |actualLength|.
  30562. // In particular, if inverseDecode is true, then the array we return must
  30563. // have a length of |computedLength|.
  30564. var computedLength = ((width + 7) >> 3) * height;
  30565. var actualLength = imgArray.byteLength;
  30566. var haveFullData = computedLength === actualLength;
  30567. var data, i;
  30568. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  30569. // imgArray came from a DecodeStream and its data is in an appropriate
  30570. // form, so we can just transfer it.
  30571. data = imgArray;
  30572. } else if (!inverseDecode) {
  30573. data = new Uint8Array(actualLength);
  30574. data.set(imgArray);
  30575. } else {
  30576. data = new Uint8Array(computedLength);
  30577. data.set(imgArray);
  30578. for (i = actualLength; i < computedLength; i++) {
  30579. data[i] = 0xff;
  30580. }
  30581. }
  30582. // If necessary, invert the original mask data (but not any extra we might
  30583. // have added above). It's safe to modify the array -- whether it's the
  30584. // original or a copy, we're about to transfer it anyway, so nothing else
  30585. // in this thread can be relying on its contents.
  30586. if (inverseDecode) {
  30587. for (i = 0; i < actualLength; i++) {
  30588. data[i] = ~data[i];
  30589. }
  30590. }
  30591. return {data: data, width: width, height: height};
  30592. };
  30593. PDFImage.prototype = {
  30594. get drawWidth() {
  30595. return Math.max(this.width,
  30596. this.smask && this.smask.width || 0,
  30597. this.mask && this.mask.width || 0);
  30598. },
  30599. get drawHeight() {
  30600. return Math.max(this.height,
  30601. this.smask && this.smask.height || 0,
  30602. this.mask && this.mask.height || 0);
  30603. },
  30604. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  30605. var bpc = this.bpc;
  30606. var numComps = this.numComps;
  30607. var decodeAddends = this.decodeAddends;
  30608. var decodeCoefficients = this.decodeCoefficients;
  30609. var max = (1 << bpc) - 1;
  30610. var i, ii;
  30611. if (bpc === 1) {
  30612. // If the buffer needed decode that means it just needs to be inverted.
  30613. for (i = 0, ii = buffer.length; i < ii; i++) {
  30614. buffer[i] = +!(buffer[i]);
  30615. }
  30616. return;
  30617. }
  30618. var index = 0;
  30619. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  30620. for (var j = 0; j < numComps; j++) {
  30621. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  30622. decodeCoefficients[j], max);
  30623. index++;
  30624. }
  30625. }
  30626. },
  30627. getComponents: function PDFImage_getComponents(buffer) {
  30628. var bpc = this.bpc;
  30629. // This image doesn't require any extra work.
  30630. if (bpc === 8) {
  30631. return buffer;
  30632. }
  30633. var width = this.width;
  30634. var height = this.height;
  30635. var numComps = this.numComps;
  30636. var length = width * height * numComps;
  30637. var bufferPos = 0;
  30638. var output = (bpc <= 8 ? new Uint8Array(length) :
  30639. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  30640. var rowComps = width * numComps;
  30641. var max = (1 << bpc) - 1;
  30642. var i = 0, ii, buf;
  30643. if (bpc === 1) {
  30644. // Optimization for reading 1 bpc images.
  30645. var mask, loop1End, loop2End;
  30646. for (var j = 0; j < height; j++) {
  30647. loop1End = i + (rowComps & ~7);
  30648. loop2End = i + rowComps;
  30649. // unroll loop for all full bytes
  30650. while (i < loop1End) {
  30651. buf = buffer[bufferPos++];
  30652. output[i] = (buf >> 7) & 1;
  30653. output[i + 1] = (buf >> 6) & 1;
  30654. output[i + 2] = (buf >> 5) & 1;
  30655. output[i + 3] = (buf >> 4) & 1;
  30656. output[i + 4] = (buf >> 3) & 1;
  30657. output[i + 5] = (buf >> 2) & 1;
  30658. output[i + 6] = (buf >> 1) & 1;
  30659. output[i + 7] = buf & 1;
  30660. i += 8;
  30661. }
  30662. // handle remaing bits
  30663. if (i < loop2End) {
  30664. buf = buffer[bufferPos++];
  30665. mask = 128;
  30666. while (i < loop2End) {
  30667. output[i++] = +!!(buf & mask);
  30668. mask >>= 1;
  30669. }
  30670. }
  30671. }
  30672. } else {
  30673. // The general case that handles all other bpc values.
  30674. var bits = 0;
  30675. buf = 0;
  30676. for (i = 0, ii = length; i < ii; ++i) {
  30677. if (i % rowComps === 0) {
  30678. buf = 0;
  30679. bits = 0;
  30680. }
  30681. while (bits < bpc) {
  30682. buf = (buf << 8) | buffer[bufferPos++];
  30683. bits += 8;
  30684. }
  30685. var remainingBits = bits - bpc;
  30686. var value = buf >> remainingBits;
  30687. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  30688. buf = buf & ((1 << remainingBits) - 1);
  30689. bits = remainingBits;
  30690. }
  30691. }
  30692. return output;
  30693. },
  30694. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  30695. actualHeight, image) {
  30696. var smask = this.smask;
  30697. var mask = this.mask;
  30698. var alphaBuf, sw, sh, i, ii, j;
  30699. if (smask) {
  30700. sw = smask.width;
  30701. sh = smask.height;
  30702. alphaBuf = new Uint8Array(sw * sh);
  30703. smask.fillGrayBuffer(alphaBuf);
  30704. if (sw !== width || sh !== height) {
  30705. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  30706. height);
  30707. }
  30708. } else if (mask) {
  30709. if (mask instanceof PDFImage) {
  30710. sw = mask.width;
  30711. sh = mask.height;
  30712. alphaBuf = new Uint8Array(sw * sh);
  30713. mask.numComps = 1;
  30714. mask.fillGrayBuffer(alphaBuf);
  30715. // Need to invert values in rgbaBuf
  30716. for (i = 0, ii = sw * sh; i < ii; ++i) {
  30717. alphaBuf[i] = 255 - alphaBuf[i];
  30718. }
  30719. if (sw !== width || sh !== height) {
  30720. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  30721. height);
  30722. }
  30723. } else if (isArray(mask)) {
  30724. // Color key mask: if any of the compontents are outside the range
  30725. // then they should be painted.
  30726. alphaBuf = new Uint8Array(width * height);
  30727. var numComps = this.numComps;
  30728. for (i = 0, ii = width * height; i < ii; ++i) {
  30729. var opacity = 0;
  30730. var imageOffset = i * numComps;
  30731. for (j = 0; j < numComps; ++j) {
  30732. var color = image[imageOffset + j];
  30733. var maskOffset = j * 2;
  30734. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  30735. opacity = 255;
  30736. break;
  30737. }
  30738. }
  30739. alphaBuf[i] = opacity;
  30740. }
  30741. } else {
  30742. error('Unknown mask format.');
  30743. }
  30744. }
  30745. if (alphaBuf) {
  30746. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30747. rgbaBuf[j] = alphaBuf[i];
  30748. }
  30749. } else {
  30750. // No mask.
  30751. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  30752. rgbaBuf[j] = 255;
  30753. }
  30754. }
  30755. },
  30756. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  30757. var matte = this.smask && this.smask.matte;
  30758. if (!matte) {
  30759. return;
  30760. }
  30761. var matteRgb = this.colorSpace.getRgb(matte, 0);
  30762. var matteR = matteRgb[0];
  30763. var matteG = matteRgb[1];
  30764. var matteB = matteRgb[2];
  30765. var length = width * height * 4;
  30766. var r, g, b;
  30767. for (var i = 0; i < length; i += 4) {
  30768. var alpha = buffer[i + 3];
  30769. if (alpha === 0) {
  30770. // according formula we have to get Infinity in all components
  30771. // making it white (typical paper color) should be okay
  30772. buffer[i] = 255;
  30773. buffer[i + 1] = 255;
  30774. buffer[i + 2] = 255;
  30775. continue;
  30776. }
  30777. var k = 255 / alpha;
  30778. r = (buffer[i] - matteR) * k + matteR;
  30779. g = (buffer[i + 1] - matteG) * k + matteG;
  30780. b = (buffer[i + 2] - matteB) * k + matteB;
  30781. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  30782. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  30783. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  30784. }
  30785. },
  30786. createImageData: function PDFImage_createImageData(forceRGBA) {
  30787. var drawWidth = this.drawWidth;
  30788. var drawHeight = this.drawHeight;
  30789. var imgData = { // other fields are filled in below
  30790. width: drawWidth,
  30791. height: drawHeight
  30792. };
  30793. var numComps = this.numComps;
  30794. var originalWidth = this.width;
  30795. var originalHeight = this.height;
  30796. var bpc = this.bpc;
  30797. // Rows start at byte boundary.
  30798. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  30799. var imgArray;
  30800. if (!forceRGBA) {
  30801. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  30802. // without any complications, we pass a same-sized copy to the main
  30803. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  30804. // of memory for many scanned documents. It's also much faster.
  30805. //
  30806. // Similarly, if it is a 24-bit-per pixel RGB image without any
  30807. // complications, we avoid expanding by 1.333x to RGBA form.
  30808. var kind;
  30809. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  30810. kind = ImageKind.GRAYSCALE_1BPP;
  30811. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  30812. !this.needsDecode) {
  30813. kind = ImageKind.RGB_24BPP;
  30814. }
  30815. if (kind && !this.smask && !this.mask &&
  30816. drawWidth === originalWidth && drawHeight === originalHeight) {
  30817. imgData.kind = kind;
  30818. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30819. // If imgArray came from a DecodeStream, we're safe to transfer it
  30820. // (and thus neuter it) because it will constitute the entire
  30821. // DecodeStream's data. But if it came from a Stream, we need to
  30822. // copy it because it'll only be a portion of the Stream's data, and
  30823. // the rest will be read later on.
  30824. if (this.image instanceof DecodeStream) {
  30825. imgData.data = imgArray;
  30826. } else {
  30827. var newArray = new Uint8Array(imgArray.length);
  30828. newArray.set(imgArray);
  30829. imgData.data = newArray;
  30830. }
  30831. if (this.needsDecode) {
  30832. // Invert the buffer (which must be grayscale if we reached here).
  30833. assert(kind === ImageKind.GRAYSCALE_1BPP);
  30834. var buffer = imgData.data;
  30835. for (var i = 0, ii = buffer.length; i < ii; i++) {
  30836. buffer[i] ^= 0xff;
  30837. }
  30838. }
  30839. return imgData;
  30840. }
  30841. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  30842. imgData.kind = ImageKind.RGB_24BPP;
  30843. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  30844. drawWidth, drawHeight, true);
  30845. return imgData;
  30846. }
  30847. }
  30848. imgArray = this.getImageBytes(originalHeight * rowBytes);
  30849. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  30850. var actualHeight = 0 | (imgArray.length / rowBytes *
  30851. drawHeight / originalHeight);
  30852. var comps = this.getComponents(imgArray);
  30853. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  30854. // more compact RGB_24BPP form if allowable.
  30855. var alpha01, maybeUndoPreblend;
  30856. if (!forceRGBA && !this.smask && !this.mask) {
  30857. imgData.kind = ImageKind.RGB_24BPP;
  30858. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  30859. alpha01 = 0;
  30860. maybeUndoPreblend = false;
  30861. } else {
  30862. imgData.kind = ImageKind.RGBA_32BPP;
  30863. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  30864. alpha01 = 1;
  30865. maybeUndoPreblend = true;
  30866. // Color key masking (opacity) must be performed before decoding.
  30867. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  30868. comps);
  30869. }
  30870. if (this.needsDecode) {
  30871. this.decodeBuffer(comps);
  30872. }
  30873. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  30874. drawWidth, drawHeight, actualHeight, bpc, comps,
  30875. alpha01);
  30876. if (maybeUndoPreblend) {
  30877. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  30878. }
  30879. return imgData;
  30880. },
  30881. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  30882. var numComps = this.numComps;
  30883. if (numComps !== 1) {
  30884. error('Reading gray scale from a color image: ' + numComps);
  30885. }
  30886. var width = this.width;
  30887. var height = this.height;
  30888. var bpc = this.bpc;
  30889. // rows start at byte boundary
  30890. var rowBytes = (width * numComps * bpc + 7) >> 3;
  30891. var imgArray = this.getImageBytes(height * rowBytes);
  30892. var comps = this.getComponents(imgArray);
  30893. var i, length;
  30894. if (bpc === 1) {
  30895. // inline decoding (= inversion) for 1 bpc images
  30896. length = width * height;
  30897. if (this.needsDecode) {
  30898. // invert and scale to {0, 255}
  30899. for (i = 0; i < length; ++i) {
  30900. buffer[i] = (comps[i] - 1) & 255;
  30901. }
  30902. } else {
  30903. // scale to {0, 255}
  30904. for (i = 0; i < length; ++i) {
  30905. buffer[i] = (-comps[i]) & 255;
  30906. }
  30907. }
  30908. return;
  30909. }
  30910. if (this.needsDecode) {
  30911. this.decodeBuffer(comps);
  30912. }
  30913. length = width * height;
  30914. // we aren't using a colorspace so we need to scale the value
  30915. var scale = 255 / ((1 << bpc) - 1);
  30916. for (i = 0; i < length; ++i) {
  30917. buffer[i] = (scale * comps[i]) | 0;
  30918. }
  30919. },
  30920. getImageBytes: function PDFImage_getImageBytes(length,
  30921. drawWidth, drawHeight,
  30922. forceRGB) {
  30923. this.image.reset();
  30924. this.image.drawWidth = drawWidth || this.width;
  30925. this.image.drawHeight = drawHeight || this.height;
  30926. this.image.forceRGB = !!forceRGB;
  30927. return this.image.getBytes(length);
  30928. }
  30929. };
  30930. return PDFImage;
  30931. })();
  30932. // The Metrics object contains glyph widths (in glyph space units).
  30933. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  30934. // space unit corresponds to 1/1000th of text space unit.
  30935. var Metrics = {
  30936. 'Courier': 600,
  30937. 'Courier-Bold': 600,
  30938. 'Courier-BoldOblique': 600,
  30939. 'Courier-Oblique': 600,
  30940. 'Helvetica' : {
  30941. 'space': 278,
  30942. 'exclam': 278,
  30943. 'quotedbl': 355,
  30944. 'numbersign': 556,
  30945. 'dollar': 556,
  30946. 'percent': 889,
  30947. 'ampersand': 667,
  30948. 'quoteright': 222,
  30949. 'parenleft': 333,
  30950. 'parenright': 333,
  30951. 'asterisk': 389,
  30952. 'plus': 584,
  30953. 'comma': 278,
  30954. 'hyphen': 333,
  30955. 'period': 278,
  30956. 'slash': 278,
  30957. 'zero': 556,
  30958. 'one': 556,
  30959. 'two': 556,
  30960. 'three': 556,
  30961. 'four': 556,
  30962. 'five': 556,
  30963. 'six': 556,
  30964. 'seven': 556,
  30965. 'eight': 556,
  30966. 'nine': 556,
  30967. 'colon': 278,
  30968. 'semicolon': 278,
  30969. 'less': 584,
  30970. 'equal': 584,
  30971. 'greater': 584,
  30972. 'question': 556,
  30973. 'at': 1015,
  30974. 'A': 667,
  30975. 'B': 667,
  30976. 'C': 722,
  30977. 'D': 722,
  30978. 'E': 667,
  30979. 'F': 611,
  30980. 'G': 778,
  30981. 'H': 722,
  30982. 'I': 278,
  30983. 'J': 500,
  30984. 'K': 667,
  30985. 'L': 556,
  30986. 'M': 833,
  30987. 'N': 722,
  30988. 'O': 778,
  30989. 'P': 667,
  30990. 'Q': 778,
  30991. 'R': 722,
  30992. 'S': 667,
  30993. 'T': 611,
  30994. 'U': 722,
  30995. 'V': 667,
  30996. 'W': 944,
  30997. 'X': 667,
  30998. 'Y': 667,
  30999. 'Z': 611,
  31000. 'bracketleft': 278,
  31001. 'backslash': 278,
  31002. 'bracketright': 278,
  31003. 'asciicircum': 469,
  31004. 'underscore': 556,
  31005. 'quoteleft': 222,
  31006. 'a': 556,
  31007. 'b': 556,
  31008. 'c': 500,
  31009. 'd': 556,
  31010. 'e': 556,
  31011. 'f': 278,
  31012. 'g': 556,
  31013. 'h': 556,
  31014. 'i': 222,
  31015. 'j': 222,
  31016. 'k': 500,
  31017. 'l': 222,
  31018. 'm': 833,
  31019. 'n': 556,
  31020. 'o': 556,
  31021. 'p': 556,
  31022. 'q': 556,
  31023. 'r': 333,
  31024. 's': 500,
  31025. 't': 278,
  31026. 'u': 556,
  31027. 'v': 500,
  31028. 'w': 722,
  31029. 'x': 500,
  31030. 'y': 500,
  31031. 'z': 500,
  31032. 'braceleft': 334,
  31033. 'bar': 260,
  31034. 'braceright': 334,
  31035. 'asciitilde': 584,
  31036. 'exclamdown': 333,
  31037. 'cent': 556,
  31038. 'sterling': 556,
  31039. 'fraction': 167,
  31040. 'yen': 556,
  31041. 'florin': 556,
  31042. 'section': 556,
  31043. 'currency': 556,
  31044. 'quotesingle': 191,
  31045. 'quotedblleft': 333,
  31046. 'guillemotleft': 556,
  31047. 'guilsinglleft': 333,
  31048. 'guilsinglright': 333,
  31049. 'fi': 500,
  31050. 'fl': 500,
  31051. 'endash': 556,
  31052. 'dagger': 556,
  31053. 'daggerdbl': 556,
  31054. 'periodcentered': 278,
  31055. 'paragraph': 537,
  31056. 'bullet': 350,
  31057. 'quotesinglbase': 222,
  31058. 'quotedblbase': 333,
  31059. 'quotedblright': 333,
  31060. 'guillemotright': 556,
  31061. 'ellipsis': 1000,
  31062. 'perthousand': 1000,
  31063. 'questiondown': 611,
  31064. 'grave': 333,
  31065. 'acute': 333,
  31066. 'circumflex': 333,
  31067. 'tilde': 333,
  31068. 'macron': 333,
  31069. 'breve': 333,
  31070. 'dotaccent': 333,
  31071. 'dieresis': 333,
  31072. 'ring': 333,
  31073. 'cedilla': 333,
  31074. 'hungarumlaut': 333,
  31075. 'ogonek': 333,
  31076. 'caron': 333,
  31077. 'emdash': 1000,
  31078. 'AE': 1000,
  31079. 'ordfeminine': 370,
  31080. 'Lslash': 556,
  31081. 'Oslash': 778,
  31082. 'OE': 1000,
  31083. 'ordmasculine': 365,
  31084. 'ae': 889,
  31085. 'dotlessi': 278,
  31086. 'lslash': 222,
  31087. 'oslash': 611,
  31088. 'oe': 944,
  31089. 'germandbls': 611,
  31090. 'Idieresis': 278,
  31091. 'eacute': 556,
  31092. 'abreve': 556,
  31093. 'uhungarumlaut': 556,
  31094. 'ecaron': 556,
  31095. 'Ydieresis': 667,
  31096. 'divide': 584,
  31097. 'Yacute': 667,
  31098. 'Acircumflex': 667,
  31099. 'aacute': 556,
  31100. 'Ucircumflex': 722,
  31101. 'yacute': 500,
  31102. 'scommaaccent': 500,
  31103. 'ecircumflex': 556,
  31104. 'Uring': 722,
  31105. 'Udieresis': 722,
  31106. 'aogonek': 556,
  31107. 'Uacute': 722,
  31108. 'uogonek': 556,
  31109. 'Edieresis': 667,
  31110. 'Dcroat': 722,
  31111. 'commaaccent': 250,
  31112. 'copyright': 737,
  31113. 'Emacron': 667,
  31114. 'ccaron': 500,
  31115. 'aring': 556,
  31116. 'Ncommaaccent': 722,
  31117. 'lacute': 222,
  31118. 'agrave': 556,
  31119. 'Tcommaaccent': 611,
  31120. 'Cacute': 722,
  31121. 'atilde': 556,
  31122. 'Edotaccent': 667,
  31123. 'scaron': 500,
  31124. 'scedilla': 500,
  31125. 'iacute': 278,
  31126. 'lozenge': 471,
  31127. 'Rcaron': 722,
  31128. 'Gcommaaccent': 778,
  31129. 'ucircumflex': 556,
  31130. 'acircumflex': 556,
  31131. 'Amacron': 667,
  31132. 'rcaron': 333,
  31133. 'ccedilla': 500,
  31134. 'Zdotaccent': 611,
  31135. 'Thorn': 667,
  31136. 'Omacron': 778,
  31137. 'Racute': 722,
  31138. 'Sacute': 667,
  31139. 'dcaron': 643,
  31140. 'Umacron': 722,
  31141. 'uring': 556,
  31142. 'threesuperior': 333,
  31143. 'Ograve': 778,
  31144. 'Agrave': 667,
  31145. 'Abreve': 667,
  31146. 'multiply': 584,
  31147. 'uacute': 556,
  31148. 'Tcaron': 611,
  31149. 'partialdiff': 476,
  31150. 'ydieresis': 500,
  31151. 'Nacute': 722,
  31152. 'icircumflex': 278,
  31153. 'Ecircumflex': 667,
  31154. 'adieresis': 556,
  31155. 'edieresis': 556,
  31156. 'cacute': 500,
  31157. 'nacute': 556,
  31158. 'umacron': 556,
  31159. 'Ncaron': 722,
  31160. 'Iacute': 278,
  31161. 'plusminus': 584,
  31162. 'brokenbar': 260,
  31163. 'registered': 737,
  31164. 'Gbreve': 778,
  31165. 'Idotaccent': 278,
  31166. 'summation': 600,
  31167. 'Egrave': 667,
  31168. 'racute': 333,
  31169. 'omacron': 556,
  31170. 'Zacute': 611,
  31171. 'Zcaron': 611,
  31172. 'greaterequal': 549,
  31173. 'Eth': 722,
  31174. 'Ccedilla': 722,
  31175. 'lcommaaccent': 222,
  31176. 'tcaron': 317,
  31177. 'eogonek': 556,
  31178. 'Uogonek': 722,
  31179. 'Aacute': 667,
  31180. 'Adieresis': 667,
  31181. 'egrave': 556,
  31182. 'zacute': 500,
  31183. 'iogonek': 222,
  31184. 'Oacute': 778,
  31185. 'oacute': 556,
  31186. 'amacron': 556,
  31187. 'sacute': 500,
  31188. 'idieresis': 278,
  31189. 'Ocircumflex': 778,
  31190. 'Ugrave': 722,
  31191. 'Delta': 612,
  31192. 'thorn': 556,
  31193. 'twosuperior': 333,
  31194. 'Odieresis': 778,
  31195. 'mu': 556,
  31196. 'igrave': 278,
  31197. 'ohungarumlaut': 556,
  31198. 'Eogonek': 667,
  31199. 'dcroat': 556,
  31200. 'threequarters': 834,
  31201. 'Scedilla': 667,
  31202. 'lcaron': 299,
  31203. 'Kcommaaccent': 667,
  31204. 'Lacute': 556,
  31205. 'trademark': 1000,
  31206. 'edotaccent': 556,
  31207. 'Igrave': 278,
  31208. 'Imacron': 278,
  31209. 'Lcaron': 556,
  31210. 'onehalf': 834,
  31211. 'lessequal': 549,
  31212. 'ocircumflex': 556,
  31213. 'ntilde': 556,
  31214. 'Uhungarumlaut': 722,
  31215. 'Eacute': 667,
  31216. 'emacron': 556,
  31217. 'gbreve': 556,
  31218. 'onequarter': 834,
  31219. 'Scaron': 667,
  31220. 'Scommaaccent': 667,
  31221. 'Ohungarumlaut': 778,
  31222. 'degree': 400,
  31223. 'ograve': 556,
  31224. 'Ccaron': 722,
  31225. 'ugrave': 556,
  31226. 'radical': 453,
  31227. 'Dcaron': 722,
  31228. 'rcommaaccent': 333,
  31229. 'Ntilde': 722,
  31230. 'otilde': 556,
  31231. 'Rcommaaccent': 722,
  31232. 'Lcommaaccent': 556,
  31233. 'Atilde': 667,
  31234. 'Aogonek': 667,
  31235. 'Aring': 667,
  31236. 'Otilde': 778,
  31237. 'zdotaccent': 500,
  31238. 'Ecaron': 667,
  31239. 'Iogonek': 278,
  31240. 'kcommaaccent': 500,
  31241. 'minus': 584,
  31242. 'Icircumflex': 278,
  31243. 'ncaron': 556,
  31244. 'tcommaaccent': 278,
  31245. 'logicalnot': 584,
  31246. 'odieresis': 556,
  31247. 'udieresis': 556,
  31248. 'notequal': 549,
  31249. 'gcommaaccent': 556,
  31250. 'eth': 556,
  31251. 'zcaron': 500,
  31252. 'ncommaaccent': 556,
  31253. 'onesuperior': 333,
  31254. 'imacron': 278,
  31255. 'Euro': 556
  31256. },
  31257. 'Helvetica-Bold': {
  31258. 'space': 278,
  31259. 'exclam': 333,
  31260. 'quotedbl': 474,
  31261. 'numbersign': 556,
  31262. 'dollar': 556,
  31263. 'percent': 889,
  31264. 'ampersand': 722,
  31265. 'quoteright': 278,
  31266. 'parenleft': 333,
  31267. 'parenright': 333,
  31268. 'asterisk': 389,
  31269. 'plus': 584,
  31270. 'comma': 278,
  31271. 'hyphen': 333,
  31272. 'period': 278,
  31273. 'slash': 278,
  31274. 'zero': 556,
  31275. 'one': 556,
  31276. 'two': 556,
  31277. 'three': 556,
  31278. 'four': 556,
  31279. 'five': 556,
  31280. 'six': 556,
  31281. 'seven': 556,
  31282. 'eight': 556,
  31283. 'nine': 556,
  31284. 'colon': 333,
  31285. 'semicolon': 333,
  31286. 'less': 584,
  31287. 'equal': 584,
  31288. 'greater': 584,
  31289. 'question': 611,
  31290. 'at': 975,
  31291. 'A': 722,
  31292. 'B': 722,
  31293. 'C': 722,
  31294. 'D': 722,
  31295. 'E': 667,
  31296. 'F': 611,
  31297. 'G': 778,
  31298. 'H': 722,
  31299. 'I': 278,
  31300. 'J': 556,
  31301. 'K': 722,
  31302. 'L': 611,
  31303. 'M': 833,
  31304. 'N': 722,
  31305. 'O': 778,
  31306. 'P': 667,
  31307. 'Q': 778,
  31308. 'R': 722,
  31309. 'S': 667,
  31310. 'T': 611,
  31311. 'U': 722,
  31312. 'V': 667,
  31313. 'W': 944,
  31314. 'X': 667,
  31315. 'Y': 667,
  31316. 'Z': 611,
  31317. 'bracketleft': 333,
  31318. 'backslash': 278,
  31319. 'bracketright': 333,
  31320. 'asciicircum': 584,
  31321. 'underscore': 556,
  31322. 'quoteleft': 278,
  31323. 'a': 556,
  31324. 'b': 611,
  31325. 'c': 556,
  31326. 'd': 611,
  31327. 'e': 556,
  31328. 'f': 333,
  31329. 'g': 611,
  31330. 'h': 611,
  31331. 'i': 278,
  31332. 'j': 278,
  31333. 'k': 556,
  31334. 'l': 278,
  31335. 'm': 889,
  31336. 'n': 611,
  31337. 'o': 611,
  31338. 'p': 611,
  31339. 'q': 611,
  31340. 'r': 389,
  31341. 's': 556,
  31342. 't': 333,
  31343. 'u': 611,
  31344. 'v': 556,
  31345. 'w': 778,
  31346. 'x': 556,
  31347. 'y': 556,
  31348. 'z': 500,
  31349. 'braceleft': 389,
  31350. 'bar': 280,
  31351. 'braceright': 389,
  31352. 'asciitilde': 584,
  31353. 'exclamdown': 333,
  31354. 'cent': 556,
  31355. 'sterling': 556,
  31356. 'fraction': 167,
  31357. 'yen': 556,
  31358. 'florin': 556,
  31359. 'section': 556,
  31360. 'currency': 556,
  31361. 'quotesingle': 238,
  31362. 'quotedblleft': 500,
  31363. 'guillemotleft': 556,
  31364. 'guilsinglleft': 333,
  31365. 'guilsinglright': 333,
  31366. 'fi': 611,
  31367. 'fl': 611,
  31368. 'endash': 556,
  31369. 'dagger': 556,
  31370. 'daggerdbl': 556,
  31371. 'periodcentered': 278,
  31372. 'paragraph': 556,
  31373. 'bullet': 350,
  31374. 'quotesinglbase': 278,
  31375. 'quotedblbase': 500,
  31376. 'quotedblright': 500,
  31377. 'guillemotright': 556,
  31378. 'ellipsis': 1000,
  31379. 'perthousand': 1000,
  31380. 'questiondown': 611,
  31381. 'grave': 333,
  31382. 'acute': 333,
  31383. 'circumflex': 333,
  31384. 'tilde': 333,
  31385. 'macron': 333,
  31386. 'breve': 333,
  31387. 'dotaccent': 333,
  31388. 'dieresis': 333,
  31389. 'ring': 333,
  31390. 'cedilla': 333,
  31391. 'hungarumlaut': 333,
  31392. 'ogonek': 333,
  31393. 'caron': 333,
  31394. 'emdash': 1000,
  31395. 'AE': 1000,
  31396. 'ordfeminine': 370,
  31397. 'Lslash': 611,
  31398. 'Oslash': 778,
  31399. 'OE': 1000,
  31400. 'ordmasculine': 365,
  31401. 'ae': 889,
  31402. 'dotlessi': 278,
  31403. 'lslash': 278,
  31404. 'oslash': 611,
  31405. 'oe': 944,
  31406. 'germandbls': 611,
  31407. 'Idieresis': 278,
  31408. 'eacute': 556,
  31409. 'abreve': 556,
  31410. 'uhungarumlaut': 611,
  31411. 'ecaron': 556,
  31412. 'Ydieresis': 667,
  31413. 'divide': 584,
  31414. 'Yacute': 667,
  31415. 'Acircumflex': 722,
  31416. 'aacute': 556,
  31417. 'Ucircumflex': 722,
  31418. 'yacute': 556,
  31419. 'scommaaccent': 556,
  31420. 'ecircumflex': 556,
  31421. 'Uring': 722,
  31422. 'Udieresis': 722,
  31423. 'aogonek': 556,
  31424. 'Uacute': 722,
  31425. 'uogonek': 611,
  31426. 'Edieresis': 667,
  31427. 'Dcroat': 722,
  31428. 'commaaccent': 250,
  31429. 'copyright': 737,
  31430. 'Emacron': 667,
  31431. 'ccaron': 556,
  31432. 'aring': 556,
  31433. 'Ncommaaccent': 722,
  31434. 'lacute': 278,
  31435. 'agrave': 556,
  31436. 'Tcommaaccent': 611,
  31437. 'Cacute': 722,
  31438. 'atilde': 556,
  31439. 'Edotaccent': 667,
  31440. 'scaron': 556,
  31441. 'scedilla': 556,
  31442. 'iacute': 278,
  31443. 'lozenge': 494,
  31444. 'Rcaron': 722,
  31445. 'Gcommaaccent': 778,
  31446. 'ucircumflex': 611,
  31447. 'acircumflex': 556,
  31448. 'Amacron': 722,
  31449. 'rcaron': 389,
  31450. 'ccedilla': 556,
  31451. 'Zdotaccent': 611,
  31452. 'Thorn': 667,
  31453. 'Omacron': 778,
  31454. 'Racute': 722,
  31455. 'Sacute': 667,
  31456. 'dcaron': 743,
  31457. 'Umacron': 722,
  31458. 'uring': 611,
  31459. 'threesuperior': 333,
  31460. 'Ograve': 778,
  31461. 'Agrave': 722,
  31462. 'Abreve': 722,
  31463. 'multiply': 584,
  31464. 'uacute': 611,
  31465. 'Tcaron': 611,
  31466. 'partialdiff': 494,
  31467. 'ydieresis': 556,
  31468. 'Nacute': 722,
  31469. 'icircumflex': 278,
  31470. 'Ecircumflex': 667,
  31471. 'adieresis': 556,
  31472. 'edieresis': 556,
  31473. 'cacute': 556,
  31474. 'nacute': 611,
  31475. 'umacron': 611,
  31476. 'Ncaron': 722,
  31477. 'Iacute': 278,
  31478. 'plusminus': 584,
  31479. 'brokenbar': 280,
  31480. 'registered': 737,
  31481. 'Gbreve': 778,
  31482. 'Idotaccent': 278,
  31483. 'summation': 600,
  31484. 'Egrave': 667,
  31485. 'racute': 389,
  31486. 'omacron': 611,
  31487. 'Zacute': 611,
  31488. 'Zcaron': 611,
  31489. 'greaterequal': 549,
  31490. 'Eth': 722,
  31491. 'Ccedilla': 722,
  31492. 'lcommaaccent': 278,
  31493. 'tcaron': 389,
  31494. 'eogonek': 556,
  31495. 'Uogonek': 722,
  31496. 'Aacute': 722,
  31497. 'Adieresis': 722,
  31498. 'egrave': 556,
  31499. 'zacute': 500,
  31500. 'iogonek': 278,
  31501. 'Oacute': 778,
  31502. 'oacute': 611,
  31503. 'amacron': 556,
  31504. 'sacute': 556,
  31505. 'idieresis': 278,
  31506. 'Ocircumflex': 778,
  31507. 'Ugrave': 722,
  31508. 'Delta': 612,
  31509. 'thorn': 611,
  31510. 'twosuperior': 333,
  31511. 'Odieresis': 778,
  31512. 'mu': 611,
  31513. 'igrave': 278,
  31514. 'ohungarumlaut': 611,
  31515. 'Eogonek': 667,
  31516. 'dcroat': 611,
  31517. 'threequarters': 834,
  31518. 'Scedilla': 667,
  31519. 'lcaron': 400,
  31520. 'Kcommaaccent': 722,
  31521. 'Lacute': 611,
  31522. 'trademark': 1000,
  31523. 'edotaccent': 556,
  31524. 'Igrave': 278,
  31525. 'Imacron': 278,
  31526. 'Lcaron': 611,
  31527. 'onehalf': 834,
  31528. 'lessequal': 549,
  31529. 'ocircumflex': 611,
  31530. 'ntilde': 611,
  31531. 'Uhungarumlaut': 722,
  31532. 'Eacute': 667,
  31533. 'emacron': 556,
  31534. 'gbreve': 611,
  31535. 'onequarter': 834,
  31536. 'Scaron': 667,
  31537. 'Scommaaccent': 667,
  31538. 'Ohungarumlaut': 778,
  31539. 'degree': 400,
  31540. 'ograve': 611,
  31541. 'Ccaron': 722,
  31542. 'ugrave': 611,
  31543. 'radical': 549,
  31544. 'Dcaron': 722,
  31545. 'rcommaaccent': 389,
  31546. 'Ntilde': 722,
  31547. 'otilde': 611,
  31548. 'Rcommaaccent': 722,
  31549. 'Lcommaaccent': 611,
  31550. 'Atilde': 722,
  31551. 'Aogonek': 722,
  31552. 'Aring': 722,
  31553. 'Otilde': 778,
  31554. 'zdotaccent': 500,
  31555. 'Ecaron': 667,
  31556. 'Iogonek': 278,
  31557. 'kcommaaccent': 556,
  31558. 'minus': 584,
  31559. 'Icircumflex': 278,
  31560. 'ncaron': 611,
  31561. 'tcommaaccent': 333,
  31562. 'logicalnot': 584,
  31563. 'odieresis': 611,
  31564. 'udieresis': 611,
  31565. 'notequal': 549,
  31566. 'gcommaaccent': 611,
  31567. 'eth': 611,
  31568. 'zcaron': 500,
  31569. 'ncommaaccent': 611,
  31570. 'onesuperior': 333,
  31571. 'imacron': 278,
  31572. 'Euro': 556
  31573. },
  31574. 'Helvetica-BoldOblique': {
  31575. 'space': 278,
  31576. 'exclam': 333,
  31577. 'quotedbl': 474,
  31578. 'numbersign': 556,
  31579. 'dollar': 556,
  31580. 'percent': 889,
  31581. 'ampersand': 722,
  31582. 'quoteright': 278,
  31583. 'parenleft': 333,
  31584. 'parenright': 333,
  31585. 'asterisk': 389,
  31586. 'plus': 584,
  31587. 'comma': 278,
  31588. 'hyphen': 333,
  31589. 'period': 278,
  31590. 'slash': 278,
  31591. 'zero': 556,
  31592. 'one': 556,
  31593. 'two': 556,
  31594. 'three': 556,
  31595. 'four': 556,
  31596. 'five': 556,
  31597. 'six': 556,
  31598. 'seven': 556,
  31599. 'eight': 556,
  31600. 'nine': 556,
  31601. 'colon': 333,
  31602. 'semicolon': 333,
  31603. 'less': 584,
  31604. 'equal': 584,
  31605. 'greater': 584,
  31606. 'question': 611,
  31607. 'at': 975,
  31608. 'A': 722,
  31609. 'B': 722,
  31610. 'C': 722,
  31611. 'D': 722,
  31612. 'E': 667,
  31613. 'F': 611,
  31614. 'G': 778,
  31615. 'H': 722,
  31616. 'I': 278,
  31617. 'J': 556,
  31618. 'K': 722,
  31619. 'L': 611,
  31620. 'M': 833,
  31621. 'N': 722,
  31622. 'O': 778,
  31623. 'P': 667,
  31624. 'Q': 778,
  31625. 'R': 722,
  31626. 'S': 667,
  31627. 'T': 611,
  31628. 'U': 722,
  31629. 'V': 667,
  31630. 'W': 944,
  31631. 'X': 667,
  31632. 'Y': 667,
  31633. 'Z': 611,
  31634. 'bracketleft': 333,
  31635. 'backslash': 278,
  31636. 'bracketright': 333,
  31637. 'asciicircum': 584,
  31638. 'underscore': 556,
  31639. 'quoteleft': 278,
  31640. 'a': 556,
  31641. 'b': 611,
  31642. 'c': 556,
  31643. 'd': 611,
  31644. 'e': 556,
  31645. 'f': 333,
  31646. 'g': 611,
  31647. 'h': 611,
  31648. 'i': 278,
  31649. 'j': 278,
  31650. 'k': 556,
  31651. 'l': 278,
  31652. 'm': 889,
  31653. 'n': 611,
  31654. 'o': 611,
  31655. 'p': 611,
  31656. 'q': 611,
  31657. 'r': 389,
  31658. 's': 556,
  31659. 't': 333,
  31660. 'u': 611,
  31661. 'v': 556,
  31662. 'w': 778,
  31663. 'x': 556,
  31664. 'y': 556,
  31665. 'z': 500,
  31666. 'braceleft': 389,
  31667. 'bar': 280,
  31668. 'braceright': 389,
  31669. 'asciitilde': 584,
  31670. 'exclamdown': 333,
  31671. 'cent': 556,
  31672. 'sterling': 556,
  31673. 'fraction': 167,
  31674. 'yen': 556,
  31675. 'florin': 556,
  31676. 'section': 556,
  31677. 'currency': 556,
  31678. 'quotesingle': 238,
  31679. 'quotedblleft': 500,
  31680. 'guillemotleft': 556,
  31681. 'guilsinglleft': 333,
  31682. 'guilsinglright': 333,
  31683. 'fi': 611,
  31684. 'fl': 611,
  31685. 'endash': 556,
  31686. 'dagger': 556,
  31687. 'daggerdbl': 556,
  31688. 'periodcentered': 278,
  31689. 'paragraph': 556,
  31690. 'bullet': 350,
  31691. 'quotesinglbase': 278,
  31692. 'quotedblbase': 500,
  31693. 'quotedblright': 500,
  31694. 'guillemotright': 556,
  31695. 'ellipsis': 1000,
  31696. 'perthousand': 1000,
  31697. 'questiondown': 611,
  31698. 'grave': 333,
  31699. 'acute': 333,
  31700. 'circumflex': 333,
  31701. 'tilde': 333,
  31702. 'macron': 333,
  31703. 'breve': 333,
  31704. 'dotaccent': 333,
  31705. 'dieresis': 333,
  31706. 'ring': 333,
  31707. 'cedilla': 333,
  31708. 'hungarumlaut': 333,
  31709. 'ogonek': 333,
  31710. 'caron': 333,
  31711. 'emdash': 1000,
  31712. 'AE': 1000,
  31713. 'ordfeminine': 370,
  31714. 'Lslash': 611,
  31715. 'Oslash': 778,
  31716. 'OE': 1000,
  31717. 'ordmasculine': 365,
  31718. 'ae': 889,
  31719. 'dotlessi': 278,
  31720. 'lslash': 278,
  31721. 'oslash': 611,
  31722. 'oe': 944,
  31723. 'germandbls': 611,
  31724. 'Idieresis': 278,
  31725. 'eacute': 556,
  31726. 'abreve': 556,
  31727. 'uhungarumlaut': 611,
  31728. 'ecaron': 556,
  31729. 'Ydieresis': 667,
  31730. 'divide': 584,
  31731. 'Yacute': 667,
  31732. 'Acircumflex': 722,
  31733. 'aacute': 556,
  31734. 'Ucircumflex': 722,
  31735. 'yacute': 556,
  31736. 'scommaaccent': 556,
  31737. 'ecircumflex': 556,
  31738. 'Uring': 722,
  31739. 'Udieresis': 722,
  31740. 'aogonek': 556,
  31741. 'Uacute': 722,
  31742. 'uogonek': 611,
  31743. 'Edieresis': 667,
  31744. 'Dcroat': 722,
  31745. 'commaaccent': 250,
  31746. 'copyright': 737,
  31747. 'Emacron': 667,
  31748. 'ccaron': 556,
  31749. 'aring': 556,
  31750. 'Ncommaaccent': 722,
  31751. 'lacute': 278,
  31752. 'agrave': 556,
  31753. 'Tcommaaccent': 611,
  31754. 'Cacute': 722,
  31755. 'atilde': 556,
  31756. 'Edotaccent': 667,
  31757. 'scaron': 556,
  31758. 'scedilla': 556,
  31759. 'iacute': 278,
  31760. 'lozenge': 494,
  31761. 'Rcaron': 722,
  31762. 'Gcommaaccent': 778,
  31763. 'ucircumflex': 611,
  31764. 'acircumflex': 556,
  31765. 'Amacron': 722,
  31766. 'rcaron': 389,
  31767. 'ccedilla': 556,
  31768. 'Zdotaccent': 611,
  31769. 'Thorn': 667,
  31770. 'Omacron': 778,
  31771. 'Racute': 722,
  31772. 'Sacute': 667,
  31773. 'dcaron': 743,
  31774. 'Umacron': 722,
  31775. 'uring': 611,
  31776. 'threesuperior': 333,
  31777. 'Ograve': 778,
  31778. 'Agrave': 722,
  31779. 'Abreve': 722,
  31780. 'multiply': 584,
  31781. 'uacute': 611,
  31782. 'Tcaron': 611,
  31783. 'partialdiff': 494,
  31784. 'ydieresis': 556,
  31785. 'Nacute': 722,
  31786. 'icircumflex': 278,
  31787. 'Ecircumflex': 667,
  31788. 'adieresis': 556,
  31789. 'edieresis': 556,
  31790. 'cacute': 556,
  31791. 'nacute': 611,
  31792. 'umacron': 611,
  31793. 'Ncaron': 722,
  31794. 'Iacute': 278,
  31795. 'plusminus': 584,
  31796. 'brokenbar': 280,
  31797. 'registered': 737,
  31798. 'Gbreve': 778,
  31799. 'Idotaccent': 278,
  31800. 'summation': 600,
  31801. 'Egrave': 667,
  31802. 'racute': 389,
  31803. 'omacron': 611,
  31804. 'Zacute': 611,
  31805. 'Zcaron': 611,
  31806. 'greaterequal': 549,
  31807. 'Eth': 722,
  31808. 'Ccedilla': 722,
  31809. 'lcommaaccent': 278,
  31810. 'tcaron': 389,
  31811. 'eogonek': 556,
  31812. 'Uogonek': 722,
  31813. 'Aacute': 722,
  31814. 'Adieresis': 722,
  31815. 'egrave': 556,
  31816. 'zacute': 500,
  31817. 'iogonek': 278,
  31818. 'Oacute': 778,
  31819. 'oacute': 611,
  31820. 'amacron': 556,
  31821. 'sacute': 556,
  31822. 'idieresis': 278,
  31823. 'Ocircumflex': 778,
  31824. 'Ugrave': 722,
  31825. 'Delta': 612,
  31826. 'thorn': 611,
  31827. 'twosuperior': 333,
  31828. 'Odieresis': 778,
  31829. 'mu': 611,
  31830. 'igrave': 278,
  31831. 'ohungarumlaut': 611,
  31832. 'Eogonek': 667,
  31833. 'dcroat': 611,
  31834. 'threequarters': 834,
  31835. 'Scedilla': 667,
  31836. 'lcaron': 400,
  31837. 'Kcommaaccent': 722,
  31838. 'Lacute': 611,
  31839. 'trademark': 1000,
  31840. 'edotaccent': 556,
  31841. 'Igrave': 278,
  31842. 'Imacron': 278,
  31843. 'Lcaron': 611,
  31844. 'onehalf': 834,
  31845. 'lessequal': 549,
  31846. 'ocircumflex': 611,
  31847. 'ntilde': 611,
  31848. 'Uhungarumlaut': 722,
  31849. 'Eacute': 667,
  31850. 'emacron': 556,
  31851. 'gbreve': 611,
  31852. 'onequarter': 834,
  31853. 'Scaron': 667,
  31854. 'Scommaaccent': 667,
  31855. 'Ohungarumlaut': 778,
  31856. 'degree': 400,
  31857. 'ograve': 611,
  31858. 'Ccaron': 722,
  31859. 'ugrave': 611,
  31860. 'radical': 549,
  31861. 'Dcaron': 722,
  31862. 'rcommaaccent': 389,
  31863. 'Ntilde': 722,
  31864. 'otilde': 611,
  31865. 'Rcommaaccent': 722,
  31866. 'Lcommaaccent': 611,
  31867. 'Atilde': 722,
  31868. 'Aogonek': 722,
  31869. 'Aring': 722,
  31870. 'Otilde': 778,
  31871. 'zdotaccent': 500,
  31872. 'Ecaron': 667,
  31873. 'Iogonek': 278,
  31874. 'kcommaaccent': 556,
  31875. 'minus': 584,
  31876. 'Icircumflex': 278,
  31877. 'ncaron': 611,
  31878. 'tcommaaccent': 333,
  31879. 'logicalnot': 584,
  31880. 'odieresis': 611,
  31881. 'udieresis': 611,
  31882. 'notequal': 549,
  31883. 'gcommaaccent': 611,
  31884. 'eth': 611,
  31885. 'zcaron': 500,
  31886. 'ncommaaccent': 611,
  31887. 'onesuperior': 333,
  31888. 'imacron': 278,
  31889. 'Euro': 556
  31890. },
  31891. 'Helvetica-Oblique' : {
  31892. 'space': 278,
  31893. 'exclam': 278,
  31894. 'quotedbl': 355,
  31895. 'numbersign': 556,
  31896. 'dollar': 556,
  31897. 'percent': 889,
  31898. 'ampersand': 667,
  31899. 'quoteright': 222,
  31900. 'parenleft': 333,
  31901. 'parenright': 333,
  31902. 'asterisk': 389,
  31903. 'plus': 584,
  31904. 'comma': 278,
  31905. 'hyphen': 333,
  31906. 'period': 278,
  31907. 'slash': 278,
  31908. 'zero': 556,
  31909. 'one': 556,
  31910. 'two': 556,
  31911. 'three': 556,
  31912. 'four': 556,
  31913. 'five': 556,
  31914. 'six': 556,
  31915. 'seven': 556,
  31916. 'eight': 556,
  31917. 'nine': 556,
  31918. 'colon': 278,
  31919. 'semicolon': 278,
  31920. 'less': 584,
  31921. 'equal': 584,
  31922. 'greater': 584,
  31923. 'question': 556,
  31924. 'at': 1015,
  31925. 'A': 667,
  31926. 'B': 667,
  31927. 'C': 722,
  31928. 'D': 722,
  31929. 'E': 667,
  31930. 'F': 611,
  31931. 'G': 778,
  31932. 'H': 722,
  31933. 'I': 278,
  31934. 'J': 500,
  31935. 'K': 667,
  31936. 'L': 556,
  31937. 'M': 833,
  31938. 'N': 722,
  31939. 'O': 778,
  31940. 'P': 667,
  31941. 'Q': 778,
  31942. 'R': 722,
  31943. 'S': 667,
  31944. 'T': 611,
  31945. 'U': 722,
  31946. 'V': 667,
  31947. 'W': 944,
  31948. 'X': 667,
  31949. 'Y': 667,
  31950. 'Z': 611,
  31951. 'bracketleft': 278,
  31952. 'backslash': 278,
  31953. 'bracketright': 278,
  31954. 'asciicircum': 469,
  31955. 'underscore': 556,
  31956. 'quoteleft': 222,
  31957. 'a': 556,
  31958. 'b': 556,
  31959. 'c': 500,
  31960. 'd': 556,
  31961. 'e': 556,
  31962. 'f': 278,
  31963. 'g': 556,
  31964. 'h': 556,
  31965. 'i': 222,
  31966. 'j': 222,
  31967. 'k': 500,
  31968. 'l': 222,
  31969. 'm': 833,
  31970. 'n': 556,
  31971. 'o': 556,
  31972. 'p': 556,
  31973. 'q': 556,
  31974. 'r': 333,
  31975. 's': 500,
  31976. 't': 278,
  31977. 'u': 556,
  31978. 'v': 500,
  31979. 'w': 722,
  31980. 'x': 500,
  31981. 'y': 500,
  31982. 'z': 500,
  31983. 'braceleft': 334,
  31984. 'bar': 260,
  31985. 'braceright': 334,
  31986. 'asciitilde': 584,
  31987. 'exclamdown': 333,
  31988. 'cent': 556,
  31989. 'sterling': 556,
  31990. 'fraction': 167,
  31991. 'yen': 556,
  31992. 'florin': 556,
  31993. 'section': 556,
  31994. 'currency': 556,
  31995. 'quotesingle': 191,
  31996. 'quotedblleft': 333,
  31997. 'guillemotleft': 556,
  31998. 'guilsinglleft': 333,
  31999. 'guilsinglright': 333,
  32000. 'fi': 500,
  32001. 'fl': 500,
  32002. 'endash': 556,
  32003. 'dagger': 556,
  32004. 'daggerdbl': 556,
  32005. 'periodcentered': 278,
  32006. 'paragraph': 537,
  32007. 'bullet': 350,
  32008. 'quotesinglbase': 222,
  32009. 'quotedblbase': 333,
  32010. 'quotedblright': 333,
  32011. 'guillemotright': 556,
  32012. 'ellipsis': 1000,
  32013. 'perthousand': 1000,
  32014. 'questiondown': 611,
  32015. 'grave': 333,
  32016. 'acute': 333,
  32017. 'circumflex': 333,
  32018. 'tilde': 333,
  32019. 'macron': 333,
  32020. 'breve': 333,
  32021. 'dotaccent': 333,
  32022. 'dieresis': 333,
  32023. 'ring': 333,
  32024. 'cedilla': 333,
  32025. 'hungarumlaut': 333,
  32026. 'ogonek': 333,
  32027. 'caron': 333,
  32028. 'emdash': 1000,
  32029. 'AE': 1000,
  32030. 'ordfeminine': 370,
  32031. 'Lslash': 556,
  32032. 'Oslash': 778,
  32033. 'OE': 1000,
  32034. 'ordmasculine': 365,
  32035. 'ae': 889,
  32036. 'dotlessi': 278,
  32037. 'lslash': 222,
  32038. 'oslash': 611,
  32039. 'oe': 944,
  32040. 'germandbls': 611,
  32041. 'Idieresis': 278,
  32042. 'eacute': 556,
  32043. 'abreve': 556,
  32044. 'uhungarumlaut': 556,
  32045. 'ecaron': 556,
  32046. 'Ydieresis': 667,
  32047. 'divide': 584,
  32048. 'Yacute': 667,
  32049. 'Acircumflex': 667,
  32050. 'aacute': 556,
  32051. 'Ucircumflex': 722,
  32052. 'yacute': 500,
  32053. 'scommaaccent': 500,
  32054. 'ecircumflex': 556,
  32055. 'Uring': 722,
  32056. 'Udieresis': 722,
  32057. 'aogonek': 556,
  32058. 'Uacute': 722,
  32059. 'uogonek': 556,
  32060. 'Edieresis': 667,
  32061. 'Dcroat': 722,
  32062. 'commaaccent': 250,
  32063. 'copyright': 737,
  32064. 'Emacron': 667,
  32065. 'ccaron': 500,
  32066. 'aring': 556,
  32067. 'Ncommaaccent': 722,
  32068. 'lacute': 222,
  32069. 'agrave': 556,
  32070. 'Tcommaaccent': 611,
  32071. 'Cacute': 722,
  32072. 'atilde': 556,
  32073. 'Edotaccent': 667,
  32074. 'scaron': 500,
  32075. 'scedilla': 500,
  32076. 'iacute': 278,
  32077. 'lozenge': 471,
  32078. 'Rcaron': 722,
  32079. 'Gcommaaccent': 778,
  32080. 'ucircumflex': 556,
  32081. 'acircumflex': 556,
  32082. 'Amacron': 667,
  32083. 'rcaron': 333,
  32084. 'ccedilla': 500,
  32085. 'Zdotaccent': 611,
  32086. 'Thorn': 667,
  32087. 'Omacron': 778,
  32088. 'Racute': 722,
  32089. 'Sacute': 667,
  32090. 'dcaron': 643,
  32091. 'Umacron': 722,
  32092. 'uring': 556,
  32093. 'threesuperior': 333,
  32094. 'Ograve': 778,
  32095. 'Agrave': 667,
  32096. 'Abreve': 667,
  32097. 'multiply': 584,
  32098. 'uacute': 556,
  32099. 'Tcaron': 611,
  32100. 'partialdiff': 476,
  32101. 'ydieresis': 500,
  32102. 'Nacute': 722,
  32103. 'icircumflex': 278,
  32104. 'Ecircumflex': 667,
  32105. 'adieresis': 556,
  32106. 'edieresis': 556,
  32107. 'cacute': 500,
  32108. 'nacute': 556,
  32109. 'umacron': 556,
  32110. 'Ncaron': 722,
  32111. 'Iacute': 278,
  32112. 'plusminus': 584,
  32113. 'brokenbar': 260,
  32114. 'registered': 737,
  32115. 'Gbreve': 778,
  32116. 'Idotaccent': 278,
  32117. 'summation': 600,
  32118. 'Egrave': 667,
  32119. 'racute': 333,
  32120. 'omacron': 556,
  32121. 'Zacute': 611,
  32122. 'Zcaron': 611,
  32123. 'greaterequal': 549,
  32124. 'Eth': 722,
  32125. 'Ccedilla': 722,
  32126. 'lcommaaccent': 222,
  32127. 'tcaron': 317,
  32128. 'eogonek': 556,
  32129. 'Uogonek': 722,
  32130. 'Aacute': 667,
  32131. 'Adieresis': 667,
  32132. 'egrave': 556,
  32133. 'zacute': 500,
  32134. 'iogonek': 222,
  32135. 'Oacute': 778,
  32136. 'oacute': 556,
  32137. 'amacron': 556,
  32138. 'sacute': 500,
  32139. 'idieresis': 278,
  32140. 'Ocircumflex': 778,
  32141. 'Ugrave': 722,
  32142. 'Delta': 612,
  32143. 'thorn': 556,
  32144. 'twosuperior': 333,
  32145. 'Odieresis': 778,
  32146. 'mu': 556,
  32147. 'igrave': 278,
  32148. 'ohungarumlaut': 556,
  32149. 'Eogonek': 667,
  32150. 'dcroat': 556,
  32151. 'threequarters': 834,
  32152. 'Scedilla': 667,
  32153. 'lcaron': 299,
  32154. 'Kcommaaccent': 667,
  32155. 'Lacute': 556,
  32156. 'trademark': 1000,
  32157. 'edotaccent': 556,
  32158. 'Igrave': 278,
  32159. 'Imacron': 278,
  32160. 'Lcaron': 556,
  32161. 'onehalf': 834,
  32162. 'lessequal': 549,
  32163. 'ocircumflex': 556,
  32164. 'ntilde': 556,
  32165. 'Uhungarumlaut': 722,
  32166. 'Eacute': 667,
  32167. 'emacron': 556,
  32168. 'gbreve': 556,
  32169. 'onequarter': 834,
  32170. 'Scaron': 667,
  32171. 'Scommaaccent': 667,
  32172. 'Ohungarumlaut': 778,
  32173. 'degree': 400,
  32174. 'ograve': 556,
  32175. 'Ccaron': 722,
  32176. 'ugrave': 556,
  32177. 'radical': 453,
  32178. 'Dcaron': 722,
  32179. 'rcommaaccent': 333,
  32180. 'Ntilde': 722,
  32181. 'otilde': 556,
  32182. 'Rcommaaccent': 722,
  32183. 'Lcommaaccent': 556,
  32184. 'Atilde': 667,
  32185. 'Aogonek': 667,
  32186. 'Aring': 667,
  32187. 'Otilde': 778,
  32188. 'zdotaccent': 500,
  32189. 'Ecaron': 667,
  32190. 'Iogonek': 278,
  32191. 'kcommaaccent': 500,
  32192. 'minus': 584,
  32193. 'Icircumflex': 278,
  32194. 'ncaron': 556,
  32195. 'tcommaaccent': 278,
  32196. 'logicalnot': 584,
  32197. 'odieresis': 556,
  32198. 'udieresis': 556,
  32199. 'notequal': 549,
  32200. 'gcommaaccent': 556,
  32201. 'eth': 556,
  32202. 'zcaron': 500,
  32203. 'ncommaaccent': 556,
  32204. 'onesuperior': 333,
  32205. 'imacron': 278,
  32206. 'Euro': 556
  32207. },
  32208. 'Symbol': {
  32209. 'space': 250,
  32210. 'exclam': 333,
  32211. 'universal': 713,
  32212. 'numbersign': 500,
  32213. 'existential': 549,
  32214. 'percent': 833,
  32215. 'ampersand': 778,
  32216. 'suchthat': 439,
  32217. 'parenleft': 333,
  32218. 'parenright': 333,
  32219. 'asteriskmath': 500,
  32220. 'plus': 549,
  32221. 'comma': 250,
  32222. 'minus': 549,
  32223. 'period': 250,
  32224. 'slash': 278,
  32225. 'zero': 500,
  32226. 'one': 500,
  32227. 'two': 500,
  32228. 'three': 500,
  32229. 'four': 500,
  32230. 'five': 500,
  32231. 'six': 500,
  32232. 'seven': 500,
  32233. 'eight': 500,
  32234. 'nine': 500,
  32235. 'colon': 278,
  32236. 'semicolon': 278,
  32237. 'less': 549,
  32238. 'equal': 549,
  32239. 'greater': 549,
  32240. 'question': 444,
  32241. 'congruent': 549,
  32242. 'Alpha': 722,
  32243. 'Beta': 667,
  32244. 'Chi': 722,
  32245. 'Delta': 612,
  32246. 'Epsilon': 611,
  32247. 'Phi': 763,
  32248. 'Gamma': 603,
  32249. 'Eta': 722,
  32250. 'Iota': 333,
  32251. 'theta1': 631,
  32252. 'Kappa': 722,
  32253. 'Lambda': 686,
  32254. 'Mu': 889,
  32255. 'Nu': 722,
  32256. 'Omicron': 722,
  32257. 'Pi': 768,
  32258. 'Theta': 741,
  32259. 'Rho': 556,
  32260. 'Sigma': 592,
  32261. 'Tau': 611,
  32262. 'Upsilon': 690,
  32263. 'sigma1': 439,
  32264. 'Omega': 768,
  32265. 'Xi': 645,
  32266. 'Psi': 795,
  32267. 'Zeta': 611,
  32268. 'bracketleft': 333,
  32269. 'therefore': 863,
  32270. 'bracketright': 333,
  32271. 'perpendicular': 658,
  32272. 'underscore': 500,
  32273. 'radicalex': 500,
  32274. 'alpha': 631,
  32275. 'beta': 549,
  32276. 'chi': 549,
  32277. 'delta': 494,
  32278. 'epsilon': 439,
  32279. 'phi': 521,
  32280. 'gamma': 411,
  32281. 'eta': 603,
  32282. 'iota': 329,
  32283. 'phi1': 603,
  32284. 'kappa': 549,
  32285. 'lambda': 549,
  32286. 'mu': 576,
  32287. 'nu': 521,
  32288. 'omicron': 549,
  32289. 'pi': 549,
  32290. 'theta': 521,
  32291. 'rho': 549,
  32292. 'sigma': 603,
  32293. 'tau': 439,
  32294. 'upsilon': 576,
  32295. 'omega1': 713,
  32296. 'omega': 686,
  32297. 'xi': 493,
  32298. 'psi': 686,
  32299. 'zeta': 494,
  32300. 'braceleft': 480,
  32301. 'bar': 200,
  32302. 'braceright': 480,
  32303. 'similar': 549,
  32304. 'Euro': 750,
  32305. 'Upsilon1': 620,
  32306. 'minute': 247,
  32307. 'lessequal': 549,
  32308. 'fraction': 167,
  32309. 'infinity': 713,
  32310. 'florin': 500,
  32311. 'club': 753,
  32312. 'diamond': 753,
  32313. 'heart': 753,
  32314. 'spade': 753,
  32315. 'arrowboth': 1042,
  32316. 'arrowleft': 987,
  32317. 'arrowup': 603,
  32318. 'arrowright': 987,
  32319. 'arrowdown': 603,
  32320. 'degree': 400,
  32321. 'plusminus': 549,
  32322. 'second': 411,
  32323. 'greaterequal': 549,
  32324. 'multiply': 549,
  32325. 'proportional': 713,
  32326. 'partialdiff': 494,
  32327. 'bullet': 460,
  32328. 'divide': 549,
  32329. 'notequal': 549,
  32330. 'equivalence': 549,
  32331. 'approxequal': 549,
  32332. 'ellipsis': 1000,
  32333. 'arrowvertex': 603,
  32334. 'arrowhorizex': 1000,
  32335. 'carriagereturn': 658,
  32336. 'aleph': 823,
  32337. 'Ifraktur': 686,
  32338. 'Rfraktur': 795,
  32339. 'weierstrass': 987,
  32340. 'circlemultiply': 768,
  32341. 'circleplus': 768,
  32342. 'emptyset': 823,
  32343. 'intersection': 768,
  32344. 'union': 768,
  32345. 'propersuperset': 713,
  32346. 'reflexsuperset': 713,
  32347. 'notsubset': 713,
  32348. 'propersubset': 713,
  32349. 'reflexsubset': 713,
  32350. 'element': 713,
  32351. 'notelement': 713,
  32352. 'angle': 768,
  32353. 'gradient': 713,
  32354. 'registerserif': 790,
  32355. 'copyrightserif': 790,
  32356. 'trademarkserif': 890,
  32357. 'product': 823,
  32358. 'radical': 549,
  32359. 'dotmath': 250,
  32360. 'logicalnot': 713,
  32361. 'logicaland': 603,
  32362. 'logicalor': 603,
  32363. 'arrowdblboth': 1042,
  32364. 'arrowdblleft': 987,
  32365. 'arrowdblup': 603,
  32366. 'arrowdblright': 987,
  32367. 'arrowdbldown': 603,
  32368. 'lozenge': 494,
  32369. 'angleleft': 329,
  32370. 'registersans': 790,
  32371. 'copyrightsans': 790,
  32372. 'trademarksans': 786,
  32373. 'summation': 713,
  32374. 'parenlefttp': 384,
  32375. 'parenleftex': 384,
  32376. 'parenleftbt': 384,
  32377. 'bracketlefttp': 384,
  32378. 'bracketleftex': 384,
  32379. 'bracketleftbt': 384,
  32380. 'bracelefttp': 494,
  32381. 'braceleftmid': 494,
  32382. 'braceleftbt': 494,
  32383. 'braceex': 494,
  32384. 'angleright': 329,
  32385. 'integral': 274,
  32386. 'integraltp': 686,
  32387. 'integralex': 686,
  32388. 'integralbt': 686,
  32389. 'parenrighttp': 384,
  32390. 'parenrightex': 384,
  32391. 'parenrightbt': 384,
  32392. 'bracketrighttp': 384,
  32393. 'bracketrightex': 384,
  32394. 'bracketrightbt': 384,
  32395. 'bracerighttp': 494,
  32396. 'bracerightmid': 494,
  32397. 'bracerightbt': 494,
  32398. 'apple': 790
  32399. },
  32400. 'Times-Roman': {
  32401. 'space': 250,
  32402. 'exclam': 333,
  32403. 'quotedbl': 408,
  32404. 'numbersign': 500,
  32405. 'dollar': 500,
  32406. 'percent': 833,
  32407. 'ampersand': 778,
  32408. 'quoteright': 333,
  32409. 'parenleft': 333,
  32410. 'parenright': 333,
  32411. 'asterisk': 500,
  32412. 'plus': 564,
  32413. 'comma': 250,
  32414. 'hyphen': 333,
  32415. 'period': 250,
  32416. 'slash': 278,
  32417. 'zero': 500,
  32418. 'one': 500,
  32419. 'two': 500,
  32420. 'three': 500,
  32421. 'four': 500,
  32422. 'five': 500,
  32423. 'six': 500,
  32424. 'seven': 500,
  32425. 'eight': 500,
  32426. 'nine': 500,
  32427. 'colon': 278,
  32428. 'semicolon': 278,
  32429. 'less': 564,
  32430. 'equal': 564,
  32431. 'greater': 564,
  32432. 'question': 444,
  32433. 'at': 921,
  32434. 'A': 722,
  32435. 'B': 667,
  32436. 'C': 667,
  32437. 'D': 722,
  32438. 'E': 611,
  32439. 'F': 556,
  32440. 'G': 722,
  32441. 'H': 722,
  32442. 'I': 333,
  32443. 'J': 389,
  32444. 'K': 722,
  32445. 'L': 611,
  32446. 'M': 889,
  32447. 'N': 722,
  32448. 'O': 722,
  32449. 'P': 556,
  32450. 'Q': 722,
  32451. 'R': 667,
  32452. 'S': 556,
  32453. 'T': 611,
  32454. 'U': 722,
  32455. 'V': 722,
  32456. 'W': 944,
  32457. 'X': 722,
  32458. 'Y': 722,
  32459. 'Z': 611,
  32460. 'bracketleft': 333,
  32461. 'backslash': 278,
  32462. 'bracketright': 333,
  32463. 'asciicircum': 469,
  32464. 'underscore': 500,
  32465. 'quoteleft': 333,
  32466. 'a': 444,
  32467. 'b': 500,
  32468. 'c': 444,
  32469. 'd': 500,
  32470. 'e': 444,
  32471. 'f': 333,
  32472. 'g': 500,
  32473. 'h': 500,
  32474. 'i': 278,
  32475. 'j': 278,
  32476. 'k': 500,
  32477. 'l': 278,
  32478. 'm': 778,
  32479. 'n': 500,
  32480. 'o': 500,
  32481. 'p': 500,
  32482. 'q': 500,
  32483. 'r': 333,
  32484. 's': 389,
  32485. 't': 278,
  32486. 'u': 500,
  32487. 'v': 500,
  32488. 'w': 722,
  32489. 'x': 500,
  32490. 'y': 500,
  32491. 'z': 444,
  32492. 'braceleft': 480,
  32493. 'bar': 200,
  32494. 'braceright': 480,
  32495. 'asciitilde': 541,
  32496. 'exclamdown': 333,
  32497. 'cent': 500,
  32498. 'sterling': 500,
  32499. 'fraction': 167,
  32500. 'yen': 500,
  32501. 'florin': 500,
  32502. 'section': 500,
  32503. 'currency': 500,
  32504. 'quotesingle': 180,
  32505. 'quotedblleft': 444,
  32506. 'guillemotleft': 500,
  32507. 'guilsinglleft': 333,
  32508. 'guilsinglright': 333,
  32509. 'fi': 556,
  32510. 'fl': 556,
  32511. 'endash': 500,
  32512. 'dagger': 500,
  32513. 'daggerdbl': 500,
  32514. 'periodcentered': 250,
  32515. 'paragraph': 453,
  32516. 'bullet': 350,
  32517. 'quotesinglbase': 333,
  32518. 'quotedblbase': 444,
  32519. 'quotedblright': 444,
  32520. 'guillemotright': 500,
  32521. 'ellipsis': 1000,
  32522. 'perthousand': 1000,
  32523. 'questiondown': 444,
  32524. 'grave': 333,
  32525. 'acute': 333,
  32526. 'circumflex': 333,
  32527. 'tilde': 333,
  32528. 'macron': 333,
  32529. 'breve': 333,
  32530. 'dotaccent': 333,
  32531. 'dieresis': 333,
  32532. 'ring': 333,
  32533. 'cedilla': 333,
  32534. 'hungarumlaut': 333,
  32535. 'ogonek': 333,
  32536. 'caron': 333,
  32537. 'emdash': 1000,
  32538. 'AE': 889,
  32539. 'ordfeminine': 276,
  32540. 'Lslash': 611,
  32541. 'Oslash': 722,
  32542. 'OE': 889,
  32543. 'ordmasculine': 310,
  32544. 'ae': 667,
  32545. 'dotlessi': 278,
  32546. 'lslash': 278,
  32547. 'oslash': 500,
  32548. 'oe': 722,
  32549. 'germandbls': 500,
  32550. 'Idieresis': 333,
  32551. 'eacute': 444,
  32552. 'abreve': 444,
  32553. 'uhungarumlaut': 500,
  32554. 'ecaron': 444,
  32555. 'Ydieresis': 722,
  32556. 'divide': 564,
  32557. 'Yacute': 722,
  32558. 'Acircumflex': 722,
  32559. 'aacute': 444,
  32560. 'Ucircumflex': 722,
  32561. 'yacute': 500,
  32562. 'scommaaccent': 389,
  32563. 'ecircumflex': 444,
  32564. 'Uring': 722,
  32565. 'Udieresis': 722,
  32566. 'aogonek': 444,
  32567. 'Uacute': 722,
  32568. 'uogonek': 500,
  32569. 'Edieresis': 611,
  32570. 'Dcroat': 722,
  32571. 'commaaccent': 250,
  32572. 'copyright': 760,
  32573. 'Emacron': 611,
  32574. 'ccaron': 444,
  32575. 'aring': 444,
  32576. 'Ncommaaccent': 722,
  32577. 'lacute': 278,
  32578. 'agrave': 444,
  32579. 'Tcommaaccent': 611,
  32580. 'Cacute': 667,
  32581. 'atilde': 444,
  32582. 'Edotaccent': 611,
  32583. 'scaron': 389,
  32584. 'scedilla': 389,
  32585. 'iacute': 278,
  32586. 'lozenge': 471,
  32587. 'Rcaron': 667,
  32588. 'Gcommaaccent': 722,
  32589. 'ucircumflex': 500,
  32590. 'acircumflex': 444,
  32591. 'Amacron': 722,
  32592. 'rcaron': 333,
  32593. 'ccedilla': 444,
  32594. 'Zdotaccent': 611,
  32595. 'Thorn': 556,
  32596. 'Omacron': 722,
  32597. 'Racute': 667,
  32598. 'Sacute': 556,
  32599. 'dcaron': 588,
  32600. 'Umacron': 722,
  32601. 'uring': 500,
  32602. 'threesuperior': 300,
  32603. 'Ograve': 722,
  32604. 'Agrave': 722,
  32605. 'Abreve': 722,
  32606. 'multiply': 564,
  32607. 'uacute': 500,
  32608. 'Tcaron': 611,
  32609. 'partialdiff': 476,
  32610. 'ydieresis': 500,
  32611. 'Nacute': 722,
  32612. 'icircumflex': 278,
  32613. 'Ecircumflex': 611,
  32614. 'adieresis': 444,
  32615. 'edieresis': 444,
  32616. 'cacute': 444,
  32617. 'nacute': 500,
  32618. 'umacron': 500,
  32619. 'Ncaron': 722,
  32620. 'Iacute': 333,
  32621. 'plusminus': 564,
  32622. 'brokenbar': 200,
  32623. 'registered': 760,
  32624. 'Gbreve': 722,
  32625. 'Idotaccent': 333,
  32626. 'summation': 600,
  32627. 'Egrave': 611,
  32628. 'racute': 333,
  32629. 'omacron': 500,
  32630. 'Zacute': 611,
  32631. 'Zcaron': 611,
  32632. 'greaterequal': 549,
  32633. 'Eth': 722,
  32634. 'Ccedilla': 667,
  32635. 'lcommaaccent': 278,
  32636. 'tcaron': 326,
  32637. 'eogonek': 444,
  32638. 'Uogonek': 722,
  32639. 'Aacute': 722,
  32640. 'Adieresis': 722,
  32641. 'egrave': 444,
  32642. 'zacute': 444,
  32643. 'iogonek': 278,
  32644. 'Oacute': 722,
  32645. 'oacute': 500,
  32646. 'amacron': 444,
  32647. 'sacute': 389,
  32648. 'idieresis': 278,
  32649. 'Ocircumflex': 722,
  32650. 'Ugrave': 722,
  32651. 'Delta': 612,
  32652. 'thorn': 500,
  32653. 'twosuperior': 300,
  32654. 'Odieresis': 722,
  32655. 'mu': 500,
  32656. 'igrave': 278,
  32657. 'ohungarumlaut': 500,
  32658. 'Eogonek': 611,
  32659. 'dcroat': 500,
  32660. 'threequarters': 750,
  32661. 'Scedilla': 556,
  32662. 'lcaron': 344,
  32663. 'Kcommaaccent': 722,
  32664. 'Lacute': 611,
  32665. 'trademark': 980,
  32666. 'edotaccent': 444,
  32667. 'Igrave': 333,
  32668. 'Imacron': 333,
  32669. 'Lcaron': 611,
  32670. 'onehalf': 750,
  32671. 'lessequal': 549,
  32672. 'ocircumflex': 500,
  32673. 'ntilde': 500,
  32674. 'Uhungarumlaut': 722,
  32675. 'Eacute': 611,
  32676. 'emacron': 444,
  32677. 'gbreve': 500,
  32678. 'onequarter': 750,
  32679. 'Scaron': 556,
  32680. 'Scommaaccent': 556,
  32681. 'Ohungarumlaut': 722,
  32682. 'degree': 400,
  32683. 'ograve': 500,
  32684. 'Ccaron': 667,
  32685. 'ugrave': 500,
  32686. 'radical': 453,
  32687. 'Dcaron': 722,
  32688. 'rcommaaccent': 333,
  32689. 'Ntilde': 722,
  32690. 'otilde': 500,
  32691. 'Rcommaaccent': 667,
  32692. 'Lcommaaccent': 611,
  32693. 'Atilde': 722,
  32694. 'Aogonek': 722,
  32695. 'Aring': 722,
  32696. 'Otilde': 722,
  32697. 'zdotaccent': 444,
  32698. 'Ecaron': 611,
  32699. 'Iogonek': 333,
  32700. 'kcommaaccent': 500,
  32701. 'minus': 564,
  32702. 'Icircumflex': 333,
  32703. 'ncaron': 500,
  32704. 'tcommaaccent': 278,
  32705. 'logicalnot': 564,
  32706. 'odieresis': 500,
  32707. 'udieresis': 500,
  32708. 'notequal': 549,
  32709. 'gcommaaccent': 500,
  32710. 'eth': 500,
  32711. 'zcaron': 444,
  32712. 'ncommaaccent': 500,
  32713. 'onesuperior': 300,
  32714. 'imacron': 278,
  32715. 'Euro': 500
  32716. },
  32717. 'Times-Bold': {
  32718. 'space': 250,
  32719. 'exclam': 333,
  32720. 'quotedbl': 555,
  32721. 'numbersign': 500,
  32722. 'dollar': 500,
  32723. 'percent': 1000,
  32724. 'ampersand': 833,
  32725. 'quoteright': 333,
  32726. 'parenleft': 333,
  32727. 'parenright': 333,
  32728. 'asterisk': 500,
  32729. 'plus': 570,
  32730. 'comma': 250,
  32731. 'hyphen': 333,
  32732. 'period': 250,
  32733. 'slash': 278,
  32734. 'zero': 500,
  32735. 'one': 500,
  32736. 'two': 500,
  32737. 'three': 500,
  32738. 'four': 500,
  32739. 'five': 500,
  32740. 'six': 500,
  32741. 'seven': 500,
  32742. 'eight': 500,
  32743. 'nine': 500,
  32744. 'colon': 333,
  32745. 'semicolon': 333,
  32746. 'less': 570,
  32747. 'equal': 570,
  32748. 'greater': 570,
  32749. 'question': 500,
  32750. 'at': 930,
  32751. 'A': 722,
  32752. 'B': 667,
  32753. 'C': 722,
  32754. 'D': 722,
  32755. 'E': 667,
  32756. 'F': 611,
  32757. 'G': 778,
  32758. 'H': 778,
  32759. 'I': 389,
  32760. 'J': 500,
  32761. 'K': 778,
  32762. 'L': 667,
  32763. 'M': 944,
  32764. 'N': 722,
  32765. 'O': 778,
  32766. 'P': 611,
  32767. 'Q': 778,
  32768. 'R': 722,
  32769. 'S': 556,
  32770. 'T': 667,
  32771. 'U': 722,
  32772. 'V': 722,
  32773. 'W': 1000,
  32774. 'X': 722,
  32775. 'Y': 722,
  32776. 'Z': 667,
  32777. 'bracketleft': 333,
  32778. 'backslash': 278,
  32779. 'bracketright': 333,
  32780. 'asciicircum': 581,
  32781. 'underscore': 500,
  32782. 'quoteleft': 333,
  32783. 'a': 500,
  32784. 'b': 556,
  32785. 'c': 444,
  32786. 'd': 556,
  32787. 'e': 444,
  32788. 'f': 333,
  32789. 'g': 500,
  32790. 'h': 556,
  32791. 'i': 278,
  32792. 'j': 333,
  32793. 'k': 556,
  32794. 'l': 278,
  32795. 'm': 833,
  32796. 'n': 556,
  32797. 'o': 500,
  32798. 'p': 556,
  32799. 'q': 556,
  32800. 'r': 444,
  32801. 's': 389,
  32802. 't': 333,
  32803. 'u': 556,
  32804. 'v': 500,
  32805. 'w': 722,
  32806. 'x': 500,
  32807. 'y': 500,
  32808. 'z': 444,
  32809. 'braceleft': 394,
  32810. 'bar': 220,
  32811. 'braceright': 394,
  32812. 'asciitilde': 520,
  32813. 'exclamdown': 333,
  32814. 'cent': 500,
  32815. 'sterling': 500,
  32816. 'fraction': 167,
  32817. 'yen': 500,
  32818. 'florin': 500,
  32819. 'section': 500,
  32820. 'currency': 500,
  32821. 'quotesingle': 278,
  32822. 'quotedblleft': 500,
  32823. 'guillemotleft': 500,
  32824. 'guilsinglleft': 333,
  32825. 'guilsinglright': 333,
  32826. 'fi': 556,
  32827. 'fl': 556,
  32828. 'endash': 500,
  32829. 'dagger': 500,
  32830. 'daggerdbl': 500,
  32831. 'periodcentered': 250,
  32832. 'paragraph': 540,
  32833. 'bullet': 350,
  32834. 'quotesinglbase': 333,
  32835. 'quotedblbase': 500,
  32836. 'quotedblright': 500,
  32837. 'guillemotright': 500,
  32838. 'ellipsis': 1000,
  32839. 'perthousand': 1000,
  32840. 'questiondown': 500,
  32841. 'grave': 333,
  32842. 'acute': 333,
  32843. 'circumflex': 333,
  32844. 'tilde': 333,
  32845. 'macron': 333,
  32846. 'breve': 333,
  32847. 'dotaccent': 333,
  32848. 'dieresis': 333,
  32849. 'ring': 333,
  32850. 'cedilla': 333,
  32851. 'hungarumlaut': 333,
  32852. 'ogonek': 333,
  32853. 'caron': 333,
  32854. 'emdash': 1000,
  32855. 'AE': 1000,
  32856. 'ordfeminine': 300,
  32857. 'Lslash': 667,
  32858. 'Oslash': 778,
  32859. 'OE': 1000,
  32860. 'ordmasculine': 330,
  32861. 'ae': 722,
  32862. 'dotlessi': 278,
  32863. 'lslash': 278,
  32864. 'oslash': 500,
  32865. 'oe': 722,
  32866. 'germandbls': 556,
  32867. 'Idieresis': 389,
  32868. 'eacute': 444,
  32869. 'abreve': 500,
  32870. 'uhungarumlaut': 556,
  32871. 'ecaron': 444,
  32872. 'Ydieresis': 722,
  32873. 'divide': 570,
  32874. 'Yacute': 722,
  32875. 'Acircumflex': 722,
  32876. 'aacute': 500,
  32877. 'Ucircumflex': 722,
  32878. 'yacute': 500,
  32879. 'scommaaccent': 389,
  32880. 'ecircumflex': 444,
  32881. 'Uring': 722,
  32882. 'Udieresis': 722,
  32883. 'aogonek': 500,
  32884. 'Uacute': 722,
  32885. 'uogonek': 556,
  32886. 'Edieresis': 667,
  32887. 'Dcroat': 722,
  32888. 'commaaccent': 250,
  32889. 'copyright': 747,
  32890. 'Emacron': 667,
  32891. 'ccaron': 444,
  32892. 'aring': 500,
  32893. 'Ncommaaccent': 722,
  32894. 'lacute': 278,
  32895. 'agrave': 500,
  32896. 'Tcommaaccent': 667,
  32897. 'Cacute': 722,
  32898. 'atilde': 500,
  32899. 'Edotaccent': 667,
  32900. 'scaron': 389,
  32901. 'scedilla': 389,
  32902. 'iacute': 278,
  32903. 'lozenge': 494,
  32904. 'Rcaron': 722,
  32905. 'Gcommaaccent': 778,
  32906. 'ucircumflex': 556,
  32907. 'acircumflex': 500,
  32908. 'Amacron': 722,
  32909. 'rcaron': 444,
  32910. 'ccedilla': 444,
  32911. 'Zdotaccent': 667,
  32912. 'Thorn': 611,
  32913. 'Omacron': 778,
  32914. 'Racute': 722,
  32915. 'Sacute': 556,
  32916. 'dcaron': 672,
  32917. 'Umacron': 722,
  32918. 'uring': 556,
  32919. 'threesuperior': 300,
  32920. 'Ograve': 778,
  32921. 'Agrave': 722,
  32922. 'Abreve': 722,
  32923. 'multiply': 570,
  32924. 'uacute': 556,
  32925. 'Tcaron': 667,
  32926. 'partialdiff': 494,
  32927. 'ydieresis': 500,
  32928. 'Nacute': 722,
  32929. 'icircumflex': 278,
  32930. 'Ecircumflex': 667,
  32931. 'adieresis': 500,
  32932. 'edieresis': 444,
  32933. 'cacute': 444,
  32934. 'nacute': 556,
  32935. 'umacron': 556,
  32936. 'Ncaron': 722,
  32937. 'Iacute': 389,
  32938. 'plusminus': 570,
  32939. 'brokenbar': 220,
  32940. 'registered': 747,
  32941. 'Gbreve': 778,
  32942. 'Idotaccent': 389,
  32943. 'summation': 600,
  32944. 'Egrave': 667,
  32945. 'racute': 444,
  32946. 'omacron': 500,
  32947. 'Zacute': 667,
  32948. 'Zcaron': 667,
  32949. 'greaterequal': 549,
  32950. 'Eth': 722,
  32951. 'Ccedilla': 722,
  32952. 'lcommaaccent': 278,
  32953. 'tcaron': 416,
  32954. 'eogonek': 444,
  32955. 'Uogonek': 722,
  32956. 'Aacute': 722,
  32957. 'Adieresis': 722,
  32958. 'egrave': 444,
  32959. 'zacute': 444,
  32960. 'iogonek': 278,
  32961. 'Oacute': 778,
  32962. 'oacute': 500,
  32963. 'amacron': 500,
  32964. 'sacute': 389,
  32965. 'idieresis': 278,
  32966. 'Ocircumflex': 778,
  32967. 'Ugrave': 722,
  32968. 'Delta': 612,
  32969. 'thorn': 556,
  32970. 'twosuperior': 300,
  32971. 'Odieresis': 778,
  32972. 'mu': 556,
  32973. 'igrave': 278,
  32974. 'ohungarumlaut': 500,
  32975. 'Eogonek': 667,
  32976. 'dcroat': 556,
  32977. 'threequarters': 750,
  32978. 'Scedilla': 556,
  32979. 'lcaron': 394,
  32980. 'Kcommaaccent': 778,
  32981. 'Lacute': 667,
  32982. 'trademark': 1000,
  32983. 'edotaccent': 444,
  32984. 'Igrave': 389,
  32985. 'Imacron': 389,
  32986. 'Lcaron': 667,
  32987. 'onehalf': 750,
  32988. 'lessequal': 549,
  32989. 'ocircumflex': 500,
  32990. 'ntilde': 556,
  32991. 'Uhungarumlaut': 722,
  32992. 'Eacute': 667,
  32993. 'emacron': 444,
  32994. 'gbreve': 500,
  32995. 'onequarter': 750,
  32996. 'Scaron': 556,
  32997. 'Scommaaccent': 556,
  32998. 'Ohungarumlaut': 778,
  32999. 'degree': 400,
  33000. 'ograve': 500,
  33001. 'Ccaron': 722,
  33002. 'ugrave': 556,
  33003. 'radical': 549,
  33004. 'Dcaron': 722,
  33005. 'rcommaaccent': 444,
  33006. 'Ntilde': 722,
  33007. 'otilde': 500,
  33008. 'Rcommaaccent': 722,
  33009. 'Lcommaaccent': 667,
  33010. 'Atilde': 722,
  33011. 'Aogonek': 722,
  33012. 'Aring': 722,
  33013. 'Otilde': 778,
  33014. 'zdotaccent': 444,
  33015. 'Ecaron': 667,
  33016. 'Iogonek': 389,
  33017. 'kcommaaccent': 556,
  33018. 'minus': 570,
  33019. 'Icircumflex': 389,
  33020. 'ncaron': 556,
  33021. 'tcommaaccent': 333,
  33022. 'logicalnot': 570,
  33023. 'odieresis': 500,
  33024. 'udieresis': 556,
  33025. 'notequal': 549,
  33026. 'gcommaaccent': 500,
  33027. 'eth': 500,
  33028. 'zcaron': 444,
  33029. 'ncommaaccent': 556,
  33030. 'onesuperior': 300,
  33031. 'imacron': 278,
  33032. 'Euro': 500
  33033. },
  33034. 'Times-BoldItalic': {
  33035. 'space': 250,
  33036. 'exclam': 389,
  33037. 'quotedbl': 555,
  33038. 'numbersign': 500,
  33039. 'dollar': 500,
  33040. 'percent': 833,
  33041. 'ampersand': 778,
  33042. 'quoteright': 333,
  33043. 'parenleft': 333,
  33044. 'parenright': 333,
  33045. 'asterisk': 500,
  33046. 'plus': 570,
  33047. 'comma': 250,
  33048. 'hyphen': 333,
  33049. 'period': 250,
  33050. 'slash': 278,
  33051. 'zero': 500,
  33052. 'one': 500,
  33053. 'two': 500,
  33054. 'three': 500,
  33055. 'four': 500,
  33056. 'five': 500,
  33057. 'six': 500,
  33058. 'seven': 500,
  33059. 'eight': 500,
  33060. 'nine': 500,
  33061. 'colon': 333,
  33062. 'semicolon': 333,
  33063. 'less': 570,
  33064. 'equal': 570,
  33065. 'greater': 570,
  33066. 'question': 500,
  33067. 'at': 832,
  33068. 'A': 667,
  33069. 'B': 667,
  33070. 'C': 667,
  33071. 'D': 722,
  33072. 'E': 667,
  33073. 'F': 667,
  33074. 'G': 722,
  33075. 'H': 778,
  33076. 'I': 389,
  33077. 'J': 500,
  33078. 'K': 667,
  33079. 'L': 611,
  33080. 'M': 889,
  33081. 'N': 722,
  33082. 'O': 722,
  33083. 'P': 611,
  33084. 'Q': 722,
  33085. 'R': 667,
  33086. 'S': 556,
  33087. 'T': 611,
  33088. 'U': 722,
  33089. 'V': 667,
  33090. 'W': 889,
  33091. 'X': 667,
  33092. 'Y': 611,
  33093. 'Z': 611,
  33094. 'bracketleft': 333,
  33095. 'backslash': 278,
  33096. 'bracketright': 333,
  33097. 'asciicircum': 570,
  33098. 'underscore': 500,
  33099. 'quoteleft': 333,
  33100. 'a': 500,
  33101. 'b': 500,
  33102. 'c': 444,
  33103. 'd': 500,
  33104. 'e': 444,
  33105. 'f': 333,
  33106. 'g': 500,
  33107. 'h': 556,
  33108. 'i': 278,
  33109. 'j': 278,
  33110. 'k': 500,
  33111. 'l': 278,
  33112. 'm': 778,
  33113. 'n': 556,
  33114. 'o': 500,
  33115. 'p': 500,
  33116. 'q': 500,
  33117. 'r': 389,
  33118. 's': 389,
  33119. 't': 278,
  33120. 'u': 556,
  33121. 'v': 444,
  33122. 'w': 667,
  33123. 'x': 500,
  33124. 'y': 444,
  33125. 'z': 389,
  33126. 'braceleft': 348,
  33127. 'bar': 220,
  33128. 'braceright': 348,
  33129. 'asciitilde': 570,
  33130. 'exclamdown': 389,
  33131. 'cent': 500,
  33132. 'sterling': 500,
  33133. 'fraction': 167,
  33134. 'yen': 500,
  33135. 'florin': 500,
  33136. 'section': 500,
  33137. 'currency': 500,
  33138. 'quotesingle': 278,
  33139. 'quotedblleft': 500,
  33140. 'guillemotleft': 500,
  33141. 'guilsinglleft': 333,
  33142. 'guilsinglright': 333,
  33143. 'fi': 556,
  33144. 'fl': 556,
  33145. 'endash': 500,
  33146. 'dagger': 500,
  33147. 'daggerdbl': 500,
  33148. 'periodcentered': 250,
  33149. 'paragraph': 500,
  33150. 'bullet': 350,
  33151. 'quotesinglbase': 333,
  33152. 'quotedblbase': 500,
  33153. 'quotedblright': 500,
  33154. 'guillemotright': 500,
  33155. 'ellipsis': 1000,
  33156. 'perthousand': 1000,
  33157. 'questiondown': 500,
  33158. 'grave': 333,
  33159. 'acute': 333,
  33160. 'circumflex': 333,
  33161. 'tilde': 333,
  33162. 'macron': 333,
  33163. 'breve': 333,
  33164. 'dotaccent': 333,
  33165. 'dieresis': 333,
  33166. 'ring': 333,
  33167. 'cedilla': 333,
  33168. 'hungarumlaut': 333,
  33169. 'ogonek': 333,
  33170. 'caron': 333,
  33171. 'emdash': 1000,
  33172. 'AE': 944,
  33173. 'ordfeminine': 266,
  33174. 'Lslash': 611,
  33175. 'Oslash': 722,
  33176. 'OE': 944,
  33177. 'ordmasculine': 300,
  33178. 'ae': 722,
  33179. 'dotlessi': 278,
  33180. 'lslash': 278,
  33181. 'oslash': 500,
  33182. 'oe': 722,
  33183. 'germandbls': 500,
  33184. 'Idieresis': 389,
  33185. 'eacute': 444,
  33186. 'abreve': 500,
  33187. 'uhungarumlaut': 556,
  33188. 'ecaron': 444,
  33189. 'Ydieresis': 611,
  33190. 'divide': 570,
  33191. 'Yacute': 611,
  33192. 'Acircumflex': 667,
  33193. 'aacute': 500,
  33194. 'Ucircumflex': 722,
  33195. 'yacute': 444,
  33196. 'scommaaccent': 389,
  33197. 'ecircumflex': 444,
  33198. 'Uring': 722,
  33199. 'Udieresis': 722,
  33200. 'aogonek': 500,
  33201. 'Uacute': 722,
  33202. 'uogonek': 556,
  33203. 'Edieresis': 667,
  33204. 'Dcroat': 722,
  33205. 'commaaccent': 250,
  33206. 'copyright': 747,
  33207. 'Emacron': 667,
  33208. 'ccaron': 444,
  33209. 'aring': 500,
  33210. 'Ncommaaccent': 722,
  33211. 'lacute': 278,
  33212. 'agrave': 500,
  33213. 'Tcommaaccent': 611,
  33214. 'Cacute': 667,
  33215. 'atilde': 500,
  33216. 'Edotaccent': 667,
  33217. 'scaron': 389,
  33218. 'scedilla': 389,
  33219. 'iacute': 278,
  33220. 'lozenge': 494,
  33221. 'Rcaron': 667,
  33222. 'Gcommaaccent': 722,
  33223. 'ucircumflex': 556,
  33224. 'acircumflex': 500,
  33225. 'Amacron': 667,
  33226. 'rcaron': 389,
  33227. 'ccedilla': 444,
  33228. 'Zdotaccent': 611,
  33229. 'Thorn': 611,
  33230. 'Omacron': 722,
  33231. 'Racute': 667,
  33232. 'Sacute': 556,
  33233. 'dcaron': 608,
  33234. 'Umacron': 722,
  33235. 'uring': 556,
  33236. 'threesuperior': 300,
  33237. 'Ograve': 722,
  33238. 'Agrave': 667,
  33239. 'Abreve': 667,
  33240. 'multiply': 570,
  33241. 'uacute': 556,
  33242. 'Tcaron': 611,
  33243. 'partialdiff': 494,
  33244. 'ydieresis': 444,
  33245. 'Nacute': 722,
  33246. 'icircumflex': 278,
  33247. 'Ecircumflex': 667,
  33248. 'adieresis': 500,
  33249. 'edieresis': 444,
  33250. 'cacute': 444,
  33251. 'nacute': 556,
  33252. 'umacron': 556,
  33253. 'Ncaron': 722,
  33254. 'Iacute': 389,
  33255. 'plusminus': 570,
  33256. 'brokenbar': 220,
  33257. 'registered': 747,
  33258. 'Gbreve': 722,
  33259. 'Idotaccent': 389,
  33260. 'summation': 600,
  33261. 'Egrave': 667,
  33262. 'racute': 389,
  33263. 'omacron': 500,
  33264. 'Zacute': 611,
  33265. 'Zcaron': 611,
  33266. 'greaterequal': 549,
  33267. 'Eth': 722,
  33268. 'Ccedilla': 667,
  33269. 'lcommaaccent': 278,
  33270. 'tcaron': 366,
  33271. 'eogonek': 444,
  33272. 'Uogonek': 722,
  33273. 'Aacute': 667,
  33274. 'Adieresis': 667,
  33275. 'egrave': 444,
  33276. 'zacute': 389,
  33277. 'iogonek': 278,
  33278. 'Oacute': 722,
  33279. 'oacute': 500,
  33280. 'amacron': 500,
  33281. 'sacute': 389,
  33282. 'idieresis': 278,
  33283. 'Ocircumflex': 722,
  33284. 'Ugrave': 722,
  33285. 'Delta': 612,
  33286. 'thorn': 500,
  33287. 'twosuperior': 300,
  33288. 'Odieresis': 722,
  33289. 'mu': 576,
  33290. 'igrave': 278,
  33291. 'ohungarumlaut': 500,
  33292. 'Eogonek': 667,
  33293. 'dcroat': 500,
  33294. 'threequarters': 750,
  33295. 'Scedilla': 556,
  33296. 'lcaron': 382,
  33297. 'Kcommaaccent': 667,
  33298. 'Lacute': 611,
  33299. 'trademark': 1000,
  33300. 'edotaccent': 444,
  33301. 'Igrave': 389,
  33302. 'Imacron': 389,
  33303. 'Lcaron': 611,
  33304. 'onehalf': 750,
  33305. 'lessequal': 549,
  33306. 'ocircumflex': 500,
  33307. 'ntilde': 556,
  33308. 'Uhungarumlaut': 722,
  33309. 'Eacute': 667,
  33310. 'emacron': 444,
  33311. 'gbreve': 500,
  33312. 'onequarter': 750,
  33313. 'Scaron': 556,
  33314. 'Scommaaccent': 556,
  33315. 'Ohungarumlaut': 722,
  33316. 'degree': 400,
  33317. 'ograve': 500,
  33318. 'Ccaron': 667,
  33319. 'ugrave': 556,
  33320. 'radical': 549,
  33321. 'Dcaron': 722,
  33322. 'rcommaaccent': 389,
  33323. 'Ntilde': 722,
  33324. 'otilde': 500,
  33325. 'Rcommaaccent': 667,
  33326. 'Lcommaaccent': 611,
  33327. 'Atilde': 667,
  33328. 'Aogonek': 667,
  33329. 'Aring': 667,
  33330. 'Otilde': 722,
  33331. 'zdotaccent': 389,
  33332. 'Ecaron': 667,
  33333. 'Iogonek': 389,
  33334. 'kcommaaccent': 500,
  33335. 'minus': 606,
  33336. 'Icircumflex': 389,
  33337. 'ncaron': 556,
  33338. 'tcommaaccent': 278,
  33339. 'logicalnot': 606,
  33340. 'odieresis': 500,
  33341. 'udieresis': 556,
  33342. 'notequal': 549,
  33343. 'gcommaaccent': 500,
  33344. 'eth': 500,
  33345. 'zcaron': 389,
  33346. 'ncommaaccent': 556,
  33347. 'onesuperior': 300,
  33348. 'imacron': 278,
  33349. 'Euro': 500
  33350. },
  33351. 'Times-Italic': {
  33352. 'space': 250,
  33353. 'exclam': 333,
  33354. 'quotedbl': 420,
  33355. 'numbersign': 500,
  33356. 'dollar': 500,
  33357. 'percent': 833,
  33358. 'ampersand': 778,
  33359. 'quoteright': 333,
  33360. 'parenleft': 333,
  33361. 'parenright': 333,
  33362. 'asterisk': 500,
  33363. 'plus': 675,
  33364. 'comma': 250,
  33365. 'hyphen': 333,
  33366. 'period': 250,
  33367. 'slash': 278,
  33368. 'zero': 500,
  33369. 'one': 500,
  33370. 'two': 500,
  33371. 'three': 500,
  33372. 'four': 500,
  33373. 'five': 500,
  33374. 'six': 500,
  33375. 'seven': 500,
  33376. 'eight': 500,
  33377. 'nine': 500,
  33378. 'colon': 333,
  33379. 'semicolon': 333,
  33380. 'less': 675,
  33381. 'equal': 675,
  33382. 'greater': 675,
  33383. 'question': 500,
  33384. 'at': 920,
  33385. 'A': 611,
  33386. 'B': 611,
  33387. 'C': 667,
  33388. 'D': 722,
  33389. 'E': 611,
  33390. 'F': 611,
  33391. 'G': 722,
  33392. 'H': 722,
  33393. 'I': 333,
  33394. 'J': 444,
  33395. 'K': 667,
  33396. 'L': 556,
  33397. 'M': 833,
  33398. 'N': 667,
  33399. 'O': 722,
  33400. 'P': 611,
  33401. 'Q': 722,
  33402. 'R': 611,
  33403. 'S': 500,
  33404. 'T': 556,
  33405. 'U': 722,
  33406. 'V': 611,
  33407. 'W': 833,
  33408. 'X': 611,
  33409. 'Y': 556,
  33410. 'Z': 556,
  33411. 'bracketleft': 389,
  33412. 'backslash': 278,
  33413. 'bracketright': 389,
  33414. 'asciicircum': 422,
  33415. 'underscore': 500,
  33416. 'quoteleft': 333,
  33417. 'a': 500,
  33418. 'b': 500,
  33419. 'c': 444,
  33420. 'd': 500,
  33421. 'e': 444,
  33422. 'f': 278,
  33423. 'g': 500,
  33424. 'h': 500,
  33425. 'i': 278,
  33426. 'j': 278,
  33427. 'k': 444,
  33428. 'l': 278,
  33429. 'm': 722,
  33430. 'n': 500,
  33431. 'o': 500,
  33432. 'p': 500,
  33433. 'q': 500,
  33434. 'r': 389,
  33435. 's': 389,
  33436. 't': 278,
  33437. 'u': 500,
  33438. 'v': 444,
  33439. 'w': 667,
  33440. 'x': 444,
  33441. 'y': 444,
  33442. 'z': 389,
  33443. 'braceleft': 400,
  33444. 'bar': 275,
  33445. 'braceright': 400,
  33446. 'asciitilde': 541,
  33447. 'exclamdown': 389,
  33448. 'cent': 500,
  33449. 'sterling': 500,
  33450. 'fraction': 167,
  33451. 'yen': 500,
  33452. 'florin': 500,
  33453. 'section': 500,
  33454. 'currency': 500,
  33455. 'quotesingle': 214,
  33456. 'quotedblleft': 556,
  33457. 'guillemotleft': 500,
  33458. 'guilsinglleft': 333,
  33459. 'guilsinglright': 333,
  33460. 'fi': 500,
  33461. 'fl': 500,
  33462. 'endash': 500,
  33463. 'dagger': 500,
  33464. 'daggerdbl': 500,
  33465. 'periodcentered': 250,
  33466. 'paragraph': 523,
  33467. 'bullet': 350,
  33468. 'quotesinglbase': 333,
  33469. 'quotedblbase': 556,
  33470. 'quotedblright': 556,
  33471. 'guillemotright': 500,
  33472. 'ellipsis': 889,
  33473. 'perthousand': 1000,
  33474. 'questiondown': 500,
  33475. 'grave': 333,
  33476. 'acute': 333,
  33477. 'circumflex': 333,
  33478. 'tilde': 333,
  33479. 'macron': 333,
  33480. 'breve': 333,
  33481. 'dotaccent': 333,
  33482. 'dieresis': 333,
  33483. 'ring': 333,
  33484. 'cedilla': 333,
  33485. 'hungarumlaut': 333,
  33486. 'ogonek': 333,
  33487. 'caron': 333,
  33488. 'emdash': 889,
  33489. 'AE': 889,
  33490. 'ordfeminine': 276,
  33491. 'Lslash': 556,
  33492. 'Oslash': 722,
  33493. 'OE': 944,
  33494. 'ordmasculine': 310,
  33495. 'ae': 667,
  33496. 'dotlessi': 278,
  33497. 'lslash': 278,
  33498. 'oslash': 500,
  33499. 'oe': 667,
  33500. 'germandbls': 500,
  33501. 'Idieresis': 333,
  33502. 'eacute': 444,
  33503. 'abreve': 500,
  33504. 'uhungarumlaut': 500,
  33505. 'ecaron': 444,
  33506. 'Ydieresis': 556,
  33507. 'divide': 675,
  33508. 'Yacute': 556,
  33509. 'Acircumflex': 611,
  33510. 'aacute': 500,
  33511. 'Ucircumflex': 722,
  33512. 'yacute': 444,
  33513. 'scommaaccent': 389,
  33514. 'ecircumflex': 444,
  33515. 'Uring': 722,
  33516. 'Udieresis': 722,
  33517. 'aogonek': 500,
  33518. 'Uacute': 722,
  33519. 'uogonek': 500,
  33520. 'Edieresis': 611,
  33521. 'Dcroat': 722,
  33522. 'commaaccent': 250,
  33523. 'copyright': 760,
  33524. 'Emacron': 611,
  33525. 'ccaron': 444,
  33526. 'aring': 500,
  33527. 'Ncommaaccent': 667,
  33528. 'lacute': 278,
  33529. 'agrave': 500,
  33530. 'Tcommaaccent': 556,
  33531. 'Cacute': 667,
  33532. 'atilde': 500,
  33533. 'Edotaccent': 611,
  33534. 'scaron': 389,
  33535. 'scedilla': 389,
  33536. 'iacute': 278,
  33537. 'lozenge': 471,
  33538. 'Rcaron': 611,
  33539. 'Gcommaaccent': 722,
  33540. 'ucircumflex': 500,
  33541. 'acircumflex': 500,
  33542. 'Amacron': 611,
  33543. 'rcaron': 389,
  33544. 'ccedilla': 444,
  33545. 'Zdotaccent': 556,
  33546. 'Thorn': 611,
  33547. 'Omacron': 722,
  33548. 'Racute': 611,
  33549. 'Sacute': 500,
  33550. 'dcaron': 544,
  33551. 'Umacron': 722,
  33552. 'uring': 500,
  33553. 'threesuperior': 300,
  33554. 'Ograve': 722,
  33555. 'Agrave': 611,
  33556. 'Abreve': 611,
  33557. 'multiply': 675,
  33558. 'uacute': 500,
  33559. 'Tcaron': 556,
  33560. 'partialdiff': 476,
  33561. 'ydieresis': 444,
  33562. 'Nacute': 667,
  33563. 'icircumflex': 278,
  33564. 'Ecircumflex': 611,
  33565. 'adieresis': 500,
  33566. 'edieresis': 444,
  33567. 'cacute': 444,
  33568. 'nacute': 500,
  33569. 'umacron': 500,
  33570. 'Ncaron': 667,
  33571. 'Iacute': 333,
  33572. 'plusminus': 675,
  33573. 'brokenbar': 275,
  33574. 'registered': 760,
  33575. 'Gbreve': 722,
  33576. 'Idotaccent': 333,
  33577. 'summation': 600,
  33578. 'Egrave': 611,
  33579. 'racute': 389,
  33580. 'omacron': 500,
  33581. 'Zacute': 556,
  33582. 'Zcaron': 556,
  33583. 'greaterequal': 549,
  33584. 'Eth': 722,
  33585. 'Ccedilla': 667,
  33586. 'lcommaaccent': 278,
  33587. 'tcaron': 300,
  33588. 'eogonek': 444,
  33589. 'Uogonek': 722,
  33590. 'Aacute': 611,
  33591. 'Adieresis': 611,
  33592. 'egrave': 444,
  33593. 'zacute': 389,
  33594. 'iogonek': 278,
  33595. 'Oacute': 722,
  33596. 'oacute': 500,
  33597. 'amacron': 500,
  33598. 'sacute': 389,
  33599. 'idieresis': 278,
  33600. 'Ocircumflex': 722,
  33601. 'Ugrave': 722,
  33602. 'Delta': 612,
  33603. 'thorn': 500,
  33604. 'twosuperior': 300,
  33605. 'Odieresis': 722,
  33606. 'mu': 500,
  33607. 'igrave': 278,
  33608. 'ohungarumlaut': 500,
  33609. 'Eogonek': 611,
  33610. 'dcroat': 500,
  33611. 'threequarters': 750,
  33612. 'Scedilla': 500,
  33613. 'lcaron': 300,
  33614. 'Kcommaaccent': 667,
  33615. 'Lacute': 556,
  33616. 'trademark': 980,
  33617. 'edotaccent': 444,
  33618. 'Igrave': 333,
  33619. 'Imacron': 333,
  33620. 'Lcaron': 611,
  33621. 'onehalf': 750,
  33622. 'lessequal': 549,
  33623. 'ocircumflex': 500,
  33624. 'ntilde': 500,
  33625. 'Uhungarumlaut': 722,
  33626. 'Eacute': 611,
  33627. 'emacron': 444,
  33628. 'gbreve': 500,
  33629. 'onequarter': 750,
  33630. 'Scaron': 500,
  33631. 'Scommaaccent': 500,
  33632. 'Ohungarumlaut': 722,
  33633. 'degree': 400,
  33634. 'ograve': 500,
  33635. 'Ccaron': 667,
  33636. 'ugrave': 500,
  33637. 'radical': 453,
  33638. 'Dcaron': 722,
  33639. 'rcommaaccent': 389,
  33640. 'Ntilde': 667,
  33641. 'otilde': 500,
  33642. 'Rcommaaccent': 611,
  33643. 'Lcommaaccent': 556,
  33644. 'Atilde': 611,
  33645. 'Aogonek': 611,
  33646. 'Aring': 611,
  33647. 'Otilde': 722,
  33648. 'zdotaccent': 389,
  33649. 'Ecaron': 611,
  33650. 'Iogonek': 333,
  33651. 'kcommaaccent': 444,
  33652. 'minus': 675,
  33653. 'Icircumflex': 333,
  33654. 'ncaron': 500,
  33655. 'tcommaaccent': 278,
  33656. 'logicalnot': 675,
  33657. 'odieresis': 500,
  33658. 'udieresis': 500,
  33659. 'notequal': 549,
  33660. 'gcommaaccent': 500,
  33661. 'eth': 500,
  33662. 'zcaron': 389,
  33663. 'ncommaaccent': 500,
  33664. 'onesuperior': 300,
  33665. 'imacron': 278,
  33666. 'Euro': 500
  33667. },
  33668. 'ZapfDingbats': {
  33669. 'space': 278,
  33670. 'a1': 974,
  33671. 'a2': 961,
  33672. 'a202': 974,
  33673. 'a3': 980,
  33674. 'a4': 719,
  33675. 'a5': 789,
  33676. 'a119': 790,
  33677. 'a118': 791,
  33678. 'a117': 690,
  33679. 'a11': 960,
  33680. 'a12': 939,
  33681. 'a13': 549,
  33682. 'a14': 855,
  33683. 'a15': 911,
  33684. 'a16': 933,
  33685. 'a105': 911,
  33686. 'a17': 945,
  33687. 'a18': 974,
  33688. 'a19': 755,
  33689. 'a20': 846,
  33690. 'a21': 762,
  33691. 'a22': 761,
  33692. 'a23': 571,
  33693. 'a24': 677,
  33694. 'a25': 763,
  33695. 'a26': 760,
  33696. 'a27': 759,
  33697. 'a28': 754,
  33698. 'a6': 494,
  33699. 'a7': 552,
  33700. 'a8': 537,
  33701. 'a9': 577,
  33702. 'a10': 692,
  33703. 'a29': 786,
  33704. 'a30': 788,
  33705. 'a31': 788,
  33706. 'a32': 790,
  33707. 'a33': 793,
  33708. 'a34': 794,
  33709. 'a35': 816,
  33710. 'a36': 823,
  33711. 'a37': 789,
  33712. 'a38': 841,
  33713. 'a39': 823,
  33714. 'a40': 833,
  33715. 'a41': 816,
  33716. 'a42': 831,
  33717. 'a43': 923,
  33718. 'a44': 744,
  33719. 'a45': 723,
  33720. 'a46': 749,
  33721. 'a47': 790,
  33722. 'a48': 792,
  33723. 'a49': 695,
  33724. 'a50': 776,
  33725. 'a51': 768,
  33726. 'a52': 792,
  33727. 'a53': 759,
  33728. 'a54': 707,
  33729. 'a55': 708,
  33730. 'a56': 682,
  33731. 'a57': 701,
  33732. 'a58': 826,
  33733. 'a59': 815,
  33734. 'a60': 789,
  33735. 'a61': 789,
  33736. 'a62': 707,
  33737. 'a63': 687,
  33738. 'a64': 696,
  33739. 'a65': 689,
  33740. 'a66': 786,
  33741. 'a67': 787,
  33742. 'a68': 713,
  33743. 'a69': 791,
  33744. 'a70': 785,
  33745. 'a71': 791,
  33746. 'a72': 873,
  33747. 'a73': 761,
  33748. 'a74': 762,
  33749. 'a203': 762,
  33750. 'a75': 759,
  33751. 'a204': 759,
  33752. 'a76': 892,
  33753. 'a77': 892,
  33754. 'a78': 788,
  33755. 'a79': 784,
  33756. 'a81': 438,
  33757. 'a82': 138,
  33758. 'a83': 277,
  33759. 'a84': 415,
  33760. 'a97': 392,
  33761. 'a98': 392,
  33762. 'a99': 668,
  33763. 'a100': 668,
  33764. 'a89': 390,
  33765. 'a90': 390,
  33766. 'a93': 317,
  33767. 'a94': 317,
  33768. 'a91': 276,
  33769. 'a92': 276,
  33770. 'a205': 509,
  33771. 'a85': 509,
  33772. 'a206': 410,
  33773. 'a86': 410,
  33774. 'a87': 234,
  33775. 'a88': 234,
  33776. 'a95': 334,
  33777. 'a96': 334,
  33778. 'a101': 732,
  33779. 'a102': 544,
  33780. 'a103': 544,
  33781. 'a104': 910,
  33782. 'a106': 667,
  33783. 'a107': 760,
  33784. 'a108': 760,
  33785. 'a112': 776,
  33786. 'a111': 595,
  33787. 'a110': 694,
  33788. 'a109': 626,
  33789. 'a120': 788,
  33790. 'a121': 788,
  33791. 'a122': 788,
  33792. 'a123': 788,
  33793. 'a124': 788,
  33794. 'a125': 788,
  33795. 'a126': 788,
  33796. 'a127': 788,
  33797. 'a128': 788,
  33798. 'a129': 788,
  33799. 'a130': 788,
  33800. 'a131': 788,
  33801. 'a132': 788,
  33802. 'a133': 788,
  33803. 'a134': 788,
  33804. 'a135': 788,
  33805. 'a136': 788,
  33806. 'a137': 788,
  33807. 'a138': 788,
  33808. 'a139': 788,
  33809. 'a140': 788,
  33810. 'a141': 788,
  33811. 'a142': 788,
  33812. 'a143': 788,
  33813. 'a144': 788,
  33814. 'a145': 788,
  33815. 'a146': 788,
  33816. 'a147': 788,
  33817. 'a148': 788,
  33818. 'a149': 788,
  33819. 'a150': 788,
  33820. 'a151': 788,
  33821. 'a152': 788,
  33822. 'a153': 788,
  33823. 'a154': 788,
  33824. 'a155': 788,
  33825. 'a156': 788,
  33826. 'a157': 788,
  33827. 'a158': 788,
  33828. 'a159': 788,
  33829. 'a160': 894,
  33830. 'a161': 838,
  33831. 'a163': 1016,
  33832. 'a164': 458,
  33833. 'a196': 748,
  33834. 'a165': 924,
  33835. 'a192': 748,
  33836. 'a166': 918,
  33837. 'a167': 927,
  33838. 'a168': 928,
  33839. 'a169': 928,
  33840. 'a170': 834,
  33841. 'a171': 873,
  33842. 'a172': 828,
  33843. 'a173': 924,
  33844. 'a162': 924,
  33845. 'a174': 917,
  33846. 'a175': 930,
  33847. 'a176': 931,
  33848. 'a177': 463,
  33849. 'a178': 883,
  33850. 'a179': 836,
  33851. 'a193': 836,
  33852. 'a180': 867,
  33853. 'a199': 867,
  33854. 'a181': 696,
  33855. 'a200': 696,
  33856. 'a182': 874,
  33857. 'a201': 874,
  33858. 'a183': 760,
  33859. 'a184': 946,
  33860. 'a197': 771,
  33861. 'a185': 865,
  33862. 'a194': 771,
  33863. 'a198': 888,
  33864. 'a186': 967,
  33865. 'a195': 888,
  33866. 'a187': 831,
  33867. 'a188': 873,
  33868. 'a189': 927,
  33869. 'a190': 970,
  33870. 'a191': 918
  33871. }
  33872. };
  33873. var EOF = {};
  33874. function isEOF(v) {
  33875. return (v === EOF);
  33876. }
  33877. var MAX_LENGTH_TO_CACHE = 1000;
  33878. var Parser = (function ParserClosure() {
  33879. function Parser(lexer, allowStreams, xref) {
  33880. this.lexer = lexer;
  33881. this.allowStreams = allowStreams;
  33882. this.xref = xref;
  33883. this.imageCache = {};
  33884. this.refill();
  33885. }
  33886. Parser.prototype = {
  33887. refill: function Parser_refill() {
  33888. this.buf1 = this.lexer.getObj();
  33889. this.buf2 = this.lexer.getObj();
  33890. },
  33891. shift: function Parser_shift() {
  33892. if (isCmd(this.buf2, 'ID')) {
  33893. this.buf1 = this.buf2;
  33894. this.buf2 = null;
  33895. } else {
  33896. this.buf1 = this.buf2;
  33897. this.buf2 = this.lexer.getObj();
  33898. }
  33899. },
  33900. getObj: function Parser_getObj(cipherTransform) {
  33901. var buf1 = this.buf1;
  33902. this.shift();
  33903. if (buf1 instanceof Cmd) {
  33904. switch (buf1.cmd) {
  33905. case 'BI': // inline image
  33906. return this.makeInlineImage(cipherTransform);
  33907. case '[': // array
  33908. var array = [];
  33909. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  33910. array.push(this.getObj(cipherTransform));
  33911. }
  33912. if (isEOF(this.buf1)) {
  33913. error('End of file inside array');
  33914. }
  33915. this.shift();
  33916. return array;
  33917. case '<<': // dictionary or stream
  33918. var dict = new Dict(this.xref);
  33919. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  33920. if (!isName(this.buf1)) {
  33921. info('Malformed dictionary: key must be a name object');
  33922. this.shift();
  33923. continue;
  33924. }
  33925. var key = this.buf1.name;
  33926. this.shift();
  33927. if (isEOF(this.buf1)) {
  33928. break;
  33929. }
  33930. dict.set(key, this.getObj(cipherTransform));
  33931. }
  33932. if (isEOF(this.buf1)) {
  33933. error('End of file inside dictionary');
  33934. }
  33935. // Stream objects are not allowed inside content streams or
  33936. // object streams.
  33937. if (isCmd(this.buf2, 'stream')) {
  33938. return (this.allowStreams ?
  33939. this.makeStream(dict, cipherTransform) : dict);
  33940. }
  33941. this.shift();
  33942. return dict;
  33943. default: // simple object
  33944. return buf1;
  33945. }
  33946. }
  33947. if (isInt(buf1)) { // indirect reference or integer
  33948. var num = buf1;
  33949. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  33950. var ref = new Ref(num, this.buf1);
  33951. this.shift();
  33952. this.shift();
  33953. return ref;
  33954. }
  33955. return num;
  33956. }
  33957. if (isString(buf1)) { // string
  33958. var str = buf1;
  33959. if (cipherTransform) {
  33960. str = cipherTransform.decryptString(str);
  33961. }
  33962. return str;
  33963. }
  33964. // simple object
  33965. return buf1;
  33966. },
  33967. /**
  33968. * Find the end of the stream by searching for the /EI\s/.
  33969. * @returns {number} The inline stream length.
  33970. */
  33971. findDefaultInlineStreamEnd:
  33972. function Parser_findDefaultInlineStreamEnd(stream) {
  33973. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  33974. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  33975. while ((ch = stream.getByte()) !== -1) {
  33976. if (state === 0) {
  33977. state = (ch === E) ? 1 : 0;
  33978. } else if (state === 1) {
  33979. state = (ch === I) ? 2 : 0;
  33980. } else {
  33981. assert(state === 2);
  33982. if (ch === SPACE || ch === LF || ch === CR) {
  33983. // Let's check the next five bytes are ASCII... just be sure.
  33984. n = 5;
  33985. followingBytes = stream.peekBytes(n);
  33986. for (i = 0; i < n; i++) {
  33987. ch = followingBytes[i];
  33988. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  33989. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  33990. // it's binary stuff. Resetting the state.
  33991. state = 0;
  33992. break;
  33993. }
  33994. }
  33995. if (state === 2) {
  33996. break; // Finished!
  33997. }
  33998. } else {
  33999. state = 0;
  34000. }
  34001. }
  34002. }
  34003. return ((stream.pos - 4) - startPos);
  34004. },
  34005. /**
  34006. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  34007. * @returns {number} The inline stream length.
  34008. */
  34009. findDCTDecodeInlineStreamEnd:
  34010. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  34011. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  34012. while ((b = stream.getByte()) !== -1) {
  34013. if (b !== 0xFF) { // Not a valid marker.
  34014. continue;
  34015. }
  34016. switch (stream.getByte()) {
  34017. case 0x00: // Byte stuffing.
  34018. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  34019. break;
  34020. case 0xFF: // Fill byte.
  34021. // Avoid skipping a valid marker, resetting the stream position.
  34022. stream.skip(-1);
  34023. break;
  34024. case 0xD9: // EOI
  34025. foundEOI = true;
  34026. break;
  34027. case 0xC0: // SOF0
  34028. case 0xC1: // SOF1
  34029. case 0xC2: // SOF2
  34030. case 0xC3: // SOF3
  34031. case 0xC5: // SOF5
  34032. case 0xC6: // SOF6
  34033. case 0xC7: // SOF7
  34034. case 0xC9: // SOF9
  34035. case 0xCA: // SOF10
  34036. case 0xCB: // SOF11
  34037. case 0xCD: // SOF13
  34038. case 0xCE: // SOF14
  34039. case 0xCF: // SOF15
  34040. case 0xC4: // DHT
  34041. case 0xCC: // DAC
  34042. case 0xDA: // SOS
  34043. case 0xDB: // DQT
  34044. case 0xDC: // DNL
  34045. case 0xDD: // DRI
  34046. case 0xDE: // DHP
  34047. case 0xDF: // EXP
  34048. case 0xE0: // APP0
  34049. case 0xE1: // APP1
  34050. case 0xE2: // APP2
  34051. case 0xE3: // APP3
  34052. case 0xE4: // APP4
  34053. case 0xE5: // APP5
  34054. case 0xE6: // APP6
  34055. case 0xE7: // APP7
  34056. case 0xE8: // APP8
  34057. case 0xE9: // APP9
  34058. case 0xEA: // APP10
  34059. case 0xEB: // APP11
  34060. case 0xEC: // APP12
  34061. case 0xED: // APP13
  34062. case 0xEE: // APP14
  34063. case 0xEF: // APP15
  34064. case 0xFE: // COM
  34065. // The marker should be followed by the length of the segment.
  34066. markerLength = stream.getUint16();
  34067. if (markerLength > 2) {
  34068. // |markerLength| contains the byte length of the marker segment,
  34069. // including its own length (2 bytes) and excluding the marker.
  34070. stream.skip(markerLength - 2); // Jump to the next marker.
  34071. } else {
  34072. // The marker length is invalid, resetting the stream position.
  34073. stream.skip(-2);
  34074. }
  34075. break;
  34076. }
  34077. if (foundEOI) {
  34078. break;
  34079. }
  34080. }
  34081. length = stream.pos - startPos;
  34082. if (b === -1) {
  34083. warn('Inline DCTDecode image stream: ' +
  34084. 'EOI marker not found, searching for /EI/ instead.');
  34085. stream.skip(-length); // Reset the stream position.
  34086. return this.findDefaultInlineStreamEnd(stream);
  34087. }
  34088. this.inlineStreamSkipEI(stream);
  34089. return length;
  34090. },
  34091. /**
  34092. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  34093. * @returns {number} The inline stream length.
  34094. */
  34095. findASCII85DecodeInlineStreamEnd:
  34096. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  34097. var TILDE = 0x7E, GT = 0x3E;
  34098. var startPos = stream.pos, ch, length;
  34099. while ((ch = stream.getByte()) !== -1) {
  34100. if (ch === TILDE && stream.peekByte() === GT) {
  34101. stream.skip();
  34102. break;
  34103. }
  34104. }
  34105. length = stream.pos - startPos;
  34106. if (ch === -1) {
  34107. warn('Inline ASCII85Decode image stream: ' +
  34108. 'EOD marker not found, searching for /EI/ instead.');
  34109. stream.skip(-length); // Reset the stream position.
  34110. return this.findDefaultInlineStreamEnd(stream);
  34111. }
  34112. this.inlineStreamSkipEI(stream);
  34113. return length;
  34114. },
  34115. /**
  34116. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  34117. * @returns {number} The inline stream length.
  34118. */
  34119. findASCIIHexDecodeInlineStreamEnd:
  34120. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  34121. var GT = 0x3E;
  34122. var startPos = stream.pos, ch, length;
  34123. while ((ch = stream.getByte()) !== -1) {
  34124. if (ch === GT) {
  34125. break;
  34126. }
  34127. }
  34128. length = stream.pos - startPos;
  34129. if (ch === -1) {
  34130. warn('Inline ASCIIHexDecode image stream: ' +
  34131. 'EOD marker not found, searching for /EI/ instead.');
  34132. stream.skip(-length); // Reset the stream position.
  34133. return this.findDefaultInlineStreamEnd(stream);
  34134. }
  34135. this.inlineStreamSkipEI(stream);
  34136. return length;
  34137. },
  34138. /**
  34139. * Skip over the /EI/ for streams where we search for an EOD marker.
  34140. */
  34141. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  34142. var E = 0x45, I = 0x49;
  34143. var state = 0, ch;
  34144. while ((ch = stream.getByte()) !== -1) {
  34145. if (state === 0) {
  34146. state = (ch === E) ? 1 : 0;
  34147. } else if (state === 1) {
  34148. state = (ch === I) ? 2 : 0;
  34149. } else if (state === 2) {
  34150. break;
  34151. }
  34152. }
  34153. },
  34154. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  34155. var lexer = this.lexer;
  34156. var stream = lexer.stream;
  34157. // Parse dictionary.
  34158. var dict = new Dict(null);
  34159. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  34160. if (!isName(this.buf1)) {
  34161. error('Dictionary key must be a name object');
  34162. }
  34163. var key = this.buf1.name;
  34164. this.shift();
  34165. if (isEOF(this.buf1)) {
  34166. break;
  34167. }
  34168. dict.set(key, this.getObj(cipherTransform));
  34169. }
  34170. // Extract the name of the first (i.e. the current) image filter.
  34171. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  34172. if (isName(filter)) {
  34173. filterName = filter.name;
  34174. } else if (isArray(filter) && isName(filter[0])) {
  34175. filterName = filter[0].name;
  34176. }
  34177. // Parse image stream.
  34178. var startPos = stream.pos, length, i, ii;
  34179. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  34180. length = this.findDCTDecodeInlineStreamEnd(stream);
  34181. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  34182. length = this.findASCII85DecodeInlineStreamEnd(stream);
  34183. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  34184. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  34185. } else {
  34186. length = this.findDefaultInlineStreamEnd(stream);
  34187. }
  34188. var imageStream = stream.makeSubStream(startPos, length, dict);
  34189. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  34190. // adler32 checksum.
  34191. var adler32;
  34192. if (length < MAX_LENGTH_TO_CACHE) {
  34193. var imageBytes = imageStream.getBytes();
  34194. imageStream.reset();
  34195. var a = 1;
  34196. var b = 0;
  34197. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  34198. // No modulo required in the loop if imageBytes.length < 5552.
  34199. a += imageBytes[i] & 0xff;
  34200. b += a;
  34201. }
  34202. adler32 = ((b % 65521) << 16) | (a % 65521);
  34203. if (this.imageCache.adler32 === adler32) {
  34204. this.buf2 = Cmd.get('EI');
  34205. this.shift();
  34206. this.imageCache[adler32].reset();
  34207. return this.imageCache[adler32];
  34208. }
  34209. }
  34210. if (cipherTransform) {
  34211. imageStream = cipherTransform.createStream(imageStream, length);
  34212. }
  34213. imageStream = this.filter(imageStream, dict, length);
  34214. imageStream.dict = dict;
  34215. if (adler32 !== undefined) {
  34216. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  34217. this.imageCache[adler32] = imageStream;
  34218. }
  34219. this.buf2 = Cmd.get('EI');
  34220. this.shift();
  34221. return imageStream;
  34222. },
  34223. fetchIfRef: function Parser_fetchIfRef(obj) {
  34224. // not relying on the xref.fetchIfRef -- xref might not be set
  34225. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  34226. },
  34227. makeStream: function Parser_makeStream(dict, cipherTransform) {
  34228. var lexer = this.lexer;
  34229. var stream = lexer.stream;
  34230. // get stream start position
  34231. lexer.skipToNextLine();
  34232. var pos = stream.pos - 1;
  34233. // get length
  34234. var length = this.fetchIfRef(dict.get('Length'));
  34235. if (!isInt(length)) {
  34236. info('Bad ' + length + ' attribute in stream');
  34237. length = 0;
  34238. }
  34239. // skip over the stream data
  34240. stream.pos = pos + length;
  34241. lexer.nextChar();
  34242. this.shift(); // '>>'
  34243. this.shift(); // 'stream'
  34244. if (!isCmd(this.buf1, 'endstream')) {
  34245. // bad stream length, scanning for endstream
  34246. stream.pos = pos;
  34247. var SCAN_BLOCK_SIZE = 2048;
  34248. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  34249. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  34250. 0x61, 0x6D];
  34251. var skipped = 0, found = false, i, j;
  34252. while (stream.pos < stream.end) {
  34253. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  34254. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  34255. if (scanLength <= 0) {
  34256. break;
  34257. }
  34258. found = false;
  34259. for (i = 0, j = 0; i < scanLength; i++) {
  34260. var b = scanBytes[i];
  34261. if (b !== ENDSTREAM_SIGNATURE[j]) {
  34262. i -= j;
  34263. j = 0;
  34264. } else {
  34265. j++;
  34266. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  34267. i++;
  34268. found = true;
  34269. break;
  34270. }
  34271. }
  34272. }
  34273. if (found) {
  34274. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  34275. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  34276. break;
  34277. }
  34278. skipped += scanLength;
  34279. stream.pos += scanLength;
  34280. }
  34281. if (!found) {
  34282. error('Missing endstream');
  34283. }
  34284. length = skipped;
  34285. lexer.nextChar();
  34286. this.shift();
  34287. this.shift();
  34288. }
  34289. this.shift(); // 'endstream'
  34290. stream = stream.makeSubStream(pos, length, dict);
  34291. if (cipherTransform) {
  34292. stream = cipherTransform.createStream(stream, length);
  34293. }
  34294. stream = this.filter(stream, dict, length);
  34295. stream.dict = dict;
  34296. return stream;
  34297. },
  34298. filter: function Parser_filter(stream, dict, length) {
  34299. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  34300. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  34301. if (isName(filter)) {
  34302. return this.makeFilter(stream, filter.name, length, params);
  34303. }
  34304. var maybeLength = length;
  34305. if (isArray(filter)) {
  34306. var filterArray = filter;
  34307. var paramsArray = params;
  34308. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  34309. filter = filterArray[i];
  34310. if (!isName(filter)) {
  34311. error('Bad filter name: ' + filter);
  34312. }
  34313. params = null;
  34314. if (isArray(paramsArray) && (i in paramsArray)) {
  34315. params = paramsArray[i];
  34316. }
  34317. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  34318. // after the first stream the length variable is invalid
  34319. maybeLength = null;
  34320. }
  34321. }
  34322. return stream;
  34323. },
  34324. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  34325. if (stream.dict.get('Length') === 0) {
  34326. return new NullStream(stream);
  34327. }
  34328. try {
  34329. if (params) {
  34330. params = this.fetchIfRef(params);
  34331. }
  34332. var xrefStreamStats = this.xref.stats.streamTypes;
  34333. if (name === 'FlateDecode' || name === 'Fl') {
  34334. xrefStreamStats[StreamType.FLATE] = true;
  34335. if (params) {
  34336. return new PredictorStream(new FlateStream(stream, maybeLength),
  34337. maybeLength, params);
  34338. }
  34339. return new FlateStream(stream, maybeLength);
  34340. }
  34341. if (name === 'LZWDecode' || name === 'LZW') {
  34342. xrefStreamStats[StreamType.LZW] = true;
  34343. var earlyChange = 1;
  34344. if (params) {
  34345. if (params.has('EarlyChange')) {
  34346. earlyChange = params.get('EarlyChange');
  34347. }
  34348. return new PredictorStream(
  34349. new LZWStream(stream, maybeLength, earlyChange),
  34350. maybeLength, params);
  34351. }
  34352. return new LZWStream(stream, maybeLength, earlyChange);
  34353. }
  34354. if (name === 'DCTDecode' || name === 'DCT') {
  34355. xrefStreamStats[StreamType.DCT] = true;
  34356. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  34357. }
  34358. if (name === 'JPXDecode' || name === 'JPX') {
  34359. xrefStreamStats[StreamType.JPX] = true;
  34360. return new JpxStream(stream, maybeLength, stream.dict);
  34361. }
  34362. if (name === 'ASCII85Decode' || name === 'A85') {
  34363. xrefStreamStats[StreamType.A85] = true;
  34364. return new Ascii85Stream(stream, maybeLength);
  34365. }
  34366. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  34367. xrefStreamStats[StreamType.AHX] = true;
  34368. return new AsciiHexStream(stream, maybeLength);
  34369. }
  34370. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  34371. xrefStreamStats[StreamType.CCF] = true;
  34372. return new CCITTFaxStream(stream, maybeLength, params);
  34373. }
  34374. if (name === 'RunLengthDecode' || name === 'RL') {
  34375. xrefStreamStats[StreamType.RL] = true;
  34376. return new RunLengthStream(stream, maybeLength);
  34377. }
  34378. if (name === 'JBIG2Decode') {
  34379. xrefStreamStats[StreamType.JBIG] = true;
  34380. return new Jbig2Stream(stream, maybeLength, stream.dict);
  34381. }
  34382. warn('filter "' + name + '" not supported yet');
  34383. return stream;
  34384. } catch (ex) {
  34385. if (ex instanceof MissingDataException) {
  34386. throw ex;
  34387. }
  34388. warn('Invalid stream: \"' + ex + '\"');
  34389. return new NullStream(stream);
  34390. }
  34391. }
  34392. };
  34393. return Parser;
  34394. })();
  34395. var Lexer = (function LexerClosure() {
  34396. function Lexer(stream, knownCommands) {
  34397. this.stream = stream;
  34398. this.nextChar();
  34399. // While lexing, we build up many strings one char at a time. Using += for
  34400. // this can result in lots of garbage strings. It's better to build an
  34401. // array of single-char strings and then join() them together at the end.
  34402. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  34403. // purpose uses less memory than using a new array for each string.
  34404. this.strBuf = [];
  34405. // The PDFs might have "glued" commands with other commands, operands or
  34406. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  34407. // commands and their prefixes. The prefixes are built the following way:
  34408. // if there a command that is a prefix of the other valid command or
  34409. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  34410. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  34411. // other commands or literals as a prefix. The knowCommands is optional.
  34412. this.knownCommands = knownCommands;
  34413. }
  34414. Lexer.isSpace = function Lexer_isSpace(ch) {
  34415. // Space is one of the following characters: SPACE, TAB, CR or LF.
  34416. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  34417. };
  34418. // A '1' in this array means the character is white space. A '1' or
  34419. // '2' means the character ends a name or command.
  34420. var specialChars = [
  34421. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  34422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  34423. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  34424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  34425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  34426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  34427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  34428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  34429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  34430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  34431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  34432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  34433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  34434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  34435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  34436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  34437. ];
  34438. function toHexDigit(ch) {
  34439. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  34440. return ch & 0x0F;
  34441. }
  34442. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  34443. // 'A'-'F', 'a'-'f'
  34444. return (ch & 0x0F) + 9;
  34445. }
  34446. return -1;
  34447. }
  34448. Lexer.prototype = {
  34449. nextChar: function Lexer_nextChar() {
  34450. return (this.currentChar = this.stream.getByte());
  34451. },
  34452. peekChar: function Lexer_peekChar() {
  34453. return this.stream.peekByte();
  34454. },
  34455. getNumber: function Lexer_getNumber() {
  34456. var ch = this.currentChar;
  34457. var eNotation = false;
  34458. var divideBy = 0; // different from 0 if it's a floating point value
  34459. var sign = 1;
  34460. if (ch === 0x2D) { // '-'
  34461. sign = -1;
  34462. ch = this.nextChar();
  34463. } else if (ch === 0x2B) { // '+'
  34464. ch = this.nextChar();
  34465. }
  34466. if (ch === 0x2E) { // '.'
  34467. divideBy = 10;
  34468. ch = this.nextChar();
  34469. }
  34470. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34471. error('Invalid number: ' + String.fromCharCode(ch));
  34472. return 0;
  34473. }
  34474. var baseValue = ch - 0x30; // '0'
  34475. var powerValue = 0;
  34476. var powerValueSign = 1;
  34477. while ((ch = this.nextChar()) >= 0) {
  34478. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  34479. var currentDigit = ch - 0x30; // '0'
  34480. if (eNotation) { // We are after an 'e' or 'E'
  34481. powerValue = powerValue * 10 + currentDigit;
  34482. } else {
  34483. if (divideBy !== 0) { // We are after a point
  34484. divideBy *= 10;
  34485. }
  34486. baseValue = baseValue * 10 + currentDigit;
  34487. }
  34488. } else if (ch === 0x2E) { // '.'
  34489. if (divideBy === 0) {
  34490. divideBy = 1;
  34491. } else {
  34492. // A number can have only one '.'
  34493. break;
  34494. }
  34495. } else if (ch === 0x2D) { // '-'
  34496. // ignore minus signs in the middle of numbers to match
  34497. // Adobe's behavior
  34498. warn('Badly formated number');
  34499. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  34500. // 'E' can be either a scientific notation or the beginning of a new
  34501. // operator
  34502. ch = this.peekChar();
  34503. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  34504. powerValueSign = (ch === 0x2D) ? -1 : 1;
  34505. this.nextChar(); // Consume the sign character
  34506. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  34507. // The 'E' must be the beginning of a new operator
  34508. break;
  34509. }
  34510. eNotation = true;
  34511. } else {
  34512. // the last character doesn't belong to us
  34513. break;
  34514. }
  34515. }
  34516. if (divideBy !== 0) {
  34517. baseValue /= divideBy;
  34518. }
  34519. if (eNotation) {
  34520. baseValue *= Math.pow(10, powerValueSign * powerValue);
  34521. }
  34522. return sign * baseValue;
  34523. },
  34524. getString: function Lexer_getString() {
  34525. var numParen = 1;
  34526. var done = false;
  34527. var strBuf = this.strBuf;
  34528. strBuf.length = 0;
  34529. var ch = this.nextChar();
  34530. while (true) {
  34531. var charBuffered = false;
  34532. switch (ch | 0) {
  34533. case -1:
  34534. warn('Unterminated string');
  34535. done = true;
  34536. break;
  34537. case 0x28: // '('
  34538. ++numParen;
  34539. strBuf.push('(');
  34540. break;
  34541. case 0x29: // ')'
  34542. if (--numParen === 0) {
  34543. this.nextChar(); // consume strings ')'
  34544. done = true;
  34545. } else {
  34546. strBuf.push(')');
  34547. }
  34548. break;
  34549. case 0x5C: // '\\'
  34550. ch = this.nextChar();
  34551. switch (ch) {
  34552. case -1:
  34553. warn('Unterminated string');
  34554. done = true;
  34555. break;
  34556. case 0x6E: // 'n'
  34557. strBuf.push('\n');
  34558. break;
  34559. case 0x72: // 'r'
  34560. strBuf.push('\r');
  34561. break;
  34562. case 0x74: // 't'
  34563. strBuf.push('\t');
  34564. break;
  34565. case 0x62: // 'b'
  34566. strBuf.push('\b');
  34567. break;
  34568. case 0x66: // 'f'
  34569. strBuf.push('\f');
  34570. break;
  34571. case 0x5C: // '\'
  34572. case 0x28: // '('
  34573. case 0x29: // ')'
  34574. strBuf.push(String.fromCharCode(ch));
  34575. break;
  34576. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  34577. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  34578. var x = ch & 0x0F;
  34579. ch = this.nextChar();
  34580. charBuffered = true;
  34581. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34582. x = (x << 3) + (ch & 0x0F);
  34583. ch = this.nextChar();
  34584. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  34585. charBuffered = false;
  34586. x = (x << 3) + (ch & 0x0F);
  34587. }
  34588. }
  34589. strBuf.push(String.fromCharCode(x));
  34590. break;
  34591. case 0x0D: // CR
  34592. if (this.peekChar() === 0x0A) { // LF
  34593. this.nextChar();
  34594. }
  34595. break;
  34596. case 0x0A: // LF
  34597. break;
  34598. default:
  34599. strBuf.push(String.fromCharCode(ch));
  34600. break;
  34601. }
  34602. break;
  34603. default:
  34604. strBuf.push(String.fromCharCode(ch));
  34605. break;
  34606. }
  34607. if (done) {
  34608. break;
  34609. }
  34610. if (!charBuffered) {
  34611. ch = this.nextChar();
  34612. }
  34613. }
  34614. return strBuf.join('');
  34615. },
  34616. getName: function Lexer_getName() {
  34617. var ch;
  34618. var strBuf = this.strBuf;
  34619. strBuf.length = 0;
  34620. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34621. if (ch === 0x23) { // '#'
  34622. ch = this.nextChar();
  34623. var x = toHexDigit(ch);
  34624. if (x !== -1) {
  34625. var x2 = toHexDigit(this.nextChar());
  34626. if (x2 === -1) {
  34627. error('Illegal digit in hex char in name: ' + x2);
  34628. }
  34629. strBuf.push(String.fromCharCode((x << 4) | x2));
  34630. } else {
  34631. strBuf.push('#', String.fromCharCode(ch));
  34632. }
  34633. } else {
  34634. strBuf.push(String.fromCharCode(ch));
  34635. }
  34636. }
  34637. if (strBuf.length > 128) {
  34638. error('Warning: name token is longer than allowed by the spec: ' +
  34639. strBuf.length);
  34640. }
  34641. return Name.get(strBuf.join(''));
  34642. },
  34643. getHexString: function Lexer_getHexString() {
  34644. var strBuf = this.strBuf;
  34645. strBuf.length = 0;
  34646. var ch = this.currentChar;
  34647. var isFirstHex = true;
  34648. var firstDigit;
  34649. var secondDigit;
  34650. while (true) {
  34651. if (ch < 0) {
  34652. warn('Unterminated hex string');
  34653. break;
  34654. } else if (ch === 0x3E) { // '>'
  34655. this.nextChar();
  34656. break;
  34657. } else if (specialChars[ch] === 1) {
  34658. ch = this.nextChar();
  34659. continue;
  34660. } else {
  34661. if (isFirstHex) {
  34662. firstDigit = toHexDigit(ch);
  34663. if (firstDigit === -1) {
  34664. warn('Ignoring invalid character "' + ch + '" in hex string');
  34665. ch = this.nextChar();
  34666. continue;
  34667. }
  34668. } else {
  34669. secondDigit = toHexDigit(ch);
  34670. if (secondDigit === -1) {
  34671. warn('Ignoring invalid character "' + ch + '" in hex string');
  34672. ch = this.nextChar();
  34673. continue;
  34674. }
  34675. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  34676. }
  34677. isFirstHex = !isFirstHex;
  34678. ch = this.nextChar();
  34679. }
  34680. }
  34681. return strBuf.join('');
  34682. },
  34683. getObj: function Lexer_getObj() {
  34684. // skip whitespace and comments
  34685. var comment = false;
  34686. var ch = this.currentChar;
  34687. while (true) {
  34688. if (ch < 0) {
  34689. return EOF;
  34690. }
  34691. if (comment) {
  34692. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  34693. comment = false;
  34694. }
  34695. } else if (ch === 0x25) { // '%'
  34696. comment = true;
  34697. } else if (specialChars[ch] !== 1) {
  34698. break;
  34699. }
  34700. ch = this.nextChar();
  34701. }
  34702. // start reading token
  34703. switch (ch | 0) {
  34704. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34705. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34706. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34707. return this.getNumber();
  34708. case 0x28: // '('
  34709. return this.getString();
  34710. case 0x2F: // '/'
  34711. return this.getName();
  34712. // array punctuation
  34713. case 0x5B: // '['
  34714. this.nextChar();
  34715. return Cmd.get('[');
  34716. case 0x5D: // ']'
  34717. this.nextChar();
  34718. return Cmd.get(']');
  34719. // hex string or dict punctuation
  34720. case 0x3C: // '<'
  34721. ch = this.nextChar();
  34722. if (ch === 0x3C) {
  34723. // dict punctuation
  34724. this.nextChar();
  34725. return Cmd.get('<<');
  34726. }
  34727. return this.getHexString();
  34728. // dict punctuation
  34729. case 0x3E: // '>'
  34730. ch = this.nextChar();
  34731. if (ch === 0x3E) {
  34732. this.nextChar();
  34733. return Cmd.get('>>');
  34734. }
  34735. return Cmd.get('>');
  34736. case 0x7B: // '{'
  34737. this.nextChar();
  34738. return Cmd.get('{');
  34739. case 0x7D: // '}'
  34740. this.nextChar();
  34741. return Cmd.get('}');
  34742. case 0x29: // ')'
  34743. error('Illegal character: ' + ch);
  34744. break;
  34745. }
  34746. // command
  34747. var str = String.fromCharCode(ch);
  34748. var knownCommands = this.knownCommands;
  34749. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34750. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  34751. // stop if known command is found and next character does not make
  34752. // the str a command
  34753. var possibleCommand = str + String.fromCharCode(ch);
  34754. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  34755. break;
  34756. }
  34757. if (str.length === 128) {
  34758. error('Command token too long: ' + str.length);
  34759. }
  34760. str = possibleCommand;
  34761. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  34762. }
  34763. if (str === 'true') {
  34764. return true;
  34765. }
  34766. if (str === 'false') {
  34767. return false;
  34768. }
  34769. if (str === 'null') {
  34770. return null;
  34771. }
  34772. return Cmd.get(str);
  34773. },
  34774. skipToNextLine: function Lexer_skipToNextLine() {
  34775. var ch = this.currentChar;
  34776. while (ch >= 0) {
  34777. if (ch === 0x0D) { // CR
  34778. ch = this.nextChar();
  34779. if (ch === 0x0A) { // LF
  34780. this.nextChar();
  34781. }
  34782. break;
  34783. } else if (ch === 0x0A) { // LF
  34784. this.nextChar();
  34785. break;
  34786. }
  34787. ch = this.nextChar();
  34788. }
  34789. }
  34790. };
  34791. return Lexer;
  34792. })();
  34793. var Linearization = {
  34794. create: function LinearizationCreate(stream) {
  34795. function getInt(name, allowZeroValue) {
  34796. var obj = linDict.get(name);
  34797. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  34798. return obj;
  34799. }
  34800. throw new Error('The "' + name + '" parameter in the linearization ' +
  34801. 'dictionary is invalid.');
  34802. }
  34803. function getHints() {
  34804. var hints = linDict.get('H'), hintsLength, item;
  34805. if (isArray(hints) &&
  34806. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  34807. for (var index = 0; index < hintsLength; index++) {
  34808. if (!(isInt(item = hints[index]) && item > 0)) {
  34809. throw new Error('Hint (' + index +
  34810. ') in the linearization dictionary is invalid.');
  34811. }
  34812. }
  34813. return hints;
  34814. }
  34815. throw new Error('Hint array in the linearization dictionary is invalid.');
  34816. }
  34817. var parser = new Parser(new Lexer(stream), false, null);
  34818. var obj1 = parser.getObj();
  34819. var obj2 = parser.getObj();
  34820. var obj3 = parser.getObj();
  34821. var linDict = parser.getObj();
  34822. var obj, length;
  34823. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  34824. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  34825. return null; // No valid linearization dictionary found.
  34826. } else if ((length = getInt('L')) !== stream.length) {
  34827. throw new Error('The "L" parameter in the linearization dictionary ' +
  34828. 'does not equal the stream length.');
  34829. }
  34830. return {
  34831. length: length,
  34832. hints: getHints(),
  34833. objectNumberFirst: getInt('O'),
  34834. endFirst: getInt('E'),
  34835. numPages: getInt('N'),
  34836. mainXRefEntriesOffset: getInt('T'),
  34837. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  34838. };
  34839. }
  34840. };
  34841. var PostScriptParser = (function PostScriptParserClosure() {
  34842. function PostScriptParser(lexer) {
  34843. this.lexer = lexer;
  34844. this.operators = [];
  34845. this.token = null;
  34846. this.prev = null;
  34847. }
  34848. PostScriptParser.prototype = {
  34849. nextToken: function PostScriptParser_nextToken() {
  34850. this.prev = this.token;
  34851. this.token = this.lexer.getToken();
  34852. },
  34853. accept: function PostScriptParser_accept(type) {
  34854. if (this.token.type === type) {
  34855. this.nextToken();
  34856. return true;
  34857. }
  34858. return false;
  34859. },
  34860. expect: function PostScriptParser_expect(type) {
  34861. if (this.accept(type)) {
  34862. return true;
  34863. }
  34864. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  34865. type + '.');
  34866. },
  34867. parse: function PostScriptParser_parse() {
  34868. this.nextToken();
  34869. this.expect(PostScriptTokenTypes.LBRACE);
  34870. this.parseBlock();
  34871. this.expect(PostScriptTokenTypes.RBRACE);
  34872. return this.operators;
  34873. },
  34874. parseBlock: function PostScriptParser_parseBlock() {
  34875. while (true) {
  34876. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  34877. this.operators.push(this.prev.value);
  34878. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  34879. this.operators.push(this.prev.value);
  34880. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34881. this.parseCondition();
  34882. } else {
  34883. return;
  34884. }
  34885. }
  34886. },
  34887. parseCondition: function PostScriptParser_parseCondition() {
  34888. // Add two place holders that will be updated later
  34889. var conditionLocation = this.operators.length;
  34890. this.operators.push(null, null);
  34891. this.parseBlock();
  34892. this.expect(PostScriptTokenTypes.RBRACE);
  34893. if (this.accept(PostScriptTokenTypes.IF)) {
  34894. // The true block is right after the 'if' so it just falls through on
  34895. // true else it jumps and skips the true block.
  34896. this.operators[conditionLocation] = this.operators.length;
  34897. this.operators[conditionLocation + 1] = 'jz';
  34898. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  34899. var jumpLocation = this.operators.length;
  34900. this.operators.push(null, null);
  34901. var endOfTrue = this.operators.length;
  34902. this.parseBlock();
  34903. this.expect(PostScriptTokenTypes.RBRACE);
  34904. this.expect(PostScriptTokenTypes.IFELSE);
  34905. // The jump is added at the end of the true block to skip the false
  34906. // block.
  34907. this.operators[jumpLocation] = this.operators.length;
  34908. this.operators[jumpLocation + 1] = 'j';
  34909. this.operators[conditionLocation] = endOfTrue;
  34910. this.operators[conditionLocation + 1] = 'jz';
  34911. } else {
  34912. error('PS Function: error parsing conditional.');
  34913. }
  34914. }
  34915. };
  34916. return PostScriptParser;
  34917. })();
  34918. var PostScriptTokenTypes = {
  34919. LBRACE: 0,
  34920. RBRACE: 1,
  34921. NUMBER: 2,
  34922. OPERATOR: 3,
  34923. IF: 4,
  34924. IFELSE: 5
  34925. };
  34926. var PostScriptToken = (function PostScriptTokenClosure() {
  34927. function PostScriptToken(type, value) {
  34928. this.type = type;
  34929. this.value = value;
  34930. }
  34931. var opCache = {};
  34932. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  34933. var opValue = opCache[op];
  34934. if (opValue) {
  34935. return opValue;
  34936. }
  34937. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  34938. };
  34939. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  34940. '{');
  34941. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  34942. '}');
  34943. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  34944. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  34945. 'IFELSE');
  34946. return PostScriptToken;
  34947. })();
  34948. var PostScriptLexer = (function PostScriptLexerClosure() {
  34949. function PostScriptLexer(stream) {
  34950. this.stream = stream;
  34951. this.nextChar();
  34952. this.strBuf = [];
  34953. }
  34954. PostScriptLexer.prototype = {
  34955. nextChar: function PostScriptLexer_nextChar() {
  34956. return (this.currentChar = this.stream.getByte());
  34957. },
  34958. getToken: function PostScriptLexer_getToken() {
  34959. var comment = false;
  34960. var ch = this.currentChar;
  34961. // skip comments
  34962. while (true) {
  34963. if (ch < 0) {
  34964. return EOF;
  34965. }
  34966. if (comment) {
  34967. if (ch === 0x0A || ch === 0x0D) {
  34968. comment = false;
  34969. }
  34970. } else if (ch === 0x25) { // '%'
  34971. comment = true;
  34972. } else if (!Lexer.isSpace(ch)) {
  34973. break;
  34974. }
  34975. ch = this.nextChar();
  34976. }
  34977. switch (ch | 0) {
  34978. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  34979. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  34980. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  34981. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  34982. this.getNumber());
  34983. case 0x7B: // '{'
  34984. this.nextChar();
  34985. return PostScriptToken.LBRACE;
  34986. case 0x7D: // '}'
  34987. this.nextChar();
  34988. return PostScriptToken.RBRACE;
  34989. }
  34990. // operator
  34991. var strBuf = this.strBuf;
  34992. strBuf.length = 0;
  34993. strBuf[0] = String.fromCharCode(ch);
  34994. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  34995. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  34996. strBuf.push(String.fromCharCode(ch));
  34997. }
  34998. var str = strBuf.join('');
  34999. switch (str.toLowerCase()) {
  35000. case 'if':
  35001. return PostScriptToken.IF;
  35002. case 'ifelse':
  35003. return PostScriptToken.IFELSE;
  35004. default:
  35005. return PostScriptToken.getOperator(str);
  35006. }
  35007. },
  35008. getNumber: function PostScriptLexer_getNumber() {
  35009. var ch = this.currentChar;
  35010. var strBuf = this.strBuf;
  35011. strBuf.length = 0;
  35012. strBuf[0] = String.fromCharCode(ch);
  35013. while ((ch = this.nextChar()) >= 0) {
  35014. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  35015. ch === 0x2D || ch === 0x2E) { // '-', '.'
  35016. strBuf.push(String.fromCharCode(ch));
  35017. } else {
  35018. break;
  35019. }
  35020. }
  35021. var value = parseFloat(strBuf.join(''));
  35022. if (isNaN(value)) {
  35023. error('Invalid floating point number: ' + value);
  35024. }
  35025. return value;
  35026. }
  35027. };
  35028. return PostScriptLexer;
  35029. })();
  35030. var Stream = (function StreamClosure() {
  35031. function Stream(arrayBuffer, start, length, dict) {
  35032. this.bytes = (arrayBuffer instanceof Uint8Array ?
  35033. arrayBuffer : new Uint8Array(arrayBuffer));
  35034. this.start = start || 0;
  35035. this.pos = this.start;
  35036. this.end = (start + length) || this.bytes.length;
  35037. this.dict = dict;
  35038. }
  35039. // required methods for a stream. if a particular stream does not
  35040. // implement these, an error should be thrown
  35041. Stream.prototype = {
  35042. get length() {
  35043. return this.end - this.start;
  35044. },
  35045. get isEmpty() {
  35046. return this.length === 0;
  35047. },
  35048. getByte: function Stream_getByte() {
  35049. if (this.pos >= this.end) {
  35050. return -1;
  35051. }
  35052. return this.bytes[this.pos++];
  35053. },
  35054. getUint16: function Stream_getUint16() {
  35055. var b0 = this.getByte();
  35056. var b1 = this.getByte();
  35057. if (b0 === -1 || b1 === -1) {
  35058. return -1;
  35059. }
  35060. return (b0 << 8) + b1;
  35061. },
  35062. getInt32: function Stream_getInt32() {
  35063. var b0 = this.getByte();
  35064. var b1 = this.getByte();
  35065. var b2 = this.getByte();
  35066. var b3 = this.getByte();
  35067. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35068. },
  35069. // returns subarray of original buffer
  35070. // should only be read
  35071. getBytes: function Stream_getBytes(length) {
  35072. var bytes = this.bytes;
  35073. var pos = this.pos;
  35074. var strEnd = this.end;
  35075. if (!length) {
  35076. return bytes.subarray(pos, strEnd);
  35077. }
  35078. var end = pos + length;
  35079. if (end > strEnd) {
  35080. end = strEnd;
  35081. }
  35082. this.pos = end;
  35083. return bytes.subarray(pos, end);
  35084. },
  35085. peekByte: function Stream_peekByte() {
  35086. var peekedByte = this.getByte();
  35087. this.pos--;
  35088. return peekedByte;
  35089. },
  35090. peekBytes: function Stream_peekBytes(length) {
  35091. var bytes = this.getBytes(length);
  35092. this.pos -= bytes.length;
  35093. return bytes;
  35094. },
  35095. skip: function Stream_skip(n) {
  35096. if (!n) {
  35097. n = 1;
  35098. }
  35099. this.pos += n;
  35100. },
  35101. reset: function Stream_reset() {
  35102. this.pos = this.start;
  35103. },
  35104. moveStart: function Stream_moveStart() {
  35105. this.start = this.pos;
  35106. },
  35107. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  35108. return new Stream(this.bytes.buffer, start, length, dict);
  35109. },
  35110. isStream: true
  35111. };
  35112. return Stream;
  35113. })();
  35114. var StringStream = (function StringStreamClosure() {
  35115. function StringStream(str) {
  35116. var length = str.length;
  35117. var bytes = new Uint8Array(length);
  35118. for (var n = 0; n < length; ++n) {
  35119. bytes[n] = str.charCodeAt(n);
  35120. }
  35121. Stream.call(this, bytes);
  35122. }
  35123. StringStream.prototype = Stream.prototype;
  35124. return StringStream;
  35125. })();
  35126. // super class for the decoding streams
  35127. var DecodeStream = (function DecodeStreamClosure() {
  35128. // Lots of DecodeStreams are created whose buffers are never used. For these
  35129. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  35130. // having special cases that would be required if we used |null| for an empty
  35131. // buffer.
  35132. var emptyBuffer = new Uint8Array(0);
  35133. function DecodeStream(maybeMinBufferLength) {
  35134. this.pos = 0;
  35135. this.bufferLength = 0;
  35136. this.eof = false;
  35137. this.buffer = emptyBuffer;
  35138. this.minBufferLength = 512;
  35139. if (maybeMinBufferLength) {
  35140. // Compute the first power of two that is as big as maybeMinBufferLength.
  35141. while (this.minBufferLength < maybeMinBufferLength) {
  35142. this.minBufferLength *= 2;
  35143. }
  35144. }
  35145. }
  35146. DecodeStream.prototype = {
  35147. get isEmpty() {
  35148. while (!this.eof && this.bufferLength === 0) {
  35149. this.readBlock();
  35150. }
  35151. return this.bufferLength === 0;
  35152. },
  35153. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  35154. var buffer = this.buffer;
  35155. if (requested <= buffer.byteLength) {
  35156. return buffer;
  35157. }
  35158. var size = this.minBufferLength;
  35159. while (size < requested) {
  35160. size *= 2;
  35161. }
  35162. var buffer2 = new Uint8Array(size);
  35163. buffer2.set(buffer);
  35164. return (this.buffer = buffer2);
  35165. },
  35166. getByte: function DecodeStream_getByte() {
  35167. var pos = this.pos;
  35168. while (this.bufferLength <= pos) {
  35169. if (this.eof) {
  35170. return -1;
  35171. }
  35172. this.readBlock();
  35173. }
  35174. return this.buffer[this.pos++];
  35175. },
  35176. getUint16: function DecodeStream_getUint16() {
  35177. var b0 = this.getByte();
  35178. var b1 = this.getByte();
  35179. if (b0 === -1 || b1 === -1) {
  35180. return -1;
  35181. }
  35182. return (b0 << 8) + b1;
  35183. },
  35184. getInt32: function DecodeStream_getInt32() {
  35185. var b0 = this.getByte();
  35186. var b1 = this.getByte();
  35187. var b2 = this.getByte();
  35188. var b3 = this.getByte();
  35189. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  35190. },
  35191. getBytes: function DecodeStream_getBytes(length) {
  35192. var end, pos = this.pos;
  35193. if (length) {
  35194. this.ensureBuffer(pos + length);
  35195. end = pos + length;
  35196. while (!this.eof && this.bufferLength < end) {
  35197. this.readBlock();
  35198. }
  35199. var bufEnd = this.bufferLength;
  35200. if (end > bufEnd) {
  35201. end = bufEnd;
  35202. }
  35203. } else {
  35204. while (!this.eof) {
  35205. this.readBlock();
  35206. }
  35207. end = this.bufferLength;
  35208. }
  35209. this.pos = end;
  35210. return this.buffer.subarray(pos, end);
  35211. },
  35212. peekByte: function DecodeStream_peekByte() {
  35213. var peekedByte = this.getByte();
  35214. this.pos--;
  35215. return peekedByte;
  35216. },
  35217. peekBytes: function DecodeStream_peekBytes(length) {
  35218. var bytes = this.getBytes(length);
  35219. this.pos -= bytes.length;
  35220. return bytes;
  35221. },
  35222. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  35223. var end = start + length;
  35224. while (this.bufferLength <= end && !this.eof) {
  35225. this.readBlock();
  35226. }
  35227. return new Stream(this.buffer, start, length, dict);
  35228. },
  35229. skip: function DecodeStream_skip(n) {
  35230. if (!n) {
  35231. n = 1;
  35232. }
  35233. this.pos += n;
  35234. },
  35235. reset: function DecodeStream_reset() {
  35236. this.pos = 0;
  35237. },
  35238. getBaseStreams: function DecodeStream_getBaseStreams() {
  35239. if (this.str && this.str.getBaseStreams) {
  35240. return this.str.getBaseStreams();
  35241. }
  35242. return [];
  35243. }
  35244. };
  35245. return DecodeStream;
  35246. })();
  35247. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  35248. function StreamsSequenceStream(streams) {
  35249. this.streams = streams;
  35250. DecodeStream.call(this, /* maybeLength = */ null);
  35251. }
  35252. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  35253. StreamsSequenceStream.prototype.readBlock =
  35254. function streamSequenceStreamReadBlock() {
  35255. var streams = this.streams;
  35256. if (streams.length === 0) {
  35257. this.eof = true;
  35258. return;
  35259. }
  35260. var stream = streams.shift();
  35261. var chunk = stream.getBytes();
  35262. var bufferLength = this.bufferLength;
  35263. var newLength = bufferLength + chunk.length;
  35264. var buffer = this.ensureBuffer(newLength);
  35265. buffer.set(chunk, bufferLength);
  35266. this.bufferLength = newLength;
  35267. };
  35268. StreamsSequenceStream.prototype.getBaseStreams =
  35269. function StreamsSequenceStream_getBaseStreams() {
  35270. var baseStreams = [];
  35271. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  35272. var stream = this.streams[i];
  35273. if (stream.getBaseStreams) {
  35274. Util.appendToArray(baseStreams, stream.getBaseStreams());
  35275. }
  35276. }
  35277. return baseStreams;
  35278. };
  35279. return StreamsSequenceStream;
  35280. })();
  35281. var FlateStream = (function FlateStreamClosure() {
  35282. var codeLenCodeMap = new Uint32Array([
  35283. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  35284. ]);
  35285. var lengthDecode = new Uint32Array([
  35286. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  35287. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  35288. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  35289. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  35290. ]);
  35291. var distDecode = new Uint32Array([
  35292. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  35293. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  35294. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  35295. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  35296. ]);
  35297. var fixedLitCodeTab = [new Uint32Array([
  35298. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  35299. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  35300. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  35301. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  35302. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  35303. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  35304. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  35305. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  35306. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  35307. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  35308. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  35309. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  35310. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  35311. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  35312. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  35313. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  35314. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  35315. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  35316. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  35317. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  35318. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  35319. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  35320. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  35321. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  35322. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  35323. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  35324. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  35325. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  35326. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  35327. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  35328. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  35329. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  35330. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  35331. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  35332. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  35333. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  35334. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  35335. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  35336. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  35337. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  35338. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  35339. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  35340. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  35341. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  35342. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  35343. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  35344. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  35345. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  35346. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  35347. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  35348. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  35349. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  35350. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  35351. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  35352. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  35353. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  35354. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  35355. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  35356. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  35357. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  35358. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  35359. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  35360. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  35361. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  35362. ]), 9];
  35363. var fixedDistCodeTab = [new Uint32Array([
  35364. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  35365. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  35366. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  35367. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  35368. ]), 5];
  35369. function FlateStream(str, maybeLength) {
  35370. this.str = str;
  35371. this.dict = str.dict;
  35372. var cmf = str.getByte();
  35373. var flg = str.getByte();
  35374. if (cmf === -1 || flg === -1) {
  35375. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  35376. }
  35377. if ((cmf & 0x0f) !== 0x08) {
  35378. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  35379. }
  35380. if ((((cmf << 8) + flg) % 31) !== 0) {
  35381. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  35382. }
  35383. if (flg & 0x20) {
  35384. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  35385. }
  35386. this.codeSize = 0;
  35387. this.codeBuf = 0;
  35388. DecodeStream.call(this, maybeLength);
  35389. }
  35390. FlateStream.prototype = Object.create(DecodeStream.prototype);
  35391. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  35392. var str = this.str;
  35393. var codeSize = this.codeSize;
  35394. var codeBuf = this.codeBuf;
  35395. var b;
  35396. while (codeSize < bits) {
  35397. if ((b = str.getByte()) === -1) {
  35398. error('Bad encoding in flate stream');
  35399. }
  35400. codeBuf |= b << codeSize;
  35401. codeSize += 8;
  35402. }
  35403. b = codeBuf & ((1 << bits) - 1);
  35404. this.codeBuf = codeBuf >> bits;
  35405. this.codeSize = codeSize -= bits;
  35406. return b;
  35407. };
  35408. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  35409. var str = this.str;
  35410. var codes = table[0];
  35411. var maxLen = table[1];
  35412. var codeSize = this.codeSize;
  35413. var codeBuf = this.codeBuf;
  35414. var b;
  35415. while (codeSize < maxLen) {
  35416. if ((b = str.getByte()) === -1) {
  35417. // premature end of stream. code might however still be valid.
  35418. // codeSize < codeLen check below guards against incomplete codeVal.
  35419. break;
  35420. }
  35421. codeBuf |= (b << codeSize);
  35422. codeSize += 8;
  35423. }
  35424. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  35425. var codeLen = code >> 16;
  35426. var codeVal = code & 0xffff;
  35427. if (codeLen < 1 || codeSize < codeLen) {
  35428. error('Bad encoding in flate stream');
  35429. }
  35430. this.codeBuf = (codeBuf >> codeLen);
  35431. this.codeSize = (codeSize - codeLen);
  35432. return codeVal;
  35433. };
  35434. FlateStream.prototype.generateHuffmanTable =
  35435. function flateStreamGenerateHuffmanTable(lengths) {
  35436. var n = lengths.length;
  35437. // find max code length
  35438. var maxLen = 0;
  35439. var i;
  35440. for (i = 0; i < n; ++i) {
  35441. if (lengths[i] > maxLen) {
  35442. maxLen = lengths[i];
  35443. }
  35444. }
  35445. // build the table
  35446. var size = 1 << maxLen;
  35447. var codes = new Uint32Array(size);
  35448. for (var len = 1, code = 0, skip = 2;
  35449. len <= maxLen;
  35450. ++len, code <<= 1, skip <<= 1) {
  35451. for (var val = 0; val < n; ++val) {
  35452. if (lengths[val] === len) {
  35453. // bit-reverse the code
  35454. var code2 = 0;
  35455. var t = code;
  35456. for (i = 0; i < len; ++i) {
  35457. code2 = (code2 << 1) | (t & 1);
  35458. t >>= 1;
  35459. }
  35460. // fill the table entries
  35461. for (i = code2; i < size; i += skip) {
  35462. codes[i] = (len << 16) | val;
  35463. }
  35464. ++code;
  35465. }
  35466. }
  35467. }
  35468. return [codes, maxLen];
  35469. };
  35470. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  35471. var buffer, len;
  35472. var str = this.str;
  35473. // read block header
  35474. var hdr = this.getBits(3);
  35475. if (hdr & 1) {
  35476. this.eof = true;
  35477. }
  35478. hdr >>= 1;
  35479. if (hdr === 0) { // uncompressed block
  35480. var b;
  35481. if ((b = str.getByte()) === -1) {
  35482. error('Bad block header in flate stream');
  35483. }
  35484. var blockLen = b;
  35485. if ((b = str.getByte()) === -1) {
  35486. error('Bad block header in flate stream');
  35487. }
  35488. blockLen |= (b << 8);
  35489. if ((b = str.getByte()) === -1) {
  35490. error('Bad block header in flate stream');
  35491. }
  35492. var check = b;
  35493. if ((b = str.getByte()) === -1) {
  35494. error('Bad block header in flate stream');
  35495. }
  35496. check |= (b << 8);
  35497. if (check !== (~blockLen & 0xffff) &&
  35498. (blockLen !== 0 || check !== 0)) {
  35499. // Ignoring error for bad "empty" block (see issue 1277)
  35500. error('Bad uncompressed block length in flate stream');
  35501. }
  35502. this.codeBuf = 0;
  35503. this.codeSize = 0;
  35504. var bufferLength = this.bufferLength;
  35505. buffer = this.ensureBuffer(bufferLength + blockLen);
  35506. var end = bufferLength + blockLen;
  35507. this.bufferLength = end;
  35508. if (blockLen === 0) {
  35509. if (str.peekByte() === -1) {
  35510. this.eof = true;
  35511. }
  35512. } else {
  35513. for (var n = bufferLength; n < end; ++n) {
  35514. if ((b = str.getByte()) === -1) {
  35515. this.eof = true;
  35516. break;
  35517. }
  35518. buffer[n] = b;
  35519. }
  35520. }
  35521. return;
  35522. }
  35523. var litCodeTable;
  35524. var distCodeTable;
  35525. if (hdr === 1) { // compressed block, fixed codes
  35526. litCodeTable = fixedLitCodeTab;
  35527. distCodeTable = fixedDistCodeTab;
  35528. } else if (hdr === 2) { // compressed block, dynamic codes
  35529. var numLitCodes = this.getBits(5) + 257;
  35530. var numDistCodes = this.getBits(5) + 1;
  35531. var numCodeLenCodes = this.getBits(4) + 4;
  35532. // build the code lengths code table
  35533. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  35534. var i;
  35535. for (i = 0; i < numCodeLenCodes; ++i) {
  35536. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  35537. }
  35538. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  35539. // build the literal and distance code tables
  35540. len = 0;
  35541. i = 0;
  35542. var codes = numLitCodes + numDistCodes;
  35543. var codeLengths = new Uint8Array(codes);
  35544. var bitsLength, bitsOffset, what;
  35545. while (i < codes) {
  35546. var code = this.getCode(codeLenCodeTab);
  35547. if (code === 16) {
  35548. bitsLength = 2; bitsOffset = 3; what = len;
  35549. } else if (code === 17) {
  35550. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  35551. } else if (code === 18) {
  35552. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  35553. } else {
  35554. codeLengths[i++] = len = code;
  35555. continue;
  35556. }
  35557. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  35558. while (repeatLength-- > 0) {
  35559. codeLengths[i++] = what;
  35560. }
  35561. }
  35562. litCodeTable =
  35563. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  35564. distCodeTable =
  35565. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  35566. } else {
  35567. error('Unknown block type in flate stream');
  35568. }
  35569. buffer = this.buffer;
  35570. var limit = buffer ? buffer.length : 0;
  35571. var pos = this.bufferLength;
  35572. while (true) {
  35573. var code1 = this.getCode(litCodeTable);
  35574. if (code1 < 256) {
  35575. if (pos + 1 >= limit) {
  35576. buffer = this.ensureBuffer(pos + 1);
  35577. limit = buffer.length;
  35578. }
  35579. buffer[pos++] = code1;
  35580. continue;
  35581. }
  35582. if (code1 === 256) {
  35583. this.bufferLength = pos;
  35584. return;
  35585. }
  35586. code1 -= 257;
  35587. code1 = lengthDecode[code1];
  35588. var code2 = code1 >> 16;
  35589. if (code2 > 0) {
  35590. code2 = this.getBits(code2);
  35591. }
  35592. len = (code1 & 0xffff) + code2;
  35593. code1 = this.getCode(distCodeTable);
  35594. code1 = distDecode[code1];
  35595. code2 = code1 >> 16;
  35596. if (code2 > 0) {
  35597. code2 = this.getBits(code2);
  35598. }
  35599. var dist = (code1 & 0xffff) + code2;
  35600. if (pos + len >= limit) {
  35601. buffer = this.ensureBuffer(pos + len);
  35602. limit = buffer.length;
  35603. }
  35604. for (var k = 0; k < len; ++k, ++pos) {
  35605. buffer[pos] = buffer[pos - dist];
  35606. }
  35607. }
  35608. };
  35609. return FlateStream;
  35610. })();
  35611. var PredictorStream = (function PredictorStreamClosure() {
  35612. function PredictorStream(str, maybeLength, params) {
  35613. var predictor = this.predictor = params.get('Predictor') || 1;
  35614. if (predictor <= 1) {
  35615. return str; // no prediction
  35616. }
  35617. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  35618. error('Unsupported predictor: ' + predictor);
  35619. }
  35620. if (predictor === 2) {
  35621. this.readBlock = this.readBlockTiff;
  35622. } else {
  35623. this.readBlock = this.readBlockPng;
  35624. }
  35625. this.str = str;
  35626. this.dict = str.dict;
  35627. var colors = this.colors = params.get('Colors') || 1;
  35628. var bits = this.bits = params.get('BitsPerComponent') || 8;
  35629. var columns = this.columns = params.get('Columns') || 1;
  35630. this.pixBytes = (colors * bits + 7) >> 3;
  35631. this.rowBytes = (columns * colors * bits + 7) >> 3;
  35632. DecodeStream.call(this, maybeLength);
  35633. return this;
  35634. }
  35635. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  35636. PredictorStream.prototype.readBlockTiff =
  35637. function predictorStreamReadBlockTiff() {
  35638. var rowBytes = this.rowBytes;
  35639. var bufferLength = this.bufferLength;
  35640. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35641. var bits = this.bits;
  35642. var colors = this.colors;
  35643. var rawBytes = this.str.getBytes(rowBytes);
  35644. this.eof = !rawBytes.length;
  35645. if (this.eof) {
  35646. return;
  35647. }
  35648. var inbuf = 0, outbuf = 0;
  35649. var inbits = 0, outbits = 0;
  35650. var pos = bufferLength;
  35651. var i;
  35652. if (bits === 1) {
  35653. for (i = 0; i < rowBytes; ++i) {
  35654. var c = rawBytes[i];
  35655. inbuf = (inbuf << 8) | c;
  35656. // bitwise addition is exclusive or
  35657. // first shift inbuf and then add
  35658. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  35659. // truncate inbuf (assumes colors < 16)
  35660. inbuf &= 0xFFFF;
  35661. }
  35662. } else if (bits === 8) {
  35663. for (i = 0; i < colors; ++i) {
  35664. buffer[pos++] = rawBytes[i];
  35665. }
  35666. for (; i < rowBytes; ++i) {
  35667. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  35668. pos++;
  35669. }
  35670. } else {
  35671. var compArray = new Uint8Array(colors + 1);
  35672. var bitMask = (1 << bits) - 1;
  35673. var j = 0, k = bufferLength;
  35674. var columns = this.columns;
  35675. for (i = 0; i < columns; ++i) {
  35676. for (var kk = 0; kk < colors; ++kk) {
  35677. if (inbits < bits) {
  35678. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  35679. inbits += 8;
  35680. }
  35681. compArray[kk] = (compArray[kk] +
  35682. (inbuf >> (inbits - bits))) & bitMask;
  35683. inbits -= bits;
  35684. outbuf = (outbuf << bits) | compArray[kk];
  35685. outbits += bits;
  35686. if (outbits >= 8) {
  35687. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  35688. outbits -= 8;
  35689. }
  35690. }
  35691. }
  35692. if (outbits > 0) {
  35693. buffer[k++] = (outbuf << (8 - outbits)) +
  35694. (inbuf & ((1 << (8 - outbits)) - 1));
  35695. }
  35696. }
  35697. this.bufferLength += rowBytes;
  35698. };
  35699. PredictorStream.prototype.readBlockPng =
  35700. function predictorStreamReadBlockPng() {
  35701. var rowBytes = this.rowBytes;
  35702. var pixBytes = this.pixBytes;
  35703. var predictor = this.str.getByte();
  35704. var rawBytes = this.str.getBytes(rowBytes);
  35705. this.eof = !rawBytes.length;
  35706. if (this.eof) {
  35707. return;
  35708. }
  35709. var bufferLength = this.bufferLength;
  35710. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  35711. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  35712. if (prevRow.length === 0) {
  35713. prevRow = new Uint8Array(rowBytes);
  35714. }
  35715. var i, j = bufferLength, up, c;
  35716. switch (predictor) {
  35717. case 0:
  35718. for (i = 0; i < rowBytes; ++i) {
  35719. buffer[j++] = rawBytes[i];
  35720. }
  35721. break;
  35722. case 1:
  35723. for (i = 0; i < pixBytes; ++i) {
  35724. buffer[j++] = rawBytes[i];
  35725. }
  35726. for (; i < rowBytes; ++i) {
  35727. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  35728. j++;
  35729. }
  35730. break;
  35731. case 2:
  35732. for (i = 0; i < rowBytes; ++i) {
  35733. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  35734. }
  35735. break;
  35736. case 3:
  35737. for (i = 0; i < pixBytes; ++i) {
  35738. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  35739. }
  35740. for (; i < rowBytes; ++i) {
  35741. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  35742. rawBytes[i]) & 0xFF;
  35743. j++;
  35744. }
  35745. break;
  35746. case 4:
  35747. // we need to save the up left pixels values. the simplest way
  35748. // is to create a new buffer
  35749. for (i = 0; i < pixBytes; ++i) {
  35750. up = prevRow[i];
  35751. c = rawBytes[i];
  35752. buffer[j++] = up + c;
  35753. }
  35754. for (; i < rowBytes; ++i) {
  35755. up = prevRow[i];
  35756. var upLeft = prevRow[i - pixBytes];
  35757. var left = buffer[j - pixBytes];
  35758. var p = left + up - upLeft;
  35759. var pa = p - left;
  35760. if (pa < 0) {
  35761. pa = -pa;
  35762. }
  35763. var pb = p - up;
  35764. if (pb < 0) {
  35765. pb = -pb;
  35766. }
  35767. var pc = p - upLeft;
  35768. if (pc < 0) {
  35769. pc = -pc;
  35770. }
  35771. c = rawBytes[i];
  35772. if (pa <= pb && pa <= pc) {
  35773. buffer[j++] = left + c;
  35774. } else if (pb <= pc) {
  35775. buffer[j++] = up + c;
  35776. } else {
  35777. buffer[j++] = upLeft + c;
  35778. }
  35779. }
  35780. break;
  35781. default:
  35782. error('Unsupported predictor: ' + predictor);
  35783. }
  35784. this.bufferLength += rowBytes;
  35785. };
  35786. return PredictorStream;
  35787. })();
  35788. /**
  35789. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  35790. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  35791. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  35792. * a library to decode these images and the stream behaves like all the other
  35793. * DecodeStreams.
  35794. */
  35795. var JpegStream = (function JpegStreamClosure() {
  35796. function JpegStream(stream, maybeLength, dict, xref) {
  35797. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  35798. // Note: this seems to mainly affect inline images.
  35799. var ch;
  35800. while ((ch = stream.getByte()) !== -1) {
  35801. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  35802. stream.skip(-1); // Reset the stream position to the SOI.
  35803. break;
  35804. }
  35805. }
  35806. this.stream = stream;
  35807. this.maybeLength = maybeLength;
  35808. this.dict = dict;
  35809. DecodeStream.call(this, maybeLength);
  35810. }
  35811. JpegStream.prototype = Object.create(DecodeStream.prototype);
  35812. Object.defineProperty(JpegStream.prototype, 'bytes', {
  35813. get: function JpegStream_bytes() {
  35814. // If this.maybeLength is null, we'll get the entire stream.
  35815. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35816. },
  35817. configurable: true
  35818. });
  35819. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  35820. if (this.bufferLength) {
  35821. return;
  35822. }
  35823. try {
  35824. var jpegImage = new JpegImage();
  35825. // checking if values needs to be transformed before conversion
  35826. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  35827. var decodeArr = this.dict.get('Decode');
  35828. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  35829. var decodeArrLength = decodeArr.length;
  35830. var transform = new Int32Array(decodeArrLength);
  35831. var transformNeeded = false;
  35832. var maxValue = (1 << bitsPerComponent) - 1;
  35833. for (var i = 0; i < decodeArrLength; i += 2) {
  35834. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  35835. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  35836. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  35837. transformNeeded = true;
  35838. }
  35839. }
  35840. if (transformNeeded) {
  35841. jpegImage.decodeTransform = transform;
  35842. }
  35843. }
  35844. jpegImage.parse(this.bytes);
  35845. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  35846. this.forceRGB);
  35847. this.buffer = data;
  35848. this.bufferLength = data.length;
  35849. this.eof = true;
  35850. } catch (e) {
  35851. error('JPEG error: ' + e);
  35852. }
  35853. };
  35854. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  35855. this.ensureBuffer();
  35856. return this.buffer;
  35857. };
  35858. JpegStream.prototype.getIR = function JpegStream_getIR() {
  35859. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  35860. };
  35861. /**
  35862. * Checks if the image can be decoded and displayed by the browser without any
  35863. * further processing such as color space conversions.
  35864. */
  35865. JpegStream.prototype.isNativelySupported =
  35866. function JpegStream_isNativelySupported(xref, res) {
  35867. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35868. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  35869. };
  35870. /**
  35871. * Checks if the image can be decoded by the browser.
  35872. */
  35873. JpegStream.prototype.isNativelyDecodable =
  35874. function JpegStream_isNativelyDecodable(xref, res) {
  35875. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  35876. var numComps = cs.numComps;
  35877. return numComps === 1 || numComps === 3;
  35878. };
  35879. return JpegStream;
  35880. })();
  35881. /**
  35882. * For JPEG 2000's we use a library to decode these images and
  35883. * the stream behaves like all the other DecodeStreams.
  35884. */
  35885. var JpxStream = (function JpxStreamClosure() {
  35886. function JpxStream(stream, maybeLength, dict) {
  35887. this.stream = stream;
  35888. this.maybeLength = maybeLength;
  35889. this.dict = dict;
  35890. DecodeStream.call(this, maybeLength);
  35891. }
  35892. JpxStream.prototype = Object.create(DecodeStream.prototype);
  35893. Object.defineProperty(JpxStream.prototype, 'bytes', {
  35894. get: function JpxStream_bytes() {
  35895. // If this.maybeLength is null, we'll get the entire stream.
  35896. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35897. },
  35898. configurable: true
  35899. });
  35900. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  35901. if (this.bufferLength) {
  35902. return;
  35903. }
  35904. var jpxImage = new JpxImage();
  35905. jpxImage.parse(this.bytes);
  35906. var width = jpxImage.width;
  35907. var height = jpxImage.height;
  35908. var componentsCount = jpxImage.componentsCount;
  35909. var tileCount = jpxImage.tiles.length;
  35910. if (tileCount === 1) {
  35911. this.buffer = jpxImage.tiles[0].items;
  35912. } else {
  35913. var data = new Uint8Array(width * height * componentsCount);
  35914. for (var k = 0; k < tileCount; k++) {
  35915. var tileComponents = jpxImage.tiles[k];
  35916. var tileWidth = tileComponents.width;
  35917. var tileHeight = tileComponents.height;
  35918. var tileLeft = tileComponents.left;
  35919. var tileTop = tileComponents.top;
  35920. var src = tileComponents.items;
  35921. var srcPosition = 0;
  35922. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  35923. var imgRowSize = width * componentsCount;
  35924. var tileRowSize = tileWidth * componentsCount;
  35925. for (var j = 0; j < tileHeight; j++) {
  35926. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  35927. data.set(rowBytes, dataPosition);
  35928. srcPosition += tileRowSize;
  35929. dataPosition += imgRowSize;
  35930. }
  35931. }
  35932. this.buffer = data;
  35933. }
  35934. this.bufferLength = this.buffer.length;
  35935. this.eof = true;
  35936. };
  35937. return JpxStream;
  35938. })();
  35939. /**
  35940. * For JBIG2's we use a library to decode these images and
  35941. * the stream behaves like all the other DecodeStreams.
  35942. */
  35943. var Jbig2Stream = (function Jbig2StreamClosure() {
  35944. function Jbig2Stream(stream, maybeLength, dict) {
  35945. this.stream = stream;
  35946. this.maybeLength = maybeLength;
  35947. this.dict = dict;
  35948. DecodeStream.call(this, maybeLength);
  35949. }
  35950. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  35951. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  35952. get: function Jbig2Stream_bytes() {
  35953. // If this.maybeLength is null, we'll get the entire stream.
  35954. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  35955. },
  35956. configurable: true
  35957. });
  35958. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  35959. if (this.bufferLength) {
  35960. return;
  35961. }
  35962. var jbig2Image = new Jbig2Image();
  35963. var chunks = [], xref = this.dict.xref;
  35964. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  35965. // According to the PDF specification, DecodeParms can be either
  35966. // a dictionary, or an array whose elements are dictionaries.
  35967. if (isArray(decodeParams)) {
  35968. if (decodeParams.length > 1) {
  35969. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  35970. 'not supported.');
  35971. }
  35972. decodeParams = xref.fetchIfRef(decodeParams[0]);
  35973. }
  35974. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  35975. var globalsStream = decodeParams.get('JBIG2Globals');
  35976. var globals = globalsStream.getBytes();
  35977. chunks.push({data: globals, start: 0, end: globals.length});
  35978. }
  35979. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  35980. var data = jbig2Image.parseChunks(chunks);
  35981. var dataLength = data.length;
  35982. // JBIG2 had black as 1 and white as 0, inverting the colors
  35983. for (var i = 0; i < dataLength; i++) {
  35984. data[i] ^= 0xFF;
  35985. }
  35986. this.buffer = data;
  35987. this.bufferLength = dataLength;
  35988. this.eof = true;
  35989. };
  35990. return Jbig2Stream;
  35991. })();
  35992. var DecryptStream = (function DecryptStreamClosure() {
  35993. function DecryptStream(str, maybeLength, decrypt) {
  35994. this.str = str;
  35995. this.dict = str.dict;
  35996. this.decrypt = decrypt;
  35997. this.nextChunk = null;
  35998. this.initialized = false;
  35999. DecodeStream.call(this, maybeLength);
  36000. }
  36001. var chunkSize = 512;
  36002. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  36003. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  36004. var chunk;
  36005. if (this.initialized) {
  36006. chunk = this.nextChunk;
  36007. } else {
  36008. chunk = this.str.getBytes(chunkSize);
  36009. this.initialized = true;
  36010. }
  36011. if (!chunk || chunk.length === 0) {
  36012. this.eof = true;
  36013. return;
  36014. }
  36015. this.nextChunk = this.str.getBytes(chunkSize);
  36016. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  36017. var decrypt = this.decrypt;
  36018. chunk = decrypt(chunk, !hasMoreData);
  36019. var bufferLength = this.bufferLength;
  36020. var i, n = chunk.length;
  36021. var buffer = this.ensureBuffer(bufferLength + n);
  36022. for (i = 0; i < n; i++) {
  36023. buffer[bufferLength++] = chunk[i];
  36024. }
  36025. this.bufferLength = bufferLength;
  36026. };
  36027. return DecryptStream;
  36028. })();
  36029. var Ascii85Stream = (function Ascii85StreamClosure() {
  36030. function Ascii85Stream(str, maybeLength) {
  36031. this.str = str;
  36032. this.dict = str.dict;
  36033. this.input = new Uint8Array(5);
  36034. // Most streams increase in size when decoded, but Ascii85 streams
  36035. // typically shrink by ~20%.
  36036. if (maybeLength) {
  36037. maybeLength = 0.8 * maybeLength;
  36038. }
  36039. DecodeStream.call(this, maybeLength);
  36040. }
  36041. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  36042. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  36043. var TILDA_CHAR = 0x7E; // '~'
  36044. var Z_LOWER_CHAR = 0x7A; // 'z'
  36045. var EOF = -1;
  36046. var str = this.str;
  36047. var c = str.getByte();
  36048. while (Lexer.isSpace(c)) {
  36049. c = str.getByte();
  36050. }
  36051. if (c === EOF || c === TILDA_CHAR) {
  36052. this.eof = true;
  36053. return;
  36054. }
  36055. var bufferLength = this.bufferLength, buffer;
  36056. var i;
  36057. // special code for z
  36058. if (c === Z_LOWER_CHAR) {
  36059. buffer = this.ensureBuffer(bufferLength + 4);
  36060. for (i = 0; i < 4; ++i) {
  36061. buffer[bufferLength + i] = 0;
  36062. }
  36063. this.bufferLength += 4;
  36064. } else {
  36065. var input = this.input;
  36066. input[0] = c;
  36067. for (i = 1; i < 5; ++i) {
  36068. c = str.getByte();
  36069. while (Lexer.isSpace(c)) {
  36070. c = str.getByte();
  36071. }
  36072. input[i] = c;
  36073. if (c === EOF || c === TILDA_CHAR) {
  36074. break;
  36075. }
  36076. }
  36077. buffer = this.ensureBuffer(bufferLength + i - 1);
  36078. this.bufferLength += i - 1;
  36079. // partial ending;
  36080. if (i < 5) {
  36081. for (; i < 5; ++i) {
  36082. input[i] = 0x21 + 84;
  36083. }
  36084. this.eof = true;
  36085. }
  36086. var t = 0;
  36087. for (i = 0; i < 5; ++i) {
  36088. t = t * 85 + (input[i] - 0x21);
  36089. }
  36090. for (i = 3; i >= 0; --i) {
  36091. buffer[bufferLength + i] = t & 0xFF;
  36092. t >>= 8;
  36093. }
  36094. }
  36095. };
  36096. return Ascii85Stream;
  36097. })();
  36098. var AsciiHexStream = (function AsciiHexStreamClosure() {
  36099. function AsciiHexStream(str, maybeLength) {
  36100. this.str = str;
  36101. this.dict = str.dict;
  36102. this.firstDigit = -1;
  36103. // Most streams increase in size when decoded, but AsciiHex streams shrink
  36104. // by 50%.
  36105. if (maybeLength) {
  36106. maybeLength = 0.5 * maybeLength;
  36107. }
  36108. DecodeStream.call(this, maybeLength);
  36109. }
  36110. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  36111. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  36112. var UPSTREAM_BLOCK_SIZE = 8000;
  36113. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  36114. if (!bytes.length) {
  36115. this.eof = true;
  36116. return;
  36117. }
  36118. var maxDecodeLength = (bytes.length + 1) >> 1;
  36119. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  36120. var bufferLength = this.bufferLength;
  36121. var firstDigit = this.firstDigit;
  36122. for (var i = 0, ii = bytes.length; i < ii; i++) {
  36123. var ch = bytes[i], digit;
  36124. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  36125. digit = ch & 0x0F;
  36126. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  36127. // 'A'-'Z', 'a'-'z'
  36128. digit = (ch & 0x0F) + 9;
  36129. } else if (ch === 0x3E) { // '>'
  36130. this.eof = true;
  36131. break;
  36132. } else { // probably whitespace
  36133. continue; // ignoring
  36134. }
  36135. if (firstDigit < 0) {
  36136. firstDigit = digit;
  36137. } else {
  36138. buffer[bufferLength++] = (firstDigit << 4) | digit;
  36139. firstDigit = -1;
  36140. }
  36141. }
  36142. if (firstDigit >= 0 && this.eof) {
  36143. // incomplete byte
  36144. buffer[bufferLength++] = (firstDigit << 4);
  36145. firstDigit = -1;
  36146. }
  36147. this.firstDigit = firstDigit;
  36148. this.bufferLength = bufferLength;
  36149. };
  36150. return AsciiHexStream;
  36151. })();
  36152. var RunLengthStream = (function RunLengthStreamClosure() {
  36153. function RunLengthStream(str, maybeLength) {
  36154. this.str = str;
  36155. this.dict = str.dict;
  36156. DecodeStream.call(this, maybeLength);
  36157. }
  36158. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  36159. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  36160. // The repeatHeader has following format. The first byte defines type of run
  36161. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  36162. // (in addition to the second byte from the header), n = 129 through 255 -
  36163. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  36164. var repeatHeader = this.str.getBytes(2);
  36165. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  36166. this.eof = true;
  36167. return;
  36168. }
  36169. var buffer;
  36170. var bufferLength = this.bufferLength;
  36171. var n = repeatHeader[0];
  36172. if (n < 128) {
  36173. // copy n bytes
  36174. buffer = this.ensureBuffer(bufferLength + n + 1);
  36175. buffer[bufferLength++] = repeatHeader[1];
  36176. if (n > 0) {
  36177. var source = this.str.getBytes(n);
  36178. buffer.set(source, bufferLength);
  36179. bufferLength += n;
  36180. }
  36181. } else {
  36182. n = 257 - n;
  36183. var b = repeatHeader[1];
  36184. buffer = this.ensureBuffer(bufferLength + n + 1);
  36185. for (var i = 0; i < n; i++) {
  36186. buffer[bufferLength++] = b;
  36187. }
  36188. }
  36189. this.bufferLength = bufferLength;
  36190. };
  36191. return RunLengthStream;
  36192. })();
  36193. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  36194. var ccittEOL = -2;
  36195. var twoDimPass = 0;
  36196. var twoDimHoriz = 1;
  36197. var twoDimVert0 = 2;
  36198. var twoDimVertR1 = 3;
  36199. var twoDimVertL1 = 4;
  36200. var twoDimVertR2 = 5;
  36201. var twoDimVertL2 = 6;
  36202. var twoDimVertR3 = 7;
  36203. var twoDimVertL3 = 8;
  36204. var twoDimTable = [
  36205. [-1, -1], [-1, -1], // 000000x
  36206. [7, twoDimVertL3], // 0000010
  36207. [7, twoDimVertR3], // 0000011
  36208. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  36209. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  36210. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  36211. [4, twoDimPass], [4, twoDimPass],
  36212. [4, twoDimPass], [4, twoDimPass],
  36213. [4, twoDimPass], [4, twoDimPass],
  36214. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  36215. [3, twoDimHoriz], [3, twoDimHoriz],
  36216. [3, twoDimHoriz], [3, twoDimHoriz],
  36217. [3, twoDimHoriz], [3, twoDimHoriz],
  36218. [3, twoDimHoriz], [3, twoDimHoriz],
  36219. [3, twoDimHoriz], [3, twoDimHoriz],
  36220. [3, twoDimHoriz], [3, twoDimHoriz],
  36221. [3, twoDimHoriz], [3, twoDimHoriz],
  36222. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  36223. [3, twoDimVertL1], [3, twoDimVertL1],
  36224. [3, twoDimVertL1], [3, twoDimVertL1],
  36225. [3, twoDimVertL1], [3, twoDimVertL1],
  36226. [3, twoDimVertL1], [3, twoDimVertL1],
  36227. [3, twoDimVertL1], [3, twoDimVertL1],
  36228. [3, twoDimVertL1], [3, twoDimVertL1],
  36229. [3, twoDimVertL1], [3, twoDimVertL1],
  36230. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  36231. [3, twoDimVertR1], [3, twoDimVertR1],
  36232. [3, twoDimVertR1], [3, twoDimVertR1],
  36233. [3, twoDimVertR1], [3, twoDimVertR1],
  36234. [3, twoDimVertR1], [3, twoDimVertR1],
  36235. [3, twoDimVertR1], [3, twoDimVertR1],
  36236. [3, twoDimVertR1], [3, twoDimVertR1],
  36237. [3, twoDimVertR1], [3, twoDimVertR1],
  36238. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  36239. [1, twoDimVert0], [1, twoDimVert0],
  36240. [1, twoDimVert0], [1, twoDimVert0],
  36241. [1, twoDimVert0], [1, twoDimVert0],
  36242. [1, twoDimVert0], [1, twoDimVert0],
  36243. [1, twoDimVert0], [1, twoDimVert0],
  36244. [1, twoDimVert0], [1, twoDimVert0],
  36245. [1, twoDimVert0], [1, twoDimVert0],
  36246. [1, twoDimVert0], [1, twoDimVert0],
  36247. [1, twoDimVert0], [1, twoDimVert0],
  36248. [1, twoDimVert0], [1, twoDimVert0],
  36249. [1, twoDimVert0], [1, twoDimVert0],
  36250. [1, twoDimVert0], [1, twoDimVert0],
  36251. [1, twoDimVert0], [1, twoDimVert0],
  36252. [1, twoDimVert0], [1, twoDimVert0],
  36253. [1, twoDimVert0], [1, twoDimVert0],
  36254. [1, twoDimVert0], [1, twoDimVert0],
  36255. [1, twoDimVert0], [1, twoDimVert0],
  36256. [1, twoDimVert0], [1, twoDimVert0],
  36257. [1, twoDimVert0], [1, twoDimVert0],
  36258. [1, twoDimVert0], [1, twoDimVert0],
  36259. [1, twoDimVert0], [1, twoDimVert0],
  36260. [1, twoDimVert0], [1, twoDimVert0],
  36261. [1, twoDimVert0], [1, twoDimVert0],
  36262. [1, twoDimVert0], [1, twoDimVert0],
  36263. [1, twoDimVert0], [1, twoDimVert0],
  36264. [1, twoDimVert0], [1, twoDimVert0],
  36265. [1, twoDimVert0], [1, twoDimVert0],
  36266. [1, twoDimVert0], [1, twoDimVert0],
  36267. [1, twoDimVert0], [1, twoDimVert0],
  36268. [1, twoDimVert0], [1, twoDimVert0],
  36269. [1, twoDimVert0], [1, twoDimVert0]
  36270. ];
  36271. var whiteTable1 = [
  36272. [-1, -1], // 00000
  36273. [12, ccittEOL], // 00001
  36274. [-1, -1], [-1, -1], // 0001x
  36275. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  36276. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  36277. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  36278. [11, 1792], [11, 1792], // 1000x
  36279. [12, 1984], // 10010
  36280. [12, 2048], // 10011
  36281. [12, 2112], // 10100
  36282. [12, 2176], // 10101
  36283. [12, 2240], // 10110
  36284. [12, 2304], // 10111
  36285. [11, 1856], [11, 1856], // 1100x
  36286. [11, 1920], [11, 1920], // 1101x
  36287. [12, 2368], // 11100
  36288. [12, 2432], // 11101
  36289. [12, 2496], // 11110
  36290. [12, 2560] // 11111
  36291. ];
  36292. var whiteTable2 = [
  36293. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  36294. [8, 29], [8, 29], // 00000010x
  36295. [8, 30], [8, 30], // 00000011x
  36296. [8, 45], [8, 45], // 00000100x
  36297. [8, 46], [8, 46], // 00000101x
  36298. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  36299. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  36300. [8, 47], [8, 47], // 00001010x
  36301. [8, 48], [8, 48], // 00001011x
  36302. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  36303. [6, 13], [6, 13], [6, 13], [6, 13],
  36304. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  36305. [8, 33], [8, 33], // 00010010x
  36306. [8, 34], [8, 34], // 00010011x
  36307. [8, 35], [8, 35], // 00010100x
  36308. [8, 36], [8, 36], // 00010101x
  36309. [8, 37], [8, 37], // 00010110x
  36310. [8, 38], [8, 38], // 00010111x
  36311. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  36312. [8, 31], [8, 31], // 00011010x
  36313. [8, 32], [8, 32], // 00011011x
  36314. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  36315. [6, 1], [6, 1], [6, 1], [6, 1],
  36316. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  36317. [6, 12], [6, 12], [6, 12], [6, 12],
  36318. [8, 53], [8, 53], // 00100100x
  36319. [8, 54], [8, 54], // 00100101x
  36320. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  36321. [8, 39], [8, 39], // 00101000x
  36322. [8, 40], [8, 40], // 00101001x
  36323. [8, 41], [8, 41], // 00101010x
  36324. [8, 42], [8, 42], // 00101011x
  36325. [8, 43], [8, 43], // 00101100x
  36326. [8, 44], [8, 44], // 00101101x
  36327. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  36328. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  36329. [8, 61], [8, 61], // 00110010x
  36330. [8, 62], [8, 62], // 00110011x
  36331. [8, 63], [8, 63], // 00110100x
  36332. [8, 0], [8, 0], // 00110101x
  36333. [8, 320], [8, 320], // 00110110x
  36334. [8, 384], [8, 384], // 00110111x
  36335. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  36336. [5, 10], [5, 10], [5, 10], [5, 10],
  36337. [5, 10], [5, 10], [5, 10], [5, 10],
  36338. [5, 10], [5, 10], [5, 10], [5, 10],
  36339. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  36340. [5, 11], [5, 11], [5, 11], [5, 11],
  36341. [5, 11], [5, 11], [5, 11], [5, 11],
  36342. [5, 11], [5, 11], [5, 11], [5, 11],
  36343. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  36344. [8, 59], [8, 59], // 01001010x
  36345. [8, 60], [8, 60], // 01001011x
  36346. [9, 1472], // 010011000
  36347. [9, 1536], // 010011001
  36348. [9, 1600], // 010011010
  36349. [9, 1728], // 010011011
  36350. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  36351. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  36352. [8, 49], [8, 49], // 01010010x
  36353. [8, 50], [8, 50], // 01010011x
  36354. [8, 51], [8, 51], // 01010100x
  36355. [8, 52], [8, 52], // 01010101x
  36356. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  36357. [8, 55], [8, 55], // 01011000x
  36358. [8, 56], [8, 56], // 01011001x
  36359. [8, 57], [8, 57], // 01011010x
  36360. [8, 58], [8, 58], // 01011011x
  36361. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  36362. [6, 192], [6, 192], [6, 192], [6, 192],
  36363. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  36364. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  36365. [8, 448], [8, 448], // 01100100x
  36366. [8, 512], [8, 512], // 01100101x
  36367. [9, 704], // 011001100
  36368. [9, 768], // 011001101
  36369. [8, 640], [8, 640], // 01100111x
  36370. [8, 576], [8, 576], // 01101000x
  36371. [9, 832], // 011010010
  36372. [9, 896], // 011010011
  36373. [9, 960], // 011010100
  36374. [9, 1024], // 011010101
  36375. [9, 1088], // 011010110
  36376. [9, 1152], // 011010111
  36377. [9, 1216], // 011011000
  36378. [9, 1280], // 011011001
  36379. [9, 1344], // 011011010
  36380. [9, 1408], // 011011011
  36381. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  36382. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  36383. [4, 2], [4, 2], [4, 2], [4, 2],
  36384. [4, 2], [4, 2], [4, 2], [4, 2],
  36385. [4, 2], [4, 2], [4, 2], [4, 2],
  36386. [4, 2], [4, 2], [4, 2], [4, 2],
  36387. [4, 2], [4, 2], [4, 2], [4, 2],
  36388. [4, 2], [4, 2], [4, 2], [4, 2],
  36389. [4, 2], [4, 2], [4, 2], [4, 2],
  36390. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  36391. [4, 3], [4, 3], [4, 3], [4, 3],
  36392. [4, 3], [4, 3], [4, 3], [4, 3],
  36393. [4, 3], [4, 3], [4, 3], [4, 3],
  36394. [4, 3], [4, 3], [4, 3], [4, 3],
  36395. [4, 3], [4, 3], [4, 3], [4, 3],
  36396. [4, 3], [4, 3], [4, 3], [4, 3],
  36397. [4, 3], [4, 3], [4, 3], [4, 3],
  36398. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  36399. [5, 128], [5, 128], [5, 128], [5, 128],
  36400. [5, 128], [5, 128], [5, 128], [5, 128],
  36401. [5, 128], [5, 128], [5, 128], [5, 128],
  36402. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  36403. [5, 8], [5, 8], [5, 8], [5, 8],
  36404. [5, 8], [5, 8], [5, 8], [5, 8],
  36405. [5, 8], [5, 8], [5, 8], [5, 8],
  36406. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  36407. [5, 9], [5, 9], [5, 9], [5, 9],
  36408. [5, 9], [5, 9], [5, 9], [5, 9],
  36409. [5, 9], [5, 9], [5, 9], [5, 9],
  36410. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  36411. [6, 16], [6, 16], [6, 16], [6, 16],
  36412. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  36413. [6, 17], [6, 17], [6, 17], [6, 17],
  36414. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  36415. [4, 4], [4, 4], [4, 4], [4, 4],
  36416. [4, 4], [4, 4], [4, 4], [4, 4],
  36417. [4, 4], [4, 4], [4, 4], [4, 4],
  36418. [4, 4], [4, 4], [4, 4], [4, 4],
  36419. [4, 4], [4, 4], [4, 4], [4, 4],
  36420. [4, 4], [4, 4], [4, 4], [4, 4],
  36421. [4, 4], [4, 4], [4, 4], [4, 4],
  36422. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  36423. [4, 5], [4, 5], [4, 5], [4, 5],
  36424. [4, 5], [4, 5], [4, 5], [4, 5],
  36425. [4, 5], [4, 5], [4, 5], [4, 5],
  36426. [4, 5], [4, 5], [4, 5], [4, 5],
  36427. [4, 5], [4, 5], [4, 5], [4, 5],
  36428. [4, 5], [4, 5], [4, 5], [4, 5],
  36429. [4, 5], [4, 5], [4, 5], [4, 5],
  36430. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  36431. [6, 14], [6, 14], [6, 14], [6, 14],
  36432. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  36433. [6, 15], [6, 15], [6, 15], [6, 15],
  36434. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  36435. [5, 64], [5, 64], [5, 64], [5, 64],
  36436. [5, 64], [5, 64], [5, 64], [5, 64],
  36437. [5, 64], [5, 64], [5, 64], [5, 64],
  36438. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  36439. [4, 6], [4, 6], [4, 6], [4, 6],
  36440. [4, 6], [4, 6], [4, 6], [4, 6],
  36441. [4, 6], [4, 6], [4, 6], [4, 6],
  36442. [4, 6], [4, 6], [4, 6], [4, 6],
  36443. [4, 6], [4, 6], [4, 6], [4, 6],
  36444. [4, 6], [4, 6], [4, 6], [4, 6],
  36445. [4, 6], [4, 6], [4, 6], [4, 6],
  36446. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  36447. [4, 7], [4, 7], [4, 7], [4, 7],
  36448. [4, 7], [4, 7], [4, 7], [4, 7],
  36449. [4, 7], [4, 7], [4, 7], [4, 7],
  36450. [4, 7], [4, 7], [4, 7], [4, 7],
  36451. [4, 7], [4, 7], [4, 7], [4, 7],
  36452. [4, 7], [4, 7], [4, 7], [4, 7],
  36453. [4, 7], [4, 7], [4, 7], [4, 7]
  36454. ];
  36455. var blackTable1 = [
  36456. [-1, -1], [-1, -1], // 000000000000x
  36457. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  36458. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  36459. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  36460. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  36461. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  36462. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  36463. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  36464. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  36465. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  36466. [12, 1984], [12, 1984], // 000000010010x
  36467. [12, 2048], [12, 2048], // 000000010011x
  36468. [12, 2112], [12, 2112], // 000000010100x
  36469. [12, 2176], [12, 2176], // 000000010101x
  36470. [12, 2240], [12, 2240], // 000000010110x
  36471. [12, 2304], [12, 2304], // 000000010111x
  36472. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  36473. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  36474. [12, 2368], [12, 2368], // 000000011100x
  36475. [12, 2432], [12, 2432], // 000000011101x
  36476. [12, 2496], [12, 2496], // 000000011110x
  36477. [12, 2560], [12, 2560], // 000000011111x
  36478. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  36479. [10, 18], [10, 18], [10, 18], [10, 18],
  36480. [12, 52], [12, 52], // 000000100100x
  36481. [13, 640], // 0000001001010
  36482. [13, 704], // 0000001001011
  36483. [13, 768], // 0000001001100
  36484. [13, 832], // 0000001001101
  36485. [12, 55], [12, 55], // 000000100111x
  36486. [12, 56], [12, 56], // 000000101000x
  36487. [13, 1280], // 0000001010010
  36488. [13, 1344], // 0000001010011
  36489. [13, 1408], // 0000001010100
  36490. [13, 1472], // 0000001010101
  36491. [12, 59], [12, 59], // 000000101011x
  36492. [12, 60], [12, 60], // 000000101100x
  36493. [13, 1536], // 0000001011010
  36494. [13, 1600], // 0000001011011
  36495. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  36496. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  36497. [13, 1664], // 0000001100100
  36498. [13, 1728], // 0000001100101
  36499. [12, 320], [12, 320], // 000000110011x
  36500. [12, 384], [12, 384], // 000000110100x
  36501. [12, 448], [12, 448], // 000000110101x
  36502. [13, 512], // 0000001101100
  36503. [13, 576], // 0000001101101
  36504. [12, 53], [12, 53], // 000000110111x
  36505. [12, 54], [12, 54], // 000000111000x
  36506. [13, 896], // 0000001110010
  36507. [13, 960], // 0000001110011
  36508. [13, 1024], // 0000001110100
  36509. [13, 1088], // 0000001110101
  36510. [13, 1152], // 0000001110110
  36511. [13, 1216], // 0000001110111
  36512. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  36513. [10, 64], [10, 64], [10, 64], [10, 64]
  36514. ];
  36515. var blackTable2 = [
  36516. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  36517. [8, 13], [8, 13], [8, 13], [8, 13],
  36518. [8, 13], [8, 13], [8, 13], [8, 13],
  36519. [8, 13], [8, 13], [8, 13], [8, 13],
  36520. [11, 23], [11, 23], // 00000101000x
  36521. [12, 50], // 000001010010
  36522. [12, 51], // 000001010011
  36523. [12, 44], // 000001010100
  36524. [12, 45], // 000001010101
  36525. [12, 46], // 000001010110
  36526. [12, 47], // 000001010111
  36527. [12, 57], // 000001011000
  36528. [12, 58], // 000001011001
  36529. [12, 61], // 000001011010
  36530. [12, 256], // 000001011011
  36531. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  36532. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  36533. [12, 48], // 000001100100
  36534. [12, 49], // 000001100101
  36535. [12, 62], // 000001100110
  36536. [12, 63], // 000001100111
  36537. [12, 30], // 000001101000
  36538. [12, 31], // 000001101001
  36539. [12, 32], // 000001101010
  36540. [12, 33], // 000001101011
  36541. [12, 40], // 000001101100
  36542. [12, 41], // 000001101101
  36543. [11, 22], [11, 22], // 00000110111x
  36544. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  36545. [8, 14], [8, 14], [8, 14], [8, 14],
  36546. [8, 14], [8, 14], [8, 14], [8, 14],
  36547. [8, 14], [8, 14], [8, 14], [8, 14],
  36548. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  36549. [7, 10], [7, 10], [7, 10], [7, 10],
  36550. [7, 10], [7, 10], [7, 10], [7, 10],
  36551. [7, 10], [7, 10], [7, 10], [7, 10],
  36552. [7, 10], [7, 10], [7, 10], [7, 10],
  36553. [7, 10], [7, 10], [7, 10], [7, 10],
  36554. [7, 10], [7, 10], [7, 10], [7, 10],
  36555. [7, 10], [7, 10], [7, 10], [7, 10],
  36556. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  36557. [7, 11], [7, 11], [7, 11], [7, 11],
  36558. [7, 11], [7, 11], [7, 11], [7, 11],
  36559. [7, 11], [7, 11], [7, 11], [7, 11],
  36560. [7, 11], [7, 11], [7, 11], [7, 11],
  36561. [7, 11], [7, 11], [7, 11], [7, 11],
  36562. [7, 11], [7, 11], [7, 11], [7, 11],
  36563. [7, 11], [7, 11], [7, 11], [7, 11],
  36564. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  36565. [9, 15], [9, 15], [9, 15], [9, 15],
  36566. [12, 128], // 000011001000
  36567. [12, 192], // 000011001001
  36568. [12, 26], // 000011001010
  36569. [12, 27], // 000011001011
  36570. [12, 28], // 000011001100
  36571. [12, 29], // 000011001101
  36572. [11, 19], [11, 19], // 00001100111x
  36573. [11, 20], [11, 20], // 00001101000x
  36574. [12, 34], // 000011010010
  36575. [12, 35], // 000011010011
  36576. [12, 36], // 000011010100
  36577. [12, 37], // 000011010101
  36578. [12, 38], // 000011010110
  36579. [12, 39], // 000011010111
  36580. [11, 21], [11, 21], // 00001101100x
  36581. [12, 42], // 000011011010
  36582. [12, 43], // 000011011011
  36583. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  36584. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  36585. [7, 12], [7, 12], [7, 12], [7, 12],
  36586. [7, 12], [7, 12], [7, 12], [7, 12],
  36587. [7, 12], [7, 12], [7, 12], [7, 12],
  36588. [7, 12], [7, 12], [7, 12], [7, 12],
  36589. [7, 12], [7, 12], [7, 12], [7, 12],
  36590. [7, 12], [7, 12], [7, 12], [7, 12],
  36591. [7, 12], [7, 12], [7, 12], [7, 12]
  36592. ];
  36593. var blackTable3 = [
  36594. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  36595. [6, 9], // 000100
  36596. [6, 8], // 000101
  36597. [5, 7], [5, 7], // 00011x
  36598. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  36599. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  36600. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  36601. [3, 1], [3, 1], [3, 1], [3, 1],
  36602. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  36603. [3, 4], [3, 4], [3, 4], [3, 4],
  36604. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  36605. [2, 3], [2, 3], [2, 3], [2, 3],
  36606. [2, 3], [2, 3], [2, 3], [2, 3],
  36607. [2, 3], [2, 3], [2, 3], [2, 3],
  36608. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  36609. [2, 2], [2, 2], [2, 2], [2, 2],
  36610. [2, 2], [2, 2], [2, 2], [2, 2],
  36611. [2, 2], [2, 2], [2, 2], [2, 2]
  36612. ];
  36613. function CCITTFaxStream(str, maybeLength, params) {
  36614. this.str = str;
  36615. this.dict = str.dict;
  36616. params = params || Dict.empty;
  36617. this.encoding = params.get('K') || 0;
  36618. this.eoline = params.get('EndOfLine') || false;
  36619. this.byteAlign = params.get('EncodedByteAlign') || false;
  36620. this.columns = params.get('Columns') || 1728;
  36621. this.rows = params.get('Rows') || 0;
  36622. var eoblock = params.get('EndOfBlock');
  36623. if (eoblock === null || eoblock === undefined) {
  36624. eoblock = true;
  36625. }
  36626. this.eoblock = eoblock;
  36627. this.black = params.get('BlackIs1') || false;
  36628. this.codingLine = new Uint32Array(this.columns + 1);
  36629. this.refLine = new Uint32Array(this.columns + 2);
  36630. this.codingLine[0] = this.columns;
  36631. this.codingPos = 0;
  36632. this.row = 0;
  36633. this.nextLine2D = this.encoding < 0;
  36634. this.inputBits = 0;
  36635. this.inputBuf = 0;
  36636. this.outputBits = 0;
  36637. var code1;
  36638. while ((code1 = this.lookBits(12)) === 0) {
  36639. this.eatBits(1);
  36640. }
  36641. if (code1 === 1) {
  36642. this.eatBits(12);
  36643. }
  36644. if (this.encoding > 0) {
  36645. this.nextLine2D = !this.lookBits(1);
  36646. this.eatBits(1);
  36647. }
  36648. DecodeStream.call(this, maybeLength);
  36649. }
  36650. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  36651. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  36652. while (!this.eof) {
  36653. var c = this.lookChar();
  36654. this.ensureBuffer(this.bufferLength + 1);
  36655. this.buffer[this.bufferLength++] = c;
  36656. }
  36657. };
  36658. CCITTFaxStream.prototype.addPixels =
  36659. function ccittFaxStreamAddPixels(a1, blackPixels) {
  36660. var codingLine = this.codingLine;
  36661. var codingPos = this.codingPos;
  36662. if (a1 > codingLine[codingPos]) {
  36663. if (a1 > this.columns) {
  36664. info('row is wrong length');
  36665. this.err = true;
  36666. a1 = this.columns;
  36667. }
  36668. if ((codingPos & 1) ^ blackPixels) {
  36669. ++codingPos;
  36670. }
  36671. codingLine[codingPos] = a1;
  36672. }
  36673. this.codingPos = codingPos;
  36674. };
  36675. CCITTFaxStream.prototype.addPixelsNeg =
  36676. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  36677. var codingLine = this.codingLine;
  36678. var codingPos = this.codingPos;
  36679. if (a1 > codingLine[codingPos]) {
  36680. if (a1 > this.columns) {
  36681. info('row is wrong length');
  36682. this.err = true;
  36683. a1 = this.columns;
  36684. }
  36685. if ((codingPos & 1) ^ blackPixels) {
  36686. ++codingPos;
  36687. }
  36688. codingLine[codingPos] = a1;
  36689. } else if (a1 < codingLine[codingPos]) {
  36690. if (a1 < 0) {
  36691. info('invalid code');
  36692. this.err = true;
  36693. a1 = 0;
  36694. }
  36695. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  36696. --codingPos;
  36697. }
  36698. codingLine[codingPos] = a1;
  36699. }
  36700. this.codingPos = codingPos;
  36701. };
  36702. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  36703. var refLine = this.refLine;
  36704. var codingLine = this.codingLine;
  36705. var columns = this.columns;
  36706. var refPos, blackPixels, bits, i;
  36707. if (this.outputBits === 0) {
  36708. if (this.eof) {
  36709. return null;
  36710. }
  36711. this.err = false;
  36712. var code1, code2, code3;
  36713. if (this.nextLine2D) {
  36714. for (i = 0; codingLine[i] < columns; ++i) {
  36715. refLine[i] = codingLine[i];
  36716. }
  36717. refLine[i++] = columns;
  36718. refLine[i] = columns;
  36719. codingLine[0] = 0;
  36720. this.codingPos = 0;
  36721. refPos = 0;
  36722. blackPixels = 0;
  36723. while (codingLine[this.codingPos] < columns) {
  36724. code1 = this.getTwoDimCode();
  36725. switch (code1) {
  36726. case twoDimPass:
  36727. this.addPixels(refLine[refPos + 1], blackPixels);
  36728. if (refLine[refPos + 1] < columns) {
  36729. refPos += 2;
  36730. }
  36731. break;
  36732. case twoDimHoriz:
  36733. code1 = code2 = 0;
  36734. if (blackPixels) {
  36735. do {
  36736. code1 += (code3 = this.getBlackCode());
  36737. } while (code3 >= 64);
  36738. do {
  36739. code2 += (code3 = this.getWhiteCode());
  36740. } while (code3 >= 64);
  36741. } else {
  36742. do {
  36743. code1 += (code3 = this.getWhiteCode());
  36744. } while (code3 >= 64);
  36745. do {
  36746. code2 += (code3 = this.getBlackCode());
  36747. } while (code3 >= 64);
  36748. }
  36749. this.addPixels(codingLine[this.codingPos] +
  36750. code1, blackPixels);
  36751. if (codingLine[this.codingPos] < columns) {
  36752. this.addPixels(codingLine[this.codingPos] + code2,
  36753. blackPixels ^ 1);
  36754. }
  36755. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36756. refLine[refPos] < columns) {
  36757. refPos += 2;
  36758. }
  36759. break;
  36760. case twoDimVertR3:
  36761. this.addPixels(refLine[refPos] + 3, blackPixels);
  36762. blackPixels ^= 1;
  36763. if (codingLine[this.codingPos] < columns) {
  36764. ++refPos;
  36765. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36766. refLine[refPos] < columns) {
  36767. refPos += 2;
  36768. }
  36769. }
  36770. break;
  36771. case twoDimVertR2:
  36772. this.addPixels(refLine[refPos] + 2, blackPixels);
  36773. blackPixels ^= 1;
  36774. if (codingLine[this.codingPos] < columns) {
  36775. ++refPos;
  36776. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36777. refLine[refPos] < columns) {
  36778. refPos += 2;
  36779. }
  36780. }
  36781. break;
  36782. case twoDimVertR1:
  36783. this.addPixels(refLine[refPos] + 1, blackPixels);
  36784. blackPixels ^= 1;
  36785. if (codingLine[this.codingPos] < columns) {
  36786. ++refPos;
  36787. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36788. refLine[refPos] < columns) {
  36789. refPos += 2;
  36790. }
  36791. }
  36792. break;
  36793. case twoDimVert0:
  36794. this.addPixels(refLine[refPos], blackPixels);
  36795. blackPixels ^= 1;
  36796. if (codingLine[this.codingPos] < columns) {
  36797. ++refPos;
  36798. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36799. refLine[refPos] < columns) {
  36800. refPos += 2;
  36801. }
  36802. }
  36803. break;
  36804. case twoDimVertL3:
  36805. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  36806. blackPixels ^= 1;
  36807. if (codingLine[this.codingPos] < columns) {
  36808. if (refPos > 0) {
  36809. --refPos;
  36810. } else {
  36811. ++refPos;
  36812. }
  36813. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36814. refLine[refPos] < columns) {
  36815. refPos += 2;
  36816. }
  36817. }
  36818. break;
  36819. case twoDimVertL2:
  36820. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  36821. blackPixels ^= 1;
  36822. if (codingLine[this.codingPos] < columns) {
  36823. if (refPos > 0) {
  36824. --refPos;
  36825. } else {
  36826. ++refPos;
  36827. }
  36828. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36829. refLine[refPos] < columns) {
  36830. refPos += 2;
  36831. }
  36832. }
  36833. break;
  36834. case twoDimVertL1:
  36835. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  36836. blackPixels ^= 1;
  36837. if (codingLine[this.codingPos] < columns) {
  36838. if (refPos > 0) {
  36839. --refPos;
  36840. } else {
  36841. ++refPos;
  36842. }
  36843. while (refLine[refPos] <= codingLine[this.codingPos] &&
  36844. refLine[refPos] < columns) {
  36845. refPos += 2;
  36846. }
  36847. }
  36848. break;
  36849. case EOF:
  36850. this.addPixels(columns, 0);
  36851. this.eof = true;
  36852. break;
  36853. default:
  36854. info('bad 2d code');
  36855. this.addPixels(columns, 0);
  36856. this.err = true;
  36857. }
  36858. }
  36859. } else {
  36860. codingLine[0] = 0;
  36861. this.codingPos = 0;
  36862. blackPixels = 0;
  36863. while (codingLine[this.codingPos] < columns) {
  36864. code1 = 0;
  36865. if (blackPixels) {
  36866. do {
  36867. code1 += (code3 = this.getBlackCode());
  36868. } while (code3 >= 64);
  36869. } else {
  36870. do {
  36871. code1 += (code3 = this.getWhiteCode());
  36872. } while (code3 >= 64);
  36873. }
  36874. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  36875. blackPixels ^= 1;
  36876. }
  36877. }
  36878. var gotEOL = false;
  36879. if (this.byteAlign) {
  36880. this.inputBits &= ~7;
  36881. }
  36882. if (!this.eoblock && this.row === this.rows - 1) {
  36883. this.eof = true;
  36884. } else {
  36885. code1 = this.lookBits(12);
  36886. if (this.eoline) {
  36887. while (code1 !== EOF && code1 !== 1) {
  36888. this.eatBits(1);
  36889. code1 = this.lookBits(12);
  36890. }
  36891. } else {
  36892. while (code1 === 0) {
  36893. this.eatBits(1);
  36894. code1 = this.lookBits(12);
  36895. }
  36896. }
  36897. if (code1 === 1) {
  36898. this.eatBits(12);
  36899. gotEOL = true;
  36900. } else if (code1 === EOF) {
  36901. this.eof = true;
  36902. }
  36903. }
  36904. if (!this.eof && this.encoding > 0) {
  36905. this.nextLine2D = !this.lookBits(1);
  36906. this.eatBits(1);
  36907. }
  36908. if (this.eoblock && gotEOL && this.byteAlign) {
  36909. code1 = this.lookBits(12);
  36910. if (code1 === 1) {
  36911. this.eatBits(12);
  36912. if (this.encoding > 0) {
  36913. this.lookBits(1);
  36914. this.eatBits(1);
  36915. }
  36916. if (this.encoding >= 0) {
  36917. for (i = 0; i < 4; ++i) {
  36918. code1 = this.lookBits(12);
  36919. if (code1 !== 1) {
  36920. info('bad rtc code: ' + code1);
  36921. }
  36922. this.eatBits(12);
  36923. if (this.encoding > 0) {
  36924. this.lookBits(1);
  36925. this.eatBits(1);
  36926. }
  36927. }
  36928. }
  36929. this.eof = true;
  36930. }
  36931. } else if (this.err && this.eoline) {
  36932. while (true) {
  36933. code1 = this.lookBits(13);
  36934. if (code1 === EOF) {
  36935. this.eof = true;
  36936. return null;
  36937. }
  36938. if ((code1 >> 1) === 1) {
  36939. break;
  36940. }
  36941. this.eatBits(1);
  36942. }
  36943. this.eatBits(12);
  36944. if (this.encoding > 0) {
  36945. this.eatBits(1);
  36946. this.nextLine2D = !(code1 & 1);
  36947. }
  36948. }
  36949. if (codingLine[0] > 0) {
  36950. this.outputBits = codingLine[this.codingPos = 0];
  36951. } else {
  36952. this.outputBits = codingLine[this.codingPos = 1];
  36953. }
  36954. this.row++;
  36955. }
  36956. var c;
  36957. if (this.outputBits >= 8) {
  36958. c = (this.codingPos & 1) ? 0 : 0xFF;
  36959. this.outputBits -= 8;
  36960. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  36961. this.codingPos++;
  36962. this.outputBits = (codingLine[this.codingPos] -
  36963. codingLine[this.codingPos - 1]);
  36964. }
  36965. } else {
  36966. bits = 8;
  36967. c = 0;
  36968. do {
  36969. if (this.outputBits > bits) {
  36970. c <<= bits;
  36971. if (!(this.codingPos & 1)) {
  36972. c |= 0xFF >> (8 - bits);
  36973. }
  36974. this.outputBits -= bits;
  36975. bits = 0;
  36976. } else {
  36977. c <<= this.outputBits;
  36978. if (!(this.codingPos & 1)) {
  36979. c |= 0xFF >> (8 - this.outputBits);
  36980. }
  36981. bits -= this.outputBits;
  36982. this.outputBits = 0;
  36983. if (codingLine[this.codingPos] < columns) {
  36984. this.codingPos++;
  36985. this.outputBits = (codingLine[this.codingPos] -
  36986. codingLine[this.codingPos - 1]);
  36987. } else if (bits > 0) {
  36988. c <<= bits;
  36989. bits = 0;
  36990. }
  36991. }
  36992. } while (bits);
  36993. }
  36994. if (this.black) {
  36995. c ^= 0xFF;
  36996. }
  36997. return c;
  36998. };
  36999. // This functions returns the code found from the table.
  37000. // The start and end parameters set the boundaries for searching the table.
  37001. // The limit parameter is optional. Function returns an array with three
  37002. // values. The first array element indicates whether a valid code is being
  37003. // returned. The second array element is the actual code. The third array
  37004. // element indicates whether EOF was reached.
  37005. CCITTFaxStream.prototype.findTableCode =
  37006. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  37007. var limitValue = limit || 0;
  37008. for (var i = start; i <= end; ++i) {
  37009. var code = this.lookBits(i);
  37010. if (code === EOF) {
  37011. return [true, 1, false];
  37012. }
  37013. if (i < end) {
  37014. code <<= end - i;
  37015. }
  37016. if (!limitValue || code >= limitValue) {
  37017. var p = table[code - limitValue];
  37018. if (p[0] === i) {
  37019. this.eatBits(i);
  37020. return [true, p[1], true];
  37021. }
  37022. }
  37023. }
  37024. return [false, 0, false];
  37025. };
  37026. CCITTFaxStream.prototype.getTwoDimCode =
  37027. function ccittFaxStreamGetTwoDimCode() {
  37028. var code = 0;
  37029. var p;
  37030. if (this.eoblock) {
  37031. code = this.lookBits(7);
  37032. p = twoDimTable[code];
  37033. if (p && p[0] > 0) {
  37034. this.eatBits(p[0]);
  37035. return p[1];
  37036. }
  37037. } else {
  37038. var result = this.findTableCode(1, 7, twoDimTable);
  37039. if (result[0] && result[2]) {
  37040. return result[1];
  37041. }
  37042. }
  37043. info('Bad two dim code');
  37044. return EOF;
  37045. };
  37046. CCITTFaxStream.prototype.getWhiteCode =
  37047. function ccittFaxStreamGetWhiteCode() {
  37048. var code = 0;
  37049. var p;
  37050. if (this.eoblock) {
  37051. code = this.lookBits(12);
  37052. if (code === EOF) {
  37053. return 1;
  37054. }
  37055. if ((code >> 5) === 0) {
  37056. p = whiteTable1[code];
  37057. } else {
  37058. p = whiteTable2[code >> 3];
  37059. }
  37060. if (p[0] > 0) {
  37061. this.eatBits(p[0]);
  37062. return p[1];
  37063. }
  37064. } else {
  37065. var result = this.findTableCode(1, 9, whiteTable2);
  37066. if (result[0]) {
  37067. return result[1];
  37068. }
  37069. result = this.findTableCode(11, 12, whiteTable1);
  37070. if (result[0]) {
  37071. return result[1];
  37072. }
  37073. }
  37074. info('bad white code');
  37075. this.eatBits(1);
  37076. return 1;
  37077. };
  37078. CCITTFaxStream.prototype.getBlackCode =
  37079. function ccittFaxStreamGetBlackCode() {
  37080. var code, p;
  37081. if (this.eoblock) {
  37082. code = this.lookBits(13);
  37083. if (code === EOF) {
  37084. return 1;
  37085. }
  37086. if ((code >> 7) === 0) {
  37087. p = blackTable1[code];
  37088. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  37089. p = blackTable2[(code >> 1) - 64];
  37090. } else {
  37091. p = blackTable3[code >> 7];
  37092. }
  37093. if (p[0] > 0) {
  37094. this.eatBits(p[0]);
  37095. return p[1];
  37096. }
  37097. } else {
  37098. var result = this.findTableCode(2, 6, blackTable3);
  37099. if (result[0]) {
  37100. return result[1];
  37101. }
  37102. result = this.findTableCode(7, 12, blackTable2, 64);
  37103. if (result[0]) {
  37104. return result[1];
  37105. }
  37106. result = this.findTableCode(10, 13, blackTable1);
  37107. if (result[0]) {
  37108. return result[1];
  37109. }
  37110. }
  37111. info('bad black code');
  37112. this.eatBits(1);
  37113. return 1;
  37114. };
  37115. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  37116. var c;
  37117. while (this.inputBits < n) {
  37118. if ((c = this.str.getByte()) === -1) {
  37119. if (this.inputBits === 0) {
  37120. return EOF;
  37121. }
  37122. return ((this.inputBuf << (n - this.inputBits)) &
  37123. (0xFFFF >> (16 - n)));
  37124. }
  37125. this.inputBuf = (this.inputBuf << 8) + c;
  37126. this.inputBits += 8;
  37127. }
  37128. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  37129. };
  37130. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  37131. if ((this.inputBits -= n) < 0) {
  37132. this.inputBits = 0;
  37133. }
  37134. };
  37135. return CCITTFaxStream;
  37136. })();
  37137. var LZWStream = (function LZWStreamClosure() {
  37138. function LZWStream(str, maybeLength, earlyChange) {
  37139. this.str = str;
  37140. this.dict = str.dict;
  37141. this.cachedData = 0;
  37142. this.bitsCached = 0;
  37143. var maxLzwDictionarySize = 4096;
  37144. var lzwState = {
  37145. earlyChange: earlyChange,
  37146. codeLength: 9,
  37147. nextCode: 258,
  37148. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  37149. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  37150. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  37151. currentSequence: new Uint8Array(maxLzwDictionarySize),
  37152. currentSequenceLength: 0
  37153. };
  37154. for (var i = 0; i < 256; ++i) {
  37155. lzwState.dictionaryValues[i] = i;
  37156. lzwState.dictionaryLengths[i] = 1;
  37157. }
  37158. this.lzwState = lzwState;
  37159. DecodeStream.call(this, maybeLength);
  37160. }
  37161. LZWStream.prototype = Object.create(DecodeStream.prototype);
  37162. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  37163. var bitsCached = this.bitsCached;
  37164. var cachedData = this.cachedData;
  37165. while (bitsCached < n) {
  37166. var c = this.str.getByte();
  37167. if (c === -1) {
  37168. this.eof = true;
  37169. return null;
  37170. }
  37171. cachedData = (cachedData << 8) | c;
  37172. bitsCached += 8;
  37173. }
  37174. this.bitsCached = (bitsCached -= n);
  37175. this.cachedData = cachedData;
  37176. this.lastCode = null;
  37177. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  37178. };
  37179. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  37180. var blockSize = 512;
  37181. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  37182. var i, j, q;
  37183. var lzwState = this.lzwState;
  37184. if (!lzwState) {
  37185. return; // eof was found
  37186. }
  37187. var earlyChange = lzwState.earlyChange;
  37188. var nextCode = lzwState.nextCode;
  37189. var dictionaryValues = lzwState.dictionaryValues;
  37190. var dictionaryLengths = lzwState.dictionaryLengths;
  37191. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  37192. var codeLength = lzwState.codeLength;
  37193. var prevCode = lzwState.prevCode;
  37194. var currentSequence = lzwState.currentSequence;
  37195. var currentSequenceLength = lzwState.currentSequenceLength;
  37196. var decodedLength = 0;
  37197. var currentBufferLength = this.bufferLength;
  37198. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37199. for (i = 0; i < blockSize; i++) {
  37200. var code = this.readBits(codeLength);
  37201. var hasPrev = currentSequenceLength > 0;
  37202. if (code < 256) {
  37203. currentSequence[0] = code;
  37204. currentSequenceLength = 1;
  37205. } else if (code >= 258) {
  37206. if (code < nextCode) {
  37207. currentSequenceLength = dictionaryLengths[code];
  37208. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  37209. currentSequence[j] = dictionaryValues[q];
  37210. q = dictionaryPrevCodes[q];
  37211. }
  37212. } else {
  37213. currentSequence[currentSequenceLength++] = currentSequence[0];
  37214. }
  37215. } else if (code === 256) {
  37216. codeLength = 9;
  37217. nextCode = 258;
  37218. currentSequenceLength = 0;
  37219. continue;
  37220. } else {
  37221. this.eof = true;
  37222. delete this.lzwState;
  37223. break;
  37224. }
  37225. if (hasPrev) {
  37226. dictionaryPrevCodes[nextCode] = prevCode;
  37227. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  37228. dictionaryValues[nextCode] = currentSequence[0];
  37229. nextCode++;
  37230. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  37231. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  37232. 0.6931471805599453 + 1, 12) | 0;
  37233. }
  37234. prevCode = code;
  37235. decodedLength += currentSequenceLength;
  37236. if (estimatedDecodedSize < decodedLength) {
  37237. do {
  37238. estimatedDecodedSize += decodedSizeDelta;
  37239. } while (estimatedDecodedSize < decodedLength);
  37240. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  37241. }
  37242. for (j = 0; j < currentSequenceLength; j++) {
  37243. buffer[currentBufferLength++] = currentSequence[j];
  37244. }
  37245. }
  37246. lzwState.nextCode = nextCode;
  37247. lzwState.codeLength = codeLength;
  37248. lzwState.prevCode = prevCode;
  37249. lzwState.currentSequenceLength = currentSequenceLength;
  37250. this.bufferLength = currentBufferLength;
  37251. };
  37252. return LZWStream;
  37253. })();
  37254. var NullStream = (function NullStreamClosure() {
  37255. function NullStream() {
  37256. Stream.call(this, new Uint8Array(0));
  37257. }
  37258. NullStream.prototype = Stream.prototype;
  37259. return NullStream;
  37260. })();
  37261. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  37262. setup: function wphSetup(handler) {
  37263. var pdfManager;
  37264. function loadDocument(recoveryMode) {
  37265. var loadDocumentCapability = createPromiseCapability();
  37266. var parseSuccess = function parseSuccess() {
  37267. var numPagesPromise = pdfManager.ensureDoc('numPages');
  37268. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  37269. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  37270. Promise.all([numPagesPromise, fingerprintPromise,
  37271. encryptedPromise]).then(function onDocReady(results) {
  37272. var doc = {
  37273. numPages: results[0],
  37274. fingerprint: results[1],
  37275. encrypted: !!results[2],
  37276. };
  37277. loadDocumentCapability.resolve(doc);
  37278. },
  37279. parseFailure);
  37280. };
  37281. var parseFailure = function parseFailure(e) {
  37282. loadDocumentCapability.reject(e);
  37283. };
  37284. pdfManager.ensureDoc('checkHeader', []).then(function() {
  37285. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  37286. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  37287. parseSuccess, parseFailure);
  37288. }, parseFailure);
  37289. }, parseFailure);
  37290. return loadDocumentCapability.promise;
  37291. }
  37292. function getPdfManager(data) {
  37293. var pdfManagerCapability = createPromiseCapability();
  37294. var source = data.source;
  37295. var disableRange = data.disableRange;
  37296. if (source.data) {
  37297. try {
  37298. pdfManager = new LocalPdfManager(source.data, source.password);
  37299. pdfManagerCapability.resolve();
  37300. } catch (ex) {
  37301. pdfManagerCapability.reject(ex);
  37302. }
  37303. return pdfManagerCapability.promise;
  37304. } else if (source.chunkedViewerLoading) {
  37305. try {
  37306. pdfManager = new NetworkPdfManager(source, handler);
  37307. pdfManagerCapability.resolve();
  37308. } catch (ex) {
  37309. pdfManagerCapability.reject(ex);
  37310. }
  37311. return pdfManagerCapability.promise;
  37312. }
  37313. var networkManager = new NetworkManager(source.url, {
  37314. httpHeaders: source.httpHeaders,
  37315. withCredentials: source.withCredentials
  37316. });
  37317. var cachedChunks = [];
  37318. var fullRequestXhrId = networkManager.requestFull({
  37319. onHeadersReceived: function onHeadersReceived() {
  37320. if (disableRange) {
  37321. return;
  37322. }
  37323. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  37324. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  37325. return;
  37326. }
  37327. var contentEncoding =
  37328. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  37329. if (contentEncoding !== 'identity') {
  37330. return;
  37331. }
  37332. var length = fullRequestXhr.getResponseHeader('Content-Length');
  37333. length = parseInt(length, 10);
  37334. if (!isInt(length)) {
  37335. return;
  37336. }
  37337. source.length = length;
  37338. if (length <= 2 * RANGE_CHUNK_SIZE) {
  37339. // The file size is smaller than the size of two chunks, so it does
  37340. // not make any sense to abort the request and retry with a range
  37341. // request.
  37342. return;
  37343. }
  37344. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  37345. // We can continue fetching when progressive loading is enabled,
  37346. // and we don't need the autoFetch feature.
  37347. source.disableAutoFetch = true;
  37348. } else {
  37349. // NOTE: by cancelling the full request, and then issuing range
  37350. // requests, there will be an issue for sites where you can only
  37351. // request the pdf once. However, if this is the case, then the
  37352. // server should not be returning that it can support range
  37353. // requests.
  37354. networkManager.abortRequest(fullRequestXhrId);
  37355. }
  37356. try {
  37357. pdfManager = new NetworkPdfManager(source, handler);
  37358. pdfManagerCapability.resolve(pdfManager);
  37359. } catch (ex) {
  37360. pdfManagerCapability.reject(ex);
  37361. }
  37362. },
  37363. onProgressiveData: source.disableStream ? null :
  37364. function onProgressiveData(chunk) {
  37365. if (!pdfManager) {
  37366. cachedChunks.push(chunk);
  37367. return;
  37368. }
  37369. pdfManager.sendProgressiveData(chunk);
  37370. },
  37371. onDone: function onDone(args) {
  37372. if (pdfManager) {
  37373. return; // already processed
  37374. }
  37375. var pdfFile;
  37376. if (args === null) {
  37377. // TODO add some streaming manager, e.g. for unknown length files.
  37378. // The data was returned in the onProgressiveData, combining...
  37379. var pdfFileLength = 0, pos = 0;
  37380. cachedChunks.forEach(function (chunk) {
  37381. pdfFileLength += chunk.byteLength;
  37382. });
  37383. if (source.length && pdfFileLength !== source.length) {
  37384. warn('reported HTTP length is different from actual');
  37385. }
  37386. var pdfFileArray = new Uint8Array(pdfFileLength);
  37387. cachedChunks.forEach(function (chunk) {
  37388. pdfFileArray.set(new Uint8Array(chunk), pos);
  37389. pos += chunk.byteLength;
  37390. });
  37391. pdfFile = pdfFileArray.buffer;
  37392. } else {
  37393. pdfFile = args.chunk;
  37394. }
  37395. // the data is array, instantiating directly from it
  37396. try {
  37397. pdfManager = new LocalPdfManager(pdfFile, source.password);
  37398. pdfManagerCapability.resolve();
  37399. } catch (ex) {
  37400. pdfManagerCapability.reject(ex);
  37401. }
  37402. },
  37403. onError: function onError(status) {
  37404. var exception;
  37405. if (status === 404) {
  37406. exception = new MissingPDFException('Missing PDF "' +
  37407. source.url + '".');
  37408. handler.send('MissingPDF', exception);
  37409. } else {
  37410. exception = new UnexpectedResponseException(
  37411. 'Unexpected server response (' + status +
  37412. ') while retrieving PDF "' + source.url + '".', status);
  37413. handler.send('UnexpectedResponse', exception);
  37414. }
  37415. },
  37416. onProgress: function onProgress(evt) {
  37417. handler.send('DocProgress', {
  37418. loaded: evt.loaded,
  37419. total: evt.lengthComputable ? evt.total : source.length
  37420. });
  37421. }
  37422. });
  37423. return pdfManagerCapability.promise;
  37424. }
  37425. handler.on('test', function wphSetupTest(data) {
  37426. // check if Uint8Array can be sent to worker
  37427. if (!(data instanceof Uint8Array)) {
  37428. handler.send('test', false);
  37429. return;
  37430. }
  37431. // making sure postMessage transfers are working
  37432. var supportTransfers = data[0] === 255;
  37433. handler.postMessageTransfers = supportTransfers;
  37434. // check if the response property is supported by xhr
  37435. var xhr = new XMLHttpRequest();
  37436. var responseExists = 'response' in xhr;
  37437. // check if the property is actually implemented
  37438. try {
  37439. var dummy = xhr.responseType;
  37440. } catch (e) {
  37441. responseExists = false;
  37442. }
  37443. if (!responseExists) {
  37444. handler.send('test', false);
  37445. return;
  37446. }
  37447. handler.send('test', {
  37448. supportTypedArray: true,
  37449. supportTransfers: supportTransfers
  37450. });
  37451. });
  37452. handler.on('GetDocRequest', function wphSetupDoc(data) {
  37453. var onSuccess = function(doc) {
  37454. handler.send('GetDoc', { pdfInfo: doc });
  37455. };
  37456. var onFailure = function(e) {
  37457. if (e instanceof PasswordException) {
  37458. if (e.code === PasswordResponses.NEED_PASSWORD) {
  37459. handler.send('NeedPassword', e);
  37460. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  37461. handler.send('IncorrectPassword', e);
  37462. }
  37463. } else if (e instanceof InvalidPDFException) {
  37464. handler.send('InvalidPDF', e);
  37465. } else if (e instanceof MissingPDFException) {
  37466. handler.send('MissingPDF', e);
  37467. } else if (e instanceof UnexpectedResponseException) {
  37468. handler.send('UnexpectedResponse', e);
  37469. } else {
  37470. handler.send('UnknownError',
  37471. new UnknownErrorException(e.message, e.toString()));
  37472. }
  37473. };
  37474. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  37475. -1 : data.maxImageSize;
  37476. PDFJS.disableFontFace = data.disableFontFace;
  37477. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  37478. PDFJS.verbosity = data.verbosity;
  37479. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  37480. null : data.cMapUrl;
  37481. PDFJS.cMapPacked = data.cMapPacked === true;
  37482. getPdfManager(data).then(function () {
  37483. handler.send('PDFManagerReady', null);
  37484. pdfManager.onLoadedStream().then(function(stream) {
  37485. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  37486. });
  37487. }).then(function pdfManagerReady() {
  37488. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  37489. // Try again with recoveryMode == true
  37490. if (!(ex instanceof XRefParseException)) {
  37491. if (ex instanceof PasswordException) {
  37492. // after password exception prepare to receive a new password
  37493. // to repeat loading
  37494. pdfManager.passwordChanged().then(pdfManagerReady);
  37495. }
  37496. onFailure(ex);
  37497. return;
  37498. }
  37499. pdfManager.requestLoadedStream();
  37500. pdfManager.onLoadedStream().then(function() {
  37501. loadDocument(true).then(onSuccess, onFailure);
  37502. });
  37503. }, onFailure);
  37504. }, onFailure);
  37505. });
  37506. handler.on('GetPage', function wphSetupGetPage(data) {
  37507. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37508. var rotatePromise = pdfManager.ensure(page, 'rotate');
  37509. var refPromise = pdfManager.ensure(page, 'ref');
  37510. var viewPromise = pdfManager.ensure(page, 'view');
  37511. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  37512. function(results) {
  37513. return {
  37514. rotate: results[0],
  37515. ref: results[1],
  37516. view: results[2]
  37517. };
  37518. });
  37519. });
  37520. });
  37521. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  37522. var ref = new Ref(data.ref.num, data.ref.gen);
  37523. var catalog = pdfManager.pdfDocument.catalog;
  37524. return catalog.getPageIndex(ref);
  37525. });
  37526. handler.on('GetDestinations',
  37527. function wphSetupGetDestinations(data) {
  37528. return pdfManager.ensureCatalog('destinations');
  37529. }
  37530. );
  37531. handler.on('GetDestination',
  37532. function wphSetupGetDestination(data) {
  37533. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  37534. }
  37535. );
  37536. handler.on('GetAttachments',
  37537. function wphSetupGetAttachments(data) {
  37538. return pdfManager.ensureCatalog('attachments');
  37539. }
  37540. );
  37541. handler.on('GetJavaScript',
  37542. function wphSetupGetJavaScript(data) {
  37543. return pdfManager.ensureCatalog('javaScript');
  37544. }
  37545. );
  37546. handler.on('GetOutline',
  37547. function wphSetupGetOutline(data) {
  37548. return pdfManager.ensureCatalog('documentOutline');
  37549. }
  37550. );
  37551. handler.on('GetMetadata',
  37552. function wphSetupGetMetadata(data) {
  37553. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  37554. pdfManager.ensureCatalog('metadata')]);
  37555. }
  37556. );
  37557. handler.on('GetData', function wphSetupGetData(data) {
  37558. pdfManager.requestLoadedStream();
  37559. return pdfManager.onLoadedStream().then(function(stream) {
  37560. return stream.bytes;
  37561. });
  37562. });
  37563. handler.on('GetStats',
  37564. function wphSetupGetStats(data) {
  37565. return pdfManager.pdfDocument.xref.stats;
  37566. }
  37567. );
  37568. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  37569. pdfManager.updatePassword(data);
  37570. });
  37571. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  37572. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37573. return pdfManager.ensure(page, 'getAnnotationsData', []);
  37574. });
  37575. });
  37576. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  37577. pdfManager.getPage(data.pageIndex).then(function(page) {
  37578. var pageNum = data.pageIndex + 1;
  37579. var start = Date.now();
  37580. // Pre compile the pdf page and fetch the fonts/images.
  37581. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  37582. info('page=' + pageNum + ' - getOperatorList: time=' +
  37583. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  37584. }, function(e) {
  37585. var minimumStackMessage =
  37586. 'worker.js: while trying to getPage() and getOperatorList()';
  37587. var wrappedException;
  37588. // Turn the error into an obj that can be serialized
  37589. if (typeof e === 'string') {
  37590. wrappedException = {
  37591. message: e,
  37592. stack: minimumStackMessage
  37593. };
  37594. } else if (typeof e === 'object') {
  37595. wrappedException = {
  37596. message: e.message || e.toString(),
  37597. stack: e.stack || minimumStackMessage
  37598. };
  37599. } else {
  37600. wrappedException = {
  37601. message: 'Unknown exception type: ' + (typeof e),
  37602. stack: minimumStackMessage
  37603. };
  37604. }
  37605. handler.send('PageError', {
  37606. pageNum: pageNum,
  37607. error: wrappedException,
  37608. intent: data.intent
  37609. });
  37610. });
  37611. });
  37612. }, this);
  37613. handler.on('GetTextContent', function wphExtractText(data) {
  37614. return pdfManager.getPage(data.pageIndex).then(function(page) {
  37615. var pageNum = data.pageIndex + 1;
  37616. var start = Date.now();
  37617. return page.extractTextContent().then(function(textContent) {
  37618. info('text indexing: page=' + pageNum + ' - time=' +
  37619. (Date.now() - start) + 'ms');
  37620. return textContent;
  37621. });
  37622. });
  37623. });
  37624. handler.on('Cleanup', function wphCleanup(data) {
  37625. return pdfManager.cleanup();
  37626. });
  37627. handler.on('Terminate', function wphTerminate(data) {
  37628. pdfManager.terminate();
  37629. });
  37630. }
  37631. };
  37632. var consoleTimer = {};
  37633. var workerConsole = {
  37634. log: function log() {
  37635. var args = Array.prototype.slice.call(arguments);
  37636. globalScope.postMessage({
  37637. action: 'console_log',
  37638. data: args
  37639. });
  37640. },
  37641. error: function error() {
  37642. var args = Array.prototype.slice.call(arguments);
  37643. globalScope.postMessage({
  37644. action: 'console_error',
  37645. data: args
  37646. });
  37647. throw 'pdf.js execution error';
  37648. },
  37649. time: function time(name) {
  37650. consoleTimer[name] = Date.now();
  37651. },
  37652. timeEnd: function timeEnd(name) {
  37653. var time = consoleTimer[name];
  37654. if (!time) {
  37655. error('Unknown timer name ' + name);
  37656. }
  37657. this.log('Timer:', name, Date.now() - time);
  37658. }
  37659. };
  37660. // Worker thread?
  37661. if (typeof window === 'undefined') {
  37662. if (!('console' in globalScope)) {
  37663. globalScope.console = workerConsole;
  37664. }
  37665. // Listen for unsupported features so we can pass them on to the main thread.
  37666. PDFJS.UnsupportedManager.listen(function (msg) {
  37667. globalScope.postMessage({
  37668. action: '_unsupported_feature',
  37669. data: msg
  37670. });
  37671. });
  37672. var handler = new MessageHandler('worker_processor', this);
  37673. WorkerMessageHandler.setup(handler);
  37674. }
  37675. /* This class implements the QM Coder decoding as defined in
  37676. * JPEG 2000 Part I Final Committee Draft Version 1.0
  37677. * Annex C.3 Arithmetic decoding procedure
  37678. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  37679. *
  37680. * The arithmetic decoder is used in conjunction with context models to decode
  37681. * JPEG2000 and JBIG2 streams.
  37682. */
  37683. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  37684. // Table C-2
  37685. var QeTable = [
  37686. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  37687. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  37688. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  37689. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  37690. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  37691. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  37692. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  37693. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  37694. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  37695. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  37696. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  37697. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  37698. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  37699. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  37700. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  37701. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  37702. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  37703. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  37704. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  37705. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  37706. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  37707. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  37708. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  37709. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  37710. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  37711. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  37712. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  37713. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  37714. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  37715. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  37716. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  37717. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  37718. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  37719. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  37720. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  37721. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  37722. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  37723. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  37724. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  37725. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  37726. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  37727. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  37728. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  37729. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  37730. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  37731. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  37732. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  37733. ];
  37734. // C.3.5 Initialisation of the decoder (INITDEC)
  37735. function ArithmeticDecoder(data, start, end) {
  37736. this.data = data;
  37737. this.bp = start;
  37738. this.dataEnd = end;
  37739. this.chigh = data[start];
  37740. this.clow = 0;
  37741. this.byteIn();
  37742. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  37743. this.clow = (this.clow << 7) & 0xFFFF;
  37744. this.ct -= 7;
  37745. this.a = 0x8000;
  37746. }
  37747. ArithmeticDecoder.prototype = {
  37748. // C.3.4 Compressed data input (BYTEIN)
  37749. byteIn: function ArithmeticDecoder_byteIn() {
  37750. var data = this.data;
  37751. var bp = this.bp;
  37752. if (data[bp] === 0xFF) {
  37753. var b1 = data[bp + 1];
  37754. if (b1 > 0x8F) {
  37755. this.clow += 0xFF00;
  37756. this.ct = 8;
  37757. } else {
  37758. bp++;
  37759. this.clow += (data[bp] << 9);
  37760. this.ct = 7;
  37761. this.bp = bp;
  37762. }
  37763. } else {
  37764. bp++;
  37765. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  37766. this.ct = 8;
  37767. this.bp = bp;
  37768. }
  37769. if (this.clow > 0xFFFF) {
  37770. this.chigh += (this.clow >> 16);
  37771. this.clow &= 0xFFFF;
  37772. }
  37773. },
  37774. // C.3.2 Decoding a decision (DECODE)
  37775. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  37776. // contexts are packed into 1 byte:
  37777. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  37778. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  37779. var qeTableIcx = QeTable[cx_index];
  37780. var qeIcx = qeTableIcx.qe;
  37781. var d;
  37782. var a = this.a - qeIcx;
  37783. if (this.chigh < qeIcx) {
  37784. // exchangeLps
  37785. if (a < qeIcx) {
  37786. a = qeIcx;
  37787. d = cx_mps;
  37788. cx_index = qeTableIcx.nmps;
  37789. } else {
  37790. a = qeIcx;
  37791. d = 1 ^ cx_mps;
  37792. if (qeTableIcx.switchFlag === 1) {
  37793. cx_mps = d;
  37794. }
  37795. cx_index = qeTableIcx.nlps;
  37796. }
  37797. } else {
  37798. this.chigh -= qeIcx;
  37799. if ((a & 0x8000) !== 0) {
  37800. this.a = a;
  37801. return cx_mps;
  37802. }
  37803. // exchangeMps
  37804. if (a < qeIcx) {
  37805. d = 1 ^ cx_mps;
  37806. if (qeTableIcx.switchFlag === 1) {
  37807. cx_mps = d;
  37808. }
  37809. cx_index = qeTableIcx.nlps;
  37810. } else {
  37811. d = cx_mps;
  37812. cx_index = qeTableIcx.nmps;
  37813. }
  37814. }
  37815. // C.3.3 renormD;
  37816. do {
  37817. if (this.ct === 0) {
  37818. this.byteIn();
  37819. }
  37820. a <<= 1;
  37821. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  37822. this.clow = (this.clow << 1) & 0xFFFF;
  37823. this.ct--;
  37824. } while ((a & 0x8000) === 0);
  37825. this.a = a;
  37826. contexts[pos] = cx_index << 1 | cx_mps;
  37827. return d;
  37828. }
  37829. };
  37830. return ArithmeticDecoder;
  37831. })();
  37832. var JpegImage = (function jpegImage() {
  37833. var dctZigZag = new Uint8Array([
  37834. 0,
  37835. 1, 8,
  37836. 16, 9, 2,
  37837. 3, 10, 17, 24,
  37838. 32, 25, 18, 11, 4,
  37839. 5, 12, 19, 26, 33, 40,
  37840. 48, 41, 34, 27, 20, 13, 6,
  37841. 7, 14, 21, 28, 35, 42, 49, 56,
  37842. 57, 50, 43, 36, 29, 22, 15,
  37843. 23, 30, 37, 44, 51, 58,
  37844. 59, 52, 45, 38, 31,
  37845. 39, 46, 53, 60,
  37846. 61, 54, 47,
  37847. 55, 62,
  37848. 63
  37849. ]);
  37850. var dctCos1 = 4017; // cos(pi/16)
  37851. var dctSin1 = 799; // sin(pi/16)
  37852. var dctCos3 = 3406; // cos(3*pi/16)
  37853. var dctSin3 = 2276; // sin(3*pi/16)
  37854. var dctCos6 = 1567; // cos(6*pi/16)
  37855. var dctSin6 = 3784; // sin(6*pi/16)
  37856. var dctSqrt2 = 5793; // sqrt(2)
  37857. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  37858. function constructor() {
  37859. }
  37860. function buildHuffmanTable(codeLengths, values) {
  37861. var k = 0, code = [], i, j, length = 16;
  37862. while (length > 0 && !codeLengths[length - 1]) {
  37863. length--;
  37864. }
  37865. code.push({children: [], index: 0});
  37866. var p = code[0], q;
  37867. for (i = 0; i < length; i++) {
  37868. for (j = 0; j < codeLengths[i]; j++) {
  37869. p = code.pop();
  37870. p.children[p.index] = values[k];
  37871. while (p.index > 0) {
  37872. p = code.pop();
  37873. }
  37874. p.index++;
  37875. code.push(p);
  37876. while (code.length <= i) {
  37877. code.push(q = {children: [], index: 0});
  37878. p.children[p.index] = q.children;
  37879. p = q;
  37880. }
  37881. k++;
  37882. }
  37883. if (i + 1 < length) {
  37884. // p here points to last code
  37885. code.push(q = {children: [], index: 0});
  37886. p.children[p.index] = q.children;
  37887. p = q;
  37888. }
  37889. }
  37890. return code[0].children;
  37891. }
  37892. function getBlockBufferOffset(component, row, col) {
  37893. return 64 * ((component.blocksPerLine + 1) * row + col);
  37894. }
  37895. function decodeScan(data, offset, frame, components, resetInterval,
  37896. spectralStart, spectralEnd, successivePrev, successive) {
  37897. var precision = frame.precision;
  37898. var samplesPerLine = frame.samplesPerLine;
  37899. var scanLines = frame.scanLines;
  37900. var mcusPerLine = frame.mcusPerLine;
  37901. var progressive = frame.progressive;
  37902. var maxH = frame.maxH, maxV = frame.maxV;
  37903. var startOffset = offset, bitsData = 0, bitsCount = 0;
  37904. function readBit() {
  37905. if (bitsCount > 0) {
  37906. bitsCount--;
  37907. return (bitsData >> bitsCount) & 1;
  37908. }
  37909. bitsData = data[offset++];
  37910. if (bitsData === 0xFF) {
  37911. var nextByte = data[offset++];
  37912. if (nextByte) {
  37913. throw 'unexpected marker: ' +
  37914. ((bitsData << 8) | nextByte).toString(16);
  37915. }
  37916. // unstuff 0
  37917. }
  37918. bitsCount = 7;
  37919. return bitsData >>> 7;
  37920. }
  37921. function decodeHuffman(tree) {
  37922. var node = tree;
  37923. while (true) {
  37924. node = node[readBit()];
  37925. if (typeof node === 'number') {
  37926. return node;
  37927. }
  37928. if (typeof node !== 'object') {
  37929. throw 'invalid huffman sequence';
  37930. }
  37931. }
  37932. }
  37933. function receive(length) {
  37934. var n = 0;
  37935. while (length > 0) {
  37936. n = (n << 1) | readBit();
  37937. length--;
  37938. }
  37939. return n;
  37940. }
  37941. function receiveAndExtend(length) {
  37942. if (length === 1) {
  37943. return readBit() === 1 ? 1 : -1;
  37944. }
  37945. var n = receive(length);
  37946. if (n >= 1 << (length - 1)) {
  37947. return n;
  37948. }
  37949. return n + (-1 << length) + 1;
  37950. }
  37951. function decodeBaseline(component, offset) {
  37952. var t = decodeHuffman(component.huffmanTableDC);
  37953. var diff = t === 0 ? 0 : receiveAndExtend(t);
  37954. component.blockData[offset] = (component.pred += diff);
  37955. var k = 1;
  37956. while (k < 64) {
  37957. var rs = decodeHuffman(component.huffmanTableAC);
  37958. var s = rs & 15, r = rs >> 4;
  37959. if (s === 0) {
  37960. if (r < 15) {
  37961. break;
  37962. }
  37963. k += 16;
  37964. continue;
  37965. }
  37966. k += r;
  37967. var z = dctZigZag[k];
  37968. component.blockData[offset + z] = receiveAndExtend(s);
  37969. k++;
  37970. }
  37971. }
  37972. function decodeDCFirst(component, offset) {
  37973. var t = decodeHuffman(component.huffmanTableDC);
  37974. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  37975. component.blockData[offset] = (component.pred += diff);
  37976. }
  37977. function decodeDCSuccessive(component, offset) {
  37978. component.blockData[offset] |= readBit() << successive;
  37979. }
  37980. var eobrun = 0;
  37981. function decodeACFirst(component, offset) {
  37982. if (eobrun > 0) {
  37983. eobrun--;
  37984. return;
  37985. }
  37986. var k = spectralStart, e = spectralEnd;
  37987. while (k <= e) {
  37988. var rs = decodeHuffman(component.huffmanTableAC);
  37989. var s = rs & 15, r = rs >> 4;
  37990. if (s === 0) {
  37991. if (r < 15) {
  37992. eobrun = receive(r) + (1 << r) - 1;
  37993. break;
  37994. }
  37995. k += 16;
  37996. continue;
  37997. }
  37998. k += r;
  37999. var z = dctZigZag[k];
  38000. component.blockData[offset + z] =
  38001. receiveAndExtend(s) * (1 << successive);
  38002. k++;
  38003. }
  38004. }
  38005. var successiveACState = 0, successiveACNextValue;
  38006. function decodeACSuccessive(component, offset) {
  38007. var k = spectralStart;
  38008. var e = spectralEnd;
  38009. var r = 0;
  38010. var s;
  38011. var rs;
  38012. while (k <= e) {
  38013. var z = dctZigZag[k];
  38014. switch (successiveACState) {
  38015. case 0: // initial state
  38016. rs = decodeHuffman(component.huffmanTableAC);
  38017. s = rs & 15;
  38018. r = rs >> 4;
  38019. if (s === 0) {
  38020. if (r < 15) {
  38021. eobrun = receive(r) + (1 << r);
  38022. successiveACState = 4;
  38023. } else {
  38024. r = 16;
  38025. successiveACState = 1;
  38026. }
  38027. } else {
  38028. if (s !== 1) {
  38029. throw 'invalid ACn encoding';
  38030. }
  38031. successiveACNextValue = receiveAndExtend(s);
  38032. successiveACState = r ? 2 : 3;
  38033. }
  38034. continue;
  38035. case 1: // skipping r zero items
  38036. case 2:
  38037. if (component.blockData[offset + z]) {
  38038. component.blockData[offset + z] += (readBit() << successive);
  38039. } else {
  38040. r--;
  38041. if (r === 0) {
  38042. successiveACState = successiveACState === 2 ? 3 : 0;
  38043. }
  38044. }
  38045. break;
  38046. case 3: // set value for a zero item
  38047. if (component.blockData[offset + z]) {
  38048. component.blockData[offset + z] += (readBit() << successive);
  38049. } else {
  38050. component.blockData[offset + z] =
  38051. successiveACNextValue << successive;
  38052. successiveACState = 0;
  38053. }
  38054. break;
  38055. case 4: // eob
  38056. if (component.blockData[offset + z]) {
  38057. component.blockData[offset + z] += (readBit() << successive);
  38058. }
  38059. break;
  38060. }
  38061. k++;
  38062. }
  38063. if (successiveACState === 4) {
  38064. eobrun--;
  38065. if (eobrun === 0) {
  38066. successiveACState = 0;
  38067. }
  38068. }
  38069. }
  38070. function decodeMcu(component, decode, mcu, row, col) {
  38071. var mcuRow = (mcu / mcusPerLine) | 0;
  38072. var mcuCol = mcu % mcusPerLine;
  38073. var blockRow = mcuRow * component.v + row;
  38074. var blockCol = mcuCol * component.h + col;
  38075. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38076. decode(component, offset);
  38077. }
  38078. function decodeBlock(component, decode, mcu) {
  38079. var blockRow = (mcu / component.blocksPerLine) | 0;
  38080. var blockCol = mcu % component.blocksPerLine;
  38081. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38082. decode(component, offset);
  38083. }
  38084. var componentsLength = components.length;
  38085. var component, i, j, k, n;
  38086. var decodeFn;
  38087. if (progressive) {
  38088. if (spectralStart === 0) {
  38089. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  38090. } else {
  38091. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  38092. }
  38093. } else {
  38094. decodeFn = decodeBaseline;
  38095. }
  38096. var mcu = 0, marker;
  38097. var mcuExpected;
  38098. if (componentsLength === 1) {
  38099. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  38100. } else {
  38101. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  38102. }
  38103. if (!resetInterval) {
  38104. resetInterval = mcuExpected;
  38105. }
  38106. var h, v;
  38107. while (mcu < mcuExpected) {
  38108. // reset interval stuff
  38109. for (i = 0; i < componentsLength; i++) {
  38110. components[i].pred = 0;
  38111. }
  38112. eobrun = 0;
  38113. if (componentsLength === 1) {
  38114. component = components[0];
  38115. for (n = 0; n < resetInterval; n++) {
  38116. decodeBlock(component, decodeFn, mcu);
  38117. mcu++;
  38118. }
  38119. } else {
  38120. for (n = 0; n < resetInterval; n++) {
  38121. for (i = 0; i < componentsLength; i++) {
  38122. component = components[i];
  38123. h = component.h;
  38124. v = component.v;
  38125. for (j = 0; j < v; j++) {
  38126. for (k = 0; k < h; k++) {
  38127. decodeMcu(component, decodeFn, mcu, j, k);
  38128. }
  38129. }
  38130. }
  38131. mcu++;
  38132. }
  38133. }
  38134. // find marker
  38135. bitsCount = 0;
  38136. marker = (data[offset] << 8) | data[offset + 1];
  38137. if (marker <= 0xFF00) {
  38138. throw 'marker was not found';
  38139. }
  38140. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  38141. offset += 2;
  38142. } else {
  38143. break;
  38144. }
  38145. }
  38146. return offset - startOffset;
  38147. }
  38148. // A port of poppler's IDCT method which in turn is taken from:
  38149. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  38150. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  38151. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  38152. // 988-991.
  38153. function quantizeAndInverse(component, blockBufferOffset, p) {
  38154. var qt = component.quantizationTable, blockData = component.blockData;
  38155. var v0, v1, v2, v3, v4, v5, v6, v7;
  38156. var p0, p1, p2, p3, p4, p5, p6, p7;
  38157. var t;
  38158. // inverse DCT on rows
  38159. for (var row = 0; row < 64; row += 8) {
  38160. // gather block data
  38161. p0 = blockData[blockBufferOffset + row];
  38162. p1 = blockData[blockBufferOffset + row + 1];
  38163. p2 = blockData[blockBufferOffset + row + 2];
  38164. p3 = blockData[blockBufferOffset + row + 3];
  38165. p4 = blockData[blockBufferOffset + row + 4];
  38166. p5 = blockData[blockBufferOffset + row + 5];
  38167. p6 = blockData[blockBufferOffset + row + 6];
  38168. p7 = blockData[blockBufferOffset + row + 7];
  38169. // dequant p0
  38170. p0 *= qt[row];
  38171. // check for all-zero AC coefficients
  38172. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38173. t = (dctSqrt2 * p0 + 512) >> 10;
  38174. p[row] = t;
  38175. p[row + 1] = t;
  38176. p[row + 2] = t;
  38177. p[row + 3] = t;
  38178. p[row + 4] = t;
  38179. p[row + 5] = t;
  38180. p[row + 6] = t;
  38181. p[row + 7] = t;
  38182. continue;
  38183. }
  38184. // dequant p1 ... p7
  38185. p1 *= qt[row + 1];
  38186. p2 *= qt[row + 2];
  38187. p3 *= qt[row + 3];
  38188. p4 *= qt[row + 4];
  38189. p5 *= qt[row + 5];
  38190. p6 *= qt[row + 6];
  38191. p7 *= qt[row + 7];
  38192. // stage 4
  38193. v0 = (dctSqrt2 * p0 + 128) >> 8;
  38194. v1 = (dctSqrt2 * p4 + 128) >> 8;
  38195. v2 = p2;
  38196. v3 = p6;
  38197. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  38198. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  38199. v5 = p3 << 4;
  38200. v6 = p5 << 4;
  38201. // stage 3
  38202. v0 = (v0 + v1 + 1) >> 1;
  38203. v1 = v0 - v1;
  38204. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  38205. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  38206. v3 = t;
  38207. v4 = (v4 + v6 + 1) >> 1;
  38208. v6 = v4 - v6;
  38209. v7 = (v7 + v5 + 1) >> 1;
  38210. v5 = v7 - v5;
  38211. // stage 2
  38212. v0 = (v0 + v3 + 1) >> 1;
  38213. v3 = v0 - v3;
  38214. v1 = (v1 + v2 + 1) >> 1;
  38215. v2 = v1 - v2;
  38216. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38217. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38218. v7 = t;
  38219. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38220. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38221. v6 = t;
  38222. // stage 1
  38223. p[row] = v0 + v7;
  38224. p[row + 7] = v0 - v7;
  38225. p[row + 1] = v1 + v6;
  38226. p[row + 6] = v1 - v6;
  38227. p[row + 2] = v2 + v5;
  38228. p[row + 5] = v2 - v5;
  38229. p[row + 3] = v3 + v4;
  38230. p[row + 4] = v3 - v4;
  38231. }
  38232. // inverse DCT on columns
  38233. for (var col = 0; col < 8; ++col) {
  38234. p0 = p[col];
  38235. p1 = p[col + 8];
  38236. p2 = p[col + 16];
  38237. p3 = p[col + 24];
  38238. p4 = p[col + 32];
  38239. p5 = p[col + 40];
  38240. p6 = p[col + 48];
  38241. p7 = p[col + 56];
  38242. // check for all-zero AC coefficients
  38243. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  38244. t = (dctSqrt2 * p0 + 8192) >> 14;
  38245. // convert to 8 bit
  38246. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  38247. blockData[blockBufferOffset + col] = t;
  38248. blockData[blockBufferOffset + col + 8] = t;
  38249. blockData[blockBufferOffset + col + 16] = t;
  38250. blockData[blockBufferOffset + col + 24] = t;
  38251. blockData[blockBufferOffset + col + 32] = t;
  38252. blockData[blockBufferOffset + col + 40] = t;
  38253. blockData[blockBufferOffset + col + 48] = t;
  38254. blockData[blockBufferOffset + col + 56] = t;
  38255. continue;
  38256. }
  38257. // stage 4
  38258. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  38259. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  38260. v2 = p2;
  38261. v3 = p6;
  38262. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  38263. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  38264. v5 = p3;
  38265. v6 = p5;
  38266. // stage 3
  38267. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  38268. // converting to UInt8 range later.
  38269. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  38270. v1 = v0 - v1;
  38271. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  38272. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  38273. v3 = t;
  38274. v4 = (v4 + v6 + 1) >> 1;
  38275. v6 = v4 - v6;
  38276. v7 = (v7 + v5 + 1) >> 1;
  38277. v5 = v7 - v5;
  38278. // stage 2
  38279. v0 = (v0 + v3 + 1) >> 1;
  38280. v3 = v0 - v3;
  38281. v1 = (v1 + v2 + 1) >> 1;
  38282. v2 = v1 - v2;
  38283. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  38284. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  38285. v7 = t;
  38286. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  38287. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  38288. v6 = t;
  38289. // stage 1
  38290. p0 = v0 + v7;
  38291. p7 = v0 - v7;
  38292. p1 = v1 + v6;
  38293. p6 = v1 - v6;
  38294. p2 = v2 + v5;
  38295. p5 = v2 - v5;
  38296. p3 = v3 + v4;
  38297. p4 = v3 - v4;
  38298. // convert to 8-bit integers
  38299. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  38300. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  38301. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  38302. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  38303. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  38304. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  38305. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  38306. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  38307. // store block data
  38308. blockData[blockBufferOffset + col] = p0;
  38309. blockData[blockBufferOffset + col + 8] = p1;
  38310. blockData[blockBufferOffset + col + 16] = p2;
  38311. blockData[blockBufferOffset + col + 24] = p3;
  38312. blockData[blockBufferOffset + col + 32] = p4;
  38313. blockData[blockBufferOffset + col + 40] = p5;
  38314. blockData[blockBufferOffset + col + 48] = p6;
  38315. blockData[blockBufferOffset + col + 56] = p7;
  38316. }
  38317. }
  38318. function buildComponentData(frame, component) {
  38319. var blocksPerLine = component.blocksPerLine;
  38320. var blocksPerColumn = component.blocksPerColumn;
  38321. var computationBuffer = new Int16Array(64);
  38322. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  38323. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  38324. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  38325. quantizeAndInverse(component, offset, computationBuffer);
  38326. }
  38327. }
  38328. return component.blockData;
  38329. }
  38330. function clamp0to255(a) {
  38331. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  38332. }
  38333. constructor.prototype = {
  38334. parse: function parse(data) {
  38335. function readUint16() {
  38336. var value = (data[offset] << 8) | data[offset + 1];
  38337. offset += 2;
  38338. return value;
  38339. }
  38340. function readDataBlock() {
  38341. var length = readUint16();
  38342. var array = data.subarray(offset, offset + length - 2);
  38343. offset += array.length;
  38344. return array;
  38345. }
  38346. function prepareComponents(frame) {
  38347. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  38348. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  38349. for (var i = 0; i < frame.components.length; i++) {
  38350. component = frame.components[i];
  38351. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  38352. component.h / frame.maxH);
  38353. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  38354. component.v / frame.maxV);
  38355. var blocksPerLineForMcu = mcusPerLine * component.h;
  38356. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  38357. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  38358. (blocksPerLineForMcu + 1);
  38359. component.blockData = new Int16Array(blocksBufferSize);
  38360. component.blocksPerLine = blocksPerLine;
  38361. component.blocksPerColumn = blocksPerColumn;
  38362. }
  38363. frame.mcusPerLine = mcusPerLine;
  38364. frame.mcusPerColumn = mcusPerColumn;
  38365. }
  38366. var offset = 0, length = data.length;
  38367. var jfif = null;
  38368. var adobe = null;
  38369. var pixels = null;
  38370. var frame, resetInterval;
  38371. var quantizationTables = [];
  38372. var huffmanTablesAC = [], huffmanTablesDC = [];
  38373. var fileMarker = readUint16();
  38374. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  38375. throw 'SOI not found';
  38376. }
  38377. fileMarker = readUint16();
  38378. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  38379. var i, j, l;
  38380. switch(fileMarker) {
  38381. case 0xFFE0: // APP0 (Application Specific)
  38382. case 0xFFE1: // APP1
  38383. case 0xFFE2: // APP2
  38384. case 0xFFE3: // APP3
  38385. case 0xFFE4: // APP4
  38386. case 0xFFE5: // APP5
  38387. case 0xFFE6: // APP6
  38388. case 0xFFE7: // APP7
  38389. case 0xFFE8: // APP8
  38390. case 0xFFE9: // APP9
  38391. case 0xFFEA: // APP10
  38392. case 0xFFEB: // APP11
  38393. case 0xFFEC: // APP12
  38394. case 0xFFED: // APP13
  38395. case 0xFFEE: // APP14
  38396. case 0xFFEF: // APP15
  38397. case 0xFFFE: // COM (Comment)
  38398. var appData = readDataBlock();
  38399. if (fileMarker === 0xFFE0) {
  38400. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  38401. appData[2] === 0x49 && appData[3] === 0x46 &&
  38402. appData[4] === 0) { // 'JFIF\x00'
  38403. jfif = {
  38404. version: { major: appData[5], minor: appData[6] },
  38405. densityUnits: appData[7],
  38406. xDensity: (appData[8] << 8) | appData[9],
  38407. yDensity: (appData[10] << 8) | appData[11],
  38408. thumbWidth: appData[12],
  38409. thumbHeight: appData[13],
  38410. thumbData: appData.subarray(14, 14 +
  38411. 3 * appData[12] * appData[13])
  38412. };
  38413. }
  38414. }
  38415. // TODO APP1 - Exif
  38416. if (fileMarker === 0xFFEE) {
  38417. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  38418. appData[2] === 0x6F && appData[3] === 0x62 &&
  38419. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  38420. adobe = {
  38421. version: appData[6],
  38422. flags0: (appData[7] << 8) | appData[8],
  38423. flags1: (appData[9] << 8) | appData[10],
  38424. transformCode: appData[11]
  38425. };
  38426. }
  38427. }
  38428. break;
  38429. case 0xFFDB: // DQT (Define Quantization Tables)
  38430. var quantizationTablesLength = readUint16();
  38431. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  38432. var z;
  38433. while (offset < quantizationTablesEnd) {
  38434. var quantizationTableSpec = data[offset++];
  38435. var tableData = new Uint16Array(64);
  38436. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  38437. for (j = 0; j < 64; j++) {
  38438. z = dctZigZag[j];
  38439. tableData[z] = data[offset++];
  38440. }
  38441. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  38442. for (j = 0; j < 64; j++) {
  38443. z = dctZigZag[j];
  38444. tableData[z] = readUint16();
  38445. }
  38446. } else {
  38447. throw 'DQT: invalid table spec';
  38448. }
  38449. quantizationTables[quantizationTableSpec & 15] = tableData;
  38450. }
  38451. break;
  38452. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  38453. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  38454. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  38455. if (frame) {
  38456. throw 'Only single frame JPEGs supported';
  38457. }
  38458. readUint16(); // skip data length
  38459. frame = {};
  38460. frame.extended = (fileMarker === 0xFFC1);
  38461. frame.progressive = (fileMarker === 0xFFC2);
  38462. frame.precision = data[offset++];
  38463. frame.scanLines = readUint16();
  38464. frame.samplesPerLine = readUint16();
  38465. frame.components = [];
  38466. frame.componentIds = {};
  38467. var componentsCount = data[offset++], componentId;
  38468. var maxH = 0, maxV = 0;
  38469. for (i = 0; i < componentsCount; i++) {
  38470. componentId = data[offset];
  38471. var h = data[offset + 1] >> 4;
  38472. var v = data[offset + 1] & 15;
  38473. if (maxH < h) {
  38474. maxH = h;
  38475. }
  38476. if (maxV < v) {
  38477. maxV = v;
  38478. }
  38479. var qId = data[offset + 2];
  38480. l = frame.components.push({
  38481. h: h,
  38482. v: v,
  38483. quantizationTable: quantizationTables[qId]
  38484. });
  38485. frame.componentIds[componentId] = l - 1;
  38486. offset += 3;
  38487. }
  38488. frame.maxH = maxH;
  38489. frame.maxV = maxV;
  38490. prepareComponents(frame);
  38491. break;
  38492. case 0xFFC4: // DHT (Define Huffman Tables)
  38493. var huffmanLength = readUint16();
  38494. for (i = 2; i < huffmanLength;) {
  38495. var huffmanTableSpec = data[offset++];
  38496. var codeLengths = new Uint8Array(16);
  38497. var codeLengthSum = 0;
  38498. for (j = 0; j < 16; j++, offset++) {
  38499. codeLengthSum += (codeLengths[j] = data[offset]);
  38500. }
  38501. var huffmanValues = new Uint8Array(codeLengthSum);
  38502. for (j = 0; j < codeLengthSum; j++, offset++) {
  38503. huffmanValues[j] = data[offset];
  38504. }
  38505. i += 17 + codeLengthSum;
  38506. ((huffmanTableSpec >> 4) === 0 ?
  38507. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  38508. buildHuffmanTable(codeLengths, huffmanValues);
  38509. }
  38510. break;
  38511. case 0xFFDD: // DRI (Define Restart Interval)
  38512. readUint16(); // skip data length
  38513. resetInterval = readUint16();
  38514. break;
  38515. case 0xFFDA: // SOS (Start of Scan)
  38516. var scanLength = readUint16();
  38517. var selectorsCount = data[offset++];
  38518. var components = [], component;
  38519. for (i = 0; i < selectorsCount; i++) {
  38520. var componentIndex = frame.componentIds[data[offset++]];
  38521. component = frame.components[componentIndex];
  38522. var tableSpec = data[offset++];
  38523. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  38524. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  38525. components.push(component);
  38526. }
  38527. var spectralStart = data[offset++];
  38528. var spectralEnd = data[offset++];
  38529. var successiveApproximation = data[offset++];
  38530. var processed = decodeScan(data, offset,
  38531. frame, components, resetInterval,
  38532. spectralStart, spectralEnd,
  38533. successiveApproximation >> 4, successiveApproximation & 15);
  38534. offset += processed;
  38535. break;
  38536. case 0xFFFF: // Fill bytes
  38537. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  38538. offset--;
  38539. }
  38540. break;
  38541. default:
  38542. if (data[offset - 3] === 0xFF &&
  38543. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  38544. // could be incorrect encoding -- last 0xFF byte of the previous
  38545. // block was eaten by the encoder
  38546. offset -= 3;
  38547. break;
  38548. }
  38549. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  38550. }
  38551. fileMarker = readUint16();
  38552. }
  38553. this.width = frame.samplesPerLine;
  38554. this.height = frame.scanLines;
  38555. this.jfif = jfif;
  38556. this.adobe = adobe;
  38557. this.components = [];
  38558. for (i = 0; i < frame.components.length; i++) {
  38559. component = frame.components[i];
  38560. this.components.push({
  38561. output: buildComponentData(frame, component),
  38562. scaleX: component.h / frame.maxH,
  38563. scaleY: component.v / frame.maxV,
  38564. blocksPerLine: component.blocksPerLine,
  38565. blocksPerColumn: component.blocksPerColumn
  38566. });
  38567. }
  38568. this.numComponents = this.components.length;
  38569. },
  38570. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  38571. var scaleX = this.width / width, scaleY = this.height / height;
  38572. var component, componentScaleX, componentScaleY, blocksPerScanline;
  38573. var x, y, i, j, k;
  38574. var index;
  38575. var offset = 0;
  38576. var output;
  38577. var numComponents = this.components.length;
  38578. var dataLength = width * height * numComponents;
  38579. var data = new Uint8Array(dataLength);
  38580. var xScaleBlockOffset = new Uint32Array(width);
  38581. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  38582. for (i = 0; i < numComponents; i++) {
  38583. component = this.components[i];
  38584. componentScaleX = component.scaleX * scaleX;
  38585. componentScaleY = component.scaleY * scaleY;
  38586. offset = i;
  38587. output = component.output;
  38588. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  38589. // precalculate the xScaleBlockOffset
  38590. for (x = 0; x < width; x++) {
  38591. j = 0 | (x * componentScaleX);
  38592. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  38593. }
  38594. // linearize the blocks of the component
  38595. for (y = 0; y < height; y++) {
  38596. j = 0 | (y * componentScaleY);
  38597. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  38598. for (x = 0; x < width; x++) {
  38599. data[offset] = output[index + xScaleBlockOffset[x]];
  38600. offset += numComponents;
  38601. }
  38602. }
  38603. }
  38604. // decodeTransform contains pairs of multiplier (-256..256) and additive
  38605. var transform = this.decodeTransform;
  38606. if (transform) {
  38607. for (i = 0; i < dataLength;) {
  38608. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  38609. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  38610. }
  38611. }
  38612. }
  38613. return data;
  38614. },
  38615. _isColorConversionNeeded: function isColorConversionNeeded() {
  38616. if (this.adobe && this.adobe.transformCode) {
  38617. // The adobe transform marker overrides any previous setting
  38618. return true;
  38619. } else if (this.numComponents === 3) {
  38620. return true;
  38621. } else {
  38622. return false;
  38623. }
  38624. },
  38625. _convertYccToRgb: function convertYccToRgb(data) {
  38626. var Y, Cb, Cr;
  38627. for (var i = 0, length = data.length; i < length; i += 3) {
  38628. Y = data[i ];
  38629. Cb = data[i + 1];
  38630. Cr = data[i + 2];
  38631. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  38632. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  38633. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  38634. }
  38635. return data;
  38636. },
  38637. _convertYcckToRgb: function convertYcckToRgb(data) {
  38638. var Y, Cb, Cr, k;
  38639. var offset = 0;
  38640. for (var i = 0, length = data.length; i < length; i += 4) {
  38641. Y = data[i];
  38642. Cb = data[i + 1];
  38643. Cr = data[i + 2];
  38644. k = data[i + 3];
  38645. var r = -122.67195406894 +
  38646. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  38647. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  38648. 0.154362151871126) +
  38649. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  38650. 0.00477271405408747 * k + 1.53380253221734) +
  38651. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  38652. 0.48357088451265) +
  38653. k * (-0.000336197177618394 * k + 0.484791561490776);
  38654. var g = 107.268039397724 +
  38655. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  38656. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  38657. 0.176491792462875) +
  38658. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  38659. 0.000770482631801132 * k - 0.151051492775562) +
  38660. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  38661. 0.25802910206845) +
  38662. k * (-0.000318913117588328 * k - 0.213742400323665);
  38663. var b = -20.810012546947 +
  38664. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  38665. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  38666. 0.814272968359295) +
  38667. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  38668. 0.000560833691242812 * k - 0.195152027534049) +
  38669. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  38670. 0.116935020465145) +
  38671. k * (-0.000343531996510555 * k + 0.24165260232407);
  38672. data[offset++] = clamp0to255(r);
  38673. data[offset++] = clamp0to255(g);
  38674. data[offset++] = clamp0to255(b);
  38675. }
  38676. return data;
  38677. },
  38678. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  38679. var Y, Cb, Cr;
  38680. for (var i = 0, length = data.length; i < length; i += 4) {
  38681. Y = data[i];
  38682. Cb = data[i + 1];
  38683. Cr = data[i + 2];
  38684. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  38685. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  38686. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  38687. // K in data[i + 3] is unchanged
  38688. }
  38689. return data;
  38690. },
  38691. _convertCmykToRgb: function convertCmykToRgb(data) {
  38692. var c, m, y, k;
  38693. var offset = 0;
  38694. var min = -255 * 255 * 255;
  38695. var scale = 1 / 255 / 255;
  38696. for (var i = 0, length = data.length; i < length; i += 4) {
  38697. c = data[i];
  38698. m = data[i + 1];
  38699. y = data[i + 2];
  38700. k = data[i + 3];
  38701. var r =
  38702. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38703. 18.82290502165302 * y + 212.25662451639585 * k -
  38704. 72734.4411664936) +
  38705. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  38706. 17.873870861415444 * k - 1401.7366389350734) +
  38707. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38708. 4465.541406466231) -
  38709. k * (21.86122147463605 * k + 48317.86113160301);
  38710. var g =
  38711. c * (8.841041422036149 * c + 60.118027045597366 * m +
  38712. 6.871425592049007 * y + 31.159100130055922 * k -
  38713. 20220.756542821975) +
  38714. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38715. 131.35250912493976 * k - 48691.05921601825) +
  38716. y * (4.444339102852739 * y + 9.8632861493405 * k -
  38717. 6341.191035517494) -
  38718. k * (20.737325471181034 * k + 47890.15695978492);
  38719. var b =
  38720. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38721. 30.89978309703729 * y - 0.23883238689178934 * k -
  38722. 3616.812083916688) +
  38723. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38724. 50.606957656360734 * k - 28620.90484698408) +
  38725. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  38726. 49363.43385999684) -
  38727. k * (22.33816807309886 * k + 45932.16563550634);
  38728. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  38729. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  38730. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  38731. }
  38732. return data;
  38733. },
  38734. getData: function getData(width, height, forceRGBoutput) {
  38735. if (this.numComponents > 4) {
  38736. throw 'Unsupported color mode';
  38737. }
  38738. // type of data: Uint8Array(width * height * numComponents)
  38739. var data = this._getLinearizedBlockData(width, height);
  38740. if (this.numComponents === 3) {
  38741. return this._convertYccToRgb(data);
  38742. } else if (this.numComponents === 4) {
  38743. if (this._isColorConversionNeeded()) {
  38744. if (forceRGBoutput) {
  38745. return this._convertYcckToRgb(data);
  38746. } else {
  38747. return this._convertYcckToCmyk(data);
  38748. }
  38749. } else if (forceRGBoutput) {
  38750. return this._convertCmykToRgb(data);
  38751. }
  38752. }
  38753. return data;
  38754. }
  38755. };
  38756. return constructor;
  38757. })();
  38758. var JpxImage = (function JpxImageClosure() {
  38759. // Table E.1
  38760. var SubbandsGainLog2 = {
  38761. 'LL': 0,
  38762. 'LH': 1,
  38763. 'HL': 1,
  38764. 'HH': 2
  38765. };
  38766. function JpxImage() {
  38767. this.failOnCorruptedImage = false;
  38768. }
  38769. JpxImage.prototype = {
  38770. parse: function JpxImage_parse(data) {
  38771. var head = readUint16(data, 0);
  38772. // No box header, immediate start of codestream (SOC)
  38773. if (head === 0xFF4F) {
  38774. this.parseCodestream(data, 0, data.length);
  38775. return;
  38776. }
  38777. var position = 0, length = data.length;
  38778. while (position < length) {
  38779. var headerSize = 8;
  38780. var lbox = readUint32(data, position);
  38781. var tbox = readUint32(data, position + 4);
  38782. position += headerSize;
  38783. if (lbox === 1) {
  38784. // XLBox: read UInt64 according to spec.
  38785. // JavaScript's int precision of 53 bit should be sufficient here.
  38786. lbox = readUint32(data, position) * 4294967296 +
  38787. readUint32(data, position + 4);
  38788. position += 8;
  38789. headerSize += 8;
  38790. }
  38791. if (lbox === 0) {
  38792. lbox = length - position + headerSize;
  38793. }
  38794. if (lbox < headerSize) {
  38795. throw new Error('JPX Error: Invalid box field size');
  38796. }
  38797. var dataLength = lbox - headerSize;
  38798. var jumpDataLength = true;
  38799. switch (tbox) {
  38800. case 0x6A703268: // 'jp2h'
  38801. jumpDataLength = false; // parsing child boxes
  38802. break;
  38803. case 0x636F6C72: // 'colr'
  38804. // Colorspaces are not used, the CS from the PDF is used.
  38805. var method = data[position];
  38806. var precedence = data[position + 1];
  38807. var approximation = data[position + 2];
  38808. if (method === 1) {
  38809. // enumerated colorspace
  38810. var colorspace = readUint32(data, position + 3);
  38811. switch (colorspace) {
  38812. case 16: // this indicates a sRGB colorspace
  38813. case 17: // this indicates a grayscale colorspace
  38814. case 18: // this indicates a YUV colorspace
  38815. break;
  38816. default:
  38817. warn('Unknown colorspace ' + colorspace);
  38818. break;
  38819. }
  38820. } else if (method === 2) {
  38821. info('ICC profile not supported');
  38822. }
  38823. break;
  38824. case 0x6A703263: // 'jp2c'
  38825. this.parseCodestream(data, position, position + dataLength);
  38826. break;
  38827. case 0x6A502020: // 'jP\024\024'
  38828. if (0x0d0a870a !== readUint32(data, position)) {
  38829. warn('Invalid JP2 signature');
  38830. }
  38831. break;
  38832. // The following header types are valid but currently not used:
  38833. case 0x6A501A1A: // 'jP\032\032'
  38834. case 0x66747970: // 'ftyp'
  38835. case 0x72726571: // 'rreq'
  38836. case 0x72657320: // 'res '
  38837. case 0x69686472: // 'ihdr'
  38838. break;
  38839. default:
  38840. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  38841. (tbox >> 16) & 0xFF,
  38842. (tbox >> 8) & 0xFF,
  38843. tbox & 0xFF);
  38844. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  38845. break;
  38846. }
  38847. if (jumpDataLength) {
  38848. position += dataLength;
  38849. }
  38850. }
  38851. },
  38852. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  38853. var newByte = stream.getByte();
  38854. while (newByte >= 0) {
  38855. var oldByte = newByte;
  38856. newByte = stream.getByte();
  38857. var code = (oldByte << 8) | newByte;
  38858. // Image and tile size (SIZ)
  38859. if (code === 0xFF51) {
  38860. stream.skip(4);
  38861. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  38862. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  38863. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  38864. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  38865. stream.skip(16);
  38866. var Csiz = stream.getUint16(); // Byte 36
  38867. this.width = Xsiz - XOsiz;
  38868. this.height = Ysiz - YOsiz;
  38869. this.componentsCount = Csiz;
  38870. // Results are always returned as Uint8Arrays
  38871. this.bitsPerComponent = 8;
  38872. return;
  38873. }
  38874. }
  38875. throw new Error('JPX Error: No size marker found in JPX stream');
  38876. },
  38877. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  38878. var context = {};
  38879. try {
  38880. var doNotRecover = false;
  38881. var position = start;
  38882. while (position + 1 < end) {
  38883. var code = readUint16(data, position);
  38884. position += 2;
  38885. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  38886. switch (code) {
  38887. case 0xFF4F: // Start of codestream (SOC)
  38888. context.mainHeader = true;
  38889. break;
  38890. case 0xFFD9: // End of codestream (EOC)
  38891. break;
  38892. case 0xFF51: // Image and tile size (SIZ)
  38893. length = readUint16(data, position);
  38894. var siz = {};
  38895. siz.Xsiz = readUint32(data, position + 4);
  38896. siz.Ysiz = readUint32(data, position + 8);
  38897. siz.XOsiz = readUint32(data, position + 12);
  38898. siz.YOsiz = readUint32(data, position + 16);
  38899. siz.XTsiz = readUint32(data, position + 20);
  38900. siz.YTsiz = readUint32(data, position + 24);
  38901. siz.XTOsiz = readUint32(data, position + 28);
  38902. siz.YTOsiz = readUint32(data, position + 32);
  38903. var componentsCount = readUint16(data, position + 36);
  38904. siz.Csiz = componentsCount;
  38905. var components = [];
  38906. j = position + 38;
  38907. for (var i = 0; i < componentsCount; i++) {
  38908. var component = {
  38909. precision: (data[j] & 0x7F) + 1,
  38910. isSigned: !!(data[j] & 0x80),
  38911. XRsiz: data[j + 1],
  38912. YRsiz: data[j + 1]
  38913. };
  38914. calculateComponentDimensions(component, siz);
  38915. components.push(component);
  38916. }
  38917. context.SIZ = siz;
  38918. context.components = components;
  38919. calculateTileGrids(context, components);
  38920. context.QCC = [];
  38921. context.COC = [];
  38922. break;
  38923. case 0xFF5C: // Quantization default (QCD)
  38924. length = readUint16(data, position);
  38925. var qcd = {};
  38926. j = position + 2;
  38927. sqcd = data[j++];
  38928. switch (sqcd & 0x1F) {
  38929. case 0:
  38930. spqcdSize = 8;
  38931. scalarExpounded = true;
  38932. break;
  38933. case 1:
  38934. spqcdSize = 16;
  38935. scalarExpounded = false;
  38936. break;
  38937. case 2:
  38938. spqcdSize = 16;
  38939. scalarExpounded = true;
  38940. break;
  38941. default:
  38942. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  38943. }
  38944. qcd.noQuantization = (spqcdSize === 8);
  38945. qcd.scalarExpounded = scalarExpounded;
  38946. qcd.guardBits = sqcd >> 5;
  38947. spqcds = [];
  38948. while (j < length + position) {
  38949. var spqcd = {};
  38950. if (spqcdSize === 8) {
  38951. spqcd.epsilon = data[j++] >> 3;
  38952. spqcd.mu = 0;
  38953. } else {
  38954. spqcd.epsilon = data[j] >> 3;
  38955. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  38956. j += 2;
  38957. }
  38958. spqcds.push(spqcd);
  38959. }
  38960. qcd.SPqcds = spqcds;
  38961. if (context.mainHeader) {
  38962. context.QCD = qcd;
  38963. } else {
  38964. context.currentTile.QCD = qcd;
  38965. context.currentTile.QCC = [];
  38966. }
  38967. break;
  38968. case 0xFF5D: // Quantization component (QCC)
  38969. length = readUint16(data, position);
  38970. var qcc = {};
  38971. j = position + 2;
  38972. var cqcc;
  38973. if (context.SIZ.Csiz < 257) {
  38974. cqcc = data[j++];
  38975. } else {
  38976. cqcc = readUint16(data, j);
  38977. j += 2;
  38978. }
  38979. sqcd = data[j++];
  38980. switch (sqcd & 0x1F) {
  38981. case 0:
  38982. spqcdSize = 8;
  38983. scalarExpounded = true;
  38984. break;
  38985. case 1:
  38986. spqcdSize = 16;
  38987. scalarExpounded = false;
  38988. break;
  38989. case 2:
  38990. spqcdSize = 16;
  38991. scalarExpounded = true;
  38992. break;
  38993. default:
  38994. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  38995. }
  38996. qcc.noQuantization = (spqcdSize === 8);
  38997. qcc.scalarExpounded = scalarExpounded;
  38998. qcc.guardBits = sqcd >> 5;
  38999. spqcds = [];
  39000. while (j < (length + position)) {
  39001. spqcd = {};
  39002. if (spqcdSize === 8) {
  39003. spqcd.epsilon = data[j++] >> 3;
  39004. spqcd.mu = 0;
  39005. } else {
  39006. spqcd.epsilon = data[j] >> 3;
  39007. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  39008. j += 2;
  39009. }
  39010. spqcds.push(spqcd);
  39011. }
  39012. qcc.SPqcds = spqcds;
  39013. if (context.mainHeader) {
  39014. context.QCC[cqcc] = qcc;
  39015. } else {
  39016. context.currentTile.QCC[cqcc] = qcc;
  39017. }
  39018. break;
  39019. case 0xFF52: // Coding style default (COD)
  39020. length = readUint16(data, position);
  39021. var cod = {};
  39022. j = position + 2;
  39023. var scod = data[j++];
  39024. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  39025. cod.sopMarkerUsed = !!(scod & 2);
  39026. cod.ephMarkerUsed = !!(scod & 4);
  39027. cod.progressionOrder = data[j++];
  39028. cod.layersCount = readUint16(data, j);
  39029. j += 2;
  39030. cod.multipleComponentTransform = data[j++];
  39031. cod.decompositionLevelsCount = data[j++];
  39032. cod.xcb = (data[j++] & 0xF) + 2;
  39033. cod.ycb = (data[j++] & 0xF) + 2;
  39034. var blockStyle = data[j++];
  39035. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  39036. cod.resetContextProbabilities = !!(blockStyle & 2);
  39037. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  39038. cod.verticalyStripe = !!(blockStyle & 8);
  39039. cod.predictableTermination = !!(blockStyle & 16);
  39040. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  39041. cod.reversibleTransformation = data[j++];
  39042. if (cod.entropyCoderWithCustomPrecincts) {
  39043. var precinctsSizes = [];
  39044. while (j < length + position) {
  39045. var precinctsSize = data[j++];
  39046. precinctsSizes.push({
  39047. PPx: precinctsSize & 0xF,
  39048. PPy: precinctsSize >> 4
  39049. });
  39050. }
  39051. cod.precinctsSizes = precinctsSizes;
  39052. }
  39053. var unsupported = [];
  39054. if (cod.selectiveArithmeticCodingBypass) {
  39055. unsupported.push('selectiveArithmeticCodingBypass');
  39056. }
  39057. if (cod.resetContextProbabilities) {
  39058. unsupported.push('resetContextProbabilities');
  39059. }
  39060. if (cod.terminationOnEachCodingPass) {
  39061. unsupported.push('terminationOnEachCodingPass');
  39062. }
  39063. if (cod.verticalyStripe) {
  39064. unsupported.push('verticalyStripe');
  39065. }
  39066. if (cod.predictableTermination) {
  39067. unsupported.push('predictableTermination');
  39068. }
  39069. if (unsupported.length > 0) {
  39070. doNotRecover = true;
  39071. throw new Error('JPX Error: Unsupported COD options (' +
  39072. unsupported.join(', ') + ')');
  39073. }
  39074. if (context.mainHeader) {
  39075. context.COD = cod;
  39076. } else {
  39077. context.currentTile.COD = cod;
  39078. context.currentTile.COC = [];
  39079. }
  39080. break;
  39081. case 0xFF90: // Start of tile-part (SOT)
  39082. length = readUint16(data, position);
  39083. tile = {};
  39084. tile.index = readUint16(data, position + 2);
  39085. tile.length = readUint32(data, position + 4);
  39086. tile.dataEnd = tile.length + position - 2;
  39087. tile.partIndex = data[position + 8];
  39088. tile.partsCount = data[position + 9];
  39089. context.mainHeader = false;
  39090. if (tile.partIndex === 0) {
  39091. // reset component specific settings
  39092. tile.COD = context.COD;
  39093. tile.COC = context.COC.slice(0); // clone of the global COC
  39094. tile.QCD = context.QCD;
  39095. tile.QCC = context.QCC.slice(0); // clone of the global COC
  39096. }
  39097. context.currentTile = tile;
  39098. break;
  39099. case 0xFF93: // Start of data (SOD)
  39100. tile = context.currentTile;
  39101. if (tile.partIndex === 0) {
  39102. initializeTile(context, tile.index);
  39103. buildPackets(context);
  39104. }
  39105. // moving to the end of the data
  39106. length = tile.dataEnd - position;
  39107. parseTilePackets(context, data, position, length);
  39108. break;
  39109. case 0xFF55: // Tile-part lengths, main header (TLM)
  39110. case 0xFF57: // Packet length, main header (PLM)
  39111. case 0xFF58: // Packet length, tile-part header (PLT)
  39112. case 0xFF64: // Comment (COM)
  39113. length = readUint16(data, position);
  39114. // skipping content
  39115. break;
  39116. case 0xFF53: // Coding style component (COC)
  39117. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  39118. 'not implemented');
  39119. default:
  39120. throw new Error('JPX Error: Unknown codestream code: ' +
  39121. code.toString(16));
  39122. }
  39123. position += length;
  39124. }
  39125. } catch (e) {
  39126. if (doNotRecover || this.failOnCorruptedImage) {
  39127. throw e;
  39128. } else {
  39129. warn('Trying to recover from ' + e.message);
  39130. }
  39131. }
  39132. this.tiles = transformComponents(context);
  39133. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  39134. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  39135. this.componentsCount = context.SIZ.Csiz;
  39136. }
  39137. };
  39138. function calculateComponentDimensions(component, siz) {
  39139. // Section B.2 Component mapping
  39140. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  39141. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  39142. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  39143. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  39144. component.width = component.x1 - component.x0;
  39145. component.height = component.y1 - component.y0;
  39146. }
  39147. function calculateTileGrids(context, components) {
  39148. var siz = context.SIZ;
  39149. // Section B.3 Division into tile and tile-components
  39150. var tile, tiles = [];
  39151. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  39152. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  39153. for (var q = 0; q < numYtiles; q++) {
  39154. for (var p = 0; p < numXtiles; p++) {
  39155. tile = {};
  39156. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  39157. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  39158. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  39159. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  39160. tile.width = tile.tx1 - tile.tx0;
  39161. tile.height = tile.ty1 - tile.ty0;
  39162. tile.components = [];
  39163. tiles.push(tile);
  39164. }
  39165. }
  39166. context.tiles = tiles;
  39167. var componentsCount = siz.Csiz;
  39168. for (var i = 0, ii = componentsCount; i < ii; i++) {
  39169. var component = components[i];
  39170. for (var j = 0, jj = tiles.length; j < jj; j++) {
  39171. var tileComponent = {};
  39172. tile = tiles[j];
  39173. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  39174. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  39175. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  39176. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  39177. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  39178. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  39179. tile.components[i] = tileComponent;
  39180. }
  39181. }
  39182. }
  39183. function getBlocksDimensions(context, component, r) {
  39184. var codOrCoc = component.codingStyleParameters;
  39185. var result = {};
  39186. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  39187. result.PPx = 15;
  39188. result.PPy = 15;
  39189. } else {
  39190. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  39191. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  39192. }
  39193. // calculate codeblock size as described in section B.7
  39194. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  39195. Math.min(codOrCoc.xcb, result.PPx));
  39196. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  39197. Math.min(codOrCoc.ycb, result.PPy));
  39198. return result;
  39199. }
  39200. function buildPrecincts(context, resolution, dimensions) {
  39201. // Section B.6 Division resolution to precincts
  39202. var precinctWidth = 1 << dimensions.PPx;
  39203. var precinctHeight = 1 << dimensions.PPy;
  39204. // Jasper introduces codeblock groups for mapping each subband codeblocks
  39205. // to precincts. Precinct partition divides a resolution according to width
  39206. // and height parameters. The subband that belongs to the resolution level
  39207. // has a different size than the level, unless it is the zero resolution.
  39208. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  39209. // The precinct partitioning for a particular subband is derived from a
  39210. // partitioning of its parent LL band (i.e., the LL band at the next higher
  39211. // resolution level)... The LL band associated with each resolution level is
  39212. // divided into precincts... Each of the resulting precinct regions is then
  39213. // mapped into its child subbands (if any) at the next lower resolution
  39214. // level. This is accomplished by using the coordinate transformation
  39215. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  39216. // coordinates of a point in the LL band and child subband, respectively.
  39217. var isZeroRes = resolution.resLevel === 0;
  39218. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  39219. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  39220. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  39221. Math.ceil(resolution.trx1 / precinctWidth) -
  39222. Math.floor(resolution.trx0 / precinctWidth) : 0);
  39223. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  39224. Math.ceil(resolution.try1 / precinctHeight) -
  39225. Math.floor(resolution.try0 / precinctHeight) : 0);
  39226. var numprecincts = numprecinctswide * numprecinctshigh;
  39227. resolution.precinctParameters = {
  39228. precinctWidth: precinctWidth,
  39229. precinctHeight: precinctHeight,
  39230. numprecinctswide: numprecinctswide,
  39231. numprecinctshigh: numprecinctshigh,
  39232. numprecincts: numprecincts,
  39233. precinctWidthInSubband: precinctWidthInSubband,
  39234. precinctHeightInSubband: precinctHeightInSubband
  39235. };
  39236. }
  39237. function buildCodeblocks(context, subband, dimensions) {
  39238. // Section B.7 Division sub-band into code-blocks
  39239. var xcb_ = dimensions.xcb_;
  39240. var ycb_ = dimensions.ycb_;
  39241. var codeblockWidth = 1 << xcb_;
  39242. var codeblockHeight = 1 << ycb_;
  39243. var cbx0 = subband.tbx0 >> xcb_;
  39244. var cby0 = subband.tby0 >> ycb_;
  39245. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  39246. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  39247. var precinctParameters = subband.resolution.precinctParameters;
  39248. var codeblocks = [];
  39249. var precincts = [];
  39250. var i, j, codeblock, precinctNumber;
  39251. for (j = cby0; j < cby1; j++) {
  39252. for (i = cbx0; i < cbx1; i++) {
  39253. codeblock = {
  39254. cbx: i,
  39255. cby: j,
  39256. tbx0: codeblockWidth * i,
  39257. tby0: codeblockHeight * j,
  39258. tbx1: codeblockWidth * (i + 1),
  39259. tby1: codeblockHeight * (j + 1)
  39260. };
  39261. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  39262. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  39263. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  39264. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  39265. // Calculate precinct number for this codeblock, codeblock position
  39266. // should be relative to its subband, use actual dimension and position
  39267. // See comment about codeblock group width and height
  39268. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  39269. precinctParameters.precinctWidthInSubband);
  39270. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  39271. precinctParameters.precinctHeightInSubband);
  39272. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  39273. codeblock.precinctNumber = precinctNumber;
  39274. codeblock.subbandType = subband.type;
  39275. codeblock.Lblock = 3;
  39276. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  39277. codeblock.tby1_ <= codeblock.tby0_) {
  39278. continue;
  39279. }
  39280. codeblocks.push(codeblock);
  39281. // building precinct for the sub-band
  39282. var precinct = precincts[precinctNumber];
  39283. if (precinct !== undefined) {
  39284. if (i < precinct.cbxMin) {
  39285. precinct.cbxMin = i;
  39286. } else if (i > precinct.cbxMax) {
  39287. precinct.cbxMax = i;
  39288. }
  39289. if (j < precinct.cbyMin) {
  39290. precinct.cbxMin = j;
  39291. } else if (j > precinct.cbyMax) {
  39292. precinct.cbyMax = j;
  39293. }
  39294. } else {
  39295. precincts[precinctNumber] = precinct = {
  39296. cbxMin: i,
  39297. cbyMin: j,
  39298. cbxMax: i,
  39299. cbyMax: j
  39300. };
  39301. }
  39302. codeblock.precinct = precinct;
  39303. }
  39304. }
  39305. subband.codeblockParameters = {
  39306. codeblockWidth: xcb_,
  39307. codeblockHeight: ycb_,
  39308. numcodeblockwide: cbx1 - cbx0 + 1,
  39309. numcodeblockhigh: cby1 - cby0 + 1
  39310. };
  39311. subband.codeblocks = codeblocks;
  39312. subband.precincts = precincts;
  39313. }
  39314. function createPacket(resolution, precinctNumber, layerNumber) {
  39315. var precinctCodeblocks = [];
  39316. // Section B.10.8 Order of info in packet
  39317. var subbands = resolution.subbands;
  39318. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  39319. for (var i = 0, ii = subbands.length; i < ii; i++) {
  39320. var subband = subbands[i];
  39321. var codeblocks = subband.codeblocks;
  39322. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  39323. var codeblock = codeblocks[j];
  39324. if (codeblock.precinctNumber !== precinctNumber) {
  39325. continue;
  39326. }
  39327. precinctCodeblocks.push(codeblock);
  39328. }
  39329. }
  39330. return {
  39331. layerNumber: layerNumber,
  39332. codeblocks: precinctCodeblocks
  39333. };
  39334. }
  39335. function LayerResolutionComponentPositionIterator(context) {
  39336. var siz = context.SIZ;
  39337. var tileIndex = context.currentTile.index;
  39338. var tile = context.tiles[tileIndex];
  39339. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39340. var componentsCount = siz.Csiz;
  39341. var maxDecompositionLevelsCount = 0;
  39342. for (var q = 0; q < componentsCount; q++) {
  39343. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39344. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39345. }
  39346. var l = 0, r = 0, i = 0, k = 0;
  39347. this.nextPacket = function JpxImage_nextPacket() {
  39348. // Section B.12.1.1 Layer-resolution-component-position
  39349. for (; l < layersCount; l++) {
  39350. for (; r <= maxDecompositionLevelsCount; r++) {
  39351. for (; i < componentsCount; i++) {
  39352. var component = tile.components[i];
  39353. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39354. continue;
  39355. }
  39356. var resolution = component.resolutions[r];
  39357. var numprecincts = resolution.precinctParameters.numprecincts;
  39358. for (; k < numprecincts;) {
  39359. var packet = createPacket(resolution, k, l);
  39360. k++;
  39361. return packet;
  39362. }
  39363. k = 0;
  39364. }
  39365. i = 0;
  39366. }
  39367. r = 0;
  39368. }
  39369. throw new Error('JPX Error: Out of packets');
  39370. };
  39371. }
  39372. function ResolutionLayerComponentPositionIterator(context) {
  39373. var siz = context.SIZ;
  39374. var tileIndex = context.currentTile.index;
  39375. var tile = context.tiles[tileIndex];
  39376. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39377. var componentsCount = siz.Csiz;
  39378. var maxDecompositionLevelsCount = 0;
  39379. for (var q = 0; q < componentsCount; q++) {
  39380. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39381. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  39382. }
  39383. var r = 0, l = 0, i = 0, k = 0;
  39384. this.nextPacket = function JpxImage_nextPacket() {
  39385. // Section B.12.1.2 Resolution-layer-component-position
  39386. for (; r <= maxDecompositionLevelsCount; r++) {
  39387. for (; l < layersCount; l++) {
  39388. for (; i < componentsCount; i++) {
  39389. var component = tile.components[i];
  39390. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39391. continue;
  39392. }
  39393. var resolution = component.resolutions[r];
  39394. var numprecincts = resolution.precinctParameters.numprecincts;
  39395. for (; k < numprecincts;) {
  39396. var packet = createPacket(resolution, k, l);
  39397. k++;
  39398. return packet;
  39399. }
  39400. k = 0;
  39401. }
  39402. i = 0;
  39403. }
  39404. l = 0;
  39405. }
  39406. throw new Error('JPX Error: Out of packets');
  39407. };
  39408. }
  39409. function ResolutionPositionComponentLayerIterator(context) {
  39410. var siz = context.SIZ;
  39411. var tileIndex = context.currentTile.index;
  39412. var tile = context.tiles[tileIndex];
  39413. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39414. var componentsCount = siz.Csiz;
  39415. var l, r, c, p;
  39416. var maxDecompositionLevelsCount = 0;
  39417. for (c = 0; c < componentsCount; c++) {
  39418. var component = tile.components[c];
  39419. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  39420. component.codingStyleParameters.decompositionLevelsCount);
  39421. }
  39422. var maxNumPrecinctsInLevel = new Int32Array(
  39423. maxDecompositionLevelsCount + 1);
  39424. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  39425. var maxNumPrecincts = 0;
  39426. for (c = 0; c < componentsCount; ++c) {
  39427. var resolutions = tile.components[c].resolutions;
  39428. if (r < resolutions.length) {
  39429. maxNumPrecincts = Math.max(maxNumPrecincts,
  39430. resolutions[r].precinctParameters.numprecincts);
  39431. }
  39432. }
  39433. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  39434. }
  39435. l = 0;
  39436. r = 0;
  39437. c = 0;
  39438. p = 0;
  39439. this.nextPacket = function JpxImage_nextPacket() {
  39440. // Section B.12.1.3 Resolution-position-component-layer
  39441. for (; r <= maxDecompositionLevelsCount; r++) {
  39442. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  39443. for (; c < componentsCount; c++) {
  39444. var component = tile.components[c];
  39445. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  39446. continue;
  39447. }
  39448. var resolution = component.resolutions[r];
  39449. var numprecincts = resolution.precinctParameters.numprecincts;
  39450. if (p >= numprecincts) {
  39451. continue;
  39452. }
  39453. for (; l < layersCount;) {
  39454. var packet = createPacket(resolution, p, l);
  39455. l++;
  39456. return packet;
  39457. }
  39458. l = 0;
  39459. }
  39460. c = 0;
  39461. }
  39462. p = 0;
  39463. }
  39464. throw new Error('JPX Error: Out of packets');
  39465. };
  39466. }
  39467. function PositionComponentResolutionLayerIterator(context) {
  39468. var siz = context.SIZ;
  39469. var tileIndex = context.currentTile.index;
  39470. var tile = context.tiles[tileIndex];
  39471. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39472. var componentsCount = siz.Csiz;
  39473. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39474. var precinctsIterationSizes = precinctsSizes;
  39475. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39476. this.nextPacket = function JpxImage_nextPacket() {
  39477. // Section B.12.1.4 Position-component-resolution-layer
  39478. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39479. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39480. for (; c < componentsCount; c++) {
  39481. var component = tile.components[c];
  39482. var decompositionLevelsCount =
  39483. component.codingStyleParameters.decompositionLevelsCount;
  39484. for (; r <= decompositionLevelsCount; r++) {
  39485. var resolution = component.resolutions[r];
  39486. var sizeInImageScale =
  39487. precinctsSizes.components[c].resolutions[r];
  39488. var k = getPrecinctIndexIfExist(
  39489. px,
  39490. py,
  39491. sizeInImageScale,
  39492. precinctsIterationSizes,
  39493. resolution);
  39494. if (k === null) {
  39495. continue;
  39496. }
  39497. for (; l < layersCount;) {
  39498. var packet = createPacket(resolution, k, l);
  39499. l++;
  39500. return packet;
  39501. }
  39502. l = 0;
  39503. }
  39504. r = 0;
  39505. }
  39506. c = 0;
  39507. }
  39508. px = 0;
  39509. }
  39510. throw new Error('JPX Error: Out of packets');
  39511. };
  39512. }
  39513. function ComponentPositionResolutionLayerIterator(context) {
  39514. var siz = context.SIZ;
  39515. var tileIndex = context.currentTile.index;
  39516. var tile = context.tiles[tileIndex];
  39517. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  39518. var componentsCount = siz.Csiz;
  39519. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  39520. var l = 0, r = 0, c = 0, px = 0, py = 0;
  39521. this.nextPacket = function JpxImage_nextPacket() {
  39522. // Section B.12.1.5 Component-position-resolution-layer
  39523. for (; c < componentsCount; ++c) {
  39524. var component = tile.components[c];
  39525. var precinctsIterationSizes = precinctsSizes.components[c];
  39526. var decompositionLevelsCount =
  39527. component.codingStyleParameters.decompositionLevelsCount;
  39528. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  39529. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  39530. for (; r <= decompositionLevelsCount; r++) {
  39531. var resolution = component.resolutions[r];
  39532. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  39533. var k = getPrecinctIndexIfExist(
  39534. px,
  39535. py,
  39536. sizeInImageScale,
  39537. precinctsIterationSizes,
  39538. resolution);
  39539. if (k === null) {
  39540. continue;
  39541. }
  39542. for (; l < layersCount;) {
  39543. var packet = createPacket(resolution, k, l);
  39544. l++;
  39545. return packet;
  39546. }
  39547. l = 0;
  39548. }
  39549. r = 0;
  39550. }
  39551. px = 0;
  39552. }
  39553. py = 0;
  39554. }
  39555. throw new Error('JPX Error: Out of packets');
  39556. };
  39557. }
  39558. function getPrecinctIndexIfExist(
  39559. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  39560. var posX = pxIndex * precinctIterationSizes.minWidth;
  39561. var posY = pyIndex * precinctIterationSizes.minHeight;
  39562. if (posX % sizeInImageScale.width !== 0 ||
  39563. posY % sizeInImageScale.height !== 0) {
  39564. return null;
  39565. }
  39566. var startPrecinctRowIndex =
  39567. (posY / sizeInImageScale.width) *
  39568. resolution.precinctParameters.numprecinctswide;
  39569. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  39570. }
  39571. function getPrecinctSizesInImageScale(tile) {
  39572. var componentsCount = tile.components.length;
  39573. var minWidth = Number.MAX_VALUE;
  39574. var minHeight = Number.MAX_VALUE;
  39575. var maxNumWide = 0;
  39576. var maxNumHigh = 0;
  39577. var sizePerComponent = new Array(componentsCount);
  39578. for (var c = 0; c < componentsCount; c++) {
  39579. var component = tile.components[c];
  39580. var decompositionLevelsCount =
  39581. component.codingStyleParameters.decompositionLevelsCount;
  39582. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  39583. var minWidthCurrentComponent = Number.MAX_VALUE;
  39584. var minHeightCurrentComponent = Number.MAX_VALUE;
  39585. var maxNumWideCurrentComponent = 0;
  39586. var maxNumHighCurrentComponent = 0;
  39587. var scale = 1;
  39588. for (var r = decompositionLevelsCount; r >= 0; --r) {
  39589. var resolution = component.resolutions[r];
  39590. var widthCurrentResolution =
  39591. scale * resolution.precinctParameters.precinctWidth;
  39592. var heightCurrentResolution =
  39593. scale * resolution.precinctParameters.precinctHeight;
  39594. minWidthCurrentComponent = Math.min(
  39595. minWidthCurrentComponent,
  39596. widthCurrentResolution);
  39597. minHeightCurrentComponent = Math.min(
  39598. minHeightCurrentComponent,
  39599. heightCurrentResolution);
  39600. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  39601. resolution.precinctParameters.numprecinctswide);
  39602. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  39603. resolution.precinctParameters.numprecinctshigh);
  39604. sizePerResolution[r] = {
  39605. width: widthCurrentResolution,
  39606. height: heightCurrentResolution
  39607. };
  39608. scale <<= 1;
  39609. }
  39610. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  39611. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  39612. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  39613. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  39614. sizePerComponent[c] = {
  39615. resolutions: sizePerResolution,
  39616. minWidth: minWidthCurrentComponent,
  39617. minHeight: minHeightCurrentComponent,
  39618. maxNumWide: maxNumWideCurrentComponent,
  39619. maxNumHigh: maxNumHighCurrentComponent
  39620. };
  39621. }
  39622. return {
  39623. components: sizePerComponent,
  39624. minWidth: minWidth,
  39625. minHeight: minHeight,
  39626. maxNumWide: maxNumWide,
  39627. maxNumHigh: maxNumHigh
  39628. };
  39629. }
  39630. function buildPackets(context) {
  39631. var siz = context.SIZ;
  39632. var tileIndex = context.currentTile.index;
  39633. var tile = context.tiles[tileIndex];
  39634. var componentsCount = siz.Csiz;
  39635. // Creating resolutions and sub-bands for each component
  39636. for (var c = 0; c < componentsCount; c++) {
  39637. var component = tile.components[c];
  39638. var decompositionLevelsCount =
  39639. component.codingStyleParameters.decompositionLevelsCount;
  39640. // Section B.5 Resolution levels and sub-bands
  39641. var resolutions = [];
  39642. var subbands = [];
  39643. for (var r = 0; r <= decompositionLevelsCount; r++) {
  39644. var blocksDimensions = getBlocksDimensions(context, component, r);
  39645. var resolution = {};
  39646. var scale = 1 << (decompositionLevelsCount - r);
  39647. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  39648. resolution.try0 = Math.ceil(component.tcy0 / scale);
  39649. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  39650. resolution.try1 = Math.ceil(component.tcy1 / scale);
  39651. resolution.resLevel = r;
  39652. buildPrecincts(context, resolution, blocksDimensions);
  39653. resolutions.push(resolution);
  39654. var subband;
  39655. if (r === 0) {
  39656. // one sub-band (LL) with last decomposition
  39657. subband = {};
  39658. subband.type = 'LL';
  39659. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  39660. subband.tby0 = Math.ceil(component.tcy0 / scale);
  39661. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  39662. subband.tby1 = Math.ceil(component.tcy1 / scale);
  39663. subband.resolution = resolution;
  39664. buildCodeblocks(context, subband, blocksDimensions);
  39665. subbands.push(subband);
  39666. resolution.subbands = [subband];
  39667. } else {
  39668. var bscale = 1 << (decompositionLevelsCount - r + 1);
  39669. var resolutionSubbands = [];
  39670. // three sub-bands (HL, LH and HH) with rest of decompositions
  39671. subband = {};
  39672. subband.type = 'HL';
  39673. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39674. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  39675. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39676. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  39677. subband.resolution = resolution;
  39678. buildCodeblocks(context, subband, blocksDimensions);
  39679. subbands.push(subband);
  39680. resolutionSubbands.push(subband);
  39681. subband = {};
  39682. subband.type = 'LH';
  39683. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  39684. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39685. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  39686. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39687. subband.resolution = resolution;
  39688. buildCodeblocks(context, subband, blocksDimensions);
  39689. subbands.push(subband);
  39690. resolutionSubbands.push(subband);
  39691. subband = {};
  39692. subband.type = 'HH';
  39693. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  39694. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  39695. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  39696. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  39697. subband.resolution = resolution;
  39698. buildCodeblocks(context, subband, blocksDimensions);
  39699. subbands.push(subband);
  39700. resolutionSubbands.push(subband);
  39701. resolution.subbands = resolutionSubbands;
  39702. }
  39703. }
  39704. component.resolutions = resolutions;
  39705. component.subbands = subbands;
  39706. }
  39707. // Generate the packets sequence
  39708. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  39709. switch (progressionOrder) {
  39710. case 0:
  39711. tile.packetsIterator =
  39712. new LayerResolutionComponentPositionIterator(context);
  39713. break;
  39714. case 1:
  39715. tile.packetsIterator =
  39716. new ResolutionLayerComponentPositionIterator(context);
  39717. break;
  39718. case 2:
  39719. tile.packetsIterator =
  39720. new ResolutionPositionComponentLayerIterator(context);
  39721. break;
  39722. case 3:
  39723. tile.packetsIterator =
  39724. new PositionComponentResolutionLayerIterator(context);
  39725. break;
  39726. case 4:
  39727. tile.packetsIterator =
  39728. new ComponentPositionResolutionLayerIterator(context);
  39729. break;
  39730. default:
  39731. throw new Error('JPX Error: Unsupported progression order ' +
  39732. progressionOrder);
  39733. }
  39734. }
  39735. function parseTilePackets(context, data, offset, dataLength) {
  39736. var position = 0;
  39737. var buffer, bufferSize = 0, skipNextBit = false;
  39738. function readBits(count) {
  39739. while (bufferSize < count) {
  39740. var b = data[offset + position];
  39741. position++;
  39742. if (skipNextBit) {
  39743. buffer = (buffer << 7) | b;
  39744. bufferSize += 7;
  39745. skipNextBit = false;
  39746. } else {
  39747. buffer = (buffer << 8) | b;
  39748. bufferSize += 8;
  39749. }
  39750. if (b === 0xFF) {
  39751. skipNextBit = true;
  39752. }
  39753. }
  39754. bufferSize -= count;
  39755. return (buffer >>> bufferSize) & ((1 << count) - 1);
  39756. }
  39757. function skipMarkerIfEqual(value) {
  39758. if (data[offset + position - 1] === 0xFF &&
  39759. data[offset + position] === value) {
  39760. skipBytes(1);
  39761. return true;
  39762. } else if (data[offset + position] === 0xFF &&
  39763. data[offset + position + 1] === value) {
  39764. skipBytes(2);
  39765. return true;
  39766. }
  39767. return false;
  39768. }
  39769. function skipBytes(count) {
  39770. position += count;
  39771. }
  39772. function alignToByte() {
  39773. bufferSize = 0;
  39774. if (skipNextBit) {
  39775. position++;
  39776. skipNextBit = false;
  39777. }
  39778. }
  39779. function readCodingpasses() {
  39780. if (readBits(1) === 0) {
  39781. return 1;
  39782. }
  39783. if (readBits(1) === 0) {
  39784. return 2;
  39785. }
  39786. var value = readBits(2);
  39787. if (value < 3) {
  39788. return value + 3;
  39789. }
  39790. value = readBits(5);
  39791. if (value < 31) {
  39792. return value + 6;
  39793. }
  39794. value = readBits(7);
  39795. return value + 37;
  39796. }
  39797. var tileIndex = context.currentTile.index;
  39798. var tile = context.tiles[tileIndex];
  39799. var sopMarkerUsed = context.COD.sopMarkerUsed;
  39800. var ephMarkerUsed = context.COD.ephMarkerUsed;
  39801. var packetsIterator = tile.packetsIterator;
  39802. while (position < dataLength) {
  39803. alignToByte();
  39804. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  39805. // Skip also marker segment length and packet sequence ID
  39806. skipBytes(4);
  39807. }
  39808. var packet = packetsIterator.nextPacket();
  39809. if (!readBits(1)) {
  39810. continue;
  39811. }
  39812. var layerNumber = packet.layerNumber;
  39813. var queue = [], codeblock;
  39814. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  39815. codeblock = packet.codeblocks[i];
  39816. var precinct = codeblock.precinct;
  39817. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  39818. var codeblockRow = codeblock.cby - precinct.cbyMin;
  39819. var codeblockIncluded = false;
  39820. var firstTimeInclusion = false;
  39821. var valueReady;
  39822. if (codeblock['included'] !== undefined) {
  39823. codeblockIncluded = !!readBits(1);
  39824. } else {
  39825. // reading inclusion tree
  39826. precinct = codeblock.precinct;
  39827. var inclusionTree, zeroBitPlanesTree;
  39828. if (precinct['inclusionTree'] !== undefined) {
  39829. inclusionTree = precinct.inclusionTree;
  39830. } else {
  39831. // building inclusion and zero bit-planes trees
  39832. var width = precinct.cbxMax - precinct.cbxMin + 1;
  39833. var height = precinct.cbyMax - precinct.cbyMin + 1;
  39834. inclusionTree = new InclusionTree(width, height, layerNumber);
  39835. zeroBitPlanesTree = new TagTree(width, height);
  39836. precinct.inclusionTree = inclusionTree;
  39837. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  39838. }
  39839. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  39840. while (true) {
  39841. if (readBits(1)) {
  39842. valueReady = !inclusionTree.nextLevel();
  39843. if (valueReady) {
  39844. codeblock.included = true;
  39845. codeblockIncluded = firstTimeInclusion = true;
  39846. break;
  39847. }
  39848. } else {
  39849. inclusionTree.incrementValue(layerNumber);
  39850. break;
  39851. }
  39852. }
  39853. }
  39854. }
  39855. if (!codeblockIncluded) {
  39856. continue;
  39857. }
  39858. if (firstTimeInclusion) {
  39859. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  39860. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  39861. while (true) {
  39862. if (readBits(1)) {
  39863. valueReady = !zeroBitPlanesTree.nextLevel();
  39864. if (valueReady) {
  39865. break;
  39866. }
  39867. } else {
  39868. zeroBitPlanesTree.incrementValue();
  39869. }
  39870. }
  39871. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  39872. }
  39873. var codingpasses = readCodingpasses();
  39874. while (readBits(1)) {
  39875. codeblock.Lblock++;
  39876. }
  39877. var codingpassesLog2 = log2(codingpasses);
  39878. // rounding down log2
  39879. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  39880. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  39881. var codedDataLength = readBits(bits);
  39882. queue.push({
  39883. codeblock: codeblock,
  39884. codingpasses: codingpasses,
  39885. dataLength: codedDataLength
  39886. });
  39887. }
  39888. alignToByte();
  39889. if (ephMarkerUsed) {
  39890. skipMarkerIfEqual(0x92);
  39891. }
  39892. while (queue.length > 0) {
  39893. var packetItem = queue.shift();
  39894. codeblock = packetItem.codeblock;
  39895. if (codeblock['data'] === undefined) {
  39896. codeblock.data = [];
  39897. }
  39898. codeblock.data.push({
  39899. data: data,
  39900. start: offset + position,
  39901. end: offset + position + packetItem.dataLength,
  39902. codingpasses: packetItem.codingpasses
  39903. });
  39904. position += packetItem.dataLength;
  39905. }
  39906. }
  39907. return position;
  39908. }
  39909. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  39910. delta, mb, reversible, segmentationSymbolUsed) {
  39911. var x0 = subband.tbx0;
  39912. var y0 = subband.tby0;
  39913. var width = subband.tbx1 - subband.tbx0;
  39914. var codeblocks = subband.codeblocks;
  39915. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  39916. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  39917. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  39918. var codeblock = codeblocks[i];
  39919. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  39920. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  39921. if (blockWidth === 0 || blockHeight === 0) {
  39922. continue;
  39923. }
  39924. if (codeblock['data'] === undefined) {
  39925. continue;
  39926. }
  39927. var bitModel, currentCodingpassType;
  39928. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  39929. codeblock.zeroBitPlanes, mb);
  39930. currentCodingpassType = 2; // first bit plane starts from cleanup
  39931. // collect data
  39932. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  39933. var j, jj, dataItem;
  39934. for (j = 0, jj = data.length; j < jj; j++) {
  39935. dataItem = data[j];
  39936. totalLength += dataItem.end - dataItem.start;
  39937. codingpasses += dataItem.codingpasses;
  39938. }
  39939. var encodedData = new Uint8Array(totalLength);
  39940. var position = 0;
  39941. for (j = 0, jj = data.length; j < jj; j++) {
  39942. dataItem = data[j];
  39943. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  39944. encodedData.set(chunk, position);
  39945. position += chunk.length;
  39946. }
  39947. // decoding the item
  39948. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  39949. bitModel.setDecoder(decoder);
  39950. for (j = 0; j < codingpasses; j++) {
  39951. switch (currentCodingpassType) {
  39952. case 0:
  39953. bitModel.runSignificancePropogationPass();
  39954. break;
  39955. case 1:
  39956. bitModel.runMagnitudeRefinementPass();
  39957. break;
  39958. case 2:
  39959. bitModel.runCleanupPass();
  39960. if (segmentationSymbolUsed) {
  39961. bitModel.checkSegmentationSymbol();
  39962. }
  39963. break;
  39964. }
  39965. currentCodingpassType = (currentCodingpassType + 1) % 3;
  39966. }
  39967. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  39968. var sign = bitModel.coefficentsSign;
  39969. var magnitude = bitModel.coefficentsMagnitude;
  39970. var bitsDecoded = bitModel.bitsDecoded;
  39971. var magnitudeCorrection = reversible ? 0 : 0.5;
  39972. var k, n, nb;
  39973. position = 0;
  39974. // Do the interleaving of Section F.3.3 here, so we do not need
  39975. // to copy later. LL level is not interleaved, just copied.
  39976. var interleave = (subband.type !== 'LL');
  39977. for (j = 0; j < blockHeight; j++) {
  39978. var row = (offset / width) | 0; // row in the non-interleaved subband
  39979. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  39980. for (k = 0; k < blockWidth; k++) {
  39981. n = magnitude[position];
  39982. if (n !== 0) {
  39983. n = (n + magnitudeCorrection) * delta;
  39984. if (sign[position] !== 0) {
  39985. n = -n;
  39986. }
  39987. nb = bitsDecoded[position];
  39988. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  39989. if (reversible && (nb >= mb)) {
  39990. coefficients[pos] = n;
  39991. } else {
  39992. coefficients[pos] = n * (1 << (mb - nb));
  39993. }
  39994. }
  39995. offset++;
  39996. position++;
  39997. }
  39998. offset += width - blockWidth;
  39999. }
  40000. }
  40001. }
  40002. function transformTile(context, tile, c) {
  40003. var component = tile.components[c];
  40004. var codingStyleParameters = component.codingStyleParameters;
  40005. var quantizationParameters = component.quantizationParameters;
  40006. var decompositionLevelsCount =
  40007. codingStyleParameters.decompositionLevelsCount;
  40008. var spqcds = quantizationParameters.SPqcds;
  40009. var scalarExpounded = quantizationParameters.scalarExpounded;
  40010. var guardBits = quantizationParameters.guardBits;
  40011. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  40012. var precision = context.components[c].precision;
  40013. var reversible = codingStyleParameters.reversibleTransformation;
  40014. var transform = (reversible ? new ReversibleTransform() :
  40015. new IrreversibleTransform());
  40016. var subbandCoefficients = [];
  40017. var b = 0;
  40018. for (var i = 0; i <= decompositionLevelsCount; i++) {
  40019. var resolution = component.resolutions[i];
  40020. var width = resolution.trx1 - resolution.trx0;
  40021. var height = resolution.try1 - resolution.try0;
  40022. // Allocate space for the whole sublevel.
  40023. var coefficients = new Float32Array(width * height);
  40024. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  40025. var mu, epsilon;
  40026. if (!scalarExpounded) {
  40027. // formula E-5
  40028. mu = spqcds[0].mu;
  40029. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  40030. } else {
  40031. mu = spqcds[b].mu;
  40032. epsilon = spqcds[b].epsilon;
  40033. b++;
  40034. }
  40035. var subband = resolution.subbands[j];
  40036. var gainLog2 = SubbandsGainLog2[subband.type];
  40037. // calulate quantization coefficient (Section E.1.1.1)
  40038. var delta = (reversible ? 1 :
  40039. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  40040. var mb = (guardBits + epsilon - 1);
  40041. // In the first resolution level, copyCoefficients will fill the
  40042. // whole array with coefficients. In the succeding passes,
  40043. // copyCoefficients will consecutively fill in the values that belong
  40044. // to the interleaved positions of the HL, LH, and HH coefficients.
  40045. // The LL coefficients will then be interleaved in Transform.iterate().
  40046. copyCoefficients(coefficients, width, height, subband, delta, mb,
  40047. reversible, segmentationSymbolUsed);
  40048. }
  40049. subbandCoefficients.push({
  40050. width: width,
  40051. height: height,
  40052. items: coefficients
  40053. });
  40054. }
  40055. var result = transform.calculate(subbandCoefficients,
  40056. component.tcx0, component.tcy0);
  40057. return {
  40058. left: component.tcx0,
  40059. top: component.tcy0,
  40060. width: result.width,
  40061. height: result.height,
  40062. items: result.items
  40063. };
  40064. }
  40065. function transformComponents(context) {
  40066. var siz = context.SIZ;
  40067. var components = context.components;
  40068. var componentsCount = siz.Csiz;
  40069. var resultImages = [];
  40070. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  40071. var tile = context.tiles[i];
  40072. var transformedTiles = [];
  40073. var c;
  40074. for (c = 0; c < componentsCount; c++) {
  40075. transformedTiles[c] = transformTile(context, tile, c);
  40076. }
  40077. var tile0 = transformedTiles[0];
  40078. var out = new Uint8Array(tile0.items.length * componentsCount);
  40079. var result = {
  40080. left: tile0.left,
  40081. top: tile0.top,
  40082. width: tile0.width,
  40083. height: tile0.height,
  40084. items: out
  40085. };
  40086. // Section G.2.2 Inverse multi component transform
  40087. var shift, offset, max, min, maxK;
  40088. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  40089. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  40090. var fourComponents = componentsCount === 4;
  40091. var y0items = transformedTiles[0].items;
  40092. var y1items = transformedTiles[1].items;
  40093. var y2items = transformedTiles[2].items;
  40094. var y3items = fourComponents ? transformedTiles[3].items : null;
  40095. // HACK: The multiple component transform formulas below assume that
  40096. // all components have the same precision. With this in mind, we
  40097. // compute shift and offset only once.
  40098. shift = components[0].precision - 8;
  40099. offset = (128 << shift) + 0.5;
  40100. max = 255 * (1 << shift);
  40101. maxK = max * 0.5;
  40102. min = -maxK;
  40103. var component0 = tile.components[0];
  40104. var alpha01 = componentsCount - 3;
  40105. jj = y0items.length;
  40106. if (!component0.codingStyleParameters.reversibleTransformation) {
  40107. // inverse irreversible multiple component transform
  40108. for (j = 0; j < jj; j++, pos += alpha01) {
  40109. y0 = y0items[j] + offset;
  40110. y1 = y1items[j];
  40111. y2 = y2items[j];
  40112. r = y0 + 1.402 * y2;
  40113. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  40114. b = y0 + 1.772 * y1;
  40115. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40116. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40117. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40118. }
  40119. } else {
  40120. // inverse reversible multiple component transform
  40121. for (j = 0; j < jj; j++, pos += alpha01) {
  40122. y0 = y0items[j] + offset;
  40123. y1 = y1items[j];
  40124. y2 = y2items[j];
  40125. g = y0 - ((y2 + y1) >> 2);
  40126. r = g + y2;
  40127. b = g + y1;
  40128. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  40129. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  40130. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  40131. }
  40132. }
  40133. if (fourComponents) {
  40134. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  40135. k = y3items[j];
  40136. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  40137. }
  40138. }
  40139. } else { // no multi-component transform
  40140. for (c = 0; c < componentsCount; c++) {
  40141. var items = transformedTiles[c].items;
  40142. shift = components[c].precision - 8;
  40143. offset = (128 << shift) + 0.5;
  40144. max = (127.5 * (1 << shift));
  40145. min = -max;
  40146. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  40147. val = items[j];
  40148. out[pos] = val <= min ? 0 :
  40149. val >= max ? 255 : (val + offset) >> shift;
  40150. pos += componentsCount;
  40151. }
  40152. }
  40153. }
  40154. resultImages.push(result);
  40155. }
  40156. return resultImages;
  40157. }
  40158. function initializeTile(context, tileIndex) {
  40159. var siz = context.SIZ;
  40160. var componentsCount = siz.Csiz;
  40161. var tile = context.tiles[tileIndex];
  40162. for (var c = 0; c < componentsCount; c++) {
  40163. var component = tile.components[c];
  40164. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  40165. context.currentTile.QCC[c] : context.currentTile.QCD);
  40166. component.quantizationParameters = qcdOrQcc;
  40167. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  40168. context.currentTile.COC[c] : context.currentTile.COD);
  40169. component.codingStyleParameters = codOrCoc;
  40170. }
  40171. tile.codingStyleDefaultParameters = context.currentTile.COD;
  40172. }
  40173. // Section B.10.2 Tag trees
  40174. var TagTree = (function TagTreeClosure() {
  40175. function TagTree(width, height) {
  40176. var levelsLength = log2(Math.max(width, height)) + 1;
  40177. this.levels = [];
  40178. for (var i = 0; i < levelsLength; i++) {
  40179. var level = {
  40180. width: width,
  40181. height: height,
  40182. items: []
  40183. };
  40184. this.levels.push(level);
  40185. width = Math.ceil(width / 2);
  40186. height = Math.ceil(height / 2);
  40187. }
  40188. }
  40189. TagTree.prototype = {
  40190. reset: function TagTree_reset(i, j) {
  40191. var currentLevel = 0, value = 0, level;
  40192. while (currentLevel < this.levels.length) {
  40193. level = this.levels[currentLevel];
  40194. var index = i + j * level.width;
  40195. if (level.items[index] !== undefined) {
  40196. value = level.items[index];
  40197. break;
  40198. }
  40199. level.index = index;
  40200. i >>= 1;
  40201. j >>= 1;
  40202. currentLevel++;
  40203. }
  40204. currentLevel--;
  40205. level = this.levels[currentLevel];
  40206. level.items[level.index] = value;
  40207. this.currentLevel = currentLevel;
  40208. delete this.value;
  40209. },
  40210. incrementValue: function TagTree_incrementValue() {
  40211. var level = this.levels[this.currentLevel];
  40212. level.items[level.index]++;
  40213. },
  40214. nextLevel: function TagTree_nextLevel() {
  40215. var currentLevel = this.currentLevel;
  40216. var level = this.levels[currentLevel];
  40217. var value = level.items[level.index];
  40218. currentLevel--;
  40219. if (currentLevel < 0) {
  40220. this.value = value;
  40221. return false;
  40222. }
  40223. this.currentLevel = currentLevel;
  40224. level = this.levels[currentLevel];
  40225. level.items[level.index] = value;
  40226. return true;
  40227. }
  40228. };
  40229. return TagTree;
  40230. })();
  40231. var InclusionTree = (function InclusionTreeClosure() {
  40232. function InclusionTree(width, height, defaultValue) {
  40233. var levelsLength = log2(Math.max(width, height)) + 1;
  40234. this.levels = [];
  40235. for (var i = 0; i < levelsLength; i++) {
  40236. var items = new Uint8Array(width * height);
  40237. for (var j = 0, jj = items.length; j < jj; j++) {
  40238. items[j] = defaultValue;
  40239. }
  40240. var level = {
  40241. width: width,
  40242. height: height,
  40243. items: items
  40244. };
  40245. this.levels.push(level);
  40246. width = Math.ceil(width / 2);
  40247. height = Math.ceil(height / 2);
  40248. }
  40249. }
  40250. InclusionTree.prototype = {
  40251. reset: function InclusionTree_reset(i, j, stopValue) {
  40252. var currentLevel = 0;
  40253. while (currentLevel < this.levels.length) {
  40254. var level = this.levels[currentLevel];
  40255. var index = i + j * level.width;
  40256. level.index = index;
  40257. var value = level.items[index];
  40258. if (value === 0xFF) {
  40259. break;
  40260. }
  40261. if (value > stopValue) {
  40262. this.currentLevel = currentLevel;
  40263. // already know about this one, propagating the value to top levels
  40264. this.propagateValues();
  40265. return false;
  40266. }
  40267. i >>= 1;
  40268. j >>= 1;
  40269. currentLevel++;
  40270. }
  40271. this.currentLevel = currentLevel - 1;
  40272. return true;
  40273. },
  40274. incrementValue: function InclusionTree_incrementValue(stopValue) {
  40275. var level = this.levels[this.currentLevel];
  40276. level.items[level.index] = stopValue + 1;
  40277. this.propagateValues();
  40278. },
  40279. propagateValues: function InclusionTree_propagateValues() {
  40280. var levelIndex = this.currentLevel;
  40281. var level = this.levels[levelIndex];
  40282. var currentValue = level.items[level.index];
  40283. while (--levelIndex >= 0) {
  40284. level = this.levels[levelIndex];
  40285. level.items[level.index] = currentValue;
  40286. }
  40287. },
  40288. nextLevel: function InclusionTree_nextLevel() {
  40289. var currentLevel = this.currentLevel;
  40290. var level = this.levels[currentLevel];
  40291. var value = level.items[level.index];
  40292. level.items[level.index] = 0xFF;
  40293. currentLevel--;
  40294. if (currentLevel < 0) {
  40295. return false;
  40296. }
  40297. this.currentLevel = currentLevel;
  40298. level = this.levels[currentLevel];
  40299. level.items[level.index] = value;
  40300. return true;
  40301. }
  40302. };
  40303. return InclusionTree;
  40304. })();
  40305. // Section D. Coefficient bit modeling
  40306. var BitModel = (function BitModelClosure() {
  40307. var UNIFORM_CONTEXT = 17;
  40308. var RUNLENGTH_CONTEXT = 18;
  40309. // Table D-1
  40310. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  40311. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  40312. var LLAndLHContextsLabel = new Uint8Array([
  40313. 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,
  40314. 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,
  40315. 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
  40316. ]);
  40317. var HLContextLabel = new Uint8Array([
  40318. 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,
  40319. 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,
  40320. 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
  40321. ]);
  40322. var HHContextLabel = new Uint8Array([
  40323. 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,
  40324. 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,
  40325. 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
  40326. ]);
  40327. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  40328. this.width = width;
  40329. this.height = height;
  40330. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  40331. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  40332. var coefficientCount = width * height;
  40333. // coefficients outside the encoding region treated as insignificant
  40334. // add border state cells for significanceState
  40335. this.neighborsSignificance = new Uint8Array(coefficientCount);
  40336. this.coefficentsSign = new Uint8Array(coefficientCount);
  40337. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  40338. mb > 6 ? new Uint16Array(coefficientCount) :
  40339. new Uint8Array(coefficientCount);
  40340. this.processingFlags = new Uint8Array(coefficientCount);
  40341. var bitsDecoded = new Uint8Array(coefficientCount);
  40342. if (zeroBitPlanes !== 0) {
  40343. for (var i = 0; i < coefficientCount; i++) {
  40344. bitsDecoded[i] = zeroBitPlanes;
  40345. }
  40346. }
  40347. this.bitsDecoded = bitsDecoded;
  40348. this.reset();
  40349. }
  40350. BitModel.prototype = {
  40351. setDecoder: function BitModel_setDecoder(decoder) {
  40352. this.decoder = decoder;
  40353. },
  40354. reset: function BitModel_reset() {
  40355. // We have 17 contexts that are accessed via context labels,
  40356. // plus the uniform and runlength context.
  40357. this.contexts = new Int8Array(19);
  40358. // Contexts are packed into 1 byte:
  40359. // highest 7 bits carry the index, lowest bit carries mps
  40360. this.contexts[0] = (4 << 1) | 0;
  40361. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  40362. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  40363. },
  40364. setNeighborsSignificance:
  40365. function BitModel_setNeighborsSignificance(row, column, index) {
  40366. var neighborsSignificance = this.neighborsSignificance;
  40367. var width = this.width, height = this.height;
  40368. var left = (column > 0);
  40369. var right = (column + 1 < width);
  40370. var i;
  40371. if (row > 0) {
  40372. i = index - width;
  40373. if (left) {
  40374. neighborsSignificance[i - 1] += 0x10;
  40375. }
  40376. if (right) {
  40377. neighborsSignificance[i + 1] += 0x10;
  40378. }
  40379. neighborsSignificance[i] += 0x04;
  40380. }
  40381. if (row + 1 < height) {
  40382. i = index + width;
  40383. if (left) {
  40384. neighborsSignificance[i - 1] += 0x10;
  40385. }
  40386. if (right) {
  40387. neighborsSignificance[i + 1] += 0x10;
  40388. }
  40389. neighborsSignificance[i] += 0x04;
  40390. }
  40391. if (left) {
  40392. neighborsSignificance[index - 1] += 0x01;
  40393. }
  40394. if (right) {
  40395. neighborsSignificance[index + 1] += 0x01;
  40396. }
  40397. neighborsSignificance[index] |= 0x80;
  40398. },
  40399. runSignificancePropogationPass:
  40400. function BitModel_runSignificancePropogationPass() {
  40401. var decoder = this.decoder;
  40402. var width = this.width, height = this.height;
  40403. var coefficentsMagnitude = this.coefficentsMagnitude;
  40404. var coefficentsSign = this.coefficentsSign;
  40405. var neighborsSignificance = this.neighborsSignificance;
  40406. var processingFlags = this.processingFlags;
  40407. var contexts = this.contexts;
  40408. var labels = this.contextLabelTable;
  40409. var bitsDecoded = this.bitsDecoded;
  40410. var processedInverseMask = ~1;
  40411. var processedMask = 1;
  40412. var firstMagnitudeBitMask = 2;
  40413. for (var i0 = 0; i0 < height; i0 += 4) {
  40414. for (var j = 0; j < width; j++) {
  40415. var index = i0 * width + j;
  40416. for (var i1 = 0; i1 < 4; i1++, index += width) {
  40417. var i = i0 + i1;
  40418. if (i >= height) {
  40419. break;
  40420. }
  40421. // clear processed flag first
  40422. processingFlags[index] &= processedInverseMask;
  40423. if (coefficentsMagnitude[index] ||
  40424. !neighborsSignificance[index]) {
  40425. continue;
  40426. }
  40427. var contextLabel = labels[neighborsSignificance[index]];
  40428. var decision = decoder.readBit(contexts, contextLabel);
  40429. if (decision) {
  40430. var sign = this.decodeSignBit(i, j, index);
  40431. coefficentsSign[index] = sign;
  40432. coefficentsMagnitude[index] = 1;
  40433. this.setNeighborsSignificance(i, j, index);
  40434. processingFlags[index] |= firstMagnitudeBitMask;
  40435. }
  40436. bitsDecoded[index]++;
  40437. processingFlags[index] |= processedMask;
  40438. }
  40439. }
  40440. }
  40441. },
  40442. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  40443. var width = this.width, height = this.height;
  40444. var coefficentsMagnitude = this.coefficentsMagnitude;
  40445. var coefficentsSign = this.coefficentsSign;
  40446. var contribution, sign0, sign1, significance1;
  40447. var contextLabel, decoded;
  40448. // calculate horizontal contribution
  40449. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  40450. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  40451. sign1 = coefficentsSign[index + 1];
  40452. if (significance1) {
  40453. sign0 = coefficentsSign[index - 1];
  40454. contribution = 1 - sign1 - sign0;
  40455. } else {
  40456. contribution = 1 - sign1 - sign1;
  40457. }
  40458. } else if (significance1) {
  40459. sign0 = coefficentsSign[index - 1];
  40460. contribution = 1 - sign0 - sign0;
  40461. } else {
  40462. contribution = 0;
  40463. }
  40464. var horizontalContribution = 3 * contribution;
  40465. // calculate vertical contribution and combine with the horizontal
  40466. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  40467. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  40468. sign1 = coefficentsSign[index + width];
  40469. if (significance1) {
  40470. sign0 = coefficentsSign[index - width];
  40471. contribution = 1 - sign1 - sign0 + horizontalContribution;
  40472. } else {
  40473. contribution = 1 - sign1 - sign1 + horizontalContribution;
  40474. }
  40475. } else if (significance1) {
  40476. sign0 = coefficentsSign[index - width];
  40477. contribution = 1 - sign0 - sign0 + horizontalContribution;
  40478. } else {
  40479. contribution = horizontalContribution;
  40480. }
  40481. if (contribution >= 0) {
  40482. contextLabel = 9 + contribution;
  40483. decoded = this.decoder.readBit(this.contexts, contextLabel);
  40484. } else {
  40485. contextLabel = 9 - contribution;
  40486. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  40487. }
  40488. return decoded;
  40489. },
  40490. runMagnitudeRefinementPass:
  40491. function BitModel_runMagnitudeRefinementPass() {
  40492. var decoder = this.decoder;
  40493. var width = this.width, height = this.height;
  40494. var coefficentsMagnitude = this.coefficentsMagnitude;
  40495. var neighborsSignificance = this.neighborsSignificance;
  40496. var contexts = this.contexts;
  40497. var bitsDecoded = this.bitsDecoded;
  40498. var processingFlags = this.processingFlags;
  40499. var processedMask = 1;
  40500. var firstMagnitudeBitMask = 2;
  40501. var length = width * height;
  40502. var width4 = width * 4;
  40503. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  40504. indexNext = Math.min(length, index0 + width4);
  40505. for (var j = 0; j < width; j++) {
  40506. for (var index = index0 + j; index < indexNext; index += width) {
  40507. // significant but not those that have just become
  40508. if (!coefficentsMagnitude[index] ||
  40509. (processingFlags[index] & processedMask) !== 0) {
  40510. continue;
  40511. }
  40512. var contextLabel = 16;
  40513. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  40514. processingFlags[index] ^= firstMagnitudeBitMask;
  40515. // first refinement
  40516. var significance = neighborsSignificance[index] & 127;
  40517. contextLabel = significance === 0 ? 15 : 14;
  40518. }
  40519. var bit = decoder.readBit(contexts, contextLabel);
  40520. coefficentsMagnitude[index] =
  40521. (coefficentsMagnitude[index] << 1) | bit;
  40522. bitsDecoded[index]++;
  40523. processingFlags[index] |= processedMask;
  40524. }
  40525. }
  40526. }
  40527. },
  40528. runCleanupPass: function BitModel_runCleanupPass() {
  40529. var decoder = this.decoder;
  40530. var width = this.width, height = this.height;
  40531. var neighborsSignificance = this.neighborsSignificance;
  40532. var coefficentsMagnitude = this.coefficentsMagnitude;
  40533. var coefficentsSign = this.coefficentsSign;
  40534. var contexts = this.contexts;
  40535. var labels = this.contextLabelTable;
  40536. var bitsDecoded = this.bitsDecoded;
  40537. var processingFlags = this.processingFlags;
  40538. var processedMask = 1;
  40539. var firstMagnitudeBitMask = 2;
  40540. var oneRowDown = width;
  40541. var twoRowsDown = width * 2;
  40542. var threeRowsDown = width * 3;
  40543. var iNext;
  40544. for (var i0 = 0; i0 < height; i0 = iNext) {
  40545. iNext = Math.min(i0 + 4, height);
  40546. var indexBase = i0 * width;
  40547. var checkAllEmpty = i0 + 3 < height;
  40548. for (var j = 0; j < width; j++) {
  40549. var index0 = indexBase + j;
  40550. // using the property: labels[neighborsSignificance[index]] === 0
  40551. // when neighborsSignificance[index] === 0
  40552. var allEmpty = (checkAllEmpty &&
  40553. processingFlags[index0] === 0 &&
  40554. processingFlags[index0 + oneRowDown] === 0 &&
  40555. processingFlags[index0 + twoRowsDown] === 0 &&
  40556. processingFlags[index0 + threeRowsDown] === 0 &&
  40557. neighborsSignificance[index0] === 0 &&
  40558. neighborsSignificance[index0 + oneRowDown] === 0 &&
  40559. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  40560. neighborsSignificance[index0 + threeRowsDown] === 0);
  40561. var i1 = 0, index = index0;
  40562. var i = i0, sign;
  40563. if (allEmpty) {
  40564. var hasSignificantCoefficent =
  40565. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  40566. if (!hasSignificantCoefficent) {
  40567. bitsDecoded[index0]++;
  40568. bitsDecoded[index0 + oneRowDown]++;
  40569. bitsDecoded[index0 + twoRowsDown]++;
  40570. bitsDecoded[index0 + threeRowsDown]++;
  40571. continue; // next column
  40572. }
  40573. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40574. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40575. if (i1 !== 0) {
  40576. i = i0 + i1;
  40577. index += i1 * width;
  40578. }
  40579. sign = this.decodeSignBit(i, j, index);
  40580. coefficentsSign[index] = sign;
  40581. coefficentsMagnitude[index] = 1;
  40582. this.setNeighborsSignificance(i, j, index);
  40583. processingFlags[index] |= firstMagnitudeBitMask;
  40584. index = index0;
  40585. for (var i2 = i0; i2 <= i; i2++, index += width) {
  40586. bitsDecoded[index]++;
  40587. }
  40588. i1++;
  40589. }
  40590. for (i = i0 + i1; i < iNext; i++, index += width) {
  40591. if (coefficentsMagnitude[index] ||
  40592. (processingFlags[index] & processedMask) !== 0) {
  40593. continue;
  40594. }
  40595. var contextLabel = labels[neighborsSignificance[index]];
  40596. var decision = decoder.readBit(contexts, contextLabel);
  40597. if (decision === 1) {
  40598. sign = this.decodeSignBit(i, j, index);
  40599. coefficentsSign[index] = sign;
  40600. coefficentsMagnitude[index] = 1;
  40601. this.setNeighborsSignificance(i, j, index);
  40602. processingFlags[index] |= firstMagnitudeBitMask;
  40603. }
  40604. bitsDecoded[index]++;
  40605. }
  40606. }
  40607. }
  40608. },
  40609. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  40610. var decoder = this.decoder;
  40611. var contexts = this.contexts;
  40612. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  40613. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  40614. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  40615. decoder.readBit(contexts, UNIFORM_CONTEXT);
  40616. if (symbol !== 0xA) {
  40617. throw new Error('JPX Error: Invalid segmentation symbol');
  40618. }
  40619. }
  40620. };
  40621. return BitModel;
  40622. })();
  40623. // Section F, Discrete wavelet transformation
  40624. var Transform = (function TransformClosure() {
  40625. function Transform() {}
  40626. Transform.prototype.calculate =
  40627. function transformCalculate(subbands, u0, v0) {
  40628. var ll = subbands[0];
  40629. for (var i = 1, ii = subbands.length; i < ii; i++) {
  40630. ll = this.iterate(ll, subbands[i], u0, v0);
  40631. }
  40632. return ll;
  40633. };
  40634. Transform.prototype.extend = function extend(buffer, offset, size) {
  40635. // Section F.3.7 extending... using max extension of 4
  40636. var i1 = offset - 1, j1 = offset + 1;
  40637. var i2 = offset + size - 2, j2 = offset + size;
  40638. buffer[i1--] = buffer[j1++];
  40639. buffer[j2++] = buffer[i2--];
  40640. buffer[i1--] = buffer[j1++];
  40641. buffer[j2++] = buffer[i2--];
  40642. buffer[i1--] = buffer[j1++];
  40643. buffer[j2++] = buffer[i2--];
  40644. buffer[i1] = buffer[j1];
  40645. buffer[j2] = buffer[i2];
  40646. };
  40647. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  40648. u0, v0) {
  40649. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  40650. var width = hl_lh_hh.width;
  40651. var height = hl_lh_hh.height;
  40652. var items = hl_lh_hh.items;
  40653. var i, j, k, l, u, v;
  40654. // Interleave LL according to Section F.3.3
  40655. for (k = 0, i = 0; i < llHeight; i++) {
  40656. l = i * 2 * width;
  40657. for (j = 0; j < llWidth; j++, k++, l += 2) {
  40658. items[l] = llItems[k];
  40659. }
  40660. }
  40661. // The LL band is not needed anymore.
  40662. llItems = ll.items = null;
  40663. var bufferPadding = 4;
  40664. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  40665. // Section F.3.4 HOR_SR
  40666. if (width === 1) {
  40667. // if width = 1, when u0 even keep items as is, when odd divide by 2
  40668. if ((u0 & 1) !== 0) {
  40669. for (v = 0, k = 0; v < height; v++, k += width) {
  40670. items[k] *= 0.5;
  40671. }
  40672. }
  40673. } else {
  40674. for (v = 0, k = 0; v < height; v++, k += width) {
  40675. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  40676. this.extend(rowBuffer, bufferPadding, width);
  40677. this.filter(rowBuffer, bufferPadding, width);
  40678. items.set(
  40679. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  40680. k);
  40681. }
  40682. }
  40683. // Accesses to the items array can take long, because it may not fit into
  40684. // CPU cache and has to be fetched from main memory. Since subsequent
  40685. // accesses to the items array are not local when reading columns, we
  40686. // have a cache miss every time. To reduce cache misses, get up to
  40687. // 'numBuffers' items at a time and store them into the individual
  40688. // buffers. The colBuffers should be small enough to fit into CPU cache.
  40689. var numBuffers = 16;
  40690. var colBuffers = [];
  40691. for (i = 0; i < numBuffers; i++) {
  40692. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  40693. }
  40694. var b, currentBuffer = 0;
  40695. ll = bufferPadding + height;
  40696. // Section F.3.5 VER_SR
  40697. if (height === 1) {
  40698. // if height = 1, when v0 even keep items as is, when odd divide by 2
  40699. if ((v0 & 1) !== 0) {
  40700. for (u = 0; u < width; u++) {
  40701. items[u] *= 0.5;
  40702. }
  40703. }
  40704. } else {
  40705. for (u = 0; u < width; u++) {
  40706. // if we ran out of buffers, copy several image columns at once
  40707. if (currentBuffer === 0) {
  40708. numBuffers = Math.min(width - u, numBuffers);
  40709. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  40710. for (b = 0; b < numBuffers; b++) {
  40711. colBuffers[b][l] = items[k + b];
  40712. }
  40713. }
  40714. currentBuffer = numBuffers;
  40715. }
  40716. currentBuffer--;
  40717. var buffer = colBuffers[currentBuffer];
  40718. this.extend(buffer, bufferPadding, height);
  40719. this.filter(buffer, bufferPadding, height);
  40720. // If this is last buffer in this group of buffers, flush all buffers.
  40721. if (currentBuffer === 0) {
  40722. k = u - numBuffers + 1;
  40723. for (l = bufferPadding; l < ll; k += width, l++) {
  40724. for (b = 0; b < numBuffers; b++) {
  40725. items[k + b] = colBuffers[b][l];
  40726. }
  40727. }
  40728. }
  40729. }
  40730. }
  40731. return {
  40732. width: width,
  40733. height: height,
  40734. items: items
  40735. };
  40736. };
  40737. return Transform;
  40738. })();
  40739. // Section 3.8.2 Irreversible 9-7 filter
  40740. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  40741. function IrreversibleTransform() {
  40742. Transform.call(this);
  40743. }
  40744. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  40745. IrreversibleTransform.prototype.filter =
  40746. function irreversibleTransformFilter(x, offset, length) {
  40747. var len = length >> 1;
  40748. offset = offset | 0;
  40749. var j, n, current, next;
  40750. var alpha = -1.586134342059924;
  40751. var beta = -0.052980118572961;
  40752. var gamma = 0.882911075530934;
  40753. var delta = 0.443506852043971;
  40754. var K = 1.230174104914001;
  40755. var K_ = 1 / K;
  40756. // step 1 is combined with step 3
  40757. // step 2
  40758. j = offset - 3;
  40759. for (n = len + 4; n--; j += 2) {
  40760. x[j] *= K_;
  40761. }
  40762. // step 1 & 3
  40763. j = offset - 2;
  40764. current = delta * x[j -1];
  40765. for (n = len + 3; n--; j += 2) {
  40766. next = delta * x[j + 1];
  40767. x[j] = K * x[j] - current - next;
  40768. if (n--) {
  40769. j += 2;
  40770. current = delta * x[j + 1];
  40771. x[j] = K * x[j] - current - next;
  40772. } else {
  40773. break;
  40774. }
  40775. }
  40776. // step 4
  40777. j = offset - 1;
  40778. current = gamma * x[j - 1];
  40779. for (n = len + 2; n--; j += 2) {
  40780. next = gamma * x[j + 1];
  40781. x[j] -= current + next;
  40782. if (n--) {
  40783. j += 2;
  40784. current = gamma * x[j + 1];
  40785. x[j] -= current + next;
  40786. } else {
  40787. break;
  40788. }
  40789. }
  40790. // step 5
  40791. j = offset;
  40792. current = beta * x[j - 1];
  40793. for (n = len + 1; n--; j += 2) {
  40794. next = beta * x[j + 1];
  40795. x[j] -= current + next;
  40796. if (n--) {
  40797. j += 2;
  40798. current = beta * x[j + 1];
  40799. x[j] -= current + next;
  40800. } else {
  40801. break;
  40802. }
  40803. }
  40804. // step 6
  40805. if (len !== 0) {
  40806. j = offset + 1;
  40807. current = alpha * x[j - 1];
  40808. for (n = len; n--; j += 2) {
  40809. next = alpha * x[j + 1];
  40810. x[j] -= current + next;
  40811. if (n--) {
  40812. j += 2;
  40813. current = alpha * x[j + 1];
  40814. x[j] -= current + next;
  40815. } else {
  40816. break;
  40817. }
  40818. }
  40819. }
  40820. };
  40821. return IrreversibleTransform;
  40822. })();
  40823. // Section 3.8.1 Reversible 5-3 filter
  40824. var ReversibleTransform = (function ReversibleTransformClosure() {
  40825. function ReversibleTransform() {
  40826. Transform.call(this);
  40827. }
  40828. ReversibleTransform.prototype = Object.create(Transform.prototype);
  40829. ReversibleTransform.prototype.filter =
  40830. function reversibleTransformFilter(x, offset, length) {
  40831. var len = length >> 1;
  40832. offset = offset | 0;
  40833. var j, n;
  40834. for (j = offset, n = len + 1; n--; j += 2) {
  40835. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  40836. }
  40837. for (j = offset + 1, n = len; n--; j += 2) {
  40838. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  40839. }
  40840. };
  40841. return ReversibleTransform;
  40842. })();
  40843. return JpxImage;
  40844. })();
  40845. var Jbig2Image = (function Jbig2ImageClosure() {
  40846. // Utility data structures
  40847. function ContextCache() {}
  40848. ContextCache.prototype = {
  40849. getContexts: function(id) {
  40850. if (id in this) {
  40851. return this[id];
  40852. }
  40853. return (this[id] = new Int8Array(1 << 16));
  40854. }
  40855. };
  40856. function DecodingContext(data, start, end) {
  40857. this.data = data;
  40858. this.start = start;
  40859. this.end = end;
  40860. }
  40861. DecodingContext.prototype = {
  40862. get decoder() {
  40863. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  40864. return shadow(this, 'decoder', decoder);
  40865. },
  40866. get contextCache() {
  40867. var cache = new ContextCache();
  40868. return shadow(this, 'contextCache', cache);
  40869. }
  40870. };
  40871. // Annex A. Arithmetic Integer Decoding Procedure
  40872. // A.2 Procedure for decoding values
  40873. function decodeInteger(contextCache, procedure, decoder) {
  40874. var contexts = contextCache.getContexts(procedure);
  40875. var prev = 1;
  40876. function readBits(length) {
  40877. var v = 0;
  40878. for (var i = 0; i < length; i++) {
  40879. var bit = decoder.readBit(contexts, prev);
  40880. prev = (prev < 256 ? (prev << 1) | bit :
  40881. (((prev << 1) | bit) & 511) | 256);
  40882. v = (v << 1) | bit;
  40883. }
  40884. return v >>> 0;
  40885. }
  40886. var sign = readBits(1);
  40887. var value = readBits(1) ?
  40888. (readBits(1) ?
  40889. (readBits(1) ?
  40890. (readBits(1) ?
  40891. (readBits(1) ?
  40892. (readBits(32) + 4436) :
  40893. readBits(12) + 340) :
  40894. readBits(8) + 84) :
  40895. readBits(6) + 20) :
  40896. readBits(4) + 4) :
  40897. readBits(2);
  40898. return (sign === 0 ? value : (value > 0 ? -value : null));
  40899. }
  40900. // A.3 The IAID decoding procedure
  40901. function decodeIAID(contextCache, decoder, codeLength) {
  40902. var contexts = contextCache.getContexts('IAID');
  40903. var prev = 1;
  40904. for (var i = 0; i < codeLength; i++) {
  40905. var bit = decoder.readBit(contexts, prev);
  40906. prev = (prev << 1) | bit;
  40907. }
  40908. if (codeLength < 31) {
  40909. return prev & ((1 << codeLength) - 1);
  40910. }
  40911. return prev & 0x7FFFFFFF;
  40912. }
  40913. // 7.3 Segment types
  40914. var SegmentTypes = [
  40915. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  40916. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  40917. null, null, null, null, null, 'patternDictionary', null, null, null,
  40918. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  40919. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  40920. null, null, null, null, null, 'IntermediateGenericRegion', null,
  40921. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  40922. 'IntermediateGenericRefinementRegion', null,
  40923. 'ImmediateGenericRefinementRegion',
  40924. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  40925. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  40926. 'Tables', null, null, null, null, null, null, null, null,
  40927. 'Extension'
  40928. ];
  40929. var CodingTemplates = [
  40930. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40931. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  40932. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40933. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  40934. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  40935. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  40936. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  40937. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  40938. {x: -1, y: 0}],
  40939. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  40940. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  40941. ];
  40942. var RefinementTemplates = [
  40943. {
  40944. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40945. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  40946. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  40947. },
  40948. {
  40949. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  40950. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  40951. {x: 0, y: 1}, {x: 1, y: 1}]
  40952. }
  40953. ];
  40954. // See 6.2.5.7 Decoding the bitmap.
  40955. var ReusedContexts = [
  40956. 0x9B25, // 10011 0110010 0101
  40957. 0x0795, // 0011 110010 101
  40958. 0x00E5, // 001 11001 01
  40959. 0x0195 // 011001 0101
  40960. ];
  40961. var RefinementReusedContexts = [
  40962. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  40963. 0x0008 // '0000' + '001000'
  40964. ];
  40965. function decodeBitmapTemplate0(width, height, decodingContext) {
  40966. var decoder = decodingContext.decoder;
  40967. var contexts = decodingContext.contextCache.getContexts('GB');
  40968. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  40969. // ...ooooo....
  40970. // ..ooooooo... Context template for current pixel (X)
  40971. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  40972. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  40973. for (i = 0; i < height; i++) {
  40974. row = bitmap[i] = new Uint8Array(width);
  40975. row1 = (i < 1) ? row : bitmap[i - 1];
  40976. row2 = (i < 2) ? row : bitmap[i - 2];
  40977. // At the beginning of each row:
  40978. // Fill contextLabel with pixels that are above/right of (X)
  40979. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  40980. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  40981. (row1[3] << 4);
  40982. for (j = 0; j < width; j++) {
  40983. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  40984. // At each pixel: Clear contextLabel pixels that are shifted
  40985. // out of the context, then add new ones.
  40986. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  40987. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  40988. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  40989. }
  40990. }
  40991. return bitmap;
  40992. }
  40993. // 6.2 Generic Region Decoding Procedure
  40994. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  40995. decodingContext) {
  40996. if (mmr) {
  40997. error('JBIG2 error: MMR encoding is not supported');
  40998. }
  40999. // Use optimized version for the most common case
  41000. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  41001. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  41002. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  41003. return decodeBitmapTemplate0(width, height, decodingContext);
  41004. }
  41005. var useskip = !!skip;
  41006. var template = CodingTemplates[templateIndex].concat(at);
  41007. // Sorting is non-standard, and it is not required. But sorting increases
  41008. // the number of template bits that can be reused from the previous
  41009. // contextLabel in the main loop.
  41010. template.sort(function (a, b) {
  41011. return (a.y - b.y) || (a.x - b.x);
  41012. });
  41013. var templateLength = template.length;
  41014. var templateX = new Int8Array(templateLength);
  41015. var templateY = new Int8Array(templateLength);
  41016. var changingTemplateEntries = [];
  41017. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  41018. var c, k;
  41019. for (k = 0; k < templateLength; k++) {
  41020. templateX[k] = template[k].x;
  41021. templateY[k] = template[k].y;
  41022. minX = Math.min(minX, template[k].x);
  41023. maxX = Math.max(maxX, template[k].x);
  41024. minY = Math.min(minY, template[k].y);
  41025. // Check if the template pixel appears in two consecutive context labels,
  41026. // so it can be reused. Otherwise, we add it to the list of changing
  41027. // template entries.
  41028. if (k < templateLength - 1 &&
  41029. template[k].y === template[k + 1].y &&
  41030. template[k].x === template[k + 1].x - 1) {
  41031. reuseMask |= 1 << (templateLength - 1 - k);
  41032. } else {
  41033. changingTemplateEntries.push(k);
  41034. }
  41035. }
  41036. var changingEntriesLength = changingTemplateEntries.length;
  41037. var changingTemplateX = new Int8Array(changingEntriesLength);
  41038. var changingTemplateY = new Int8Array(changingEntriesLength);
  41039. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  41040. for (c = 0; c < changingEntriesLength; c++) {
  41041. k = changingTemplateEntries[c];
  41042. changingTemplateX[c] = template[k].x;
  41043. changingTemplateY[c] = template[k].y;
  41044. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  41045. }
  41046. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  41047. var sbb_left = -minX;
  41048. var sbb_top = -minY;
  41049. var sbb_right = width - maxX;
  41050. var pseudoPixelContext = ReusedContexts[templateIndex];
  41051. var row = new Uint8Array(width);
  41052. var bitmap = [];
  41053. var decoder = decodingContext.decoder;
  41054. var contexts = decodingContext.contextCache.getContexts('GB');
  41055. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  41056. for (var i = 0; i < height; i++) {
  41057. if (prediction) {
  41058. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41059. ltp ^= sltp;
  41060. if (ltp) {
  41061. bitmap.push(row); // duplicate previous row
  41062. continue;
  41063. }
  41064. }
  41065. row = new Uint8Array(row);
  41066. bitmap.push(row);
  41067. for (j = 0; j < width; j++) {
  41068. if (useskip && skip[i][j]) {
  41069. row[j] = 0;
  41070. continue;
  41071. }
  41072. // Are we in the middle of a scanline, so we can reuse contextLabel
  41073. // bits?
  41074. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  41075. // If yes, we can just shift the bits that are reusable and only
  41076. // fetch the remaining ones.
  41077. contextLabel = (contextLabel << 1) & reuseMask;
  41078. for (k = 0; k < changingEntriesLength; k++) {
  41079. i0 = i + changingTemplateY[k];
  41080. j0 = j + changingTemplateX[k];
  41081. bit = bitmap[i0][j0];
  41082. if (bit) {
  41083. bit = changingTemplateBit[k];
  41084. contextLabel |= bit;
  41085. }
  41086. }
  41087. } else {
  41088. // compute the contextLabel from scratch
  41089. contextLabel = 0;
  41090. shift = templateLength - 1;
  41091. for (k = 0; k < templateLength; k++, shift--) {
  41092. j0 = j + templateX[k];
  41093. if (j0 >= 0 && j0 < width) {
  41094. i0 = i + templateY[k];
  41095. if (i0 >= 0) {
  41096. bit = bitmap[i0][j0];
  41097. if (bit) {
  41098. contextLabel |= bit << shift;
  41099. }
  41100. }
  41101. }
  41102. }
  41103. }
  41104. var pixel = decoder.readBit(contexts, contextLabel);
  41105. row[j] = pixel;
  41106. }
  41107. }
  41108. return bitmap;
  41109. }
  41110. // 6.3.2 Generic Refinement Region Decoding Procedure
  41111. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  41112. offsetX, offsetY, prediction, at,
  41113. decodingContext) {
  41114. var codingTemplate = RefinementTemplates[templateIndex].coding;
  41115. if (templateIndex === 0) {
  41116. codingTemplate = codingTemplate.concat([at[0]]);
  41117. }
  41118. var codingTemplateLength = codingTemplate.length;
  41119. var codingTemplateX = new Int32Array(codingTemplateLength);
  41120. var codingTemplateY = new Int32Array(codingTemplateLength);
  41121. var k;
  41122. for (k = 0; k < codingTemplateLength; k++) {
  41123. codingTemplateX[k] = codingTemplate[k].x;
  41124. codingTemplateY[k] = codingTemplate[k].y;
  41125. }
  41126. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  41127. if (templateIndex === 0) {
  41128. referenceTemplate = referenceTemplate.concat([at[1]]);
  41129. }
  41130. var referenceTemplateLength = referenceTemplate.length;
  41131. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  41132. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  41133. for (k = 0; k < referenceTemplateLength; k++) {
  41134. referenceTemplateX[k] = referenceTemplate[k].x;
  41135. referenceTemplateY[k] = referenceTemplate[k].y;
  41136. }
  41137. var referenceWidth = referenceBitmap[0].length;
  41138. var referenceHeight = referenceBitmap.length;
  41139. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  41140. var bitmap = [];
  41141. var decoder = decodingContext.decoder;
  41142. var contexts = decodingContext.contextCache.getContexts('GR');
  41143. var ltp = 0;
  41144. for (var i = 0; i < height; i++) {
  41145. if (prediction) {
  41146. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  41147. ltp ^= sltp;
  41148. if (ltp) {
  41149. error('JBIG2 error: prediction is not supported');
  41150. }
  41151. }
  41152. var row = new Uint8Array(width);
  41153. bitmap.push(row);
  41154. for (var j = 0; j < width; j++) {
  41155. var i0, j0;
  41156. var contextLabel = 0;
  41157. for (k = 0; k < codingTemplateLength; k++) {
  41158. i0 = i + codingTemplateY[k];
  41159. j0 = j + codingTemplateX[k];
  41160. if (i0 < 0 || j0 < 0 || j0 >= width) {
  41161. contextLabel <<= 1; // out of bound pixel
  41162. } else {
  41163. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  41164. }
  41165. }
  41166. for (k = 0; k < referenceTemplateLength; k++) {
  41167. i0 = i + referenceTemplateY[k] + offsetY;
  41168. j0 = j + referenceTemplateX[k] + offsetX;
  41169. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  41170. j0 >= referenceWidth) {
  41171. contextLabel <<= 1; // out of bound pixel
  41172. } else {
  41173. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  41174. }
  41175. }
  41176. var pixel = decoder.readBit(contexts, contextLabel);
  41177. row[j] = pixel;
  41178. }
  41179. }
  41180. return bitmap;
  41181. }
  41182. // 6.5.5 Decoding the symbol dictionary
  41183. function decodeSymbolDictionary(huffman, refinement, symbols,
  41184. numberOfNewSymbols, numberOfExportedSymbols,
  41185. huffmanTables, templateIndex, at,
  41186. refinementTemplateIndex, refinementAt,
  41187. decodingContext) {
  41188. if (huffman) {
  41189. error('JBIG2 error: huffman is not supported');
  41190. }
  41191. var newSymbols = [];
  41192. var currentHeight = 0;
  41193. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  41194. var decoder = decodingContext.decoder;
  41195. var contextCache = decodingContext.contextCache;
  41196. while (newSymbols.length < numberOfNewSymbols) {
  41197. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  41198. currentHeight += deltaHeight;
  41199. var currentWidth = 0;
  41200. var totalWidth = 0;
  41201. while (true) {
  41202. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  41203. if (deltaWidth === null) {
  41204. break; // OOB
  41205. }
  41206. currentWidth += deltaWidth;
  41207. totalWidth += currentWidth;
  41208. var bitmap;
  41209. if (refinement) {
  41210. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  41211. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  41212. if (numberOfInstances > 1) {
  41213. bitmap = decodeTextRegion(huffman, refinement,
  41214. currentWidth, currentHeight, 0,
  41215. numberOfInstances, 1, //strip size
  41216. symbols.concat(newSymbols),
  41217. symbolCodeLength,
  41218. 0, //transposed
  41219. 0, //ds offset
  41220. 1, //top left 7.4.3.1.1
  41221. 0, //OR operator
  41222. huffmanTables,
  41223. refinementTemplateIndex, refinementAt,
  41224. decodingContext);
  41225. } else {
  41226. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41227. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41228. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41229. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  41230. newSymbols[symbolId - symbols.length]);
  41231. bitmap = decodeRefinement(currentWidth, currentHeight,
  41232. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  41233. decodingContext);
  41234. }
  41235. } else {
  41236. // 6.5.8.1 Direct-coded symbol bitmap
  41237. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  41238. templateIndex, false, null, at, decodingContext);
  41239. }
  41240. newSymbols.push(bitmap);
  41241. }
  41242. }
  41243. // 6.5.10 Exported symbols
  41244. var exportedSymbols = [];
  41245. var flags = [], currentFlag = false;
  41246. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  41247. while (flags.length < totalSymbolsLength) {
  41248. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  41249. while (runLength--) {
  41250. flags.push(currentFlag);
  41251. }
  41252. currentFlag = !currentFlag;
  41253. }
  41254. for (var i = 0, ii = symbols.length; i < ii; i++) {
  41255. if (flags[i]) {
  41256. exportedSymbols.push(symbols[i]);
  41257. }
  41258. }
  41259. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  41260. if (flags[i]) {
  41261. exportedSymbols.push(newSymbols[j]);
  41262. }
  41263. }
  41264. return exportedSymbols;
  41265. }
  41266. function decodeTextRegion(huffman, refinement, width, height,
  41267. defaultPixelValue, numberOfSymbolInstances,
  41268. stripSize, inputSymbols, symbolCodeLength,
  41269. transposed, dsOffset, referenceCorner,
  41270. combinationOperator, huffmanTables,
  41271. refinementTemplateIndex, refinementAt,
  41272. decodingContext) {
  41273. if (huffman) {
  41274. error('JBIG2 error: huffman is not supported');
  41275. }
  41276. // Prepare bitmap
  41277. var bitmap = [];
  41278. var i, row;
  41279. for (i = 0; i < height; i++) {
  41280. row = new Uint8Array(width);
  41281. if (defaultPixelValue) {
  41282. for (var j = 0; j < width; j++) {
  41283. row[j] = defaultPixelValue;
  41284. }
  41285. }
  41286. bitmap.push(row);
  41287. }
  41288. var decoder = decodingContext.decoder;
  41289. var contextCache = decodingContext.contextCache;
  41290. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41291. var firstS = 0;
  41292. i = 0;
  41293. while (i < numberOfSymbolInstances) {
  41294. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  41295. stripT += deltaT;
  41296. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  41297. firstS += deltaFirstS;
  41298. var currentS = firstS;
  41299. do {
  41300. var currentT = (stripSize === 1 ? 0 :
  41301. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  41302. var t = stripSize * stripT + currentT;
  41303. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  41304. var applyRefinement = (refinement &&
  41305. decodeInteger(contextCache, 'IARI', decoder));
  41306. var symbolBitmap = inputSymbols[symbolId];
  41307. var symbolWidth = symbolBitmap[0].length;
  41308. var symbolHeight = symbolBitmap.length;
  41309. if (applyRefinement) {
  41310. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  41311. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  41312. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  41313. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  41314. symbolWidth += rdw;
  41315. symbolHeight += rdh;
  41316. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  41317. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  41318. (rdh >> 1) + rdy, false, refinementAt,
  41319. decodingContext);
  41320. }
  41321. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  41322. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  41323. var s2, t2, symbolRow;
  41324. if (transposed) {
  41325. // Place Symbol Bitmap from T1,S1
  41326. for (s2 = 0; s2 < symbolHeight; s2++) {
  41327. row = bitmap[offsetS + s2];
  41328. if (!row) {
  41329. continue;
  41330. }
  41331. symbolRow = symbolBitmap[s2];
  41332. // To ignore Parts of Symbol bitmap which goes
  41333. // outside bitmap region
  41334. var maxWidth = Math.min(width - offsetT, symbolWidth);
  41335. switch (combinationOperator) {
  41336. case 0: // OR
  41337. for (t2 = 0; t2 < maxWidth; t2++) {
  41338. row[offsetT + t2] |= symbolRow[t2];
  41339. }
  41340. break;
  41341. case 2: // XOR
  41342. for (t2 = 0; t2 < maxWidth; t2++) {
  41343. row[offsetT + t2] ^= symbolRow[t2];
  41344. }
  41345. break;
  41346. default:
  41347. error('JBIG2 error: operator ' + combinationOperator +
  41348. ' is not supported');
  41349. }
  41350. }
  41351. currentS += symbolHeight - 1;
  41352. } else {
  41353. for (t2 = 0; t2 < symbolHeight; t2++) {
  41354. row = bitmap[offsetT + t2];
  41355. if (!row) {
  41356. continue;
  41357. }
  41358. symbolRow = symbolBitmap[t2];
  41359. switch (combinationOperator) {
  41360. case 0: // OR
  41361. for (s2 = 0; s2 < symbolWidth; s2++) {
  41362. row[offsetS + s2] |= symbolRow[s2];
  41363. }
  41364. break;
  41365. case 2: // XOR
  41366. for (s2 = 0; s2 < symbolWidth; s2++) {
  41367. row[offsetS + s2] ^= symbolRow[s2];
  41368. }
  41369. break;
  41370. default:
  41371. error('JBIG2 error: operator ' + combinationOperator +
  41372. ' is not supported');
  41373. }
  41374. }
  41375. currentS += symbolWidth - 1;
  41376. }
  41377. i++;
  41378. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  41379. if (deltaS === null) {
  41380. break; // OOB
  41381. }
  41382. currentS += deltaS + dsOffset;
  41383. } while (true);
  41384. }
  41385. return bitmap;
  41386. }
  41387. function readSegmentHeader(data, start) {
  41388. var segmentHeader = {};
  41389. segmentHeader.number = readUint32(data, start);
  41390. var flags = data[start + 4];
  41391. var segmentType = flags & 0x3F;
  41392. if (!SegmentTypes[segmentType]) {
  41393. error('JBIG2 error: invalid segment type: ' + segmentType);
  41394. }
  41395. segmentHeader.type = segmentType;
  41396. segmentHeader.typeName = SegmentTypes[segmentType];
  41397. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  41398. var pageAssociationFieldSize = !!(flags & 0x40);
  41399. var referredFlags = data[start + 5];
  41400. var referredToCount = (referredFlags >> 5) & 7;
  41401. var retainBits = [referredFlags & 31];
  41402. var position = start + 6;
  41403. if (referredFlags === 7) {
  41404. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  41405. position += 3;
  41406. var bytes = (referredToCount + 7) >> 3;
  41407. retainBits[0] = data[position++];
  41408. while (--bytes > 0) {
  41409. retainBits.push(data[position++]);
  41410. }
  41411. } else if (referredFlags === 5 || referredFlags === 6) {
  41412. error('JBIG2 error: invalid referred-to flags');
  41413. }
  41414. segmentHeader.retainBits = retainBits;
  41415. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  41416. (segmentHeader.number <= 65536 ? 2 : 4));
  41417. var referredTo = [];
  41418. var i, ii;
  41419. for (i = 0; i < referredToCount; i++) {
  41420. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  41421. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  41422. readUint32(data, position)));
  41423. referredTo.push(number);
  41424. position += referredToSegmentNumberSize;
  41425. }
  41426. segmentHeader.referredTo = referredTo;
  41427. if (!pageAssociationFieldSize) {
  41428. segmentHeader.pageAssociation = data[position++];
  41429. } else {
  41430. segmentHeader.pageAssociation = readUint32(data, position);
  41431. position += 4;
  41432. }
  41433. segmentHeader.length = readUint32(data, position);
  41434. position += 4;
  41435. if (segmentHeader.length === 0xFFFFFFFF) {
  41436. // 7.2.7 Segment data length, unknown segment length
  41437. if (segmentType === 38) { // ImmediateGenericRegion
  41438. var genericRegionInfo = readRegionSegmentInformation(data, position);
  41439. var genericRegionSegmentFlags = data[position +
  41440. RegionSegmentInformationFieldLength];
  41441. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  41442. // searching for the segment end
  41443. var searchPatternLength = 6;
  41444. var searchPattern = new Uint8Array(searchPatternLength);
  41445. if (!genericRegionMmr) {
  41446. searchPattern[0] = 0xFF;
  41447. searchPattern[1] = 0xAC;
  41448. }
  41449. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  41450. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  41451. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  41452. searchPattern[5] = genericRegionInfo.height & 0xFF;
  41453. for (i = position, ii = data.length; i < ii; i++) {
  41454. var j = 0;
  41455. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  41456. j++;
  41457. }
  41458. if (j === searchPatternLength) {
  41459. segmentHeader.length = i + searchPatternLength;
  41460. break;
  41461. }
  41462. }
  41463. if (segmentHeader.length === 0xFFFFFFFF) {
  41464. error('JBIG2 error: segment end was not found');
  41465. }
  41466. } else {
  41467. error('JBIG2 error: invalid unknown segment length');
  41468. }
  41469. }
  41470. segmentHeader.headerEnd = position;
  41471. return segmentHeader;
  41472. }
  41473. function readSegments(header, data, start, end) {
  41474. var segments = [];
  41475. var position = start;
  41476. while (position < end) {
  41477. var segmentHeader = readSegmentHeader(data, position);
  41478. position = segmentHeader.headerEnd;
  41479. var segment = {
  41480. header: segmentHeader,
  41481. data: data
  41482. };
  41483. if (!header.randomAccess) {
  41484. segment.start = position;
  41485. position += segmentHeader.length;
  41486. segment.end = position;
  41487. }
  41488. segments.push(segment);
  41489. if (segmentHeader.type === 51) {
  41490. break; // end of file is found
  41491. }
  41492. }
  41493. if (header.randomAccess) {
  41494. for (var i = 0, ii = segments.length; i < ii; i++) {
  41495. segments[i].start = position;
  41496. position += segments[i].header.length;
  41497. segments[i].end = position;
  41498. }
  41499. }
  41500. return segments;
  41501. }
  41502. // 7.4.1 Region segment information field
  41503. function readRegionSegmentInformation(data, start) {
  41504. return {
  41505. width: readUint32(data, start),
  41506. height: readUint32(data, start + 4),
  41507. x: readUint32(data, start + 8),
  41508. y: readUint32(data, start + 12),
  41509. combinationOperator: data[start + 16] & 7
  41510. };
  41511. }
  41512. var RegionSegmentInformationFieldLength = 17;
  41513. function processSegment(segment, visitor) {
  41514. var header = segment.header;
  41515. var data = segment.data, position = segment.start, end = segment.end;
  41516. var args, at, i, atLength;
  41517. switch (header.type) {
  41518. case 0: // SymbolDictionary
  41519. // 7.4.2 Symbol dictionary segment syntax
  41520. var dictionary = {};
  41521. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  41522. dictionary.huffman = !!(dictionaryFlags & 1);
  41523. dictionary.refinement = !!(dictionaryFlags & 2);
  41524. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  41525. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  41526. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  41527. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  41528. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  41529. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  41530. dictionary.template = (dictionaryFlags >> 10) & 3;
  41531. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  41532. position += 2;
  41533. if (!dictionary.huffman) {
  41534. atLength = dictionary.template === 0 ? 4 : 1;
  41535. at = [];
  41536. for (i = 0; i < atLength; i++) {
  41537. at.push({
  41538. x: readInt8(data, position),
  41539. y: readInt8(data, position + 1)
  41540. });
  41541. position += 2;
  41542. }
  41543. dictionary.at = at;
  41544. }
  41545. if (dictionary.refinement && !dictionary.refinementTemplate) {
  41546. at = [];
  41547. for (i = 0; i < 2; i++) {
  41548. at.push({
  41549. x: readInt8(data, position),
  41550. y: readInt8(data, position + 1)
  41551. });
  41552. position += 2;
  41553. }
  41554. dictionary.refinementAt = at;
  41555. }
  41556. dictionary.numberOfExportedSymbols = readUint32(data, position);
  41557. position += 4;
  41558. dictionary.numberOfNewSymbols = readUint32(data, position);
  41559. position += 4;
  41560. args = [dictionary, header.number, header.referredTo,
  41561. data, position, end];
  41562. break;
  41563. case 6: // ImmediateTextRegion
  41564. case 7: // ImmediateLosslessTextRegion
  41565. var textRegion = {};
  41566. textRegion.info = readRegionSegmentInformation(data, position);
  41567. position += RegionSegmentInformationFieldLength;
  41568. var textRegionSegmentFlags = readUint16(data, position);
  41569. position += 2;
  41570. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  41571. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  41572. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  41573. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  41574. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  41575. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  41576. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  41577. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  41578. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  41579. if (textRegion.huffman) {
  41580. var textRegionHuffmanFlags = readUint16(data, position);
  41581. position += 2;
  41582. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  41583. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  41584. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  41585. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  41586. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  41587. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  41588. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  41589. textRegion.huffmanRefinementSizeSelector =
  41590. !!(textRegionHuffmanFlags & 14);
  41591. }
  41592. if (textRegion.refinement && !textRegion.refinementTemplate) {
  41593. at = [];
  41594. for (i = 0; i < 2; i++) {
  41595. at.push({
  41596. x: readInt8(data, position),
  41597. y: readInt8(data, position + 1)
  41598. });
  41599. position += 2;
  41600. }
  41601. textRegion.refinementAt = at;
  41602. }
  41603. textRegion.numberOfSymbolInstances = readUint32(data, position);
  41604. position += 4;
  41605. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  41606. if (textRegion.huffman) {
  41607. error('JBIG2 error: huffman is not supported');
  41608. }
  41609. args = [textRegion, header.referredTo, data, position, end];
  41610. break;
  41611. case 38: // ImmediateGenericRegion
  41612. case 39: // ImmediateLosslessGenericRegion
  41613. var genericRegion = {};
  41614. genericRegion.info = readRegionSegmentInformation(data, position);
  41615. position += RegionSegmentInformationFieldLength;
  41616. var genericRegionSegmentFlags = data[position++];
  41617. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  41618. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  41619. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  41620. if (!genericRegion.mmr) {
  41621. atLength = genericRegion.template === 0 ? 4 : 1;
  41622. at = [];
  41623. for (i = 0; i < atLength; i++) {
  41624. at.push({
  41625. x: readInt8(data, position),
  41626. y: readInt8(data, position + 1)
  41627. });
  41628. position += 2;
  41629. }
  41630. genericRegion.at = at;
  41631. }
  41632. args = [genericRegion, data, position, end];
  41633. break;
  41634. case 48: // PageInformation
  41635. var pageInfo = {
  41636. width: readUint32(data, position),
  41637. height: readUint32(data, position + 4),
  41638. resolutionX: readUint32(data, position + 8),
  41639. resolutionY: readUint32(data, position + 12)
  41640. };
  41641. if (pageInfo.height === 0xFFFFFFFF) {
  41642. delete pageInfo.height;
  41643. }
  41644. var pageSegmentFlags = data[position + 16];
  41645. var pageStripingInformatiom = readUint16(data, position + 17);
  41646. pageInfo.lossless = !!(pageSegmentFlags & 1);
  41647. pageInfo.refinement = !!(pageSegmentFlags & 2);
  41648. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  41649. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  41650. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  41651. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  41652. args = [pageInfo];
  41653. break;
  41654. case 49: // EndOfPage
  41655. break;
  41656. case 50: // EndOfStripe
  41657. break;
  41658. case 51: // EndOfFile
  41659. break;
  41660. case 62: // 7.4.15 defines 2 extension types which
  41661. // are comments and can be ignored.
  41662. break;
  41663. default:
  41664. error('JBIG2 error: segment type ' + header.typeName + '(' +
  41665. header.type + ') is not implemented');
  41666. }
  41667. var callbackName = 'on' + header.typeName;
  41668. if (callbackName in visitor) {
  41669. visitor[callbackName].apply(visitor, args);
  41670. }
  41671. }
  41672. function processSegments(segments, visitor) {
  41673. for (var i = 0, ii = segments.length; i < ii; i++) {
  41674. processSegment(segments[i], visitor);
  41675. }
  41676. }
  41677. function parseJbig2(data, start, end) {
  41678. var position = start;
  41679. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  41680. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  41681. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  41682. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  41683. error('JBIG2 error: invalid header');
  41684. }
  41685. var header = {};
  41686. position += 8;
  41687. var flags = data[position++];
  41688. header.randomAccess = !(flags & 1);
  41689. if (!(flags & 2)) {
  41690. header.numberOfPages = readUint32(data, position);
  41691. position += 4;
  41692. }
  41693. var segments = readSegments(header, data, position, end);
  41694. error('Not implemented');
  41695. // processSegments(segments, new SimpleSegmentVisitor());
  41696. }
  41697. function parseJbig2Chunks(chunks) {
  41698. var visitor = new SimpleSegmentVisitor();
  41699. for (var i = 0, ii = chunks.length; i < ii; i++) {
  41700. var chunk = chunks[i];
  41701. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  41702. processSegments(segments, visitor);
  41703. }
  41704. return visitor.buffer;
  41705. }
  41706. function SimpleSegmentVisitor() {}
  41707. SimpleSegmentVisitor.prototype = {
  41708. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  41709. this.currentPageInfo = info;
  41710. var rowSize = (info.width + 7) >> 3;
  41711. var buffer = new Uint8Array(rowSize * info.height);
  41712. // The contents of ArrayBuffers are initialized to 0.
  41713. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  41714. if (info.defaultPixelValue) {
  41715. for (var i = 0, ii = buffer.length; i < ii; i++) {
  41716. buffer[i] = 0xFF;
  41717. }
  41718. }
  41719. this.buffer = buffer;
  41720. },
  41721. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  41722. var pageInfo = this.currentPageInfo;
  41723. var width = regionInfo.width, height = regionInfo.height;
  41724. var rowSize = (pageInfo.width + 7) >> 3;
  41725. var combinationOperator = pageInfo.combinationOperatorOverride ?
  41726. regionInfo.combinationOperator : pageInfo.combinationOperator;
  41727. var buffer = this.buffer;
  41728. var mask0 = 128 >> (regionInfo.x & 7);
  41729. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  41730. var i, j, mask, offset;
  41731. switch (combinationOperator) {
  41732. case 0: // OR
  41733. for (i = 0; i < height; i++) {
  41734. mask = mask0;
  41735. offset = offset0;
  41736. for (j = 0; j < width; j++) {
  41737. if (bitmap[i][j]) {
  41738. buffer[offset] |= mask;
  41739. }
  41740. mask >>= 1;
  41741. if (!mask) {
  41742. mask = 128;
  41743. offset++;
  41744. }
  41745. }
  41746. offset0 += rowSize;
  41747. }
  41748. break;
  41749. case 2: // XOR
  41750. for (i = 0; i < height; i++) {
  41751. mask = mask0;
  41752. offset = offset0;
  41753. for (j = 0; j < width; j++) {
  41754. if (bitmap[i][j]) {
  41755. buffer[offset] ^= mask;
  41756. }
  41757. mask >>= 1;
  41758. if (!mask) {
  41759. mask = 128;
  41760. offset++;
  41761. }
  41762. }
  41763. offset0 += rowSize;
  41764. }
  41765. break;
  41766. default:
  41767. error('JBIG2 error: operator ' + combinationOperator +
  41768. ' is not supported');
  41769. }
  41770. },
  41771. onImmediateGenericRegion:
  41772. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  41773. start, end) {
  41774. var regionInfo = region.info;
  41775. var decodingContext = new DecodingContext(data, start, end);
  41776. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  41777. region.template, region.prediction, null,
  41778. region.at, decodingContext);
  41779. this.drawBitmap(regionInfo, bitmap);
  41780. },
  41781. onImmediateLosslessGenericRegion:
  41782. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  41783. this.onImmediateGenericRegion.apply(this, arguments);
  41784. },
  41785. onSymbolDictionary:
  41786. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  41787. currentSegment,
  41788. referredSegments,
  41789. data, start, end) {
  41790. var huffmanTables;
  41791. if (dictionary.huffman) {
  41792. error('JBIG2 error: huffman is not supported');
  41793. }
  41794. // Combines exported symbols from all referred segments
  41795. var symbols = this.symbols;
  41796. if (!symbols) {
  41797. this.symbols = symbols = {};
  41798. }
  41799. var inputSymbols = [];
  41800. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41801. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41802. }
  41803. var decodingContext = new DecodingContext(data, start, end);
  41804. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  41805. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  41806. dictionary.numberOfExportedSymbols, huffmanTables,
  41807. dictionary.template, dictionary.at,
  41808. dictionary.refinementTemplate, dictionary.refinementAt,
  41809. decodingContext);
  41810. },
  41811. onImmediateTextRegion:
  41812. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  41813. referredSegments,
  41814. data, start, end) {
  41815. var regionInfo = region.info;
  41816. var huffmanTables;
  41817. // Combines exported symbols from all referred segments
  41818. var symbols = this.symbols;
  41819. var inputSymbols = [];
  41820. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  41821. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  41822. }
  41823. var symbolCodeLength = log2(inputSymbols.length);
  41824. var decodingContext = new DecodingContext(data, start, end);
  41825. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  41826. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  41827. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  41828. symbolCodeLength, region.transposed, region.dsOffset,
  41829. region.referenceCorner, region.combinationOperator, huffmanTables,
  41830. region.refinementTemplate, region.refinementAt, decodingContext);
  41831. this.drawBitmap(regionInfo, bitmap);
  41832. },
  41833. onImmediateLosslessTextRegion:
  41834. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  41835. this.onImmediateTextRegion.apply(this, arguments);
  41836. }
  41837. };
  41838. function Jbig2Image() {}
  41839. Jbig2Image.prototype = {
  41840. parseChunks: function Jbig2Image_parseChunks(chunks) {
  41841. return parseJbig2Chunks(chunks);
  41842. }
  41843. };
  41844. return Jbig2Image;
  41845. })();
  41846. var bidi = PDFJS.bidi = (function bidiClosure() {
  41847. // Character types for symbols from 0000 to 00FF.
  41848. var baseTypes = [
  41849. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  41850. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41851. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  41852. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  41853. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  41854. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41855. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  41856. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41857. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41858. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  41859. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41860. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  41861. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  41862. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  41863. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41864. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41865. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41866. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  41867. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  41868. ];
  41869. // Character types for symbols from 0600 to 06FF
  41870. var arabicTypes = [
  41871. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41872. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  41873. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41874. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41875. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41876. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41877. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41878. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41879. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  41880. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  41881. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41882. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41883. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41884. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41885. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41886. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41887. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41888. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41889. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  41890. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  41891. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  41892. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  41893. ];
  41894. function isOdd(i) {
  41895. return (i & 1) !== 0;
  41896. }
  41897. function isEven(i) {
  41898. return (i & 1) === 0;
  41899. }
  41900. function findUnequal(arr, start, value) {
  41901. for (var j = start, jj = arr.length; j < jj; ++j) {
  41902. if (arr[j] !== value) {
  41903. return j;
  41904. }
  41905. }
  41906. return j;
  41907. }
  41908. function setValues(arr, start, end, value) {
  41909. for (var j = start; j < end; ++j) {
  41910. arr[j] = value;
  41911. }
  41912. }
  41913. function reverseValues(arr, start, end) {
  41914. for (var i = start, j = end - 1; i < j; ++i, --j) {
  41915. var temp = arr[i];
  41916. arr[i] = arr[j];
  41917. arr[j] = temp;
  41918. }
  41919. }
  41920. function createBidiText(str, isLTR, vertical) {
  41921. return {
  41922. str: str,
  41923. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  41924. };
  41925. }
  41926. // These are used in bidi(), which is called frequently. We re-use them on
  41927. // each call to avoid unnecessary allocations.
  41928. var chars = [];
  41929. var types = [];
  41930. function bidi(str, startLevel, vertical) {
  41931. var isLTR = true;
  41932. var strLength = str.length;
  41933. if (strLength === 0 || vertical) {
  41934. return createBidiText(str, isLTR, vertical);
  41935. }
  41936. // Get types and fill arrays
  41937. chars.length = strLength;
  41938. types.length = strLength;
  41939. var numBidi = 0;
  41940. var i, ii;
  41941. for (i = 0; i < strLength; ++i) {
  41942. chars[i] = str.charAt(i);
  41943. var charCode = str.charCodeAt(i);
  41944. var charType = 'L';
  41945. if (charCode <= 0x00ff) {
  41946. charType = baseTypes[charCode];
  41947. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  41948. charType = 'R';
  41949. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  41950. charType = arabicTypes[charCode & 0xff];
  41951. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  41952. charType = 'AL';
  41953. }
  41954. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  41955. numBidi++;
  41956. }
  41957. types[i] = charType;
  41958. }
  41959. // Detect the bidi method
  41960. // - If there are no rtl characters then no bidi needed
  41961. // - If less than 30% chars are rtl then string is primarily ltr
  41962. // - If more than 30% chars are rtl then string is primarily rtl
  41963. if (numBidi === 0) {
  41964. isLTR = true;
  41965. return createBidiText(str, isLTR);
  41966. }
  41967. if (startLevel === -1) {
  41968. if ((strLength / numBidi) < 0.3) {
  41969. isLTR = true;
  41970. startLevel = 0;
  41971. } else {
  41972. isLTR = false;
  41973. startLevel = 1;
  41974. }
  41975. }
  41976. var levels = [];
  41977. for (i = 0; i < strLength; ++i) {
  41978. levels[i] = startLevel;
  41979. }
  41980. /*
  41981. X1-X10: skip most of this, since we are NOT doing the embeddings.
  41982. */
  41983. var e = (isOdd(startLevel) ? 'R' : 'L');
  41984. var sor = e;
  41985. var eor = sor;
  41986. /*
  41987. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  41988. type of the NSM to the type of the previous character. If the NSM is at the
  41989. start of the level run, it will get the type of sor.
  41990. */
  41991. var lastType = sor;
  41992. for (i = 0; i < strLength; ++i) {
  41993. if (types[i] === 'NSM') {
  41994. types[i] = lastType;
  41995. } else {
  41996. lastType = types[i];
  41997. }
  41998. }
  41999. /*
  42000. W2. Search backwards from each instance of a European number until the
  42001. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  42002. the type of the European number to Arabic number.
  42003. */
  42004. lastType = sor;
  42005. var t;
  42006. for (i = 0; i < strLength; ++i) {
  42007. t = types[i];
  42008. if (t === 'EN') {
  42009. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  42010. } else if (t === 'R' || t === 'L' || t === 'AL') {
  42011. lastType = t;
  42012. }
  42013. }
  42014. /*
  42015. W3. Change all ALs to R.
  42016. */
  42017. for (i = 0; i < strLength; ++i) {
  42018. t = types[i];
  42019. if (t === 'AL') {
  42020. types[i] = 'R';
  42021. }
  42022. }
  42023. /*
  42024. W4. A single European separator between two European numbers changes to a
  42025. European number. A single common separator between two numbers of the same
  42026. type changes to that type:
  42027. */
  42028. for (i = 1; i < strLength - 1; ++i) {
  42029. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  42030. types[i] = 'EN';
  42031. }
  42032. if (types[i] === 'CS' &&
  42033. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  42034. types[i + 1] === types[i - 1]) {
  42035. types[i] = types[i - 1];
  42036. }
  42037. }
  42038. /*
  42039. W5. A sequence of European terminators adjacent to European numbers changes
  42040. to all European numbers:
  42041. */
  42042. for (i = 0; i < strLength; ++i) {
  42043. if (types[i] === 'EN') {
  42044. // do before
  42045. var j;
  42046. for (j = i - 1; j >= 0; --j) {
  42047. if (types[j] !== 'ET') {
  42048. break;
  42049. }
  42050. types[j] = 'EN';
  42051. }
  42052. // do after
  42053. for (j = i + 1; j < strLength; --j) {
  42054. if (types[j] !== 'ET') {
  42055. break;
  42056. }
  42057. types[j] = 'EN';
  42058. }
  42059. }
  42060. }
  42061. /*
  42062. W6. Otherwise, separators and terminators change to Other Neutral:
  42063. */
  42064. for (i = 0; i < strLength; ++i) {
  42065. t = types[i];
  42066. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  42067. types[i] = 'ON';
  42068. }
  42069. }
  42070. /*
  42071. W7. Search backwards from each instance of a European number until the
  42072. first strong type (R, L, or sor) is found. If an L is found, then change
  42073. the type of the European number to L.
  42074. */
  42075. lastType = sor;
  42076. for (i = 0; i < strLength; ++i) {
  42077. t = types[i];
  42078. if (t === 'EN') {
  42079. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  42080. } else if (t === 'R' || t === 'L') {
  42081. lastType = t;
  42082. }
  42083. }
  42084. /*
  42085. N1. A sequence of neutrals takes the direction of the surrounding strong
  42086. text if the text on both sides has the same direction. European and Arabic
  42087. numbers are treated as though they were R. Start-of-level-run (sor) and
  42088. end-of-level-run (eor) are used at level run boundaries.
  42089. */
  42090. for (i = 0; i < strLength; ++i) {
  42091. if (types[i] === 'ON') {
  42092. var end = findUnequal(types, i + 1, 'ON');
  42093. var before = sor;
  42094. if (i > 0) {
  42095. before = types[i - 1];
  42096. }
  42097. var after = eor;
  42098. if (end + 1 < strLength) {
  42099. after = types[end + 1];
  42100. }
  42101. if (before !== 'L') {
  42102. before = 'R';
  42103. }
  42104. if (after !== 'L') {
  42105. after = 'R';
  42106. }
  42107. if (before === after) {
  42108. setValues(types, i, end, before);
  42109. }
  42110. i = end - 1; // reset to end (-1 so next iteration is ok)
  42111. }
  42112. }
  42113. /*
  42114. N2. Any remaining neutrals take the embedding direction.
  42115. */
  42116. for (i = 0; i < strLength; ++i) {
  42117. if (types[i] === 'ON') {
  42118. types[i] = e;
  42119. }
  42120. }
  42121. /*
  42122. I1. For all characters with an even (left-to-right) embedding direction,
  42123. those of type R go up one level and those of type AN or EN go up two
  42124. levels.
  42125. I2. For all characters with an odd (right-to-left) embedding direction,
  42126. those of type L, EN or AN go up one level.
  42127. */
  42128. for (i = 0; i < strLength; ++i) {
  42129. t = types[i];
  42130. if (isEven(levels[i])) {
  42131. if (t === 'R') {
  42132. levels[i] += 1;
  42133. } else if (t === 'AN' || t === 'EN') {
  42134. levels[i] += 2;
  42135. }
  42136. } else { // isOdd
  42137. if (t === 'L' || t === 'AN' || t === 'EN') {
  42138. levels[i] += 1;
  42139. }
  42140. }
  42141. }
  42142. /*
  42143. L1. On each line, reset the embedding level of the following characters to
  42144. the paragraph embedding level:
  42145. segment separators,
  42146. paragraph separators,
  42147. any sequence of whitespace characters preceding a segment separator or
  42148. paragraph separator, and any sequence of white space characters at the end
  42149. of the line.
  42150. */
  42151. // don't bother as text is only single line
  42152. /*
  42153. L2. From the highest level found in the text to the lowest odd level on
  42154. each line, reverse any contiguous sequence of characters that are at that
  42155. level or higher.
  42156. */
  42157. // find highest level & lowest odd level
  42158. var highestLevel = -1;
  42159. var lowestOddLevel = 99;
  42160. var level;
  42161. for (i = 0, ii = levels.length; i < ii; ++i) {
  42162. level = levels[i];
  42163. if (highestLevel < level) {
  42164. highestLevel = level;
  42165. }
  42166. if (lowestOddLevel > level && isOdd(level)) {
  42167. lowestOddLevel = level;
  42168. }
  42169. }
  42170. // now reverse between those limits
  42171. for (level = highestLevel; level >= lowestOddLevel; --level) {
  42172. // find segments to reverse
  42173. var start = -1;
  42174. for (i = 0, ii = levels.length; i < ii; ++i) {
  42175. if (levels[i] < level) {
  42176. if (start >= 0) {
  42177. reverseValues(chars, start, i);
  42178. start = -1;
  42179. }
  42180. } else if (start < 0) {
  42181. start = i;
  42182. }
  42183. }
  42184. if (start >= 0) {
  42185. reverseValues(chars, start, levels.length);
  42186. }
  42187. }
  42188. /*
  42189. L3. Combining marks applied to a right-to-left base character will at this
  42190. point precede their base character. If the rendering engine expects them to
  42191. follow the base characters in the final display process, then the ordering
  42192. of the marks and the base character must be reversed.
  42193. */
  42194. // don't bother for now
  42195. /*
  42196. L4. A character that possesses the mirrored property as specified by
  42197. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  42198. directionality of that character is R.
  42199. */
  42200. // don't mirror as characters are already mirrored in the pdf
  42201. // Finally, return string
  42202. var result = '';
  42203. for (i = 0, ii = chars.length; i < ii; ++i) {
  42204. var ch = chars[i];
  42205. if (ch !== '<' && ch !== '>') {
  42206. result += ch;
  42207. }
  42208. }
  42209. return createBidiText(result, isLTR);
  42210. }
  42211. return bidi;
  42212. })();
  42213. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  42214. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  42215. /* Copyright 2014 Opera Software ASA
  42216. *
  42217. * Licensed under the Apache License, Version 2.0 (the "License");
  42218. * you may not use this file except in compliance with the License.
  42219. * You may obtain a copy of the License at
  42220. *
  42221. * http://www.apache.org/licenses/LICENSE-2.0
  42222. *
  42223. * Unless required by applicable law or agreed to in writing, software
  42224. * distributed under the License is distributed on an "AS IS" BASIS,
  42225. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  42226. * See the License for the specific language governing permissions and
  42227. * limitations under the License.
  42228. *
  42229. *
  42230. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  42231. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  42232. */
  42233. /* globals Uint32ArrayView */
  42234. 'use strict';
  42235. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  42236. // Workaround for missing math precison in JS.
  42237. var MASK_HIGH = 0xffff0000;
  42238. var MASK_LOW = 0xffff;
  42239. function MurmurHash3_64 (seed) {
  42240. var SEED = 0xc3d2e1f0;
  42241. this.h1 = seed ? seed & 0xffffffff : SEED;
  42242. this.h2 = seed ? seed & 0xffffffff : SEED;
  42243. }
  42244. var alwaysUseUint32ArrayView = false;
  42245. // old webkits have issues with non-aligned arrays
  42246. try {
  42247. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  42248. } catch (e) {
  42249. alwaysUseUint32ArrayView = true;
  42250. }
  42251. MurmurHash3_64.prototype = {
  42252. update: function MurmurHash3_64_update(input) {
  42253. var useUint32ArrayView = alwaysUseUint32ArrayView;
  42254. var i;
  42255. if (typeof input === 'string') {
  42256. var data = new Uint8Array(input.length * 2);
  42257. var length = 0;
  42258. for (i = 0; i < input.length; i++) {
  42259. var code = input.charCodeAt(i);
  42260. if (code <= 0xff) {
  42261. data[length++] = code;
  42262. }
  42263. else {
  42264. data[length++] = code >>> 8;
  42265. data[length++] = code & 0xff;
  42266. }
  42267. }
  42268. } else if (input instanceof Uint8Array) {
  42269. data = input;
  42270. length = data.length;
  42271. } else if (typeof input === 'object' && ('length' in input)) {
  42272. // processing regular arrays as well, e.g. for IE9
  42273. data = input;
  42274. length = data.length;
  42275. useUint32ArrayView = true;
  42276. } else {
  42277. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  42278. 'Input must be a string or array.');
  42279. }
  42280. var blockCounts = length >> 2;
  42281. var tailLength = length - blockCounts * 4;
  42282. // we don't care about endianness here
  42283. var dataUint32 = useUint32ArrayView ?
  42284. new Uint32ArrayView(data, blockCounts) :
  42285. new Uint32Array(data.buffer, 0, blockCounts);
  42286. var k1 = 0;
  42287. var k2 = 0;
  42288. var h1 = this.h1;
  42289. var h2 = this.h2;
  42290. var C1 = 0xcc9e2d51;
  42291. var C2 = 0x1b873593;
  42292. var C1_LOW = C1 & MASK_LOW;
  42293. var C2_LOW = C2 & MASK_LOW;
  42294. for (i = 0; i < blockCounts; i++) {
  42295. if (i & 1) {
  42296. k1 = dataUint32[i];
  42297. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42298. k1 = k1 << 15 | k1 >>> 17;
  42299. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42300. h1 ^= k1;
  42301. h1 = h1 << 13 | h1 >>> 19;
  42302. h1 = h1 * 5 + 0xe6546b64;
  42303. } else {
  42304. k2 = dataUint32[i];
  42305. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  42306. k2 = k2 << 15 | k2 >>> 17;
  42307. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  42308. h2 ^= k2;
  42309. h2 = h2 << 13 | h2 >>> 19;
  42310. h2 = h2 * 5 + 0xe6546b64;
  42311. }
  42312. }
  42313. k1 = 0;
  42314. switch (tailLength) {
  42315. case 3:
  42316. k1 ^= data[blockCounts * 4 + 2] << 16;
  42317. /* falls through */
  42318. case 2:
  42319. k1 ^= data[blockCounts * 4 + 1] << 8;
  42320. /* falls through */
  42321. case 1:
  42322. k1 ^= data[blockCounts * 4];
  42323. /* falls through */
  42324. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  42325. k1 = k1 << 15 | k1 >>> 17;
  42326. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  42327. if (blockCounts & 1) {
  42328. h1 ^= k1;
  42329. } else {
  42330. h2 ^= k1;
  42331. }
  42332. }
  42333. this.h1 = h1;
  42334. this.h2 = h2;
  42335. return this;
  42336. },
  42337. hexdigest: function MurmurHash3_64_hexdigest () {
  42338. var h1 = this.h1;
  42339. var h2 = this.h2;
  42340. h1 ^= h2 >>> 1;
  42341. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  42342. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  42343. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  42344. h1 ^= h2 >>> 1;
  42345. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  42346. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  42347. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  42348. h1 ^= h2 >>> 1;
  42349. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  42350. var hex = (arr[i] >>> 0).toString(16);
  42351. while (hex.length < 8) {
  42352. hex = '0' + hex;
  42353. }
  42354. str += hex;
  42355. }
  42356. return str;
  42357. }
  42358. };
  42359. return MurmurHash3_64;
  42360. })();
  42361. }).call((typeof window === 'undefined') ? this : window);
  42362. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  42363. // workerSrc is not set -- using last script url to define default location
  42364. PDFJS.workerSrc = (function () {
  42365. 'use strict';
  42366. var scriptTagContainer = document.body ||
  42367. document.getElementsByTagName('head')[0];
  42368. var pdfjsSrc = scriptTagContainer.lastChild.src;
  42369. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  42370. })();
  42371. }