pdf.combined.js 1.4 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /*jshint globalstrict: false */
  16. /* globals PDFJS */
  17. // Initializing PDFJS global object (if still undefined)
  18. if (typeof PDFJS === 'undefined') {
  19. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  20. }
  21. PDFJS.version = '1.3.10';
  22. PDFJS.build = 'fc2d7e8';
  23. (function pdfjsWrapper() {
  24. // Use strict in our context only - users might not want it
  25. 'use strict';
  26. var globalScope = (typeof window === 'undefined') ? this : window;
  27. var isWorker = (typeof window === 'undefined');
  28. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  29. var TextRenderingMode = {
  30. FILL: 0,
  31. STROKE: 1,
  32. FILL_STROKE: 2,
  33. INVISIBLE: 3,
  34. FILL_ADD_TO_PATH: 4,
  35. STROKE_ADD_TO_PATH: 5,
  36. FILL_STROKE_ADD_TO_PATH: 6,
  37. ADD_TO_PATH: 7,
  38. FILL_STROKE_MASK: 3,
  39. ADD_TO_PATH_FLAG: 4
  40. };
  41. var ImageKind = {
  42. GRAYSCALE_1BPP: 1,
  43. RGB_24BPP: 2,
  44. RGBA_32BPP: 3
  45. };
  46. var AnnotationType = {
  47. WIDGET: 1,
  48. TEXT: 2,
  49. LINK: 3
  50. };
  51. var AnnotationBorderStyleType = {
  52. SOLID: 1,
  53. DASHED: 2,
  54. BEVELED: 3,
  55. INSET: 4,
  56. UNDERLINE: 5
  57. };
  58. var StreamType = {
  59. UNKNOWN: 0,
  60. FLATE: 1,
  61. LZW: 2,
  62. DCT: 3,
  63. JPX: 4,
  64. JBIG: 5,
  65. A85: 6,
  66. AHX: 7,
  67. CCF: 8,
  68. RL: 9
  69. };
  70. var FontType = {
  71. UNKNOWN: 0,
  72. TYPE1: 1,
  73. TYPE1C: 2,
  74. CIDFONTTYPE0: 3,
  75. CIDFONTTYPE0C: 4,
  76. TRUETYPE: 5,
  77. CIDFONTTYPE2: 6,
  78. TYPE3: 7,
  79. OPENTYPE: 8,
  80. TYPE0: 9,
  81. MMTYPE1: 10
  82. };
  83. // The global PDFJS object exposes the API
  84. // In production, it will be declared outside a global wrapper
  85. // In development, it will be declared here
  86. if (!globalScope.PDFJS) {
  87. globalScope.PDFJS = {};
  88. }
  89. globalScope.PDFJS.pdfBug = false;
  90. PDFJS.VERBOSITY_LEVELS = {
  91. errors: 0,
  92. warnings: 1,
  93. infos: 5
  94. };
  95. // All the possible operations for an operator list.
  96. var OPS = PDFJS.OPS = {
  97. // Intentionally start from 1 so it is easy to spot bad operators that will be
  98. // 0's.
  99. dependency: 1,
  100. setLineWidth: 2,
  101. setLineCap: 3,
  102. setLineJoin: 4,
  103. setMiterLimit: 5,
  104. setDash: 6,
  105. setRenderingIntent: 7,
  106. setFlatness: 8,
  107. setGState: 9,
  108. save: 10,
  109. restore: 11,
  110. transform: 12,
  111. moveTo: 13,
  112. lineTo: 14,
  113. curveTo: 15,
  114. curveTo2: 16,
  115. curveTo3: 17,
  116. closePath: 18,
  117. rectangle: 19,
  118. stroke: 20,
  119. closeStroke: 21,
  120. fill: 22,
  121. eoFill: 23,
  122. fillStroke: 24,
  123. eoFillStroke: 25,
  124. closeFillStroke: 26,
  125. closeEOFillStroke: 27,
  126. endPath: 28,
  127. clip: 29,
  128. eoClip: 30,
  129. beginText: 31,
  130. endText: 32,
  131. setCharSpacing: 33,
  132. setWordSpacing: 34,
  133. setHScale: 35,
  134. setLeading: 36,
  135. setFont: 37,
  136. setTextRenderingMode: 38,
  137. setTextRise: 39,
  138. moveText: 40,
  139. setLeadingMoveText: 41,
  140. setTextMatrix: 42,
  141. nextLine: 43,
  142. showText: 44,
  143. showSpacedText: 45,
  144. nextLineShowText: 46,
  145. nextLineSetSpacingShowText: 47,
  146. setCharWidth: 48,
  147. setCharWidthAndBounds: 49,
  148. setStrokeColorSpace: 50,
  149. setFillColorSpace: 51,
  150. setStrokeColor: 52,
  151. setStrokeColorN: 53,
  152. setFillColor: 54,
  153. setFillColorN: 55,
  154. setStrokeGray: 56,
  155. setFillGray: 57,
  156. setStrokeRGBColor: 58,
  157. setFillRGBColor: 59,
  158. setStrokeCMYKColor: 60,
  159. setFillCMYKColor: 61,
  160. shadingFill: 62,
  161. beginInlineImage: 63,
  162. beginImageData: 64,
  163. endInlineImage: 65,
  164. paintXObject: 66,
  165. markPoint: 67,
  166. markPointProps: 68,
  167. beginMarkedContent: 69,
  168. beginMarkedContentProps: 70,
  169. endMarkedContent: 71,
  170. beginCompat: 72,
  171. endCompat: 73,
  172. paintFormXObjectBegin: 74,
  173. paintFormXObjectEnd: 75,
  174. beginGroup: 76,
  175. endGroup: 77,
  176. beginAnnotations: 78,
  177. endAnnotations: 79,
  178. beginAnnotation: 80,
  179. endAnnotation: 81,
  180. paintJpegXObject: 82,
  181. paintImageMaskXObject: 83,
  182. paintImageMaskXObjectGroup: 84,
  183. paintImageXObject: 85,
  184. paintInlineImageXObject: 86,
  185. paintInlineImageXObjectGroup: 87,
  186. paintImageXObjectRepeat: 88,
  187. paintImageMaskXObjectRepeat: 89,
  188. paintSolidColorImageMask: 90,
  189. constructPath: 91
  190. };
  191. // A notice for devs. These are good for things that are helpful to devs, such
  192. // as warning that Workers were disabled, which is important to devs but not
  193. // end users.
  194. function info(msg) {
  195. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  196. console.log('Info: ' + msg);
  197. }
  198. }
  199. // Non-fatal warnings.
  200. function warn(msg) {
  201. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  202. console.log('Warning: ' + msg);
  203. }
  204. }
  205. // Deprecated API function -- treated as warnings.
  206. function deprecated(details) {
  207. warn('Deprecated API usage: ' + details);
  208. }
  209. // Fatal errors that should trigger the fallback UI and halt execution by
  210. // throwing an exception.
  211. function error(msg) {
  212. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  213. console.log('Error: ' + msg);
  214. console.log(backtrace());
  215. }
  216. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  217. throw new Error(msg);
  218. }
  219. function backtrace() {
  220. try {
  221. throw new Error();
  222. } catch (e) {
  223. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  224. }
  225. }
  226. function assert(cond, msg) {
  227. if (!cond) {
  228. error(msg);
  229. }
  230. }
  231. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  232. unknown: 'unknown',
  233. forms: 'forms',
  234. javaScript: 'javaScript',
  235. smask: 'smask',
  236. shadingPattern: 'shadingPattern',
  237. font: 'font'
  238. };
  239. var UnsupportedManager = PDFJS.UnsupportedManager =
  240. (function UnsupportedManagerClosure() {
  241. var listeners = [];
  242. return {
  243. listen: function (cb) {
  244. listeners.push(cb);
  245. },
  246. notify: function (featureId) {
  247. warn('Unsupported feature "' + featureId + '"');
  248. for (var i = 0, ii = listeners.length; i < ii; i++) {
  249. listeners[i](featureId);
  250. }
  251. }
  252. };
  253. })();
  254. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  255. // absolute URL, it will be returned as is.
  256. function combineUrl(baseUrl, url) {
  257. if (!url) {
  258. return baseUrl;
  259. }
  260. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  261. return url;
  262. }
  263. var i;
  264. if (url.charAt(0) === '/') {
  265. // absolute path
  266. i = baseUrl.indexOf('://');
  267. if (url.charAt(1) === '/') {
  268. ++i;
  269. } else {
  270. i = baseUrl.indexOf('/', i + 3);
  271. }
  272. return baseUrl.substring(0, i) + url;
  273. } else {
  274. // relative path
  275. var pathLength = baseUrl.length;
  276. i = baseUrl.lastIndexOf('#');
  277. pathLength = i >= 0 ? i : pathLength;
  278. i = baseUrl.lastIndexOf('?', pathLength);
  279. pathLength = i >= 0 ? i : pathLength;
  280. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  281. return baseUrl.substring(0, prefixLength + 1) + url;
  282. }
  283. }
  284. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  285. function isValidUrl(url, allowRelative) {
  286. if (!url) {
  287. return false;
  288. }
  289. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  290. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  291. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  292. if (!protocol) {
  293. return allowRelative;
  294. }
  295. protocol = protocol[0].toLowerCase();
  296. switch (protocol) {
  297. case 'http':
  298. case 'https':
  299. case 'ftp':
  300. case 'mailto':
  301. case 'tel':
  302. return true;
  303. default:
  304. return false;
  305. }
  306. }
  307. PDFJS.isValidUrl = isValidUrl;
  308. function shadow(obj, prop, value) {
  309. Object.defineProperty(obj, prop, { value: value,
  310. enumerable: true,
  311. configurable: true,
  312. writable: false });
  313. return value;
  314. }
  315. PDFJS.shadow = shadow;
  316. var LinkTarget = PDFJS.LinkTarget = {
  317. NONE: 0, // Default value.
  318. SELF: 1,
  319. BLANK: 2,
  320. PARENT: 3,
  321. TOP: 4,
  322. };
  323. var LinkTargetStringMap = [
  324. '',
  325. '_self',
  326. '_blank',
  327. '_parent',
  328. '_top'
  329. ];
  330. function isExternalLinkTargetSet() {
  331. switch (PDFJS.externalLinkTarget) {
  332. case LinkTarget.NONE:
  333. return false;
  334. case LinkTarget.SELF:
  335. case LinkTarget.BLANK:
  336. case LinkTarget.PARENT:
  337. case LinkTarget.TOP:
  338. return true;
  339. }
  340. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  341. // Reset the external link target, to suppress further warnings.
  342. PDFJS.externalLinkTarget = LinkTarget.NONE;
  343. return false;
  344. }
  345. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  346. var PasswordResponses = PDFJS.PasswordResponses = {
  347. NEED_PASSWORD: 1,
  348. INCORRECT_PASSWORD: 2
  349. };
  350. var PasswordException = (function PasswordExceptionClosure() {
  351. function PasswordException(msg, code) {
  352. this.name = 'PasswordException';
  353. this.message = msg;
  354. this.code = code;
  355. }
  356. PasswordException.prototype = new Error();
  357. PasswordException.constructor = PasswordException;
  358. return PasswordException;
  359. })();
  360. PDFJS.PasswordException = PasswordException;
  361. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  362. function UnknownErrorException(msg, details) {
  363. this.name = 'UnknownErrorException';
  364. this.message = msg;
  365. this.details = details;
  366. }
  367. UnknownErrorException.prototype = new Error();
  368. UnknownErrorException.constructor = UnknownErrorException;
  369. return UnknownErrorException;
  370. })();
  371. PDFJS.UnknownErrorException = UnknownErrorException;
  372. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  373. function InvalidPDFException(msg) {
  374. this.name = 'InvalidPDFException';
  375. this.message = msg;
  376. }
  377. InvalidPDFException.prototype = new Error();
  378. InvalidPDFException.constructor = InvalidPDFException;
  379. return InvalidPDFException;
  380. })();
  381. PDFJS.InvalidPDFException = InvalidPDFException;
  382. var MissingPDFException = (function MissingPDFExceptionClosure() {
  383. function MissingPDFException(msg) {
  384. this.name = 'MissingPDFException';
  385. this.message = msg;
  386. }
  387. MissingPDFException.prototype = new Error();
  388. MissingPDFException.constructor = MissingPDFException;
  389. return MissingPDFException;
  390. })();
  391. PDFJS.MissingPDFException = MissingPDFException;
  392. var UnexpectedResponseException =
  393. (function UnexpectedResponseExceptionClosure() {
  394. function UnexpectedResponseException(msg, status) {
  395. this.name = 'UnexpectedResponseException';
  396. this.message = msg;
  397. this.status = status;
  398. }
  399. UnexpectedResponseException.prototype = new Error();
  400. UnexpectedResponseException.constructor = UnexpectedResponseException;
  401. return UnexpectedResponseException;
  402. })();
  403. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  404. var NotImplementedException = (function NotImplementedExceptionClosure() {
  405. function NotImplementedException(msg) {
  406. this.message = msg;
  407. }
  408. NotImplementedException.prototype = new Error();
  409. NotImplementedException.prototype.name = 'NotImplementedException';
  410. NotImplementedException.constructor = NotImplementedException;
  411. return NotImplementedException;
  412. })();
  413. var MissingDataException = (function MissingDataExceptionClosure() {
  414. function MissingDataException(begin, end) {
  415. this.begin = begin;
  416. this.end = end;
  417. this.message = 'Missing data [' + begin + ', ' + end + ')';
  418. }
  419. MissingDataException.prototype = new Error();
  420. MissingDataException.prototype.name = 'MissingDataException';
  421. MissingDataException.constructor = MissingDataException;
  422. return MissingDataException;
  423. })();
  424. var XRefParseException = (function XRefParseExceptionClosure() {
  425. function XRefParseException(msg) {
  426. this.message = msg;
  427. }
  428. XRefParseException.prototype = new Error();
  429. XRefParseException.prototype.name = 'XRefParseException';
  430. XRefParseException.constructor = XRefParseException;
  431. return XRefParseException;
  432. })();
  433. function bytesToString(bytes) {
  434. assert(bytes !== null && typeof bytes === 'object' &&
  435. bytes.length !== undefined, 'Invalid argument for bytesToString');
  436. var length = bytes.length;
  437. var MAX_ARGUMENT_COUNT = 8192;
  438. if (length < MAX_ARGUMENT_COUNT) {
  439. return String.fromCharCode.apply(null, bytes);
  440. }
  441. var strBuf = [];
  442. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  443. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  444. var chunk = bytes.subarray(i, chunkEnd);
  445. strBuf.push(String.fromCharCode.apply(null, chunk));
  446. }
  447. return strBuf.join('');
  448. }
  449. function stringToBytes(str) {
  450. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  451. var length = str.length;
  452. var bytes = new Uint8Array(length);
  453. for (var i = 0; i < length; ++i) {
  454. bytes[i] = str.charCodeAt(i) & 0xFF;
  455. }
  456. return bytes;
  457. }
  458. function string32(value) {
  459. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  460. (value >> 8) & 0xff, value & 0xff);
  461. }
  462. function log2(x) {
  463. var n = 1, i = 0;
  464. while (x > n) {
  465. n <<= 1;
  466. i++;
  467. }
  468. return i;
  469. }
  470. function readInt8(data, start) {
  471. return (data[start] << 24) >> 24;
  472. }
  473. function readUint16(data, offset) {
  474. return (data[offset] << 8) | data[offset + 1];
  475. }
  476. function readUint32(data, offset) {
  477. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  478. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  479. }
  480. // Lazy test the endianness of the platform
  481. // NOTE: This will be 'true' for simulated TypedArrays
  482. function isLittleEndian() {
  483. var buffer8 = new Uint8Array(2);
  484. buffer8[0] = 1;
  485. var buffer16 = new Uint16Array(buffer8.buffer);
  486. return (buffer16[0] === 1);
  487. }
  488. Object.defineProperty(PDFJS, 'isLittleEndian', {
  489. configurable: true,
  490. get: function PDFJS_isLittleEndian() {
  491. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  492. }
  493. });
  494. // Lazy test if the userAgent support CanvasTypedArrays
  495. function hasCanvasTypedArrays() {
  496. var canvas = document.createElement('canvas');
  497. canvas.width = canvas.height = 1;
  498. var ctx = canvas.getContext('2d');
  499. var imageData = ctx.createImageData(1, 1);
  500. return (typeof imageData.data.buffer !== 'undefined');
  501. }
  502. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  503. configurable: true,
  504. get: function PDFJS_hasCanvasTypedArrays() {
  505. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  506. }
  507. });
  508. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  509. function Uint32ArrayView(buffer, length) {
  510. this.buffer = buffer;
  511. this.byteLength = buffer.length;
  512. this.length = length === undefined ? (this.byteLength >> 2) : length;
  513. ensureUint32ArrayViewProps(this.length);
  514. }
  515. Uint32ArrayView.prototype = Object.create(null);
  516. var uint32ArrayViewSetters = 0;
  517. function createUint32ArrayProp(index) {
  518. return {
  519. get: function () {
  520. var buffer = this.buffer, offset = index << 2;
  521. return (buffer[offset] | (buffer[offset + 1] << 8) |
  522. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  523. },
  524. set: function (value) {
  525. var buffer = this.buffer, offset = index << 2;
  526. buffer[offset] = value & 255;
  527. buffer[offset + 1] = (value >> 8) & 255;
  528. buffer[offset + 2] = (value >> 16) & 255;
  529. buffer[offset + 3] = (value >>> 24) & 255;
  530. }
  531. };
  532. }
  533. function ensureUint32ArrayViewProps(length) {
  534. while (uint32ArrayViewSetters < length) {
  535. Object.defineProperty(Uint32ArrayView.prototype,
  536. uint32ArrayViewSetters,
  537. createUint32ArrayProp(uint32ArrayViewSetters));
  538. uint32ArrayViewSetters++;
  539. }
  540. }
  541. return Uint32ArrayView;
  542. })();
  543. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  544. var Util = PDFJS.Util = (function UtilClosure() {
  545. function Util() {}
  546. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  547. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  548. // creating many intermediate strings.
  549. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  550. rgbBuf[1] = r;
  551. rgbBuf[3] = g;
  552. rgbBuf[5] = b;
  553. return rgbBuf.join('');
  554. };
  555. // Concatenates two transformation matrices together and returns the result.
  556. Util.transform = function Util_transform(m1, m2) {
  557. return [
  558. m1[0] * m2[0] + m1[2] * m2[1],
  559. m1[1] * m2[0] + m1[3] * m2[1],
  560. m1[0] * m2[2] + m1[2] * m2[3],
  561. m1[1] * m2[2] + m1[3] * m2[3],
  562. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  563. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  564. ];
  565. };
  566. // For 2d affine transforms
  567. Util.applyTransform = function Util_applyTransform(p, m) {
  568. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  569. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  570. return [xt, yt];
  571. };
  572. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  573. var d = m[0] * m[3] - m[1] * m[2];
  574. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  575. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  576. return [xt, yt];
  577. };
  578. // Applies the transform to the rectangle and finds the minimum axially
  579. // aligned bounding box.
  580. Util.getAxialAlignedBoundingBox =
  581. function Util_getAxialAlignedBoundingBox(r, m) {
  582. var p1 = Util.applyTransform(r, m);
  583. var p2 = Util.applyTransform(r.slice(2, 4), m);
  584. var p3 = Util.applyTransform([r[0], r[3]], m);
  585. var p4 = Util.applyTransform([r[2], r[1]], m);
  586. return [
  587. Math.min(p1[0], p2[0], p3[0], p4[0]),
  588. Math.min(p1[1], p2[1], p3[1], p4[1]),
  589. Math.max(p1[0], p2[0], p3[0], p4[0]),
  590. Math.max(p1[1], p2[1], p3[1], p4[1])
  591. ];
  592. };
  593. Util.inverseTransform = function Util_inverseTransform(m) {
  594. var d = m[0] * m[3] - m[1] * m[2];
  595. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  596. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  597. };
  598. // Apply a generic 3d matrix M on a 3-vector v:
  599. // | a b c | | X |
  600. // | d e f | x | Y |
  601. // | g h i | | Z |
  602. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  603. // with v as [X,Y,Z]
  604. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  605. return [
  606. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  607. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  608. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  609. ];
  610. };
  611. // This calculation uses Singular Value Decomposition.
  612. // The SVD can be represented with formula A = USV. We are interested in the
  613. // matrix S here because it represents the scale values.
  614. Util.singularValueDecompose2dScale =
  615. function Util_singularValueDecompose2dScale(m) {
  616. var transpose = [m[0], m[2], m[1], m[3]];
  617. // Multiply matrix m with its transpose.
  618. var a = m[0] * transpose[0] + m[1] * transpose[2];
  619. var b = m[0] * transpose[1] + m[1] * transpose[3];
  620. var c = m[2] * transpose[0] + m[3] * transpose[2];
  621. var d = m[2] * transpose[1] + m[3] * transpose[3];
  622. // Solve the second degree polynomial to get roots.
  623. var first = (a + d) / 2;
  624. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  625. var sx = first + second || 1;
  626. var sy = first - second || 1;
  627. // Scale values are the square roots of the eigenvalues.
  628. return [Math.sqrt(sx), Math.sqrt(sy)];
  629. };
  630. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  631. // For coordinate systems whose origin lies in the bottom-left, this
  632. // means normalization to (BL,TR) ordering. For systems with origin in the
  633. // top-left, this means (TL,BR) ordering.
  634. Util.normalizeRect = function Util_normalizeRect(rect) {
  635. var r = rect.slice(0); // clone rect
  636. if (rect[0] > rect[2]) {
  637. r[0] = rect[2];
  638. r[2] = rect[0];
  639. }
  640. if (rect[1] > rect[3]) {
  641. r[1] = rect[3];
  642. r[3] = rect[1];
  643. }
  644. return r;
  645. };
  646. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  647. // intersection of rect1 and rect2. If no intersection, returns 'false'
  648. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  649. Util.intersect = function Util_intersect(rect1, rect2) {
  650. function compare(a, b) {
  651. return a - b;
  652. }
  653. // Order points along the axes
  654. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  655. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  656. result = [];
  657. rect1 = Util.normalizeRect(rect1);
  658. rect2 = Util.normalizeRect(rect2);
  659. // X: first and second points belong to different rectangles?
  660. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  661. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  662. // Intersection must be between second and third points
  663. result[0] = orderedX[1];
  664. result[2] = orderedX[2];
  665. } else {
  666. return false;
  667. }
  668. // Y: first and second points belong to different rectangles?
  669. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  670. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  671. // Intersection must be between second and third points
  672. result[1] = orderedY[1];
  673. result[3] = orderedY[2];
  674. } else {
  675. return false;
  676. }
  677. return result;
  678. };
  679. Util.sign = function Util_sign(num) {
  680. return num < 0 ? -1 : 1;
  681. };
  682. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  683. Array.prototype.push.apply(arr1, arr2);
  684. };
  685. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  686. Array.prototype.unshift.apply(arr1, arr2);
  687. };
  688. Util.extendObj = function extendObj(obj1, obj2) {
  689. for (var key in obj2) {
  690. obj1[key] = obj2[key];
  691. }
  692. };
  693. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  694. name) {
  695. while (dict && !dict.has(name)) {
  696. dict = dict.get('Parent');
  697. }
  698. if (!dict) {
  699. return null;
  700. }
  701. return dict.get(name);
  702. };
  703. Util.inherit = function Util_inherit(sub, base, prototype) {
  704. sub.prototype = Object.create(base.prototype);
  705. sub.prototype.constructor = sub;
  706. for (var prop in prototype) {
  707. sub.prototype[prop] = prototype[prop];
  708. }
  709. };
  710. Util.loadScript = function Util_loadScript(src, callback) {
  711. var script = document.createElement('script');
  712. var loaded = false;
  713. script.setAttribute('src', src);
  714. if (callback) {
  715. script.onload = function() {
  716. if (!loaded) {
  717. callback();
  718. }
  719. loaded = true;
  720. };
  721. }
  722. document.getElementsByTagName('head')[0].appendChild(script);
  723. };
  724. return Util;
  725. })();
  726. /**
  727. * PDF page viewport created based on scale, rotation and offset.
  728. * @class
  729. * @alias PDFJS.PageViewport
  730. */
  731. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  732. /**
  733. * @constructor
  734. * @private
  735. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  736. * @param scale {number} scale of the viewport.
  737. * @param rotation {number} rotations of the viewport in degrees.
  738. * @param offsetX {number} offset X
  739. * @param offsetY {number} offset Y
  740. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  741. */
  742. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  743. this.viewBox = viewBox;
  744. this.scale = scale;
  745. this.rotation = rotation;
  746. this.offsetX = offsetX;
  747. this.offsetY = offsetY;
  748. // creating transform to convert pdf coordinate system to the normal
  749. // canvas like coordinates taking in account scale and rotation
  750. var centerX = (viewBox[2] + viewBox[0]) / 2;
  751. var centerY = (viewBox[3] + viewBox[1]) / 2;
  752. var rotateA, rotateB, rotateC, rotateD;
  753. rotation = rotation % 360;
  754. rotation = rotation < 0 ? rotation + 360 : rotation;
  755. switch (rotation) {
  756. case 180:
  757. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  758. break;
  759. case 90:
  760. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  761. break;
  762. case 270:
  763. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  764. break;
  765. //case 0:
  766. default:
  767. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  768. break;
  769. }
  770. if (dontFlip) {
  771. rotateC = -rotateC; rotateD = -rotateD;
  772. }
  773. var offsetCanvasX, offsetCanvasY;
  774. var width, height;
  775. if (rotateA === 0) {
  776. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  777. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  778. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  779. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  780. } else {
  781. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  782. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  783. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  784. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  785. }
  786. // creating transform for the following operations:
  787. // translate(-centerX, -centerY), rotate and flip vertically,
  788. // scale, and translate(offsetCanvasX, offsetCanvasY)
  789. this.transform = [
  790. rotateA * scale,
  791. rotateB * scale,
  792. rotateC * scale,
  793. rotateD * scale,
  794. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  795. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  796. ];
  797. this.width = width;
  798. this.height = height;
  799. this.fontScale = scale;
  800. }
  801. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  802. /**
  803. * Clones viewport with additional properties.
  804. * @param args {Object} (optional) If specified, may contain the 'scale' or
  805. * 'rotation' properties to override the corresponding properties in
  806. * the cloned viewport.
  807. * @returns {PDFJS.PageViewport} Cloned viewport.
  808. */
  809. clone: function PageViewPort_clone(args) {
  810. args = args || {};
  811. var scale = 'scale' in args ? args.scale : this.scale;
  812. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  813. return new PageViewport(this.viewBox.slice(), scale, rotation,
  814. this.offsetX, this.offsetY, args.dontFlip);
  815. },
  816. /**
  817. * Converts PDF point to the viewport coordinates. For examples, useful for
  818. * converting PDF location into canvas pixel coordinates.
  819. * @param x {number} X coordinate.
  820. * @param y {number} Y coordinate.
  821. * @returns {Object} Object that contains 'x' and 'y' properties of the
  822. * point in the viewport coordinate space.
  823. * @see {@link convertToPdfPoint}
  824. * @see {@link convertToViewportRectangle}
  825. */
  826. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  827. return Util.applyTransform([x, y], this.transform);
  828. },
  829. /**
  830. * Converts PDF rectangle to the viewport coordinates.
  831. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  832. * @returns {Array} Contains corresponding coordinates of the rectangle
  833. * in the viewport coordinate space.
  834. * @see {@link convertToViewportPoint}
  835. */
  836. convertToViewportRectangle:
  837. function PageViewport_convertToViewportRectangle(rect) {
  838. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  839. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  840. return [tl[0], tl[1], br[0], br[1]];
  841. },
  842. /**
  843. * Converts viewport coordinates to the PDF location. For examples, useful
  844. * for converting canvas pixel location into PDF one.
  845. * @param x {number} X coordinate.
  846. * @param y {number} Y coordinate.
  847. * @returns {Object} Object that contains 'x' and 'y' properties of the
  848. * point in the PDF coordinate space.
  849. * @see {@link convertToViewportPoint}
  850. */
  851. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  852. return Util.applyInverseTransform([x, y], this.transform);
  853. }
  854. };
  855. return PageViewport;
  856. })();
  857. var PDFStringTranslateTable = [
  858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  859. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  860. 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,
  861. 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,
  862. 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,
  863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  864. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  865. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  866. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  867. ];
  868. function stringToPDFString(str) {
  869. var i, n = str.length, strBuf = [];
  870. if (str[0] === '\xFE' && str[1] === '\xFF') {
  871. // UTF16BE BOM
  872. for (i = 2; i < n; i += 2) {
  873. strBuf.push(String.fromCharCode(
  874. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  875. }
  876. } else {
  877. for (i = 0; i < n; ++i) {
  878. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  879. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  880. }
  881. }
  882. return strBuf.join('');
  883. }
  884. function stringToUTF8String(str) {
  885. return decodeURIComponent(escape(str));
  886. }
  887. function utf8StringToString(str) {
  888. return unescape(encodeURIComponent(str));
  889. }
  890. function isEmptyObj(obj) {
  891. for (var key in obj) {
  892. return false;
  893. }
  894. return true;
  895. }
  896. function isBool(v) {
  897. return typeof v === 'boolean';
  898. }
  899. function isInt(v) {
  900. return typeof v === 'number' && ((v | 0) === v);
  901. }
  902. function isNum(v) {
  903. return typeof v === 'number';
  904. }
  905. function isString(v) {
  906. return typeof v === 'string';
  907. }
  908. function isName(v) {
  909. return v instanceof Name;
  910. }
  911. function isCmd(v, cmd) {
  912. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  913. }
  914. function isDict(v, type) {
  915. if (!(v instanceof Dict)) {
  916. return false;
  917. }
  918. if (!type) {
  919. return true;
  920. }
  921. var dictType = v.get('Type');
  922. return isName(dictType) && dictType.name === type;
  923. }
  924. function isArray(v) {
  925. return v instanceof Array;
  926. }
  927. function isStream(v) {
  928. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  929. }
  930. function isArrayBuffer(v) {
  931. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  932. }
  933. function isRef(v) {
  934. return v instanceof Ref;
  935. }
  936. /**
  937. * Promise Capability object.
  938. *
  939. * @typedef {Object} PromiseCapability
  940. * @property {Promise} promise - A promise object.
  941. * @property {function} resolve - Fullfills the promise.
  942. * @property {function} reject - Rejects the promise.
  943. */
  944. /**
  945. * Creates a promise capability object.
  946. * @alias PDFJS.createPromiseCapability
  947. *
  948. * @return {PromiseCapability} A capability object contains:
  949. * - a Promise, resolve and reject methods.
  950. */
  951. function createPromiseCapability() {
  952. var capability = {};
  953. capability.promise = new Promise(function (resolve, reject) {
  954. capability.resolve = resolve;
  955. capability.reject = reject;
  956. });
  957. return capability;
  958. }
  959. PDFJS.createPromiseCapability = createPromiseCapability;
  960. /**
  961. * Polyfill for Promises:
  962. * The following promise implementation tries to generally implement the
  963. * Promise/A+ spec. Some notable differences from other promise libaries are:
  964. * - There currently isn't a seperate deferred and promise object.
  965. * - Unhandled rejections eventually show an error if they aren't handled.
  966. *
  967. * Based off of the work in:
  968. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  969. */
  970. (function PromiseClosure() {
  971. if (globalScope.Promise) {
  972. // Promises existing in the DOM/Worker, checking presence of all/resolve
  973. if (typeof globalScope.Promise.all !== 'function') {
  974. globalScope.Promise.all = function (iterable) {
  975. var count = 0, results = [], resolve, reject;
  976. var promise = new globalScope.Promise(function (resolve_, reject_) {
  977. resolve = resolve_;
  978. reject = reject_;
  979. });
  980. iterable.forEach(function (p, i) {
  981. count++;
  982. p.then(function (result) {
  983. results[i] = result;
  984. count--;
  985. if (count === 0) {
  986. resolve(results);
  987. }
  988. }, reject);
  989. });
  990. if (count === 0) {
  991. resolve(results);
  992. }
  993. return promise;
  994. };
  995. }
  996. if (typeof globalScope.Promise.resolve !== 'function') {
  997. globalScope.Promise.resolve = function (value) {
  998. return new globalScope.Promise(function (resolve) { resolve(value); });
  999. };
  1000. }
  1001. if (typeof globalScope.Promise.reject !== 'function') {
  1002. globalScope.Promise.reject = function (reason) {
  1003. return new globalScope.Promise(function (resolve, reject) {
  1004. reject(reason);
  1005. });
  1006. };
  1007. }
  1008. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1009. globalScope.Promise.prototype.catch = function (onReject) {
  1010. return globalScope.Promise.prototype.then(undefined, onReject);
  1011. };
  1012. }
  1013. return;
  1014. }
  1015. var STATUS_PENDING = 0;
  1016. var STATUS_RESOLVED = 1;
  1017. var STATUS_REJECTED = 2;
  1018. // In an attempt to avoid silent exceptions, unhandled rejections are
  1019. // tracked and if they aren't handled in a certain amount of time an
  1020. // error is logged.
  1021. var REJECTION_TIMEOUT = 500;
  1022. var HandlerManager = {
  1023. handlers: [],
  1024. running: false,
  1025. unhandledRejections: [],
  1026. pendingRejectionCheck: false,
  1027. scheduleHandlers: function scheduleHandlers(promise) {
  1028. if (promise._status === STATUS_PENDING) {
  1029. return;
  1030. }
  1031. this.handlers = this.handlers.concat(promise._handlers);
  1032. promise._handlers = [];
  1033. if (this.running) {
  1034. return;
  1035. }
  1036. this.running = true;
  1037. setTimeout(this.runHandlers.bind(this), 0);
  1038. },
  1039. runHandlers: function runHandlers() {
  1040. var RUN_TIMEOUT = 1; // ms
  1041. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1042. while (this.handlers.length > 0) {
  1043. var handler = this.handlers.shift();
  1044. var nextStatus = handler.thisPromise._status;
  1045. var nextValue = handler.thisPromise._value;
  1046. try {
  1047. if (nextStatus === STATUS_RESOLVED) {
  1048. if (typeof handler.onResolve === 'function') {
  1049. nextValue = handler.onResolve(nextValue);
  1050. }
  1051. } else if (typeof handler.onReject === 'function') {
  1052. nextValue = handler.onReject(nextValue);
  1053. nextStatus = STATUS_RESOLVED;
  1054. if (handler.thisPromise._unhandledRejection) {
  1055. this.removeUnhandeledRejection(handler.thisPromise);
  1056. }
  1057. }
  1058. } catch (ex) {
  1059. nextStatus = STATUS_REJECTED;
  1060. nextValue = ex;
  1061. }
  1062. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1063. if (Date.now() >= timeoutAt) {
  1064. break;
  1065. }
  1066. }
  1067. if (this.handlers.length > 0) {
  1068. setTimeout(this.runHandlers.bind(this), 0);
  1069. return;
  1070. }
  1071. this.running = false;
  1072. },
  1073. addUnhandledRejection: function addUnhandledRejection(promise) {
  1074. this.unhandledRejections.push({
  1075. promise: promise,
  1076. time: Date.now()
  1077. });
  1078. this.scheduleRejectionCheck();
  1079. },
  1080. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1081. promise._unhandledRejection = false;
  1082. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1083. if (this.unhandledRejections[i].promise === promise) {
  1084. this.unhandledRejections.splice(i);
  1085. i--;
  1086. }
  1087. }
  1088. },
  1089. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1090. if (this.pendingRejectionCheck) {
  1091. return;
  1092. }
  1093. this.pendingRejectionCheck = true;
  1094. setTimeout(function rejectionCheck() {
  1095. this.pendingRejectionCheck = false;
  1096. var now = Date.now();
  1097. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1098. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1099. var unhandled = this.unhandledRejections[i].promise._value;
  1100. var msg = 'Unhandled rejection: ' + unhandled;
  1101. if (unhandled.stack) {
  1102. msg += '\n' + unhandled.stack;
  1103. }
  1104. warn(msg);
  1105. this.unhandledRejections.splice(i);
  1106. i--;
  1107. }
  1108. }
  1109. if (this.unhandledRejections.length) {
  1110. this.scheduleRejectionCheck();
  1111. }
  1112. }.bind(this), REJECTION_TIMEOUT);
  1113. }
  1114. };
  1115. function Promise(resolver) {
  1116. this._status = STATUS_PENDING;
  1117. this._handlers = [];
  1118. try {
  1119. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1120. } catch (e) {
  1121. this._reject(e);
  1122. }
  1123. }
  1124. /**
  1125. * Builds a promise that is resolved when all the passed in promises are
  1126. * resolved.
  1127. * @param {array} array of data and/or promises to wait for.
  1128. * @return {Promise} New dependant promise.
  1129. */
  1130. Promise.all = function Promise_all(promises) {
  1131. var resolveAll, rejectAll;
  1132. var deferred = new Promise(function (resolve, reject) {
  1133. resolveAll = resolve;
  1134. rejectAll = reject;
  1135. });
  1136. var unresolved = promises.length;
  1137. var results = [];
  1138. if (unresolved === 0) {
  1139. resolveAll(results);
  1140. return deferred;
  1141. }
  1142. function reject(reason) {
  1143. if (deferred._status === STATUS_REJECTED) {
  1144. return;
  1145. }
  1146. results = [];
  1147. rejectAll(reason);
  1148. }
  1149. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1150. var promise = promises[i];
  1151. var resolve = (function(i) {
  1152. return function(value) {
  1153. if (deferred._status === STATUS_REJECTED) {
  1154. return;
  1155. }
  1156. results[i] = value;
  1157. unresolved--;
  1158. if (unresolved === 0) {
  1159. resolveAll(results);
  1160. }
  1161. };
  1162. })(i);
  1163. if (Promise.isPromise(promise)) {
  1164. promise.then(resolve, reject);
  1165. } else {
  1166. resolve(promise);
  1167. }
  1168. }
  1169. return deferred;
  1170. };
  1171. /**
  1172. * Checks if the value is likely a promise (has a 'then' function).
  1173. * @return {boolean} true if value is thenable
  1174. */
  1175. Promise.isPromise = function Promise_isPromise(value) {
  1176. return value && typeof value.then === 'function';
  1177. };
  1178. /**
  1179. * Creates resolved promise
  1180. * @param value resolve value
  1181. * @returns {Promise}
  1182. */
  1183. Promise.resolve = function Promise_resolve(value) {
  1184. return new Promise(function (resolve) { resolve(value); });
  1185. };
  1186. /**
  1187. * Creates rejected promise
  1188. * @param reason rejection value
  1189. * @returns {Promise}
  1190. */
  1191. Promise.reject = function Promise_reject(reason) {
  1192. return new Promise(function (resolve, reject) { reject(reason); });
  1193. };
  1194. Promise.prototype = {
  1195. _status: null,
  1196. _value: null,
  1197. _handlers: null,
  1198. _unhandledRejection: null,
  1199. _updateStatus: function Promise__updateStatus(status, value) {
  1200. if (this._status === STATUS_RESOLVED ||
  1201. this._status === STATUS_REJECTED) {
  1202. return;
  1203. }
  1204. if (status === STATUS_RESOLVED &&
  1205. Promise.isPromise(value)) {
  1206. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1207. this._updateStatus.bind(this, STATUS_REJECTED));
  1208. return;
  1209. }
  1210. this._status = status;
  1211. this._value = value;
  1212. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1213. this._unhandledRejection = true;
  1214. HandlerManager.addUnhandledRejection(this);
  1215. }
  1216. HandlerManager.scheduleHandlers(this);
  1217. },
  1218. _resolve: function Promise_resolve(value) {
  1219. this._updateStatus(STATUS_RESOLVED, value);
  1220. },
  1221. _reject: function Promise_reject(reason) {
  1222. this._updateStatus(STATUS_REJECTED, reason);
  1223. },
  1224. then: function Promise_then(onResolve, onReject) {
  1225. var nextPromise = new Promise(function (resolve, reject) {
  1226. this.resolve = resolve;
  1227. this.reject = reject;
  1228. });
  1229. this._handlers.push({
  1230. thisPromise: this,
  1231. onResolve: onResolve,
  1232. onReject: onReject,
  1233. nextPromise: nextPromise
  1234. });
  1235. HandlerManager.scheduleHandlers(this);
  1236. return nextPromise;
  1237. },
  1238. catch: function Promise_catch(onReject) {
  1239. return this.then(undefined, onReject);
  1240. }
  1241. };
  1242. globalScope.Promise = Promise;
  1243. })();
  1244. var StatTimer = (function StatTimerClosure() {
  1245. function rpad(str, pad, length) {
  1246. while (str.length < length) {
  1247. str += pad;
  1248. }
  1249. return str;
  1250. }
  1251. function StatTimer() {
  1252. this.started = {};
  1253. this.times = [];
  1254. this.enabled = true;
  1255. }
  1256. StatTimer.prototype = {
  1257. time: function StatTimer_time(name) {
  1258. if (!this.enabled) {
  1259. return;
  1260. }
  1261. if (name in this.started) {
  1262. warn('Timer is already running for ' + name);
  1263. }
  1264. this.started[name] = Date.now();
  1265. },
  1266. timeEnd: function StatTimer_timeEnd(name) {
  1267. if (!this.enabled) {
  1268. return;
  1269. }
  1270. if (!(name in this.started)) {
  1271. warn('Timer has not been started for ' + name);
  1272. }
  1273. this.times.push({
  1274. 'name': name,
  1275. 'start': this.started[name],
  1276. 'end': Date.now()
  1277. });
  1278. // Remove timer from started so it can be called again.
  1279. delete this.started[name];
  1280. },
  1281. toString: function StatTimer_toString() {
  1282. var i, ii;
  1283. var times = this.times;
  1284. var out = '';
  1285. // Find the longest name for padding purposes.
  1286. var longest = 0;
  1287. for (i = 0, ii = times.length; i < ii; ++i) {
  1288. var name = times[i]['name'];
  1289. if (name.length > longest) {
  1290. longest = name.length;
  1291. }
  1292. }
  1293. for (i = 0, ii = times.length; i < ii; ++i) {
  1294. var span = times[i];
  1295. var duration = span.end - span.start;
  1296. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1297. }
  1298. return out;
  1299. }
  1300. };
  1301. return StatTimer;
  1302. })();
  1303. PDFJS.createBlob = function createBlob(data, contentType) {
  1304. if (typeof Blob !== 'undefined') {
  1305. return new Blob([data], { type: contentType });
  1306. }
  1307. // Blob builder is deprecated in FF14 and removed in FF18.
  1308. var bb = new MozBlobBuilder();
  1309. bb.append(data);
  1310. return bb.getBlob(contentType);
  1311. };
  1312. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1313. // Blob/createObjectURL is not available, falling back to data schema.
  1314. var digits =
  1315. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1316. return function createObjectURL(data, contentType) {
  1317. if (!PDFJS.disableCreateObjectURL &&
  1318. typeof URL !== 'undefined' && URL.createObjectURL) {
  1319. var blob = PDFJS.createBlob(data, contentType);
  1320. return URL.createObjectURL(blob);
  1321. }
  1322. var buffer = 'data:' + contentType + ';base64,';
  1323. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1324. var b1 = data[i] & 0xFF;
  1325. var b2 = data[i + 1] & 0xFF;
  1326. var b3 = data[i + 2] & 0xFF;
  1327. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1328. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1329. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1330. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1331. }
  1332. return buffer;
  1333. };
  1334. })();
  1335. function MessageHandler(name, comObj) {
  1336. this.name = name;
  1337. this.comObj = comObj;
  1338. this.callbackIndex = 1;
  1339. this.postMessageTransfers = true;
  1340. var callbacksCapabilities = this.callbacksCapabilities = {};
  1341. var ah = this.actionHandler = {};
  1342. ah['console_log'] = [function ahConsoleLog(data) {
  1343. console.log.apply(console, data);
  1344. }];
  1345. ah['console_error'] = [function ahConsoleError(data) {
  1346. console.error.apply(console, data);
  1347. }];
  1348. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1349. UnsupportedManager.notify(data);
  1350. }];
  1351. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1352. var data = event.data;
  1353. if (data.isReply) {
  1354. var callbackId = data.callbackId;
  1355. if (data.callbackId in callbacksCapabilities) {
  1356. var callback = callbacksCapabilities[callbackId];
  1357. delete callbacksCapabilities[callbackId];
  1358. if ('error' in data) {
  1359. callback.reject(data.error);
  1360. } else {
  1361. callback.resolve(data.data);
  1362. }
  1363. } else {
  1364. error('Cannot resolve callback ' + callbackId);
  1365. }
  1366. } else if (data.action in ah) {
  1367. var action = ah[data.action];
  1368. if (data.callbackId) {
  1369. Promise.resolve().then(function () {
  1370. return action[0].call(action[1], data.data);
  1371. }).then(function (result) {
  1372. comObj.postMessage({
  1373. isReply: true,
  1374. callbackId: data.callbackId,
  1375. data: result
  1376. });
  1377. }, function (reason) {
  1378. if (reason instanceof Error) {
  1379. // Serialize error to avoid "DataCloneError"
  1380. reason = reason + '';
  1381. }
  1382. comObj.postMessage({
  1383. isReply: true,
  1384. callbackId: data.callbackId,
  1385. error: reason
  1386. });
  1387. });
  1388. } else {
  1389. action[0].call(action[1], data.data);
  1390. }
  1391. } else {
  1392. error('Unknown action from worker: ' + data.action);
  1393. }
  1394. };
  1395. }
  1396. MessageHandler.prototype = {
  1397. on: function messageHandlerOn(actionName, handler, scope) {
  1398. var ah = this.actionHandler;
  1399. if (ah[actionName]) {
  1400. error('There is already an actionName called "' + actionName + '"');
  1401. }
  1402. ah[actionName] = [handler, scope];
  1403. },
  1404. /**
  1405. * Sends a message to the comObj to invoke the action with the supplied data.
  1406. * @param {String} actionName Action to call.
  1407. * @param {JSON} data JSON data to send.
  1408. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1409. */
  1410. send: function messageHandlerSend(actionName, data, transfers) {
  1411. var message = {
  1412. action: actionName,
  1413. data: data
  1414. };
  1415. this.postMessage(message, transfers);
  1416. },
  1417. /**
  1418. * Sends a message to the comObj to invoke the action with the supplied data.
  1419. * Expects that other side will callback with the response.
  1420. * @param {String} actionName Action to call.
  1421. * @param {JSON} data JSON data to send.
  1422. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1423. * @returns {Promise} Promise to be resolved with response data.
  1424. */
  1425. sendWithPromise:
  1426. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1427. var callbackId = this.callbackIndex++;
  1428. var message = {
  1429. action: actionName,
  1430. data: data,
  1431. callbackId: callbackId
  1432. };
  1433. var capability = createPromiseCapability();
  1434. this.callbacksCapabilities[callbackId] = capability;
  1435. try {
  1436. this.postMessage(message, transfers);
  1437. } catch (e) {
  1438. capability.reject(e);
  1439. }
  1440. return capability.promise;
  1441. },
  1442. /**
  1443. * Sends raw message to the comObj.
  1444. * @private
  1445. * @param message {Object} Raw message.
  1446. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1447. */
  1448. postMessage: function (message, transfers) {
  1449. if (transfers && this.postMessageTransfers) {
  1450. this.comObj.postMessage(message, transfers);
  1451. } else {
  1452. this.comObj.postMessage(message);
  1453. }
  1454. }
  1455. };
  1456. function loadJpegStream(id, imageUrl, objs) {
  1457. var img = new Image();
  1458. img.onload = (function loadJpegStream_onloadClosure() {
  1459. objs.resolve(id, img);
  1460. });
  1461. img.onerror = (function loadJpegStream_onerrorClosure() {
  1462. objs.resolve(id, null);
  1463. warn('Error during JPEG image loading');
  1464. });
  1465. img.src = imageUrl;
  1466. }
  1467. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  1468. /**
  1469. * The maximum allowed image size in total pixels e.g. width * height. Images
  1470. * above this value will not be drawn. Use -1 for no limit.
  1471. * @var {number}
  1472. */
  1473. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  1474. -1 : PDFJS.maxImageSize);
  1475. /**
  1476. * The url of where the predefined Adobe CMaps are located. Include trailing
  1477. * slash.
  1478. * @var {string}
  1479. */
  1480. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  1481. /**
  1482. * Specifies if CMaps are binary packed.
  1483. * @var {boolean}
  1484. */
  1485. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  1486. /**
  1487. * By default fonts are converted to OpenType fonts and loaded via font face
  1488. * rules. If disabled, the font will be rendered using a built in font renderer
  1489. * that constructs the glyphs with primitive path commands.
  1490. * @var {boolean}
  1491. */
  1492. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  1493. false : PDFJS.disableFontFace);
  1494. /**
  1495. * Path for image resources, mainly for annotation icons. Include trailing
  1496. * slash.
  1497. * @var {string}
  1498. */
  1499. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  1500. '' : PDFJS.imageResourcesPath);
  1501. /**
  1502. * Disable the web worker and run all code on the main thread. This will happen
  1503. * automatically if the browser doesn't support workers or sending typed arrays
  1504. * to workers.
  1505. * @var {boolean}
  1506. */
  1507. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  1508. false : PDFJS.disableWorker);
  1509. /**
  1510. * Path and filename of the worker file. Required when the worker is enabled in
  1511. * development mode. If unspecified in the production build, the worker will be
  1512. * loaded based on the location of the pdf.js file. It is recommended that
  1513. * the workerSrc is set in a custom application to prevent issues caused by
  1514. * third-party frameworks and libraries.
  1515. * @var {string}
  1516. */
  1517. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  1518. /**
  1519. * Disable range request loading of PDF files. When enabled and if the server
  1520. * supports partial content requests then the PDF will be fetched in chunks.
  1521. * Enabled (false) by default.
  1522. * @var {boolean}
  1523. */
  1524. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  1525. false : PDFJS.disableRange);
  1526. /**
  1527. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  1528. * in chunks. This default behavior can be disabled.
  1529. * @var {boolean}
  1530. */
  1531. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  1532. false : PDFJS.disableStream);
  1533. /**
  1534. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  1535. * will automatically keep fetching more data even if it isn't needed to display
  1536. * the current page. This default behavior can be disabled.
  1537. *
  1538. * NOTE: It is also necessary to disable streaming, see above,
  1539. * in order for disabling of pre-fetching to work correctly.
  1540. * @var {boolean}
  1541. */
  1542. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  1543. false : PDFJS.disableAutoFetch);
  1544. /**
  1545. * Enables special hooks for debugging PDF.js.
  1546. * @var {boolean}
  1547. */
  1548. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  1549. /**
  1550. * Enables transfer usage in postMessage for ArrayBuffers.
  1551. * @var {boolean}
  1552. */
  1553. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  1554. true : PDFJS.postMessageTransfers);
  1555. /**
  1556. * Disables URL.createObjectURL usage.
  1557. * @var {boolean}
  1558. */
  1559. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  1560. false : PDFJS.disableCreateObjectURL);
  1561. /**
  1562. * Disables WebGL usage.
  1563. * @var {boolean}
  1564. */
  1565. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  1566. true : PDFJS.disableWebGL);
  1567. /**
  1568. * Disables fullscreen support, and by extension Presentation Mode,
  1569. * in browsers which support the fullscreen API.
  1570. * @var {boolean}
  1571. */
  1572. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  1573. false : PDFJS.disableFullscreen);
  1574. /**
  1575. * Enables CSS only zooming.
  1576. * @var {boolean}
  1577. */
  1578. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  1579. false : PDFJS.useOnlyCssZoom);
  1580. /**
  1581. * Controls the logging level.
  1582. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  1583. * - errors
  1584. * - warnings [default]
  1585. * - infos
  1586. * @var {number}
  1587. */
  1588. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  1589. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  1590. /**
  1591. * The maximum supported canvas size in total pixels e.g. width * height.
  1592. * The default value is 4096 * 4096. Use -1 for no limit.
  1593. * @var {number}
  1594. */
  1595. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  1596. 16777216 : PDFJS.maxCanvasPixels);
  1597. /**
  1598. * (Deprecated) Opens external links in a new window if enabled.
  1599. * The default behavior opens external links in the PDF.js window.
  1600. * @var {boolean}
  1601. */
  1602. PDFJS.openExternalLinksInNewWindow = (
  1603. PDFJS.openExternalLinksInNewWindow === undefined ?
  1604. false : PDFJS.openExternalLinksInNewWindow);
  1605. /**
  1606. * Specifies the |target| attribute for external links.
  1607. * The constants from PDFJS.LinkTarget should be used:
  1608. * - NONE [default]
  1609. * - SELF
  1610. * - BLANK
  1611. * - PARENT
  1612. * - TOP
  1613. * @var {number}
  1614. */
  1615. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  1616. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  1617. /**
  1618. * Determines if we can eval strings as JS. Primarily used to improve
  1619. * performance for font rendering.
  1620. * @var {boolean}
  1621. */
  1622. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  1623. true : PDFJS.isEvalSupported);
  1624. /**
  1625. * Document initialization / loading parameters object.
  1626. *
  1627. * @typedef {Object} DocumentInitParameters
  1628. * @property {string} url - The URL of the PDF.
  1629. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  1630. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  1631. * use atob() to convert it to a binary string first.
  1632. * @property {Object} httpHeaders - Basic authentication headers.
  1633. * @property {boolean} withCredentials - Indicates whether or not cross-site
  1634. * Access-Control requests should be made using credentials such as cookies
  1635. * or authorization headers. The default is false.
  1636. * @property {string} password - For decrypting password-protected PDFs.
  1637. * @property {TypedArray} initialData - A typed array with the first portion or
  1638. * all of the pdf data. Used by the extension since some data is already
  1639. * loaded before the switch to range requests.
  1640. * @property {number} length - The PDF file length. It's used for progress
  1641. * reports and range requests operations.
  1642. * @property {PDFDataRangeTransport} range
  1643. * @property {number} rangeChunkSize - Optional parameter to specify
  1644. * maximum number of bytes fetched per range request. The default value is
  1645. * 2^16 = 65536.
  1646. */
  1647. /**
  1648. * @typedef {Object} PDFDocumentStats
  1649. * @property {Array} streamTypes - Used stream types in the document (an item
  1650. * is set to true if specific stream ID was used in the document).
  1651. * @property {Array} fontTypes - Used font type in the document (an item is set
  1652. * to true if specific font ID was used in the document).
  1653. */
  1654. /**
  1655. * This is the main entry point for loading a PDF and interacting with it.
  1656. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  1657. * is used, which means it must follow the same origin rules that any XHR does
  1658. * e.g. No cross domain requests without CORS.
  1659. *
  1660. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  1661. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  1662. * already populated with data or parameter object.
  1663. *
  1664. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  1665. * if you want to manually serve range requests for data in the PDF.
  1666. *
  1667. * @param {function} passwordCallback (deprecated) It is used to request a
  1668. * password if wrong or no password was provided. The callback receives two
  1669. * parameters: function that needs to be called with new password and reason
  1670. * (see {PasswordResponses}).
  1671. *
  1672. * @param {function} progressCallback (deprecated) It is used to be able to
  1673. * monitor the loading progress of the PDF file (necessary to implement e.g.
  1674. * a loading bar). The callback receives an {Object} with the properties:
  1675. * {number} loaded and {number} total.
  1676. *
  1677. * @return {PDFDocumentLoadingTask}
  1678. */
  1679. PDFJS.getDocument = function getDocument(src,
  1680. pdfDataRangeTransport,
  1681. passwordCallback,
  1682. progressCallback) {
  1683. var task = new PDFDocumentLoadingTask();
  1684. // Support of the obsolete arguments (for compatibility with API v1.0)
  1685. if (arguments.length > 1) {
  1686. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  1687. 'passwordCallback or progressCallback argument');
  1688. }
  1689. if (pdfDataRangeTransport) {
  1690. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  1691. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  1692. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  1693. pdfDataRangeTransport.length = src.length;
  1694. pdfDataRangeTransport.initialData = src.initialData;
  1695. if (!pdfDataRangeTransport.abort) {
  1696. pdfDataRangeTransport.abort = function () {};
  1697. }
  1698. }
  1699. src = Object.create(src);
  1700. src.range = pdfDataRangeTransport;
  1701. }
  1702. task.onPassword = passwordCallback || null;
  1703. task.onProgress = progressCallback || null;
  1704. var workerInitializedCapability, transport;
  1705. var source;
  1706. if (typeof src === 'string') {
  1707. source = { url: src };
  1708. } else if (isArrayBuffer(src)) {
  1709. source = { data: src };
  1710. } else if (src instanceof PDFDataRangeTransport) {
  1711. source = { range: src };
  1712. } else {
  1713. if (typeof src !== 'object') {
  1714. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  1715. 'string or a parameter object');
  1716. }
  1717. if (!src.url && !src.data && !src.range) {
  1718. error('Invalid parameter object: need either .data, .range or .url');
  1719. }
  1720. source = src;
  1721. }
  1722. var params = {};
  1723. for (var key in source) {
  1724. if (key === 'url' && typeof window !== 'undefined') {
  1725. // The full path is required in the 'url' field.
  1726. params[key] = combineUrl(window.location.href, source[key]);
  1727. continue;
  1728. } else if (key === 'range') {
  1729. continue;
  1730. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  1731. // Converting string or array-like data to Uint8Array.
  1732. var pdfBytes = source[key];
  1733. if (typeof pdfBytes === 'string') {
  1734. params[key] = stringToBytes(pdfBytes);
  1735. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  1736. !isNaN(pdfBytes.length)) {
  1737. params[key] = new Uint8Array(pdfBytes);
  1738. } else if (isArrayBuffer(pdfBytes)) {
  1739. params[key] = new Uint8Array(pdfBytes);
  1740. } else {
  1741. error('Invalid PDF binary data: either typed array, string or ' +
  1742. 'array-like object is expected in the data property.');
  1743. }
  1744. continue;
  1745. }
  1746. params[key] = source[key];
  1747. }
  1748. params.rangeChunkSize = source.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  1749. workerInitializedCapability = createPromiseCapability();
  1750. transport = new WorkerTransport(workerInitializedCapability, source.range);
  1751. workerInitializedCapability.promise.then(function transportInitialized() {
  1752. transport.fetchDocument(task, params);
  1753. });
  1754. task._transport = transport;
  1755. return task;
  1756. };
  1757. /**
  1758. * PDF document loading operation.
  1759. * @class
  1760. * @alias PDFDocumentLoadingTask
  1761. */
  1762. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  1763. function PDFDocumentLoadingTask() {
  1764. this._capability = createPromiseCapability();
  1765. this._transport = null;
  1766. /**
  1767. * Callback to request a password if wrong or no password was provided.
  1768. * The callback receives two parameters: function that needs to be called
  1769. * with new password and reason (see {PasswordResponses}).
  1770. */
  1771. this.onPassword = null;
  1772. /**
  1773. * Callback to be able to monitor the loading progress of the PDF file
  1774. * (necessary to implement e.g. a loading bar). The callback receives
  1775. * an {Object} with the properties: {number} loaded and {number} total.
  1776. */
  1777. this.onProgress = null;
  1778. }
  1779. PDFDocumentLoadingTask.prototype =
  1780. /** @lends PDFDocumentLoadingTask.prototype */ {
  1781. /**
  1782. * @return {Promise}
  1783. */
  1784. get promise() {
  1785. return this._capability.promise;
  1786. },
  1787. /**
  1788. * Aborts all network requests and destroys worker.
  1789. * @return {Promise} A promise that is resolved after destruction activity
  1790. * is completed.
  1791. */
  1792. destroy: function () {
  1793. return this._transport.destroy();
  1794. },
  1795. /**
  1796. * Registers callbacks to indicate the document loading completion.
  1797. *
  1798. * @param {function} onFulfilled The callback for the loading completion.
  1799. * @param {function} onRejected The callback for the loading failure.
  1800. * @return {Promise} A promise that is resolved after the onFulfilled or
  1801. * onRejected callback.
  1802. */
  1803. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  1804. return this.promise.then.apply(this.promise, arguments);
  1805. }
  1806. };
  1807. return PDFDocumentLoadingTask;
  1808. })();
  1809. /**
  1810. * Abstract class to support range requests file loading.
  1811. * @class
  1812. * @alias PDFJS.PDFDataRangeTransport
  1813. * @param {number} length
  1814. * @param {Uint8Array} initialData
  1815. */
  1816. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  1817. function PDFDataRangeTransport(length, initialData) {
  1818. this.length = length;
  1819. this.initialData = initialData;
  1820. this._rangeListeners = [];
  1821. this._progressListeners = [];
  1822. this._progressiveReadListeners = [];
  1823. this._readyCapability = createPromiseCapability();
  1824. }
  1825. PDFDataRangeTransport.prototype =
  1826. /** @lends PDFDataRangeTransport.prototype */ {
  1827. addRangeListener:
  1828. function PDFDataRangeTransport_addRangeListener(listener) {
  1829. this._rangeListeners.push(listener);
  1830. },
  1831. addProgressListener:
  1832. function PDFDataRangeTransport_addProgressListener(listener) {
  1833. this._progressListeners.push(listener);
  1834. },
  1835. addProgressiveReadListener:
  1836. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  1837. this._progressiveReadListeners.push(listener);
  1838. },
  1839. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  1840. var listeners = this._rangeListeners;
  1841. for (var i = 0, n = listeners.length; i < n; ++i) {
  1842. listeners[i](begin, chunk);
  1843. }
  1844. },
  1845. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  1846. this._readyCapability.promise.then(function () {
  1847. var listeners = this._progressListeners;
  1848. for (var i = 0, n = listeners.length; i < n; ++i) {
  1849. listeners[i](loaded);
  1850. }
  1851. }.bind(this));
  1852. },
  1853. onDataProgressiveRead:
  1854. function PDFDataRangeTransport_onDataProgress(chunk) {
  1855. this._readyCapability.promise.then(function () {
  1856. var listeners = this._progressiveReadListeners;
  1857. for (var i = 0, n = listeners.length; i < n; ++i) {
  1858. listeners[i](chunk);
  1859. }
  1860. }.bind(this));
  1861. },
  1862. transportReady: function PDFDataRangeTransport_transportReady() {
  1863. this._readyCapability.resolve();
  1864. },
  1865. requestDataRange:
  1866. function PDFDataRangeTransport_requestDataRange(begin, end) {
  1867. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  1868. },
  1869. abort: function PDFDataRangeTransport_abort() {
  1870. }
  1871. };
  1872. return PDFDataRangeTransport;
  1873. })();
  1874. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  1875. /**
  1876. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  1877. * properties that can be read synchronously.
  1878. * @class
  1879. * @alias PDFDocumentProxy
  1880. */
  1881. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  1882. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  1883. this.pdfInfo = pdfInfo;
  1884. this.transport = transport;
  1885. this.loadingTask = loadingTask;
  1886. }
  1887. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  1888. /**
  1889. * @return {number} Total number of pages the PDF contains.
  1890. */
  1891. get numPages() {
  1892. return this.pdfInfo.numPages;
  1893. },
  1894. /**
  1895. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  1896. * unique.
  1897. */
  1898. get fingerprint() {
  1899. return this.pdfInfo.fingerprint;
  1900. },
  1901. /**
  1902. * @param {number} pageNumber The page number to get. The first page is 1.
  1903. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  1904. * object.
  1905. */
  1906. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  1907. return this.transport.getPage(pageNumber);
  1908. },
  1909. /**
  1910. * @param {{num: number, gen: number}} ref The page reference. Must have
  1911. * the 'num' and 'gen' properties.
  1912. * @return {Promise} A promise that is resolved with the page index that is
  1913. * associated with the reference.
  1914. */
  1915. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  1916. return this.transport.getPageIndex(ref);
  1917. },
  1918. /**
  1919. * @return {Promise} A promise that is resolved with a lookup table for
  1920. * mapping named destinations to reference numbers.
  1921. *
  1922. * This can be slow for large documents: use getDestination instead
  1923. */
  1924. getDestinations: function PDFDocumentProxy_getDestinations() {
  1925. return this.transport.getDestinations();
  1926. },
  1927. /**
  1928. * @param {string} id The named destination to get.
  1929. * @return {Promise} A promise that is resolved with all information
  1930. * of the given named destination.
  1931. */
  1932. getDestination: function PDFDocumentProxy_getDestination(id) {
  1933. return this.transport.getDestination(id);
  1934. },
  1935. /**
  1936. * @return {Promise} A promise that is resolved with a lookup table for
  1937. * mapping named attachments to their content.
  1938. */
  1939. getAttachments: function PDFDocumentProxy_getAttachments() {
  1940. return this.transport.getAttachments();
  1941. },
  1942. /**
  1943. * @return {Promise} A promise that is resolved with an array of all the
  1944. * JavaScript strings in the name tree.
  1945. */
  1946. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  1947. return this.transport.getJavaScript();
  1948. },
  1949. /**
  1950. * @return {Promise} A promise that is resolved with an {Array} that is a
  1951. * tree outline (if it has one) of the PDF. The tree is in the format of:
  1952. * [
  1953. * {
  1954. * title: string,
  1955. * bold: boolean,
  1956. * italic: boolean,
  1957. * color: rgb array,
  1958. * dest: dest obj,
  1959. * items: array of more items like this
  1960. * },
  1961. * ...
  1962. * ].
  1963. */
  1964. getOutline: function PDFDocumentProxy_getOutline() {
  1965. return this.transport.getOutline();
  1966. },
  1967. /**
  1968. * @return {Promise} A promise that is resolved with an {Object} that has
  1969. * info and metadata properties. Info is an {Object} filled with anything
  1970. * available in the information dictionary and similarly metadata is a
  1971. * {Metadata} object with information from the metadata section of the PDF.
  1972. */
  1973. getMetadata: function PDFDocumentProxy_getMetadata() {
  1974. return this.transport.getMetadata();
  1975. },
  1976. /**
  1977. * @return {Promise} A promise that is resolved with a TypedArray that has
  1978. * the raw data from the PDF.
  1979. */
  1980. getData: function PDFDocumentProxy_getData() {
  1981. return this.transport.getData();
  1982. },
  1983. /**
  1984. * @return {Promise} A promise that is resolved when the document's data
  1985. * is loaded. It is resolved with an {Object} that contains the length
  1986. * property that indicates size of the PDF data in bytes.
  1987. */
  1988. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  1989. return this.transport.downloadInfoCapability.promise;
  1990. },
  1991. /**
  1992. * @return {Promise} A promise this is resolved with current stats about
  1993. * document structures (see {@link PDFDocumentStats}).
  1994. */
  1995. getStats: function PDFDocumentProxy_getStats() {
  1996. return this.transport.getStats();
  1997. },
  1998. /**
  1999. * Cleans up resources allocated by the document, e.g. created @font-face.
  2000. */
  2001. cleanup: function PDFDocumentProxy_cleanup() {
  2002. this.transport.startCleanup();
  2003. },
  2004. /**
  2005. * Destroys current document instance and terminates worker.
  2006. */
  2007. destroy: function PDFDocumentProxy_destroy() {
  2008. return this.transport.destroy();
  2009. }
  2010. };
  2011. return PDFDocumentProxy;
  2012. })();
  2013. /**
  2014. * Page text content.
  2015. *
  2016. * @typedef {Object} TextContent
  2017. * @property {array} items - array of {@link TextItem}
  2018. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  2019. * name.
  2020. */
  2021. /**
  2022. * Page text content part.
  2023. *
  2024. * @typedef {Object} TextItem
  2025. * @property {string} str - text content.
  2026. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  2027. * @property {array} transform - transformation matrix.
  2028. * @property {number} width - width in device space.
  2029. * @property {number} height - height in device space.
  2030. * @property {string} fontName - font name used by pdf.js for converted font.
  2031. */
  2032. /**
  2033. * Text style.
  2034. *
  2035. * @typedef {Object} TextStyle
  2036. * @property {number} ascent - font ascent.
  2037. * @property {number} descent - font descent.
  2038. * @property {boolean} vertical - text is in vertical mode.
  2039. * @property {string} fontFamily - possible font family
  2040. */
  2041. /**
  2042. * Page render parameters.
  2043. *
  2044. * @typedef {Object} RenderParameters
  2045. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  2046. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  2047. * calling of PDFPage.getViewport method.
  2048. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  2049. * (default value is 'display').
  2050. * @property {Array} transform - (optional) Additional transform, applied
  2051. * just before viewport transform.
  2052. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  2053. * endLayout and appendImage functions.
  2054. * @property {function} continueCallback - (deprecated) A function that will be
  2055. * called each time the rendering is paused. To continue
  2056. * rendering call the function that is the first argument
  2057. * to the callback.
  2058. */
  2059. /**
  2060. * PDF page operator list.
  2061. *
  2062. * @typedef {Object} PDFOperatorList
  2063. * @property {Array} fnArray - Array containing the operator functions.
  2064. * @property {Array} argsArray - Array containing the arguments of the
  2065. * functions.
  2066. */
  2067. /**
  2068. * Proxy to a PDFPage in the worker thread.
  2069. * @class
  2070. * @alias PDFPageProxy
  2071. */
  2072. var PDFPageProxy = (function PDFPageProxyClosure() {
  2073. function PDFPageProxy(pageIndex, pageInfo, transport) {
  2074. this.pageIndex = pageIndex;
  2075. this.pageInfo = pageInfo;
  2076. this.transport = transport;
  2077. this.stats = new StatTimer();
  2078. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  2079. this.commonObjs = transport.commonObjs;
  2080. this.objs = new PDFObjects();
  2081. this.cleanupAfterRender = false;
  2082. this.pendingCleanup = false;
  2083. this.intentStates = {};
  2084. this.destroyed = false;
  2085. }
  2086. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  2087. /**
  2088. * @return {number} Page number of the page. First page is 1.
  2089. */
  2090. get pageNumber() {
  2091. return this.pageIndex + 1;
  2092. },
  2093. /**
  2094. * @return {number} The number of degrees the page is rotated clockwise.
  2095. */
  2096. get rotate() {
  2097. return this.pageInfo.rotate;
  2098. },
  2099. /**
  2100. * @return {Object} The reference that points to this page. It has 'num' and
  2101. * 'gen' properties.
  2102. */
  2103. get ref() {
  2104. return this.pageInfo.ref;
  2105. },
  2106. /**
  2107. * @return {Array} An array of the visible portion of the PDF page in the
  2108. * user space units - [x1, y1, x2, y2].
  2109. */
  2110. get view() {
  2111. return this.pageInfo.view;
  2112. },
  2113. /**
  2114. * @param {number} scale The desired scale of the viewport.
  2115. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  2116. * defaults to the page rotation.
  2117. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  2118. * along with transforms required for rendering.
  2119. */
  2120. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  2121. if (arguments.length < 2) {
  2122. rotate = this.rotate;
  2123. }
  2124. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  2125. },
  2126. /**
  2127. * @return {Promise} A promise that is resolved with an {Array} of the
  2128. * annotation objects.
  2129. */
  2130. getAnnotations: function PDFPageProxy_getAnnotations() {
  2131. if (!this.annotationsPromise) {
  2132. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex);
  2133. }
  2134. return this.annotationsPromise;
  2135. },
  2136. /**
  2137. * Begins the process of rendering a page to the desired context.
  2138. * @param {RenderParameters} params Page render parameters.
  2139. * @return {RenderTask} An object that contains the promise, which
  2140. * is resolved when the page finishes rendering.
  2141. */
  2142. render: function PDFPageProxy_render(params) {
  2143. var stats = this.stats;
  2144. stats.time('Overall');
  2145. // If there was a pending destroy cancel it so no cleanup happens during
  2146. // this call to render.
  2147. this.pendingCleanup = false;
  2148. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  2149. if (!this.intentStates[renderingIntent]) {
  2150. this.intentStates[renderingIntent] = {};
  2151. }
  2152. var intentState = this.intentStates[renderingIntent];
  2153. // If there's no displayReadyCapability yet, then the operatorList
  2154. // was never requested before. Make the request and create the promise.
  2155. if (!intentState.displayReadyCapability) {
  2156. intentState.receivingOperatorList = true;
  2157. intentState.displayReadyCapability = createPromiseCapability();
  2158. intentState.operatorList = {
  2159. fnArray: [],
  2160. argsArray: [],
  2161. lastChunk: false
  2162. };
  2163. this.stats.time('Page Request');
  2164. this.transport.messageHandler.send('RenderPageRequest', {
  2165. pageIndex: this.pageNumber - 1,
  2166. intent: renderingIntent
  2167. });
  2168. }
  2169. var internalRenderTask = new InternalRenderTask(complete, params,
  2170. this.objs,
  2171. this.commonObjs,
  2172. intentState.operatorList,
  2173. this.pageNumber);
  2174. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  2175. if (!intentState.renderTasks) {
  2176. intentState.renderTasks = [];
  2177. }
  2178. intentState.renderTasks.push(internalRenderTask);
  2179. var renderTask = internalRenderTask.task;
  2180. // Obsolete parameter support
  2181. if (params.continueCallback) {
  2182. deprecated('render is used with continueCallback parameter');
  2183. renderTask.onContinue = params.continueCallback;
  2184. }
  2185. var self = this;
  2186. intentState.displayReadyCapability.promise.then(
  2187. function pageDisplayReadyPromise(transparency) {
  2188. if (self.pendingCleanup) {
  2189. complete();
  2190. return;
  2191. }
  2192. stats.time('Rendering');
  2193. internalRenderTask.initalizeGraphics(transparency);
  2194. internalRenderTask.operatorListChanged();
  2195. },
  2196. function pageDisplayReadPromiseError(reason) {
  2197. complete(reason);
  2198. }
  2199. );
  2200. function complete(error) {
  2201. var i = intentState.renderTasks.indexOf(internalRenderTask);
  2202. if (i >= 0) {
  2203. intentState.renderTasks.splice(i, 1);
  2204. }
  2205. if (self.cleanupAfterRender) {
  2206. self.pendingCleanup = true;
  2207. }
  2208. self._tryCleanup();
  2209. if (error) {
  2210. internalRenderTask.capability.reject(error);
  2211. } else {
  2212. internalRenderTask.capability.resolve();
  2213. }
  2214. stats.timeEnd('Rendering');
  2215. stats.timeEnd('Overall');
  2216. }
  2217. return renderTask;
  2218. },
  2219. /**
  2220. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  2221. * object that represents page's operator list.
  2222. */
  2223. getOperatorList: function PDFPageProxy_getOperatorList() {
  2224. function operatorListChanged() {
  2225. if (intentState.operatorList.lastChunk) {
  2226. intentState.opListReadCapability.resolve(intentState.operatorList);
  2227. }
  2228. }
  2229. var renderingIntent = 'oplist';
  2230. if (!this.intentStates[renderingIntent]) {
  2231. this.intentStates[renderingIntent] = {};
  2232. }
  2233. var intentState = this.intentStates[renderingIntent];
  2234. if (!intentState.opListReadCapability) {
  2235. var opListTask = {};
  2236. opListTask.operatorListChanged = operatorListChanged;
  2237. intentState.receivingOperatorList = true;
  2238. intentState.opListReadCapability = createPromiseCapability();
  2239. intentState.renderTasks = [];
  2240. intentState.renderTasks.push(opListTask);
  2241. intentState.operatorList = {
  2242. fnArray: [],
  2243. argsArray: [],
  2244. lastChunk: false
  2245. };
  2246. this.transport.messageHandler.send('RenderPageRequest', {
  2247. pageIndex: this.pageIndex,
  2248. intent: renderingIntent
  2249. });
  2250. }
  2251. return intentState.opListReadCapability.promise;
  2252. },
  2253. /**
  2254. * @return {Promise} That is resolved a {@link TextContent}
  2255. * object that represent the page text content.
  2256. */
  2257. getTextContent: function PDFPageProxy_getTextContent() {
  2258. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  2259. pageIndex: this.pageNumber - 1
  2260. });
  2261. },
  2262. /**
  2263. * Destroys page object.
  2264. */
  2265. _destroy: function PDFPageProxy_destroy() {
  2266. this.destroyed = true;
  2267. this.transport.pageCache[this.pageIndex] = null;
  2268. var waitOn = [];
  2269. Object.keys(this.intentStates).forEach(function(intent) {
  2270. var intentState = this.intentStates[intent];
  2271. intentState.renderTasks.forEach(function(renderTask) {
  2272. var renderCompleted = renderTask.capability.promise.
  2273. catch(function () {}); // ignoring failures
  2274. waitOn.push(renderCompleted);
  2275. renderTask.cancel();
  2276. });
  2277. }, this);
  2278. this.objs.clear();
  2279. this.annotationsPromise = null;
  2280. this.pendingCleanup = false;
  2281. return Promise.all(waitOn);
  2282. },
  2283. /**
  2284. * Cleans up resources allocated by the page. (deprecated)
  2285. */
  2286. destroy: function() {
  2287. deprecated('page destroy method, use cleanup() instead');
  2288. this.cleanup();
  2289. },
  2290. /**
  2291. * Cleans up resources allocated by the page.
  2292. */
  2293. cleanup: function PDFPageProxy_cleanup() {
  2294. this.pendingCleanup = true;
  2295. this._tryCleanup();
  2296. },
  2297. /**
  2298. * For internal use only. Attempts to clean up if rendering is in a state
  2299. * where that's possible.
  2300. * @ignore
  2301. */
  2302. _tryCleanup: function PDFPageProxy_tryCleanup() {
  2303. if (!this.pendingCleanup ||
  2304. Object.keys(this.intentStates).some(function(intent) {
  2305. var intentState = this.intentStates[intent];
  2306. return (intentState.renderTasks.length !== 0 ||
  2307. intentState.receivingOperatorList);
  2308. }, this)) {
  2309. return;
  2310. }
  2311. Object.keys(this.intentStates).forEach(function(intent) {
  2312. delete this.intentStates[intent];
  2313. }, this);
  2314. this.objs.clear();
  2315. this.annotationsPromise = null;
  2316. this.pendingCleanup = false;
  2317. },
  2318. /**
  2319. * For internal use only.
  2320. * @ignore
  2321. */
  2322. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  2323. intent) {
  2324. var intentState = this.intentStates[intent];
  2325. // TODO Refactor RenderPageRequest to separate rendering
  2326. // and operator list logic
  2327. if (intentState.displayReadyCapability) {
  2328. intentState.displayReadyCapability.resolve(transparency);
  2329. }
  2330. },
  2331. /**
  2332. * For internal use only.
  2333. * @ignore
  2334. */
  2335. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  2336. intent) {
  2337. var intentState = this.intentStates[intent];
  2338. var i, ii;
  2339. // Add the new chunk to the current operator list.
  2340. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  2341. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  2342. intentState.operatorList.argsArray.push(
  2343. operatorListChunk.argsArray[i]);
  2344. }
  2345. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  2346. // Notify all the rendering tasks there are more operators to be consumed.
  2347. for (i = 0; i < intentState.renderTasks.length; i++) {
  2348. intentState.renderTasks[i].operatorListChanged();
  2349. }
  2350. if (operatorListChunk.lastChunk) {
  2351. intentState.receivingOperatorList = false;
  2352. this._tryCleanup();
  2353. }
  2354. }
  2355. };
  2356. return PDFPageProxy;
  2357. })();
  2358. /**
  2359. * For internal use only.
  2360. * @ignore
  2361. */
  2362. var WorkerTransport = (function WorkerTransportClosure() {
  2363. function WorkerTransport(workerInitializedCapability, pdfDataRangeTransport) {
  2364. this.pdfDataRangeTransport = pdfDataRangeTransport;
  2365. this.workerInitializedCapability = workerInitializedCapability;
  2366. this.commonObjs = new PDFObjects();
  2367. this.loadingTask = null;
  2368. this.destroyed = false;
  2369. this.destroyCapability = null;
  2370. this.pageCache = [];
  2371. this.pagePromises = [];
  2372. this.downloadInfoCapability = createPromiseCapability();
  2373. // If worker support isn't disabled explicit and the browser has worker
  2374. // support, create a new web worker and test if it/the browser fullfills
  2375. // all requirements to run parts of pdf.js in a web worker.
  2376. // Right now, the requirement is, that an Uint8Array is still an Uint8Array
  2377. // as it arrives on the worker. Chrome added this with version 15.
  2378. // Either workers are disabled, not supported or have thrown an exception.
  2379. // Thus, we fallback to a faked worker.
  2380. this.setupFakeWorker();
  2381. }
  2382. WorkerTransport.prototype = {
  2383. destroy: function WorkerTransport_destroy() {
  2384. if (this.destroyCapability) {
  2385. return this.destroyCapability.promise;
  2386. }
  2387. this.destroyed = true;
  2388. this.destroyCapability = createPromiseCapability();
  2389. var waitOn = [];
  2390. // We need to wait for all renderings to be completed, e.g.
  2391. // timeout/rAF can take a long time.
  2392. this.pageCache.forEach(function (page) {
  2393. if (page) {
  2394. waitOn.push(page._destroy());
  2395. }
  2396. });
  2397. this.pageCache = [];
  2398. this.pagePromises = [];
  2399. var self = this;
  2400. // We also need to wait for the worker to finish its long running tasks.
  2401. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  2402. waitOn.push(terminated);
  2403. Promise.all(waitOn).then(function () {
  2404. FontLoader.clear();
  2405. if (self.worker) {
  2406. self.worker.terminate();
  2407. }
  2408. if (self.pdfDataRangeTransport) {
  2409. self.pdfDataRangeTransport.abort();
  2410. self.pdfDataRangeTransport = null;
  2411. }
  2412. self.messageHandler = null;
  2413. self.destroyCapability.resolve();
  2414. }, this.destroyCapability.reject);
  2415. return this.destroyCapability.promise;
  2416. },
  2417. setupFakeWorker: function WorkerTransport_setupFakeWorker() {
  2418. globalScope.PDFJS.disableWorker = true;
  2419. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  2420. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  2421. // In the developer build load worker_loader which in turn loads all the
  2422. // other files and resolves the promise. In production only the
  2423. // pdf.worker.js file is needed.
  2424. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  2425. }
  2426. PDFJS.fakeWorkerFilesLoadedCapability.promise.then(function () {
  2427. warn('Setting up fake worker.');
  2428. // If we don't use a worker, just post/sendMessage to the main thread.
  2429. var fakeWorker = {
  2430. postMessage: function WorkerTransport_postMessage(obj) {
  2431. fakeWorker.onmessage({data: obj});
  2432. },
  2433. terminate: function WorkerTransport_terminate() {}
  2434. };
  2435. var messageHandler = new MessageHandler('main', fakeWorker);
  2436. this.setupMessageHandler(messageHandler);
  2437. // If the main thread is our worker, setup the handling for the messages
  2438. // the main thread sends to it self.
  2439. PDFJS.WorkerMessageHandler.setup(messageHandler);
  2440. this.workerInitializedCapability.resolve();
  2441. }.bind(this));
  2442. },
  2443. setupMessageHandler:
  2444. function WorkerTransport_setupMessageHandler(messageHandler) {
  2445. this.messageHandler = messageHandler;
  2446. function updatePassword(password) {
  2447. messageHandler.send('UpdatePassword', password);
  2448. }
  2449. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  2450. if (pdfDataRangeTransport) {
  2451. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  2452. messageHandler.send('OnDataRange', {
  2453. begin: begin,
  2454. chunk: chunk
  2455. });
  2456. });
  2457. pdfDataRangeTransport.addProgressListener(function(loaded) {
  2458. messageHandler.send('OnDataProgress', {
  2459. loaded: loaded
  2460. });
  2461. });
  2462. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  2463. messageHandler.send('OnDataRange', {
  2464. chunk: chunk
  2465. });
  2466. });
  2467. messageHandler.on('RequestDataRange',
  2468. function transportDataRange(data) {
  2469. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  2470. }, this);
  2471. }
  2472. messageHandler.on('GetDoc', function transportDoc(data) {
  2473. var pdfInfo = data.pdfInfo;
  2474. this.numPages = data.pdfInfo.numPages;
  2475. var loadingTask = this.loadingTask;
  2476. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  2477. this.pdfDocument = pdfDocument;
  2478. loadingTask._capability.resolve(pdfDocument);
  2479. }, this);
  2480. messageHandler.on('NeedPassword',
  2481. function transportNeedPassword(exception) {
  2482. var loadingTask = this.loadingTask;
  2483. if (loadingTask.onPassword) {
  2484. return loadingTask.onPassword(updatePassword,
  2485. PasswordResponses.NEED_PASSWORD);
  2486. }
  2487. loadingTask._capability.reject(
  2488. new PasswordException(exception.message, exception.code));
  2489. }, this);
  2490. messageHandler.on('IncorrectPassword',
  2491. function transportIncorrectPassword(exception) {
  2492. var loadingTask = this.loadingTask;
  2493. if (loadingTask.onPassword) {
  2494. return loadingTask.onPassword(updatePassword,
  2495. PasswordResponses.INCORRECT_PASSWORD);
  2496. }
  2497. loadingTask._capability.reject(
  2498. new PasswordException(exception.message, exception.code));
  2499. }, this);
  2500. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  2501. this.loadingTask._capability.reject(
  2502. new InvalidPDFException(exception.message));
  2503. }, this);
  2504. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  2505. this.loadingTask._capability.reject(
  2506. new MissingPDFException(exception.message));
  2507. }, this);
  2508. messageHandler.on('UnexpectedResponse',
  2509. function transportUnexpectedResponse(exception) {
  2510. this.loadingTask._capability.reject(
  2511. new UnexpectedResponseException(exception.message, exception.status));
  2512. }, this);
  2513. messageHandler.on('UnknownError',
  2514. function transportUnknownError(exception) {
  2515. this.loadingTask._capability.reject(
  2516. new UnknownErrorException(exception.message, exception.details));
  2517. }, this);
  2518. messageHandler.on('DataLoaded', function transportPage(data) {
  2519. this.downloadInfoCapability.resolve(data);
  2520. }, this);
  2521. messageHandler.on('PDFManagerReady', function transportPage(data) {
  2522. if (this.pdfDataRangeTransport) {
  2523. this.pdfDataRangeTransport.transportReady();
  2524. }
  2525. }, this);
  2526. messageHandler.on('StartRenderPage', function transportRender(data) {
  2527. if (this.destroyed) {
  2528. return; // Ignore any pending requests if the worker was terminated.
  2529. }
  2530. var page = this.pageCache[data.pageIndex];
  2531. page.stats.timeEnd('Page Request');
  2532. page._startRenderPage(data.transparency, data.intent);
  2533. }, this);
  2534. messageHandler.on('RenderPageChunk', function transportRender(data) {
  2535. if (this.destroyed) {
  2536. return; // Ignore any pending requests if the worker was terminated.
  2537. }
  2538. var page = this.pageCache[data.pageIndex];
  2539. page._renderPageChunk(data.operatorList, data.intent);
  2540. }, this);
  2541. messageHandler.on('commonobj', function transportObj(data) {
  2542. if (this.destroyed) {
  2543. return; // Ignore any pending requests if the worker was terminated.
  2544. }
  2545. var id = data[0];
  2546. var type = data[1];
  2547. if (this.commonObjs.hasData(id)) {
  2548. return;
  2549. }
  2550. switch (type) {
  2551. case 'Font':
  2552. var exportedData = data[2];
  2553. var font;
  2554. if ('error' in exportedData) {
  2555. var error = exportedData.error;
  2556. warn('Error during font loading: ' + error);
  2557. this.commonObjs.resolve(id, error);
  2558. break;
  2559. } else {
  2560. font = new FontFaceObject(exportedData);
  2561. }
  2562. FontLoader.bind(
  2563. [font],
  2564. function fontReady(fontObjs) {
  2565. this.commonObjs.resolve(id, font);
  2566. }.bind(this)
  2567. );
  2568. break;
  2569. case 'FontPath':
  2570. this.commonObjs.resolve(id, data[2]);
  2571. break;
  2572. default:
  2573. error('Got unknown common object type ' + type);
  2574. }
  2575. }, this);
  2576. messageHandler.on('obj', function transportObj(data) {
  2577. if (this.destroyed) {
  2578. return; // Ignore any pending requests if the worker was terminated.
  2579. }
  2580. var id = data[0];
  2581. var pageIndex = data[1];
  2582. var type = data[2];
  2583. var pageProxy = this.pageCache[pageIndex];
  2584. var imageData;
  2585. if (pageProxy.objs.hasData(id)) {
  2586. return;
  2587. }
  2588. switch (type) {
  2589. case 'JpegStream':
  2590. imageData = data[3];
  2591. loadJpegStream(id, imageData, pageProxy.objs);
  2592. break;
  2593. case 'Image':
  2594. imageData = data[3];
  2595. pageProxy.objs.resolve(id, imageData);
  2596. // heuristics that will allow not to store large data
  2597. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  2598. if (imageData && 'data' in imageData &&
  2599. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  2600. pageProxy.cleanupAfterRender = true;
  2601. }
  2602. break;
  2603. default:
  2604. error('Got unknown object type ' + type);
  2605. }
  2606. }, this);
  2607. messageHandler.on('DocProgress', function transportDocProgress(data) {
  2608. if (this.destroyed) {
  2609. return; // Ignore any pending requests if the worker was terminated.
  2610. }
  2611. var loadingTask = this.loadingTask;
  2612. if (loadingTask.onProgress) {
  2613. loadingTask.onProgress({
  2614. loaded: data.loaded,
  2615. total: data.total
  2616. });
  2617. }
  2618. }, this);
  2619. messageHandler.on('PageError', function transportError(data) {
  2620. if (this.destroyed) {
  2621. return; // Ignore any pending requests if the worker was terminated.
  2622. }
  2623. var page = this.pageCache[data.pageNum - 1];
  2624. var intentState = page.intentStates[data.intent];
  2625. if (intentState.displayReadyCapability) {
  2626. intentState.displayReadyCapability.reject(data.error);
  2627. } else {
  2628. error(data.error);
  2629. }
  2630. }, this);
  2631. messageHandler.on('JpegDecode', function(data) {
  2632. if (this.destroyed) {
  2633. return Promise.reject('Worker was terminated');
  2634. }
  2635. var imageUrl = data[0];
  2636. var components = data[1];
  2637. if (components !== 3 && components !== 1) {
  2638. return Promise.reject(
  2639. new Error('Only 3 components or 1 component can be returned'));
  2640. }
  2641. return new Promise(function (resolve, reject) {
  2642. var img = new Image();
  2643. img.onload = function () {
  2644. var width = img.width;
  2645. var height = img.height;
  2646. var size = width * height;
  2647. var rgbaLength = size * 4;
  2648. var buf = new Uint8Array(size * components);
  2649. var tmpCanvas = createScratchCanvas(width, height);
  2650. var tmpCtx = tmpCanvas.getContext('2d');
  2651. tmpCtx.drawImage(img, 0, 0);
  2652. var data = tmpCtx.getImageData(0, 0, width, height).data;
  2653. var i, j;
  2654. if (components === 3) {
  2655. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  2656. buf[j] = data[i];
  2657. buf[j + 1] = data[i + 1];
  2658. buf[j + 2] = data[i + 2];
  2659. }
  2660. } else if (components === 1) {
  2661. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  2662. buf[j] = data[i];
  2663. }
  2664. }
  2665. resolve({ data: buf, width: width, height: height});
  2666. };
  2667. img.onerror = function () {
  2668. reject(new Error('JpegDecode failed to load image'));
  2669. };
  2670. img.src = imageUrl;
  2671. });
  2672. }, this);
  2673. },
  2674. fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
  2675. if (this.destroyed) {
  2676. loadingTask._capability.reject(new Error('Loading aborted'));
  2677. this.destroyCapability.resolve();
  2678. return;
  2679. }
  2680. this.loadingTask = loadingTask;
  2681. source.disableAutoFetch = PDFJS.disableAutoFetch;
  2682. source.disableStream = PDFJS.disableStream;
  2683. source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
  2684. if (this.pdfDataRangeTransport) {
  2685. source.length = this.pdfDataRangeTransport.length;
  2686. source.initialData = this.pdfDataRangeTransport.initialData;
  2687. }
  2688. this.messageHandler.send('GetDocRequest', {
  2689. source: source,
  2690. disableRange: PDFJS.disableRange,
  2691. maxImageSize: PDFJS.maxImageSize,
  2692. cMapUrl: PDFJS.cMapUrl,
  2693. cMapPacked: PDFJS.cMapPacked,
  2694. disableFontFace: PDFJS.disableFontFace,
  2695. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  2696. verbosity: PDFJS.verbosity
  2697. });
  2698. },
  2699. getData: function WorkerTransport_getData() {
  2700. return this.messageHandler.sendWithPromise('GetData', null);
  2701. },
  2702. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  2703. if (pageNumber <= 0 || pageNumber > this.numPages ||
  2704. (pageNumber|0) !== pageNumber) {
  2705. return Promise.reject(new Error('Invalid page request'));
  2706. }
  2707. var pageIndex = pageNumber - 1;
  2708. if (pageIndex in this.pagePromises) {
  2709. return this.pagePromises[pageIndex];
  2710. }
  2711. var promise = this.messageHandler.sendWithPromise('GetPage', {
  2712. pageIndex: pageIndex
  2713. }).then(function (pageInfo) {
  2714. if (this.destroyed) {
  2715. throw new Error('Transport destroyed');
  2716. }
  2717. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  2718. this.pageCache[pageIndex] = page;
  2719. return page;
  2720. }.bind(this));
  2721. this.pagePromises[pageIndex] = promise;
  2722. return promise;
  2723. },
  2724. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  2725. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  2726. },
  2727. getAnnotations: function WorkerTransport_getAnnotations(pageIndex) {
  2728. return this.messageHandler.sendWithPromise('GetAnnotations',
  2729. { pageIndex: pageIndex });
  2730. },
  2731. getDestinations: function WorkerTransport_getDestinations() {
  2732. return this.messageHandler.sendWithPromise('GetDestinations', null);
  2733. },
  2734. getDestination: function WorkerTransport_getDestination(id) {
  2735. return this.messageHandler.sendWithPromise('GetDestination', { id: id } );
  2736. },
  2737. getAttachments: function WorkerTransport_getAttachments() {
  2738. return this.messageHandler.sendWithPromise('GetAttachments', null);
  2739. },
  2740. getJavaScript: function WorkerTransport_getJavaScript() {
  2741. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  2742. },
  2743. getOutline: function WorkerTransport_getOutline() {
  2744. return this.messageHandler.sendWithPromise('GetOutline', null);
  2745. },
  2746. getMetadata: function WorkerTransport_getMetadata() {
  2747. return this.messageHandler.sendWithPromise('GetMetadata', null).
  2748. then(function transportMetadata(results) {
  2749. return {
  2750. info: results[0],
  2751. metadata: (results[1] ? new PDFJS.Metadata(results[1]) : null)
  2752. };
  2753. });
  2754. },
  2755. getStats: function WorkerTransport_getStats() {
  2756. return this.messageHandler.sendWithPromise('GetStats', null);
  2757. },
  2758. startCleanup: function WorkerTransport_startCleanup() {
  2759. this.messageHandler.sendWithPromise('Cleanup', null).
  2760. then(function endCleanup() {
  2761. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  2762. var page = this.pageCache[i];
  2763. if (page) {
  2764. page.cleanup();
  2765. }
  2766. }
  2767. this.commonObjs.clear();
  2768. FontLoader.clear();
  2769. }.bind(this));
  2770. }
  2771. };
  2772. return WorkerTransport;
  2773. })();
  2774. /**
  2775. * A PDF document and page is built of many objects. E.g. there are objects
  2776. * for fonts, images, rendering code and such. These objects might get processed
  2777. * inside of a worker. The `PDFObjects` implements some basic functions to
  2778. * manage these objects.
  2779. * @ignore
  2780. */
  2781. var PDFObjects = (function PDFObjectsClosure() {
  2782. function PDFObjects() {
  2783. this.objs = {};
  2784. }
  2785. PDFObjects.prototype = {
  2786. /**
  2787. * Internal function.
  2788. * Ensures there is an object defined for `objId`.
  2789. */
  2790. ensureObj: function PDFObjects_ensureObj(objId) {
  2791. if (this.objs[objId]) {
  2792. return this.objs[objId];
  2793. }
  2794. var obj = {
  2795. capability: createPromiseCapability(),
  2796. data: null,
  2797. resolved: false
  2798. };
  2799. this.objs[objId] = obj;
  2800. return obj;
  2801. },
  2802. /**
  2803. * If called *without* callback, this returns the data of `objId` but the
  2804. * object needs to be resolved. If it isn't, this function throws.
  2805. *
  2806. * If called *with* a callback, the callback is called with the data of the
  2807. * object once the object is resolved. That means, if you call this
  2808. * function and the object is already resolved, the callback gets called
  2809. * right away.
  2810. */
  2811. get: function PDFObjects_get(objId, callback) {
  2812. // If there is a callback, then the get can be async and the object is
  2813. // not required to be resolved right now
  2814. if (callback) {
  2815. this.ensureObj(objId).capability.promise.then(callback);
  2816. return null;
  2817. }
  2818. // If there isn't a callback, the user expects to get the resolved data
  2819. // directly.
  2820. var obj = this.objs[objId];
  2821. // If there isn't an object yet or the object isn't resolved, then the
  2822. // data isn't ready yet!
  2823. if (!obj || !obj.resolved) {
  2824. error('Requesting object that isn\'t resolved yet ' + objId);
  2825. }
  2826. return obj.data;
  2827. },
  2828. /**
  2829. * Resolves the object `objId` with optional `data`.
  2830. */
  2831. resolve: function PDFObjects_resolve(objId, data) {
  2832. var obj = this.ensureObj(objId);
  2833. obj.resolved = true;
  2834. obj.data = data;
  2835. obj.capability.resolve(data);
  2836. },
  2837. isResolved: function PDFObjects_isResolved(objId) {
  2838. var objs = this.objs;
  2839. if (!objs[objId]) {
  2840. return false;
  2841. } else {
  2842. return objs[objId].resolved;
  2843. }
  2844. },
  2845. hasData: function PDFObjects_hasData(objId) {
  2846. return this.isResolved(objId);
  2847. },
  2848. /**
  2849. * Returns the data of `objId` if object exists, null otherwise.
  2850. */
  2851. getData: function PDFObjects_getData(objId) {
  2852. var objs = this.objs;
  2853. if (!objs[objId] || !objs[objId].resolved) {
  2854. return null;
  2855. } else {
  2856. return objs[objId].data;
  2857. }
  2858. },
  2859. clear: function PDFObjects_clear() {
  2860. this.objs = {};
  2861. }
  2862. };
  2863. return PDFObjects;
  2864. })();
  2865. /**
  2866. * Allows controlling of the rendering tasks.
  2867. * @class
  2868. * @alias RenderTask
  2869. */
  2870. var RenderTask = (function RenderTaskClosure() {
  2871. function RenderTask(internalRenderTask) {
  2872. this._internalRenderTask = internalRenderTask;
  2873. /**
  2874. * Callback for incremental rendering -- a function that will be called
  2875. * each time the rendering is paused. To continue rendering call the
  2876. * function that is the first argument to the callback.
  2877. * @type {function}
  2878. */
  2879. this.onContinue = null;
  2880. }
  2881. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  2882. /**
  2883. * Promise for rendering task completion.
  2884. * @return {Promise}
  2885. */
  2886. get promise() {
  2887. return this._internalRenderTask.capability.promise;
  2888. },
  2889. /**
  2890. * Cancels the rendering task. If the task is currently rendering it will
  2891. * not be cancelled until graphics pauses with a timeout. The promise that
  2892. * this object extends will resolved when cancelled.
  2893. */
  2894. cancel: function RenderTask_cancel() {
  2895. this._internalRenderTask.cancel();
  2896. },
  2897. /**
  2898. * Registers callbacks to indicate the rendering task completion.
  2899. *
  2900. * @param {function} onFulfilled The callback for the rendering completion.
  2901. * @param {function} onRejected The callback for the rendering failure.
  2902. * @return {Promise} A promise that is resolved after the onFulfilled or
  2903. * onRejected callback.
  2904. */
  2905. then: function RenderTask_then(onFulfilled, onRejected) {
  2906. return this.promise.then.apply(this.promise, arguments);
  2907. }
  2908. };
  2909. return RenderTask;
  2910. })();
  2911. /**
  2912. * For internal use only.
  2913. * @ignore
  2914. */
  2915. var InternalRenderTask = (function InternalRenderTaskClosure() {
  2916. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  2917. pageNumber) {
  2918. this.callback = callback;
  2919. this.params = params;
  2920. this.objs = objs;
  2921. this.commonObjs = commonObjs;
  2922. this.operatorListIdx = null;
  2923. this.operatorList = operatorList;
  2924. this.pageNumber = pageNumber;
  2925. this.running = false;
  2926. this.graphicsReadyCallback = null;
  2927. this.graphicsReady = false;
  2928. this.useRequestAnimationFrame = false;
  2929. this.cancelled = false;
  2930. this.capability = createPromiseCapability();
  2931. this.task = new RenderTask(this);
  2932. // caching this-bound methods
  2933. this._continueBound = this._continue.bind(this);
  2934. this._scheduleNextBound = this._scheduleNext.bind(this);
  2935. this._nextBound = this._next.bind(this);
  2936. }
  2937. InternalRenderTask.prototype = {
  2938. initalizeGraphics:
  2939. function InternalRenderTask_initalizeGraphics(transparency) {
  2940. if (this.cancelled) {
  2941. return;
  2942. }
  2943. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  2944. globalScope.StepperManager.enabled) {
  2945. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  2946. this.stepper.init(this.operatorList);
  2947. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  2948. }
  2949. var params = this.params;
  2950. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  2951. this.objs, params.imageLayer);
  2952. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  2953. this.operatorListIdx = 0;
  2954. this.graphicsReady = true;
  2955. if (this.graphicsReadyCallback) {
  2956. this.graphicsReadyCallback();
  2957. }
  2958. },
  2959. cancel: function InternalRenderTask_cancel() {
  2960. this.running = false;
  2961. this.cancelled = true;
  2962. this.callback('cancelled');
  2963. },
  2964. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  2965. if (!this.graphicsReady) {
  2966. if (!this.graphicsReadyCallback) {
  2967. this.graphicsReadyCallback = this._continueBound;
  2968. }
  2969. return;
  2970. }
  2971. if (this.stepper) {
  2972. this.stepper.updateOperatorList(this.operatorList);
  2973. }
  2974. if (this.running) {
  2975. return;
  2976. }
  2977. this._continue();
  2978. },
  2979. _continue: function InternalRenderTask__continue() {
  2980. this.running = true;
  2981. if (this.cancelled) {
  2982. return;
  2983. }
  2984. if (this.task.onContinue) {
  2985. this.task.onContinue.call(this.task, this._scheduleNextBound);
  2986. } else {
  2987. this._scheduleNext();
  2988. }
  2989. },
  2990. _scheduleNext: function InternalRenderTask__scheduleNext() {
  2991. if (this.useRequestAnimationFrame) {
  2992. window.requestAnimationFrame(this._nextBound);
  2993. } else {
  2994. Promise.resolve(undefined).then(this._nextBound);
  2995. }
  2996. },
  2997. _next: function InternalRenderTask__next() {
  2998. if (this.cancelled) {
  2999. return;
  3000. }
  3001. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  3002. this.operatorListIdx,
  3003. this._continueBound,
  3004. this.stepper);
  3005. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  3006. this.running = false;
  3007. if (this.operatorList.lastChunk) {
  3008. this.gfx.endDrawing();
  3009. this.callback();
  3010. }
  3011. }
  3012. }
  3013. };
  3014. return InternalRenderTask;
  3015. })();
  3016. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  3017. function fixMetadata(meta) {
  3018. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  3019. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  3020. function(code, d1, d2, d3) {
  3021. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  3022. });
  3023. var chars = '';
  3024. for (var i = 0; i < bytes.length; i += 2) {
  3025. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  3026. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  3027. code !== 38 && false ? String.fromCharCode(code) :
  3028. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  3029. }
  3030. return '>' + chars;
  3031. });
  3032. }
  3033. function Metadata(meta) {
  3034. if (typeof meta === 'string') {
  3035. // Ghostscript produces invalid metadata
  3036. meta = fixMetadata(meta);
  3037. var parser = new DOMParser();
  3038. meta = parser.parseFromString(meta, 'application/xml');
  3039. } else if (!(meta instanceof Document)) {
  3040. error('Metadata: Invalid metadata object');
  3041. }
  3042. this.metaDocument = meta;
  3043. this.metadata = {};
  3044. this.parse();
  3045. }
  3046. Metadata.prototype = {
  3047. parse: function Metadata_parse() {
  3048. var doc = this.metaDocument;
  3049. var rdf = doc.documentElement;
  3050. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  3051. rdf = rdf.firstChild;
  3052. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  3053. rdf = rdf.nextSibling;
  3054. }
  3055. }
  3056. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  3057. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  3058. return;
  3059. }
  3060. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  3061. for (i = 0, length = children.length; i < length; i++) {
  3062. desc = children[i];
  3063. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  3064. continue;
  3065. }
  3066. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  3067. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  3068. entry = desc.childNodes[ii];
  3069. name = entry.nodeName.toLowerCase();
  3070. this.metadata[name] = entry.textContent.trim();
  3071. }
  3072. }
  3073. }
  3074. },
  3075. get: function Metadata_get(name) {
  3076. return this.metadata[name] || null;
  3077. },
  3078. has: function Metadata_has(name) {
  3079. return typeof this.metadata[name] !== 'undefined';
  3080. }
  3081. };
  3082. return Metadata;
  3083. })();
  3084. // <canvas> contexts store most of the state we need natively.
  3085. // However, PDF needs a bit more state, which we store here.
  3086. // Minimal font size that would be used during canvas fillText operations.
  3087. var MIN_FONT_SIZE = 16;
  3088. // Maximum font size that would be used during canvas fillText operations.
  3089. var MAX_FONT_SIZE = 100;
  3090. var MAX_GROUP_SIZE = 4096;
  3091. // Heuristic value used when enforcing minimum line widths.
  3092. var MIN_WIDTH_FACTOR = 0.65;
  3093. var COMPILE_TYPE3_GLYPHS = true;
  3094. var MAX_SIZE_TO_COMPILE = 1000;
  3095. var FULL_CHUNK_HEIGHT = 16;
  3096. function createScratchCanvas(width, height) {
  3097. var canvas = document.createElement('canvas');
  3098. canvas.width = width;
  3099. canvas.height = height;
  3100. return canvas;
  3101. }
  3102. function addContextCurrentTransform(ctx) {
  3103. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  3104. if (!ctx.mozCurrentTransform) {
  3105. ctx._originalSave = ctx.save;
  3106. ctx._originalRestore = ctx.restore;
  3107. ctx._originalRotate = ctx.rotate;
  3108. ctx._originalScale = ctx.scale;
  3109. ctx._originalTranslate = ctx.translate;
  3110. ctx._originalTransform = ctx.transform;
  3111. ctx._originalSetTransform = ctx.setTransform;
  3112. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  3113. ctx._transformStack = [];
  3114. Object.defineProperty(ctx, 'mozCurrentTransform', {
  3115. get: function getCurrentTransform() {
  3116. return this._transformMatrix;
  3117. }
  3118. });
  3119. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  3120. get: function getCurrentTransformInverse() {
  3121. // Calculation done using WolframAlpha:
  3122. // http://www.wolframalpha.com/input/?
  3123. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  3124. var m = this._transformMatrix;
  3125. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  3126. var ad_bc = a * d - b * c;
  3127. var bc_ad = b * c - a * d;
  3128. return [
  3129. d / ad_bc,
  3130. b / bc_ad,
  3131. c / bc_ad,
  3132. a / ad_bc,
  3133. (d * e - c * f) / bc_ad,
  3134. (b * e - a * f) / ad_bc
  3135. ];
  3136. }
  3137. });
  3138. ctx.save = function ctxSave() {
  3139. var old = this._transformMatrix;
  3140. this._transformStack.push(old);
  3141. this._transformMatrix = old.slice(0, 6);
  3142. this._originalSave();
  3143. };
  3144. ctx.restore = function ctxRestore() {
  3145. var prev = this._transformStack.pop();
  3146. if (prev) {
  3147. this._transformMatrix = prev;
  3148. this._originalRestore();
  3149. }
  3150. };
  3151. ctx.translate = function ctxTranslate(x, y) {
  3152. var m = this._transformMatrix;
  3153. m[4] = m[0] * x + m[2] * y + m[4];
  3154. m[5] = m[1] * x + m[3] * y + m[5];
  3155. this._originalTranslate(x, y);
  3156. };
  3157. ctx.scale = function ctxScale(x, y) {
  3158. var m = this._transformMatrix;
  3159. m[0] = m[0] * x;
  3160. m[1] = m[1] * x;
  3161. m[2] = m[2] * y;
  3162. m[3] = m[3] * y;
  3163. this._originalScale(x, y);
  3164. };
  3165. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  3166. var m = this._transformMatrix;
  3167. this._transformMatrix = [
  3168. m[0] * a + m[2] * b,
  3169. m[1] * a + m[3] * b,
  3170. m[0] * c + m[2] * d,
  3171. m[1] * c + m[3] * d,
  3172. m[0] * e + m[2] * f + m[4],
  3173. m[1] * e + m[3] * f + m[5]
  3174. ];
  3175. ctx._originalTransform(a, b, c, d, e, f);
  3176. };
  3177. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  3178. this._transformMatrix = [a, b, c, d, e, f];
  3179. ctx._originalSetTransform(a, b, c, d, e, f);
  3180. };
  3181. ctx.rotate = function ctxRotate(angle) {
  3182. var cosValue = Math.cos(angle);
  3183. var sinValue = Math.sin(angle);
  3184. var m = this._transformMatrix;
  3185. this._transformMatrix = [
  3186. m[0] * cosValue + m[2] * sinValue,
  3187. m[1] * cosValue + m[3] * sinValue,
  3188. m[0] * (-sinValue) + m[2] * cosValue,
  3189. m[1] * (-sinValue) + m[3] * cosValue,
  3190. m[4],
  3191. m[5]
  3192. ];
  3193. this._originalRotate(angle);
  3194. };
  3195. }
  3196. }
  3197. var CachedCanvases = (function CachedCanvasesClosure() {
  3198. function CachedCanvases() {
  3199. this.cache = Object.create(null);
  3200. }
  3201. CachedCanvases.prototype = {
  3202. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  3203. trackTransform) {
  3204. var canvasEntry;
  3205. if (this.cache[id] !== undefined) {
  3206. canvasEntry = this.cache[id];
  3207. canvasEntry.canvas.width = width;
  3208. canvasEntry.canvas.height = height;
  3209. // reset canvas transform for emulated mozCurrentTransform, if needed
  3210. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  3211. } else {
  3212. var canvas = createScratchCanvas(width, height);
  3213. var ctx = canvas.getContext('2d');
  3214. if (trackTransform) {
  3215. addContextCurrentTransform(ctx);
  3216. }
  3217. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  3218. }
  3219. return canvasEntry;
  3220. },
  3221. clear: function () {
  3222. for (var id in this.cache) {
  3223. var canvasEntry = this.cache[id];
  3224. // Zeroing the width and height causes Firefox to release graphics
  3225. // resources immediately, which can greatly reduce memory consumption.
  3226. canvasEntry.canvas.width = 0;
  3227. canvasEntry.canvas.height = 0;
  3228. delete this.cache[id];
  3229. }
  3230. }
  3231. };
  3232. return CachedCanvases;
  3233. })();
  3234. function compileType3Glyph(imgData) {
  3235. var POINT_TO_PROCESS_LIMIT = 1000;
  3236. var width = imgData.width, height = imgData.height;
  3237. var i, j, j0, width1 = width + 1;
  3238. var points = new Uint8Array(width1 * (height + 1));
  3239. var POINT_TYPES =
  3240. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  3241. // decodes bit-packed mask data
  3242. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  3243. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  3244. for (i = 0, ii = data0.length; i < ii; i++) {
  3245. var mask = 128, elem = data0[i];
  3246. while (mask > 0) {
  3247. data[pos++] = (elem & mask) ? 0 : 255;
  3248. mask >>= 1;
  3249. }
  3250. }
  3251. // finding iteresting points: every point is located between mask pixels,
  3252. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  3253. // will have flags assigned based on neighboring mask pixels:
  3254. // 4 | 8
  3255. // --P--
  3256. // 2 | 1
  3257. // We are interested only in points with the flags:
  3258. // - outside corners: 1, 2, 4, 8;
  3259. // - inside corners: 7, 11, 13, 14;
  3260. // - and, intersections: 5, 10.
  3261. var count = 0;
  3262. pos = 0;
  3263. if (data[pos] !== 0) {
  3264. points[0] = 1;
  3265. ++count;
  3266. }
  3267. for (j = 1; j < width; j++) {
  3268. if (data[pos] !== data[pos + 1]) {
  3269. points[j] = data[pos] ? 2 : 1;
  3270. ++count;
  3271. }
  3272. pos++;
  3273. }
  3274. if (data[pos] !== 0) {
  3275. points[j] = 2;
  3276. ++count;
  3277. }
  3278. for (i = 1; i < height; i++) {
  3279. pos = i * lineSize;
  3280. j0 = i * width1;
  3281. if (data[pos - lineSize] !== data[pos]) {
  3282. points[j0] = data[pos] ? 1 : 8;
  3283. ++count;
  3284. }
  3285. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  3286. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  3287. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  3288. for (j = 1; j < width; j++) {
  3289. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  3290. (data[pos - lineSize + 1] ? 8 : 0);
  3291. if (POINT_TYPES[sum]) {
  3292. points[j0 + j] = POINT_TYPES[sum];
  3293. ++count;
  3294. }
  3295. pos++;
  3296. }
  3297. if (data[pos - lineSize] !== data[pos]) {
  3298. points[j0 + j] = data[pos] ? 2 : 4;
  3299. ++count;
  3300. }
  3301. if (count > POINT_TO_PROCESS_LIMIT) {
  3302. return null;
  3303. }
  3304. }
  3305. pos = lineSize * (height - 1);
  3306. j0 = i * width1;
  3307. if (data[pos] !== 0) {
  3308. points[j0] = 8;
  3309. ++count;
  3310. }
  3311. for (j = 1; j < width; j++) {
  3312. if (data[pos] !== data[pos + 1]) {
  3313. points[j0 + j] = data[pos] ? 4 : 8;
  3314. ++count;
  3315. }
  3316. pos++;
  3317. }
  3318. if (data[pos] !== 0) {
  3319. points[j0 + j] = 4;
  3320. ++count;
  3321. }
  3322. if (count > POINT_TO_PROCESS_LIMIT) {
  3323. return null;
  3324. }
  3325. // building outlines
  3326. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  3327. var outlines = [];
  3328. for (i = 0; count && i <= height; i++) {
  3329. var p = i * width1;
  3330. var end = p + width;
  3331. while (p < end && !points[p]) {
  3332. p++;
  3333. }
  3334. if (p === end) {
  3335. continue;
  3336. }
  3337. var coords = [p % width1, i];
  3338. var type = points[p], p0 = p, pp;
  3339. do {
  3340. var step = steps[type];
  3341. do {
  3342. p += step;
  3343. } while (!points[p]);
  3344. pp = points[p];
  3345. if (pp !== 5 && pp !== 10) {
  3346. // set new direction
  3347. type = pp;
  3348. // delete mark
  3349. points[p] = 0;
  3350. } else { // type is 5 or 10, ie, a crossing
  3351. // set new direction
  3352. type = pp & ((0x33 * type) >> 4);
  3353. // set new type for "future hit"
  3354. points[p] &= (type >> 2 | type << 2);
  3355. }
  3356. coords.push(p % width1);
  3357. coords.push((p / width1) | 0);
  3358. --count;
  3359. } while (p0 !== p);
  3360. outlines.push(coords);
  3361. --i;
  3362. }
  3363. var drawOutline = function(c) {
  3364. c.save();
  3365. // the path shall be painted in [0..1]x[0..1] space
  3366. c.scale(1 / width, -1 / height);
  3367. c.translate(0, -height);
  3368. c.beginPath();
  3369. for (var i = 0, ii = outlines.length; i < ii; i++) {
  3370. var o = outlines[i];
  3371. c.moveTo(o[0], o[1]);
  3372. for (var j = 2, jj = o.length; j < jj; j += 2) {
  3373. c.lineTo(o[j], o[j+1]);
  3374. }
  3375. }
  3376. c.fill();
  3377. c.beginPath();
  3378. c.restore();
  3379. };
  3380. return drawOutline;
  3381. }
  3382. var CanvasExtraState = (function CanvasExtraStateClosure() {
  3383. function CanvasExtraState(old) {
  3384. // Are soft masks and alpha values shapes or opacities?
  3385. this.alphaIsShape = false;
  3386. this.fontSize = 0;
  3387. this.fontSizeScale = 1;
  3388. this.textMatrix = IDENTITY_MATRIX;
  3389. this.textMatrixScale = 1;
  3390. this.fontMatrix = FONT_IDENTITY_MATRIX;
  3391. this.leading = 0;
  3392. // Current point (in user coordinates)
  3393. this.x = 0;
  3394. this.y = 0;
  3395. // Start of text line (in text coordinates)
  3396. this.lineX = 0;
  3397. this.lineY = 0;
  3398. // Character and word spacing
  3399. this.charSpacing = 0;
  3400. this.wordSpacing = 0;
  3401. this.textHScale = 1;
  3402. this.textRenderingMode = TextRenderingMode.FILL;
  3403. this.textRise = 0;
  3404. // Default fore and background colors
  3405. this.fillColor = '#000000';
  3406. this.strokeColor = '#000000';
  3407. this.patternFill = false;
  3408. // Note: fill alpha applies to all non-stroking operations
  3409. this.fillAlpha = 1;
  3410. this.strokeAlpha = 1;
  3411. this.lineWidth = 1;
  3412. this.activeSMask = null; // nonclonable field (see the save method below)
  3413. this.old = old;
  3414. }
  3415. CanvasExtraState.prototype = {
  3416. clone: function CanvasExtraState_clone() {
  3417. return Object.create(this);
  3418. },
  3419. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  3420. this.x = x;
  3421. this.y = y;
  3422. }
  3423. };
  3424. return CanvasExtraState;
  3425. })();
  3426. var CanvasGraphics = (function CanvasGraphicsClosure() {
  3427. // Defines the time the executeOperatorList is going to be executing
  3428. // before it stops and shedules a continue of execution.
  3429. var EXECUTION_TIME = 15;
  3430. // Defines the number of steps before checking the execution time
  3431. var EXECUTION_STEPS = 10;
  3432. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  3433. this.ctx = canvasCtx;
  3434. this.current = new CanvasExtraState();
  3435. this.stateStack = [];
  3436. this.pendingClip = null;
  3437. this.pendingEOFill = false;
  3438. this.res = null;
  3439. this.xobjs = null;
  3440. this.commonObjs = commonObjs;
  3441. this.objs = objs;
  3442. this.imageLayer = imageLayer;
  3443. this.groupStack = [];
  3444. this.processingType3 = null;
  3445. // Patterns are painted relative to the initial page/form transform, see pdf
  3446. // spec 8.7.2 NOTE 1.
  3447. this.baseTransform = null;
  3448. this.baseTransformStack = [];
  3449. this.groupLevel = 0;
  3450. this.smaskStack = [];
  3451. this.smaskCounter = 0;
  3452. this.tempSMask = null;
  3453. this.cachedCanvases = new CachedCanvases();
  3454. if (canvasCtx) {
  3455. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  3456. // the transformation must already be set in canvasCtx._transformMatrix.
  3457. addContextCurrentTransform(canvasCtx);
  3458. }
  3459. this.cachedGetSinglePixelWidth = null;
  3460. }
  3461. function putBinaryImageData(ctx, imgData) {
  3462. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  3463. ctx.putImageData(imgData, 0, 0);
  3464. return;
  3465. }
  3466. // Put the image data to the canvas in chunks, rather than putting the
  3467. // whole image at once. This saves JS memory, because the ImageData object
  3468. // is smaller. It also possibly saves C++ memory within the implementation
  3469. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  3470. // the data passed to putImageData()). |n| shouldn't be too small, however,
  3471. // because too many putImageData() calls will slow things down.
  3472. //
  3473. // Note: as written, if the last chunk is partial, the putImageData() call
  3474. // will (conceptually) put pixels past the bounds of the canvas. But
  3475. // that's ok; any such pixels are ignored.
  3476. var height = imgData.height, width = imgData.width;
  3477. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3478. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3479. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3480. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3481. var srcPos = 0, destPos;
  3482. var src = imgData.data;
  3483. var dest = chunkImgData.data;
  3484. var i, j, thisChunkHeight, elemsInThisChunk;
  3485. // There are multiple forms in which the pixel data can be passed, and
  3486. // imgData.kind tells us which one this is.
  3487. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  3488. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  3489. var srcLength = src.byteLength;
  3490. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  3491. new Uint32ArrayView(dest);
  3492. var dest32DataLength = dest32.length;
  3493. var fullSrcDiff = (width + 7) >> 3;
  3494. var white = 0xFFFFFFFF;
  3495. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  3496. 0xFF000000 : 0x000000FF;
  3497. for (i = 0; i < totalChunks; i++) {
  3498. thisChunkHeight =
  3499. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3500. destPos = 0;
  3501. for (j = 0; j < thisChunkHeight; j++) {
  3502. var srcDiff = srcLength - srcPos;
  3503. var k = 0;
  3504. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  3505. var kEndUnrolled = kEnd & ~7;
  3506. var mask = 0;
  3507. var srcByte = 0;
  3508. for (; k < kEndUnrolled; k += 8) {
  3509. srcByte = src[srcPos++];
  3510. dest32[destPos++] = (srcByte & 128) ? white : black;
  3511. dest32[destPos++] = (srcByte & 64) ? white : black;
  3512. dest32[destPos++] = (srcByte & 32) ? white : black;
  3513. dest32[destPos++] = (srcByte & 16) ? white : black;
  3514. dest32[destPos++] = (srcByte & 8) ? white : black;
  3515. dest32[destPos++] = (srcByte & 4) ? white : black;
  3516. dest32[destPos++] = (srcByte & 2) ? white : black;
  3517. dest32[destPos++] = (srcByte & 1) ? white : black;
  3518. }
  3519. for (; k < kEnd; k++) {
  3520. if (mask === 0) {
  3521. srcByte = src[srcPos++];
  3522. mask = 128;
  3523. }
  3524. dest32[destPos++] = (srcByte & mask) ? white : black;
  3525. mask >>= 1;
  3526. }
  3527. }
  3528. // We ran out of input. Make all remaining pixels transparent.
  3529. while (destPos < dest32DataLength) {
  3530. dest32[destPos++] = 0;
  3531. }
  3532. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3533. }
  3534. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  3535. // RGBA, 32-bits per pixel.
  3536. j = 0;
  3537. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  3538. for (i = 0; i < fullChunks; i++) {
  3539. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3540. srcPos += elemsInThisChunk;
  3541. ctx.putImageData(chunkImgData, 0, j);
  3542. j += FULL_CHUNK_HEIGHT;
  3543. }
  3544. if (i < totalChunks) {
  3545. elemsInThisChunk = width * partialChunkHeight * 4;
  3546. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  3547. ctx.putImageData(chunkImgData, 0, j);
  3548. }
  3549. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  3550. // RGB, 24-bits per pixel.
  3551. thisChunkHeight = FULL_CHUNK_HEIGHT;
  3552. elemsInThisChunk = width * thisChunkHeight;
  3553. for (i = 0; i < totalChunks; i++) {
  3554. if (i >= fullChunks) {
  3555. thisChunkHeight = partialChunkHeight;
  3556. elemsInThisChunk = width * thisChunkHeight;
  3557. }
  3558. destPos = 0;
  3559. for (j = elemsInThisChunk; j--;) {
  3560. dest[destPos++] = src[srcPos++];
  3561. dest[destPos++] = src[srcPos++];
  3562. dest[destPos++] = src[srcPos++];
  3563. dest[destPos++] = 255;
  3564. }
  3565. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3566. }
  3567. } else {
  3568. error('bad image kind: ' + imgData.kind);
  3569. }
  3570. }
  3571. function putBinaryImageMask(ctx, imgData) {
  3572. var height = imgData.height, width = imgData.width;
  3573. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  3574. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  3575. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  3576. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  3577. var srcPos = 0;
  3578. var src = imgData.data;
  3579. var dest = chunkImgData.data;
  3580. for (var i = 0; i < totalChunks; i++) {
  3581. var thisChunkHeight =
  3582. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  3583. // Expand the mask so it can be used by the canvas. Any required
  3584. // inversion has already been handled.
  3585. var destPos = 3; // alpha component offset
  3586. for (var j = 0; j < thisChunkHeight; j++) {
  3587. var mask = 0;
  3588. for (var k = 0; k < width; k++) {
  3589. if (!mask) {
  3590. var elem = src[srcPos++];
  3591. mask = 128;
  3592. }
  3593. dest[destPos] = (elem & mask) ? 0 : 255;
  3594. destPos += 4;
  3595. mask >>= 1;
  3596. }
  3597. }
  3598. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  3599. }
  3600. }
  3601. function copyCtxState(sourceCtx, destCtx) {
  3602. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  3603. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  3604. 'globalCompositeOperation', 'font'];
  3605. for (var i = 0, ii = properties.length; i < ii; i++) {
  3606. var property = properties[i];
  3607. if (sourceCtx[property] !== undefined) {
  3608. destCtx[property] = sourceCtx[property];
  3609. }
  3610. }
  3611. if (sourceCtx.setLineDash !== undefined) {
  3612. destCtx.setLineDash(sourceCtx.getLineDash());
  3613. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  3614. } else if (sourceCtx.mozDashOffset !== undefined) {
  3615. destCtx.mozDash = sourceCtx.mozDash;
  3616. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  3617. }
  3618. }
  3619. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  3620. var length = bytes.length;
  3621. for (var i = 3; i < length; i += 4) {
  3622. var alpha = bytes[i];
  3623. if (alpha === 0) {
  3624. bytes[i - 3] = r0;
  3625. bytes[i - 2] = g0;
  3626. bytes[i - 1] = b0;
  3627. } else if (alpha < 255) {
  3628. var alpha_ = 255 - alpha;
  3629. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  3630. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  3631. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  3632. }
  3633. }
  3634. }
  3635. function composeSMaskAlpha(maskData, layerData) {
  3636. var length = maskData.length;
  3637. var scale = 1 / 255;
  3638. for (var i = 3; i < length; i += 4) {
  3639. var alpha = maskData[i];
  3640. layerData[i] = (layerData[i] * alpha * scale) | 0;
  3641. }
  3642. }
  3643. function composeSMaskLuminosity(maskData, layerData) {
  3644. var length = maskData.length;
  3645. for (var i = 3; i < length; i += 4) {
  3646. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  3647. (maskData[i - 2] * 152) + // * 0.59 ....
  3648. (maskData[i - 1] * 28); // * 0.11 ....
  3649. layerData[i] = (layerData[i] * y) >> 16;
  3650. }
  3651. }
  3652. function genericComposeSMask(maskCtx, layerCtx, width, height,
  3653. subtype, backdrop) {
  3654. var hasBackdrop = !!backdrop;
  3655. var r0 = hasBackdrop ? backdrop[0] : 0;
  3656. var g0 = hasBackdrop ? backdrop[1] : 0;
  3657. var b0 = hasBackdrop ? backdrop[2] : 0;
  3658. var composeFn;
  3659. if (subtype === 'Luminosity') {
  3660. composeFn = composeSMaskLuminosity;
  3661. } else {
  3662. composeFn = composeSMaskAlpha;
  3663. }
  3664. // processing image in chunks to save memory
  3665. var PIXELS_TO_PROCESS = 1048576;
  3666. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  3667. for (var row = 0; row < height; row += chunkSize) {
  3668. var chunkHeight = Math.min(chunkSize, height - row);
  3669. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  3670. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  3671. if (hasBackdrop) {
  3672. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  3673. }
  3674. composeFn(maskData.data, layerData.data);
  3675. maskCtx.putImageData(layerData, 0, row);
  3676. }
  3677. }
  3678. function composeSMask(ctx, smask, layerCtx) {
  3679. var mask = smask.canvas;
  3680. var maskCtx = smask.context;
  3681. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  3682. smask.offsetX, smask.offsetY);
  3683. var backdrop = smask.backdrop || null;
  3684. if (WebGLUtils.isEnabled) {
  3685. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  3686. {subtype: smask.subtype, backdrop: backdrop});
  3687. ctx.setTransform(1, 0, 0, 1, 0, 0);
  3688. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  3689. return;
  3690. }
  3691. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  3692. smask.subtype, backdrop);
  3693. ctx.drawImage(mask, 0, 0);
  3694. }
  3695. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  3696. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  3697. var NORMAL_CLIP = {};
  3698. var EO_CLIP = {};
  3699. CanvasGraphics.prototype = {
  3700. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  3701. transparency) {
  3702. // For pdfs that use blend modes we have to clear the canvas else certain
  3703. // blend modes can look wrong since we'd be blending with a white
  3704. // backdrop. The problem with a transparent backdrop though is we then
  3705. // don't get sub pixel anti aliasing on text, creating temporary
  3706. // transparent canvas when we have blend modes.
  3707. var width = this.ctx.canvas.width;
  3708. var height = this.ctx.canvas.height;
  3709. this.ctx.save();
  3710. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  3711. this.ctx.fillRect(0, 0, width, height);
  3712. this.ctx.restore();
  3713. if (transparency) {
  3714. var transparentCanvas = this.cachedCanvases.getCanvas(
  3715. 'transparent', width, height, true);
  3716. this.compositeCtx = this.ctx;
  3717. this.transparentCanvas = transparentCanvas.canvas;
  3718. this.ctx = transparentCanvas.context;
  3719. this.ctx.save();
  3720. // The transform can be applied before rendering, transferring it to
  3721. // the new canvas.
  3722. this.ctx.transform.apply(this.ctx,
  3723. this.compositeCtx.mozCurrentTransform);
  3724. }
  3725. this.ctx.save();
  3726. if (transform) {
  3727. this.ctx.transform.apply(this.ctx, transform);
  3728. }
  3729. this.ctx.transform.apply(this.ctx, viewport.transform);
  3730. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  3731. if (this.imageLayer) {
  3732. this.imageLayer.beginLayout();
  3733. }
  3734. },
  3735. executeOperatorList: function CanvasGraphics_executeOperatorList(
  3736. operatorList,
  3737. executionStartIdx, continueCallback,
  3738. stepper) {
  3739. var argsArray = operatorList.argsArray;
  3740. var fnArray = operatorList.fnArray;
  3741. var i = executionStartIdx || 0;
  3742. var argsArrayLen = argsArray.length;
  3743. // Sometimes the OperatorList to execute is empty.
  3744. if (argsArrayLen === i) {
  3745. return i;
  3746. }
  3747. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  3748. typeof continueCallback === 'function');
  3749. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  3750. var steps = 0;
  3751. var commonObjs = this.commonObjs;
  3752. var objs = this.objs;
  3753. var fnId;
  3754. while (true) {
  3755. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  3756. stepper.breakIt(i, continueCallback);
  3757. return i;
  3758. }
  3759. fnId = fnArray[i];
  3760. if (fnId !== OPS.dependency) {
  3761. this[fnId].apply(this, argsArray[i]);
  3762. } else {
  3763. var deps = argsArray[i];
  3764. for (var n = 0, nn = deps.length; n < nn; n++) {
  3765. var depObjId = deps[n];
  3766. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  3767. var objsPool = common ? commonObjs : objs;
  3768. // If the promise isn't resolved yet, add the continueCallback
  3769. // to the promise and bail out.
  3770. if (!objsPool.isResolved(depObjId)) {
  3771. objsPool.get(depObjId, continueCallback);
  3772. return i;
  3773. }
  3774. }
  3775. }
  3776. i++;
  3777. // If the entire operatorList was executed, stop as were done.
  3778. if (i === argsArrayLen) {
  3779. return i;
  3780. }
  3781. // If the execution took longer then a certain amount of time and
  3782. // `continueCallback` is specified, interrupt the execution.
  3783. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  3784. if (Date.now() > endTime) {
  3785. continueCallback();
  3786. return i;
  3787. }
  3788. steps = 0;
  3789. }
  3790. // If the operatorList isn't executed completely yet OR the execution
  3791. // time was short enough, do another execution round.
  3792. }
  3793. },
  3794. endDrawing: function CanvasGraphics_endDrawing() {
  3795. this.ctx.restore();
  3796. if (this.transparentCanvas) {
  3797. this.ctx = this.compositeCtx;
  3798. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  3799. this.transparentCanvas = null;
  3800. }
  3801. this.cachedCanvases.clear();
  3802. WebGLUtils.clear();
  3803. if (this.imageLayer) {
  3804. this.imageLayer.endLayout();
  3805. }
  3806. },
  3807. // Graphics state
  3808. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  3809. this.current.lineWidth = width;
  3810. this.ctx.lineWidth = width;
  3811. },
  3812. setLineCap: function CanvasGraphics_setLineCap(style) {
  3813. this.ctx.lineCap = LINE_CAP_STYLES[style];
  3814. },
  3815. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  3816. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  3817. },
  3818. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  3819. this.ctx.miterLimit = limit;
  3820. },
  3821. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  3822. var ctx = this.ctx;
  3823. if (ctx.setLineDash !== undefined) {
  3824. ctx.setLineDash(dashArray);
  3825. ctx.lineDashOffset = dashPhase;
  3826. } else {
  3827. ctx.mozDash = dashArray;
  3828. ctx.mozDashOffset = dashPhase;
  3829. }
  3830. },
  3831. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  3832. // Maybe if we one day fully support color spaces this will be important
  3833. // for now we can ignore.
  3834. // TODO set rendering intent?
  3835. },
  3836. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  3837. // There's no way to control this with canvas, but we can safely ignore.
  3838. // TODO set flatness?
  3839. },
  3840. setGState: function CanvasGraphics_setGState(states) {
  3841. for (var i = 0, ii = states.length; i < ii; i++) {
  3842. var state = states[i];
  3843. var key = state[0];
  3844. var value = state[1];
  3845. switch (key) {
  3846. case 'LW':
  3847. this.setLineWidth(value);
  3848. break;
  3849. case 'LC':
  3850. this.setLineCap(value);
  3851. break;
  3852. case 'LJ':
  3853. this.setLineJoin(value);
  3854. break;
  3855. case 'ML':
  3856. this.setMiterLimit(value);
  3857. break;
  3858. case 'D':
  3859. this.setDash(value[0], value[1]);
  3860. break;
  3861. case 'RI':
  3862. this.setRenderingIntent(value);
  3863. break;
  3864. case 'FL':
  3865. this.setFlatness(value);
  3866. break;
  3867. case 'Font':
  3868. this.setFont(value[0], value[1]);
  3869. break;
  3870. case 'CA':
  3871. this.current.strokeAlpha = state[1];
  3872. break;
  3873. case 'ca':
  3874. this.current.fillAlpha = state[1];
  3875. this.ctx.globalAlpha = state[1];
  3876. break;
  3877. case 'BM':
  3878. if (value && value.name && (value.name !== 'Normal')) {
  3879. var mode = value.name.replace(/([A-Z])/g,
  3880. function(c) {
  3881. return '-' + c.toLowerCase();
  3882. }
  3883. ).substring(1);
  3884. this.ctx.globalCompositeOperation = mode;
  3885. if (this.ctx.globalCompositeOperation !== mode) {
  3886. warn('globalCompositeOperation "' + mode +
  3887. '" is not supported');
  3888. }
  3889. } else {
  3890. this.ctx.globalCompositeOperation = 'source-over';
  3891. }
  3892. break;
  3893. case 'SMask':
  3894. if (this.current.activeSMask) {
  3895. this.endSMaskGroup();
  3896. }
  3897. this.current.activeSMask = value ? this.tempSMask : null;
  3898. if (this.current.activeSMask) {
  3899. this.beginSMaskGroup();
  3900. }
  3901. this.tempSMask = null;
  3902. break;
  3903. }
  3904. }
  3905. },
  3906. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  3907. var activeSMask = this.current.activeSMask;
  3908. var drawnWidth = activeSMask.canvas.width;
  3909. var drawnHeight = activeSMask.canvas.height;
  3910. var cacheId = 'smaskGroupAt' + this.groupLevel;
  3911. var scratchCanvas = this.cachedCanvases.getCanvas(
  3912. cacheId, drawnWidth, drawnHeight, true);
  3913. var currentCtx = this.ctx;
  3914. var currentTransform = currentCtx.mozCurrentTransform;
  3915. this.ctx.save();
  3916. var groupCtx = scratchCanvas.context;
  3917. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  3918. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  3919. groupCtx.transform.apply(groupCtx, currentTransform);
  3920. copyCtxState(currentCtx, groupCtx);
  3921. this.ctx = groupCtx;
  3922. this.setGState([
  3923. ['BM', 'Normal'],
  3924. ['ca', 1],
  3925. ['CA', 1]
  3926. ]);
  3927. this.groupStack.push(currentCtx);
  3928. this.groupLevel++;
  3929. },
  3930. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  3931. var groupCtx = this.ctx;
  3932. this.groupLevel--;
  3933. this.ctx = this.groupStack.pop();
  3934. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  3935. this.ctx.restore();
  3936. },
  3937. save: function CanvasGraphics_save() {
  3938. this.ctx.save();
  3939. var old = this.current;
  3940. this.stateStack.push(old);
  3941. this.current = old.clone();
  3942. this.current.activeSMask = null;
  3943. },
  3944. restore: function CanvasGraphics_restore() {
  3945. if (this.stateStack.length !== 0) {
  3946. if (this.current.activeSMask !== null) {
  3947. this.endSMaskGroup();
  3948. }
  3949. this.current = this.stateStack.pop();
  3950. this.ctx.restore();
  3951. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  3952. this.pendingClip = null;
  3953. this.cachedGetSinglePixelWidth = null;
  3954. }
  3955. },
  3956. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  3957. this.ctx.transform(a, b, c, d, e, f);
  3958. this.cachedGetSinglePixelWidth = null;
  3959. },
  3960. // Path
  3961. constructPath: function CanvasGraphics_constructPath(ops, args) {
  3962. var ctx = this.ctx;
  3963. var current = this.current;
  3964. var x = current.x, y = current.y;
  3965. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  3966. switch (ops[i] | 0) {
  3967. case OPS.rectangle:
  3968. x = args[j++];
  3969. y = args[j++];
  3970. var width = args[j++];
  3971. var height = args[j++];
  3972. if (width === 0) {
  3973. width = this.getSinglePixelWidth();
  3974. }
  3975. if (height === 0) {
  3976. height = this.getSinglePixelWidth();
  3977. }
  3978. var xw = x + width;
  3979. var yh = y + height;
  3980. this.ctx.moveTo(x, y);
  3981. this.ctx.lineTo(xw, y);
  3982. this.ctx.lineTo(xw, yh);
  3983. this.ctx.lineTo(x, yh);
  3984. this.ctx.lineTo(x, y);
  3985. this.ctx.closePath();
  3986. break;
  3987. case OPS.moveTo:
  3988. x = args[j++];
  3989. y = args[j++];
  3990. ctx.moveTo(x, y);
  3991. break;
  3992. case OPS.lineTo:
  3993. x = args[j++];
  3994. y = args[j++];
  3995. ctx.lineTo(x, y);
  3996. break;
  3997. case OPS.curveTo:
  3998. x = args[j + 4];
  3999. y = args[j + 5];
  4000. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  4001. x, y);
  4002. j += 6;
  4003. break;
  4004. case OPS.curveTo2:
  4005. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  4006. args[j + 2], args[j + 3]);
  4007. x = args[j + 2];
  4008. y = args[j + 3];
  4009. j += 4;
  4010. break;
  4011. case OPS.curveTo3:
  4012. x = args[j + 2];
  4013. y = args[j + 3];
  4014. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  4015. j += 4;
  4016. break;
  4017. case OPS.closePath:
  4018. ctx.closePath();
  4019. break;
  4020. }
  4021. }
  4022. current.setCurrentPoint(x, y);
  4023. },
  4024. closePath: function CanvasGraphics_closePath() {
  4025. this.ctx.closePath();
  4026. },
  4027. stroke: function CanvasGraphics_stroke(consumePath) {
  4028. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  4029. var ctx = this.ctx;
  4030. var strokeColor = this.current.strokeColor;
  4031. // Prevent drawing too thin lines by enforcing a minimum line width.
  4032. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  4033. this.current.lineWidth);
  4034. // For stroke we want to temporarily change the global alpha to the
  4035. // stroking alpha.
  4036. ctx.globalAlpha = this.current.strokeAlpha;
  4037. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  4038. strokeColor.type === 'Pattern') {
  4039. // for patterns, we transform to pattern space, calculate
  4040. // the pattern, call stroke, and restore to user space
  4041. ctx.save();
  4042. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  4043. ctx.stroke();
  4044. ctx.restore();
  4045. } else {
  4046. ctx.stroke();
  4047. }
  4048. if (consumePath) {
  4049. this.consumePath();
  4050. }
  4051. // Restore the global alpha to the fill alpha
  4052. ctx.globalAlpha = this.current.fillAlpha;
  4053. },
  4054. closeStroke: function CanvasGraphics_closeStroke() {
  4055. this.closePath();
  4056. this.stroke();
  4057. },
  4058. fill: function CanvasGraphics_fill(consumePath) {
  4059. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  4060. var ctx = this.ctx;
  4061. var fillColor = this.current.fillColor;
  4062. var isPatternFill = this.current.patternFill;
  4063. var needRestore = false;
  4064. if (isPatternFill) {
  4065. ctx.save();
  4066. ctx.fillStyle = fillColor.getPattern(ctx, this);
  4067. needRestore = true;
  4068. }
  4069. if (this.pendingEOFill) {
  4070. if (ctx.mozFillRule !== undefined) {
  4071. ctx.mozFillRule = 'evenodd';
  4072. ctx.fill();
  4073. ctx.mozFillRule = 'nonzero';
  4074. } else {
  4075. ctx.fill('evenodd');
  4076. }
  4077. this.pendingEOFill = false;
  4078. } else {
  4079. ctx.fill();
  4080. }
  4081. if (needRestore) {
  4082. ctx.restore();
  4083. }
  4084. if (consumePath) {
  4085. this.consumePath();
  4086. }
  4087. },
  4088. eoFill: function CanvasGraphics_eoFill() {
  4089. this.pendingEOFill = true;
  4090. this.fill();
  4091. },
  4092. fillStroke: function CanvasGraphics_fillStroke() {
  4093. this.fill(false);
  4094. this.stroke(false);
  4095. this.consumePath();
  4096. },
  4097. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  4098. this.pendingEOFill = true;
  4099. this.fillStroke();
  4100. },
  4101. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  4102. this.closePath();
  4103. this.fillStroke();
  4104. },
  4105. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  4106. this.pendingEOFill = true;
  4107. this.closePath();
  4108. this.fillStroke();
  4109. },
  4110. endPath: function CanvasGraphics_endPath() {
  4111. this.consumePath();
  4112. },
  4113. // Clipping
  4114. clip: function CanvasGraphics_clip() {
  4115. this.pendingClip = NORMAL_CLIP;
  4116. },
  4117. eoClip: function CanvasGraphics_eoClip() {
  4118. this.pendingClip = EO_CLIP;
  4119. },
  4120. // Text
  4121. beginText: function CanvasGraphics_beginText() {
  4122. this.current.textMatrix = IDENTITY_MATRIX;
  4123. this.current.textMatrixScale = 1;
  4124. this.current.x = this.current.lineX = 0;
  4125. this.current.y = this.current.lineY = 0;
  4126. },
  4127. endText: function CanvasGraphics_endText() {
  4128. var paths = this.pendingTextPaths;
  4129. var ctx = this.ctx;
  4130. if (paths === undefined) {
  4131. ctx.beginPath();
  4132. return;
  4133. }
  4134. ctx.save();
  4135. ctx.beginPath();
  4136. for (var i = 0; i < paths.length; i++) {
  4137. var path = paths[i];
  4138. ctx.setTransform.apply(ctx, path.transform);
  4139. ctx.translate(path.x, path.y);
  4140. path.addToPath(ctx, path.fontSize);
  4141. }
  4142. ctx.restore();
  4143. ctx.clip();
  4144. ctx.beginPath();
  4145. delete this.pendingTextPaths;
  4146. },
  4147. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  4148. this.current.charSpacing = spacing;
  4149. },
  4150. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  4151. this.current.wordSpacing = spacing;
  4152. },
  4153. setHScale: function CanvasGraphics_setHScale(scale) {
  4154. this.current.textHScale = scale / 100;
  4155. },
  4156. setLeading: function CanvasGraphics_setLeading(leading) {
  4157. this.current.leading = -leading;
  4158. },
  4159. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  4160. var fontObj = this.commonObjs.get(fontRefName);
  4161. var current = this.current;
  4162. if (!fontObj) {
  4163. error('Can\'t find font for ' + fontRefName);
  4164. }
  4165. current.fontMatrix = (fontObj.fontMatrix ?
  4166. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  4167. // A valid matrix needs all main diagonal elements to be non-zero
  4168. // This also ensures we bypass FF bugzilla bug #719844.
  4169. if (current.fontMatrix[0] === 0 ||
  4170. current.fontMatrix[3] === 0) {
  4171. warn('Invalid font matrix for font ' + fontRefName);
  4172. }
  4173. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  4174. // and in some docs this can be negative (inverted x-y axes).
  4175. if (size < 0) {
  4176. size = -size;
  4177. current.fontDirection = -1;
  4178. } else {
  4179. current.fontDirection = 1;
  4180. }
  4181. this.current.font = fontObj;
  4182. this.current.fontSize = size;
  4183. if (fontObj.isType3Font) {
  4184. return; // we don't need ctx.font for Type3 fonts
  4185. }
  4186. var name = fontObj.loadedName || 'sans-serif';
  4187. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  4188. (fontObj.bold ? 'bold' : 'normal');
  4189. var italic = fontObj.italic ? 'italic' : 'normal';
  4190. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  4191. // Some font backends cannot handle fonts below certain size.
  4192. // Keeping the font at minimal size and using the fontSizeScale to change
  4193. // the current transformation matrix before the fillText/strokeText.
  4194. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  4195. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  4196. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  4197. this.current.fontSizeScale = size / browserFontSize;
  4198. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  4199. this.ctx.font = rule;
  4200. },
  4201. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  4202. this.current.textRenderingMode = mode;
  4203. },
  4204. setTextRise: function CanvasGraphics_setTextRise(rise) {
  4205. this.current.textRise = rise;
  4206. },
  4207. moveText: function CanvasGraphics_moveText(x, y) {
  4208. this.current.x = this.current.lineX += x;
  4209. this.current.y = this.current.lineY += y;
  4210. },
  4211. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  4212. this.setLeading(-y);
  4213. this.moveText(x, y);
  4214. },
  4215. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  4216. this.current.textMatrix = [a, b, c, d, e, f];
  4217. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  4218. this.current.x = this.current.lineX = 0;
  4219. this.current.y = this.current.lineY = 0;
  4220. },
  4221. nextLine: function CanvasGraphics_nextLine() {
  4222. this.moveText(0, this.current.leading);
  4223. },
  4224. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  4225. var ctx = this.ctx;
  4226. var current = this.current;
  4227. var font = current.font;
  4228. var textRenderingMode = current.textRenderingMode;
  4229. var fontSize = current.fontSize / current.fontSizeScale;
  4230. var fillStrokeMode = textRenderingMode &
  4231. TextRenderingMode.FILL_STROKE_MASK;
  4232. var isAddToPathSet = !!(textRenderingMode &
  4233. TextRenderingMode.ADD_TO_PATH_FLAG);
  4234. var addToPath;
  4235. if (font.disableFontFace || isAddToPathSet) {
  4236. addToPath = font.getPathGenerator(this.commonObjs, character);
  4237. }
  4238. if (font.disableFontFace) {
  4239. ctx.save();
  4240. ctx.translate(x, y);
  4241. ctx.beginPath();
  4242. addToPath(ctx, fontSize);
  4243. if (fillStrokeMode === TextRenderingMode.FILL ||
  4244. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4245. ctx.fill();
  4246. }
  4247. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4248. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4249. ctx.stroke();
  4250. }
  4251. ctx.restore();
  4252. } else {
  4253. if (fillStrokeMode === TextRenderingMode.FILL ||
  4254. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4255. ctx.fillText(character, x, y);
  4256. }
  4257. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4258. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4259. ctx.strokeText(character, x, y);
  4260. }
  4261. }
  4262. if (isAddToPathSet) {
  4263. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  4264. paths.push({
  4265. transform: ctx.mozCurrentTransform,
  4266. x: x,
  4267. y: y,
  4268. fontSize: fontSize,
  4269. addToPath: addToPath
  4270. });
  4271. }
  4272. },
  4273. get isFontSubpixelAAEnabled() {
  4274. // Checks if anti-aliasing is enabled when scaled text is painted.
  4275. // On Windows GDI scaled fonts looks bad.
  4276. var ctx = document.createElement('canvas').getContext('2d');
  4277. ctx.scale(1.5, 1);
  4278. ctx.fillText('I', 0, 10);
  4279. var data = ctx.getImageData(0, 0, 10, 10).data;
  4280. var enabled = false;
  4281. for (var i = 3; i < data.length; i += 4) {
  4282. if (data[i] > 0 && data[i] < 255) {
  4283. enabled = true;
  4284. break;
  4285. }
  4286. }
  4287. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  4288. },
  4289. showText: function CanvasGraphics_showText(glyphs) {
  4290. var current = this.current;
  4291. var font = current.font;
  4292. if (font.isType3Font) {
  4293. return this.showType3Text(glyphs);
  4294. }
  4295. var fontSize = current.fontSize;
  4296. if (fontSize === 0) {
  4297. return;
  4298. }
  4299. var ctx = this.ctx;
  4300. var fontSizeScale = current.fontSizeScale;
  4301. var charSpacing = current.charSpacing;
  4302. var wordSpacing = current.wordSpacing;
  4303. var fontDirection = current.fontDirection;
  4304. var textHScale = current.textHScale * fontDirection;
  4305. var glyphsLength = glyphs.length;
  4306. var vertical = font.vertical;
  4307. var spacingDir = vertical ? 1 : -1;
  4308. var defaultVMetrics = font.defaultVMetrics;
  4309. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  4310. var simpleFillText =
  4311. current.textRenderingMode === TextRenderingMode.FILL &&
  4312. !font.disableFontFace;
  4313. ctx.save();
  4314. ctx.transform.apply(ctx, current.textMatrix);
  4315. ctx.translate(current.x, current.y + current.textRise);
  4316. if (fontDirection > 0) {
  4317. ctx.scale(textHScale, -1);
  4318. } else {
  4319. ctx.scale(textHScale, 1);
  4320. }
  4321. var lineWidth = current.lineWidth;
  4322. var scale = current.textMatrixScale;
  4323. if (scale === 0 || lineWidth === 0) {
  4324. var fillStrokeMode = current.textRenderingMode &
  4325. TextRenderingMode.FILL_STROKE_MASK;
  4326. if (fillStrokeMode === TextRenderingMode.STROKE ||
  4327. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  4328. this.cachedGetSinglePixelWidth = null;
  4329. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  4330. }
  4331. } else {
  4332. lineWidth /= scale;
  4333. }
  4334. if (fontSizeScale !== 1.0) {
  4335. ctx.scale(fontSizeScale, fontSizeScale);
  4336. lineWidth /= fontSizeScale;
  4337. }
  4338. ctx.lineWidth = lineWidth;
  4339. var x = 0, i;
  4340. for (i = 0; i < glyphsLength; ++i) {
  4341. var glyph = glyphs[i];
  4342. if (isNum(glyph)) {
  4343. x += spacingDir * glyph * fontSize / 1000;
  4344. continue;
  4345. }
  4346. var restoreNeeded = false;
  4347. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4348. var character = glyph.fontChar;
  4349. var accent = glyph.accent;
  4350. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  4351. var width = glyph.width;
  4352. if (vertical) {
  4353. var vmetric, vx, vy;
  4354. vmetric = glyph.vmetric || defaultVMetrics;
  4355. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  4356. vx = -vx * widthAdvanceScale;
  4357. vy = vmetric[2] * widthAdvanceScale;
  4358. width = vmetric ? -vmetric[0] : width;
  4359. scaledX = vx / fontSizeScale;
  4360. scaledY = (x + vy) / fontSizeScale;
  4361. } else {
  4362. scaledX = x / fontSizeScale;
  4363. scaledY = 0;
  4364. }
  4365. if (font.remeasure && width > 0 && this.isFontSubpixelAAEnabled) {
  4366. // some standard fonts may not have the exact width, trying to
  4367. // rescale per character
  4368. var measuredWidth = ctx.measureText(character).width * 1000 /
  4369. fontSize * fontSizeScale;
  4370. var characterScaleX = width / measuredWidth;
  4371. restoreNeeded = true;
  4372. ctx.save();
  4373. ctx.scale(characterScaleX, 1);
  4374. scaledX /= characterScaleX;
  4375. }
  4376. if (simpleFillText && !accent) {
  4377. // common case
  4378. ctx.fillText(character, scaledX, scaledY);
  4379. } else {
  4380. this.paintChar(character, scaledX, scaledY);
  4381. if (accent) {
  4382. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  4383. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  4384. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  4385. }
  4386. }
  4387. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  4388. x += charWidth;
  4389. if (restoreNeeded) {
  4390. ctx.restore();
  4391. }
  4392. }
  4393. if (vertical) {
  4394. current.y -= x * textHScale;
  4395. } else {
  4396. current.x += x * textHScale;
  4397. }
  4398. ctx.restore();
  4399. },
  4400. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  4401. // Type3 fonts - each glyph is a "mini-PDF"
  4402. var ctx = this.ctx;
  4403. var current = this.current;
  4404. var font = current.font;
  4405. var fontSize = current.fontSize;
  4406. var fontDirection = current.fontDirection;
  4407. var spacingDir = font.vertical ? 1 : -1;
  4408. var charSpacing = current.charSpacing;
  4409. var wordSpacing = current.wordSpacing;
  4410. var textHScale = current.textHScale * fontDirection;
  4411. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  4412. var glyphsLength = glyphs.length;
  4413. var isTextInvisible =
  4414. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  4415. var i, glyph, width, spacingLength;
  4416. if (isTextInvisible || fontSize === 0) {
  4417. return;
  4418. }
  4419. this.cachedGetSinglePixelWidth = null;
  4420. ctx.save();
  4421. ctx.transform.apply(ctx, current.textMatrix);
  4422. ctx.translate(current.x, current.y);
  4423. ctx.scale(textHScale, fontDirection);
  4424. for (i = 0; i < glyphsLength; ++i) {
  4425. glyph = glyphs[i];
  4426. if (isNum(glyph)) {
  4427. spacingLength = spacingDir * glyph * fontSize / 1000;
  4428. this.ctx.translate(spacingLength, 0);
  4429. current.x += spacingLength * textHScale;
  4430. continue;
  4431. }
  4432. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  4433. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  4434. if (!operatorList) {
  4435. warn('Type3 character \"' + glyph.operatorListId +
  4436. '\" is not available');
  4437. continue;
  4438. }
  4439. this.processingType3 = glyph;
  4440. this.save();
  4441. ctx.scale(fontSize, fontSize);
  4442. ctx.transform.apply(ctx, fontMatrix);
  4443. this.executeOperatorList(operatorList);
  4444. this.restore();
  4445. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  4446. width = transformed[0] * fontSize + spacing;
  4447. ctx.translate(width, 0);
  4448. current.x += width * textHScale;
  4449. }
  4450. ctx.restore();
  4451. this.processingType3 = null;
  4452. },
  4453. // Type3 fonts
  4454. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  4455. // We can safely ignore this since the width should be the same
  4456. // as the width in the Widths array.
  4457. },
  4458. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  4459. yWidth,
  4460. llx,
  4461. lly,
  4462. urx,
  4463. ury) {
  4464. // TODO According to the spec we're also suppose to ignore any operators
  4465. // that set color or include images while processing this type3 font.
  4466. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  4467. this.clip();
  4468. this.endPath();
  4469. },
  4470. // Color
  4471. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  4472. var pattern;
  4473. if (IR[0] === 'TilingPattern') {
  4474. var color = IR[1];
  4475. var baseTransform = this.baseTransform ||
  4476. this.ctx.mozCurrentTransform.slice();
  4477. pattern = new TilingPattern(IR, color, this.ctx, this.objs,
  4478. this.commonObjs, baseTransform);
  4479. } else {
  4480. pattern = getShadingPatternFromIR(IR);
  4481. }
  4482. return pattern;
  4483. },
  4484. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  4485. this.current.strokeColor = this.getColorN_Pattern(arguments);
  4486. },
  4487. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  4488. this.current.fillColor = this.getColorN_Pattern(arguments);
  4489. this.current.patternFill = true;
  4490. },
  4491. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  4492. var color = Util.makeCssRgb(r, g, b);
  4493. this.ctx.strokeStyle = color;
  4494. this.current.strokeColor = color;
  4495. },
  4496. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  4497. var color = Util.makeCssRgb(r, g, b);
  4498. this.ctx.fillStyle = color;
  4499. this.current.fillColor = color;
  4500. this.current.patternFill = false;
  4501. },
  4502. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  4503. var ctx = this.ctx;
  4504. this.save();
  4505. var pattern = getShadingPatternFromIR(patternIR);
  4506. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  4507. var inv = ctx.mozCurrentTransformInverse;
  4508. if (inv) {
  4509. var canvas = ctx.canvas;
  4510. var width = canvas.width;
  4511. var height = canvas.height;
  4512. var bl = Util.applyTransform([0, 0], inv);
  4513. var br = Util.applyTransform([0, height], inv);
  4514. var ul = Util.applyTransform([width, 0], inv);
  4515. var ur = Util.applyTransform([width, height], inv);
  4516. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  4517. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  4518. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  4519. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  4520. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  4521. } else {
  4522. // HACK to draw the gradient onto an infinite rectangle.
  4523. // PDF gradients are drawn across the entire image while
  4524. // Canvas only allows gradients to be drawn in a rectangle
  4525. // The following bug should allow us to remove this.
  4526. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  4527. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  4528. }
  4529. this.restore();
  4530. },
  4531. // Images
  4532. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  4533. error('Should not call beginInlineImage');
  4534. },
  4535. beginImageData: function CanvasGraphics_beginImageData() {
  4536. error('Should not call beginImageData');
  4537. },
  4538. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  4539. bbox) {
  4540. this.save();
  4541. this.baseTransformStack.push(this.baseTransform);
  4542. if (isArray(matrix) && 6 === matrix.length) {
  4543. this.transform.apply(this, matrix);
  4544. }
  4545. this.baseTransform = this.ctx.mozCurrentTransform;
  4546. if (isArray(bbox) && 4 === bbox.length) {
  4547. var width = bbox[2] - bbox[0];
  4548. var height = bbox[3] - bbox[1];
  4549. this.ctx.rect(bbox[0], bbox[1], width, height);
  4550. this.clip();
  4551. this.endPath();
  4552. }
  4553. },
  4554. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  4555. this.restore();
  4556. this.baseTransform = this.baseTransformStack.pop();
  4557. },
  4558. beginGroup: function CanvasGraphics_beginGroup(group) {
  4559. this.save();
  4560. var currentCtx = this.ctx;
  4561. // TODO non-isolated groups - according to Rik at adobe non-isolated
  4562. // group results aren't usually that different and they even have tools
  4563. // that ignore this setting. Notes from Rik on implmenting:
  4564. // - When you encounter an transparency group, create a new canvas with
  4565. // the dimensions of the bbox
  4566. // - copy the content from the previous canvas to the new canvas
  4567. // - draw as usual
  4568. // - remove the backdrop alpha:
  4569. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  4570. // value of your transparency group and 'alphaBackdrop' the alpha of the
  4571. // backdrop
  4572. // - remove background color:
  4573. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  4574. if (!group.isolated) {
  4575. info('TODO: Support non-isolated groups.');
  4576. }
  4577. // TODO knockout - supposedly possible with the clever use of compositing
  4578. // modes.
  4579. if (group.knockout) {
  4580. warn('Knockout groups not supported.');
  4581. }
  4582. var currentTransform = currentCtx.mozCurrentTransform;
  4583. if (group.matrix) {
  4584. currentCtx.transform.apply(currentCtx, group.matrix);
  4585. }
  4586. assert(group.bbox, 'Bounding box is required.');
  4587. // Based on the current transform figure out how big the bounding box
  4588. // will actually be.
  4589. var bounds = Util.getAxialAlignedBoundingBox(
  4590. group.bbox,
  4591. currentCtx.mozCurrentTransform);
  4592. // Clip the bounding box to the current canvas.
  4593. var canvasBounds = [0,
  4594. 0,
  4595. currentCtx.canvas.width,
  4596. currentCtx.canvas.height];
  4597. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  4598. // Use ceil in case we're between sizes so we don't create canvas that is
  4599. // too small and make the canvas at least 1x1 pixels.
  4600. var offsetX = Math.floor(bounds[0]);
  4601. var offsetY = Math.floor(bounds[1]);
  4602. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  4603. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  4604. var scaleX = 1, scaleY = 1;
  4605. if (drawnWidth > MAX_GROUP_SIZE) {
  4606. scaleX = drawnWidth / MAX_GROUP_SIZE;
  4607. drawnWidth = MAX_GROUP_SIZE;
  4608. }
  4609. if (drawnHeight > MAX_GROUP_SIZE) {
  4610. scaleY = drawnHeight / MAX_GROUP_SIZE;
  4611. drawnHeight = MAX_GROUP_SIZE;
  4612. }
  4613. var cacheId = 'groupAt' + this.groupLevel;
  4614. if (group.smask) {
  4615. // Using two cache entries is case if masks are used one after another.
  4616. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  4617. }
  4618. var scratchCanvas = this.cachedCanvases.getCanvas(
  4619. cacheId, drawnWidth, drawnHeight, true);
  4620. var groupCtx = scratchCanvas.context;
  4621. // Since we created a new canvas that is just the size of the bounding box
  4622. // we have to translate the group ctx.
  4623. groupCtx.scale(1 / scaleX, 1 / scaleY);
  4624. groupCtx.translate(-offsetX, -offsetY);
  4625. groupCtx.transform.apply(groupCtx, currentTransform);
  4626. if (group.smask) {
  4627. // Saving state and cached mask to be used in setGState.
  4628. this.smaskStack.push({
  4629. canvas: scratchCanvas.canvas,
  4630. context: groupCtx,
  4631. offsetX: offsetX,
  4632. offsetY: offsetY,
  4633. scaleX: scaleX,
  4634. scaleY: scaleY,
  4635. subtype: group.smask.subtype,
  4636. backdrop: group.smask.backdrop
  4637. });
  4638. } else {
  4639. // Setup the current ctx so when the group is popped we draw it at the
  4640. // right location.
  4641. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  4642. currentCtx.translate(offsetX, offsetY);
  4643. currentCtx.scale(scaleX, scaleY);
  4644. }
  4645. // The transparency group inherits all off the current graphics state
  4646. // except the blend mode, soft mask, and alpha constants.
  4647. copyCtxState(currentCtx, groupCtx);
  4648. this.ctx = groupCtx;
  4649. this.setGState([
  4650. ['BM', 'Normal'],
  4651. ['ca', 1],
  4652. ['CA', 1]
  4653. ]);
  4654. this.groupStack.push(currentCtx);
  4655. this.groupLevel++;
  4656. },
  4657. endGroup: function CanvasGraphics_endGroup(group) {
  4658. this.groupLevel--;
  4659. var groupCtx = this.ctx;
  4660. this.ctx = this.groupStack.pop();
  4661. // Turn off image smoothing to avoid sub pixel interpolation which can
  4662. // look kind of blurry for some pdfs.
  4663. if (this.ctx.imageSmoothingEnabled !== undefined) {
  4664. this.ctx.imageSmoothingEnabled = false;
  4665. } else {
  4666. this.ctx.mozImageSmoothingEnabled = false;
  4667. }
  4668. if (group.smask) {
  4669. this.tempSMask = this.smaskStack.pop();
  4670. } else {
  4671. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  4672. }
  4673. this.restore();
  4674. },
  4675. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  4676. this.save();
  4677. this.current = new CanvasExtraState();
  4678. },
  4679. endAnnotations: function CanvasGraphics_endAnnotations() {
  4680. this.restore();
  4681. },
  4682. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  4683. matrix) {
  4684. this.save();
  4685. if (isArray(rect) && 4 === rect.length) {
  4686. var width = rect[2] - rect[0];
  4687. var height = rect[3] - rect[1];
  4688. this.ctx.rect(rect[0], rect[1], width, height);
  4689. this.clip();
  4690. this.endPath();
  4691. }
  4692. this.transform.apply(this, transform);
  4693. this.transform.apply(this, matrix);
  4694. },
  4695. endAnnotation: function CanvasGraphics_endAnnotation() {
  4696. this.restore();
  4697. },
  4698. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  4699. var domImage = this.objs.get(objId);
  4700. if (!domImage) {
  4701. warn('Dependent image isn\'t ready yet');
  4702. return;
  4703. }
  4704. this.save();
  4705. var ctx = this.ctx;
  4706. // scale the image to the unit square
  4707. ctx.scale(1 / w, -1 / h);
  4708. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  4709. 0, -h, w, h);
  4710. if (this.imageLayer) {
  4711. var currentTransform = ctx.mozCurrentTransformInverse;
  4712. var position = this.getCanvasPosition(0, 0);
  4713. this.imageLayer.appendImage({
  4714. objId: objId,
  4715. left: position[0],
  4716. top: position[1],
  4717. width: w / currentTransform[0],
  4718. height: h / currentTransform[3]
  4719. });
  4720. }
  4721. this.restore();
  4722. },
  4723. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  4724. var ctx = this.ctx;
  4725. var width = img.width, height = img.height;
  4726. var fillColor = this.current.fillColor;
  4727. var isPatternFill = this.current.patternFill;
  4728. var glyph = this.processingType3;
  4729. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  4730. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  4731. glyph.compiled =
  4732. compileType3Glyph({data: img.data, width: width, height: height});
  4733. } else {
  4734. glyph.compiled = null;
  4735. }
  4736. }
  4737. if (glyph && glyph.compiled) {
  4738. glyph.compiled(ctx);
  4739. return;
  4740. }
  4741. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  4742. width, height);
  4743. var maskCtx = maskCanvas.context;
  4744. maskCtx.save();
  4745. putBinaryImageMask(maskCtx, img);
  4746. maskCtx.globalCompositeOperation = 'source-in';
  4747. maskCtx.fillStyle = isPatternFill ?
  4748. fillColor.getPattern(maskCtx, this) : fillColor;
  4749. maskCtx.fillRect(0, 0, width, height);
  4750. maskCtx.restore();
  4751. this.paintInlineImageXObject(maskCanvas.canvas);
  4752. },
  4753. paintImageMaskXObjectRepeat:
  4754. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  4755. scaleY, positions) {
  4756. var width = imgData.width;
  4757. var height = imgData.height;
  4758. var fillColor = this.current.fillColor;
  4759. var isPatternFill = this.current.patternFill;
  4760. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  4761. width, height);
  4762. var maskCtx = maskCanvas.context;
  4763. maskCtx.save();
  4764. putBinaryImageMask(maskCtx, imgData);
  4765. maskCtx.globalCompositeOperation = 'source-in';
  4766. maskCtx.fillStyle = isPatternFill ?
  4767. fillColor.getPattern(maskCtx, this) : fillColor;
  4768. maskCtx.fillRect(0, 0, width, height);
  4769. maskCtx.restore();
  4770. var ctx = this.ctx;
  4771. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4772. ctx.save();
  4773. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  4774. ctx.scale(1, -1);
  4775. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4776. 0, -1, 1, 1);
  4777. ctx.restore();
  4778. }
  4779. },
  4780. paintImageMaskXObjectGroup:
  4781. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  4782. var ctx = this.ctx;
  4783. var fillColor = this.current.fillColor;
  4784. var isPatternFill = this.current.patternFill;
  4785. for (var i = 0, ii = images.length; i < ii; i++) {
  4786. var image = images[i];
  4787. var width = image.width, height = image.height;
  4788. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  4789. width, height);
  4790. var maskCtx = maskCanvas.context;
  4791. maskCtx.save();
  4792. putBinaryImageMask(maskCtx, image);
  4793. maskCtx.globalCompositeOperation = 'source-in';
  4794. maskCtx.fillStyle = isPatternFill ?
  4795. fillColor.getPattern(maskCtx, this) : fillColor;
  4796. maskCtx.fillRect(0, 0, width, height);
  4797. maskCtx.restore();
  4798. ctx.save();
  4799. ctx.transform.apply(ctx, image.transform);
  4800. ctx.scale(1, -1);
  4801. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  4802. 0, -1, 1, 1);
  4803. ctx.restore();
  4804. }
  4805. },
  4806. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  4807. var imgData = this.objs.get(objId);
  4808. if (!imgData) {
  4809. warn('Dependent image isn\'t ready yet');
  4810. return;
  4811. }
  4812. this.paintInlineImageXObject(imgData);
  4813. },
  4814. paintImageXObjectRepeat:
  4815. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  4816. positions) {
  4817. var imgData = this.objs.get(objId);
  4818. if (!imgData) {
  4819. warn('Dependent image isn\'t ready yet');
  4820. return;
  4821. }
  4822. var width = imgData.width;
  4823. var height = imgData.height;
  4824. var map = [];
  4825. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  4826. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  4827. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  4828. }
  4829. this.paintInlineImageXObjectGroup(imgData, map);
  4830. },
  4831. paintInlineImageXObject:
  4832. function CanvasGraphics_paintInlineImageXObject(imgData) {
  4833. var width = imgData.width;
  4834. var height = imgData.height;
  4835. var ctx = this.ctx;
  4836. this.save();
  4837. // scale the image to the unit square
  4838. ctx.scale(1 / width, -1 / height);
  4839. var currentTransform = ctx.mozCurrentTransformInverse;
  4840. var a = currentTransform[0], b = currentTransform[1];
  4841. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  4842. var c = currentTransform[2], d = currentTransform[3];
  4843. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  4844. var imgToPaint, tmpCanvas;
  4845. // instanceof HTMLElement does not work in jsdom node.js module
  4846. if (imgData instanceof HTMLElement || !imgData.data) {
  4847. imgToPaint = imgData;
  4848. } else {
  4849. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  4850. width, height);
  4851. var tmpCtx = tmpCanvas.context;
  4852. putBinaryImageData(tmpCtx, imgData);
  4853. imgToPaint = tmpCanvas.canvas;
  4854. }
  4855. var paintWidth = width, paintHeight = height;
  4856. var tmpCanvasId = 'prescale1';
  4857. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  4858. // pixels during drawImage operation, painting on the temporary canvas(es)
  4859. // that are twice smaller in size
  4860. while ((widthScale > 2 && paintWidth > 1) ||
  4861. (heightScale > 2 && paintHeight > 1)) {
  4862. var newWidth = paintWidth, newHeight = paintHeight;
  4863. if (widthScale > 2 && paintWidth > 1) {
  4864. newWidth = Math.ceil(paintWidth / 2);
  4865. widthScale /= paintWidth / newWidth;
  4866. }
  4867. if (heightScale > 2 && paintHeight > 1) {
  4868. newHeight = Math.ceil(paintHeight / 2);
  4869. heightScale /= paintHeight / newHeight;
  4870. }
  4871. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  4872. newWidth, newHeight);
  4873. tmpCtx = tmpCanvas.context;
  4874. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  4875. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4876. 0, 0, newWidth, newHeight);
  4877. imgToPaint = tmpCanvas.canvas;
  4878. paintWidth = newWidth;
  4879. paintHeight = newHeight;
  4880. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  4881. }
  4882. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  4883. 0, -height, width, height);
  4884. if (this.imageLayer) {
  4885. var position = this.getCanvasPosition(0, -height);
  4886. this.imageLayer.appendImage({
  4887. imgData: imgData,
  4888. left: position[0],
  4889. top: position[1],
  4890. width: width / currentTransform[0],
  4891. height: height / currentTransform[3]
  4892. });
  4893. }
  4894. this.restore();
  4895. },
  4896. paintInlineImageXObjectGroup:
  4897. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  4898. var ctx = this.ctx;
  4899. var w = imgData.width;
  4900. var h = imgData.height;
  4901. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  4902. var tmpCtx = tmpCanvas.context;
  4903. putBinaryImageData(tmpCtx, imgData);
  4904. for (var i = 0, ii = map.length; i < ii; i++) {
  4905. var entry = map[i];
  4906. ctx.save();
  4907. ctx.transform.apply(ctx, entry.transform);
  4908. ctx.scale(1, -1);
  4909. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  4910. 0, -1, 1, 1);
  4911. if (this.imageLayer) {
  4912. var position = this.getCanvasPosition(entry.x, entry.y);
  4913. this.imageLayer.appendImage({
  4914. imgData: imgData,
  4915. left: position[0],
  4916. top: position[1],
  4917. width: w,
  4918. height: h
  4919. });
  4920. }
  4921. ctx.restore();
  4922. }
  4923. },
  4924. paintSolidColorImageMask:
  4925. function CanvasGraphics_paintSolidColorImageMask() {
  4926. this.ctx.fillRect(0, 0, 1, 1);
  4927. },
  4928. paintXObject: function CanvasGraphics_paintXObject() {
  4929. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  4930. warn('Unsupported \'paintXObject\' command.');
  4931. },
  4932. // Marked content
  4933. markPoint: function CanvasGraphics_markPoint(tag) {
  4934. // TODO Marked content.
  4935. },
  4936. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  4937. // TODO Marked content.
  4938. },
  4939. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  4940. // TODO Marked content.
  4941. },
  4942. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  4943. tag, properties) {
  4944. // TODO Marked content.
  4945. },
  4946. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  4947. // TODO Marked content.
  4948. },
  4949. // Compatibility
  4950. beginCompat: function CanvasGraphics_beginCompat() {
  4951. // TODO ignore undefined operators (should we do that anyway?)
  4952. },
  4953. endCompat: function CanvasGraphics_endCompat() {
  4954. // TODO stop ignoring undefined operators
  4955. },
  4956. // Helper functions
  4957. consumePath: function CanvasGraphics_consumePath() {
  4958. var ctx = this.ctx;
  4959. if (this.pendingClip) {
  4960. if (this.pendingClip === EO_CLIP) {
  4961. if (ctx.mozFillRule !== undefined) {
  4962. ctx.mozFillRule = 'evenodd';
  4963. ctx.clip();
  4964. ctx.mozFillRule = 'nonzero';
  4965. } else {
  4966. ctx.clip('evenodd');
  4967. }
  4968. } else {
  4969. ctx.clip();
  4970. }
  4971. this.pendingClip = null;
  4972. }
  4973. ctx.beginPath();
  4974. },
  4975. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  4976. if (this.cachedGetSinglePixelWidth === null) {
  4977. var inverse = this.ctx.mozCurrentTransformInverse;
  4978. // max of the current horizontal and vertical scale
  4979. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  4980. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  4981. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  4982. }
  4983. return this.cachedGetSinglePixelWidth;
  4984. },
  4985. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  4986. var transform = this.ctx.mozCurrentTransform;
  4987. return [
  4988. transform[0] * x + transform[2] * y + transform[4],
  4989. transform[1] * x + transform[3] * y + transform[5]
  4990. ];
  4991. }
  4992. };
  4993. for (var op in OPS) {
  4994. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  4995. }
  4996. return CanvasGraphics;
  4997. })();
  4998. var WebGLUtils = (function WebGLUtilsClosure() {
  4999. function loadShader(gl, code, shaderType) {
  5000. var shader = gl.createShader(shaderType);
  5001. gl.shaderSource(shader, code);
  5002. gl.compileShader(shader);
  5003. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  5004. if (!compiled) {
  5005. var errorMsg = gl.getShaderInfoLog(shader);
  5006. throw new Error('Error during shader compilation: ' + errorMsg);
  5007. }
  5008. return shader;
  5009. }
  5010. function createVertexShader(gl, code) {
  5011. return loadShader(gl, code, gl.VERTEX_SHADER);
  5012. }
  5013. function createFragmentShader(gl, code) {
  5014. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  5015. }
  5016. function createProgram(gl, shaders) {
  5017. var program = gl.createProgram();
  5018. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  5019. gl.attachShader(program, shaders[i]);
  5020. }
  5021. gl.linkProgram(program);
  5022. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  5023. if (!linked) {
  5024. var errorMsg = gl.getProgramInfoLog(program);
  5025. throw new Error('Error during program linking: ' + errorMsg);
  5026. }
  5027. return program;
  5028. }
  5029. function createTexture(gl, image, textureId) {
  5030. gl.activeTexture(textureId);
  5031. var texture = gl.createTexture();
  5032. gl.bindTexture(gl.TEXTURE_2D, texture);
  5033. // Set the parameters so we can render any size image.
  5034. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  5035. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  5036. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  5037. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  5038. // Upload the image into the texture.
  5039. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  5040. return texture;
  5041. }
  5042. var currentGL, currentCanvas;
  5043. function generateGL() {
  5044. if (currentGL) {
  5045. return;
  5046. }
  5047. currentCanvas = document.createElement('canvas');
  5048. currentGL = currentCanvas.getContext('webgl',
  5049. { premultipliedalpha: false });
  5050. }
  5051. var smaskVertexShaderCode = '\
  5052. attribute vec2 a_position; \
  5053. attribute vec2 a_texCoord; \
  5054. \
  5055. uniform vec2 u_resolution; \
  5056. \
  5057. varying vec2 v_texCoord; \
  5058. \
  5059. void main() { \
  5060. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  5061. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5062. \
  5063. v_texCoord = a_texCoord; \
  5064. } ';
  5065. var smaskFragmentShaderCode = '\
  5066. precision mediump float; \
  5067. \
  5068. uniform vec4 u_backdrop; \
  5069. uniform int u_subtype; \
  5070. uniform sampler2D u_image; \
  5071. uniform sampler2D u_mask; \
  5072. \
  5073. varying vec2 v_texCoord; \
  5074. \
  5075. void main() { \
  5076. vec4 imageColor = texture2D(u_image, v_texCoord); \
  5077. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  5078. if (u_backdrop.a > 0.0) { \
  5079. maskColor.rgb = maskColor.rgb * maskColor.a + \
  5080. u_backdrop.rgb * (1.0 - maskColor.a); \
  5081. } \
  5082. float lum; \
  5083. if (u_subtype == 0) { \
  5084. lum = maskColor.a; \
  5085. } else { \
  5086. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  5087. maskColor.b * 0.11; \
  5088. } \
  5089. imageColor.a *= lum; \
  5090. imageColor.rgb *= imageColor.a; \
  5091. gl_FragColor = imageColor; \
  5092. } ';
  5093. var smaskCache = null;
  5094. function initSmaskGL() {
  5095. var canvas, gl;
  5096. generateGL();
  5097. canvas = currentCanvas;
  5098. currentCanvas = null;
  5099. gl = currentGL;
  5100. currentGL = null;
  5101. // setup a GLSL program
  5102. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  5103. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  5104. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5105. gl.useProgram(program);
  5106. var cache = {};
  5107. cache.gl = gl;
  5108. cache.canvas = canvas;
  5109. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5110. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5111. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  5112. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  5113. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  5114. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  5115. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  5116. // provide texture coordinates for the rectangle.
  5117. var texCoordBuffer = gl.createBuffer();
  5118. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  5119. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  5120. 0.0, 0.0,
  5121. 1.0, 0.0,
  5122. 0.0, 1.0,
  5123. 0.0, 1.0,
  5124. 1.0, 0.0,
  5125. 1.0, 1.0]), gl.STATIC_DRAW);
  5126. gl.enableVertexAttribArray(texCoordLocation);
  5127. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  5128. gl.uniform1i(texLayerLocation, 0);
  5129. gl.uniform1i(texMaskLocation, 1);
  5130. smaskCache = cache;
  5131. }
  5132. function composeSMask(layer, mask, properties) {
  5133. var width = layer.width, height = layer.height;
  5134. if (!smaskCache) {
  5135. initSmaskGL();
  5136. }
  5137. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  5138. canvas.width = width;
  5139. canvas.height = height;
  5140. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5141. gl.uniform2f(cache.resolutionLocation, width, height);
  5142. if (properties.backdrop) {
  5143. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  5144. properties.backdrop[1], properties.backdrop[2], 1);
  5145. } else {
  5146. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  5147. }
  5148. gl.uniform1i(cache.subtypeLocation,
  5149. properties.subtype === 'Luminosity' ? 1 : 0);
  5150. // Create a textures
  5151. var texture = createTexture(gl, layer, gl.TEXTURE0);
  5152. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  5153. // Create a buffer and put a single clipspace rectangle in
  5154. // it (2 triangles)
  5155. var buffer = gl.createBuffer();
  5156. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  5157. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  5158. 0, 0,
  5159. width, 0,
  5160. 0, height,
  5161. 0, height,
  5162. width, 0,
  5163. width, height]), gl.STATIC_DRAW);
  5164. gl.enableVertexAttribArray(cache.positionLocation);
  5165. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5166. // draw
  5167. gl.clearColor(0, 0, 0, 0);
  5168. gl.enable(gl.BLEND);
  5169. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  5170. gl.clear(gl.COLOR_BUFFER_BIT);
  5171. gl.drawArrays(gl.TRIANGLES, 0, 6);
  5172. gl.flush();
  5173. gl.deleteTexture(texture);
  5174. gl.deleteTexture(maskTexture);
  5175. gl.deleteBuffer(buffer);
  5176. return canvas;
  5177. }
  5178. var figuresVertexShaderCode = '\
  5179. attribute vec2 a_position; \
  5180. attribute vec3 a_color; \
  5181. \
  5182. uniform vec2 u_resolution; \
  5183. uniform vec2 u_scale; \
  5184. uniform vec2 u_offset; \
  5185. \
  5186. varying vec4 v_color; \
  5187. \
  5188. void main() { \
  5189. vec2 position = (a_position + u_offset) * u_scale; \
  5190. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  5191. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  5192. \
  5193. v_color = vec4(a_color / 255.0, 1.0); \
  5194. } ';
  5195. var figuresFragmentShaderCode = '\
  5196. precision mediump float; \
  5197. \
  5198. varying vec4 v_color; \
  5199. \
  5200. void main() { \
  5201. gl_FragColor = v_color; \
  5202. } ';
  5203. var figuresCache = null;
  5204. function initFiguresGL() {
  5205. var canvas, gl;
  5206. generateGL();
  5207. canvas = currentCanvas;
  5208. currentCanvas = null;
  5209. gl = currentGL;
  5210. currentGL = null;
  5211. // setup a GLSL program
  5212. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  5213. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  5214. var program = createProgram(gl, [vertexShader, fragmentShader]);
  5215. gl.useProgram(program);
  5216. var cache = {};
  5217. cache.gl = gl;
  5218. cache.canvas = canvas;
  5219. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  5220. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  5221. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  5222. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  5223. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  5224. figuresCache = cache;
  5225. }
  5226. function drawFigures(width, height, backgroundColor, figures, context) {
  5227. if (!figuresCache) {
  5228. initFiguresGL();
  5229. }
  5230. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  5231. canvas.width = width;
  5232. canvas.height = height;
  5233. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  5234. gl.uniform2f(cache.resolutionLocation, width, height);
  5235. // count triangle points
  5236. var count = 0;
  5237. var i, ii, rows;
  5238. for (i = 0, ii = figures.length; i < ii; i++) {
  5239. switch (figures[i].type) {
  5240. case 'lattice':
  5241. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  5242. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  5243. break;
  5244. case 'triangles':
  5245. count += figures[i].coords.length;
  5246. break;
  5247. }
  5248. }
  5249. // transfer data
  5250. var coords = new Float32Array(count * 2);
  5251. var colors = new Uint8Array(count * 3);
  5252. var coordsMap = context.coords, colorsMap = context.colors;
  5253. var pIndex = 0, cIndex = 0;
  5254. for (i = 0, ii = figures.length; i < ii; i++) {
  5255. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  5256. switch (figure.type) {
  5257. case 'lattice':
  5258. var cols = figure.verticesPerRow;
  5259. rows = (ps.length / cols) | 0;
  5260. for (var row = 1; row < rows; row++) {
  5261. var offset = row * cols + 1;
  5262. for (var col = 1; col < cols; col++, offset++) {
  5263. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  5264. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  5265. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  5266. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  5267. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  5268. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  5269. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  5270. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  5271. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  5272. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  5273. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  5274. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  5275. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  5276. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  5277. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  5278. coords[pIndex + 6] = coords[pIndex + 2];
  5279. coords[pIndex + 7] = coords[pIndex + 3];
  5280. coords[pIndex + 8] = coords[pIndex + 4];
  5281. coords[pIndex + 9] = coords[pIndex + 5];
  5282. coords[pIndex + 10] = coordsMap[ps[offset]];
  5283. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  5284. colors[cIndex + 9] = colors[cIndex + 3];
  5285. colors[cIndex + 10] = colors[cIndex + 4];
  5286. colors[cIndex + 11] = colors[cIndex + 5];
  5287. colors[cIndex + 12] = colors[cIndex + 6];
  5288. colors[cIndex + 13] = colors[cIndex + 7];
  5289. colors[cIndex + 14] = colors[cIndex + 8];
  5290. colors[cIndex + 15] = colorsMap[cs[offset]];
  5291. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  5292. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  5293. pIndex += 12;
  5294. cIndex += 18;
  5295. }
  5296. }
  5297. break;
  5298. case 'triangles':
  5299. for (var j = 0, jj = ps.length; j < jj; j++) {
  5300. coords[pIndex] = coordsMap[ps[j]];
  5301. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  5302. colors[cIndex] = colorsMap[cs[j]];
  5303. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  5304. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  5305. pIndex += 2;
  5306. cIndex += 3;
  5307. }
  5308. break;
  5309. }
  5310. }
  5311. // draw
  5312. if (backgroundColor) {
  5313. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  5314. backgroundColor[2] / 255, 1.0);
  5315. } else {
  5316. gl.clearColor(0, 0, 0, 0);
  5317. }
  5318. gl.clear(gl.COLOR_BUFFER_BIT);
  5319. var coordsBuffer = gl.createBuffer();
  5320. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  5321. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  5322. gl.enableVertexAttribArray(cache.positionLocation);
  5323. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  5324. var colorsBuffer = gl.createBuffer();
  5325. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  5326. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  5327. gl.enableVertexAttribArray(cache.colorLocation);
  5328. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  5329. 0, 0);
  5330. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  5331. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  5332. gl.drawArrays(gl.TRIANGLES, 0, count);
  5333. gl.flush();
  5334. gl.deleteBuffer(coordsBuffer);
  5335. gl.deleteBuffer(colorsBuffer);
  5336. return canvas;
  5337. }
  5338. function cleanup() {
  5339. if (smaskCache && smaskCache.canvas) {
  5340. smaskCache.canvas.width = 0;
  5341. smaskCache.canvas.height = 0;
  5342. }
  5343. if (figuresCache && figuresCache.canvas) {
  5344. figuresCache.canvas.width = 0;
  5345. figuresCache.canvas.height = 0;
  5346. }
  5347. smaskCache = null;
  5348. figuresCache = null;
  5349. }
  5350. return {
  5351. get isEnabled() {
  5352. if (PDFJS.disableWebGL) {
  5353. return false;
  5354. }
  5355. var enabled = false;
  5356. try {
  5357. generateGL();
  5358. enabled = !!currentGL;
  5359. } catch (e) { }
  5360. return shadow(this, 'isEnabled', enabled);
  5361. },
  5362. composeSMask: composeSMask,
  5363. drawFigures: drawFigures,
  5364. clear: cleanup
  5365. };
  5366. })();
  5367. var ShadingIRs = {};
  5368. ShadingIRs.RadialAxial = {
  5369. fromIR: function RadialAxial_fromIR(raw) {
  5370. var type = raw[1];
  5371. var colorStops = raw[2];
  5372. var p0 = raw[3];
  5373. var p1 = raw[4];
  5374. var r0 = raw[5];
  5375. var r1 = raw[6];
  5376. return {
  5377. type: 'Pattern',
  5378. getPattern: function RadialAxial_getPattern(ctx) {
  5379. var grad;
  5380. if (type === 'axial') {
  5381. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  5382. } else if (type === 'radial') {
  5383. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  5384. }
  5385. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  5386. var c = colorStops[i];
  5387. grad.addColorStop(c[0], c[1]);
  5388. }
  5389. return grad;
  5390. }
  5391. };
  5392. }
  5393. };
  5394. var createMeshCanvas = (function createMeshCanvasClosure() {
  5395. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  5396. // Very basic Gouraud-shaded triangle rasterization algorithm.
  5397. var coords = context.coords, colors = context.colors;
  5398. var bytes = data.data, rowSize = data.width * 4;
  5399. var tmp;
  5400. if (coords[p1 + 1] > coords[p2 + 1]) {
  5401. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5402. }
  5403. if (coords[p2 + 1] > coords[p3 + 1]) {
  5404. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  5405. }
  5406. if (coords[p1 + 1] > coords[p2 + 1]) {
  5407. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  5408. }
  5409. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  5410. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  5411. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  5412. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  5413. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  5414. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  5415. if (y1 >= y3) {
  5416. return;
  5417. }
  5418. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  5419. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  5420. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  5421. var minY = Math.round(y1), maxY = Math.round(y3);
  5422. var xa, car, cag, cab;
  5423. var xb, cbr, cbg, cbb;
  5424. var k;
  5425. for (var y = minY; y <= maxY; y++) {
  5426. if (y < y2) {
  5427. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  5428. xa = x1 - (x1 - x2) * k;
  5429. car = c1r - (c1r - c2r) * k;
  5430. cag = c1g - (c1g - c2g) * k;
  5431. cab = c1b - (c1b - c2b) * k;
  5432. } else {
  5433. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  5434. xa = x2 - (x2 - x3) * k;
  5435. car = c2r - (c2r - c3r) * k;
  5436. cag = c2g - (c2g - c3g) * k;
  5437. cab = c2b - (c2b - c3b) * k;
  5438. }
  5439. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  5440. xb = x1 - (x1 - x3) * k;
  5441. cbr = c1r - (c1r - c3r) * k;
  5442. cbg = c1g - (c1g - c3g) * k;
  5443. cbb = c1b - (c1b - c3b) * k;
  5444. var x1_ = Math.round(Math.min(xa, xb));
  5445. var x2_ = Math.round(Math.max(xa, xb));
  5446. var j = rowSize * y + x1_ * 4;
  5447. for (var x = x1_; x <= x2_; x++) {
  5448. k = (xa - x) / (xa - xb);
  5449. k = k < 0 ? 0 : k > 1 ? 1 : k;
  5450. bytes[j++] = (car - (car - cbr) * k) | 0;
  5451. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  5452. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  5453. bytes[j++] = 255;
  5454. }
  5455. }
  5456. }
  5457. function drawFigure(data, figure, context) {
  5458. var ps = figure.coords;
  5459. var cs = figure.colors;
  5460. var i, ii;
  5461. switch (figure.type) {
  5462. case 'lattice':
  5463. var verticesPerRow = figure.verticesPerRow;
  5464. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  5465. var cols = verticesPerRow - 1;
  5466. for (i = 0; i < rows; i++) {
  5467. var q = i * verticesPerRow;
  5468. for (var j = 0; j < cols; j++, q++) {
  5469. drawTriangle(data, context,
  5470. ps[q], ps[q + 1], ps[q + verticesPerRow],
  5471. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  5472. drawTriangle(data, context,
  5473. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  5474. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  5475. }
  5476. }
  5477. break;
  5478. case 'triangles':
  5479. for (i = 0, ii = ps.length; i < ii; i += 3) {
  5480. drawTriangle(data, context,
  5481. ps[i], ps[i + 1], ps[i + 2],
  5482. cs[i], cs[i + 1], cs[i + 2]);
  5483. }
  5484. break;
  5485. default:
  5486. error('illigal figure');
  5487. break;
  5488. }
  5489. }
  5490. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  5491. backgroundColor, cachedCanvases) {
  5492. // we will increase scale on some weird factor to let antialiasing take
  5493. // care of "rough" edges
  5494. var EXPECTED_SCALE = 1.1;
  5495. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5496. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5497. var offsetX = Math.floor(bounds[0]);
  5498. var offsetY = Math.floor(bounds[1]);
  5499. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  5500. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  5501. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  5502. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5503. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  5504. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  5505. var scaleX = boundsWidth / width;
  5506. var scaleY = boundsHeight / height;
  5507. var context = {
  5508. coords: coords,
  5509. colors: colors,
  5510. offsetX: -offsetX,
  5511. offsetY: -offsetY,
  5512. scaleX: 1 / scaleX,
  5513. scaleY: 1 / scaleY
  5514. };
  5515. var canvas, tmpCanvas, i, ii;
  5516. if (WebGLUtils.isEnabled) {
  5517. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  5518. figures, context);
  5519. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  5520. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  5521. tmpCanvas.context.drawImage(canvas, 0, 0);
  5522. canvas = tmpCanvas.canvas;
  5523. } else {
  5524. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  5525. var tmpCtx = tmpCanvas.context;
  5526. var data = tmpCtx.createImageData(width, height);
  5527. if (backgroundColor) {
  5528. var bytes = data.data;
  5529. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  5530. bytes[i] = backgroundColor[0];
  5531. bytes[i + 1] = backgroundColor[1];
  5532. bytes[i + 2] = backgroundColor[2];
  5533. bytes[i + 3] = 255;
  5534. }
  5535. }
  5536. for (i = 0; i < figures.length; i++) {
  5537. drawFigure(data, figures[i], context);
  5538. }
  5539. tmpCtx.putImageData(data, 0, 0);
  5540. canvas = tmpCanvas.canvas;
  5541. }
  5542. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  5543. scaleX: scaleX, scaleY: scaleY};
  5544. }
  5545. return createMeshCanvas;
  5546. })();
  5547. ShadingIRs.Mesh = {
  5548. fromIR: function Mesh_fromIR(raw) {
  5549. //var type = raw[1];
  5550. var coords = raw[2];
  5551. var colors = raw[3];
  5552. var figures = raw[4];
  5553. var bounds = raw[5];
  5554. var matrix = raw[6];
  5555. //var bbox = raw[7];
  5556. var background = raw[8];
  5557. return {
  5558. type: 'Pattern',
  5559. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  5560. var scale;
  5561. if (shadingFill) {
  5562. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  5563. } else {
  5564. // Obtain scale from matrix and current transformation matrix.
  5565. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  5566. if (matrix) {
  5567. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  5568. scale = [scale[0] * matrixScale[0],
  5569. scale[1] * matrixScale[1]];
  5570. }
  5571. }
  5572. // Rasterizing on the main thread since sending/queue large canvases
  5573. // might cause OOM.
  5574. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  5575. colors, figures, shadingFill ? null : background,
  5576. owner.cachedCanvases);
  5577. if (!shadingFill) {
  5578. ctx.setTransform.apply(ctx, owner.baseTransform);
  5579. if (matrix) {
  5580. ctx.transform.apply(ctx, matrix);
  5581. }
  5582. }
  5583. ctx.translate(temporaryPatternCanvas.offsetX,
  5584. temporaryPatternCanvas.offsetY);
  5585. ctx.scale(temporaryPatternCanvas.scaleX,
  5586. temporaryPatternCanvas.scaleY);
  5587. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  5588. }
  5589. };
  5590. }
  5591. };
  5592. ShadingIRs.Dummy = {
  5593. fromIR: function Dummy_fromIR() {
  5594. return {
  5595. type: 'Pattern',
  5596. getPattern: function Dummy_fromIR_getPattern() {
  5597. return 'hotpink';
  5598. }
  5599. };
  5600. }
  5601. };
  5602. function getShadingPatternFromIR(raw) {
  5603. var shadingIR = ShadingIRs[raw[0]];
  5604. if (!shadingIR) {
  5605. error('Unknown IR type: ' + raw[0]);
  5606. }
  5607. return shadingIR.fromIR(raw);
  5608. }
  5609. var TilingPattern = (function TilingPatternClosure() {
  5610. var PaintType = {
  5611. COLORED: 1,
  5612. UNCOLORED: 2
  5613. };
  5614. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  5615. function TilingPattern(IR, color, ctx, objs, commonObjs, baseTransform) {
  5616. this.operatorList = IR[2];
  5617. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  5618. this.bbox = IR[4];
  5619. this.xstep = IR[5];
  5620. this.ystep = IR[6];
  5621. this.paintType = IR[7];
  5622. this.tilingType = IR[8];
  5623. this.color = color;
  5624. this.objs = objs;
  5625. this.commonObjs = commonObjs;
  5626. this.baseTransform = baseTransform;
  5627. this.type = 'Pattern';
  5628. this.ctx = ctx;
  5629. }
  5630. TilingPattern.prototype = {
  5631. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  5632. var operatorList = this.operatorList;
  5633. var bbox = this.bbox;
  5634. var xstep = this.xstep;
  5635. var ystep = this.ystep;
  5636. var paintType = this.paintType;
  5637. var tilingType = this.tilingType;
  5638. var color = this.color;
  5639. var objs = this.objs;
  5640. var commonObjs = this.commonObjs;
  5641. info('TilingType: ' + tilingType);
  5642. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  5643. var topLeft = [x0, y0];
  5644. // we want the canvas to be as large as the step size
  5645. var botRight = [x0 + xstep, y0 + ystep];
  5646. var width = botRight[0] - topLeft[0];
  5647. var height = botRight[1] - topLeft[1];
  5648. // Obtain scale from matrix and current transformation matrix.
  5649. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  5650. var curMatrixScale = Util.singularValueDecompose2dScale(
  5651. this.baseTransform);
  5652. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  5653. matrixScale[1] * curMatrixScale[1]];
  5654. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  5655. // Use width and height values that are as close as possible to the end
  5656. // result when the pattern is used. Too low value makes the pattern look
  5657. // blurry. Too large value makes it look too crispy.
  5658. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  5659. MAX_PATTERN_SIZE);
  5660. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  5661. MAX_PATTERN_SIZE);
  5662. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  5663. width, height, true);
  5664. var tmpCtx = tmpCanvas.context;
  5665. var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
  5666. graphics.groupLevel = owner.groupLevel;
  5667. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  5668. this.setScale(width, height, xstep, ystep);
  5669. this.transformToScale(graphics);
  5670. // transform coordinates to pattern space
  5671. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  5672. graphics.transform.apply(graphics, tmpTranslate);
  5673. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  5674. graphics.executeOperatorList(operatorList);
  5675. return tmpCanvas.canvas;
  5676. },
  5677. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  5678. this.scale = [width / xstep, height / ystep];
  5679. },
  5680. transformToScale: function TilingPattern_transformToScale(graphics) {
  5681. var scale = this.scale;
  5682. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  5683. graphics.transform.apply(graphics, tmpScale);
  5684. },
  5685. scaleToContext: function TilingPattern_scaleToContext() {
  5686. var scale = this.scale;
  5687. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  5688. },
  5689. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  5690. if (bbox && isArray(bbox) && bbox.length === 4) {
  5691. var bboxWidth = x1 - x0;
  5692. var bboxHeight = y1 - y0;
  5693. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  5694. graphics.clip();
  5695. graphics.endPath();
  5696. }
  5697. },
  5698. setFillAndStrokeStyleToContext:
  5699. function setFillAndStrokeStyleToContext(context, paintType, color) {
  5700. switch (paintType) {
  5701. case PaintType.COLORED:
  5702. var ctx = this.ctx;
  5703. context.fillStyle = ctx.fillStyle;
  5704. context.strokeStyle = ctx.strokeStyle;
  5705. break;
  5706. case PaintType.UNCOLORED:
  5707. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  5708. context.fillStyle = cssColor;
  5709. context.strokeStyle = cssColor;
  5710. break;
  5711. default:
  5712. error('Unsupported paint type: ' + paintType);
  5713. }
  5714. },
  5715. getPattern: function TilingPattern_getPattern(ctx, owner) {
  5716. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  5717. ctx = this.ctx;
  5718. ctx.setTransform.apply(ctx, this.baseTransform);
  5719. ctx.transform.apply(ctx, this.matrix);
  5720. this.scaleToContext();
  5721. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  5722. }
  5723. };
  5724. return TilingPattern;
  5725. })();
  5726. PDFJS.disableFontFace = false;
  5727. var FontLoader = {
  5728. insertRule: function fontLoaderInsertRule(rule) {
  5729. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5730. if (!styleElement) {
  5731. styleElement = document.createElement('style');
  5732. styleElement.id = 'PDFJS_FONT_STYLE_TAG';
  5733. document.documentElement.getElementsByTagName('head')[0].appendChild(
  5734. styleElement);
  5735. }
  5736. var styleSheet = styleElement.sheet;
  5737. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  5738. },
  5739. clear: function fontLoaderClear() {
  5740. var styleElement = document.getElementById('PDFJS_FONT_STYLE_TAG');
  5741. if (styleElement) {
  5742. styleElement.parentNode.removeChild(styleElement);
  5743. }
  5744. this.nativeFontFaces.forEach(function(nativeFontFace) {
  5745. document.fonts.delete(nativeFontFace);
  5746. });
  5747. this.nativeFontFaces.length = 0;
  5748. },
  5749. get loadTestFont() {
  5750. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  5751. // height.
  5752. return shadow(this, 'loadTestFont', atob(
  5753. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  5754. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  5755. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  5756. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  5757. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  5758. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  5759. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  5760. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  5761. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  5762. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  5763. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  5764. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  5765. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  5766. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5767. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5768. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  5769. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  5770. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  5771. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  5772. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  5773. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  5774. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  5775. ));
  5776. },
  5777. get isEvalSupported() {
  5778. var evalSupport = false;
  5779. if (PDFJS.isEvalSupported) {
  5780. try {
  5781. /* jshint evil: true */
  5782. new Function('');
  5783. evalSupport = true;
  5784. } catch (e) {}
  5785. }
  5786. return shadow(this, 'isEvalSupported', evalSupport);
  5787. },
  5788. loadTestFontId: 0,
  5789. loadingContext: {
  5790. requests: [],
  5791. nextRequestId: 0
  5792. },
  5793. isSyncFontLoadingSupported: (function detectSyncFontLoadingSupport() {
  5794. if (isWorker) {
  5795. return false;
  5796. }
  5797. // User agent string sniffing is bad, but there is no reliable way to tell
  5798. // if font is fully loaded and ready to be used with canvas.
  5799. var userAgent = window.navigator.userAgent;
  5800. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  5801. if (m && m[1] >= 14) {
  5802. return true;
  5803. }
  5804. // TODO other browsers
  5805. if (userAgent === 'node') {
  5806. return true;
  5807. }
  5808. return false;
  5809. })(),
  5810. nativeFontFaces: [],
  5811. isFontLoadingAPISupported: (!isWorker && typeof document !== 'undefined' &&
  5812. !!document.fonts),
  5813. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  5814. this.nativeFontFaces.push(nativeFontFace);
  5815. document.fonts.add(nativeFontFace);
  5816. },
  5817. bind: function fontLoaderBind(fonts, callback) {
  5818. assert(!isWorker, 'bind() shall be called from main thread');
  5819. var rules = [];
  5820. var fontsToLoad = [];
  5821. var fontLoadPromises = [];
  5822. var getNativeFontPromise = function(nativeFontFace) {
  5823. // Return a promise that is always fulfilled, even when the font fails to
  5824. // load.
  5825. return nativeFontFace.loaded.catch(function(e) {
  5826. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  5827. });
  5828. };
  5829. for (var i = 0, ii = fonts.length; i < ii; i++) {
  5830. var font = fonts[i];
  5831. // Add the font to the DOM only once or skip if the font
  5832. // is already loaded.
  5833. if (font.attached || font.loading === false) {
  5834. continue;
  5835. }
  5836. font.attached = true;
  5837. if (this.isFontLoadingAPISupported) {
  5838. var nativeFontFace = font.createNativeFontFace();
  5839. if (nativeFontFace) {
  5840. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  5841. }
  5842. } else {
  5843. var rule = font.bindDOM();
  5844. if (rule) {
  5845. rules.push(rule);
  5846. fontsToLoad.push(font);
  5847. }
  5848. }
  5849. }
  5850. var request = FontLoader.queueLoadingCallback(callback);
  5851. if (this.isFontLoadingAPISupported) {
  5852. Promise.all(fontLoadPromises).then(function() {
  5853. request.complete();
  5854. });
  5855. } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) {
  5856. FontLoader.prepareFontLoadEvent(rules, fontsToLoad, request);
  5857. } else {
  5858. request.complete();
  5859. }
  5860. },
  5861. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  5862. function LoadLoader_completeRequest() {
  5863. assert(!request.end, 'completeRequest() cannot be called twice');
  5864. request.end = Date.now();
  5865. // sending all completed requests in order how they were queued
  5866. while (context.requests.length > 0 && context.requests[0].end) {
  5867. var otherRequest = context.requests.shift();
  5868. setTimeout(otherRequest.callback, 0);
  5869. }
  5870. }
  5871. var context = FontLoader.loadingContext;
  5872. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  5873. var request = {
  5874. id: requestId,
  5875. complete: LoadLoader_completeRequest,
  5876. callback: callback,
  5877. started: Date.now()
  5878. };
  5879. context.requests.push(request);
  5880. return request;
  5881. },
  5882. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  5883. fonts,
  5884. request) {
  5885. /** Hack begin */
  5886. // There's currently no event when a font has finished downloading so the
  5887. // following code is a dirty hack to 'guess' when a font is
  5888. // ready. It's assumed fonts are loaded in order, so add a known test
  5889. // font after the desired fonts and then test for the loading of that
  5890. // test font.
  5891. function int32(data, offset) {
  5892. return (data.charCodeAt(offset) << 24) |
  5893. (data.charCodeAt(offset + 1) << 16) |
  5894. (data.charCodeAt(offset + 2) << 8) |
  5895. (data.charCodeAt(offset + 3) & 0xff);
  5896. }
  5897. function spliceString(s, offset, remove, insert) {
  5898. var chunk1 = s.substr(0, offset);
  5899. var chunk2 = s.substr(offset + remove);
  5900. return chunk1 + insert + chunk2;
  5901. }
  5902. var i, ii;
  5903. var canvas = document.createElement('canvas');
  5904. canvas.width = 1;
  5905. canvas.height = 1;
  5906. var ctx = canvas.getContext('2d');
  5907. var called = 0;
  5908. function isFontReady(name, callback) {
  5909. called++;
  5910. // With setTimeout clamping this gives the font ~100ms to load.
  5911. if(called > 30) {
  5912. warn('Load test font never loaded.');
  5913. callback();
  5914. return;
  5915. }
  5916. ctx.font = '30px ' + name;
  5917. ctx.fillText('.', 0, 20);
  5918. var imageData = ctx.getImageData(0, 0, 1, 1);
  5919. if (imageData.data[3] > 0) {
  5920. callback();
  5921. return;
  5922. }
  5923. setTimeout(isFontReady.bind(null, name, callback));
  5924. }
  5925. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  5926. // Chromium seems to cache fonts based on a hash of the actual font data,
  5927. // so the font must be modified for each load test else it will appear to
  5928. // be loaded already.
  5929. // TODO: This could maybe be made faster by avoiding the btoa of the full
  5930. // font by splitting it in chunks before hand and padding the font id.
  5931. var data = this.loadTestFont;
  5932. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  5933. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  5934. loadTestFontId);
  5935. // CFF checksum is important for IE, adjusting it
  5936. var CFF_CHECKSUM_OFFSET = 16;
  5937. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  5938. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  5939. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  5940. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  5941. }
  5942. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  5943. checksum = (checksum - XXXX_VALUE +
  5944. int32(loadTestFontId + 'XXX', i)) | 0;
  5945. }
  5946. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  5947. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  5948. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  5949. url + '}';
  5950. FontLoader.insertRule(rule);
  5951. var names = [];
  5952. for (i = 0, ii = fonts.length; i < ii; i++) {
  5953. names.push(fonts[i].loadedName);
  5954. }
  5955. names.push(loadTestFontId);
  5956. var div = document.createElement('div');
  5957. div.setAttribute('style',
  5958. 'visibility: hidden;' +
  5959. 'width: 10px; height: 10px;' +
  5960. 'position: absolute; top: 0px; left: 0px;');
  5961. for (i = 0, ii = names.length; i < ii; ++i) {
  5962. var span = document.createElement('span');
  5963. span.textContent = 'Hi';
  5964. span.style.fontFamily = names[i];
  5965. div.appendChild(span);
  5966. }
  5967. document.body.appendChild(div);
  5968. isFontReady(loadTestFontId, function() {
  5969. document.body.removeChild(div);
  5970. request.complete();
  5971. });
  5972. /** Hack end */
  5973. }
  5974. };
  5975. var FontFaceObject = (function FontFaceObjectClosure() {
  5976. function FontFaceObject(name, file, properties) {
  5977. this.compiledGlyphs = {};
  5978. if (arguments.length === 1) {
  5979. // importing translated data
  5980. var data = arguments[0];
  5981. for (var i in data) {
  5982. this[i] = data[i];
  5983. }
  5984. return;
  5985. }
  5986. }
  5987. FontFaceObject.prototype = {
  5988. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  5989. if (!this.data) {
  5990. return null;
  5991. }
  5992. if (PDFJS.disableFontFace) {
  5993. this.disableFontFace = true;
  5994. return null;
  5995. }
  5996. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  5997. FontLoader.addNativeFontFace(nativeFontFace);
  5998. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  5999. globalScope['FontInspector'].enabled) {
  6000. globalScope['FontInspector'].fontAdded(this);
  6001. }
  6002. return nativeFontFace;
  6003. },
  6004. bindDOM: function FontFaceObject_bindDOM() {
  6005. if (!this.data) {
  6006. return null;
  6007. }
  6008. if (PDFJS.disableFontFace) {
  6009. this.disableFontFace = true;
  6010. return null;
  6011. }
  6012. var data = bytesToString(new Uint8Array(this.data));
  6013. var fontName = this.loadedName;
  6014. // Add the font-face rule to the document
  6015. var url = ('url(data:' + this.mimetype + ';base64,' +
  6016. window.btoa(data) + ');');
  6017. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  6018. FontLoader.insertRule(rule);
  6019. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  6020. globalScope['FontInspector'].enabled) {
  6021. globalScope['FontInspector'].fontAdded(this, url);
  6022. }
  6023. return rule;
  6024. },
  6025. getPathGenerator: function FontLoader_getPathGenerator(objs, character) {
  6026. if (!(character in this.compiledGlyphs)) {
  6027. var cmds = objs.get(this.loadedName + '_path_' + character);
  6028. var current, i, len;
  6029. // If we can, compile cmds into JS for MAXIMUM SPEED
  6030. if (FontLoader.isEvalSupported) {
  6031. var args, js = '';
  6032. for (i = 0, len = cmds.length; i < len; i++) {
  6033. current = cmds[i];
  6034. if (current.args !== undefined) {
  6035. args = current.args.join(',');
  6036. } else {
  6037. args = '';
  6038. }
  6039. js += 'c.' + current.cmd + '(' + args + ');\n';
  6040. }
  6041. /* jshint -W054 */
  6042. this.compiledGlyphs[character] = new Function('c', 'size', js);
  6043. } else {
  6044. // But fall back on using Function.prototype.apply() if we're
  6045. // blocked from using eval() for whatever reason (like CSP policies)
  6046. this.compiledGlyphs[character] = function(c, size) {
  6047. for (i = 0, len = cmds.length; i < len; i++) {
  6048. current = cmds[i];
  6049. if (current.cmd === 'scale') {
  6050. current.args = [size, -size];
  6051. }
  6052. c[current.cmd].apply(c, current.args);
  6053. }
  6054. };
  6055. }
  6056. }
  6057. return this.compiledGlyphs[character];
  6058. }
  6059. };
  6060. return FontFaceObject;
  6061. })();
  6062. /**
  6063. * Optimised CSS custom property getter/setter.
  6064. * @class
  6065. */
  6066. var CustomStyle = (function CustomStyleClosure() {
  6067. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  6068. // animate-css-transforms-firefox-webkit.html
  6069. // in some versions of IE9 it is critical that ms appear in this list
  6070. // before Moz
  6071. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  6072. var _cache = {};
  6073. function CustomStyle() {}
  6074. CustomStyle.getProp = function get(propName, element) {
  6075. // check cache only when no element is given
  6076. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  6077. return _cache[propName];
  6078. }
  6079. element = element || document.documentElement;
  6080. var style = element.style, prefixed, uPropName;
  6081. // test standard property first
  6082. if (typeof style[propName] === 'string') {
  6083. return (_cache[propName] = propName);
  6084. }
  6085. // capitalize
  6086. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  6087. // test vendor specific properties
  6088. for (var i = 0, l = prefixes.length; i < l; i++) {
  6089. prefixed = prefixes[i] + uPropName;
  6090. if (typeof style[prefixed] === 'string') {
  6091. return (_cache[propName] = prefixed);
  6092. }
  6093. }
  6094. //if all fails then set to undefined
  6095. return (_cache[propName] = 'undefined');
  6096. };
  6097. CustomStyle.setProp = function set(propName, element, str) {
  6098. var prop = this.getProp(propName);
  6099. if (prop !== 'undefined') {
  6100. element.style[prop] = str;
  6101. }
  6102. };
  6103. return CustomStyle;
  6104. })();
  6105. PDFJS.CustomStyle = CustomStyle;
  6106. var ANNOT_MIN_SIZE = 10; // px
  6107. var AnnotationUtils = (function AnnotationUtilsClosure() {
  6108. // TODO(mack): This dupes some of the logic in CanvasGraphics.setFont()
  6109. function setTextStyles(element, item, fontObj) {
  6110. var style = element.style;
  6111. style.fontSize = item.fontSize + 'px';
  6112. style.direction = item.fontDirection < 0 ? 'rtl': 'ltr';
  6113. if (!fontObj) {
  6114. return;
  6115. }
  6116. style.fontWeight = fontObj.black ?
  6117. (fontObj.bold ? 'bolder' : 'bold') :
  6118. (fontObj.bold ? 'bold' : 'normal');
  6119. style.fontStyle = fontObj.italic ? 'italic' : 'normal';
  6120. var fontName = fontObj.loadedName;
  6121. var fontFamily = fontName ? '"' + fontName + '", ' : '';
  6122. // Use a reasonable default font if the font doesn't specify a fallback
  6123. var fallbackName = fontObj.fallbackName || 'Helvetica, sans-serif';
  6124. style.fontFamily = fontFamily + fallbackName;
  6125. }
  6126. function initContainer(item) {
  6127. var container = document.createElement('section');
  6128. var cstyle = container.style;
  6129. var width = item.rect[2] - item.rect[0];
  6130. var height = item.rect[3] - item.rect[1];
  6131. // Border
  6132. if (item.borderStyle.width > 0) {
  6133. // Border width
  6134. container.style.borderWidth = item.borderStyle.width + 'px';
  6135. if (item.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  6136. // Underline styles only have a bottom border, so we do not need
  6137. // to adjust for all borders. This yields a similar result as
  6138. // Adobe Acrobat/Reader.
  6139. width = width - 2 * item.borderStyle.width;
  6140. height = height - 2 * item.borderStyle.width;
  6141. }
  6142. // Horizontal and vertical border radius
  6143. var horizontalRadius = item.borderStyle.horizontalCornerRadius;
  6144. var verticalRadius = item.borderStyle.verticalCornerRadius;
  6145. if (horizontalRadius > 0 || verticalRadius > 0) {
  6146. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  6147. CustomStyle.setProp('borderRadius', container, radius);
  6148. }
  6149. // Border style
  6150. switch (item.borderStyle.style) {
  6151. case AnnotationBorderStyleType.SOLID:
  6152. container.style.borderStyle = 'solid';
  6153. break;
  6154. case AnnotationBorderStyleType.DASHED:
  6155. container.style.borderStyle = 'dashed';
  6156. break;
  6157. case AnnotationBorderStyleType.BEVELED:
  6158. warn('Unimplemented border style: beveled');
  6159. break;
  6160. case AnnotationBorderStyleType.INSET:
  6161. warn('Unimplemented border style: inset');
  6162. break;
  6163. case AnnotationBorderStyleType.UNDERLINE:
  6164. container.style.borderBottomStyle = 'solid';
  6165. break;
  6166. default:
  6167. break;
  6168. }
  6169. // Border color
  6170. if (item.color) {
  6171. container.style.borderColor =
  6172. Util.makeCssRgb(item.color[0] | 0,
  6173. item.color[1] | 0,
  6174. item.color[2] | 0);
  6175. } else {
  6176. // Transparent (invisible) border, so do not draw it at all.
  6177. container.style.borderWidth = 0;
  6178. }
  6179. }
  6180. cstyle.width = width + 'px';
  6181. cstyle.height = height + 'px';
  6182. return container;
  6183. }
  6184. function getHtmlElementForTextWidgetAnnotation(item, commonObjs) {
  6185. var element = document.createElement('div');
  6186. var width = item.rect[2] - item.rect[0];
  6187. var height = item.rect[3] - item.rect[1];
  6188. element.style.width = width + 'px';
  6189. element.style.height = height + 'px';
  6190. element.style.display = 'table';
  6191. var content = document.createElement('div');
  6192. content.textContent = item.fieldValue;
  6193. var textAlignment = item.textAlignment;
  6194. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  6195. content.style.verticalAlign = 'middle';
  6196. content.style.display = 'table-cell';
  6197. var fontObj = item.fontRefName ?
  6198. commonObjs.getData(item.fontRefName) : null;
  6199. setTextStyles(content, item, fontObj);
  6200. element.appendChild(content);
  6201. return element;
  6202. }
  6203. function getHtmlElementForTextAnnotation(item) {
  6204. var rect = item.rect;
  6205. // sanity check because of OOo-generated PDFs
  6206. if ((rect[3] - rect[1]) < ANNOT_MIN_SIZE) {
  6207. rect[3] = rect[1] + ANNOT_MIN_SIZE;
  6208. }
  6209. if ((rect[2] - rect[0]) < ANNOT_MIN_SIZE) {
  6210. rect[2] = rect[0] + (rect[3] - rect[1]); // make it square
  6211. }
  6212. var container = initContainer(item);
  6213. container.className = 'annotText';
  6214. var image = document.createElement('img');
  6215. image.style.height = container.style.height;
  6216. image.style.width = container.style.width;
  6217. var iconName = item.name;
  6218. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  6219. iconName.toLowerCase() + '.svg';
  6220. image.alt = '[{{type}} Annotation]';
  6221. image.dataset.l10nId = 'text_annotation_type';
  6222. image.dataset.l10nArgs = JSON.stringify({type: iconName});
  6223. var contentWrapper = document.createElement('div');
  6224. contentWrapper.className = 'annotTextContentWrapper';
  6225. contentWrapper.style.left = Math.floor(rect[2] - rect[0] + 5) + 'px';
  6226. contentWrapper.style.top = '-10px';
  6227. var content = document.createElement('div');
  6228. content.className = 'annotTextContent';
  6229. content.setAttribute('hidden', true);
  6230. var i, ii;
  6231. if (item.hasBgColor && item.color) {
  6232. var color = item.color;
  6233. // Enlighten the color (70%)
  6234. var BACKGROUND_ENLIGHT = 0.7;
  6235. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  6236. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  6237. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  6238. content.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  6239. }
  6240. var title = document.createElement('h1');
  6241. var text = document.createElement('p');
  6242. title.textContent = item.title;
  6243. if (!item.content && !item.title) {
  6244. content.setAttribute('hidden', true);
  6245. } else {
  6246. var e = document.createElement('span');
  6247. var lines = item.content.split(/(?:\r\n?|\n)/);
  6248. for (i = 0, ii = lines.length; i < ii; ++i) {
  6249. var line = lines[i];
  6250. e.appendChild(document.createTextNode(line));
  6251. if (i < (ii - 1)) {
  6252. e.appendChild(document.createElement('br'));
  6253. }
  6254. }
  6255. text.appendChild(e);
  6256. var pinned = false;
  6257. var showAnnotation = function showAnnotation(pin) {
  6258. if (pin) {
  6259. pinned = true;
  6260. }
  6261. if (content.hasAttribute('hidden')) {
  6262. container.style.zIndex += 1;
  6263. content.removeAttribute('hidden');
  6264. }
  6265. };
  6266. var hideAnnotation = function hideAnnotation(unpin) {
  6267. if (unpin) {
  6268. pinned = false;
  6269. }
  6270. if (!content.hasAttribute('hidden') && !pinned) {
  6271. container.style.zIndex -= 1;
  6272. content.setAttribute('hidden', true);
  6273. }
  6274. };
  6275. var toggleAnnotation = function toggleAnnotation() {
  6276. if (pinned) {
  6277. hideAnnotation(true);
  6278. } else {
  6279. showAnnotation(true);
  6280. }
  6281. };
  6282. image.addEventListener('click', function image_clickHandler() {
  6283. toggleAnnotation();
  6284. }, false);
  6285. image.addEventListener('mouseover', function image_mouseOverHandler() {
  6286. showAnnotation();
  6287. }, false);
  6288. image.addEventListener('mouseout', function image_mouseOutHandler() {
  6289. hideAnnotation();
  6290. }, false);
  6291. content.addEventListener('click', function content_clickHandler() {
  6292. hideAnnotation(true);
  6293. }, false);
  6294. }
  6295. content.appendChild(title);
  6296. content.appendChild(text);
  6297. contentWrapper.appendChild(content);
  6298. container.appendChild(image);
  6299. container.appendChild(contentWrapper);
  6300. return container;
  6301. }
  6302. function getHtmlElementForLinkAnnotation(item) {
  6303. var container = initContainer(item);
  6304. container.className = 'annotLink';
  6305. var link = document.createElement('a');
  6306. link.href = link.title = item.url || '';
  6307. if (item.url && isExternalLinkTargetSet()) {
  6308. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  6309. }
  6310. container.appendChild(link);
  6311. return container;
  6312. }
  6313. function getHtmlElement(data, objs) {
  6314. switch (data.annotationType) {
  6315. case AnnotationType.WIDGET:
  6316. return getHtmlElementForTextWidgetAnnotation(data, objs);
  6317. case AnnotationType.TEXT:
  6318. return getHtmlElementForTextAnnotation(data);
  6319. case AnnotationType.LINK:
  6320. return getHtmlElementForLinkAnnotation(data);
  6321. default:
  6322. throw new Error('Unsupported annotationType: ' + data.annotationType);
  6323. }
  6324. }
  6325. return {
  6326. getHtmlElement: getHtmlElement
  6327. };
  6328. })();
  6329. PDFJS.AnnotationUtils = AnnotationUtils;
  6330. /**
  6331. * Text layer render parameters.
  6332. *
  6333. * @typedef {Object} TextLayerRenderParameters
  6334. * @property {TextContent} textContent - Text content to render (the object is
  6335. * returned by the page's getTextContent() method).
  6336. * @property {HTMLElement} container - HTML element that will contain text runs.
  6337. * @property {PDFJS.PageViewport} viewport - The target viewport to properly
  6338. * layout the text runs.
  6339. * @property {Array} textDivs - (optional) HTML elements that are correspond
  6340. * the text items of the textContent input. This is output and shall be
  6341. * initially be set to empty array.
  6342. * @property {number} timeout - (optional) Delay in milliseconds before
  6343. * rendering of the text runs occurs.
  6344. */
  6345. var renderTextLayer = (function renderTextLayerClosure() {
  6346. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  6347. var NonWhitespaceRegexp = /\S/;
  6348. function isAllWhitespace(str) {
  6349. return !NonWhitespaceRegexp.test(str);
  6350. }
  6351. function appendText(textDivs, viewport, geom, styles) {
  6352. var style = styles[geom.fontName];
  6353. var textDiv = document.createElement('div');
  6354. textDivs.push(textDiv);
  6355. if (isAllWhitespace(geom.str)) {
  6356. textDiv.dataset.isWhitespace = true;
  6357. return;
  6358. }
  6359. var tx = PDFJS.Util.transform(viewport.transform, geom.transform);
  6360. var angle = Math.atan2(tx[1], tx[0]);
  6361. if (style.vertical) {
  6362. angle += Math.PI / 2;
  6363. }
  6364. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  6365. var fontAscent = fontHeight;
  6366. if (style.ascent) {
  6367. fontAscent = style.ascent * fontAscent;
  6368. } else if (style.descent) {
  6369. fontAscent = (1 + style.descent) * fontAscent;
  6370. }
  6371. var left;
  6372. var top;
  6373. if (angle === 0) {
  6374. left = tx[4];
  6375. top = tx[5] - fontAscent;
  6376. } else {
  6377. left = tx[4] + (fontAscent * Math.sin(angle));
  6378. top = tx[5] - (fontAscent * Math.cos(angle));
  6379. }
  6380. textDiv.style.left = left + 'px';
  6381. textDiv.style.top = top + 'px';
  6382. textDiv.style.fontSize = fontHeight + 'px';
  6383. textDiv.style.fontFamily = style.fontFamily;
  6384. textDiv.textContent = geom.str;
  6385. // |fontName| is only used by the Font Inspector. This test will succeed
  6386. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  6387. // not worth the effort to do a more accurate test.
  6388. if (PDFJS.pdfBug) {
  6389. textDiv.dataset.fontName = geom.fontName;
  6390. }
  6391. // Storing into dataset will convert number into string.
  6392. if (angle !== 0) {
  6393. textDiv.dataset.angle = angle * (180 / Math.PI);
  6394. }
  6395. // We don't bother scaling single-char text divs, because it has very
  6396. // little effect on text highlighting. This makes scrolling on docs with
  6397. // lots of such divs a lot faster.
  6398. if (geom.str.length > 1) {
  6399. if (style.vertical) {
  6400. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  6401. } else {
  6402. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  6403. }
  6404. }
  6405. }
  6406. function render(task) {
  6407. if (task._canceled) {
  6408. return;
  6409. }
  6410. var textLayerFrag = task._container;
  6411. var textDivs = task._textDivs;
  6412. var capability = task._capability;
  6413. var textDivsLength = textDivs.length;
  6414. // No point in rendering many divs as it would make the browser
  6415. // unusable even after the divs are rendered.
  6416. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  6417. capability.resolve();
  6418. return;
  6419. }
  6420. var canvas = document.createElement('canvas');
  6421. var ctx = canvas.getContext('2d', {alpha: false});
  6422. var lastFontSize;
  6423. var lastFontFamily;
  6424. for (var i = 0; i < textDivsLength; i++) {
  6425. var textDiv = textDivs[i];
  6426. if (textDiv.dataset.isWhitespace !== undefined) {
  6427. continue;
  6428. }
  6429. var fontSize = textDiv.style.fontSize;
  6430. var fontFamily = textDiv.style.fontFamily;
  6431. // Only build font string and set to context if different from last.
  6432. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  6433. ctx.font = fontSize + ' ' + fontFamily;
  6434. lastFontSize = fontSize;
  6435. lastFontFamily = fontFamily;
  6436. }
  6437. var width = ctx.measureText(textDiv.textContent).width;
  6438. if (width > 0) {
  6439. textLayerFrag.appendChild(textDiv);
  6440. var transform;
  6441. if (textDiv.dataset.canvasWidth !== undefined) {
  6442. // Dataset values come of type string.
  6443. var textScale = textDiv.dataset.canvasWidth / width;
  6444. transform = 'scaleX(' + textScale + ')';
  6445. } else {
  6446. transform = '';
  6447. }
  6448. var rotation = textDiv.dataset.angle;
  6449. if (rotation) {
  6450. transform = 'rotate(' + rotation + 'deg) ' + transform;
  6451. }
  6452. if (transform) {
  6453. PDFJS.CustomStyle.setProp('transform' , textDiv, transform);
  6454. }
  6455. }
  6456. }
  6457. capability.resolve();
  6458. }
  6459. /**
  6460. * Text layer rendering task.
  6461. *
  6462. * @param {TextContent} textContent
  6463. * @param {HTMLElement} container
  6464. * @param {PDFJS.PageViewport} viewport
  6465. * @param {Array} textDivs
  6466. * @private
  6467. */
  6468. function TextLayerRenderTask(textContent, container, viewport, textDivs) {
  6469. this._textContent = textContent;
  6470. this._container = container;
  6471. this._viewport = viewport;
  6472. textDivs = textDivs || [];
  6473. this._textDivs = textDivs;
  6474. this._canceled = false;
  6475. this._capability = createPromiseCapability();
  6476. this._renderTimer = null;
  6477. }
  6478. TextLayerRenderTask.prototype = {
  6479. get promise() {
  6480. return this._capability.promise;
  6481. },
  6482. cancel: function TextLayer_cancel() {
  6483. this._canceled = true;
  6484. if (this._renderTimer !== null) {
  6485. clearTimeout(this._renderTimer);
  6486. this._renderTimer = null;
  6487. }
  6488. this._capability.reject('canceled');
  6489. },
  6490. _render: function TextLayer_render(timeout) {
  6491. var textItems = this._textContent.items;
  6492. var styles = this._textContent.styles;
  6493. var textDivs = this._textDivs;
  6494. var viewport = this._viewport;
  6495. for (var i = 0, len = textItems.length; i < len; i++) {
  6496. appendText(textDivs, viewport, textItems[i], styles);
  6497. }
  6498. if (!timeout) { // Render right away
  6499. render(this);
  6500. } else { // Schedule
  6501. var self = this;
  6502. this._renderTimer = setTimeout(function() {
  6503. render(self);
  6504. self._renderTimer = null;
  6505. }, timeout);
  6506. }
  6507. }
  6508. };
  6509. /**
  6510. * Starts rendering of the text layer.
  6511. *
  6512. * @param {TextLayerRenderParameters} renderParameters
  6513. * @returns {TextLayerRenderTask}
  6514. */
  6515. function renderTextLayer(renderParameters) {
  6516. var task = new TextLayerRenderTask(renderParameters.textContent,
  6517. renderParameters.container,
  6518. renderParameters.viewport,
  6519. renderParameters.textDivs);
  6520. task._render(renderParameters.timeout);
  6521. return task;
  6522. }
  6523. return renderTextLayer;
  6524. })();
  6525. PDFJS.renderTextLayer = renderTextLayer;
  6526. var SVG_DEFAULTS = {
  6527. fontStyle: 'normal',
  6528. fontWeight: 'normal',
  6529. fillColor: '#000000'
  6530. };
  6531. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  6532. var PNG_HEADER =
  6533. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  6534. var CHUNK_WRAPPER_SIZE = 12;
  6535. var crcTable = new Int32Array(256);
  6536. for (var i = 0; i < 256; i++) {
  6537. var c = i;
  6538. for (var h = 0; h < 8; h++) {
  6539. if (c & 1) {
  6540. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  6541. } else {
  6542. c = (c >> 1) & 0x7fffffff;
  6543. }
  6544. }
  6545. crcTable[i] = c;
  6546. }
  6547. function crc32(data, start, end) {
  6548. var crc = -1;
  6549. for (var i = start; i < end; i++) {
  6550. var a = (crc ^ data[i]) & 0xff;
  6551. var b = crcTable[a];
  6552. crc = (crc >>> 8) ^ b;
  6553. }
  6554. return crc ^ -1;
  6555. }
  6556. function writePngChunk(type, body, data, offset) {
  6557. var p = offset;
  6558. var len = body.length;
  6559. data[p] = len >> 24 & 0xff;
  6560. data[p + 1] = len >> 16 & 0xff;
  6561. data[p + 2] = len >> 8 & 0xff;
  6562. data[p + 3] = len & 0xff;
  6563. p += 4;
  6564. data[p] = type.charCodeAt(0) & 0xff;
  6565. data[p + 1] = type.charCodeAt(1) & 0xff;
  6566. data[p + 2] = type.charCodeAt(2) & 0xff;
  6567. data[p + 3] = type.charCodeAt(3) & 0xff;
  6568. p += 4;
  6569. data.set(body, p);
  6570. p += body.length;
  6571. var crc = crc32(data, offset + 4, p);
  6572. data[p] = crc >> 24 & 0xff;
  6573. data[p + 1] = crc >> 16 & 0xff;
  6574. data[p + 2] = crc >> 8 & 0xff;
  6575. data[p + 3] = crc & 0xff;
  6576. }
  6577. function adler32(data, start, end) {
  6578. var a = 1;
  6579. var b = 0;
  6580. for (var i = start; i < end; ++i) {
  6581. a = (a + (data[i] & 0xff)) % 65521;
  6582. b = (b + a) % 65521;
  6583. }
  6584. return (b << 16) | a;
  6585. }
  6586. function encode(imgData, kind) {
  6587. var width = imgData.width;
  6588. var height = imgData.height;
  6589. var bitDepth, colorType, lineSize;
  6590. var bytes = imgData.data;
  6591. switch (kind) {
  6592. case ImageKind.GRAYSCALE_1BPP:
  6593. colorType = 0;
  6594. bitDepth = 1;
  6595. lineSize = (width + 7) >> 3;
  6596. break;
  6597. case ImageKind.RGB_24BPP:
  6598. colorType = 2;
  6599. bitDepth = 8;
  6600. lineSize = width * 3;
  6601. break;
  6602. case ImageKind.RGBA_32BPP:
  6603. colorType = 6;
  6604. bitDepth = 8;
  6605. lineSize = width * 4;
  6606. break;
  6607. default:
  6608. throw new Error('invalid format');
  6609. }
  6610. // prefix every row with predictor 0
  6611. var literals = new Uint8Array((1 + lineSize) * height);
  6612. var offsetLiterals = 0, offsetBytes = 0;
  6613. var y, i;
  6614. for (y = 0; y < height; ++y) {
  6615. literals[offsetLiterals++] = 0; // no prediction
  6616. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  6617. offsetLiterals);
  6618. offsetBytes += lineSize;
  6619. offsetLiterals += lineSize;
  6620. }
  6621. if (kind === ImageKind.GRAYSCALE_1BPP) {
  6622. // inverting for B/W
  6623. offsetLiterals = 0;
  6624. for (y = 0; y < height; y++) {
  6625. offsetLiterals++; // skipping predictor
  6626. for (i = 0; i < lineSize; i++) {
  6627. literals[offsetLiterals++] ^= 0xFF;
  6628. }
  6629. }
  6630. }
  6631. var ihdr = new Uint8Array([
  6632. width >> 24 & 0xff,
  6633. width >> 16 & 0xff,
  6634. width >> 8 & 0xff,
  6635. width & 0xff,
  6636. height >> 24 & 0xff,
  6637. height >> 16 & 0xff,
  6638. height >> 8 & 0xff,
  6639. height & 0xff,
  6640. bitDepth, // bit depth
  6641. colorType, // color type
  6642. 0x00, // compression method
  6643. 0x00, // filter method
  6644. 0x00 // interlace method
  6645. ]);
  6646. var len = literals.length;
  6647. var maxBlockLength = 0xFFFF;
  6648. var deflateBlocks = Math.ceil(len / maxBlockLength);
  6649. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  6650. var pi = 0;
  6651. idat[pi++] = 0x78; // compression method and flags
  6652. idat[pi++] = 0x9c; // flags
  6653. var pos = 0;
  6654. while (len > maxBlockLength) {
  6655. // writing non-final DEFLATE blocks type 0 and length of 65535
  6656. idat[pi++] = 0x00;
  6657. idat[pi++] = 0xff;
  6658. idat[pi++] = 0xff;
  6659. idat[pi++] = 0x00;
  6660. idat[pi++] = 0x00;
  6661. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  6662. pi += maxBlockLength;
  6663. pos += maxBlockLength;
  6664. len -= maxBlockLength;
  6665. }
  6666. // writing non-final DEFLATE blocks type 0
  6667. idat[pi++] = 0x01;
  6668. idat[pi++] = len & 0xff;
  6669. idat[pi++] = len >> 8 & 0xff;
  6670. idat[pi++] = (~len & 0xffff) & 0xff;
  6671. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  6672. idat.set(literals.subarray(pos), pi);
  6673. pi += literals.length - pos;
  6674. var adler = adler32(literals, 0, literals.length); // checksum
  6675. idat[pi++] = adler >> 24 & 0xff;
  6676. idat[pi++] = adler >> 16 & 0xff;
  6677. idat[pi++] = adler >> 8 & 0xff;
  6678. idat[pi++] = adler & 0xff;
  6679. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  6680. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  6681. ihdr.length + idat.length;
  6682. var data = new Uint8Array(pngLength);
  6683. var offset = 0;
  6684. data.set(PNG_HEADER, offset);
  6685. offset += PNG_HEADER.length;
  6686. writePngChunk('IHDR', ihdr, data, offset);
  6687. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  6688. writePngChunk('IDATA', idat, data, offset);
  6689. offset += CHUNK_WRAPPER_SIZE + idat.length;
  6690. writePngChunk('IEND', new Uint8Array(0), data, offset);
  6691. return PDFJS.createObjectURL(data, 'image/png');
  6692. }
  6693. return function convertImgDataToPng(imgData) {
  6694. var kind = (imgData.kind === undefined ?
  6695. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  6696. return encode(imgData, kind);
  6697. };
  6698. })();
  6699. var SVGExtraState = (function SVGExtraStateClosure() {
  6700. function SVGExtraState() {
  6701. this.fontSizeScale = 1;
  6702. this.fontWeight = SVG_DEFAULTS.fontWeight;
  6703. this.fontSize = 0;
  6704. this.textMatrix = IDENTITY_MATRIX;
  6705. this.fontMatrix = FONT_IDENTITY_MATRIX;
  6706. this.leading = 0;
  6707. // Current point (in user coordinates)
  6708. this.x = 0;
  6709. this.y = 0;
  6710. // Start of text line (in text coordinates)
  6711. this.lineX = 0;
  6712. this.lineY = 0;
  6713. // Character and word spacing
  6714. this.charSpacing = 0;
  6715. this.wordSpacing = 0;
  6716. this.textHScale = 1;
  6717. this.textRise = 0;
  6718. // Default foreground and background colors
  6719. this.fillColor = SVG_DEFAULTS.fillColor;
  6720. this.strokeColor = '#000000';
  6721. this.fillAlpha = 1;
  6722. this.strokeAlpha = 1;
  6723. this.lineWidth = 1;
  6724. this.lineJoin = '';
  6725. this.lineCap = '';
  6726. this.miterLimit = 0;
  6727. this.dashArray = [];
  6728. this.dashPhase = 0;
  6729. this.dependencies = [];
  6730. // Clipping
  6731. this.clipId = '';
  6732. this.pendingClip = false;
  6733. this.maskId = '';
  6734. }
  6735. SVGExtraState.prototype = {
  6736. clone: function SVGExtraState_clone() {
  6737. return Object.create(this);
  6738. },
  6739. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  6740. this.x = x;
  6741. this.y = y;
  6742. }
  6743. };
  6744. return SVGExtraState;
  6745. })();
  6746. var SVGGraphics = (function SVGGraphicsClosure() {
  6747. function createScratchSVG(width, height) {
  6748. var NS = 'http://www.w3.org/2000/svg';
  6749. var svg = document.createElementNS(NS, 'svg:svg');
  6750. svg.setAttributeNS(null, 'version', '1.1');
  6751. svg.setAttributeNS(null, 'width', width + 'px');
  6752. svg.setAttributeNS(null, 'height', height + 'px');
  6753. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  6754. return svg;
  6755. }
  6756. function opListToTree(opList) {
  6757. var opTree = [];
  6758. var tmp = [];
  6759. var opListLen = opList.length;
  6760. for (var x = 0; x < opListLen; x++) {
  6761. if (opList[x].fn === 'save') {
  6762. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  6763. tmp.push(opTree);
  6764. opTree = opTree[opTree.length - 1].items;
  6765. continue;
  6766. }
  6767. if(opList[x].fn === 'restore') {
  6768. opTree = tmp.pop();
  6769. } else {
  6770. opTree.push(opList[x]);
  6771. }
  6772. }
  6773. return opTree;
  6774. }
  6775. /**
  6776. * Formats float number.
  6777. * @param value {number} number to format.
  6778. * @returns {string}
  6779. */
  6780. function pf(value) {
  6781. if (value === (value | 0)) { // integer number
  6782. return value.toString();
  6783. }
  6784. var s = value.toFixed(10);
  6785. var i = s.length - 1;
  6786. if (s[i] !== '0') {
  6787. return s;
  6788. }
  6789. // removing trailing zeros
  6790. do {
  6791. i--;
  6792. } while (s[i] === '0');
  6793. return s.substr(0, s[i] === '.' ? i : i + 1);
  6794. }
  6795. /**
  6796. * Formats transform matrix. The standard rotation, scale and translate
  6797. * matrices are replaced by their shorter forms, and for identity matrix
  6798. * returns empty string to save the memory.
  6799. * @param m {Array} matrix to format.
  6800. * @returns {string}
  6801. */
  6802. function pm(m) {
  6803. if (m[4] === 0 && m[5] === 0) {
  6804. if (m[1] === 0 && m[2] === 0) {
  6805. if (m[0] === 1 && m[3] === 1) {
  6806. return '';
  6807. }
  6808. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  6809. }
  6810. if (m[0] === m[3] && m[1] === -m[2]) {
  6811. var a = Math.acos(m[0]) * 180 / Math.PI;
  6812. return 'rotate(' + pf(a) + ')';
  6813. }
  6814. } else {
  6815. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  6816. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6817. }
  6818. }
  6819. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  6820. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  6821. }
  6822. function SVGGraphics(commonObjs, objs) {
  6823. this.current = new SVGExtraState();
  6824. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  6825. this.transformStack = [];
  6826. this.extraStack = [];
  6827. this.commonObjs = commonObjs;
  6828. this.objs = objs;
  6829. this.pendingEOFill = false;
  6830. this.embedFonts = false;
  6831. this.embeddedFonts = {};
  6832. this.cssStyle = null;
  6833. }
  6834. var NS = 'http://www.w3.org/2000/svg';
  6835. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  6836. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  6837. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  6838. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  6839. var clipCount = 0;
  6840. var maskCount = 0;
  6841. SVGGraphics.prototype = {
  6842. save: function SVGGraphics_save() {
  6843. this.transformStack.push(this.transformMatrix);
  6844. var old = this.current;
  6845. this.extraStack.push(old);
  6846. this.current = old.clone();
  6847. },
  6848. restore: function SVGGraphics_restore() {
  6849. this.transformMatrix = this.transformStack.pop();
  6850. this.current = this.extraStack.pop();
  6851. this.tgrp = document.createElementNS(NS, 'svg:g');
  6852. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6853. this.pgrp.appendChild(this.tgrp);
  6854. },
  6855. group: function SVGGraphics_group(items) {
  6856. this.save();
  6857. this.executeOpTree(items);
  6858. this.restore();
  6859. },
  6860. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  6861. var fnArray = operatorList.fnArray;
  6862. var fnArrayLen = fnArray.length;
  6863. var argsArray = operatorList.argsArray;
  6864. var self = this;
  6865. for (var i = 0; i < fnArrayLen; i++) {
  6866. if (OPS.dependency === fnArray[i]) {
  6867. var deps = argsArray[i];
  6868. for (var n = 0, nn = deps.length; n < nn; n++) {
  6869. var obj = deps[n];
  6870. var common = obj.substring(0, 2) === 'g_';
  6871. var promise;
  6872. if (common) {
  6873. promise = new Promise(function(resolve) {
  6874. self.commonObjs.get(obj, resolve);
  6875. });
  6876. } else {
  6877. promise = new Promise(function(resolve) {
  6878. self.objs.get(obj, resolve);
  6879. });
  6880. }
  6881. this.current.dependencies.push(promise);
  6882. }
  6883. }
  6884. }
  6885. return Promise.all(this.current.dependencies);
  6886. },
  6887. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  6888. var transformMatrix = [a, b, c, d, e, f];
  6889. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  6890. transformMatrix);
  6891. this.tgrp = document.createElementNS(NS, 'svg:g');
  6892. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6893. },
  6894. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  6895. this.svg = createScratchSVG(viewport.width, viewport.height);
  6896. this.viewport = viewport;
  6897. return this.loadDependencies(operatorList).then(function () {
  6898. this.transformMatrix = IDENTITY_MATRIX;
  6899. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  6900. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  6901. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  6902. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  6903. this.defs = document.createElementNS(NS, 'svg:defs');
  6904. this.pgrp.appendChild(this.defs);
  6905. this.pgrp.appendChild(this.tgrp);
  6906. this.svg.appendChild(this.pgrp);
  6907. var opTree = this.convertOpList(operatorList);
  6908. this.executeOpTree(opTree);
  6909. return this.svg;
  6910. }.bind(this));
  6911. },
  6912. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  6913. var argsArray = operatorList.argsArray;
  6914. var fnArray = operatorList.fnArray;
  6915. var fnArrayLen = fnArray.length;
  6916. var REVOPS = [];
  6917. var opList = [];
  6918. for (var op in OPS) {
  6919. REVOPS[OPS[op]] = op;
  6920. }
  6921. for (var x = 0; x < fnArrayLen; x++) {
  6922. var fnId = fnArray[x];
  6923. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  6924. }
  6925. return opListToTree(opList);
  6926. },
  6927. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  6928. var opTreeLen = opTree.length;
  6929. for(var x = 0; x < opTreeLen; x++) {
  6930. var fn = opTree[x].fn;
  6931. var fnId = opTree[x].fnId;
  6932. var args = opTree[x].args;
  6933. switch (fnId | 0) {
  6934. case OPS.beginText:
  6935. this.beginText();
  6936. break;
  6937. case OPS.setLeading:
  6938. this.setLeading(args);
  6939. break;
  6940. case OPS.setLeadingMoveText:
  6941. this.setLeadingMoveText(args[0], args[1]);
  6942. break;
  6943. case OPS.setFont:
  6944. this.setFont(args);
  6945. break;
  6946. case OPS.showText:
  6947. this.showText(args[0]);
  6948. break;
  6949. case OPS.showSpacedText:
  6950. this.showText(args[0]);
  6951. break;
  6952. case OPS.endText:
  6953. this.endText();
  6954. break;
  6955. case OPS.moveText:
  6956. this.moveText(args[0], args[1]);
  6957. break;
  6958. case OPS.setCharSpacing:
  6959. this.setCharSpacing(args[0]);
  6960. break;
  6961. case OPS.setWordSpacing:
  6962. this.setWordSpacing(args[0]);
  6963. break;
  6964. case OPS.setHScale:
  6965. this.setHScale(args[0]);
  6966. break;
  6967. case OPS.setTextMatrix:
  6968. this.setTextMatrix(args[0], args[1], args[2],
  6969. args[3], args[4], args[5]);
  6970. break;
  6971. case OPS.setLineWidth:
  6972. this.setLineWidth(args[0]);
  6973. break;
  6974. case OPS.setLineJoin:
  6975. this.setLineJoin(args[0]);
  6976. break;
  6977. case OPS.setLineCap:
  6978. this.setLineCap(args[0]);
  6979. break;
  6980. case OPS.setMiterLimit:
  6981. this.setMiterLimit(args[0]);
  6982. break;
  6983. case OPS.setFillRGBColor:
  6984. this.setFillRGBColor(args[0], args[1], args[2]);
  6985. break;
  6986. case OPS.setStrokeRGBColor:
  6987. this.setStrokeRGBColor(args[0], args[1], args[2]);
  6988. break;
  6989. case OPS.setDash:
  6990. this.setDash(args[0], args[1]);
  6991. break;
  6992. case OPS.setGState:
  6993. this.setGState(args[0]);
  6994. break;
  6995. case OPS.fill:
  6996. this.fill();
  6997. break;
  6998. case OPS.eoFill:
  6999. this.eoFill();
  7000. break;
  7001. case OPS.stroke:
  7002. this.stroke();
  7003. break;
  7004. case OPS.fillStroke:
  7005. this.fillStroke();
  7006. break;
  7007. case OPS.eoFillStroke:
  7008. this.eoFillStroke();
  7009. break;
  7010. case OPS.clip:
  7011. this.clip('nonzero');
  7012. break;
  7013. case OPS.eoClip:
  7014. this.clip('evenodd');
  7015. break;
  7016. case OPS.paintSolidColorImageMask:
  7017. this.paintSolidColorImageMask();
  7018. break;
  7019. case OPS.paintJpegXObject:
  7020. this.paintJpegXObject(args[0], args[1], args[2]);
  7021. break;
  7022. case OPS.paintImageXObject:
  7023. this.paintImageXObject(args[0]);
  7024. break;
  7025. case OPS.paintInlineImageXObject:
  7026. this.paintInlineImageXObject(args[0]);
  7027. break;
  7028. case OPS.paintImageMaskXObject:
  7029. this.paintImageMaskXObject(args[0]);
  7030. break;
  7031. case OPS.paintFormXObjectBegin:
  7032. this.paintFormXObjectBegin(args[0], args[1]);
  7033. break;
  7034. case OPS.paintFormXObjectEnd:
  7035. this.paintFormXObjectEnd();
  7036. break;
  7037. case OPS.closePath:
  7038. this.closePath();
  7039. break;
  7040. case OPS.closeStroke:
  7041. this.closeStroke();
  7042. break;
  7043. case OPS.closeFillStroke:
  7044. this.closeFillStroke();
  7045. break;
  7046. case OPS.nextLine:
  7047. this.nextLine();
  7048. break;
  7049. case OPS.transform:
  7050. this.transform(args[0], args[1], args[2], args[3],
  7051. args[4], args[5]);
  7052. break;
  7053. case OPS.constructPath:
  7054. this.constructPath(args[0], args[1]);
  7055. break;
  7056. case OPS.endPath:
  7057. this.endPath();
  7058. break;
  7059. case 92:
  7060. this.group(opTree[x].items);
  7061. break;
  7062. default:
  7063. warn('Unimplemented method '+ fn);
  7064. break;
  7065. }
  7066. }
  7067. },
  7068. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  7069. this.current.wordSpacing = wordSpacing;
  7070. },
  7071. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  7072. this.current.charSpacing = charSpacing;
  7073. },
  7074. nextLine: function SVGGraphics_nextLine() {
  7075. this.moveText(0, this.current.leading);
  7076. },
  7077. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  7078. var current = this.current;
  7079. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  7080. this.current.x = this.current.lineX = 0;
  7081. this.current.y = this.current.lineY = 0;
  7082. current.xcoords = [];
  7083. current.tspan = document.createElementNS(NS, 'svg:tspan');
  7084. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7085. current.tspan.setAttributeNS(null, 'font-size',
  7086. pf(current.fontSize) + 'px');
  7087. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7088. current.txtElement = document.createElementNS(NS, 'svg:text');
  7089. current.txtElement.appendChild(current.tspan);
  7090. },
  7091. beginText: function SVGGraphics_beginText() {
  7092. this.current.x = this.current.lineX = 0;
  7093. this.current.y = this.current.lineY = 0;
  7094. this.current.textMatrix = IDENTITY_MATRIX;
  7095. this.current.lineMatrix = IDENTITY_MATRIX;
  7096. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  7097. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  7098. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  7099. this.current.xcoords = [];
  7100. },
  7101. moveText: function SVGGraphics_moveText(x, y) {
  7102. var current = this.current;
  7103. this.current.x = this.current.lineX += x;
  7104. this.current.y = this.current.lineY += y;
  7105. current.xcoords = [];
  7106. current.tspan = document.createElementNS(NS, 'svg:tspan');
  7107. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7108. current.tspan.setAttributeNS(null, 'font-size',
  7109. pf(current.fontSize) + 'px');
  7110. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7111. },
  7112. showText: function SVGGraphics_showText(glyphs) {
  7113. var current = this.current;
  7114. var font = current.font;
  7115. var fontSize = current.fontSize;
  7116. if (fontSize === 0) {
  7117. return;
  7118. }
  7119. var charSpacing = current.charSpacing;
  7120. var wordSpacing = current.wordSpacing;
  7121. var fontDirection = current.fontDirection;
  7122. var textHScale = current.textHScale * fontDirection;
  7123. var glyphsLength = glyphs.length;
  7124. var vertical = font.vertical;
  7125. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  7126. var x = 0, i;
  7127. for (i = 0; i < glyphsLength; ++i) {
  7128. var glyph = glyphs[i];
  7129. if (glyph === null) {
  7130. // word break
  7131. x += fontDirection * wordSpacing;
  7132. continue;
  7133. } else if (isNum(glyph)) {
  7134. x += -glyph * fontSize * 0.001;
  7135. continue;
  7136. }
  7137. current.xcoords.push(current.x + x * textHScale);
  7138. var width = glyph.width;
  7139. var character = glyph.fontChar;
  7140. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  7141. x += charWidth;
  7142. current.tspan.textContent += character;
  7143. }
  7144. if (vertical) {
  7145. current.y -= x * textHScale;
  7146. } else {
  7147. current.x += x * textHScale;
  7148. }
  7149. current.tspan.setAttributeNS(null, 'x',
  7150. current.xcoords.map(pf).join(' '));
  7151. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7152. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  7153. current.tspan.setAttributeNS(null, 'font-size',
  7154. pf(current.fontSize) + 'px');
  7155. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  7156. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  7157. }
  7158. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  7159. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  7160. }
  7161. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  7162. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  7163. }
  7164. current.txtElement.setAttributeNS(null, 'transform',
  7165. pm(current.textMatrix) +
  7166. ' scale(1, -1)' );
  7167. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  7168. current.txtElement.appendChild(current.tspan);
  7169. current.txtgrp.appendChild(current.txtElement);
  7170. this.tgrp.appendChild(current.txtElement);
  7171. },
  7172. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  7173. this.setLeading(-y);
  7174. this.moveText(x, y);
  7175. },
  7176. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  7177. if (!this.cssStyle) {
  7178. this.cssStyle = document.createElementNS(NS, 'svg:style');
  7179. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  7180. this.defs.appendChild(this.cssStyle);
  7181. }
  7182. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  7183. this.cssStyle.textContent +=
  7184. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  7185. ' src: url(' + url + '); }\n';
  7186. },
  7187. setFont: function SVGGraphics_setFont(details) {
  7188. var current = this.current;
  7189. var fontObj = this.commonObjs.get(details[0]);
  7190. var size = details[1];
  7191. this.current.font = fontObj;
  7192. if (this.embedFonts && fontObj.data &&
  7193. !this.embeddedFonts[fontObj.loadedName]) {
  7194. this.addFontStyle(fontObj);
  7195. this.embeddedFonts[fontObj.loadedName] = fontObj;
  7196. }
  7197. current.fontMatrix = (fontObj.fontMatrix ?
  7198. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  7199. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  7200. (fontObj.bold ? 'bold' : 'normal');
  7201. var italic = fontObj.italic ? 'italic' : 'normal';
  7202. if (size < 0) {
  7203. size = -size;
  7204. current.fontDirection = -1;
  7205. } else {
  7206. current.fontDirection = 1;
  7207. }
  7208. current.fontSize = size;
  7209. current.fontFamily = fontObj.loadedName;
  7210. current.fontWeight = bold;
  7211. current.fontStyle = italic;
  7212. current.tspan = document.createElementNS(NS, 'svg:tspan');
  7213. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  7214. current.xcoords = [];
  7215. },
  7216. endText: function SVGGraphics_endText() {
  7217. if (this.current.pendingClip) {
  7218. this.cgrp.appendChild(this.tgrp);
  7219. this.pgrp.appendChild(this.cgrp);
  7220. } else {
  7221. this.pgrp.appendChild(this.tgrp);
  7222. }
  7223. this.tgrp = document.createElementNS(NS, 'svg:g');
  7224. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7225. },
  7226. // Path properties
  7227. setLineWidth: function SVGGraphics_setLineWidth(width) {
  7228. this.current.lineWidth = width;
  7229. },
  7230. setLineCap: function SVGGraphics_setLineCap(style) {
  7231. this.current.lineCap = LINE_CAP_STYLES[style];
  7232. },
  7233. setLineJoin: function SVGGraphics_setLineJoin(style) {
  7234. this.current.lineJoin = LINE_JOIN_STYLES[style];
  7235. },
  7236. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  7237. this.current.miterLimit = limit;
  7238. },
  7239. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  7240. var color = Util.makeCssRgb(r, g, b);
  7241. this.current.strokeColor = color;
  7242. },
  7243. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  7244. var color = Util.makeCssRgb(r, g, b);
  7245. this.current.fillColor = color;
  7246. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  7247. this.current.xcoords = [];
  7248. },
  7249. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  7250. this.current.dashArray = dashArray;
  7251. this.current.dashPhase = dashPhase;
  7252. },
  7253. constructPath: function SVGGraphics_constructPath(ops, args) {
  7254. var current = this.current;
  7255. var x = current.x, y = current.y;
  7256. current.path = document.createElementNS(NS, 'svg:path');
  7257. var d = [];
  7258. var opLength = ops.length;
  7259. for (var i = 0, j = 0; i < opLength; i++) {
  7260. switch (ops[i] | 0) {
  7261. case OPS.rectangle:
  7262. x = args[j++];
  7263. y = args[j++];
  7264. var width = args[j++];
  7265. var height = args[j++];
  7266. var xw = x + width;
  7267. var yh = y + height;
  7268. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  7269. 'L', pf(x), pf(yh), 'Z');
  7270. break;
  7271. case OPS.moveTo:
  7272. x = args[j++];
  7273. y = args[j++];
  7274. d.push('M', pf(x), pf(y));
  7275. break;
  7276. case OPS.lineTo:
  7277. x = args[j++];
  7278. y = args[j++];
  7279. d.push('L', pf(x) , pf(y));
  7280. break;
  7281. case OPS.curveTo:
  7282. x = args[j + 4];
  7283. y = args[j + 5];
  7284. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  7285. pf(args[j + 3]), pf(x), pf(y));
  7286. j += 6;
  7287. break;
  7288. case OPS.curveTo2:
  7289. x = args[j + 2];
  7290. y = args[j + 3];
  7291. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  7292. pf(args[j + 2]), pf(args[j + 3]));
  7293. j += 4;
  7294. break;
  7295. case OPS.curveTo3:
  7296. x = args[j + 2];
  7297. y = args[j + 3];
  7298. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  7299. pf(x), pf(y));
  7300. j += 4;
  7301. break;
  7302. case OPS.closePath:
  7303. d.push('Z');
  7304. break;
  7305. }
  7306. }
  7307. current.path.setAttributeNS(null, 'd', d.join(' '));
  7308. current.path.setAttributeNS(null, 'stroke-miterlimit',
  7309. pf(current.miterLimit));
  7310. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  7311. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  7312. current.path.setAttributeNS(null, 'stroke-width',
  7313. pf(current.lineWidth) + 'px');
  7314. current.path.setAttributeNS(null, 'stroke-dasharray',
  7315. current.dashArray.map(pf).join(' '));
  7316. current.path.setAttributeNS(null, 'stroke-dashoffset',
  7317. pf(current.dashPhase) + 'px');
  7318. current.path.setAttributeNS(null, 'fill', 'none');
  7319. this.tgrp.appendChild(current.path);
  7320. if (current.pendingClip) {
  7321. this.cgrp.appendChild(this.tgrp);
  7322. this.pgrp.appendChild(this.cgrp);
  7323. } else {
  7324. this.pgrp.appendChild(this.tgrp);
  7325. }
  7326. // Saving a reference in current.element so that it can be addressed
  7327. // in 'fill' and 'stroke'
  7328. current.element = current.path;
  7329. current.setCurrentPoint(x, y);
  7330. },
  7331. endPath: function SVGGraphics_endPath() {
  7332. var current = this.current;
  7333. if (current.pendingClip) {
  7334. this.cgrp.appendChild(this.tgrp);
  7335. this.pgrp.appendChild(this.cgrp);
  7336. } else {
  7337. this.pgrp.appendChild(this.tgrp);
  7338. }
  7339. this.tgrp = document.createElementNS(NS, 'svg:g');
  7340. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7341. },
  7342. clip: function SVGGraphics_clip(type) {
  7343. var current = this.current;
  7344. // Add current path to clipping path
  7345. current.clipId = 'clippath' + clipCount;
  7346. clipCount++;
  7347. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  7348. this.clippath.setAttributeNS(null, 'id', current.clipId);
  7349. var clipElement = current.element.cloneNode();
  7350. if (type === 'evenodd') {
  7351. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  7352. } else {
  7353. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  7354. }
  7355. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  7356. this.clippath.appendChild(clipElement);
  7357. this.defs.appendChild(this.clippath);
  7358. // Create a new group with that attribute
  7359. current.pendingClip = true;
  7360. this.cgrp = document.createElementNS(NS, 'svg:g');
  7361. this.cgrp.setAttributeNS(null, 'clip-path',
  7362. 'url(#' + current.clipId + ')');
  7363. this.pgrp.appendChild(this.cgrp);
  7364. },
  7365. closePath: function SVGGraphics_closePath() {
  7366. var current = this.current;
  7367. var d = current.path.getAttributeNS(null, 'd');
  7368. d += 'Z';
  7369. current.path.setAttributeNS(null, 'd', d);
  7370. },
  7371. setLeading: function SVGGraphics_setLeading(leading) {
  7372. this.current.leading = -leading;
  7373. },
  7374. setTextRise: function SVGGraphics_setTextRise(textRise) {
  7375. this.current.textRise = textRise;
  7376. },
  7377. setHScale: function SVGGraphics_setHScale(scale) {
  7378. this.current.textHScale = scale / 100;
  7379. },
  7380. setGState: function SVGGraphics_setGState(states) {
  7381. for (var i = 0, ii = states.length; i < ii; i++) {
  7382. var state = states[i];
  7383. var key = state[0];
  7384. var value = state[1];
  7385. switch (key) {
  7386. case 'LW':
  7387. this.setLineWidth(value);
  7388. break;
  7389. case 'LC':
  7390. this.setLineCap(value);
  7391. break;
  7392. case 'LJ':
  7393. this.setLineJoin(value);
  7394. break;
  7395. case 'ML':
  7396. this.setMiterLimit(value);
  7397. break;
  7398. case 'D':
  7399. this.setDash(value[0], value[1]);
  7400. break;
  7401. case 'RI':
  7402. break;
  7403. case 'FL':
  7404. break;
  7405. case 'Font':
  7406. this.setFont(value);
  7407. break;
  7408. case 'CA':
  7409. break;
  7410. case 'ca':
  7411. break;
  7412. case 'BM':
  7413. break;
  7414. case 'SMask':
  7415. break;
  7416. }
  7417. }
  7418. },
  7419. fill: function SVGGraphics_fill() {
  7420. var current = this.current;
  7421. current.element.setAttributeNS(null, 'fill', current.fillColor);
  7422. },
  7423. stroke: function SVGGraphics_stroke() {
  7424. var current = this.current;
  7425. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  7426. current.element.setAttributeNS(null, 'fill', 'none');
  7427. },
  7428. eoFill: function SVGGraphics_eoFill() {
  7429. var current = this.current;
  7430. current.element.setAttributeNS(null, 'fill', current.fillColor);
  7431. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  7432. },
  7433. fillStroke: function SVGGraphics_fillStroke() {
  7434. // Order is important since stroke wants fill to be none.
  7435. // First stroke, then if fill needed, it will be overwritten.
  7436. this.stroke();
  7437. this.fill();
  7438. },
  7439. eoFillStroke: function SVGGraphics_eoFillStroke() {
  7440. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  7441. this.fillStroke();
  7442. },
  7443. closeStroke: function SVGGraphics_closeStroke() {
  7444. this.closePath();
  7445. this.stroke();
  7446. },
  7447. closeFillStroke: function SVGGraphics_closeFillStroke() {
  7448. this.closePath();
  7449. this.fillStroke();
  7450. },
  7451. paintSolidColorImageMask:
  7452. function SVGGraphics_paintSolidColorImageMask() {
  7453. var current = this.current;
  7454. var rect = document.createElementNS(NS, 'svg:rect');
  7455. rect.setAttributeNS(null, 'x', '0');
  7456. rect.setAttributeNS(null, 'y', '0');
  7457. rect.setAttributeNS(null, 'width', '1px');
  7458. rect.setAttributeNS(null, 'height', '1px');
  7459. rect.setAttributeNS(null, 'fill', current.fillColor);
  7460. this.tgrp.appendChild(rect);
  7461. },
  7462. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  7463. var current = this.current;
  7464. var imgObj = this.objs.get(objId);
  7465. var imgEl = document.createElementNS(NS, 'svg:image');
  7466. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  7467. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  7468. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  7469. imgEl.setAttributeNS(null, 'x', '0');
  7470. imgEl.setAttributeNS(null, 'y', pf(-h));
  7471. imgEl.setAttributeNS(null, 'transform',
  7472. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  7473. this.tgrp.appendChild(imgEl);
  7474. if (current.pendingClip) {
  7475. this.cgrp.appendChild(this.tgrp);
  7476. this.pgrp.appendChild(this.cgrp);
  7477. } else {
  7478. this.pgrp.appendChild(this.tgrp);
  7479. }
  7480. },
  7481. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  7482. var imgData = this.objs.get(objId);
  7483. if (!imgData) {
  7484. warn('Dependent image isn\'t ready yet');
  7485. return;
  7486. }
  7487. this.paintInlineImageXObject(imgData);
  7488. },
  7489. paintInlineImageXObject:
  7490. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  7491. var current = this.current;
  7492. var width = imgData.width;
  7493. var height = imgData.height;
  7494. var imgSrc = convertImgDataToPng(imgData);
  7495. var cliprect = document.createElementNS(NS, 'svg:rect');
  7496. cliprect.setAttributeNS(null, 'x', '0');
  7497. cliprect.setAttributeNS(null, 'y', '0');
  7498. cliprect.setAttributeNS(null, 'width', pf(width));
  7499. cliprect.setAttributeNS(null, 'height', pf(height));
  7500. current.element = cliprect;
  7501. this.clip('nonzero');
  7502. var imgEl = document.createElementNS(NS, 'svg:image');
  7503. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  7504. imgEl.setAttributeNS(null, 'x', '0');
  7505. imgEl.setAttributeNS(null, 'y', pf(-height));
  7506. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  7507. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  7508. imgEl.setAttributeNS(null, 'transform',
  7509. 'scale(' + pf(1 / width) + ' ' +
  7510. pf(-1 / height) + ')');
  7511. if (mask) {
  7512. mask.appendChild(imgEl);
  7513. } else {
  7514. this.tgrp.appendChild(imgEl);
  7515. }
  7516. if (current.pendingClip) {
  7517. this.cgrp.appendChild(this.tgrp);
  7518. this.pgrp.appendChild(this.cgrp);
  7519. } else {
  7520. this.pgrp.appendChild(this.tgrp);
  7521. }
  7522. },
  7523. paintImageMaskXObject:
  7524. function SVGGraphics_paintImageMaskXObject(imgData) {
  7525. var current = this.current;
  7526. var width = imgData.width;
  7527. var height = imgData.height;
  7528. var fillColor = current.fillColor;
  7529. current.maskId = 'mask' + maskCount++;
  7530. var mask = document.createElementNS(NS, 'svg:mask');
  7531. mask.setAttributeNS(null, 'id', current.maskId);
  7532. var rect = document.createElementNS(NS, 'svg:rect');
  7533. rect.setAttributeNS(null, 'x', '0');
  7534. rect.setAttributeNS(null, 'y', '0');
  7535. rect.setAttributeNS(null, 'width', pf(width));
  7536. rect.setAttributeNS(null, 'height', pf(height));
  7537. rect.setAttributeNS(null, 'fill', fillColor);
  7538. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  7539. this.defs.appendChild(mask);
  7540. this.tgrp.appendChild(rect);
  7541. this.paintInlineImageXObject(imgData, mask);
  7542. },
  7543. paintFormXObjectBegin:
  7544. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  7545. this.save();
  7546. if (isArray(matrix) && matrix.length === 6) {
  7547. this.transform(matrix[0], matrix[1], matrix[2],
  7548. matrix[3], matrix[4], matrix[5]);
  7549. }
  7550. if (isArray(bbox) && bbox.length === 4) {
  7551. var width = bbox[2] - bbox[0];
  7552. var height = bbox[3] - bbox[1];
  7553. var cliprect = document.createElementNS(NS, 'svg:rect');
  7554. cliprect.setAttributeNS(null, 'x', bbox[0]);
  7555. cliprect.setAttributeNS(null, 'y', bbox[1]);
  7556. cliprect.setAttributeNS(null, 'width', pf(width));
  7557. cliprect.setAttributeNS(null, 'height', pf(height));
  7558. this.current.element = cliprect;
  7559. this.clip('nonzero');
  7560. this.endPath();
  7561. }
  7562. },
  7563. paintFormXObjectEnd:
  7564. function SVGGraphics_paintFormXObjectEnd() {
  7565. this.restore();
  7566. }
  7567. };
  7568. return SVGGraphics;
  7569. })();
  7570. PDFJS.SVGGraphics = SVGGraphics;
  7571. var NetworkManager = (function NetworkManagerClosure() {
  7572. var OK_RESPONSE = 200;
  7573. var PARTIAL_CONTENT_RESPONSE = 206;
  7574. function NetworkManager(url, args) {
  7575. this.url = url;
  7576. args = args || {};
  7577. this.isHttp = /^https?:/i.test(url);
  7578. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  7579. this.withCredentials = args.withCredentials || false;
  7580. this.getXhr = args.getXhr ||
  7581. function NetworkManager_getXhr() {
  7582. return new XMLHttpRequest();
  7583. };
  7584. this.currXhrId = 0;
  7585. this.pendingRequests = {};
  7586. this.loadedRequests = {};
  7587. }
  7588. function getArrayBuffer(xhr) {
  7589. var data = xhr.response;
  7590. if (typeof data !== 'string') {
  7591. return data;
  7592. }
  7593. var length = data.length;
  7594. var array = new Uint8Array(length);
  7595. for (var i = 0; i < length; i++) {
  7596. array[i] = data.charCodeAt(i) & 0xFF;
  7597. }
  7598. return array.buffer;
  7599. }
  7600. var supportsMozChunked = (function supportsMozChunkedClosure() {
  7601. try {
  7602. var x = new XMLHttpRequest();
  7603. // Firefox 37- required .open() to be called before setting responseType.
  7604. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  7605. // Even though the URL is not visited, .open() could fail if the URL is
  7606. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  7607. // When this error occurs, this feature detection method will mistakenly
  7608. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  7609. x.open('GET', 'https://example.com');
  7610. x.responseType = 'moz-chunked-arraybuffer';
  7611. return x.responseType === 'moz-chunked-arraybuffer';
  7612. } catch (e) {
  7613. return false;
  7614. }
  7615. })();
  7616. NetworkManager.prototype = {
  7617. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  7618. var args = {
  7619. begin: begin,
  7620. end: end
  7621. };
  7622. for (var prop in listeners) {
  7623. args[prop] = listeners[prop];
  7624. }
  7625. return this.request(args);
  7626. },
  7627. requestFull: function NetworkManager_requestFull(listeners) {
  7628. return this.request(listeners);
  7629. },
  7630. request: function NetworkManager_request(args) {
  7631. var xhr = this.getXhr();
  7632. var xhrId = this.currXhrId++;
  7633. var pendingRequest = this.pendingRequests[xhrId] = {
  7634. xhr: xhr
  7635. };
  7636. xhr.open('GET', this.url);
  7637. xhr.withCredentials = this.withCredentials;
  7638. for (var property in this.httpHeaders) {
  7639. var value = this.httpHeaders[property];
  7640. if (typeof value === 'undefined') {
  7641. continue;
  7642. }
  7643. xhr.setRequestHeader(property, value);
  7644. }
  7645. if (this.isHttp && 'begin' in args && 'end' in args) {
  7646. var rangeStr = args.begin + '-' + (args.end - 1);
  7647. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  7648. pendingRequest.expectedStatus = 206;
  7649. } else {
  7650. pendingRequest.expectedStatus = 200;
  7651. }
  7652. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  7653. if (useMozChunkedLoading) {
  7654. xhr.responseType = 'moz-chunked-arraybuffer';
  7655. pendingRequest.onProgressiveData = args.onProgressiveData;
  7656. pendingRequest.mozChunked = true;
  7657. } else {
  7658. xhr.responseType = 'arraybuffer';
  7659. }
  7660. if (args.onError) {
  7661. xhr.onerror = function(evt) {
  7662. args.onError(xhr.status);
  7663. };
  7664. }
  7665. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  7666. xhr.onprogress = this.onProgress.bind(this, xhrId);
  7667. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  7668. pendingRequest.onDone = args.onDone;
  7669. pendingRequest.onError = args.onError;
  7670. pendingRequest.onProgress = args.onProgress;
  7671. xhr.send(null);
  7672. return xhrId;
  7673. },
  7674. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  7675. var pendingRequest = this.pendingRequests[xhrId];
  7676. if (!pendingRequest) {
  7677. // Maybe abortRequest was called...
  7678. return;
  7679. }
  7680. if (pendingRequest.mozChunked) {
  7681. var chunk = getArrayBuffer(pendingRequest.xhr);
  7682. pendingRequest.onProgressiveData(chunk);
  7683. }
  7684. var onProgress = pendingRequest.onProgress;
  7685. if (onProgress) {
  7686. onProgress(evt);
  7687. }
  7688. },
  7689. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  7690. var pendingRequest = this.pendingRequests[xhrId];
  7691. if (!pendingRequest) {
  7692. // Maybe abortRequest was called...
  7693. return;
  7694. }
  7695. var xhr = pendingRequest.xhr;
  7696. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  7697. pendingRequest.onHeadersReceived();
  7698. delete pendingRequest.onHeadersReceived;
  7699. }
  7700. if (xhr.readyState !== 4) {
  7701. return;
  7702. }
  7703. if (!(xhrId in this.pendingRequests)) {
  7704. // The XHR request might have been aborted in onHeadersReceived()
  7705. // callback, in which case we should abort request
  7706. return;
  7707. }
  7708. delete this.pendingRequests[xhrId];
  7709. // success status == 0 can be on ftp, file and other protocols
  7710. if (xhr.status === 0 && this.isHttp) {
  7711. if (pendingRequest.onError) {
  7712. pendingRequest.onError(xhr.status);
  7713. }
  7714. return;
  7715. }
  7716. var xhrStatus = xhr.status || OK_RESPONSE;
  7717. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  7718. // "A server MAY ignore the Range header". This means it's possible to
  7719. // get a 200 rather than a 206 response from a range request.
  7720. var ok_response_on_range_request =
  7721. xhrStatus === OK_RESPONSE &&
  7722. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  7723. if (!ok_response_on_range_request &&
  7724. xhrStatus !== pendingRequest.expectedStatus) {
  7725. if (pendingRequest.onError) {
  7726. pendingRequest.onError(xhr.status);
  7727. }
  7728. return;
  7729. }
  7730. this.loadedRequests[xhrId] = true;
  7731. var chunk = getArrayBuffer(xhr);
  7732. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  7733. var rangeHeader = xhr.getResponseHeader('Content-Range');
  7734. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  7735. var begin = parseInt(matches[1], 10);
  7736. pendingRequest.onDone({
  7737. begin: begin,
  7738. chunk: chunk
  7739. });
  7740. } else if (pendingRequest.onProgressiveData) {
  7741. pendingRequest.onDone(null);
  7742. } else if (chunk) {
  7743. pendingRequest.onDone({
  7744. begin: 0,
  7745. chunk: chunk
  7746. });
  7747. } else if (pendingRequest.onError) {
  7748. pendingRequest.onError(xhr.status);
  7749. }
  7750. },
  7751. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  7752. for (var xhrId in this.pendingRequests) {
  7753. return true;
  7754. }
  7755. return false;
  7756. },
  7757. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  7758. return this.pendingRequests[xhrId].xhr;
  7759. },
  7760. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  7761. return !!(this.pendingRequests[xhrId].onProgressiveData);
  7762. },
  7763. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  7764. return xhrId in this.pendingRequests;
  7765. },
  7766. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  7767. return xhrId in this.loadedRequests;
  7768. },
  7769. abortAllRequests: function NetworkManager_abortAllRequests() {
  7770. for (var xhrId in this.pendingRequests) {
  7771. this.abortRequest(xhrId | 0);
  7772. }
  7773. },
  7774. abortRequest: function NetworkManager_abortRequest(xhrId) {
  7775. var xhr = this.pendingRequests[xhrId].xhr;
  7776. delete this.pendingRequests[xhrId];
  7777. xhr.abort();
  7778. }
  7779. };
  7780. return NetworkManager;
  7781. })();
  7782. var ChunkedStream = (function ChunkedStreamClosure() {
  7783. function ChunkedStream(length, chunkSize, manager) {
  7784. this.bytes = new Uint8Array(length);
  7785. this.start = 0;
  7786. this.pos = 0;
  7787. this.end = length;
  7788. this.chunkSize = chunkSize;
  7789. this.loadedChunks = [];
  7790. this.numChunksLoaded = 0;
  7791. this.numChunks = Math.ceil(length / chunkSize);
  7792. this.manager = manager;
  7793. this.progressiveDataLength = 0;
  7794. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  7795. }
  7796. // required methods for a stream. if a particular stream does not
  7797. // implement these, an error should be thrown
  7798. ChunkedStream.prototype = {
  7799. getMissingChunks: function ChunkedStream_getMissingChunks() {
  7800. var chunks = [];
  7801. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  7802. if (!this.loadedChunks[chunk]) {
  7803. chunks.push(chunk);
  7804. }
  7805. }
  7806. return chunks;
  7807. },
  7808. getBaseStreams: function ChunkedStream_getBaseStreams() {
  7809. return [this];
  7810. },
  7811. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  7812. return this.numChunksLoaded === this.numChunks;
  7813. },
  7814. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  7815. var end = begin + chunk.byteLength;
  7816. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  7817. // Using this.length is inaccurate here since this.start can be moved
  7818. // See ChunkedStream.moveStart()
  7819. var length = this.bytes.length;
  7820. assert(end % this.chunkSize === 0 || end === length,
  7821. 'Bad end offset: ' + end);
  7822. this.bytes.set(new Uint8Array(chunk), begin);
  7823. var chunkSize = this.chunkSize;
  7824. var beginChunk = Math.floor(begin / chunkSize);
  7825. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7826. var curChunk;
  7827. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7828. if (!this.loadedChunks[curChunk]) {
  7829. this.loadedChunks[curChunk] = true;
  7830. ++this.numChunksLoaded;
  7831. }
  7832. }
  7833. },
  7834. onReceiveProgressiveData:
  7835. function ChunkedStream_onReceiveProgressiveData(data) {
  7836. var position = this.progressiveDataLength;
  7837. var beginChunk = Math.floor(position / this.chunkSize);
  7838. this.bytes.set(new Uint8Array(data), position);
  7839. position += data.byteLength;
  7840. this.progressiveDataLength = position;
  7841. var endChunk = position >= this.end ? this.numChunks :
  7842. Math.floor(position / this.chunkSize);
  7843. var curChunk;
  7844. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  7845. if (!this.loadedChunks[curChunk]) {
  7846. this.loadedChunks[curChunk] = true;
  7847. ++this.numChunksLoaded;
  7848. }
  7849. }
  7850. },
  7851. ensureByte: function ChunkedStream_ensureByte(pos) {
  7852. var chunk = Math.floor(pos / this.chunkSize);
  7853. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  7854. return;
  7855. }
  7856. if (!this.loadedChunks[chunk]) {
  7857. throw new MissingDataException(pos, pos + 1);
  7858. }
  7859. this.lastSuccessfulEnsureByteChunk = chunk;
  7860. },
  7861. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  7862. if (begin >= end) {
  7863. return;
  7864. }
  7865. if (end <= this.progressiveDataLength) {
  7866. return;
  7867. }
  7868. var chunkSize = this.chunkSize;
  7869. var beginChunk = Math.floor(begin / chunkSize);
  7870. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  7871. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7872. if (!this.loadedChunks[chunk]) {
  7873. throw new MissingDataException(begin, end);
  7874. }
  7875. }
  7876. },
  7877. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  7878. var chunk, numChunks = this.numChunks;
  7879. for (var i = 0; i < numChunks; ++i) {
  7880. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  7881. if (!this.loadedChunks[chunk]) {
  7882. return chunk;
  7883. }
  7884. }
  7885. return null;
  7886. },
  7887. hasChunk: function ChunkedStream_hasChunk(chunk) {
  7888. return !!this.loadedChunks[chunk];
  7889. },
  7890. get length() {
  7891. return this.end - this.start;
  7892. },
  7893. get isEmpty() {
  7894. return this.length === 0;
  7895. },
  7896. getByte: function ChunkedStream_getByte() {
  7897. var pos = this.pos;
  7898. if (pos >= this.end) {
  7899. return -1;
  7900. }
  7901. this.ensureByte(pos);
  7902. return this.bytes[this.pos++];
  7903. },
  7904. getUint16: function ChunkedStream_getUint16() {
  7905. var b0 = this.getByte();
  7906. var b1 = this.getByte();
  7907. if (b0 === -1 || b1 === -1) {
  7908. return -1;
  7909. }
  7910. return (b0 << 8) + b1;
  7911. },
  7912. getInt32: function ChunkedStream_getInt32() {
  7913. var b0 = this.getByte();
  7914. var b1 = this.getByte();
  7915. var b2 = this.getByte();
  7916. var b3 = this.getByte();
  7917. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  7918. },
  7919. // returns subarray of original buffer
  7920. // should only be read
  7921. getBytes: function ChunkedStream_getBytes(length) {
  7922. var bytes = this.bytes;
  7923. var pos = this.pos;
  7924. var strEnd = this.end;
  7925. if (!length) {
  7926. this.ensureRange(pos, strEnd);
  7927. return bytes.subarray(pos, strEnd);
  7928. }
  7929. var end = pos + length;
  7930. if (end > strEnd) {
  7931. end = strEnd;
  7932. }
  7933. this.ensureRange(pos, end);
  7934. this.pos = end;
  7935. return bytes.subarray(pos, end);
  7936. },
  7937. peekByte: function ChunkedStream_peekByte() {
  7938. var peekedByte = this.getByte();
  7939. this.pos--;
  7940. return peekedByte;
  7941. },
  7942. peekBytes: function ChunkedStream_peekBytes(length) {
  7943. var bytes = this.getBytes(length);
  7944. this.pos -= bytes.length;
  7945. return bytes;
  7946. },
  7947. getByteRange: function ChunkedStream_getBytes(begin, end) {
  7948. this.ensureRange(begin, end);
  7949. return this.bytes.subarray(begin, end);
  7950. },
  7951. skip: function ChunkedStream_skip(n) {
  7952. if (!n) {
  7953. n = 1;
  7954. }
  7955. this.pos += n;
  7956. },
  7957. reset: function ChunkedStream_reset() {
  7958. this.pos = this.start;
  7959. },
  7960. moveStart: function ChunkedStream_moveStart() {
  7961. this.start = this.pos;
  7962. },
  7963. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  7964. this.ensureRange(start, start + length);
  7965. function ChunkedStreamSubstream() {}
  7966. ChunkedStreamSubstream.prototype = Object.create(this);
  7967. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  7968. var chunkSize = this.chunkSize;
  7969. var beginChunk = Math.floor(this.start / chunkSize);
  7970. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  7971. var missingChunks = [];
  7972. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  7973. if (!this.loadedChunks[chunk]) {
  7974. missingChunks.push(chunk);
  7975. }
  7976. }
  7977. return missingChunks;
  7978. };
  7979. var subStream = new ChunkedStreamSubstream();
  7980. subStream.pos = subStream.start = start;
  7981. subStream.end = start + length || this.end;
  7982. subStream.dict = dict;
  7983. return subStream;
  7984. },
  7985. isStream: true
  7986. };
  7987. return ChunkedStream;
  7988. })();
  7989. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  7990. function ChunkedStreamManager(length, chunkSize, url, args) {
  7991. this.stream = new ChunkedStream(length, chunkSize, this);
  7992. this.length = length;
  7993. this.chunkSize = chunkSize;
  7994. this.url = url;
  7995. this.disableAutoFetch = args.disableAutoFetch;
  7996. var msgHandler = this.msgHandler = args.msgHandler;
  7997. if (args.chunkedViewerLoading) {
  7998. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  7999. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  8000. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  8001. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  8002. };
  8003. } else {
  8004. var getXhr = function getXhr() {
  8005. return new XMLHttpRequest();
  8006. };
  8007. this.networkManager = new NetworkManager(this.url, {
  8008. getXhr: getXhr,
  8009. httpHeaders: args.httpHeaders,
  8010. withCredentials: args.withCredentials
  8011. });
  8012. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  8013. this.networkManager.requestRange(begin, end, {
  8014. onDone: this.onReceiveData.bind(this),
  8015. onProgress: this.onProgress.bind(this)
  8016. });
  8017. };
  8018. }
  8019. this.currRequestId = 0;
  8020. this.chunksNeededByRequest = {};
  8021. this.requestsByChunk = {};
  8022. this.promisesByRequest = {};
  8023. this.progressiveDataLength = 0;
  8024. this._loadedStreamCapability = createPromiseCapability();
  8025. if (args.initialData) {
  8026. this.onReceiveData({chunk: args.initialData});
  8027. }
  8028. }
  8029. ChunkedStreamManager.prototype = {
  8030. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  8031. return this._loadedStreamCapability.promise;
  8032. },
  8033. // Get all the chunks that are not yet loaded and groups them into
  8034. // contiguous ranges to load in as few requests as possible
  8035. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  8036. var missingChunks = this.stream.getMissingChunks();
  8037. this._requestChunks(missingChunks);
  8038. return this._loadedStreamCapability.promise;
  8039. },
  8040. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  8041. var requestId = this.currRequestId++;
  8042. var chunksNeeded;
  8043. var i, ii;
  8044. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  8045. for (i = 0, ii = chunks.length; i < ii; i++) {
  8046. if (!this.stream.hasChunk(chunks[i])) {
  8047. chunksNeeded[chunks[i]] = true;
  8048. }
  8049. }
  8050. if (isEmptyObj(chunksNeeded)) {
  8051. return Promise.resolve();
  8052. }
  8053. var capability = createPromiseCapability();
  8054. this.promisesByRequest[requestId] = capability;
  8055. var chunksToRequest = [];
  8056. for (var chunk in chunksNeeded) {
  8057. chunk = chunk | 0;
  8058. if (!(chunk in this.requestsByChunk)) {
  8059. this.requestsByChunk[chunk] = [];
  8060. chunksToRequest.push(chunk);
  8061. }
  8062. this.requestsByChunk[chunk].push(requestId);
  8063. }
  8064. if (!chunksToRequest.length) {
  8065. return capability.promise;
  8066. }
  8067. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  8068. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  8069. var groupedChunk = groupedChunksToRequest[i];
  8070. var begin = groupedChunk.beginChunk * this.chunkSize;
  8071. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  8072. this.sendRequest(begin, end);
  8073. }
  8074. return capability.promise;
  8075. },
  8076. getStream: function ChunkedStreamManager_getStream() {
  8077. return this.stream;
  8078. },
  8079. // Loads any chunks in the requested range that are not yet loaded
  8080. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  8081. end = Math.min(end, this.length);
  8082. var beginChunk = this.getBeginChunk(begin);
  8083. var endChunk = this.getEndChunk(end);
  8084. var chunks = [];
  8085. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8086. chunks.push(chunk);
  8087. }
  8088. return this._requestChunks(chunks);
  8089. },
  8090. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  8091. ranges = ranges || [];
  8092. var chunksToRequest = [];
  8093. for (var i = 0; i < ranges.length; i++) {
  8094. var beginChunk = this.getBeginChunk(ranges[i].begin);
  8095. var endChunk = this.getEndChunk(ranges[i].end);
  8096. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  8097. if (chunksToRequest.indexOf(chunk) < 0) {
  8098. chunksToRequest.push(chunk);
  8099. }
  8100. }
  8101. }
  8102. chunksToRequest.sort(function(a, b) { return a - b; });
  8103. return this._requestChunks(chunksToRequest);
  8104. },
  8105. // Groups a sorted array of chunks into as few contiguous larger
  8106. // chunks as possible
  8107. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  8108. var groupedChunks = [];
  8109. var beginChunk = -1;
  8110. var prevChunk = -1;
  8111. for (var i = 0; i < chunks.length; ++i) {
  8112. var chunk = chunks[i];
  8113. if (beginChunk < 0) {
  8114. beginChunk = chunk;
  8115. }
  8116. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  8117. groupedChunks.push({ beginChunk: beginChunk,
  8118. endChunk: prevChunk + 1 });
  8119. beginChunk = chunk;
  8120. }
  8121. if (i + 1 === chunks.length) {
  8122. groupedChunks.push({ beginChunk: beginChunk,
  8123. endChunk: chunk + 1 });
  8124. }
  8125. prevChunk = chunk;
  8126. }
  8127. return groupedChunks;
  8128. },
  8129. onProgress: function ChunkedStreamManager_onProgress(args) {
  8130. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  8131. args.loaded);
  8132. this.msgHandler.send('DocProgress', {
  8133. loaded: bytesLoaded,
  8134. total: this.length
  8135. });
  8136. },
  8137. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  8138. var chunk = args.chunk;
  8139. var isProgressive = args.begin === undefined;
  8140. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  8141. var end = begin + chunk.byteLength;
  8142. var beginChunk = Math.floor(begin / this.chunkSize);
  8143. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  8144. Math.ceil(end / this.chunkSize);
  8145. if (isProgressive) {
  8146. this.stream.onReceiveProgressiveData(chunk);
  8147. this.progressiveDataLength = end;
  8148. } else {
  8149. this.stream.onReceiveData(begin, chunk);
  8150. }
  8151. if (this.stream.allChunksLoaded()) {
  8152. this._loadedStreamCapability.resolve(this.stream);
  8153. }
  8154. var loadedRequests = [];
  8155. var i, requestId;
  8156. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  8157. // The server might return more chunks than requested
  8158. var requestIds = this.requestsByChunk[chunk] || [];
  8159. delete this.requestsByChunk[chunk];
  8160. for (i = 0; i < requestIds.length; ++i) {
  8161. requestId = requestIds[i];
  8162. var chunksNeeded = this.chunksNeededByRequest[requestId];
  8163. if (chunk in chunksNeeded) {
  8164. delete chunksNeeded[chunk];
  8165. }
  8166. if (!isEmptyObj(chunksNeeded)) {
  8167. continue;
  8168. }
  8169. loadedRequests.push(requestId);
  8170. }
  8171. }
  8172. // If there are no pending requests, automatically fetch the next
  8173. // unfetched chunk of the PDF
  8174. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  8175. var nextEmptyChunk;
  8176. if (this.stream.numChunksLoaded === 1) {
  8177. // This is a special optimization so that after fetching the first
  8178. // chunk, rather than fetching the second chunk, we fetch the last
  8179. // chunk.
  8180. var lastChunk = this.stream.numChunks - 1;
  8181. if (!this.stream.hasChunk(lastChunk)) {
  8182. nextEmptyChunk = lastChunk;
  8183. }
  8184. } else {
  8185. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  8186. }
  8187. if (isInt(nextEmptyChunk)) {
  8188. this._requestChunks([nextEmptyChunk]);
  8189. }
  8190. }
  8191. for (i = 0; i < loadedRequests.length; ++i) {
  8192. requestId = loadedRequests[i];
  8193. var capability = this.promisesByRequest[requestId];
  8194. delete this.promisesByRequest[requestId];
  8195. capability.resolve();
  8196. }
  8197. this.msgHandler.send('DocProgress', {
  8198. loaded: this.stream.numChunksLoaded * this.chunkSize,
  8199. total: this.length
  8200. });
  8201. },
  8202. onError: function ChunkedStreamManager_onError(err) {
  8203. this._loadedStreamCapability.reject(err);
  8204. },
  8205. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  8206. var chunk = Math.floor(begin / this.chunkSize);
  8207. return chunk;
  8208. },
  8209. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  8210. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  8211. return chunk;
  8212. },
  8213. abort: function ChunkedStreamManager_abort() {
  8214. if (this.networkManager) {
  8215. this.networkManager.abortAllRequests();
  8216. }
  8217. for(var requestId in this.promisesByRequest) {
  8218. var capability = this.promisesByRequest[requestId];
  8219. capability.reject(new Error('Request was aborted'));
  8220. }
  8221. }
  8222. };
  8223. return ChunkedStreamManager;
  8224. })();
  8225. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  8226. var BasePdfManager = (function BasePdfManagerClosure() {
  8227. function BasePdfManager() {
  8228. throw new Error('Cannot initialize BaseManagerManager');
  8229. }
  8230. BasePdfManager.prototype = {
  8231. onLoadedStream: function BasePdfManager_onLoadedStream() {
  8232. throw new NotImplementedException();
  8233. },
  8234. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  8235. return this.ensure(this.pdfDocument, prop, args);
  8236. },
  8237. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  8238. return this.ensure(this.pdfDocument.xref, prop, args);
  8239. },
  8240. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  8241. return this.ensure(this.pdfDocument.catalog, prop, args);
  8242. },
  8243. getPage: function BasePdfManager_pagePage(pageIndex) {
  8244. return this.pdfDocument.getPage(pageIndex);
  8245. },
  8246. cleanup: function BasePdfManager_cleanup() {
  8247. return this.pdfDocument.cleanup();
  8248. },
  8249. ensure: function BasePdfManager_ensure(obj, prop, args) {
  8250. return new NotImplementedException();
  8251. },
  8252. requestRange: function BasePdfManager_ensure(begin, end) {
  8253. return new NotImplementedException();
  8254. },
  8255. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  8256. return new NotImplementedException();
  8257. },
  8258. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  8259. return new NotImplementedException();
  8260. },
  8261. updatePassword: function BasePdfManager_updatePassword(password) {
  8262. this.pdfDocument.xref.password = this.password = password;
  8263. if (this._passwordChangedCapability) {
  8264. this._passwordChangedCapability.resolve();
  8265. }
  8266. },
  8267. passwordChanged: function BasePdfManager_passwordChanged() {
  8268. this._passwordChangedCapability = createPromiseCapability();
  8269. return this._passwordChangedCapability.promise;
  8270. },
  8271. terminate: function BasePdfManager_terminate() {
  8272. return new NotImplementedException();
  8273. }
  8274. };
  8275. return BasePdfManager;
  8276. })();
  8277. var LocalPdfManager = (function LocalPdfManagerClosure() {
  8278. function LocalPdfManager(data, password) {
  8279. var stream = new Stream(data);
  8280. this.pdfDocument = new PDFDocument(this, stream, password);
  8281. this._loadedStreamCapability = createPromiseCapability();
  8282. this._loadedStreamCapability.resolve(stream);
  8283. }
  8284. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  8285. LocalPdfManager.prototype.constructor = LocalPdfManager;
  8286. LocalPdfManager.prototype.ensure =
  8287. function LocalPdfManager_ensure(obj, prop, args) {
  8288. return new Promise(function (resolve, reject) {
  8289. try {
  8290. var value = obj[prop];
  8291. var result;
  8292. if (typeof value === 'function') {
  8293. result = value.apply(obj, args);
  8294. } else {
  8295. result = value;
  8296. }
  8297. resolve(result);
  8298. } catch (e) {
  8299. reject(e);
  8300. }
  8301. });
  8302. };
  8303. LocalPdfManager.prototype.requestRange =
  8304. function LocalPdfManager_requestRange(begin, end) {
  8305. return Promise.resolve();
  8306. };
  8307. LocalPdfManager.prototype.requestLoadedStream =
  8308. function LocalPdfManager_requestLoadedStream() {
  8309. };
  8310. LocalPdfManager.prototype.onLoadedStream =
  8311. function LocalPdfManager_getLoadedStream() {
  8312. return this._loadedStreamCapability.promise;
  8313. };
  8314. LocalPdfManager.prototype.terminate =
  8315. function LocalPdfManager_terminate() {
  8316. return;
  8317. };
  8318. return LocalPdfManager;
  8319. })();
  8320. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  8321. function NetworkPdfManager(args, msgHandler) {
  8322. this.msgHandler = msgHandler;
  8323. var params = {
  8324. msgHandler: msgHandler,
  8325. httpHeaders: args.httpHeaders,
  8326. withCredentials: args.withCredentials,
  8327. chunkedViewerLoading: args.chunkedViewerLoading,
  8328. disableAutoFetch: args.disableAutoFetch,
  8329. initialData: args.initialData
  8330. };
  8331. this.streamManager = new ChunkedStreamManager(args.length,
  8332. args.rangeChunkSize,
  8333. args.url, params);
  8334. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  8335. args.password);
  8336. }
  8337. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  8338. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  8339. NetworkPdfManager.prototype.ensure =
  8340. function NetworkPdfManager_ensure(obj, prop, args) {
  8341. var pdfManager = this;
  8342. return new Promise(function (resolve, reject) {
  8343. function ensureHelper() {
  8344. try {
  8345. var result;
  8346. var value = obj[prop];
  8347. if (typeof value === 'function') {
  8348. result = value.apply(obj, args);
  8349. } else {
  8350. result = value;
  8351. }
  8352. resolve(result);
  8353. } catch(e) {
  8354. if (!(e instanceof MissingDataException)) {
  8355. reject(e);
  8356. return;
  8357. }
  8358. pdfManager.streamManager.requestRange(e.begin, e.end).
  8359. then(ensureHelper, reject);
  8360. }
  8361. }
  8362. ensureHelper();
  8363. });
  8364. };
  8365. NetworkPdfManager.prototype.requestRange =
  8366. function NetworkPdfManager_requestRange(begin, end) {
  8367. return this.streamManager.requestRange(begin, end);
  8368. };
  8369. NetworkPdfManager.prototype.requestLoadedStream =
  8370. function NetworkPdfManager_requestLoadedStream() {
  8371. this.streamManager.requestAllChunks();
  8372. };
  8373. NetworkPdfManager.prototype.sendProgressiveData =
  8374. function NetworkPdfManager_sendProgressiveData(chunk) {
  8375. this.streamManager.onReceiveData({ chunk: chunk });
  8376. };
  8377. NetworkPdfManager.prototype.onLoadedStream =
  8378. function NetworkPdfManager_getLoadedStream() {
  8379. return this.streamManager.onLoadedStream();
  8380. };
  8381. NetworkPdfManager.prototype.terminate =
  8382. function NetworkPdfManager_terminate() {
  8383. this.streamManager.abort();
  8384. };
  8385. return NetworkPdfManager;
  8386. })();
  8387. var Page = (function PageClosure() {
  8388. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  8389. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  8390. this.pdfManager = pdfManager;
  8391. this.pageIndex = pageIndex;
  8392. this.pageDict = pageDict;
  8393. this.xref = xref;
  8394. this.ref = ref;
  8395. this.fontCache = fontCache;
  8396. this.idCounters = {
  8397. obj: 0
  8398. };
  8399. this.resourcesPromise = null;
  8400. }
  8401. Page.prototype = {
  8402. getPageProp: function Page_getPageProp(key) {
  8403. return this.pageDict.get(key);
  8404. },
  8405. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  8406. var dict = this.pageDict, valueArray = null, loopCount = 0;
  8407. var MAX_LOOP_COUNT = 100;
  8408. // Always walk up the entire parent chain, to be able to find
  8409. // e.g. \Resources placed on multiple levels of the tree.
  8410. while (dict) {
  8411. var value = dict.get(key);
  8412. if (value) {
  8413. if (!valueArray) {
  8414. valueArray = [];
  8415. }
  8416. valueArray.push(value);
  8417. }
  8418. if (++loopCount > MAX_LOOP_COUNT) {
  8419. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  8420. break;
  8421. }
  8422. dict = dict.get('Parent');
  8423. }
  8424. if (!valueArray) {
  8425. return Dict.empty;
  8426. }
  8427. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  8428. loopCount > MAX_LOOP_COUNT) {
  8429. return valueArray[0];
  8430. }
  8431. return Dict.merge(this.xref, valueArray);
  8432. },
  8433. get content() {
  8434. return this.getPageProp('Contents');
  8435. },
  8436. get resources() {
  8437. // For robustness: The spec states that a \Resources entry has to be
  8438. // present, but can be empty. Some document omit it still, in this case
  8439. // we return an empty dictionary.
  8440. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  8441. },
  8442. get mediaBox() {
  8443. var obj = this.getInheritedPageProp('MediaBox');
  8444. // Reset invalid media box to letter size.
  8445. if (!isArray(obj) || obj.length !== 4) {
  8446. obj = LETTER_SIZE_MEDIABOX;
  8447. }
  8448. return shadow(this, 'mediaBox', obj);
  8449. },
  8450. get view() {
  8451. var mediaBox = this.mediaBox;
  8452. var cropBox = this.getInheritedPageProp('CropBox');
  8453. if (!isArray(cropBox) || cropBox.length !== 4) {
  8454. return shadow(this, 'view', mediaBox);
  8455. }
  8456. // From the spec, 6th ed., p.963:
  8457. // "The crop, bleed, trim, and art boxes should not ordinarily
  8458. // extend beyond the boundaries of the media box. If they do, they are
  8459. // effectively reduced to their intersection with the media box."
  8460. cropBox = Util.intersect(cropBox, mediaBox);
  8461. if (!cropBox) {
  8462. return shadow(this, 'view', mediaBox);
  8463. }
  8464. return shadow(this, 'view', cropBox);
  8465. },
  8466. get rotate() {
  8467. var rotate = this.getInheritedPageProp('Rotate') || 0;
  8468. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  8469. if (rotate % 90 !== 0) {
  8470. rotate = 0;
  8471. } else if (rotate >= 360) {
  8472. rotate = rotate % 360;
  8473. } else if (rotate < 0) {
  8474. // The spec doesn't cover negatives, assume its counterclockwise
  8475. // rotation. The following is the other implementation of modulo.
  8476. rotate = ((rotate % 360) + 360) % 360;
  8477. }
  8478. return shadow(this, 'rotate', rotate);
  8479. },
  8480. getContentStream: function Page_getContentStream() {
  8481. var content = this.content;
  8482. var stream;
  8483. if (isArray(content)) {
  8484. // fetching items
  8485. var xref = this.xref;
  8486. var i, n = content.length;
  8487. var streams = [];
  8488. for (i = 0; i < n; ++i) {
  8489. streams.push(xref.fetchIfRef(content[i]));
  8490. }
  8491. stream = new StreamsSequenceStream(streams);
  8492. } else if (isStream(content)) {
  8493. stream = content;
  8494. } else {
  8495. // replacing non-existent page content with empty one
  8496. stream = new NullStream();
  8497. }
  8498. return stream;
  8499. },
  8500. loadResources: function Page_loadResources(keys) {
  8501. if (!this.resourcesPromise) {
  8502. // TODO: add async getInheritedPageProp and remove this.
  8503. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  8504. }
  8505. return this.resourcesPromise.then(function resourceSuccess() {
  8506. var objectLoader = new ObjectLoader(this.resources.map,
  8507. keys,
  8508. this.xref);
  8509. return objectLoader.load();
  8510. }.bind(this));
  8511. },
  8512. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  8513. var self = this;
  8514. var pdfManager = this.pdfManager;
  8515. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8516. []);
  8517. var resourcesPromise = this.loadResources([
  8518. 'ExtGState',
  8519. 'ColorSpace',
  8520. 'Pattern',
  8521. 'Shading',
  8522. 'XObject',
  8523. 'Font'
  8524. // ProcSet
  8525. // Properties
  8526. ]);
  8527. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  8528. handler, this.pageIndex,
  8529. 'p' + this.pageIndex + '_',
  8530. this.idCounters,
  8531. this.fontCache);
  8532. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  8533. var pageListPromise = dataPromises.then(function(data) {
  8534. var contentStream = data[0];
  8535. var opList = new OperatorList(intent, handler, self.pageIndex);
  8536. handler.send('StartRenderPage', {
  8537. transparency: partialEvaluator.hasBlendModes(self.resources),
  8538. pageIndex: self.pageIndex,
  8539. intent: intent
  8540. });
  8541. return partialEvaluator.getOperatorList(contentStream, task,
  8542. self.resources, opList).then(function () {
  8543. return opList;
  8544. });
  8545. });
  8546. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  8547. return Promise.all([pageListPromise, annotationsPromise]).then(
  8548. function(datas) {
  8549. var pageOpList = datas[0];
  8550. var annotations = datas[1];
  8551. if (annotations.length === 0) {
  8552. pageOpList.flush(true);
  8553. return pageOpList;
  8554. }
  8555. var annotationsReadyPromise = Annotation.appendToOperatorList(
  8556. annotations, pageOpList, pdfManager, partialEvaluator, task, intent);
  8557. return annotationsReadyPromise.then(function () {
  8558. pageOpList.flush(true);
  8559. return pageOpList;
  8560. });
  8561. });
  8562. },
  8563. extractTextContent: function Page_extractTextContent(task) {
  8564. var handler = {
  8565. on: function nullHandlerOn() {},
  8566. send: function nullHandlerSend() {}
  8567. };
  8568. var self = this;
  8569. var pdfManager = this.pdfManager;
  8570. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  8571. []);
  8572. var resourcesPromise = this.loadResources([
  8573. 'ExtGState',
  8574. 'XObject',
  8575. 'Font'
  8576. ]);
  8577. var dataPromises = Promise.all([contentStreamPromise,
  8578. resourcesPromise]);
  8579. return dataPromises.then(function(data) {
  8580. var contentStream = data[0];
  8581. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  8582. handler, self.pageIndex,
  8583. 'p' + self.pageIndex + '_',
  8584. self.idCounters,
  8585. self.fontCache);
  8586. return partialEvaluator.getTextContent(contentStream,
  8587. task,
  8588. self.resources);
  8589. });
  8590. },
  8591. getAnnotationsData: function Page_getAnnotationsData() {
  8592. var annotations = this.annotations;
  8593. var annotationsData = [];
  8594. for (var i = 0, n = annotations.length; i < n; ++i) {
  8595. annotationsData.push(annotations[i].data);
  8596. }
  8597. return annotationsData;
  8598. },
  8599. get annotations() {
  8600. var annotations = [];
  8601. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  8602. var annotationFactory = new AnnotationFactory();
  8603. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  8604. var annotationRef = annotationRefs[i];
  8605. var annotation = annotationFactory.create(this.xref, annotationRef);
  8606. if (annotation &&
  8607. (annotation.isViewable() || annotation.isPrintable())) {
  8608. annotations.push(annotation);
  8609. }
  8610. }
  8611. return shadow(this, 'annotations', annotations);
  8612. }
  8613. };
  8614. return Page;
  8615. })();
  8616. /**
  8617. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  8618. * `PDFDoc`, this one doesn't have any job management code.
  8619. * Right now there exists one PDFDocument on the main thread + one object
  8620. * for each worker. If there is no worker support enabled, there are two
  8621. * `PDFDocument` objects on the main thread created.
  8622. */
  8623. var PDFDocument = (function PDFDocumentClosure() {
  8624. var FINGERPRINT_FIRST_BYTES = 1024;
  8625. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  8626. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  8627. function PDFDocument(pdfManager, arg, password) {
  8628. if (isStream(arg)) {
  8629. init.call(this, pdfManager, arg, password);
  8630. } else if (isArrayBuffer(arg)) {
  8631. init.call(this, pdfManager, new Stream(arg), password);
  8632. } else {
  8633. error('PDFDocument: Unknown argument type');
  8634. }
  8635. }
  8636. function init(pdfManager, stream, password) {
  8637. assert(stream.length > 0, 'stream must have data');
  8638. this.pdfManager = pdfManager;
  8639. this.stream = stream;
  8640. var xref = new XRef(this.stream, password, pdfManager);
  8641. this.xref = xref;
  8642. }
  8643. function find(stream, needle, limit, backwards) {
  8644. var pos = stream.pos;
  8645. var end = stream.end;
  8646. var strBuf = [];
  8647. if (pos + limit > end) {
  8648. limit = end - pos;
  8649. }
  8650. for (var n = 0; n < limit; ++n) {
  8651. strBuf.push(String.fromCharCode(stream.getByte()));
  8652. }
  8653. var str = strBuf.join('');
  8654. stream.pos = pos;
  8655. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  8656. if (index === -1) {
  8657. return false; /* not found */
  8658. }
  8659. stream.pos += index;
  8660. return true; /* found */
  8661. }
  8662. var DocumentInfoValidators = {
  8663. get entries() {
  8664. // Lazily build this since all the validation functions below are not
  8665. // defined until after this file loads.
  8666. return shadow(this, 'entries', {
  8667. Title: isString,
  8668. Author: isString,
  8669. Subject: isString,
  8670. Keywords: isString,
  8671. Creator: isString,
  8672. Producer: isString,
  8673. CreationDate: isString,
  8674. ModDate: isString,
  8675. Trapped: isName
  8676. });
  8677. }
  8678. };
  8679. PDFDocument.prototype = {
  8680. parse: function PDFDocument_parse(recoveryMode) {
  8681. this.setup(recoveryMode);
  8682. var version = this.catalog.catDict.get('Version');
  8683. if (isName(version)) {
  8684. this.pdfFormatVersion = version.name;
  8685. }
  8686. try {
  8687. // checking if AcroForm is present
  8688. this.acroForm = this.catalog.catDict.get('AcroForm');
  8689. if (this.acroForm) {
  8690. this.xfa = this.acroForm.get('XFA');
  8691. var fields = this.acroForm.get('Fields');
  8692. if ((!fields || !isArray(fields) || fields.length === 0) &&
  8693. !this.xfa) {
  8694. // no fields and no XFA -- not a form (?)
  8695. this.acroForm = null;
  8696. }
  8697. }
  8698. } catch (ex) {
  8699. info('Something wrong with AcroForm entry');
  8700. this.acroForm = null;
  8701. }
  8702. },
  8703. get linearization() {
  8704. var linearization = null;
  8705. if (this.stream.length) {
  8706. try {
  8707. linearization = Linearization.create(this.stream);
  8708. } catch (err) {
  8709. if (err instanceof MissingDataException) {
  8710. throw err;
  8711. }
  8712. info(err);
  8713. }
  8714. }
  8715. // shadow the prototype getter with a data property
  8716. return shadow(this, 'linearization', linearization);
  8717. },
  8718. get startXRef() {
  8719. var stream = this.stream;
  8720. var startXRef = 0;
  8721. var linearization = this.linearization;
  8722. if (linearization) {
  8723. // Find end of first obj.
  8724. stream.reset();
  8725. if (find(stream, 'endobj', 1024)) {
  8726. startXRef = stream.pos + 6;
  8727. }
  8728. } else {
  8729. // Find startxref by jumping backward from the end of the file.
  8730. var step = 1024;
  8731. var found = false, pos = stream.end;
  8732. while (!found && pos > 0) {
  8733. pos -= step - 'startxref'.length;
  8734. if (pos < 0) {
  8735. pos = 0;
  8736. }
  8737. stream.pos = pos;
  8738. found = find(stream, 'startxref', step, true);
  8739. }
  8740. if (found) {
  8741. stream.skip(9);
  8742. var ch;
  8743. do {
  8744. ch = stream.getByte();
  8745. } while (Lexer.isSpace(ch));
  8746. var str = '';
  8747. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  8748. str += String.fromCharCode(ch);
  8749. ch = stream.getByte();
  8750. }
  8751. startXRef = parseInt(str, 10);
  8752. if (isNaN(startXRef)) {
  8753. startXRef = 0;
  8754. }
  8755. }
  8756. }
  8757. // shadow the prototype getter with a data property
  8758. return shadow(this, 'startXRef', startXRef);
  8759. },
  8760. get mainXRefEntriesOffset() {
  8761. var mainXRefEntriesOffset = 0;
  8762. var linearization = this.linearization;
  8763. if (linearization) {
  8764. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  8765. }
  8766. // shadow the prototype getter with a data property
  8767. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  8768. },
  8769. // Find the header, remove leading garbage and setup the stream
  8770. // starting from the header.
  8771. checkHeader: function PDFDocument_checkHeader() {
  8772. var stream = this.stream;
  8773. stream.reset();
  8774. if (find(stream, '%PDF-', 1024)) {
  8775. // Found the header, trim off any garbage before it.
  8776. stream.moveStart();
  8777. // Reading file format version
  8778. var MAX_VERSION_LENGTH = 12;
  8779. var version = '', ch;
  8780. while ((ch = stream.getByte()) > 0x20) { // SPACE
  8781. if (version.length >= MAX_VERSION_LENGTH) {
  8782. break;
  8783. }
  8784. version += String.fromCharCode(ch);
  8785. }
  8786. if (!this.pdfFormatVersion) {
  8787. // removing "%PDF-"-prefix
  8788. this.pdfFormatVersion = version.substring(5);
  8789. }
  8790. return;
  8791. }
  8792. // May not be a PDF file, continue anyway.
  8793. },
  8794. parseStartXRef: function PDFDocument_parseStartXRef() {
  8795. var startXRef = this.startXRef;
  8796. this.xref.setStartXRef(startXRef);
  8797. },
  8798. setup: function PDFDocument_setup(recoveryMode) {
  8799. this.xref.parse(recoveryMode);
  8800. this.catalog = new Catalog(this.pdfManager, this.xref);
  8801. },
  8802. get numPages() {
  8803. var linearization = this.linearization;
  8804. var num = linearization ? linearization.numPages : this.catalog.numPages;
  8805. // shadow the prototype getter
  8806. return shadow(this, 'numPages', num);
  8807. },
  8808. get documentInfo() {
  8809. var docInfo = {
  8810. PDFFormatVersion: this.pdfFormatVersion,
  8811. IsAcroFormPresent: !!this.acroForm,
  8812. IsXFAPresent: !!this.xfa
  8813. };
  8814. var infoDict;
  8815. try {
  8816. infoDict = this.xref.trailer.get('Info');
  8817. } catch (err) {
  8818. info('The document information dictionary is invalid.');
  8819. }
  8820. if (infoDict) {
  8821. var validEntries = DocumentInfoValidators.entries;
  8822. // Only fill the document info with valid entries from the spec.
  8823. for (var key in validEntries) {
  8824. if (infoDict.has(key)) {
  8825. var value = infoDict.get(key);
  8826. // Make sure the value conforms to the spec.
  8827. if (validEntries[key](value)) {
  8828. docInfo[key] = (typeof value !== 'string' ?
  8829. value : stringToPDFString(value));
  8830. } else {
  8831. info('Bad value in document info for "' + key + '"');
  8832. }
  8833. }
  8834. }
  8835. }
  8836. return shadow(this, 'documentInfo', docInfo);
  8837. },
  8838. get fingerprint() {
  8839. var xref = this.xref, hash, fileID = '';
  8840. var idArray = xref.trailer.get('ID');
  8841. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  8842. idArray[0] !== EMPTY_FINGERPRINT) {
  8843. hash = stringToBytes(idArray[0]);
  8844. } else {
  8845. if (this.stream.ensureRange) {
  8846. this.stream.ensureRange(0,
  8847. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  8848. }
  8849. hash = calculateMD5(this.stream.bytes.subarray(0,
  8850. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  8851. }
  8852. for (var i = 0, n = hash.length; i < n; i++) {
  8853. var hex = hash[i].toString(16);
  8854. fileID += hex.length === 1 ? '0' + hex : hex;
  8855. }
  8856. return shadow(this, 'fingerprint', fileID);
  8857. },
  8858. getPage: function PDFDocument_getPage(pageIndex) {
  8859. return this.catalog.getPage(pageIndex);
  8860. },
  8861. cleanup: function PDFDocument_cleanup() {
  8862. return this.catalog.cleanup();
  8863. }
  8864. };
  8865. return PDFDocument;
  8866. })();
  8867. var Name = (function NameClosure() {
  8868. function Name(name) {
  8869. this.name = name;
  8870. }
  8871. Name.prototype = {};
  8872. var nameCache = {};
  8873. Name.get = function Name_get(name) {
  8874. var nameValue = nameCache[name];
  8875. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  8876. };
  8877. return Name;
  8878. })();
  8879. var Cmd = (function CmdClosure() {
  8880. function Cmd(cmd) {
  8881. this.cmd = cmd;
  8882. }
  8883. Cmd.prototype = {};
  8884. var cmdCache = {};
  8885. Cmd.get = function Cmd_get(cmd) {
  8886. var cmdValue = cmdCache[cmd];
  8887. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  8888. };
  8889. return Cmd;
  8890. })();
  8891. var Dict = (function DictClosure() {
  8892. var nonSerializable = function nonSerializableClosure() {
  8893. return nonSerializable; // creating closure on some variable
  8894. };
  8895. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  8896. 'Background': true,
  8897. 'ExtGState': true,
  8898. 'Halftone': true,
  8899. 'Layout': true,
  8900. 'Mask': true,
  8901. 'Pagination': true,
  8902. 'Printing': true
  8903. };
  8904. function isRecursionAllowedFor(dict) {
  8905. if (!isName(dict.Type)) {
  8906. return true;
  8907. }
  8908. var dictType = dict.Type.name;
  8909. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  8910. }
  8911. // xref is optional
  8912. function Dict(xref) {
  8913. // Map should only be used internally, use functions below to access.
  8914. this.map = Object.create(null);
  8915. this.xref = xref;
  8916. this.objId = null;
  8917. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  8918. }
  8919. Dict.prototype = {
  8920. assignXref: function Dict_assignXref(newXref) {
  8921. this.xref = newXref;
  8922. },
  8923. // automatically dereferences Ref objects
  8924. get: function Dict_get(key1, key2, key3) {
  8925. var value;
  8926. var xref = this.xref;
  8927. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8928. typeof key2 === 'undefined') {
  8929. return xref ? xref.fetchIfRef(value) : value;
  8930. }
  8931. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8932. typeof key3 === 'undefined') {
  8933. return xref ? xref.fetchIfRef(value) : value;
  8934. }
  8935. value = this.map[key3] || null;
  8936. return xref ? xref.fetchIfRef(value) : value;
  8937. },
  8938. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  8939. getAsync: function Dict_getAsync(key1, key2, key3) {
  8940. var value;
  8941. var xref = this.xref;
  8942. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  8943. typeof key2 === 'undefined') {
  8944. if (xref) {
  8945. return xref.fetchIfRefAsync(value);
  8946. }
  8947. return Promise.resolve(value);
  8948. }
  8949. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  8950. typeof key3 === 'undefined') {
  8951. if (xref) {
  8952. return xref.fetchIfRefAsync(value);
  8953. }
  8954. return Promise.resolve(value);
  8955. }
  8956. value = this.map[key3] || null;
  8957. if (xref) {
  8958. return xref.fetchIfRefAsync(value);
  8959. }
  8960. return Promise.resolve(value);
  8961. },
  8962. // Same as get(), but dereferences all elements if the result is an Array.
  8963. getArray: function Dict_getArray(key1, key2, key3) {
  8964. var value = this.get(key1, key2, key3);
  8965. var xref = this.xref;
  8966. if (!isArray(value) || !xref) {
  8967. return value;
  8968. }
  8969. value = value.slice(); // Ensure that we don't modify the Dict data.
  8970. for (var i = 0, ii = value.length; i < ii; i++) {
  8971. if (!isRef(value[i])) {
  8972. continue;
  8973. }
  8974. value[i] = xref.fetch(value[i]);
  8975. }
  8976. return value;
  8977. },
  8978. // no dereferencing
  8979. getRaw: function Dict_getRaw(key) {
  8980. return this.map[key];
  8981. },
  8982. // creates new map and dereferences all Refs
  8983. getAll: function Dict_getAll() {
  8984. var all = Object.create(null);
  8985. var queue = null;
  8986. var key, obj;
  8987. for (key in this.map) {
  8988. obj = this.get(key);
  8989. if (obj instanceof Dict) {
  8990. if (isRecursionAllowedFor(obj)) {
  8991. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  8992. } else {
  8993. all[key] = this.getRaw(key);
  8994. }
  8995. } else {
  8996. all[key] = obj;
  8997. }
  8998. }
  8999. if (!queue) {
  9000. return all;
  9001. }
  9002. // trying to take cyclic references into the account
  9003. var processed = Object.create(null);
  9004. while (queue.length > 0) {
  9005. var item = queue.shift();
  9006. var itemObj = item.obj;
  9007. var objId = itemObj.objId;
  9008. if (objId && objId in processed) {
  9009. item.target[item.key] = processed[objId];
  9010. continue;
  9011. }
  9012. var dereferenced = Object.create(null);
  9013. for (key in itemObj.map) {
  9014. obj = itemObj.get(key);
  9015. if (obj instanceof Dict) {
  9016. if (isRecursionAllowedFor(obj)) {
  9017. queue.push({target: dereferenced, key: key, obj: obj});
  9018. } else {
  9019. dereferenced[key] = itemObj.getRaw(key);
  9020. }
  9021. } else {
  9022. dereferenced[key] = obj;
  9023. }
  9024. }
  9025. if (objId) {
  9026. processed[objId] = dereferenced;
  9027. }
  9028. item.target[item.key] = dereferenced;
  9029. }
  9030. return all;
  9031. },
  9032. getKeys: function Dict_getKeys() {
  9033. return Object.keys(this.map);
  9034. },
  9035. set: function Dict_set(key, value) {
  9036. this.map[key] = value;
  9037. },
  9038. has: function Dict_has(key) {
  9039. return key in this.map;
  9040. },
  9041. forEach: function Dict_forEach(callback) {
  9042. for (var key in this.map) {
  9043. callback(key, this.get(key));
  9044. }
  9045. }
  9046. };
  9047. Dict.empty = new Dict(null);
  9048. Dict.merge = function Dict_merge(xref, dictArray) {
  9049. var mergedDict = new Dict(xref);
  9050. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  9051. var dict = dictArray[i];
  9052. if (!isDict(dict)) {
  9053. continue;
  9054. }
  9055. for (var keyName in dict.map) {
  9056. if (mergedDict.map[keyName]) {
  9057. continue;
  9058. }
  9059. mergedDict.map[keyName] = dict.map[keyName];
  9060. }
  9061. }
  9062. return mergedDict;
  9063. };
  9064. return Dict;
  9065. })();
  9066. var Ref = (function RefClosure() {
  9067. function Ref(num, gen) {
  9068. this.num = num;
  9069. this.gen = gen;
  9070. }
  9071. Ref.prototype = {
  9072. toString: function Ref_toString() {
  9073. // This function is hot, so we make the string as compact as possible.
  9074. // |this.gen| is almost always zero, so we treat that case specially.
  9075. var str = this.num + 'R';
  9076. if (this.gen !== 0) {
  9077. str += this.gen;
  9078. }
  9079. return str;
  9080. }
  9081. };
  9082. return Ref;
  9083. })();
  9084. // The reference is identified by number and generation.
  9085. // This structure stores only one instance of the reference.
  9086. var RefSet = (function RefSetClosure() {
  9087. function RefSet() {
  9088. this.dict = {};
  9089. }
  9090. RefSet.prototype = {
  9091. has: function RefSet_has(ref) {
  9092. return ref.toString() in this.dict;
  9093. },
  9094. put: function RefSet_put(ref) {
  9095. this.dict[ref.toString()] = true;
  9096. },
  9097. remove: function RefSet_remove(ref) {
  9098. delete this.dict[ref.toString()];
  9099. }
  9100. };
  9101. return RefSet;
  9102. })();
  9103. var RefSetCache = (function RefSetCacheClosure() {
  9104. function RefSetCache() {
  9105. this.dict = Object.create(null);
  9106. }
  9107. RefSetCache.prototype = {
  9108. get: function RefSetCache_get(ref) {
  9109. return this.dict[ref.toString()];
  9110. },
  9111. has: function RefSetCache_has(ref) {
  9112. return ref.toString() in this.dict;
  9113. },
  9114. put: function RefSetCache_put(ref, obj) {
  9115. this.dict[ref.toString()] = obj;
  9116. },
  9117. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  9118. this.dict[ref.toString()] = this.get(aliasRef);
  9119. },
  9120. forEach: function RefSetCache_forEach(fn, thisArg) {
  9121. for (var i in this.dict) {
  9122. fn.call(thisArg, this.dict[i]);
  9123. }
  9124. },
  9125. clear: function RefSetCache_clear() {
  9126. this.dict = Object.create(null);
  9127. }
  9128. };
  9129. return RefSetCache;
  9130. })();
  9131. var Catalog = (function CatalogClosure() {
  9132. function Catalog(pdfManager, xref) {
  9133. this.pdfManager = pdfManager;
  9134. this.xref = xref;
  9135. this.catDict = xref.getCatalogObj();
  9136. this.fontCache = new RefSetCache();
  9137. assert(isDict(this.catDict),
  9138. 'catalog object is not a dictionary');
  9139. this.pagePromises = [];
  9140. }
  9141. Catalog.prototype = {
  9142. get metadata() {
  9143. var streamRef = this.catDict.getRaw('Metadata');
  9144. if (!isRef(streamRef)) {
  9145. return shadow(this, 'metadata', null);
  9146. }
  9147. var encryptMetadata = (!this.xref.encrypt ? false :
  9148. this.xref.encrypt.encryptMetadata);
  9149. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  9150. var metadata;
  9151. if (stream && isDict(stream.dict)) {
  9152. var type = stream.dict.get('Type');
  9153. var subtype = stream.dict.get('Subtype');
  9154. if (isName(type) && isName(subtype) &&
  9155. type.name === 'Metadata' && subtype.name === 'XML') {
  9156. // XXX: This should examine the charset the XML document defines,
  9157. // however since there are currently no real means to decode
  9158. // arbitrary charsets, let's just hope that the author of the PDF
  9159. // was reasonable enough to stick with the XML default charset,
  9160. // which is UTF-8.
  9161. try {
  9162. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  9163. } catch (e) {
  9164. info('Skipping invalid metadata.');
  9165. }
  9166. }
  9167. }
  9168. return shadow(this, 'metadata', metadata);
  9169. },
  9170. get toplevelPagesDict() {
  9171. var pagesObj = this.catDict.get('Pages');
  9172. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  9173. // shadow the prototype getter
  9174. return shadow(this, 'toplevelPagesDict', pagesObj);
  9175. },
  9176. get documentOutline() {
  9177. var obj = null;
  9178. try {
  9179. obj = this.readDocumentOutline();
  9180. } catch (ex) {
  9181. if (ex instanceof MissingDataException) {
  9182. throw ex;
  9183. }
  9184. warn('Unable to read document outline');
  9185. }
  9186. return shadow(this, 'documentOutline', obj);
  9187. },
  9188. readDocumentOutline: function Catalog_readDocumentOutline() {
  9189. var xref = this.xref;
  9190. var obj = this.catDict.get('Outlines');
  9191. var root = { items: [] };
  9192. if (isDict(obj)) {
  9193. obj = obj.getRaw('First');
  9194. var processed = new RefSet();
  9195. if (isRef(obj)) {
  9196. var queue = [{obj: obj, parent: root}];
  9197. // to avoid recursion keeping track of the items
  9198. // in the processed dictionary
  9199. processed.put(obj);
  9200. while (queue.length > 0) {
  9201. var i = queue.shift();
  9202. var outlineDict = xref.fetchIfRef(i.obj);
  9203. if (outlineDict === null) {
  9204. continue;
  9205. }
  9206. if (!outlineDict.has('Title')) {
  9207. error('Invalid outline item');
  9208. }
  9209. var dest = outlineDict.get('A');
  9210. if (dest) {
  9211. dest = dest.get('D');
  9212. } else if (outlineDict.has('Dest')) {
  9213. dest = outlineDict.getRaw('Dest');
  9214. if (isName(dest)) {
  9215. dest = dest.name;
  9216. }
  9217. }
  9218. var title = outlineDict.get('Title');
  9219. var outlineItem = {
  9220. dest: dest,
  9221. title: stringToPDFString(title),
  9222. color: outlineDict.get('C') || [0, 0, 0],
  9223. count: outlineDict.get('Count'),
  9224. bold: !!(outlineDict.get('F') & 2),
  9225. italic: !!(outlineDict.get('F') & 1),
  9226. items: []
  9227. };
  9228. i.parent.items.push(outlineItem);
  9229. obj = outlineDict.getRaw('First');
  9230. if (isRef(obj) && !processed.has(obj)) {
  9231. queue.push({obj: obj, parent: outlineItem});
  9232. processed.put(obj);
  9233. }
  9234. obj = outlineDict.getRaw('Next');
  9235. if (isRef(obj) && !processed.has(obj)) {
  9236. queue.push({obj: obj, parent: i.parent});
  9237. processed.put(obj);
  9238. }
  9239. }
  9240. }
  9241. }
  9242. return (root.items.length > 0 ? root.items : null);
  9243. },
  9244. get numPages() {
  9245. var obj = this.toplevelPagesDict.get('Count');
  9246. assert(
  9247. isInt(obj),
  9248. 'page count in top level pages object is not an integer'
  9249. );
  9250. // shadow the prototype getter
  9251. return shadow(this, 'num', obj);
  9252. },
  9253. get destinations() {
  9254. function fetchDestination(dest) {
  9255. return isDict(dest) ? dest.get('D') : dest;
  9256. }
  9257. var xref = this.xref;
  9258. var dests = {}, nameTreeRef, nameDictionaryRef;
  9259. var obj = this.catDict.get('Names');
  9260. if (obj && obj.has('Dests')) {
  9261. nameTreeRef = obj.getRaw('Dests');
  9262. } else if (this.catDict.has('Dests')) {
  9263. nameDictionaryRef = this.catDict.get('Dests');
  9264. }
  9265. if (nameDictionaryRef) {
  9266. // reading simple destination dictionary
  9267. obj = nameDictionaryRef;
  9268. obj.forEach(function catalogForEach(key, value) {
  9269. if (!value) {
  9270. return;
  9271. }
  9272. dests[key] = fetchDestination(value);
  9273. });
  9274. }
  9275. if (nameTreeRef) {
  9276. var nameTree = new NameTree(nameTreeRef, xref);
  9277. var names = nameTree.getAll();
  9278. for (var name in names) {
  9279. if (!names.hasOwnProperty(name)) {
  9280. continue;
  9281. }
  9282. dests[name] = fetchDestination(names[name]);
  9283. }
  9284. }
  9285. return shadow(this, 'destinations', dests);
  9286. },
  9287. getDestination: function Catalog_getDestination(destinationId) {
  9288. function fetchDestination(dest) {
  9289. return isDict(dest) ? dest.get('D') : dest;
  9290. }
  9291. var xref = this.xref;
  9292. var dest = null, nameTreeRef, nameDictionaryRef;
  9293. var obj = this.catDict.get('Names');
  9294. if (obj && obj.has('Dests')) {
  9295. nameTreeRef = obj.getRaw('Dests');
  9296. } else if (this.catDict.has('Dests')) {
  9297. nameDictionaryRef = this.catDict.get('Dests');
  9298. }
  9299. if (nameDictionaryRef) { // Simple destination dictionary.
  9300. var value = nameDictionaryRef.get(destinationId);
  9301. if (value) {
  9302. dest = fetchDestination(value);
  9303. }
  9304. }
  9305. if (nameTreeRef) {
  9306. var nameTree = new NameTree(nameTreeRef, xref);
  9307. dest = fetchDestination(nameTree.get(destinationId));
  9308. }
  9309. return dest;
  9310. },
  9311. get attachments() {
  9312. var xref = this.xref;
  9313. var attachments = null, nameTreeRef;
  9314. var obj = this.catDict.get('Names');
  9315. if (obj) {
  9316. nameTreeRef = obj.getRaw('EmbeddedFiles');
  9317. }
  9318. if (nameTreeRef) {
  9319. var nameTree = new NameTree(nameTreeRef, xref);
  9320. var names = nameTree.getAll();
  9321. for (var name in names) {
  9322. if (!names.hasOwnProperty(name)) {
  9323. continue;
  9324. }
  9325. var fs = new FileSpec(names[name], xref);
  9326. if (!attachments) {
  9327. attachments = {};
  9328. }
  9329. attachments[stringToPDFString(name)] = fs.serializable;
  9330. }
  9331. }
  9332. return shadow(this, 'attachments', attachments);
  9333. },
  9334. get javaScript() {
  9335. var xref = this.xref;
  9336. var obj = this.catDict.get('Names');
  9337. var javaScript = [];
  9338. function appendIfJavaScriptDict(jsDict) {
  9339. var type = jsDict.get('S');
  9340. if (!isName(type) || type.name !== 'JavaScript') {
  9341. return;
  9342. }
  9343. var js = jsDict.get('JS');
  9344. if (isStream(js)) {
  9345. js = bytesToString(js.getBytes());
  9346. } else if (!isString(js)) {
  9347. return;
  9348. }
  9349. javaScript.push(stringToPDFString(js));
  9350. }
  9351. if (obj && obj.has('JavaScript')) {
  9352. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  9353. var names = nameTree.getAll();
  9354. for (var name in names) {
  9355. if (!names.hasOwnProperty(name)) {
  9356. continue;
  9357. }
  9358. // We don't really use the JavaScript right now. This code is
  9359. // defensive so we don't cause errors on document load.
  9360. var jsDict = names[name];
  9361. if (isDict(jsDict)) {
  9362. appendIfJavaScriptDict(jsDict);
  9363. }
  9364. }
  9365. }
  9366. // Append OpenAction actions to javaScript array
  9367. var openactionDict = this.catDict.get('OpenAction');
  9368. if (isDict(openactionDict, 'Action')) {
  9369. var actionType = openactionDict.get('S');
  9370. if (isName(actionType) && actionType.name === 'Named') {
  9371. // The named Print action is not a part of the PDF 1.7 specification,
  9372. // but is supported by many PDF readers/writers (including Adobe's).
  9373. var action = openactionDict.get('N');
  9374. if (isName(action) && action.name === 'Print') {
  9375. javaScript.push('print({});');
  9376. }
  9377. } else {
  9378. appendIfJavaScriptDict(openactionDict);
  9379. }
  9380. }
  9381. return shadow(this, 'javaScript', javaScript);
  9382. },
  9383. cleanup: function Catalog_cleanup() {
  9384. var promises = [];
  9385. this.fontCache.forEach(function (promise) {
  9386. promises.push(promise);
  9387. });
  9388. return Promise.all(promises).then(function (translatedFonts) {
  9389. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  9390. var font = translatedFonts[i].dict;
  9391. delete font.translated;
  9392. }
  9393. this.fontCache.clear();
  9394. }.bind(this));
  9395. },
  9396. getPage: function Catalog_getPage(pageIndex) {
  9397. if (!(pageIndex in this.pagePromises)) {
  9398. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  9399. function (a) {
  9400. var dict = a[0];
  9401. var ref = a[1];
  9402. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  9403. this.fontCache);
  9404. }.bind(this)
  9405. );
  9406. }
  9407. return this.pagePromises[pageIndex];
  9408. },
  9409. getPageDict: function Catalog_getPageDict(pageIndex) {
  9410. var capability = createPromiseCapability();
  9411. var nodesToVisit = [this.catDict.getRaw('Pages')];
  9412. var currentPageIndex = 0;
  9413. var xref = this.xref;
  9414. var checkAllKids = false;
  9415. function next() {
  9416. while (nodesToVisit.length) {
  9417. var currentNode = nodesToVisit.pop();
  9418. if (isRef(currentNode)) {
  9419. xref.fetchAsync(currentNode).then(function (obj) {
  9420. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  9421. if (pageIndex === currentPageIndex) {
  9422. capability.resolve([obj, currentNode]);
  9423. } else {
  9424. currentPageIndex++;
  9425. next();
  9426. }
  9427. return;
  9428. }
  9429. nodesToVisit.push(obj);
  9430. next();
  9431. }, capability.reject);
  9432. return;
  9433. }
  9434. // Must be a child page dictionary.
  9435. assert(
  9436. isDict(currentNode),
  9437. 'page dictionary kid reference points to wrong type of object'
  9438. );
  9439. var count = currentNode.get('Count');
  9440. // If the current node doesn't have any children, avoid getting stuck
  9441. // in an empty node further down in the tree (see issue5644.pdf).
  9442. if (count === 0) {
  9443. checkAllKids = true;
  9444. }
  9445. // Skip nodes where the page can't be.
  9446. if (currentPageIndex + count <= pageIndex) {
  9447. currentPageIndex += count;
  9448. continue;
  9449. }
  9450. var kids = currentNode.get('Kids');
  9451. assert(isArray(kids), 'page dictionary kids object is not an array');
  9452. if (!checkAllKids && count === kids.length) {
  9453. // Nodes that don't have the page have been skipped and this is the
  9454. // bottom of the tree which means the page requested must be a
  9455. // descendant of this pages node. Ideally we would just resolve the
  9456. // promise with the page ref here, but there is the case where more
  9457. // pages nodes could link to single a page (see issue 3666 pdf). To
  9458. // handle this push it back on the queue so if it is a pages node it
  9459. // will be descended into.
  9460. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  9461. currentPageIndex = pageIndex;
  9462. continue;
  9463. } else {
  9464. for (var last = kids.length - 1; last >= 0; last--) {
  9465. nodesToVisit.push(kids[last]);
  9466. }
  9467. }
  9468. }
  9469. capability.reject('Page index ' + pageIndex + ' not found.');
  9470. }
  9471. next();
  9472. return capability.promise;
  9473. },
  9474. getPageIndex: function Catalog_getPageIndex(ref) {
  9475. // The page tree nodes have the count of all the leaves below them. To get
  9476. // how many pages are before we just have to walk up the tree and keep
  9477. // adding the count of siblings to the left of the node.
  9478. var xref = this.xref;
  9479. function pagesBeforeRef(kidRef) {
  9480. var total = 0;
  9481. var parentRef;
  9482. return xref.fetchAsync(kidRef).then(function (node) {
  9483. if (!node) {
  9484. return null;
  9485. }
  9486. parentRef = node.getRaw('Parent');
  9487. return node.getAsync('Parent');
  9488. }).then(function (parent) {
  9489. if (!parent) {
  9490. return null;
  9491. }
  9492. return parent.getAsync('Kids');
  9493. }).then(function (kids) {
  9494. if (!kids) {
  9495. return null;
  9496. }
  9497. var kidPromises = [];
  9498. var found = false;
  9499. for (var i = 0; i < kids.length; i++) {
  9500. var kid = kids[i];
  9501. assert(isRef(kid), 'kids must be a ref');
  9502. if (kid.num === kidRef.num) {
  9503. found = true;
  9504. break;
  9505. }
  9506. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  9507. if (kid.has('Count')) {
  9508. var count = kid.get('Count');
  9509. total += count;
  9510. } else { // page leaf node
  9511. total++;
  9512. }
  9513. }));
  9514. }
  9515. if (!found) {
  9516. error('kid ref not found in parents kids');
  9517. }
  9518. return Promise.all(kidPromises).then(function () {
  9519. return [total, parentRef];
  9520. });
  9521. });
  9522. }
  9523. var total = 0;
  9524. function next(ref) {
  9525. return pagesBeforeRef(ref).then(function (args) {
  9526. if (!args) {
  9527. return total;
  9528. }
  9529. var count = args[0];
  9530. var parentRef = args[1];
  9531. total += count;
  9532. return next(parentRef);
  9533. });
  9534. }
  9535. return next(ref);
  9536. }
  9537. };
  9538. return Catalog;
  9539. })();
  9540. var XRef = (function XRefClosure() {
  9541. function XRef(stream, password) {
  9542. this.stream = stream;
  9543. this.entries = [];
  9544. this.xrefstms = {};
  9545. // prepare the XRef cache
  9546. this.cache = [];
  9547. this.password = password;
  9548. this.stats = {
  9549. streamTypes: [],
  9550. fontTypes: []
  9551. };
  9552. }
  9553. XRef.prototype = {
  9554. setStartXRef: function XRef_setStartXRef(startXRef) {
  9555. // Store the starting positions of xref tables as we process them
  9556. // so we can recover from missing data errors
  9557. this.startXRefQueue = [startXRef];
  9558. },
  9559. parse: function XRef_parse(recoveryMode) {
  9560. var trailerDict;
  9561. if (!recoveryMode) {
  9562. trailerDict = this.readXRef();
  9563. } else {
  9564. warn('Indexing all PDF objects');
  9565. trailerDict = this.indexObjects();
  9566. }
  9567. trailerDict.assignXref(this);
  9568. this.trailer = trailerDict;
  9569. var encrypt = trailerDict.get('Encrypt');
  9570. if (encrypt) {
  9571. var ids = trailerDict.get('ID');
  9572. var fileId = (ids && ids.length) ? ids[0] : '';
  9573. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  9574. this.password);
  9575. }
  9576. // get the root dictionary (catalog) object
  9577. if (!(this.root = trailerDict.get('Root'))) {
  9578. error('Invalid root reference');
  9579. }
  9580. },
  9581. processXRefTable: function XRef_processXRefTable(parser) {
  9582. if (!('tableState' in this)) {
  9583. // Stores state of the table as we process it so we can resume
  9584. // from middle of table in case of missing data error
  9585. this.tableState = {
  9586. entryNum: 0,
  9587. streamPos: parser.lexer.stream.pos,
  9588. parserBuf1: parser.buf1,
  9589. parserBuf2: parser.buf2
  9590. };
  9591. }
  9592. var obj = this.readXRefTable(parser);
  9593. // Sanity check
  9594. if (!isCmd(obj, 'trailer')) {
  9595. error('Invalid XRef table: could not find trailer dictionary');
  9596. }
  9597. // Read trailer dictionary, e.g.
  9598. // trailer
  9599. // << /Size 22
  9600. // /Root 20R
  9601. // /Info 10R
  9602. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  9603. // >>
  9604. // The parser goes through the entire stream << ... >> and provides
  9605. // a getter interface for the key-value table
  9606. var dict = parser.getObj();
  9607. // The pdflib PDF generator can generate a nested trailer dictionary
  9608. if (!isDict(dict) && dict.dict) {
  9609. dict = dict.dict;
  9610. }
  9611. if (!isDict(dict)) {
  9612. error('Invalid XRef table: could not parse trailer dictionary');
  9613. }
  9614. delete this.tableState;
  9615. return dict;
  9616. },
  9617. readXRefTable: function XRef_readXRefTable(parser) {
  9618. // Example of cross-reference table:
  9619. // xref
  9620. // 0 1 <-- subsection header (first obj #, obj count)
  9621. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  9622. // 23 2 <-- subsection header ... and so on ...
  9623. // 0000025518 00002 n
  9624. // 0000025635 00000 n
  9625. // trailer
  9626. // ...
  9627. var stream = parser.lexer.stream;
  9628. var tableState = this.tableState;
  9629. stream.pos = tableState.streamPos;
  9630. parser.buf1 = tableState.parserBuf1;
  9631. parser.buf2 = tableState.parserBuf2;
  9632. // Outer loop is over subsection headers
  9633. var obj;
  9634. while (true) {
  9635. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  9636. if (isCmd(obj = parser.getObj(), 'trailer')) {
  9637. break;
  9638. }
  9639. tableState.firstEntryNum = obj;
  9640. tableState.entryCount = parser.getObj();
  9641. }
  9642. var first = tableState.firstEntryNum;
  9643. var count = tableState.entryCount;
  9644. if (!isInt(first) || !isInt(count)) {
  9645. error('Invalid XRef table: wrong types in subsection header');
  9646. }
  9647. // Inner loop is over objects themselves
  9648. for (var i = tableState.entryNum; i < count; i++) {
  9649. tableState.streamPos = stream.pos;
  9650. tableState.entryNum = i;
  9651. tableState.parserBuf1 = parser.buf1;
  9652. tableState.parserBuf2 = parser.buf2;
  9653. var entry = {};
  9654. entry.offset = parser.getObj();
  9655. entry.gen = parser.getObj();
  9656. var type = parser.getObj();
  9657. if (isCmd(type, 'f')) {
  9658. entry.free = true;
  9659. } else if (isCmd(type, 'n')) {
  9660. entry.uncompressed = true;
  9661. }
  9662. // Validate entry obj
  9663. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  9664. !(entry.free || entry.uncompressed)) {
  9665. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  9666. }
  9667. if (!this.entries[i + first]) {
  9668. this.entries[i + first] = entry;
  9669. }
  9670. }
  9671. tableState.entryNum = 0;
  9672. tableState.streamPos = stream.pos;
  9673. tableState.parserBuf1 = parser.buf1;
  9674. tableState.parserBuf2 = parser.buf2;
  9675. delete tableState.firstEntryNum;
  9676. delete tableState.entryCount;
  9677. }
  9678. // Per issue 3248: hp scanners generate bad XRef
  9679. if (first === 1 && this.entries[1] && this.entries[1].free) {
  9680. // shifting the entries
  9681. this.entries.shift();
  9682. }
  9683. // Sanity check: as per spec, first object must be free
  9684. if (this.entries[0] && !this.entries[0].free) {
  9685. error('Invalid XRef table: unexpected first object');
  9686. }
  9687. return obj;
  9688. },
  9689. processXRefStream: function XRef_processXRefStream(stream) {
  9690. if (!('streamState' in this)) {
  9691. // Stores state of the stream as we process it so we can resume
  9692. // from middle of stream in case of missing data error
  9693. var streamParameters = stream.dict;
  9694. var byteWidths = streamParameters.get('W');
  9695. var range = streamParameters.get('Index');
  9696. if (!range) {
  9697. range = [0, streamParameters.get('Size')];
  9698. }
  9699. this.streamState = {
  9700. entryRanges: range,
  9701. byteWidths: byteWidths,
  9702. entryNum: 0,
  9703. streamPos: stream.pos
  9704. };
  9705. }
  9706. this.readXRefStream(stream);
  9707. delete this.streamState;
  9708. return stream.dict;
  9709. },
  9710. readXRefStream: function XRef_readXRefStream(stream) {
  9711. var i, j;
  9712. var streamState = this.streamState;
  9713. stream.pos = streamState.streamPos;
  9714. var byteWidths = streamState.byteWidths;
  9715. var typeFieldWidth = byteWidths[0];
  9716. var offsetFieldWidth = byteWidths[1];
  9717. var generationFieldWidth = byteWidths[2];
  9718. var entryRanges = streamState.entryRanges;
  9719. while (entryRanges.length > 0) {
  9720. var first = entryRanges[0];
  9721. var n = entryRanges[1];
  9722. if (!isInt(first) || !isInt(n)) {
  9723. error('Invalid XRef range fields: ' + first + ', ' + n);
  9724. }
  9725. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  9726. !isInt(generationFieldWidth)) {
  9727. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  9728. }
  9729. for (i = streamState.entryNum; i < n; ++i) {
  9730. streamState.entryNum = i;
  9731. streamState.streamPos = stream.pos;
  9732. var type = 0, offset = 0, generation = 0;
  9733. for (j = 0; j < typeFieldWidth; ++j) {
  9734. type = (type << 8) | stream.getByte();
  9735. }
  9736. // if type field is absent, its default value is 1
  9737. if (typeFieldWidth === 0) {
  9738. type = 1;
  9739. }
  9740. for (j = 0; j < offsetFieldWidth; ++j) {
  9741. offset = (offset << 8) | stream.getByte();
  9742. }
  9743. for (j = 0; j < generationFieldWidth; ++j) {
  9744. generation = (generation << 8) | stream.getByte();
  9745. }
  9746. var entry = {};
  9747. entry.offset = offset;
  9748. entry.gen = generation;
  9749. switch (type) {
  9750. case 0:
  9751. entry.free = true;
  9752. break;
  9753. case 1:
  9754. entry.uncompressed = true;
  9755. break;
  9756. case 2:
  9757. break;
  9758. default:
  9759. error('Invalid XRef entry type: ' + type);
  9760. }
  9761. if (!this.entries[first + i]) {
  9762. this.entries[first + i] = entry;
  9763. }
  9764. }
  9765. streamState.entryNum = 0;
  9766. streamState.streamPos = stream.pos;
  9767. entryRanges.splice(0, 2);
  9768. }
  9769. },
  9770. indexObjects: function XRef_indexObjects() {
  9771. // Simple scan through the PDF content to find objects,
  9772. // trailers and XRef streams.
  9773. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  9774. var PERCENT = 0x25, LT = 0x3C;
  9775. function readToken(data, offset) {
  9776. var token = '', ch = data[offset];
  9777. while (ch !== LF && ch !== CR && ch !== LT) {
  9778. if (++offset >= data.length) {
  9779. break;
  9780. }
  9781. token += String.fromCharCode(ch);
  9782. ch = data[offset];
  9783. }
  9784. return token;
  9785. }
  9786. function skipUntil(data, offset, what) {
  9787. var length = what.length, dataLength = data.length;
  9788. var skipped = 0;
  9789. // finding byte sequence
  9790. while (offset < dataLength) {
  9791. var i = 0;
  9792. while (i < length && data[offset + i] === what[i]) {
  9793. ++i;
  9794. }
  9795. if (i >= length) {
  9796. break; // sequence found
  9797. }
  9798. offset++;
  9799. skipped++;
  9800. }
  9801. return skipped;
  9802. }
  9803. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  9804. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  9805. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  9806. 101, 102]);
  9807. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  9808. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  9809. // Clear out any existing entries, since they may be bogus.
  9810. this.entries.length = 0;
  9811. var stream = this.stream;
  9812. stream.pos = 0;
  9813. var buffer = stream.getBytes();
  9814. var position = stream.start, length = buffer.length;
  9815. var trailers = [], xrefStms = [];
  9816. while (position < length) {
  9817. var ch = buffer[position];
  9818. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  9819. ++position;
  9820. continue;
  9821. }
  9822. if (ch === PERCENT) { // %-comment
  9823. do {
  9824. ++position;
  9825. if (position >= length) {
  9826. break;
  9827. }
  9828. ch = buffer[position];
  9829. } while (ch !== LF && ch !== CR);
  9830. continue;
  9831. }
  9832. var token = readToken(buffer, position);
  9833. var m;
  9834. if (token.indexOf('xref') === 0 &&
  9835. (token.length === 4 || /\s/.test(token[4]))) {
  9836. position += skipUntil(buffer, position, trailerBytes);
  9837. trailers.push(position);
  9838. position += skipUntil(buffer, position, startxrefBytes);
  9839. } else if ((m = objRegExp.exec(token))) {
  9840. if (typeof this.entries[m[1]] === 'undefined') {
  9841. this.entries[m[1]] = {
  9842. offset: position - stream.start,
  9843. gen: m[2] | 0,
  9844. uncompressed: true
  9845. };
  9846. }
  9847. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  9848. var content = buffer.subarray(position, position + contentLength);
  9849. // checking XRef stream suspect
  9850. // (it shall have '/XRef' and next char is not a letter)
  9851. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  9852. if (xrefTagOffset < contentLength &&
  9853. content[xrefTagOffset + 5] < 64) {
  9854. xrefStms.push(position - stream.start);
  9855. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  9856. }
  9857. position += contentLength;
  9858. } else if (token.indexOf('trailer') === 0 &&
  9859. (token.length === 7 || /\s/.test(token[7]))) {
  9860. trailers.push(position);
  9861. position += skipUntil(buffer, position, startxrefBytes);
  9862. } else {
  9863. position += token.length + 1;
  9864. }
  9865. }
  9866. // reading XRef streams
  9867. var i, ii;
  9868. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  9869. this.startXRefQueue.push(xrefStms[i]);
  9870. this.readXRef(/* recoveryMode */ true);
  9871. }
  9872. // finding main trailer
  9873. var dict;
  9874. for (i = 0, ii = trailers.length; i < ii; ++i) {
  9875. stream.pos = trailers[i];
  9876. var parser = new Parser(new Lexer(stream), true, this);
  9877. var obj = parser.getObj();
  9878. if (!isCmd(obj, 'trailer')) {
  9879. continue;
  9880. }
  9881. // read the trailer dictionary
  9882. if (!isDict(dict = parser.getObj())) {
  9883. continue;
  9884. }
  9885. // taking the first one with 'ID'
  9886. if (dict.has('ID')) {
  9887. return dict;
  9888. }
  9889. }
  9890. // no tailer with 'ID', taking last one (if exists)
  9891. if (dict) {
  9892. return dict;
  9893. }
  9894. // nothing helps
  9895. // calling error() would reject worker with an UnknownErrorException.
  9896. throw new InvalidPDFException('Invalid PDF structure');
  9897. },
  9898. readXRef: function XRef_readXRef(recoveryMode) {
  9899. var stream = this.stream;
  9900. try {
  9901. while (this.startXRefQueue.length) {
  9902. var startXRef = this.startXRefQueue[0];
  9903. stream.pos = startXRef + stream.start;
  9904. var parser = new Parser(new Lexer(stream), true, this);
  9905. var obj = parser.getObj();
  9906. var dict;
  9907. // Get dictionary
  9908. if (isCmd(obj, 'xref')) {
  9909. // Parse end-of-file XRef
  9910. dict = this.processXRefTable(parser);
  9911. if (!this.topDict) {
  9912. this.topDict = dict;
  9913. }
  9914. // Recursively get other XRefs 'XRefStm', if any
  9915. obj = dict.get('XRefStm');
  9916. if (isInt(obj)) {
  9917. var pos = obj;
  9918. // ignore previously loaded xref streams
  9919. // (possible infinite recursion)
  9920. if (!(pos in this.xrefstms)) {
  9921. this.xrefstms[pos] = 1;
  9922. this.startXRefQueue.push(pos);
  9923. }
  9924. }
  9925. } else if (isInt(obj)) {
  9926. // Parse in-stream XRef
  9927. if (!isInt(parser.getObj()) ||
  9928. !isCmd(parser.getObj(), 'obj') ||
  9929. !isStream(obj = parser.getObj())) {
  9930. error('Invalid XRef stream');
  9931. }
  9932. dict = this.processXRefStream(obj);
  9933. if (!this.topDict) {
  9934. this.topDict = dict;
  9935. }
  9936. if (!dict) {
  9937. error('Failed to read XRef stream');
  9938. }
  9939. } else {
  9940. error('Invalid XRef stream header');
  9941. }
  9942. // Recursively get previous dictionary, if any
  9943. obj = dict.get('Prev');
  9944. if (isInt(obj)) {
  9945. this.startXRefQueue.push(obj);
  9946. } else if (isRef(obj)) {
  9947. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  9948. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  9949. this.startXRefQueue.push(obj.num);
  9950. }
  9951. this.startXRefQueue.shift();
  9952. }
  9953. return this.topDict;
  9954. } catch (e) {
  9955. if (e instanceof MissingDataException) {
  9956. throw e;
  9957. }
  9958. info('(while reading XRef): ' + e);
  9959. }
  9960. if (recoveryMode) {
  9961. return;
  9962. }
  9963. throw new XRefParseException();
  9964. },
  9965. getEntry: function XRef_getEntry(i) {
  9966. var xrefEntry = this.entries[i];
  9967. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  9968. return xrefEntry;
  9969. }
  9970. return null;
  9971. },
  9972. fetchIfRef: function XRef_fetchIfRef(obj) {
  9973. if (!isRef(obj)) {
  9974. return obj;
  9975. }
  9976. return this.fetch(obj);
  9977. },
  9978. fetch: function XRef_fetch(ref, suppressEncryption) {
  9979. assert(isRef(ref), 'ref object is not a reference');
  9980. var num = ref.num;
  9981. if (num in this.cache) {
  9982. var cacheEntry = this.cache[num];
  9983. return cacheEntry;
  9984. }
  9985. var xrefEntry = this.getEntry(num);
  9986. // the referenced entry can be free
  9987. if (xrefEntry === null) {
  9988. return (this.cache[num] = null);
  9989. }
  9990. if (xrefEntry.uncompressed) {
  9991. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  9992. } else {
  9993. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  9994. }
  9995. if (isDict(xrefEntry)){
  9996. xrefEntry.objId = ref.toString();
  9997. } else if (isStream(xrefEntry)) {
  9998. xrefEntry.dict.objId = ref.toString();
  9999. }
  10000. return xrefEntry;
  10001. },
  10002. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  10003. suppressEncryption) {
  10004. var gen = ref.gen;
  10005. var num = ref.num;
  10006. if (xrefEntry.gen !== gen) {
  10007. error('inconsistent generation in XRef');
  10008. }
  10009. var stream = this.stream.makeSubStream(xrefEntry.offset +
  10010. this.stream.start);
  10011. var parser = new Parser(new Lexer(stream), true, this);
  10012. var obj1 = parser.getObj();
  10013. var obj2 = parser.getObj();
  10014. var obj3 = parser.getObj();
  10015. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  10016. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  10017. !isCmd(obj3)) {
  10018. error('bad XRef entry');
  10019. }
  10020. if (!isCmd(obj3, 'obj')) {
  10021. // some bad PDFs use "obj1234" and really mean 1234
  10022. if (obj3.cmd.indexOf('obj') === 0) {
  10023. num = parseInt(obj3.cmd.substring(3), 10);
  10024. if (!isNaN(num)) {
  10025. return num;
  10026. }
  10027. }
  10028. error('bad XRef entry');
  10029. }
  10030. if (this.encrypt && !suppressEncryption) {
  10031. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  10032. } else {
  10033. xrefEntry = parser.getObj();
  10034. }
  10035. if (!isStream(xrefEntry)) {
  10036. this.cache[num] = xrefEntry;
  10037. }
  10038. return xrefEntry;
  10039. },
  10040. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  10041. suppressEncryption) {
  10042. var tableOffset = xrefEntry.offset;
  10043. var stream = this.fetch(new Ref(tableOffset, 0));
  10044. if (!isStream(stream)) {
  10045. error('bad ObjStm stream');
  10046. }
  10047. var first = stream.dict.get('First');
  10048. var n = stream.dict.get('N');
  10049. if (!isInt(first) || !isInt(n)) {
  10050. error('invalid first and n parameters for ObjStm stream');
  10051. }
  10052. var parser = new Parser(new Lexer(stream), false, this);
  10053. parser.allowStreams = true;
  10054. var i, entries = [], num, nums = [];
  10055. // read the object numbers to populate cache
  10056. for (i = 0; i < n; ++i) {
  10057. num = parser.getObj();
  10058. if (!isInt(num)) {
  10059. error('invalid object number in the ObjStm stream: ' + num);
  10060. }
  10061. nums.push(num);
  10062. var offset = parser.getObj();
  10063. if (!isInt(offset)) {
  10064. error('invalid object offset in the ObjStm stream: ' + offset);
  10065. }
  10066. }
  10067. // read stream objects for cache
  10068. for (i = 0; i < n; ++i) {
  10069. entries.push(parser.getObj());
  10070. num = nums[i];
  10071. var entry = this.entries[num];
  10072. if (entry && entry.offset === tableOffset && entry.gen === i) {
  10073. this.cache[num] = entries[i];
  10074. }
  10075. }
  10076. xrefEntry = entries[xrefEntry.gen];
  10077. if (xrefEntry === undefined) {
  10078. error('bad XRef entry for compressed object');
  10079. }
  10080. return xrefEntry;
  10081. },
  10082. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  10083. if (!isRef(obj)) {
  10084. return Promise.resolve(obj);
  10085. }
  10086. return this.fetchAsync(obj);
  10087. },
  10088. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  10089. var streamManager = this.stream.manager;
  10090. var xref = this;
  10091. return new Promise(function tryFetch(resolve, reject) {
  10092. try {
  10093. resolve(xref.fetch(ref, suppressEncryption));
  10094. } catch (e) {
  10095. if (e instanceof MissingDataException) {
  10096. streamManager.requestRange(e.begin, e.end).then(function () {
  10097. tryFetch(resolve, reject);
  10098. }, reject);
  10099. return;
  10100. }
  10101. reject(e);
  10102. }
  10103. });
  10104. },
  10105. getCatalogObj: function XRef_getCatalogObj() {
  10106. return this.root;
  10107. }
  10108. };
  10109. return XRef;
  10110. })();
  10111. /**
  10112. * A NameTree is like a Dict but has some advantageous properties, see the
  10113. * spec (7.9.6) for more details.
  10114. * TODO: implement all the Dict functions and make this more efficent.
  10115. */
  10116. var NameTree = (function NameTreeClosure() {
  10117. function NameTree(root, xref) {
  10118. this.root = root;
  10119. this.xref = xref;
  10120. }
  10121. NameTree.prototype = {
  10122. getAll: function NameTree_getAll() {
  10123. var dict = {};
  10124. if (!this.root) {
  10125. return dict;
  10126. }
  10127. var xref = this.xref;
  10128. // reading name tree
  10129. var processed = new RefSet();
  10130. processed.put(this.root);
  10131. var queue = [this.root];
  10132. while (queue.length > 0) {
  10133. var i, n;
  10134. var obj = xref.fetchIfRef(queue.shift());
  10135. if (!isDict(obj)) {
  10136. continue;
  10137. }
  10138. if (obj.has('Kids')) {
  10139. var kids = obj.get('Kids');
  10140. for (i = 0, n = kids.length; i < n; i++) {
  10141. var kid = kids[i];
  10142. if (processed.has(kid)) {
  10143. error('invalid destinations');
  10144. }
  10145. queue.push(kid);
  10146. processed.put(kid);
  10147. }
  10148. continue;
  10149. }
  10150. var names = obj.get('Names');
  10151. if (names) {
  10152. for (i = 0, n = names.length; i < n; i += 2) {
  10153. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  10154. }
  10155. }
  10156. }
  10157. return dict;
  10158. },
  10159. get: function NameTree_get(destinationId) {
  10160. if (!this.root) {
  10161. return null;
  10162. }
  10163. var xref = this.xref;
  10164. var kidsOrNames = xref.fetchIfRef(this.root);
  10165. var loopCount = 0;
  10166. var MAX_NAMES_LEVELS = 10;
  10167. var l, r, m;
  10168. // Perform a binary search to quickly find the entry that
  10169. // contains the named destination we are looking for.
  10170. while (kidsOrNames.has('Kids')) {
  10171. loopCount++;
  10172. if (loopCount > MAX_NAMES_LEVELS) {
  10173. warn('Search depth limit for named destionations has been reached.');
  10174. return null;
  10175. }
  10176. var kids = kidsOrNames.get('Kids');
  10177. if (!isArray(kids)) {
  10178. return null;
  10179. }
  10180. l = 0;
  10181. r = kids.length - 1;
  10182. while (l <= r) {
  10183. m = (l + r) >> 1;
  10184. var kid = xref.fetchIfRef(kids[m]);
  10185. var limits = kid.get('Limits');
  10186. if (destinationId < xref.fetchIfRef(limits[0])) {
  10187. r = m - 1;
  10188. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  10189. l = m + 1;
  10190. } else {
  10191. kidsOrNames = xref.fetchIfRef(kids[m]);
  10192. break;
  10193. }
  10194. }
  10195. if (l > r) {
  10196. return null;
  10197. }
  10198. }
  10199. // If we get here, then we have found the right entry. Now
  10200. // go through the named destinations in the Named dictionary
  10201. // until we find the exact destination we're looking for.
  10202. var names = kidsOrNames.get('Names');
  10203. if (isArray(names)) {
  10204. // Perform a binary search to reduce the lookup time.
  10205. l = 0;
  10206. r = names.length - 2;
  10207. while (l <= r) {
  10208. // Check only even indices (0, 2, 4, ...) because the
  10209. // odd indices contain the actual D array.
  10210. m = (l + r) & ~1;
  10211. if (destinationId < xref.fetchIfRef(names[m])) {
  10212. r = m - 2;
  10213. } else if (destinationId > xref.fetchIfRef(names[m])) {
  10214. l = m + 2;
  10215. } else {
  10216. return xref.fetchIfRef(names[m + 1]);
  10217. }
  10218. }
  10219. }
  10220. return null;
  10221. }
  10222. };
  10223. return NameTree;
  10224. })();
  10225. /**
  10226. * "A PDF file can refer to the contents of another file by using a File
  10227. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  10228. * NOTE: Only embedded files are supported (as part of the attachments support)
  10229. * TODO: support the 'URL' file system (with caching if !/V), portable
  10230. * collections attributes and related files (/RF)
  10231. */
  10232. var FileSpec = (function FileSpecClosure() {
  10233. function FileSpec(root, xref) {
  10234. if (!root || !isDict(root)) {
  10235. return;
  10236. }
  10237. this.xref = xref;
  10238. this.root = root;
  10239. if (root.has('FS')) {
  10240. this.fs = root.get('FS');
  10241. }
  10242. this.description = root.has('Desc') ?
  10243. stringToPDFString(root.get('Desc')) :
  10244. '';
  10245. if (root.has('RF')) {
  10246. warn('Related file specifications are not supported');
  10247. }
  10248. this.contentAvailable = true;
  10249. if (!root.has('EF')) {
  10250. this.contentAvailable = false;
  10251. warn('Non-embedded file specifications are not supported');
  10252. }
  10253. }
  10254. function pickPlatformItem(dict) {
  10255. // Look for the filename in this order:
  10256. // UF, F, Unix, Mac, DOS
  10257. if (dict.has('UF')) {
  10258. return dict.get('UF');
  10259. } else if (dict.has('F')) {
  10260. return dict.get('F');
  10261. } else if (dict.has('Unix')) {
  10262. return dict.get('Unix');
  10263. } else if (dict.has('Mac')) {
  10264. return dict.get('Mac');
  10265. } else if (dict.has('DOS')) {
  10266. return dict.get('DOS');
  10267. } else {
  10268. return null;
  10269. }
  10270. }
  10271. FileSpec.prototype = {
  10272. get filename() {
  10273. if (!this._filename && this.root) {
  10274. var filename = pickPlatformItem(this.root) || 'unnamed';
  10275. this._filename = stringToPDFString(filename).
  10276. replace(/\\\\/g, '\\').
  10277. replace(/\\\//g, '/').
  10278. replace(/\\/g, '/');
  10279. }
  10280. return this._filename;
  10281. },
  10282. get content() {
  10283. if (!this.contentAvailable) {
  10284. return null;
  10285. }
  10286. if (!this.contentRef && this.root) {
  10287. this.contentRef = pickPlatformItem(this.root.get('EF'));
  10288. }
  10289. var content = null;
  10290. if (this.contentRef) {
  10291. var xref = this.xref;
  10292. var fileObj = xref.fetchIfRef(this.contentRef);
  10293. if (fileObj && isStream(fileObj)) {
  10294. content = fileObj.getBytes();
  10295. } else {
  10296. warn('Embedded file specification points to non-existing/invalid ' +
  10297. 'content');
  10298. }
  10299. } else {
  10300. warn('Embedded file specification does not have a content');
  10301. }
  10302. return content;
  10303. },
  10304. get serializable() {
  10305. return {
  10306. filename: this.filename,
  10307. content: this.content
  10308. };
  10309. }
  10310. };
  10311. return FileSpec;
  10312. })();
  10313. /**
  10314. * A helper for loading missing data in object graphs. It traverses the graph
  10315. * depth first and queues up any objects that have missing data. Once it has
  10316. * has traversed as many objects that are available it attempts to bundle the
  10317. * missing data requests and then resume from the nodes that weren't ready.
  10318. *
  10319. * NOTE: It provides protection from circular references by keeping track of
  10320. * of loaded references. However, you must be careful not to load any graphs
  10321. * that have references to the catalog or other pages since that will cause the
  10322. * entire PDF document object graph to be traversed.
  10323. */
  10324. var ObjectLoader = (function() {
  10325. function mayHaveChildren(value) {
  10326. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  10327. }
  10328. function addChildren(node, nodesToVisit) {
  10329. var value;
  10330. if (isDict(node) || isStream(node)) {
  10331. var map;
  10332. if (isDict(node)) {
  10333. map = node.map;
  10334. } else {
  10335. map = node.dict.map;
  10336. }
  10337. for (var key in map) {
  10338. value = map[key];
  10339. if (mayHaveChildren(value)) {
  10340. nodesToVisit.push(value);
  10341. }
  10342. }
  10343. } else if (isArray(node)) {
  10344. for (var i = 0, ii = node.length; i < ii; i++) {
  10345. value = node[i];
  10346. if (mayHaveChildren(value)) {
  10347. nodesToVisit.push(value);
  10348. }
  10349. }
  10350. }
  10351. }
  10352. function ObjectLoader(obj, keys, xref) {
  10353. this.obj = obj;
  10354. this.keys = keys;
  10355. this.xref = xref;
  10356. this.refSet = null;
  10357. this.capability = null;
  10358. }
  10359. ObjectLoader.prototype = {
  10360. load: function ObjectLoader_load() {
  10361. var keys = this.keys;
  10362. this.capability = createPromiseCapability();
  10363. // Don't walk the graph if all the data is already loaded.
  10364. if (!(this.xref.stream instanceof ChunkedStream) ||
  10365. this.xref.stream.getMissingChunks().length === 0) {
  10366. this.capability.resolve();
  10367. return this.capability.promise;
  10368. }
  10369. this.refSet = new RefSet();
  10370. // Setup the initial nodes to visit.
  10371. var nodesToVisit = [];
  10372. for (var i = 0; i < keys.length; i++) {
  10373. nodesToVisit.push(this.obj[keys[i]]);
  10374. }
  10375. this._walk(nodesToVisit);
  10376. return this.capability.promise;
  10377. },
  10378. _walk: function ObjectLoader_walk(nodesToVisit) {
  10379. var nodesToRevisit = [];
  10380. var pendingRequests = [];
  10381. // DFS walk of the object graph.
  10382. while (nodesToVisit.length) {
  10383. var currentNode = nodesToVisit.pop();
  10384. // Only references or chunked streams can cause missing data exceptions.
  10385. if (isRef(currentNode)) {
  10386. // Skip nodes that have already been visited.
  10387. if (this.refSet.has(currentNode)) {
  10388. continue;
  10389. }
  10390. try {
  10391. var ref = currentNode;
  10392. this.refSet.put(ref);
  10393. currentNode = this.xref.fetch(currentNode);
  10394. } catch (e) {
  10395. if (!(e instanceof MissingDataException)) {
  10396. throw e;
  10397. }
  10398. nodesToRevisit.push(currentNode);
  10399. pendingRequests.push({ begin: e.begin, end: e.end });
  10400. }
  10401. }
  10402. if (currentNode && currentNode.getBaseStreams) {
  10403. var baseStreams = currentNode.getBaseStreams();
  10404. var foundMissingData = false;
  10405. for (var i = 0; i < baseStreams.length; i++) {
  10406. var stream = baseStreams[i];
  10407. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  10408. foundMissingData = true;
  10409. pendingRequests.push({
  10410. begin: stream.start,
  10411. end: stream.end
  10412. });
  10413. }
  10414. }
  10415. if (foundMissingData) {
  10416. nodesToRevisit.push(currentNode);
  10417. }
  10418. }
  10419. addChildren(currentNode, nodesToVisit);
  10420. }
  10421. if (pendingRequests.length) {
  10422. this.xref.stream.manager.requestRanges(pendingRequests).then(
  10423. function pendingRequestCallback() {
  10424. nodesToVisit = nodesToRevisit;
  10425. for (var i = 0; i < nodesToRevisit.length; i++) {
  10426. var node = nodesToRevisit[i];
  10427. // Remove any reference nodes from the currrent refset so they
  10428. // aren't skipped when we revist them.
  10429. if (isRef(node)) {
  10430. this.refSet.remove(node);
  10431. }
  10432. }
  10433. this._walk(nodesToVisit);
  10434. }.bind(this), this.capability.reject);
  10435. return;
  10436. }
  10437. // Everything is loaded.
  10438. this.refSet = null;
  10439. this.capability.resolve();
  10440. }
  10441. };
  10442. return ObjectLoader;
  10443. })();
  10444. var ISOAdobeCharset = [
  10445. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  10446. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  10447. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  10448. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  10449. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  10450. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  10451. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  10452. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  10453. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  10454. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  10455. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  10456. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  10457. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  10458. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  10459. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  10460. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  10461. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  10462. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  10463. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  10464. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  10465. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  10466. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  10467. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  10468. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  10469. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  10470. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  10471. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  10472. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  10473. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  10474. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  10475. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  10476. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  10477. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  10478. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  10479. ];
  10480. var ExpertCharset = [
  10481. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  10482. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  10483. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  10484. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  10485. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  10486. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  10487. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  10488. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  10489. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  10490. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  10491. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  10492. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  10493. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  10494. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  10495. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  10496. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  10497. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  10498. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  10499. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  10500. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  10501. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  10502. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  10503. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  10504. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  10505. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  10506. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  10507. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  10508. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  10509. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  10510. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  10511. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  10512. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  10513. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  10514. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  10515. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  10516. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  10517. 'Ydieresissmall'
  10518. ];
  10519. var ExpertSubsetCharset = [
  10520. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  10521. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  10522. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  10523. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  10524. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  10525. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  10526. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  10527. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  10528. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  10529. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  10530. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  10531. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  10532. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  10533. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  10534. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  10535. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  10536. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  10537. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  10538. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  10539. 'periodinferior', 'commainferior'
  10540. ];
  10541. var DEFAULT_ICON_SIZE = 22; // px
  10542. /**
  10543. * @class
  10544. * @alias AnnotationFactory
  10545. */
  10546. function AnnotationFactory() {}
  10547. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  10548. /**
  10549. * @param {XRef} xref
  10550. * @param {Object} ref
  10551. * @returns {Annotation}
  10552. */
  10553. create: function AnnotationFactory_create(xref, ref) {
  10554. var dict = xref.fetchIfRef(ref);
  10555. if (!isDict(dict)) {
  10556. return;
  10557. }
  10558. // Determine the annotation's subtype.
  10559. var subtype = dict.get('Subtype');
  10560. subtype = isName(subtype) ? subtype.name : '';
  10561. // Return the right annotation object based on the subtype and field type.
  10562. var parameters = {
  10563. dict: dict,
  10564. ref: ref
  10565. };
  10566. switch (subtype) {
  10567. case 'Link':
  10568. return new LinkAnnotation(parameters);
  10569. case 'Text':
  10570. return new TextAnnotation(parameters);
  10571. case 'Widget':
  10572. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10573. if (isName(fieldType) && fieldType.name === 'Tx') {
  10574. return new TextWidgetAnnotation(parameters);
  10575. }
  10576. return new WidgetAnnotation(parameters);
  10577. default:
  10578. warn('Unimplemented annotation type "' + subtype + '", ' +
  10579. 'falling back to base annotation');
  10580. return new Annotation(parameters);
  10581. }
  10582. }
  10583. };
  10584. var Annotation = (function AnnotationClosure() {
  10585. // 12.5.5: Algorithm: Appearance streams
  10586. function getTransformMatrix(rect, bbox, matrix) {
  10587. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  10588. var minX = bounds[0];
  10589. var minY = bounds[1];
  10590. var maxX = bounds[2];
  10591. var maxY = bounds[3];
  10592. if (minX === maxX || minY === maxY) {
  10593. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  10594. // just apply the transform for rect
  10595. return [1, 0, 0, 1, rect[0], rect[1]];
  10596. }
  10597. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  10598. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  10599. return [
  10600. xRatio,
  10601. 0,
  10602. 0,
  10603. yRatio,
  10604. rect[0] - minX * xRatio,
  10605. rect[1] - minY * yRatio
  10606. ];
  10607. }
  10608. function getDefaultAppearance(dict) {
  10609. var appearanceState = dict.get('AP');
  10610. if (!isDict(appearanceState)) {
  10611. return;
  10612. }
  10613. var appearance;
  10614. var appearances = appearanceState.get('N');
  10615. if (isDict(appearances)) {
  10616. var as = dict.get('AS');
  10617. if (as && appearances.has(as.name)) {
  10618. appearance = appearances.get(as.name);
  10619. }
  10620. } else {
  10621. appearance = appearances;
  10622. }
  10623. return appearance;
  10624. }
  10625. function Annotation(params) {
  10626. var dict = params.dict;
  10627. var data = this.data = {};
  10628. data.subtype = dict.get('Subtype').name;
  10629. data.annotationFlags = dict.get('F');
  10630. this.setRectangle(dict.get('Rect'));
  10631. data.rect = this.rectangle;
  10632. this.setColor(dict.get('C'));
  10633. data.color = this.color;
  10634. this.borderStyle = data.borderStyle = new AnnotationBorderStyle();
  10635. this.setBorderStyle(dict);
  10636. this.appearance = getDefaultAppearance(dict);
  10637. data.hasAppearance = !!this.appearance;
  10638. data.id = params.ref.num;
  10639. }
  10640. Annotation.prototype = {
  10641. /**
  10642. * Set the rectangle.
  10643. *
  10644. * @public
  10645. * @memberof Annotation
  10646. * @param {Array} rectangle - The rectangle array with exactly four entries
  10647. */
  10648. setRectangle: function Annotation_setRectangle(rectangle) {
  10649. if (isArray(rectangle) && rectangle.length === 4) {
  10650. this.rectangle = Util.normalizeRect(rectangle);
  10651. } else {
  10652. this.rectangle = [0, 0, 0, 0];
  10653. }
  10654. },
  10655. /**
  10656. * Set the color and take care of color space conversion.
  10657. *
  10658. * @public
  10659. * @memberof Annotation
  10660. * @param {Array} color - The color array containing either 0
  10661. * (transparent), 1 (grayscale), 3 (RGB) or
  10662. * 4 (CMYK) elements
  10663. */
  10664. setColor: function Annotation_setColor(color) {
  10665. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  10666. if (!isArray(color)) {
  10667. this.color = rgbColor;
  10668. return;
  10669. }
  10670. switch (color.length) {
  10671. case 0: // Transparent, which we indicate with a null value
  10672. this.color = null;
  10673. break;
  10674. case 1: // Convert grayscale to RGB
  10675. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  10676. this.color = rgbColor;
  10677. break;
  10678. case 3: // Convert RGB percentages to RGB
  10679. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  10680. this.color = rgbColor;
  10681. break;
  10682. case 4: // Convert CMYK to RGB
  10683. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  10684. this.color = rgbColor;
  10685. break;
  10686. default:
  10687. this.color = rgbColor;
  10688. break;
  10689. }
  10690. },
  10691. /**
  10692. * Set the border style (as AnnotationBorderStyle object).
  10693. *
  10694. * @public
  10695. * @memberof Annotation
  10696. * @param {Dict} borderStyle - The border style dictionary
  10697. */
  10698. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  10699. if (!isDict(borderStyle)) {
  10700. return;
  10701. }
  10702. if (borderStyle.has('BS')) {
  10703. var dict = borderStyle.get('BS');
  10704. var dictType;
  10705. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  10706. dictType.name === 'Border')) {
  10707. this.borderStyle.setWidth(dict.get('W'));
  10708. this.borderStyle.setStyle(dict.get('S'));
  10709. this.borderStyle.setDashArray(dict.get('D'));
  10710. }
  10711. } else if (borderStyle.has('Border')) {
  10712. var array = borderStyle.get('Border');
  10713. if (isArray(array) && array.length >= 3) {
  10714. this.borderStyle.setHorizontalCornerRadius(array[0]);
  10715. this.borderStyle.setVerticalCornerRadius(array[1]);
  10716. this.borderStyle.setWidth(array[2]);
  10717. if (array.length === 4) { // Dash array available
  10718. this.borderStyle.setDashArray(array[3]);
  10719. }
  10720. }
  10721. } else {
  10722. // There are no border entries in the dictionary. According to the
  10723. // specification, we should draw a solid border of width 1 in that
  10724. // case, but Adobe Reader did not implement that part of the
  10725. // specification and instead draws no border at all, so we do the same.
  10726. // See also https://github.com/mozilla/pdf.js/issues/6179.
  10727. this.borderStyle.setWidth(0);
  10728. }
  10729. },
  10730. isInvisible: function Annotation_isInvisible() {
  10731. var data = this.data;
  10732. return !!(data &&
  10733. data.annotationFlags && // Default: not invisible
  10734. data.annotationFlags & 0x1); // Invisible
  10735. },
  10736. isViewable: function Annotation_isViewable() {
  10737. var data = this.data;
  10738. return !!(!this.isInvisible() &&
  10739. data &&
  10740. (!data.annotationFlags ||
  10741. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  10742. data.rect); // rectangle is necessary
  10743. },
  10744. isPrintable: function Annotation_isPrintable() {
  10745. var data = this.data;
  10746. return !!(!this.isInvisible() &&
  10747. data &&
  10748. data.annotationFlags && // Default: not printable
  10749. data.annotationFlags & 0x4 && // Print
  10750. !(data.annotationFlags & 0x2) && // Hidden
  10751. data.rect); // rectangle is necessary
  10752. },
  10753. loadResources: function Annotation_loadResources(keys) {
  10754. return new Promise(function (resolve, reject) {
  10755. this.appearance.dict.getAsync('Resources').then(function (resources) {
  10756. if (!resources) {
  10757. resolve();
  10758. return;
  10759. }
  10760. var objectLoader = new ObjectLoader(resources.map,
  10761. keys,
  10762. resources.xref);
  10763. objectLoader.load().then(function() {
  10764. resolve(resources);
  10765. }, reject);
  10766. }, reject);
  10767. }.bind(this));
  10768. },
  10769. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  10770. if (!this.appearance) {
  10771. return Promise.resolve(new OperatorList());
  10772. }
  10773. var data = this.data;
  10774. var appearanceDict = this.appearance.dict;
  10775. var resourcesPromise = this.loadResources([
  10776. 'ExtGState',
  10777. 'ColorSpace',
  10778. 'Pattern',
  10779. 'Shading',
  10780. 'XObject',
  10781. 'Font'
  10782. // ProcSet
  10783. // Properties
  10784. ]);
  10785. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  10786. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  10787. var transform = getTransformMatrix(data.rect, bbox, matrix);
  10788. var self = this;
  10789. return resourcesPromise.then(function(resources) {
  10790. var opList = new OperatorList();
  10791. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  10792. return evaluator.getOperatorList(self.appearance, task,
  10793. resources, opList).
  10794. then(function () {
  10795. opList.addOp(OPS.endAnnotation, []);
  10796. self.appearance.reset();
  10797. return opList;
  10798. });
  10799. });
  10800. }
  10801. };
  10802. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  10803. annotations, opList, pdfManager, partialEvaluator, task, intent) {
  10804. function reject(e) {
  10805. annotationsReadyCapability.reject(e);
  10806. }
  10807. var annotationsReadyCapability = createPromiseCapability();
  10808. var annotationPromises = [];
  10809. for (var i = 0, n = annotations.length; i < n; ++i) {
  10810. if (intent === 'display' && annotations[i].isViewable() ||
  10811. intent === 'print' && annotations[i].isPrintable()) {
  10812. annotationPromises.push(
  10813. annotations[i].getOperatorList(partialEvaluator, task));
  10814. }
  10815. }
  10816. Promise.all(annotationPromises).then(function(datas) {
  10817. opList.addOp(OPS.beginAnnotations, []);
  10818. for (var i = 0, n = datas.length; i < n; ++i) {
  10819. var annotOpList = datas[i];
  10820. opList.addOpList(annotOpList);
  10821. }
  10822. opList.addOp(OPS.endAnnotations, []);
  10823. annotationsReadyCapability.resolve();
  10824. }, reject);
  10825. return annotationsReadyCapability.promise;
  10826. };
  10827. return Annotation;
  10828. })();
  10829. /**
  10830. * Contains all data regarding an annotation's border style.
  10831. *
  10832. * @class
  10833. */
  10834. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  10835. /**
  10836. * @constructor
  10837. * @private
  10838. */
  10839. function AnnotationBorderStyle() {
  10840. this.width = 1;
  10841. this.style = AnnotationBorderStyleType.SOLID;
  10842. this.dashArray = [3];
  10843. this.horizontalCornerRadius = 0;
  10844. this.verticalCornerRadius = 0;
  10845. }
  10846. AnnotationBorderStyle.prototype = {
  10847. /**
  10848. * Set the width.
  10849. *
  10850. * @public
  10851. * @memberof AnnotationBorderStyle
  10852. * @param {integer} width - The width
  10853. */
  10854. setWidth: function AnnotationBorderStyle_setWidth(width) {
  10855. if (width === (width | 0)) {
  10856. this.width = width;
  10857. }
  10858. },
  10859. /**
  10860. * Set the style.
  10861. *
  10862. * @public
  10863. * @memberof AnnotationBorderStyle
  10864. * @param {Object} style - The style object
  10865. * @see {@link shared/util.js}
  10866. */
  10867. setStyle: function AnnotationBorderStyle_setStyle(style) {
  10868. if (!style) {
  10869. return;
  10870. }
  10871. switch (style.name) {
  10872. case 'S':
  10873. this.style = AnnotationBorderStyleType.SOLID;
  10874. break;
  10875. case 'D':
  10876. this.style = AnnotationBorderStyleType.DASHED;
  10877. break;
  10878. case 'B':
  10879. this.style = AnnotationBorderStyleType.BEVELED;
  10880. break;
  10881. case 'I':
  10882. this.style = AnnotationBorderStyleType.INSET;
  10883. break;
  10884. case 'U':
  10885. this.style = AnnotationBorderStyleType.UNDERLINE;
  10886. break;
  10887. default:
  10888. break;
  10889. }
  10890. },
  10891. /**
  10892. * Set the dash array.
  10893. *
  10894. * @public
  10895. * @memberof AnnotationBorderStyle
  10896. * @param {Array} dashArray - The dash array with at least one element
  10897. */
  10898. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  10899. // We validate the dash array, but we do not use it because CSS does not
  10900. // allow us to change spacing of dashes. For more information, visit
  10901. // http://www.w3.org/TR/css3-background/#the-border-style.
  10902. if (isArray(dashArray) && dashArray.length > 0) {
  10903. // According to the PDF specification: the elements in a dashArray
  10904. // shall be numbers that are nonnegative and not all equal to zero.
  10905. var isValid = true;
  10906. var allZeros = true;
  10907. for (var i = 0, len = dashArray.length; i < len; i++) {
  10908. var element = dashArray[i];
  10909. var validNumber = (+element >= 0);
  10910. if (!validNumber) {
  10911. isValid = false;
  10912. break;
  10913. } else if (element > 0) {
  10914. allZeros = false;
  10915. }
  10916. }
  10917. if (isValid && !allZeros) {
  10918. this.dashArray = dashArray;
  10919. } else {
  10920. this.width = 0; // Adobe behavior when the array is invalid.
  10921. }
  10922. } else if (dashArray) {
  10923. this.width = 0; // Adobe behavior when the array is invalid.
  10924. }
  10925. },
  10926. /**
  10927. * Set the horizontal corner radius (from a Border dictionary).
  10928. *
  10929. * @public
  10930. * @memberof AnnotationBorderStyle
  10931. * @param {integer} radius - The horizontal corner radius
  10932. */
  10933. setHorizontalCornerRadius:
  10934. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  10935. if (radius === (radius | 0)) {
  10936. this.horizontalCornerRadius = radius;
  10937. }
  10938. },
  10939. /**
  10940. * Set the vertical corner radius (from a Border dictionary).
  10941. *
  10942. * @public
  10943. * @memberof AnnotationBorderStyle
  10944. * @param {integer} radius - The vertical corner radius
  10945. */
  10946. setVerticalCornerRadius:
  10947. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  10948. if (radius === (radius | 0)) {
  10949. this.verticalCornerRadius = radius;
  10950. }
  10951. }
  10952. };
  10953. return AnnotationBorderStyle;
  10954. })();
  10955. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  10956. function WidgetAnnotation(params) {
  10957. Annotation.call(this, params);
  10958. var dict = params.dict;
  10959. var data = this.data;
  10960. data.fieldValue = stringToPDFString(
  10961. Util.getInheritableProperty(dict, 'V') || '');
  10962. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  10963. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  10964. var fieldType = Util.getInheritableProperty(dict, 'FT');
  10965. data.fieldType = isName(fieldType) ? fieldType.name : '';
  10966. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  10967. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  10968. // Building the full field name by collecting the field and
  10969. // its ancestors 'T' data and joining them using '.'.
  10970. var fieldName = [];
  10971. var namedItem = dict;
  10972. var ref = params.ref;
  10973. while (namedItem) {
  10974. var parent = namedItem.get('Parent');
  10975. var parentRef = namedItem.getRaw('Parent');
  10976. var name = namedItem.get('T');
  10977. if (name) {
  10978. fieldName.unshift(stringToPDFString(name));
  10979. } else if (parent && ref) {
  10980. // The field name is absent, that means more than one field
  10981. // with the same name may exist. Replacing the empty name
  10982. // with the '`' plus index in the parent's 'Kids' array.
  10983. // This is not in the PDF spec but necessary to id the
  10984. // the input controls.
  10985. var kids = parent.get('Kids');
  10986. var j, jj;
  10987. for (j = 0, jj = kids.length; j < jj; j++) {
  10988. var kidRef = kids[j];
  10989. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  10990. break;
  10991. }
  10992. }
  10993. fieldName.unshift('`' + j);
  10994. }
  10995. namedItem = parent;
  10996. ref = parentRef;
  10997. }
  10998. data.fullName = fieldName.join('.');
  10999. }
  11000. var parent = Annotation.prototype;
  11001. Util.inherit(WidgetAnnotation, Annotation, {
  11002. isViewable: function WidgetAnnotation_isViewable() {
  11003. if (this.data.fieldType === 'Sig') {
  11004. warn('unimplemented annotation type: Widget signature');
  11005. return false;
  11006. }
  11007. return parent.isViewable.call(this);
  11008. }
  11009. });
  11010. return WidgetAnnotation;
  11011. })();
  11012. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  11013. function TextWidgetAnnotation(params) {
  11014. WidgetAnnotation.call(this, params);
  11015. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  11016. this.data.annotationType = AnnotationType.WIDGET;
  11017. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  11018. }
  11019. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  11020. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  11021. task) {
  11022. if (this.appearance) {
  11023. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  11024. }
  11025. var opList = new OperatorList();
  11026. var data = this.data;
  11027. // Even if there is an appearance stream, ignore it. This is the
  11028. // behaviour used by Adobe Reader.
  11029. if (!data.defaultAppearance) {
  11030. return Promise.resolve(opList);
  11031. }
  11032. var stream = new Stream(stringToBytes(data.defaultAppearance));
  11033. return evaluator.getOperatorList(stream, task,
  11034. this.fieldResources, opList).
  11035. then(function () {
  11036. return opList;
  11037. });
  11038. }
  11039. });
  11040. return TextWidgetAnnotation;
  11041. })();
  11042. var TextAnnotation = (function TextAnnotationClosure() {
  11043. function TextAnnotation(params) {
  11044. Annotation.call(this, params);
  11045. var dict = params.dict;
  11046. var data = this.data;
  11047. var content = dict.get('Contents');
  11048. var title = dict.get('T');
  11049. data.annotationType = AnnotationType.TEXT;
  11050. data.content = stringToPDFString(content || '');
  11051. data.title = stringToPDFString(title || '');
  11052. data.hasHtml = true;
  11053. if (data.hasAppearance) {
  11054. data.name = 'NoIcon';
  11055. } else {
  11056. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  11057. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  11058. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  11059. }
  11060. if (dict.has('C')) {
  11061. data.hasBgColor = true;
  11062. }
  11063. }
  11064. Util.inherit(TextAnnotation, Annotation, { });
  11065. return TextAnnotation;
  11066. })();
  11067. var LinkAnnotation = (function LinkAnnotationClosure() {
  11068. function LinkAnnotation(params) {
  11069. Annotation.call(this, params);
  11070. var dict = params.dict;
  11071. var data = this.data;
  11072. data.annotationType = AnnotationType.LINK;
  11073. data.hasHtml = true;
  11074. var action = dict.get('A');
  11075. if (action && isDict(action)) {
  11076. var linkType = action.get('S').name;
  11077. if (linkType === 'URI') {
  11078. var url = action.get('URI');
  11079. if (isName(url)) {
  11080. // Some bad PDFs do not put parentheses around relative URLs.
  11081. url = '/' + url.name;
  11082. } else if (url) {
  11083. url = addDefaultProtocolToUrl(url);
  11084. }
  11085. // TODO: pdf spec mentions urls can be relative to a Base
  11086. // entry in the dictionary.
  11087. if (!isValidUrl(url, false)) {
  11088. url = '';
  11089. }
  11090. // According to ISO 32000-1:2008, section 12.6.4.7,
  11091. // URI should to be encoded in 7-bit ASCII.
  11092. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  11093. try {
  11094. data.url = stringToUTF8String(url);
  11095. } catch (e) {
  11096. // Fall back to a simple copy.
  11097. data.url = url;
  11098. }
  11099. } else if (linkType === 'GoTo') {
  11100. data.dest = action.get('D');
  11101. } else if (linkType === 'GoToR') {
  11102. var urlDict = action.get('F');
  11103. if (isDict(urlDict)) {
  11104. // We assume that the 'url' is a Filspec dictionary
  11105. // and fetch the url without checking any further
  11106. url = urlDict.get('F') || '';
  11107. }
  11108. // TODO: pdf reference says that GoToR
  11109. // can also have 'NewWindow' attribute
  11110. if (!isValidUrl(url, false)) {
  11111. url = '';
  11112. }
  11113. data.url = url;
  11114. data.dest = action.get('D');
  11115. } else if (linkType === 'Named') {
  11116. data.action = action.get('N').name;
  11117. } else {
  11118. warn('unrecognized link type: ' + linkType);
  11119. }
  11120. } else if (dict.has('Dest')) {
  11121. // simple destination link
  11122. var dest = dict.get('Dest');
  11123. data.dest = isName(dest) ? dest.name : dest;
  11124. }
  11125. }
  11126. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  11127. function addDefaultProtocolToUrl(url) {
  11128. if (url && url.indexOf('www.') === 0) {
  11129. return ('http://' + url);
  11130. }
  11131. return url;
  11132. }
  11133. Util.inherit(LinkAnnotation, Annotation, { });
  11134. return LinkAnnotation;
  11135. })();
  11136. var PDFFunction = (function PDFFunctionClosure() {
  11137. var CONSTRUCT_SAMPLED = 0;
  11138. var CONSTRUCT_INTERPOLATED = 2;
  11139. var CONSTRUCT_STICHED = 3;
  11140. var CONSTRUCT_POSTSCRIPT = 4;
  11141. return {
  11142. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  11143. str) {
  11144. var i, ii;
  11145. var length = 1;
  11146. for (i = 0, ii = size.length; i < ii; i++) {
  11147. length *= size[i];
  11148. }
  11149. length *= outputSize;
  11150. var array = new Array(length);
  11151. var codeSize = 0;
  11152. var codeBuf = 0;
  11153. // 32 is a valid bps so shifting won't work
  11154. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  11155. var strBytes = str.getBytes((length * bps + 7) / 8);
  11156. var strIdx = 0;
  11157. for (i = 0; i < length; i++) {
  11158. while (codeSize < bps) {
  11159. codeBuf <<= 8;
  11160. codeBuf |= strBytes[strIdx++];
  11161. codeSize += 8;
  11162. }
  11163. codeSize -= bps;
  11164. array[i] = (codeBuf >> codeSize) * sampleMul;
  11165. codeBuf &= (1 << codeSize) - 1;
  11166. }
  11167. return array;
  11168. },
  11169. getIR: function PDFFunction_getIR(xref, fn) {
  11170. var dict = fn.dict;
  11171. if (!dict) {
  11172. dict = fn;
  11173. }
  11174. var types = [this.constructSampled,
  11175. null,
  11176. this.constructInterpolated,
  11177. this.constructStiched,
  11178. this.constructPostScript];
  11179. var typeNum = dict.get('FunctionType');
  11180. var typeFn = types[typeNum];
  11181. if (!typeFn) {
  11182. error('Unknown type of function');
  11183. }
  11184. return typeFn.call(this, fn, dict, xref);
  11185. },
  11186. fromIR: function PDFFunction_fromIR(IR) {
  11187. var type = IR[0];
  11188. switch (type) {
  11189. case CONSTRUCT_SAMPLED:
  11190. return this.constructSampledFromIR(IR);
  11191. case CONSTRUCT_INTERPOLATED:
  11192. return this.constructInterpolatedFromIR(IR);
  11193. case CONSTRUCT_STICHED:
  11194. return this.constructStichedFromIR(IR);
  11195. //case CONSTRUCT_POSTSCRIPT:
  11196. default:
  11197. return this.constructPostScriptFromIR(IR);
  11198. }
  11199. },
  11200. parse: function PDFFunction_parse(xref, fn) {
  11201. var IR = this.getIR(xref, fn);
  11202. return this.fromIR(IR);
  11203. },
  11204. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  11205. if (!isArray(fnObj)) {
  11206. // not an array -- parsing as regular function
  11207. return this.parse(xref, fnObj);
  11208. }
  11209. var fnArray = [];
  11210. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  11211. var obj = xref.fetchIfRef(fnObj[j]);
  11212. fnArray.push(PDFFunction.parse(xref, obj));
  11213. }
  11214. return function (src, srcOffset, dest, destOffset) {
  11215. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  11216. fnArray[i](src, srcOffset, dest, destOffset + i);
  11217. }
  11218. };
  11219. },
  11220. constructSampled: function PDFFunction_constructSampled(str, dict) {
  11221. function toMultiArray(arr) {
  11222. var inputLength = arr.length;
  11223. var out = [];
  11224. var index = 0;
  11225. for (var i = 0; i < inputLength; i += 2) {
  11226. out[index] = [arr[i], arr[i + 1]];
  11227. ++index;
  11228. }
  11229. return out;
  11230. }
  11231. var domain = dict.get('Domain');
  11232. var range = dict.get('Range');
  11233. if (!domain || !range) {
  11234. error('No domain or range');
  11235. }
  11236. var inputSize = domain.length / 2;
  11237. var outputSize = range.length / 2;
  11238. domain = toMultiArray(domain);
  11239. range = toMultiArray(range);
  11240. var size = dict.get('Size');
  11241. var bps = dict.get('BitsPerSample');
  11242. var order = dict.get('Order') || 1;
  11243. if (order !== 1) {
  11244. // No description how cubic spline interpolation works in PDF32000:2008
  11245. // As in poppler, ignoring order, linear interpolation may work as good
  11246. info('No support for cubic spline interpolation: ' + order);
  11247. }
  11248. var encode = dict.get('Encode');
  11249. if (!encode) {
  11250. encode = [];
  11251. for (var i = 0; i < inputSize; ++i) {
  11252. encode.push(0);
  11253. encode.push(size[i] - 1);
  11254. }
  11255. }
  11256. encode = toMultiArray(encode);
  11257. var decode = dict.get('Decode');
  11258. if (!decode) {
  11259. decode = range;
  11260. } else {
  11261. decode = toMultiArray(decode);
  11262. }
  11263. var samples = this.getSampleArray(size, outputSize, bps, str);
  11264. return [
  11265. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  11266. outputSize, Math.pow(2, bps) - 1, range
  11267. ];
  11268. },
  11269. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  11270. // See chapter 3, page 109 of the PDF reference
  11271. function interpolate(x, xmin, xmax, ymin, ymax) {
  11272. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  11273. }
  11274. return function constructSampledFromIRResult(src, srcOffset,
  11275. dest, destOffset) {
  11276. // See chapter 3, page 110 of the PDF reference.
  11277. var m = IR[1];
  11278. var domain = IR[2];
  11279. var encode = IR[3];
  11280. var decode = IR[4];
  11281. var samples = IR[5];
  11282. var size = IR[6];
  11283. var n = IR[7];
  11284. //var mask = IR[8];
  11285. var range = IR[9];
  11286. // Building the cube vertices: its part and sample index
  11287. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  11288. var cubeVertices = 1 << m;
  11289. var cubeN = new Float64Array(cubeVertices);
  11290. var cubeVertex = new Uint32Array(cubeVertices);
  11291. var i, j;
  11292. for (j = 0; j < cubeVertices; j++) {
  11293. cubeN[j] = 1;
  11294. }
  11295. var k = n, pos = 1;
  11296. // Map x_i to y_j for 0 <= i < m using the sampled function.
  11297. for (i = 0; i < m; ++i) {
  11298. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  11299. var domain_2i = domain[i][0];
  11300. var domain_2i_1 = domain[i][1];
  11301. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  11302. domain_2i_1);
  11303. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  11304. // Encode_2i, Encode_2i+1)
  11305. var e = interpolate(xi, domain_2i, domain_2i_1,
  11306. encode[i][0], encode[i][1]);
  11307. // e_i' = min(max(e_i, 0), Size_i - 1)
  11308. var size_i = size[i];
  11309. e = Math.min(Math.max(e, 0), size_i - 1);
  11310. // Adjusting the cube: N and vertex sample index
  11311. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  11312. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  11313. var n1 = e - e0; // (e - e0) / (e1 - e0);
  11314. var offset0 = e0 * k;
  11315. var offset1 = offset0 + k; // e1 * k
  11316. for (j = 0; j < cubeVertices; j++) {
  11317. if (j & pos) {
  11318. cubeN[j] *= n1;
  11319. cubeVertex[j] += offset1;
  11320. } else {
  11321. cubeN[j] *= n0;
  11322. cubeVertex[j] += offset0;
  11323. }
  11324. }
  11325. k *= size_i;
  11326. pos <<= 1;
  11327. }
  11328. for (j = 0; j < n; ++j) {
  11329. // Sum all cube vertices' samples portions
  11330. var rj = 0;
  11331. for (i = 0; i < cubeVertices; i++) {
  11332. rj += samples[cubeVertex[i] + j] * cubeN[i];
  11333. }
  11334. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  11335. // Decode_2j, Decode_2j+1)
  11336. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  11337. // y_j = min(max(r_j, range_2j), range_2j+1)
  11338. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  11339. range[j][1]);
  11340. }
  11341. };
  11342. },
  11343. constructInterpolated: function PDFFunction_constructInterpolated(str,
  11344. dict) {
  11345. var c0 = dict.get('C0') || [0];
  11346. var c1 = dict.get('C1') || [1];
  11347. var n = dict.get('N');
  11348. if (!isArray(c0) || !isArray(c1)) {
  11349. error('Illegal dictionary for interpolated function');
  11350. }
  11351. var length = c0.length;
  11352. var diff = [];
  11353. for (var i = 0; i < length; ++i) {
  11354. diff.push(c1[i] - c0[i]);
  11355. }
  11356. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  11357. },
  11358. constructInterpolatedFromIR:
  11359. function PDFFunction_constructInterpolatedFromIR(IR) {
  11360. var c0 = IR[1];
  11361. var diff = IR[2];
  11362. var n = IR[3];
  11363. var length = diff.length;
  11364. return function constructInterpolatedFromIRResult(src, srcOffset,
  11365. dest, destOffset) {
  11366. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  11367. for (var j = 0; j < length; ++j) {
  11368. dest[destOffset + j] = c0[j] + (x * diff[j]);
  11369. }
  11370. };
  11371. },
  11372. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  11373. var domain = dict.get('Domain');
  11374. if (!domain) {
  11375. error('No domain');
  11376. }
  11377. var inputSize = domain.length / 2;
  11378. if (inputSize !== 1) {
  11379. error('Bad domain for stiched function');
  11380. }
  11381. var fnRefs = dict.get('Functions');
  11382. var fns = [];
  11383. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  11384. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  11385. }
  11386. var bounds = dict.get('Bounds');
  11387. var encode = dict.get('Encode');
  11388. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  11389. },
  11390. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  11391. var domain = IR[1];
  11392. var bounds = IR[2];
  11393. var encode = IR[3];
  11394. var fnsIR = IR[4];
  11395. var fns = [];
  11396. var tmpBuf = new Float32Array(1);
  11397. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  11398. fns.push(PDFFunction.fromIR(fnsIR[i]));
  11399. }
  11400. return function constructStichedFromIRResult(src, srcOffset,
  11401. dest, destOffset) {
  11402. var clip = function constructStichedFromIRClip(v, min, max) {
  11403. if (v > max) {
  11404. v = max;
  11405. } else if (v < min) {
  11406. v = min;
  11407. }
  11408. return v;
  11409. };
  11410. // clip to domain
  11411. var v = clip(src[srcOffset], domain[0], domain[1]);
  11412. // calulate which bound the value is in
  11413. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  11414. if (v < bounds[i]) {
  11415. break;
  11416. }
  11417. }
  11418. // encode value into domain of function
  11419. var dmin = domain[0];
  11420. if (i > 0) {
  11421. dmin = bounds[i - 1];
  11422. }
  11423. var dmax = domain[1];
  11424. if (i < bounds.length) {
  11425. dmax = bounds[i];
  11426. }
  11427. var rmin = encode[2 * i];
  11428. var rmax = encode[2 * i + 1];
  11429. // Prevent the value from becoming NaN as a result
  11430. // of division by zero (fixes issue6113.pdf).
  11431. tmpBuf[0] = dmin === dmax ? rmin :
  11432. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  11433. // call the appropriate function
  11434. fns[i](tmpBuf, 0, dest, destOffset);
  11435. };
  11436. },
  11437. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  11438. xref) {
  11439. var domain = dict.get('Domain');
  11440. var range = dict.get('Range');
  11441. if (!domain) {
  11442. error('No domain.');
  11443. }
  11444. if (!range) {
  11445. error('No range.');
  11446. }
  11447. var lexer = new PostScriptLexer(fn);
  11448. var parser = new PostScriptParser(lexer);
  11449. var code = parser.parse();
  11450. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  11451. },
  11452. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  11453. IR) {
  11454. var domain = IR[1];
  11455. var range = IR[2];
  11456. var code = IR[3];
  11457. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  11458. if (compiled) {
  11459. // Compiled function consists of simple expressions such as addition,
  11460. // subtraction, Math.max, and also contains 'var' and 'return'
  11461. // statements. See the generation in the PostScriptCompiler below.
  11462. /*jshint -W054 */
  11463. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  11464. }
  11465. info('Unable to compile PS function');
  11466. var numOutputs = range.length >> 1;
  11467. var numInputs = domain.length >> 1;
  11468. var evaluator = new PostScriptEvaluator(code);
  11469. // Cache the values for a big speed up, the cache size is limited though
  11470. // since the number of possible values can be huge from a PS function.
  11471. var cache = {};
  11472. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  11473. // seen in our tests.
  11474. var MAX_CACHE_SIZE = 2048 * 4;
  11475. var cache_available = MAX_CACHE_SIZE;
  11476. var tmpBuf = new Float32Array(numInputs);
  11477. return function constructPostScriptFromIRResult(src, srcOffset,
  11478. dest, destOffset) {
  11479. var i, value;
  11480. var key = '';
  11481. var input = tmpBuf;
  11482. for (i = 0; i < numInputs; i++) {
  11483. value = src[srcOffset + i];
  11484. input[i] = value;
  11485. key += value + '_';
  11486. }
  11487. var cachedValue = cache[key];
  11488. if (cachedValue !== undefined) {
  11489. dest.set(cachedValue, destOffset);
  11490. return;
  11491. }
  11492. var output = new Float32Array(numOutputs);
  11493. var stack = evaluator.execute(input);
  11494. var stackIndex = stack.length - numOutputs;
  11495. for (i = 0; i < numOutputs; i++) {
  11496. value = stack[stackIndex + i];
  11497. var bound = range[i * 2];
  11498. if (value < bound) {
  11499. value = bound;
  11500. } else {
  11501. bound = range[i * 2 +1];
  11502. if (value > bound) {
  11503. value = bound;
  11504. }
  11505. }
  11506. output[i] = value;
  11507. }
  11508. if (cache_available > 0) {
  11509. cache_available--;
  11510. cache[key] = output;
  11511. }
  11512. dest.set(output, destOffset);
  11513. };
  11514. }
  11515. };
  11516. })();
  11517. function isPDFFunction(v) {
  11518. var fnDict;
  11519. if (typeof v !== 'object') {
  11520. return false;
  11521. } else if (isDict(v)) {
  11522. fnDict = v;
  11523. } else if (isStream(v)) {
  11524. fnDict = v.dict;
  11525. } else {
  11526. return false;
  11527. }
  11528. return fnDict.has('FunctionType');
  11529. }
  11530. var PostScriptStack = (function PostScriptStackClosure() {
  11531. var MAX_STACK_SIZE = 100;
  11532. function PostScriptStack(initialStack) {
  11533. this.stack = !initialStack ? [] :
  11534. Array.prototype.slice.call(initialStack, 0);
  11535. }
  11536. PostScriptStack.prototype = {
  11537. push: function PostScriptStack_push(value) {
  11538. if (this.stack.length >= MAX_STACK_SIZE) {
  11539. error('PostScript function stack overflow.');
  11540. }
  11541. this.stack.push(value);
  11542. },
  11543. pop: function PostScriptStack_pop() {
  11544. if (this.stack.length <= 0) {
  11545. error('PostScript function stack underflow.');
  11546. }
  11547. return this.stack.pop();
  11548. },
  11549. copy: function PostScriptStack_copy(n) {
  11550. if (this.stack.length + n >= MAX_STACK_SIZE) {
  11551. error('PostScript function stack overflow.');
  11552. }
  11553. var stack = this.stack;
  11554. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  11555. stack.push(stack[i]);
  11556. }
  11557. },
  11558. index: function PostScriptStack_index(n) {
  11559. this.push(this.stack[this.stack.length - n - 1]);
  11560. },
  11561. // rotate the last n stack elements p times
  11562. roll: function PostScriptStack_roll(n, p) {
  11563. var stack = this.stack;
  11564. var l = stack.length - n;
  11565. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  11566. for (i = l, j = r; i < j; i++, j--) {
  11567. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  11568. }
  11569. for (i = l, j = c - 1; i < j; i++, j--) {
  11570. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  11571. }
  11572. for (i = c, j = r; i < j; i++, j--) {
  11573. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  11574. }
  11575. }
  11576. };
  11577. return PostScriptStack;
  11578. })();
  11579. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  11580. function PostScriptEvaluator(operators) {
  11581. this.operators = operators;
  11582. }
  11583. PostScriptEvaluator.prototype = {
  11584. execute: function PostScriptEvaluator_execute(initialStack) {
  11585. var stack = new PostScriptStack(initialStack);
  11586. var counter = 0;
  11587. var operators = this.operators;
  11588. var length = operators.length;
  11589. var operator, a, b;
  11590. while (counter < length) {
  11591. operator = operators[counter++];
  11592. if (typeof operator === 'number') {
  11593. // Operator is really an operand and should be pushed to the stack.
  11594. stack.push(operator);
  11595. continue;
  11596. }
  11597. switch (operator) {
  11598. // non standard ps operators
  11599. case 'jz': // jump if false
  11600. b = stack.pop();
  11601. a = stack.pop();
  11602. if (!a) {
  11603. counter = b;
  11604. }
  11605. break;
  11606. case 'j': // jump
  11607. a = stack.pop();
  11608. counter = a;
  11609. break;
  11610. // all ps operators in alphabetical order (excluding if/ifelse)
  11611. case 'abs':
  11612. a = stack.pop();
  11613. stack.push(Math.abs(a));
  11614. break;
  11615. case 'add':
  11616. b = stack.pop();
  11617. a = stack.pop();
  11618. stack.push(a + b);
  11619. break;
  11620. case 'and':
  11621. b = stack.pop();
  11622. a = stack.pop();
  11623. if (isBool(a) && isBool(b)) {
  11624. stack.push(a && b);
  11625. } else {
  11626. stack.push(a & b);
  11627. }
  11628. break;
  11629. case 'atan':
  11630. a = stack.pop();
  11631. stack.push(Math.atan(a));
  11632. break;
  11633. case 'bitshift':
  11634. b = stack.pop();
  11635. a = stack.pop();
  11636. if (a > 0) {
  11637. stack.push(a << b);
  11638. } else {
  11639. stack.push(a >> b);
  11640. }
  11641. break;
  11642. case 'ceiling':
  11643. a = stack.pop();
  11644. stack.push(Math.ceil(a));
  11645. break;
  11646. case 'copy':
  11647. a = stack.pop();
  11648. stack.copy(a);
  11649. break;
  11650. case 'cos':
  11651. a = stack.pop();
  11652. stack.push(Math.cos(a));
  11653. break;
  11654. case 'cvi':
  11655. a = stack.pop() | 0;
  11656. stack.push(a);
  11657. break;
  11658. case 'cvr':
  11659. // noop
  11660. break;
  11661. case 'div':
  11662. b = stack.pop();
  11663. a = stack.pop();
  11664. stack.push(a / b);
  11665. break;
  11666. case 'dup':
  11667. stack.copy(1);
  11668. break;
  11669. case 'eq':
  11670. b = stack.pop();
  11671. a = stack.pop();
  11672. stack.push(a === b);
  11673. break;
  11674. case 'exch':
  11675. stack.roll(2, 1);
  11676. break;
  11677. case 'exp':
  11678. b = stack.pop();
  11679. a = stack.pop();
  11680. stack.push(Math.pow(a, b));
  11681. break;
  11682. case 'false':
  11683. stack.push(false);
  11684. break;
  11685. case 'floor':
  11686. a = stack.pop();
  11687. stack.push(Math.floor(a));
  11688. break;
  11689. case 'ge':
  11690. b = stack.pop();
  11691. a = stack.pop();
  11692. stack.push(a >= b);
  11693. break;
  11694. case 'gt':
  11695. b = stack.pop();
  11696. a = stack.pop();
  11697. stack.push(a > b);
  11698. break;
  11699. case 'idiv':
  11700. b = stack.pop();
  11701. a = stack.pop();
  11702. stack.push((a / b) | 0);
  11703. break;
  11704. case 'index':
  11705. a = stack.pop();
  11706. stack.index(a);
  11707. break;
  11708. case 'le':
  11709. b = stack.pop();
  11710. a = stack.pop();
  11711. stack.push(a <= b);
  11712. break;
  11713. case 'ln':
  11714. a = stack.pop();
  11715. stack.push(Math.log(a));
  11716. break;
  11717. case 'log':
  11718. a = stack.pop();
  11719. stack.push(Math.log(a) / Math.LN10);
  11720. break;
  11721. case 'lt':
  11722. b = stack.pop();
  11723. a = stack.pop();
  11724. stack.push(a < b);
  11725. break;
  11726. case 'mod':
  11727. b = stack.pop();
  11728. a = stack.pop();
  11729. stack.push(a % b);
  11730. break;
  11731. case 'mul':
  11732. b = stack.pop();
  11733. a = stack.pop();
  11734. stack.push(a * b);
  11735. break;
  11736. case 'ne':
  11737. b = stack.pop();
  11738. a = stack.pop();
  11739. stack.push(a !== b);
  11740. break;
  11741. case 'neg':
  11742. a = stack.pop();
  11743. stack.push(-a);
  11744. break;
  11745. case 'not':
  11746. a = stack.pop();
  11747. if (isBool(a)) {
  11748. stack.push(!a);
  11749. } else {
  11750. stack.push(~a);
  11751. }
  11752. break;
  11753. case 'or':
  11754. b = stack.pop();
  11755. a = stack.pop();
  11756. if (isBool(a) && isBool(b)) {
  11757. stack.push(a || b);
  11758. } else {
  11759. stack.push(a | b);
  11760. }
  11761. break;
  11762. case 'pop':
  11763. stack.pop();
  11764. break;
  11765. case 'roll':
  11766. b = stack.pop();
  11767. a = stack.pop();
  11768. stack.roll(a, b);
  11769. break;
  11770. case 'round':
  11771. a = stack.pop();
  11772. stack.push(Math.round(a));
  11773. break;
  11774. case 'sin':
  11775. a = stack.pop();
  11776. stack.push(Math.sin(a));
  11777. break;
  11778. case 'sqrt':
  11779. a = stack.pop();
  11780. stack.push(Math.sqrt(a));
  11781. break;
  11782. case 'sub':
  11783. b = stack.pop();
  11784. a = stack.pop();
  11785. stack.push(a - b);
  11786. break;
  11787. case 'true':
  11788. stack.push(true);
  11789. break;
  11790. case 'truncate':
  11791. a = stack.pop();
  11792. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  11793. stack.push(a);
  11794. break;
  11795. case 'xor':
  11796. b = stack.pop();
  11797. a = stack.pop();
  11798. if (isBool(a) && isBool(b)) {
  11799. stack.push(a !== b);
  11800. } else {
  11801. stack.push(a ^ b);
  11802. }
  11803. break;
  11804. default:
  11805. error('Unknown operator ' + operator);
  11806. break;
  11807. }
  11808. }
  11809. return stack.stack;
  11810. }
  11811. };
  11812. return PostScriptEvaluator;
  11813. })();
  11814. // Most of the PDFs functions consist of simple operations such as:
  11815. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  11816. //
  11817. // We can compile most of such programs, and at the same moment, we can
  11818. // optimize some expressions using basic math properties. Keeping track of
  11819. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  11820. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  11821. function AstNode(type) {
  11822. this.type = type;
  11823. }
  11824. AstNode.prototype.visit = function (visitor) {
  11825. throw new Error('abstract method');
  11826. };
  11827. function AstArgument(index, min, max) {
  11828. AstNode.call(this, 'args');
  11829. this.index = index;
  11830. this.min = min;
  11831. this.max = max;
  11832. }
  11833. AstArgument.prototype = Object.create(AstNode.prototype);
  11834. AstArgument.prototype.visit = function (visitor) {
  11835. visitor.visitArgument(this);
  11836. };
  11837. function AstLiteral(number) {
  11838. AstNode.call(this, 'literal');
  11839. this.number = number;
  11840. this.min = number;
  11841. this.max = number;
  11842. }
  11843. AstLiteral.prototype = Object.create(AstNode.prototype);
  11844. AstLiteral.prototype.visit = function (visitor) {
  11845. visitor.visitLiteral(this);
  11846. };
  11847. function AstBinaryOperation(op, arg1, arg2, min, max) {
  11848. AstNode.call(this, 'binary');
  11849. this.op = op;
  11850. this.arg1 = arg1;
  11851. this.arg2 = arg2;
  11852. this.min = min;
  11853. this.max = max;
  11854. }
  11855. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  11856. AstBinaryOperation.prototype.visit = function (visitor) {
  11857. visitor.visitBinaryOperation(this);
  11858. };
  11859. function AstMin(arg, max) {
  11860. AstNode.call(this, 'max');
  11861. this.arg = arg;
  11862. this.min = arg.min;
  11863. this.max = max;
  11864. }
  11865. AstMin.prototype = Object.create(AstNode.prototype);
  11866. AstMin.prototype.visit = function (visitor) {
  11867. visitor.visitMin(this);
  11868. };
  11869. function AstVariable(index, min, max) {
  11870. AstNode.call(this, 'var');
  11871. this.index = index;
  11872. this.min = min;
  11873. this.max = max;
  11874. }
  11875. AstVariable.prototype = Object.create(AstNode.prototype);
  11876. AstVariable.prototype.visit = function (visitor) {
  11877. visitor.visitVariable(this);
  11878. };
  11879. function AstVariableDefinition(variable, arg) {
  11880. AstNode.call(this, 'definition');
  11881. this.variable = variable;
  11882. this.arg = arg;
  11883. }
  11884. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  11885. AstVariableDefinition.prototype.visit = function (visitor) {
  11886. visitor.visitVariableDefinition(this);
  11887. };
  11888. function ExpressionBuilderVisitor() {
  11889. this.parts = [];
  11890. }
  11891. ExpressionBuilderVisitor.prototype = {
  11892. visitArgument: function (arg) {
  11893. this.parts.push('Math.max(', arg.min, ', Math.min(',
  11894. arg.max, ', src[srcOffset + ', arg.index, ']))');
  11895. },
  11896. visitVariable: function (variable) {
  11897. this.parts.push('v', variable.index);
  11898. },
  11899. visitLiteral: function (literal) {
  11900. this.parts.push(literal.number);
  11901. },
  11902. visitBinaryOperation: function (operation) {
  11903. this.parts.push('(');
  11904. operation.arg1.visit(this);
  11905. this.parts.push(' ', operation.op, ' ');
  11906. operation.arg2.visit(this);
  11907. this.parts.push(')');
  11908. },
  11909. visitVariableDefinition: function (definition) {
  11910. this.parts.push('var ');
  11911. definition.variable.visit(this);
  11912. this.parts.push(' = ');
  11913. definition.arg.visit(this);
  11914. this.parts.push(';');
  11915. },
  11916. visitMin: function (max) {
  11917. this.parts.push('Math.min(');
  11918. max.arg.visit(this);
  11919. this.parts.push(', ', max.max, ')');
  11920. },
  11921. toString: function () {
  11922. return this.parts.join('');
  11923. }
  11924. };
  11925. function buildAddOperation(num1, num2) {
  11926. if (num2.type === 'literal' && num2.number === 0) {
  11927. // optimization: second operand is 0
  11928. return num1;
  11929. }
  11930. if (num1.type === 'literal' && num1.number === 0) {
  11931. // optimization: first operand is 0
  11932. return num2;
  11933. }
  11934. if (num2.type === 'literal' && num1.type === 'literal') {
  11935. // optimization: operands operand are literals
  11936. return new AstLiteral(num1.number + num2.number);
  11937. }
  11938. return new AstBinaryOperation('+', num1, num2,
  11939. num1.min + num2.min, num1.max + num2.max);
  11940. }
  11941. function buildMulOperation(num1, num2) {
  11942. if (num2.type === 'literal') {
  11943. // optimization: second operands is a literal...
  11944. if (num2.number === 0) {
  11945. return new AstLiteral(0); // and it's 0
  11946. } else if (num2.number === 1) {
  11947. return num1; // and it's 1
  11948. } else if (num1.type === 'literal') {
  11949. // ... and first operands is a literal too
  11950. return new AstLiteral(num1.number * num2.number);
  11951. }
  11952. }
  11953. if (num1.type === 'literal') {
  11954. // optimization: first operands is a literal...
  11955. if (num1.number === 0) {
  11956. return new AstLiteral(0); // and it's 0
  11957. } else if (num1.number === 1) {
  11958. return num2; // and it's 1
  11959. }
  11960. }
  11961. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  11962. num1.max * num2.min, num1.max * num2.max);
  11963. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  11964. num1.max * num2.min, num1.max * num2.max);
  11965. return new AstBinaryOperation('*', num1, num2, min, max);
  11966. }
  11967. function buildSubOperation(num1, num2) {
  11968. if (num2.type === 'literal') {
  11969. // optimization: second operands is a literal...
  11970. if (num2.number === 0) {
  11971. return num1; // ... and it's 0
  11972. } else if (num1.type === 'literal') {
  11973. // ... and first operands is a literal too
  11974. return new AstLiteral(num1.number - num2.number);
  11975. }
  11976. }
  11977. if (num2.type === 'binary' && num2.op === '-' &&
  11978. num1.type === 'literal' && num1.number === 1 &&
  11979. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  11980. // optimization for case: 1 - (1 - x)
  11981. return num2.arg2;
  11982. }
  11983. return new AstBinaryOperation('-', num1, num2,
  11984. num1.min - num2.max, num1.max - num2.min);
  11985. }
  11986. function buildMinOperation(num1, max) {
  11987. if (num1.min >= max) {
  11988. // optimization: num1 min value is not less than required max
  11989. return new AstLiteral(max); // just returning max
  11990. } else if (num1.max <= max) {
  11991. // optimization: num1 max value is not greater than required max
  11992. return num1; // just returning an argument
  11993. }
  11994. return new AstMin(num1, max);
  11995. }
  11996. function PostScriptCompiler() {}
  11997. PostScriptCompiler.prototype = {
  11998. compile: function PostScriptCompiler_compile(code, domain, range) {
  11999. var stack = [];
  12000. var i, ii;
  12001. var instructions = [];
  12002. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  12003. var lastRegister = 0;
  12004. var n, j, min, max;
  12005. var num1, num2, ast1, ast2, tmpVar, item;
  12006. for (i = 0; i < inputSize; i++) {
  12007. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  12008. }
  12009. for (i = 0, ii = code.length; i < ii; i++) {
  12010. item = code[i];
  12011. if (typeof item === 'number') {
  12012. stack.push(new AstLiteral(item));
  12013. continue;
  12014. }
  12015. switch (item) {
  12016. case 'add':
  12017. if (stack.length < 2) {
  12018. return null;
  12019. }
  12020. num2 = stack.pop();
  12021. num1 = stack.pop();
  12022. stack.push(buildAddOperation(num1, num2));
  12023. break;
  12024. case 'cvr':
  12025. if (stack.length < 1) {
  12026. return null;
  12027. }
  12028. break;
  12029. case 'mul':
  12030. if (stack.length < 2) {
  12031. return null;
  12032. }
  12033. num2 = stack.pop();
  12034. num1 = stack.pop();
  12035. stack.push(buildMulOperation(num1, num2));
  12036. break;
  12037. case 'sub':
  12038. if (stack.length < 2) {
  12039. return null;
  12040. }
  12041. num2 = stack.pop();
  12042. num1 = stack.pop();
  12043. stack.push(buildSubOperation(num1, num2));
  12044. break;
  12045. case 'exch':
  12046. if (stack.length < 2) {
  12047. return null;
  12048. }
  12049. ast1 = stack.pop(); ast2 = stack.pop();
  12050. stack.push(ast1, ast2);
  12051. break;
  12052. case 'pop':
  12053. if (stack.length < 1) {
  12054. return null;
  12055. }
  12056. stack.pop();
  12057. break;
  12058. case 'index':
  12059. if (stack.length < 1) {
  12060. return null;
  12061. }
  12062. num1 = stack.pop();
  12063. if (num1.type !== 'literal') {
  12064. return null;
  12065. }
  12066. n = num1.number;
  12067. if (n < 0 || (n|0) !== n || stack.length < n) {
  12068. return null;
  12069. }
  12070. ast1 = stack[stack.length - n - 1];
  12071. if (ast1.type === 'literal' || ast1.type === 'var') {
  12072. stack.push(ast1);
  12073. break;
  12074. }
  12075. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  12076. stack[stack.length - n - 1] = tmpVar;
  12077. stack.push(tmpVar);
  12078. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  12079. break;
  12080. case 'dup':
  12081. if (stack.length < 1) {
  12082. return null;
  12083. }
  12084. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  12085. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  12086. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  12087. // special case of the commands sequence for the min operation
  12088. num1 = stack.pop();
  12089. stack.push(buildMinOperation(num1, code[i + 1]));
  12090. i += 6;
  12091. break;
  12092. }
  12093. ast1 = stack[stack.length - 1];
  12094. if (ast1.type === 'literal' || ast1.type === 'var') {
  12095. // we don't have to save into intermediate variable a literal or
  12096. // variable.
  12097. stack.push(ast1);
  12098. break;
  12099. }
  12100. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  12101. stack[stack.length - 1] = tmpVar;
  12102. stack.push(tmpVar);
  12103. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  12104. break;
  12105. case 'roll':
  12106. if (stack.length < 2) {
  12107. return null;
  12108. }
  12109. num2 = stack.pop();
  12110. num1 = stack.pop();
  12111. if (num2.type !== 'literal' || num1.type !== 'literal') {
  12112. // both roll operands must be numbers
  12113. return null;
  12114. }
  12115. j = num2.number;
  12116. n = num1.number;
  12117. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  12118. // ... and integers
  12119. return null;
  12120. }
  12121. j = ((j % n) + n) % n;
  12122. if (j === 0) {
  12123. break; // just skipping -- there are nothing to rotate
  12124. }
  12125. Array.prototype.push.apply(stack,
  12126. stack.splice(stack.length - n, n - j));
  12127. break;
  12128. default:
  12129. return null; // unsupported operator
  12130. }
  12131. }
  12132. if (stack.length !== outputSize) {
  12133. return null;
  12134. }
  12135. var result = [];
  12136. instructions.forEach(function (instruction) {
  12137. var statementBuilder = new ExpressionBuilderVisitor();
  12138. instruction.visit(statementBuilder);
  12139. result.push(statementBuilder.toString());
  12140. });
  12141. stack.forEach(function (expr, i) {
  12142. var statementBuilder = new ExpressionBuilderVisitor();
  12143. expr.visit(statementBuilder);
  12144. var min = range[i * 2], max = range[i * 2 + 1];
  12145. var out = [statementBuilder.toString()];
  12146. if (min > expr.min) {
  12147. out.unshift('Math.max(', min, ', ');
  12148. out.push(')');
  12149. }
  12150. if (max < expr.max) {
  12151. out.unshift('Math.min(', max, ', ');
  12152. out.push(')');
  12153. }
  12154. out.unshift('dest[destOffset + ', i, '] = ');
  12155. out.push(';');
  12156. result.push(out.join(''));
  12157. });
  12158. return result.join('\n');
  12159. }
  12160. };
  12161. return PostScriptCompiler;
  12162. })();
  12163. var ColorSpace = (function ColorSpaceClosure() {
  12164. // Constructor should define this.numComps, this.defaultColor, this.name
  12165. function ColorSpace() {
  12166. error('should not call ColorSpace constructor');
  12167. }
  12168. ColorSpace.prototype = {
  12169. /**
  12170. * Converts the color value to the RGB color. The color components are
  12171. * located in the src array starting from the srcOffset. Returns the array
  12172. * of the rgb components, each value ranging from [0,255].
  12173. */
  12174. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  12175. var rgb = new Uint8Array(3);
  12176. this.getRgbItem(src, srcOffset, rgb, 0);
  12177. return rgb;
  12178. },
  12179. /**
  12180. * Converts the color value to the RGB color, similar to the getRgb method.
  12181. * The result placed into the dest array starting from the destOffset.
  12182. */
  12183. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  12184. dest, destOffset) {
  12185. error('Should not call ColorSpace.getRgbItem');
  12186. },
  12187. /**
  12188. * Converts the specified number of the color values to the RGB colors.
  12189. * The colors are located in the src array starting from the srcOffset.
  12190. * The result is placed into the dest array starting from the destOffset.
  12191. * The src array items shall be in [0,2^bits) range, the dest array items
  12192. * will be in [0,255] range. alpha01 indicates how many alpha components
  12193. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  12194. * array).
  12195. */
  12196. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  12197. dest, destOffset, bits,
  12198. alpha01) {
  12199. error('Should not call ColorSpace.getRgbBuffer');
  12200. },
  12201. /**
  12202. * Determines the number of bytes required to store the result of the
  12203. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  12204. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  12205. */
  12206. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  12207. alpha01) {
  12208. error('Should not call ColorSpace.getOutputLength');
  12209. },
  12210. /**
  12211. * Returns true if source data will be equal the result/output data.
  12212. */
  12213. isPassthrough: function ColorSpace_isPassthrough(bits) {
  12214. return false;
  12215. },
  12216. /**
  12217. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  12218. * how many alpha components there are in the dest array; it will be either
  12219. * 0 (RGB array) or 1 (RGBA array).
  12220. */
  12221. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  12222. originalHeight, width, height,
  12223. actualHeight, bpc, comps, alpha01) {
  12224. var count = originalWidth * originalHeight;
  12225. var rgbBuf = null;
  12226. var numComponentColors = 1 << bpc;
  12227. var needsResizing = originalHeight !== height || originalWidth !== width;
  12228. var i, ii;
  12229. if (this.isPassthrough(bpc)) {
  12230. rgbBuf = comps;
  12231. } else if (this.numComps === 1 && count > numComponentColors &&
  12232. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  12233. // Optimization: create a color map when there is just one component and
  12234. // we are converting more colors than the size of the color map. We
  12235. // don't build the map if the colorspace is gray or rgb since those
  12236. // methods are faster than building a map. This mainly offers big speed
  12237. // ups for indexed and alternate colorspaces.
  12238. //
  12239. // TODO it may be worth while to cache the color map. While running
  12240. // testing I never hit a cache so I will leave that out for now (perhaps
  12241. // we are reparsing colorspaces too much?).
  12242. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  12243. new Uint16Array(numComponentColors);
  12244. var key;
  12245. for (i = 0; i < numComponentColors; i++) {
  12246. allColors[i] = i;
  12247. }
  12248. var colorMap = new Uint8Array(numComponentColors * 3);
  12249. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  12250. /* alpha01 = */ 0);
  12251. var destPos, rgbPos;
  12252. if (!needsResizing) {
  12253. // Fill in the RGB values directly into |dest|.
  12254. destPos = 0;
  12255. for (i = 0; i < count; ++i) {
  12256. key = comps[i] * 3;
  12257. dest[destPos++] = colorMap[key];
  12258. dest[destPos++] = colorMap[key + 1];
  12259. dest[destPos++] = colorMap[key + 2];
  12260. destPos += alpha01;
  12261. }
  12262. } else {
  12263. rgbBuf = new Uint8Array(count * 3);
  12264. rgbPos = 0;
  12265. for (i = 0; i < count; ++i) {
  12266. key = comps[i] * 3;
  12267. rgbBuf[rgbPos++] = colorMap[key];
  12268. rgbBuf[rgbPos++] = colorMap[key + 1];
  12269. rgbBuf[rgbPos++] = colorMap[key + 2];
  12270. }
  12271. }
  12272. } else {
  12273. if (!needsResizing) {
  12274. // Fill in the RGB values directly into |dest|.
  12275. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  12276. alpha01);
  12277. } else {
  12278. rgbBuf = new Uint8Array(count * 3);
  12279. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  12280. /* alpha01 = */ 0);
  12281. }
  12282. }
  12283. if (rgbBuf) {
  12284. if (needsResizing) {
  12285. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  12286. height, dest, alpha01);
  12287. } else {
  12288. rgbPos = 0;
  12289. destPos = 0;
  12290. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  12291. dest[destPos++] = rgbBuf[rgbPos++];
  12292. dest[destPos++] = rgbBuf[rgbPos++];
  12293. dest[destPos++] = rgbBuf[rgbPos++];
  12294. destPos += alpha01;
  12295. }
  12296. }
  12297. }
  12298. },
  12299. /**
  12300. * True if the colorspace has components in the default range of [0, 1].
  12301. * This should be true for all colorspaces except for lab color spaces
  12302. * which are [0,100], [-128, 127], [-128, 127].
  12303. */
  12304. usesZeroToOneRange: true
  12305. };
  12306. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  12307. var IR = ColorSpace.parseToIR(cs, xref, res);
  12308. if (IR instanceof AlternateCS) {
  12309. return IR;
  12310. }
  12311. return ColorSpace.fromIR(IR);
  12312. };
  12313. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  12314. var name = isArray(IR) ? IR[0] : IR;
  12315. var whitePoint, blackPoint, gamma;
  12316. switch (name) {
  12317. case 'DeviceGrayCS':
  12318. return this.singletons.gray;
  12319. case 'DeviceRgbCS':
  12320. return this.singletons.rgb;
  12321. case 'DeviceCmykCS':
  12322. return this.singletons.cmyk;
  12323. case 'CalGrayCS':
  12324. whitePoint = IR[1].WhitePoint;
  12325. blackPoint = IR[1].BlackPoint;
  12326. gamma = IR[1].Gamma;
  12327. return new CalGrayCS(whitePoint, blackPoint, gamma);
  12328. case 'CalRGBCS':
  12329. whitePoint = IR[1].WhitePoint;
  12330. blackPoint = IR[1].BlackPoint;
  12331. gamma = IR[1].Gamma;
  12332. var matrix = IR[1].Matrix;
  12333. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  12334. case 'PatternCS':
  12335. var basePatternCS = IR[1];
  12336. if (basePatternCS) {
  12337. basePatternCS = ColorSpace.fromIR(basePatternCS);
  12338. }
  12339. return new PatternCS(basePatternCS);
  12340. case 'IndexedCS':
  12341. var baseIndexedCS = IR[1];
  12342. var hiVal = IR[2];
  12343. var lookup = IR[3];
  12344. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  12345. case 'AlternateCS':
  12346. var numComps = IR[1];
  12347. var alt = IR[2];
  12348. var tintFnIR = IR[3];
  12349. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  12350. PDFFunction.fromIR(tintFnIR));
  12351. case 'LabCS':
  12352. whitePoint = IR[1].WhitePoint;
  12353. blackPoint = IR[1].BlackPoint;
  12354. var range = IR[1].Range;
  12355. return new LabCS(whitePoint, blackPoint, range);
  12356. default:
  12357. error('Unknown name ' + name);
  12358. }
  12359. return null;
  12360. };
  12361. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  12362. if (isName(cs)) {
  12363. var colorSpaces = res.get('ColorSpace');
  12364. if (isDict(colorSpaces)) {
  12365. var refcs = colorSpaces.get(cs.name);
  12366. if (refcs) {
  12367. cs = refcs;
  12368. }
  12369. }
  12370. }
  12371. cs = xref.fetchIfRef(cs);
  12372. var mode;
  12373. if (isName(cs)) {
  12374. mode = cs.name;
  12375. this.mode = mode;
  12376. switch (mode) {
  12377. case 'DeviceGray':
  12378. case 'G':
  12379. return 'DeviceGrayCS';
  12380. case 'DeviceRGB':
  12381. case 'RGB':
  12382. return 'DeviceRgbCS';
  12383. case 'DeviceCMYK':
  12384. case 'CMYK':
  12385. return 'DeviceCmykCS';
  12386. case 'Pattern':
  12387. return ['PatternCS', null];
  12388. default:
  12389. error('unrecognized colorspace ' + mode);
  12390. }
  12391. } else if (isArray(cs)) {
  12392. mode = xref.fetchIfRef(cs[0]).name;
  12393. this.mode = mode;
  12394. var numComps, params, alt;
  12395. switch (mode) {
  12396. case 'DeviceGray':
  12397. case 'G':
  12398. return 'DeviceGrayCS';
  12399. case 'DeviceRGB':
  12400. case 'RGB':
  12401. return 'DeviceRgbCS';
  12402. case 'DeviceCMYK':
  12403. case 'CMYK':
  12404. return 'DeviceCmykCS';
  12405. case 'CalGray':
  12406. params = xref.fetchIfRef(cs[1]).getAll();
  12407. return ['CalGrayCS', params];
  12408. case 'CalRGB':
  12409. params = xref.fetchIfRef(cs[1]).getAll();
  12410. return ['CalRGBCS', params];
  12411. case 'ICCBased':
  12412. var stream = xref.fetchIfRef(cs[1]);
  12413. var dict = stream.dict;
  12414. numComps = dict.get('N');
  12415. alt = dict.get('Alternate');
  12416. if (alt) {
  12417. var altIR = ColorSpace.parseToIR(alt, xref, res);
  12418. // Parse the /Alternate CS to ensure that the number of components
  12419. // are correct, and also (indirectly) that it is not a PatternCS.
  12420. var altCS = ColorSpace.fromIR(altIR);
  12421. if (altCS.numComps === numComps) {
  12422. return altIR;
  12423. }
  12424. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  12425. }
  12426. if (numComps === 1) {
  12427. return 'DeviceGrayCS';
  12428. } else if (numComps === 3) {
  12429. return 'DeviceRgbCS';
  12430. } else if (numComps === 4) {
  12431. return 'DeviceCmykCS';
  12432. }
  12433. break;
  12434. case 'Pattern':
  12435. var basePatternCS = cs[1] || null;
  12436. if (basePatternCS) {
  12437. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  12438. }
  12439. return ['PatternCS', basePatternCS];
  12440. case 'Indexed':
  12441. case 'I':
  12442. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  12443. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  12444. var lookup = xref.fetchIfRef(cs[3]);
  12445. if (isStream(lookup)) {
  12446. lookup = lookup.getBytes();
  12447. }
  12448. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  12449. case 'Separation':
  12450. case 'DeviceN':
  12451. var name = xref.fetchIfRef(cs[1]);
  12452. numComps = 1;
  12453. if (isName(name)) {
  12454. numComps = 1;
  12455. } else if (isArray(name)) {
  12456. numComps = name.length;
  12457. }
  12458. alt = ColorSpace.parseToIR(cs[2], xref, res);
  12459. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  12460. return ['AlternateCS', numComps, alt, tintFnIR];
  12461. case 'Lab':
  12462. params = xref.fetchIfRef(cs[1]).getAll();
  12463. return ['LabCS', params];
  12464. default:
  12465. error('unimplemented color space object "' + mode + '"');
  12466. }
  12467. } else {
  12468. error('unrecognized color space object: "' + cs + '"');
  12469. }
  12470. return null;
  12471. };
  12472. /**
  12473. * Checks if a decode map matches the default decode map for a color space.
  12474. * This handles the general decode maps where there are two values per
  12475. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  12476. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  12477. * slightly different.
  12478. * @param {Array} decode Decode map (usually from an image).
  12479. * @param {Number} n Number of components the color space has.
  12480. */
  12481. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  12482. if (!isArray(decode)) {
  12483. return true;
  12484. }
  12485. if (n * 2 !== decode.length) {
  12486. warn('The decode map is not the correct length');
  12487. return true;
  12488. }
  12489. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  12490. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  12491. return false;
  12492. }
  12493. }
  12494. return true;
  12495. };
  12496. ColorSpace.singletons = {
  12497. get gray() {
  12498. return shadow(this, 'gray', new DeviceGrayCS());
  12499. },
  12500. get rgb() {
  12501. return shadow(this, 'rgb', new DeviceRgbCS());
  12502. },
  12503. get cmyk() {
  12504. return shadow(this, 'cmyk', new DeviceCmykCS());
  12505. }
  12506. };
  12507. return ColorSpace;
  12508. })();
  12509. /**
  12510. * Alternate color space handles both Separation and DeviceN color spaces. A
  12511. * Separation color space is actually just a DeviceN with one color component.
  12512. * Both color spaces use a tinting function to convert colors to a base color
  12513. * space.
  12514. */
  12515. var AlternateCS = (function AlternateCSClosure() {
  12516. function AlternateCS(numComps, base, tintFn) {
  12517. this.name = 'Alternate';
  12518. this.numComps = numComps;
  12519. this.defaultColor = new Float32Array(numComps);
  12520. for (var i = 0; i < numComps; ++i) {
  12521. this.defaultColor[i] = 1;
  12522. }
  12523. this.base = base;
  12524. this.tintFn = tintFn;
  12525. this.tmpBuf = new Float32Array(base.numComps);
  12526. }
  12527. AlternateCS.prototype = {
  12528. getRgb: ColorSpace.prototype.getRgb,
  12529. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  12530. dest, destOffset) {
  12531. var tmpBuf = this.tmpBuf;
  12532. this.tintFn(src, srcOffset, tmpBuf, 0);
  12533. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  12534. },
  12535. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  12536. dest, destOffset, bits,
  12537. alpha01) {
  12538. var tintFn = this.tintFn;
  12539. var base = this.base;
  12540. var scale = 1 / ((1 << bits) - 1);
  12541. var baseNumComps = base.numComps;
  12542. var usesZeroToOneRange = base.usesZeroToOneRange;
  12543. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  12544. alpha01 === 0;
  12545. var pos = isPassthrough ? destOffset : 0;
  12546. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  12547. var numComps = this.numComps;
  12548. var scaled = new Float32Array(numComps);
  12549. var tinted = new Float32Array(baseNumComps);
  12550. var i, j;
  12551. if (usesZeroToOneRange) {
  12552. for (i = 0; i < count; i++) {
  12553. for (j = 0; j < numComps; j++) {
  12554. scaled[j] = src[srcOffset++] * scale;
  12555. }
  12556. tintFn(scaled, 0, tinted, 0);
  12557. for (j = 0; j < baseNumComps; j++) {
  12558. baseBuf[pos++] = tinted[j] * 255;
  12559. }
  12560. }
  12561. } else {
  12562. for (i = 0; i < count; i++) {
  12563. for (j = 0; j < numComps; j++) {
  12564. scaled[j] = src[srcOffset++] * scale;
  12565. }
  12566. tintFn(scaled, 0, tinted, 0);
  12567. base.getRgbItem(tinted, 0, baseBuf, pos);
  12568. pos += baseNumComps;
  12569. }
  12570. }
  12571. if (!isPassthrough) {
  12572. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  12573. }
  12574. },
  12575. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  12576. alpha01) {
  12577. return this.base.getOutputLength(inputLength *
  12578. this.base.numComps / this.numComps,
  12579. alpha01);
  12580. },
  12581. isPassthrough: ColorSpace.prototype.isPassthrough,
  12582. fillRgb: ColorSpace.prototype.fillRgb,
  12583. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  12584. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12585. },
  12586. usesZeroToOneRange: true
  12587. };
  12588. return AlternateCS;
  12589. })();
  12590. var PatternCS = (function PatternCSClosure() {
  12591. function PatternCS(baseCS) {
  12592. this.name = 'Pattern';
  12593. this.base = baseCS;
  12594. }
  12595. PatternCS.prototype = {};
  12596. return PatternCS;
  12597. })();
  12598. var IndexedCS = (function IndexedCSClosure() {
  12599. function IndexedCS(base, highVal, lookup) {
  12600. this.name = 'Indexed';
  12601. this.numComps = 1;
  12602. this.defaultColor = new Uint8Array([0]);
  12603. this.base = base;
  12604. this.highVal = highVal;
  12605. var baseNumComps = base.numComps;
  12606. var length = baseNumComps * highVal;
  12607. var lookupArray;
  12608. if (isStream(lookup)) {
  12609. lookupArray = new Uint8Array(length);
  12610. var bytes = lookup.getBytes(length);
  12611. lookupArray.set(bytes);
  12612. } else if (isString(lookup)) {
  12613. lookupArray = new Uint8Array(length);
  12614. for (var i = 0; i < length; ++i) {
  12615. lookupArray[i] = lookup.charCodeAt(i);
  12616. }
  12617. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  12618. lookupArray = lookup;
  12619. } else {
  12620. error('Unrecognized lookup table: ' + lookup);
  12621. }
  12622. this.lookup = lookupArray;
  12623. }
  12624. IndexedCS.prototype = {
  12625. getRgb: ColorSpace.prototype.getRgb,
  12626. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  12627. dest, destOffset) {
  12628. var numComps = this.base.numComps;
  12629. var start = src[srcOffset] * numComps;
  12630. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  12631. },
  12632. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  12633. dest, destOffset, bits,
  12634. alpha01) {
  12635. var base = this.base;
  12636. var numComps = base.numComps;
  12637. var outputDelta = base.getOutputLength(numComps, alpha01);
  12638. var lookup = this.lookup;
  12639. for (var i = 0; i < count; ++i) {
  12640. var lookupPos = src[srcOffset++] * numComps;
  12641. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  12642. destOffset += outputDelta;
  12643. }
  12644. },
  12645. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  12646. return this.base.getOutputLength(inputLength * this.base.numComps,
  12647. alpha01);
  12648. },
  12649. isPassthrough: ColorSpace.prototype.isPassthrough,
  12650. fillRgb: ColorSpace.prototype.fillRgb,
  12651. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  12652. // indexed color maps shouldn't be changed
  12653. return true;
  12654. },
  12655. usesZeroToOneRange: true
  12656. };
  12657. return IndexedCS;
  12658. })();
  12659. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  12660. function DeviceGrayCS() {
  12661. this.name = 'DeviceGray';
  12662. this.numComps = 1;
  12663. this.defaultColor = new Float32Array([0]);
  12664. }
  12665. DeviceGrayCS.prototype = {
  12666. getRgb: ColorSpace.prototype.getRgb,
  12667. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  12668. dest, destOffset) {
  12669. var c = (src[srcOffset] * 255) | 0;
  12670. c = c < 0 ? 0 : c > 255 ? 255 : c;
  12671. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  12672. },
  12673. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  12674. dest, destOffset, bits,
  12675. alpha01) {
  12676. var scale = 255 / ((1 << bits) - 1);
  12677. var j = srcOffset, q = destOffset;
  12678. for (var i = 0; i < count; ++i) {
  12679. var c = (scale * src[j++]) | 0;
  12680. dest[q++] = c;
  12681. dest[q++] = c;
  12682. dest[q++] = c;
  12683. q += alpha01;
  12684. }
  12685. },
  12686. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  12687. alpha01) {
  12688. return inputLength * (3 + alpha01);
  12689. },
  12690. isPassthrough: ColorSpace.prototype.isPassthrough,
  12691. fillRgb: ColorSpace.prototype.fillRgb,
  12692. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  12693. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12694. },
  12695. usesZeroToOneRange: true
  12696. };
  12697. return DeviceGrayCS;
  12698. })();
  12699. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  12700. function DeviceRgbCS() {
  12701. this.name = 'DeviceRGB';
  12702. this.numComps = 3;
  12703. this.defaultColor = new Float32Array([0, 0, 0]);
  12704. }
  12705. DeviceRgbCS.prototype = {
  12706. getRgb: ColorSpace.prototype.getRgb,
  12707. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  12708. dest, destOffset) {
  12709. var r = (src[srcOffset] * 255) | 0;
  12710. var g = (src[srcOffset + 1] * 255) | 0;
  12711. var b = (src[srcOffset + 2] * 255) | 0;
  12712. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  12713. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  12714. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  12715. },
  12716. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  12717. dest, destOffset, bits,
  12718. alpha01) {
  12719. if (bits === 8 && alpha01 === 0) {
  12720. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  12721. return;
  12722. }
  12723. var scale = 255 / ((1 << bits) - 1);
  12724. var j = srcOffset, q = destOffset;
  12725. for (var i = 0; i < count; ++i) {
  12726. dest[q++] = (scale * src[j++]) | 0;
  12727. dest[q++] = (scale * src[j++]) | 0;
  12728. dest[q++] = (scale * src[j++]) | 0;
  12729. q += alpha01;
  12730. }
  12731. },
  12732. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  12733. alpha01) {
  12734. return (inputLength * (3 + alpha01) / 3) | 0;
  12735. },
  12736. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  12737. return bits === 8;
  12738. },
  12739. fillRgb: ColorSpace.prototype.fillRgb,
  12740. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  12741. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12742. },
  12743. usesZeroToOneRange: true
  12744. };
  12745. return DeviceRgbCS;
  12746. })();
  12747. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  12748. // The coefficients below was found using numerical analysis: the method of
  12749. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  12750. // where color_value is the tabular value from the table of sampled RGB colors
  12751. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  12752. // CMYK color conversion using the estimation below:
  12753. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  12754. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  12755. var c = src[srcOffset + 0] * srcScale;
  12756. var m = src[srcOffset + 1] * srcScale;
  12757. var y = src[srcOffset + 2] * srcScale;
  12758. var k = src[srcOffset + 3] * srcScale;
  12759. var r =
  12760. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  12761. 18.82290502165302 * y + 212.25662451639585 * k +
  12762. -285.2331026137004) +
  12763. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  12764. -17.873870861415444 * k - 5.497006427196366) +
  12765. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  12766. 17.5119270841813) +
  12767. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  12768. var g =
  12769. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  12770. 6.871425592049007 * y + 31.159100130055922 * k +
  12771. -79.2970844816548) +
  12772. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  12773. 131.35250912493976 * k - 190.9453302588951) +
  12774. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  12775. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  12776. var b =
  12777. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  12778. 30.89978309703729 * y - 0.23883238689178934 * k +
  12779. -14.183576799673286) +
  12780. m * (10.49593273432072 * m + 63.02378494754052 * y +
  12781. 50.606957656360734 * k - 112.23884253719248) +
  12782. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  12783. -193.58209356861505) +
  12784. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  12785. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  12786. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  12787. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  12788. }
  12789. function DeviceCmykCS() {
  12790. this.name = 'DeviceCMYK';
  12791. this.numComps = 4;
  12792. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  12793. }
  12794. DeviceCmykCS.prototype = {
  12795. getRgb: ColorSpace.prototype.getRgb,
  12796. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  12797. dest, destOffset) {
  12798. convertToRgb(src, srcOffset, 1, dest, destOffset);
  12799. },
  12800. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  12801. dest, destOffset, bits,
  12802. alpha01) {
  12803. var scale = 1 / ((1 << bits) - 1);
  12804. for (var i = 0; i < count; i++) {
  12805. convertToRgb(src, srcOffset, scale, dest, destOffset);
  12806. srcOffset += 4;
  12807. destOffset += 3 + alpha01;
  12808. }
  12809. },
  12810. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  12811. alpha01) {
  12812. return (inputLength / 4 * (3 + alpha01)) | 0;
  12813. },
  12814. isPassthrough: ColorSpace.prototype.isPassthrough,
  12815. fillRgb: ColorSpace.prototype.fillRgb,
  12816. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  12817. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12818. },
  12819. usesZeroToOneRange: true
  12820. };
  12821. return DeviceCmykCS;
  12822. })();
  12823. //
  12824. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  12825. //
  12826. var CalGrayCS = (function CalGrayCSClosure() {
  12827. function CalGrayCS(whitePoint, blackPoint, gamma) {
  12828. this.name = 'CalGray';
  12829. this.numComps = 1;
  12830. this.defaultColor = new Float32Array([0]);
  12831. if (!whitePoint) {
  12832. error('WhitePoint missing - required for color space CalGray');
  12833. }
  12834. blackPoint = blackPoint || [0, 0, 0];
  12835. gamma = gamma || 1;
  12836. // Translate arguments to spec variables.
  12837. this.XW = whitePoint[0];
  12838. this.YW = whitePoint[1];
  12839. this.ZW = whitePoint[2];
  12840. this.XB = blackPoint[0];
  12841. this.YB = blackPoint[1];
  12842. this.ZB = blackPoint[2];
  12843. this.G = gamma;
  12844. // Validate variables as per spec.
  12845. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  12846. error('Invalid WhitePoint components for ' + this.name +
  12847. ', no fallback available');
  12848. }
  12849. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  12850. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  12851. this.XB = this.YB = this.ZB = 0;
  12852. }
  12853. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  12854. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  12855. ', ZB: ' + this.ZB + ', only default values are supported.');
  12856. }
  12857. if (this.G < 1) {
  12858. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  12859. ', falling back to default');
  12860. this.G = 1;
  12861. }
  12862. }
  12863. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  12864. // A represents a gray component of a calibrated gray space.
  12865. // A <---> AG in the spec
  12866. var A = src[srcOffset] * scale;
  12867. var AG = Math.pow(A, cs.G);
  12868. // Computes L as per spec. ( = cs.YW * AG )
  12869. // Except if other than default BlackPoint values are used.
  12870. var L = cs.YW * AG;
  12871. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  12872. // Convert values to rgb range [0, 255].
  12873. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  12874. dest[destOffset] = val;
  12875. dest[destOffset + 1] = val;
  12876. dest[destOffset + 2] = val;
  12877. }
  12878. CalGrayCS.prototype = {
  12879. getRgb: ColorSpace.prototype.getRgb,
  12880. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  12881. dest, destOffset) {
  12882. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  12883. },
  12884. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  12885. dest, destOffset, bits,
  12886. alpha01) {
  12887. var scale = 1 / ((1 << bits) - 1);
  12888. for (var i = 0; i < count; ++i) {
  12889. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  12890. srcOffset += 1;
  12891. destOffset += 3 + alpha01;
  12892. }
  12893. },
  12894. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  12895. return inputLength * (3 + alpha01);
  12896. },
  12897. isPassthrough: ColorSpace.prototype.isPassthrough,
  12898. fillRgb: ColorSpace.prototype.fillRgb,
  12899. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  12900. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  12901. },
  12902. usesZeroToOneRange: true
  12903. };
  12904. return CalGrayCS;
  12905. })();
  12906. //
  12907. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  12908. //
  12909. var CalRGBCS = (function CalRGBCSClosure() {
  12910. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  12911. // matrices.
  12912. var BRADFORD_SCALE_MATRIX = new Float32Array([
  12913. 0.8951, 0.2664, -0.1614,
  12914. -0.7502, 1.7135, 0.0367,
  12915. 0.0389, -0.0685, 1.0296]);
  12916. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  12917. 0.9869929, -0.1470543, 0.1599627,
  12918. 0.4323053, 0.5183603, 0.0492912,
  12919. -0.0085287, 0.0400428, 0.9684867]);
  12920. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  12921. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  12922. 3.2404542, -1.5371385, -0.4985314,
  12923. -0.9692660, 1.8760108, 0.0415560,
  12924. 0.0556434, -0.2040259, 1.0572252]);
  12925. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  12926. var tempNormalizeMatrix = new Float32Array(3);
  12927. var tempConvertMatrix1 = new Float32Array(3);
  12928. var tempConvertMatrix2 = new Float32Array(3);
  12929. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  12930. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  12931. this.name = 'CalRGB';
  12932. this.numComps = 3;
  12933. this.defaultColor = new Float32Array(3);
  12934. if (!whitePoint) {
  12935. error('WhitePoint missing - required for color space CalRGB');
  12936. }
  12937. blackPoint = blackPoint || new Float32Array(3);
  12938. gamma = gamma || new Float32Array([1, 1, 1]);
  12939. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  12940. // Translate arguments to spec variables.
  12941. var XW = whitePoint[0];
  12942. var YW = whitePoint[1];
  12943. var ZW = whitePoint[2];
  12944. this.whitePoint = whitePoint;
  12945. var XB = blackPoint[0];
  12946. var YB = blackPoint[1];
  12947. var ZB = blackPoint[2];
  12948. this.blackPoint = blackPoint;
  12949. this.GR = gamma[0];
  12950. this.GG = gamma[1];
  12951. this.GB = gamma[2];
  12952. this.MXA = matrix[0];
  12953. this.MYA = matrix[1];
  12954. this.MZA = matrix[2];
  12955. this.MXB = matrix[3];
  12956. this.MYB = matrix[4];
  12957. this.MZB = matrix[5];
  12958. this.MXC = matrix[6];
  12959. this.MYC = matrix[7];
  12960. this.MZC = matrix[8];
  12961. // Validate variables as per spec.
  12962. if (XW < 0 || ZW < 0 || YW !== 1) {
  12963. error('Invalid WhitePoint components for ' + this.name +
  12964. ', no fallback available');
  12965. }
  12966. if (XB < 0 || YB < 0 || ZB < 0) {
  12967. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  12968. ', ' + ZB + '], falling back to default');
  12969. this.blackPoint = new Float32Array(3);
  12970. }
  12971. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  12972. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  12973. '] for ' + this.name + ', falling back to default');
  12974. this.GR = this.GG = this.GB = 1;
  12975. }
  12976. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  12977. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  12978. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  12979. info('Invalid Matrix for ' + this.name + ' [' +
  12980. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  12981. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  12982. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  12983. '], falling back to default');
  12984. this.MXA = this.MYB = this.MZC = 1;
  12985. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  12986. }
  12987. }
  12988. function matrixProduct(a, b, result) {
  12989. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  12990. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  12991. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  12992. }
  12993. function convertToFlat(sourceWhitePoint, LMS, result) {
  12994. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  12995. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  12996. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  12997. }
  12998. function convertToD65(sourceWhitePoint, LMS, result) {
  12999. var D65X = 0.95047;
  13000. var D65Y = 1;
  13001. var D65Z = 1.08883;
  13002. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  13003. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  13004. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  13005. }
  13006. function sRGBTransferFunction(color) {
  13007. // See http://en.wikipedia.org/wiki/SRGB.
  13008. if (color <= 0.0031308){
  13009. return adjustToRange(0, 1, 12.92 * color);
  13010. }
  13011. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  13012. }
  13013. function adjustToRange(min, max, value) {
  13014. return Math.max(min, Math.min(max, value));
  13015. }
  13016. function decodeL(L) {
  13017. if (L < 0) {
  13018. return -decodeL(-L);
  13019. }
  13020. if (L > 8.0) {
  13021. return Math.pow(((L + 16) / 116), 3);
  13022. }
  13023. return L * DECODE_L_CONSTANT;
  13024. }
  13025. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  13026. // In case the blackPoint is already the default blackPoint then there is
  13027. // no need to do compensation.
  13028. if (sourceBlackPoint[0] === 0 &&
  13029. sourceBlackPoint[1] === 0 &&
  13030. sourceBlackPoint[2] === 0) {
  13031. result[0] = XYZ_Flat[0];
  13032. result[1] = XYZ_Flat[1];
  13033. result[2] = XYZ_Flat[2];
  13034. return;
  13035. }
  13036. // For the blackPoint calculation details, please see
  13037. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  13038. // AdobeBPC.pdf.
  13039. // The destination blackPoint is the default blackPoint [0, 0, 0].
  13040. var zeroDecodeL = decodeL(0);
  13041. var X_DST = zeroDecodeL;
  13042. var X_SRC = decodeL(sourceBlackPoint[0]);
  13043. var Y_DST = zeroDecodeL;
  13044. var Y_SRC = decodeL(sourceBlackPoint[1]);
  13045. var Z_DST = zeroDecodeL;
  13046. var Z_SRC = decodeL(sourceBlackPoint[2]);
  13047. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  13048. var X_Offset = 1 - X_Scale;
  13049. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  13050. var Y_Offset = 1 - Y_Scale;
  13051. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  13052. var Z_Offset = 1 - Z_Scale;
  13053. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  13054. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  13055. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  13056. }
  13057. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  13058. // In case the whitePoint is already flat then there is no need to do
  13059. // normalization.
  13060. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  13061. result[0] = XYZ_In[0];
  13062. result[1] = XYZ_In[1];
  13063. result[2] = XYZ_In[2];
  13064. return;
  13065. }
  13066. var LMS = result;
  13067. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  13068. var LMS_Flat = tempNormalizeMatrix;
  13069. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  13070. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  13071. }
  13072. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  13073. var LMS = result;
  13074. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  13075. var LMS_D65 = tempNormalizeMatrix;
  13076. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  13077. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  13078. }
  13079. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  13080. // A, B and C represent a red, green and blue components of a calibrated
  13081. // rgb space.
  13082. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  13083. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  13084. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  13085. // A <---> AGR in the spec
  13086. // B <---> BGG in the spec
  13087. // C <---> CGB in the spec
  13088. var AGR = Math.pow(A, cs.GR);
  13089. var BGG = Math.pow(B, cs.GG);
  13090. var CGB = Math.pow(C, cs.GB);
  13091. // Computes intermediate variables L, M, N as per spec.
  13092. // To decode X, Y, Z values map L, M, N directly to them.
  13093. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  13094. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  13095. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  13096. // The following calculations are based on this document:
  13097. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  13098. // AdobeBPC.pdf.
  13099. var XYZ = tempConvertMatrix1;
  13100. XYZ[0] = X;
  13101. XYZ[1] = Y;
  13102. XYZ[2] = Z;
  13103. var XYZ_Flat = tempConvertMatrix2;
  13104. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  13105. var XYZ_Black = tempConvertMatrix1;
  13106. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  13107. var XYZ_D65 = tempConvertMatrix2;
  13108. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  13109. var SRGB = tempConvertMatrix1;
  13110. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  13111. var sR = sRGBTransferFunction(SRGB[0]);
  13112. var sG = sRGBTransferFunction(SRGB[1]);
  13113. var sB = sRGBTransferFunction(SRGB[2]);
  13114. // Convert the values to rgb range [0, 255].
  13115. dest[destOffset] = Math.round(sR * 255);
  13116. dest[destOffset + 1] = Math.round(sG * 255);
  13117. dest[destOffset + 2] = Math.round(sB * 255);
  13118. }
  13119. CalRGBCS.prototype = {
  13120. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  13121. var rgb = new Uint8Array(3);
  13122. this.getRgbItem(src, srcOffset, rgb, 0);
  13123. return rgb;
  13124. },
  13125. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  13126. dest, destOffset) {
  13127. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  13128. },
  13129. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  13130. dest, destOffset, bits,
  13131. alpha01) {
  13132. var scale = 1 / ((1 << bits) - 1);
  13133. for (var i = 0; i < count; ++i) {
  13134. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  13135. srcOffset += 3;
  13136. destOffset += 3 + alpha01;
  13137. }
  13138. },
  13139. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  13140. return (inputLength * (3 + alpha01) / 3) | 0;
  13141. },
  13142. isPassthrough: ColorSpace.prototype.isPassthrough,
  13143. fillRgb: ColorSpace.prototype.fillRgb,
  13144. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  13145. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  13146. },
  13147. usesZeroToOneRange: true
  13148. };
  13149. return CalRGBCS;
  13150. })();
  13151. //
  13152. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  13153. //
  13154. var LabCS = (function LabCSClosure() {
  13155. function LabCS(whitePoint, blackPoint, range) {
  13156. this.name = 'Lab';
  13157. this.numComps = 3;
  13158. this.defaultColor = new Float32Array([0, 0, 0]);
  13159. if (!whitePoint) {
  13160. error('WhitePoint missing - required for color space Lab');
  13161. }
  13162. blackPoint = blackPoint || [0, 0, 0];
  13163. range = range || [-100, 100, -100, 100];
  13164. // Translate args to spec variables
  13165. this.XW = whitePoint[0];
  13166. this.YW = whitePoint[1];
  13167. this.ZW = whitePoint[2];
  13168. this.amin = range[0];
  13169. this.amax = range[1];
  13170. this.bmin = range[2];
  13171. this.bmax = range[3];
  13172. // These are here just for completeness - the spec doesn't offer any
  13173. // formulas that use BlackPoint in Lab
  13174. this.XB = blackPoint[0];
  13175. this.YB = blackPoint[1];
  13176. this.ZB = blackPoint[2];
  13177. // Validate vars as per spec
  13178. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  13179. error('Invalid WhitePoint components, no fallback available');
  13180. }
  13181. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  13182. info('Invalid BlackPoint, falling back to default');
  13183. this.XB = this.YB = this.ZB = 0;
  13184. }
  13185. if (this.amin > this.amax || this.bmin > this.bmax) {
  13186. info('Invalid Range, falling back to defaults');
  13187. this.amin = -100;
  13188. this.amax = 100;
  13189. this.bmin = -100;
  13190. this.bmax = 100;
  13191. }
  13192. }
  13193. // Function g(x) from spec
  13194. function fn_g(x) {
  13195. if (x >= 6 / 29) {
  13196. return x * x * x;
  13197. } else {
  13198. return (108 / 841) * (x - 4 / 29);
  13199. }
  13200. }
  13201. function decode(value, high1, low2, high2) {
  13202. return low2 + (value) * (high2 - low2) / (high1);
  13203. }
  13204. // If decoding is needed maxVal should be 2^bits per component - 1.
  13205. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  13206. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  13207. // not the usual [0, 1]. If a command like setFillColor is used the src
  13208. // values will already be within the correct range. However, if we are
  13209. // converting an image we have to map the values to the correct range given
  13210. // above.
  13211. // Ls,as,bs <---> L*,a*,b* in the spec
  13212. var Ls = src[srcOffset];
  13213. var as = src[srcOffset + 1];
  13214. var bs = src[srcOffset + 2];
  13215. if (maxVal !== false) {
  13216. Ls = decode(Ls, maxVal, 0, 100);
  13217. as = decode(as, maxVal, cs.amin, cs.amax);
  13218. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  13219. }
  13220. // Adjust limits of 'as' and 'bs'
  13221. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  13222. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  13223. // Computes intermediate variables X,Y,Z as per spec
  13224. var M = (Ls + 16) / 116;
  13225. var L = M + (as / 500);
  13226. var N = M - (bs / 200);
  13227. var X = cs.XW * fn_g(L);
  13228. var Y = cs.YW * fn_g(M);
  13229. var Z = cs.ZW * fn_g(N);
  13230. var r, g, b;
  13231. // Using different conversions for D50 and D65 white points,
  13232. // per http://www.color.org/srgb.pdf
  13233. if (cs.ZW < 1) {
  13234. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  13235. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  13236. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  13237. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  13238. } else {
  13239. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  13240. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  13241. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  13242. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  13243. }
  13244. // clamp color values to [0,1] range then convert to [0,255] range.
  13245. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  13246. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  13247. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  13248. }
  13249. LabCS.prototype = {
  13250. getRgb: ColorSpace.prototype.getRgb,
  13251. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  13252. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  13253. },
  13254. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  13255. dest, destOffset, bits,
  13256. alpha01) {
  13257. var maxVal = (1 << bits) - 1;
  13258. for (var i = 0; i < count; i++) {
  13259. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  13260. srcOffset += 3;
  13261. destOffset += 3 + alpha01;
  13262. }
  13263. },
  13264. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  13265. return (inputLength * (3 + alpha01) / 3) | 0;
  13266. },
  13267. isPassthrough: ColorSpace.prototype.isPassthrough,
  13268. fillRgb: ColorSpace.prototype.fillRgb,
  13269. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  13270. // XXX: Decoding is handled with the lab conversion because of the strange
  13271. // ranges that are used.
  13272. return true;
  13273. },
  13274. usesZeroToOneRange: false
  13275. };
  13276. return LabCS;
  13277. })();
  13278. var ARCFourCipher = (function ARCFourCipherClosure() {
  13279. function ARCFourCipher(key) {
  13280. this.a = 0;
  13281. this.b = 0;
  13282. var s = new Uint8Array(256);
  13283. var i, j = 0, tmp, keyLength = key.length;
  13284. for (i = 0; i < 256; ++i) {
  13285. s[i] = i;
  13286. }
  13287. for (i = 0; i < 256; ++i) {
  13288. tmp = s[i];
  13289. j = (j + tmp + key[i % keyLength]) & 0xFF;
  13290. s[i] = s[j];
  13291. s[j] = tmp;
  13292. }
  13293. this.s = s;
  13294. }
  13295. ARCFourCipher.prototype = {
  13296. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  13297. var i, n = data.length, tmp, tmp2;
  13298. var a = this.a, b = this.b, s = this.s;
  13299. var output = new Uint8Array(n);
  13300. for (i = 0; i < n; ++i) {
  13301. a = (a + 1) & 0xFF;
  13302. tmp = s[a];
  13303. b = (b + tmp) & 0xFF;
  13304. tmp2 = s[b];
  13305. s[a] = tmp2;
  13306. s[b] = tmp;
  13307. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  13308. }
  13309. this.a = a;
  13310. this.b = b;
  13311. return output;
  13312. }
  13313. };
  13314. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  13315. return ARCFourCipher;
  13316. })();
  13317. var calculateMD5 = (function calculateMD5Closure() {
  13318. var r = new Uint8Array([
  13319. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  13320. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  13321. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  13322. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  13323. var k = new Int32Array([
  13324. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  13325. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  13326. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  13327. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  13328. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  13329. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  13330. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  13331. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  13332. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  13333. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  13334. -145523070, -1120210379, 718787259, -343485551]);
  13335. function hash(data, offset, length) {
  13336. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  13337. // pre-processing
  13338. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  13339. var padded = new Uint8Array(paddedLength);
  13340. var i, j, n;
  13341. for (i = 0; i < length; ++i) {
  13342. padded[i] = data[offset++];
  13343. }
  13344. padded[i++] = 0x80;
  13345. n = paddedLength - 8;
  13346. while (i < n) {
  13347. padded[i++] = 0;
  13348. }
  13349. padded[i++] = (length << 3) & 0xFF;
  13350. padded[i++] = (length >> 5) & 0xFF;
  13351. padded[i++] = (length >> 13) & 0xFF;
  13352. padded[i++] = (length >> 21) & 0xFF;
  13353. padded[i++] = (length >>> 29) & 0xFF;
  13354. padded[i++] = 0;
  13355. padded[i++] = 0;
  13356. padded[i++] = 0;
  13357. var w = new Int32Array(16);
  13358. for (i = 0; i < paddedLength;) {
  13359. for (j = 0; j < 16; ++j, i += 4) {
  13360. w[j] = (padded[i] | (padded[i + 1] << 8) |
  13361. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  13362. }
  13363. var a = h0, b = h1, c = h2, d = h3, f, g;
  13364. for (j = 0; j < 64; ++j) {
  13365. if (j < 16) {
  13366. f = (b & c) | ((~b) & d);
  13367. g = j;
  13368. } else if (j < 32) {
  13369. f = (d & b) | ((~d) & c);
  13370. g = (5 * j + 1) & 15;
  13371. } else if (j < 48) {
  13372. f = b ^ c ^ d;
  13373. g = (3 * j + 5) & 15;
  13374. } else {
  13375. f = c ^ (b | (~d));
  13376. g = (7 * j) & 15;
  13377. }
  13378. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  13379. d = c;
  13380. c = b;
  13381. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  13382. a = tmp;
  13383. }
  13384. h0 = (h0 + a) | 0;
  13385. h1 = (h1 + b) | 0;
  13386. h2 = (h2 + c) | 0;
  13387. h3 = (h3 + d) | 0;
  13388. }
  13389. return new Uint8Array([
  13390. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  13391. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  13392. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  13393. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  13394. ]);
  13395. }
  13396. return hash;
  13397. })();
  13398. var Word64 = (function Word64Closure() {
  13399. function Word64(highInteger, lowInteger) {
  13400. this.high = highInteger | 0;
  13401. this.low = lowInteger | 0;
  13402. }
  13403. Word64.prototype = {
  13404. and: function Word64_and(word) {
  13405. this.high &= word.high;
  13406. this.low &= word.low;
  13407. },
  13408. xor: function Word64_xor(word) {
  13409. this.high ^= word.high;
  13410. this.low ^= word.low;
  13411. },
  13412. or: function Word64_or(word) {
  13413. this.high |= word.high;
  13414. this.low |= word.low;
  13415. },
  13416. shiftRight: function Word64_shiftRight(places) {
  13417. if (places >= 32) {
  13418. this.low = (this.high >>> (places - 32)) | 0;
  13419. this.high = 0;
  13420. } else {
  13421. this.low = (this.low >>> places) | (this.high << (32 - places));
  13422. this.high = (this.high >>> places) | 0;
  13423. }
  13424. },
  13425. shiftLeft: function Word64_shiftLeft(places) {
  13426. if (places >= 32) {
  13427. this.high = this.low << (places - 32);
  13428. this.low = 0;
  13429. } else {
  13430. this.high = (this.high << places) | (this.low >>> (32 - places));
  13431. this.low = this.low << places;
  13432. }
  13433. },
  13434. rotateRight: function Word64_rotateRight(places) {
  13435. var low, high;
  13436. if (places & 32) {
  13437. high = this.low;
  13438. low = this.high;
  13439. } else {
  13440. low = this.low;
  13441. high = this.high;
  13442. }
  13443. places &= 31;
  13444. this.low = (low >>> places) | (high << (32 - places));
  13445. this.high = (high >>> places) | (low << (32 - places));
  13446. },
  13447. not: function Word64_not() {
  13448. this.high = ~this.high;
  13449. this.low = ~this.low;
  13450. },
  13451. add: function Word64_add(word) {
  13452. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  13453. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  13454. if (lowAdd > 0xFFFFFFFF) {
  13455. highAdd += 1;
  13456. }
  13457. this.low = lowAdd | 0;
  13458. this.high = highAdd | 0;
  13459. },
  13460. copyTo: function Word64_copyTo(bytes, offset) {
  13461. bytes[offset] = (this.high >>> 24) & 0xFF;
  13462. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  13463. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  13464. bytes[offset + 3] = this.high & 0xFF;
  13465. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  13466. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  13467. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  13468. bytes[offset + 7] = this.low & 0xFF;
  13469. },
  13470. assign: function Word64_assign(word) {
  13471. this.high = word.high;
  13472. this.low = word.low;
  13473. }
  13474. };
  13475. return Word64;
  13476. })();
  13477. var calculateSHA256 = (function calculateSHA256Closure() {
  13478. function rotr(x, n) {
  13479. return (x >>> n) | (x << 32 - n);
  13480. }
  13481. function ch(x, y, z) {
  13482. return (x & y) ^ (~x & z);
  13483. }
  13484. function maj(x, y, z) {
  13485. return (x & y) ^ (x & z) ^ (y & z);
  13486. }
  13487. function sigma(x) {
  13488. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  13489. }
  13490. function sigmaPrime(x) {
  13491. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  13492. }
  13493. function littleSigma(x) {
  13494. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  13495. }
  13496. function littleSigmaPrime(x) {
  13497. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  13498. }
  13499. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  13500. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  13501. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  13502. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  13503. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  13504. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  13505. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  13506. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  13507. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  13508. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  13509. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  13510. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  13511. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  13512. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  13513. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  13514. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  13515. function hash(data, offset, length) {
  13516. // initial hash values
  13517. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  13518. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  13519. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  13520. // pre-processing
  13521. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  13522. var padded = new Uint8Array(paddedLength);
  13523. var i, j, n;
  13524. for (i = 0; i < length; ++i) {
  13525. padded[i] = data[offset++];
  13526. }
  13527. padded[i++] = 0x80;
  13528. n = paddedLength - 8;
  13529. while (i < n) {
  13530. padded[i++] = 0;
  13531. }
  13532. padded[i++] = 0;
  13533. padded[i++] = 0;
  13534. padded[i++] = 0;
  13535. padded[i++] = (length >>> 29) & 0xFF;
  13536. padded[i++] = (length >> 21) & 0xFF;
  13537. padded[i++] = (length >> 13) & 0xFF;
  13538. padded[i++] = (length >> 5) & 0xFF;
  13539. padded[i++] = (length << 3) & 0xFF;
  13540. var w = new Uint32Array(64);
  13541. // for each 512 bit block
  13542. for (i = 0; i < paddedLength;) {
  13543. for (j = 0; j < 16; ++j) {
  13544. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  13545. (padded[i + 2] << 8) | (padded[i + 3]));
  13546. i += 4;
  13547. }
  13548. for (j = 16; j < 64; ++j) {
  13549. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  13550. littleSigma(w[j - 15]) + w[j - 16] | 0;
  13551. }
  13552. var a = h0, b = h1, c = h2, d = h3, e = h4,
  13553. f = h5, g = h6, h = h7, t1, t2;
  13554. for (j = 0; j < 64; ++j) {
  13555. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  13556. t2 = sigma(a) + maj(a, b, c);
  13557. h = g;
  13558. g = f;
  13559. f = e;
  13560. e = (d + t1) | 0;
  13561. d = c;
  13562. c = b;
  13563. b = a;
  13564. a = (t1 + t2) | 0;
  13565. }
  13566. h0 = (h0 + a) | 0;
  13567. h1 = (h1 + b) | 0;
  13568. h2 = (h2 + c) | 0;
  13569. h3 = (h3 + d) | 0;
  13570. h4 = (h4 + e) | 0;
  13571. h5 = (h5 + f) | 0;
  13572. h6 = (h6 + g) | 0;
  13573. h7 = (h7 + h) | 0;
  13574. }
  13575. return new Uint8Array([
  13576. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  13577. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  13578. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  13579. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  13580. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  13581. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  13582. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  13583. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  13584. ]);
  13585. }
  13586. return hash;
  13587. })();
  13588. var calculateSHA512 = (function calculateSHA512Closure() {
  13589. function ch(result, x, y, z, tmp) {
  13590. result.assign(x);
  13591. result.and(y);
  13592. tmp.assign(x);
  13593. tmp.not();
  13594. tmp.and(z);
  13595. result.xor(tmp);
  13596. }
  13597. function maj(result, x, y, z, tmp) {
  13598. result.assign(x);
  13599. result.and(y);
  13600. tmp.assign(x);
  13601. tmp.and(z);
  13602. result.xor(tmp);
  13603. tmp.assign(y);
  13604. tmp.and(z);
  13605. result.xor(tmp);
  13606. }
  13607. function sigma(result, x, tmp) {
  13608. result.assign(x);
  13609. result.rotateRight(28);
  13610. tmp.assign(x);
  13611. tmp.rotateRight(34);
  13612. result.xor(tmp);
  13613. tmp.assign(x);
  13614. tmp.rotateRight(39);
  13615. result.xor(tmp);
  13616. }
  13617. function sigmaPrime(result, x, tmp) {
  13618. result.assign(x);
  13619. result.rotateRight(14);
  13620. tmp.assign(x);
  13621. tmp.rotateRight(18);
  13622. result.xor(tmp);
  13623. tmp.assign(x);
  13624. tmp.rotateRight(41);
  13625. result.xor(tmp);
  13626. }
  13627. function littleSigma(result, x, tmp) {
  13628. result.assign(x);
  13629. result.rotateRight(1);
  13630. tmp.assign(x);
  13631. tmp.rotateRight(8);
  13632. result.xor(tmp);
  13633. tmp.assign(x);
  13634. tmp.shiftRight(7);
  13635. result.xor(tmp);
  13636. }
  13637. function littleSigmaPrime(result, x, tmp) {
  13638. result.assign(x);
  13639. result.rotateRight(19);
  13640. tmp.assign(x);
  13641. tmp.rotateRight(61);
  13642. result.xor(tmp);
  13643. tmp.assign(x);
  13644. tmp.shiftRight(6);
  13645. result.xor(tmp);
  13646. }
  13647. var k = [
  13648. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  13649. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  13650. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  13651. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  13652. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  13653. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  13654. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  13655. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  13656. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  13657. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  13658. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  13659. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  13660. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  13661. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  13662. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  13663. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  13664. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  13665. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  13666. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  13667. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  13668. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  13669. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  13670. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  13671. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  13672. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  13673. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  13674. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  13675. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  13676. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  13677. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  13678. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  13679. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  13680. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  13681. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  13682. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  13683. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  13684. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  13685. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  13686. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  13687. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  13688. function hash(data, offset, length, mode384) {
  13689. mode384 = !!mode384;
  13690. // initial hash values
  13691. var h0, h1, h2, h3, h4, h5, h6, h7;
  13692. if (!mode384) {
  13693. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  13694. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  13695. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  13696. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  13697. h4 = new Word64(0x510e527f, 0xade682d1);
  13698. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  13699. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  13700. h7 = new Word64(0x5be0cd19, 0x137e2179);
  13701. }
  13702. else {
  13703. // SHA384 is exactly the same
  13704. // except with different starting values and a trimmed result
  13705. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  13706. h1 = new Word64(0x629a292a, 0x367cd507);
  13707. h2 = new Word64(0x9159015a, 0x3070dd17);
  13708. h3 = new Word64(0x152fecd8, 0xf70e5939);
  13709. h4 = new Word64(0x67332667, 0xffc00b31);
  13710. h5 = new Word64(0x8eb44a87, 0x68581511);
  13711. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  13712. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  13713. }
  13714. // pre-processing
  13715. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  13716. var padded = new Uint8Array(paddedLength);
  13717. var i, j, n;
  13718. for (i = 0; i < length; ++i) {
  13719. padded[i] = data[offset++];
  13720. }
  13721. padded[i++] = 0x80;
  13722. n = paddedLength - 16;
  13723. while (i < n) {
  13724. padded[i++] = 0;
  13725. }
  13726. padded[i++] = 0;
  13727. padded[i++] = 0;
  13728. padded[i++] = 0;
  13729. padded[i++] = 0;
  13730. padded[i++] = 0;
  13731. padded[i++] = 0;
  13732. padded[i++] = 0;
  13733. padded[i++] = 0;
  13734. padded[i++] = 0;
  13735. padded[i++] = 0;
  13736. padded[i++] = 0;
  13737. padded[i++] = (length >>> 29) & 0xFF;
  13738. padded[i++] = (length >> 21) & 0xFF;
  13739. padded[i++] = (length >> 13) & 0xFF;
  13740. padded[i++] = (length >> 5) & 0xFF;
  13741. padded[i++] = (length << 3) & 0xFF;
  13742. var w = new Array(80);
  13743. for (i = 0; i < 80; i++) {
  13744. w[i] = new Word64(0, 0);
  13745. }
  13746. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  13747. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  13748. var g = new Word64(0, 0), h = new Word64(0, 0);
  13749. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  13750. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  13751. // for each 1024 bit block
  13752. for (i = 0; i < paddedLength;) {
  13753. for (j = 0; j < 16; ++j) {
  13754. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  13755. (padded[i + 2] << 8) | (padded[i + 3]);
  13756. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  13757. (padded[i + 6]) << 8 | (padded[i + 7]);
  13758. i += 8;
  13759. }
  13760. for (j = 16; j < 80; ++j) {
  13761. tmp3 = w[j];
  13762. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  13763. tmp3.add(w[j - 7]);
  13764. littleSigma(tmp1, w[j - 15], tmp2);
  13765. tmp3.add(tmp1);
  13766. tmp3.add(w[j - 16]);
  13767. }
  13768. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  13769. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  13770. for (j = 0; j < 80; ++j) {
  13771. t1.assign(h);
  13772. sigmaPrime(tmp1, e, tmp2);
  13773. t1.add(tmp1);
  13774. ch(tmp1, e, f, g, tmp2);
  13775. t1.add(tmp1);
  13776. t1.add(k[j]);
  13777. t1.add(w[j]);
  13778. sigma(t2, a, tmp2);
  13779. maj(tmp1, a, b, c, tmp2);
  13780. t2.add(tmp1);
  13781. tmp3 = h;
  13782. h = g;
  13783. g = f;
  13784. f = e;
  13785. d.add(t1);
  13786. e = d;
  13787. d = c;
  13788. c = b;
  13789. b = a;
  13790. tmp3.assign(t1);
  13791. tmp3.add(t2);
  13792. a = tmp3;
  13793. }
  13794. h0.add(a);
  13795. h1.add(b);
  13796. h2.add(c);
  13797. h3.add(d);
  13798. h4.add(e);
  13799. h5.add(f);
  13800. h6.add(g);
  13801. h7.add(h);
  13802. }
  13803. var result;
  13804. if (!mode384) {
  13805. result = new Uint8Array(64);
  13806. h0.copyTo(result,0);
  13807. h1.copyTo(result,8);
  13808. h2.copyTo(result,16);
  13809. h3.copyTo(result,24);
  13810. h4.copyTo(result,32);
  13811. h5.copyTo(result,40);
  13812. h6.copyTo(result,48);
  13813. h7.copyTo(result,56);
  13814. }
  13815. else {
  13816. result = new Uint8Array(48);
  13817. h0.copyTo(result,0);
  13818. h1.copyTo(result,8);
  13819. h2.copyTo(result,16);
  13820. h3.copyTo(result,24);
  13821. h4.copyTo(result,32);
  13822. h5.copyTo(result,40);
  13823. }
  13824. return result;
  13825. }
  13826. return hash;
  13827. })();
  13828. var calculateSHA384 = (function calculateSHA384Closure() {
  13829. function hash(data, offset, length) {
  13830. return calculateSHA512(data, offset, length, true);
  13831. }
  13832. return hash;
  13833. })();
  13834. var NullCipher = (function NullCipherClosure() {
  13835. function NullCipher() {
  13836. }
  13837. NullCipher.prototype = {
  13838. decryptBlock: function NullCipher_decryptBlock(data) {
  13839. return data;
  13840. }
  13841. };
  13842. return NullCipher;
  13843. })();
  13844. var AES128Cipher = (function AES128CipherClosure() {
  13845. var rcon = new Uint8Array([
  13846. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13847. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13848. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13849. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13850. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  13851. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  13852. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  13853. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  13854. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  13855. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  13856. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  13857. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  13858. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  13859. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  13860. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  13861. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  13862. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  13863. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  13864. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  13865. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  13866. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  13867. 0x74, 0xe8, 0xcb, 0x8d]);
  13868. var s = new Uint8Array([
  13869. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  13870. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  13871. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  13872. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  13873. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  13874. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  13875. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  13876. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  13877. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  13878. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  13879. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  13880. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  13881. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  13882. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  13883. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  13884. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  13885. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  13886. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  13887. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  13888. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  13889. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  13890. 0xb0, 0x54, 0xbb, 0x16]);
  13891. var inv_s = new Uint8Array([
  13892. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  13893. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  13894. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  13895. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  13896. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  13897. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  13898. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  13899. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  13900. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  13901. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  13902. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  13903. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  13904. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  13905. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  13906. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  13907. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  13908. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  13909. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  13910. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  13911. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  13912. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  13913. 0x55, 0x21, 0x0c, 0x7d]);
  13914. var mixCol = new Uint8Array(256);
  13915. for (var i = 0; i < 256; i++) {
  13916. if (i < 128) {
  13917. mixCol[i] = i << 1;
  13918. } else {
  13919. mixCol[i] = (i << 1) ^ 0x1b;
  13920. }
  13921. }
  13922. var mix = new Uint32Array([
  13923. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  13924. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  13925. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  13926. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  13927. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  13928. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  13929. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  13930. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  13931. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  13932. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  13933. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  13934. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  13935. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  13936. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  13937. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  13938. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  13939. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  13940. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  13941. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  13942. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  13943. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  13944. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  13945. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  13946. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  13947. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  13948. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  13949. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  13950. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  13951. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  13952. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  13953. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  13954. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  13955. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  13956. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  13957. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  13958. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  13959. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  13960. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  13961. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  13962. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  13963. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  13964. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  13965. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  13966. function expandKey128(cipherKey) {
  13967. var b = 176, result = new Uint8Array(b);
  13968. result.set(cipherKey);
  13969. for (var j = 16, i = 1; j < b; ++i) {
  13970. // RotWord
  13971. var t1 = result[j - 3], t2 = result[j - 2],
  13972. t3 = result[j - 1], t4 = result[j - 4];
  13973. // SubWord
  13974. t1 = s[t1];
  13975. t2 = s[t2];
  13976. t3 = s[t3];
  13977. t4 = s[t4];
  13978. // Rcon
  13979. t1 = t1 ^ rcon[i];
  13980. for (var n = 0; n < 4; ++n) {
  13981. result[j] = (t1 ^= result[j - 16]);
  13982. j++;
  13983. result[j] = (t2 ^= result[j - 16]);
  13984. j++;
  13985. result[j] = (t3 ^= result[j - 16]);
  13986. j++;
  13987. result[j] = (t4 ^= result[j - 16]);
  13988. j++;
  13989. }
  13990. }
  13991. return result;
  13992. }
  13993. function decrypt128(input, key) {
  13994. var state = new Uint8Array(16);
  13995. state.set(input);
  13996. var i, j, k;
  13997. var t, u, v;
  13998. // AddRoundKey
  13999. for (j = 0, k = 160; j < 16; ++j, ++k) {
  14000. state[j] ^= key[k];
  14001. }
  14002. for (i = 9; i >= 1; --i) {
  14003. // InvShiftRows
  14004. t = state[13];
  14005. state[13] = state[9];
  14006. state[9] = state[5];
  14007. state[5] = state[1];
  14008. state[1] = t;
  14009. t = state[14];
  14010. u = state[10];
  14011. state[14] = state[6];
  14012. state[10] = state[2];
  14013. state[6] = t;
  14014. state[2] = u;
  14015. t = state[15];
  14016. u = state[11];
  14017. v = state[7];
  14018. state[15] = state[3];
  14019. state[11] = t;
  14020. state[7] = u;
  14021. state[3] = v;
  14022. // InvSubBytes
  14023. for (j = 0; j < 16; ++j) {
  14024. state[j] = inv_s[state[j]];
  14025. }
  14026. // AddRoundKey
  14027. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  14028. state[j] ^= key[k];
  14029. }
  14030. // InvMixColumns
  14031. for (j = 0; j < 16; j += 4) {
  14032. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  14033. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  14034. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  14035. (s3 >>> 24) ^ (s3 << 8));
  14036. state[j] = (t >>> 24) & 0xFF;
  14037. state[j + 1] = (t >> 16) & 0xFF;
  14038. state[j + 2] = (t >> 8) & 0xFF;
  14039. state[j + 3] = t & 0xFF;
  14040. }
  14041. }
  14042. // InvShiftRows
  14043. t = state[13];
  14044. state[13] = state[9];
  14045. state[9] = state[5];
  14046. state[5] = state[1];
  14047. state[1] = t;
  14048. t = state[14];
  14049. u = state[10];
  14050. state[14] = state[6];
  14051. state[10] = state[2];
  14052. state[6] = t;
  14053. state[2] = u;
  14054. t = state[15];
  14055. u = state[11];
  14056. v = state[7];
  14057. state[15] = state[3];
  14058. state[11] = t;
  14059. state[7] = u;
  14060. state[3] = v;
  14061. for (j = 0; j < 16; ++j) {
  14062. // InvSubBytes
  14063. state[j] = inv_s[state[j]];
  14064. // AddRoundKey
  14065. state[j] ^= key[j];
  14066. }
  14067. return state;
  14068. }
  14069. function encrypt128(input, key) {
  14070. var t, u, v, k;
  14071. var state = new Uint8Array(16);
  14072. state.set(input);
  14073. for (j = 0; j < 16; ++j) {
  14074. // AddRoundKey
  14075. state[j] ^= key[j];
  14076. }
  14077. for (i = 1; i < 10; i++) {
  14078. //SubBytes
  14079. for (j = 0; j < 16; ++j) {
  14080. state[j] = s[state[j]];
  14081. }
  14082. //ShiftRows
  14083. v = state[1];
  14084. state[1] = state[5];
  14085. state[5] = state[9];
  14086. state[9] = state[13];
  14087. state[13] = v;
  14088. v = state[2];
  14089. u = state[6];
  14090. state[2] = state[10];
  14091. state[6] = state[14];
  14092. state[10] = v;
  14093. state[14] = u;
  14094. v = state[3];
  14095. u = state[7];
  14096. t = state[11];
  14097. state[3] = state[15];
  14098. state[7] = v;
  14099. state[11] = u;
  14100. state[15] = t;
  14101. //MixColumns
  14102. for (var j = 0; j < 16; j += 4) {
  14103. var s0 = state[j + 0], s1 = state[j + 1];
  14104. var s2 = state[j + 2], s3 = state[j + 3];
  14105. t = s0 ^ s1 ^ s2 ^ s3;
  14106. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  14107. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  14108. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  14109. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  14110. }
  14111. //AddRoundKey
  14112. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  14113. state[j] ^= key[k];
  14114. }
  14115. }
  14116. //SubBytes
  14117. for (j = 0; j < 16; ++j) {
  14118. state[j] = s[state[j]];
  14119. }
  14120. //ShiftRows
  14121. v = state[1];
  14122. state[1] = state[5];
  14123. state[5] = state[9];
  14124. state[9] = state[13];
  14125. state[13] = v;
  14126. v = state[2];
  14127. u = state[6];
  14128. state[2] = state[10];
  14129. state[6] = state[14];
  14130. state[10] = v;
  14131. state[14] = u;
  14132. v = state[3];
  14133. u = state[7];
  14134. t = state[11];
  14135. state[3] = state[15];
  14136. state[7] = v;
  14137. state[11] = u;
  14138. state[15] = t;
  14139. //AddRoundKey
  14140. for (j = 0, k = 160; j < 16; ++j, ++k) {
  14141. state[j] ^= key[k];
  14142. }
  14143. return state;
  14144. }
  14145. function AES128Cipher(key) {
  14146. this.key = expandKey128(key);
  14147. this.buffer = new Uint8Array(16);
  14148. this.bufferPosition = 0;
  14149. }
  14150. function decryptBlock2(data, finalize) {
  14151. var i, j, ii, sourceLength = data.length,
  14152. buffer = this.buffer, bufferLength = this.bufferPosition,
  14153. result = [], iv = this.iv;
  14154. for (i = 0; i < sourceLength; ++i) {
  14155. buffer[bufferLength] = data[i];
  14156. ++bufferLength;
  14157. if (bufferLength < 16) {
  14158. continue;
  14159. }
  14160. // buffer is full, decrypting
  14161. var plain = decrypt128(buffer, this.key);
  14162. // xor-ing the IV vector to get plain text
  14163. for (j = 0; j < 16; ++j) {
  14164. plain[j] ^= iv[j];
  14165. }
  14166. iv = buffer;
  14167. result.push(plain);
  14168. buffer = new Uint8Array(16);
  14169. bufferLength = 0;
  14170. }
  14171. // saving incomplete buffer
  14172. this.buffer = buffer;
  14173. this.bufferLength = bufferLength;
  14174. this.iv = iv;
  14175. if (result.length === 0) {
  14176. return new Uint8Array([]);
  14177. }
  14178. // combining plain text blocks into one
  14179. var outputLength = 16 * result.length;
  14180. if (finalize) {
  14181. // undo a padding that is described in RFC 2898
  14182. var lastBlock = result[result.length - 1];
  14183. var psLen = lastBlock[15];
  14184. if (psLen <= 16) {
  14185. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  14186. if (lastBlock[i] !== psLen) {
  14187. // Invalid padding, assume that the block has no padding.
  14188. psLen = 0;
  14189. break;
  14190. }
  14191. }
  14192. outputLength -= psLen;
  14193. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  14194. }
  14195. }
  14196. var output = new Uint8Array(outputLength);
  14197. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  14198. output.set(result[i], j);
  14199. }
  14200. return output;
  14201. }
  14202. AES128Cipher.prototype = {
  14203. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  14204. var i, sourceLength = data.length;
  14205. var buffer = this.buffer, bufferLength = this.bufferPosition;
  14206. // waiting for IV values -- they are at the start of the stream
  14207. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  14208. buffer[bufferLength] = data[i];
  14209. }
  14210. if (bufferLength < 16) {
  14211. // need more data
  14212. this.bufferLength = bufferLength;
  14213. return new Uint8Array([]);
  14214. }
  14215. this.iv = buffer;
  14216. this.buffer = new Uint8Array(16);
  14217. this.bufferLength = 0;
  14218. // starting decryption
  14219. this.decryptBlock = decryptBlock2;
  14220. return this.decryptBlock(data.subarray(16), finalize);
  14221. },
  14222. encrypt: function AES128Cipher_encrypt(data, iv) {
  14223. var i, j, ii, sourceLength = data.length,
  14224. buffer = this.buffer, bufferLength = this.bufferPosition,
  14225. result = [];
  14226. if (!iv) {
  14227. iv = new Uint8Array(16);
  14228. }
  14229. for (i = 0; i < sourceLength; ++i) {
  14230. buffer[bufferLength] = data[i];
  14231. ++bufferLength;
  14232. if (bufferLength < 16) {
  14233. continue;
  14234. }
  14235. for (j = 0; j < 16; ++j) {
  14236. buffer[j] ^= iv[j];
  14237. }
  14238. // buffer is full, encrypting
  14239. var cipher = encrypt128(buffer, this.key);
  14240. iv = cipher;
  14241. result.push(cipher);
  14242. buffer = new Uint8Array(16);
  14243. bufferLength = 0;
  14244. }
  14245. // saving incomplete buffer
  14246. this.buffer = buffer;
  14247. this.bufferLength = bufferLength;
  14248. this.iv = iv;
  14249. if (result.length === 0) {
  14250. return new Uint8Array([]);
  14251. }
  14252. // combining plain text blocks into one
  14253. var outputLength = 16 * result.length;
  14254. var output = new Uint8Array(outputLength);
  14255. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  14256. output.set(result[i], j);
  14257. }
  14258. return output;
  14259. }
  14260. };
  14261. return AES128Cipher;
  14262. })();
  14263. var AES256Cipher = (function AES256CipherClosure() {
  14264. var rcon = new Uint8Array([
  14265. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  14266. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  14267. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  14268. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  14269. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  14270. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  14271. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  14272. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  14273. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  14274. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  14275. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  14276. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  14277. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  14278. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  14279. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  14280. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  14281. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  14282. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  14283. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  14284. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  14285. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  14286. 0x74, 0xe8, 0xcb, 0x8d]);
  14287. var s = new Uint8Array([
  14288. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  14289. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  14290. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  14291. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  14292. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  14293. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  14294. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  14295. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  14296. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  14297. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  14298. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  14299. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  14300. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  14301. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  14302. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  14303. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  14304. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  14305. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  14306. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  14307. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  14308. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  14309. 0xb0, 0x54, 0xbb, 0x16]);
  14310. var inv_s = new Uint8Array([
  14311. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  14312. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  14313. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  14314. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  14315. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  14316. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  14317. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  14318. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  14319. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  14320. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  14321. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  14322. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  14323. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  14324. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  14325. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  14326. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  14327. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  14328. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  14329. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  14330. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  14331. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  14332. 0x55, 0x21, 0x0c, 0x7d]);
  14333. var mixCol = new Uint8Array(256);
  14334. for (var i = 0; i < 256; i++) {
  14335. if (i < 128) {
  14336. mixCol[i] = i << 1;
  14337. } else {
  14338. mixCol[i] = (i << 1) ^ 0x1b;
  14339. }
  14340. }
  14341. var mix = new Uint32Array([
  14342. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  14343. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  14344. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  14345. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  14346. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  14347. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  14348. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  14349. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  14350. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  14351. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  14352. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  14353. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  14354. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  14355. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  14356. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  14357. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  14358. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  14359. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  14360. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  14361. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  14362. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  14363. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  14364. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  14365. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  14366. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  14367. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  14368. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  14369. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  14370. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  14371. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  14372. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  14373. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  14374. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  14375. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  14376. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  14377. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  14378. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  14379. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  14380. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  14381. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  14382. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  14383. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  14384. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  14385. function expandKey256(cipherKey) {
  14386. var b = 240, result = new Uint8Array(b);
  14387. var r = 1;
  14388. result.set(cipherKey);
  14389. for (var j = 32, i = 1; j < b; ++i) {
  14390. if (j % 32 === 16) {
  14391. t1 = s[t1];
  14392. t2 = s[t2];
  14393. t3 = s[t3];
  14394. t4 = s[t4];
  14395. } else if (j % 32 === 0) {
  14396. // RotWord
  14397. var t1 = result[j - 3], t2 = result[j - 2],
  14398. t3 = result[j - 1], t4 = result[j - 4];
  14399. // SubWord
  14400. t1 = s[t1];
  14401. t2 = s[t2];
  14402. t3 = s[t3];
  14403. t4 = s[t4];
  14404. // Rcon
  14405. t1 = t1 ^ r;
  14406. if ((r <<= 1) >= 256) {
  14407. r = (r ^ 0x1b) & 0xFF;
  14408. }
  14409. }
  14410. for (var n = 0; n < 4; ++n) {
  14411. result[j] = (t1 ^= result[j - 32]);
  14412. j++;
  14413. result[j] = (t2 ^= result[j - 32]);
  14414. j++;
  14415. result[j] = (t3 ^= result[j - 32]);
  14416. j++;
  14417. result[j] = (t4 ^= result[j - 32]);
  14418. j++;
  14419. }
  14420. }
  14421. return result;
  14422. }
  14423. function decrypt256(input, key) {
  14424. var state = new Uint8Array(16);
  14425. state.set(input);
  14426. var i, j, k;
  14427. var t, u, v;
  14428. // AddRoundKey
  14429. for (j = 0, k = 224; j < 16; ++j, ++k) {
  14430. state[j] ^= key[k];
  14431. }
  14432. for (i = 13; i >= 1; --i) {
  14433. // InvShiftRows
  14434. t = state[13];
  14435. state[13] = state[9];
  14436. state[9] = state[5];
  14437. state[5] = state[1];
  14438. state[1] = t;
  14439. t = state[14];
  14440. u = state[10];
  14441. state[14] = state[6];
  14442. state[10] = state[2];
  14443. state[6] = t;
  14444. state[2] = u;
  14445. t = state[15];
  14446. u = state[11];
  14447. v = state[7];
  14448. state[15] = state[3];
  14449. state[11] = t;
  14450. state[7] = u;
  14451. state[3] = v;
  14452. // InvSubBytes
  14453. for (j = 0; j < 16; ++j) {
  14454. state[j] = inv_s[state[j]];
  14455. }
  14456. // AddRoundKey
  14457. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  14458. state[j] ^= key[k];
  14459. }
  14460. // InvMixColumns
  14461. for (j = 0; j < 16; j += 4) {
  14462. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  14463. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  14464. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  14465. (s3 >>> 24) ^ (s3 << 8));
  14466. state[j] = (t >>> 24) & 0xFF;
  14467. state[j + 1] = (t >> 16) & 0xFF;
  14468. state[j + 2] = (t >> 8) & 0xFF;
  14469. state[j + 3] = t & 0xFF;
  14470. }
  14471. }
  14472. // InvShiftRows
  14473. t = state[13];
  14474. state[13] = state[9];
  14475. state[9] = state[5];
  14476. state[5] = state[1];
  14477. state[1] = t;
  14478. t = state[14];
  14479. u = state[10];
  14480. state[14] = state[6];
  14481. state[10] = state[2];
  14482. state[6] = t;
  14483. state[2] = u;
  14484. t = state[15];
  14485. u = state[11];
  14486. v = state[7];
  14487. state[15] = state[3];
  14488. state[11] = t;
  14489. state[7] = u;
  14490. state[3] = v;
  14491. for (j = 0; j < 16; ++j) {
  14492. // InvSubBytes
  14493. state[j] = inv_s[state[j]];
  14494. // AddRoundKey
  14495. state[j] ^= key[j];
  14496. }
  14497. return state;
  14498. }
  14499. function encrypt256(input, key) {
  14500. var t, u, v, k;
  14501. var state = new Uint8Array(16);
  14502. state.set(input);
  14503. for (j = 0; j < 16; ++j) {
  14504. // AddRoundKey
  14505. state[j] ^= key[j];
  14506. }
  14507. for (i = 1; i < 14; i++) {
  14508. //SubBytes
  14509. for (j = 0; j < 16; ++j) {
  14510. state[j] = s[state[j]];
  14511. }
  14512. //ShiftRows
  14513. v = state[1];
  14514. state[1] = state[5];
  14515. state[5] = state[9];
  14516. state[9] = state[13];
  14517. state[13] = v;
  14518. v = state[2];
  14519. u = state[6];
  14520. state[2] = state[10];
  14521. state[6] = state[14];
  14522. state[10] = v;
  14523. state[14] = u;
  14524. v = state[3];
  14525. u = state[7];
  14526. t = state[11];
  14527. state[3] = state[15];
  14528. state[7] = v;
  14529. state[11] = u;
  14530. state[15] = t;
  14531. //MixColumns
  14532. for (var j = 0; j < 16; j += 4) {
  14533. var s0 = state[j + 0], s1 = state[j + 1];
  14534. var s2 = state[j + 2], s3 = state[j + 3];
  14535. t = s0 ^ s1 ^ s2 ^ s3;
  14536. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  14537. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  14538. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  14539. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  14540. }
  14541. //AddRoundKey
  14542. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  14543. state[j] ^= key[k];
  14544. }
  14545. }
  14546. //SubBytes
  14547. for (j = 0; j < 16; ++j) {
  14548. state[j] = s[state[j]];
  14549. }
  14550. //ShiftRows
  14551. v = state[1];
  14552. state[1] = state[5];
  14553. state[5] = state[9];
  14554. state[9] = state[13];
  14555. state[13] = v;
  14556. v = state[2];
  14557. u = state[6];
  14558. state[2] = state[10];
  14559. state[6] = state[14];
  14560. state[10] = v;
  14561. state[14] = u;
  14562. v = state[3];
  14563. u = state[7];
  14564. t = state[11];
  14565. state[3] = state[15];
  14566. state[7] = v;
  14567. state[11] = u;
  14568. state[15] = t;
  14569. //AddRoundKey
  14570. for (j = 0, k = 224; j < 16; ++j, ++k) {
  14571. state[j] ^= key[k];
  14572. }
  14573. return state;
  14574. }
  14575. function AES256Cipher(key) {
  14576. this.key = expandKey256(key);
  14577. this.buffer = new Uint8Array(16);
  14578. this.bufferPosition = 0;
  14579. }
  14580. function decryptBlock2(data, finalize) {
  14581. var i, j, ii, sourceLength = data.length,
  14582. buffer = this.buffer, bufferLength = this.bufferPosition,
  14583. result = [], iv = this.iv;
  14584. for (i = 0; i < sourceLength; ++i) {
  14585. buffer[bufferLength] = data[i];
  14586. ++bufferLength;
  14587. if (bufferLength < 16) {
  14588. continue;
  14589. }
  14590. // buffer is full, decrypting
  14591. var plain = decrypt256(buffer, this.key);
  14592. // xor-ing the IV vector to get plain text
  14593. for (j = 0; j < 16; ++j) {
  14594. plain[j] ^= iv[j];
  14595. }
  14596. iv = buffer;
  14597. result.push(plain);
  14598. buffer = new Uint8Array(16);
  14599. bufferLength = 0;
  14600. }
  14601. // saving incomplete buffer
  14602. this.buffer = buffer;
  14603. this.bufferLength = bufferLength;
  14604. this.iv = iv;
  14605. if (result.length === 0) {
  14606. return new Uint8Array([]);
  14607. }
  14608. // combining plain text blocks into one
  14609. var outputLength = 16 * result.length;
  14610. if (finalize) {
  14611. // undo a padding that is described in RFC 2898
  14612. var lastBlock = result[result.length - 1];
  14613. var psLen = lastBlock[15];
  14614. if (psLen <= 16) {
  14615. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  14616. if (lastBlock[i] !== psLen) {
  14617. // Invalid padding, assume that the block has no padding.
  14618. psLen = 0;
  14619. break;
  14620. }
  14621. }
  14622. outputLength -= psLen;
  14623. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  14624. }
  14625. }
  14626. var output = new Uint8Array(outputLength);
  14627. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  14628. output.set(result[i], j);
  14629. }
  14630. return output;
  14631. }
  14632. AES256Cipher.prototype = {
  14633. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  14634. var i, sourceLength = data.length;
  14635. var buffer = this.buffer, bufferLength = this.bufferPosition;
  14636. // if not supplied an IV wait for IV values
  14637. // they are at the start of the stream
  14638. if (iv) {
  14639. this.iv = iv;
  14640. } else {
  14641. for (i = 0; bufferLength < 16 &&
  14642. i < sourceLength; ++i, ++bufferLength) {
  14643. buffer[bufferLength] = data[i];
  14644. }
  14645. if (bufferLength < 16) {
  14646. //need more data
  14647. this.bufferLength = bufferLength;
  14648. return new Uint8Array([]);
  14649. }
  14650. this.iv = buffer;
  14651. data = data.subarray(16);
  14652. }
  14653. this.buffer = new Uint8Array(16);
  14654. this.bufferLength = 0;
  14655. // starting decryption
  14656. this.decryptBlock = decryptBlock2;
  14657. return this.decryptBlock(data, finalize);
  14658. },
  14659. encrypt: function AES256Cipher_encrypt(data, iv) {
  14660. var i, j, ii, sourceLength = data.length,
  14661. buffer = this.buffer, bufferLength = this.bufferPosition,
  14662. result = [];
  14663. if (!iv) {
  14664. iv = new Uint8Array(16);
  14665. }
  14666. for (i = 0; i < sourceLength; ++i) {
  14667. buffer[bufferLength] = data[i];
  14668. ++bufferLength;
  14669. if (bufferLength < 16) {
  14670. continue;
  14671. }
  14672. for (j = 0; j < 16; ++j) {
  14673. buffer[j] ^= iv[j];
  14674. }
  14675. // buffer is full, encrypting
  14676. var cipher = encrypt256(buffer, this.key);
  14677. this.iv = cipher;
  14678. result.push(cipher);
  14679. buffer = new Uint8Array(16);
  14680. bufferLength = 0;
  14681. }
  14682. // saving incomplete buffer
  14683. this.buffer = buffer;
  14684. this.bufferLength = bufferLength;
  14685. this.iv = iv;
  14686. if (result.length === 0) {
  14687. return new Uint8Array([]);
  14688. }
  14689. // combining plain text blocks into one
  14690. var outputLength = 16 * result.length;
  14691. var output = new Uint8Array(outputLength);
  14692. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  14693. output.set(result[i], j);
  14694. }
  14695. return output;
  14696. }
  14697. };
  14698. return AES256Cipher;
  14699. })();
  14700. var PDF17 = (function PDF17Closure() {
  14701. function compareByteArrays(array1, array2) {
  14702. if (array1.length !== array2.length) {
  14703. return false;
  14704. }
  14705. for (var i = 0; i < array1.length; i++) {
  14706. if (array1[i] !== array2[i]) {
  14707. return false;
  14708. }
  14709. }
  14710. return true;
  14711. }
  14712. function PDF17() {
  14713. }
  14714. PDF17.prototype = {
  14715. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  14716. ownerValidationSalt,
  14717. userBytes,
  14718. ownerPassword) {
  14719. var hashData = new Uint8Array(password.length + 56);
  14720. hashData.set(password, 0);
  14721. hashData.set(ownerValidationSalt, password.length);
  14722. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14723. var result = calculateSHA256(hashData, 0, hashData.length);
  14724. return compareByteArrays(result, ownerPassword);
  14725. },
  14726. checkUserPassword: function PDF17_checkUserPassword(password,
  14727. userValidationSalt,
  14728. userPassword) {
  14729. var hashData = new Uint8Array(password.length + 8);
  14730. hashData.set(password, 0);
  14731. hashData.set(userValidationSalt, password.length);
  14732. var result = calculateSHA256(hashData, 0, hashData.length);
  14733. return compareByteArrays(result, userPassword);
  14734. },
  14735. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  14736. ownerEncryption) {
  14737. var hashData = new Uint8Array(password.length + 56);
  14738. hashData.set(password, 0);
  14739. hashData.set(ownerKeySalt, password.length);
  14740. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14741. var key = calculateSHA256(hashData, 0, hashData.length);
  14742. var cipher = new AES256Cipher(key);
  14743. return cipher.decryptBlock(ownerEncryption,
  14744. false,
  14745. new Uint8Array(16));
  14746. },
  14747. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  14748. userEncryption) {
  14749. var hashData = new Uint8Array(password.length + 8);
  14750. hashData.set(password, 0);
  14751. hashData.set(userKeySalt, password.length);
  14752. //key is the decryption key for the UE string
  14753. var key = calculateSHA256(hashData, 0, hashData.length);
  14754. var cipher = new AES256Cipher(key);
  14755. return cipher.decryptBlock(userEncryption,
  14756. false,
  14757. new Uint8Array(16));
  14758. }
  14759. };
  14760. return PDF17;
  14761. })();
  14762. var PDF20 = (function PDF20Closure() {
  14763. function concatArrays(array1, array2) {
  14764. var t = new Uint8Array(array1.length + array2.length);
  14765. t.set(array1, 0);
  14766. t.set(array2, array1.length);
  14767. return t;
  14768. }
  14769. function calculatePDF20Hash(password, input, userBytes) {
  14770. //This refers to Algorithm 2.B as defined in ISO 32000-2
  14771. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  14772. var e = [0];
  14773. var i = 0;
  14774. while (i < 64 || e[e.length - 1] > i - 32) {
  14775. var arrayLength = password.length + k.length + userBytes.length;
  14776. var k1 = new Uint8Array(arrayLength * 64);
  14777. var array = concatArrays(password, k);
  14778. array = concatArrays(array, userBytes);
  14779. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  14780. k1.set(array, pos);
  14781. }
  14782. //AES128 CBC NO PADDING with
  14783. //first 16 bytes of k as the key and the second 16 as the iv.
  14784. var cipher = new AES128Cipher(k.subarray(0, 16));
  14785. e = cipher.encrypt(k1, k.subarray(16, 32));
  14786. //Now we have to take the first 16 bytes of an unsigned
  14787. //big endian integer... and compute the remainder
  14788. //modulo 3.... That is a fairly large number and
  14789. //JavaScript isn't going to handle that well...
  14790. //So we're using a trick that allows us to perform
  14791. //modulo math byte by byte
  14792. var remainder = 0;
  14793. for (var z = 0; z < 16; z++) {
  14794. remainder *= (256 % 3);
  14795. remainder %= 3;
  14796. remainder += ((e[z] >>> 0) % 3);
  14797. remainder %= 3;
  14798. }
  14799. if (remainder === 0) {
  14800. k = calculateSHA256(e, 0, e.length);
  14801. }
  14802. else if (remainder === 1) {
  14803. k = calculateSHA384(e, 0, e.length);
  14804. }
  14805. else if (remainder === 2) {
  14806. k = calculateSHA512(e, 0, e.length);
  14807. }
  14808. i++;
  14809. }
  14810. return k.subarray(0, 32);
  14811. }
  14812. function PDF20() {
  14813. }
  14814. function compareByteArrays(array1, array2) {
  14815. if (array1.length !== array2.length) {
  14816. return false;
  14817. }
  14818. for (var i = 0; i < array1.length; i++) {
  14819. if (array1[i] !== array2[i]) {
  14820. return false;
  14821. }
  14822. }
  14823. return true;
  14824. }
  14825. PDF20.prototype = {
  14826. hash: function PDF20_hash(password, concatBytes, userBytes) {
  14827. return calculatePDF20Hash(password, concatBytes, userBytes);
  14828. },
  14829. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  14830. ownerValidationSalt,
  14831. userBytes,
  14832. ownerPassword) {
  14833. var hashData = new Uint8Array(password.length + 56);
  14834. hashData.set(password, 0);
  14835. hashData.set(ownerValidationSalt, password.length);
  14836. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  14837. var result = calculatePDF20Hash(password, hashData, userBytes);
  14838. return compareByteArrays(result, ownerPassword);
  14839. },
  14840. checkUserPassword: function PDF20_checkUserPassword(password,
  14841. userValidationSalt,
  14842. userPassword) {
  14843. var hashData = new Uint8Array(password.length + 8);
  14844. hashData.set(password, 0);
  14845. hashData.set(userValidationSalt, password.length);
  14846. var result = calculatePDF20Hash(password, hashData, []);
  14847. return compareByteArrays(result, userPassword);
  14848. },
  14849. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  14850. ownerEncryption) {
  14851. var hashData = new Uint8Array(password.length + 56);
  14852. hashData.set(password, 0);
  14853. hashData.set(ownerKeySalt, password.length);
  14854. hashData.set(userBytes, password.length + ownerKeySalt.length);
  14855. var key = calculatePDF20Hash(password, hashData, userBytes);
  14856. var cipher = new AES256Cipher(key);
  14857. return cipher.decryptBlock(ownerEncryption,
  14858. false,
  14859. new Uint8Array(16));
  14860. },
  14861. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  14862. userEncryption) {
  14863. var hashData = new Uint8Array(password.length + 8);
  14864. hashData.set(password, 0);
  14865. hashData.set(userKeySalt, password.length);
  14866. //key is the decryption key for the UE string
  14867. var key = calculatePDF20Hash(password, hashData, []);
  14868. var cipher = new AES256Cipher(key);
  14869. return cipher.decryptBlock(userEncryption,
  14870. false,
  14871. new Uint8Array(16));
  14872. }
  14873. };
  14874. return PDF20;
  14875. })();
  14876. var CipherTransform = (function CipherTransformClosure() {
  14877. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  14878. this.stringCipherConstructor = stringCipherConstructor;
  14879. this.streamCipherConstructor = streamCipherConstructor;
  14880. }
  14881. CipherTransform.prototype = {
  14882. createStream: function CipherTransform_createStream(stream, length) {
  14883. var cipher = new this.streamCipherConstructor();
  14884. return new DecryptStream(stream, length,
  14885. function cipherTransformDecryptStream(data, finalize) {
  14886. return cipher.decryptBlock(data, finalize);
  14887. }
  14888. );
  14889. },
  14890. decryptString: function CipherTransform_decryptString(s) {
  14891. var cipher = new this.stringCipherConstructor();
  14892. var data = stringToBytes(s);
  14893. data = cipher.decryptBlock(data, true);
  14894. return bytesToString(data);
  14895. }
  14896. };
  14897. return CipherTransform;
  14898. })();
  14899. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  14900. var defaultPasswordBytes = new Uint8Array([
  14901. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  14902. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  14903. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  14904. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  14905. function createEncryptionKey20(revision, password, ownerPassword,
  14906. ownerValidationSalt, ownerKeySalt, uBytes,
  14907. userPassword, userValidationSalt, userKeySalt,
  14908. ownerEncryption, userEncryption, perms) {
  14909. if (password) {
  14910. var passwordLength = Math.min(127, password.length);
  14911. password = password.subarray(0, passwordLength);
  14912. } else {
  14913. password = [];
  14914. }
  14915. var pdfAlgorithm;
  14916. if (revision === 6) {
  14917. pdfAlgorithm = new PDF20();
  14918. } else {
  14919. pdfAlgorithm = new PDF17();
  14920. }
  14921. if (pdfAlgorithm) {
  14922. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  14923. userPassword)) {
  14924. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  14925. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  14926. ownerValidationSalt,
  14927. uBytes,
  14928. ownerPassword)) {
  14929. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  14930. ownerEncryption);
  14931. }
  14932. }
  14933. return null;
  14934. }
  14935. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  14936. flags, revision, keyLength, encryptMetadata) {
  14937. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  14938. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  14939. if (password) {
  14940. n = Math.min(32, password.length);
  14941. for (; i < n; ++i) {
  14942. hashData[i] = password[i];
  14943. }
  14944. }
  14945. j = 0;
  14946. while (i < 32) {
  14947. hashData[i++] = defaultPasswordBytes[j++];
  14948. }
  14949. // as now the padded password in the hashData[0..i]
  14950. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  14951. hashData[i++] = ownerPassword[j];
  14952. }
  14953. hashData[i++] = flags & 0xFF;
  14954. hashData[i++] = (flags >> 8) & 0xFF;
  14955. hashData[i++] = (flags >> 16) & 0xFF;
  14956. hashData[i++] = (flags >>> 24) & 0xFF;
  14957. for (j = 0, n = fileId.length; j < n; ++j) {
  14958. hashData[i++] = fileId[j];
  14959. }
  14960. if (revision >= 4 && !encryptMetadata) {
  14961. hashData[i++] = 0xFF;
  14962. hashData[i++] = 0xFF;
  14963. hashData[i++] = 0xFF;
  14964. hashData[i++] = 0xFF;
  14965. }
  14966. var hash = calculateMD5(hashData, 0, i);
  14967. var keyLengthInBytes = keyLength >> 3;
  14968. if (revision >= 3) {
  14969. for (j = 0; j < 50; ++j) {
  14970. hash = calculateMD5(hash, 0, keyLengthInBytes);
  14971. }
  14972. }
  14973. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  14974. var cipher, checkData;
  14975. if (revision >= 3) {
  14976. for (i = 0; i < 32; ++i) {
  14977. hashData[i] = defaultPasswordBytes[i];
  14978. }
  14979. for (j = 0, n = fileId.length; j < n; ++j) {
  14980. hashData[i++] = fileId[j];
  14981. }
  14982. cipher = new ARCFourCipher(encryptionKey);
  14983. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  14984. n = encryptionKey.length;
  14985. var derivedKey = new Uint8Array(n), k;
  14986. for (j = 1; j <= 19; ++j) {
  14987. for (k = 0; k < n; ++k) {
  14988. derivedKey[k] = encryptionKey[k] ^ j;
  14989. }
  14990. cipher = new ARCFourCipher(derivedKey);
  14991. checkData = cipher.encryptBlock(checkData);
  14992. }
  14993. for (j = 0, n = checkData.length; j < n; ++j) {
  14994. if (userPassword[j] !== checkData[j]) {
  14995. return null;
  14996. }
  14997. }
  14998. } else {
  14999. cipher = new ARCFourCipher(encryptionKey);
  15000. checkData = cipher.encryptBlock(defaultPasswordBytes);
  15001. for (j = 0, n = checkData.length; j < n; ++j) {
  15002. if (userPassword[j] !== checkData[j]) {
  15003. return null;
  15004. }
  15005. }
  15006. }
  15007. return encryptionKey;
  15008. }
  15009. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  15010. var hashData = new Uint8Array(32), i = 0, j, n;
  15011. n = Math.min(32, password.length);
  15012. for (; i < n; ++i) {
  15013. hashData[i] = password[i];
  15014. }
  15015. j = 0;
  15016. while (i < 32) {
  15017. hashData[i++] = defaultPasswordBytes[j++];
  15018. }
  15019. var hash = calculateMD5(hashData, 0, i);
  15020. var keyLengthInBytes = keyLength >> 3;
  15021. if (revision >= 3) {
  15022. for (j = 0; j < 50; ++j) {
  15023. hash = calculateMD5(hash, 0, hash.length);
  15024. }
  15025. }
  15026. var cipher, userPassword;
  15027. if (revision >= 3) {
  15028. userPassword = ownerPassword;
  15029. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  15030. for (j = 19; j >= 0; j--) {
  15031. for (k = 0; k < keyLengthInBytes; ++k) {
  15032. derivedKey[k] = hash[k] ^ j;
  15033. }
  15034. cipher = new ARCFourCipher(derivedKey);
  15035. userPassword = cipher.encryptBlock(userPassword);
  15036. }
  15037. } else {
  15038. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  15039. userPassword = cipher.encryptBlock(ownerPassword);
  15040. }
  15041. return userPassword;
  15042. }
  15043. var identityName = Name.get('Identity');
  15044. function CipherTransformFactory(dict, fileId, password) {
  15045. var filter = dict.get('Filter');
  15046. if (!isName(filter) || filter.name !== 'Standard') {
  15047. error('unknown encryption method');
  15048. }
  15049. this.dict = dict;
  15050. var algorithm = dict.get('V');
  15051. if (!isInt(algorithm) ||
  15052. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  15053. algorithm !== 5)) {
  15054. error('unsupported encryption algorithm');
  15055. }
  15056. this.algorithm = algorithm;
  15057. var keyLength = dict.get('Length') || 40;
  15058. if (!isInt(keyLength) ||
  15059. keyLength < 40 || (keyLength % 8) !== 0) {
  15060. error('invalid key length');
  15061. }
  15062. // prepare keys
  15063. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  15064. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  15065. var flags = dict.get('P');
  15066. var revision = dict.get('R');
  15067. // meaningful when V is 4 or 5
  15068. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  15069. dict.get('EncryptMetadata') !== false);
  15070. this.encryptMetadata = encryptMetadata;
  15071. var fileIdBytes = stringToBytes(fileId);
  15072. var passwordBytes;
  15073. if (password) {
  15074. if (revision === 6) {
  15075. try {
  15076. password = utf8StringToString(password);
  15077. } catch (ex) {
  15078. warn('CipherTransformFactory: ' +
  15079. 'Unable to convert UTF8 encoded password.');
  15080. }
  15081. }
  15082. passwordBytes = stringToBytes(password);
  15083. }
  15084. var encryptionKey;
  15085. if (algorithm !== 5) {
  15086. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  15087. ownerPassword, userPassword, flags,
  15088. revision, keyLength, encryptMetadata);
  15089. }
  15090. else {
  15091. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  15092. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  15093. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  15094. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  15095. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  15096. var ownerEncryption = stringToBytes(dict.get('OE'));
  15097. var userEncryption = stringToBytes(dict.get('UE'));
  15098. var perms = stringToBytes(dict.get('Perms'));
  15099. encryptionKey =
  15100. createEncryptionKey20(revision, passwordBytes,
  15101. ownerPassword, ownerValidationSalt,
  15102. ownerKeySalt, uBytes,
  15103. userPassword, userValidationSalt,
  15104. userKeySalt, ownerEncryption,
  15105. userEncryption, perms);
  15106. }
  15107. if (!encryptionKey && !password) {
  15108. throw new PasswordException('No password given',
  15109. PasswordResponses.NEED_PASSWORD);
  15110. } else if (!encryptionKey && password) {
  15111. // Attempting use the password as an owner password
  15112. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  15113. revision, keyLength);
  15114. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  15115. ownerPassword, userPassword, flags,
  15116. revision, keyLength, encryptMetadata);
  15117. }
  15118. if (!encryptionKey) {
  15119. throw new PasswordException('Incorrect Password',
  15120. PasswordResponses.INCORRECT_PASSWORD);
  15121. }
  15122. this.encryptionKey = encryptionKey;
  15123. if (algorithm >= 4) {
  15124. this.cf = dict.get('CF');
  15125. this.stmf = dict.get('StmF') || identityName;
  15126. this.strf = dict.get('StrF') || identityName;
  15127. this.eff = dict.get('EFF') || this.stmf;
  15128. }
  15129. }
  15130. function buildObjectKey(num, gen, encryptionKey, isAes) {
  15131. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  15132. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  15133. key[i] = encryptionKey[i];
  15134. }
  15135. key[i++] = num & 0xFF;
  15136. key[i++] = (num >> 8) & 0xFF;
  15137. key[i++] = (num >> 16) & 0xFF;
  15138. key[i++] = gen & 0xFF;
  15139. key[i++] = (gen >> 8) & 0xFF;
  15140. if (isAes) {
  15141. key[i++] = 0x73;
  15142. key[i++] = 0x41;
  15143. key[i++] = 0x6C;
  15144. key[i++] = 0x54;
  15145. }
  15146. var hash = calculateMD5(key, 0, i);
  15147. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  15148. }
  15149. function buildCipherConstructor(cf, name, num, gen, key) {
  15150. var cryptFilter = cf.get(name.name);
  15151. var cfm;
  15152. if (cryptFilter !== null && cryptFilter !== undefined) {
  15153. cfm = cryptFilter.get('CFM');
  15154. }
  15155. if (!cfm || cfm.name === 'None') {
  15156. return function cipherTransformFactoryBuildCipherConstructorNone() {
  15157. return new NullCipher();
  15158. };
  15159. }
  15160. if ('V2' === cfm.name) {
  15161. return function cipherTransformFactoryBuildCipherConstructorV2() {
  15162. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  15163. };
  15164. }
  15165. if ('AESV2' === cfm.name) {
  15166. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  15167. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  15168. };
  15169. }
  15170. if ('AESV3' === cfm.name) {
  15171. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  15172. return new AES256Cipher(key);
  15173. };
  15174. }
  15175. error('Unknown crypto method');
  15176. }
  15177. CipherTransformFactory.prototype = {
  15178. createCipherTransform:
  15179. function CipherTransformFactory_createCipherTransform(num, gen) {
  15180. if (this.algorithm === 4 || this.algorithm === 5) {
  15181. return new CipherTransform(
  15182. buildCipherConstructor(this.cf, this.stmf,
  15183. num, gen, this.encryptionKey),
  15184. buildCipherConstructor(this.cf, this.strf,
  15185. num, gen, this.encryptionKey));
  15186. }
  15187. // algorithms 1 and 2
  15188. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  15189. var cipherConstructor = function buildCipherCipherConstructor() {
  15190. return new ARCFourCipher(key);
  15191. };
  15192. return new CipherTransform(cipherConstructor, cipherConstructor);
  15193. }
  15194. };
  15195. return CipherTransformFactory;
  15196. })();
  15197. var ShadingType = {
  15198. FUNCTION_BASED: 1,
  15199. AXIAL: 2,
  15200. RADIAL: 3,
  15201. FREE_FORM_MESH: 4,
  15202. LATTICE_FORM_MESH: 5,
  15203. COONS_PATCH_MESH: 6,
  15204. TENSOR_PATCH_MESH: 7
  15205. };
  15206. var Pattern = (function PatternClosure() {
  15207. // Constructor should define this.getPattern
  15208. function Pattern() {
  15209. error('should not call Pattern constructor');
  15210. }
  15211. Pattern.prototype = {
  15212. // Input: current Canvas context
  15213. // Output: the appropriate fillStyle or strokeStyle
  15214. getPattern: function Pattern_getPattern(ctx) {
  15215. error('Should not call Pattern.getStyle: ' + ctx);
  15216. }
  15217. };
  15218. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  15219. res) {
  15220. var dict = isStream(shading) ? shading.dict : shading;
  15221. var type = dict.get('ShadingType');
  15222. try {
  15223. switch (type) {
  15224. case ShadingType.AXIAL:
  15225. case ShadingType.RADIAL:
  15226. // Both radial and axial shadings are handled by RadialAxial shading.
  15227. return new Shadings.RadialAxial(dict, matrix, xref, res);
  15228. case ShadingType.FREE_FORM_MESH:
  15229. case ShadingType.LATTICE_FORM_MESH:
  15230. case ShadingType.COONS_PATCH_MESH:
  15231. case ShadingType.TENSOR_PATCH_MESH:
  15232. return new Shadings.Mesh(shading, matrix, xref, res);
  15233. default:
  15234. throw new Error('Unsupported ShadingType: ' + type);
  15235. }
  15236. } catch (ex) {
  15237. if (ex instanceof MissingDataException) {
  15238. throw ex;
  15239. }
  15240. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  15241. warn(ex);
  15242. return new Shadings.Dummy();
  15243. }
  15244. };
  15245. return Pattern;
  15246. })();
  15247. var Shadings = {};
  15248. // A small number to offset the first/last color stops so we can insert ones to
  15249. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  15250. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  15251. // internally so we have to go bigger.
  15252. Shadings.SMALL_NUMBER = 1e-2;
  15253. // Radial and axial shading have very similar implementations
  15254. // If needed, the implementations can be broken into two classes
  15255. Shadings.RadialAxial = (function RadialAxialClosure() {
  15256. function RadialAxial(dict, matrix, xref, res) {
  15257. this.matrix = matrix;
  15258. this.coordsArr = dict.get('Coords');
  15259. this.shadingType = dict.get('ShadingType');
  15260. this.type = 'Pattern';
  15261. var cs = dict.get('ColorSpace', 'CS');
  15262. cs = ColorSpace.parse(cs, xref, res);
  15263. this.cs = cs;
  15264. var t0 = 0.0, t1 = 1.0;
  15265. if (dict.has('Domain')) {
  15266. var domainArr = dict.get('Domain');
  15267. t0 = domainArr[0];
  15268. t1 = domainArr[1];
  15269. }
  15270. var extendStart = false, extendEnd = false;
  15271. if (dict.has('Extend')) {
  15272. var extendArr = dict.get('Extend');
  15273. extendStart = extendArr[0];
  15274. extendEnd = extendArr[1];
  15275. }
  15276. if (this.shadingType === ShadingType.RADIAL &&
  15277. (!extendStart || !extendEnd)) {
  15278. // Radial gradient only currently works if either circle is fully within
  15279. // the other circle.
  15280. var x1 = this.coordsArr[0];
  15281. var y1 = this.coordsArr[1];
  15282. var r1 = this.coordsArr[2];
  15283. var x2 = this.coordsArr[3];
  15284. var y2 = this.coordsArr[4];
  15285. var r2 = this.coordsArr[5];
  15286. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  15287. if (r1 <= r2 + distance &&
  15288. r2 <= r1 + distance) {
  15289. warn('Unsupported radial gradient.');
  15290. }
  15291. }
  15292. this.extendStart = extendStart;
  15293. this.extendEnd = extendEnd;
  15294. var fnObj = dict.get('Function');
  15295. var fn = PDFFunction.parseArray(xref, fnObj);
  15296. // 10 samples seems good enough for now, but probably won't work
  15297. // if there are sharp color changes. Ideally, we would implement
  15298. // the spec faithfully and add lossless optimizations.
  15299. var diff = t1 - t0;
  15300. var step = diff / 10;
  15301. var colorStops = this.colorStops = [];
  15302. // Protect against bad domains so we don't end up in an infinte loop below.
  15303. if (t0 >= t1 || step <= 0) {
  15304. // Acrobat doesn't seem to handle these cases so we'll ignore for
  15305. // now.
  15306. info('Bad shading domain.');
  15307. return;
  15308. }
  15309. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  15310. var rgbColor;
  15311. for (var i = t0; i <= t1; i += step) {
  15312. ratio[0] = i;
  15313. fn(ratio, 0, color, 0);
  15314. rgbColor = cs.getRgb(color, 0);
  15315. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  15316. colorStops.push([(i - t0) / diff, cssColor]);
  15317. }
  15318. var background = 'transparent';
  15319. if (dict.has('Background')) {
  15320. rgbColor = cs.getRgb(dict.get('Background'), 0);
  15321. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  15322. }
  15323. if (!extendStart) {
  15324. // Insert a color stop at the front and offset the first real color stop
  15325. // so it doesn't conflict with the one we insert.
  15326. colorStops.unshift([0, background]);
  15327. colorStops[1][0] += Shadings.SMALL_NUMBER;
  15328. }
  15329. if (!extendEnd) {
  15330. // Same idea as above in extendStart but for the end.
  15331. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  15332. colorStops.push([1, background]);
  15333. }
  15334. this.colorStops = colorStops;
  15335. }
  15336. RadialAxial.prototype = {
  15337. getIR: function RadialAxial_getIR() {
  15338. var coordsArr = this.coordsArr;
  15339. var shadingType = this.shadingType;
  15340. var type, p0, p1, r0, r1;
  15341. if (shadingType === ShadingType.AXIAL) {
  15342. p0 = [coordsArr[0], coordsArr[1]];
  15343. p1 = [coordsArr[2], coordsArr[3]];
  15344. r0 = null;
  15345. r1 = null;
  15346. type = 'axial';
  15347. } else if (shadingType === ShadingType.RADIAL) {
  15348. p0 = [coordsArr[0], coordsArr[1]];
  15349. p1 = [coordsArr[3], coordsArr[4]];
  15350. r0 = coordsArr[2];
  15351. r1 = coordsArr[5];
  15352. type = 'radial';
  15353. } else {
  15354. error('getPattern type unknown: ' + shadingType);
  15355. }
  15356. var matrix = this.matrix;
  15357. if (matrix) {
  15358. p0 = Util.applyTransform(p0, matrix);
  15359. p1 = Util.applyTransform(p1, matrix);
  15360. if (shadingType === ShadingType.RADIAL) {
  15361. var scale = Util.singularValueDecompose2dScale(matrix);
  15362. r0 *= scale[0];
  15363. r1 *= scale[1];
  15364. }
  15365. }
  15366. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  15367. }
  15368. };
  15369. return RadialAxial;
  15370. })();
  15371. // All mesh shading. For now, they will be presented as set of the triangles
  15372. // to be drawn on the canvas and rgb color for each vertex.
  15373. Shadings.Mesh = (function MeshClosure() {
  15374. function MeshStreamReader(stream, context) {
  15375. this.stream = stream;
  15376. this.context = context;
  15377. this.buffer = 0;
  15378. this.bufferLength = 0;
  15379. var numComps = context.numComps;
  15380. this.tmpCompsBuf = new Float32Array(numComps);
  15381. var csNumComps = context.colorSpace.numComps;
  15382. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  15383. this.tmpCompsBuf;
  15384. }
  15385. MeshStreamReader.prototype = {
  15386. get hasData() {
  15387. if (this.stream.end) {
  15388. return this.stream.pos < this.stream.end;
  15389. }
  15390. if (this.bufferLength > 0) {
  15391. return true;
  15392. }
  15393. var nextByte = this.stream.getByte();
  15394. if (nextByte < 0) {
  15395. return false;
  15396. }
  15397. this.buffer = nextByte;
  15398. this.bufferLength = 8;
  15399. return true;
  15400. },
  15401. readBits: function MeshStreamReader_readBits(n) {
  15402. var buffer = this.buffer;
  15403. var bufferLength = this.bufferLength;
  15404. if (n === 32) {
  15405. if (bufferLength === 0) {
  15406. return ((this.stream.getByte() << 24) |
  15407. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  15408. this.stream.getByte()) >>> 0;
  15409. }
  15410. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  15411. (this.stream.getByte() << 8) | this.stream.getByte();
  15412. var nextByte = this.stream.getByte();
  15413. this.buffer = nextByte & ((1 << bufferLength) - 1);
  15414. return ((buffer << (8 - bufferLength)) |
  15415. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  15416. }
  15417. if (n === 8 && bufferLength === 0) {
  15418. return this.stream.getByte();
  15419. }
  15420. while (bufferLength < n) {
  15421. buffer = (buffer << 8) | this.stream.getByte();
  15422. bufferLength += 8;
  15423. }
  15424. bufferLength -= n;
  15425. this.bufferLength = bufferLength;
  15426. this.buffer = buffer & ((1 << bufferLength) - 1);
  15427. return buffer >> bufferLength;
  15428. },
  15429. align: function MeshStreamReader_align() {
  15430. this.buffer = 0;
  15431. this.bufferLength = 0;
  15432. },
  15433. readFlag: function MeshStreamReader_readFlag() {
  15434. return this.readBits(this.context.bitsPerFlag);
  15435. },
  15436. readCoordinate: function MeshStreamReader_readCoordinate() {
  15437. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  15438. var xi = this.readBits(bitsPerCoordinate);
  15439. var yi = this.readBits(bitsPerCoordinate);
  15440. var decode = this.context.decode;
  15441. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  15442. 2.3283064365386963e-10; // 2 ^ -32
  15443. return [
  15444. xi * scale * (decode[1] - decode[0]) + decode[0],
  15445. yi * scale * (decode[3] - decode[2]) + decode[2]
  15446. ];
  15447. },
  15448. readComponents: function MeshStreamReader_readComponents() {
  15449. var numComps = this.context.numComps;
  15450. var bitsPerComponent = this.context.bitsPerComponent;
  15451. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  15452. 2.3283064365386963e-10; // 2 ^ -32
  15453. var decode = this.context.decode;
  15454. var components = this.tmpCompsBuf;
  15455. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  15456. var ci = this.readBits(bitsPerComponent);
  15457. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  15458. }
  15459. var color = this.tmpCsCompsBuf;
  15460. if (this.context.colorFn) {
  15461. this.context.colorFn(components, 0, color, 0);
  15462. }
  15463. return this.context.colorSpace.getRgb(color, 0);
  15464. }
  15465. };
  15466. function decodeType4Shading(mesh, reader) {
  15467. var coords = mesh.coords;
  15468. var colors = mesh.colors;
  15469. var operators = [];
  15470. var ps = []; // not maintaining cs since that will match ps
  15471. var verticesLeft = 0; // assuming we have all data to start a new triangle
  15472. while (reader.hasData) {
  15473. var f = reader.readFlag();
  15474. var coord = reader.readCoordinate();
  15475. var color = reader.readComponents();
  15476. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  15477. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  15478. switch (f) {
  15479. case 0:
  15480. verticesLeft = 3;
  15481. break;
  15482. case 1:
  15483. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  15484. verticesLeft = 1;
  15485. break;
  15486. case 2:
  15487. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  15488. verticesLeft = 1;
  15489. break;
  15490. }
  15491. operators.push(f);
  15492. }
  15493. ps.push(coords.length);
  15494. coords.push(coord);
  15495. colors.push(color);
  15496. verticesLeft--;
  15497. reader.align();
  15498. }
  15499. mesh.figures.push({
  15500. type: 'triangles',
  15501. coords: new Int32Array(ps),
  15502. colors: new Int32Array(ps),
  15503. });
  15504. }
  15505. function decodeType5Shading(mesh, reader, verticesPerRow) {
  15506. var coords = mesh.coords;
  15507. var colors = mesh.colors;
  15508. var ps = []; // not maintaining cs since that will match ps
  15509. while (reader.hasData) {
  15510. var coord = reader.readCoordinate();
  15511. var color = reader.readComponents();
  15512. ps.push(coords.length);
  15513. coords.push(coord);
  15514. colors.push(color);
  15515. }
  15516. mesh.figures.push({
  15517. type: 'lattice',
  15518. coords: new Int32Array(ps),
  15519. colors: new Int32Array(ps),
  15520. verticesPerRow: verticesPerRow
  15521. });
  15522. }
  15523. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  15524. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  15525. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  15526. var getB = (function getBClosure() {
  15527. function buildB(count) {
  15528. var lut = [];
  15529. for (var i = 0; i <= count; i++) {
  15530. var t = i / count, t_ = 1 - t;
  15531. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  15532. 3 * t * t * t_, t * t * t]));
  15533. }
  15534. return lut;
  15535. }
  15536. var cache = [];
  15537. return function getB(count) {
  15538. if (!cache[count]) {
  15539. cache[count] = buildB(count);
  15540. }
  15541. return cache[count];
  15542. };
  15543. })();
  15544. function buildFigureFromPatch(mesh, index) {
  15545. var figure = mesh.figures[index];
  15546. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  15547. var coords = mesh.coords, colors = mesh.colors;
  15548. var pi = figure.coords;
  15549. var ci = figure.colors;
  15550. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  15551. coords[pi[12]][0], coords[pi[15]][0]);
  15552. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  15553. coords[pi[12]][1], coords[pi[15]][1]);
  15554. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  15555. coords[pi[12]][0], coords[pi[15]][0]);
  15556. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  15557. coords[pi[12]][1], coords[pi[15]][1]);
  15558. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  15559. (mesh.bounds[2] - mesh.bounds[0]));
  15560. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  15561. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  15562. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  15563. (mesh.bounds[3] - mesh.bounds[1]));
  15564. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  15565. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  15566. var verticesPerRow = splitXBy + 1;
  15567. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  15568. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  15569. var k = 0;
  15570. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  15571. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  15572. c2 = colors[ci[2]], c3 = colors[ci[3]];
  15573. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  15574. for (var row = 0; row <= splitYBy; row++) {
  15575. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  15576. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  15577. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  15578. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  15579. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  15580. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  15581. for (var col = 0; col <= splitXBy; col++, k++) {
  15582. if ((row === 0 || row === splitYBy) &&
  15583. (col === 0 || col === splitXBy)) {
  15584. continue;
  15585. }
  15586. var x = 0, y = 0;
  15587. var q = 0;
  15588. for (var i = 0; i <= 3; i++) {
  15589. for (var j = 0; j <= 3; j++, q++) {
  15590. var m = bRow[row][i] * bCol[col][j];
  15591. x += coords[pi[q]][0] * m;
  15592. y += coords[pi[q]][1] * m;
  15593. }
  15594. }
  15595. figureCoords[k] = coords.length;
  15596. coords.push([x, y]);
  15597. figureColors[k] = colors.length;
  15598. var newColor = new Uint8Array(3);
  15599. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  15600. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  15601. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  15602. colors.push(newColor);
  15603. }
  15604. }
  15605. figureCoords[0] = pi[0];
  15606. figureColors[0] = ci[0];
  15607. figureCoords[splitXBy] = pi[3];
  15608. figureColors[splitXBy] = ci[1];
  15609. figureCoords[verticesPerRow * splitYBy] = pi[12];
  15610. figureColors[verticesPerRow * splitYBy] = ci[2];
  15611. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  15612. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  15613. mesh.figures[index] = {
  15614. type: 'lattice',
  15615. coords: figureCoords,
  15616. colors: figureColors,
  15617. verticesPerRow: verticesPerRow
  15618. };
  15619. }
  15620. function decodeType6Shading(mesh, reader) {
  15621. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  15622. var coords = mesh.coords;
  15623. var colors = mesh.colors;
  15624. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  15625. var cs = new Int32Array(4); // c00, c30, c03, c33
  15626. while (reader.hasData) {
  15627. var f = reader.readFlag();
  15628. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  15629. var i, ii;
  15630. var pi = coords.length;
  15631. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  15632. coords.push(reader.readCoordinate());
  15633. }
  15634. var ci = colors.length;
  15635. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  15636. colors.push(reader.readComponents());
  15637. }
  15638. var tmp1, tmp2, tmp3, tmp4;
  15639. switch (f) {
  15640. case 0:
  15641. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  15642. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  15643. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  15644. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  15645. cs[2] = ci + 1; cs[3] = ci + 2;
  15646. cs[0] = ci; cs[1] = ci + 3;
  15647. break;
  15648. case 1:
  15649. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  15650. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15651. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  15652. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  15653. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15654. tmp1 = cs[2]; tmp2 = cs[3];
  15655. cs[2] = tmp2; cs[3] = ci;
  15656. cs[0] = tmp1; cs[1] = ci + 1;
  15657. break;
  15658. case 2:
  15659. tmp1 = ps[15];
  15660. tmp2 = ps[11];
  15661. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15662. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  15663. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  15664. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15665. tmp1 = cs[3];
  15666. cs[2] = cs[1]; cs[3] = ci;
  15667. cs[0] = tmp1; cs[1] = ci + 1;
  15668. break;
  15669. case 3:
  15670. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15671. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  15672. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  15673. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15674. cs[2] = cs[0]; cs[3] = ci;
  15675. cs[0] = cs[1]; cs[1] = ci + 1;
  15676. break;
  15677. }
  15678. // set p11, p12, p21, p22
  15679. ps[5] = coords.length;
  15680. coords.push([
  15681. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  15682. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  15683. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  15684. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  15685. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  15686. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  15687. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  15688. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  15689. ]);
  15690. ps[6] = coords.length;
  15691. coords.push([
  15692. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  15693. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  15694. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  15695. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  15696. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  15697. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  15698. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  15699. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  15700. ]);
  15701. ps[9] = coords.length;
  15702. coords.push([
  15703. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  15704. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  15705. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  15706. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  15707. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  15708. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  15709. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  15710. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  15711. ]);
  15712. ps[10] = coords.length;
  15713. coords.push([
  15714. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  15715. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  15716. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  15717. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  15718. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  15719. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  15720. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  15721. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  15722. ]);
  15723. mesh.figures.push({
  15724. type: 'patch',
  15725. coords: new Int32Array(ps), // making copies of ps and cs
  15726. colors: new Int32Array(cs)
  15727. });
  15728. }
  15729. }
  15730. function decodeType7Shading(mesh, reader) {
  15731. var coords = mesh.coords;
  15732. var colors = mesh.colors;
  15733. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  15734. var cs = new Int32Array(4); // c00, c30, c03, c33
  15735. while (reader.hasData) {
  15736. var f = reader.readFlag();
  15737. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  15738. var i, ii;
  15739. var pi = coords.length;
  15740. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  15741. coords.push(reader.readCoordinate());
  15742. }
  15743. var ci = colors.length;
  15744. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  15745. colors.push(reader.readComponents());
  15746. }
  15747. var tmp1, tmp2, tmp3, tmp4;
  15748. switch (f) {
  15749. case 0:
  15750. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  15751. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  15752. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  15753. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  15754. cs[2] = ci + 1; cs[3] = ci + 2;
  15755. cs[0] = ci; cs[1] = ci + 3;
  15756. break;
  15757. case 1:
  15758. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  15759. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15760. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  15761. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  15762. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15763. tmp1 = cs[2]; tmp2 = cs[3];
  15764. cs[2] = tmp2; cs[3] = ci;
  15765. cs[0] = tmp1; cs[1] = ci + 1;
  15766. break;
  15767. case 2:
  15768. tmp1 = ps[15];
  15769. tmp2 = ps[11];
  15770. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15771. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  15772. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  15773. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15774. tmp1 = cs[3];
  15775. cs[2] = cs[1]; cs[3] = ci;
  15776. cs[0] = tmp1; cs[1] = ci + 1;
  15777. break;
  15778. case 3:
  15779. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  15780. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  15781. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  15782. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  15783. cs[2] = cs[0]; cs[3] = ci;
  15784. cs[0] = cs[1]; cs[1] = ci + 1;
  15785. break;
  15786. }
  15787. mesh.figures.push({
  15788. type: 'patch',
  15789. coords: new Int32Array(ps), // making copies of ps and cs
  15790. colors: new Int32Array(cs)
  15791. });
  15792. }
  15793. }
  15794. function updateBounds(mesh) {
  15795. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  15796. maxX = minX, maxY = minY;
  15797. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  15798. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  15799. minX = minX > x ? x : minX;
  15800. minY = minY > y ? y : minY;
  15801. maxX = maxX < x ? x : maxX;
  15802. maxY = maxY < y ? y : maxY;
  15803. }
  15804. mesh.bounds = [minX, minY, maxX, maxY];
  15805. }
  15806. function packData(mesh) {
  15807. var i, ii, j, jj;
  15808. var coords = mesh.coords;
  15809. var coordsPacked = new Float32Array(coords.length * 2);
  15810. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  15811. var xy = coords[i];
  15812. coordsPacked[j++] = xy[0];
  15813. coordsPacked[j++] = xy[1];
  15814. }
  15815. mesh.coords = coordsPacked;
  15816. var colors = mesh.colors;
  15817. var colorsPacked = new Uint8Array(colors.length * 3);
  15818. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  15819. var c = colors[i];
  15820. colorsPacked[j++] = c[0];
  15821. colorsPacked[j++] = c[1];
  15822. colorsPacked[j++] = c[2];
  15823. }
  15824. mesh.colors = colorsPacked;
  15825. var figures = mesh.figures;
  15826. for (i = 0, ii = figures.length; i < ii; i++) {
  15827. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  15828. for (j = 0, jj = ps.length; j < jj; j++) {
  15829. ps[j] *= 2;
  15830. cs[j] *= 3;
  15831. }
  15832. }
  15833. }
  15834. function Mesh(stream, matrix, xref, res) {
  15835. assert(isStream(stream), 'Mesh data is not a stream');
  15836. var dict = stream.dict;
  15837. this.matrix = matrix;
  15838. this.shadingType = dict.get('ShadingType');
  15839. this.type = 'Pattern';
  15840. this.bbox = dict.get('BBox');
  15841. var cs = dict.get('ColorSpace', 'CS');
  15842. cs = ColorSpace.parse(cs, xref, res);
  15843. this.cs = cs;
  15844. this.background = dict.has('Background') ?
  15845. cs.getRgb(dict.get('Background'), 0) : null;
  15846. var fnObj = dict.get('Function');
  15847. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  15848. this.coords = [];
  15849. this.colors = [];
  15850. this.figures = [];
  15851. var decodeContext = {
  15852. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  15853. bitsPerComponent: dict.get('BitsPerComponent'),
  15854. bitsPerFlag: dict.get('BitsPerFlag'),
  15855. decode: dict.get('Decode'),
  15856. colorFn: fn,
  15857. colorSpace: cs,
  15858. numComps: fn ? 1 : cs.numComps
  15859. };
  15860. var reader = new MeshStreamReader(stream, decodeContext);
  15861. var patchMesh = false;
  15862. switch (this.shadingType) {
  15863. case ShadingType.FREE_FORM_MESH:
  15864. decodeType4Shading(this, reader);
  15865. break;
  15866. case ShadingType.LATTICE_FORM_MESH:
  15867. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  15868. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  15869. decodeType5Shading(this, reader, verticesPerRow);
  15870. break;
  15871. case ShadingType.COONS_PATCH_MESH:
  15872. decodeType6Shading(this, reader);
  15873. patchMesh = true;
  15874. break;
  15875. case ShadingType.TENSOR_PATCH_MESH:
  15876. decodeType7Shading(this, reader);
  15877. patchMesh = true;
  15878. break;
  15879. default:
  15880. error('Unsupported mesh type.');
  15881. break;
  15882. }
  15883. if (patchMesh) {
  15884. // dirty bounds calculation for determining, how dense shall be triangles
  15885. updateBounds(this);
  15886. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  15887. buildFigureFromPatch(this, i);
  15888. }
  15889. }
  15890. // calculate bounds
  15891. updateBounds(this);
  15892. packData(this);
  15893. }
  15894. Mesh.prototype = {
  15895. getIR: function Mesh_getIR() {
  15896. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  15897. this.bounds, this.matrix, this.bbox, this.background];
  15898. }
  15899. };
  15900. return Mesh;
  15901. })();
  15902. Shadings.Dummy = (function DummyClosure() {
  15903. function Dummy() {
  15904. this.type = 'Pattern';
  15905. }
  15906. Dummy.prototype = {
  15907. getIR: function Dummy_getIR() {
  15908. return ['Dummy'];
  15909. }
  15910. };
  15911. return Dummy;
  15912. })();
  15913. function getTilingPatternIR(operatorList, dict, args) {
  15914. var matrix = dict.get('Matrix');
  15915. var bbox = dict.get('BBox');
  15916. var xstep = dict.get('XStep');
  15917. var ystep = dict.get('YStep');
  15918. var paintType = dict.get('PaintType');
  15919. var tilingType = dict.get('TilingType');
  15920. return [
  15921. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  15922. paintType, tilingType
  15923. ];
  15924. }
  15925. var PartialEvaluator = (function PartialEvaluatorClosure() {
  15926. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  15927. uniquePrefix, idCounters, fontCache) {
  15928. this.pdfManager = pdfManager;
  15929. this.xref = xref;
  15930. this.handler = handler;
  15931. this.pageIndex = pageIndex;
  15932. this.uniquePrefix = uniquePrefix;
  15933. this.idCounters = idCounters;
  15934. this.fontCache = fontCache;
  15935. }
  15936. // Trying to minimize Date.now() usage and check every 100 time
  15937. var TIME_SLOT_DURATION_MS = 20;
  15938. var CHECK_TIME_EVERY = 100;
  15939. function TimeSlotManager() {
  15940. this.reset();
  15941. }
  15942. TimeSlotManager.prototype = {
  15943. check: function TimeSlotManager_check() {
  15944. if (++this.checked < CHECK_TIME_EVERY) {
  15945. return false;
  15946. }
  15947. this.checked = 0;
  15948. return this.endTime <= Date.now();
  15949. },
  15950. reset: function TimeSlotManager_reset() {
  15951. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  15952. this.checked = 0;
  15953. }
  15954. };
  15955. var deferred = Promise.resolve();
  15956. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  15957. PartialEvaluator.prototype = {
  15958. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  15959. if (!isDict(resources)) {
  15960. return false;
  15961. }
  15962. var processed = Object.create(null);
  15963. if (resources.objId) {
  15964. processed[resources.objId] = true;
  15965. }
  15966. var nodes = [resources];
  15967. while (nodes.length) {
  15968. var key;
  15969. var node = nodes.shift();
  15970. // First check the current resources for blend modes.
  15971. var graphicStates = node.get('ExtGState');
  15972. if (isDict(graphicStates)) {
  15973. graphicStates = graphicStates.getAll();
  15974. for (key in graphicStates) {
  15975. var graphicState = graphicStates[key];
  15976. var bm = graphicState['BM'];
  15977. if (isName(bm) && bm.name !== 'Normal') {
  15978. return true;
  15979. }
  15980. }
  15981. }
  15982. // Descend into the XObjects to look for more resources and blend modes.
  15983. var xObjects = node.get('XObject');
  15984. if (!isDict(xObjects)) {
  15985. continue;
  15986. }
  15987. xObjects = xObjects.getAll();
  15988. for (key in xObjects) {
  15989. var xObject = xObjects[key];
  15990. if (!isStream(xObject)) {
  15991. continue;
  15992. }
  15993. if (xObject.dict.objId) {
  15994. if (processed[xObject.dict.objId]) {
  15995. // stream has objId and is processed already
  15996. continue;
  15997. }
  15998. processed[xObject.dict.objId] = true;
  15999. }
  16000. var xResources = xObject.dict.get('Resources');
  16001. // Checking objId to detect an infinite loop.
  16002. if (isDict(xResources) &&
  16003. (!xResources.objId || !processed[xResources.objId])) {
  16004. nodes.push(xResources);
  16005. if (xResources.objId) {
  16006. processed[xResources.objId] = true;
  16007. }
  16008. }
  16009. }
  16010. }
  16011. return false;
  16012. },
  16013. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  16014. xobj, smask,
  16015. operatorList,
  16016. task,
  16017. initialState) {
  16018. var matrix = xobj.dict.getArray('Matrix');
  16019. var bbox = xobj.dict.getArray('BBox');
  16020. var group = xobj.dict.get('Group');
  16021. if (group) {
  16022. var groupOptions = {
  16023. matrix: matrix,
  16024. bbox: bbox,
  16025. smask: smask,
  16026. isolated: false,
  16027. knockout: false
  16028. };
  16029. var groupSubtype = group.get('S');
  16030. var colorSpace;
  16031. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  16032. groupOptions.isolated = (group.get('I') || false);
  16033. groupOptions.knockout = (group.get('K') || false);
  16034. colorSpace = (group.has('CS') ?
  16035. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  16036. }
  16037. if (smask && smask.backdrop) {
  16038. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  16039. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  16040. }
  16041. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  16042. }
  16043. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  16044. return this.getOperatorList(xobj, task,
  16045. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  16046. then(function () {
  16047. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  16048. if (group) {
  16049. operatorList.addOp(OPS.endGroup, [groupOptions]);
  16050. }
  16051. });
  16052. },
  16053. buildPaintImageXObject:
  16054. function PartialEvaluator_buildPaintImageXObject(resources, image,
  16055. inline, operatorList,
  16056. cacheKey, imageCache) {
  16057. var self = this;
  16058. var dict = image.dict;
  16059. var w = dict.get('Width', 'W');
  16060. var h = dict.get('Height', 'H');
  16061. if (!(w && isNum(w)) || !(h && isNum(h))) {
  16062. warn('Image dimensions are missing, or not numbers.');
  16063. return;
  16064. }
  16065. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  16066. warn('Image exceeded maximum allowed size and was removed.');
  16067. return;
  16068. }
  16069. var imageMask = (dict.get('ImageMask', 'IM') || false);
  16070. var imgData, args;
  16071. if (imageMask) {
  16072. // This depends on a tmpCanvas being filled with the
  16073. // current fillStyle, such that processing the pixel
  16074. // data can't be done here. Instead of creating a
  16075. // complete PDFImage, only read the information needed
  16076. // for later.
  16077. var width = dict.get('Width', 'W');
  16078. var height = dict.get('Height', 'H');
  16079. var bitStrideLength = (width + 7) >> 3;
  16080. var imgArray = image.getBytes(bitStrideLength * height);
  16081. var decode = dict.get('Decode', 'D');
  16082. var inverseDecode = (!!decode && decode[0] > 0);
  16083. imgData = PDFImage.createMask(imgArray, width, height,
  16084. image instanceof DecodeStream,
  16085. inverseDecode);
  16086. imgData.cached = true;
  16087. args = [imgData];
  16088. operatorList.addOp(OPS.paintImageMaskXObject, args);
  16089. if (cacheKey) {
  16090. imageCache[cacheKey] = {
  16091. fn: OPS.paintImageMaskXObject,
  16092. args: args
  16093. };
  16094. }
  16095. return;
  16096. }
  16097. var softMask = (dict.get('SMask', 'SM') || false);
  16098. var mask = (dict.get('Mask') || false);
  16099. var SMALL_IMAGE_DIMENSIONS = 200;
  16100. // Inlining small images into the queue as RGB data
  16101. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  16102. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  16103. var imageObj = new PDFImage(this.xref, resources, image,
  16104. inline, null, null);
  16105. // We force the use of RGBA_32BPP images here, because we can't handle
  16106. // any other kind.
  16107. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  16108. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  16109. return;
  16110. }
  16111. // If there is no imageMask, create the PDFImage and a lot
  16112. // of image processing can be done here.
  16113. var uniquePrefix = (this.uniquePrefix || '');
  16114. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  16115. operatorList.addDependency(objId);
  16116. args = [objId, w, h];
  16117. if (!softMask && !mask && image instanceof JpegStream &&
  16118. image.isNativelySupported(this.xref, resources)) {
  16119. // These JPEGs don't need any more processing so we can just send it.
  16120. operatorList.addOp(OPS.paintJpegXObject, args);
  16121. this.handler.send('obj',
  16122. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  16123. return;
  16124. }
  16125. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  16126. then(function(imageObj) {
  16127. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  16128. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  16129. [imgData.data.buffer]);
  16130. }).then(undefined, function (reason) {
  16131. warn('Unable to decode image: ' + reason);
  16132. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  16133. });
  16134. operatorList.addOp(OPS.paintImageXObject, args);
  16135. if (cacheKey) {
  16136. imageCache[cacheKey] = {
  16137. fn: OPS.paintImageXObject,
  16138. args: args
  16139. };
  16140. }
  16141. },
  16142. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  16143. operatorList, task,
  16144. stateManager) {
  16145. var smaskContent = smask.get('G');
  16146. var smaskOptions = {
  16147. subtype: smask.get('S').name,
  16148. backdrop: smask.get('BC')
  16149. };
  16150. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  16151. operatorList, task, stateManager.state.clone());
  16152. },
  16153. handleTilingType:
  16154. function PartialEvaluator_handleTilingType(fn, args, resources,
  16155. pattern, patternDict,
  16156. operatorList, task) {
  16157. // Create an IR of the pattern code.
  16158. var tilingOpList = new OperatorList();
  16159. // Merge the available resources, to prevent issues when the patternDict
  16160. // is missing some /Resources entries (fixes issue6541.pdf).
  16161. var resourcesArray = [patternDict.get('Resources'), resources];
  16162. var patternResources = Dict.merge(this.xref, resourcesArray);
  16163. return this.getOperatorList(pattern, task, patternResources,
  16164. tilingOpList).then(function () {
  16165. // Add the dependencies to the parent operator list so they are
  16166. // resolved before sub operator list is executed synchronously.
  16167. operatorList.addDependencies(tilingOpList.dependencies);
  16168. operatorList.addOp(fn, getTilingPatternIR({
  16169. fnArray: tilingOpList.fnArray,
  16170. argsArray: tilingOpList.argsArray
  16171. }, patternDict, args));
  16172. });
  16173. },
  16174. handleSetFont:
  16175. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  16176. operatorList, task, state) {
  16177. // TODO(mack): Not needed?
  16178. var fontName;
  16179. if (fontArgs) {
  16180. fontArgs = fontArgs.slice();
  16181. fontName = fontArgs[0].name;
  16182. }
  16183. var self = this;
  16184. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  16185. function (translated) {
  16186. if (!translated.font.isType3Font) {
  16187. return translated;
  16188. }
  16189. return translated.loadType3Data(self, resources, operatorList, task).
  16190. then(function () {
  16191. return translated;
  16192. });
  16193. }).then(function (translated) {
  16194. state.font = translated.font;
  16195. translated.send(self.handler);
  16196. return translated.loadedName;
  16197. });
  16198. },
  16199. handleText: function PartialEvaluator_handleText(chars, state) {
  16200. var font = state.font;
  16201. var glyphs = font.charsToGlyphs(chars);
  16202. var isAddToPathSet = !!(state.textRenderingMode &
  16203. TextRenderingMode.ADD_TO_PATH_FLAG);
  16204. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  16205. var buildPath = function (fontChar) {
  16206. if (!font.renderer.hasBuiltPath(fontChar)) {
  16207. var path = font.renderer.getPathJs(fontChar);
  16208. this.handler.send('commonobj', [
  16209. font.loadedName + '_path_' + fontChar,
  16210. 'FontPath',
  16211. path
  16212. ]);
  16213. }
  16214. }.bind(this);
  16215. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  16216. var glyph = glyphs[i];
  16217. buildPath(glyph.fontChar);
  16218. // If the glyph has an accent we need to build a path for its
  16219. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  16220. var accent = glyph.accent;
  16221. if (accent && accent.fontChar) {
  16222. buildPath(accent.fontChar);
  16223. }
  16224. }
  16225. }
  16226. return glyphs;
  16227. },
  16228. setGState: function PartialEvaluator_setGState(resources, gState,
  16229. operatorList, task,
  16230. xref, stateManager) {
  16231. // This array holds the converted/processed state data.
  16232. var gStateObj = [];
  16233. var gStateMap = gState.map;
  16234. var self = this;
  16235. var promise = Promise.resolve();
  16236. for (var key in gStateMap) {
  16237. var value = gStateMap[key];
  16238. switch (key) {
  16239. case 'Type':
  16240. break;
  16241. case 'LW':
  16242. case 'LC':
  16243. case 'LJ':
  16244. case 'ML':
  16245. case 'D':
  16246. case 'RI':
  16247. case 'FL':
  16248. case 'CA':
  16249. case 'ca':
  16250. gStateObj.push([key, value]);
  16251. break;
  16252. case 'Font':
  16253. promise = promise.then(function () {
  16254. return self.handleSetFont(resources, null, value[0], operatorList,
  16255. task, stateManager.state).
  16256. then(function (loadedName) {
  16257. operatorList.addDependency(loadedName);
  16258. gStateObj.push([key, [loadedName, value[1]]]);
  16259. });
  16260. });
  16261. break;
  16262. case 'BM':
  16263. gStateObj.push([key, value]);
  16264. break;
  16265. case 'SMask':
  16266. if (isName(value) && value.name === 'None') {
  16267. gStateObj.push([key, false]);
  16268. break;
  16269. }
  16270. var dict = xref.fetchIfRef(value);
  16271. if (isDict(dict)) {
  16272. promise = promise.then(function () {
  16273. return self.handleSMask(dict, resources, operatorList,
  16274. task, stateManager);
  16275. });
  16276. gStateObj.push([key, true]);
  16277. } else {
  16278. warn('Unsupported SMask type');
  16279. }
  16280. break;
  16281. // Only generate info log messages for the following since
  16282. // they are unlikely to have a big impact on the rendering.
  16283. case 'OP':
  16284. case 'op':
  16285. case 'OPM':
  16286. case 'BG':
  16287. case 'BG2':
  16288. case 'UCR':
  16289. case 'UCR2':
  16290. case 'TR':
  16291. case 'TR2':
  16292. case 'HT':
  16293. case 'SM':
  16294. case 'SA':
  16295. case 'AIS':
  16296. case 'TK':
  16297. // TODO implement these operators.
  16298. info('graphic state operator ' + key);
  16299. break;
  16300. default:
  16301. info('Unknown graphic state operator ' + key);
  16302. break;
  16303. }
  16304. }
  16305. return promise.then(function () {
  16306. if (gStateObj.length >= 0) {
  16307. operatorList.addOp(OPS.setGState, [gStateObj]);
  16308. }
  16309. });
  16310. },
  16311. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  16312. resources) {
  16313. function errorFont() {
  16314. return Promise.resolve(new TranslatedFont('g_font_error',
  16315. new ErrorFont('Font ' + fontName + ' is not available'), font));
  16316. }
  16317. var fontRef;
  16318. if (font) { // Loading by ref.
  16319. assert(isRef(font));
  16320. fontRef = font;
  16321. } else { // Loading by name.
  16322. var fontRes = resources.get('Font');
  16323. if (fontRes) {
  16324. fontRef = fontRes.getRaw(fontName);
  16325. } else {
  16326. warn('fontRes not available');
  16327. return errorFont();
  16328. }
  16329. }
  16330. if (!fontRef) {
  16331. warn('fontRef not available');
  16332. return errorFont();
  16333. }
  16334. if (this.fontCache.has(fontRef)) {
  16335. return this.fontCache.get(fontRef);
  16336. }
  16337. font = xref.fetchIfRef(fontRef);
  16338. if (!isDict(font)) {
  16339. return errorFont();
  16340. }
  16341. // We are holding font.translated references just for fontRef that are not
  16342. // dictionaries (Dict). See explanation below.
  16343. if (font.translated) {
  16344. return font.translated;
  16345. }
  16346. var fontCapability = createPromiseCapability();
  16347. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  16348. var descriptor = preEvaluatedFont.descriptor;
  16349. var fontID = fontRef.num + '_' + fontRef.gen;
  16350. if (isDict(descriptor)) {
  16351. if (!descriptor.fontAliases) {
  16352. descriptor.fontAliases = Object.create(null);
  16353. }
  16354. var fontAliases = descriptor.fontAliases;
  16355. var hash = preEvaluatedFont.hash;
  16356. if (fontAliases[hash]) {
  16357. var aliasFontRef = fontAliases[hash].aliasRef;
  16358. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  16359. this.fontCache.putAlias(fontRef, aliasFontRef);
  16360. return this.fontCache.get(fontRef);
  16361. }
  16362. }
  16363. if (!fontAliases[hash]) {
  16364. fontAliases[hash] = {
  16365. fontID: Font.getFontID()
  16366. };
  16367. }
  16368. fontAliases[hash].aliasRef = fontRef;
  16369. fontID = fontAliases[hash].fontID;
  16370. }
  16371. // Workaround for bad PDF generators that don't reference fonts
  16372. // properly, i.e. by not using an object identifier.
  16373. // Check if the fontRef is a Dict (as opposed to a standard object),
  16374. // in which case we don't cache the font and instead reference it by
  16375. // fontName in font.loadedName below.
  16376. var fontRefIsDict = isDict(fontRef);
  16377. if (!fontRefIsDict) {
  16378. this.fontCache.put(fontRef, fontCapability.promise);
  16379. }
  16380. // Keep track of each font we translated so the caller can
  16381. // load them asynchronously before calling display on a page.
  16382. font.loadedName = 'g_font_' + (fontRefIsDict ?
  16383. fontName.replace(/\W/g, '') : fontID);
  16384. font.translated = fontCapability.promise;
  16385. // TODO move promises into translate font
  16386. var translatedPromise;
  16387. try {
  16388. translatedPromise = Promise.resolve(
  16389. this.translateFont(preEvaluatedFont, xref));
  16390. } catch (e) {
  16391. translatedPromise = Promise.reject(e);
  16392. }
  16393. translatedPromise.then(function (translatedFont) {
  16394. if (translatedFont.fontType !== undefined) {
  16395. var xrefFontStats = xref.stats.fontTypes;
  16396. xrefFontStats[translatedFont.fontType] = true;
  16397. }
  16398. fontCapability.resolve(new TranslatedFont(font.loadedName,
  16399. translatedFont, font));
  16400. }, function (reason) {
  16401. // TODO fontCapability.reject?
  16402. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  16403. try {
  16404. // error, but it's still nice to have font type reported
  16405. var descriptor = preEvaluatedFont.descriptor;
  16406. var fontFile3 = descriptor && descriptor.get('FontFile3');
  16407. var subtype = fontFile3 && fontFile3.get('Subtype');
  16408. var fontType = getFontType(preEvaluatedFont.type,
  16409. subtype && subtype.name);
  16410. var xrefFontStats = xref.stats.fontTypes;
  16411. xrefFontStats[fontType] = true;
  16412. } catch (ex) { }
  16413. fontCapability.resolve(new TranslatedFont(font.loadedName,
  16414. new ErrorFont(reason instanceof Error ? reason.message : reason),
  16415. font));
  16416. });
  16417. return fontCapability.promise;
  16418. },
  16419. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  16420. var lastIndex = operatorList.length - 1;
  16421. if (!args) {
  16422. args = [];
  16423. }
  16424. if (lastIndex < 0 ||
  16425. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  16426. operatorList.addOp(OPS.constructPath, [[fn], args]);
  16427. } else {
  16428. var opArgs = operatorList.argsArray[lastIndex];
  16429. opArgs[0].push(fn);
  16430. Array.prototype.push.apply(opArgs[1], args);
  16431. }
  16432. },
  16433. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  16434. cs, patterns, resources, task, xref) {
  16435. // compile tiling patterns
  16436. var patternName = args[args.length - 1];
  16437. // SCN/scn applies patterns along with normal colors
  16438. var pattern;
  16439. if (isName(patternName) &&
  16440. (pattern = patterns.get(patternName.name))) {
  16441. var dict = (isStream(pattern) ? pattern.dict : pattern);
  16442. var typeNum = dict.get('PatternType');
  16443. if (typeNum === TILING_PATTERN) {
  16444. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  16445. return this.handleTilingType(fn, color, resources, pattern,
  16446. dict, operatorList, task);
  16447. } else if (typeNum === SHADING_PATTERN) {
  16448. var shading = dict.get('Shading');
  16449. var matrix = dict.get('Matrix');
  16450. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  16451. operatorList.addOp(fn, pattern.getIR());
  16452. return Promise.resolve();
  16453. } else {
  16454. return Promise.reject('Unknown PatternType: ' + typeNum);
  16455. }
  16456. }
  16457. // TODO shall we fail here?
  16458. operatorList.addOp(fn, args);
  16459. return Promise.resolve();
  16460. },
  16461. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  16462. task,
  16463. resources,
  16464. operatorList,
  16465. initialState) {
  16466. var self = this;
  16467. var xref = this.xref;
  16468. var imageCache = {};
  16469. assert(operatorList);
  16470. resources = (resources || Dict.empty);
  16471. var xobjs = (resources.get('XObject') || Dict.empty);
  16472. var patterns = (resources.get('Pattern') || Dict.empty);
  16473. var stateManager = new StateManager(initialState || new EvalState());
  16474. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  16475. var timeSlotManager = new TimeSlotManager();
  16476. return new Promise(function next(resolve, reject) {
  16477. task.ensureNotTerminated();
  16478. timeSlotManager.reset();
  16479. var stop, operation = {}, i, ii, cs;
  16480. while (!(stop = timeSlotManager.check())) {
  16481. // The arguments parsed by read() are used beyond this loop, so we
  16482. // cannot reuse the same array on each iteration. Therefore we pass
  16483. // in |null| as the initial value (see the comment on
  16484. // EvaluatorPreprocessor_read() for why).
  16485. operation.args = null;
  16486. if (!(preprocessor.read(operation))) {
  16487. break;
  16488. }
  16489. var args = operation.args;
  16490. var fn = operation.fn;
  16491. switch (fn | 0) {
  16492. case OPS.paintXObject:
  16493. if (args[0].code) {
  16494. break;
  16495. }
  16496. // eagerly compile XForm objects
  16497. var name = args[0].name;
  16498. if (!name) {
  16499. warn('XObject must be referred to by name.');
  16500. continue;
  16501. }
  16502. if (imageCache[name] !== undefined) {
  16503. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  16504. args = null;
  16505. continue;
  16506. }
  16507. var xobj = xobjs.get(name);
  16508. if (xobj) {
  16509. assert(isStream(xobj), 'XObject should be a stream');
  16510. var type = xobj.dict.get('Subtype');
  16511. assert(isName(type),
  16512. 'XObject should have a Name subtype');
  16513. if (type.name === 'Form') {
  16514. stateManager.save();
  16515. return self.buildFormXObject(resources, xobj, null,
  16516. operatorList, task,
  16517. stateManager.state.clone()).
  16518. then(function () {
  16519. stateManager.restore();
  16520. next(resolve, reject);
  16521. }, reject);
  16522. } else if (type.name === 'Image') {
  16523. self.buildPaintImageXObject(resources, xobj, false,
  16524. operatorList, name, imageCache);
  16525. args = null;
  16526. continue;
  16527. } else if (type.name === 'PS') {
  16528. // PostScript XObjects are unused when viewing documents.
  16529. // See section 4.7.1 of Adobe's PDF reference.
  16530. info('Ignored XObject subtype PS');
  16531. continue;
  16532. } else {
  16533. error('Unhandled XObject subtype ' + type.name);
  16534. }
  16535. }
  16536. break;
  16537. case OPS.setFont:
  16538. var fontSize = args[1];
  16539. // eagerly collect all fonts
  16540. return self.handleSetFont(resources, args, null, operatorList,
  16541. task, stateManager.state).
  16542. then(function (loadedName) {
  16543. operatorList.addDependency(loadedName);
  16544. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  16545. next(resolve, reject);
  16546. }, reject);
  16547. case OPS.endInlineImage:
  16548. var cacheKey = args[0].cacheKey;
  16549. if (cacheKey) {
  16550. var cacheEntry = imageCache[cacheKey];
  16551. if (cacheEntry !== undefined) {
  16552. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  16553. args = null;
  16554. continue;
  16555. }
  16556. }
  16557. self.buildPaintImageXObject(resources, args[0], true,
  16558. operatorList, cacheKey, imageCache);
  16559. args = null;
  16560. continue;
  16561. case OPS.showText:
  16562. args[0] = self.handleText(args[0], stateManager.state);
  16563. break;
  16564. case OPS.showSpacedText:
  16565. var arr = args[0];
  16566. var combinedGlyphs = [];
  16567. var arrLength = arr.length;
  16568. var state = stateManager.state;
  16569. for (i = 0; i < arrLength; ++i) {
  16570. var arrItem = arr[i];
  16571. if (isString(arrItem)) {
  16572. Array.prototype.push.apply(combinedGlyphs,
  16573. self.handleText(arrItem, state));
  16574. } else if (isNum(arrItem)) {
  16575. combinedGlyphs.push(arrItem);
  16576. }
  16577. }
  16578. args[0] = combinedGlyphs;
  16579. fn = OPS.showText;
  16580. break;
  16581. case OPS.nextLineShowText:
  16582. operatorList.addOp(OPS.nextLine);
  16583. args[0] = self.handleText(args[0], stateManager.state);
  16584. fn = OPS.showText;
  16585. break;
  16586. case OPS.nextLineSetSpacingShowText:
  16587. operatorList.addOp(OPS.nextLine);
  16588. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  16589. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  16590. args[0] = self.handleText(args[0], stateManager.state);
  16591. fn = OPS.showText;
  16592. break;
  16593. case OPS.setTextRenderingMode:
  16594. stateManager.state.textRenderingMode = args[0];
  16595. break;
  16596. case OPS.setFillColorSpace:
  16597. stateManager.state.fillColorSpace =
  16598. ColorSpace.parse(args[0], xref, resources);
  16599. continue;
  16600. case OPS.setStrokeColorSpace:
  16601. stateManager.state.strokeColorSpace =
  16602. ColorSpace.parse(args[0], xref, resources);
  16603. continue;
  16604. case OPS.setFillColor:
  16605. cs = stateManager.state.fillColorSpace;
  16606. args = cs.getRgb(args, 0);
  16607. fn = OPS.setFillRGBColor;
  16608. break;
  16609. case OPS.setStrokeColor:
  16610. cs = stateManager.state.strokeColorSpace;
  16611. args = cs.getRgb(args, 0);
  16612. fn = OPS.setStrokeRGBColor;
  16613. break;
  16614. case OPS.setFillGray:
  16615. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  16616. args = ColorSpace.singletons.gray.getRgb(args, 0);
  16617. fn = OPS.setFillRGBColor;
  16618. break;
  16619. case OPS.setStrokeGray:
  16620. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  16621. args = ColorSpace.singletons.gray.getRgb(args, 0);
  16622. fn = OPS.setStrokeRGBColor;
  16623. break;
  16624. case OPS.setFillCMYKColor:
  16625. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  16626. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  16627. fn = OPS.setFillRGBColor;
  16628. break;
  16629. case OPS.setStrokeCMYKColor:
  16630. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  16631. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  16632. fn = OPS.setStrokeRGBColor;
  16633. break;
  16634. case OPS.setFillRGBColor:
  16635. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  16636. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  16637. break;
  16638. case OPS.setStrokeRGBColor:
  16639. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  16640. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  16641. break;
  16642. case OPS.setFillColorN:
  16643. cs = stateManager.state.fillColorSpace;
  16644. if (cs.name === 'Pattern') {
  16645. return self.handleColorN(operatorList, OPS.setFillColorN,
  16646. args, cs, patterns, resources, task, xref).then(function() {
  16647. next(resolve, reject);
  16648. }, reject);
  16649. }
  16650. args = cs.getRgb(args, 0);
  16651. fn = OPS.setFillRGBColor;
  16652. break;
  16653. case OPS.setStrokeColorN:
  16654. cs = stateManager.state.strokeColorSpace;
  16655. if (cs.name === 'Pattern') {
  16656. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  16657. args, cs, patterns, resources, task, xref).then(function() {
  16658. next(resolve, reject);
  16659. }, reject);
  16660. }
  16661. args = cs.getRgb(args, 0);
  16662. fn = OPS.setStrokeRGBColor;
  16663. break;
  16664. case OPS.shadingFill:
  16665. var shadingRes = resources.get('Shading');
  16666. if (!shadingRes) {
  16667. error('No shading resource found');
  16668. }
  16669. var shading = shadingRes.get(args[0].name);
  16670. if (!shading) {
  16671. error('No shading object found');
  16672. }
  16673. var shadingFill = Pattern.parseShading(shading, null, xref,
  16674. resources);
  16675. var patternIR = shadingFill.getIR();
  16676. args = [patternIR];
  16677. fn = OPS.shadingFill;
  16678. break;
  16679. case OPS.setGState:
  16680. var dictName = args[0];
  16681. var extGState = resources.get('ExtGState');
  16682. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  16683. break;
  16684. }
  16685. var gState = extGState.get(dictName.name);
  16686. return self.setGState(resources, gState, operatorList, task,
  16687. xref, stateManager).then(function() {
  16688. next(resolve, reject);
  16689. }, reject);
  16690. case OPS.moveTo:
  16691. case OPS.lineTo:
  16692. case OPS.curveTo:
  16693. case OPS.curveTo2:
  16694. case OPS.curveTo3:
  16695. case OPS.closePath:
  16696. self.buildPath(operatorList, fn, args);
  16697. continue;
  16698. case OPS.rectangle:
  16699. self.buildPath(operatorList, fn, args);
  16700. continue;
  16701. case OPS.markPoint:
  16702. case OPS.markPointProps:
  16703. case OPS.beginMarkedContent:
  16704. case OPS.beginMarkedContentProps:
  16705. case OPS.endMarkedContent:
  16706. case OPS.beginCompat:
  16707. case OPS.endCompat:
  16708. // Ignore operators where the corresponding handlers are known to
  16709. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  16710. // serialization errors and is also a bit more efficient.
  16711. // We could also try to serialize all objects in a general way,
  16712. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  16713. // but doing so is meaningless without knowing the semantics.
  16714. continue;
  16715. default:
  16716. // Note: Let's hope that the ignored operator does not have any
  16717. // non-serializable arguments, otherwise postMessage will throw
  16718. // "An object could not be cloned.".
  16719. }
  16720. operatorList.addOp(fn, args);
  16721. }
  16722. if (stop) {
  16723. deferred.then(function () {
  16724. next(resolve, reject);
  16725. }, reject);
  16726. return;
  16727. }
  16728. // Some PDFs don't close all restores inside object/form.
  16729. // Closing those for them.
  16730. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  16731. operatorList.addOp(OPS.restore, []);
  16732. }
  16733. resolve();
  16734. });
  16735. },
  16736. getTextContent: function PartialEvaluator_getTextContent(stream, task,
  16737. resources,
  16738. stateManager) {
  16739. stateManager = (stateManager || new StateManager(new TextState()));
  16740. var textContent = {
  16741. items: [],
  16742. styles: Object.create(null)
  16743. };
  16744. var textContentItem = {
  16745. initialized: false,
  16746. str: [],
  16747. width: 0,
  16748. height: 0,
  16749. vertical: false,
  16750. lastAdvanceWidth: 0,
  16751. lastAdvanceHeight: 0,
  16752. textAdvanceScale: 0,
  16753. spaceWidth: 0,
  16754. fakeSpaceMin: Infinity,
  16755. fakeMultiSpaceMin: Infinity,
  16756. fakeMultiSpaceMax: -0,
  16757. textRunBreakAllowed: false,
  16758. transform: null,
  16759. fontName: null
  16760. };
  16761. var SPACE_FACTOR = 0.3;
  16762. var MULTI_SPACE_FACTOR = 1.5;
  16763. var MULTI_SPACE_FACTOR_MAX = 4;
  16764. var self = this;
  16765. var xref = this.xref;
  16766. resources = (xref.fetchIfRef(resources) || Dict.empty);
  16767. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  16768. var xobjs = null;
  16769. var xobjsCache = {};
  16770. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  16771. var textState;
  16772. function ensureTextContentItem() {
  16773. if (textContentItem.initialized) {
  16774. return textContentItem;
  16775. }
  16776. var font = textState.font;
  16777. if (!(font.loadedName in textContent.styles)) {
  16778. textContent.styles[font.loadedName] = {
  16779. fontFamily: font.fallbackName,
  16780. ascent: font.ascent,
  16781. descent: font.descent,
  16782. vertical: font.vertical
  16783. };
  16784. }
  16785. textContentItem.fontName = font.loadedName;
  16786. // 9.4.4 Text Space Details
  16787. var tsm = [textState.fontSize * textState.textHScale, 0,
  16788. 0, textState.fontSize,
  16789. 0, textState.textRise];
  16790. if (font.isType3Font &&
  16791. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  16792. textState.fontSize === 1) {
  16793. var glyphHeight = font.bbox[3] - font.bbox[1];
  16794. if (glyphHeight > 0) {
  16795. glyphHeight = glyphHeight * textState.fontMatrix[3];
  16796. tsm[3] *= glyphHeight;
  16797. }
  16798. }
  16799. var trm = Util.transform(textState.ctm,
  16800. Util.transform(textState.textMatrix, tsm));
  16801. textContentItem.transform = trm;
  16802. if (!font.vertical) {
  16803. textContentItem.width = 0;
  16804. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  16805. textContentItem.vertical = false;
  16806. } else {
  16807. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  16808. textContentItem.height = 0;
  16809. textContentItem.vertical = true;
  16810. }
  16811. var a = textState.textLineMatrix[0];
  16812. var b = textState.textLineMatrix[1];
  16813. var scaleLineX = Math.sqrt(a * a + b * b);
  16814. a = textState.ctm[0];
  16815. b = textState.ctm[1];
  16816. var scaleCtmX = Math.sqrt(a * a + b * b);
  16817. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  16818. textContentItem.lastAdvanceWidth = 0;
  16819. textContentItem.lastAdvanceHeight = 0;
  16820. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  16821. if (spaceWidth) {
  16822. textContentItem.spaceWidth = spaceWidth;
  16823. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  16824. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  16825. textContentItem.fakeMultiSpaceMax =
  16826. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  16827. // It's okay for monospace fonts to fake as much space as needed.
  16828. textContentItem.textRunBreakAllowed = !font.isMonospace;
  16829. } else {
  16830. textContentItem.spaceWidth = 0;
  16831. textContentItem.fakeSpaceMin = Infinity;
  16832. textContentItem.fakeMultiSpaceMin = Infinity;
  16833. textContentItem.fakeMultiSpaceMax = 0;
  16834. textContentItem.textRunBreakAllowed = false;
  16835. }
  16836. textContentItem.initialized = true;
  16837. return textContentItem;
  16838. }
  16839. function runBidiTransform(textChunk) {
  16840. var str = textChunk.str.join('');
  16841. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  16842. return {
  16843. str: bidiResult.str,
  16844. dir: bidiResult.dir,
  16845. width: textChunk.width,
  16846. height: textChunk.height,
  16847. transform: textChunk.transform,
  16848. fontName: textChunk.fontName
  16849. };
  16850. }
  16851. function handleSetFont(fontName, fontRef) {
  16852. return self.loadFont(fontName, fontRef, xref, resources).
  16853. then(function (translated) {
  16854. textState.font = translated.font;
  16855. textState.fontMatrix = translated.font.fontMatrix ||
  16856. FONT_IDENTITY_MATRIX;
  16857. });
  16858. }
  16859. function buildTextContentItem(chars) {
  16860. var font = textState.font;
  16861. var textChunk = ensureTextContentItem();
  16862. var width = 0;
  16863. var height = 0;
  16864. var glyphs = font.charsToGlyphs(chars);
  16865. var defaultVMetrics = font.defaultVMetrics;
  16866. for (var i = 0; i < glyphs.length; i++) {
  16867. var glyph = glyphs[i];
  16868. var vMetricX = null;
  16869. var vMetricY = null;
  16870. var glyphWidth = null;
  16871. if (font.vertical) {
  16872. if (glyph.vmetric) {
  16873. glyphWidth = glyph.vmetric[0];
  16874. vMetricX = glyph.vmetric[1];
  16875. vMetricY = glyph.vmetric[2];
  16876. } else {
  16877. glyphWidth = glyph.width;
  16878. vMetricX = glyph.width * 0.5;
  16879. vMetricY = defaultVMetrics[2];
  16880. }
  16881. } else {
  16882. glyphWidth = glyph.width;
  16883. }
  16884. var glyphUnicode = glyph.unicode;
  16885. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  16886. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  16887. }
  16888. glyphUnicode = reverseIfRtl(glyphUnicode);
  16889. // The following will calculate the x and y of the individual glyphs.
  16890. // if (font.vertical) {
  16891. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  16892. // textState.fontMatrix[0];
  16893. // tsm[5] -= vMetricY * textState.fontSize *
  16894. // textState.fontMatrix[0];
  16895. // }
  16896. // var trm = Util.transform(textState.textMatrix, tsm);
  16897. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  16898. // var x = pt[0];
  16899. // var y = pt[1];
  16900. var charSpacing = textState.charSpacing;
  16901. if (glyph.isSpace) {
  16902. var wordSpacing = textState.wordSpacing;
  16903. charSpacing += wordSpacing;
  16904. if (wordSpacing > 0) {
  16905. addFakeSpaces(wordSpacing, textChunk.str);
  16906. }
  16907. }
  16908. var tx = 0;
  16909. var ty = 0;
  16910. if (!font.vertical) {
  16911. var w0 = glyphWidth * textState.fontMatrix[0];
  16912. tx = (w0 * textState.fontSize + charSpacing) *
  16913. textState.textHScale;
  16914. width += tx;
  16915. } else {
  16916. var w1 = glyphWidth * textState.fontMatrix[0];
  16917. ty = w1 * textState.fontSize + charSpacing;
  16918. height += ty;
  16919. }
  16920. textState.translateTextMatrix(tx, ty);
  16921. textChunk.str.push(glyphUnicode);
  16922. }
  16923. if (!font.vertical) {
  16924. textChunk.lastAdvanceWidth = width;
  16925. textChunk.width += width * textChunk.textAdvanceScale;
  16926. } else {
  16927. textChunk.lastAdvanceHeight = height;
  16928. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  16929. }
  16930. return textChunk;
  16931. }
  16932. function addFakeSpaces(width, strBuf) {
  16933. if (width < textContentItem.fakeSpaceMin) {
  16934. return;
  16935. }
  16936. if (width < textContentItem.fakeMultiSpaceMin) {
  16937. strBuf.push(' ');
  16938. return;
  16939. }
  16940. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  16941. while (fakeSpaces-- > 0) {
  16942. strBuf.push(' ');
  16943. }
  16944. }
  16945. function flushTextContentItem() {
  16946. if (!textContentItem.initialized) {
  16947. return;
  16948. }
  16949. textContent.items.push(runBidiTransform(textContentItem));
  16950. textContentItem.initialized = false;
  16951. textContentItem.str.length = 0;
  16952. }
  16953. var timeSlotManager = new TimeSlotManager();
  16954. return new Promise(function next(resolve, reject) {
  16955. task.ensureNotTerminated();
  16956. timeSlotManager.reset();
  16957. var stop, operation = {}, args = [];
  16958. while (!(stop = timeSlotManager.check())) {
  16959. // The arguments parsed by read() are not used beyond this loop, so
  16960. // we can reuse the same array on every iteration, thus avoiding
  16961. // unnecessary allocations.
  16962. args.length = 0;
  16963. operation.args = args;
  16964. if (!(preprocessor.read(operation))) {
  16965. break;
  16966. }
  16967. textState = stateManager.state;
  16968. var fn = operation.fn;
  16969. args = operation.args;
  16970. var advance;
  16971. switch (fn | 0) {
  16972. case OPS.setFont:
  16973. flushTextContentItem();
  16974. textState.fontSize = args[1];
  16975. return handleSetFont(args[0].name).then(function() {
  16976. next(resolve, reject);
  16977. }, reject);
  16978. case OPS.setTextRise:
  16979. flushTextContentItem();
  16980. textState.textRise = args[0];
  16981. break;
  16982. case OPS.setHScale:
  16983. flushTextContentItem();
  16984. textState.textHScale = args[0] / 100;
  16985. break;
  16986. case OPS.setLeading:
  16987. flushTextContentItem();
  16988. textState.leading = args[0];
  16989. break;
  16990. case OPS.moveText:
  16991. // Optimization to treat same line movement as advance
  16992. var isSameTextLine = !textState.font ? false :
  16993. ((textState.font.vertical ? args[0] : args[1]) === 0);
  16994. advance = args[0] - args[1];
  16995. if (isSameTextLine && textContentItem.initialized &&
  16996. advance > 0 &&
  16997. advance <= textContentItem.fakeMultiSpaceMax) {
  16998. textState.translateTextLineMatrix(args[0], args[1]);
  16999. textContentItem.width +=
  17000. (args[0] - textContentItem.lastAdvanceWidth);
  17001. textContentItem.height +=
  17002. (args[1] - textContentItem.lastAdvanceHeight);
  17003. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  17004. (args[1] - textContentItem.lastAdvanceHeight);
  17005. addFakeSpaces(diff, textContentItem.str);
  17006. break;
  17007. }
  17008. flushTextContentItem();
  17009. textState.translateTextLineMatrix(args[0], args[1]);
  17010. textState.textMatrix = textState.textLineMatrix.slice();
  17011. break;
  17012. case OPS.setLeadingMoveText:
  17013. flushTextContentItem();
  17014. textState.leading = -args[1];
  17015. textState.translateTextLineMatrix(args[0], args[1]);
  17016. textState.textMatrix = textState.textLineMatrix.slice();
  17017. break;
  17018. case OPS.nextLine:
  17019. flushTextContentItem();
  17020. textState.carriageReturn();
  17021. break;
  17022. case OPS.setTextMatrix:
  17023. flushTextContentItem();
  17024. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  17025. args[4], args[5]);
  17026. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  17027. args[4], args[5]);
  17028. break;
  17029. case OPS.setCharSpacing:
  17030. textState.charSpacing = args[0];
  17031. break;
  17032. case OPS.setWordSpacing:
  17033. textState.wordSpacing = args[0];
  17034. break;
  17035. case OPS.beginText:
  17036. flushTextContentItem();
  17037. textState.textMatrix = IDENTITY_MATRIX.slice();
  17038. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  17039. break;
  17040. case OPS.showSpacedText:
  17041. var items = args[0];
  17042. var offset;
  17043. for (var j = 0, jj = items.length; j < jj; j++) {
  17044. if (typeof items[j] === 'string') {
  17045. buildTextContentItem(items[j]);
  17046. } else {
  17047. ensureTextContentItem();
  17048. // PDF Specification 5.3.2 states:
  17049. // The number is expressed in thousandths of a unit of text
  17050. // space.
  17051. // This amount is subtracted from the current horizontal or
  17052. // vertical coordinate, depending on the writing mode.
  17053. // In the default coordinate system, a positive adjustment
  17054. // has the effect of moving the next glyph painted either to
  17055. // the left or down by the given amount.
  17056. advance = items[j] * textState.fontSize / 1000;
  17057. var breakTextRun = false;
  17058. if (textState.font.vertical) {
  17059. offset = advance *
  17060. (textState.textHScale * textState.textMatrix[2] +
  17061. textState.textMatrix[3]);
  17062. textState.translateTextMatrix(0, advance);
  17063. breakTextRun = textContentItem.textRunBreakAllowed &&
  17064. advance > textContentItem.fakeMultiSpaceMax;
  17065. if (!breakTextRun) {
  17066. // Value needs to be added to height to paint down.
  17067. textContentItem.height += offset;
  17068. }
  17069. } else {
  17070. advance = -advance;
  17071. offset = advance * (
  17072. textState.textHScale * textState.textMatrix[0] +
  17073. textState.textMatrix[1]);
  17074. textState.translateTextMatrix(advance, 0);
  17075. breakTextRun = textContentItem.textRunBreakAllowed &&
  17076. advance > textContentItem.fakeMultiSpaceMax;
  17077. if (!breakTextRun) {
  17078. // Value needs to be subtracted from width to paint left.
  17079. textContentItem.width += offset;
  17080. }
  17081. }
  17082. if (breakTextRun) {
  17083. flushTextContentItem();
  17084. } else if (advance > 0) {
  17085. addFakeSpaces(advance, textContentItem.str);
  17086. }
  17087. }
  17088. }
  17089. break;
  17090. case OPS.showText:
  17091. buildTextContentItem(args[0]);
  17092. break;
  17093. case OPS.nextLineShowText:
  17094. flushTextContentItem();
  17095. textState.carriageReturn();
  17096. buildTextContentItem(args[0]);
  17097. break;
  17098. case OPS.nextLineSetSpacingShowText:
  17099. flushTextContentItem();
  17100. textState.wordSpacing = args[0];
  17101. textState.charSpacing = args[1];
  17102. textState.carriageReturn();
  17103. buildTextContentItem(args[2]);
  17104. break;
  17105. case OPS.paintXObject:
  17106. flushTextContentItem();
  17107. if (args[0].code) {
  17108. break;
  17109. }
  17110. if (!xobjs) {
  17111. xobjs = (resources.get('XObject') || Dict.empty);
  17112. }
  17113. var name = args[0].name;
  17114. if (xobjsCache.key === name) {
  17115. if (xobjsCache.texts) {
  17116. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  17117. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  17118. }
  17119. break;
  17120. }
  17121. var xobj = xobjs.get(name);
  17122. if (!xobj) {
  17123. break;
  17124. }
  17125. assert(isStream(xobj), 'XObject should be a stream');
  17126. var type = xobj.dict.get('Subtype');
  17127. assert(isName(type),
  17128. 'XObject should have a Name subtype');
  17129. if ('Form' !== type.name) {
  17130. xobjsCache.key = name;
  17131. xobjsCache.texts = null;
  17132. break;
  17133. }
  17134. stateManager.save();
  17135. var matrix = xobj.dict.get('Matrix');
  17136. if (isArray(matrix) && matrix.length === 6) {
  17137. stateManager.transform(matrix);
  17138. }
  17139. return self.getTextContent(xobj, task,
  17140. xobj.dict.get('Resources') || resources, stateManager).
  17141. then(function (formTextContent) {
  17142. Util.appendToArray(textContent.items, formTextContent.items);
  17143. Util.extendObj(textContent.styles, formTextContent.styles);
  17144. stateManager.restore();
  17145. xobjsCache.key = name;
  17146. xobjsCache.texts = formTextContent;
  17147. next(resolve, reject);
  17148. }, reject);
  17149. case OPS.setGState:
  17150. flushTextContentItem();
  17151. var dictName = args[0];
  17152. var extGState = resources.get('ExtGState');
  17153. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  17154. break;
  17155. }
  17156. var gsStateMap = extGState.get(dictName.name);
  17157. var gsStateFont = null;
  17158. for (var key in gsStateMap) {
  17159. if (key === 'Font') {
  17160. assert(!gsStateFont);
  17161. gsStateFont = gsStateMap[key];
  17162. }
  17163. }
  17164. if (gsStateFont) {
  17165. textState.fontSize = gsStateFont[1];
  17166. return handleSetFont(gsStateFont[0]).then(function() {
  17167. next(resolve, reject);
  17168. }, reject);
  17169. }
  17170. break;
  17171. } // switch
  17172. } // while
  17173. if (stop) {
  17174. deferred.then(function () {
  17175. next(resolve, reject);
  17176. }, reject);
  17177. return;
  17178. }
  17179. flushTextContentItem();
  17180. resolve(textContent);
  17181. });
  17182. },
  17183. extractDataStructures: function
  17184. partialEvaluatorExtractDataStructures(dict, baseDict,
  17185. xref, properties) {
  17186. // 9.10.2
  17187. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  17188. if (toUnicode) {
  17189. properties.toUnicode = this.readToUnicode(toUnicode);
  17190. }
  17191. if (properties.composite) {
  17192. // CIDSystemInfo helps to match CID to glyphs
  17193. var cidSystemInfo = dict.get('CIDSystemInfo');
  17194. if (isDict(cidSystemInfo)) {
  17195. properties.cidSystemInfo = {
  17196. registry: cidSystemInfo.get('Registry'),
  17197. ordering: cidSystemInfo.get('Ordering'),
  17198. supplement: cidSystemInfo.get('Supplement')
  17199. };
  17200. }
  17201. var cidToGidMap = dict.get('CIDToGIDMap');
  17202. if (isStream(cidToGidMap)) {
  17203. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  17204. }
  17205. }
  17206. // Based on 9.6.6 of the spec the encoding can come from multiple places
  17207. // and depends on the font type. The base encoding and differences are
  17208. // read here, but the encoding that is actually used is chosen during
  17209. // glyph mapping in the font.
  17210. // TODO: Loading the built in encoding in the font would allow the
  17211. // differences to be merged in here not require us to hold on to it.
  17212. var differences = [];
  17213. var baseEncodingName = null;
  17214. var encoding;
  17215. if (dict.has('Encoding')) {
  17216. encoding = dict.get('Encoding');
  17217. if (isDict(encoding)) {
  17218. baseEncodingName = encoding.get('BaseEncoding');
  17219. baseEncodingName = (isName(baseEncodingName) ?
  17220. baseEncodingName.name : null);
  17221. // Load the differences between the base and original
  17222. if (encoding.has('Differences')) {
  17223. var diffEncoding = encoding.get('Differences');
  17224. var index = 0;
  17225. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  17226. var data = diffEncoding[j];
  17227. if (isNum(data)) {
  17228. index = data;
  17229. } else if (isName(data)) {
  17230. differences[index++] = data.name;
  17231. } else if (isRef(data)) {
  17232. diffEncoding[j--] = xref.fetch(data);
  17233. continue;
  17234. } else {
  17235. error('Invalid entry in \'Differences\' array: ' + data);
  17236. }
  17237. }
  17238. }
  17239. } else if (isName(encoding)) {
  17240. baseEncodingName = encoding.name;
  17241. } else {
  17242. error('Encoding is not a Name nor a Dict');
  17243. }
  17244. // According to table 114 if the encoding is a named encoding it must be
  17245. // one of these predefined encodings.
  17246. if ((baseEncodingName !== 'MacRomanEncoding' &&
  17247. baseEncodingName !== 'MacExpertEncoding' &&
  17248. baseEncodingName !== 'WinAnsiEncoding')) {
  17249. baseEncodingName = null;
  17250. }
  17251. }
  17252. if (baseEncodingName) {
  17253. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  17254. } else {
  17255. encoding = (properties.type === 'TrueType' ?
  17256. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  17257. // The Symbolic attribute can be misused for regular fonts
  17258. // Heuristic: we have to check if the font is a standard one also
  17259. if (!!(properties.flags & FontFlags.Symbolic)) {
  17260. encoding = Encodings.MacRomanEncoding;
  17261. if (!properties.file) {
  17262. if (/Symbol/i.test(properties.name)) {
  17263. encoding = Encodings.SymbolSetEncoding;
  17264. } else if (/Dingbats/i.test(properties.name)) {
  17265. encoding = Encodings.ZapfDingbatsEncoding;
  17266. }
  17267. }
  17268. }
  17269. properties.defaultEncoding = encoding;
  17270. }
  17271. properties.differences = differences;
  17272. properties.baseEncodingName = baseEncodingName;
  17273. properties.dict = dict;
  17274. },
  17275. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  17276. var cmap, cmapObj = toUnicode;
  17277. if (isName(cmapObj)) {
  17278. cmap = CMapFactory.create(cmapObj,
  17279. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17280. if (cmap instanceof IdentityCMap) {
  17281. return new IdentityToUnicodeMap(0, 0xFFFF);
  17282. }
  17283. return new ToUnicodeMap(cmap.getMap());
  17284. } else if (isStream(cmapObj)) {
  17285. cmap = CMapFactory.create(cmapObj,
  17286. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17287. if (cmap instanceof IdentityCMap) {
  17288. return new IdentityToUnicodeMap(0, 0xFFFF);
  17289. }
  17290. var map = new Array(cmap.length);
  17291. // Convert UTF-16BE
  17292. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  17293. // to iterate over all keys.
  17294. cmap.forEach(function(charCode, token) {
  17295. var str = [];
  17296. for (var k = 0; k < token.length; k += 2) {
  17297. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  17298. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  17299. str.push(w1);
  17300. continue;
  17301. }
  17302. k += 2;
  17303. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  17304. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  17305. }
  17306. map[charCode] = String.fromCharCode.apply(String, str);
  17307. });
  17308. return new ToUnicodeMap(map);
  17309. }
  17310. return null;
  17311. },
  17312. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  17313. // Extract the encoding from the CIDToGIDMap
  17314. var glyphsData = cidToGidStream.getBytes();
  17315. // Set encoding 0 to later verify the font has an encoding
  17316. var result = [];
  17317. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  17318. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  17319. if (glyphID === 0) {
  17320. continue;
  17321. }
  17322. var code = j >> 1;
  17323. result[code] = glyphID;
  17324. }
  17325. return result;
  17326. },
  17327. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  17328. descriptor,
  17329. properties) {
  17330. var glyphsWidths = [];
  17331. var defaultWidth = 0;
  17332. var glyphsVMetrics = [];
  17333. var defaultVMetrics;
  17334. var i, ii, j, jj, start, code, widths;
  17335. if (properties.composite) {
  17336. defaultWidth = dict.get('DW') || 1000;
  17337. widths = dict.get('W');
  17338. if (widths) {
  17339. for (i = 0, ii = widths.length; i < ii; i++) {
  17340. start = widths[i++];
  17341. code = xref.fetchIfRef(widths[i]);
  17342. if (isArray(code)) {
  17343. for (j = 0, jj = code.length; j < jj; j++) {
  17344. glyphsWidths[start++] = code[j];
  17345. }
  17346. } else {
  17347. var width = widths[++i];
  17348. for (j = start; j <= code; j++) {
  17349. glyphsWidths[j] = width;
  17350. }
  17351. }
  17352. }
  17353. }
  17354. if (properties.vertical) {
  17355. var vmetrics = (dict.get('DW2') || [880, -1000]);
  17356. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  17357. vmetrics = dict.get('W2');
  17358. if (vmetrics) {
  17359. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  17360. start = vmetrics[i++];
  17361. code = xref.fetchIfRef(vmetrics[i]);
  17362. if (isArray(code)) {
  17363. for (j = 0, jj = code.length; j < jj; j++) {
  17364. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  17365. }
  17366. } else {
  17367. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  17368. for (j = start; j <= code; j++) {
  17369. glyphsVMetrics[j] = vmetric;
  17370. }
  17371. }
  17372. }
  17373. }
  17374. }
  17375. } else {
  17376. var firstChar = properties.firstChar;
  17377. widths = dict.get('Widths');
  17378. if (widths) {
  17379. j = firstChar;
  17380. for (i = 0, ii = widths.length; i < ii; i++) {
  17381. glyphsWidths[j++] = widths[i];
  17382. }
  17383. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  17384. } else {
  17385. // Trying get the BaseFont metrics (see comment above).
  17386. var baseFontName = dict.get('BaseFont');
  17387. if (isName(baseFontName)) {
  17388. var metrics = this.getBaseFontMetrics(baseFontName.name);
  17389. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  17390. properties);
  17391. defaultWidth = metrics.defaultWidth;
  17392. }
  17393. }
  17394. }
  17395. // Heuristic: detection of monospace font by checking all non-zero widths
  17396. var isMonospace = true;
  17397. var firstWidth = defaultWidth;
  17398. for (var glyph in glyphsWidths) {
  17399. var glyphWidth = glyphsWidths[glyph];
  17400. if (!glyphWidth) {
  17401. continue;
  17402. }
  17403. if (!firstWidth) {
  17404. firstWidth = glyphWidth;
  17405. continue;
  17406. }
  17407. if (firstWidth !== glyphWidth) {
  17408. isMonospace = false;
  17409. break;
  17410. }
  17411. }
  17412. if (isMonospace) {
  17413. properties.flags |= FontFlags.FixedPitch;
  17414. }
  17415. properties.defaultWidth = defaultWidth;
  17416. properties.widths = glyphsWidths;
  17417. properties.defaultVMetrics = defaultVMetrics;
  17418. properties.vmetrics = glyphsVMetrics;
  17419. },
  17420. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  17421. // Simulating descriptor flags attribute
  17422. var fontNameWoStyle = baseFontName.split('-')[0];
  17423. return (fontNameWoStyle in serifFonts) ||
  17424. (fontNameWoStyle.search(/serif/gi) !== -1);
  17425. },
  17426. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  17427. var defaultWidth = 0;
  17428. var widths = [];
  17429. var monospace = false;
  17430. var lookupName = (stdFontMap[name] || name);
  17431. if (!(lookupName in Metrics)) {
  17432. // Use default fonts for looking up font metrics if the passed
  17433. // font is not a base font
  17434. if (this.isSerifFont(name)) {
  17435. lookupName = 'Times-Roman';
  17436. } else {
  17437. lookupName = 'Helvetica';
  17438. }
  17439. }
  17440. var glyphWidths = Metrics[lookupName];
  17441. if (isNum(glyphWidths)) {
  17442. defaultWidth = glyphWidths;
  17443. monospace = true;
  17444. } else {
  17445. widths = glyphWidths;
  17446. }
  17447. return {
  17448. defaultWidth: defaultWidth,
  17449. monospace: monospace,
  17450. widths: widths
  17451. };
  17452. },
  17453. buildCharCodeToWidth:
  17454. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  17455. properties) {
  17456. var widths = Object.create(null);
  17457. var differences = properties.differences;
  17458. var encoding = properties.defaultEncoding;
  17459. for (var charCode = 0; charCode < 256; charCode++) {
  17460. if (charCode in differences &&
  17461. widthsByGlyphName[differences[charCode]]) {
  17462. widths[charCode] = widthsByGlyphName[differences[charCode]];
  17463. continue;
  17464. }
  17465. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  17466. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  17467. continue;
  17468. }
  17469. }
  17470. return widths;
  17471. },
  17472. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  17473. var baseDict = dict;
  17474. var type = dict.get('Subtype');
  17475. assert(isName(type), 'invalid font Subtype');
  17476. var composite = false;
  17477. var uint8array;
  17478. if (type.name === 'Type0') {
  17479. // If font is a composite
  17480. // - get the descendant font
  17481. // - set the type according to the descendant font
  17482. // - get the FontDescriptor from the descendant font
  17483. var df = dict.get('DescendantFonts');
  17484. if (!df) {
  17485. error('Descendant fonts are not specified');
  17486. }
  17487. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  17488. type = dict.get('Subtype');
  17489. assert(isName(type), 'invalid font Subtype');
  17490. composite = true;
  17491. }
  17492. var descriptor = dict.get('FontDescriptor');
  17493. if (descriptor) {
  17494. var hash = new MurmurHash3_64();
  17495. var encoding = baseDict.getRaw('Encoding');
  17496. if (isName(encoding)) {
  17497. hash.update(encoding.name);
  17498. } else if (isRef(encoding)) {
  17499. hash.update(encoding.num + '_' + encoding.gen);
  17500. } else if (isDict(encoding)) {
  17501. var keys = encoding.getKeys();
  17502. for (var i = 0, ii = keys.length; i < ii; i++) {
  17503. var entry = encoding.getRaw(keys[i]);
  17504. if (isName(entry)) {
  17505. hash.update(entry.name);
  17506. } else if (isRef(entry)) {
  17507. hash.update(entry.num + '_' + entry.gen);
  17508. } else if (isArray(entry)) { // 'Differences' entry.
  17509. // Ideally we should check the contents of the array, but to avoid
  17510. // parsing it here and then again in |extractDataStructures|,
  17511. // we only use the array length for now (fixes bug1157493.pdf).
  17512. hash.update(entry.length.toString());
  17513. }
  17514. }
  17515. }
  17516. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  17517. if (isStream(toUnicode)) {
  17518. var stream = toUnicode.str || toUnicode;
  17519. uint8array = stream.buffer ?
  17520. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  17521. new Uint8Array(stream.bytes.buffer,
  17522. stream.start, stream.end - stream.start);
  17523. hash.update(uint8array);
  17524. } else if (isName(toUnicode)) {
  17525. hash.update(toUnicode.name);
  17526. }
  17527. var widths = dict.get('Widths') || baseDict.get('Widths');
  17528. if (widths) {
  17529. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  17530. hash.update(uint8array);
  17531. }
  17532. }
  17533. return {
  17534. descriptor: descriptor,
  17535. dict: dict,
  17536. baseDict: baseDict,
  17537. composite: composite,
  17538. type: type.name,
  17539. hash: hash ? hash.hexdigest() : ''
  17540. };
  17541. },
  17542. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  17543. xref) {
  17544. var baseDict = preEvaluatedFont.baseDict;
  17545. var dict = preEvaluatedFont.dict;
  17546. var composite = preEvaluatedFont.composite;
  17547. var descriptor = preEvaluatedFont.descriptor;
  17548. var type = preEvaluatedFont.type;
  17549. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  17550. var properties;
  17551. if (!descriptor) {
  17552. if (type === 'Type3') {
  17553. // FontDescriptor is only required for Type3 fonts when the document
  17554. // is a tagged pdf. Create a barbebones one to get by.
  17555. descriptor = new Dict(null);
  17556. descriptor.set('FontName', Name.get(type));
  17557. descriptor.set('FontBBox', dict.get('FontBBox'));
  17558. } else {
  17559. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  17560. // FontDescriptor was not required.
  17561. // This case is here for compatibility.
  17562. var baseFontName = dict.get('BaseFont');
  17563. if (!isName(baseFontName)) {
  17564. error('Base font is not specified');
  17565. }
  17566. // Using base font name as a font name.
  17567. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  17568. var metrics = this.getBaseFontMetrics(baseFontName);
  17569. // Simulating descriptor flags attribute
  17570. var fontNameWoStyle = baseFontName.split('-')[0];
  17571. var flags =
  17572. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  17573. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  17574. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  17575. FontFlags.Nonsymbolic);
  17576. properties = {
  17577. type: type,
  17578. name: baseFontName,
  17579. widths: metrics.widths,
  17580. defaultWidth: metrics.defaultWidth,
  17581. flags: flags,
  17582. firstChar: 0,
  17583. lastChar: maxCharIndex
  17584. };
  17585. this.extractDataStructures(dict, dict, xref, properties);
  17586. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  17587. properties);
  17588. return new Font(baseFontName, null, properties);
  17589. }
  17590. }
  17591. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  17592. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  17593. // to ignore this rule when a variant of a standart font is used.
  17594. // TODO Fill the width array depending on which of the base font this is
  17595. // a variant.
  17596. var firstChar = (dict.get('FirstChar') || 0);
  17597. var lastChar = (dict.get('LastChar') || maxCharIndex);
  17598. var fontName = descriptor.get('FontName');
  17599. var baseFont = dict.get('BaseFont');
  17600. // Some bad PDFs have a string as the font name.
  17601. if (isString(fontName)) {
  17602. fontName = Name.get(fontName);
  17603. }
  17604. if (isString(baseFont)) {
  17605. baseFont = Name.get(baseFont);
  17606. }
  17607. if (type !== 'Type3') {
  17608. var fontNameStr = fontName && fontName.name;
  17609. var baseFontStr = baseFont && baseFont.name;
  17610. if (fontNameStr !== baseFontStr) {
  17611. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  17612. '" but should be the same as the Font\'s BaseFont "' +
  17613. baseFontStr + '"');
  17614. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  17615. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  17616. if (fontNameStr && baseFontStr &&
  17617. baseFontStr.indexOf(fontNameStr) === 0) {
  17618. fontName = baseFont;
  17619. }
  17620. }
  17621. }
  17622. fontName = (fontName || baseFont);
  17623. assert(isName(fontName), 'invalid font name');
  17624. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  17625. if (fontFile) {
  17626. if (fontFile.dict) {
  17627. var subtype = fontFile.dict.get('Subtype');
  17628. if (subtype) {
  17629. subtype = subtype.name;
  17630. }
  17631. var length1 = fontFile.dict.get('Length1');
  17632. var length2 = fontFile.dict.get('Length2');
  17633. }
  17634. }
  17635. properties = {
  17636. type: type,
  17637. name: fontName.name,
  17638. subtype: subtype,
  17639. file: fontFile,
  17640. length1: length1,
  17641. length2: length2,
  17642. loadedName: baseDict.loadedName,
  17643. composite: composite,
  17644. wideChars: composite,
  17645. fixedPitch: false,
  17646. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  17647. firstChar: firstChar || 0,
  17648. lastChar: (lastChar || maxCharIndex),
  17649. bbox: descriptor.get('FontBBox'),
  17650. ascent: descriptor.get('Ascent'),
  17651. descent: descriptor.get('Descent'),
  17652. xHeight: descriptor.get('XHeight'),
  17653. capHeight: descriptor.get('CapHeight'),
  17654. flags: descriptor.get('Flags'),
  17655. italicAngle: descriptor.get('ItalicAngle'),
  17656. coded: false
  17657. };
  17658. if (composite) {
  17659. var cidEncoding = baseDict.get('Encoding');
  17660. if (isName(cidEncoding)) {
  17661. properties.cidEncoding = cidEncoding.name;
  17662. }
  17663. properties.cMap = CMapFactory.create(cidEncoding,
  17664. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17665. properties.vertical = properties.cMap.vertical;
  17666. }
  17667. this.extractDataStructures(dict, baseDict, xref, properties);
  17668. this.extractWidths(dict, xref, descriptor, properties);
  17669. if (type === 'Type3') {
  17670. properties.isType3Font = true;
  17671. }
  17672. return new Font(fontName.name, fontFile, properties);
  17673. }
  17674. };
  17675. return PartialEvaluator;
  17676. })();
  17677. var TranslatedFont = (function TranslatedFontClosure() {
  17678. function TranslatedFont(loadedName, font, dict) {
  17679. this.loadedName = loadedName;
  17680. this.font = font;
  17681. this.dict = dict;
  17682. this.type3Loaded = null;
  17683. this.sent = false;
  17684. }
  17685. TranslatedFont.prototype = {
  17686. send: function (handler) {
  17687. if (this.sent) {
  17688. return;
  17689. }
  17690. var fontData = this.font.exportData();
  17691. handler.send('commonobj', [
  17692. this.loadedName,
  17693. 'Font',
  17694. fontData
  17695. ]);
  17696. this.sent = true;
  17697. },
  17698. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  17699. assert(this.font.isType3Font);
  17700. if (this.type3Loaded) {
  17701. return this.type3Loaded;
  17702. }
  17703. var translatedFont = this.font;
  17704. var loadCharProcsPromise = Promise.resolve();
  17705. var charProcs = this.dict.get('CharProcs').getAll();
  17706. var fontResources = this.dict.get('Resources') || resources;
  17707. var charProcKeys = Object.keys(charProcs);
  17708. var charProcOperatorList = {};
  17709. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  17710. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  17711. var glyphStream = charProcs[key];
  17712. var operatorList = new OperatorList();
  17713. return evaluator.getOperatorList(glyphStream, task, fontResources,
  17714. operatorList).then(function () {
  17715. charProcOperatorList[key] = operatorList.getIR();
  17716. // Add the dependencies to the parent operator list so they are
  17717. // resolved before sub operator list is executed synchronously.
  17718. parentOperatorList.addDependencies(operatorList.dependencies);
  17719. }, function (reason) {
  17720. warn('Type3 font resource \"' + key + '\" is not available');
  17721. var operatorList = new OperatorList();
  17722. charProcOperatorList[key] = operatorList.getIR();
  17723. });
  17724. }.bind(this, charProcKeys[i]));
  17725. }
  17726. this.type3Loaded = loadCharProcsPromise.then(function () {
  17727. translatedFont.charProcOperatorList = charProcOperatorList;
  17728. });
  17729. return this.type3Loaded;
  17730. }
  17731. };
  17732. return TranslatedFont;
  17733. })();
  17734. var OperatorList = (function OperatorListClosure() {
  17735. var CHUNK_SIZE = 1000;
  17736. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  17737. function getTransfers(queue) {
  17738. var transfers = [];
  17739. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  17740. for (var i = 0, ii = queue.length; i < ii; i++) {
  17741. switch (fnArray[i]) {
  17742. case OPS.paintInlineImageXObject:
  17743. case OPS.paintInlineImageXObjectGroup:
  17744. case OPS.paintImageMaskXObject:
  17745. var arg = argsArray[i][0]; // first param in imgData
  17746. if (!arg.cached) {
  17747. transfers.push(arg.data.buffer);
  17748. }
  17749. break;
  17750. }
  17751. }
  17752. return transfers;
  17753. }
  17754. function OperatorList(intent, messageHandler, pageIndex) {
  17755. this.messageHandler = messageHandler;
  17756. this.fnArray = [];
  17757. this.argsArray = [];
  17758. this.dependencies = {};
  17759. this._totalLength = 0;
  17760. this.pageIndex = pageIndex;
  17761. this.intent = intent;
  17762. }
  17763. OperatorList.prototype = {
  17764. get length() {
  17765. return this.argsArray.length;
  17766. },
  17767. /**
  17768. * @returns {number} The total length of the entire operator list,
  17769. * since `this.length === 0` after flushing.
  17770. */
  17771. get totalLength() {
  17772. return (this._totalLength + this.length);
  17773. },
  17774. addOp: function(fn, args) {
  17775. this.fnArray.push(fn);
  17776. this.argsArray.push(args);
  17777. if (this.messageHandler) {
  17778. if (this.fnArray.length >= CHUNK_SIZE) {
  17779. this.flush();
  17780. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  17781. (fn === OPS.restore || fn === OPS.endText)) {
  17782. // heuristic to flush on boundary of restore or endText
  17783. this.flush();
  17784. }
  17785. }
  17786. },
  17787. addDependency: function(dependency) {
  17788. if (dependency in this.dependencies) {
  17789. return;
  17790. }
  17791. this.dependencies[dependency] = true;
  17792. this.addOp(OPS.dependency, [dependency]);
  17793. },
  17794. addDependencies: function(dependencies) {
  17795. for (var key in dependencies) {
  17796. this.addDependency(key);
  17797. }
  17798. },
  17799. addOpList: function(opList) {
  17800. Util.extendObj(this.dependencies, opList.dependencies);
  17801. for (var i = 0, ii = opList.length; i < ii; i++) {
  17802. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  17803. }
  17804. },
  17805. getIR: function() {
  17806. return {
  17807. fnArray: this.fnArray,
  17808. argsArray: this.argsArray,
  17809. length: this.length
  17810. };
  17811. },
  17812. flush: function(lastChunk) {
  17813. if (this.intent !== 'oplist') {
  17814. new QueueOptimizer().optimize(this);
  17815. }
  17816. var transfers = getTransfers(this);
  17817. var length = this.length;
  17818. this._totalLength += length;
  17819. this.messageHandler.send('RenderPageChunk', {
  17820. operatorList: {
  17821. fnArray: this.fnArray,
  17822. argsArray: this.argsArray,
  17823. lastChunk: lastChunk,
  17824. length: length
  17825. },
  17826. pageIndex: this.pageIndex,
  17827. intent: this.intent
  17828. }, transfers);
  17829. this.dependencies = {};
  17830. this.fnArray.length = 0;
  17831. this.argsArray.length = 0;
  17832. }
  17833. };
  17834. return OperatorList;
  17835. })();
  17836. var StateManager = (function StateManagerClosure() {
  17837. function StateManager(initialState) {
  17838. this.state = initialState;
  17839. this.stateStack = [];
  17840. }
  17841. StateManager.prototype = {
  17842. save: function () {
  17843. var old = this.state;
  17844. this.stateStack.push(this.state);
  17845. this.state = old.clone();
  17846. },
  17847. restore: function () {
  17848. var prev = this.stateStack.pop();
  17849. if (prev) {
  17850. this.state = prev;
  17851. }
  17852. },
  17853. transform: function (args) {
  17854. this.state.ctm = Util.transform(this.state.ctm, args);
  17855. }
  17856. };
  17857. return StateManager;
  17858. })();
  17859. var TextState = (function TextStateClosure() {
  17860. function TextState() {
  17861. this.ctm = new Float32Array(IDENTITY_MATRIX);
  17862. this.fontSize = 0;
  17863. this.font = null;
  17864. this.fontMatrix = FONT_IDENTITY_MATRIX;
  17865. this.textMatrix = IDENTITY_MATRIX.slice();
  17866. this.textLineMatrix = IDENTITY_MATRIX.slice();
  17867. this.charSpacing = 0;
  17868. this.wordSpacing = 0;
  17869. this.leading = 0;
  17870. this.textHScale = 1;
  17871. this.textRise = 0;
  17872. }
  17873. TextState.prototype = {
  17874. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  17875. var m = this.textMatrix;
  17876. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  17877. },
  17878. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  17879. var m = this.textLineMatrix;
  17880. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  17881. },
  17882. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  17883. var m = this.textMatrix;
  17884. m[4] = m[0] * x + m[2] * y + m[4];
  17885. m[5] = m[1] * x + m[3] * y + m[5];
  17886. },
  17887. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  17888. var m = this.textLineMatrix;
  17889. m[4] = m[0] * x + m[2] * y + m[4];
  17890. m[5] = m[1] * x + m[3] * y + m[5];
  17891. },
  17892. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  17893. // 9.4.4 Text Space Details
  17894. var tsm = [this.fontSize * this.textHScale, 0,
  17895. 0, this.fontSize,
  17896. 0, this.textRise];
  17897. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  17898. },
  17899. carriageReturn: function TextState_carriageReturn() {
  17900. this.translateTextLineMatrix(0, -this.leading);
  17901. this.textMatrix = this.textLineMatrix.slice();
  17902. },
  17903. clone: function TextState_clone() {
  17904. var clone = Object.create(this);
  17905. clone.textMatrix = this.textMatrix.slice();
  17906. clone.textLineMatrix = this.textLineMatrix.slice();
  17907. clone.fontMatrix = this.fontMatrix.slice();
  17908. return clone;
  17909. }
  17910. };
  17911. return TextState;
  17912. })();
  17913. var EvalState = (function EvalStateClosure() {
  17914. function EvalState() {
  17915. this.ctm = new Float32Array(IDENTITY_MATRIX);
  17916. this.font = null;
  17917. this.textRenderingMode = TextRenderingMode.FILL;
  17918. this.fillColorSpace = ColorSpace.singletons.gray;
  17919. this.strokeColorSpace = ColorSpace.singletons.gray;
  17920. }
  17921. EvalState.prototype = {
  17922. clone: function CanvasExtraState_clone() {
  17923. return Object.create(this);
  17924. },
  17925. };
  17926. return EvalState;
  17927. })();
  17928. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  17929. // Specifies properties for each command
  17930. //
  17931. // If variableArgs === true: [0, `numArgs`] expected
  17932. // If variableArgs === false: exactly `numArgs` expected
  17933. var OP_MAP = {
  17934. // Graphic state
  17935. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  17936. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  17937. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  17938. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  17939. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  17940. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  17941. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  17942. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  17943. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  17944. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  17945. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  17946. // Path
  17947. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  17948. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  17949. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  17950. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  17951. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  17952. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  17953. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  17954. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  17955. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  17956. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17957. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  17958. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  17959. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  17960. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  17961. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  17962. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  17963. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  17964. // Clipping
  17965. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  17966. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  17967. // Text
  17968. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  17969. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  17970. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  17971. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  17972. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  17973. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  17974. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  17975. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  17976. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  17977. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  17978. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  17979. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  17980. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  17981. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  17982. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  17983. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  17984. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  17985. variableArgs: false },
  17986. // Type3 fonts
  17987. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  17988. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  17989. // Color
  17990. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  17991. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  17992. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  17993. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  17994. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  17995. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  17996. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  17997. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  17998. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  17999. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  18000. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  18001. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  18002. // Shading
  18003. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  18004. // Images
  18005. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  18006. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  18007. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  18008. // XObjects
  18009. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  18010. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  18011. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  18012. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  18013. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  18014. variableArgs: false },
  18015. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  18016. // Compatibility
  18017. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  18018. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  18019. // (reserved partial commands for the lexer)
  18020. BM: null,
  18021. BD: null,
  18022. 'true': null,
  18023. fa: null,
  18024. fal: null,
  18025. fals: null,
  18026. 'false': null,
  18027. nu: null,
  18028. nul: null,
  18029. 'null': null
  18030. };
  18031. function EvaluatorPreprocessor(stream, xref, stateManager) {
  18032. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  18033. // dictionary
  18034. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  18035. this.stateManager = stateManager;
  18036. this.nonProcessedArgs = [];
  18037. }
  18038. EvaluatorPreprocessor.prototype = {
  18039. get savedStatesDepth() {
  18040. return this.stateManager.stateStack.length;
  18041. },
  18042. // |operation| is an object with two fields:
  18043. //
  18044. // - |fn| is an out param.
  18045. //
  18046. // - |args| is an inout param. On entry, it should have one of two values.
  18047. //
  18048. // - An empty array. This indicates that the caller is providing the
  18049. // array in which the args will be stored in. The caller should use
  18050. // this value if it can reuse a single array for each call to read().
  18051. //
  18052. // - |null|. This indicates that the caller needs this function to create
  18053. // the array in which any args are stored in. If there are zero args,
  18054. // this function will leave |operation.args| as |null| (thus avoiding
  18055. // allocations that would occur if we used an empty array to represent
  18056. // zero arguments). Otherwise, it will replace |null| with a new array
  18057. // containing the arguments. The caller should use this value if it
  18058. // cannot reuse an array for each call to read().
  18059. //
  18060. // These two modes are present because this function is very hot and so
  18061. // avoiding allocations where possible is worthwhile.
  18062. //
  18063. read: function EvaluatorPreprocessor_read(operation) {
  18064. var args = operation.args;
  18065. while (true) {
  18066. var obj = this.parser.getObj();
  18067. if (isCmd(obj)) {
  18068. var cmd = obj.cmd;
  18069. // Check that the command is valid
  18070. var opSpec = OP_MAP[cmd];
  18071. if (!opSpec) {
  18072. warn('Unknown command "' + cmd + '"');
  18073. continue;
  18074. }
  18075. var fn = opSpec.id;
  18076. var numArgs = opSpec.numArgs;
  18077. var argsLength = args !== null ? args.length : 0;
  18078. if (!opSpec.variableArgs) {
  18079. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  18080. if (argsLength !== numArgs) {
  18081. var nonProcessedArgs = this.nonProcessedArgs;
  18082. while (argsLength > numArgs) {
  18083. nonProcessedArgs.push(args.shift());
  18084. argsLength--;
  18085. }
  18086. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  18087. if (!args) {
  18088. args = [];
  18089. }
  18090. args.unshift(nonProcessedArgs.pop());
  18091. argsLength++;
  18092. }
  18093. }
  18094. if (argsLength < numArgs) {
  18095. // If we receive too few args, it's not possible to possible
  18096. // to execute the command, so skip the command
  18097. info('Command ' + fn + ': because expected ' +
  18098. numArgs + ' args, but received ' + argsLength +
  18099. ' args; skipping');
  18100. args = null;
  18101. continue;
  18102. }
  18103. } else if (argsLength > numArgs) {
  18104. info('Command ' + fn + ': expected [0,' + numArgs +
  18105. '] args, but received ' + argsLength + ' args');
  18106. }
  18107. // TODO figure out how to type-check vararg functions
  18108. this.preprocessCommand(fn, args);
  18109. operation.fn = fn;
  18110. operation.args = args;
  18111. return true;
  18112. } else {
  18113. if (isEOF(obj)) {
  18114. return false; // no more commands
  18115. }
  18116. // argument
  18117. if (obj !== null) {
  18118. if (!args) {
  18119. args = [];
  18120. }
  18121. args.push((obj instanceof Dict ? obj.getAll() : obj));
  18122. assert(args.length <= 33, 'Too many arguments');
  18123. }
  18124. }
  18125. }
  18126. },
  18127. preprocessCommand:
  18128. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  18129. switch (fn | 0) {
  18130. case OPS.save:
  18131. this.stateManager.save();
  18132. break;
  18133. case OPS.restore:
  18134. this.stateManager.restore();
  18135. break;
  18136. case OPS.transform:
  18137. this.stateManager.transform(args);
  18138. break;
  18139. }
  18140. }
  18141. };
  18142. return EvaluatorPreprocessor;
  18143. })();
  18144. var QueueOptimizer = (function QueueOptimizerClosure() {
  18145. function addState(parentState, pattern, fn) {
  18146. var state = parentState;
  18147. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  18148. var item = pattern[i];
  18149. state = (state[item] || (state[item] = []));
  18150. }
  18151. state[pattern[pattern.length - 1]] = fn;
  18152. }
  18153. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  18154. argsArray) {
  18155. // Handles special case of mainly LaTeX documents which use image masks to
  18156. // draw lines with the current fill style.
  18157. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  18158. // have been found at iFirstSave.
  18159. var iFirstPIMXO = iFirstSave + 2;
  18160. for (var i = 0; i < count; i++) {
  18161. var arg = argsArray[iFirstPIMXO + 4 * i];
  18162. var imageMask = arg.length === 1 && arg[0];
  18163. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  18164. (!imageMask.data.length ||
  18165. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  18166. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  18167. continue;
  18168. }
  18169. break;
  18170. }
  18171. return count - i;
  18172. }
  18173. var InitialState = [];
  18174. // This replaces (save, transform, paintInlineImageXObject, restore)+
  18175. // sequences with one |paintInlineImageXObjectGroup| operation.
  18176. addState(InitialState,
  18177. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  18178. function foundInlineImageGroup(context) {
  18179. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  18180. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  18181. var MAX_WIDTH = 1000;
  18182. var IMAGE_PADDING = 1;
  18183. var fnArray = context.fnArray, argsArray = context.argsArray;
  18184. var curr = context.iCurr;
  18185. var iFirstSave = curr - 3;
  18186. var iFirstTransform = curr - 2;
  18187. var iFirstPIIXO = curr - 1;
  18188. // Look for the quartets.
  18189. var i = iFirstSave + 4;
  18190. var ii = fnArray.length;
  18191. while (i + 3 < ii) {
  18192. if (fnArray[i] !== OPS.save ||
  18193. fnArray[i + 1] !== OPS.transform ||
  18194. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  18195. fnArray[i + 3] !== OPS.restore) {
  18196. break; // ops don't match
  18197. }
  18198. i += 4;
  18199. }
  18200. // At this point, i is the index of the first op past the last valid
  18201. // quartet.
  18202. var count = Math.min((i - iFirstSave) / 4,
  18203. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  18204. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  18205. return i;
  18206. }
  18207. // assuming that heights of those image is too small (~1 pixel)
  18208. // packing as much as possible by lines
  18209. var maxX = 0;
  18210. var map = [], maxLineHeight = 0;
  18211. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  18212. var q;
  18213. for (q = 0; q < count; q++) {
  18214. var transform = argsArray[iFirstTransform + (q << 2)];
  18215. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  18216. if (currentX + img.width > MAX_WIDTH) {
  18217. // starting new line
  18218. maxX = Math.max(maxX, currentX);
  18219. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  18220. currentX = 0;
  18221. maxLineHeight = 0;
  18222. }
  18223. map.push({
  18224. transform: transform,
  18225. x: currentX, y: currentY,
  18226. w: img.width, h: img.height
  18227. });
  18228. currentX += img.width + 2 * IMAGE_PADDING;
  18229. maxLineHeight = Math.max(maxLineHeight, img.height);
  18230. }
  18231. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  18232. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  18233. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  18234. var imgRowSize = imgWidth << 2;
  18235. for (q = 0; q < count; q++) {
  18236. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  18237. // Copy image by lines and extends pixels into padding.
  18238. var rowSize = map[q].w << 2;
  18239. var dataOffset = 0;
  18240. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  18241. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  18242. for (var k = 0, kk = map[q].h; k < kk; k++) {
  18243. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  18244. dataOffset += rowSize;
  18245. offset += imgRowSize;
  18246. }
  18247. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  18248. while (offset >= 0) {
  18249. data[offset - 4] = data[offset];
  18250. data[offset - 3] = data[offset + 1];
  18251. data[offset - 2] = data[offset + 2];
  18252. data[offset - 1] = data[offset + 3];
  18253. data[offset + rowSize] = data[offset + rowSize - 4];
  18254. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  18255. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  18256. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  18257. offset -= imgRowSize;
  18258. }
  18259. }
  18260. // Replace queue items.
  18261. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  18262. argsArray.splice(iFirstSave, count * 4,
  18263. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  18264. data: imgData }, map]);
  18265. return iFirstSave + 1;
  18266. });
  18267. // This replaces (save, transform, paintImageMaskXObject, restore)+
  18268. // sequences with one |paintImageMaskXObjectGroup| or one
  18269. // |paintImageMaskXObjectRepeat| operation.
  18270. addState(InitialState,
  18271. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  18272. function foundImageMaskGroup(context) {
  18273. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  18274. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  18275. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  18276. var fnArray = context.fnArray, argsArray = context.argsArray;
  18277. var curr = context.iCurr;
  18278. var iFirstSave = curr - 3;
  18279. var iFirstTransform = curr - 2;
  18280. var iFirstPIMXO = curr - 1;
  18281. // Look for the quartets.
  18282. var i = iFirstSave + 4;
  18283. var ii = fnArray.length;
  18284. while (i + 3 < ii) {
  18285. if (fnArray[i] !== OPS.save ||
  18286. fnArray[i + 1] !== OPS.transform ||
  18287. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  18288. fnArray[i + 3] !== OPS.restore) {
  18289. break; // ops don't match
  18290. }
  18291. i += 4;
  18292. }
  18293. // At this point, i is the index of the first op past the last valid
  18294. // quartet.
  18295. var count = (i - iFirstSave) / 4;
  18296. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  18297. argsArray);
  18298. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  18299. return i;
  18300. }
  18301. var q;
  18302. var isSameImage = false;
  18303. var iTransform, transformArgs;
  18304. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  18305. if (argsArray[iFirstTransform][1] === 0 &&
  18306. argsArray[iFirstTransform][2] === 0) {
  18307. isSameImage = true;
  18308. var firstTransformArg0 = argsArray[iFirstTransform][0];
  18309. var firstTransformArg3 = argsArray[iFirstTransform][3];
  18310. iTransform = iFirstTransform + 4;
  18311. var iPIMXO = iFirstPIMXO + 4;
  18312. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  18313. transformArgs = argsArray[iTransform];
  18314. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  18315. transformArgs[0] !== firstTransformArg0 ||
  18316. transformArgs[1] !== 0 ||
  18317. transformArgs[2] !== 0 ||
  18318. transformArgs[3] !== firstTransformArg3) {
  18319. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  18320. isSameImage = false;
  18321. } else {
  18322. count = q;
  18323. }
  18324. break; // different image or transform
  18325. }
  18326. }
  18327. }
  18328. if (isSameImage) {
  18329. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  18330. var positions = new Float32Array(count * 2);
  18331. iTransform = iFirstTransform;
  18332. for (q = 0; q < count; q++, iTransform += 4) {
  18333. transformArgs = argsArray[iTransform];
  18334. positions[(q << 1)] = transformArgs[4];
  18335. positions[(q << 1) + 1] = transformArgs[5];
  18336. }
  18337. // Replace queue items.
  18338. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  18339. argsArray.splice(iFirstSave, count * 4,
  18340. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  18341. } else {
  18342. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  18343. var images = [];
  18344. for (q = 0; q < count; q++) {
  18345. transformArgs = argsArray[iFirstTransform + (q << 2)];
  18346. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  18347. images.push({ data: maskParams.data, width: maskParams.width,
  18348. height: maskParams.height,
  18349. transform: transformArgs });
  18350. }
  18351. // Replace queue items.
  18352. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  18353. argsArray.splice(iFirstSave, count * 4, [images]);
  18354. }
  18355. return iFirstSave + 1;
  18356. });
  18357. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  18358. // with one paintImageXObjectRepeat operation, if the |transform| and
  18359. // |paintImageXObjectRepeat| ops are appropriate.
  18360. addState(InitialState,
  18361. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  18362. function (context) {
  18363. var MIN_IMAGES_IN_BLOCK = 3;
  18364. var MAX_IMAGES_IN_BLOCK = 1000;
  18365. var fnArray = context.fnArray, argsArray = context.argsArray;
  18366. var curr = context.iCurr;
  18367. var iFirstSave = curr - 3;
  18368. var iFirstTransform = curr - 2;
  18369. var iFirstPIXO = curr - 1;
  18370. var iFirstRestore = curr;
  18371. if (argsArray[iFirstTransform][1] !== 0 ||
  18372. argsArray[iFirstTransform][2] !== 0) {
  18373. return iFirstRestore + 1; // transform has the wrong form
  18374. }
  18375. // Look for the quartets.
  18376. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  18377. var firstTransformArg0 = argsArray[iFirstTransform][0];
  18378. var firstTransformArg3 = argsArray[iFirstTransform][3];
  18379. var i = iFirstSave + 4;
  18380. var ii = fnArray.length;
  18381. while (i + 3 < ii) {
  18382. if (fnArray[i] !== OPS.save ||
  18383. fnArray[i + 1] !== OPS.transform ||
  18384. fnArray[i + 2] !== OPS.paintImageXObject ||
  18385. fnArray[i + 3] !== OPS.restore) {
  18386. break; // ops don't match
  18387. }
  18388. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  18389. argsArray[i + 1][1] !== 0 ||
  18390. argsArray[i + 1][2] !== 0 ||
  18391. argsArray[i + 1][3] !== firstTransformArg3) {
  18392. break; // transforms don't match
  18393. }
  18394. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  18395. break; // images don't match
  18396. }
  18397. i += 4;
  18398. }
  18399. // At this point, i is the index of the first op past the last valid
  18400. // quartet.
  18401. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  18402. if (count < MIN_IMAGES_IN_BLOCK) {
  18403. return i;
  18404. }
  18405. // Extract the (x,y) positions from all of the matching transforms.
  18406. var positions = new Float32Array(count * 2);
  18407. var iTransform = iFirstTransform;
  18408. for (var q = 0; q < count; q++, iTransform += 4) {
  18409. var transformArgs = argsArray[iTransform];
  18410. positions[(q << 1)] = transformArgs[4];
  18411. positions[(q << 1) + 1] = transformArgs[5];
  18412. }
  18413. // Replace queue items.
  18414. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  18415. positions];
  18416. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  18417. argsArray.splice(iFirstSave, count * 4, args);
  18418. return iFirstSave + 1;
  18419. });
  18420. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  18421. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  18422. // sequences, if the font for each one is the same.
  18423. addState(InitialState,
  18424. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  18425. function (context) {
  18426. var MIN_CHARS_IN_BLOCK = 3;
  18427. var MAX_CHARS_IN_BLOCK = 1000;
  18428. var fnArray = context.fnArray, argsArray = context.argsArray;
  18429. var curr = context.iCurr;
  18430. var iFirstBeginText = curr - 4;
  18431. var iFirstSetFont = curr - 3;
  18432. var iFirstSetTextMatrix = curr - 2;
  18433. var iFirstShowText = curr - 1;
  18434. var iFirstEndText = curr;
  18435. // Look for the quintets.
  18436. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  18437. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  18438. var i = iFirstBeginText + 5;
  18439. var ii = fnArray.length;
  18440. while (i + 4 < ii) {
  18441. if (fnArray[i] !== OPS.beginText ||
  18442. fnArray[i + 1] !== OPS.setFont ||
  18443. fnArray[i + 2] !== OPS.setTextMatrix ||
  18444. fnArray[i + 3] !== OPS.showText ||
  18445. fnArray[i + 4] !== OPS.endText) {
  18446. break; // ops don't match
  18447. }
  18448. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  18449. argsArray[i + 1][1] !== firstSetFontArg1) {
  18450. break; // fonts don't match
  18451. }
  18452. i += 5;
  18453. }
  18454. // At this point, i is the index of the first op past the last valid
  18455. // quintet.
  18456. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  18457. if (count < MIN_CHARS_IN_BLOCK) {
  18458. return i;
  18459. }
  18460. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  18461. // showText, endText), include that as well. (E.g. <something> might be
  18462. // |dependency|.)
  18463. var iFirst = iFirstBeginText;
  18464. if (iFirstBeginText >= 4 &&
  18465. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  18466. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  18467. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  18468. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  18469. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  18470. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  18471. count++;
  18472. iFirst -= 5;
  18473. }
  18474. // Remove (endText, beginText, setFont) trios.
  18475. var iEndText = iFirst + 4;
  18476. for (var q = 1; q < count; q++) {
  18477. fnArray.splice(iEndText, 3);
  18478. argsArray.splice(iEndText, 3);
  18479. iEndText += 2;
  18480. }
  18481. return iEndText + 1;
  18482. });
  18483. function QueueOptimizer() {}
  18484. QueueOptimizer.prototype = {
  18485. optimize: function QueueOptimizer_optimize(queue) {
  18486. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  18487. var context = {
  18488. iCurr: 0,
  18489. fnArray: fnArray,
  18490. argsArray: argsArray
  18491. };
  18492. var state;
  18493. var i = 0, ii = fnArray.length;
  18494. while (i < ii) {
  18495. state = (state || InitialState)[fnArray[i]];
  18496. if (typeof state === 'function') { // we found some handler
  18497. context.iCurr = i;
  18498. // state() returns the index of the first non-matching op (if we
  18499. // didn't match) or the first op past the modified ops (if we did
  18500. // match and replace).
  18501. i = state(context);
  18502. state = undefined; // reset the state machine
  18503. ii = context.fnArray.length;
  18504. } else {
  18505. i++;
  18506. }
  18507. }
  18508. }
  18509. };
  18510. return QueueOptimizer;
  18511. })();
  18512. var BUILT_IN_CMAPS = [
  18513. // << Start unicode maps.
  18514. 'Adobe-GB1-UCS2',
  18515. 'Adobe-CNS1-UCS2',
  18516. 'Adobe-Japan1-UCS2',
  18517. 'Adobe-Korea1-UCS2',
  18518. // >> End unicode maps.
  18519. '78-EUC-H',
  18520. '78-EUC-V',
  18521. '78-H',
  18522. '78-RKSJ-H',
  18523. '78-RKSJ-V',
  18524. '78-V',
  18525. '78ms-RKSJ-H',
  18526. '78ms-RKSJ-V',
  18527. '83pv-RKSJ-H',
  18528. '90ms-RKSJ-H',
  18529. '90ms-RKSJ-V',
  18530. '90msp-RKSJ-H',
  18531. '90msp-RKSJ-V',
  18532. '90pv-RKSJ-H',
  18533. '90pv-RKSJ-V',
  18534. 'Add-H',
  18535. 'Add-RKSJ-H',
  18536. 'Add-RKSJ-V',
  18537. 'Add-V',
  18538. 'Adobe-CNS1-0',
  18539. 'Adobe-CNS1-1',
  18540. 'Adobe-CNS1-2',
  18541. 'Adobe-CNS1-3',
  18542. 'Adobe-CNS1-4',
  18543. 'Adobe-CNS1-5',
  18544. 'Adobe-CNS1-6',
  18545. 'Adobe-GB1-0',
  18546. 'Adobe-GB1-1',
  18547. 'Adobe-GB1-2',
  18548. 'Adobe-GB1-3',
  18549. 'Adobe-GB1-4',
  18550. 'Adobe-GB1-5',
  18551. 'Adobe-Japan1-0',
  18552. 'Adobe-Japan1-1',
  18553. 'Adobe-Japan1-2',
  18554. 'Adobe-Japan1-3',
  18555. 'Adobe-Japan1-4',
  18556. 'Adobe-Japan1-5',
  18557. 'Adobe-Japan1-6',
  18558. 'Adobe-Korea1-0',
  18559. 'Adobe-Korea1-1',
  18560. 'Adobe-Korea1-2',
  18561. 'B5-H',
  18562. 'B5-V',
  18563. 'B5pc-H',
  18564. 'B5pc-V',
  18565. 'CNS-EUC-H',
  18566. 'CNS-EUC-V',
  18567. 'CNS1-H',
  18568. 'CNS1-V',
  18569. 'CNS2-H',
  18570. 'CNS2-V',
  18571. 'ETHK-B5-H',
  18572. 'ETHK-B5-V',
  18573. 'ETen-B5-H',
  18574. 'ETen-B5-V',
  18575. 'ETenms-B5-H',
  18576. 'ETenms-B5-V',
  18577. 'EUC-H',
  18578. 'EUC-V',
  18579. 'Ext-H',
  18580. 'Ext-RKSJ-H',
  18581. 'Ext-RKSJ-V',
  18582. 'Ext-V',
  18583. 'GB-EUC-H',
  18584. 'GB-EUC-V',
  18585. 'GB-H',
  18586. 'GB-V',
  18587. 'GBK-EUC-H',
  18588. 'GBK-EUC-V',
  18589. 'GBK2K-H',
  18590. 'GBK2K-V',
  18591. 'GBKp-EUC-H',
  18592. 'GBKp-EUC-V',
  18593. 'GBT-EUC-H',
  18594. 'GBT-EUC-V',
  18595. 'GBT-H',
  18596. 'GBT-V',
  18597. 'GBTpc-EUC-H',
  18598. 'GBTpc-EUC-V',
  18599. 'GBpc-EUC-H',
  18600. 'GBpc-EUC-V',
  18601. 'H',
  18602. 'HKdla-B5-H',
  18603. 'HKdla-B5-V',
  18604. 'HKdlb-B5-H',
  18605. 'HKdlb-B5-V',
  18606. 'HKgccs-B5-H',
  18607. 'HKgccs-B5-V',
  18608. 'HKm314-B5-H',
  18609. 'HKm314-B5-V',
  18610. 'HKm471-B5-H',
  18611. 'HKm471-B5-V',
  18612. 'HKscs-B5-H',
  18613. 'HKscs-B5-V',
  18614. 'Hankaku',
  18615. 'Hiragana',
  18616. 'KSC-EUC-H',
  18617. 'KSC-EUC-V',
  18618. 'KSC-H',
  18619. 'KSC-Johab-H',
  18620. 'KSC-Johab-V',
  18621. 'KSC-V',
  18622. 'KSCms-UHC-H',
  18623. 'KSCms-UHC-HW-H',
  18624. 'KSCms-UHC-HW-V',
  18625. 'KSCms-UHC-V',
  18626. 'KSCpc-EUC-H',
  18627. 'KSCpc-EUC-V',
  18628. 'Katakana',
  18629. 'NWP-H',
  18630. 'NWP-V',
  18631. 'RKSJ-H',
  18632. 'RKSJ-V',
  18633. 'Roman',
  18634. 'UniCNS-UCS2-H',
  18635. 'UniCNS-UCS2-V',
  18636. 'UniCNS-UTF16-H',
  18637. 'UniCNS-UTF16-V',
  18638. 'UniCNS-UTF32-H',
  18639. 'UniCNS-UTF32-V',
  18640. 'UniCNS-UTF8-H',
  18641. 'UniCNS-UTF8-V',
  18642. 'UniGB-UCS2-H',
  18643. 'UniGB-UCS2-V',
  18644. 'UniGB-UTF16-H',
  18645. 'UniGB-UTF16-V',
  18646. 'UniGB-UTF32-H',
  18647. 'UniGB-UTF32-V',
  18648. 'UniGB-UTF8-H',
  18649. 'UniGB-UTF8-V',
  18650. 'UniJIS-UCS2-H',
  18651. 'UniJIS-UCS2-HW-H',
  18652. 'UniJIS-UCS2-HW-V',
  18653. 'UniJIS-UCS2-V',
  18654. 'UniJIS-UTF16-H',
  18655. 'UniJIS-UTF16-V',
  18656. 'UniJIS-UTF32-H',
  18657. 'UniJIS-UTF32-V',
  18658. 'UniJIS-UTF8-H',
  18659. 'UniJIS-UTF8-V',
  18660. 'UniJIS2004-UTF16-H',
  18661. 'UniJIS2004-UTF16-V',
  18662. 'UniJIS2004-UTF32-H',
  18663. 'UniJIS2004-UTF32-V',
  18664. 'UniJIS2004-UTF8-H',
  18665. 'UniJIS2004-UTF8-V',
  18666. 'UniJISPro-UCS2-HW-V',
  18667. 'UniJISPro-UCS2-V',
  18668. 'UniJISPro-UTF8-V',
  18669. 'UniJISX0213-UTF32-H',
  18670. 'UniJISX0213-UTF32-V',
  18671. 'UniJISX02132004-UTF32-H',
  18672. 'UniJISX02132004-UTF32-V',
  18673. 'UniKS-UCS2-H',
  18674. 'UniKS-UCS2-V',
  18675. 'UniKS-UTF16-H',
  18676. 'UniKS-UTF16-V',
  18677. 'UniKS-UTF32-H',
  18678. 'UniKS-UTF32-V',
  18679. 'UniKS-UTF8-H',
  18680. 'UniKS-UTF8-V',
  18681. 'V',
  18682. 'WP-Symbol'];
  18683. // CMap, not to be confused with TrueType's cmap.
  18684. var CMap = (function CMapClosure() {
  18685. function CMap(builtInCMap) {
  18686. // Codespace ranges are stored as follows:
  18687. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  18688. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  18689. this.codespaceRanges = [[], [], [], []];
  18690. this.numCodespaceRanges = 0;
  18691. // Map entries have one of two forms.
  18692. // - cid chars are 16-bit unsigned integers, stored as integers.
  18693. // - bf chars are variable-length byte sequences, stored as strings, with
  18694. // one byte per character.
  18695. this._map = [];
  18696. this.name = '';
  18697. this.vertical = false;
  18698. this.useCMap = null;
  18699. this.builtInCMap = builtInCMap;
  18700. }
  18701. CMap.prototype = {
  18702. addCodespaceRange: function(n, low, high) {
  18703. this.codespaceRanges[n - 1].push(low, high);
  18704. this.numCodespaceRanges++;
  18705. },
  18706. mapCidRange: function(low, high, dstLow) {
  18707. while (low <= high) {
  18708. this._map[low++] = dstLow++;
  18709. }
  18710. },
  18711. mapBfRange: function(low, high, dstLow) {
  18712. var lastByte = dstLow.length - 1;
  18713. while (low <= high) {
  18714. this._map[low++] = dstLow;
  18715. // Only the last byte has to be incremented.
  18716. dstLow = dstLow.substr(0, lastByte) +
  18717. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  18718. }
  18719. },
  18720. mapBfRangeToArray: function(low, high, array) {
  18721. var i = 0, ii = array.length;
  18722. while (low <= high && i < ii) {
  18723. this._map[low] = array[i++];
  18724. ++low;
  18725. }
  18726. },
  18727. // This is used for both bf and cid chars.
  18728. mapOne: function(src, dst) {
  18729. this._map[src] = dst;
  18730. },
  18731. lookup: function(code) {
  18732. return this._map[code];
  18733. },
  18734. contains: function(code) {
  18735. return this._map[code] !== undefined;
  18736. },
  18737. forEach: function(callback) {
  18738. // Most maps have fewer than 65536 entries, and for those we use normal
  18739. // array iteration. But really sparse tables are possible -- e.g. with
  18740. // indices in the *billions*. For such tables we use for..in, which isn't
  18741. // ideal because it stringifies the indices for all present elements, but
  18742. // it does avoid iterating over every undefined entry.
  18743. var map = this._map;
  18744. var length = map.length;
  18745. var i;
  18746. if (length <= 0x10000) {
  18747. for (i = 0; i < length; i++) {
  18748. if (map[i] !== undefined) {
  18749. callback(i, map[i]);
  18750. }
  18751. }
  18752. } else {
  18753. for (i in this._map) {
  18754. callback(i, map[i]);
  18755. }
  18756. }
  18757. },
  18758. charCodeOf: function(value) {
  18759. return this._map.indexOf(value);
  18760. },
  18761. getMap: function() {
  18762. return this._map;
  18763. },
  18764. readCharCode: function(str, offset, out) {
  18765. var c = 0;
  18766. var codespaceRanges = this.codespaceRanges;
  18767. var codespaceRangesLen = this.codespaceRanges.length;
  18768. // 9.7.6.2 CMap Mapping
  18769. // The code length is at most 4.
  18770. for (var n = 0; n < codespaceRangesLen; n++) {
  18771. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  18772. // Check each codespace range to see if it falls within.
  18773. var codespaceRange = codespaceRanges[n];
  18774. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  18775. var low = codespaceRange[k++];
  18776. var high = codespaceRange[k++];
  18777. if (c >= low && c <= high) {
  18778. out.charcode = c;
  18779. out.length = n + 1;
  18780. return;
  18781. }
  18782. }
  18783. }
  18784. out.charcode = 0;
  18785. out.length = 1;
  18786. },
  18787. get length() {
  18788. return this._map.length;
  18789. },
  18790. get isIdentityCMap() {
  18791. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  18792. return false;
  18793. }
  18794. if (this._map.length !== 0x10000) {
  18795. return false;
  18796. }
  18797. for (var i = 0; i < 0x10000; i++) {
  18798. if (this._map[i] !== i) {
  18799. return false;
  18800. }
  18801. }
  18802. return true;
  18803. }
  18804. };
  18805. return CMap;
  18806. })();
  18807. // A special case of CMap, where the _map array implicitly has a length of
  18808. // 65536 and each element is equal to its index.
  18809. var IdentityCMap = (function IdentityCMapClosure() {
  18810. function IdentityCMap(vertical, n) {
  18811. CMap.call(this);
  18812. this.vertical = vertical;
  18813. this.addCodespaceRange(n, 0, 0xffff);
  18814. }
  18815. Util.inherit(IdentityCMap, CMap, {});
  18816. IdentityCMap.prototype = {
  18817. addCodespaceRange: CMap.prototype.addCodespaceRange,
  18818. mapCidRange: function(low, high, dstLow) {
  18819. error('should not call mapCidRange');
  18820. },
  18821. mapBfRange: function(low, high, dstLow) {
  18822. error('should not call mapBfRange');
  18823. },
  18824. mapBfRangeToArray: function(low, high, array) {
  18825. error('should not call mapBfRangeToArray');
  18826. },
  18827. mapOne: function(src, dst) {
  18828. error('should not call mapCidOne');
  18829. },
  18830. lookup: function(code) {
  18831. return (isInt(code) && code <= 0xffff) ? code : undefined;
  18832. },
  18833. contains: function(code) {
  18834. return isInt(code) && code <= 0xffff;
  18835. },
  18836. forEach: function(callback) {
  18837. for (var i = 0; i <= 0xffff; i++) {
  18838. callback(i, i);
  18839. }
  18840. },
  18841. charCodeOf: function(value) {
  18842. return (isInt(value) && value <= 0xffff) ? value : -1;
  18843. },
  18844. getMap: function() {
  18845. // Sometimes identity maps must be instantiated, but it's rare.
  18846. var map = new Array(0x10000);
  18847. for (var i = 0; i <= 0xffff; i++) {
  18848. map[i] = i;
  18849. }
  18850. return map;
  18851. },
  18852. readCharCode: CMap.prototype.readCharCode,
  18853. get length() {
  18854. return 0x10000;
  18855. },
  18856. get isIdentityCMap() {
  18857. error('should not access .isIdentityCMap');
  18858. }
  18859. };
  18860. return IdentityCMap;
  18861. })();
  18862. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  18863. function fetchBinaryData(url) {
  18864. var nonBinaryRequest = PDFJS.disableWorker;
  18865. var request = new XMLHttpRequest();
  18866. request.open('GET', url, false);
  18867. if (!nonBinaryRequest) {
  18868. try {
  18869. request.responseType = 'arraybuffer';
  18870. nonBinaryRequest = request.responseType !== 'arraybuffer';
  18871. } catch (e) {
  18872. nonBinaryRequest = true;
  18873. }
  18874. }
  18875. if (nonBinaryRequest && request.overrideMimeType) {
  18876. request.overrideMimeType('text/plain; charset=x-user-defined');
  18877. }
  18878. request.send(null);
  18879. if (nonBinaryRequest ? !request.responseText : !request.response) {
  18880. error('Unable to get binary cMap at: ' + url);
  18881. }
  18882. if (nonBinaryRequest) {
  18883. var data = Array.prototype.map.call(request.responseText, function (ch) {
  18884. return ch.charCodeAt(0) & 255;
  18885. });
  18886. return new Uint8Array(data);
  18887. }
  18888. return new Uint8Array(request.response);
  18889. }
  18890. function hexToInt(a, size) {
  18891. var n = 0;
  18892. for (var i = 0; i <= size; i++) {
  18893. n = (n << 8) | a[i];
  18894. }
  18895. return n >>> 0;
  18896. }
  18897. function hexToStr(a, size) {
  18898. // This code is hot. Special-case some common values to avoid creating an
  18899. // object with subarray().
  18900. if (size === 1) {
  18901. return String.fromCharCode(a[0], a[1]);
  18902. }
  18903. if (size === 3) {
  18904. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  18905. }
  18906. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  18907. }
  18908. function addHex(a, b, size) {
  18909. var c = 0;
  18910. for (var i = size; i >= 0; i--) {
  18911. c += a[i] + b[i];
  18912. a[i] = c & 255;
  18913. c >>= 8;
  18914. }
  18915. }
  18916. function incHex(a, size) {
  18917. var c = 1;
  18918. for (var i = size; i >= 0 && c > 0; i--) {
  18919. c += a[i];
  18920. a[i] = c & 255;
  18921. c >>= 8;
  18922. }
  18923. }
  18924. var MAX_NUM_SIZE = 16;
  18925. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  18926. function BinaryCMapStream(data) {
  18927. this.buffer = data;
  18928. this.pos = 0;
  18929. this.end = data.length;
  18930. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  18931. }
  18932. BinaryCMapStream.prototype = {
  18933. readByte: function () {
  18934. if (this.pos >= this.end) {
  18935. return -1;
  18936. }
  18937. return this.buffer[this.pos++];
  18938. },
  18939. readNumber: function () {
  18940. var n = 0;
  18941. var last;
  18942. do {
  18943. var b = this.readByte();
  18944. if (b < 0) {
  18945. error('unexpected EOF in bcmap');
  18946. }
  18947. last = !(b & 0x80);
  18948. n = (n << 7) | (b & 0x7F);
  18949. } while (!last);
  18950. return n;
  18951. },
  18952. readSigned: function () {
  18953. var n = this.readNumber();
  18954. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  18955. },
  18956. readHex: function (num, size) {
  18957. num.set(this.buffer.subarray(this.pos,
  18958. this.pos + size + 1));
  18959. this.pos += size + 1;
  18960. },
  18961. readHexNumber: function (num, size) {
  18962. var last;
  18963. var stack = this.tmpBuf, sp = 0;
  18964. do {
  18965. var b = this.readByte();
  18966. if (b < 0) {
  18967. error('unexpected EOF in bcmap');
  18968. }
  18969. last = !(b & 0x80);
  18970. stack[sp++] = b & 0x7F;
  18971. } while (!last);
  18972. var i = size, buffer = 0, bufferSize = 0;
  18973. while (i >= 0) {
  18974. while (bufferSize < 8 && stack.length > 0) {
  18975. buffer = (stack[--sp] << bufferSize) | buffer;
  18976. bufferSize += 7;
  18977. }
  18978. num[i] = buffer & 255;
  18979. i--;
  18980. buffer >>= 8;
  18981. bufferSize -= 8;
  18982. }
  18983. },
  18984. readHexSigned: function (num, size) {
  18985. this.readHexNumber(num, size);
  18986. var sign = num[size] & 1 ? 255 : 0;
  18987. var c = 0;
  18988. for (var i = 0; i <= size; i++) {
  18989. c = ((c & 1) << 8) | num[i];
  18990. num[i] = (c >> 1) ^ sign;
  18991. }
  18992. },
  18993. readString: function () {
  18994. var len = this.readNumber();
  18995. var s = '';
  18996. for (var i = 0; i < len; i++) {
  18997. s += String.fromCharCode(this.readNumber());
  18998. }
  18999. return s;
  19000. }
  19001. };
  19002. function processBinaryCMap(url, cMap, extend) {
  19003. var data = fetchBinaryData(url);
  19004. var stream = new BinaryCMapStream(data);
  19005. var header = stream.readByte();
  19006. cMap.vertical = !!(header & 1);
  19007. var useCMap = null;
  19008. var start = new Uint8Array(MAX_NUM_SIZE);
  19009. var end = new Uint8Array(MAX_NUM_SIZE);
  19010. var char = new Uint8Array(MAX_NUM_SIZE);
  19011. var charCode = new Uint8Array(MAX_NUM_SIZE);
  19012. var tmp = new Uint8Array(MAX_NUM_SIZE);
  19013. var code;
  19014. var b;
  19015. while ((b = stream.readByte()) >= 0) {
  19016. var type = b >> 5;
  19017. if (type === 7) { // metadata, e.g. comment or usecmap
  19018. switch (b & 0x1F) {
  19019. case 0:
  19020. stream.readString(); // skipping comment
  19021. break;
  19022. case 1:
  19023. useCMap = stream.readString();
  19024. break;
  19025. }
  19026. continue;
  19027. }
  19028. var sequence = !!(b & 0x10);
  19029. var dataSize = b & 15;
  19030. assert(dataSize + 1 <= MAX_NUM_SIZE);
  19031. var ucs2DataSize = 1;
  19032. var subitemsCount = stream.readNumber();
  19033. var i;
  19034. switch (type) {
  19035. case 0: // codespacerange
  19036. stream.readHex(start, dataSize);
  19037. stream.readHexNumber(end, dataSize);
  19038. addHex(end, start, dataSize);
  19039. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  19040. hexToInt(end, dataSize));
  19041. for (i = 1; i < subitemsCount; i++) {
  19042. incHex(end, dataSize);
  19043. stream.readHexNumber(start, dataSize);
  19044. addHex(start, end, dataSize);
  19045. stream.readHexNumber(end, dataSize);
  19046. addHex(end, start, dataSize);
  19047. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  19048. hexToInt(end, dataSize));
  19049. }
  19050. break;
  19051. case 1: // notdefrange
  19052. stream.readHex(start, dataSize);
  19053. stream.readHexNumber(end, dataSize);
  19054. addHex(end, start, dataSize);
  19055. code = stream.readNumber();
  19056. // undefined range, skipping
  19057. for (i = 1; i < subitemsCount; i++) {
  19058. incHex(end, dataSize);
  19059. stream.readHexNumber(start, dataSize);
  19060. addHex(start, end, dataSize);
  19061. stream.readHexNumber(end, dataSize);
  19062. addHex(end, start, dataSize);
  19063. code = stream.readNumber();
  19064. // nop
  19065. }
  19066. break;
  19067. case 2: // cidchar
  19068. stream.readHex(char, dataSize);
  19069. code = stream.readNumber();
  19070. cMap.mapOne(hexToInt(char, dataSize), code);
  19071. for (i = 1; i < subitemsCount; i++) {
  19072. incHex(char, dataSize);
  19073. if (!sequence) {
  19074. stream.readHexNumber(tmp, dataSize);
  19075. addHex(char, tmp, dataSize);
  19076. }
  19077. code = stream.readSigned() + (code + 1);
  19078. cMap.mapOne(hexToInt(char, dataSize), code);
  19079. }
  19080. break;
  19081. case 3: // cidrange
  19082. stream.readHex(start, dataSize);
  19083. stream.readHexNumber(end, dataSize);
  19084. addHex(end, start, dataSize);
  19085. code = stream.readNumber();
  19086. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  19087. code);
  19088. for (i = 1; i < subitemsCount; i++) {
  19089. incHex(end, dataSize);
  19090. if (!sequence) {
  19091. stream.readHexNumber(start, dataSize);
  19092. addHex(start, end, dataSize);
  19093. } else {
  19094. start.set(end);
  19095. }
  19096. stream.readHexNumber(end, dataSize);
  19097. addHex(end, start, dataSize);
  19098. code = stream.readNumber();
  19099. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  19100. code);
  19101. }
  19102. break;
  19103. case 4: // bfchar
  19104. stream.readHex(char, ucs2DataSize);
  19105. stream.readHex(charCode, dataSize);
  19106. cMap.mapOne(hexToInt(char, ucs2DataSize),
  19107. hexToStr(charCode, dataSize));
  19108. for (i = 1; i < subitemsCount; i++) {
  19109. incHex(char, ucs2DataSize);
  19110. if (!sequence) {
  19111. stream.readHexNumber(tmp, ucs2DataSize);
  19112. addHex(char, tmp, ucs2DataSize);
  19113. }
  19114. incHex(charCode, dataSize);
  19115. stream.readHexSigned(tmp, dataSize);
  19116. addHex(charCode, tmp, dataSize);
  19117. cMap.mapOne(hexToInt(char, ucs2DataSize),
  19118. hexToStr(charCode, dataSize));
  19119. }
  19120. break;
  19121. case 5: // bfrange
  19122. stream.readHex(start, ucs2DataSize);
  19123. stream.readHexNumber(end, ucs2DataSize);
  19124. addHex(end, start, ucs2DataSize);
  19125. stream.readHex(charCode, dataSize);
  19126. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  19127. hexToInt(end, ucs2DataSize),
  19128. hexToStr(charCode, dataSize));
  19129. for (i = 1; i < subitemsCount; i++) {
  19130. incHex(end, ucs2DataSize);
  19131. if (!sequence) {
  19132. stream.readHexNumber(start, ucs2DataSize);
  19133. addHex(start, end, ucs2DataSize);
  19134. } else {
  19135. start.set(end);
  19136. }
  19137. stream.readHexNumber(end, ucs2DataSize);
  19138. addHex(end, start, ucs2DataSize);
  19139. stream.readHex(charCode, dataSize);
  19140. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  19141. hexToInt(end, ucs2DataSize),
  19142. hexToStr(charCode, dataSize));
  19143. }
  19144. break;
  19145. default:
  19146. error('Unknown type: ' + type);
  19147. break;
  19148. }
  19149. }
  19150. if (useCMap) {
  19151. extend(useCMap);
  19152. }
  19153. return cMap;
  19154. }
  19155. function BinaryCMapReader() {}
  19156. BinaryCMapReader.prototype = {
  19157. read: processBinaryCMap
  19158. };
  19159. return BinaryCMapReader;
  19160. })();
  19161. var CMapFactory = (function CMapFactoryClosure() {
  19162. function strToInt(str) {
  19163. var a = 0;
  19164. for (var i = 0; i < str.length; i++) {
  19165. a = (a << 8) | str.charCodeAt(i);
  19166. }
  19167. return a >>> 0;
  19168. }
  19169. function expectString(obj) {
  19170. if (!isString(obj)) {
  19171. error('Malformed CMap: expected string.');
  19172. }
  19173. }
  19174. function expectInt(obj) {
  19175. if (!isInt(obj)) {
  19176. error('Malformed CMap: expected int.');
  19177. }
  19178. }
  19179. function parseBfChar(cMap, lexer) {
  19180. while (true) {
  19181. var obj = lexer.getObj();
  19182. if (isEOF(obj)) {
  19183. break;
  19184. }
  19185. if (isCmd(obj, 'endbfchar')) {
  19186. return;
  19187. }
  19188. expectString(obj);
  19189. var src = strToInt(obj);
  19190. obj = lexer.getObj();
  19191. // TODO are /dstName used?
  19192. expectString(obj);
  19193. var dst = obj;
  19194. cMap.mapOne(src, dst);
  19195. }
  19196. }
  19197. function parseBfRange(cMap, lexer) {
  19198. while (true) {
  19199. var obj = lexer.getObj();
  19200. if (isEOF(obj)) {
  19201. break;
  19202. }
  19203. if (isCmd(obj, 'endbfrange')) {
  19204. return;
  19205. }
  19206. expectString(obj);
  19207. var low = strToInt(obj);
  19208. obj = lexer.getObj();
  19209. expectString(obj);
  19210. var high = strToInt(obj);
  19211. obj = lexer.getObj();
  19212. if (isInt(obj) || isString(obj)) {
  19213. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  19214. cMap.mapBfRange(low, high, dstLow);
  19215. } else if (isCmd(obj, '[')) {
  19216. obj = lexer.getObj();
  19217. var array = [];
  19218. while (!isCmd(obj, ']') && !isEOF(obj)) {
  19219. array.push(obj);
  19220. obj = lexer.getObj();
  19221. }
  19222. cMap.mapBfRangeToArray(low, high, array);
  19223. } else {
  19224. break;
  19225. }
  19226. }
  19227. error('Invalid bf range.');
  19228. }
  19229. function parseCidChar(cMap, lexer) {
  19230. while (true) {
  19231. var obj = lexer.getObj();
  19232. if (isEOF(obj)) {
  19233. break;
  19234. }
  19235. if (isCmd(obj, 'endcidchar')) {
  19236. return;
  19237. }
  19238. expectString(obj);
  19239. var src = strToInt(obj);
  19240. obj = lexer.getObj();
  19241. expectInt(obj);
  19242. var dst = obj;
  19243. cMap.mapOne(src, dst);
  19244. }
  19245. }
  19246. function parseCidRange(cMap, lexer) {
  19247. while (true) {
  19248. var obj = lexer.getObj();
  19249. if (isEOF(obj)) {
  19250. break;
  19251. }
  19252. if (isCmd(obj, 'endcidrange')) {
  19253. return;
  19254. }
  19255. expectString(obj);
  19256. var low = strToInt(obj);
  19257. obj = lexer.getObj();
  19258. expectString(obj);
  19259. var high = strToInt(obj);
  19260. obj = lexer.getObj();
  19261. expectInt(obj);
  19262. var dstLow = obj;
  19263. cMap.mapCidRange(low, high, dstLow);
  19264. }
  19265. }
  19266. function parseCodespaceRange(cMap, lexer) {
  19267. while (true) {
  19268. var obj = lexer.getObj();
  19269. if (isEOF(obj)) {
  19270. break;
  19271. }
  19272. if (isCmd(obj, 'endcodespacerange')) {
  19273. return;
  19274. }
  19275. if (!isString(obj)) {
  19276. break;
  19277. }
  19278. var low = strToInt(obj);
  19279. obj = lexer.getObj();
  19280. if (!isString(obj)) {
  19281. break;
  19282. }
  19283. var high = strToInt(obj);
  19284. cMap.addCodespaceRange(obj.length, low, high);
  19285. }
  19286. error('Invalid codespace range.');
  19287. }
  19288. function parseWMode(cMap, lexer) {
  19289. var obj = lexer.getObj();
  19290. if (isInt(obj)) {
  19291. cMap.vertical = !!obj;
  19292. }
  19293. }
  19294. function parseCMapName(cMap, lexer) {
  19295. var obj = lexer.getObj();
  19296. if (isName(obj) && isString(obj.name)) {
  19297. cMap.name = obj.name;
  19298. }
  19299. }
  19300. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  19301. var previous;
  19302. var embededUseCMap;
  19303. objLoop: while (true) {
  19304. var obj = lexer.getObj();
  19305. if (isEOF(obj)) {
  19306. break;
  19307. } else if (isName(obj)) {
  19308. if (obj.name === 'WMode') {
  19309. parseWMode(cMap, lexer);
  19310. } else if (obj.name === 'CMapName') {
  19311. parseCMapName(cMap, lexer);
  19312. }
  19313. previous = obj;
  19314. } else if (isCmd(obj)) {
  19315. switch (obj.cmd) {
  19316. case 'endcmap':
  19317. break objLoop;
  19318. case 'usecmap':
  19319. if (isName(previous)) {
  19320. embededUseCMap = previous.name;
  19321. }
  19322. break;
  19323. case 'begincodespacerange':
  19324. parseCodespaceRange(cMap, lexer);
  19325. break;
  19326. case 'beginbfchar':
  19327. parseBfChar(cMap, lexer);
  19328. break;
  19329. case 'begincidchar':
  19330. parseCidChar(cMap, lexer);
  19331. break;
  19332. case 'beginbfrange':
  19333. parseBfRange(cMap, lexer);
  19334. break;
  19335. case 'begincidrange':
  19336. parseCidRange(cMap, lexer);
  19337. break;
  19338. }
  19339. }
  19340. }
  19341. if (!useCMap && embededUseCMap) {
  19342. // Load the usecmap definition from the file only if there wasn't one
  19343. // specified.
  19344. useCMap = embededUseCMap;
  19345. }
  19346. if (useCMap) {
  19347. extendCMap(cMap, builtInCMapParams, useCMap);
  19348. }
  19349. }
  19350. function extendCMap(cMap, builtInCMapParams, useCMap) {
  19351. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  19352. // If there aren't any code space ranges defined clone all the parent ones
  19353. // into this cMap.
  19354. if (cMap.numCodespaceRanges === 0) {
  19355. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  19356. for (var i = 0; i < useCodespaceRanges.length; i++) {
  19357. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  19358. }
  19359. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  19360. }
  19361. // Merge the map into the current one, making sure not to override
  19362. // any previously defined entries.
  19363. cMap.useCMap.forEach(function(key, value) {
  19364. if (!cMap.contains(key)) {
  19365. cMap.mapOne(key, cMap.useCMap.lookup(key));
  19366. }
  19367. });
  19368. }
  19369. function parseBinaryCMap(name, builtInCMapParams) {
  19370. var url = builtInCMapParams.url + name + '.bcmap';
  19371. var cMap = new CMap(true);
  19372. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  19373. extendCMap(cMap, builtInCMapParams, useCMap);
  19374. });
  19375. return cMap;
  19376. }
  19377. function createBuiltInCMap(name, builtInCMapParams) {
  19378. if (name === 'Identity-H') {
  19379. return new IdentityCMap(false, 2);
  19380. } else if (name === 'Identity-V') {
  19381. return new IdentityCMap(true, 2);
  19382. }
  19383. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  19384. error('Unknown cMap name: ' + name);
  19385. }
  19386. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  19387. if (builtInCMapParams.packed) {
  19388. return parseBinaryCMap(name, builtInCMapParams);
  19389. }
  19390. var request = new XMLHttpRequest();
  19391. var url = builtInCMapParams.url + name;
  19392. request.open('GET', url, false);
  19393. request.send(null);
  19394. if (!request.responseText) {
  19395. error('Unable to get cMap at: ' + url);
  19396. }
  19397. var cMap = new CMap(true);
  19398. var lexer = new Lexer(new StringStream(request.responseText));
  19399. parseCMap(cMap, lexer, builtInCMapParams, null);
  19400. return cMap;
  19401. }
  19402. return {
  19403. create: function (encoding, builtInCMapParams, useCMap) {
  19404. if (isName(encoding)) {
  19405. return createBuiltInCMap(encoding.name, builtInCMapParams);
  19406. } else if (isStream(encoding)) {
  19407. var cMap = new CMap();
  19408. var lexer = new Lexer(encoding);
  19409. try {
  19410. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  19411. } catch (e) {
  19412. warn('Invalid CMap data. ' + e);
  19413. }
  19414. if (cMap.isIdentityCMap) {
  19415. return createBuiltInCMap(cMap.name, builtInCMapParams);
  19416. }
  19417. return cMap;
  19418. }
  19419. error('Encoding required.');
  19420. }
  19421. };
  19422. })();
  19423. // Unicode Private Use Area
  19424. var PRIVATE_USE_OFFSET_START = 0xE000;
  19425. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  19426. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  19427. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  19428. // except for Type 3 fonts
  19429. var PDF_GLYPH_SPACE_UNITS = 1000;
  19430. // Hinting is currently disabled due to unknown problems on windows
  19431. // in tracemonkey and various other pdfs with type1 fonts.
  19432. var HINTING_ENABLED = false;
  19433. // Accented charactars are not displayed properly on windows, using this flag
  19434. // to control analysis of seac charstrings.
  19435. var SEAC_ANALYSIS_ENABLED = false;
  19436. var FontFlags = {
  19437. FixedPitch: 1,
  19438. Serif: 2,
  19439. Symbolic: 4,
  19440. Script: 8,
  19441. Nonsymbolic: 32,
  19442. Italic: 64,
  19443. AllCap: 65536,
  19444. SmallCap: 131072,
  19445. ForceBold: 262144
  19446. };
  19447. var Encodings = {
  19448. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19449. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19450. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  19451. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  19452. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  19453. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  19454. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  19455. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  19456. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  19457. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  19458. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  19459. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  19460. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  19461. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  19462. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  19463. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  19464. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  19465. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  19466. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  19467. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19468. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  19469. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  19470. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  19471. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  19472. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  19473. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  19474. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  19475. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  19476. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  19477. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  19478. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  19479. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  19480. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  19481. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  19482. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  19483. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  19484. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  19485. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  19486. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  19487. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  19488. 'Ydieresissmall'],
  19489. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19490. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19491. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  19492. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  19493. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  19494. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  19495. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  19496. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  19497. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  19498. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  19499. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  19500. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  19501. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  19502. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  19503. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  19504. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  19505. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  19506. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  19507. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  19508. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  19509. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  19510. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  19511. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  19512. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  19513. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  19514. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  19515. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  19516. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  19517. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  19518. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  19519. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  19520. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  19521. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  19522. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  19523. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  19524. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  19525. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  19526. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  19527. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  19528. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  19529. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19530. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19531. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  19532. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  19533. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  19534. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  19535. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  19536. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  19537. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  19538. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  19539. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  19540. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  19541. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  19542. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  19543. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  19544. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  19545. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  19546. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  19547. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  19548. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  19549. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  19550. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  19551. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  19552. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  19553. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  19554. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  19555. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  19556. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  19557. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  19558. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  19559. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  19560. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  19561. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  19562. 'ogonek', 'caron'],
  19563. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19564. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19565. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  19566. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  19567. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  19568. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  19569. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  19570. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  19571. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  19572. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  19573. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  19574. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  19575. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19576. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  19577. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  19578. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  19579. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  19580. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  19581. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  19582. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  19583. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  19584. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  19585. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  19586. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  19587. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  19588. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19589. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19590. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  19591. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  19592. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  19593. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  19594. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  19595. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  19596. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  19597. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  19598. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  19599. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  19600. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  19601. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  19602. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  19603. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  19604. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  19605. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  19606. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  19607. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  19608. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  19609. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  19610. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  19611. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  19612. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  19613. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  19614. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  19615. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  19616. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  19617. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  19618. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  19619. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  19620. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  19621. 'ydieresis'],
  19622. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19623. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19624. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  19625. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  19626. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  19627. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  19628. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  19629. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  19630. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  19631. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  19632. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  19633. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  19634. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  19635. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  19636. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  19637. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19638. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  19639. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  19640. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  19641. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  19642. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  19643. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  19644. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  19645. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  19646. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  19647. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  19648. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  19649. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  19650. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  19651. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  19652. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  19653. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  19654. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  19655. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  19656. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  19657. 'bracerightbt'],
  19658. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19659. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  19660. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  19661. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  19662. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  19663. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  19664. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  19665. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  19666. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  19667. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  19668. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  19669. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  19670. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  19671. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  19672. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  19673. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  19674. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  19675. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  19676. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  19677. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  19678. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  19679. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  19680. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  19681. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  19682. };
  19683. /**
  19684. * Hold a map of decoded fonts and of the standard fourteen Type1
  19685. * fonts and their acronyms.
  19686. */
  19687. var stdFontMap = {
  19688. 'ArialNarrow': 'Helvetica',
  19689. 'ArialNarrow-Bold': 'Helvetica-Bold',
  19690. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  19691. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  19692. 'ArialBlack': 'Helvetica',
  19693. 'ArialBlack-Bold': 'Helvetica-Bold',
  19694. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  19695. 'ArialBlack-Italic': 'Helvetica-Oblique',
  19696. 'Arial': 'Helvetica',
  19697. 'Arial-Bold': 'Helvetica-Bold',
  19698. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  19699. 'Arial-Italic': 'Helvetica-Oblique',
  19700. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  19701. 'Arial-BoldMT': 'Helvetica-Bold',
  19702. 'Arial-ItalicMT': 'Helvetica-Oblique',
  19703. 'ArialMT': 'Helvetica',
  19704. 'Courier-Bold': 'Courier-Bold',
  19705. 'Courier-BoldItalic': 'Courier-BoldOblique',
  19706. 'Courier-Italic': 'Courier-Oblique',
  19707. 'CourierNew': 'Courier',
  19708. 'CourierNew-Bold': 'Courier-Bold',
  19709. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  19710. 'CourierNew-Italic': 'Courier-Oblique',
  19711. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  19712. 'CourierNewPS-BoldMT': 'Courier-Bold',
  19713. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  19714. 'CourierNewPSMT': 'Courier',
  19715. 'Helvetica': 'Helvetica',
  19716. 'Helvetica-Bold': 'Helvetica-Bold',
  19717. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  19718. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  19719. 'Helvetica-Italic': 'Helvetica-Oblique',
  19720. 'Helvetica-Oblique':'Helvetica-Oblique',
  19721. 'Symbol-Bold': 'Symbol',
  19722. 'Symbol-BoldItalic': 'Symbol',
  19723. 'Symbol-Italic': 'Symbol',
  19724. 'TimesNewRoman': 'Times-Roman',
  19725. 'TimesNewRoman-Bold': 'Times-Bold',
  19726. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  19727. 'TimesNewRoman-Italic': 'Times-Italic',
  19728. 'TimesNewRomanPS': 'Times-Roman',
  19729. 'TimesNewRomanPS-Bold': 'Times-Bold',
  19730. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  19731. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  19732. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  19733. 'TimesNewRomanPS-Italic': 'Times-Italic',
  19734. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  19735. 'TimesNewRomanPSMT': 'Times-Roman',
  19736. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  19737. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  19738. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  19739. };
  19740. /**
  19741. * Holds the map of the non-standard fonts that might be included as a standard
  19742. * fonts without glyph data.
  19743. */
  19744. var nonStdFontMap = {
  19745. 'CenturyGothic': 'Helvetica',
  19746. 'CenturyGothic-Bold': 'Helvetica-Bold',
  19747. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  19748. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  19749. 'ComicSansMS': 'Comic Sans MS',
  19750. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  19751. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  19752. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  19753. 'LucidaConsole': 'Courier',
  19754. 'LucidaConsole-Bold': 'Courier-Bold',
  19755. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  19756. 'LucidaConsole-Italic': 'Courier-Oblique',
  19757. 'MS-Gothic': 'MS Gothic',
  19758. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  19759. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  19760. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  19761. 'MS-Mincho': 'MS Mincho',
  19762. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  19763. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  19764. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  19765. 'MS-PGothic': 'MS PGothic',
  19766. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  19767. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  19768. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  19769. 'MS-PMincho': 'MS PMincho',
  19770. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  19771. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  19772. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  19773. 'Wingdings': 'ZapfDingbats'
  19774. };
  19775. var serifFonts = {
  19776. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  19777. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  19778. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  19779. 'Arno': true, 'Aster': true, 'Aurora': true,
  19780. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  19781. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  19782. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  19783. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  19784. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  19785. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  19786. 'Cartier': true, 'Caslon': true, 'Catull': true,
  19787. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  19788. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  19789. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  19790. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  19791. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  19792. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  19793. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  19794. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  19795. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  19796. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  19797. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  19798. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  19799. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  19800. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  19801. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  19802. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  19803. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  19804. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  19805. 'Miller': true, 'Minion': true, 'Modern': true,
  19806. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  19807. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  19808. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  19809. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  19810. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  19811. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  19812. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  19813. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  19814. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  19815. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  19816. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  19817. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  19818. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  19819. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  19820. };
  19821. var symbolsFonts = {
  19822. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  19823. };
  19824. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  19825. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  19826. // glyphs, but common for some set of the standard fonts.
  19827. var GlyphMapForStandardFonts = {
  19828. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  19829. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  19830. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  19831. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  19832. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  19833. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  19834. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  19835. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  19836. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  19837. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  19838. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  19839. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  19840. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  19841. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  19842. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  19843. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  19844. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  19845. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  19846. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  19847. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  19848. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  19849. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  19850. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  19851. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  19852. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  19853. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  19854. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  19855. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  19856. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  19857. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  19858. '298': 380, '305': 963,
  19859. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  19860. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  19861. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  19862. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  19863. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  19864. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  19865. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  19866. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  19867. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  19868. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  19869. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  19870. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  19871. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  19872. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  19873. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  19874. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  19875. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  19876. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  19877. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  19878. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  19879. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  19880. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  19881. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  19882. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  19883. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  19884. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  19885. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  19886. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  19887. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  19888. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  19889. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  19890. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  19891. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  19892. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  19893. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  19894. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  19895. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  19896. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  19897. };
  19898. // The glyph map for ArialBlack differs slightly from the glyph map used for
  19899. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  19900. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  19901. var SupplementalGlyphMapForArialBlack = {
  19902. '227': 322, '264': 261, '291': 346,
  19903. };
  19904. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  19905. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  19906. // to the similar equivalents in the normal characters range.
  19907. var SpecialPUASymbols = {
  19908. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  19909. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  19910. '63720': 0x00AE, // registersans (0xF8E8) => registered
  19911. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  19912. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  19913. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  19914. '63729': 0x23A7, // bracelefttp (0xF8F1)
  19915. '63730': 0x23A8, // braceleftmid (0xF8F2)
  19916. '63731': 0x23A9, // braceleftbt (0xF8F3)
  19917. '63740': 0x23AB, // bracerighttp (0xF8FC)
  19918. '63741': 0x23AC, // bracerightmid (0xF8FD)
  19919. '63742': 0x23AD, // bracerightbt (0xF8FE)
  19920. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  19921. '63727': 0x23A2, // bracketleftex (0xF8EF)
  19922. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  19923. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  19924. '63738': 0x23A5, // bracketrightex (0xF8FA)
  19925. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  19926. '63723': 0x239B, // parenlefttp (0xF8EB)
  19927. '63724': 0x239C, // parenleftex (0xF8EC)
  19928. '63725': 0x239D, // parenleftbt (0xF8ED)
  19929. '63734': 0x239E, // parenrighttp (0xF8F6)
  19930. '63735': 0x239F, // parenrightex (0xF8F7)
  19931. '63736': 0x23A0, // parenrightbt (0xF8F8)
  19932. };
  19933. function mapSpecialUnicodeValues(code) {
  19934. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  19935. return 0;
  19936. } else if (code >= 0xF600 && code <= 0xF8FF) {
  19937. return (SpecialPUASymbols[code] || code);
  19938. }
  19939. return code;
  19940. }
  19941. var UnicodeRanges = [
  19942. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  19943. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  19944. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  19945. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  19946. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  19947. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  19948. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  19949. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  19950. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  19951. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  19952. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  19953. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  19954. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  19955. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  19956. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  19957. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  19958. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  19959. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  19960. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  19961. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  19962. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  19963. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  19964. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  19965. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  19966. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  19967. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  19968. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  19969. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  19970. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  19971. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  19972. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  19973. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  19974. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  19975. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  19976. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  19977. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  19978. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  19979. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  19980. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  19981. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  19982. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  19983. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  19984. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  19985. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  19986. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  19987. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  19988. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  19989. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  19990. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  19991. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  19992. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  19993. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  19994. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  19995. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  19996. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  19997. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  19998. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  19999. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  20000. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  20001. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  20002. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  20003. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  20004. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  20005. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  20006. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  20007. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  20008. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  20009. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  20010. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  20011. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  20012. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  20013. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  20014. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  20015. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  20016. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  20017. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  20018. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  20019. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  20020. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  20021. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  20022. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  20023. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  20024. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  20025. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  20026. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  20027. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  20028. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  20029. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  20030. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  20031. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  20032. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  20033. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  20034. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  20035. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  20036. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  20037. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  20038. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  20039. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  20040. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  20041. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  20042. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  20043. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  20044. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  20045. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  20046. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  20047. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  20048. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  20049. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  20050. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  20051. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  20052. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  20053. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  20054. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  20055. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  20056. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  20057. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  20058. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  20059. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  20060. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  20061. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  20062. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  20063. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  20064. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  20065. ];
  20066. var MacStandardGlyphOrdering = [
  20067. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  20068. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  20069. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  20070. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  20071. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  20072. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  20073. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  20074. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  20075. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  20076. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  20077. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  20078. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  20079. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  20080. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  20081. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  20082. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  20083. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  20084. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  20085. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  20086. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  20087. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  20088. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  20089. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  20090. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  20091. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  20092. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  20093. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  20094. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  20095. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  20096. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  20097. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  20098. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  20099. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  20100. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  20101. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  20102. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  20103. function getUnicodeRangeFor(value) {
  20104. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  20105. var range = UnicodeRanges[i];
  20106. if (value >= range.begin && value < range.end) {
  20107. return i;
  20108. }
  20109. }
  20110. return -1;
  20111. }
  20112. function isRTLRangeFor(value) {
  20113. var range = UnicodeRanges[13];
  20114. if (value >= range.begin && value < range.end) {
  20115. return true;
  20116. }
  20117. range = UnicodeRanges[11];
  20118. if (value >= range.begin && value < range.end) {
  20119. return true;
  20120. }
  20121. return false;
  20122. }
  20123. // The normalization table is obtained by filtering the Unicode characters
  20124. // database with <compat> entries.
  20125. var NormalizedUnicodes = {
  20126. '\u00A8': '\u0020\u0308',
  20127. '\u00AF': '\u0020\u0304',
  20128. '\u00B4': '\u0020\u0301',
  20129. '\u00B5': '\u03BC',
  20130. '\u00B8': '\u0020\u0327',
  20131. '\u0132': '\u0049\u004A',
  20132. '\u0133': '\u0069\u006A',
  20133. '\u013F': '\u004C\u00B7',
  20134. '\u0140': '\u006C\u00B7',
  20135. '\u0149': '\u02BC\u006E',
  20136. '\u017F': '\u0073',
  20137. '\u01C4': '\u0044\u017D',
  20138. '\u01C5': '\u0044\u017E',
  20139. '\u01C6': '\u0064\u017E',
  20140. '\u01C7': '\u004C\u004A',
  20141. '\u01C8': '\u004C\u006A',
  20142. '\u01C9': '\u006C\u006A',
  20143. '\u01CA': '\u004E\u004A',
  20144. '\u01CB': '\u004E\u006A',
  20145. '\u01CC': '\u006E\u006A',
  20146. '\u01F1': '\u0044\u005A',
  20147. '\u01F2': '\u0044\u007A',
  20148. '\u01F3': '\u0064\u007A',
  20149. '\u02D8': '\u0020\u0306',
  20150. '\u02D9': '\u0020\u0307',
  20151. '\u02DA': '\u0020\u030A',
  20152. '\u02DB': '\u0020\u0328',
  20153. '\u02DC': '\u0020\u0303',
  20154. '\u02DD': '\u0020\u030B',
  20155. '\u037A': '\u0020\u0345',
  20156. '\u0384': '\u0020\u0301',
  20157. '\u03D0': '\u03B2',
  20158. '\u03D1': '\u03B8',
  20159. '\u03D2': '\u03A5',
  20160. '\u03D5': '\u03C6',
  20161. '\u03D6': '\u03C0',
  20162. '\u03F0': '\u03BA',
  20163. '\u03F1': '\u03C1',
  20164. '\u03F2': '\u03C2',
  20165. '\u03F4': '\u0398',
  20166. '\u03F5': '\u03B5',
  20167. '\u03F9': '\u03A3',
  20168. '\u0587': '\u0565\u0582',
  20169. '\u0675': '\u0627\u0674',
  20170. '\u0676': '\u0648\u0674',
  20171. '\u0677': '\u06C7\u0674',
  20172. '\u0678': '\u064A\u0674',
  20173. '\u0E33': '\u0E4D\u0E32',
  20174. '\u0EB3': '\u0ECD\u0EB2',
  20175. '\u0EDC': '\u0EAB\u0E99',
  20176. '\u0EDD': '\u0EAB\u0EA1',
  20177. '\u0F77': '\u0FB2\u0F81',
  20178. '\u0F79': '\u0FB3\u0F81',
  20179. '\u1E9A': '\u0061\u02BE',
  20180. '\u1FBD': '\u0020\u0313',
  20181. '\u1FBF': '\u0020\u0313',
  20182. '\u1FC0': '\u0020\u0342',
  20183. '\u1FFE': '\u0020\u0314',
  20184. '\u2002': '\u0020',
  20185. '\u2003': '\u0020',
  20186. '\u2004': '\u0020',
  20187. '\u2005': '\u0020',
  20188. '\u2006': '\u0020',
  20189. '\u2008': '\u0020',
  20190. '\u2009': '\u0020',
  20191. '\u200A': '\u0020',
  20192. '\u2017': '\u0020\u0333',
  20193. '\u2024': '\u002E',
  20194. '\u2025': '\u002E\u002E',
  20195. '\u2026': '\u002E\u002E\u002E',
  20196. '\u2033': '\u2032\u2032',
  20197. '\u2034': '\u2032\u2032\u2032',
  20198. '\u2036': '\u2035\u2035',
  20199. '\u2037': '\u2035\u2035\u2035',
  20200. '\u203C': '\u0021\u0021',
  20201. '\u203E': '\u0020\u0305',
  20202. '\u2047': '\u003F\u003F',
  20203. '\u2048': '\u003F\u0021',
  20204. '\u2049': '\u0021\u003F',
  20205. '\u2057': '\u2032\u2032\u2032\u2032',
  20206. '\u205F': '\u0020',
  20207. '\u20A8': '\u0052\u0073',
  20208. '\u2100': '\u0061\u002F\u0063',
  20209. '\u2101': '\u0061\u002F\u0073',
  20210. '\u2103': '\u00B0\u0043',
  20211. '\u2105': '\u0063\u002F\u006F',
  20212. '\u2106': '\u0063\u002F\u0075',
  20213. '\u2107': '\u0190',
  20214. '\u2109': '\u00B0\u0046',
  20215. '\u2116': '\u004E\u006F',
  20216. '\u2121': '\u0054\u0045\u004C',
  20217. '\u2135': '\u05D0',
  20218. '\u2136': '\u05D1',
  20219. '\u2137': '\u05D2',
  20220. '\u2138': '\u05D3',
  20221. '\u213B': '\u0046\u0041\u0058',
  20222. '\u2160': '\u0049',
  20223. '\u2161': '\u0049\u0049',
  20224. '\u2162': '\u0049\u0049\u0049',
  20225. '\u2163': '\u0049\u0056',
  20226. '\u2164': '\u0056',
  20227. '\u2165': '\u0056\u0049',
  20228. '\u2166': '\u0056\u0049\u0049',
  20229. '\u2167': '\u0056\u0049\u0049\u0049',
  20230. '\u2168': '\u0049\u0058',
  20231. '\u2169': '\u0058',
  20232. '\u216A': '\u0058\u0049',
  20233. '\u216B': '\u0058\u0049\u0049',
  20234. '\u216C': '\u004C',
  20235. '\u216D': '\u0043',
  20236. '\u216E': '\u0044',
  20237. '\u216F': '\u004D',
  20238. '\u2170': '\u0069',
  20239. '\u2171': '\u0069\u0069',
  20240. '\u2172': '\u0069\u0069\u0069',
  20241. '\u2173': '\u0069\u0076',
  20242. '\u2174': '\u0076',
  20243. '\u2175': '\u0076\u0069',
  20244. '\u2176': '\u0076\u0069\u0069',
  20245. '\u2177': '\u0076\u0069\u0069\u0069',
  20246. '\u2178': '\u0069\u0078',
  20247. '\u2179': '\u0078',
  20248. '\u217A': '\u0078\u0069',
  20249. '\u217B': '\u0078\u0069\u0069',
  20250. '\u217C': '\u006C',
  20251. '\u217D': '\u0063',
  20252. '\u217E': '\u0064',
  20253. '\u217F': '\u006D',
  20254. '\u222C': '\u222B\u222B',
  20255. '\u222D': '\u222B\u222B\u222B',
  20256. '\u222F': '\u222E\u222E',
  20257. '\u2230': '\u222E\u222E\u222E',
  20258. '\u2474': '\u0028\u0031\u0029',
  20259. '\u2475': '\u0028\u0032\u0029',
  20260. '\u2476': '\u0028\u0033\u0029',
  20261. '\u2477': '\u0028\u0034\u0029',
  20262. '\u2478': '\u0028\u0035\u0029',
  20263. '\u2479': '\u0028\u0036\u0029',
  20264. '\u247A': '\u0028\u0037\u0029',
  20265. '\u247B': '\u0028\u0038\u0029',
  20266. '\u247C': '\u0028\u0039\u0029',
  20267. '\u247D': '\u0028\u0031\u0030\u0029',
  20268. '\u247E': '\u0028\u0031\u0031\u0029',
  20269. '\u247F': '\u0028\u0031\u0032\u0029',
  20270. '\u2480': '\u0028\u0031\u0033\u0029',
  20271. '\u2481': '\u0028\u0031\u0034\u0029',
  20272. '\u2482': '\u0028\u0031\u0035\u0029',
  20273. '\u2483': '\u0028\u0031\u0036\u0029',
  20274. '\u2484': '\u0028\u0031\u0037\u0029',
  20275. '\u2485': '\u0028\u0031\u0038\u0029',
  20276. '\u2486': '\u0028\u0031\u0039\u0029',
  20277. '\u2487': '\u0028\u0032\u0030\u0029',
  20278. '\u2488': '\u0031\u002E',
  20279. '\u2489': '\u0032\u002E',
  20280. '\u248A': '\u0033\u002E',
  20281. '\u248B': '\u0034\u002E',
  20282. '\u248C': '\u0035\u002E',
  20283. '\u248D': '\u0036\u002E',
  20284. '\u248E': '\u0037\u002E',
  20285. '\u248F': '\u0038\u002E',
  20286. '\u2490': '\u0039\u002E',
  20287. '\u2491': '\u0031\u0030\u002E',
  20288. '\u2492': '\u0031\u0031\u002E',
  20289. '\u2493': '\u0031\u0032\u002E',
  20290. '\u2494': '\u0031\u0033\u002E',
  20291. '\u2495': '\u0031\u0034\u002E',
  20292. '\u2496': '\u0031\u0035\u002E',
  20293. '\u2497': '\u0031\u0036\u002E',
  20294. '\u2498': '\u0031\u0037\u002E',
  20295. '\u2499': '\u0031\u0038\u002E',
  20296. '\u249A': '\u0031\u0039\u002E',
  20297. '\u249B': '\u0032\u0030\u002E',
  20298. '\u249C': '\u0028\u0061\u0029',
  20299. '\u249D': '\u0028\u0062\u0029',
  20300. '\u249E': '\u0028\u0063\u0029',
  20301. '\u249F': '\u0028\u0064\u0029',
  20302. '\u24A0': '\u0028\u0065\u0029',
  20303. '\u24A1': '\u0028\u0066\u0029',
  20304. '\u24A2': '\u0028\u0067\u0029',
  20305. '\u24A3': '\u0028\u0068\u0029',
  20306. '\u24A4': '\u0028\u0069\u0029',
  20307. '\u24A5': '\u0028\u006A\u0029',
  20308. '\u24A6': '\u0028\u006B\u0029',
  20309. '\u24A7': '\u0028\u006C\u0029',
  20310. '\u24A8': '\u0028\u006D\u0029',
  20311. '\u24A9': '\u0028\u006E\u0029',
  20312. '\u24AA': '\u0028\u006F\u0029',
  20313. '\u24AB': '\u0028\u0070\u0029',
  20314. '\u24AC': '\u0028\u0071\u0029',
  20315. '\u24AD': '\u0028\u0072\u0029',
  20316. '\u24AE': '\u0028\u0073\u0029',
  20317. '\u24AF': '\u0028\u0074\u0029',
  20318. '\u24B0': '\u0028\u0075\u0029',
  20319. '\u24B1': '\u0028\u0076\u0029',
  20320. '\u24B2': '\u0028\u0077\u0029',
  20321. '\u24B3': '\u0028\u0078\u0029',
  20322. '\u24B4': '\u0028\u0079\u0029',
  20323. '\u24B5': '\u0028\u007A\u0029',
  20324. '\u2A0C': '\u222B\u222B\u222B\u222B',
  20325. '\u2A74': '\u003A\u003A\u003D',
  20326. '\u2A75': '\u003D\u003D',
  20327. '\u2A76': '\u003D\u003D\u003D',
  20328. '\u2E9F': '\u6BCD',
  20329. '\u2EF3': '\u9F9F',
  20330. '\u2F00': '\u4E00',
  20331. '\u2F01': '\u4E28',
  20332. '\u2F02': '\u4E36',
  20333. '\u2F03': '\u4E3F',
  20334. '\u2F04': '\u4E59',
  20335. '\u2F05': '\u4E85',
  20336. '\u2F06': '\u4E8C',
  20337. '\u2F07': '\u4EA0',
  20338. '\u2F08': '\u4EBA',
  20339. '\u2F09': '\u513F',
  20340. '\u2F0A': '\u5165',
  20341. '\u2F0B': '\u516B',
  20342. '\u2F0C': '\u5182',
  20343. '\u2F0D': '\u5196',
  20344. '\u2F0E': '\u51AB',
  20345. '\u2F0F': '\u51E0',
  20346. '\u2F10': '\u51F5',
  20347. '\u2F11': '\u5200',
  20348. '\u2F12': '\u529B',
  20349. '\u2F13': '\u52F9',
  20350. '\u2F14': '\u5315',
  20351. '\u2F15': '\u531A',
  20352. '\u2F16': '\u5338',
  20353. '\u2F17': '\u5341',
  20354. '\u2F18': '\u535C',
  20355. '\u2F19': '\u5369',
  20356. '\u2F1A': '\u5382',
  20357. '\u2F1B': '\u53B6',
  20358. '\u2F1C': '\u53C8',
  20359. '\u2F1D': '\u53E3',
  20360. '\u2F1E': '\u56D7',
  20361. '\u2F1F': '\u571F',
  20362. '\u2F20': '\u58EB',
  20363. '\u2F21': '\u5902',
  20364. '\u2F22': '\u590A',
  20365. '\u2F23': '\u5915',
  20366. '\u2F24': '\u5927',
  20367. '\u2F25': '\u5973',
  20368. '\u2F26': '\u5B50',
  20369. '\u2F27': '\u5B80',
  20370. '\u2F28': '\u5BF8',
  20371. '\u2F29': '\u5C0F',
  20372. '\u2F2A': '\u5C22',
  20373. '\u2F2B': '\u5C38',
  20374. '\u2F2C': '\u5C6E',
  20375. '\u2F2D': '\u5C71',
  20376. '\u2F2E': '\u5DDB',
  20377. '\u2F2F': '\u5DE5',
  20378. '\u2F30': '\u5DF1',
  20379. '\u2F31': '\u5DFE',
  20380. '\u2F32': '\u5E72',
  20381. '\u2F33': '\u5E7A',
  20382. '\u2F34': '\u5E7F',
  20383. '\u2F35': '\u5EF4',
  20384. '\u2F36': '\u5EFE',
  20385. '\u2F37': '\u5F0B',
  20386. '\u2F38': '\u5F13',
  20387. '\u2F39': '\u5F50',
  20388. '\u2F3A': '\u5F61',
  20389. '\u2F3B': '\u5F73',
  20390. '\u2F3C': '\u5FC3',
  20391. '\u2F3D': '\u6208',
  20392. '\u2F3E': '\u6236',
  20393. '\u2F3F': '\u624B',
  20394. '\u2F40': '\u652F',
  20395. '\u2F41': '\u6534',
  20396. '\u2F42': '\u6587',
  20397. '\u2F43': '\u6597',
  20398. '\u2F44': '\u65A4',
  20399. '\u2F45': '\u65B9',
  20400. '\u2F46': '\u65E0',
  20401. '\u2F47': '\u65E5',
  20402. '\u2F48': '\u66F0',
  20403. '\u2F49': '\u6708',
  20404. '\u2F4A': '\u6728',
  20405. '\u2F4B': '\u6B20',
  20406. '\u2F4C': '\u6B62',
  20407. '\u2F4D': '\u6B79',
  20408. '\u2F4E': '\u6BB3',
  20409. '\u2F4F': '\u6BCB',
  20410. '\u2F50': '\u6BD4',
  20411. '\u2F51': '\u6BDB',
  20412. '\u2F52': '\u6C0F',
  20413. '\u2F53': '\u6C14',
  20414. '\u2F54': '\u6C34',
  20415. '\u2F55': '\u706B',
  20416. '\u2F56': '\u722A',
  20417. '\u2F57': '\u7236',
  20418. '\u2F58': '\u723B',
  20419. '\u2F59': '\u723F',
  20420. '\u2F5A': '\u7247',
  20421. '\u2F5B': '\u7259',
  20422. '\u2F5C': '\u725B',
  20423. '\u2F5D': '\u72AC',
  20424. '\u2F5E': '\u7384',
  20425. '\u2F5F': '\u7389',
  20426. '\u2F60': '\u74DC',
  20427. '\u2F61': '\u74E6',
  20428. '\u2F62': '\u7518',
  20429. '\u2F63': '\u751F',
  20430. '\u2F64': '\u7528',
  20431. '\u2F65': '\u7530',
  20432. '\u2F66': '\u758B',
  20433. '\u2F67': '\u7592',
  20434. '\u2F68': '\u7676',
  20435. '\u2F69': '\u767D',
  20436. '\u2F6A': '\u76AE',
  20437. '\u2F6B': '\u76BF',
  20438. '\u2F6C': '\u76EE',
  20439. '\u2F6D': '\u77DB',
  20440. '\u2F6E': '\u77E2',
  20441. '\u2F6F': '\u77F3',
  20442. '\u2F70': '\u793A',
  20443. '\u2F71': '\u79B8',
  20444. '\u2F72': '\u79BE',
  20445. '\u2F73': '\u7A74',
  20446. '\u2F74': '\u7ACB',
  20447. '\u2F75': '\u7AF9',
  20448. '\u2F76': '\u7C73',
  20449. '\u2F77': '\u7CF8',
  20450. '\u2F78': '\u7F36',
  20451. '\u2F79': '\u7F51',
  20452. '\u2F7A': '\u7F8A',
  20453. '\u2F7B': '\u7FBD',
  20454. '\u2F7C': '\u8001',
  20455. '\u2F7D': '\u800C',
  20456. '\u2F7E': '\u8012',
  20457. '\u2F7F': '\u8033',
  20458. '\u2F80': '\u807F',
  20459. '\u2F81': '\u8089',
  20460. '\u2F82': '\u81E3',
  20461. '\u2F83': '\u81EA',
  20462. '\u2F84': '\u81F3',
  20463. '\u2F85': '\u81FC',
  20464. '\u2F86': '\u820C',
  20465. '\u2F87': '\u821B',
  20466. '\u2F88': '\u821F',
  20467. '\u2F89': '\u826E',
  20468. '\u2F8A': '\u8272',
  20469. '\u2F8B': '\u8278',
  20470. '\u2F8C': '\u864D',
  20471. '\u2F8D': '\u866B',
  20472. '\u2F8E': '\u8840',
  20473. '\u2F8F': '\u884C',
  20474. '\u2F90': '\u8863',
  20475. '\u2F91': '\u897E',
  20476. '\u2F92': '\u898B',
  20477. '\u2F93': '\u89D2',
  20478. '\u2F94': '\u8A00',
  20479. '\u2F95': '\u8C37',
  20480. '\u2F96': '\u8C46',
  20481. '\u2F97': '\u8C55',
  20482. '\u2F98': '\u8C78',
  20483. '\u2F99': '\u8C9D',
  20484. '\u2F9A': '\u8D64',
  20485. '\u2F9B': '\u8D70',
  20486. '\u2F9C': '\u8DB3',
  20487. '\u2F9D': '\u8EAB',
  20488. '\u2F9E': '\u8ECA',
  20489. '\u2F9F': '\u8F9B',
  20490. '\u2FA0': '\u8FB0',
  20491. '\u2FA1': '\u8FB5',
  20492. '\u2FA2': '\u9091',
  20493. '\u2FA3': '\u9149',
  20494. '\u2FA4': '\u91C6',
  20495. '\u2FA5': '\u91CC',
  20496. '\u2FA6': '\u91D1',
  20497. '\u2FA7': '\u9577',
  20498. '\u2FA8': '\u9580',
  20499. '\u2FA9': '\u961C',
  20500. '\u2FAA': '\u96B6',
  20501. '\u2FAB': '\u96B9',
  20502. '\u2FAC': '\u96E8',
  20503. '\u2FAD': '\u9751',
  20504. '\u2FAE': '\u975E',
  20505. '\u2FAF': '\u9762',
  20506. '\u2FB0': '\u9769',
  20507. '\u2FB1': '\u97CB',
  20508. '\u2FB2': '\u97ED',
  20509. '\u2FB3': '\u97F3',
  20510. '\u2FB4': '\u9801',
  20511. '\u2FB5': '\u98A8',
  20512. '\u2FB6': '\u98DB',
  20513. '\u2FB7': '\u98DF',
  20514. '\u2FB8': '\u9996',
  20515. '\u2FB9': '\u9999',
  20516. '\u2FBA': '\u99AC',
  20517. '\u2FBB': '\u9AA8',
  20518. '\u2FBC': '\u9AD8',
  20519. '\u2FBD': '\u9ADF',
  20520. '\u2FBE': '\u9B25',
  20521. '\u2FBF': '\u9B2F',
  20522. '\u2FC0': '\u9B32',
  20523. '\u2FC1': '\u9B3C',
  20524. '\u2FC2': '\u9B5A',
  20525. '\u2FC3': '\u9CE5',
  20526. '\u2FC4': '\u9E75',
  20527. '\u2FC5': '\u9E7F',
  20528. '\u2FC6': '\u9EA5',
  20529. '\u2FC7': '\u9EBB',
  20530. '\u2FC8': '\u9EC3',
  20531. '\u2FC9': '\u9ECD',
  20532. '\u2FCA': '\u9ED1',
  20533. '\u2FCB': '\u9EF9',
  20534. '\u2FCC': '\u9EFD',
  20535. '\u2FCD': '\u9F0E',
  20536. '\u2FCE': '\u9F13',
  20537. '\u2FCF': '\u9F20',
  20538. '\u2FD0': '\u9F3B',
  20539. '\u2FD1': '\u9F4A',
  20540. '\u2FD2': '\u9F52',
  20541. '\u2FD3': '\u9F8D',
  20542. '\u2FD4': '\u9F9C',
  20543. '\u2FD5': '\u9FA0',
  20544. '\u3036': '\u3012',
  20545. '\u3038': '\u5341',
  20546. '\u3039': '\u5344',
  20547. '\u303A': '\u5345',
  20548. '\u309B': '\u0020\u3099',
  20549. '\u309C': '\u0020\u309A',
  20550. '\u3131': '\u1100',
  20551. '\u3132': '\u1101',
  20552. '\u3133': '\u11AA',
  20553. '\u3134': '\u1102',
  20554. '\u3135': '\u11AC',
  20555. '\u3136': '\u11AD',
  20556. '\u3137': '\u1103',
  20557. '\u3138': '\u1104',
  20558. '\u3139': '\u1105',
  20559. '\u313A': '\u11B0',
  20560. '\u313B': '\u11B1',
  20561. '\u313C': '\u11B2',
  20562. '\u313D': '\u11B3',
  20563. '\u313E': '\u11B4',
  20564. '\u313F': '\u11B5',
  20565. '\u3140': '\u111A',
  20566. '\u3141': '\u1106',
  20567. '\u3142': '\u1107',
  20568. '\u3143': '\u1108',
  20569. '\u3144': '\u1121',
  20570. '\u3145': '\u1109',
  20571. '\u3146': '\u110A',
  20572. '\u3147': '\u110B',
  20573. '\u3148': '\u110C',
  20574. '\u3149': '\u110D',
  20575. '\u314A': '\u110E',
  20576. '\u314B': '\u110F',
  20577. '\u314C': '\u1110',
  20578. '\u314D': '\u1111',
  20579. '\u314E': '\u1112',
  20580. '\u314F': '\u1161',
  20581. '\u3150': '\u1162',
  20582. '\u3151': '\u1163',
  20583. '\u3152': '\u1164',
  20584. '\u3153': '\u1165',
  20585. '\u3154': '\u1166',
  20586. '\u3155': '\u1167',
  20587. '\u3156': '\u1168',
  20588. '\u3157': '\u1169',
  20589. '\u3158': '\u116A',
  20590. '\u3159': '\u116B',
  20591. '\u315A': '\u116C',
  20592. '\u315B': '\u116D',
  20593. '\u315C': '\u116E',
  20594. '\u315D': '\u116F',
  20595. '\u315E': '\u1170',
  20596. '\u315F': '\u1171',
  20597. '\u3160': '\u1172',
  20598. '\u3161': '\u1173',
  20599. '\u3162': '\u1174',
  20600. '\u3163': '\u1175',
  20601. '\u3164': '\u1160',
  20602. '\u3165': '\u1114',
  20603. '\u3166': '\u1115',
  20604. '\u3167': '\u11C7',
  20605. '\u3168': '\u11C8',
  20606. '\u3169': '\u11CC',
  20607. '\u316A': '\u11CE',
  20608. '\u316B': '\u11D3',
  20609. '\u316C': '\u11D7',
  20610. '\u316D': '\u11D9',
  20611. '\u316E': '\u111C',
  20612. '\u316F': '\u11DD',
  20613. '\u3170': '\u11DF',
  20614. '\u3171': '\u111D',
  20615. '\u3172': '\u111E',
  20616. '\u3173': '\u1120',
  20617. '\u3174': '\u1122',
  20618. '\u3175': '\u1123',
  20619. '\u3176': '\u1127',
  20620. '\u3177': '\u1129',
  20621. '\u3178': '\u112B',
  20622. '\u3179': '\u112C',
  20623. '\u317A': '\u112D',
  20624. '\u317B': '\u112E',
  20625. '\u317C': '\u112F',
  20626. '\u317D': '\u1132',
  20627. '\u317E': '\u1136',
  20628. '\u317F': '\u1140',
  20629. '\u3180': '\u1147',
  20630. '\u3181': '\u114C',
  20631. '\u3182': '\u11F1',
  20632. '\u3183': '\u11F2',
  20633. '\u3184': '\u1157',
  20634. '\u3185': '\u1158',
  20635. '\u3186': '\u1159',
  20636. '\u3187': '\u1184',
  20637. '\u3188': '\u1185',
  20638. '\u3189': '\u1188',
  20639. '\u318A': '\u1191',
  20640. '\u318B': '\u1192',
  20641. '\u318C': '\u1194',
  20642. '\u318D': '\u119E',
  20643. '\u318E': '\u11A1',
  20644. '\u3200': '\u0028\u1100\u0029',
  20645. '\u3201': '\u0028\u1102\u0029',
  20646. '\u3202': '\u0028\u1103\u0029',
  20647. '\u3203': '\u0028\u1105\u0029',
  20648. '\u3204': '\u0028\u1106\u0029',
  20649. '\u3205': '\u0028\u1107\u0029',
  20650. '\u3206': '\u0028\u1109\u0029',
  20651. '\u3207': '\u0028\u110B\u0029',
  20652. '\u3208': '\u0028\u110C\u0029',
  20653. '\u3209': '\u0028\u110E\u0029',
  20654. '\u320A': '\u0028\u110F\u0029',
  20655. '\u320B': '\u0028\u1110\u0029',
  20656. '\u320C': '\u0028\u1111\u0029',
  20657. '\u320D': '\u0028\u1112\u0029',
  20658. '\u320E': '\u0028\u1100\u1161\u0029',
  20659. '\u320F': '\u0028\u1102\u1161\u0029',
  20660. '\u3210': '\u0028\u1103\u1161\u0029',
  20661. '\u3211': '\u0028\u1105\u1161\u0029',
  20662. '\u3212': '\u0028\u1106\u1161\u0029',
  20663. '\u3213': '\u0028\u1107\u1161\u0029',
  20664. '\u3214': '\u0028\u1109\u1161\u0029',
  20665. '\u3215': '\u0028\u110B\u1161\u0029',
  20666. '\u3216': '\u0028\u110C\u1161\u0029',
  20667. '\u3217': '\u0028\u110E\u1161\u0029',
  20668. '\u3218': '\u0028\u110F\u1161\u0029',
  20669. '\u3219': '\u0028\u1110\u1161\u0029',
  20670. '\u321A': '\u0028\u1111\u1161\u0029',
  20671. '\u321B': '\u0028\u1112\u1161\u0029',
  20672. '\u321C': '\u0028\u110C\u116E\u0029',
  20673. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  20674. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  20675. '\u3220': '\u0028\u4E00\u0029',
  20676. '\u3221': '\u0028\u4E8C\u0029',
  20677. '\u3222': '\u0028\u4E09\u0029',
  20678. '\u3223': '\u0028\u56DB\u0029',
  20679. '\u3224': '\u0028\u4E94\u0029',
  20680. '\u3225': '\u0028\u516D\u0029',
  20681. '\u3226': '\u0028\u4E03\u0029',
  20682. '\u3227': '\u0028\u516B\u0029',
  20683. '\u3228': '\u0028\u4E5D\u0029',
  20684. '\u3229': '\u0028\u5341\u0029',
  20685. '\u322A': '\u0028\u6708\u0029',
  20686. '\u322B': '\u0028\u706B\u0029',
  20687. '\u322C': '\u0028\u6C34\u0029',
  20688. '\u322D': '\u0028\u6728\u0029',
  20689. '\u322E': '\u0028\u91D1\u0029',
  20690. '\u322F': '\u0028\u571F\u0029',
  20691. '\u3230': '\u0028\u65E5\u0029',
  20692. '\u3231': '\u0028\u682A\u0029',
  20693. '\u3232': '\u0028\u6709\u0029',
  20694. '\u3233': '\u0028\u793E\u0029',
  20695. '\u3234': '\u0028\u540D\u0029',
  20696. '\u3235': '\u0028\u7279\u0029',
  20697. '\u3236': '\u0028\u8CA1\u0029',
  20698. '\u3237': '\u0028\u795D\u0029',
  20699. '\u3238': '\u0028\u52B4\u0029',
  20700. '\u3239': '\u0028\u4EE3\u0029',
  20701. '\u323A': '\u0028\u547C\u0029',
  20702. '\u323B': '\u0028\u5B66\u0029',
  20703. '\u323C': '\u0028\u76E3\u0029',
  20704. '\u323D': '\u0028\u4F01\u0029',
  20705. '\u323E': '\u0028\u8CC7\u0029',
  20706. '\u323F': '\u0028\u5354\u0029',
  20707. '\u3240': '\u0028\u796D\u0029',
  20708. '\u3241': '\u0028\u4F11\u0029',
  20709. '\u3242': '\u0028\u81EA\u0029',
  20710. '\u3243': '\u0028\u81F3\u0029',
  20711. '\u32C0': '\u0031\u6708',
  20712. '\u32C1': '\u0032\u6708',
  20713. '\u32C2': '\u0033\u6708',
  20714. '\u32C3': '\u0034\u6708',
  20715. '\u32C4': '\u0035\u6708',
  20716. '\u32C5': '\u0036\u6708',
  20717. '\u32C6': '\u0037\u6708',
  20718. '\u32C7': '\u0038\u6708',
  20719. '\u32C8': '\u0039\u6708',
  20720. '\u32C9': '\u0031\u0030\u6708',
  20721. '\u32CA': '\u0031\u0031\u6708',
  20722. '\u32CB': '\u0031\u0032\u6708',
  20723. '\u3358': '\u0030\u70B9',
  20724. '\u3359': '\u0031\u70B9',
  20725. '\u335A': '\u0032\u70B9',
  20726. '\u335B': '\u0033\u70B9',
  20727. '\u335C': '\u0034\u70B9',
  20728. '\u335D': '\u0035\u70B9',
  20729. '\u335E': '\u0036\u70B9',
  20730. '\u335F': '\u0037\u70B9',
  20731. '\u3360': '\u0038\u70B9',
  20732. '\u3361': '\u0039\u70B9',
  20733. '\u3362': '\u0031\u0030\u70B9',
  20734. '\u3363': '\u0031\u0031\u70B9',
  20735. '\u3364': '\u0031\u0032\u70B9',
  20736. '\u3365': '\u0031\u0033\u70B9',
  20737. '\u3366': '\u0031\u0034\u70B9',
  20738. '\u3367': '\u0031\u0035\u70B9',
  20739. '\u3368': '\u0031\u0036\u70B9',
  20740. '\u3369': '\u0031\u0037\u70B9',
  20741. '\u336A': '\u0031\u0038\u70B9',
  20742. '\u336B': '\u0031\u0039\u70B9',
  20743. '\u336C': '\u0032\u0030\u70B9',
  20744. '\u336D': '\u0032\u0031\u70B9',
  20745. '\u336E': '\u0032\u0032\u70B9',
  20746. '\u336F': '\u0032\u0033\u70B9',
  20747. '\u3370': '\u0032\u0034\u70B9',
  20748. '\u33E0': '\u0031\u65E5',
  20749. '\u33E1': '\u0032\u65E5',
  20750. '\u33E2': '\u0033\u65E5',
  20751. '\u33E3': '\u0034\u65E5',
  20752. '\u33E4': '\u0035\u65E5',
  20753. '\u33E5': '\u0036\u65E5',
  20754. '\u33E6': '\u0037\u65E5',
  20755. '\u33E7': '\u0038\u65E5',
  20756. '\u33E8': '\u0039\u65E5',
  20757. '\u33E9': '\u0031\u0030\u65E5',
  20758. '\u33EA': '\u0031\u0031\u65E5',
  20759. '\u33EB': '\u0031\u0032\u65E5',
  20760. '\u33EC': '\u0031\u0033\u65E5',
  20761. '\u33ED': '\u0031\u0034\u65E5',
  20762. '\u33EE': '\u0031\u0035\u65E5',
  20763. '\u33EF': '\u0031\u0036\u65E5',
  20764. '\u33F0': '\u0031\u0037\u65E5',
  20765. '\u33F1': '\u0031\u0038\u65E5',
  20766. '\u33F2': '\u0031\u0039\u65E5',
  20767. '\u33F3': '\u0032\u0030\u65E5',
  20768. '\u33F4': '\u0032\u0031\u65E5',
  20769. '\u33F5': '\u0032\u0032\u65E5',
  20770. '\u33F6': '\u0032\u0033\u65E5',
  20771. '\u33F7': '\u0032\u0034\u65E5',
  20772. '\u33F8': '\u0032\u0035\u65E5',
  20773. '\u33F9': '\u0032\u0036\u65E5',
  20774. '\u33FA': '\u0032\u0037\u65E5',
  20775. '\u33FB': '\u0032\u0038\u65E5',
  20776. '\u33FC': '\u0032\u0039\u65E5',
  20777. '\u33FD': '\u0033\u0030\u65E5',
  20778. '\u33FE': '\u0033\u0031\u65E5',
  20779. '\uFB00': '\u0066\u0066',
  20780. '\uFB01': '\u0066\u0069',
  20781. '\uFB02': '\u0066\u006C',
  20782. '\uFB03': '\u0066\u0066\u0069',
  20783. '\uFB04': '\u0066\u0066\u006C',
  20784. '\uFB05': '\u017F\u0074',
  20785. '\uFB06': '\u0073\u0074',
  20786. '\uFB13': '\u0574\u0576',
  20787. '\uFB14': '\u0574\u0565',
  20788. '\uFB15': '\u0574\u056B',
  20789. '\uFB16': '\u057E\u0576',
  20790. '\uFB17': '\u0574\u056D',
  20791. '\uFB4F': '\u05D0\u05DC',
  20792. '\uFB50': '\u0671',
  20793. '\uFB51': '\u0671',
  20794. '\uFB52': '\u067B',
  20795. '\uFB53': '\u067B',
  20796. '\uFB54': '\u067B',
  20797. '\uFB55': '\u067B',
  20798. '\uFB56': '\u067E',
  20799. '\uFB57': '\u067E',
  20800. '\uFB58': '\u067E',
  20801. '\uFB59': '\u067E',
  20802. '\uFB5A': '\u0680',
  20803. '\uFB5B': '\u0680',
  20804. '\uFB5C': '\u0680',
  20805. '\uFB5D': '\u0680',
  20806. '\uFB5E': '\u067A',
  20807. '\uFB5F': '\u067A',
  20808. '\uFB60': '\u067A',
  20809. '\uFB61': '\u067A',
  20810. '\uFB62': '\u067F',
  20811. '\uFB63': '\u067F',
  20812. '\uFB64': '\u067F',
  20813. '\uFB65': '\u067F',
  20814. '\uFB66': '\u0679',
  20815. '\uFB67': '\u0679',
  20816. '\uFB68': '\u0679',
  20817. '\uFB69': '\u0679',
  20818. '\uFB6A': '\u06A4',
  20819. '\uFB6B': '\u06A4',
  20820. '\uFB6C': '\u06A4',
  20821. '\uFB6D': '\u06A4',
  20822. '\uFB6E': '\u06A6',
  20823. '\uFB6F': '\u06A6',
  20824. '\uFB70': '\u06A6',
  20825. '\uFB71': '\u06A6',
  20826. '\uFB72': '\u0684',
  20827. '\uFB73': '\u0684',
  20828. '\uFB74': '\u0684',
  20829. '\uFB75': '\u0684',
  20830. '\uFB76': '\u0683',
  20831. '\uFB77': '\u0683',
  20832. '\uFB78': '\u0683',
  20833. '\uFB79': '\u0683',
  20834. '\uFB7A': '\u0686',
  20835. '\uFB7B': '\u0686',
  20836. '\uFB7C': '\u0686',
  20837. '\uFB7D': '\u0686',
  20838. '\uFB7E': '\u0687',
  20839. '\uFB7F': '\u0687',
  20840. '\uFB80': '\u0687',
  20841. '\uFB81': '\u0687',
  20842. '\uFB82': '\u068D',
  20843. '\uFB83': '\u068D',
  20844. '\uFB84': '\u068C',
  20845. '\uFB85': '\u068C',
  20846. '\uFB86': '\u068E',
  20847. '\uFB87': '\u068E',
  20848. '\uFB88': '\u0688',
  20849. '\uFB89': '\u0688',
  20850. '\uFB8A': '\u0698',
  20851. '\uFB8B': '\u0698',
  20852. '\uFB8C': '\u0691',
  20853. '\uFB8D': '\u0691',
  20854. '\uFB8E': '\u06A9',
  20855. '\uFB8F': '\u06A9',
  20856. '\uFB90': '\u06A9',
  20857. '\uFB91': '\u06A9',
  20858. '\uFB92': '\u06AF',
  20859. '\uFB93': '\u06AF',
  20860. '\uFB94': '\u06AF',
  20861. '\uFB95': '\u06AF',
  20862. '\uFB96': '\u06B3',
  20863. '\uFB97': '\u06B3',
  20864. '\uFB98': '\u06B3',
  20865. '\uFB99': '\u06B3',
  20866. '\uFB9A': '\u06B1',
  20867. '\uFB9B': '\u06B1',
  20868. '\uFB9C': '\u06B1',
  20869. '\uFB9D': '\u06B1',
  20870. '\uFB9E': '\u06BA',
  20871. '\uFB9F': '\u06BA',
  20872. '\uFBA0': '\u06BB',
  20873. '\uFBA1': '\u06BB',
  20874. '\uFBA2': '\u06BB',
  20875. '\uFBA3': '\u06BB',
  20876. '\uFBA4': '\u06C0',
  20877. '\uFBA5': '\u06C0',
  20878. '\uFBA6': '\u06C1',
  20879. '\uFBA7': '\u06C1',
  20880. '\uFBA8': '\u06C1',
  20881. '\uFBA9': '\u06C1',
  20882. '\uFBAA': '\u06BE',
  20883. '\uFBAB': '\u06BE',
  20884. '\uFBAC': '\u06BE',
  20885. '\uFBAD': '\u06BE',
  20886. '\uFBAE': '\u06D2',
  20887. '\uFBAF': '\u06D2',
  20888. '\uFBB0': '\u06D3',
  20889. '\uFBB1': '\u06D3',
  20890. '\uFBD3': '\u06AD',
  20891. '\uFBD4': '\u06AD',
  20892. '\uFBD5': '\u06AD',
  20893. '\uFBD6': '\u06AD',
  20894. '\uFBD7': '\u06C7',
  20895. '\uFBD8': '\u06C7',
  20896. '\uFBD9': '\u06C6',
  20897. '\uFBDA': '\u06C6',
  20898. '\uFBDB': '\u06C8',
  20899. '\uFBDC': '\u06C8',
  20900. '\uFBDD': '\u0677',
  20901. '\uFBDE': '\u06CB',
  20902. '\uFBDF': '\u06CB',
  20903. '\uFBE0': '\u06C5',
  20904. '\uFBE1': '\u06C5',
  20905. '\uFBE2': '\u06C9',
  20906. '\uFBE3': '\u06C9',
  20907. '\uFBE4': '\u06D0',
  20908. '\uFBE5': '\u06D0',
  20909. '\uFBE6': '\u06D0',
  20910. '\uFBE7': '\u06D0',
  20911. '\uFBE8': '\u0649',
  20912. '\uFBE9': '\u0649',
  20913. '\uFBEA': '\u0626\u0627',
  20914. '\uFBEB': '\u0626\u0627',
  20915. '\uFBEC': '\u0626\u06D5',
  20916. '\uFBED': '\u0626\u06D5',
  20917. '\uFBEE': '\u0626\u0648',
  20918. '\uFBEF': '\u0626\u0648',
  20919. '\uFBF0': '\u0626\u06C7',
  20920. '\uFBF1': '\u0626\u06C7',
  20921. '\uFBF2': '\u0626\u06C6',
  20922. '\uFBF3': '\u0626\u06C6',
  20923. '\uFBF4': '\u0626\u06C8',
  20924. '\uFBF5': '\u0626\u06C8',
  20925. '\uFBF6': '\u0626\u06D0',
  20926. '\uFBF7': '\u0626\u06D0',
  20927. '\uFBF8': '\u0626\u06D0',
  20928. '\uFBF9': '\u0626\u0649',
  20929. '\uFBFA': '\u0626\u0649',
  20930. '\uFBFB': '\u0626\u0649',
  20931. '\uFBFC': '\u06CC',
  20932. '\uFBFD': '\u06CC',
  20933. '\uFBFE': '\u06CC',
  20934. '\uFBFF': '\u06CC',
  20935. '\uFC00': '\u0626\u062C',
  20936. '\uFC01': '\u0626\u062D',
  20937. '\uFC02': '\u0626\u0645',
  20938. '\uFC03': '\u0626\u0649',
  20939. '\uFC04': '\u0626\u064A',
  20940. '\uFC05': '\u0628\u062C',
  20941. '\uFC06': '\u0628\u062D',
  20942. '\uFC07': '\u0628\u062E',
  20943. '\uFC08': '\u0628\u0645',
  20944. '\uFC09': '\u0628\u0649',
  20945. '\uFC0A': '\u0628\u064A',
  20946. '\uFC0B': '\u062A\u062C',
  20947. '\uFC0C': '\u062A\u062D',
  20948. '\uFC0D': '\u062A\u062E',
  20949. '\uFC0E': '\u062A\u0645',
  20950. '\uFC0F': '\u062A\u0649',
  20951. '\uFC10': '\u062A\u064A',
  20952. '\uFC11': '\u062B\u062C',
  20953. '\uFC12': '\u062B\u0645',
  20954. '\uFC13': '\u062B\u0649',
  20955. '\uFC14': '\u062B\u064A',
  20956. '\uFC15': '\u062C\u062D',
  20957. '\uFC16': '\u062C\u0645',
  20958. '\uFC17': '\u062D\u062C',
  20959. '\uFC18': '\u062D\u0645',
  20960. '\uFC19': '\u062E\u062C',
  20961. '\uFC1A': '\u062E\u062D',
  20962. '\uFC1B': '\u062E\u0645',
  20963. '\uFC1C': '\u0633\u062C',
  20964. '\uFC1D': '\u0633\u062D',
  20965. '\uFC1E': '\u0633\u062E',
  20966. '\uFC1F': '\u0633\u0645',
  20967. '\uFC20': '\u0635\u062D',
  20968. '\uFC21': '\u0635\u0645',
  20969. '\uFC22': '\u0636\u062C',
  20970. '\uFC23': '\u0636\u062D',
  20971. '\uFC24': '\u0636\u062E',
  20972. '\uFC25': '\u0636\u0645',
  20973. '\uFC26': '\u0637\u062D',
  20974. '\uFC27': '\u0637\u0645',
  20975. '\uFC28': '\u0638\u0645',
  20976. '\uFC29': '\u0639\u062C',
  20977. '\uFC2A': '\u0639\u0645',
  20978. '\uFC2B': '\u063A\u062C',
  20979. '\uFC2C': '\u063A\u0645',
  20980. '\uFC2D': '\u0641\u062C',
  20981. '\uFC2E': '\u0641\u062D',
  20982. '\uFC2F': '\u0641\u062E',
  20983. '\uFC30': '\u0641\u0645',
  20984. '\uFC31': '\u0641\u0649',
  20985. '\uFC32': '\u0641\u064A',
  20986. '\uFC33': '\u0642\u062D',
  20987. '\uFC34': '\u0642\u0645',
  20988. '\uFC35': '\u0642\u0649',
  20989. '\uFC36': '\u0642\u064A',
  20990. '\uFC37': '\u0643\u0627',
  20991. '\uFC38': '\u0643\u062C',
  20992. '\uFC39': '\u0643\u062D',
  20993. '\uFC3A': '\u0643\u062E',
  20994. '\uFC3B': '\u0643\u0644',
  20995. '\uFC3C': '\u0643\u0645',
  20996. '\uFC3D': '\u0643\u0649',
  20997. '\uFC3E': '\u0643\u064A',
  20998. '\uFC3F': '\u0644\u062C',
  20999. '\uFC40': '\u0644\u062D',
  21000. '\uFC41': '\u0644\u062E',
  21001. '\uFC42': '\u0644\u0645',
  21002. '\uFC43': '\u0644\u0649',
  21003. '\uFC44': '\u0644\u064A',
  21004. '\uFC45': '\u0645\u062C',
  21005. '\uFC46': '\u0645\u062D',
  21006. '\uFC47': '\u0645\u062E',
  21007. '\uFC48': '\u0645\u0645',
  21008. '\uFC49': '\u0645\u0649',
  21009. '\uFC4A': '\u0645\u064A',
  21010. '\uFC4B': '\u0646\u062C',
  21011. '\uFC4C': '\u0646\u062D',
  21012. '\uFC4D': '\u0646\u062E',
  21013. '\uFC4E': '\u0646\u0645',
  21014. '\uFC4F': '\u0646\u0649',
  21015. '\uFC50': '\u0646\u064A',
  21016. '\uFC51': '\u0647\u062C',
  21017. '\uFC52': '\u0647\u0645',
  21018. '\uFC53': '\u0647\u0649',
  21019. '\uFC54': '\u0647\u064A',
  21020. '\uFC55': '\u064A\u062C',
  21021. '\uFC56': '\u064A\u062D',
  21022. '\uFC57': '\u064A\u062E',
  21023. '\uFC58': '\u064A\u0645',
  21024. '\uFC59': '\u064A\u0649',
  21025. '\uFC5A': '\u064A\u064A',
  21026. '\uFC5B': '\u0630\u0670',
  21027. '\uFC5C': '\u0631\u0670',
  21028. '\uFC5D': '\u0649\u0670',
  21029. '\uFC5E': '\u0020\u064C\u0651',
  21030. '\uFC5F': '\u0020\u064D\u0651',
  21031. '\uFC60': '\u0020\u064E\u0651',
  21032. '\uFC61': '\u0020\u064F\u0651',
  21033. '\uFC62': '\u0020\u0650\u0651',
  21034. '\uFC63': '\u0020\u0651\u0670',
  21035. '\uFC64': '\u0626\u0631',
  21036. '\uFC65': '\u0626\u0632',
  21037. '\uFC66': '\u0626\u0645',
  21038. '\uFC67': '\u0626\u0646',
  21039. '\uFC68': '\u0626\u0649',
  21040. '\uFC69': '\u0626\u064A',
  21041. '\uFC6A': '\u0628\u0631',
  21042. '\uFC6B': '\u0628\u0632',
  21043. '\uFC6C': '\u0628\u0645',
  21044. '\uFC6D': '\u0628\u0646',
  21045. '\uFC6E': '\u0628\u0649',
  21046. '\uFC6F': '\u0628\u064A',
  21047. '\uFC70': '\u062A\u0631',
  21048. '\uFC71': '\u062A\u0632',
  21049. '\uFC72': '\u062A\u0645',
  21050. '\uFC73': '\u062A\u0646',
  21051. '\uFC74': '\u062A\u0649',
  21052. '\uFC75': '\u062A\u064A',
  21053. '\uFC76': '\u062B\u0631',
  21054. '\uFC77': '\u062B\u0632',
  21055. '\uFC78': '\u062B\u0645',
  21056. '\uFC79': '\u062B\u0646',
  21057. '\uFC7A': '\u062B\u0649',
  21058. '\uFC7B': '\u062B\u064A',
  21059. '\uFC7C': '\u0641\u0649',
  21060. '\uFC7D': '\u0641\u064A',
  21061. '\uFC7E': '\u0642\u0649',
  21062. '\uFC7F': '\u0642\u064A',
  21063. '\uFC80': '\u0643\u0627',
  21064. '\uFC81': '\u0643\u0644',
  21065. '\uFC82': '\u0643\u0645',
  21066. '\uFC83': '\u0643\u0649',
  21067. '\uFC84': '\u0643\u064A',
  21068. '\uFC85': '\u0644\u0645',
  21069. '\uFC86': '\u0644\u0649',
  21070. '\uFC87': '\u0644\u064A',
  21071. '\uFC88': '\u0645\u0627',
  21072. '\uFC89': '\u0645\u0645',
  21073. '\uFC8A': '\u0646\u0631',
  21074. '\uFC8B': '\u0646\u0632',
  21075. '\uFC8C': '\u0646\u0645',
  21076. '\uFC8D': '\u0646\u0646',
  21077. '\uFC8E': '\u0646\u0649',
  21078. '\uFC8F': '\u0646\u064A',
  21079. '\uFC90': '\u0649\u0670',
  21080. '\uFC91': '\u064A\u0631',
  21081. '\uFC92': '\u064A\u0632',
  21082. '\uFC93': '\u064A\u0645',
  21083. '\uFC94': '\u064A\u0646',
  21084. '\uFC95': '\u064A\u0649',
  21085. '\uFC96': '\u064A\u064A',
  21086. '\uFC97': '\u0626\u062C',
  21087. '\uFC98': '\u0626\u062D',
  21088. '\uFC99': '\u0626\u062E',
  21089. '\uFC9A': '\u0626\u0645',
  21090. '\uFC9B': '\u0626\u0647',
  21091. '\uFC9C': '\u0628\u062C',
  21092. '\uFC9D': '\u0628\u062D',
  21093. '\uFC9E': '\u0628\u062E',
  21094. '\uFC9F': '\u0628\u0645',
  21095. '\uFCA0': '\u0628\u0647',
  21096. '\uFCA1': '\u062A\u062C',
  21097. '\uFCA2': '\u062A\u062D',
  21098. '\uFCA3': '\u062A\u062E',
  21099. '\uFCA4': '\u062A\u0645',
  21100. '\uFCA5': '\u062A\u0647',
  21101. '\uFCA6': '\u062B\u0645',
  21102. '\uFCA7': '\u062C\u062D',
  21103. '\uFCA8': '\u062C\u0645',
  21104. '\uFCA9': '\u062D\u062C',
  21105. '\uFCAA': '\u062D\u0645',
  21106. '\uFCAB': '\u062E\u062C',
  21107. '\uFCAC': '\u062E\u0645',
  21108. '\uFCAD': '\u0633\u062C',
  21109. '\uFCAE': '\u0633\u062D',
  21110. '\uFCAF': '\u0633\u062E',
  21111. '\uFCB0': '\u0633\u0645',
  21112. '\uFCB1': '\u0635\u062D',
  21113. '\uFCB2': '\u0635\u062E',
  21114. '\uFCB3': '\u0635\u0645',
  21115. '\uFCB4': '\u0636\u062C',
  21116. '\uFCB5': '\u0636\u062D',
  21117. '\uFCB6': '\u0636\u062E',
  21118. '\uFCB7': '\u0636\u0645',
  21119. '\uFCB8': '\u0637\u062D',
  21120. '\uFCB9': '\u0638\u0645',
  21121. '\uFCBA': '\u0639\u062C',
  21122. '\uFCBB': '\u0639\u0645',
  21123. '\uFCBC': '\u063A\u062C',
  21124. '\uFCBD': '\u063A\u0645',
  21125. '\uFCBE': '\u0641\u062C',
  21126. '\uFCBF': '\u0641\u062D',
  21127. '\uFCC0': '\u0641\u062E',
  21128. '\uFCC1': '\u0641\u0645',
  21129. '\uFCC2': '\u0642\u062D',
  21130. '\uFCC3': '\u0642\u0645',
  21131. '\uFCC4': '\u0643\u062C',
  21132. '\uFCC5': '\u0643\u062D',
  21133. '\uFCC6': '\u0643\u062E',
  21134. '\uFCC7': '\u0643\u0644',
  21135. '\uFCC8': '\u0643\u0645',
  21136. '\uFCC9': '\u0644\u062C',
  21137. '\uFCCA': '\u0644\u062D',
  21138. '\uFCCB': '\u0644\u062E',
  21139. '\uFCCC': '\u0644\u0645',
  21140. '\uFCCD': '\u0644\u0647',
  21141. '\uFCCE': '\u0645\u062C',
  21142. '\uFCCF': '\u0645\u062D',
  21143. '\uFCD0': '\u0645\u062E',
  21144. '\uFCD1': '\u0645\u0645',
  21145. '\uFCD2': '\u0646\u062C',
  21146. '\uFCD3': '\u0646\u062D',
  21147. '\uFCD4': '\u0646\u062E',
  21148. '\uFCD5': '\u0646\u0645',
  21149. '\uFCD6': '\u0646\u0647',
  21150. '\uFCD7': '\u0647\u062C',
  21151. '\uFCD8': '\u0647\u0645',
  21152. '\uFCD9': '\u0647\u0670',
  21153. '\uFCDA': '\u064A\u062C',
  21154. '\uFCDB': '\u064A\u062D',
  21155. '\uFCDC': '\u064A\u062E',
  21156. '\uFCDD': '\u064A\u0645',
  21157. '\uFCDE': '\u064A\u0647',
  21158. '\uFCDF': '\u0626\u0645',
  21159. '\uFCE0': '\u0626\u0647',
  21160. '\uFCE1': '\u0628\u0645',
  21161. '\uFCE2': '\u0628\u0647',
  21162. '\uFCE3': '\u062A\u0645',
  21163. '\uFCE4': '\u062A\u0647',
  21164. '\uFCE5': '\u062B\u0645',
  21165. '\uFCE6': '\u062B\u0647',
  21166. '\uFCE7': '\u0633\u0645',
  21167. '\uFCE8': '\u0633\u0647',
  21168. '\uFCE9': '\u0634\u0645',
  21169. '\uFCEA': '\u0634\u0647',
  21170. '\uFCEB': '\u0643\u0644',
  21171. '\uFCEC': '\u0643\u0645',
  21172. '\uFCED': '\u0644\u0645',
  21173. '\uFCEE': '\u0646\u0645',
  21174. '\uFCEF': '\u0646\u0647',
  21175. '\uFCF0': '\u064A\u0645',
  21176. '\uFCF1': '\u064A\u0647',
  21177. '\uFCF2': '\u0640\u064E\u0651',
  21178. '\uFCF3': '\u0640\u064F\u0651',
  21179. '\uFCF4': '\u0640\u0650\u0651',
  21180. '\uFCF5': '\u0637\u0649',
  21181. '\uFCF6': '\u0637\u064A',
  21182. '\uFCF7': '\u0639\u0649',
  21183. '\uFCF8': '\u0639\u064A',
  21184. '\uFCF9': '\u063A\u0649',
  21185. '\uFCFA': '\u063A\u064A',
  21186. '\uFCFB': '\u0633\u0649',
  21187. '\uFCFC': '\u0633\u064A',
  21188. '\uFCFD': '\u0634\u0649',
  21189. '\uFCFE': '\u0634\u064A',
  21190. '\uFCFF': '\u062D\u0649',
  21191. '\uFD00': '\u062D\u064A',
  21192. '\uFD01': '\u062C\u0649',
  21193. '\uFD02': '\u062C\u064A',
  21194. '\uFD03': '\u062E\u0649',
  21195. '\uFD04': '\u062E\u064A',
  21196. '\uFD05': '\u0635\u0649',
  21197. '\uFD06': '\u0635\u064A',
  21198. '\uFD07': '\u0636\u0649',
  21199. '\uFD08': '\u0636\u064A',
  21200. '\uFD09': '\u0634\u062C',
  21201. '\uFD0A': '\u0634\u062D',
  21202. '\uFD0B': '\u0634\u062E',
  21203. '\uFD0C': '\u0634\u0645',
  21204. '\uFD0D': '\u0634\u0631',
  21205. '\uFD0E': '\u0633\u0631',
  21206. '\uFD0F': '\u0635\u0631',
  21207. '\uFD10': '\u0636\u0631',
  21208. '\uFD11': '\u0637\u0649',
  21209. '\uFD12': '\u0637\u064A',
  21210. '\uFD13': '\u0639\u0649',
  21211. '\uFD14': '\u0639\u064A',
  21212. '\uFD15': '\u063A\u0649',
  21213. '\uFD16': '\u063A\u064A',
  21214. '\uFD17': '\u0633\u0649',
  21215. '\uFD18': '\u0633\u064A',
  21216. '\uFD19': '\u0634\u0649',
  21217. '\uFD1A': '\u0634\u064A',
  21218. '\uFD1B': '\u062D\u0649',
  21219. '\uFD1C': '\u062D\u064A',
  21220. '\uFD1D': '\u062C\u0649',
  21221. '\uFD1E': '\u062C\u064A',
  21222. '\uFD1F': '\u062E\u0649',
  21223. '\uFD20': '\u062E\u064A',
  21224. '\uFD21': '\u0635\u0649',
  21225. '\uFD22': '\u0635\u064A',
  21226. '\uFD23': '\u0636\u0649',
  21227. '\uFD24': '\u0636\u064A',
  21228. '\uFD25': '\u0634\u062C',
  21229. '\uFD26': '\u0634\u062D',
  21230. '\uFD27': '\u0634\u062E',
  21231. '\uFD28': '\u0634\u0645',
  21232. '\uFD29': '\u0634\u0631',
  21233. '\uFD2A': '\u0633\u0631',
  21234. '\uFD2B': '\u0635\u0631',
  21235. '\uFD2C': '\u0636\u0631',
  21236. '\uFD2D': '\u0634\u062C',
  21237. '\uFD2E': '\u0634\u062D',
  21238. '\uFD2F': '\u0634\u062E',
  21239. '\uFD30': '\u0634\u0645',
  21240. '\uFD31': '\u0633\u0647',
  21241. '\uFD32': '\u0634\u0647',
  21242. '\uFD33': '\u0637\u0645',
  21243. '\uFD34': '\u0633\u062C',
  21244. '\uFD35': '\u0633\u062D',
  21245. '\uFD36': '\u0633\u062E',
  21246. '\uFD37': '\u0634\u062C',
  21247. '\uFD38': '\u0634\u062D',
  21248. '\uFD39': '\u0634\u062E',
  21249. '\uFD3A': '\u0637\u0645',
  21250. '\uFD3B': '\u0638\u0645',
  21251. '\uFD3C': '\u0627\u064B',
  21252. '\uFD3D': '\u0627\u064B',
  21253. '\uFD50': '\u062A\u062C\u0645',
  21254. '\uFD51': '\u062A\u062D\u062C',
  21255. '\uFD52': '\u062A\u062D\u062C',
  21256. '\uFD53': '\u062A\u062D\u0645',
  21257. '\uFD54': '\u062A\u062E\u0645',
  21258. '\uFD55': '\u062A\u0645\u062C',
  21259. '\uFD56': '\u062A\u0645\u062D',
  21260. '\uFD57': '\u062A\u0645\u062E',
  21261. '\uFD58': '\u062C\u0645\u062D',
  21262. '\uFD59': '\u062C\u0645\u062D',
  21263. '\uFD5A': '\u062D\u0645\u064A',
  21264. '\uFD5B': '\u062D\u0645\u0649',
  21265. '\uFD5C': '\u0633\u062D\u062C',
  21266. '\uFD5D': '\u0633\u062C\u062D',
  21267. '\uFD5E': '\u0633\u062C\u0649',
  21268. '\uFD5F': '\u0633\u0645\u062D',
  21269. '\uFD60': '\u0633\u0645\u062D',
  21270. '\uFD61': '\u0633\u0645\u062C',
  21271. '\uFD62': '\u0633\u0645\u0645',
  21272. '\uFD63': '\u0633\u0645\u0645',
  21273. '\uFD64': '\u0635\u062D\u062D',
  21274. '\uFD65': '\u0635\u062D\u062D',
  21275. '\uFD66': '\u0635\u0645\u0645',
  21276. '\uFD67': '\u0634\u062D\u0645',
  21277. '\uFD68': '\u0634\u062D\u0645',
  21278. '\uFD69': '\u0634\u062C\u064A',
  21279. '\uFD6A': '\u0634\u0645\u062E',
  21280. '\uFD6B': '\u0634\u0645\u062E',
  21281. '\uFD6C': '\u0634\u0645\u0645',
  21282. '\uFD6D': '\u0634\u0645\u0645',
  21283. '\uFD6E': '\u0636\u062D\u0649',
  21284. '\uFD6F': '\u0636\u062E\u0645',
  21285. '\uFD70': '\u0636\u062E\u0645',
  21286. '\uFD71': '\u0637\u0645\u062D',
  21287. '\uFD72': '\u0637\u0645\u062D',
  21288. '\uFD73': '\u0637\u0645\u0645',
  21289. '\uFD74': '\u0637\u0645\u064A',
  21290. '\uFD75': '\u0639\u062C\u0645',
  21291. '\uFD76': '\u0639\u0645\u0645',
  21292. '\uFD77': '\u0639\u0645\u0645',
  21293. '\uFD78': '\u0639\u0645\u0649',
  21294. '\uFD79': '\u063A\u0645\u0645',
  21295. '\uFD7A': '\u063A\u0645\u064A',
  21296. '\uFD7B': '\u063A\u0645\u0649',
  21297. '\uFD7C': '\u0641\u062E\u0645',
  21298. '\uFD7D': '\u0641\u062E\u0645',
  21299. '\uFD7E': '\u0642\u0645\u062D',
  21300. '\uFD7F': '\u0642\u0645\u0645',
  21301. '\uFD80': '\u0644\u062D\u0645',
  21302. '\uFD81': '\u0644\u062D\u064A',
  21303. '\uFD82': '\u0644\u062D\u0649',
  21304. '\uFD83': '\u0644\u062C\u062C',
  21305. '\uFD84': '\u0644\u062C\u062C',
  21306. '\uFD85': '\u0644\u062E\u0645',
  21307. '\uFD86': '\u0644\u062E\u0645',
  21308. '\uFD87': '\u0644\u0645\u062D',
  21309. '\uFD88': '\u0644\u0645\u062D',
  21310. '\uFD89': '\u0645\u062D\u062C',
  21311. '\uFD8A': '\u0645\u062D\u0645',
  21312. '\uFD8B': '\u0645\u062D\u064A',
  21313. '\uFD8C': '\u0645\u062C\u062D',
  21314. '\uFD8D': '\u0645\u062C\u0645',
  21315. '\uFD8E': '\u0645\u062E\u062C',
  21316. '\uFD8F': '\u0645\u062E\u0645',
  21317. '\uFD92': '\u0645\u062C\u062E',
  21318. '\uFD93': '\u0647\u0645\u062C',
  21319. '\uFD94': '\u0647\u0645\u0645',
  21320. '\uFD95': '\u0646\u062D\u0645',
  21321. '\uFD96': '\u0646\u062D\u0649',
  21322. '\uFD97': '\u0646\u062C\u0645',
  21323. '\uFD98': '\u0646\u062C\u0645',
  21324. '\uFD99': '\u0646\u062C\u0649',
  21325. '\uFD9A': '\u0646\u0645\u064A',
  21326. '\uFD9B': '\u0646\u0645\u0649',
  21327. '\uFD9C': '\u064A\u0645\u0645',
  21328. '\uFD9D': '\u064A\u0645\u0645',
  21329. '\uFD9E': '\u0628\u062E\u064A',
  21330. '\uFD9F': '\u062A\u062C\u064A',
  21331. '\uFDA0': '\u062A\u062C\u0649',
  21332. '\uFDA1': '\u062A\u062E\u064A',
  21333. '\uFDA2': '\u062A\u062E\u0649',
  21334. '\uFDA3': '\u062A\u0645\u064A',
  21335. '\uFDA4': '\u062A\u0645\u0649',
  21336. '\uFDA5': '\u062C\u0645\u064A',
  21337. '\uFDA6': '\u062C\u062D\u0649',
  21338. '\uFDA7': '\u062C\u0645\u0649',
  21339. '\uFDA8': '\u0633\u062E\u0649',
  21340. '\uFDA9': '\u0635\u062D\u064A',
  21341. '\uFDAA': '\u0634\u062D\u064A',
  21342. '\uFDAB': '\u0636\u062D\u064A',
  21343. '\uFDAC': '\u0644\u062C\u064A',
  21344. '\uFDAD': '\u0644\u0645\u064A',
  21345. '\uFDAE': '\u064A\u062D\u064A',
  21346. '\uFDAF': '\u064A\u062C\u064A',
  21347. '\uFDB0': '\u064A\u0645\u064A',
  21348. '\uFDB1': '\u0645\u0645\u064A',
  21349. '\uFDB2': '\u0642\u0645\u064A',
  21350. '\uFDB3': '\u0646\u062D\u064A',
  21351. '\uFDB4': '\u0642\u0645\u062D',
  21352. '\uFDB5': '\u0644\u062D\u0645',
  21353. '\uFDB6': '\u0639\u0645\u064A',
  21354. '\uFDB7': '\u0643\u0645\u064A',
  21355. '\uFDB8': '\u0646\u062C\u062D',
  21356. '\uFDB9': '\u0645\u062E\u064A',
  21357. '\uFDBA': '\u0644\u062C\u0645',
  21358. '\uFDBB': '\u0643\u0645\u0645',
  21359. '\uFDBC': '\u0644\u062C\u0645',
  21360. '\uFDBD': '\u0646\u062C\u062D',
  21361. '\uFDBE': '\u062C\u062D\u064A',
  21362. '\uFDBF': '\u062D\u062C\u064A',
  21363. '\uFDC0': '\u0645\u062C\u064A',
  21364. '\uFDC1': '\u0641\u0645\u064A',
  21365. '\uFDC2': '\u0628\u062D\u064A',
  21366. '\uFDC3': '\u0643\u0645\u0645',
  21367. '\uFDC4': '\u0639\u062C\u0645',
  21368. '\uFDC5': '\u0635\u0645\u0645',
  21369. '\uFDC6': '\u0633\u062E\u064A',
  21370. '\uFDC7': '\u0646\u062C\u064A',
  21371. '\uFE49': '\u203E',
  21372. '\uFE4A': '\u203E',
  21373. '\uFE4B': '\u203E',
  21374. '\uFE4C': '\u203E',
  21375. '\uFE4D': '\u005F',
  21376. '\uFE4E': '\u005F',
  21377. '\uFE4F': '\u005F',
  21378. '\uFE80': '\u0621',
  21379. '\uFE81': '\u0622',
  21380. '\uFE82': '\u0622',
  21381. '\uFE83': '\u0623',
  21382. '\uFE84': '\u0623',
  21383. '\uFE85': '\u0624',
  21384. '\uFE86': '\u0624',
  21385. '\uFE87': '\u0625',
  21386. '\uFE88': '\u0625',
  21387. '\uFE89': '\u0626',
  21388. '\uFE8A': '\u0626',
  21389. '\uFE8B': '\u0626',
  21390. '\uFE8C': '\u0626',
  21391. '\uFE8D': '\u0627',
  21392. '\uFE8E': '\u0627',
  21393. '\uFE8F': '\u0628',
  21394. '\uFE90': '\u0628',
  21395. '\uFE91': '\u0628',
  21396. '\uFE92': '\u0628',
  21397. '\uFE93': '\u0629',
  21398. '\uFE94': '\u0629',
  21399. '\uFE95': '\u062A',
  21400. '\uFE96': '\u062A',
  21401. '\uFE97': '\u062A',
  21402. '\uFE98': '\u062A',
  21403. '\uFE99': '\u062B',
  21404. '\uFE9A': '\u062B',
  21405. '\uFE9B': '\u062B',
  21406. '\uFE9C': '\u062B',
  21407. '\uFE9D': '\u062C',
  21408. '\uFE9E': '\u062C',
  21409. '\uFE9F': '\u062C',
  21410. '\uFEA0': '\u062C',
  21411. '\uFEA1': '\u062D',
  21412. '\uFEA2': '\u062D',
  21413. '\uFEA3': '\u062D',
  21414. '\uFEA4': '\u062D',
  21415. '\uFEA5': '\u062E',
  21416. '\uFEA6': '\u062E',
  21417. '\uFEA7': '\u062E',
  21418. '\uFEA8': '\u062E',
  21419. '\uFEA9': '\u062F',
  21420. '\uFEAA': '\u062F',
  21421. '\uFEAB': '\u0630',
  21422. '\uFEAC': '\u0630',
  21423. '\uFEAD': '\u0631',
  21424. '\uFEAE': '\u0631',
  21425. '\uFEAF': '\u0632',
  21426. '\uFEB0': '\u0632',
  21427. '\uFEB1': '\u0633',
  21428. '\uFEB2': '\u0633',
  21429. '\uFEB3': '\u0633',
  21430. '\uFEB4': '\u0633',
  21431. '\uFEB5': '\u0634',
  21432. '\uFEB6': '\u0634',
  21433. '\uFEB7': '\u0634',
  21434. '\uFEB8': '\u0634',
  21435. '\uFEB9': '\u0635',
  21436. '\uFEBA': '\u0635',
  21437. '\uFEBB': '\u0635',
  21438. '\uFEBC': '\u0635',
  21439. '\uFEBD': '\u0636',
  21440. '\uFEBE': '\u0636',
  21441. '\uFEBF': '\u0636',
  21442. '\uFEC0': '\u0636',
  21443. '\uFEC1': '\u0637',
  21444. '\uFEC2': '\u0637',
  21445. '\uFEC3': '\u0637',
  21446. '\uFEC4': '\u0637',
  21447. '\uFEC5': '\u0638',
  21448. '\uFEC6': '\u0638',
  21449. '\uFEC7': '\u0638',
  21450. '\uFEC8': '\u0638',
  21451. '\uFEC9': '\u0639',
  21452. '\uFECA': '\u0639',
  21453. '\uFECB': '\u0639',
  21454. '\uFECC': '\u0639',
  21455. '\uFECD': '\u063A',
  21456. '\uFECE': '\u063A',
  21457. '\uFECF': '\u063A',
  21458. '\uFED0': '\u063A',
  21459. '\uFED1': '\u0641',
  21460. '\uFED2': '\u0641',
  21461. '\uFED3': '\u0641',
  21462. '\uFED4': '\u0641',
  21463. '\uFED5': '\u0642',
  21464. '\uFED6': '\u0642',
  21465. '\uFED7': '\u0642',
  21466. '\uFED8': '\u0642',
  21467. '\uFED9': '\u0643',
  21468. '\uFEDA': '\u0643',
  21469. '\uFEDB': '\u0643',
  21470. '\uFEDC': '\u0643',
  21471. '\uFEDD': '\u0644',
  21472. '\uFEDE': '\u0644',
  21473. '\uFEDF': '\u0644',
  21474. '\uFEE0': '\u0644',
  21475. '\uFEE1': '\u0645',
  21476. '\uFEE2': '\u0645',
  21477. '\uFEE3': '\u0645',
  21478. '\uFEE4': '\u0645',
  21479. '\uFEE5': '\u0646',
  21480. '\uFEE6': '\u0646',
  21481. '\uFEE7': '\u0646',
  21482. '\uFEE8': '\u0646',
  21483. '\uFEE9': '\u0647',
  21484. '\uFEEA': '\u0647',
  21485. '\uFEEB': '\u0647',
  21486. '\uFEEC': '\u0647',
  21487. '\uFEED': '\u0648',
  21488. '\uFEEE': '\u0648',
  21489. '\uFEEF': '\u0649',
  21490. '\uFEF0': '\u0649',
  21491. '\uFEF1': '\u064A',
  21492. '\uFEF2': '\u064A',
  21493. '\uFEF3': '\u064A',
  21494. '\uFEF4': '\u064A',
  21495. '\uFEF5': '\u0644\u0622',
  21496. '\uFEF6': '\u0644\u0622',
  21497. '\uFEF7': '\u0644\u0623',
  21498. '\uFEF8': '\u0644\u0623',
  21499. '\uFEF9': '\u0644\u0625',
  21500. '\uFEFA': '\u0644\u0625',
  21501. '\uFEFB': '\u0644\u0627',
  21502. '\uFEFC': '\u0644\u0627'
  21503. };
  21504. function reverseIfRtl(chars) {
  21505. var charsLength = chars.length;
  21506. //reverse an arabic ligature
  21507. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  21508. return chars;
  21509. }
  21510. var s = '';
  21511. for (var ii = charsLength - 1; ii >= 0; ii--) {
  21512. s += chars[ii];
  21513. }
  21514. return s;
  21515. }
  21516. function adjustWidths(properties) {
  21517. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  21518. return;
  21519. }
  21520. // adjusting width to fontMatrix scale
  21521. var scale = 0.001 / properties.fontMatrix[0];
  21522. var glyphsWidths = properties.widths;
  21523. for (var glyph in glyphsWidths) {
  21524. glyphsWidths[glyph] *= scale;
  21525. }
  21526. properties.defaultWidth *= scale;
  21527. }
  21528. function getFontType(type, subtype) {
  21529. switch (type) {
  21530. case 'Type1':
  21531. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  21532. case 'CIDFontType0':
  21533. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  21534. FontType.CIDFONTTYPE0;
  21535. case 'OpenType':
  21536. return FontType.OPENTYPE;
  21537. case 'TrueType':
  21538. return FontType.TRUETYPE;
  21539. case 'CIDFontType2':
  21540. return FontType.CIDFONTTYPE2;
  21541. case 'MMType1':
  21542. return FontType.MMTYPE1;
  21543. case 'Type0':
  21544. return FontType.TYPE0;
  21545. default:
  21546. return FontType.UNKNOWN;
  21547. }
  21548. }
  21549. var Glyph = (function GlyphClosure() {
  21550. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  21551. isSpace) {
  21552. this.fontChar = fontChar;
  21553. this.unicode = unicode;
  21554. this.accent = accent;
  21555. this.width = width;
  21556. this.vmetric = vmetric;
  21557. this.operatorListId = operatorListId;
  21558. this.isSpace = isSpace;
  21559. }
  21560. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  21561. vmetric, operatorListId, isSpace) {
  21562. return this.fontChar === fontChar &&
  21563. this.unicode === unicode &&
  21564. this.accent === accent &&
  21565. this.width === width &&
  21566. this.vmetric === vmetric &&
  21567. this.operatorListId === operatorListId &&
  21568. this.isSpace === isSpace;
  21569. };
  21570. return Glyph;
  21571. })();
  21572. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  21573. function ToUnicodeMap(cmap) {
  21574. // The elements of this._map can be integers or strings, depending on how
  21575. // |cmap| was created.
  21576. this._map = cmap;
  21577. }
  21578. ToUnicodeMap.prototype = {
  21579. get length() {
  21580. return this._map.length;
  21581. },
  21582. forEach: function(callback) {
  21583. for (var charCode in this._map) {
  21584. callback(charCode, this._map[charCode].charCodeAt(0));
  21585. }
  21586. },
  21587. has: function(i) {
  21588. return this._map[i] !== undefined;
  21589. },
  21590. get: function(i) {
  21591. return this._map[i];
  21592. },
  21593. charCodeOf: function(v) {
  21594. return this._map.indexOf(v);
  21595. }
  21596. };
  21597. return ToUnicodeMap;
  21598. })();
  21599. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  21600. function IdentityToUnicodeMap(firstChar, lastChar) {
  21601. this.firstChar = firstChar;
  21602. this.lastChar = lastChar;
  21603. }
  21604. IdentityToUnicodeMap.prototype = {
  21605. get length() {
  21606. return (this.lastChar + 1) - this.firstChar;
  21607. },
  21608. forEach: function (callback) {
  21609. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  21610. callback(i, i);
  21611. }
  21612. },
  21613. has: function (i) {
  21614. return this.firstChar <= i && i <= this.lastChar;
  21615. },
  21616. get: function (i) {
  21617. if (this.firstChar <= i && i <= this.lastChar) {
  21618. return String.fromCharCode(i);
  21619. }
  21620. return undefined;
  21621. },
  21622. charCodeOf: function (v) {
  21623. error('should not call .charCodeOf');
  21624. }
  21625. };
  21626. return IdentityToUnicodeMap;
  21627. })();
  21628. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  21629. function writeInt16(dest, offset, num) {
  21630. dest[offset] = (num >> 8) & 0xFF;
  21631. dest[offset + 1] = num & 0xFF;
  21632. }
  21633. function writeInt32(dest, offset, num) {
  21634. dest[offset] = (num >> 24) & 0xFF;
  21635. dest[offset + 1] = (num >> 16) & 0xFF;
  21636. dest[offset + 2] = (num >> 8) & 0xFF;
  21637. dest[offset + 3] = num & 0xFF;
  21638. }
  21639. function writeData(dest, offset, data) {
  21640. var i, ii;
  21641. if (data instanceof Uint8Array) {
  21642. dest.set(data, offset);
  21643. } else if (typeof data === 'string') {
  21644. for (i = 0, ii = data.length; i < ii; i++) {
  21645. dest[offset++] = data.charCodeAt(i) & 0xFF;
  21646. }
  21647. } else {
  21648. // treating everything else as array
  21649. for (i = 0, ii = data.length; i < ii; i++) {
  21650. dest[offset++] = data[i] & 0xFF;
  21651. }
  21652. }
  21653. }
  21654. function OpenTypeFileBuilder(sfnt) {
  21655. this.sfnt = sfnt;
  21656. this.tables = Object.create(null);
  21657. }
  21658. OpenTypeFileBuilder.getSearchParams =
  21659. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  21660. var maxPower2 = 1, log2 = 0;
  21661. while ((maxPower2 ^ entriesCount) > maxPower2) {
  21662. maxPower2 <<= 1;
  21663. log2++;
  21664. }
  21665. var searchRange = maxPower2 * entrySize;
  21666. return {
  21667. range: searchRange,
  21668. entry: log2,
  21669. rangeShift: entrySize * entriesCount - searchRange
  21670. };
  21671. };
  21672. var OTF_HEADER_SIZE = 12;
  21673. var OTF_TABLE_ENTRY_SIZE = 16;
  21674. OpenTypeFileBuilder.prototype = {
  21675. toArray: function OpenTypeFileBuilder_toArray() {
  21676. var sfnt = this.sfnt;
  21677. // Tables needs to be written by ascendant alphabetic order
  21678. var tables = this.tables;
  21679. var tablesNames = Object.keys(tables);
  21680. tablesNames.sort();
  21681. var numTables = tablesNames.length;
  21682. var i, j, jj, table, tableName;
  21683. // layout the tables data
  21684. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  21685. var tableOffsets = [offset];
  21686. for (i = 0; i < numTables; i++) {
  21687. table = tables[tablesNames[i]];
  21688. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  21689. offset += paddedLength;
  21690. tableOffsets.push(offset);
  21691. }
  21692. var file = new Uint8Array(offset);
  21693. // write the table data first (mostly for checksum)
  21694. for (i = 0; i < numTables; i++) {
  21695. table = tables[tablesNames[i]];
  21696. writeData(file, tableOffsets[i], table);
  21697. }
  21698. // sfnt version (4 bytes)
  21699. if (sfnt === 'true') {
  21700. // Windows hates the Mac TrueType sfnt version number
  21701. sfnt = string32(0x00010000);
  21702. }
  21703. file[0] = sfnt.charCodeAt(0) & 0xFF;
  21704. file[1] = sfnt.charCodeAt(1) & 0xFF;
  21705. file[2] = sfnt.charCodeAt(2) & 0xFF;
  21706. file[3] = sfnt.charCodeAt(3) & 0xFF;
  21707. // numTables (2 bytes)
  21708. writeInt16(file, 4, numTables);
  21709. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  21710. // searchRange (2 bytes)
  21711. writeInt16(file, 6, searchParams.range);
  21712. // entrySelector (2 bytes)
  21713. writeInt16(file, 8, searchParams.entry);
  21714. // rangeShift (2 bytes)
  21715. writeInt16(file, 10, searchParams.rangeShift);
  21716. offset = OTF_HEADER_SIZE;
  21717. // writing table entries
  21718. for (i = 0; i < numTables; i++) {
  21719. tableName = tablesNames[i];
  21720. file[offset] = tableName.charCodeAt(0) & 0xFF;
  21721. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  21722. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  21723. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  21724. // checksum
  21725. var checksum = 0;
  21726. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  21727. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  21728. (file[j + 2] << 8) + file[j + 3];
  21729. checksum = (checksum + quad) | 0;
  21730. }
  21731. writeInt32(file, offset + 4, checksum);
  21732. // offset
  21733. writeInt32(file, offset + 8, tableOffsets[i]);
  21734. // length
  21735. writeInt32(file, offset + 12, tables[tableName].length);
  21736. offset += OTF_TABLE_ENTRY_SIZE;
  21737. }
  21738. return file;
  21739. },
  21740. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  21741. if (tag in this.tables) {
  21742. throw new Error('Table ' + tag + ' already exists');
  21743. }
  21744. this.tables[tag] = data;
  21745. }
  21746. };
  21747. return OpenTypeFileBuilder;
  21748. })();
  21749. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  21750. // issues when they are painted on the canvas, e.g. complex-script shaping or
  21751. // control/whitespace characters. The ranges are listed in pairs: the first item
  21752. // is a code of the first problematic code, the second one is the next
  21753. // non-problematic code. The ranges must be in sorted order.
  21754. var ProblematicCharRanges = new Int32Array([
  21755. // Control characters.
  21756. 0x0000, 0x0020,
  21757. 0x007F, 0x00A1,
  21758. 0x00AD, 0x00AE,
  21759. // Chars that is used in complex-script shaping.
  21760. 0x0600, 0x0780,
  21761. 0x08A0, 0x10A0,
  21762. 0x1780, 0x1800,
  21763. // General punctuation chars.
  21764. 0x2000, 0x2010,
  21765. 0x2011, 0x2012,
  21766. 0x2028, 0x2030,
  21767. 0x205F, 0x2070,
  21768. 0x25CC, 0x25CD,
  21769. // Chars that is used in complex-script shaping.
  21770. 0xAA60, 0xAA80,
  21771. // Specials Unicode block.
  21772. 0xFFF0, 0x10000
  21773. ]);
  21774. /**
  21775. * 'Font' is the class the outside world should use, it encapsulate all the font
  21776. * decoding logics whatever type it is (assuming the font type is supported).
  21777. *
  21778. * For example to read a Type1 font and to attach it to the document:
  21779. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  21780. * type1Font.bind();
  21781. */
  21782. var Font = (function FontClosure() {
  21783. function Font(name, file, properties) {
  21784. var charCode, glyphName, fontChar;
  21785. this.name = name;
  21786. this.loadedName = properties.loadedName;
  21787. this.isType3Font = properties.isType3Font;
  21788. this.sizes = [];
  21789. this.glyphCache = {};
  21790. var names = name.split('+');
  21791. names = names.length > 1 ? names[1] : names[0];
  21792. names = names.split(/[-,_]/g)[0];
  21793. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  21794. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  21795. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  21796. var type = properties.type;
  21797. var subtype = properties.subtype;
  21798. this.type = type;
  21799. this.fallbackName = (this.isMonospace ? 'monospace' :
  21800. (this.isSerifFont ? 'serif' : 'sans-serif'));
  21801. this.differences = properties.differences;
  21802. this.widths = properties.widths;
  21803. this.defaultWidth = properties.defaultWidth;
  21804. this.composite = properties.composite;
  21805. this.wideChars = properties.wideChars;
  21806. this.cMap = properties.cMap;
  21807. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  21808. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  21809. this.fontMatrix = properties.fontMatrix;
  21810. this.bbox = properties.bbox;
  21811. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  21812. this.toFontChar = [];
  21813. if (properties.type === 'Type3') {
  21814. for (charCode = 0; charCode < 256; charCode++) {
  21815. this.toFontChar[charCode] = (this.differences[charCode] ||
  21816. properties.defaultEncoding[charCode]);
  21817. }
  21818. this.fontType = FontType.TYPE3;
  21819. return;
  21820. }
  21821. this.cidEncoding = properties.cidEncoding;
  21822. this.vertical = properties.vertical;
  21823. if (this.vertical) {
  21824. this.vmetrics = properties.vmetrics;
  21825. this.defaultVMetrics = properties.defaultVMetrics;
  21826. }
  21827. if (!file || file.isEmpty) {
  21828. if (file) {
  21829. // Some bad PDF generators will include empty font files,
  21830. // attempting to recover by assuming that no file exists.
  21831. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  21832. }
  21833. this.missingFile = true;
  21834. // The file data is not specified. Trying to fix the font name
  21835. // to be used with the canvas.font.
  21836. var fontName = name.replace(/[,_]/g, '-');
  21837. var isStandardFont = !!stdFontMap[fontName] ||
  21838. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  21839. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  21840. this.bold = (fontName.search(/bold/gi) !== -1);
  21841. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  21842. (fontName.search(/italic/gi) !== -1));
  21843. // Use 'name' instead of 'fontName' here because the original
  21844. // name ArialBlack for example will be replaced by Helvetica.
  21845. this.black = (name.search(/Black/g) !== -1);
  21846. // if at least one width is present, remeasure all chars when exists
  21847. this.remeasure = Object.keys(this.widths).length > 0;
  21848. if (isStandardFont && type === 'CIDFontType2' &&
  21849. properties.cidEncoding.indexOf('Identity-') === 0) {
  21850. // Standard fonts might be embedded as CID font without glyph mapping.
  21851. // Building one based on GlyphMapForStandardFonts.
  21852. var map = [];
  21853. for (charCode in GlyphMapForStandardFonts) {
  21854. map[+charCode] = GlyphMapForStandardFonts[charCode];
  21855. }
  21856. if (/ArialBlack/i.test(name)) {
  21857. for (charCode in SupplementalGlyphMapForArialBlack) {
  21858. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  21859. }
  21860. }
  21861. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  21862. if (!isIdentityUnicode) {
  21863. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  21864. map[+charCode] = unicodeCharCode;
  21865. });
  21866. }
  21867. this.toFontChar = map;
  21868. this.toUnicode = new ToUnicodeMap(map);
  21869. } else if (/Symbol/i.test(fontName)) {
  21870. var symbols = Encodings.SymbolSetEncoding;
  21871. for (charCode in symbols) {
  21872. fontChar = GlyphsUnicode[symbols[charCode]];
  21873. if (!fontChar) {
  21874. continue;
  21875. }
  21876. this.toFontChar[charCode] = fontChar;
  21877. }
  21878. for (charCode in properties.differences) {
  21879. fontChar = GlyphsUnicode[properties.differences[charCode]];
  21880. if (!fontChar) {
  21881. continue;
  21882. }
  21883. this.toFontChar[charCode] = fontChar;
  21884. }
  21885. } else if (/Dingbats/i.test(fontName)) {
  21886. if (/Wingdings/i.test(name)) {
  21887. warn('Wingdings font without embedded font file, ' +
  21888. 'falling back to the ZapfDingbats encoding.');
  21889. }
  21890. var dingbats = Encodings.ZapfDingbatsEncoding;
  21891. for (charCode in dingbats) {
  21892. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  21893. if (!fontChar) {
  21894. continue;
  21895. }
  21896. this.toFontChar[charCode] = fontChar;
  21897. }
  21898. for (charCode in properties.differences) {
  21899. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  21900. if (!fontChar) {
  21901. continue;
  21902. }
  21903. this.toFontChar[charCode] = fontChar;
  21904. }
  21905. } else if (isStandardFont) {
  21906. this.toFontChar = [];
  21907. for (charCode in properties.defaultEncoding) {
  21908. glyphName = (properties.differences[charCode] ||
  21909. properties.defaultEncoding[charCode]);
  21910. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  21911. }
  21912. } else {
  21913. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  21914. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  21915. if (notCidFont) {
  21916. glyphName = (properties.differences[charCode] ||
  21917. properties.defaultEncoding[charCode]);
  21918. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  21919. }
  21920. this.toFontChar[charCode] = unicodeCharCode;
  21921. }.bind(this));
  21922. }
  21923. this.loadedName = fontName.split('-')[0];
  21924. this.loading = false;
  21925. this.fontType = getFontType(type, subtype);
  21926. return;
  21927. }
  21928. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  21929. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  21930. // Some TrueType fonts by mistake claim Type1C
  21931. if (isTrueTypeFile(file)) {
  21932. subtype = 'TrueType';
  21933. } else {
  21934. type = 'Type1';
  21935. }
  21936. }
  21937. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  21938. type = 'CIDFontType0';
  21939. }
  21940. if (subtype === 'OpenType') {
  21941. type = 'OpenType';
  21942. }
  21943. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  21944. if (type === 'CIDFontType0') {
  21945. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  21946. }
  21947. var data;
  21948. switch (type) {
  21949. case 'MMType1':
  21950. info('MMType1 font (' + name + '), falling back to Type1.');
  21951. /* falls through */
  21952. case 'Type1':
  21953. case 'CIDFontType0':
  21954. this.mimetype = 'font/opentype';
  21955. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  21956. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  21957. adjustWidths(properties);
  21958. // Wrap the CFF data inside an OTF font file
  21959. data = this.convert(name, cff, properties);
  21960. break;
  21961. case 'OpenType':
  21962. case 'TrueType':
  21963. case 'CIDFontType2':
  21964. this.mimetype = 'font/opentype';
  21965. // Repair the TrueType file. It is can be damaged in the point of
  21966. // view of the sanitizer
  21967. data = this.checkAndRepair(name, file, properties);
  21968. if (this.isOpenType) {
  21969. type = 'OpenType';
  21970. }
  21971. break;
  21972. default:
  21973. error('Font ' + type + ' is not supported');
  21974. break;
  21975. }
  21976. this.data = data;
  21977. this.fontType = getFontType(type, subtype);
  21978. // Transfer some properties again that could change during font conversion
  21979. this.fontMatrix = properties.fontMatrix;
  21980. this.widths = properties.widths;
  21981. this.defaultWidth = properties.defaultWidth;
  21982. this.encoding = properties.baseEncoding;
  21983. this.seacMap = properties.seacMap;
  21984. this.loading = true;
  21985. }
  21986. Font.getFontID = (function () {
  21987. var ID = 1;
  21988. return function Font_getFontID() {
  21989. return String(ID++);
  21990. };
  21991. })();
  21992. function int16(b0, b1) {
  21993. return (b0 << 8) + b1;
  21994. }
  21995. function int32(b0, b1, b2, b3) {
  21996. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  21997. }
  21998. function string16(value) {
  21999. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  22000. }
  22001. function safeString16(value) {
  22002. // clamp value to the 16-bit int range
  22003. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  22004. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  22005. }
  22006. function isTrueTypeFile(file) {
  22007. var header = file.peekBytes(4);
  22008. return readUint32(header, 0) === 0x00010000;
  22009. }
  22010. function isType1File(file) {
  22011. var header = file.peekBytes(2);
  22012. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  22013. if (header[0] === 0x25 && header[1] === 0x21) {
  22014. return true;
  22015. }
  22016. // ... obviously some fonts violate that part of the specification,
  22017. // please refer to the comment in |Type1Font| below.
  22018. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  22019. return true;
  22020. }
  22021. return false;
  22022. }
  22023. /**
  22024. * Helper function for |adjustMapping|.
  22025. * @return {boolean}
  22026. */
  22027. function isProblematicUnicodeLocation(code) {
  22028. // Using binary search to find a range start.
  22029. var i = 0, j = ProblematicCharRanges.length - 1;
  22030. while (i < j) {
  22031. var c = (i + j + 1) >> 1;
  22032. if (code < ProblematicCharRanges[c]) {
  22033. j = c - 1;
  22034. } else {
  22035. i = c;
  22036. }
  22037. }
  22038. // Even index means code in problematic range.
  22039. return !(i & 1);
  22040. }
  22041. /**
  22042. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  22043. * with their unicode value. It also moves char codes that are in known
  22044. * problematic locations.
  22045. * @return {Object} Two properties:
  22046. * 'toFontChar' - maps original char codes(the value that will be read
  22047. * from commands such as show text) to the char codes that will be used in the
  22048. * font that we build
  22049. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  22050. */
  22051. function adjustMapping(charCodeToGlyphId, properties) {
  22052. var toUnicode = properties.toUnicode;
  22053. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  22054. var isIdentityUnicode =
  22055. properties.toUnicode instanceof IdentityToUnicodeMap;
  22056. var newMap = Object.create(null);
  22057. var toFontChar = [];
  22058. var usedFontCharCodes = [];
  22059. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  22060. for (var originalCharCode in charCodeToGlyphId) {
  22061. originalCharCode |= 0;
  22062. var glyphId = charCodeToGlyphId[originalCharCode];
  22063. var fontCharCode = originalCharCode;
  22064. // First try to map the value to a unicode position if a non identity map
  22065. // was created.
  22066. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  22067. var unicode = toUnicode.get(fontCharCode);
  22068. // TODO: Try to map ligatures to the correct spot.
  22069. if (unicode.length === 1) {
  22070. fontCharCode = unicode.charCodeAt(0);
  22071. }
  22072. }
  22073. // Try to move control characters, special characters and already mapped
  22074. // characters to the private use area since they will not be drawn by
  22075. // canvas if left in their current position. Also, move characters if the
  22076. // font was symbolic and there is only an identity unicode map since the
  22077. // characters probably aren't in the correct position (fixes an issue
  22078. // with firefox and thuluthfont).
  22079. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  22080. isProblematicUnicodeLocation(fontCharCode) ||
  22081. (isSymbolic && isIdentityUnicode)) &&
  22082. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  22083. // Loop to try and find a free spot in the private use area.
  22084. do {
  22085. fontCharCode = nextAvailableFontCharCode++;
  22086. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  22087. fontCharCode = 0xF020;
  22088. nextAvailableFontCharCode = fontCharCode + 1;
  22089. }
  22090. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  22091. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  22092. }
  22093. newMap[fontCharCode] = glyphId;
  22094. toFontChar[originalCharCode] = fontCharCode;
  22095. usedFontCharCodes[fontCharCode] = true;
  22096. }
  22097. return {
  22098. toFontChar: toFontChar,
  22099. charCodeToGlyphId: newMap,
  22100. nextAvailableFontCharCode: nextAvailableFontCharCode
  22101. };
  22102. }
  22103. function getRanges(glyphs) {
  22104. // Array.sort() sorts by characters, not numerically, so convert to an
  22105. // array of characters.
  22106. var codes = [];
  22107. for (var charCode in glyphs) {
  22108. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  22109. }
  22110. codes.sort(function fontGetRangesSort(a, b) {
  22111. return a.fontCharCode - b.fontCharCode;
  22112. });
  22113. // Split the sorted codes into ranges.
  22114. var ranges = [];
  22115. var length = codes.length;
  22116. for (var n = 0; n < length; ) {
  22117. var start = codes[n].fontCharCode;
  22118. var codeIndices = [codes[n].glyphId];
  22119. ++n;
  22120. var end = start;
  22121. while (n < length && end + 1 === codes[n].fontCharCode) {
  22122. codeIndices.push(codes[n].glyphId);
  22123. ++end;
  22124. ++n;
  22125. if (end === 0xFFFF) {
  22126. break;
  22127. }
  22128. }
  22129. ranges.push([start, end, codeIndices]);
  22130. }
  22131. return ranges;
  22132. }
  22133. function createCmapTable(glyphs) {
  22134. var ranges = getRanges(glyphs);
  22135. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  22136. var cmap = '\x00\x00' + // version
  22137. string16(numTables) + // numTables
  22138. '\x00\x03' + // platformID
  22139. '\x00\x01' + // encodingID
  22140. string32(4 + numTables * 8); // start of the table record
  22141. var i, ii, j, jj;
  22142. for (i = ranges.length - 1; i >= 0; --i) {
  22143. if (ranges[i][0] <= 0xFFFF) { break; }
  22144. }
  22145. var bmpLength = i + 1;
  22146. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  22147. ranges[i][1] = 0xFFFE;
  22148. }
  22149. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  22150. var segCount = bmpLength + trailingRangesCount;
  22151. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  22152. // Fill up the 4 parallel arrays describing the segments.
  22153. var startCount = '';
  22154. var endCount = '';
  22155. var idDeltas = '';
  22156. var idRangeOffsets = '';
  22157. var glyphsIds = '';
  22158. var bias = 0;
  22159. var range, start, end, codes;
  22160. for (i = 0, ii = bmpLength; i < ii; i++) {
  22161. range = ranges[i];
  22162. start = range[0];
  22163. end = range[1];
  22164. startCount += string16(start);
  22165. endCount += string16(end);
  22166. codes = range[2];
  22167. var contiguous = true;
  22168. for (j = 1, jj = codes.length; j < jj; ++j) {
  22169. if (codes[j] !== codes[j - 1] + 1) {
  22170. contiguous = false;
  22171. break;
  22172. }
  22173. }
  22174. if (!contiguous) {
  22175. var offset = (segCount - i) * 2 + bias * 2;
  22176. bias += (end - start + 1);
  22177. idDeltas += string16(0);
  22178. idRangeOffsets += string16(offset);
  22179. for (j = 0, jj = codes.length; j < jj; ++j) {
  22180. glyphsIds += string16(codes[j]);
  22181. }
  22182. } else {
  22183. var startCode = codes[0];
  22184. idDeltas += string16((startCode - start) & 0xFFFF);
  22185. idRangeOffsets += string16(0);
  22186. }
  22187. }
  22188. if (trailingRangesCount > 0) {
  22189. endCount += '\xFF\xFF';
  22190. startCount += '\xFF\xFF';
  22191. idDeltas += '\x00\x01';
  22192. idRangeOffsets += '\x00\x00';
  22193. }
  22194. var format314 = '\x00\x00' + // language
  22195. string16(2 * segCount) +
  22196. string16(searchParams.range) +
  22197. string16(searchParams.entry) +
  22198. string16(searchParams.rangeShift) +
  22199. endCount + '\x00\x00' + startCount +
  22200. idDeltas + idRangeOffsets + glyphsIds;
  22201. var format31012 = '';
  22202. var header31012 = '';
  22203. if (numTables > 1) {
  22204. cmap += '\x00\x03' + // platformID
  22205. '\x00\x0A' + // encodingID
  22206. string32(4 + numTables * 8 +
  22207. 4 + format314.length); // start of the table record
  22208. format31012 = '';
  22209. for (i = 0, ii = ranges.length; i < ii; i++) {
  22210. range = ranges[i];
  22211. start = range[0];
  22212. codes = range[2];
  22213. var code = codes[0];
  22214. for (j = 1, jj = codes.length; j < jj; ++j) {
  22215. if (codes[j] !== codes[j - 1] + 1) {
  22216. end = range[0] + j - 1;
  22217. format31012 += string32(start) + // startCharCode
  22218. string32(end) + // endCharCode
  22219. string32(code); // startGlyphID
  22220. start = end + 1;
  22221. code = codes[j];
  22222. }
  22223. }
  22224. format31012 += string32(start) + // startCharCode
  22225. string32(range[1]) + // endCharCode
  22226. string32(code); // startGlyphID
  22227. }
  22228. header31012 = '\x00\x0C' + // format
  22229. '\x00\x00' + // reserved
  22230. string32(format31012.length + 16) + // length
  22231. '\x00\x00\x00\x00' + // language
  22232. string32(format31012.length / 12); // nGroups
  22233. }
  22234. return cmap + '\x00\x04' + // format
  22235. string16(format314.length + 4) + // length
  22236. format314 + header31012 + format31012;
  22237. }
  22238. function validateOS2Table(os2) {
  22239. var stream = new Stream(os2.data);
  22240. var version = stream.getUint16();
  22241. // TODO verify all OS/2 tables fields, but currently we validate only those
  22242. // that give us issues
  22243. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  22244. var selection = stream.getUint16();
  22245. if (version < 4 && (selection & 0x0300)) {
  22246. return false;
  22247. }
  22248. var firstChar = stream.getUint16();
  22249. var lastChar = stream.getUint16();
  22250. if (firstChar > lastChar) {
  22251. return false;
  22252. }
  22253. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  22254. var usWinAscent = stream.getUint16();
  22255. if (usWinAscent === 0) { // makes font unreadable by windows
  22256. return false;
  22257. }
  22258. // OS/2 appears to be valid, resetting some fields
  22259. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  22260. return true;
  22261. }
  22262. function createOS2Table(properties, charstrings, override) {
  22263. override = override || {
  22264. unitsPerEm: 0,
  22265. yMax: 0,
  22266. yMin: 0,
  22267. ascent: 0,
  22268. descent: 0
  22269. };
  22270. var ulUnicodeRange1 = 0;
  22271. var ulUnicodeRange2 = 0;
  22272. var ulUnicodeRange3 = 0;
  22273. var ulUnicodeRange4 = 0;
  22274. var firstCharIndex = null;
  22275. var lastCharIndex = 0;
  22276. if (charstrings) {
  22277. for (var code in charstrings) {
  22278. code |= 0;
  22279. if (firstCharIndex > code || !firstCharIndex) {
  22280. firstCharIndex = code;
  22281. }
  22282. if (lastCharIndex < code) {
  22283. lastCharIndex = code;
  22284. }
  22285. var position = getUnicodeRangeFor(code);
  22286. if (position < 32) {
  22287. ulUnicodeRange1 |= 1 << position;
  22288. } else if (position < 64) {
  22289. ulUnicodeRange2 |= 1 << position - 32;
  22290. } else if (position < 96) {
  22291. ulUnicodeRange3 |= 1 << position - 64;
  22292. } else if (position < 123) {
  22293. ulUnicodeRange4 |= 1 << position - 96;
  22294. } else {
  22295. error('Unicode ranges Bits > 123 are reserved for internal usage');
  22296. }
  22297. }
  22298. } else {
  22299. // TODO
  22300. firstCharIndex = 0;
  22301. lastCharIndex = 255;
  22302. }
  22303. var bbox = properties.bbox || [0, 0, 0, 0];
  22304. var unitsPerEm = (override.unitsPerEm ||
  22305. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  22306. // if the font units differ to the PDF glyph space units
  22307. // then scale up the values
  22308. var scale = (properties.ascentScaled ? 1.0 :
  22309. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  22310. var typoAscent = (override.ascent ||
  22311. Math.round(scale * (properties.ascent || bbox[3])));
  22312. var typoDescent = (override.descent ||
  22313. Math.round(scale * (properties.descent || bbox[1])));
  22314. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  22315. typoDescent = -typoDescent; // fixing incorrect descent
  22316. }
  22317. var winAscent = override.yMax || typoAscent;
  22318. var winDescent = -override.yMin || -typoDescent;
  22319. return '\x00\x03' + // version
  22320. '\x02\x24' + // xAvgCharWidth
  22321. '\x01\xF4' + // usWeightClass
  22322. '\x00\x05' + // usWidthClass
  22323. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  22324. '\x02\x8A' + // ySubscriptXSize
  22325. '\x02\xBB' + // ySubscriptYSize
  22326. '\x00\x00' + // ySubscriptXOffset
  22327. '\x00\x8C' + // ySubscriptYOffset
  22328. '\x02\x8A' + // ySuperScriptXSize
  22329. '\x02\xBB' + // ySuperScriptYSize
  22330. '\x00\x00' + // ySuperScriptXOffset
  22331. '\x01\xDF' + // ySuperScriptYOffset
  22332. '\x00\x31' + // yStrikeOutSize
  22333. '\x01\x02' + // yStrikeOutPosition
  22334. '\x00\x00' + // sFamilyClass
  22335. '\x00\x00\x06' +
  22336. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  22337. '\x00\x00\x00\x00\x00\x00' + // Panose
  22338. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  22339. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  22340. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  22341. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  22342. '\x2A\x32\x31\x2A' + // achVendID
  22343. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  22344. string16(firstCharIndex ||
  22345. properties.firstChar) + // usFirstCharIndex
  22346. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  22347. string16(typoAscent) + // sTypoAscender
  22348. string16(typoDescent) + // sTypoDescender
  22349. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  22350. string16(winAscent) + // usWinAscent
  22351. string16(winDescent) + // usWinDescent
  22352. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  22353. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  22354. string16(properties.xHeight) + // sxHeight
  22355. string16(properties.capHeight) + // sCapHeight
  22356. string16(0) + // usDefaultChar
  22357. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  22358. '\x00\x03'; // usMaxContext
  22359. }
  22360. function createPostTable(properties) {
  22361. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  22362. return ('\x00\x03\x00\x00' + // Version number
  22363. string32(angle) + // italicAngle
  22364. '\x00\x00' + // underlinePosition
  22365. '\x00\x00' + // underlineThickness
  22366. string32(properties.fixedPitch) + // isFixedPitch
  22367. '\x00\x00\x00\x00' + // minMemType42
  22368. '\x00\x00\x00\x00' + // maxMemType42
  22369. '\x00\x00\x00\x00' + // minMemType1
  22370. '\x00\x00\x00\x00'); // maxMemType1
  22371. }
  22372. function createNameTable(name, proto) {
  22373. if (!proto) {
  22374. proto = [[], []]; // no strings and unicode strings
  22375. }
  22376. var strings = [
  22377. proto[0][0] || 'Original licence', // 0.Copyright
  22378. proto[0][1] || name, // 1.Font family
  22379. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  22380. proto[0][3] || 'uniqueID', // 3.Unique ID
  22381. proto[0][4] || name, // 4.Full font name
  22382. proto[0][5] || 'Version 0.11', // 5.Version
  22383. proto[0][6] || '', // 6.Postscript name
  22384. proto[0][7] || 'Unknown', // 7.Trademark
  22385. proto[0][8] || 'Unknown', // 8.Manufacturer
  22386. proto[0][9] || 'Unknown' // 9.Designer
  22387. ];
  22388. // Mac want 1-byte per character strings while Windows want
  22389. // 2-bytes per character, so duplicate the names table
  22390. var stringsUnicode = [];
  22391. var i, ii, j, jj, str;
  22392. for (i = 0, ii = strings.length; i < ii; i++) {
  22393. str = proto[1][i] || strings[i];
  22394. var strBufUnicode = [];
  22395. for (j = 0, jj = str.length; j < jj; j++) {
  22396. strBufUnicode.push(string16(str.charCodeAt(j)));
  22397. }
  22398. stringsUnicode.push(strBufUnicode.join(''));
  22399. }
  22400. var names = [strings, stringsUnicode];
  22401. var platforms = ['\x00\x01', '\x00\x03'];
  22402. var encodings = ['\x00\x00', '\x00\x01'];
  22403. var languages = ['\x00\x00', '\x04\x09'];
  22404. var namesRecordCount = strings.length * platforms.length;
  22405. var nameTable =
  22406. '\x00\x00' + // format
  22407. string16(namesRecordCount) + // Number of names Record
  22408. string16(namesRecordCount * 12 + 6); // Storage
  22409. // Build the name records field
  22410. var strOffset = 0;
  22411. for (i = 0, ii = platforms.length; i < ii; i++) {
  22412. var strs = names[i];
  22413. for (j = 0, jj = strs.length; j < jj; j++) {
  22414. str = strs[j];
  22415. var nameRecord =
  22416. platforms[i] + // platform ID
  22417. encodings[i] + // encoding ID
  22418. languages[i] + // language ID
  22419. string16(j) + // name ID
  22420. string16(str.length) +
  22421. string16(strOffset);
  22422. nameTable += nameRecord;
  22423. strOffset += str.length;
  22424. }
  22425. }
  22426. nameTable += strings.join('') + stringsUnicode.join('');
  22427. return nameTable;
  22428. }
  22429. Font.prototype = {
  22430. name: null,
  22431. font: null,
  22432. mimetype: null,
  22433. encoding: null,
  22434. get renderer() {
  22435. var renderer = FontRendererFactory.create(this);
  22436. return shadow(this, 'renderer', renderer);
  22437. },
  22438. exportData: function Font_exportData() {
  22439. var data = {};
  22440. for (var i in this) {
  22441. if (this.hasOwnProperty(i)) {
  22442. data[i] = this[i];
  22443. }
  22444. }
  22445. return data;
  22446. },
  22447. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  22448. function readTableEntry(file) {
  22449. var tag = bytesToString(file.getBytes(4));
  22450. var checksum = file.getInt32();
  22451. var offset = file.getInt32() >>> 0;
  22452. var length = file.getInt32() >>> 0;
  22453. // Read the table associated data
  22454. var previousPosition = file.pos;
  22455. file.pos = file.start ? file.start : 0;
  22456. file.skip(offset);
  22457. var data = file.getBytes(length);
  22458. file.pos = previousPosition;
  22459. if (tag === 'head') {
  22460. // clearing checksum adjustment
  22461. data[8] = data[9] = data[10] = data[11] = 0;
  22462. data[17] |= 0x20; //Set font optimized for cleartype flag
  22463. }
  22464. return {
  22465. tag: tag,
  22466. checksum: checksum,
  22467. length: length,
  22468. offset: offset,
  22469. data: data
  22470. };
  22471. }
  22472. function readOpenTypeHeader(ttf) {
  22473. return {
  22474. version: bytesToString(ttf.getBytes(4)),
  22475. numTables: ttf.getUint16(),
  22476. searchRange: ttf.getUint16(),
  22477. entrySelector: ttf.getUint16(),
  22478. rangeShift: ttf.getUint16()
  22479. };
  22480. }
  22481. /**
  22482. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  22483. * PDF spec
  22484. */
  22485. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  22486. if (!cmap) {
  22487. warn('No cmap table available.');
  22488. return {
  22489. platformId: -1,
  22490. encodingId: -1,
  22491. mappings: [],
  22492. hasShortCmap: false
  22493. };
  22494. }
  22495. var segment;
  22496. var start = (font.start ? font.start : 0) + cmap.offset;
  22497. font.pos = start;
  22498. var version = font.getUint16();
  22499. var numTables = font.getUint16();
  22500. var potentialTable;
  22501. var canBreak = false;
  22502. // There's an order of preference in terms of which cmap subtable to
  22503. // use:
  22504. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  22505. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  22506. // The following takes advantage of the fact that the tables are sorted
  22507. // to work.
  22508. for (var i = 0; i < numTables; i++) {
  22509. var platformId = font.getUint16();
  22510. var encodingId = font.getUint16();
  22511. var offset = font.getInt32() >>> 0;
  22512. var useTable = false;
  22513. if (platformId === 0 && encodingId === 0) {
  22514. useTable = true;
  22515. // Continue the loop since there still may be a higher priority
  22516. // table.
  22517. } else if (platformId === 1 && encodingId === 0) {
  22518. useTable = true;
  22519. // Continue the loop since there still may be a higher priority
  22520. // table.
  22521. } else if (platformId === 3 && encodingId === 1 &&
  22522. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  22523. useTable = true;
  22524. if (!isSymbolicFont) {
  22525. canBreak = true;
  22526. }
  22527. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  22528. useTable = true;
  22529. canBreak = true;
  22530. }
  22531. if (useTable) {
  22532. potentialTable = {
  22533. platformId: platformId,
  22534. encodingId: encodingId,
  22535. offset: offset
  22536. };
  22537. }
  22538. if (canBreak) {
  22539. break;
  22540. }
  22541. }
  22542. if (potentialTable) {
  22543. font.pos = start + potentialTable.offset;
  22544. }
  22545. if (!potentialTable || font.peekByte() === -1) {
  22546. warn('Could not find a preferred cmap table.');
  22547. return {
  22548. platformId: -1,
  22549. encodingId: -1,
  22550. mappings: [],
  22551. hasShortCmap: false
  22552. };
  22553. }
  22554. var format = font.getUint16();
  22555. var length = font.getUint16();
  22556. var language = font.getUint16();
  22557. var hasShortCmap = false;
  22558. var mappings = [];
  22559. var j, glyphId;
  22560. // TODO(mack): refactor this cmap subtable reading logic out
  22561. if (format === 0) {
  22562. for (j = 0; j < 256; j++) {
  22563. var index = font.getByte();
  22564. if (!index) {
  22565. continue;
  22566. }
  22567. mappings.push({
  22568. charCode: j,
  22569. glyphId: index
  22570. });
  22571. }
  22572. hasShortCmap = true;
  22573. } else if (format === 4) {
  22574. // re-creating the table in format 4 since the encoding
  22575. // might be changed
  22576. var segCount = (font.getUint16() >> 1);
  22577. font.getBytes(6); // skipping range fields
  22578. var segIndex, segments = [];
  22579. for (segIndex = 0; segIndex < segCount; segIndex++) {
  22580. segments.push({ end: font.getUint16() });
  22581. }
  22582. font.getUint16();
  22583. for (segIndex = 0; segIndex < segCount; segIndex++) {
  22584. segments[segIndex].start = font.getUint16();
  22585. }
  22586. for (segIndex = 0; segIndex < segCount; segIndex++) {
  22587. segments[segIndex].delta = font.getUint16();
  22588. }
  22589. var offsetsCount = 0;
  22590. for (segIndex = 0; segIndex < segCount; segIndex++) {
  22591. segment = segments[segIndex];
  22592. var rangeOffset = font.getUint16();
  22593. if (!rangeOffset) {
  22594. segment.offsetIndex = -1;
  22595. continue;
  22596. }
  22597. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  22598. segment.offsetIndex = offsetIndex;
  22599. offsetsCount = Math.max(offsetsCount, offsetIndex +
  22600. segment.end - segment.start + 1);
  22601. }
  22602. var offsets = [];
  22603. for (j = 0; j < offsetsCount; j++) {
  22604. offsets.push(font.getUint16());
  22605. }
  22606. for (segIndex = 0; segIndex < segCount; segIndex++) {
  22607. segment = segments[segIndex];
  22608. start = segment.start;
  22609. var end = segment.end;
  22610. var delta = segment.delta;
  22611. offsetIndex = segment.offsetIndex;
  22612. for (j = start; j <= end; j++) {
  22613. if (j === 0xFFFF) {
  22614. continue;
  22615. }
  22616. glyphId = (offsetIndex < 0 ?
  22617. j : offsets[offsetIndex + j - start]);
  22618. glyphId = (glyphId + delta) & 0xFFFF;
  22619. if (glyphId === 0) {
  22620. continue;
  22621. }
  22622. mappings.push({
  22623. charCode: j,
  22624. glyphId: glyphId
  22625. });
  22626. }
  22627. }
  22628. } else if (format === 6) {
  22629. // Format 6 is a 2-bytes dense mapping, which means the font data
  22630. // lives glue together even if they are pretty far in the unicode
  22631. // table. (This looks weird, so I can have missed something), this
  22632. // works on Linux but seems to fails on Mac so let's rewrite the
  22633. // cmap table to a 3-1-4 style
  22634. var firstCode = font.getUint16();
  22635. var entryCount = font.getUint16();
  22636. for (j = 0; j < entryCount; j++) {
  22637. glyphId = font.getUint16();
  22638. var charCode = firstCode + j;
  22639. mappings.push({
  22640. charCode: charCode,
  22641. glyphId: glyphId
  22642. });
  22643. }
  22644. } else {
  22645. warn('cmap table has unsupported format: ' + format);
  22646. return {
  22647. platformId: -1,
  22648. encodingId: -1,
  22649. mappings: [],
  22650. hasShortCmap: false
  22651. };
  22652. }
  22653. // removing duplicate entries
  22654. mappings.sort(function (a, b) {
  22655. return a.charCode - b.charCode;
  22656. });
  22657. for (i = 1; i < mappings.length; i++) {
  22658. if (mappings[i - 1].charCode === mappings[i].charCode) {
  22659. mappings.splice(i, 1);
  22660. i--;
  22661. }
  22662. }
  22663. return {
  22664. platformId: potentialTable.platformId,
  22665. encodingId: potentialTable.encodingId,
  22666. mappings: mappings,
  22667. hasShortCmap: hasShortCmap
  22668. };
  22669. }
  22670. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  22671. if (!header) {
  22672. if (metrics) {
  22673. metrics.data = null;
  22674. }
  22675. return;
  22676. }
  22677. font.pos = (font.start ? font.start : 0) + header.offset;
  22678. font.pos += header.length - 2;
  22679. var numOfMetrics = font.getUint16();
  22680. if (numOfMetrics > numGlyphs) {
  22681. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  22682. 'greater than the numGlyphs (' + numGlyphs + ')');
  22683. // Reduce numOfMetrics if it is greater than numGlyphs
  22684. numOfMetrics = numGlyphs;
  22685. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  22686. header.data[35] = numOfMetrics & 0x00ff;
  22687. }
  22688. var numOfSidebearings = numGlyphs - numOfMetrics;
  22689. var numMissing = numOfSidebearings -
  22690. ((metrics.length - numOfMetrics * 4) >> 1);
  22691. if (numMissing > 0) {
  22692. // For each missing glyph, we set both the width and lsb to 0 (zero).
  22693. // Since we need to add two properties for each glyph, this explains
  22694. // the use of |numMissing * 2| when initializing the typed array.
  22695. var entries = new Uint8Array(metrics.length + numMissing * 2);
  22696. entries.set(metrics.data);
  22697. metrics.data = entries;
  22698. }
  22699. }
  22700. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  22701. hintsValid) {
  22702. if (sourceEnd - sourceStart <= 12) {
  22703. // glyph with data less than 12 is invalid one
  22704. return 0;
  22705. }
  22706. var glyf = source.subarray(sourceStart, sourceEnd);
  22707. var contoursCount = (glyf[0] << 8) | glyf[1];
  22708. if (contoursCount & 0x8000) {
  22709. // complex glyph, writing as is
  22710. dest.set(glyf, destStart);
  22711. return glyf.length;
  22712. }
  22713. var i, j = 10, flagsCount = 0;
  22714. for (i = 0; i < contoursCount; i++) {
  22715. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  22716. flagsCount = endPoint + 1;
  22717. j += 2;
  22718. }
  22719. // skipping instructions
  22720. var instructionsStart = j;
  22721. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  22722. j += 2 + instructionsLength;
  22723. var instructionsEnd = j;
  22724. // validating flags
  22725. var coordinatesLength = 0;
  22726. for (i = 0; i < flagsCount; i++) {
  22727. var flag = glyf[j++];
  22728. if (flag & 0xC0) {
  22729. // reserved flags must be zero, cleaning up
  22730. glyf[j - 1] = flag & 0x3F;
  22731. }
  22732. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  22733. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  22734. coordinatesLength += xyLength;
  22735. if (flag & 8) {
  22736. var repeat = glyf[j++];
  22737. i += repeat;
  22738. coordinatesLength += repeat * xyLength;
  22739. }
  22740. }
  22741. // glyph without coordinates will be rejected
  22742. if (coordinatesLength === 0) {
  22743. return 0;
  22744. }
  22745. var glyphDataLength = j + coordinatesLength;
  22746. if (glyphDataLength > glyf.length) {
  22747. // not enough data for coordinates
  22748. return 0;
  22749. }
  22750. if (!hintsValid && instructionsLength > 0) {
  22751. dest.set(glyf.subarray(0, instructionsStart), destStart);
  22752. dest.set([0, 0], destStart + instructionsStart);
  22753. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  22754. destStart + instructionsStart + 2);
  22755. glyphDataLength -= instructionsLength;
  22756. if (glyf.length - glyphDataLength > 3) {
  22757. glyphDataLength = (glyphDataLength + 3) & ~3;
  22758. }
  22759. return glyphDataLength;
  22760. }
  22761. if (glyf.length - glyphDataLength > 3) {
  22762. // truncating and aligning to 4 bytes the long glyph data
  22763. glyphDataLength = (glyphDataLength + 3) & ~3;
  22764. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  22765. return glyphDataLength;
  22766. }
  22767. // glyph data is fine
  22768. dest.set(glyf, destStart);
  22769. return glyf.length;
  22770. }
  22771. function sanitizeHead(head, numGlyphs, locaLength) {
  22772. var data = head.data;
  22773. // Validate version:
  22774. // Should always be 0x00010000
  22775. var version = int32(data[0], data[1], data[2], data[3]);
  22776. if (version >> 16 !== 1) {
  22777. info('Attempting to fix invalid version in head table: ' + version);
  22778. data[0] = 0;
  22779. data[1] = 1;
  22780. data[2] = 0;
  22781. data[3] = 0;
  22782. }
  22783. var indexToLocFormat = int16(data[50], data[51]);
  22784. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  22785. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  22786. indexToLocFormat);
  22787. // The value of indexToLocFormat should be 0 if the loca table
  22788. // consists of short offsets, and should be 1 if the loca table
  22789. // consists of long offsets.
  22790. //
  22791. // The number of entries in the loca table should be numGlyphs + 1.
  22792. //
  22793. // Using this information, we can work backwards to deduce if the
  22794. // size of each offset in the loca table, and thus figure out the
  22795. // appropriate value for indexToLocFormat.
  22796. var numGlyphsPlusOne = numGlyphs + 1;
  22797. if (locaLength === numGlyphsPlusOne << 1) {
  22798. // 0x0000 indicates the loca table consists of short offsets
  22799. data[50] = 0;
  22800. data[51] = 0;
  22801. } else if (locaLength === numGlyphsPlusOne << 2) {
  22802. // 0x0001 indicates the loca table consists of long offsets
  22803. data[50] = 0;
  22804. data[51] = 1;
  22805. } else {
  22806. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  22807. }
  22808. }
  22809. }
  22810. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  22811. isGlyphLocationsLong, hintsValid,
  22812. dupFirstEntry) {
  22813. var itemSize, itemDecode, itemEncode;
  22814. if (isGlyphLocationsLong) {
  22815. itemSize = 4;
  22816. itemDecode = function fontItemDecodeLong(data, offset) {
  22817. return (data[offset] << 24) | (data[offset + 1] << 16) |
  22818. (data[offset + 2] << 8) | data[offset + 3];
  22819. };
  22820. itemEncode = function fontItemEncodeLong(data, offset, value) {
  22821. data[offset] = (value >>> 24) & 0xFF;
  22822. data[offset + 1] = (value >> 16) & 0xFF;
  22823. data[offset + 2] = (value >> 8) & 0xFF;
  22824. data[offset + 3] = value & 0xFF;
  22825. };
  22826. } else {
  22827. itemSize = 2;
  22828. itemDecode = function fontItemDecode(data, offset) {
  22829. return (data[offset] << 9) | (data[offset + 1] << 1);
  22830. };
  22831. itemEncode = function fontItemEncode(data, offset, value) {
  22832. data[offset] = (value >> 9) & 0xFF;
  22833. data[offset + 1] = (value >> 1) & 0xFF;
  22834. };
  22835. }
  22836. var locaData = loca.data;
  22837. var locaDataSize = itemSize * (1 + numGlyphs);
  22838. // is loca.data too short or long?
  22839. if (locaData.length !== locaDataSize) {
  22840. locaData = new Uint8Array(locaDataSize);
  22841. locaData.set(loca.data.subarray(0, locaDataSize));
  22842. loca.data = locaData;
  22843. }
  22844. // removing the invalid glyphs
  22845. var oldGlyfData = glyf.data;
  22846. var oldGlyfDataLength = oldGlyfData.length;
  22847. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  22848. var startOffset = itemDecode(locaData, 0);
  22849. var writeOffset = 0;
  22850. var missingGlyphData = {};
  22851. itemEncode(locaData, 0, writeOffset);
  22852. var i, j;
  22853. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  22854. var endOffset = itemDecode(locaData, j);
  22855. if (endOffset > oldGlyfDataLength &&
  22856. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  22857. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  22858. // the glyf table size, which makes last glyph out of range.
  22859. endOffset = oldGlyfDataLength;
  22860. }
  22861. if (endOffset > oldGlyfDataLength) {
  22862. // glyph end offset points outside glyf data, rejecting the glyph
  22863. itemEncode(locaData, j, writeOffset);
  22864. startOffset = endOffset;
  22865. continue;
  22866. }
  22867. if (startOffset === endOffset) {
  22868. missingGlyphData[i] = true;
  22869. }
  22870. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  22871. newGlyfData, writeOffset, hintsValid);
  22872. writeOffset += newLength;
  22873. itemEncode(locaData, j, writeOffset);
  22874. startOffset = endOffset;
  22875. }
  22876. if (writeOffset === 0) {
  22877. // glyf table cannot be empty -- redoing the glyf and loca tables
  22878. // to have single glyph with one point
  22879. var simpleGlyph = new Uint8Array(
  22880. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  22881. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  22882. itemEncode(locaData, j, simpleGlyph.length);
  22883. }
  22884. glyf.data = simpleGlyph;
  22885. return missingGlyphData;
  22886. }
  22887. if (dupFirstEntry) {
  22888. var firstEntryLength = itemDecode(locaData, itemSize);
  22889. if (newGlyfData.length > firstEntryLength + writeOffset) {
  22890. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  22891. } else {
  22892. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  22893. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  22894. }
  22895. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  22896. itemEncode(loca.data, locaData.length - itemSize,
  22897. writeOffset + firstEntryLength);
  22898. } else {
  22899. glyf.data = newGlyfData.subarray(0, writeOffset);
  22900. }
  22901. return missingGlyphData;
  22902. }
  22903. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  22904. var start = (font.start ? font.start : 0) + post.offset;
  22905. font.pos = start;
  22906. var length = post.length, end = start + length;
  22907. var version = font.getInt32();
  22908. // skip rest to the tables
  22909. font.getBytes(28);
  22910. var glyphNames;
  22911. var valid = true;
  22912. var i;
  22913. switch (version) {
  22914. case 0x00010000:
  22915. glyphNames = MacStandardGlyphOrdering;
  22916. break;
  22917. case 0x00020000:
  22918. var numGlyphs = font.getUint16();
  22919. if (numGlyphs !== maxpNumGlyphs) {
  22920. valid = false;
  22921. break;
  22922. }
  22923. var glyphNameIndexes = [];
  22924. for (i = 0; i < numGlyphs; ++i) {
  22925. var index = font.getUint16();
  22926. if (index >= 32768) {
  22927. valid = false;
  22928. break;
  22929. }
  22930. glyphNameIndexes.push(index);
  22931. }
  22932. if (!valid) {
  22933. break;
  22934. }
  22935. var customNames = [];
  22936. var strBuf = [];
  22937. while (font.pos < end) {
  22938. var stringLength = font.getByte();
  22939. strBuf.length = stringLength;
  22940. for (i = 0; i < stringLength; ++i) {
  22941. strBuf[i] = String.fromCharCode(font.getByte());
  22942. }
  22943. customNames.push(strBuf.join(''));
  22944. }
  22945. glyphNames = [];
  22946. for (i = 0; i < numGlyphs; ++i) {
  22947. var j = glyphNameIndexes[i];
  22948. if (j < 258) {
  22949. glyphNames.push(MacStandardGlyphOrdering[j]);
  22950. continue;
  22951. }
  22952. glyphNames.push(customNames[j - 258]);
  22953. }
  22954. break;
  22955. case 0x00030000:
  22956. break;
  22957. default:
  22958. warn('Unknown/unsupported post table version ' + version);
  22959. valid = false;
  22960. if (properties.defaultEncoding) {
  22961. glyphNames = properties.defaultEncoding;
  22962. }
  22963. break;
  22964. }
  22965. properties.glyphNames = glyphNames;
  22966. return valid;
  22967. }
  22968. function readNameTable(nameTable) {
  22969. var start = (font.start ? font.start : 0) + nameTable.offset;
  22970. font.pos = start;
  22971. var names = [[], []];
  22972. var length = nameTable.length, end = start + length;
  22973. var format = font.getUint16();
  22974. var FORMAT_0_HEADER_LENGTH = 6;
  22975. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  22976. // unsupported name table format or table "too" small
  22977. return names;
  22978. }
  22979. var numRecords = font.getUint16();
  22980. var stringsStart = font.getUint16();
  22981. var records = [];
  22982. var NAME_RECORD_LENGTH = 12;
  22983. var i, ii;
  22984. for (i = 0; i < numRecords &&
  22985. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  22986. var r = {
  22987. platform: font.getUint16(),
  22988. encoding: font.getUint16(),
  22989. language: font.getUint16(),
  22990. name: font.getUint16(),
  22991. length: font.getUint16(),
  22992. offset: font.getUint16()
  22993. };
  22994. // using only Macintosh and Windows platform/encoding names
  22995. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  22996. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  22997. records.push(r);
  22998. }
  22999. }
  23000. for (i = 0, ii = records.length; i < ii; i++) {
  23001. var record = records[i];
  23002. var pos = start + stringsStart + record.offset;
  23003. if (pos + record.length > end) {
  23004. continue; // outside of name table, ignoring
  23005. }
  23006. font.pos = pos;
  23007. var nameIndex = record.name;
  23008. if (record.encoding) {
  23009. // unicode
  23010. var str = '';
  23011. for (var j = 0, jj = record.length; j < jj; j += 2) {
  23012. str += String.fromCharCode(font.getUint16());
  23013. }
  23014. names[1][nameIndex] = str;
  23015. } else {
  23016. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  23017. }
  23018. }
  23019. return names;
  23020. }
  23021. var TTOpsStackDeltas = [
  23022. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  23023. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  23024. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  23025. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  23026. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  23027. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  23028. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  23029. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  23030. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  23031. // 0xC0-DF == -1 and 0xE0-FF == -2
  23032. function sanitizeTTProgram(table, ttContext) {
  23033. var data = table.data;
  23034. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  23035. var stack = [];
  23036. var callstack = [];
  23037. var functionsCalled = [];
  23038. var tooComplexToFollowFunctions =
  23039. ttContext.tooComplexToFollowFunctions;
  23040. var inFDEF = false, ifLevel = 0, inELSE = 0;
  23041. for (var ii = data.length; i < ii;) {
  23042. var op = data[i++];
  23043. // The TrueType instruction set docs can be found at
  23044. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  23045. if (op === 0x40) { // NPUSHB - pushes n bytes
  23046. n = data[i++];
  23047. if (inFDEF || inELSE) {
  23048. i += n;
  23049. } else {
  23050. for (j = 0; j < n; j++) {
  23051. stack.push(data[i++]);
  23052. }
  23053. }
  23054. } else if (op === 0x41) { // NPUSHW - pushes n words
  23055. n = data[i++];
  23056. if (inFDEF || inELSE) {
  23057. i += n * 2;
  23058. } else {
  23059. for (j = 0; j < n; j++) {
  23060. b = data[i++];
  23061. stack.push((b << 8) | data[i++]);
  23062. }
  23063. }
  23064. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  23065. n = op - 0xB0 + 1;
  23066. if (inFDEF || inELSE) {
  23067. i += n;
  23068. } else {
  23069. for (j = 0; j < n; j++) {
  23070. stack.push(data[i++]);
  23071. }
  23072. }
  23073. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  23074. n = op - 0xB8 + 1;
  23075. if (inFDEF || inELSE) {
  23076. i += n * 2;
  23077. } else {
  23078. for (j = 0; j < n; j++) {
  23079. b = data[i++];
  23080. stack.push((b << 8) | data[i++]);
  23081. }
  23082. }
  23083. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  23084. if (!inFDEF && !inELSE) {
  23085. // collecting inforamtion about which functions are used
  23086. funcId = stack[stack.length - 1];
  23087. ttContext.functionsUsed[funcId] = true;
  23088. if (funcId in ttContext.functionsStackDeltas) {
  23089. stack.length += ttContext.functionsStackDeltas[funcId];
  23090. } else if (funcId in ttContext.functionsDefined &&
  23091. functionsCalled.indexOf(funcId) < 0) {
  23092. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  23093. functionsCalled.push(funcId);
  23094. pc = ttContext.functionsDefined[funcId];
  23095. if (!pc) {
  23096. warn('TT: CALL non-existent function');
  23097. ttContext.hintsValid = false;
  23098. return;
  23099. }
  23100. data = pc.data;
  23101. i = pc.i;
  23102. }
  23103. }
  23104. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  23105. if (inFDEF || inELSE) {
  23106. warn('TT: nested FDEFs not allowed');
  23107. tooComplexToFollowFunctions = true;
  23108. }
  23109. inFDEF = true;
  23110. // collecting inforamtion about which functions are defined
  23111. lastDeff = i;
  23112. funcId = stack.pop();
  23113. ttContext.functionsDefined[funcId] = {data: data, i: i};
  23114. } else if (op === 0x2D) { // ENDF - end of function
  23115. if (inFDEF) {
  23116. inFDEF = false;
  23117. lastEndf = i;
  23118. } else {
  23119. pc = callstack.pop();
  23120. if (!pc) {
  23121. warn('TT: ENDF bad stack');
  23122. ttContext.hintsValid = false;
  23123. return;
  23124. }
  23125. funcId = functionsCalled.pop();
  23126. data = pc.data;
  23127. i = pc.i;
  23128. ttContext.functionsStackDeltas[funcId] =
  23129. stack.length - pc.stackTop;
  23130. }
  23131. } else if (op === 0x89) { // IDEF - instruction definition
  23132. if (inFDEF || inELSE) {
  23133. warn('TT: nested IDEFs not allowed');
  23134. tooComplexToFollowFunctions = true;
  23135. }
  23136. inFDEF = true;
  23137. // recording it as a function to track ENDF
  23138. lastDeff = i;
  23139. } else if (op === 0x58) { // IF
  23140. ++ifLevel;
  23141. } else if (op === 0x1B) { // ELSE
  23142. inELSE = ifLevel;
  23143. } else if (op === 0x59) { // EIF
  23144. if (inELSE === ifLevel) {
  23145. inELSE = 0;
  23146. }
  23147. --ifLevel;
  23148. } else if (op === 0x1C) { // JMPR
  23149. if (!inFDEF && !inELSE) {
  23150. var offset = stack[stack.length - 1];
  23151. // only jumping forward to prevent infinite loop
  23152. if (offset > 0) {
  23153. i += offset - 1;
  23154. }
  23155. }
  23156. }
  23157. // Adjusting stack not extactly, but just enough to get function id
  23158. if (!inFDEF && !inELSE) {
  23159. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  23160. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  23161. if (op >= 0x71 && op <= 0x75) {
  23162. n = stack.pop();
  23163. if (n === n) {
  23164. stackDelta = -n * 2;
  23165. }
  23166. }
  23167. while (stackDelta < 0 && stack.length > 0) {
  23168. stack.pop();
  23169. stackDelta++;
  23170. }
  23171. while (stackDelta > 0) {
  23172. stack.push(NaN); // pushing any number into stack
  23173. stackDelta--;
  23174. }
  23175. }
  23176. }
  23177. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  23178. var content = [data];
  23179. if (i > data.length) {
  23180. content.push(new Uint8Array(i - data.length));
  23181. }
  23182. if (lastDeff > lastEndf) {
  23183. warn('TT: complementing a missing function tail');
  23184. // new function definition started, but not finished
  23185. // complete function by [CLEAR, ENDF]
  23186. content.push(new Uint8Array([0x22, 0x2D]));
  23187. }
  23188. foldTTTable(table, content);
  23189. }
  23190. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  23191. if (ttContext.tooComplexToFollowFunctions) {
  23192. return;
  23193. }
  23194. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  23195. warn('TT: more functions defined than expected');
  23196. ttContext.hintsValid = false;
  23197. return;
  23198. }
  23199. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  23200. if (j > maxFunctionDefs) {
  23201. warn('TT: invalid function id: ' + j);
  23202. ttContext.hintsValid = false;
  23203. return;
  23204. }
  23205. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  23206. warn('TT: undefined function: ' + j);
  23207. ttContext.hintsValid = false;
  23208. return;
  23209. }
  23210. }
  23211. }
  23212. function foldTTTable(table, content) {
  23213. if (content.length > 1) {
  23214. // concatenating the content items
  23215. var newLength = 0;
  23216. var j, jj;
  23217. for (j = 0, jj = content.length; j < jj; j++) {
  23218. newLength += content[j].length;
  23219. }
  23220. newLength = (newLength + 3) & ~3;
  23221. var result = new Uint8Array(newLength);
  23222. var pos = 0;
  23223. for (j = 0, jj = content.length; j < jj; j++) {
  23224. result.set(content[j], pos);
  23225. pos += content[j].length;
  23226. }
  23227. table.data = result;
  23228. table.length = newLength;
  23229. }
  23230. }
  23231. function sanitizeTTPrograms(fpgm, prep, cvt) {
  23232. var ttContext = {
  23233. functionsDefined: [],
  23234. functionsUsed: [],
  23235. functionsStackDeltas: [],
  23236. tooComplexToFollowFunctions: false,
  23237. hintsValid: true
  23238. };
  23239. if (fpgm) {
  23240. sanitizeTTProgram(fpgm, ttContext);
  23241. }
  23242. if (prep) {
  23243. sanitizeTTProgram(prep, ttContext);
  23244. }
  23245. if (fpgm) {
  23246. checkInvalidFunctions(ttContext, maxFunctionDefs);
  23247. }
  23248. if (cvt && (cvt.length & 1)) {
  23249. var cvtData = new Uint8Array(cvt.length + 1);
  23250. cvtData.set(cvt.data);
  23251. cvt.data = cvtData;
  23252. }
  23253. return ttContext.hintsValid;
  23254. }
  23255. // The following steps modify the original font data, making copy
  23256. font = new Stream(new Uint8Array(font.getBytes()));
  23257. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  23258. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  23259. var header = readOpenTypeHeader(font);
  23260. var numTables = header.numTables;
  23261. var cff, cffFile;
  23262. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  23263. hmtx: null, maxp: null, name: null, post: null };
  23264. var table;
  23265. for (var i = 0; i < numTables; i++) {
  23266. table = readTableEntry(font);
  23267. if (VALID_TABLES.indexOf(table.tag) < 0) {
  23268. continue; // skipping table if it's not a required or optional table
  23269. }
  23270. if (table.length === 0) {
  23271. continue; // skipping empty tables
  23272. }
  23273. tables[table.tag] = table;
  23274. }
  23275. var isTrueType = !tables['CFF '];
  23276. if (!isTrueType) {
  23277. // OpenType font
  23278. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  23279. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  23280. // no major tables: throwing everything at CFFFont
  23281. cffFile = new Stream(tables['CFF '].data);
  23282. cff = new CFFFont(cffFile, properties);
  23283. return this.convert(name, cff, properties);
  23284. }
  23285. delete tables.glyf;
  23286. delete tables.loca;
  23287. delete tables.fpgm;
  23288. delete tables.prep;
  23289. delete tables['cvt '];
  23290. this.isOpenType = true;
  23291. } else {
  23292. if (!tables.glyf || !tables.loca) {
  23293. error('Required "glyf" or "loca" tables are not found');
  23294. }
  23295. this.isOpenType = false;
  23296. }
  23297. if (!tables.maxp) {
  23298. error('Required "maxp" table is not found');
  23299. }
  23300. font.pos = (font.start || 0) + tables.maxp.offset;
  23301. var version = font.getInt32();
  23302. var numGlyphs = font.getUint16();
  23303. var maxFunctionDefs = 0;
  23304. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  23305. // maxZones can be invalid
  23306. font.pos += 8;
  23307. var maxZones = font.getUint16();
  23308. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  23309. tables.maxp.data[14] = 0;
  23310. tables.maxp.data[15] = 2;
  23311. }
  23312. font.pos += 4;
  23313. maxFunctionDefs = font.getUint16();
  23314. }
  23315. var dupFirstEntry = false;
  23316. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  23317. properties.toUnicode.get(0) > '\u0000') {
  23318. // oracle's defect (see 3427), duplicating first entry
  23319. dupFirstEntry = true;
  23320. numGlyphs++;
  23321. tables.maxp.data[4] = numGlyphs >> 8;
  23322. tables.maxp.data[5] = numGlyphs & 255;
  23323. }
  23324. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  23325. tables['cvt '], maxFunctionDefs);
  23326. if (!hintsValid) {
  23327. delete tables.fpgm;
  23328. delete tables.prep;
  23329. delete tables['cvt '];
  23330. }
  23331. // Ensure the hmtx table contains the advance width and
  23332. // sidebearings information for numGlyphs in the maxp table
  23333. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  23334. if (!tables.head) {
  23335. error('Required "head" table is not found');
  23336. }
  23337. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  23338. var missingGlyphs = {};
  23339. if (isTrueType) {
  23340. var isGlyphLocationsLong = int16(tables.head.data[50],
  23341. tables.head.data[51]);
  23342. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  23343. numGlyphs, isGlyphLocationsLong,
  23344. hintsValid, dupFirstEntry);
  23345. }
  23346. if (!tables.hhea) {
  23347. error('Required "hhea" table is not found');
  23348. }
  23349. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  23350. // Sometimes it's 0. That needs to be fixed
  23351. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  23352. tables.hhea.data[10] = 0xFF;
  23353. tables.hhea.data[11] = 0xFF;
  23354. }
  23355. // Extract some more font properties from the OpenType head and
  23356. // hhea tables; yMin and descent value are always negative.
  23357. var metricsOverride = {
  23358. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  23359. yMax: int16(tables.head.data[42], tables.head.data[43]),
  23360. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  23361. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  23362. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  23363. };
  23364. // PDF FontDescriptor metrics lie -- using data from actual font.
  23365. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  23366. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  23367. // The 'post' table has glyphs names.
  23368. if (tables.post) {
  23369. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  23370. if (!valid) {
  23371. tables.post = null;
  23372. }
  23373. }
  23374. var charCodeToGlyphId = [], charCode;
  23375. var toUnicode = properties.toUnicode, widths = properties.widths;
  23376. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  23377. toUnicode.length === 0x10000);
  23378. // Helper function to try to skip mapping of empty glyphs.
  23379. // Note: In some cases, just relying on the glyph data doesn't work,
  23380. // hence we also use a few heuristics to fix various PDF files.
  23381. function hasGlyph(glyphId, charCode, widthCode) {
  23382. if (!missingGlyphs[glyphId]) {
  23383. return true;
  23384. }
  23385. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  23386. return true;
  23387. }
  23388. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  23389. return true;
  23390. }
  23391. return false;
  23392. }
  23393. if (properties.type === 'CIDFontType2') {
  23394. var cidToGidMap = properties.cidToGidMap || [];
  23395. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  23396. properties.cMap.forEach(function(charCode, cid) {
  23397. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  23398. var glyphId = -1;
  23399. if (isCidToGidMapEmpty) {
  23400. glyphId = charCode;
  23401. } else if (cidToGidMap[cid] !== undefined) {
  23402. glyphId = cidToGidMap[cid];
  23403. }
  23404. if (glyphId >= 0 && glyphId < numGlyphs &&
  23405. hasGlyph(glyphId, charCode, cid)) {
  23406. charCodeToGlyphId[charCode] = glyphId;
  23407. }
  23408. });
  23409. if (dupFirstEntry) {
  23410. charCodeToGlyphId[0] = numGlyphs - 1;
  23411. }
  23412. } else {
  23413. // Most of the following logic in this code branch is based on the
  23414. // 9.6.6.4 of the PDF spec.
  23415. var hasEncoding =
  23416. properties.differences.length > 0 || !!properties.baseEncodingName;
  23417. var cmapTable =
  23418. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  23419. var cmapPlatformId = cmapTable.platformId;
  23420. var cmapEncodingId = cmapTable.encodingId;
  23421. var cmapMappings = cmapTable.mappings;
  23422. var cmapMappingsLength = cmapMappings.length;
  23423. // The spec seems to imply that if the font is symbolic the encoding
  23424. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  23425. // where the the font is symbolic and it has an encoding.
  23426. if (hasEncoding &&
  23427. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  23428. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  23429. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  23430. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  23431. // When no preferred cmap table was found and |baseEncodingName| is
  23432. // one of the predefined encodings, we seem to obtain a better
  23433. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  23434. // TODO: Note that this is a hack which should be removed as soon as
  23435. // we have proper support for more exotic cmap tables.
  23436. var baseEncoding = [];
  23437. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  23438. properties.baseEncodingName === 'WinAnsiEncoding') {
  23439. baseEncoding = Encodings[properties.baseEncodingName];
  23440. }
  23441. for (charCode = 0; charCode < 256; charCode++) {
  23442. var glyphName;
  23443. if (this.differences && charCode in this.differences) {
  23444. glyphName = this.differences[charCode];
  23445. } else if (charCode in baseEncoding &&
  23446. baseEncoding[charCode] !== '') {
  23447. glyphName = baseEncoding[charCode];
  23448. } else {
  23449. glyphName = Encodings.StandardEncoding[charCode];
  23450. }
  23451. if (!glyphName) {
  23452. continue;
  23453. }
  23454. var unicodeOrCharCode, isUnicode = false;
  23455. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  23456. unicodeOrCharCode = GlyphsUnicode[glyphName];
  23457. isUnicode = true;
  23458. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  23459. // TODO: the encoding needs to be updated with mac os table.
  23460. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  23461. }
  23462. var found = false;
  23463. for (i = 0; i < cmapMappingsLength; ++i) {
  23464. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  23465. continue;
  23466. }
  23467. var code = isUnicode ? charCode : unicodeOrCharCode;
  23468. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  23469. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  23470. found = true;
  23471. break;
  23472. }
  23473. }
  23474. if (!found && properties.glyphNames) {
  23475. // Try to map using the post table.
  23476. var glyphId = properties.glyphNames.indexOf(glyphName);
  23477. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  23478. charCodeToGlyphId[charCode] = glyphId;
  23479. } else {
  23480. charCodeToGlyphId[charCode] = 0; // notdef
  23481. }
  23482. }
  23483. }
  23484. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  23485. // Default Unicode semantics, use the charcodes as is.
  23486. for (i = 0; i < cmapMappingsLength; ++i) {
  23487. charCodeToGlyphId[cmapMappings[i].charCode] =
  23488. cmapMappings[i].glyphId;
  23489. }
  23490. } else {
  23491. // For (3, 0) cmap tables:
  23492. // The charcode key being stored in charCodeToGlyphId is the lower
  23493. // byte of the two-byte charcodes of the cmap table since according to
  23494. // the spec: 'each byte from the string shall be prepended with the
  23495. // high byte of the range [of charcodes in the cmap table], to form
  23496. // a two-byte character, which shall be used to select the
  23497. // associated glyph description from the subtable'.
  23498. //
  23499. // For (1, 0) cmap tables:
  23500. // 'single bytes from the string shall be used to look up the
  23501. // associated glyph descriptions from the subtable'. This means
  23502. // charcodes in the cmap will be single bytes, so no-op since
  23503. // glyph.charCode & 0xFF === glyph.charCode
  23504. for (i = 0; i < cmapMappingsLength; ++i) {
  23505. charCode = cmapMappings[i].charCode & 0xFF;
  23506. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  23507. }
  23508. }
  23509. }
  23510. if (charCodeToGlyphId.length === 0) {
  23511. // defines at least one glyph
  23512. charCodeToGlyphId[0] = 0;
  23513. }
  23514. // Converting glyphs and ids into font's cmap table
  23515. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  23516. this.toFontChar = newMapping.toFontChar;
  23517. tables.cmap = {
  23518. tag: 'cmap',
  23519. data: createCmapTable(newMapping.charCodeToGlyphId)
  23520. };
  23521. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  23522. tables['OS/2'] = {
  23523. tag: 'OS/2',
  23524. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  23525. metricsOverride)
  23526. };
  23527. }
  23528. // Rewrite the 'post' table if needed
  23529. if (!tables.post) {
  23530. tables.post = {
  23531. tag: 'post',
  23532. data: createPostTable(properties)
  23533. };
  23534. }
  23535. if (!isTrueType) {
  23536. try {
  23537. // Trying to repair CFF file
  23538. cffFile = new Stream(tables['CFF '].data);
  23539. var parser = new CFFParser(cffFile, properties);
  23540. cff = parser.parse();
  23541. var compiler = new CFFCompiler(cff);
  23542. tables['CFF '].data = compiler.compile();
  23543. } catch (e) {
  23544. warn('Failed to compile font ' + properties.loadedName);
  23545. }
  23546. }
  23547. // Re-creating 'name' table
  23548. if (!tables.name) {
  23549. tables.name = {
  23550. tag: 'name',
  23551. data: createNameTable(this.name)
  23552. };
  23553. } else {
  23554. // ... using existing 'name' table as prototype
  23555. var namePrototype = readNameTable(tables.name);
  23556. tables.name.data = createNameTable(name, namePrototype);
  23557. }
  23558. var builder = new OpenTypeFileBuilder(header.version);
  23559. for (var tableTag in tables) {
  23560. builder.addTable(tableTag, tables[tableTag].data);
  23561. }
  23562. return builder.toArray();
  23563. },
  23564. convert: function Font_convert(fontName, font, properties) {
  23565. // TODO: Check the charstring widths to determine this.
  23566. properties.fixedPitch = false;
  23567. var mapping = font.getGlyphMapping(properties);
  23568. var newMapping = adjustMapping(mapping, properties);
  23569. this.toFontChar = newMapping.toFontChar;
  23570. var numGlyphs = font.numGlyphs;
  23571. function getCharCodes(charCodeToGlyphId, glyphId) {
  23572. var charCodes = null;
  23573. for (var charCode in charCodeToGlyphId) {
  23574. if (glyphId === charCodeToGlyphId[charCode]) {
  23575. if (!charCodes) {
  23576. charCodes = [];
  23577. }
  23578. charCodes.push(charCode | 0);
  23579. }
  23580. }
  23581. return charCodes;
  23582. }
  23583. function createCharCode(charCodeToGlyphId, glyphId) {
  23584. for (var charCode in charCodeToGlyphId) {
  23585. if (glyphId === charCodeToGlyphId[charCode]) {
  23586. return charCode | 0;
  23587. }
  23588. }
  23589. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  23590. glyphId;
  23591. return newMapping.nextAvailableFontCharCode++;
  23592. }
  23593. var seacs = font.seacs;
  23594. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  23595. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  23596. var charset = font.getCharset();
  23597. var seacMap = Object.create(null);
  23598. for (var glyphId in seacs) {
  23599. glyphId |= 0;
  23600. var seac = seacs[glyphId];
  23601. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  23602. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  23603. var baseGlyphId = charset.indexOf(baseGlyphName);
  23604. var accentGlyphId = charset.indexOf(accentGlyphName);
  23605. if (baseGlyphId < 0 || accentGlyphId < 0) {
  23606. continue;
  23607. }
  23608. var accentOffset = {
  23609. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  23610. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  23611. };
  23612. var charCodes = getCharCodes(mapping, glyphId);
  23613. if (!charCodes) {
  23614. // There's no point in mapping it if the char code was never mapped
  23615. // to begin with.
  23616. continue;
  23617. }
  23618. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  23619. var charCode = charCodes[i];
  23620. // Find a fontCharCode that maps to the base and accent glyphs.
  23621. // If one doesn't exists, create it.
  23622. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  23623. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  23624. baseGlyphId);
  23625. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  23626. accentGlyphId);
  23627. seacMap[charCode] = {
  23628. baseFontCharCode: baseFontCharCode,
  23629. accentFontCharCode: accentFontCharCode,
  23630. accentOffset: accentOffset
  23631. };
  23632. }
  23633. }
  23634. properties.seacMap = seacMap;
  23635. }
  23636. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  23637. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  23638. // PostScript Font Program
  23639. builder.addTable('CFF ', font.data);
  23640. // OS/2 and Windows Specific metrics
  23641. builder.addTable('OS/2', createOS2Table(properties,
  23642. newMapping.charCodeToGlyphId));
  23643. // Character to glyphs mapping
  23644. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  23645. // Font header
  23646. builder.addTable('head',
  23647. '\x00\x01\x00\x00' + // Version number
  23648. '\x00\x00\x10\x00' + // fontRevision
  23649. '\x00\x00\x00\x00' + // checksumAdjustement
  23650. '\x5F\x0F\x3C\xF5' + // magicNumber
  23651. '\x00\x00' + // Flags
  23652. safeString16(unitsPerEm) + // unitsPerEM
  23653. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  23654. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  23655. '\x00\x00' + // xMin
  23656. safeString16(properties.descent) + // yMin
  23657. '\x0F\xFF' + // xMax
  23658. safeString16(properties.ascent) + // yMax
  23659. string16(properties.italicAngle ? 2 : 0) + // macStyle
  23660. '\x00\x11' + // lowestRecPPEM
  23661. '\x00\x00' + // fontDirectionHint
  23662. '\x00\x00' + // indexToLocFormat
  23663. '\x00\x00'); // glyphDataFormat
  23664. // Horizontal header
  23665. builder.addTable('hhea',
  23666. '\x00\x01\x00\x00' + // Version number
  23667. safeString16(properties.ascent) + // Typographic Ascent
  23668. safeString16(properties.descent) + // Typographic Descent
  23669. '\x00\x00' + // Line Gap
  23670. '\xFF\xFF' + // advanceWidthMax
  23671. '\x00\x00' + // minLeftSidebearing
  23672. '\x00\x00' + // minRightSidebearing
  23673. '\x00\x00' + // xMaxExtent
  23674. safeString16(properties.capHeight) + // caretSlopeRise
  23675. safeString16(Math.tan(properties.italicAngle) *
  23676. properties.xHeight) + // caretSlopeRun
  23677. '\x00\x00' + // caretOffset
  23678. '\x00\x00' + // -reserved-
  23679. '\x00\x00' + // -reserved-
  23680. '\x00\x00' + // -reserved-
  23681. '\x00\x00' + // -reserved-
  23682. '\x00\x00' + // metricDataFormat
  23683. string16(numGlyphs)); // Number of HMetrics
  23684. // Horizontal metrics
  23685. builder.addTable('hmtx', (function fontFieldsHmtx() {
  23686. var charstrings = font.charstrings;
  23687. var cffWidths = font.cff ? font.cff.widths : null;
  23688. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  23689. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  23690. var width = 0;
  23691. if (charstrings) {
  23692. var charstring = charstrings[i - 1];
  23693. width = 'width' in charstring ? charstring.width : 0;
  23694. } else if (cffWidths) {
  23695. width = Math.ceil(cffWidths[i] || 0);
  23696. }
  23697. hmtx += string16(width) + string16(0);
  23698. }
  23699. return hmtx;
  23700. })());
  23701. // Maximum profile
  23702. builder.addTable('maxp',
  23703. '\x00\x00\x50\x00' + // Version number
  23704. string16(numGlyphs)); // Num of glyphs
  23705. // Naming tables
  23706. builder.addTable('name', createNameTable(fontName));
  23707. // PostScript informations
  23708. builder.addTable('post', createPostTable(properties));
  23709. return builder.toArray();
  23710. },
  23711. /**
  23712. * Builds a char code to unicode map based on section 9.10 of the spec.
  23713. * @param {Object} properties Font properties object.
  23714. * @return {Object} A ToUnicodeMap object.
  23715. */
  23716. buildToUnicode: function Font_buildToUnicode(properties) {
  23717. // Section 9.10.2 Mapping Character Codes to Unicode Values
  23718. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  23719. return properties.toUnicode;
  23720. }
  23721. // According to the spec if the font is a simple font we should only map
  23722. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  23723. // the differences array only contains adobe standard or symbol set names,
  23724. // in pratice it seems better to always try to create a toUnicode
  23725. // map based of the default encoding.
  23726. var toUnicode, charcode;
  23727. if (!properties.composite /* is simple font */) {
  23728. toUnicode = [];
  23729. var encoding = properties.defaultEncoding.slice();
  23730. var baseEncodingName = properties.baseEncodingName;
  23731. // Merge in the differences array.
  23732. var differences = properties.differences;
  23733. for (charcode in differences) {
  23734. encoding[charcode] = differences[charcode];
  23735. }
  23736. for (charcode in encoding) {
  23737. // a) Map the character code to a character name.
  23738. var glyphName = encoding[charcode];
  23739. // b) Look up the character name in the Adobe Glyph List (see the
  23740. // Bibliography) to obtain the corresponding Unicode value.
  23741. if (glyphName === '') {
  23742. continue;
  23743. } else if (GlyphsUnicode[glyphName] === undefined) {
  23744. // (undocumented) c) Few heuristics to recognize unknown glyphs
  23745. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  23746. var code = 0;
  23747. switch (glyphName[0]) {
  23748. case 'G': // Gxx glyph
  23749. if (glyphName.length === 3) {
  23750. code = parseInt(glyphName.substr(1), 16);
  23751. }
  23752. break;
  23753. case 'g': // g00xx glyph
  23754. if (glyphName.length === 5) {
  23755. code = parseInt(glyphName.substr(1), 16);
  23756. }
  23757. break;
  23758. case 'C': // Cddd glyph
  23759. case 'c': // cddd glyph
  23760. if (glyphName.length >= 3) {
  23761. code = +glyphName.substr(1);
  23762. }
  23763. break;
  23764. }
  23765. if (code) {
  23766. // If |baseEncodingName| is one the predefined encodings,
  23767. // and |code| equals |charcode|, using the glyph defined in the
  23768. // baseEncoding seems to yield a better |toUnicode| mapping
  23769. // (fixes issue 5070).
  23770. if (baseEncodingName && code === +charcode) {
  23771. var baseEncoding = Encodings[baseEncodingName];
  23772. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  23773. toUnicode[charcode] =
  23774. String.fromCharCode(GlyphsUnicode[glyphName]);
  23775. continue;
  23776. }
  23777. }
  23778. toUnicode[charcode] = String.fromCharCode(code);
  23779. }
  23780. continue;
  23781. }
  23782. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  23783. }
  23784. return new ToUnicodeMap(toUnicode);
  23785. }
  23786. // If the font is a composite font that uses one of the predefined CMaps
  23787. // listed in Table 118 (except Identity–H and Identity–V) or whose
  23788. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  23789. // Adobe-Korea1 character collection:
  23790. if (properties.composite && (
  23791. (properties.cMap.builtInCMap &&
  23792. !(properties.cMap instanceof IdentityCMap)) ||
  23793. (properties.cidSystemInfo.registry === 'Adobe' &&
  23794. (properties.cidSystemInfo.ordering === 'GB1' ||
  23795. properties.cidSystemInfo.ordering === 'CNS1' ||
  23796. properties.cidSystemInfo.ordering === 'Japan1' ||
  23797. properties.cidSystemInfo.ordering === 'Korea1')))) {
  23798. // Then:
  23799. // a) Map the character code to a character identifier (CID) according
  23800. // to the font’s CMap.
  23801. // b) Obtain the registry and ordering of the character collection used
  23802. // by the font’s CMap (for example, Adobe and Japan1) from its
  23803. // CIDSystemInfo dictionary.
  23804. var registry = properties.cidSystemInfo.registry;
  23805. var ordering = properties.cidSystemInfo.ordering;
  23806. // c) Construct a second CMap name by concatenating the registry and
  23807. // ordering obtained in step (b) in the format registry–ordering–UCS2
  23808. // (for example, Adobe–Japan1–UCS2).
  23809. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  23810. // d) Obtain the CMap with the name constructed in step (c) (available
  23811. // from the ASN Web site; see the Bibliography).
  23812. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  23813. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  23814. var cMap = properties.cMap;
  23815. toUnicode = [];
  23816. cMap.forEach(function(charcode, cid) {
  23817. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  23818. // e) Map the CID obtained in step (a) according to the CMap obtained
  23819. // in step (d), producing a Unicode value.
  23820. var ucs2 = ucs2CMap.lookup(cid);
  23821. if (ucs2) {
  23822. toUnicode[charcode] =
  23823. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  23824. ucs2.charCodeAt(1));
  23825. }
  23826. });
  23827. return new ToUnicodeMap(toUnicode);
  23828. }
  23829. // The viewer's choice, just use an identity map.
  23830. return new IdentityToUnicodeMap(properties.firstChar,
  23831. properties.lastChar);
  23832. },
  23833. get spaceWidth() {
  23834. if ('_shadowWidth' in this) {
  23835. return this._shadowWidth;
  23836. }
  23837. // trying to estimate space character width
  23838. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  23839. var width;
  23840. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  23841. var glyphName = possibleSpaceReplacements[i];
  23842. // if possible, getting width by glyph name
  23843. if (glyphName in this.widths) {
  23844. width = this.widths[glyphName];
  23845. break;
  23846. }
  23847. var glyphUnicode = GlyphsUnicode[glyphName];
  23848. // finding the charcode via unicodeToCID map
  23849. var charcode = 0;
  23850. if (this.composite) {
  23851. if (this.cMap.contains(glyphUnicode)) {
  23852. charcode = this.cMap.lookup(glyphUnicode);
  23853. }
  23854. }
  23855. // ... via toUnicode map
  23856. if (!charcode && 'toUnicode' in this) {
  23857. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  23858. }
  23859. // setting it to unicode if negative or undefined
  23860. if (charcode <= 0) {
  23861. charcode = glyphUnicode;
  23862. }
  23863. // trying to get width via charcode
  23864. width = this.widths[charcode];
  23865. if (width) {
  23866. break; // the non-zero width found
  23867. }
  23868. }
  23869. width = width || this.defaultWidth;
  23870. // Do not shadow the property here. See discussion:
  23871. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  23872. this._shadowWidth = width;
  23873. return width;
  23874. },
  23875. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  23876. var fontCharCode, width, operatorListId;
  23877. var widthCode = charcode;
  23878. if (this.cMap && this.cMap.contains(charcode)) {
  23879. widthCode = this.cMap.lookup(charcode);
  23880. }
  23881. width = this.widths[widthCode];
  23882. width = isNum(width) ? width : this.defaultWidth;
  23883. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  23884. var unicode = this.toUnicode.get(charcode) || charcode;
  23885. if (typeof unicode === 'number') {
  23886. unicode = String.fromCharCode(unicode);
  23887. }
  23888. // First try the toFontChar map, if it's not there then try falling
  23889. // back to the char code.
  23890. fontCharCode = this.toFontChar[charcode] || charcode;
  23891. if (this.missingFile) {
  23892. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  23893. }
  23894. if (this.isType3Font) {
  23895. // Font char code in this case is actually a glyph name.
  23896. operatorListId = fontCharCode;
  23897. }
  23898. var accent = null;
  23899. if (this.seacMap && this.seacMap[charcode]) {
  23900. var seac = this.seacMap[charcode];
  23901. fontCharCode = seac.baseFontCharCode;
  23902. accent = {
  23903. fontChar: String.fromCharCode(seac.accentFontCharCode),
  23904. offset: seac.accentOffset
  23905. };
  23906. }
  23907. var fontChar = String.fromCharCode(fontCharCode);
  23908. var glyph = this.glyphCache[charcode];
  23909. if (!glyph ||
  23910. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  23911. operatorListId, isSpace)) {
  23912. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  23913. operatorListId, isSpace);
  23914. this.glyphCache[charcode] = glyph;
  23915. }
  23916. return glyph;
  23917. },
  23918. charsToGlyphs: function Font_charsToGlyphs(chars) {
  23919. var charsCache = this.charsCache;
  23920. var glyphs, glyph, charcode;
  23921. // if we translated this string before, just grab it from the cache
  23922. if (charsCache) {
  23923. glyphs = charsCache[chars];
  23924. if (glyphs) {
  23925. return glyphs;
  23926. }
  23927. }
  23928. // lazily create the translation cache
  23929. if (!charsCache) {
  23930. charsCache = this.charsCache = Object.create(null);
  23931. }
  23932. glyphs = [];
  23933. var charsCacheKey = chars;
  23934. var i = 0, ii;
  23935. if (this.cMap) {
  23936. // composite fonts have multi-byte strings convert the string from
  23937. // single-byte to multi-byte
  23938. var c = {};
  23939. while (i < chars.length) {
  23940. this.cMap.readCharCode(chars, i, c);
  23941. charcode = c.charcode;
  23942. var length = c.length;
  23943. i += length;
  23944. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  23945. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  23946. glyph = this.charToGlyph(charcode, isSpace);
  23947. glyphs.push(glyph);
  23948. }
  23949. } else {
  23950. for (i = 0, ii = chars.length; i < ii; ++i) {
  23951. charcode = chars.charCodeAt(i);
  23952. glyph = this.charToGlyph(charcode, charcode === 0x20);
  23953. glyphs.push(glyph);
  23954. }
  23955. }
  23956. // Enter the translated string into the cache
  23957. return (charsCache[charsCacheKey] = glyphs);
  23958. }
  23959. };
  23960. return Font;
  23961. })();
  23962. var ErrorFont = (function ErrorFontClosure() {
  23963. function ErrorFont(error) {
  23964. this.error = error;
  23965. this.loadedName = 'g_font_error';
  23966. this.loading = false;
  23967. }
  23968. ErrorFont.prototype = {
  23969. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  23970. return [];
  23971. },
  23972. exportData: function ErrorFont_exportData() {
  23973. return {error: this.error};
  23974. }
  23975. };
  23976. return ErrorFont;
  23977. })();
  23978. /**
  23979. * Shared logic for building a char code to glyph id mapping for Type1 and
  23980. * simple CFF fonts. See section 9.6.6.2 of the spec.
  23981. * @param {Object} properties Font properties object.
  23982. * @param {Object} builtInEncoding The encoding contained within the actual font
  23983. * data.
  23984. * @param {Array} Array of glyph names where the index is the glyph ID.
  23985. * @returns {Object} A char code to glyph ID map.
  23986. */
  23987. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  23988. var charCodeToGlyphId = Object.create(null);
  23989. var glyphId, charCode, baseEncoding;
  23990. if (properties.baseEncodingName) {
  23991. // If a valid base encoding name was used, the mapping is initialized with
  23992. // that.
  23993. baseEncoding = Encodings[properties.baseEncodingName];
  23994. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  23995. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  23996. if (glyphId >= 0) {
  23997. charCodeToGlyphId[charCode] = glyphId;
  23998. } else {
  23999. charCodeToGlyphId[charCode] = 0; // notdef
  24000. }
  24001. }
  24002. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  24003. // For a symbolic font the encoding should be the fonts built-in
  24004. // encoding.
  24005. for (charCode in builtInEncoding) {
  24006. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  24007. }
  24008. } else {
  24009. // For non-symbolic fonts that don't have a base encoding the standard
  24010. // encoding should be used.
  24011. baseEncoding = Encodings.StandardEncoding;
  24012. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  24013. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  24014. if (glyphId >= 0) {
  24015. charCodeToGlyphId[charCode] = glyphId;
  24016. } else {
  24017. charCodeToGlyphId[charCode] = 0; // notdef
  24018. }
  24019. }
  24020. }
  24021. // Lastly, merge in the differences.
  24022. var differences = properties.differences;
  24023. if (differences) {
  24024. for (charCode in differences) {
  24025. var glyphName = differences[charCode];
  24026. glyphId = glyphNames.indexOf(glyphName);
  24027. if (glyphId >= 0) {
  24028. charCodeToGlyphId[charCode] = glyphId;
  24029. } else {
  24030. charCodeToGlyphId[charCode] = 0; // notdef
  24031. }
  24032. }
  24033. }
  24034. return charCodeToGlyphId;
  24035. }
  24036. /*
  24037. * CharStrings are encoded following the the CharString Encoding sequence
  24038. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  24039. * The value in a byte indicates a command, a number, or subsequent bytes
  24040. * that are to be interpreted in a special way.
  24041. *
  24042. * CharString Number Encoding:
  24043. * A CharString byte containing the values from 32 through 255 inclusive
  24044. * indicate an integer. These values are decoded in four ranges.
  24045. *
  24046. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  24047. * indicate the integer v - 139. Thus, the integer values from -107 through
  24048. * 107 inclusive may be encoded in single byte.
  24049. *
  24050. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  24051. * indicates an integer involving the next byte, w, according to the formula:
  24052. * [(v - 247) x 256] + w + 108
  24053. *
  24054. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  24055. * indicates an integer involving the next byte, w, according to the formula:
  24056. * -[(v - 251) * 256] - w - 108
  24057. *
  24058. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  24059. * are a two complement signed integer. The first of these bytes contains the
  24060. * highest order bits, the second byte contains the next higher order bits
  24061. * and the fourth byte contain the lowest order bits.
  24062. *
  24063. *
  24064. * CharString Command Encoding:
  24065. * CharStrings commands are encoded in 1 or 2 bytes.
  24066. *
  24067. * Single byte commands are encoded in 1 byte that contains a value between
  24068. * 0 and 31 inclusive.
  24069. * If a command byte contains the value 12, then the value in the next byte
  24070. * indicates a command. This "escape" mechanism allows many extra commands
  24071. * to be encoded and this encoding technique helps to minimize the length of
  24072. * the charStrings.
  24073. */
  24074. var Type1CharString = (function Type1CharStringClosure() {
  24075. var COMMAND_MAP = {
  24076. 'hstem': [1],
  24077. 'vstem': [3],
  24078. 'vmoveto': [4],
  24079. 'rlineto': [5],
  24080. 'hlineto': [6],
  24081. 'vlineto': [7],
  24082. 'rrcurveto': [8],
  24083. 'callsubr': [10],
  24084. 'flex': [12, 35],
  24085. 'drop' : [12, 18],
  24086. 'endchar': [14],
  24087. 'rmoveto': [21],
  24088. 'hmoveto': [22],
  24089. 'vhcurveto': [30],
  24090. 'hvcurveto': [31]
  24091. };
  24092. function Type1CharString() {
  24093. this.width = 0;
  24094. this.lsb = 0;
  24095. this.flexing = false;
  24096. this.output = [];
  24097. this.stack = [];
  24098. }
  24099. Type1CharString.prototype = {
  24100. convert: function Type1CharString_convert(encoded, subrs) {
  24101. var count = encoded.length;
  24102. var error = false;
  24103. var wx, sbx, subrNumber;
  24104. for (var i = 0; i < count; i++) {
  24105. var value = encoded[i];
  24106. if (value < 32) {
  24107. if (value === 12) {
  24108. value = (value << 8) + encoded[++i];
  24109. }
  24110. switch (value) {
  24111. case 1: // hstem
  24112. if (!HINTING_ENABLED) {
  24113. this.stack = [];
  24114. break;
  24115. }
  24116. error = this.executeCommand(2, COMMAND_MAP.hstem);
  24117. break;
  24118. case 3: // vstem
  24119. if (!HINTING_ENABLED) {
  24120. this.stack = [];
  24121. break;
  24122. }
  24123. error = this.executeCommand(2, COMMAND_MAP.vstem);
  24124. break;
  24125. case 4: // vmoveto
  24126. if (this.flexing) {
  24127. if (this.stack.length < 1) {
  24128. error = true;
  24129. break;
  24130. }
  24131. // Add the dx for flex and but also swap the values so they are
  24132. // the right order.
  24133. var dy = this.stack.pop();
  24134. this.stack.push(0, dy);
  24135. break;
  24136. }
  24137. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  24138. break;
  24139. case 5: // rlineto
  24140. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  24141. break;
  24142. case 6: // hlineto
  24143. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  24144. break;
  24145. case 7: // vlineto
  24146. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  24147. break;
  24148. case 8: // rrcurveto
  24149. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  24150. break;
  24151. case 9: // closepath
  24152. // closepath is a Type1 command that does not take argument and is
  24153. // useless in Type2 and it can simply be ignored.
  24154. this.stack = [];
  24155. break;
  24156. case 10: // callsubr
  24157. if (this.stack.length < 1) {
  24158. error = true;
  24159. break;
  24160. }
  24161. subrNumber = this.stack.pop();
  24162. error = this.convert(subrs[subrNumber], subrs);
  24163. break;
  24164. case 11: // return
  24165. return error;
  24166. case 13: // hsbw
  24167. if (this.stack.length < 2) {
  24168. error = true;
  24169. break;
  24170. }
  24171. // To convert to type2 we have to move the width value to the
  24172. // first part of the charstring and then use hmoveto with lsb.
  24173. wx = this.stack.pop();
  24174. sbx = this.stack.pop();
  24175. this.lsb = sbx;
  24176. this.width = wx;
  24177. this.stack.push(wx, sbx);
  24178. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  24179. break;
  24180. case 14: // endchar
  24181. this.output.push(COMMAND_MAP.endchar[0]);
  24182. break;
  24183. case 21: // rmoveto
  24184. if (this.flexing) {
  24185. break;
  24186. }
  24187. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  24188. break;
  24189. case 22: // hmoveto
  24190. if (this.flexing) {
  24191. // Add the dy for flex.
  24192. this.stack.push(0);
  24193. break;
  24194. }
  24195. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  24196. break;
  24197. case 30: // vhcurveto
  24198. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  24199. break;
  24200. case 31: // hvcurveto
  24201. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  24202. break;
  24203. case (12 << 8) + 0: // dotsection
  24204. // dotsection is a Type1 command to specify some hinting feature
  24205. // for dots that do not take a parameter and it can safely be
  24206. // ignored for Type2.
  24207. this.stack = [];
  24208. break;
  24209. case (12 << 8) + 1: // vstem3
  24210. if (!HINTING_ENABLED) {
  24211. this.stack = [];
  24212. break;
  24213. }
  24214. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  24215. // multiple parameters, so instead of returning [vh]stem3 take a
  24216. // shortcut and return [vhstem] instead.
  24217. error = this.executeCommand(2, COMMAND_MAP.vstem);
  24218. break;
  24219. case (12 << 8) + 2: // hstem3
  24220. if (!HINTING_ENABLED) {
  24221. this.stack = [];
  24222. break;
  24223. }
  24224. // See vstem3.
  24225. error = this.executeCommand(2, COMMAND_MAP.hstem);
  24226. break;
  24227. case (12 << 8) + 6: // seac
  24228. // seac is like type 2's special endchar but it doesn't use the
  24229. // first argument asb, so remove it.
  24230. if (SEAC_ANALYSIS_ENABLED) {
  24231. this.seac = this.stack.splice(-4, 4);
  24232. error = this.executeCommand(0, COMMAND_MAP.endchar);
  24233. } else {
  24234. error = this.executeCommand(4, COMMAND_MAP.endchar);
  24235. }
  24236. break;
  24237. case (12 << 8) + 7: // sbw
  24238. if (this.stack.length < 4) {
  24239. error = true;
  24240. break;
  24241. }
  24242. // To convert to type2 we have to move the width value to the
  24243. // first part of the charstring and then use rmoveto with
  24244. // (dx, dy). The height argument will not be used for vmtx and
  24245. // vhea tables reconstruction -- ignoring it.
  24246. var wy = this.stack.pop();
  24247. wx = this.stack.pop();
  24248. var sby = this.stack.pop();
  24249. sbx = this.stack.pop();
  24250. this.lsb = sbx;
  24251. this.width = wx;
  24252. this.stack.push(wx, sbx, sby);
  24253. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  24254. break;
  24255. case (12 << 8) + 12: // div
  24256. if (this.stack.length < 2) {
  24257. error = true;
  24258. break;
  24259. }
  24260. var num2 = this.stack.pop();
  24261. var num1 = this.stack.pop();
  24262. this.stack.push(num1 / num2);
  24263. break;
  24264. case (12 << 8) + 16: // callothersubr
  24265. if (this.stack.length < 2) {
  24266. error = true;
  24267. break;
  24268. }
  24269. subrNumber = this.stack.pop();
  24270. var numArgs = this.stack.pop();
  24271. if (subrNumber === 0 && numArgs === 3) {
  24272. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  24273. this.stack.push(
  24274. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  24275. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  24276. flexArgs[4], // bcp2x
  24277. flexArgs[5], // bcp2y
  24278. flexArgs[6], // p2x
  24279. flexArgs[7], // p2y
  24280. flexArgs[8], // bcp3x
  24281. flexArgs[9], // bcp3y
  24282. flexArgs[10], // bcp4x
  24283. flexArgs[11], // bcp4y
  24284. flexArgs[12], // p3x
  24285. flexArgs[13], // p3y
  24286. flexArgs[14] // flexDepth
  24287. // 15 = finalx unused by flex
  24288. // 16 = finaly unused by flex
  24289. );
  24290. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  24291. this.flexing = false;
  24292. this.stack.push(flexArgs[15], flexArgs[16]);
  24293. } else if (subrNumber === 1 && numArgs === 0) {
  24294. this.flexing = true;
  24295. }
  24296. break;
  24297. case (12 << 8) + 17: // pop
  24298. // Ignore this since it is only used with othersubr.
  24299. break;
  24300. case (12 << 8) + 33: // setcurrentpoint
  24301. // Ignore for now.
  24302. this.stack = [];
  24303. break;
  24304. default:
  24305. warn('Unknown type 1 charstring command of "' + value + '"');
  24306. break;
  24307. }
  24308. if (error) {
  24309. break;
  24310. }
  24311. continue;
  24312. } else if (value <= 246) {
  24313. value = value - 139;
  24314. } else if (value <= 250) {
  24315. value = ((value - 247) * 256) + encoded[++i] + 108;
  24316. } else if (value <= 254) {
  24317. value = -((value - 251) * 256) - encoded[++i] - 108;
  24318. } else {
  24319. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  24320. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  24321. }
  24322. this.stack.push(value);
  24323. }
  24324. return error;
  24325. },
  24326. executeCommand: function(howManyArgs, command, keepStack) {
  24327. var stackLength = this.stack.length;
  24328. if (howManyArgs > stackLength) {
  24329. return true;
  24330. }
  24331. var start = stackLength - howManyArgs;
  24332. for (var i = start; i < stackLength; i++) {
  24333. var value = this.stack[i];
  24334. if (value === (value | 0)) { // int
  24335. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  24336. } else { // fixed point
  24337. value = (65536 * value) | 0;
  24338. this.output.push(255,
  24339. (value >> 24) & 0xFF,
  24340. (value >> 16) & 0xFF,
  24341. (value >> 8) & 0xFF,
  24342. value & 0xFF);
  24343. }
  24344. }
  24345. this.output.push.apply(this.output, command);
  24346. if (keepStack) {
  24347. this.stack.splice(start, howManyArgs);
  24348. } else {
  24349. this.stack.length = 0;
  24350. }
  24351. return false;
  24352. }
  24353. };
  24354. return Type1CharString;
  24355. })();
  24356. /*
  24357. * Type1Parser encapsulate the needed code for parsing a Type1 font
  24358. * program. Some of its logic depends on the Type2 charstrings
  24359. * structure.
  24360. * Note: this doesn't really parse the font since that would require evaluation
  24361. * of PostScript, but it is possible in most cases to extract what we need
  24362. * without a full parse.
  24363. */
  24364. var Type1Parser = (function Type1ParserClosure() {
  24365. /*
  24366. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  24367. * of Plaintext Bytes. The function took a key as a parameter which can be
  24368. * for decrypting the eexec block of for decoding charStrings.
  24369. */
  24370. var EEXEC_ENCRYPT_KEY = 55665;
  24371. var CHAR_STRS_ENCRYPT_KEY = 4330;
  24372. function isHexDigit(code) {
  24373. return code >= 48 && code <= 57 || // '0'-'9'
  24374. code >= 65 && code <= 70 || // 'A'-'F'
  24375. code >= 97 && code <= 102; // 'a'-'f'
  24376. }
  24377. function decrypt(data, key, discardNumber) {
  24378. var r = key | 0, c1 = 52845, c2 = 22719;
  24379. var count = data.length;
  24380. var decrypted = new Uint8Array(count);
  24381. for (var i = 0; i < count; i++) {
  24382. var value = data[i];
  24383. decrypted[i] = value ^ (r >> 8);
  24384. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  24385. }
  24386. return Array.prototype.slice.call(decrypted, discardNumber);
  24387. }
  24388. function decryptAscii(data, key, discardNumber) {
  24389. var r = key | 0, c1 = 52845, c2 = 22719;
  24390. var count = data.length, maybeLength = count >>> 1;
  24391. var decrypted = new Uint8Array(maybeLength);
  24392. var i, j;
  24393. for (i = 0, j = 0; i < count; i++) {
  24394. var digit1 = data[i];
  24395. if (!isHexDigit(digit1)) {
  24396. continue;
  24397. }
  24398. i++;
  24399. var digit2;
  24400. while (i < count && !isHexDigit(digit2 = data[i])) {
  24401. i++;
  24402. }
  24403. if (i < count) {
  24404. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  24405. decrypted[j++] = value ^ (r >> 8);
  24406. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  24407. }
  24408. }
  24409. return Array.prototype.slice.call(decrypted, discardNumber, j);
  24410. }
  24411. function isSpecial(c) {
  24412. return c === 0x2F || // '/'
  24413. c === 0x5B || c === 0x5D || // '[', ']'
  24414. c === 0x7B || c === 0x7D || // '{', '}'
  24415. c === 0x28 || c === 0x29; // '(', ')'
  24416. }
  24417. function Type1Parser(stream, encrypted) {
  24418. if (encrypted) {
  24419. var data = stream.getBytes();
  24420. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  24421. isHexDigit(data[2]) && isHexDigit(data[3]));
  24422. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  24423. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  24424. }
  24425. this.stream = stream;
  24426. this.nextChar();
  24427. }
  24428. Type1Parser.prototype = {
  24429. readNumberArray: function Type1Parser_readNumberArray() {
  24430. this.getToken(); // read '[' or '{' (arrays can start with either)
  24431. var array = [];
  24432. while (true) {
  24433. var token = this.getToken();
  24434. if (token === null || token === ']' || token === '}') {
  24435. break;
  24436. }
  24437. array.push(parseFloat(token || 0));
  24438. }
  24439. return array;
  24440. },
  24441. readNumber: function Type1Parser_readNumber() {
  24442. var token = this.getToken();
  24443. return parseFloat(token || 0);
  24444. },
  24445. readInt: function Type1Parser_readInt() {
  24446. // Use '| 0' to prevent setting a double into length such as the double
  24447. // does not flow into the loop variable.
  24448. var token = this.getToken();
  24449. return parseInt(token || 0, 10) | 0;
  24450. },
  24451. readBoolean: function Type1Parser_readBoolean() {
  24452. var token = this.getToken();
  24453. // Use 1 and 0 since that's what type2 charstrings use.
  24454. return token === 'true' ? 1 : 0;
  24455. },
  24456. nextChar : function Type1_nextChar() {
  24457. return (this.currentChar = this.stream.getByte());
  24458. },
  24459. getToken: function Type1Parser_getToken() {
  24460. // Eat whitespace and comments.
  24461. var comment = false;
  24462. var ch = this.currentChar;
  24463. while (true) {
  24464. if (ch === -1) {
  24465. return null;
  24466. }
  24467. if (comment) {
  24468. if (ch === 0x0A || ch === 0x0D) {
  24469. comment = false;
  24470. }
  24471. } else if (ch === 0x25) { // '%'
  24472. comment = true;
  24473. } else if (!Lexer.isSpace(ch)) {
  24474. break;
  24475. }
  24476. ch = this.nextChar();
  24477. }
  24478. if (isSpecial(ch)) {
  24479. this.nextChar();
  24480. return String.fromCharCode(ch);
  24481. }
  24482. var token = '';
  24483. do {
  24484. token += String.fromCharCode(ch);
  24485. ch = this.nextChar();
  24486. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  24487. return token;
  24488. },
  24489. /*
  24490. * Returns an object containing a Subrs array and a CharStrings
  24491. * array extracted from and eexec encrypted block of data
  24492. */
  24493. extractFontProgram: function Type1Parser_extractFontProgram() {
  24494. var stream = this.stream;
  24495. var subrs = [], charstrings = [];
  24496. var program = {
  24497. subrs: [],
  24498. charstrings: [],
  24499. properties: {
  24500. 'privateData': {
  24501. 'lenIV': 4
  24502. }
  24503. }
  24504. };
  24505. var token, length, data, lenIV, encoded;
  24506. while ((token = this.getToken()) !== null) {
  24507. if (token !== '/') {
  24508. continue;
  24509. }
  24510. token = this.getToken();
  24511. switch (token) {
  24512. case 'CharStrings':
  24513. // The number immediately following CharStrings must be greater or
  24514. // equal to the number of CharStrings.
  24515. this.getToken();
  24516. this.getToken(); // read in 'dict'
  24517. this.getToken(); // read in 'dup'
  24518. this.getToken(); // read in 'begin'
  24519. while(true) {
  24520. token = this.getToken();
  24521. if (token === null || token === 'end') {
  24522. break;
  24523. }
  24524. if (token !== '/') {
  24525. continue;
  24526. }
  24527. var glyph = this.getToken();
  24528. length = this.readInt();
  24529. this.getToken(); // read in 'RD' or '-|'
  24530. data = stream.makeSubStream(stream.pos, length);
  24531. lenIV = program.properties.privateData['lenIV'];
  24532. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  24533. // Skip past the required space and binary data.
  24534. stream.skip(length);
  24535. this.nextChar();
  24536. token = this.getToken(); // read in 'ND' or '|-'
  24537. if (token === 'noaccess') {
  24538. this.getToken(); // read in 'def'
  24539. }
  24540. charstrings.push({
  24541. glyph: glyph,
  24542. encoded: encoded
  24543. });
  24544. }
  24545. break;
  24546. case 'Subrs':
  24547. var num = this.readInt();
  24548. this.getToken(); // read in 'array'
  24549. while ((token = this.getToken()) === 'dup') {
  24550. var index = this.readInt();
  24551. length = this.readInt();
  24552. this.getToken(); // read in 'RD' or '-|'
  24553. data = stream.makeSubStream(stream.pos, length);
  24554. lenIV = program.properties.privateData['lenIV'];
  24555. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  24556. // Skip past the required space and binary data.
  24557. stream.skip(length);
  24558. this.nextChar();
  24559. token = this.getToken(); // read in 'NP' or '|'
  24560. if (token === 'noaccess') {
  24561. this.getToken(); // read in 'put'
  24562. }
  24563. subrs[index] = encoded;
  24564. }
  24565. break;
  24566. case 'BlueValues':
  24567. case 'OtherBlues':
  24568. case 'FamilyBlues':
  24569. case 'FamilyOtherBlues':
  24570. var blueArray = this.readNumberArray();
  24571. // *Blue* values may contain invalid data: disables reading of
  24572. // those values when hinting is disabled.
  24573. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  24574. HINTING_ENABLED) {
  24575. program.properties.privateData[token] = blueArray;
  24576. }
  24577. break;
  24578. case 'StemSnapH':
  24579. case 'StemSnapV':
  24580. program.properties.privateData[token] = this.readNumberArray();
  24581. break;
  24582. case 'StdHW':
  24583. case 'StdVW':
  24584. program.properties.privateData[token] =
  24585. this.readNumberArray()[0];
  24586. break;
  24587. case 'BlueShift':
  24588. case 'lenIV':
  24589. case 'BlueFuzz':
  24590. case 'BlueScale':
  24591. case 'LanguageGroup':
  24592. case 'ExpansionFactor':
  24593. program.properties.privateData[token] = this.readNumber();
  24594. break;
  24595. case 'ForceBold':
  24596. program.properties.privateData[token] = this.readBoolean();
  24597. break;
  24598. }
  24599. }
  24600. for (var i = 0; i < charstrings.length; i++) {
  24601. glyph = charstrings[i].glyph;
  24602. encoded = charstrings[i].encoded;
  24603. var charString = new Type1CharString();
  24604. var error = charString.convert(encoded, subrs);
  24605. var output = charString.output;
  24606. if (error) {
  24607. // It seems when FreeType encounters an error while evaluating a glyph
  24608. // that it completely ignores the glyph so we'll mimic that behaviour
  24609. // here and put an endchar to make the validator happy.
  24610. output = [14];
  24611. }
  24612. program.charstrings.push({
  24613. glyphName: glyph,
  24614. charstring: output,
  24615. width: charString.width,
  24616. lsb: charString.lsb,
  24617. seac: charString.seac
  24618. });
  24619. }
  24620. return program;
  24621. },
  24622. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  24623. var token;
  24624. while ((token = this.getToken()) !== null) {
  24625. if (token !== '/') {
  24626. continue;
  24627. }
  24628. token = this.getToken();
  24629. switch (token) {
  24630. case 'FontMatrix':
  24631. var matrix = this.readNumberArray();
  24632. properties.fontMatrix = matrix;
  24633. break;
  24634. case 'Encoding':
  24635. var encodingArg = this.getToken();
  24636. var encoding;
  24637. if (!/^\d+$/.test(encodingArg)) {
  24638. // encoding name is specified
  24639. encoding = Encodings[encodingArg];
  24640. } else {
  24641. encoding = [];
  24642. var size = parseInt(encodingArg, 10) | 0;
  24643. this.getToken(); // read in 'array'
  24644. for (var j = 0; j < size; j++) {
  24645. token = this.getToken();
  24646. // skipping till first dup or def (e.g. ignoring for statement)
  24647. while (token !== 'dup' && token !== 'def') {
  24648. token = this.getToken();
  24649. if (token === null) {
  24650. return; // invalid header
  24651. }
  24652. }
  24653. if (token === 'def') {
  24654. break; // read all array data
  24655. }
  24656. var index = this.readInt();
  24657. this.getToken(); // read in '/'
  24658. var glyph = this.getToken();
  24659. encoding[index] = glyph;
  24660. this.getToken(); // read the in 'put'
  24661. }
  24662. }
  24663. properties.builtInEncoding = encoding;
  24664. break;
  24665. case 'FontBBox':
  24666. var fontBBox = this.readNumberArray();
  24667. // adjusting ascent/descent
  24668. properties.ascent = fontBBox[3];
  24669. properties.descent = fontBBox[1];
  24670. properties.ascentScaled = true;
  24671. break;
  24672. }
  24673. }
  24674. }
  24675. };
  24676. return Type1Parser;
  24677. })();
  24678. /**
  24679. * The CFF class takes a Type1 file and wrap it into a
  24680. * 'Compact Font Format' which itself embed Type2 charstrings.
  24681. */
  24682. var CFFStandardStrings = [
  24683. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  24684. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  24685. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  24686. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  24687. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  24688. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  24689. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  24690. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  24691. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  24692. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  24693. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  24694. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  24695. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  24696. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  24697. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  24698. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  24699. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  24700. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  24701. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  24702. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  24703. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  24704. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  24705. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  24706. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  24707. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  24708. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  24709. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  24710. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  24711. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  24712. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  24713. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  24714. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  24715. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  24716. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  24717. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  24718. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  24719. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  24720. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  24721. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  24722. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  24723. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  24724. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  24725. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  24726. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  24727. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  24728. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  24729. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  24730. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  24731. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  24732. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  24733. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  24734. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  24735. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  24736. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  24737. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  24738. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  24739. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  24740. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  24741. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  24742. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  24743. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  24744. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  24745. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  24746. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  24747. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  24748. ];
  24749. // Type1Font is also a CIDFontType0.
  24750. var Type1Font = function Type1Font(name, file, properties) {
  24751. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  24752. // Also, length1 and length2 might be off by 6 bytes as well.
  24753. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  24754. var PFB_HEADER_SIZE = 6;
  24755. var headerBlockLength = properties.length1;
  24756. var eexecBlockLength = properties.length2;
  24757. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  24758. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  24759. if (pfbHeaderPresent) {
  24760. file.skip(PFB_HEADER_SIZE);
  24761. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  24762. (pfbHeader[3] << 8) | pfbHeader[2];
  24763. }
  24764. // Get the data block containing glyphs and subrs informations
  24765. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  24766. var headerBlockParser = new Type1Parser(headerBlock);
  24767. headerBlockParser.extractFontHeader(properties);
  24768. if (pfbHeaderPresent) {
  24769. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  24770. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  24771. (pfbHeader[3] << 8) | pfbHeader[2];
  24772. }
  24773. // Decrypt the data blocks and retrieve it's content
  24774. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  24775. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  24776. var data = eexecBlockParser.extractFontProgram();
  24777. for (var info in data.properties) {
  24778. properties[info] = data.properties[info];
  24779. }
  24780. var charstrings = data.charstrings;
  24781. var type2Charstrings = this.getType2Charstrings(charstrings);
  24782. var subrs = this.getType2Subrs(data.subrs);
  24783. this.charstrings = charstrings;
  24784. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  24785. subrs, properties);
  24786. this.seacs = this.getSeacs(data.charstrings);
  24787. };
  24788. Type1Font.prototype = {
  24789. get numGlyphs() {
  24790. return this.charstrings.length + 1;
  24791. },
  24792. getCharset: function Type1Font_getCharset() {
  24793. var charset = ['.notdef'];
  24794. var charstrings = this.charstrings;
  24795. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  24796. charset.push(charstrings[glyphId].glyphName);
  24797. }
  24798. return charset;
  24799. },
  24800. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  24801. var charstrings = this.charstrings;
  24802. var glyphNames = ['.notdef'], glyphId;
  24803. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  24804. glyphNames.push(charstrings[glyphId].glyphName);
  24805. }
  24806. var encoding = properties.builtInEncoding;
  24807. if (encoding) {
  24808. var builtInEncoding = {};
  24809. for (var charCode in encoding) {
  24810. glyphId = glyphNames.indexOf(encoding[charCode]);
  24811. if (glyphId >= 0) {
  24812. builtInEncoding[charCode] = glyphId;
  24813. }
  24814. }
  24815. }
  24816. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  24817. },
  24818. getSeacs: function Type1Font_getSeacs(charstrings) {
  24819. var i, ii;
  24820. var seacMap = [];
  24821. for (i = 0, ii = charstrings.length; i < ii; i++) {
  24822. var charstring = charstrings[i];
  24823. if (charstring.seac) {
  24824. // Offset by 1 for .notdef
  24825. seacMap[i + 1] = charstring.seac;
  24826. }
  24827. }
  24828. return seacMap;
  24829. },
  24830. getType2Charstrings: function Type1Font_getType2Charstrings(
  24831. type1Charstrings) {
  24832. var type2Charstrings = [];
  24833. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  24834. type2Charstrings.push(type1Charstrings[i].charstring);
  24835. }
  24836. return type2Charstrings;
  24837. },
  24838. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  24839. var bias = 0;
  24840. var count = type1Subrs.length;
  24841. if (count < 1133) {
  24842. bias = 107;
  24843. } else if (count < 33769) {
  24844. bias = 1131;
  24845. } else {
  24846. bias = 32768;
  24847. }
  24848. // Add a bunch of empty subrs to deal with the Type2 bias
  24849. var type2Subrs = [];
  24850. var i;
  24851. for (i = 0; i < bias; i++) {
  24852. type2Subrs.push([0x0B]);
  24853. }
  24854. for (i = 0; i < count; i++) {
  24855. type2Subrs.push(type1Subrs[i]);
  24856. }
  24857. return type2Subrs;
  24858. },
  24859. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  24860. var cff = new CFF();
  24861. cff.header = new CFFHeader(1, 0, 4, 4);
  24862. cff.names = [name];
  24863. var topDict = new CFFTopDict();
  24864. // CFF strings IDs 0...390 are predefined names, so refering
  24865. // to entries in our own String INDEX starts at SID 391.
  24866. topDict.setByName('version', 391);
  24867. topDict.setByName('Notice', 392);
  24868. topDict.setByName('FullName', 393);
  24869. topDict.setByName('FamilyName', 394);
  24870. topDict.setByName('Weight', 395);
  24871. topDict.setByName('Encoding', null); // placeholder
  24872. topDict.setByName('FontMatrix', properties.fontMatrix);
  24873. topDict.setByName('FontBBox', properties.bbox);
  24874. topDict.setByName('charset', null); // placeholder
  24875. topDict.setByName('CharStrings', null); // placeholder
  24876. topDict.setByName('Private', null); // placeholder
  24877. cff.topDict = topDict;
  24878. var strings = new CFFStrings();
  24879. strings.add('Version 0.11'); // Version
  24880. strings.add('See original notice'); // Notice
  24881. strings.add(name); // FullName
  24882. strings.add(name); // FamilyName
  24883. strings.add('Medium'); // Weight
  24884. cff.strings = strings;
  24885. cff.globalSubrIndex = new CFFIndex();
  24886. var count = glyphs.length;
  24887. var charsetArray = [0];
  24888. var i, ii;
  24889. for (i = 0; i < count; i++) {
  24890. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  24891. // TODO: Insert the string and correctly map it. Previously it was
  24892. // thought mapping names that aren't in the standard strings to .notdef
  24893. // was fine, however in issue818 when mapping them all to .notdef the
  24894. // adieresis glyph no longer worked.
  24895. if (index === -1) {
  24896. index = 0;
  24897. }
  24898. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  24899. }
  24900. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  24901. var charStringsIndex = new CFFIndex();
  24902. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  24903. for (i = 0; i < count; i++) {
  24904. charStringsIndex.add(glyphs[i]);
  24905. }
  24906. cff.charStrings = charStringsIndex;
  24907. var privateDict = new CFFPrivateDict();
  24908. privateDict.setByName('Subrs', null); // placeholder
  24909. var fields = [
  24910. 'BlueValues',
  24911. 'OtherBlues',
  24912. 'FamilyBlues',
  24913. 'FamilyOtherBlues',
  24914. 'StemSnapH',
  24915. 'StemSnapV',
  24916. 'BlueShift',
  24917. 'BlueFuzz',
  24918. 'BlueScale',
  24919. 'LanguageGroup',
  24920. 'ExpansionFactor',
  24921. 'ForceBold',
  24922. 'StdHW',
  24923. 'StdVW'
  24924. ];
  24925. for (i = 0, ii = fields.length; i < ii; i++) {
  24926. var field = fields[i];
  24927. if (!properties.privateData.hasOwnProperty(field)) {
  24928. continue;
  24929. }
  24930. var value = properties.privateData[field];
  24931. if (isArray(value)) {
  24932. // All of the private dictionary array data in CFF must be stored as
  24933. // "delta-encoded" numbers.
  24934. for (var j = value.length - 1; j > 0; j--) {
  24935. value[j] -= value[j - 1]; // ... difference from previous value
  24936. }
  24937. }
  24938. privateDict.setByName(field, value);
  24939. }
  24940. cff.topDict.privateDict = privateDict;
  24941. var subrIndex = new CFFIndex();
  24942. for (i = 0, ii = subrs.length; i < ii; i++) {
  24943. subrIndex.add(subrs[i]);
  24944. }
  24945. privateDict.subrsIndex = subrIndex;
  24946. var compiler = new CFFCompiler(cff);
  24947. return compiler.compile();
  24948. }
  24949. };
  24950. var CFFFont = (function CFFFontClosure() {
  24951. function CFFFont(file, properties) {
  24952. this.properties = properties;
  24953. var parser = new CFFParser(file, properties);
  24954. this.cff = parser.parse();
  24955. var compiler = new CFFCompiler(this.cff);
  24956. this.seacs = this.cff.seacs;
  24957. try {
  24958. this.data = compiler.compile();
  24959. } catch (e) {
  24960. warn('Failed to compile font ' + properties.loadedName);
  24961. // There may have just been an issue with the compiler, set the data
  24962. // anyway and hope the font loaded.
  24963. this.data = file;
  24964. }
  24965. }
  24966. CFFFont.prototype = {
  24967. get numGlyphs() {
  24968. return this.cff.charStrings.count;
  24969. },
  24970. getCharset: function CFFFont_getCharset() {
  24971. return this.cff.charset.charset;
  24972. },
  24973. getGlyphMapping: function CFFFont_getGlyphMapping() {
  24974. var cff = this.cff;
  24975. var properties = this.properties;
  24976. var charsets = cff.charset.charset;
  24977. var charCodeToGlyphId;
  24978. var glyphId;
  24979. if (properties.composite) {
  24980. charCodeToGlyphId = Object.create(null);
  24981. if (cff.isCIDFont) {
  24982. // If the font is actually a CID font then we should use the charset
  24983. // to map CIDs to GIDs.
  24984. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  24985. var cid = charsets[glyphId];
  24986. var charCode = properties.cMap.charCodeOf(cid);
  24987. charCodeToGlyphId[charCode] = glyphId;
  24988. }
  24989. } else {
  24990. // If it is NOT actually a CID font then CIDs should be mapped
  24991. // directly to GIDs.
  24992. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  24993. charCodeToGlyphId[glyphId] = glyphId;
  24994. }
  24995. }
  24996. return charCodeToGlyphId;
  24997. }
  24998. var encoding = cff.encoding ? cff.encoding.encoding : null;
  24999. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  25000. return charCodeToGlyphId;
  25001. }
  25002. };
  25003. return CFFFont;
  25004. })();
  25005. var CFFParser = (function CFFParserClosure() {
  25006. var CharstringValidationData = [
  25007. null,
  25008. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  25009. null,
  25010. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  25011. { id: 'vmoveto', min: 1, stackClearing: true },
  25012. { id: 'rlineto', min: 2, resetStack: true },
  25013. { id: 'hlineto', min: 1, resetStack: true },
  25014. { id: 'vlineto', min: 1, resetStack: true },
  25015. { id: 'rrcurveto', min: 6, resetStack: true },
  25016. null,
  25017. { id: 'callsubr', min: 1, undefStack: true },
  25018. { id: 'return', min: 0, undefStack: true },
  25019. null, // 12
  25020. null,
  25021. { id: 'endchar', min: 0, stackClearing: true },
  25022. null,
  25023. null,
  25024. null,
  25025. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  25026. { id: 'hintmask', min: 0, stackClearing: true },
  25027. { id: 'cntrmask', min: 0, stackClearing: true },
  25028. { id: 'rmoveto', min: 2, stackClearing: true },
  25029. { id: 'hmoveto', min: 1, stackClearing: true },
  25030. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  25031. { id: 'rcurveline', min: 8, resetStack: true },
  25032. { id: 'rlinecurve', min: 8, resetStack: true },
  25033. { id: 'vvcurveto', min: 4, resetStack: true },
  25034. { id: 'hhcurveto', min: 4, resetStack: true },
  25035. null, // shortint
  25036. { id: 'callgsubr', min: 1, undefStack: true },
  25037. { id: 'vhcurveto', min: 4, resetStack: true },
  25038. { id: 'hvcurveto', min: 4, resetStack: true }
  25039. ];
  25040. var CharstringValidationData12 = [
  25041. null,
  25042. null,
  25043. null,
  25044. { id: 'and', min: 2, stackDelta: -1 },
  25045. { id: 'or', min: 2, stackDelta: -1 },
  25046. { id: 'not', min: 1, stackDelta: 0 },
  25047. null,
  25048. null,
  25049. null,
  25050. { id: 'abs', min: 1, stackDelta: 0 },
  25051. { id: 'add', min: 2, stackDelta: -1,
  25052. stackFn: function stack_div(stack, index) {
  25053. stack[index - 2] = stack[index - 2] + stack[index - 1];
  25054. }
  25055. },
  25056. { id: 'sub', min: 2, stackDelta: -1,
  25057. stackFn: function stack_div(stack, index) {
  25058. stack[index - 2] = stack[index - 2] - stack[index - 1];
  25059. }
  25060. },
  25061. { id: 'div', min: 2, stackDelta: -1,
  25062. stackFn: function stack_div(stack, index) {
  25063. stack[index - 2] = stack[index - 2] / stack[index - 1];
  25064. }
  25065. },
  25066. null,
  25067. { id: 'neg', min: 1, stackDelta: 0,
  25068. stackFn: function stack_div(stack, index) {
  25069. stack[index - 1] = -stack[index - 1];
  25070. }
  25071. },
  25072. { id: 'eq', min: 2, stackDelta: -1 },
  25073. null,
  25074. null,
  25075. { id: 'drop', min: 1, stackDelta: -1 },
  25076. null,
  25077. { id: 'put', min: 2, stackDelta: -2 },
  25078. { id: 'get', min: 1, stackDelta: 0 },
  25079. { id: 'ifelse', min: 4, stackDelta: -3 },
  25080. { id: 'random', min: 0, stackDelta: 1 },
  25081. { id: 'mul', min: 2, stackDelta: -1,
  25082. stackFn: function stack_div(stack, index) {
  25083. stack[index - 2] = stack[index - 2] * stack[index - 1];
  25084. }
  25085. },
  25086. null,
  25087. { id: 'sqrt', min: 1, stackDelta: 0 },
  25088. { id: 'dup', min: 1, stackDelta: 1 },
  25089. { id: 'exch', min: 2, stackDelta: 0 },
  25090. { id: 'index', min: 2, stackDelta: 0 },
  25091. { id: 'roll', min: 3, stackDelta: -2 },
  25092. null,
  25093. null,
  25094. null,
  25095. { id: 'hflex', min: 7, resetStack: true },
  25096. { id: 'flex', min: 13, resetStack: true },
  25097. { id: 'hflex1', min: 9, resetStack: true },
  25098. { id: 'flex1', min: 11, resetStack: true }
  25099. ];
  25100. function CFFParser(file, properties) {
  25101. this.bytes = file.getBytes();
  25102. this.properties = properties;
  25103. }
  25104. CFFParser.prototype = {
  25105. parse: function CFFParser_parse() {
  25106. var properties = this.properties;
  25107. var cff = new CFF();
  25108. this.cff = cff;
  25109. // The first five sections must be in order, all the others are reached
  25110. // via offsets contained in one of the below.
  25111. var header = this.parseHeader();
  25112. var nameIndex = this.parseIndex(header.endPos);
  25113. var topDictIndex = this.parseIndex(nameIndex.endPos);
  25114. var stringIndex = this.parseIndex(topDictIndex.endPos);
  25115. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  25116. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  25117. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  25118. cff.header = header.obj;
  25119. cff.names = this.parseNameIndex(nameIndex.obj);
  25120. cff.strings = this.parseStringIndex(stringIndex.obj);
  25121. cff.topDict = topDict;
  25122. cff.globalSubrIndex = globalSubrIndex.obj;
  25123. this.parsePrivateDict(cff.topDict);
  25124. cff.isCIDFont = topDict.hasName('ROS');
  25125. var charStringOffset = topDict.getByName('CharStrings');
  25126. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  25127. cff.charStrings = charStringsAndSeacs.charStrings;
  25128. cff.seacs = charStringsAndSeacs.seacs;
  25129. cff.widths = charStringsAndSeacs.widths;
  25130. var fontMatrix = topDict.getByName('FontMatrix');
  25131. if (fontMatrix) {
  25132. properties.fontMatrix = fontMatrix;
  25133. }
  25134. var fontBBox = topDict.getByName('FontBBox');
  25135. if (fontBBox) {
  25136. // adjusting ascent/descent
  25137. properties.ascent = fontBBox[3];
  25138. properties.descent = fontBBox[1];
  25139. properties.ascentScaled = true;
  25140. }
  25141. var charset, encoding;
  25142. if (cff.isCIDFont) {
  25143. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  25144. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  25145. var dictRaw = fdArrayIndex.get(i);
  25146. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  25147. cff.strings);
  25148. this.parsePrivateDict(fontDict);
  25149. cff.fdArray.push(fontDict);
  25150. }
  25151. // cid fonts don't have an encoding
  25152. encoding = null;
  25153. charset = this.parseCharsets(topDict.getByName('charset'),
  25154. cff.charStrings.count, cff.strings, true);
  25155. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  25156. cff.charStrings.count);
  25157. } else {
  25158. charset = this.parseCharsets(topDict.getByName('charset'),
  25159. cff.charStrings.count, cff.strings, false);
  25160. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  25161. properties,
  25162. cff.strings, charset.charset);
  25163. }
  25164. cff.charset = charset;
  25165. cff.encoding = encoding;
  25166. return cff;
  25167. },
  25168. parseHeader: function CFFParser_parseHeader() {
  25169. var bytes = this.bytes;
  25170. var bytesLength = bytes.length;
  25171. var offset = 0;
  25172. // Prevent an infinite loop, by checking that the offset is within the
  25173. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  25174. while (offset < bytesLength && bytes[offset] !== 1) {
  25175. ++offset;
  25176. }
  25177. if (offset >= bytesLength) {
  25178. error('Invalid CFF header');
  25179. } else if (offset !== 0) {
  25180. info('cff data is shifted');
  25181. bytes = bytes.subarray(offset);
  25182. this.bytes = bytes;
  25183. }
  25184. var major = bytes[0];
  25185. var minor = bytes[1];
  25186. var hdrSize = bytes[2];
  25187. var offSize = bytes[3];
  25188. var header = new CFFHeader(major, minor, hdrSize, offSize);
  25189. return { obj: header, endPos: hdrSize };
  25190. },
  25191. parseDict: function CFFParser_parseDict(dict) {
  25192. var pos = 0;
  25193. function parseOperand() {
  25194. var value = dict[pos++];
  25195. if (value === 30) {
  25196. return parseFloatOperand(pos);
  25197. } else if (value === 28) {
  25198. value = dict[pos++];
  25199. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  25200. return value;
  25201. } else if (value === 29) {
  25202. value = dict[pos++];
  25203. value = (value << 8) | dict[pos++];
  25204. value = (value << 8) | dict[pos++];
  25205. value = (value << 8) | dict[pos++];
  25206. return value;
  25207. } else if (value >= 32 && value <= 246) {
  25208. return value - 139;
  25209. } else if (value >= 247 && value <= 250) {
  25210. return ((value - 247) * 256) + dict[pos++] + 108;
  25211. } else if (value >= 251 && value <= 254) {
  25212. return -((value - 251) * 256) - dict[pos++] - 108;
  25213. } else {
  25214. error('255 is not a valid DICT command');
  25215. }
  25216. return -1;
  25217. }
  25218. function parseFloatOperand() {
  25219. var str = '';
  25220. var eof = 15;
  25221. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  25222. '9', '.', 'E', 'E-', null, '-'];
  25223. var length = dict.length;
  25224. while (pos < length) {
  25225. var b = dict[pos++];
  25226. var b1 = b >> 4;
  25227. var b2 = b & 15;
  25228. if (b1 === eof) {
  25229. break;
  25230. }
  25231. str += lookup[b1];
  25232. if (b2 === eof) {
  25233. break;
  25234. }
  25235. str += lookup[b2];
  25236. }
  25237. return parseFloat(str);
  25238. }
  25239. var operands = [];
  25240. var entries = [];
  25241. pos = 0;
  25242. var end = dict.length;
  25243. while (pos < end) {
  25244. var b = dict[pos];
  25245. if (b <= 21) {
  25246. if (b === 12) {
  25247. b = (b << 8) | dict[++pos];
  25248. }
  25249. entries.push([b, operands]);
  25250. operands = [];
  25251. ++pos;
  25252. } else {
  25253. operands.push(parseOperand());
  25254. }
  25255. }
  25256. return entries;
  25257. },
  25258. parseIndex: function CFFParser_parseIndex(pos) {
  25259. var cffIndex = new CFFIndex();
  25260. var bytes = this.bytes;
  25261. var count = (bytes[pos++] << 8) | bytes[pos++];
  25262. var offsets = [];
  25263. var end = pos;
  25264. var i, ii;
  25265. if (count !== 0) {
  25266. var offsetSize = bytes[pos++];
  25267. // add 1 for offset to determine size of last object
  25268. var startPos = pos + ((count + 1) * offsetSize) - 1;
  25269. for (i = 0, ii = count + 1; i < ii; ++i) {
  25270. var offset = 0;
  25271. for (var j = 0; j < offsetSize; ++j) {
  25272. offset <<= 8;
  25273. offset += bytes[pos++];
  25274. }
  25275. offsets.push(startPos + offset);
  25276. }
  25277. end = offsets[count];
  25278. }
  25279. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  25280. var offsetStart = offsets[i];
  25281. var offsetEnd = offsets[i + 1];
  25282. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  25283. }
  25284. return {obj: cffIndex, endPos: end};
  25285. },
  25286. parseNameIndex: function CFFParser_parseNameIndex(index) {
  25287. var names = [];
  25288. for (var i = 0, ii = index.count; i < ii; ++i) {
  25289. var name = index.get(i);
  25290. // OTS doesn't allow names to be over 127 characters.
  25291. var length = Math.min(name.length, 127);
  25292. var data = [];
  25293. // OTS also only permits certain characters in the name.
  25294. for (var j = 0; j < length; ++j) {
  25295. var c = name[j];
  25296. if (j === 0 && c === 0) {
  25297. data[j] = c;
  25298. continue;
  25299. }
  25300. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  25301. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  25302. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  25303. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  25304. data[j] = 95;
  25305. continue;
  25306. }
  25307. data[j] = c;
  25308. }
  25309. names.push(bytesToString(data));
  25310. }
  25311. return names;
  25312. },
  25313. parseStringIndex: function CFFParser_parseStringIndex(index) {
  25314. var strings = new CFFStrings();
  25315. for (var i = 0, ii = index.count; i < ii; ++i) {
  25316. var data = index.get(i);
  25317. strings.add(bytesToString(data));
  25318. }
  25319. return strings;
  25320. },
  25321. createDict: function CFFParser_createDict(Type, dict, strings) {
  25322. var cffDict = new Type(strings);
  25323. for (var i = 0, ii = dict.length; i < ii; ++i) {
  25324. var pair = dict[i];
  25325. var key = pair[0];
  25326. var value = pair[1];
  25327. cffDict.setByKey(key, value);
  25328. }
  25329. return cffDict;
  25330. },
  25331. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  25332. var charStrings = this.parseIndex(charStringOffset).obj;
  25333. var seacs = [];
  25334. var widths = [];
  25335. var count = charStrings.count;
  25336. for (var i = 0; i < count; i++) {
  25337. var charstring = charStrings.get(i);
  25338. var stackSize = 0;
  25339. var stack = [];
  25340. var undefStack = true;
  25341. var hints = 0;
  25342. var valid = true;
  25343. var data = charstring;
  25344. var length = data.length;
  25345. var firstStackClearing = true;
  25346. for (var j = 0; j < length;) {
  25347. var value = data[j++];
  25348. var validationCommand = null;
  25349. if (value === 12) {
  25350. var q = data[j++];
  25351. if (q === 0) {
  25352. // The CFF specification state that the 'dotsection' command
  25353. // (12, 0) is deprecated and treated as a no-op, but all Type2
  25354. // charstrings processors should support them. Unfortunately
  25355. // the font sanitizer don't. As a workaround the sequence (12, 0)
  25356. // is replaced by a useless (0, hmoveto).
  25357. data[j - 2] = 139;
  25358. data[j - 1] = 22;
  25359. stackSize = 0;
  25360. } else {
  25361. validationCommand = CharstringValidationData12[q];
  25362. }
  25363. } else if (value === 28) { // number (16 bit)
  25364. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  25365. j += 2;
  25366. stackSize++;
  25367. } else if (value === 14) {
  25368. if (stackSize >= 4) {
  25369. stackSize -= 4;
  25370. if (SEAC_ANALYSIS_ENABLED) {
  25371. seacs[i] = stack.slice(stackSize, stackSize + 4);
  25372. valid = false;
  25373. }
  25374. }
  25375. validationCommand = CharstringValidationData[value];
  25376. } else if (value >= 32 && value <= 246) { // number
  25377. stack[stackSize] = value - 139;
  25378. stackSize++;
  25379. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  25380. stack[stackSize] = (value < 251 ?
  25381. ((value - 247) << 8) + data[j] + 108 :
  25382. -((value - 251) << 8) - data[j] - 108);
  25383. j++;
  25384. stackSize++;
  25385. } else if (value === 255) { // number (32 bit)
  25386. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  25387. (data[j + 2] << 8) | data[j + 3]) / 65536;
  25388. j += 4;
  25389. stackSize++;
  25390. } else if (value === 19 || value === 20) {
  25391. hints += stackSize >> 1;
  25392. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  25393. stackSize %= 2;
  25394. validationCommand = CharstringValidationData[value];
  25395. } else {
  25396. validationCommand = CharstringValidationData[value];
  25397. }
  25398. if (validationCommand) {
  25399. if (validationCommand.stem) {
  25400. hints += stackSize >> 1;
  25401. }
  25402. if ('min' in validationCommand) {
  25403. if (!undefStack && stackSize < validationCommand.min) {
  25404. warn('Not enough parameters for ' + validationCommand.id +
  25405. '; actual: ' + stackSize +
  25406. ', expected: ' + validationCommand.min);
  25407. valid = false;
  25408. break;
  25409. }
  25410. }
  25411. if (firstStackClearing && validationCommand.stackClearing) {
  25412. firstStackClearing = false;
  25413. // the optional character width can be found before the first
  25414. // stack-clearing command arguments
  25415. stackSize -= validationCommand.min;
  25416. if (stackSize >= 2 && validationCommand.stem) {
  25417. // there are even amount of arguments for stem commands
  25418. stackSize %= 2;
  25419. } else if (stackSize > 1) {
  25420. warn('Found too many parameters for stack-clearing command');
  25421. }
  25422. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  25423. widths[i] = stack[stackSize - 1];
  25424. }
  25425. }
  25426. if ('stackDelta' in validationCommand) {
  25427. if ('stackFn' in validationCommand) {
  25428. validationCommand.stackFn(stack, stackSize);
  25429. }
  25430. stackSize += validationCommand.stackDelta;
  25431. } else if (validationCommand.stackClearing) {
  25432. stackSize = 0;
  25433. } else if (validationCommand.resetStack) {
  25434. stackSize = 0;
  25435. undefStack = false;
  25436. } else if (validationCommand.undefStack) {
  25437. stackSize = 0;
  25438. undefStack = true;
  25439. firstStackClearing = false;
  25440. }
  25441. }
  25442. }
  25443. if (!valid) {
  25444. // resetting invalid charstring to single 'endchar'
  25445. charStrings.set(i, new Uint8Array([14]));
  25446. }
  25447. }
  25448. return { charStrings: charStrings, seacs: seacs, widths: widths };
  25449. },
  25450. emptyPrivateDictionary:
  25451. function CFFParser_emptyPrivateDictionary(parentDict) {
  25452. var privateDict = this.createDict(CFFPrivateDict, [],
  25453. parentDict.strings);
  25454. parentDict.setByKey(18, [0, 0]);
  25455. parentDict.privateDict = privateDict;
  25456. },
  25457. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  25458. // no private dict, do nothing
  25459. if (!parentDict.hasName('Private')) {
  25460. this.emptyPrivateDictionary(parentDict);
  25461. return;
  25462. }
  25463. var privateOffset = parentDict.getByName('Private');
  25464. // make sure the params are formatted correctly
  25465. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  25466. parentDict.removeByName('Private');
  25467. return;
  25468. }
  25469. var size = privateOffset[0];
  25470. var offset = privateOffset[1];
  25471. // remove empty dicts or ones that refer to invalid location
  25472. if (size === 0 || offset >= this.bytes.length) {
  25473. this.emptyPrivateDictionary(parentDict);
  25474. return;
  25475. }
  25476. var privateDictEnd = offset + size;
  25477. var dictData = this.bytes.subarray(offset, privateDictEnd);
  25478. var dict = this.parseDict(dictData);
  25479. var privateDict = this.createDict(CFFPrivateDict, dict,
  25480. parentDict.strings);
  25481. parentDict.privateDict = privateDict;
  25482. // Parse the Subrs index also since it's relative to the private dict.
  25483. if (!privateDict.getByName('Subrs')) {
  25484. return;
  25485. }
  25486. var subrsOffset = privateDict.getByName('Subrs');
  25487. var relativeOffset = offset + subrsOffset;
  25488. // Validate the offset.
  25489. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  25490. this.emptyPrivateDictionary(parentDict);
  25491. return;
  25492. }
  25493. var subrsIndex = this.parseIndex(relativeOffset);
  25494. privateDict.subrsIndex = subrsIndex.obj;
  25495. },
  25496. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  25497. if (pos === 0) {
  25498. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  25499. ISOAdobeCharset);
  25500. } else if (pos === 1) {
  25501. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  25502. ExpertCharset);
  25503. } else if (pos === 2) {
  25504. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  25505. ExpertSubsetCharset);
  25506. }
  25507. var bytes = this.bytes;
  25508. var start = pos;
  25509. var format = bytes[pos++];
  25510. var charset = ['.notdef'];
  25511. var id, count, i;
  25512. // subtract 1 for the .notdef glyph
  25513. length -= 1;
  25514. switch (format) {
  25515. case 0:
  25516. for (i = 0; i < length; i++) {
  25517. id = (bytes[pos++] << 8) | bytes[pos++];
  25518. charset.push(cid ? id : strings.get(id));
  25519. }
  25520. break;
  25521. case 1:
  25522. while (charset.length <= length) {
  25523. id = (bytes[pos++] << 8) | bytes[pos++];
  25524. count = bytes[pos++];
  25525. for (i = 0; i <= count; i++) {
  25526. charset.push(cid ? id++ : strings.get(id++));
  25527. }
  25528. }
  25529. break;
  25530. case 2:
  25531. while (charset.length <= length) {
  25532. id = (bytes[pos++] << 8) | bytes[pos++];
  25533. count = (bytes[pos++] << 8) | bytes[pos++];
  25534. for (i = 0; i <= count; i++) {
  25535. charset.push(cid ? id++ : strings.get(id++));
  25536. }
  25537. }
  25538. break;
  25539. default:
  25540. error('Unknown charset format');
  25541. }
  25542. // Raw won't be needed if we actually compile the charset.
  25543. var end = pos;
  25544. var raw = bytes.subarray(start, end);
  25545. return new CFFCharset(false, format, charset, raw);
  25546. },
  25547. parseEncoding: function CFFParser_parseEncoding(pos,
  25548. properties,
  25549. strings,
  25550. charset) {
  25551. var encoding = {};
  25552. var bytes = this.bytes;
  25553. var predefined = false;
  25554. var hasSupplement = false;
  25555. var format, i, ii;
  25556. var raw = null;
  25557. function readSupplement() {
  25558. var supplementsCount = bytes[pos++];
  25559. for (i = 0; i < supplementsCount; i++) {
  25560. var code = bytes[pos++];
  25561. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  25562. encoding[code] = charset.indexOf(strings.get(sid));
  25563. }
  25564. }
  25565. if (pos === 0 || pos === 1) {
  25566. predefined = true;
  25567. format = pos;
  25568. var baseEncoding = pos ? Encodings.ExpertEncoding :
  25569. Encodings.StandardEncoding;
  25570. for (i = 0, ii = charset.length; i < ii; i++) {
  25571. var index = baseEncoding.indexOf(charset[i]);
  25572. if (index !== -1) {
  25573. encoding[index] = i;
  25574. }
  25575. }
  25576. } else {
  25577. var dataStart = pos;
  25578. format = bytes[pos++];
  25579. switch (format & 0x7f) {
  25580. case 0:
  25581. var glyphsCount = bytes[pos++];
  25582. for (i = 1; i <= glyphsCount; i++) {
  25583. encoding[bytes[pos++]] = i;
  25584. }
  25585. break;
  25586. case 1:
  25587. var rangesCount = bytes[pos++];
  25588. var gid = 1;
  25589. for (i = 0; i < rangesCount; i++) {
  25590. var start = bytes[pos++];
  25591. var left = bytes[pos++];
  25592. for (var j = start; j <= start + left; j++) {
  25593. encoding[j] = gid++;
  25594. }
  25595. }
  25596. break;
  25597. default:
  25598. error('Unknow encoding format: ' + format + ' in CFF');
  25599. break;
  25600. }
  25601. var dataEnd = pos;
  25602. if (format & 0x80) {
  25603. // The font sanitizer does not support CFF encoding with a
  25604. // supplement, since the encoding is not really used to map
  25605. // between gid to glyph, let's overwrite what is declared in
  25606. // the top dictionary to let the sanitizer think the font use
  25607. // StandardEncoding, that's a lie but that's ok.
  25608. bytes[dataStart] &= 0x7f;
  25609. readSupplement();
  25610. hasSupplement = true;
  25611. }
  25612. raw = bytes.subarray(dataStart, dataEnd);
  25613. }
  25614. format = format & 0x7f;
  25615. return new CFFEncoding(predefined, format, encoding, raw);
  25616. },
  25617. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  25618. var start = pos;
  25619. var bytes = this.bytes;
  25620. var format = bytes[pos++];
  25621. var fdSelect = [];
  25622. var i;
  25623. switch (format) {
  25624. case 0:
  25625. for (i = 0; i < length; ++i) {
  25626. var id = bytes[pos++];
  25627. fdSelect.push(id);
  25628. }
  25629. break;
  25630. case 3:
  25631. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  25632. for (i = 0; i < rangesCount; ++i) {
  25633. var first = (bytes[pos++] << 8) | bytes[pos++];
  25634. var fdIndex = bytes[pos++];
  25635. var next = (bytes[pos] << 8) | bytes[pos + 1];
  25636. for (var j = first; j < next; ++j) {
  25637. fdSelect.push(fdIndex);
  25638. }
  25639. }
  25640. // Advance past the sentinel(next).
  25641. pos += 2;
  25642. break;
  25643. default:
  25644. error('Unknown fdselect format ' + format);
  25645. break;
  25646. }
  25647. var end = pos;
  25648. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  25649. }
  25650. };
  25651. return CFFParser;
  25652. })();
  25653. // Compact Font Format
  25654. var CFF = (function CFFClosure() {
  25655. function CFF() {
  25656. this.header = null;
  25657. this.names = [];
  25658. this.topDict = null;
  25659. this.strings = new CFFStrings();
  25660. this.globalSubrIndex = null;
  25661. // The following could really be per font, but since we only have one font
  25662. // store them here.
  25663. this.encoding = null;
  25664. this.charset = null;
  25665. this.charStrings = null;
  25666. this.fdArray = [];
  25667. this.fdSelect = null;
  25668. this.isCIDFont = false;
  25669. }
  25670. return CFF;
  25671. })();
  25672. var CFFHeader = (function CFFHeaderClosure() {
  25673. function CFFHeader(major, minor, hdrSize, offSize) {
  25674. this.major = major;
  25675. this.minor = minor;
  25676. this.hdrSize = hdrSize;
  25677. this.offSize = offSize;
  25678. }
  25679. return CFFHeader;
  25680. })();
  25681. var CFFStrings = (function CFFStringsClosure() {
  25682. function CFFStrings() {
  25683. this.strings = [];
  25684. }
  25685. CFFStrings.prototype = {
  25686. get: function CFFStrings_get(index) {
  25687. if (index >= 0 && index <= 390) {
  25688. return CFFStandardStrings[index];
  25689. }
  25690. if (index - 391 <= this.strings.length) {
  25691. return this.strings[index - 391];
  25692. }
  25693. return CFFStandardStrings[0];
  25694. },
  25695. add: function CFFStrings_add(value) {
  25696. this.strings.push(value);
  25697. },
  25698. get count() {
  25699. return this.strings.length;
  25700. }
  25701. };
  25702. return CFFStrings;
  25703. })();
  25704. var CFFIndex = (function CFFIndexClosure() {
  25705. function CFFIndex() {
  25706. this.objects = [];
  25707. this.length = 0;
  25708. }
  25709. CFFIndex.prototype = {
  25710. add: function CFFIndex_add(data) {
  25711. this.length += data.length;
  25712. this.objects.push(data);
  25713. },
  25714. set: function CFFIndex_set(index, data) {
  25715. this.length += data.length - this.objects[index].length;
  25716. this.objects[index] = data;
  25717. },
  25718. get: function CFFIndex_get(index) {
  25719. return this.objects[index];
  25720. },
  25721. get count() {
  25722. return this.objects.length;
  25723. }
  25724. };
  25725. return CFFIndex;
  25726. })();
  25727. var CFFDict = (function CFFDictClosure() {
  25728. function CFFDict(tables, strings) {
  25729. this.keyToNameMap = tables.keyToNameMap;
  25730. this.nameToKeyMap = tables.nameToKeyMap;
  25731. this.defaults = tables.defaults;
  25732. this.types = tables.types;
  25733. this.opcodes = tables.opcodes;
  25734. this.order = tables.order;
  25735. this.strings = strings;
  25736. this.values = {};
  25737. }
  25738. CFFDict.prototype = {
  25739. // value should always be an array
  25740. setByKey: function CFFDict_setByKey(key, value) {
  25741. if (!(key in this.keyToNameMap)) {
  25742. return false;
  25743. }
  25744. // ignore empty values
  25745. if (value.length === 0) {
  25746. return true;
  25747. }
  25748. var type = this.types[key];
  25749. // remove the array wrapping these types of values
  25750. if (type === 'num' || type === 'sid' || type === 'offset') {
  25751. value = value[0];
  25752. }
  25753. this.values[key] = value;
  25754. return true;
  25755. },
  25756. setByName: function CFFDict_setByName(name, value) {
  25757. if (!(name in this.nameToKeyMap)) {
  25758. error('Invalid dictionary name "' + name + '"');
  25759. }
  25760. this.values[this.nameToKeyMap[name]] = value;
  25761. },
  25762. hasName: function CFFDict_hasName(name) {
  25763. return this.nameToKeyMap[name] in this.values;
  25764. },
  25765. getByName: function CFFDict_getByName(name) {
  25766. if (!(name in this.nameToKeyMap)) {
  25767. error('Invalid dictionary name "' + name + '"');
  25768. }
  25769. var key = this.nameToKeyMap[name];
  25770. if (!(key in this.values)) {
  25771. return this.defaults[key];
  25772. }
  25773. return this.values[key];
  25774. },
  25775. removeByName: function CFFDict_removeByName(name) {
  25776. delete this.values[this.nameToKeyMap[name]];
  25777. }
  25778. };
  25779. CFFDict.createTables = function CFFDict_createTables(layout) {
  25780. var tables = {
  25781. keyToNameMap: {},
  25782. nameToKeyMap: {},
  25783. defaults: {},
  25784. types: {},
  25785. opcodes: {},
  25786. order: []
  25787. };
  25788. for (var i = 0, ii = layout.length; i < ii; ++i) {
  25789. var entry = layout[i];
  25790. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  25791. tables.keyToNameMap[key] = entry[1];
  25792. tables.nameToKeyMap[entry[1]] = key;
  25793. tables.types[key] = entry[2];
  25794. tables.defaults[key] = entry[3];
  25795. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  25796. tables.order.push(key);
  25797. }
  25798. return tables;
  25799. };
  25800. return CFFDict;
  25801. })();
  25802. var CFFTopDict = (function CFFTopDictClosure() {
  25803. var layout = [
  25804. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  25805. [[12, 20], 'SyntheticBase', 'num', null],
  25806. [0, 'version', 'sid', null],
  25807. [1, 'Notice', 'sid', null],
  25808. [[12, 0], 'Copyright', 'sid', null],
  25809. [2, 'FullName', 'sid', null],
  25810. [3, 'FamilyName', 'sid', null],
  25811. [4, 'Weight', 'sid', null],
  25812. [[12, 1], 'isFixedPitch', 'num', 0],
  25813. [[12, 2], 'ItalicAngle', 'num', 0],
  25814. [[12, 3], 'UnderlinePosition', 'num', -100],
  25815. [[12, 4], 'UnderlineThickness', 'num', 50],
  25816. [[12, 5], 'PaintType', 'num', 0],
  25817. [[12, 6], 'CharstringType', 'num', 2],
  25818. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  25819. [0.001, 0, 0, 0.001, 0, 0]],
  25820. [13, 'UniqueID', 'num', null],
  25821. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  25822. [[12, 8], 'StrokeWidth', 'num', 0],
  25823. [14, 'XUID', 'array', null],
  25824. [15, 'charset', 'offset', 0],
  25825. [16, 'Encoding', 'offset', 0],
  25826. [17, 'CharStrings', 'offset', 0],
  25827. [18, 'Private', ['offset', 'offset'], null],
  25828. [[12, 21], 'PostScript', 'sid', null],
  25829. [[12, 22], 'BaseFontName', 'sid', null],
  25830. [[12, 23], 'BaseFontBlend', 'delta', null],
  25831. [[12, 31], 'CIDFontVersion', 'num', 0],
  25832. [[12, 32], 'CIDFontRevision', 'num', 0],
  25833. [[12, 33], 'CIDFontType', 'num', 0],
  25834. [[12, 34], 'CIDCount', 'num', 8720],
  25835. [[12, 35], 'UIDBase', 'num', null],
  25836. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  25837. // before FDArray.
  25838. [[12, 37], 'FDSelect', 'offset', null],
  25839. [[12, 36], 'FDArray', 'offset', null],
  25840. [[12, 38], 'FontName', 'sid', null]
  25841. ];
  25842. var tables = null;
  25843. function CFFTopDict(strings) {
  25844. if (tables === null) {
  25845. tables = CFFDict.createTables(layout);
  25846. }
  25847. CFFDict.call(this, tables, strings);
  25848. this.privateDict = null;
  25849. }
  25850. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  25851. return CFFTopDict;
  25852. })();
  25853. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  25854. var layout = [
  25855. [6, 'BlueValues', 'delta', null],
  25856. [7, 'OtherBlues', 'delta', null],
  25857. [8, 'FamilyBlues', 'delta', null],
  25858. [9, 'FamilyOtherBlues', 'delta', null],
  25859. [[12, 9], 'BlueScale', 'num', 0.039625],
  25860. [[12, 10], 'BlueShift', 'num', 7],
  25861. [[12, 11], 'BlueFuzz', 'num', 1],
  25862. [10, 'StdHW', 'num', null],
  25863. [11, 'StdVW', 'num', null],
  25864. [[12, 12], 'StemSnapH', 'delta', null],
  25865. [[12, 13], 'StemSnapV', 'delta', null],
  25866. [[12, 14], 'ForceBold', 'num', 0],
  25867. [[12, 17], 'LanguageGroup', 'num', 0],
  25868. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  25869. [[12, 19], 'initialRandomSeed', 'num', 0],
  25870. [20, 'defaultWidthX', 'num', 0],
  25871. [21, 'nominalWidthX', 'num', 0],
  25872. [19, 'Subrs', 'offset', null]
  25873. ];
  25874. var tables = null;
  25875. function CFFPrivateDict(strings) {
  25876. if (tables === null) {
  25877. tables = CFFDict.createTables(layout);
  25878. }
  25879. CFFDict.call(this, tables, strings);
  25880. this.subrsIndex = null;
  25881. }
  25882. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  25883. return CFFPrivateDict;
  25884. })();
  25885. var CFFCharsetPredefinedTypes = {
  25886. ISO_ADOBE: 0,
  25887. EXPERT: 1,
  25888. EXPERT_SUBSET: 2
  25889. };
  25890. var CFFCharset = (function CFFCharsetClosure() {
  25891. function CFFCharset(predefined, format, charset, raw) {
  25892. this.predefined = predefined;
  25893. this.format = format;
  25894. this.charset = charset;
  25895. this.raw = raw;
  25896. }
  25897. return CFFCharset;
  25898. })();
  25899. var CFFEncoding = (function CFFEncodingClosure() {
  25900. function CFFEncoding(predefined, format, encoding, raw) {
  25901. this.predefined = predefined;
  25902. this.format = format;
  25903. this.encoding = encoding;
  25904. this.raw = raw;
  25905. }
  25906. return CFFEncoding;
  25907. })();
  25908. var CFFFDSelect = (function CFFFDSelectClosure() {
  25909. function CFFFDSelect(fdSelect, raw) {
  25910. this.fdSelect = fdSelect;
  25911. this.raw = raw;
  25912. }
  25913. return CFFFDSelect;
  25914. })();
  25915. // Helper class to keep track of where an offset is within the data and helps
  25916. // filling in that offset once it's known.
  25917. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  25918. function CFFOffsetTracker() {
  25919. this.offsets = {};
  25920. }
  25921. CFFOffsetTracker.prototype = {
  25922. isTracking: function CFFOffsetTracker_isTracking(key) {
  25923. return key in this.offsets;
  25924. },
  25925. track: function CFFOffsetTracker_track(key, location) {
  25926. if (key in this.offsets) {
  25927. error('Already tracking location of ' + key);
  25928. }
  25929. this.offsets[key] = location;
  25930. },
  25931. offset: function CFFOffsetTracker_offset(value) {
  25932. for (var key in this.offsets) {
  25933. this.offsets[key] += value;
  25934. }
  25935. },
  25936. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  25937. values,
  25938. output) {
  25939. if (!(key in this.offsets)) {
  25940. error('Not tracking location of ' + key);
  25941. }
  25942. var data = output.data;
  25943. var dataOffset = this.offsets[key];
  25944. var size = 5;
  25945. for (var i = 0, ii = values.length; i < ii; ++i) {
  25946. var offset0 = i * size + dataOffset;
  25947. var offset1 = offset0 + 1;
  25948. var offset2 = offset0 + 2;
  25949. var offset3 = offset0 + 3;
  25950. var offset4 = offset0 + 4;
  25951. // It's easy to screw up offsets so perform this sanity check.
  25952. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  25953. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  25954. error('writing to an offset that is not empty');
  25955. }
  25956. var value = values[i];
  25957. data[offset0] = 0x1d;
  25958. data[offset1] = (value >> 24) & 0xFF;
  25959. data[offset2] = (value >> 16) & 0xFF;
  25960. data[offset3] = (value >> 8) & 0xFF;
  25961. data[offset4] = value & 0xFF;
  25962. }
  25963. }
  25964. };
  25965. return CFFOffsetTracker;
  25966. })();
  25967. // Takes a CFF and converts it to the binary representation.
  25968. var CFFCompiler = (function CFFCompilerClosure() {
  25969. function CFFCompiler(cff) {
  25970. this.cff = cff;
  25971. }
  25972. CFFCompiler.prototype = {
  25973. compile: function CFFCompiler_compile() {
  25974. var cff = this.cff;
  25975. var output = {
  25976. data: [],
  25977. length: 0,
  25978. add: function CFFCompiler_add(data) {
  25979. this.data = this.data.concat(data);
  25980. this.length = this.data.length;
  25981. }
  25982. };
  25983. // Compile the five entries that must be in order.
  25984. var header = this.compileHeader(cff.header);
  25985. output.add(header);
  25986. var nameIndex = this.compileNameIndex(cff.names);
  25987. output.add(nameIndex);
  25988. if (cff.isCIDFont) {
  25989. // The spec is unclear on how font matrices should relate to each other
  25990. // when there is one in the main top dict and the sub top dicts.
  25991. // Windows handles this differently than linux and osx so we have to
  25992. // normalize to work on all.
  25993. // Rules based off of some mailing list discussions:
  25994. // - If main font has a matrix and subfont doesn't, use the main matrix.
  25995. // - If no main font matrix and there is a subfont matrix, use the
  25996. // subfont matrix.
  25997. // - If both have matrices, concat together.
  25998. // - If neither have matrices, use default.
  25999. // To make this work on all platforms we move the top matrix into each
  26000. // sub top dict and concat if necessary.
  26001. if (cff.topDict.hasName('FontMatrix')) {
  26002. var base = cff.topDict.getByName('FontMatrix');
  26003. cff.topDict.removeByName('FontMatrix');
  26004. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  26005. var subDict = cff.fdArray[i];
  26006. var matrix = base.slice(0);
  26007. if (subDict.hasName('FontMatrix')) {
  26008. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  26009. }
  26010. subDict.setByName('FontMatrix', matrix);
  26011. }
  26012. }
  26013. }
  26014. var compiled = this.compileTopDicts([cff.topDict],
  26015. output.length,
  26016. cff.isCIDFont);
  26017. output.add(compiled.output);
  26018. var topDictTracker = compiled.trackers[0];
  26019. var stringIndex = this.compileStringIndex(cff.strings.strings);
  26020. output.add(stringIndex);
  26021. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  26022. output.add(globalSubrIndex);
  26023. // Now start on the other entries that have no specfic order.
  26024. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  26025. if (cff.encoding.predefined) {
  26026. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  26027. output);
  26028. } else {
  26029. var encoding = this.compileEncoding(cff.encoding);
  26030. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  26031. output.add(encoding);
  26032. }
  26033. }
  26034. if (cff.charset && cff.topDict.hasName('charset')) {
  26035. if (cff.charset.predefined) {
  26036. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  26037. output);
  26038. } else {
  26039. var charset = this.compileCharset(cff.charset);
  26040. topDictTracker.setEntryLocation('charset', [output.length], output);
  26041. output.add(charset);
  26042. }
  26043. }
  26044. var charStrings = this.compileCharStrings(cff.charStrings);
  26045. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  26046. output.add(charStrings);
  26047. if (cff.isCIDFont) {
  26048. // For some reason FDSelect must be in front of FDArray on windows. OSX
  26049. // and linux don't seem to care.
  26050. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  26051. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  26052. output.add(fdSelect);
  26053. // It is unclear if the sub font dictionary can have CID related
  26054. // dictionary keys, but the sanitizer doesn't like them so remove them.
  26055. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  26056. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  26057. output.add(compiled.output);
  26058. var fontDictTrackers = compiled.trackers;
  26059. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  26060. }
  26061. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  26062. // If the font data ends with INDEX whose object data is zero-length,
  26063. // the sanitizer will bail out. Add a dummy byte to avoid that.
  26064. output.add([0]);
  26065. return output.data;
  26066. },
  26067. encodeNumber: function CFFCompiler_encodeNumber(value) {
  26068. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  26069. return this.encodeInteger(value);
  26070. } else {
  26071. return this.encodeFloat(value);
  26072. }
  26073. },
  26074. encodeFloat: function CFFCompiler_encodeFloat(num) {
  26075. var value = num.toString();
  26076. // rounding inaccurate doubles
  26077. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  26078. if (m) {
  26079. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  26080. value = (Math.round(num * epsilon) / epsilon).toString();
  26081. }
  26082. var nibbles = '';
  26083. var i, ii;
  26084. for (i = 0, ii = value.length; i < ii; ++i) {
  26085. var a = value[i];
  26086. if (a === 'e') {
  26087. nibbles += value[++i] === '-' ? 'c' : 'b';
  26088. } else if (a === '.') {
  26089. nibbles += 'a';
  26090. } else if (a === '-') {
  26091. nibbles += 'e';
  26092. } else {
  26093. nibbles += a;
  26094. }
  26095. }
  26096. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  26097. var out = [30];
  26098. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  26099. out.push(parseInt(nibbles.substr(i, 2), 16));
  26100. }
  26101. return out;
  26102. },
  26103. encodeInteger: function CFFCompiler_encodeInteger(value) {
  26104. var code;
  26105. if (value >= -107 && value <= 107) {
  26106. code = [value + 139];
  26107. } else if (value >= 108 && value <= 1131) {
  26108. value = [value - 108];
  26109. code = [(value >> 8) + 247, value & 0xFF];
  26110. } else if (value >= -1131 && value <= -108) {
  26111. value = -value - 108;
  26112. code = [(value >> 8) + 251, value & 0xFF];
  26113. } else if (value >= -32768 && value <= 32767) {
  26114. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  26115. } else {
  26116. code = [0x1d,
  26117. (value >> 24) & 0xFF,
  26118. (value >> 16) & 0xFF,
  26119. (value >> 8) & 0xFF,
  26120. value & 0xFF];
  26121. }
  26122. return code;
  26123. },
  26124. compileHeader: function CFFCompiler_compileHeader(header) {
  26125. return [
  26126. header.major,
  26127. header.minor,
  26128. header.hdrSize,
  26129. header.offSize
  26130. ];
  26131. },
  26132. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  26133. var nameIndex = new CFFIndex();
  26134. for (var i = 0, ii = names.length; i < ii; ++i) {
  26135. nameIndex.add(stringToBytes(names[i]));
  26136. }
  26137. return this.compileIndex(nameIndex);
  26138. },
  26139. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  26140. length,
  26141. removeCidKeys) {
  26142. var fontDictTrackers = [];
  26143. var fdArrayIndex = new CFFIndex();
  26144. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  26145. var fontDict = dicts[i];
  26146. if (removeCidKeys) {
  26147. fontDict.removeByName('CIDFontVersion');
  26148. fontDict.removeByName('CIDFontRevision');
  26149. fontDict.removeByName('CIDFontType');
  26150. fontDict.removeByName('CIDCount');
  26151. fontDict.removeByName('UIDBase');
  26152. }
  26153. var fontDictTracker = new CFFOffsetTracker();
  26154. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  26155. fontDictTrackers.push(fontDictTracker);
  26156. fdArrayIndex.add(fontDictData);
  26157. fontDictTracker.offset(length);
  26158. }
  26159. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  26160. return {
  26161. trackers: fontDictTrackers,
  26162. output: fdArrayIndex
  26163. };
  26164. },
  26165. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  26166. trackers,
  26167. output) {
  26168. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  26169. var fontDict = dicts[i];
  26170. assert(fontDict.privateDict && fontDict.hasName('Private'),
  26171. 'There must be an private dictionary.');
  26172. var privateDict = fontDict.privateDict;
  26173. var privateDictTracker = new CFFOffsetTracker();
  26174. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  26175. var outputLength = output.length;
  26176. privateDictTracker.offset(outputLength);
  26177. if (!privateDictData.length) {
  26178. // The private dictionary was empty, set the output length to zero to
  26179. // ensure the offset length isn't out of bounds in the eyes of the
  26180. // sanitizer.
  26181. outputLength = 0;
  26182. }
  26183. trackers[i].setEntryLocation('Private',
  26184. [privateDictData.length, outputLength],
  26185. output);
  26186. output.add(privateDictData);
  26187. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  26188. var subrs = this.compileIndex(privateDict.subrsIndex);
  26189. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  26190. output);
  26191. output.add(subrs);
  26192. }
  26193. }
  26194. },
  26195. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  26196. var out = [];
  26197. // The dictionary keys must be in a certain order.
  26198. var order = dict.order;
  26199. for (var i = 0; i < order.length; ++i) {
  26200. var key = order[i];
  26201. if (!(key in dict.values)) {
  26202. continue;
  26203. }
  26204. var values = dict.values[key];
  26205. var types = dict.types[key];
  26206. if (!isArray(types)) {
  26207. types = [types];
  26208. }
  26209. if (!isArray(values)) {
  26210. values = [values];
  26211. }
  26212. // Remove any empty dict values.
  26213. if (values.length === 0) {
  26214. continue;
  26215. }
  26216. for (var j = 0, jj = types.length; j < jj; ++j) {
  26217. var type = types[j];
  26218. var value = values[j];
  26219. switch (type) {
  26220. case 'num':
  26221. case 'sid':
  26222. out = out.concat(this.encodeNumber(value));
  26223. break;
  26224. case 'offset':
  26225. // For offsets we just insert a 32bit integer so we don't have to
  26226. // deal with figuring out the length of the offset when it gets
  26227. // replaced later on by the compiler.
  26228. var name = dict.keyToNameMap[key];
  26229. // Some offsets have the offset and the length, so just record the
  26230. // position of the first one.
  26231. if (!offsetTracker.isTracking(name)) {
  26232. offsetTracker.track(name, out.length);
  26233. }
  26234. out = out.concat([0x1d, 0, 0, 0, 0]);
  26235. break;
  26236. case 'array':
  26237. case 'delta':
  26238. out = out.concat(this.encodeNumber(value));
  26239. for (var k = 1, kk = values.length; k < kk; ++k) {
  26240. out = out.concat(this.encodeNumber(values[k]));
  26241. }
  26242. break;
  26243. default:
  26244. error('Unknown data type of ' + type);
  26245. break;
  26246. }
  26247. }
  26248. out = out.concat(dict.opcodes[key]);
  26249. }
  26250. return out;
  26251. },
  26252. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  26253. var stringIndex = new CFFIndex();
  26254. for (var i = 0, ii = strings.length; i < ii; ++i) {
  26255. stringIndex.add(stringToBytes(strings[i]));
  26256. }
  26257. return this.compileIndex(stringIndex);
  26258. },
  26259. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  26260. var globalSubrIndex = this.cff.globalSubrIndex;
  26261. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  26262. },
  26263. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  26264. return this.compileIndex(charStrings);
  26265. },
  26266. compileCharset: function CFFCompiler_compileCharset(charset) {
  26267. return this.compileTypedArray(charset.raw);
  26268. },
  26269. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  26270. return this.compileTypedArray(encoding.raw);
  26271. },
  26272. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  26273. return this.compileTypedArray(fdSelect);
  26274. },
  26275. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  26276. var out = [];
  26277. for (var i = 0, ii = data.length; i < ii; ++i) {
  26278. out[i] = data[i];
  26279. }
  26280. return out;
  26281. },
  26282. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  26283. trackers = trackers || [];
  26284. var objects = index.objects;
  26285. // First 2 bytes contains the number of objects contained into this index
  26286. var count = objects.length;
  26287. // If there is no object, just create an index. This technically
  26288. // should just be [0, 0] but OTS has an issue with that.
  26289. if (count === 0) {
  26290. return [0, 0, 0];
  26291. }
  26292. var data = [(count >> 8) & 0xFF, count & 0xff];
  26293. var lastOffset = 1, i;
  26294. for (i = 0; i < count; ++i) {
  26295. lastOffset += objects[i].length;
  26296. }
  26297. var offsetSize;
  26298. if (lastOffset < 0x100) {
  26299. offsetSize = 1;
  26300. } else if (lastOffset < 0x10000) {
  26301. offsetSize = 2;
  26302. } else if (lastOffset < 0x1000000) {
  26303. offsetSize = 3;
  26304. } else {
  26305. offsetSize = 4;
  26306. }
  26307. // Next byte contains the offset size use to reference object in the file
  26308. data.push(offsetSize);
  26309. // Add another offset after this one because we need a new offset
  26310. var relativeOffset = 1;
  26311. for (i = 0; i < count + 1; i++) {
  26312. if (offsetSize === 1) {
  26313. data.push(relativeOffset & 0xFF);
  26314. } else if (offsetSize === 2) {
  26315. data.push((relativeOffset >> 8) & 0xFF,
  26316. relativeOffset & 0xFF);
  26317. } else if (offsetSize === 3) {
  26318. data.push((relativeOffset >> 16) & 0xFF,
  26319. (relativeOffset >> 8) & 0xFF,
  26320. relativeOffset & 0xFF);
  26321. } else {
  26322. data.push((relativeOffset >>> 24) & 0xFF,
  26323. (relativeOffset >> 16) & 0xFF,
  26324. (relativeOffset >> 8) & 0xFF,
  26325. relativeOffset & 0xFF);
  26326. }
  26327. if (objects[i]) {
  26328. relativeOffset += objects[i].length;
  26329. }
  26330. }
  26331. for (i = 0; i < count; i++) {
  26332. // Notify the tracker where the object will be offset in the data.
  26333. if (trackers[i]) {
  26334. trackers[i].offset(data.length);
  26335. }
  26336. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  26337. data.push(objects[i][j]);
  26338. }
  26339. }
  26340. return data;
  26341. }
  26342. };
  26343. return CFFCompiler;
  26344. })();
  26345. // Workaround for seac on Windows.
  26346. (function checkSeacSupport() {
  26347. if (/Windows/.test(navigator.userAgent)) {
  26348. SEAC_ANALYSIS_ENABLED = true;
  26349. }
  26350. })();
  26351. // Workaround for Private Use Area characters in Chrome on Windows
  26352. // http://code.google.com/p/chromium/issues/detail?id=122465
  26353. // https://github.com/mozilla/pdf.js/issues/1689
  26354. (function checkChromeWindows() {
  26355. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  26356. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  26357. }
  26358. })();
  26359. var FontRendererFactory = (function FontRendererFactoryClosure() {
  26360. function getLong(data, offset) {
  26361. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26362. (data[offset + 2] << 8) | data[offset + 3];
  26363. }
  26364. function getUshort(data, offset) {
  26365. return (data[offset] << 8) | data[offset + 1];
  26366. }
  26367. function parseCmap(data, start, end) {
  26368. var offset = (getUshort(data, start + 2) === 1 ?
  26369. getLong(data, start + 8) : getLong(data, start + 16));
  26370. var format = getUshort(data, start + offset);
  26371. var length, ranges, p, i;
  26372. if (format === 4) {
  26373. length = getUshort(data, start + offset + 2);
  26374. var segCount = getUshort(data, start + offset + 6) >> 1;
  26375. p = start + offset + 14;
  26376. ranges = [];
  26377. for (i = 0; i < segCount; i++, p += 2) {
  26378. ranges[i] = {end: getUshort(data, p)};
  26379. }
  26380. p += 2;
  26381. for (i = 0; i < segCount; i++, p += 2) {
  26382. ranges[i].start = getUshort(data, p);
  26383. }
  26384. for (i = 0; i < segCount; i++, p += 2) {
  26385. ranges[i].idDelta = getUshort(data, p);
  26386. }
  26387. for (i = 0; i < segCount; i++, p += 2) {
  26388. var idOffset = getUshort(data, p);
  26389. if (idOffset === 0) {
  26390. continue;
  26391. }
  26392. ranges[i].ids = [];
  26393. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  26394. ranges[i].ids[j] = getUshort(data, p + idOffset);
  26395. idOffset += 2;
  26396. }
  26397. }
  26398. return ranges;
  26399. } else if (format === 12) {
  26400. length = getLong(data, start + offset + 4);
  26401. var groups = getLong(data, start + offset + 12);
  26402. p = start + offset + 16;
  26403. ranges = [];
  26404. for (i = 0; i < groups; i++) {
  26405. ranges.push({
  26406. start: getLong(data, p),
  26407. end: getLong(data, p + 4),
  26408. idDelta: getLong(data, p + 8) - getLong(data, p)
  26409. });
  26410. p += 12;
  26411. }
  26412. return ranges;
  26413. }
  26414. error('not supported cmap: ' + format);
  26415. }
  26416. function parseCff(data, start, end) {
  26417. var properties = {};
  26418. var parser = new CFFParser(new Stream(data, start, end - start),
  26419. properties);
  26420. var cff = parser.parse();
  26421. return {
  26422. glyphs: cff.charStrings.objects,
  26423. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  26424. cff.topDict.privateDict.subrsIndex.objects),
  26425. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  26426. };
  26427. }
  26428. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  26429. var itemSize, itemDecode;
  26430. if (isGlyphLocationsLong) {
  26431. itemSize = 4;
  26432. itemDecode = function fontItemDecodeLong(data, offset) {
  26433. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26434. (data[offset + 2] << 8) | data[offset + 3];
  26435. };
  26436. } else {
  26437. itemSize = 2;
  26438. itemDecode = function fontItemDecode(data, offset) {
  26439. return (data[offset] << 9) | (data[offset + 1] << 1);
  26440. };
  26441. }
  26442. var glyphs = [];
  26443. var startOffset = itemDecode(loca, 0);
  26444. for (var j = itemSize; j < loca.length; j += itemSize) {
  26445. var endOffset = itemDecode(loca, j);
  26446. glyphs.push(glyf.subarray(startOffset, endOffset));
  26447. startOffset = endOffset;
  26448. }
  26449. return glyphs;
  26450. }
  26451. function lookupCmap(ranges, unicode) {
  26452. var code = unicode.charCodeAt(0);
  26453. var l = 0, r = ranges.length - 1;
  26454. while (l < r) {
  26455. var c = (l + r + 1) >> 1;
  26456. if (code < ranges[c].start) {
  26457. r = c - 1;
  26458. } else {
  26459. l = c;
  26460. }
  26461. }
  26462. if (ranges[l].start <= code && code <= ranges[l].end) {
  26463. return (ranges[l].idDelta + (ranges[l].ids ?
  26464. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  26465. }
  26466. return 0;
  26467. }
  26468. function compileGlyf(code, cmds, font) {
  26469. function moveTo(x, y) {
  26470. cmds.push({cmd: 'moveTo', args: [x, y]});
  26471. }
  26472. function lineTo(x, y) {
  26473. cmds.push({cmd: 'lineTo', args: [x, y]});
  26474. }
  26475. function quadraticCurveTo(xa, ya, x, y) {
  26476. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  26477. }
  26478. var i = 0;
  26479. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26480. var flags;
  26481. var x = 0, y = 0;
  26482. i += 10;
  26483. if (numberOfContours < 0) {
  26484. // composite glyph
  26485. do {
  26486. flags = (code[i] << 8) | code[i + 1];
  26487. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  26488. i += 4;
  26489. var arg1, arg2;
  26490. if ((flags & 0x01)) {
  26491. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26492. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  26493. i += 4;
  26494. } else {
  26495. arg1 = code[i++]; arg2 = code[i++];
  26496. }
  26497. if ((flags & 0x02)) {
  26498. x = arg1;
  26499. y = arg2;
  26500. } else {
  26501. x = 0; y = 0; // TODO "they are points" ?
  26502. }
  26503. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  26504. if ((flags & 0x08)) {
  26505. scaleX =
  26506. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26507. i += 2;
  26508. } else if ((flags & 0x40)) {
  26509. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26510. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  26511. i += 4;
  26512. } else if ((flags & 0x80)) {
  26513. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  26514. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  26515. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  26516. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  26517. i += 8;
  26518. }
  26519. var subglyph = font.glyphs[glyphIndex];
  26520. if (subglyph) {
  26521. cmds.push({cmd: 'save'});
  26522. cmds.push({cmd: 'transform',
  26523. args: [scaleX, scale01, scale10, scaleY, x, y]});
  26524. compileGlyf(subglyph, cmds, font);
  26525. cmds.push({cmd: 'restore'});
  26526. }
  26527. } while ((flags & 0x20));
  26528. } else {
  26529. // simple glyph
  26530. var endPtsOfContours = [];
  26531. var j, jj;
  26532. for (j = 0; j < numberOfContours; j++) {
  26533. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  26534. i += 2;
  26535. }
  26536. var instructionLength = (code[i] << 8) | code[i + 1];
  26537. i += 2 + instructionLength; // skipping the instructions
  26538. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  26539. var points = [];
  26540. while (points.length < numberOfPoints) {
  26541. flags = code[i++];
  26542. var repeat = 1;
  26543. if ((flags & 0x08)) {
  26544. repeat += code[i++];
  26545. }
  26546. while (repeat-- > 0) {
  26547. points.push({flags: flags});
  26548. }
  26549. }
  26550. for (j = 0; j < numberOfPoints; j++) {
  26551. switch (points[j].flags & 0x12) {
  26552. case 0x00:
  26553. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26554. i += 2;
  26555. break;
  26556. case 0x02:
  26557. x -= code[i++];
  26558. break;
  26559. case 0x12:
  26560. x += code[i++];
  26561. break;
  26562. }
  26563. points[j].x = x;
  26564. }
  26565. for (j = 0; j < numberOfPoints; j++) {
  26566. switch (points[j].flags & 0x24) {
  26567. case 0x00:
  26568. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  26569. i += 2;
  26570. break;
  26571. case 0x04:
  26572. y -= code[i++];
  26573. break;
  26574. case 0x24:
  26575. y += code[i++];
  26576. break;
  26577. }
  26578. points[j].y = y;
  26579. }
  26580. var startPoint = 0;
  26581. for (i = 0; i < numberOfContours; i++) {
  26582. var endPoint = endPtsOfContours[i];
  26583. // contours might have implicit points, which is located in the middle
  26584. // between two neighboring off-curve points
  26585. var contour = points.slice(startPoint, endPoint + 1);
  26586. if ((contour[0].flags & 1)) {
  26587. contour.push(contour[0]); // using start point at the contour end
  26588. } else if ((contour[contour.length - 1].flags & 1)) {
  26589. // first is off-curve point, trying to use one from the end
  26590. contour.unshift(contour[contour.length - 1]);
  26591. } else {
  26592. // start and end are off-curve points, creating implicit one
  26593. var p = {
  26594. flags: 1,
  26595. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  26596. y: (contour[0].y + contour[contour.length - 1].y) / 2
  26597. };
  26598. contour.unshift(p);
  26599. contour.push(p);
  26600. }
  26601. moveTo(contour[0].x, contour[0].y);
  26602. for (j = 1, jj = contour.length; j < jj; j++) {
  26603. if ((contour[j].flags & 1)) {
  26604. lineTo(contour[j].x, contour[j].y);
  26605. } else if ((contour[j + 1].flags & 1)){
  26606. quadraticCurveTo(contour[j].x, contour[j].y,
  26607. contour[j + 1].x, contour[j + 1].y);
  26608. j++;
  26609. } else {
  26610. quadraticCurveTo(contour[j].x, contour[j].y,
  26611. (contour[j].x + contour[j + 1].x) / 2,
  26612. (contour[j].y + contour[j + 1].y) / 2);
  26613. }
  26614. }
  26615. startPoint = endPoint + 1;
  26616. }
  26617. }
  26618. }
  26619. function compileCharString(code, cmds, font) {
  26620. var stack = [];
  26621. var x = 0, y = 0;
  26622. var stems = 0;
  26623. function moveTo(x, y) {
  26624. cmds.push({cmd: 'moveTo', args: [x, y]});
  26625. }
  26626. function lineTo(x, y) {
  26627. cmds.push({cmd: 'lineTo', args: [x, y]});
  26628. }
  26629. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  26630. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  26631. }
  26632. function parse(code) {
  26633. var i = 0;
  26634. while (i < code.length) {
  26635. var stackClean = false;
  26636. var v = code[i++];
  26637. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  26638. switch (v) {
  26639. case 1: // hstem
  26640. stems += stack.length >> 1;
  26641. stackClean = true;
  26642. break;
  26643. case 3: // vstem
  26644. stems += stack.length >> 1;
  26645. stackClean = true;
  26646. break;
  26647. case 4: // vmoveto
  26648. y += stack.pop();
  26649. moveTo(x, y);
  26650. stackClean = true;
  26651. break;
  26652. case 5: // rlineto
  26653. while (stack.length > 0) {
  26654. x += stack.shift();
  26655. y += stack.shift();
  26656. lineTo(x, y);
  26657. }
  26658. break;
  26659. case 6: // hlineto
  26660. while (stack.length > 0) {
  26661. x += stack.shift();
  26662. lineTo(x, y);
  26663. if (stack.length === 0) {
  26664. break;
  26665. }
  26666. y += stack.shift();
  26667. lineTo(x, y);
  26668. }
  26669. break;
  26670. case 7: // vlineto
  26671. while (stack.length > 0) {
  26672. y += stack.shift();
  26673. lineTo(x, y);
  26674. if (stack.length === 0) {
  26675. break;
  26676. }
  26677. x += stack.shift();
  26678. lineTo(x, y);
  26679. }
  26680. break;
  26681. case 8: // rrcurveto
  26682. while (stack.length > 0) {
  26683. xa = x + stack.shift(); ya = y + stack.shift();
  26684. xb = xa + stack.shift(); yb = ya + stack.shift();
  26685. x = xb + stack.shift(); y = yb + stack.shift();
  26686. bezierCurveTo(xa, ya, xb, yb, x, y);
  26687. }
  26688. break;
  26689. case 10: // callsubr
  26690. n = stack.pop() + font.subrsBias;
  26691. subrCode = font.subrs[n];
  26692. if (subrCode) {
  26693. parse(subrCode);
  26694. }
  26695. break;
  26696. case 11: // return
  26697. return;
  26698. case 12:
  26699. v = code[i++];
  26700. switch (v) {
  26701. case 34: // flex
  26702. xa = x + stack.shift();
  26703. xb = xa + stack.shift(); y1 = y + stack.shift();
  26704. x = xb + stack.shift();
  26705. bezierCurveTo(xa, y, xb, y1, x, y1);
  26706. xa = x + stack.shift();
  26707. xb = xa + stack.shift();
  26708. x = xb + stack.shift();
  26709. bezierCurveTo(xa, y1, xb, y, x, y);
  26710. break;
  26711. case 35: // flex
  26712. xa = x + stack.shift(); ya = y + stack.shift();
  26713. xb = xa + stack.shift(); yb = ya + stack.shift();
  26714. x = xb + stack.shift(); y = yb + stack.shift();
  26715. bezierCurveTo(xa, ya, xb, yb, x, y);
  26716. xa = x + stack.shift(); ya = y + stack.shift();
  26717. xb = xa + stack.shift(); yb = ya + stack.shift();
  26718. x = xb + stack.shift(); y = yb + stack.shift();
  26719. bezierCurveTo(xa, ya, xb, yb, x, y);
  26720. stack.pop(); // fd
  26721. break;
  26722. case 36: // hflex1
  26723. xa = x + stack.shift(); y1 = y + stack.shift();
  26724. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  26725. x = xb + stack.shift();
  26726. bezierCurveTo(xa, y1, xb, y2, x, y2);
  26727. xa = x + stack.shift();
  26728. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  26729. x = xb + stack.shift();
  26730. bezierCurveTo(xa, y2, xb, y3, x, y);
  26731. break;
  26732. case 37: // flex1
  26733. var x0 = x, y0 = y;
  26734. xa = x + stack.shift(); ya = y + stack.shift();
  26735. xb = xa + stack.shift(); yb = ya + stack.shift();
  26736. x = xb + stack.shift(); y = yb + stack.shift();
  26737. bezierCurveTo(xa, ya, xb, yb, x, y);
  26738. xa = x + stack.shift(); ya = y + stack.shift();
  26739. xb = xa + stack.shift(); yb = ya + stack.shift();
  26740. x = xb; y = yb;
  26741. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  26742. x += stack.shift();
  26743. } else {
  26744. y += stack.shift();
  26745. }
  26746. bezierCurveTo(xa, ya, xb, yb, x, y);
  26747. break;
  26748. default:
  26749. error('unknown operator: 12 ' + v);
  26750. }
  26751. break;
  26752. case 14: // endchar
  26753. if (stack.length >= 4) {
  26754. var achar = stack.pop();
  26755. var bchar = stack.pop();
  26756. y = stack.pop();
  26757. x = stack.pop();
  26758. cmds.push({cmd: 'save'});
  26759. cmds.push({cmd: 'translate', args: [x, y]});
  26760. var gid = lookupCmap(font.cmap, String.fromCharCode(
  26761. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  26762. compileCharString(font.glyphs[gid], cmds, font);
  26763. cmds.push({cmd: 'restore'});
  26764. gid = lookupCmap(font.cmap, String.fromCharCode(
  26765. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  26766. compileCharString(font.glyphs[gid], cmds, font);
  26767. }
  26768. return;
  26769. case 18: // hstemhm
  26770. stems += stack.length >> 1;
  26771. stackClean = true;
  26772. break;
  26773. case 19: // hintmask
  26774. stems += stack.length >> 1;
  26775. i += (stems + 7) >> 3;
  26776. stackClean = true;
  26777. break;
  26778. case 20: // cntrmask
  26779. stems += stack.length >> 1;
  26780. i += (stems + 7) >> 3;
  26781. stackClean = true;
  26782. break;
  26783. case 21: // rmoveto
  26784. y += stack.pop();
  26785. x += stack.pop();
  26786. moveTo(x, y);
  26787. stackClean = true;
  26788. break;
  26789. case 22: // hmoveto
  26790. x += stack.pop();
  26791. moveTo(x, y);
  26792. stackClean = true;
  26793. break;
  26794. case 23: // vstemhm
  26795. stems += stack.length >> 1;
  26796. stackClean = true;
  26797. break;
  26798. case 24: // rcurveline
  26799. while (stack.length > 2) {
  26800. xa = x + stack.shift(); ya = y + stack.shift();
  26801. xb = xa + stack.shift(); yb = ya + stack.shift();
  26802. x = xb + stack.shift(); y = yb + stack.shift();
  26803. bezierCurveTo(xa, ya, xb, yb, x, y);
  26804. }
  26805. x += stack.shift();
  26806. y += stack.shift();
  26807. lineTo(x, y);
  26808. break;
  26809. case 25: // rlinecurve
  26810. while (stack.length > 6) {
  26811. x += stack.shift();
  26812. y += stack.shift();
  26813. lineTo(x, y);
  26814. }
  26815. xa = x + stack.shift(); ya = y + stack.shift();
  26816. xb = xa + stack.shift(); yb = ya + stack.shift();
  26817. x = xb + stack.shift(); y = yb + stack.shift();
  26818. bezierCurveTo(xa, ya, xb, yb, x, y);
  26819. break;
  26820. case 26: // vvcurveto
  26821. if (stack.length % 2) {
  26822. x += stack.shift();
  26823. }
  26824. while (stack.length > 0) {
  26825. xa = x; ya = y + stack.shift();
  26826. xb = xa + stack.shift(); yb = ya + stack.shift();
  26827. x = xb; y = yb + stack.shift();
  26828. bezierCurveTo(xa, ya, xb, yb, x, y);
  26829. }
  26830. break;
  26831. case 27: // hhcurveto
  26832. if (stack.length % 2) {
  26833. y += stack.shift();
  26834. }
  26835. while (stack.length > 0) {
  26836. xa = x + stack.shift(); ya = y;
  26837. xb = xa + stack.shift(); yb = ya + stack.shift();
  26838. x = xb + stack.shift(); y = yb;
  26839. bezierCurveTo(xa, ya, xb, yb, x, y);
  26840. }
  26841. break;
  26842. case 28:
  26843. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  26844. i += 2;
  26845. break;
  26846. case 29: // callgsubr
  26847. n = stack.pop() + font.gsubrsBias;
  26848. subrCode = font.gsubrs[n];
  26849. if (subrCode) {
  26850. parse(subrCode);
  26851. }
  26852. break;
  26853. case 30: // vhcurveto
  26854. while (stack.length > 0) {
  26855. xa = x; ya = y + stack.shift();
  26856. xb = xa + stack.shift(); yb = ya + stack.shift();
  26857. x = xb + stack.shift();
  26858. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26859. bezierCurveTo(xa, ya, xb, yb, x, y);
  26860. if (stack.length === 0) {
  26861. break;
  26862. }
  26863. xa = x + stack.shift(); ya = y;
  26864. xb = xa + stack.shift(); yb = ya + stack.shift();
  26865. y = yb + stack.shift();
  26866. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26867. bezierCurveTo(xa, ya, xb, yb, x, y);
  26868. }
  26869. break;
  26870. case 31: // hvcurveto
  26871. while (stack.length > 0) {
  26872. xa = x + stack.shift(); ya = y;
  26873. xb = xa + stack.shift(); yb = ya + stack.shift();
  26874. y = yb + stack.shift();
  26875. x = xb + (stack.length === 1 ? stack.shift() : 0);
  26876. bezierCurveTo(xa, ya, xb, yb, x, y);
  26877. if (stack.length === 0) {
  26878. break;
  26879. }
  26880. xa = x; ya = y + stack.shift();
  26881. xb = xa + stack.shift(); yb = ya + stack.shift();
  26882. x = xb + stack.shift();
  26883. y = yb + (stack.length === 1 ? stack.shift() : 0);
  26884. bezierCurveTo(xa, ya, xb, yb, x, y);
  26885. }
  26886. break;
  26887. default:
  26888. if (v < 32) {
  26889. error('unknown operator: ' + v);
  26890. }
  26891. if (v < 247) {
  26892. stack.push(v - 139);
  26893. } else if (v < 251) {
  26894. stack.push((v - 247) * 256 + code[i++] + 108);
  26895. } else if (v < 255) {
  26896. stack.push(-(v - 251) * 256 - code[i++] - 108);
  26897. } else {
  26898. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  26899. (code[i + 2] << 8) | code[i + 3]) / 65536);
  26900. i += 4;
  26901. }
  26902. break;
  26903. }
  26904. if (stackClean) {
  26905. stack.length = 0;
  26906. }
  26907. }
  26908. }
  26909. parse(code);
  26910. }
  26911. var noop = '';
  26912. function CompiledFont(fontMatrix) {
  26913. this.compiledGlyphs = {};
  26914. this.fontMatrix = fontMatrix;
  26915. }
  26916. CompiledFont.prototype = {
  26917. getPathJs: function (unicode) {
  26918. var gid = lookupCmap(this.cmap, unicode);
  26919. var fn = this.compiledGlyphs[gid];
  26920. if (!fn) {
  26921. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  26922. }
  26923. return fn;
  26924. },
  26925. compileGlyph: function (code) {
  26926. if (!code || code.length === 0 || code[0] === 14) {
  26927. return noop;
  26928. }
  26929. var cmds = [];
  26930. cmds.push({cmd: 'save'});
  26931. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  26932. cmds.push({cmd: 'scale', args: ['size', '-size']});
  26933. this.compileGlyphImpl(code, cmds);
  26934. cmds.push({cmd: 'restore'});
  26935. return cmds;
  26936. },
  26937. compileGlyphImpl: function () {
  26938. error('Children classes should implement this.');
  26939. },
  26940. hasBuiltPath: function (unicode) {
  26941. var gid = lookupCmap(this.cmap, unicode);
  26942. return gid in this.compiledGlyphs;
  26943. }
  26944. };
  26945. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  26946. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  26947. CompiledFont.call(this, fontMatrix);
  26948. this.glyphs = glyphs;
  26949. this.cmap = cmap;
  26950. this.compiledGlyphs = [];
  26951. }
  26952. Util.inherit(TrueTypeCompiled, CompiledFont, {
  26953. compileGlyphImpl: function (code, cmds) {
  26954. compileGlyf(code, cmds, this);
  26955. }
  26956. });
  26957. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  26958. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  26959. CompiledFont.call(this, fontMatrix);
  26960. this.glyphs = cffInfo.glyphs;
  26961. this.gsubrs = cffInfo.gsubrs || [];
  26962. this.subrs = cffInfo.subrs || [];
  26963. this.cmap = cmap;
  26964. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  26965. this.compiledGlyphs = [];
  26966. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  26967. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  26968. this.subrsBias = (this.subrs.length < 1240 ?
  26969. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  26970. }
  26971. Util.inherit(Type2Compiled, CompiledFont, {
  26972. compileGlyphImpl: function (code, cmds) {
  26973. compileCharString(code, cmds, this);
  26974. }
  26975. });
  26976. return {
  26977. create: function FontRendererFactory_create(font) {
  26978. var data = new Uint8Array(font.data);
  26979. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  26980. var numTables = getUshort(data, 4);
  26981. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  26982. var tag = bytesToString(data.subarray(p, p + 4));
  26983. var offset = getLong(data, p + 8);
  26984. var length = getLong(data, p + 12);
  26985. switch (tag) {
  26986. case 'cmap':
  26987. cmap = parseCmap(data, offset, offset + length);
  26988. break;
  26989. case 'glyf':
  26990. glyf = data.subarray(offset, offset + length);
  26991. break;
  26992. case 'loca':
  26993. loca = data.subarray(offset, offset + length);
  26994. break;
  26995. case 'head':
  26996. unitsPerEm = getUshort(data, offset + 18);
  26997. indexToLocFormat = getUshort(data, offset + 50);
  26998. break;
  26999. case 'CFF ':
  27000. cff = parseCff(data, offset, offset + length);
  27001. break;
  27002. }
  27003. }
  27004. if (glyf) {
  27005. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  27006. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  27007. return new TrueTypeCompiled(
  27008. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  27009. } else {
  27010. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  27011. }
  27012. }
  27013. };
  27014. })();
  27015. var GlyphsUnicode = {
  27016. A: 0x0041,
  27017. AE: 0x00C6,
  27018. AEacute: 0x01FC,
  27019. AEmacron: 0x01E2,
  27020. AEsmall: 0xF7E6,
  27021. Aacute: 0x00C1,
  27022. Aacutesmall: 0xF7E1,
  27023. Abreve: 0x0102,
  27024. Abreveacute: 0x1EAE,
  27025. Abrevecyrillic: 0x04D0,
  27026. Abrevedotbelow: 0x1EB6,
  27027. Abrevegrave: 0x1EB0,
  27028. Abrevehookabove: 0x1EB2,
  27029. Abrevetilde: 0x1EB4,
  27030. Acaron: 0x01CD,
  27031. Acircle: 0x24B6,
  27032. Acircumflex: 0x00C2,
  27033. Acircumflexacute: 0x1EA4,
  27034. Acircumflexdotbelow: 0x1EAC,
  27035. Acircumflexgrave: 0x1EA6,
  27036. Acircumflexhookabove: 0x1EA8,
  27037. Acircumflexsmall: 0xF7E2,
  27038. Acircumflextilde: 0x1EAA,
  27039. Acute: 0xF6C9,
  27040. Acutesmall: 0xF7B4,
  27041. Acyrillic: 0x0410,
  27042. Adblgrave: 0x0200,
  27043. Adieresis: 0x00C4,
  27044. Adieresiscyrillic: 0x04D2,
  27045. Adieresismacron: 0x01DE,
  27046. Adieresissmall: 0xF7E4,
  27047. Adotbelow: 0x1EA0,
  27048. Adotmacron: 0x01E0,
  27049. Agrave: 0x00C0,
  27050. Agravesmall: 0xF7E0,
  27051. Ahookabove: 0x1EA2,
  27052. Aiecyrillic: 0x04D4,
  27053. Ainvertedbreve: 0x0202,
  27054. Alpha: 0x0391,
  27055. Alphatonos: 0x0386,
  27056. Amacron: 0x0100,
  27057. Amonospace: 0xFF21,
  27058. Aogonek: 0x0104,
  27059. Aring: 0x00C5,
  27060. Aringacute: 0x01FA,
  27061. Aringbelow: 0x1E00,
  27062. Aringsmall: 0xF7E5,
  27063. Asmall: 0xF761,
  27064. Atilde: 0x00C3,
  27065. Atildesmall: 0xF7E3,
  27066. Aybarmenian: 0x0531,
  27067. B: 0x0042,
  27068. Bcircle: 0x24B7,
  27069. Bdotaccent: 0x1E02,
  27070. Bdotbelow: 0x1E04,
  27071. Becyrillic: 0x0411,
  27072. Benarmenian: 0x0532,
  27073. Beta: 0x0392,
  27074. Bhook: 0x0181,
  27075. Blinebelow: 0x1E06,
  27076. Bmonospace: 0xFF22,
  27077. Brevesmall: 0xF6F4,
  27078. Bsmall: 0xF762,
  27079. Btopbar: 0x0182,
  27080. C: 0x0043,
  27081. Caarmenian: 0x053E,
  27082. Cacute: 0x0106,
  27083. Caron: 0xF6CA,
  27084. Caronsmall: 0xF6F5,
  27085. Ccaron: 0x010C,
  27086. Ccedilla: 0x00C7,
  27087. Ccedillaacute: 0x1E08,
  27088. Ccedillasmall: 0xF7E7,
  27089. Ccircle: 0x24B8,
  27090. Ccircumflex: 0x0108,
  27091. Cdot: 0x010A,
  27092. Cdotaccent: 0x010A,
  27093. Cedillasmall: 0xF7B8,
  27094. Chaarmenian: 0x0549,
  27095. Cheabkhasiancyrillic: 0x04BC,
  27096. Checyrillic: 0x0427,
  27097. Chedescenderabkhasiancyrillic: 0x04BE,
  27098. Chedescendercyrillic: 0x04B6,
  27099. Chedieresiscyrillic: 0x04F4,
  27100. Cheharmenian: 0x0543,
  27101. Chekhakassiancyrillic: 0x04CB,
  27102. Cheverticalstrokecyrillic: 0x04B8,
  27103. Chi: 0x03A7,
  27104. Chook: 0x0187,
  27105. Circumflexsmall: 0xF6F6,
  27106. Cmonospace: 0xFF23,
  27107. Coarmenian: 0x0551,
  27108. Csmall: 0xF763,
  27109. D: 0x0044,
  27110. DZ: 0x01F1,
  27111. DZcaron: 0x01C4,
  27112. Daarmenian: 0x0534,
  27113. Dafrican: 0x0189,
  27114. Dcaron: 0x010E,
  27115. Dcedilla: 0x1E10,
  27116. Dcircle: 0x24B9,
  27117. Dcircumflexbelow: 0x1E12,
  27118. Dcroat: 0x0110,
  27119. Ddotaccent: 0x1E0A,
  27120. Ddotbelow: 0x1E0C,
  27121. Decyrillic: 0x0414,
  27122. Deicoptic: 0x03EE,
  27123. Delta: 0x2206,
  27124. Deltagreek: 0x0394,
  27125. Dhook: 0x018A,
  27126. Dieresis: 0xF6CB,
  27127. DieresisAcute: 0xF6CC,
  27128. DieresisGrave: 0xF6CD,
  27129. Dieresissmall: 0xF7A8,
  27130. Digammagreek: 0x03DC,
  27131. Djecyrillic: 0x0402,
  27132. Dlinebelow: 0x1E0E,
  27133. Dmonospace: 0xFF24,
  27134. Dotaccentsmall: 0xF6F7,
  27135. Dslash: 0x0110,
  27136. Dsmall: 0xF764,
  27137. Dtopbar: 0x018B,
  27138. Dz: 0x01F2,
  27139. Dzcaron: 0x01C5,
  27140. Dzeabkhasiancyrillic: 0x04E0,
  27141. Dzecyrillic: 0x0405,
  27142. Dzhecyrillic: 0x040F,
  27143. E: 0x0045,
  27144. Eacute: 0x00C9,
  27145. Eacutesmall: 0xF7E9,
  27146. Ebreve: 0x0114,
  27147. Ecaron: 0x011A,
  27148. Ecedillabreve: 0x1E1C,
  27149. Echarmenian: 0x0535,
  27150. Ecircle: 0x24BA,
  27151. Ecircumflex: 0x00CA,
  27152. Ecircumflexacute: 0x1EBE,
  27153. Ecircumflexbelow: 0x1E18,
  27154. Ecircumflexdotbelow: 0x1EC6,
  27155. Ecircumflexgrave: 0x1EC0,
  27156. Ecircumflexhookabove: 0x1EC2,
  27157. Ecircumflexsmall: 0xF7EA,
  27158. Ecircumflextilde: 0x1EC4,
  27159. Ecyrillic: 0x0404,
  27160. Edblgrave: 0x0204,
  27161. Edieresis: 0x00CB,
  27162. Edieresissmall: 0xF7EB,
  27163. Edot: 0x0116,
  27164. Edotaccent: 0x0116,
  27165. Edotbelow: 0x1EB8,
  27166. Efcyrillic: 0x0424,
  27167. Egrave: 0x00C8,
  27168. Egravesmall: 0xF7E8,
  27169. Eharmenian: 0x0537,
  27170. Ehookabove: 0x1EBA,
  27171. Eightroman: 0x2167,
  27172. Einvertedbreve: 0x0206,
  27173. Eiotifiedcyrillic: 0x0464,
  27174. Elcyrillic: 0x041B,
  27175. Elevenroman: 0x216A,
  27176. Emacron: 0x0112,
  27177. Emacronacute: 0x1E16,
  27178. Emacrongrave: 0x1E14,
  27179. Emcyrillic: 0x041C,
  27180. Emonospace: 0xFF25,
  27181. Encyrillic: 0x041D,
  27182. Endescendercyrillic: 0x04A2,
  27183. Eng: 0x014A,
  27184. Enghecyrillic: 0x04A4,
  27185. Enhookcyrillic: 0x04C7,
  27186. Eogonek: 0x0118,
  27187. Eopen: 0x0190,
  27188. Epsilon: 0x0395,
  27189. Epsilontonos: 0x0388,
  27190. Ercyrillic: 0x0420,
  27191. Ereversed: 0x018E,
  27192. Ereversedcyrillic: 0x042D,
  27193. Escyrillic: 0x0421,
  27194. Esdescendercyrillic: 0x04AA,
  27195. Esh: 0x01A9,
  27196. Esmall: 0xF765,
  27197. Eta: 0x0397,
  27198. Etarmenian: 0x0538,
  27199. Etatonos: 0x0389,
  27200. Eth: 0x00D0,
  27201. Ethsmall: 0xF7F0,
  27202. Etilde: 0x1EBC,
  27203. Etildebelow: 0x1E1A,
  27204. Euro: 0x20AC,
  27205. Ezh: 0x01B7,
  27206. Ezhcaron: 0x01EE,
  27207. Ezhreversed: 0x01B8,
  27208. F: 0x0046,
  27209. Fcircle: 0x24BB,
  27210. Fdotaccent: 0x1E1E,
  27211. Feharmenian: 0x0556,
  27212. Feicoptic: 0x03E4,
  27213. Fhook: 0x0191,
  27214. Fitacyrillic: 0x0472,
  27215. Fiveroman: 0x2164,
  27216. Fmonospace: 0xFF26,
  27217. Fourroman: 0x2163,
  27218. Fsmall: 0xF766,
  27219. G: 0x0047,
  27220. GBsquare: 0x3387,
  27221. Gacute: 0x01F4,
  27222. Gamma: 0x0393,
  27223. Gammaafrican: 0x0194,
  27224. Gangiacoptic: 0x03EA,
  27225. Gbreve: 0x011E,
  27226. Gcaron: 0x01E6,
  27227. Gcedilla: 0x0122,
  27228. Gcircle: 0x24BC,
  27229. Gcircumflex: 0x011C,
  27230. Gcommaaccent: 0x0122,
  27231. Gdot: 0x0120,
  27232. Gdotaccent: 0x0120,
  27233. Gecyrillic: 0x0413,
  27234. Ghadarmenian: 0x0542,
  27235. Ghemiddlehookcyrillic: 0x0494,
  27236. Ghestrokecyrillic: 0x0492,
  27237. Gheupturncyrillic: 0x0490,
  27238. Ghook: 0x0193,
  27239. Gimarmenian: 0x0533,
  27240. Gjecyrillic: 0x0403,
  27241. Gmacron: 0x1E20,
  27242. Gmonospace: 0xFF27,
  27243. Grave: 0xF6CE,
  27244. Gravesmall: 0xF760,
  27245. Gsmall: 0xF767,
  27246. Gsmallhook: 0x029B,
  27247. Gstroke: 0x01E4,
  27248. H: 0x0048,
  27249. H18533: 0x25CF,
  27250. H18543: 0x25AA,
  27251. H18551: 0x25AB,
  27252. H22073: 0x25A1,
  27253. HPsquare: 0x33CB,
  27254. Haabkhasiancyrillic: 0x04A8,
  27255. Hadescendercyrillic: 0x04B2,
  27256. Hardsigncyrillic: 0x042A,
  27257. Hbar: 0x0126,
  27258. Hbrevebelow: 0x1E2A,
  27259. Hcedilla: 0x1E28,
  27260. Hcircle: 0x24BD,
  27261. Hcircumflex: 0x0124,
  27262. Hdieresis: 0x1E26,
  27263. Hdotaccent: 0x1E22,
  27264. Hdotbelow: 0x1E24,
  27265. Hmonospace: 0xFF28,
  27266. Hoarmenian: 0x0540,
  27267. Horicoptic: 0x03E8,
  27268. Hsmall: 0xF768,
  27269. Hungarumlaut: 0xF6CF,
  27270. Hungarumlautsmall: 0xF6F8,
  27271. Hzsquare: 0x3390,
  27272. I: 0x0049,
  27273. IAcyrillic: 0x042F,
  27274. IJ: 0x0132,
  27275. IUcyrillic: 0x042E,
  27276. Iacute: 0x00CD,
  27277. Iacutesmall: 0xF7ED,
  27278. Ibreve: 0x012C,
  27279. Icaron: 0x01CF,
  27280. Icircle: 0x24BE,
  27281. Icircumflex: 0x00CE,
  27282. Icircumflexsmall: 0xF7EE,
  27283. Icyrillic: 0x0406,
  27284. Idblgrave: 0x0208,
  27285. Idieresis: 0x00CF,
  27286. Idieresisacute: 0x1E2E,
  27287. Idieresiscyrillic: 0x04E4,
  27288. Idieresissmall: 0xF7EF,
  27289. Idot: 0x0130,
  27290. Idotaccent: 0x0130,
  27291. Idotbelow: 0x1ECA,
  27292. Iebrevecyrillic: 0x04D6,
  27293. Iecyrillic: 0x0415,
  27294. Ifraktur: 0x2111,
  27295. Igrave: 0x00CC,
  27296. Igravesmall: 0xF7EC,
  27297. Ihookabove: 0x1EC8,
  27298. Iicyrillic: 0x0418,
  27299. Iinvertedbreve: 0x020A,
  27300. Iishortcyrillic: 0x0419,
  27301. Imacron: 0x012A,
  27302. Imacroncyrillic: 0x04E2,
  27303. Imonospace: 0xFF29,
  27304. Iniarmenian: 0x053B,
  27305. Iocyrillic: 0x0401,
  27306. Iogonek: 0x012E,
  27307. Iota: 0x0399,
  27308. Iotaafrican: 0x0196,
  27309. Iotadieresis: 0x03AA,
  27310. Iotatonos: 0x038A,
  27311. Ismall: 0xF769,
  27312. Istroke: 0x0197,
  27313. Itilde: 0x0128,
  27314. Itildebelow: 0x1E2C,
  27315. Izhitsacyrillic: 0x0474,
  27316. Izhitsadblgravecyrillic: 0x0476,
  27317. J: 0x004A,
  27318. Jaarmenian: 0x0541,
  27319. Jcircle: 0x24BF,
  27320. Jcircumflex: 0x0134,
  27321. Jecyrillic: 0x0408,
  27322. Jheharmenian: 0x054B,
  27323. Jmonospace: 0xFF2A,
  27324. Jsmall: 0xF76A,
  27325. K: 0x004B,
  27326. KBsquare: 0x3385,
  27327. KKsquare: 0x33CD,
  27328. Kabashkircyrillic: 0x04A0,
  27329. Kacute: 0x1E30,
  27330. Kacyrillic: 0x041A,
  27331. Kadescendercyrillic: 0x049A,
  27332. Kahookcyrillic: 0x04C3,
  27333. Kappa: 0x039A,
  27334. Kastrokecyrillic: 0x049E,
  27335. Kaverticalstrokecyrillic: 0x049C,
  27336. Kcaron: 0x01E8,
  27337. Kcedilla: 0x0136,
  27338. Kcircle: 0x24C0,
  27339. Kcommaaccent: 0x0136,
  27340. Kdotbelow: 0x1E32,
  27341. Keharmenian: 0x0554,
  27342. Kenarmenian: 0x053F,
  27343. Khacyrillic: 0x0425,
  27344. Kheicoptic: 0x03E6,
  27345. Khook: 0x0198,
  27346. Kjecyrillic: 0x040C,
  27347. Klinebelow: 0x1E34,
  27348. Kmonospace: 0xFF2B,
  27349. Koppacyrillic: 0x0480,
  27350. Koppagreek: 0x03DE,
  27351. Ksicyrillic: 0x046E,
  27352. Ksmall: 0xF76B,
  27353. L: 0x004C,
  27354. LJ: 0x01C7,
  27355. LL: 0xF6BF,
  27356. Lacute: 0x0139,
  27357. Lambda: 0x039B,
  27358. Lcaron: 0x013D,
  27359. Lcedilla: 0x013B,
  27360. Lcircle: 0x24C1,
  27361. Lcircumflexbelow: 0x1E3C,
  27362. Lcommaaccent: 0x013B,
  27363. Ldot: 0x013F,
  27364. Ldotaccent: 0x013F,
  27365. Ldotbelow: 0x1E36,
  27366. Ldotbelowmacron: 0x1E38,
  27367. Liwnarmenian: 0x053C,
  27368. Lj: 0x01C8,
  27369. Ljecyrillic: 0x0409,
  27370. Llinebelow: 0x1E3A,
  27371. Lmonospace: 0xFF2C,
  27372. Lslash: 0x0141,
  27373. Lslashsmall: 0xF6F9,
  27374. Lsmall: 0xF76C,
  27375. M: 0x004D,
  27376. MBsquare: 0x3386,
  27377. Macron: 0xF6D0,
  27378. Macronsmall: 0xF7AF,
  27379. Macute: 0x1E3E,
  27380. Mcircle: 0x24C2,
  27381. Mdotaccent: 0x1E40,
  27382. Mdotbelow: 0x1E42,
  27383. Menarmenian: 0x0544,
  27384. Mmonospace: 0xFF2D,
  27385. Msmall: 0xF76D,
  27386. Mturned: 0x019C,
  27387. Mu: 0x039C,
  27388. N: 0x004E,
  27389. NJ: 0x01CA,
  27390. Nacute: 0x0143,
  27391. Ncaron: 0x0147,
  27392. Ncedilla: 0x0145,
  27393. Ncircle: 0x24C3,
  27394. Ncircumflexbelow: 0x1E4A,
  27395. Ncommaaccent: 0x0145,
  27396. Ndotaccent: 0x1E44,
  27397. Ndotbelow: 0x1E46,
  27398. Nhookleft: 0x019D,
  27399. Nineroman: 0x2168,
  27400. Nj: 0x01CB,
  27401. Njecyrillic: 0x040A,
  27402. Nlinebelow: 0x1E48,
  27403. Nmonospace: 0xFF2E,
  27404. Nowarmenian: 0x0546,
  27405. Nsmall: 0xF76E,
  27406. Ntilde: 0x00D1,
  27407. Ntildesmall: 0xF7F1,
  27408. Nu: 0x039D,
  27409. O: 0x004F,
  27410. OE: 0x0152,
  27411. OEsmall: 0xF6FA,
  27412. Oacute: 0x00D3,
  27413. Oacutesmall: 0xF7F3,
  27414. Obarredcyrillic: 0x04E8,
  27415. Obarreddieresiscyrillic: 0x04EA,
  27416. Obreve: 0x014E,
  27417. Ocaron: 0x01D1,
  27418. Ocenteredtilde: 0x019F,
  27419. Ocircle: 0x24C4,
  27420. Ocircumflex: 0x00D4,
  27421. Ocircumflexacute: 0x1ED0,
  27422. Ocircumflexdotbelow: 0x1ED8,
  27423. Ocircumflexgrave: 0x1ED2,
  27424. Ocircumflexhookabove: 0x1ED4,
  27425. Ocircumflexsmall: 0xF7F4,
  27426. Ocircumflextilde: 0x1ED6,
  27427. Ocyrillic: 0x041E,
  27428. Odblacute: 0x0150,
  27429. Odblgrave: 0x020C,
  27430. Odieresis: 0x00D6,
  27431. Odieresiscyrillic: 0x04E6,
  27432. Odieresissmall: 0xF7F6,
  27433. Odotbelow: 0x1ECC,
  27434. Ogoneksmall: 0xF6FB,
  27435. Ograve: 0x00D2,
  27436. Ogravesmall: 0xF7F2,
  27437. Oharmenian: 0x0555,
  27438. Ohm: 0x2126,
  27439. Ohookabove: 0x1ECE,
  27440. Ohorn: 0x01A0,
  27441. Ohornacute: 0x1EDA,
  27442. Ohorndotbelow: 0x1EE2,
  27443. Ohorngrave: 0x1EDC,
  27444. Ohornhookabove: 0x1EDE,
  27445. Ohorntilde: 0x1EE0,
  27446. Ohungarumlaut: 0x0150,
  27447. Oi: 0x01A2,
  27448. Oinvertedbreve: 0x020E,
  27449. Omacron: 0x014C,
  27450. Omacronacute: 0x1E52,
  27451. Omacrongrave: 0x1E50,
  27452. Omega: 0x2126,
  27453. Omegacyrillic: 0x0460,
  27454. Omegagreek: 0x03A9,
  27455. Omegaroundcyrillic: 0x047A,
  27456. Omegatitlocyrillic: 0x047C,
  27457. Omegatonos: 0x038F,
  27458. Omicron: 0x039F,
  27459. Omicrontonos: 0x038C,
  27460. Omonospace: 0xFF2F,
  27461. Oneroman: 0x2160,
  27462. Oogonek: 0x01EA,
  27463. Oogonekmacron: 0x01EC,
  27464. Oopen: 0x0186,
  27465. Oslash: 0x00D8,
  27466. Oslashacute: 0x01FE,
  27467. Oslashsmall: 0xF7F8,
  27468. Osmall: 0xF76F,
  27469. Ostrokeacute: 0x01FE,
  27470. Otcyrillic: 0x047E,
  27471. Otilde: 0x00D5,
  27472. Otildeacute: 0x1E4C,
  27473. Otildedieresis: 0x1E4E,
  27474. Otildesmall: 0xF7F5,
  27475. P: 0x0050,
  27476. Pacute: 0x1E54,
  27477. Pcircle: 0x24C5,
  27478. Pdotaccent: 0x1E56,
  27479. Pecyrillic: 0x041F,
  27480. Peharmenian: 0x054A,
  27481. Pemiddlehookcyrillic: 0x04A6,
  27482. Phi: 0x03A6,
  27483. Phook: 0x01A4,
  27484. Pi: 0x03A0,
  27485. Piwrarmenian: 0x0553,
  27486. Pmonospace: 0xFF30,
  27487. Psi: 0x03A8,
  27488. Psicyrillic: 0x0470,
  27489. Psmall: 0xF770,
  27490. Q: 0x0051,
  27491. Qcircle: 0x24C6,
  27492. Qmonospace: 0xFF31,
  27493. Qsmall: 0xF771,
  27494. R: 0x0052,
  27495. Raarmenian: 0x054C,
  27496. Racute: 0x0154,
  27497. Rcaron: 0x0158,
  27498. Rcedilla: 0x0156,
  27499. Rcircle: 0x24C7,
  27500. Rcommaaccent: 0x0156,
  27501. Rdblgrave: 0x0210,
  27502. Rdotaccent: 0x1E58,
  27503. Rdotbelow: 0x1E5A,
  27504. Rdotbelowmacron: 0x1E5C,
  27505. Reharmenian: 0x0550,
  27506. Rfraktur: 0x211C,
  27507. Rho: 0x03A1,
  27508. Ringsmall: 0xF6FC,
  27509. Rinvertedbreve: 0x0212,
  27510. Rlinebelow: 0x1E5E,
  27511. Rmonospace: 0xFF32,
  27512. Rsmall: 0xF772,
  27513. Rsmallinverted: 0x0281,
  27514. Rsmallinvertedsuperior: 0x02B6,
  27515. S: 0x0053,
  27516. SF010000: 0x250C,
  27517. SF020000: 0x2514,
  27518. SF030000: 0x2510,
  27519. SF040000: 0x2518,
  27520. SF050000: 0x253C,
  27521. SF060000: 0x252C,
  27522. SF070000: 0x2534,
  27523. SF080000: 0x251C,
  27524. SF090000: 0x2524,
  27525. SF100000: 0x2500,
  27526. SF110000: 0x2502,
  27527. SF190000: 0x2561,
  27528. SF200000: 0x2562,
  27529. SF210000: 0x2556,
  27530. SF220000: 0x2555,
  27531. SF230000: 0x2563,
  27532. SF240000: 0x2551,
  27533. SF250000: 0x2557,
  27534. SF260000: 0x255D,
  27535. SF270000: 0x255C,
  27536. SF280000: 0x255B,
  27537. SF360000: 0x255E,
  27538. SF370000: 0x255F,
  27539. SF380000: 0x255A,
  27540. SF390000: 0x2554,
  27541. SF400000: 0x2569,
  27542. SF410000: 0x2566,
  27543. SF420000: 0x2560,
  27544. SF430000: 0x2550,
  27545. SF440000: 0x256C,
  27546. SF450000: 0x2567,
  27547. SF460000: 0x2568,
  27548. SF470000: 0x2564,
  27549. SF480000: 0x2565,
  27550. SF490000: 0x2559,
  27551. SF500000: 0x2558,
  27552. SF510000: 0x2552,
  27553. SF520000: 0x2553,
  27554. SF530000: 0x256B,
  27555. SF540000: 0x256A,
  27556. Sacute: 0x015A,
  27557. Sacutedotaccent: 0x1E64,
  27558. Sampigreek: 0x03E0,
  27559. Scaron: 0x0160,
  27560. Scarondotaccent: 0x1E66,
  27561. Scaronsmall: 0xF6FD,
  27562. Scedilla: 0x015E,
  27563. Schwa: 0x018F,
  27564. Schwacyrillic: 0x04D8,
  27565. Schwadieresiscyrillic: 0x04DA,
  27566. Scircle: 0x24C8,
  27567. Scircumflex: 0x015C,
  27568. Scommaaccent: 0x0218,
  27569. Sdotaccent: 0x1E60,
  27570. Sdotbelow: 0x1E62,
  27571. Sdotbelowdotaccent: 0x1E68,
  27572. Seharmenian: 0x054D,
  27573. Sevenroman: 0x2166,
  27574. Shaarmenian: 0x0547,
  27575. Shacyrillic: 0x0428,
  27576. Shchacyrillic: 0x0429,
  27577. Sheicoptic: 0x03E2,
  27578. Shhacyrillic: 0x04BA,
  27579. Shimacoptic: 0x03EC,
  27580. Sigma: 0x03A3,
  27581. Sixroman: 0x2165,
  27582. Smonospace: 0xFF33,
  27583. Softsigncyrillic: 0x042C,
  27584. Ssmall: 0xF773,
  27585. Stigmagreek: 0x03DA,
  27586. T: 0x0054,
  27587. Tau: 0x03A4,
  27588. Tbar: 0x0166,
  27589. Tcaron: 0x0164,
  27590. Tcedilla: 0x0162,
  27591. Tcircle: 0x24C9,
  27592. Tcircumflexbelow: 0x1E70,
  27593. Tcommaaccent: 0x0162,
  27594. Tdotaccent: 0x1E6A,
  27595. Tdotbelow: 0x1E6C,
  27596. Tecyrillic: 0x0422,
  27597. Tedescendercyrillic: 0x04AC,
  27598. Tenroman: 0x2169,
  27599. Tetsecyrillic: 0x04B4,
  27600. Theta: 0x0398,
  27601. Thook: 0x01AC,
  27602. Thorn: 0x00DE,
  27603. Thornsmall: 0xF7FE,
  27604. Threeroman: 0x2162,
  27605. Tildesmall: 0xF6FE,
  27606. Tiwnarmenian: 0x054F,
  27607. Tlinebelow: 0x1E6E,
  27608. Tmonospace: 0xFF34,
  27609. Toarmenian: 0x0539,
  27610. Tonefive: 0x01BC,
  27611. Tonesix: 0x0184,
  27612. Tonetwo: 0x01A7,
  27613. Tretroflexhook: 0x01AE,
  27614. Tsecyrillic: 0x0426,
  27615. Tshecyrillic: 0x040B,
  27616. Tsmall: 0xF774,
  27617. Twelveroman: 0x216B,
  27618. Tworoman: 0x2161,
  27619. U: 0x0055,
  27620. Uacute: 0x00DA,
  27621. Uacutesmall: 0xF7FA,
  27622. Ubreve: 0x016C,
  27623. Ucaron: 0x01D3,
  27624. Ucircle: 0x24CA,
  27625. Ucircumflex: 0x00DB,
  27626. Ucircumflexbelow: 0x1E76,
  27627. Ucircumflexsmall: 0xF7FB,
  27628. Ucyrillic: 0x0423,
  27629. Udblacute: 0x0170,
  27630. Udblgrave: 0x0214,
  27631. Udieresis: 0x00DC,
  27632. Udieresisacute: 0x01D7,
  27633. Udieresisbelow: 0x1E72,
  27634. Udieresiscaron: 0x01D9,
  27635. Udieresiscyrillic: 0x04F0,
  27636. Udieresisgrave: 0x01DB,
  27637. Udieresismacron: 0x01D5,
  27638. Udieresissmall: 0xF7FC,
  27639. Udotbelow: 0x1EE4,
  27640. Ugrave: 0x00D9,
  27641. Ugravesmall: 0xF7F9,
  27642. Uhookabove: 0x1EE6,
  27643. Uhorn: 0x01AF,
  27644. Uhornacute: 0x1EE8,
  27645. Uhorndotbelow: 0x1EF0,
  27646. Uhorngrave: 0x1EEA,
  27647. Uhornhookabove: 0x1EEC,
  27648. Uhorntilde: 0x1EEE,
  27649. Uhungarumlaut: 0x0170,
  27650. Uhungarumlautcyrillic: 0x04F2,
  27651. Uinvertedbreve: 0x0216,
  27652. Ukcyrillic: 0x0478,
  27653. Umacron: 0x016A,
  27654. Umacroncyrillic: 0x04EE,
  27655. Umacrondieresis: 0x1E7A,
  27656. Umonospace: 0xFF35,
  27657. Uogonek: 0x0172,
  27658. Upsilon: 0x03A5,
  27659. Upsilon1: 0x03D2,
  27660. Upsilonacutehooksymbolgreek: 0x03D3,
  27661. Upsilonafrican: 0x01B1,
  27662. Upsilondieresis: 0x03AB,
  27663. Upsilondieresishooksymbolgreek: 0x03D4,
  27664. Upsilonhooksymbol: 0x03D2,
  27665. Upsilontonos: 0x038E,
  27666. Uring: 0x016E,
  27667. Ushortcyrillic: 0x040E,
  27668. Usmall: 0xF775,
  27669. Ustraightcyrillic: 0x04AE,
  27670. Ustraightstrokecyrillic: 0x04B0,
  27671. Utilde: 0x0168,
  27672. Utildeacute: 0x1E78,
  27673. Utildebelow: 0x1E74,
  27674. V: 0x0056,
  27675. Vcircle: 0x24CB,
  27676. Vdotbelow: 0x1E7E,
  27677. Vecyrillic: 0x0412,
  27678. Vewarmenian: 0x054E,
  27679. Vhook: 0x01B2,
  27680. Vmonospace: 0xFF36,
  27681. Voarmenian: 0x0548,
  27682. Vsmall: 0xF776,
  27683. Vtilde: 0x1E7C,
  27684. W: 0x0057,
  27685. Wacute: 0x1E82,
  27686. Wcircle: 0x24CC,
  27687. Wcircumflex: 0x0174,
  27688. Wdieresis: 0x1E84,
  27689. Wdotaccent: 0x1E86,
  27690. Wdotbelow: 0x1E88,
  27691. Wgrave: 0x1E80,
  27692. Wmonospace: 0xFF37,
  27693. Wsmall: 0xF777,
  27694. X: 0x0058,
  27695. Xcircle: 0x24CD,
  27696. Xdieresis: 0x1E8C,
  27697. Xdotaccent: 0x1E8A,
  27698. Xeharmenian: 0x053D,
  27699. Xi: 0x039E,
  27700. Xmonospace: 0xFF38,
  27701. Xsmall: 0xF778,
  27702. Y: 0x0059,
  27703. Yacute: 0x00DD,
  27704. Yacutesmall: 0xF7FD,
  27705. Yatcyrillic: 0x0462,
  27706. Ycircle: 0x24CE,
  27707. Ycircumflex: 0x0176,
  27708. Ydieresis: 0x0178,
  27709. Ydieresissmall: 0xF7FF,
  27710. Ydotaccent: 0x1E8E,
  27711. Ydotbelow: 0x1EF4,
  27712. Yericyrillic: 0x042B,
  27713. Yerudieresiscyrillic: 0x04F8,
  27714. Ygrave: 0x1EF2,
  27715. Yhook: 0x01B3,
  27716. Yhookabove: 0x1EF6,
  27717. Yiarmenian: 0x0545,
  27718. Yicyrillic: 0x0407,
  27719. Yiwnarmenian: 0x0552,
  27720. Ymonospace: 0xFF39,
  27721. Ysmall: 0xF779,
  27722. Ytilde: 0x1EF8,
  27723. Yusbigcyrillic: 0x046A,
  27724. Yusbigiotifiedcyrillic: 0x046C,
  27725. Yuslittlecyrillic: 0x0466,
  27726. Yuslittleiotifiedcyrillic: 0x0468,
  27727. Z: 0x005A,
  27728. Zaarmenian: 0x0536,
  27729. Zacute: 0x0179,
  27730. Zcaron: 0x017D,
  27731. Zcaronsmall: 0xF6FF,
  27732. Zcircle: 0x24CF,
  27733. Zcircumflex: 0x1E90,
  27734. Zdot: 0x017B,
  27735. Zdotaccent: 0x017B,
  27736. Zdotbelow: 0x1E92,
  27737. Zecyrillic: 0x0417,
  27738. Zedescendercyrillic: 0x0498,
  27739. Zedieresiscyrillic: 0x04DE,
  27740. Zeta: 0x0396,
  27741. Zhearmenian: 0x053A,
  27742. Zhebrevecyrillic: 0x04C1,
  27743. Zhecyrillic: 0x0416,
  27744. Zhedescendercyrillic: 0x0496,
  27745. Zhedieresiscyrillic: 0x04DC,
  27746. Zlinebelow: 0x1E94,
  27747. Zmonospace: 0xFF3A,
  27748. Zsmall: 0xF77A,
  27749. Zstroke: 0x01B5,
  27750. a: 0x0061,
  27751. aabengali: 0x0986,
  27752. aacute: 0x00E1,
  27753. aadeva: 0x0906,
  27754. aagujarati: 0x0A86,
  27755. aagurmukhi: 0x0A06,
  27756. aamatragurmukhi: 0x0A3E,
  27757. aarusquare: 0x3303,
  27758. aavowelsignbengali: 0x09BE,
  27759. aavowelsigndeva: 0x093E,
  27760. aavowelsigngujarati: 0x0ABE,
  27761. abbreviationmarkarmenian: 0x055F,
  27762. abbreviationsigndeva: 0x0970,
  27763. abengali: 0x0985,
  27764. abopomofo: 0x311A,
  27765. abreve: 0x0103,
  27766. abreveacute: 0x1EAF,
  27767. abrevecyrillic: 0x04D1,
  27768. abrevedotbelow: 0x1EB7,
  27769. abrevegrave: 0x1EB1,
  27770. abrevehookabove: 0x1EB3,
  27771. abrevetilde: 0x1EB5,
  27772. acaron: 0x01CE,
  27773. acircle: 0x24D0,
  27774. acircumflex: 0x00E2,
  27775. acircumflexacute: 0x1EA5,
  27776. acircumflexdotbelow: 0x1EAD,
  27777. acircumflexgrave: 0x1EA7,
  27778. acircumflexhookabove: 0x1EA9,
  27779. acircumflextilde: 0x1EAB,
  27780. acute: 0x00B4,
  27781. acutebelowcmb: 0x0317,
  27782. acutecmb: 0x0301,
  27783. acutecomb: 0x0301,
  27784. acutedeva: 0x0954,
  27785. acutelowmod: 0x02CF,
  27786. acutetonecmb: 0x0341,
  27787. acyrillic: 0x0430,
  27788. adblgrave: 0x0201,
  27789. addakgurmukhi: 0x0A71,
  27790. adeva: 0x0905,
  27791. adieresis: 0x00E4,
  27792. adieresiscyrillic: 0x04D3,
  27793. adieresismacron: 0x01DF,
  27794. adotbelow: 0x1EA1,
  27795. adotmacron: 0x01E1,
  27796. ae: 0x00E6,
  27797. aeacute: 0x01FD,
  27798. aekorean: 0x3150,
  27799. aemacron: 0x01E3,
  27800. afii00208: 0x2015,
  27801. afii08941: 0x20A4,
  27802. afii10017: 0x0410,
  27803. afii10018: 0x0411,
  27804. afii10019: 0x0412,
  27805. afii10020: 0x0413,
  27806. afii10021: 0x0414,
  27807. afii10022: 0x0415,
  27808. afii10023: 0x0401,
  27809. afii10024: 0x0416,
  27810. afii10025: 0x0417,
  27811. afii10026: 0x0418,
  27812. afii10027: 0x0419,
  27813. afii10028: 0x041A,
  27814. afii10029: 0x041B,
  27815. afii10030: 0x041C,
  27816. afii10031: 0x041D,
  27817. afii10032: 0x041E,
  27818. afii10033: 0x041F,
  27819. afii10034: 0x0420,
  27820. afii10035: 0x0421,
  27821. afii10036: 0x0422,
  27822. afii10037: 0x0423,
  27823. afii10038: 0x0424,
  27824. afii10039: 0x0425,
  27825. afii10040: 0x0426,
  27826. afii10041: 0x0427,
  27827. afii10042: 0x0428,
  27828. afii10043: 0x0429,
  27829. afii10044: 0x042A,
  27830. afii10045: 0x042B,
  27831. afii10046: 0x042C,
  27832. afii10047: 0x042D,
  27833. afii10048: 0x042E,
  27834. afii10049: 0x042F,
  27835. afii10050: 0x0490,
  27836. afii10051: 0x0402,
  27837. afii10052: 0x0403,
  27838. afii10053: 0x0404,
  27839. afii10054: 0x0405,
  27840. afii10055: 0x0406,
  27841. afii10056: 0x0407,
  27842. afii10057: 0x0408,
  27843. afii10058: 0x0409,
  27844. afii10059: 0x040A,
  27845. afii10060: 0x040B,
  27846. afii10061: 0x040C,
  27847. afii10062: 0x040E,
  27848. afii10063: 0xF6C4,
  27849. afii10064: 0xF6C5,
  27850. afii10065: 0x0430,
  27851. afii10066: 0x0431,
  27852. afii10067: 0x0432,
  27853. afii10068: 0x0433,
  27854. afii10069: 0x0434,
  27855. afii10070: 0x0435,
  27856. afii10071: 0x0451,
  27857. afii10072: 0x0436,
  27858. afii10073: 0x0437,
  27859. afii10074: 0x0438,
  27860. afii10075: 0x0439,
  27861. afii10076: 0x043A,
  27862. afii10077: 0x043B,
  27863. afii10078: 0x043C,
  27864. afii10079: 0x043D,
  27865. afii10080: 0x043E,
  27866. afii10081: 0x043F,
  27867. afii10082: 0x0440,
  27868. afii10083: 0x0441,
  27869. afii10084: 0x0442,
  27870. afii10085: 0x0443,
  27871. afii10086: 0x0444,
  27872. afii10087: 0x0445,
  27873. afii10088: 0x0446,
  27874. afii10089: 0x0447,
  27875. afii10090: 0x0448,
  27876. afii10091: 0x0449,
  27877. afii10092: 0x044A,
  27878. afii10093: 0x044B,
  27879. afii10094: 0x044C,
  27880. afii10095: 0x044D,
  27881. afii10096: 0x044E,
  27882. afii10097: 0x044F,
  27883. afii10098: 0x0491,
  27884. afii10099: 0x0452,
  27885. afii10100: 0x0453,
  27886. afii10101: 0x0454,
  27887. afii10102: 0x0455,
  27888. afii10103: 0x0456,
  27889. afii10104: 0x0457,
  27890. afii10105: 0x0458,
  27891. afii10106: 0x0459,
  27892. afii10107: 0x045A,
  27893. afii10108: 0x045B,
  27894. afii10109: 0x045C,
  27895. afii10110: 0x045E,
  27896. afii10145: 0x040F,
  27897. afii10146: 0x0462,
  27898. afii10147: 0x0472,
  27899. afii10148: 0x0474,
  27900. afii10192: 0xF6C6,
  27901. afii10193: 0x045F,
  27902. afii10194: 0x0463,
  27903. afii10195: 0x0473,
  27904. afii10196: 0x0475,
  27905. afii10831: 0xF6C7,
  27906. afii10832: 0xF6C8,
  27907. afii10846: 0x04D9,
  27908. afii299: 0x200E,
  27909. afii300: 0x200F,
  27910. afii301: 0x200D,
  27911. afii57381: 0x066A,
  27912. afii57388: 0x060C,
  27913. afii57392: 0x0660,
  27914. afii57393: 0x0661,
  27915. afii57394: 0x0662,
  27916. afii57395: 0x0663,
  27917. afii57396: 0x0664,
  27918. afii57397: 0x0665,
  27919. afii57398: 0x0666,
  27920. afii57399: 0x0667,
  27921. afii57400: 0x0668,
  27922. afii57401: 0x0669,
  27923. afii57403: 0x061B,
  27924. afii57407: 0x061F,
  27925. afii57409: 0x0621,
  27926. afii57410: 0x0622,
  27927. afii57411: 0x0623,
  27928. afii57412: 0x0624,
  27929. afii57413: 0x0625,
  27930. afii57414: 0x0626,
  27931. afii57415: 0x0627,
  27932. afii57416: 0x0628,
  27933. afii57417: 0x0629,
  27934. afii57418: 0x062A,
  27935. afii57419: 0x062B,
  27936. afii57420: 0x062C,
  27937. afii57421: 0x062D,
  27938. afii57422: 0x062E,
  27939. afii57423: 0x062F,
  27940. afii57424: 0x0630,
  27941. afii57425: 0x0631,
  27942. afii57426: 0x0632,
  27943. afii57427: 0x0633,
  27944. afii57428: 0x0634,
  27945. afii57429: 0x0635,
  27946. afii57430: 0x0636,
  27947. afii57431: 0x0637,
  27948. afii57432: 0x0638,
  27949. afii57433: 0x0639,
  27950. afii57434: 0x063A,
  27951. afii57440: 0x0640,
  27952. afii57441: 0x0641,
  27953. afii57442: 0x0642,
  27954. afii57443: 0x0643,
  27955. afii57444: 0x0644,
  27956. afii57445: 0x0645,
  27957. afii57446: 0x0646,
  27958. afii57448: 0x0648,
  27959. afii57449: 0x0649,
  27960. afii57450: 0x064A,
  27961. afii57451: 0x064B,
  27962. afii57452: 0x064C,
  27963. afii57453: 0x064D,
  27964. afii57454: 0x064E,
  27965. afii57455: 0x064F,
  27966. afii57456: 0x0650,
  27967. afii57457: 0x0651,
  27968. afii57458: 0x0652,
  27969. afii57470: 0x0647,
  27970. afii57505: 0x06A4,
  27971. afii57506: 0x067E,
  27972. afii57507: 0x0686,
  27973. afii57508: 0x0698,
  27974. afii57509: 0x06AF,
  27975. afii57511: 0x0679,
  27976. afii57512: 0x0688,
  27977. afii57513: 0x0691,
  27978. afii57514: 0x06BA,
  27979. afii57519: 0x06D2,
  27980. afii57534: 0x06D5,
  27981. afii57636: 0x20AA,
  27982. afii57645: 0x05BE,
  27983. afii57658: 0x05C3,
  27984. afii57664: 0x05D0,
  27985. afii57665: 0x05D1,
  27986. afii57666: 0x05D2,
  27987. afii57667: 0x05D3,
  27988. afii57668: 0x05D4,
  27989. afii57669: 0x05D5,
  27990. afii57670: 0x05D6,
  27991. afii57671: 0x05D7,
  27992. afii57672: 0x05D8,
  27993. afii57673: 0x05D9,
  27994. afii57674: 0x05DA,
  27995. afii57675: 0x05DB,
  27996. afii57676: 0x05DC,
  27997. afii57677: 0x05DD,
  27998. afii57678: 0x05DE,
  27999. afii57679: 0x05DF,
  28000. afii57680: 0x05E0,
  28001. afii57681: 0x05E1,
  28002. afii57682: 0x05E2,
  28003. afii57683: 0x05E3,
  28004. afii57684: 0x05E4,
  28005. afii57685: 0x05E5,
  28006. afii57686: 0x05E6,
  28007. afii57687: 0x05E7,
  28008. afii57688: 0x05E8,
  28009. afii57689: 0x05E9,
  28010. afii57690: 0x05EA,
  28011. afii57694: 0xFB2A,
  28012. afii57695: 0xFB2B,
  28013. afii57700: 0xFB4B,
  28014. afii57705: 0xFB1F,
  28015. afii57716: 0x05F0,
  28016. afii57717: 0x05F1,
  28017. afii57718: 0x05F2,
  28018. afii57723: 0xFB35,
  28019. afii57793: 0x05B4,
  28020. afii57794: 0x05B5,
  28021. afii57795: 0x05B6,
  28022. afii57796: 0x05BB,
  28023. afii57797: 0x05B8,
  28024. afii57798: 0x05B7,
  28025. afii57799: 0x05B0,
  28026. afii57800: 0x05B2,
  28027. afii57801: 0x05B1,
  28028. afii57802: 0x05B3,
  28029. afii57803: 0x05C2,
  28030. afii57804: 0x05C1,
  28031. afii57806: 0x05B9,
  28032. afii57807: 0x05BC,
  28033. afii57839: 0x05BD,
  28034. afii57841: 0x05BF,
  28035. afii57842: 0x05C0,
  28036. afii57929: 0x02BC,
  28037. afii61248: 0x2105,
  28038. afii61289: 0x2113,
  28039. afii61352: 0x2116,
  28040. afii61573: 0x202C,
  28041. afii61574: 0x202D,
  28042. afii61575: 0x202E,
  28043. afii61664: 0x200C,
  28044. afii63167: 0x066D,
  28045. afii64937: 0x02BD,
  28046. agrave: 0x00E0,
  28047. agujarati: 0x0A85,
  28048. agurmukhi: 0x0A05,
  28049. ahiragana: 0x3042,
  28050. ahookabove: 0x1EA3,
  28051. aibengali: 0x0990,
  28052. aibopomofo: 0x311E,
  28053. aideva: 0x0910,
  28054. aiecyrillic: 0x04D5,
  28055. aigujarati: 0x0A90,
  28056. aigurmukhi: 0x0A10,
  28057. aimatragurmukhi: 0x0A48,
  28058. ainarabic: 0x0639,
  28059. ainfinalarabic: 0xFECA,
  28060. aininitialarabic: 0xFECB,
  28061. ainmedialarabic: 0xFECC,
  28062. ainvertedbreve: 0x0203,
  28063. aivowelsignbengali: 0x09C8,
  28064. aivowelsigndeva: 0x0948,
  28065. aivowelsigngujarati: 0x0AC8,
  28066. akatakana: 0x30A2,
  28067. akatakanahalfwidth: 0xFF71,
  28068. akorean: 0x314F,
  28069. alef: 0x05D0,
  28070. alefarabic: 0x0627,
  28071. alefdageshhebrew: 0xFB30,
  28072. aleffinalarabic: 0xFE8E,
  28073. alefhamzaabovearabic: 0x0623,
  28074. alefhamzaabovefinalarabic: 0xFE84,
  28075. alefhamzabelowarabic: 0x0625,
  28076. alefhamzabelowfinalarabic: 0xFE88,
  28077. alefhebrew: 0x05D0,
  28078. aleflamedhebrew: 0xFB4F,
  28079. alefmaddaabovearabic: 0x0622,
  28080. alefmaddaabovefinalarabic: 0xFE82,
  28081. alefmaksuraarabic: 0x0649,
  28082. alefmaksurafinalarabic: 0xFEF0,
  28083. alefmaksurainitialarabic: 0xFEF3,
  28084. alefmaksuramedialarabic: 0xFEF4,
  28085. alefpatahhebrew: 0xFB2E,
  28086. alefqamatshebrew: 0xFB2F,
  28087. aleph: 0x2135,
  28088. allequal: 0x224C,
  28089. alpha: 0x03B1,
  28090. alphatonos: 0x03AC,
  28091. amacron: 0x0101,
  28092. amonospace: 0xFF41,
  28093. ampersand: 0x0026,
  28094. ampersandmonospace: 0xFF06,
  28095. ampersandsmall: 0xF726,
  28096. amsquare: 0x33C2,
  28097. anbopomofo: 0x3122,
  28098. angbopomofo: 0x3124,
  28099. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  28100. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  28101. angkhankhuthai: 0x0E5A,
  28102. angle: 0x2220,
  28103. anglebracketleft: 0x3008,
  28104. anglebracketleftvertical: 0xFE3F,
  28105. anglebracketright: 0x3009,
  28106. anglebracketrightvertical: 0xFE40,
  28107. angleleft: 0x2329,
  28108. angleright: 0x232A,
  28109. angstrom: 0x212B,
  28110. anoteleia: 0x0387,
  28111. anudattadeva: 0x0952,
  28112. anusvarabengali: 0x0982,
  28113. anusvaradeva: 0x0902,
  28114. anusvaragujarati: 0x0A82,
  28115. aogonek: 0x0105,
  28116. apaatosquare: 0x3300,
  28117. aparen: 0x249C,
  28118. apostrophearmenian: 0x055A,
  28119. apostrophemod: 0x02BC,
  28120. apple: 0xF8FF,
  28121. approaches: 0x2250,
  28122. approxequal: 0x2248,
  28123. approxequalorimage: 0x2252,
  28124. approximatelyequal: 0x2245,
  28125. araeaekorean: 0x318E,
  28126. araeakorean: 0x318D,
  28127. arc: 0x2312,
  28128. arighthalfring: 0x1E9A,
  28129. aring: 0x00E5,
  28130. aringacute: 0x01FB,
  28131. aringbelow: 0x1E01,
  28132. arrowboth: 0x2194,
  28133. arrowdashdown: 0x21E3,
  28134. arrowdashleft: 0x21E0,
  28135. arrowdashright: 0x21E2,
  28136. arrowdashup: 0x21E1,
  28137. arrowdblboth: 0x21D4,
  28138. arrowdbldown: 0x21D3,
  28139. arrowdblleft: 0x21D0,
  28140. arrowdblright: 0x21D2,
  28141. arrowdblup: 0x21D1,
  28142. arrowdown: 0x2193,
  28143. arrowdownleft: 0x2199,
  28144. arrowdownright: 0x2198,
  28145. arrowdownwhite: 0x21E9,
  28146. arrowheaddownmod: 0x02C5,
  28147. arrowheadleftmod: 0x02C2,
  28148. arrowheadrightmod: 0x02C3,
  28149. arrowheadupmod: 0x02C4,
  28150. arrowhorizex: 0xF8E7,
  28151. arrowleft: 0x2190,
  28152. arrowleftdbl: 0x21D0,
  28153. arrowleftdblstroke: 0x21CD,
  28154. arrowleftoverright: 0x21C6,
  28155. arrowleftwhite: 0x21E6,
  28156. arrowright: 0x2192,
  28157. arrowrightdblstroke: 0x21CF,
  28158. arrowrightheavy: 0x279E,
  28159. arrowrightoverleft: 0x21C4,
  28160. arrowrightwhite: 0x21E8,
  28161. arrowtableft: 0x21E4,
  28162. arrowtabright: 0x21E5,
  28163. arrowup: 0x2191,
  28164. arrowupdn: 0x2195,
  28165. arrowupdnbse: 0x21A8,
  28166. arrowupdownbase: 0x21A8,
  28167. arrowupleft: 0x2196,
  28168. arrowupleftofdown: 0x21C5,
  28169. arrowupright: 0x2197,
  28170. arrowupwhite: 0x21E7,
  28171. arrowvertex: 0xF8E6,
  28172. asciicircum: 0x005E,
  28173. asciicircummonospace: 0xFF3E,
  28174. asciitilde: 0x007E,
  28175. asciitildemonospace: 0xFF5E,
  28176. ascript: 0x0251,
  28177. ascriptturned: 0x0252,
  28178. asmallhiragana: 0x3041,
  28179. asmallkatakana: 0x30A1,
  28180. asmallkatakanahalfwidth: 0xFF67,
  28181. asterisk: 0x002A,
  28182. asteriskaltonearabic: 0x066D,
  28183. asteriskarabic: 0x066D,
  28184. asteriskmath: 0x2217,
  28185. asteriskmonospace: 0xFF0A,
  28186. asterisksmall: 0xFE61,
  28187. asterism: 0x2042,
  28188. asuperior: 0xF6E9,
  28189. asymptoticallyequal: 0x2243,
  28190. at: 0x0040,
  28191. atilde: 0x00E3,
  28192. atmonospace: 0xFF20,
  28193. atsmall: 0xFE6B,
  28194. aturned: 0x0250,
  28195. aubengali: 0x0994,
  28196. aubopomofo: 0x3120,
  28197. audeva: 0x0914,
  28198. augujarati: 0x0A94,
  28199. augurmukhi: 0x0A14,
  28200. aulengthmarkbengali: 0x09D7,
  28201. aumatragurmukhi: 0x0A4C,
  28202. auvowelsignbengali: 0x09CC,
  28203. auvowelsigndeva: 0x094C,
  28204. auvowelsigngujarati: 0x0ACC,
  28205. avagrahadeva: 0x093D,
  28206. aybarmenian: 0x0561,
  28207. ayin: 0x05E2,
  28208. ayinaltonehebrew: 0xFB20,
  28209. ayinhebrew: 0x05E2,
  28210. b: 0x0062,
  28211. babengali: 0x09AC,
  28212. backslash: 0x005C,
  28213. backslashmonospace: 0xFF3C,
  28214. badeva: 0x092C,
  28215. bagujarati: 0x0AAC,
  28216. bagurmukhi: 0x0A2C,
  28217. bahiragana: 0x3070,
  28218. bahtthai: 0x0E3F,
  28219. bakatakana: 0x30D0,
  28220. bar: 0x007C,
  28221. barmonospace: 0xFF5C,
  28222. bbopomofo: 0x3105,
  28223. bcircle: 0x24D1,
  28224. bdotaccent: 0x1E03,
  28225. bdotbelow: 0x1E05,
  28226. beamedsixteenthnotes: 0x266C,
  28227. because: 0x2235,
  28228. becyrillic: 0x0431,
  28229. beharabic: 0x0628,
  28230. behfinalarabic: 0xFE90,
  28231. behinitialarabic: 0xFE91,
  28232. behiragana: 0x3079,
  28233. behmedialarabic: 0xFE92,
  28234. behmeeminitialarabic: 0xFC9F,
  28235. behmeemisolatedarabic: 0xFC08,
  28236. behnoonfinalarabic: 0xFC6D,
  28237. bekatakana: 0x30D9,
  28238. benarmenian: 0x0562,
  28239. bet: 0x05D1,
  28240. beta: 0x03B2,
  28241. betasymbolgreek: 0x03D0,
  28242. betdagesh: 0xFB31,
  28243. betdageshhebrew: 0xFB31,
  28244. bethebrew: 0x05D1,
  28245. betrafehebrew: 0xFB4C,
  28246. bhabengali: 0x09AD,
  28247. bhadeva: 0x092D,
  28248. bhagujarati: 0x0AAD,
  28249. bhagurmukhi: 0x0A2D,
  28250. bhook: 0x0253,
  28251. bihiragana: 0x3073,
  28252. bikatakana: 0x30D3,
  28253. bilabialclick: 0x0298,
  28254. bindigurmukhi: 0x0A02,
  28255. birusquare: 0x3331,
  28256. blackcircle: 0x25CF,
  28257. blackdiamond: 0x25C6,
  28258. blackdownpointingtriangle: 0x25BC,
  28259. blackleftpointingpointer: 0x25C4,
  28260. blackleftpointingtriangle: 0x25C0,
  28261. blacklenticularbracketleft: 0x3010,
  28262. blacklenticularbracketleftvertical: 0xFE3B,
  28263. blacklenticularbracketright: 0x3011,
  28264. blacklenticularbracketrightvertical: 0xFE3C,
  28265. blacklowerlefttriangle: 0x25E3,
  28266. blacklowerrighttriangle: 0x25E2,
  28267. blackrectangle: 0x25AC,
  28268. blackrightpointingpointer: 0x25BA,
  28269. blackrightpointingtriangle: 0x25B6,
  28270. blacksmallsquare: 0x25AA,
  28271. blacksmilingface: 0x263B,
  28272. blacksquare: 0x25A0,
  28273. blackstar: 0x2605,
  28274. blackupperlefttriangle: 0x25E4,
  28275. blackupperrighttriangle: 0x25E5,
  28276. blackuppointingsmalltriangle: 0x25B4,
  28277. blackuppointingtriangle: 0x25B2,
  28278. blank: 0x2423,
  28279. blinebelow: 0x1E07,
  28280. block: 0x2588,
  28281. bmonospace: 0xFF42,
  28282. bobaimaithai: 0x0E1A,
  28283. bohiragana: 0x307C,
  28284. bokatakana: 0x30DC,
  28285. bparen: 0x249D,
  28286. bqsquare: 0x33C3,
  28287. braceex: 0xF8F4,
  28288. braceleft: 0x007B,
  28289. braceleftbt: 0xF8F3,
  28290. braceleftmid: 0xF8F2,
  28291. braceleftmonospace: 0xFF5B,
  28292. braceleftsmall: 0xFE5B,
  28293. bracelefttp: 0xF8F1,
  28294. braceleftvertical: 0xFE37,
  28295. braceright: 0x007D,
  28296. bracerightbt: 0xF8FE,
  28297. bracerightmid: 0xF8FD,
  28298. bracerightmonospace: 0xFF5D,
  28299. bracerightsmall: 0xFE5C,
  28300. bracerighttp: 0xF8FC,
  28301. bracerightvertical: 0xFE38,
  28302. bracketleft: 0x005B,
  28303. bracketleftbt: 0xF8F0,
  28304. bracketleftex: 0xF8EF,
  28305. bracketleftmonospace: 0xFF3B,
  28306. bracketlefttp: 0xF8EE,
  28307. bracketright: 0x005D,
  28308. bracketrightbt: 0xF8FB,
  28309. bracketrightex: 0xF8FA,
  28310. bracketrightmonospace: 0xFF3D,
  28311. bracketrighttp: 0xF8F9,
  28312. breve: 0x02D8,
  28313. brevebelowcmb: 0x032E,
  28314. brevecmb: 0x0306,
  28315. breveinvertedbelowcmb: 0x032F,
  28316. breveinvertedcmb: 0x0311,
  28317. breveinverteddoublecmb: 0x0361,
  28318. bridgebelowcmb: 0x032A,
  28319. bridgeinvertedbelowcmb: 0x033A,
  28320. brokenbar: 0x00A6,
  28321. bstroke: 0x0180,
  28322. bsuperior: 0xF6EA,
  28323. btopbar: 0x0183,
  28324. buhiragana: 0x3076,
  28325. bukatakana: 0x30D6,
  28326. bullet: 0x2022,
  28327. bulletinverse: 0x25D8,
  28328. bulletoperator: 0x2219,
  28329. bullseye: 0x25CE,
  28330. c: 0x0063,
  28331. caarmenian: 0x056E,
  28332. cabengali: 0x099A,
  28333. cacute: 0x0107,
  28334. cadeva: 0x091A,
  28335. cagujarati: 0x0A9A,
  28336. cagurmukhi: 0x0A1A,
  28337. calsquare: 0x3388,
  28338. candrabindubengali: 0x0981,
  28339. candrabinducmb: 0x0310,
  28340. candrabindudeva: 0x0901,
  28341. candrabindugujarati: 0x0A81,
  28342. capslock: 0x21EA,
  28343. careof: 0x2105,
  28344. caron: 0x02C7,
  28345. caronbelowcmb: 0x032C,
  28346. caroncmb: 0x030C,
  28347. carriagereturn: 0x21B5,
  28348. cbopomofo: 0x3118,
  28349. ccaron: 0x010D,
  28350. ccedilla: 0x00E7,
  28351. ccedillaacute: 0x1E09,
  28352. ccircle: 0x24D2,
  28353. ccircumflex: 0x0109,
  28354. ccurl: 0x0255,
  28355. cdot: 0x010B,
  28356. cdotaccent: 0x010B,
  28357. cdsquare: 0x33C5,
  28358. cedilla: 0x00B8,
  28359. cedillacmb: 0x0327,
  28360. cent: 0x00A2,
  28361. centigrade: 0x2103,
  28362. centinferior: 0xF6DF,
  28363. centmonospace: 0xFFE0,
  28364. centoldstyle: 0xF7A2,
  28365. centsuperior: 0xF6E0,
  28366. chaarmenian: 0x0579,
  28367. chabengali: 0x099B,
  28368. chadeva: 0x091B,
  28369. chagujarati: 0x0A9B,
  28370. chagurmukhi: 0x0A1B,
  28371. chbopomofo: 0x3114,
  28372. cheabkhasiancyrillic: 0x04BD,
  28373. checkmark: 0x2713,
  28374. checyrillic: 0x0447,
  28375. chedescenderabkhasiancyrillic: 0x04BF,
  28376. chedescendercyrillic: 0x04B7,
  28377. chedieresiscyrillic: 0x04F5,
  28378. cheharmenian: 0x0573,
  28379. chekhakassiancyrillic: 0x04CC,
  28380. cheverticalstrokecyrillic: 0x04B9,
  28381. chi: 0x03C7,
  28382. chieuchacirclekorean: 0x3277,
  28383. chieuchaparenkorean: 0x3217,
  28384. chieuchcirclekorean: 0x3269,
  28385. chieuchkorean: 0x314A,
  28386. chieuchparenkorean: 0x3209,
  28387. chochangthai: 0x0E0A,
  28388. chochanthai: 0x0E08,
  28389. chochingthai: 0x0E09,
  28390. chochoethai: 0x0E0C,
  28391. chook: 0x0188,
  28392. cieucacirclekorean: 0x3276,
  28393. cieucaparenkorean: 0x3216,
  28394. cieuccirclekorean: 0x3268,
  28395. cieuckorean: 0x3148,
  28396. cieucparenkorean: 0x3208,
  28397. cieucuparenkorean: 0x321C,
  28398. circle: 0x25CB,
  28399. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  28400. circlemultiply: 0x2297,
  28401. circleot: 0x2299,
  28402. circleplus: 0x2295,
  28403. circlepostalmark: 0x3036,
  28404. circlewithlefthalfblack: 0x25D0,
  28405. circlewithrighthalfblack: 0x25D1,
  28406. circumflex: 0x02C6,
  28407. circumflexbelowcmb: 0x032D,
  28408. circumflexcmb: 0x0302,
  28409. clear: 0x2327,
  28410. clickalveolar: 0x01C2,
  28411. clickdental: 0x01C0,
  28412. clicklateral: 0x01C1,
  28413. clickretroflex: 0x01C3,
  28414. club: 0x2663,
  28415. clubsuitblack: 0x2663,
  28416. clubsuitwhite: 0x2667,
  28417. cmcubedsquare: 0x33A4,
  28418. cmonospace: 0xFF43,
  28419. cmsquaredsquare: 0x33A0,
  28420. coarmenian: 0x0581,
  28421. colon: 0x003A,
  28422. colonmonetary: 0x20A1,
  28423. colonmonospace: 0xFF1A,
  28424. colonsign: 0x20A1,
  28425. colonsmall: 0xFE55,
  28426. colontriangularhalfmod: 0x02D1,
  28427. colontriangularmod: 0x02D0,
  28428. comma: 0x002C,
  28429. commaabovecmb: 0x0313,
  28430. commaaboverightcmb: 0x0315,
  28431. commaaccent: 0xF6C3,
  28432. commaarabic: 0x060C,
  28433. commaarmenian: 0x055D,
  28434. commainferior: 0xF6E1,
  28435. commamonospace: 0xFF0C,
  28436. commareversedabovecmb: 0x0314,
  28437. commareversedmod: 0x02BD,
  28438. commasmall: 0xFE50,
  28439. commasuperior: 0xF6E2,
  28440. commaturnedabovecmb: 0x0312,
  28441. commaturnedmod: 0x02BB,
  28442. compass: 0x263C,
  28443. congruent: 0x2245,
  28444. contourintegral: 0x222E,
  28445. control: 0x2303,
  28446. controlACK: 0x0006,
  28447. controlBEL: 0x0007,
  28448. controlBS: 0x0008,
  28449. controlCAN: 0x0018,
  28450. controlCR: 0x000D,
  28451. controlDC1: 0x0011,
  28452. controlDC2: 0x0012,
  28453. controlDC3: 0x0013,
  28454. controlDC4: 0x0014,
  28455. controlDEL: 0x007F,
  28456. controlDLE: 0x0010,
  28457. controlEM: 0x0019,
  28458. controlENQ: 0x0005,
  28459. controlEOT: 0x0004,
  28460. controlESC: 0x001B,
  28461. controlETB: 0x0017,
  28462. controlETX: 0x0003,
  28463. controlFF: 0x000C,
  28464. controlFS: 0x001C,
  28465. controlGS: 0x001D,
  28466. controlHT: 0x0009,
  28467. controlLF: 0x000A,
  28468. controlNAK: 0x0015,
  28469. controlRS: 0x001E,
  28470. controlSI: 0x000F,
  28471. controlSO: 0x000E,
  28472. controlSOT: 0x0002,
  28473. controlSTX: 0x0001,
  28474. controlSUB: 0x001A,
  28475. controlSYN: 0x0016,
  28476. controlUS: 0x001F,
  28477. controlVT: 0x000B,
  28478. copyright: 0x00A9,
  28479. copyrightsans: 0xF8E9,
  28480. copyrightserif: 0xF6D9,
  28481. cornerbracketleft: 0x300C,
  28482. cornerbracketlefthalfwidth: 0xFF62,
  28483. cornerbracketleftvertical: 0xFE41,
  28484. cornerbracketright: 0x300D,
  28485. cornerbracketrighthalfwidth: 0xFF63,
  28486. cornerbracketrightvertical: 0xFE42,
  28487. corporationsquare: 0x337F,
  28488. cosquare: 0x33C7,
  28489. coverkgsquare: 0x33C6,
  28490. cparen: 0x249E,
  28491. cruzeiro: 0x20A2,
  28492. cstretched: 0x0297,
  28493. curlyand: 0x22CF,
  28494. curlyor: 0x22CE,
  28495. currency: 0x00A4,
  28496. cyrBreve: 0xF6D1,
  28497. cyrFlex: 0xF6D2,
  28498. cyrbreve: 0xF6D4,
  28499. cyrflex: 0xF6D5,
  28500. d: 0x0064,
  28501. daarmenian: 0x0564,
  28502. dabengali: 0x09A6,
  28503. dadarabic: 0x0636,
  28504. dadeva: 0x0926,
  28505. dadfinalarabic: 0xFEBE,
  28506. dadinitialarabic: 0xFEBF,
  28507. dadmedialarabic: 0xFEC0,
  28508. dagesh: 0x05BC,
  28509. dageshhebrew: 0x05BC,
  28510. dagger: 0x2020,
  28511. daggerdbl: 0x2021,
  28512. dagujarati: 0x0AA6,
  28513. dagurmukhi: 0x0A26,
  28514. dahiragana: 0x3060,
  28515. dakatakana: 0x30C0,
  28516. dalarabic: 0x062F,
  28517. dalet: 0x05D3,
  28518. daletdagesh: 0xFB33,
  28519. daletdageshhebrew: 0xFB33,
  28520. dalethebrew: 0x05D3,
  28521. dalfinalarabic: 0xFEAA,
  28522. dammaarabic: 0x064F,
  28523. dammalowarabic: 0x064F,
  28524. dammatanaltonearabic: 0x064C,
  28525. dammatanarabic: 0x064C,
  28526. danda: 0x0964,
  28527. dargahebrew: 0x05A7,
  28528. dargalefthebrew: 0x05A7,
  28529. dasiapneumatacyrilliccmb: 0x0485,
  28530. dblGrave: 0xF6D3,
  28531. dblanglebracketleft: 0x300A,
  28532. dblanglebracketleftvertical: 0xFE3D,
  28533. dblanglebracketright: 0x300B,
  28534. dblanglebracketrightvertical: 0xFE3E,
  28535. dblarchinvertedbelowcmb: 0x032B,
  28536. dblarrowleft: 0x21D4,
  28537. dblarrowright: 0x21D2,
  28538. dbldanda: 0x0965,
  28539. dblgrave: 0xF6D6,
  28540. dblgravecmb: 0x030F,
  28541. dblintegral: 0x222C,
  28542. dbllowline: 0x2017,
  28543. dbllowlinecmb: 0x0333,
  28544. dbloverlinecmb: 0x033F,
  28545. dblprimemod: 0x02BA,
  28546. dblverticalbar: 0x2016,
  28547. dblverticallineabovecmb: 0x030E,
  28548. dbopomofo: 0x3109,
  28549. dbsquare: 0x33C8,
  28550. dcaron: 0x010F,
  28551. dcedilla: 0x1E11,
  28552. dcircle: 0x24D3,
  28553. dcircumflexbelow: 0x1E13,
  28554. dcroat: 0x0111,
  28555. ddabengali: 0x09A1,
  28556. ddadeva: 0x0921,
  28557. ddagujarati: 0x0AA1,
  28558. ddagurmukhi: 0x0A21,
  28559. ddalarabic: 0x0688,
  28560. ddalfinalarabic: 0xFB89,
  28561. dddhadeva: 0x095C,
  28562. ddhabengali: 0x09A2,
  28563. ddhadeva: 0x0922,
  28564. ddhagujarati: 0x0AA2,
  28565. ddhagurmukhi: 0x0A22,
  28566. ddotaccent: 0x1E0B,
  28567. ddotbelow: 0x1E0D,
  28568. decimalseparatorarabic: 0x066B,
  28569. decimalseparatorpersian: 0x066B,
  28570. decyrillic: 0x0434,
  28571. degree: 0x00B0,
  28572. dehihebrew: 0x05AD,
  28573. dehiragana: 0x3067,
  28574. deicoptic: 0x03EF,
  28575. dekatakana: 0x30C7,
  28576. deleteleft: 0x232B,
  28577. deleteright: 0x2326,
  28578. delta: 0x03B4,
  28579. deltaturned: 0x018D,
  28580. denominatorminusonenumeratorbengali: 0x09F8,
  28581. dezh: 0x02A4,
  28582. dhabengali: 0x09A7,
  28583. dhadeva: 0x0927,
  28584. dhagujarati: 0x0AA7,
  28585. dhagurmukhi: 0x0A27,
  28586. dhook: 0x0257,
  28587. dialytikatonos: 0x0385,
  28588. dialytikatonoscmb: 0x0344,
  28589. diamond: 0x2666,
  28590. diamondsuitwhite: 0x2662,
  28591. dieresis: 0x00A8,
  28592. dieresisacute: 0xF6D7,
  28593. dieresisbelowcmb: 0x0324,
  28594. dieresiscmb: 0x0308,
  28595. dieresisgrave: 0xF6D8,
  28596. dieresistonos: 0x0385,
  28597. dihiragana: 0x3062,
  28598. dikatakana: 0x30C2,
  28599. dittomark: 0x3003,
  28600. divide: 0x00F7,
  28601. divides: 0x2223,
  28602. divisionslash: 0x2215,
  28603. djecyrillic: 0x0452,
  28604. dkshade: 0x2593,
  28605. dlinebelow: 0x1E0F,
  28606. dlsquare: 0x3397,
  28607. dmacron: 0x0111,
  28608. dmonospace: 0xFF44,
  28609. dnblock: 0x2584,
  28610. dochadathai: 0x0E0E,
  28611. dodekthai: 0x0E14,
  28612. dohiragana: 0x3069,
  28613. dokatakana: 0x30C9,
  28614. dollar: 0x0024,
  28615. dollarinferior: 0xF6E3,
  28616. dollarmonospace: 0xFF04,
  28617. dollaroldstyle: 0xF724,
  28618. dollarsmall: 0xFE69,
  28619. dollarsuperior: 0xF6E4,
  28620. dong: 0x20AB,
  28621. dorusquare: 0x3326,
  28622. dotaccent: 0x02D9,
  28623. dotaccentcmb: 0x0307,
  28624. dotbelowcmb: 0x0323,
  28625. dotbelowcomb: 0x0323,
  28626. dotkatakana: 0x30FB,
  28627. dotlessi: 0x0131,
  28628. dotlessj: 0xF6BE,
  28629. dotlessjstrokehook: 0x0284,
  28630. dotmath: 0x22C5,
  28631. dottedcircle: 0x25CC,
  28632. doubleyodpatah: 0xFB1F,
  28633. doubleyodpatahhebrew: 0xFB1F,
  28634. downtackbelowcmb: 0x031E,
  28635. downtackmod: 0x02D5,
  28636. dparen: 0x249F,
  28637. dsuperior: 0xF6EB,
  28638. dtail: 0x0256,
  28639. dtopbar: 0x018C,
  28640. duhiragana: 0x3065,
  28641. dukatakana: 0x30C5,
  28642. dz: 0x01F3,
  28643. dzaltone: 0x02A3,
  28644. dzcaron: 0x01C6,
  28645. dzcurl: 0x02A5,
  28646. dzeabkhasiancyrillic: 0x04E1,
  28647. dzecyrillic: 0x0455,
  28648. dzhecyrillic: 0x045F,
  28649. e: 0x0065,
  28650. eacute: 0x00E9,
  28651. earth: 0x2641,
  28652. ebengali: 0x098F,
  28653. ebopomofo: 0x311C,
  28654. ebreve: 0x0115,
  28655. ecandradeva: 0x090D,
  28656. ecandragujarati: 0x0A8D,
  28657. ecandravowelsigndeva: 0x0945,
  28658. ecandravowelsigngujarati: 0x0AC5,
  28659. ecaron: 0x011B,
  28660. ecedillabreve: 0x1E1D,
  28661. echarmenian: 0x0565,
  28662. echyiwnarmenian: 0x0587,
  28663. ecircle: 0x24D4,
  28664. ecircumflex: 0x00EA,
  28665. ecircumflexacute: 0x1EBF,
  28666. ecircumflexbelow: 0x1E19,
  28667. ecircumflexdotbelow: 0x1EC7,
  28668. ecircumflexgrave: 0x1EC1,
  28669. ecircumflexhookabove: 0x1EC3,
  28670. ecircumflextilde: 0x1EC5,
  28671. ecyrillic: 0x0454,
  28672. edblgrave: 0x0205,
  28673. edeva: 0x090F,
  28674. edieresis: 0x00EB,
  28675. edot: 0x0117,
  28676. edotaccent: 0x0117,
  28677. edotbelow: 0x1EB9,
  28678. eegurmukhi: 0x0A0F,
  28679. eematragurmukhi: 0x0A47,
  28680. efcyrillic: 0x0444,
  28681. egrave: 0x00E8,
  28682. egujarati: 0x0A8F,
  28683. eharmenian: 0x0567,
  28684. ehbopomofo: 0x311D,
  28685. ehiragana: 0x3048,
  28686. ehookabove: 0x1EBB,
  28687. eibopomofo: 0x311F,
  28688. eight: 0x0038,
  28689. eightarabic: 0x0668,
  28690. eightbengali: 0x09EE,
  28691. eightcircle: 0x2467,
  28692. eightcircleinversesansserif: 0x2791,
  28693. eightdeva: 0x096E,
  28694. eighteencircle: 0x2471,
  28695. eighteenparen: 0x2485,
  28696. eighteenperiod: 0x2499,
  28697. eightgujarati: 0x0AEE,
  28698. eightgurmukhi: 0x0A6E,
  28699. eighthackarabic: 0x0668,
  28700. eighthangzhou: 0x3028,
  28701. eighthnotebeamed: 0x266B,
  28702. eightideographicparen: 0x3227,
  28703. eightinferior: 0x2088,
  28704. eightmonospace: 0xFF18,
  28705. eightoldstyle: 0xF738,
  28706. eightparen: 0x247B,
  28707. eightperiod: 0x248F,
  28708. eightpersian: 0x06F8,
  28709. eightroman: 0x2177,
  28710. eightsuperior: 0x2078,
  28711. eightthai: 0x0E58,
  28712. einvertedbreve: 0x0207,
  28713. eiotifiedcyrillic: 0x0465,
  28714. ekatakana: 0x30A8,
  28715. ekatakanahalfwidth: 0xFF74,
  28716. ekonkargurmukhi: 0x0A74,
  28717. ekorean: 0x3154,
  28718. elcyrillic: 0x043B,
  28719. element: 0x2208,
  28720. elevencircle: 0x246A,
  28721. elevenparen: 0x247E,
  28722. elevenperiod: 0x2492,
  28723. elevenroman: 0x217A,
  28724. ellipsis: 0x2026,
  28725. ellipsisvertical: 0x22EE,
  28726. emacron: 0x0113,
  28727. emacronacute: 0x1E17,
  28728. emacrongrave: 0x1E15,
  28729. emcyrillic: 0x043C,
  28730. emdash: 0x2014,
  28731. emdashvertical: 0xFE31,
  28732. emonospace: 0xFF45,
  28733. emphasismarkarmenian: 0x055B,
  28734. emptyset: 0x2205,
  28735. enbopomofo: 0x3123,
  28736. encyrillic: 0x043D,
  28737. endash: 0x2013,
  28738. endashvertical: 0xFE32,
  28739. endescendercyrillic: 0x04A3,
  28740. eng: 0x014B,
  28741. engbopomofo: 0x3125,
  28742. enghecyrillic: 0x04A5,
  28743. enhookcyrillic: 0x04C8,
  28744. enspace: 0x2002,
  28745. eogonek: 0x0119,
  28746. eokorean: 0x3153,
  28747. eopen: 0x025B,
  28748. eopenclosed: 0x029A,
  28749. eopenreversed: 0x025C,
  28750. eopenreversedclosed: 0x025E,
  28751. eopenreversedhook: 0x025D,
  28752. eparen: 0x24A0,
  28753. epsilon: 0x03B5,
  28754. epsilontonos: 0x03AD,
  28755. equal: 0x003D,
  28756. equalmonospace: 0xFF1D,
  28757. equalsmall: 0xFE66,
  28758. equalsuperior: 0x207C,
  28759. equivalence: 0x2261,
  28760. erbopomofo: 0x3126,
  28761. ercyrillic: 0x0440,
  28762. ereversed: 0x0258,
  28763. ereversedcyrillic: 0x044D,
  28764. escyrillic: 0x0441,
  28765. esdescendercyrillic: 0x04AB,
  28766. esh: 0x0283,
  28767. eshcurl: 0x0286,
  28768. eshortdeva: 0x090E,
  28769. eshortvowelsigndeva: 0x0946,
  28770. eshreversedloop: 0x01AA,
  28771. eshsquatreversed: 0x0285,
  28772. esmallhiragana: 0x3047,
  28773. esmallkatakana: 0x30A7,
  28774. esmallkatakanahalfwidth: 0xFF6A,
  28775. estimated: 0x212E,
  28776. esuperior: 0xF6EC,
  28777. eta: 0x03B7,
  28778. etarmenian: 0x0568,
  28779. etatonos: 0x03AE,
  28780. eth: 0x00F0,
  28781. etilde: 0x1EBD,
  28782. etildebelow: 0x1E1B,
  28783. etnahtafoukhhebrew: 0x0591,
  28784. etnahtafoukhlefthebrew: 0x0591,
  28785. etnahtahebrew: 0x0591,
  28786. etnahtalefthebrew: 0x0591,
  28787. eturned: 0x01DD,
  28788. eukorean: 0x3161,
  28789. euro: 0x20AC,
  28790. evowelsignbengali: 0x09C7,
  28791. evowelsigndeva: 0x0947,
  28792. evowelsigngujarati: 0x0AC7,
  28793. exclam: 0x0021,
  28794. exclamarmenian: 0x055C,
  28795. exclamdbl: 0x203C,
  28796. exclamdown: 0x00A1,
  28797. exclamdownsmall: 0xF7A1,
  28798. exclammonospace: 0xFF01,
  28799. exclamsmall: 0xF721,
  28800. existential: 0x2203,
  28801. ezh: 0x0292,
  28802. ezhcaron: 0x01EF,
  28803. ezhcurl: 0x0293,
  28804. ezhreversed: 0x01B9,
  28805. ezhtail: 0x01BA,
  28806. f: 0x0066,
  28807. fadeva: 0x095E,
  28808. fagurmukhi: 0x0A5E,
  28809. fahrenheit: 0x2109,
  28810. fathaarabic: 0x064E,
  28811. fathalowarabic: 0x064E,
  28812. fathatanarabic: 0x064B,
  28813. fbopomofo: 0x3108,
  28814. fcircle: 0x24D5,
  28815. fdotaccent: 0x1E1F,
  28816. feharabic: 0x0641,
  28817. feharmenian: 0x0586,
  28818. fehfinalarabic: 0xFED2,
  28819. fehinitialarabic: 0xFED3,
  28820. fehmedialarabic: 0xFED4,
  28821. feicoptic: 0x03E5,
  28822. female: 0x2640,
  28823. ff: 0xFB00,
  28824. ffi: 0xFB03,
  28825. ffl: 0xFB04,
  28826. fi: 0xFB01,
  28827. fifteencircle: 0x246E,
  28828. fifteenparen: 0x2482,
  28829. fifteenperiod: 0x2496,
  28830. figuredash: 0x2012,
  28831. filledbox: 0x25A0,
  28832. filledrect: 0x25AC,
  28833. finalkaf: 0x05DA,
  28834. finalkafdagesh: 0xFB3A,
  28835. finalkafdageshhebrew: 0xFB3A,
  28836. finalkafhebrew: 0x05DA,
  28837. finalmem: 0x05DD,
  28838. finalmemhebrew: 0x05DD,
  28839. finalnun: 0x05DF,
  28840. finalnunhebrew: 0x05DF,
  28841. finalpe: 0x05E3,
  28842. finalpehebrew: 0x05E3,
  28843. finaltsadi: 0x05E5,
  28844. finaltsadihebrew: 0x05E5,
  28845. firsttonechinese: 0x02C9,
  28846. fisheye: 0x25C9,
  28847. fitacyrillic: 0x0473,
  28848. five: 0x0035,
  28849. fivearabic: 0x0665,
  28850. fivebengali: 0x09EB,
  28851. fivecircle: 0x2464,
  28852. fivecircleinversesansserif: 0x278E,
  28853. fivedeva: 0x096B,
  28854. fiveeighths: 0x215D,
  28855. fivegujarati: 0x0AEB,
  28856. fivegurmukhi: 0x0A6B,
  28857. fivehackarabic: 0x0665,
  28858. fivehangzhou: 0x3025,
  28859. fiveideographicparen: 0x3224,
  28860. fiveinferior: 0x2085,
  28861. fivemonospace: 0xFF15,
  28862. fiveoldstyle: 0xF735,
  28863. fiveparen: 0x2478,
  28864. fiveperiod: 0x248C,
  28865. fivepersian: 0x06F5,
  28866. fiveroman: 0x2174,
  28867. fivesuperior: 0x2075,
  28868. fivethai: 0x0E55,
  28869. fl: 0xFB02,
  28870. florin: 0x0192,
  28871. fmonospace: 0xFF46,
  28872. fmsquare: 0x3399,
  28873. fofanthai: 0x0E1F,
  28874. fofathai: 0x0E1D,
  28875. fongmanthai: 0x0E4F,
  28876. forall: 0x2200,
  28877. four: 0x0034,
  28878. fourarabic: 0x0664,
  28879. fourbengali: 0x09EA,
  28880. fourcircle: 0x2463,
  28881. fourcircleinversesansserif: 0x278D,
  28882. fourdeva: 0x096A,
  28883. fourgujarati: 0x0AEA,
  28884. fourgurmukhi: 0x0A6A,
  28885. fourhackarabic: 0x0664,
  28886. fourhangzhou: 0x3024,
  28887. fourideographicparen: 0x3223,
  28888. fourinferior: 0x2084,
  28889. fourmonospace: 0xFF14,
  28890. fournumeratorbengali: 0x09F7,
  28891. fouroldstyle: 0xF734,
  28892. fourparen: 0x2477,
  28893. fourperiod: 0x248B,
  28894. fourpersian: 0x06F4,
  28895. fourroman: 0x2173,
  28896. foursuperior: 0x2074,
  28897. fourteencircle: 0x246D,
  28898. fourteenparen: 0x2481,
  28899. fourteenperiod: 0x2495,
  28900. fourthai: 0x0E54,
  28901. fourthtonechinese: 0x02CB,
  28902. fparen: 0x24A1,
  28903. fraction: 0x2044,
  28904. franc: 0x20A3,
  28905. g: 0x0067,
  28906. gabengali: 0x0997,
  28907. gacute: 0x01F5,
  28908. gadeva: 0x0917,
  28909. gafarabic: 0x06AF,
  28910. gaffinalarabic: 0xFB93,
  28911. gafinitialarabic: 0xFB94,
  28912. gafmedialarabic: 0xFB95,
  28913. gagujarati: 0x0A97,
  28914. gagurmukhi: 0x0A17,
  28915. gahiragana: 0x304C,
  28916. gakatakana: 0x30AC,
  28917. gamma: 0x03B3,
  28918. gammalatinsmall: 0x0263,
  28919. gammasuperior: 0x02E0,
  28920. gangiacoptic: 0x03EB,
  28921. gbopomofo: 0x310D,
  28922. gbreve: 0x011F,
  28923. gcaron: 0x01E7,
  28924. gcedilla: 0x0123,
  28925. gcircle: 0x24D6,
  28926. gcircumflex: 0x011D,
  28927. gcommaaccent: 0x0123,
  28928. gdot: 0x0121,
  28929. gdotaccent: 0x0121,
  28930. gecyrillic: 0x0433,
  28931. gehiragana: 0x3052,
  28932. gekatakana: 0x30B2,
  28933. geometricallyequal: 0x2251,
  28934. gereshaccenthebrew: 0x059C,
  28935. gereshhebrew: 0x05F3,
  28936. gereshmuqdamhebrew: 0x059D,
  28937. germandbls: 0x00DF,
  28938. gershayimaccenthebrew: 0x059E,
  28939. gershayimhebrew: 0x05F4,
  28940. getamark: 0x3013,
  28941. ghabengali: 0x0998,
  28942. ghadarmenian: 0x0572,
  28943. ghadeva: 0x0918,
  28944. ghagujarati: 0x0A98,
  28945. ghagurmukhi: 0x0A18,
  28946. ghainarabic: 0x063A,
  28947. ghainfinalarabic: 0xFECE,
  28948. ghaininitialarabic: 0xFECF,
  28949. ghainmedialarabic: 0xFED0,
  28950. ghemiddlehookcyrillic: 0x0495,
  28951. ghestrokecyrillic: 0x0493,
  28952. gheupturncyrillic: 0x0491,
  28953. ghhadeva: 0x095A,
  28954. ghhagurmukhi: 0x0A5A,
  28955. ghook: 0x0260,
  28956. ghzsquare: 0x3393,
  28957. gihiragana: 0x304E,
  28958. gikatakana: 0x30AE,
  28959. gimarmenian: 0x0563,
  28960. gimel: 0x05D2,
  28961. gimeldagesh: 0xFB32,
  28962. gimeldageshhebrew: 0xFB32,
  28963. gimelhebrew: 0x05D2,
  28964. gjecyrillic: 0x0453,
  28965. glottalinvertedstroke: 0x01BE,
  28966. glottalstop: 0x0294,
  28967. glottalstopinverted: 0x0296,
  28968. glottalstopmod: 0x02C0,
  28969. glottalstopreversed: 0x0295,
  28970. glottalstopreversedmod: 0x02C1,
  28971. glottalstopreversedsuperior: 0x02E4,
  28972. glottalstopstroke: 0x02A1,
  28973. glottalstopstrokereversed: 0x02A2,
  28974. gmacron: 0x1E21,
  28975. gmonospace: 0xFF47,
  28976. gohiragana: 0x3054,
  28977. gokatakana: 0x30B4,
  28978. gparen: 0x24A2,
  28979. gpasquare: 0x33AC,
  28980. gradient: 0x2207,
  28981. grave: 0x0060,
  28982. gravebelowcmb: 0x0316,
  28983. gravecmb: 0x0300,
  28984. gravecomb: 0x0300,
  28985. gravedeva: 0x0953,
  28986. gravelowmod: 0x02CE,
  28987. gravemonospace: 0xFF40,
  28988. gravetonecmb: 0x0340,
  28989. greater: 0x003E,
  28990. greaterequal: 0x2265,
  28991. greaterequalorless: 0x22DB,
  28992. greatermonospace: 0xFF1E,
  28993. greaterorequivalent: 0x2273,
  28994. greaterorless: 0x2277,
  28995. greateroverequal: 0x2267,
  28996. greatersmall: 0xFE65,
  28997. gscript: 0x0261,
  28998. gstroke: 0x01E5,
  28999. guhiragana: 0x3050,
  29000. guillemotleft: 0x00AB,
  29001. guillemotright: 0x00BB,
  29002. guilsinglleft: 0x2039,
  29003. guilsinglright: 0x203A,
  29004. gukatakana: 0x30B0,
  29005. guramusquare: 0x3318,
  29006. gysquare: 0x33C9,
  29007. h: 0x0068,
  29008. haabkhasiancyrillic: 0x04A9,
  29009. haaltonearabic: 0x06C1,
  29010. habengali: 0x09B9,
  29011. hadescendercyrillic: 0x04B3,
  29012. hadeva: 0x0939,
  29013. hagujarati: 0x0AB9,
  29014. hagurmukhi: 0x0A39,
  29015. haharabic: 0x062D,
  29016. hahfinalarabic: 0xFEA2,
  29017. hahinitialarabic: 0xFEA3,
  29018. hahiragana: 0x306F,
  29019. hahmedialarabic: 0xFEA4,
  29020. haitusquare: 0x332A,
  29021. hakatakana: 0x30CF,
  29022. hakatakanahalfwidth: 0xFF8A,
  29023. halantgurmukhi: 0x0A4D,
  29024. hamzaarabic: 0x0621,
  29025. hamzalowarabic: 0x0621,
  29026. hangulfiller: 0x3164,
  29027. hardsigncyrillic: 0x044A,
  29028. harpoonleftbarbup: 0x21BC,
  29029. harpoonrightbarbup: 0x21C0,
  29030. hasquare: 0x33CA,
  29031. hatafpatah: 0x05B2,
  29032. hatafpatah16: 0x05B2,
  29033. hatafpatah23: 0x05B2,
  29034. hatafpatah2f: 0x05B2,
  29035. hatafpatahhebrew: 0x05B2,
  29036. hatafpatahnarrowhebrew: 0x05B2,
  29037. hatafpatahquarterhebrew: 0x05B2,
  29038. hatafpatahwidehebrew: 0x05B2,
  29039. hatafqamats: 0x05B3,
  29040. hatafqamats1b: 0x05B3,
  29041. hatafqamats28: 0x05B3,
  29042. hatafqamats34: 0x05B3,
  29043. hatafqamatshebrew: 0x05B3,
  29044. hatafqamatsnarrowhebrew: 0x05B3,
  29045. hatafqamatsquarterhebrew: 0x05B3,
  29046. hatafqamatswidehebrew: 0x05B3,
  29047. hatafsegol: 0x05B1,
  29048. hatafsegol17: 0x05B1,
  29049. hatafsegol24: 0x05B1,
  29050. hatafsegol30: 0x05B1,
  29051. hatafsegolhebrew: 0x05B1,
  29052. hatafsegolnarrowhebrew: 0x05B1,
  29053. hatafsegolquarterhebrew: 0x05B1,
  29054. hatafsegolwidehebrew: 0x05B1,
  29055. hbar: 0x0127,
  29056. hbopomofo: 0x310F,
  29057. hbrevebelow: 0x1E2B,
  29058. hcedilla: 0x1E29,
  29059. hcircle: 0x24D7,
  29060. hcircumflex: 0x0125,
  29061. hdieresis: 0x1E27,
  29062. hdotaccent: 0x1E23,
  29063. hdotbelow: 0x1E25,
  29064. he: 0x05D4,
  29065. heart: 0x2665,
  29066. heartsuitblack: 0x2665,
  29067. heartsuitwhite: 0x2661,
  29068. hedagesh: 0xFB34,
  29069. hedageshhebrew: 0xFB34,
  29070. hehaltonearabic: 0x06C1,
  29071. heharabic: 0x0647,
  29072. hehebrew: 0x05D4,
  29073. hehfinalaltonearabic: 0xFBA7,
  29074. hehfinalalttwoarabic: 0xFEEA,
  29075. hehfinalarabic: 0xFEEA,
  29076. hehhamzaabovefinalarabic: 0xFBA5,
  29077. hehhamzaaboveisolatedarabic: 0xFBA4,
  29078. hehinitialaltonearabic: 0xFBA8,
  29079. hehinitialarabic: 0xFEEB,
  29080. hehiragana: 0x3078,
  29081. hehmedialaltonearabic: 0xFBA9,
  29082. hehmedialarabic: 0xFEEC,
  29083. heiseierasquare: 0x337B,
  29084. hekatakana: 0x30D8,
  29085. hekatakanahalfwidth: 0xFF8D,
  29086. hekutaarusquare: 0x3336,
  29087. henghook: 0x0267,
  29088. herutusquare: 0x3339,
  29089. het: 0x05D7,
  29090. hethebrew: 0x05D7,
  29091. hhook: 0x0266,
  29092. hhooksuperior: 0x02B1,
  29093. hieuhacirclekorean: 0x327B,
  29094. hieuhaparenkorean: 0x321B,
  29095. hieuhcirclekorean: 0x326D,
  29096. hieuhkorean: 0x314E,
  29097. hieuhparenkorean: 0x320D,
  29098. hihiragana: 0x3072,
  29099. hikatakana: 0x30D2,
  29100. hikatakanahalfwidth: 0xFF8B,
  29101. hiriq: 0x05B4,
  29102. hiriq14: 0x05B4,
  29103. hiriq21: 0x05B4,
  29104. hiriq2d: 0x05B4,
  29105. hiriqhebrew: 0x05B4,
  29106. hiriqnarrowhebrew: 0x05B4,
  29107. hiriqquarterhebrew: 0x05B4,
  29108. hiriqwidehebrew: 0x05B4,
  29109. hlinebelow: 0x1E96,
  29110. hmonospace: 0xFF48,
  29111. hoarmenian: 0x0570,
  29112. hohipthai: 0x0E2B,
  29113. hohiragana: 0x307B,
  29114. hokatakana: 0x30DB,
  29115. hokatakanahalfwidth: 0xFF8E,
  29116. holam: 0x05B9,
  29117. holam19: 0x05B9,
  29118. holam26: 0x05B9,
  29119. holam32: 0x05B9,
  29120. holamhebrew: 0x05B9,
  29121. holamnarrowhebrew: 0x05B9,
  29122. holamquarterhebrew: 0x05B9,
  29123. holamwidehebrew: 0x05B9,
  29124. honokhukthai: 0x0E2E,
  29125. hookabovecomb: 0x0309,
  29126. hookcmb: 0x0309,
  29127. hookpalatalizedbelowcmb: 0x0321,
  29128. hookretroflexbelowcmb: 0x0322,
  29129. hoonsquare: 0x3342,
  29130. horicoptic: 0x03E9,
  29131. horizontalbar: 0x2015,
  29132. horncmb: 0x031B,
  29133. hotsprings: 0x2668,
  29134. house: 0x2302,
  29135. hparen: 0x24A3,
  29136. hsuperior: 0x02B0,
  29137. hturned: 0x0265,
  29138. huhiragana: 0x3075,
  29139. huiitosquare: 0x3333,
  29140. hukatakana: 0x30D5,
  29141. hukatakanahalfwidth: 0xFF8C,
  29142. hungarumlaut: 0x02DD,
  29143. hungarumlautcmb: 0x030B,
  29144. hv: 0x0195,
  29145. hyphen: 0x002D,
  29146. hypheninferior: 0xF6E5,
  29147. hyphenmonospace: 0xFF0D,
  29148. hyphensmall: 0xFE63,
  29149. hyphensuperior: 0xF6E6,
  29150. hyphentwo: 0x2010,
  29151. i: 0x0069,
  29152. iacute: 0x00ED,
  29153. iacyrillic: 0x044F,
  29154. ibengali: 0x0987,
  29155. ibopomofo: 0x3127,
  29156. ibreve: 0x012D,
  29157. icaron: 0x01D0,
  29158. icircle: 0x24D8,
  29159. icircumflex: 0x00EE,
  29160. icyrillic: 0x0456,
  29161. idblgrave: 0x0209,
  29162. ideographearthcircle: 0x328F,
  29163. ideographfirecircle: 0x328B,
  29164. ideographicallianceparen: 0x323F,
  29165. ideographiccallparen: 0x323A,
  29166. ideographiccentrecircle: 0x32A5,
  29167. ideographicclose: 0x3006,
  29168. ideographiccomma: 0x3001,
  29169. ideographiccommaleft: 0xFF64,
  29170. ideographiccongratulationparen: 0x3237,
  29171. ideographiccorrectcircle: 0x32A3,
  29172. ideographicearthparen: 0x322F,
  29173. ideographicenterpriseparen: 0x323D,
  29174. ideographicexcellentcircle: 0x329D,
  29175. ideographicfestivalparen: 0x3240,
  29176. ideographicfinancialcircle: 0x3296,
  29177. ideographicfinancialparen: 0x3236,
  29178. ideographicfireparen: 0x322B,
  29179. ideographichaveparen: 0x3232,
  29180. ideographichighcircle: 0x32A4,
  29181. ideographiciterationmark: 0x3005,
  29182. ideographiclaborcircle: 0x3298,
  29183. ideographiclaborparen: 0x3238,
  29184. ideographicleftcircle: 0x32A7,
  29185. ideographiclowcircle: 0x32A6,
  29186. ideographicmedicinecircle: 0x32A9,
  29187. ideographicmetalparen: 0x322E,
  29188. ideographicmoonparen: 0x322A,
  29189. ideographicnameparen: 0x3234,
  29190. ideographicperiod: 0x3002,
  29191. ideographicprintcircle: 0x329E,
  29192. ideographicreachparen: 0x3243,
  29193. ideographicrepresentparen: 0x3239,
  29194. ideographicresourceparen: 0x323E,
  29195. ideographicrightcircle: 0x32A8,
  29196. ideographicsecretcircle: 0x3299,
  29197. ideographicselfparen: 0x3242,
  29198. ideographicsocietyparen: 0x3233,
  29199. ideographicspace: 0x3000,
  29200. ideographicspecialparen: 0x3235,
  29201. ideographicstockparen: 0x3231,
  29202. ideographicstudyparen: 0x323B,
  29203. ideographicsunparen: 0x3230,
  29204. ideographicsuperviseparen: 0x323C,
  29205. ideographicwaterparen: 0x322C,
  29206. ideographicwoodparen: 0x322D,
  29207. ideographiczero: 0x3007,
  29208. ideographmetalcircle: 0x328E,
  29209. ideographmooncircle: 0x328A,
  29210. ideographnamecircle: 0x3294,
  29211. ideographsuncircle: 0x3290,
  29212. ideographwatercircle: 0x328C,
  29213. ideographwoodcircle: 0x328D,
  29214. ideva: 0x0907,
  29215. idieresis: 0x00EF,
  29216. idieresisacute: 0x1E2F,
  29217. idieresiscyrillic: 0x04E5,
  29218. idotbelow: 0x1ECB,
  29219. iebrevecyrillic: 0x04D7,
  29220. iecyrillic: 0x0435,
  29221. ieungacirclekorean: 0x3275,
  29222. ieungaparenkorean: 0x3215,
  29223. ieungcirclekorean: 0x3267,
  29224. ieungkorean: 0x3147,
  29225. ieungparenkorean: 0x3207,
  29226. igrave: 0x00EC,
  29227. igujarati: 0x0A87,
  29228. igurmukhi: 0x0A07,
  29229. ihiragana: 0x3044,
  29230. ihookabove: 0x1EC9,
  29231. iibengali: 0x0988,
  29232. iicyrillic: 0x0438,
  29233. iideva: 0x0908,
  29234. iigujarati: 0x0A88,
  29235. iigurmukhi: 0x0A08,
  29236. iimatragurmukhi: 0x0A40,
  29237. iinvertedbreve: 0x020B,
  29238. iishortcyrillic: 0x0439,
  29239. iivowelsignbengali: 0x09C0,
  29240. iivowelsigndeva: 0x0940,
  29241. iivowelsigngujarati: 0x0AC0,
  29242. ij: 0x0133,
  29243. ikatakana: 0x30A4,
  29244. ikatakanahalfwidth: 0xFF72,
  29245. ikorean: 0x3163,
  29246. ilde: 0x02DC,
  29247. iluyhebrew: 0x05AC,
  29248. imacron: 0x012B,
  29249. imacroncyrillic: 0x04E3,
  29250. imageorapproximatelyequal: 0x2253,
  29251. imatragurmukhi: 0x0A3F,
  29252. imonospace: 0xFF49,
  29253. increment: 0x2206,
  29254. infinity: 0x221E,
  29255. iniarmenian: 0x056B,
  29256. integral: 0x222B,
  29257. integralbottom: 0x2321,
  29258. integralbt: 0x2321,
  29259. integralex: 0xF8F5,
  29260. integraltop: 0x2320,
  29261. integraltp: 0x2320,
  29262. intersection: 0x2229,
  29263. intisquare: 0x3305,
  29264. invbullet: 0x25D8,
  29265. invcircle: 0x25D9,
  29266. invsmileface: 0x263B,
  29267. iocyrillic: 0x0451,
  29268. iogonek: 0x012F,
  29269. iota: 0x03B9,
  29270. iotadieresis: 0x03CA,
  29271. iotadieresistonos: 0x0390,
  29272. iotalatin: 0x0269,
  29273. iotatonos: 0x03AF,
  29274. iparen: 0x24A4,
  29275. irigurmukhi: 0x0A72,
  29276. ismallhiragana: 0x3043,
  29277. ismallkatakana: 0x30A3,
  29278. ismallkatakanahalfwidth: 0xFF68,
  29279. issharbengali: 0x09FA,
  29280. istroke: 0x0268,
  29281. isuperior: 0xF6ED,
  29282. iterationhiragana: 0x309D,
  29283. iterationkatakana: 0x30FD,
  29284. itilde: 0x0129,
  29285. itildebelow: 0x1E2D,
  29286. iubopomofo: 0x3129,
  29287. iucyrillic: 0x044E,
  29288. ivowelsignbengali: 0x09BF,
  29289. ivowelsigndeva: 0x093F,
  29290. ivowelsigngujarati: 0x0ABF,
  29291. izhitsacyrillic: 0x0475,
  29292. izhitsadblgravecyrillic: 0x0477,
  29293. j: 0x006A,
  29294. jaarmenian: 0x0571,
  29295. jabengali: 0x099C,
  29296. jadeva: 0x091C,
  29297. jagujarati: 0x0A9C,
  29298. jagurmukhi: 0x0A1C,
  29299. jbopomofo: 0x3110,
  29300. jcaron: 0x01F0,
  29301. jcircle: 0x24D9,
  29302. jcircumflex: 0x0135,
  29303. jcrossedtail: 0x029D,
  29304. jdotlessstroke: 0x025F,
  29305. jecyrillic: 0x0458,
  29306. jeemarabic: 0x062C,
  29307. jeemfinalarabic: 0xFE9E,
  29308. jeeminitialarabic: 0xFE9F,
  29309. jeemmedialarabic: 0xFEA0,
  29310. jeharabic: 0x0698,
  29311. jehfinalarabic: 0xFB8B,
  29312. jhabengali: 0x099D,
  29313. jhadeva: 0x091D,
  29314. jhagujarati: 0x0A9D,
  29315. jhagurmukhi: 0x0A1D,
  29316. jheharmenian: 0x057B,
  29317. jis: 0x3004,
  29318. jmonospace: 0xFF4A,
  29319. jparen: 0x24A5,
  29320. jsuperior: 0x02B2,
  29321. k: 0x006B,
  29322. kabashkircyrillic: 0x04A1,
  29323. kabengali: 0x0995,
  29324. kacute: 0x1E31,
  29325. kacyrillic: 0x043A,
  29326. kadescendercyrillic: 0x049B,
  29327. kadeva: 0x0915,
  29328. kaf: 0x05DB,
  29329. kafarabic: 0x0643,
  29330. kafdagesh: 0xFB3B,
  29331. kafdageshhebrew: 0xFB3B,
  29332. kaffinalarabic: 0xFEDA,
  29333. kafhebrew: 0x05DB,
  29334. kafinitialarabic: 0xFEDB,
  29335. kafmedialarabic: 0xFEDC,
  29336. kafrafehebrew: 0xFB4D,
  29337. kagujarati: 0x0A95,
  29338. kagurmukhi: 0x0A15,
  29339. kahiragana: 0x304B,
  29340. kahookcyrillic: 0x04C4,
  29341. kakatakana: 0x30AB,
  29342. kakatakanahalfwidth: 0xFF76,
  29343. kappa: 0x03BA,
  29344. kappasymbolgreek: 0x03F0,
  29345. kapyeounmieumkorean: 0x3171,
  29346. kapyeounphieuphkorean: 0x3184,
  29347. kapyeounpieupkorean: 0x3178,
  29348. kapyeounssangpieupkorean: 0x3179,
  29349. karoriisquare: 0x330D,
  29350. kashidaautoarabic: 0x0640,
  29351. kashidaautonosidebearingarabic: 0x0640,
  29352. kasmallkatakana: 0x30F5,
  29353. kasquare: 0x3384,
  29354. kasraarabic: 0x0650,
  29355. kasratanarabic: 0x064D,
  29356. kastrokecyrillic: 0x049F,
  29357. katahiraprolongmarkhalfwidth: 0xFF70,
  29358. kaverticalstrokecyrillic: 0x049D,
  29359. kbopomofo: 0x310E,
  29360. kcalsquare: 0x3389,
  29361. kcaron: 0x01E9,
  29362. kcedilla: 0x0137,
  29363. kcircle: 0x24DA,
  29364. kcommaaccent: 0x0137,
  29365. kdotbelow: 0x1E33,
  29366. keharmenian: 0x0584,
  29367. kehiragana: 0x3051,
  29368. kekatakana: 0x30B1,
  29369. kekatakanahalfwidth: 0xFF79,
  29370. kenarmenian: 0x056F,
  29371. kesmallkatakana: 0x30F6,
  29372. kgreenlandic: 0x0138,
  29373. khabengali: 0x0996,
  29374. khacyrillic: 0x0445,
  29375. khadeva: 0x0916,
  29376. khagujarati: 0x0A96,
  29377. khagurmukhi: 0x0A16,
  29378. khaharabic: 0x062E,
  29379. khahfinalarabic: 0xFEA6,
  29380. khahinitialarabic: 0xFEA7,
  29381. khahmedialarabic: 0xFEA8,
  29382. kheicoptic: 0x03E7,
  29383. khhadeva: 0x0959,
  29384. khhagurmukhi: 0x0A59,
  29385. khieukhacirclekorean: 0x3278,
  29386. khieukhaparenkorean: 0x3218,
  29387. khieukhcirclekorean: 0x326A,
  29388. khieukhkorean: 0x314B,
  29389. khieukhparenkorean: 0x320A,
  29390. khokhaithai: 0x0E02,
  29391. khokhonthai: 0x0E05,
  29392. khokhuatthai: 0x0E03,
  29393. khokhwaithai: 0x0E04,
  29394. khomutthai: 0x0E5B,
  29395. khook: 0x0199,
  29396. khorakhangthai: 0x0E06,
  29397. khzsquare: 0x3391,
  29398. kihiragana: 0x304D,
  29399. kikatakana: 0x30AD,
  29400. kikatakanahalfwidth: 0xFF77,
  29401. kiroguramusquare: 0x3315,
  29402. kiromeetorusquare: 0x3316,
  29403. kirosquare: 0x3314,
  29404. kiyeokacirclekorean: 0x326E,
  29405. kiyeokaparenkorean: 0x320E,
  29406. kiyeokcirclekorean: 0x3260,
  29407. kiyeokkorean: 0x3131,
  29408. kiyeokparenkorean: 0x3200,
  29409. kiyeoksioskorean: 0x3133,
  29410. kjecyrillic: 0x045C,
  29411. klinebelow: 0x1E35,
  29412. klsquare: 0x3398,
  29413. kmcubedsquare: 0x33A6,
  29414. kmonospace: 0xFF4B,
  29415. kmsquaredsquare: 0x33A2,
  29416. kohiragana: 0x3053,
  29417. kohmsquare: 0x33C0,
  29418. kokaithai: 0x0E01,
  29419. kokatakana: 0x30B3,
  29420. kokatakanahalfwidth: 0xFF7A,
  29421. kooposquare: 0x331E,
  29422. koppacyrillic: 0x0481,
  29423. koreanstandardsymbol: 0x327F,
  29424. koroniscmb: 0x0343,
  29425. kparen: 0x24A6,
  29426. kpasquare: 0x33AA,
  29427. ksicyrillic: 0x046F,
  29428. ktsquare: 0x33CF,
  29429. kturned: 0x029E,
  29430. kuhiragana: 0x304F,
  29431. kukatakana: 0x30AF,
  29432. kukatakanahalfwidth: 0xFF78,
  29433. kvsquare: 0x33B8,
  29434. kwsquare: 0x33BE,
  29435. l: 0x006C,
  29436. labengali: 0x09B2,
  29437. lacute: 0x013A,
  29438. ladeva: 0x0932,
  29439. lagujarati: 0x0AB2,
  29440. lagurmukhi: 0x0A32,
  29441. lakkhangyaothai: 0x0E45,
  29442. lamaleffinalarabic: 0xFEFC,
  29443. lamalefhamzaabovefinalarabic: 0xFEF8,
  29444. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  29445. lamalefhamzabelowfinalarabic: 0xFEFA,
  29446. lamalefhamzabelowisolatedarabic: 0xFEF9,
  29447. lamalefisolatedarabic: 0xFEFB,
  29448. lamalefmaddaabovefinalarabic: 0xFEF6,
  29449. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  29450. lamarabic: 0x0644,
  29451. lambda: 0x03BB,
  29452. lambdastroke: 0x019B,
  29453. lamed: 0x05DC,
  29454. lameddagesh: 0xFB3C,
  29455. lameddageshhebrew: 0xFB3C,
  29456. lamedhebrew: 0x05DC,
  29457. lamfinalarabic: 0xFEDE,
  29458. lamhahinitialarabic: 0xFCCA,
  29459. laminitialarabic: 0xFEDF,
  29460. lamjeeminitialarabic: 0xFCC9,
  29461. lamkhahinitialarabic: 0xFCCB,
  29462. lamlamhehisolatedarabic: 0xFDF2,
  29463. lammedialarabic: 0xFEE0,
  29464. lammeemhahinitialarabic: 0xFD88,
  29465. lammeeminitialarabic: 0xFCCC,
  29466. largecircle: 0x25EF,
  29467. lbar: 0x019A,
  29468. lbelt: 0x026C,
  29469. lbopomofo: 0x310C,
  29470. lcaron: 0x013E,
  29471. lcedilla: 0x013C,
  29472. lcircle: 0x24DB,
  29473. lcircumflexbelow: 0x1E3D,
  29474. lcommaaccent: 0x013C,
  29475. ldot: 0x0140,
  29476. ldotaccent: 0x0140,
  29477. ldotbelow: 0x1E37,
  29478. ldotbelowmacron: 0x1E39,
  29479. leftangleabovecmb: 0x031A,
  29480. lefttackbelowcmb: 0x0318,
  29481. less: 0x003C,
  29482. lessequal: 0x2264,
  29483. lessequalorgreater: 0x22DA,
  29484. lessmonospace: 0xFF1C,
  29485. lessorequivalent: 0x2272,
  29486. lessorgreater: 0x2276,
  29487. lessoverequal: 0x2266,
  29488. lesssmall: 0xFE64,
  29489. lezh: 0x026E,
  29490. lfblock: 0x258C,
  29491. lhookretroflex: 0x026D,
  29492. lira: 0x20A4,
  29493. liwnarmenian: 0x056C,
  29494. lj: 0x01C9,
  29495. ljecyrillic: 0x0459,
  29496. ll: 0xF6C0,
  29497. lladeva: 0x0933,
  29498. llagujarati: 0x0AB3,
  29499. llinebelow: 0x1E3B,
  29500. llladeva: 0x0934,
  29501. llvocalicbengali: 0x09E1,
  29502. llvocalicdeva: 0x0961,
  29503. llvocalicvowelsignbengali: 0x09E3,
  29504. llvocalicvowelsigndeva: 0x0963,
  29505. lmiddletilde: 0x026B,
  29506. lmonospace: 0xFF4C,
  29507. lmsquare: 0x33D0,
  29508. lochulathai: 0x0E2C,
  29509. logicaland: 0x2227,
  29510. logicalnot: 0x00AC,
  29511. logicalnotreversed: 0x2310,
  29512. logicalor: 0x2228,
  29513. lolingthai: 0x0E25,
  29514. longs: 0x017F,
  29515. lowlinecenterline: 0xFE4E,
  29516. lowlinecmb: 0x0332,
  29517. lowlinedashed: 0xFE4D,
  29518. lozenge: 0x25CA,
  29519. lparen: 0x24A7,
  29520. lslash: 0x0142,
  29521. lsquare: 0x2113,
  29522. lsuperior: 0xF6EE,
  29523. ltshade: 0x2591,
  29524. luthai: 0x0E26,
  29525. lvocalicbengali: 0x098C,
  29526. lvocalicdeva: 0x090C,
  29527. lvocalicvowelsignbengali: 0x09E2,
  29528. lvocalicvowelsigndeva: 0x0962,
  29529. lxsquare: 0x33D3,
  29530. m: 0x006D,
  29531. mabengali: 0x09AE,
  29532. macron: 0x00AF,
  29533. macronbelowcmb: 0x0331,
  29534. macroncmb: 0x0304,
  29535. macronlowmod: 0x02CD,
  29536. macronmonospace: 0xFFE3,
  29537. macute: 0x1E3F,
  29538. madeva: 0x092E,
  29539. magujarati: 0x0AAE,
  29540. magurmukhi: 0x0A2E,
  29541. mahapakhhebrew: 0x05A4,
  29542. mahapakhlefthebrew: 0x05A4,
  29543. mahiragana: 0x307E,
  29544. maichattawalowleftthai: 0xF895,
  29545. maichattawalowrightthai: 0xF894,
  29546. maichattawathai: 0x0E4B,
  29547. maichattawaupperleftthai: 0xF893,
  29548. maieklowleftthai: 0xF88C,
  29549. maieklowrightthai: 0xF88B,
  29550. maiekthai: 0x0E48,
  29551. maiekupperleftthai: 0xF88A,
  29552. maihanakatleftthai: 0xF884,
  29553. maihanakatthai: 0x0E31,
  29554. maitaikhuleftthai: 0xF889,
  29555. maitaikhuthai: 0x0E47,
  29556. maitholowleftthai: 0xF88F,
  29557. maitholowrightthai: 0xF88E,
  29558. maithothai: 0x0E49,
  29559. maithoupperleftthai: 0xF88D,
  29560. maitrilowleftthai: 0xF892,
  29561. maitrilowrightthai: 0xF891,
  29562. maitrithai: 0x0E4A,
  29563. maitriupperleftthai: 0xF890,
  29564. maiyamokthai: 0x0E46,
  29565. makatakana: 0x30DE,
  29566. makatakanahalfwidth: 0xFF8F,
  29567. male: 0x2642,
  29568. mansyonsquare: 0x3347,
  29569. maqafhebrew: 0x05BE,
  29570. mars: 0x2642,
  29571. masoracirclehebrew: 0x05AF,
  29572. masquare: 0x3383,
  29573. mbopomofo: 0x3107,
  29574. mbsquare: 0x33D4,
  29575. mcircle: 0x24DC,
  29576. mcubedsquare: 0x33A5,
  29577. mdotaccent: 0x1E41,
  29578. mdotbelow: 0x1E43,
  29579. meemarabic: 0x0645,
  29580. meemfinalarabic: 0xFEE2,
  29581. meeminitialarabic: 0xFEE3,
  29582. meemmedialarabic: 0xFEE4,
  29583. meemmeeminitialarabic: 0xFCD1,
  29584. meemmeemisolatedarabic: 0xFC48,
  29585. meetorusquare: 0x334D,
  29586. mehiragana: 0x3081,
  29587. meizierasquare: 0x337E,
  29588. mekatakana: 0x30E1,
  29589. mekatakanahalfwidth: 0xFF92,
  29590. mem: 0x05DE,
  29591. memdagesh: 0xFB3E,
  29592. memdageshhebrew: 0xFB3E,
  29593. memhebrew: 0x05DE,
  29594. menarmenian: 0x0574,
  29595. merkhahebrew: 0x05A5,
  29596. merkhakefulahebrew: 0x05A6,
  29597. merkhakefulalefthebrew: 0x05A6,
  29598. merkhalefthebrew: 0x05A5,
  29599. mhook: 0x0271,
  29600. mhzsquare: 0x3392,
  29601. middledotkatakanahalfwidth: 0xFF65,
  29602. middot: 0x00B7,
  29603. mieumacirclekorean: 0x3272,
  29604. mieumaparenkorean: 0x3212,
  29605. mieumcirclekorean: 0x3264,
  29606. mieumkorean: 0x3141,
  29607. mieumpansioskorean: 0x3170,
  29608. mieumparenkorean: 0x3204,
  29609. mieumpieupkorean: 0x316E,
  29610. mieumsioskorean: 0x316F,
  29611. mihiragana: 0x307F,
  29612. mikatakana: 0x30DF,
  29613. mikatakanahalfwidth: 0xFF90,
  29614. minus: 0x2212,
  29615. minusbelowcmb: 0x0320,
  29616. minuscircle: 0x2296,
  29617. minusmod: 0x02D7,
  29618. minusplus: 0x2213,
  29619. minute: 0x2032,
  29620. miribaarusquare: 0x334A,
  29621. mirisquare: 0x3349,
  29622. mlonglegturned: 0x0270,
  29623. mlsquare: 0x3396,
  29624. mmcubedsquare: 0x33A3,
  29625. mmonospace: 0xFF4D,
  29626. mmsquaredsquare: 0x339F,
  29627. mohiragana: 0x3082,
  29628. mohmsquare: 0x33C1,
  29629. mokatakana: 0x30E2,
  29630. mokatakanahalfwidth: 0xFF93,
  29631. molsquare: 0x33D6,
  29632. momathai: 0x0E21,
  29633. moverssquare: 0x33A7,
  29634. moverssquaredsquare: 0x33A8,
  29635. mparen: 0x24A8,
  29636. mpasquare: 0x33AB,
  29637. mssquare: 0x33B3,
  29638. msuperior: 0xF6EF,
  29639. mturned: 0x026F,
  29640. mu: 0x00B5,
  29641. mu1: 0x00B5,
  29642. muasquare: 0x3382,
  29643. muchgreater: 0x226B,
  29644. muchless: 0x226A,
  29645. mufsquare: 0x338C,
  29646. mugreek: 0x03BC,
  29647. mugsquare: 0x338D,
  29648. muhiragana: 0x3080,
  29649. mukatakana: 0x30E0,
  29650. mukatakanahalfwidth: 0xFF91,
  29651. mulsquare: 0x3395,
  29652. multiply: 0x00D7,
  29653. mumsquare: 0x339B,
  29654. munahhebrew: 0x05A3,
  29655. munahlefthebrew: 0x05A3,
  29656. musicalnote: 0x266A,
  29657. musicalnotedbl: 0x266B,
  29658. musicflatsign: 0x266D,
  29659. musicsharpsign: 0x266F,
  29660. mussquare: 0x33B2,
  29661. muvsquare: 0x33B6,
  29662. muwsquare: 0x33BC,
  29663. mvmegasquare: 0x33B9,
  29664. mvsquare: 0x33B7,
  29665. mwmegasquare: 0x33BF,
  29666. mwsquare: 0x33BD,
  29667. n: 0x006E,
  29668. nabengali: 0x09A8,
  29669. nabla: 0x2207,
  29670. nacute: 0x0144,
  29671. nadeva: 0x0928,
  29672. nagujarati: 0x0AA8,
  29673. nagurmukhi: 0x0A28,
  29674. nahiragana: 0x306A,
  29675. nakatakana: 0x30CA,
  29676. nakatakanahalfwidth: 0xFF85,
  29677. napostrophe: 0x0149,
  29678. nasquare: 0x3381,
  29679. nbopomofo: 0x310B,
  29680. nbspace: 0x00A0,
  29681. ncaron: 0x0148,
  29682. ncedilla: 0x0146,
  29683. ncircle: 0x24DD,
  29684. ncircumflexbelow: 0x1E4B,
  29685. ncommaaccent: 0x0146,
  29686. ndotaccent: 0x1E45,
  29687. ndotbelow: 0x1E47,
  29688. nehiragana: 0x306D,
  29689. nekatakana: 0x30CD,
  29690. nekatakanahalfwidth: 0xFF88,
  29691. newsheqelsign: 0x20AA,
  29692. nfsquare: 0x338B,
  29693. ngabengali: 0x0999,
  29694. ngadeva: 0x0919,
  29695. ngagujarati: 0x0A99,
  29696. ngagurmukhi: 0x0A19,
  29697. ngonguthai: 0x0E07,
  29698. nhiragana: 0x3093,
  29699. nhookleft: 0x0272,
  29700. nhookretroflex: 0x0273,
  29701. nieunacirclekorean: 0x326F,
  29702. nieunaparenkorean: 0x320F,
  29703. nieuncieuckorean: 0x3135,
  29704. nieuncirclekorean: 0x3261,
  29705. nieunhieuhkorean: 0x3136,
  29706. nieunkorean: 0x3134,
  29707. nieunpansioskorean: 0x3168,
  29708. nieunparenkorean: 0x3201,
  29709. nieunsioskorean: 0x3167,
  29710. nieuntikeutkorean: 0x3166,
  29711. nihiragana: 0x306B,
  29712. nikatakana: 0x30CB,
  29713. nikatakanahalfwidth: 0xFF86,
  29714. nikhahitleftthai: 0xF899,
  29715. nikhahitthai: 0x0E4D,
  29716. nine: 0x0039,
  29717. ninearabic: 0x0669,
  29718. ninebengali: 0x09EF,
  29719. ninecircle: 0x2468,
  29720. ninecircleinversesansserif: 0x2792,
  29721. ninedeva: 0x096F,
  29722. ninegujarati: 0x0AEF,
  29723. ninegurmukhi: 0x0A6F,
  29724. ninehackarabic: 0x0669,
  29725. ninehangzhou: 0x3029,
  29726. nineideographicparen: 0x3228,
  29727. nineinferior: 0x2089,
  29728. ninemonospace: 0xFF19,
  29729. nineoldstyle: 0xF739,
  29730. nineparen: 0x247C,
  29731. nineperiod: 0x2490,
  29732. ninepersian: 0x06F9,
  29733. nineroman: 0x2178,
  29734. ninesuperior: 0x2079,
  29735. nineteencircle: 0x2472,
  29736. nineteenparen: 0x2486,
  29737. nineteenperiod: 0x249A,
  29738. ninethai: 0x0E59,
  29739. nj: 0x01CC,
  29740. njecyrillic: 0x045A,
  29741. nkatakana: 0x30F3,
  29742. nkatakanahalfwidth: 0xFF9D,
  29743. nlegrightlong: 0x019E,
  29744. nlinebelow: 0x1E49,
  29745. nmonospace: 0xFF4E,
  29746. nmsquare: 0x339A,
  29747. nnabengali: 0x09A3,
  29748. nnadeva: 0x0923,
  29749. nnagujarati: 0x0AA3,
  29750. nnagurmukhi: 0x0A23,
  29751. nnnadeva: 0x0929,
  29752. nohiragana: 0x306E,
  29753. nokatakana: 0x30CE,
  29754. nokatakanahalfwidth: 0xFF89,
  29755. nonbreakingspace: 0x00A0,
  29756. nonenthai: 0x0E13,
  29757. nonuthai: 0x0E19,
  29758. noonarabic: 0x0646,
  29759. noonfinalarabic: 0xFEE6,
  29760. noonghunnaarabic: 0x06BA,
  29761. noonghunnafinalarabic: 0xFB9F,
  29762. nooninitialarabic: 0xFEE7,
  29763. noonjeeminitialarabic: 0xFCD2,
  29764. noonjeemisolatedarabic: 0xFC4B,
  29765. noonmedialarabic: 0xFEE8,
  29766. noonmeeminitialarabic: 0xFCD5,
  29767. noonmeemisolatedarabic: 0xFC4E,
  29768. noonnoonfinalarabic: 0xFC8D,
  29769. notcontains: 0x220C,
  29770. notelement: 0x2209,
  29771. notelementof: 0x2209,
  29772. notequal: 0x2260,
  29773. notgreater: 0x226F,
  29774. notgreaternorequal: 0x2271,
  29775. notgreaternorless: 0x2279,
  29776. notidentical: 0x2262,
  29777. notless: 0x226E,
  29778. notlessnorequal: 0x2270,
  29779. notparallel: 0x2226,
  29780. notprecedes: 0x2280,
  29781. notsubset: 0x2284,
  29782. notsucceeds: 0x2281,
  29783. notsuperset: 0x2285,
  29784. nowarmenian: 0x0576,
  29785. nparen: 0x24A9,
  29786. nssquare: 0x33B1,
  29787. nsuperior: 0x207F,
  29788. ntilde: 0x00F1,
  29789. nu: 0x03BD,
  29790. nuhiragana: 0x306C,
  29791. nukatakana: 0x30CC,
  29792. nukatakanahalfwidth: 0xFF87,
  29793. nuktabengali: 0x09BC,
  29794. nuktadeva: 0x093C,
  29795. nuktagujarati: 0x0ABC,
  29796. nuktagurmukhi: 0x0A3C,
  29797. numbersign: 0x0023,
  29798. numbersignmonospace: 0xFF03,
  29799. numbersignsmall: 0xFE5F,
  29800. numeralsigngreek: 0x0374,
  29801. numeralsignlowergreek: 0x0375,
  29802. numero: 0x2116,
  29803. nun: 0x05E0,
  29804. nundagesh: 0xFB40,
  29805. nundageshhebrew: 0xFB40,
  29806. nunhebrew: 0x05E0,
  29807. nvsquare: 0x33B5,
  29808. nwsquare: 0x33BB,
  29809. nyabengali: 0x099E,
  29810. nyadeva: 0x091E,
  29811. nyagujarati: 0x0A9E,
  29812. nyagurmukhi: 0x0A1E,
  29813. o: 0x006F,
  29814. oacute: 0x00F3,
  29815. oangthai: 0x0E2D,
  29816. obarred: 0x0275,
  29817. obarredcyrillic: 0x04E9,
  29818. obarreddieresiscyrillic: 0x04EB,
  29819. obengali: 0x0993,
  29820. obopomofo: 0x311B,
  29821. obreve: 0x014F,
  29822. ocandradeva: 0x0911,
  29823. ocandragujarati: 0x0A91,
  29824. ocandravowelsigndeva: 0x0949,
  29825. ocandravowelsigngujarati: 0x0AC9,
  29826. ocaron: 0x01D2,
  29827. ocircle: 0x24DE,
  29828. ocircumflex: 0x00F4,
  29829. ocircumflexacute: 0x1ED1,
  29830. ocircumflexdotbelow: 0x1ED9,
  29831. ocircumflexgrave: 0x1ED3,
  29832. ocircumflexhookabove: 0x1ED5,
  29833. ocircumflextilde: 0x1ED7,
  29834. ocyrillic: 0x043E,
  29835. odblacute: 0x0151,
  29836. odblgrave: 0x020D,
  29837. odeva: 0x0913,
  29838. odieresis: 0x00F6,
  29839. odieresiscyrillic: 0x04E7,
  29840. odotbelow: 0x1ECD,
  29841. oe: 0x0153,
  29842. oekorean: 0x315A,
  29843. ogonek: 0x02DB,
  29844. ogonekcmb: 0x0328,
  29845. ograve: 0x00F2,
  29846. ogujarati: 0x0A93,
  29847. oharmenian: 0x0585,
  29848. ohiragana: 0x304A,
  29849. ohookabove: 0x1ECF,
  29850. ohorn: 0x01A1,
  29851. ohornacute: 0x1EDB,
  29852. ohorndotbelow: 0x1EE3,
  29853. ohorngrave: 0x1EDD,
  29854. ohornhookabove: 0x1EDF,
  29855. ohorntilde: 0x1EE1,
  29856. ohungarumlaut: 0x0151,
  29857. oi: 0x01A3,
  29858. oinvertedbreve: 0x020F,
  29859. okatakana: 0x30AA,
  29860. okatakanahalfwidth: 0xFF75,
  29861. okorean: 0x3157,
  29862. olehebrew: 0x05AB,
  29863. omacron: 0x014D,
  29864. omacronacute: 0x1E53,
  29865. omacrongrave: 0x1E51,
  29866. omdeva: 0x0950,
  29867. omega: 0x03C9,
  29868. omega1: 0x03D6,
  29869. omegacyrillic: 0x0461,
  29870. omegalatinclosed: 0x0277,
  29871. omegaroundcyrillic: 0x047B,
  29872. omegatitlocyrillic: 0x047D,
  29873. omegatonos: 0x03CE,
  29874. omgujarati: 0x0AD0,
  29875. omicron: 0x03BF,
  29876. omicrontonos: 0x03CC,
  29877. omonospace: 0xFF4F,
  29878. one: 0x0031,
  29879. onearabic: 0x0661,
  29880. onebengali: 0x09E7,
  29881. onecircle: 0x2460,
  29882. onecircleinversesansserif: 0x278A,
  29883. onedeva: 0x0967,
  29884. onedotenleader: 0x2024,
  29885. oneeighth: 0x215B,
  29886. onefitted: 0xF6DC,
  29887. onegujarati: 0x0AE7,
  29888. onegurmukhi: 0x0A67,
  29889. onehackarabic: 0x0661,
  29890. onehalf: 0x00BD,
  29891. onehangzhou: 0x3021,
  29892. oneideographicparen: 0x3220,
  29893. oneinferior: 0x2081,
  29894. onemonospace: 0xFF11,
  29895. onenumeratorbengali: 0x09F4,
  29896. oneoldstyle: 0xF731,
  29897. oneparen: 0x2474,
  29898. oneperiod: 0x2488,
  29899. onepersian: 0x06F1,
  29900. onequarter: 0x00BC,
  29901. oneroman: 0x2170,
  29902. onesuperior: 0x00B9,
  29903. onethai: 0x0E51,
  29904. onethird: 0x2153,
  29905. oogonek: 0x01EB,
  29906. oogonekmacron: 0x01ED,
  29907. oogurmukhi: 0x0A13,
  29908. oomatragurmukhi: 0x0A4B,
  29909. oopen: 0x0254,
  29910. oparen: 0x24AA,
  29911. openbullet: 0x25E6,
  29912. option: 0x2325,
  29913. ordfeminine: 0x00AA,
  29914. ordmasculine: 0x00BA,
  29915. orthogonal: 0x221F,
  29916. oshortdeva: 0x0912,
  29917. oshortvowelsigndeva: 0x094A,
  29918. oslash: 0x00F8,
  29919. oslashacute: 0x01FF,
  29920. osmallhiragana: 0x3049,
  29921. osmallkatakana: 0x30A9,
  29922. osmallkatakanahalfwidth: 0xFF6B,
  29923. ostrokeacute: 0x01FF,
  29924. osuperior: 0xF6F0,
  29925. otcyrillic: 0x047F,
  29926. otilde: 0x00F5,
  29927. otildeacute: 0x1E4D,
  29928. otildedieresis: 0x1E4F,
  29929. oubopomofo: 0x3121,
  29930. overline: 0x203E,
  29931. overlinecenterline: 0xFE4A,
  29932. overlinecmb: 0x0305,
  29933. overlinedashed: 0xFE49,
  29934. overlinedblwavy: 0xFE4C,
  29935. overlinewavy: 0xFE4B,
  29936. overscore: 0x00AF,
  29937. ovowelsignbengali: 0x09CB,
  29938. ovowelsigndeva: 0x094B,
  29939. ovowelsigngujarati: 0x0ACB,
  29940. p: 0x0070,
  29941. paampssquare: 0x3380,
  29942. paasentosquare: 0x332B,
  29943. pabengali: 0x09AA,
  29944. pacute: 0x1E55,
  29945. padeva: 0x092A,
  29946. pagedown: 0x21DF,
  29947. pageup: 0x21DE,
  29948. pagujarati: 0x0AAA,
  29949. pagurmukhi: 0x0A2A,
  29950. pahiragana: 0x3071,
  29951. paiyannoithai: 0x0E2F,
  29952. pakatakana: 0x30D1,
  29953. palatalizationcyrilliccmb: 0x0484,
  29954. palochkacyrillic: 0x04C0,
  29955. pansioskorean: 0x317F,
  29956. paragraph: 0x00B6,
  29957. parallel: 0x2225,
  29958. parenleft: 0x0028,
  29959. parenleftaltonearabic: 0xFD3E,
  29960. parenleftbt: 0xF8ED,
  29961. parenleftex: 0xF8EC,
  29962. parenleftinferior: 0x208D,
  29963. parenleftmonospace: 0xFF08,
  29964. parenleftsmall: 0xFE59,
  29965. parenleftsuperior: 0x207D,
  29966. parenlefttp: 0xF8EB,
  29967. parenleftvertical: 0xFE35,
  29968. parenright: 0x0029,
  29969. parenrightaltonearabic: 0xFD3F,
  29970. parenrightbt: 0xF8F8,
  29971. parenrightex: 0xF8F7,
  29972. parenrightinferior: 0x208E,
  29973. parenrightmonospace: 0xFF09,
  29974. parenrightsmall: 0xFE5A,
  29975. parenrightsuperior: 0x207E,
  29976. parenrighttp: 0xF8F6,
  29977. parenrightvertical: 0xFE36,
  29978. partialdiff: 0x2202,
  29979. paseqhebrew: 0x05C0,
  29980. pashtahebrew: 0x0599,
  29981. pasquare: 0x33A9,
  29982. patah: 0x05B7,
  29983. patah11: 0x05B7,
  29984. patah1d: 0x05B7,
  29985. patah2a: 0x05B7,
  29986. patahhebrew: 0x05B7,
  29987. patahnarrowhebrew: 0x05B7,
  29988. patahquarterhebrew: 0x05B7,
  29989. patahwidehebrew: 0x05B7,
  29990. pazerhebrew: 0x05A1,
  29991. pbopomofo: 0x3106,
  29992. pcircle: 0x24DF,
  29993. pdotaccent: 0x1E57,
  29994. pe: 0x05E4,
  29995. pecyrillic: 0x043F,
  29996. pedagesh: 0xFB44,
  29997. pedageshhebrew: 0xFB44,
  29998. peezisquare: 0x333B,
  29999. pefinaldageshhebrew: 0xFB43,
  30000. peharabic: 0x067E,
  30001. peharmenian: 0x057A,
  30002. pehebrew: 0x05E4,
  30003. pehfinalarabic: 0xFB57,
  30004. pehinitialarabic: 0xFB58,
  30005. pehiragana: 0x307A,
  30006. pehmedialarabic: 0xFB59,
  30007. pekatakana: 0x30DA,
  30008. pemiddlehookcyrillic: 0x04A7,
  30009. perafehebrew: 0xFB4E,
  30010. percent: 0x0025,
  30011. percentarabic: 0x066A,
  30012. percentmonospace: 0xFF05,
  30013. percentsmall: 0xFE6A,
  30014. period: 0x002E,
  30015. periodarmenian: 0x0589,
  30016. periodcentered: 0x00B7,
  30017. periodhalfwidth: 0xFF61,
  30018. periodinferior: 0xF6E7,
  30019. periodmonospace: 0xFF0E,
  30020. periodsmall: 0xFE52,
  30021. periodsuperior: 0xF6E8,
  30022. perispomenigreekcmb: 0x0342,
  30023. perpendicular: 0x22A5,
  30024. perthousand: 0x2030,
  30025. peseta: 0x20A7,
  30026. pfsquare: 0x338A,
  30027. phabengali: 0x09AB,
  30028. phadeva: 0x092B,
  30029. phagujarati: 0x0AAB,
  30030. phagurmukhi: 0x0A2B,
  30031. phi: 0x03C6,
  30032. phi1: 0x03D5,
  30033. phieuphacirclekorean: 0x327A,
  30034. phieuphaparenkorean: 0x321A,
  30035. phieuphcirclekorean: 0x326C,
  30036. phieuphkorean: 0x314D,
  30037. phieuphparenkorean: 0x320C,
  30038. philatin: 0x0278,
  30039. phinthuthai: 0x0E3A,
  30040. phisymbolgreek: 0x03D5,
  30041. phook: 0x01A5,
  30042. phophanthai: 0x0E1E,
  30043. phophungthai: 0x0E1C,
  30044. phosamphaothai: 0x0E20,
  30045. pi: 0x03C0,
  30046. pieupacirclekorean: 0x3273,
  30047. pieupaparenkorean: 0x3213,
  30048. pieupcieuckorean: 0x3176,
  30049. pieupcirclekorean: 0x3265,
  30050. pieupkiyeokkorean: 0x3172,
  30051. pieupkorean: 0x3142,
  30052. pieupparenkorean: 0x3205,
  30053. pieupsioskiyeokkorean: 0x3174,
  30054. pieupsioskorean: 0x3144,
  30055. pieupsiostikeutkorean: 0x3175,
  30056. pieupthieuthkorean: 0x3177,
  30057. pieuptikeutkorean: 0x3173,
  30058. pihiragana: 0x3074,
  30059. pikatakana: 0x30D4,
  30060. pisymbolgreek: 0x03D6,
  30061. piwrarmenian: 0x0583,
  30062. plus: 0x002B,
  30063. plusbelowcmb: 0x031F,
  30064. pluscircle: 0x2295,
  30065. plusminus: 0x00B1,
  30066. plusmod: 0x02D6,
  30067. plusmonospace: 0xFF0B,
  30068. plussmall: 0xFE62,
  30069. plussuperior: 0x207A,
  30070. pmonospace: 0xFF50,
  30071. pmsquare: 0x33D8,
  30072. pohiragana: 0x307D,
  30073. pointingindexdownwhite: 0x261F,
  30074. pointingindexleftwhite: 0x261C,
  30075. pointingindexrightwhite: 0x261E,
  30076. pointingindexupwhite: 0x261D,
  30077. pokatakana: 0x30DD,
  30078. poplathai: 0x0E1B,
  30079. postalmark: 0x3012,
  30080. postalmarkface: 0x3020,
  30081. pparen: 0x24AB,
  30082. precedes: 0x227A,
  30083. prescription: 0x211E,
  30084. primemod: 0x02B9,
  30085. primereversed: 0x2035,
  30086. product: 0x220F,
  30087. projective: 0x2305,
  30088. prolongedkana: 0x30FC,
  30089. propellor: 0x2318,
  30090. propersubset: 0x2282,
  30091. propersuperset: 0x2283,
  30092. proportion: 0x2237,
  30093. proportional: 0x221D,
  30094. psi: 0x03C8,
  30095. psicyrillic: 0x0471,
  30096. psilipneumatacyrilliccmb: 0x0486,
  30097. pssquare: 0x33B0,
  30098. puhiragana: 0x3077,
  30099. pukatakana: 0x30D7,
  30100. pvsquare: 0x33B4,
  30101. pwsquare: 0x33BA,
  30102. q: 0x0071,
  30103. qadeva: 0x0958,
  30104. qadmahebrew: 0x05A8,
  30105. qafarabic: 0x0642,
  30106. qaffinalarabic: 0xFED6,
  30107. qafinitialarabic: 0xFED7,
  30108. qafmedialarabic: 0xFED8,
  30109. qamats: 0x05B8,
  30110. qamats10: 0x05B8,
  30111. qamats1a: 0x05B8,
  30112. qamats1c: 0x05B8,
  30113. qamats27: 0x05B8,
  30114. qamats29: 0x05B8,
  30115. qamats33: 0x05B8,
  30116. qamatsde: 0x05B8,
  30117. qamatshebrew: 0x05B8,
  30118. qamatsnarrowhebrew: 0x05B8,
  30119. qamatsqatanhebrew: 0x05B8,
  30120. qamatsqatannarrowhebrew: 0x05B8,
  30121. qamatsqatanquarterhebrew: 0x05B8,
  30122. qamatsqatanwidehebrew: 0x05B8,
  30123. qamatsquarterhebrew: 0x05B8,
  30124. qamatswidehebrew: 0x05B8,
  30125. qarneyparahebrew: 0x059F,
  30126. qbopomofo: 0x3111,
  30127. qcircle: 0x24E0,
  30128. qhook: 0x02A0,
  30129. qmonospace: 0xFF51,
  30130. qof: 0x05E7,
  30131. qofdagesh: 0xFB47,
  30132. qofdageshhebrew: 0xFB47,
  30133. qofhebrew: 0x05E7,
  30134. qparen: 0x24AC,
  30135. quarternote: 0x2669,
  30136. qubuts: 0x05BB,
  30137. qubuts18: 0x05BB,
  30138. qubuts25: 0x05BB,
  30139. qubuts31: 0x05BB,
  30140. qubutshebrew: 0x05BB,
  30141. qubutsnarrowhebrew: 0x05BB,
  30142. qubutsquarterhebrew: 0x05BB,
  30143. qubutswidehebrew: 0x05BB,
  30144. question: 0x003F,
  30145. questionarabic: 0x061F,
  30146. questionarmenian: 0x055E,
  30147. questiondown: 0x00BF,
  30148. questiondownsmall: 0xF7BF,
  30149. questiongreek: 0x037E,
  30150. questionmonospace: 0xFF1F,
  30151. questionsmall: 0xF73F,
  30152. quotedbl: 0x0022,
  30153. quotedblbase: 0x201E,
  30154. quotedblleft: 0x201C,
  30155. quotedblmonospace: 0xFF02,
  30156. quotedblprime: 0x301E,
  30157. quotedblprimereversed: 0x301D,
  30158. quotedblright: 0x201D,
  30159. quoteleft: 0x2018,
  30160. quoteleftreversed: 0x201B,
  30161. quotereversed: 0x201B,
  30162. quoteright: 0x2019,
  30163. quoterightn: 0x0149,
  30164. quotesinglbase: 0x201A,
  30165. quotesingle: 0x0027,
  30166. quotesinglemonospace: 0xFF07,
  30167. r: 0x0072,
  30168. raarmenian: 0x057C,
  30169. rabengali: 0x09B0,
  30170. racute: 0x0155,
  30171. radeva: 0x0930,
  30172. radical: 0x221A,
  30173. radicalex: 0xF8E5,
  30174. radoverssquare: 0x33AE,
  30175. radoverssquaredsquare: 0x33AF,
  30176. radsquare: 0x33AD,
  30177. rafe: 0x05BF,
  30178. rafehebrew: 0x05BF,
  30179. ragujarati: 0x0AB0,
  30180. ragurmukhi: 0x0A30,
  30181. rahiragana: 0x3089,
  30182. rakatakana: 0x30E9,
  30183. rakatakanahalfwidth: 0xFF97,
  30184. ralowerdiagonalbengali: 0x09F1,
  30185. ramiddlediagonalbengali: 0x09F0,
  30186. ramshorn: 0x0264,
  30187. ratio: 0x2236,
  30188. rbopomofo: 0x3116,
  30189. rcaron: 0x0159,
  30190. rcedilla: 0x0157,
  30191. rcircle: 0x24E1,
  30192. rcommaaccent: 0x0157,
  30193. rdblgrave: 0x0211,
  30194. rdotaccent: 0x1E59,
  30195. rdotbelow: 0x1E5B,
  30196. rdotbelowmacron: 0x1E5D,
  30197. referencemark: 0x203B,
  30198. reflexsubset: 0x2286,
  30199. reflexsuperset: 0x2287,
  30200. registered: 0x00AE,
  30201. registersans: 0xF8E8,
  30202. registerserif: 0xF6DA,
  30203. reharabic: 0x0631,
  30204. reharmenian: 0x0580,
  30205. rehfinalarabic: 0xFEAE,
  30206. rehiragana: 0x308C,
  30207. rekatakana: 0x30EC,
  30208. rekatakanahalfwidth: 0xFF9A,
  30209. resh: 0x05E8,
  30210. reshdageshhebrew: 0xFB48,
  30211. reshhebrew: 0x05E8,
  30212. reversedtilde: 0x223D,
  30213. reviahebrew: 0x0597,
  30214. reviamugrashhebrew: 0x0597,
  30215. revlogicalnot: 0x2310,
  30216. rfishhook: 0x027E,
  30217. rfishhookreversed: 0x027F,
  30218. rhabengali: 0x09DD,
  30219. rhadeva: 0x095D,
  30220. rho: 0x03C1,
  30221. rhook: 0x027D,
  30222. rhookturned: 0x027B,
  30223. rhookturnedsuperior: 0x02B5,
  30224. rhosymbolgreek: 0x03F1,
  30225. rhotichookmod: 0x02DE,
  30226. rieulacirclekorean: 0x3271,
  30227. rieulaparenkorean: 0x3211,
  30228. rieulcirclekorean: 0x3263,
  30229. rieulhieuhkorean: 0x3140,
  30230. rieulkiyeokkorean: 0x313A,
  30231. rieulkiyeoksioskorean: 0x3169,
  30232. rieulkorean: 0x3139,
  30233. rieulmieumkorean: 0x313B,
  30234. rieulpansioskorean: 0x316C,
  30235. rieulparenkorean: 0x3203,
  30236. rieulphieuphkorean: 0x313F,
  30237. rieulpieupkorean: 0x313C,
  30238. rieulpieupsioskorean: 0x316B,
  30239. rieulsioskorean: 0x313D,
  30240. rieulthieuthkorean: 0x313E,
  30241. rieultikeutkorean: 0x316A,
  30242. rieulyeorinhieuhkorean: 0x316D,
  30243. rightangle: 0x221F,
  30244. righttackbelowcmb: 0x0319,
  30245. righttriangle: 0x22BF,
  30246. rihiragana: 0x308A,
  30247. rikatakana: 0x30EA,
  30248. rikatakanahalfwidth: 0xFF98,
  30249. ring: 0x02DA,
  30250. ringbelowcmb: 0x0325,
  30251. ringcmb: 0x030A,
  30252. ringhalfleft: 0x02BF,
  30253. ringhalfleftarmenian: 0x0559,
  30254. ringhalfleftbelowcmb: 0x031C,
  30255. ringhalfleftcentered: 0x02D3,
  30256. ringhalfright: 0x02BE,
  30257. ringhalfrightbelowcmb: 0x0339,
  30258. ringhalfrightcentered: 0x02D2,
  30259. rinvertedbreve: 0x0213,
  30260. rittorusquare: 0x3351,
  30261. rlinebelow: 0x1E5F,
  30262. rlongleg: 0x027C,
  30263. rlonglegturned: 0x027A,
  30264. rmonospace: 0xFF52,
  30265. rohiragana: 0x308D,
  30266. rokatakana: 0x30ED,
  30267. rokatakanahalfwidth: 0xFF9B,
  30268. roruathai: 0x0E23,
  30269. rparen: 0x24AD,
  30270. rrabengali: 0x09DC,
  30271. rradeva: 0x0931,
  30272. rragurmukhi: 0x0A5C,
  30273. rreharabic: 0x0691,
  30274. rrehfinalarabic: 0xFB8D,
  30275. rrvocalicbengali: 0x09E0,
  30276. rrvocalicdeva: 0x0960,
  30277. rrvocalicgujarati: 0x0AE0,
  30278. rrvocalicvowelsignbengali: 0x09C4,
  30279. rrvocalicvowelsigndeva: 0x0944,
  30280. rrvocalicvowelsigngujarati: 0x0AC4,
  30281. rsuperior: 0xF6F1,
  30282. rtblock: 0x2590,
  30283. rturned: 0x0279,
  30284. rturnedsuperior: 0x02B4,
  30285. ruhiragana: 0x308B,
  30286. rukatakana: 0x30EB,
  30287. rukatakanahalfwidth: 0xFF99,
  30288. rupeemarkbengali: 0x09F2,
  30289. rupeesignbengali: 0x09F3,
  30290. rupiah: 0xF6DD,
  30291. ruthai: 0x0E24,
  30292. rvocalicbengali: 0x098B,
  30293. rvocalicdeva: 0x090B,
  30294. rvocalicgujarati: 0x0A8B,
  30295. rvocalicvowelsignbengali: 0x09C3,
  30296. rvocalicvowelsigndeva: 0x0943,
  30297. rvocalicvowelsigngujarati: 0x0AC3,
  30298. s: 0x0073,
  30299. sabengali: 0x09B8,
  30300. sacute: 0x015B,
  30301. sacutedotaccent: 0x1E65,
  30302. sadarabic: 0x0635,
  30303. sadeva: 0x0938,
  30304. sadfinalarabic: 0xFEBA,
  30305. sadinitialarabic: 0xFEBB,
  30306. sadmedialarabic: 0xFEBC,
  30307. sagujarati: 0x0AB8,
  30308. sagurmukhi: 0x0A38,
  30309. sahiragana: 0x3055,
  30310. sakatakana: 0x30B5,
  30311. sakatakanahalfwidth: 0xFF7B,
  30312. sallallahoualayhewasallamarabic: 0xFDFA,
  30313. samekh: 0x05E1,
  30314. samekhdagesh: 0xFB41,
  30315. samekhdageshhebrew: 0xFB41,
  30316. samekhhebrew: 0x05E1,
  30317. saraaathai: 0x0E32,
  30318. saraaethai: 0x0E41,
  30319. saraaimaimalaithai: 0x0E44,
  30320. saraaimaimuanthai: 0x0E43,
  30321. saraamthai: 0x0E33,
  30322. saraathai: 0x0E30,
  30323. saraethai: 0x0E40,
  30324. saraiileftthai: 0xF886,
  30325. saraiithai: 0x0E35,
  30326. saraileftthai: 0xF885,
  30327. saraithai: 0x0E34,
  30328. saraothai: 0x0E42,
  30329. saraueeleftthai: 0xF888,
  30330. saraueethai: 0x0E37,
  30331. saraueleftthai: 0xF887,
  30332. sarauethai: 0x0E36,
  30333. sarauthai: 0x0E38,
  30334. sarauuthai: 0x0E39,
  30335. sbopomofo: 0x3119,
  30336. scaron: 0x0161,
  30337. scarondotaccent: 0x1E67,
  30338. scedilla: 0x015F,
  30339. schwa: 0x0259,
  30340. schwacyrillic: 0x04D9,
  30341. schwadieresiscyrillic: 0x04DB,
  30342. schwahook: 0x025A,
  30343. scircle: 0x24E2,
  30344. scircumflex: 0x015D,
  30345. scommaaccent: 0x0219,
  30346. sdotaccent: 0x1E61,
  30347. sdotbelow: 0x1E63,
  30348. sdotbelowdotaccent: 0x1E69,
  30349. seagullbelowcmb: 0x033C,
  30350. second: 0x2033,
  30351. secondtonechinese: 0x02CA,
  30352. section: 0x00A7,
  30353. seenarabic: 0x0633,
  30354. seenfinalarabic: 0xFEB2,
  30355. seeninitialarabic: 0xFEB3,
  30356. seenmedialarabic: 0xFEB4,
  30357. segol: 0x05B6,
  30358. segol13: 0x05B6,
  30359. segol1f: 0x05B6,
  30360. segol2c: 0x05B6,
  30361. segolhebrew: 0x05B6,
  30362. segolnarrowhebrew: 0x05B6,
  30363. segolquarterhebrew: 0x05B6,
  30364. segoltahebrew: 0x0592,
  30365. segolwidehebrew: 0x05B6,
  30366. seharmenian: 0x057D,
  30367. sehiragana: 0x305B,
  30368. sekatakana: 0x30BB,
  30369. sekatakanahalfwidth: 0xFF7E,
  30370. semicolon: 0x003B,
  30371. semicolonarabic: 0x061B,
  30372. semicolonmonospace: 0xFF1B,
  30373. semicolonsmall: 0xFE54,
  30374. semivoicedmarkkana: 0x309C,
  30375. semivoicedmarkkanahalfwidth: 0xFF9F,
  30376. sentisquare: 0x3322,
  30377. sentosquare: 0x3323,
  30378. seven: 0x0037,
  30379. sevenarabic: 0x0667,
  30380. sevenbengali: 0x09ED,
  30381. sevencircle: 0x2466,
  30382. sevencircleinversesansserif: 0x2790,
  30383. sevendeva: 0x096D,
  30384. seveneighths: 0x215E,
  30385. sevengujarati: 0x0AED,
  30386. sevengurmukhi: 0x0A6D,
  30387. sevenhackarabic: 0x0667,
  30388. sevenhangzhou: 0x3027,
  30389. sevenideographicparen: 0x3226,
  30390. seveninferior: 0x2087,
  30391. sevenmonospace: 0xFF17,
  30392. sevenoldstyle: 0xF737,
  30393. sevenparen: 0x247A,
  30394. sevenperiod: 0x248E,
  30395. sevenpersian: 0x06F7,
  30396. sevenroman: 0x2176,
  30397. sevensuperior: 0x2077,
  30398. seventeencircle: 0x2470,
  30399. seventeenparen: 0x2484,
  30400. seventeenperiod: 0x2498,
  30401. seventhai: 0x0E57,
  30402. sfthyphen: 0x00AD,
  30403. shaarmenian: 0x0577,
  30404. shabengali: 0x09B6,
  30405. shacyrillic: 0x0448,
  30406. shaddaarabic: 0x0651,
  30407. shaddadammaarabic: 0xFC61,
  30408. shaddadammatanarabic: 0xFC5E,
  30409. shaddafathaarabic: 0xFC60,
  30410. shaddakasraarabic: 0xFC62,
  30411. shaddakasratanarabic: 0xFC5F,
  30412. shade: 0x2592,
  30413. shadedark: 0x2593,
  30414. shadelight: 0x2591,
  30415. shademedium: 0x2592,
  30416. shadeva: 0x0936,
  30417. shagujarati: 0x0AB6,
  30418. shagurmukhi: 0x0A36,
  30419. shalshelethebrew: 0x0593,
  30420. shbopomofo: 0x3115,
  30421. shchacyrillic: 0x0449,
  30422. sheenarabic: 0x0634,
  30423. sheenfinalarabic: 0xFEB6,
  30424. sheeninitialarabic: 0xFEB7,
  30425. sheenmedialarabic: 0xFEB8,
  30426. sheicoptic: 0x03E3,
  30427. sheqel: 0x20AA,
  30428. sheqelhebrew: 0x20AA,
  30429. sheva: 0x05B0,
  30430. sheva115: 0x05B0,
  30431. sheva15: 0x05B0,
  30432. sheva22: 0x05B0,
  30433. sheva2e: 0x05B0,
  30434. shevahebrew: 0x05B0,
  30435. shevanarrowhebrew: 0x05B0,
  30436. shevaquarterhebrew: 0x05B0,
  30437. shevawidehebrew: 0x05B0,
  30438. shhacyrillic: 0x04BB,
  30439. shimacoptic: 0x03ED,
  30440. shin: 0x05E9,
  30441. shindagesh: 0xFB49,
  30442. shindageshhebrew: 0xFB49,
  30443. shindageshshindot: 0xFB2C,
  30444. shindageshshindothebrew: 0xFB2C,
  30445. shindageshsindot: 0xFB2D,
  30446. shindageshsindothebrew: 0xFB2D,
  30447. shindothebrew: 0x05C1,
  30448. shinhebrew: 0x05E9,
  30449. shinshindot: 0xFB2A,
  30450. shinshindothebrew: 0xFB2A,
  30451. shinsindot: 0xFB2B,
  30452. shinsindothebrew: 0xFB2B,
  30453. shook: 0x0282,
  30454. sigma: 0x03C3,
  30455. sigma1: 0x03C2,
  30456. sigmafinal: 0x03C2,
  30457. sigmalunatesymbolgreek: 0x03F2,
  30458. sihiragana: 0x3057,
  30459. sikatakana: 0x30B7,
  30460. sikatakanahalfwidth: 0xFF7C,
  30461. siluqhebrew: 0x05BD,
  30462. siluqlefthebrew: 0x05BD,
  30463. similar: 0x223C,
  30464. sindothebrew: 0x05C2,
  30465. siosacirclekorean: 0x3274,
  30466. siosaparenkorean: 0x3214,
  30467. sioscieuckorean: 0x317E,
  30468. sioscirclekorean: 0x3266,
  30469. sioskiyeokkorean: 0x317A,
  30470. sioskorean: 0x3145,
  30471. siosnieunkorean: 0x317B,
  30472. siosparenkorean: 0x3206,
  30473. siospieupkorean: 0x317D,
  30474. siostikeutkorean: 0x317C,
  30475. six: 0x0036,
  30476. sixarabic: 0x0666,
  30477. sixbengali: 0x09EC,
  30478. sixcircle: 0x2465,
  30479. sixcircleinversesansserif: 0x278F,
  30480. sixdeva: 0x096C,
  30481. sixgujarati: 0x0AEC,
  30482. sixgurmukhi: 0x0A6C,
  30483. sixhackarabic: 0x0666,
  30484. sixhangzhou: 0x3026,
  30485. sixideographicparen: 0x3225,
  30486. sixinferior: 0x2086,
  30487. sixmonospace: 0xFF16,
  30488. sixoldstyle: 0xF736,
  30489. sixparen: 0x2479,
  30490. sixperiod: 0x248D,
  30491. sixpersian: 0x06F6,
  30492. sixroman: 0x2175,
  30493. sixsuperior: 0x2076,
  30494. sixteencircle: 0x246F,
  30495. sixteencurrencydenominatorbengali: 0x09F9,
  30496. sixteenparen: 0x2483,
  30497. sixteenperiod: 0x2497,
  30498. sixthai: 0x0E56,
  30499. slash: 0x002F,
  30500. slashmonospace: 0xFF0F,
  30501. slong: 0x017F,
  30502. slongdotaccent: 0x1E9B,
  30503. smileface: 0x263A,
  30504. smonospace: 0xFF53,
  30505. sofpasuqhebrew: 0x05C3,
  30506. softhyphen: 0x00AD,
  30507. softsigncyrillic: 0x044C,
  30508. sohiragana: 0x305D,
  30509. sokatakana: 0x30BD,
  30510. sokatakanahalfwidth: 0xFF7F,
  30511. soliduslongoverlaycmb: 0x0338,
  30512. solidusshortoverlaycmb: 0x0337,
  30513. sorusithai: 0x0E29,
  30514. sosalathai: 0x0E28,
  30515. sosothai: 0x0E0B,
  30516. sosuathai: 0x0E2A,
  30517. space: 0x0020,
  30518. spacehackarabic: 0x0020,
  30519. spade: 0x2660,
  30520. spadesuitblack: 0x2660,
  30521. spadesuitwhite: 0x2664,
  30522. sparen: 0x24AE,
  30523. squarebelowcmb: 0x033B,
  30524. squarecc: 0x33C4,
  30525. squarecm: 0x339D,
  30526. squarediagonalcrosshatchfill: 0x25A9,
  30527. squarehorizontalfill: 0x25A4,
  30528. squarekg: 0x338F,
  30529. squarekm: 0x339E,
  30530. squarekmcapital: 0x33CE,
  30531. squareln: 0x33D1,
  30532. squarelog: 0x33D2,
  30533. squaremg: 0x338E,
  30534. squaremil: 0x33D5,
  30535. squaremm: 0x339C,
  30536. squaremsquared: 0x33A1,
  30537. squareorthogonalcrosshatchfill: 0x25A6,
  30538. squareupperlefttolowerrightfill: 0x25A7,
  30539. squareupperrighttolowerleftfill: 0x25A8,
  30540. squareverticalfill: 0x25A5,
  30541. squarewhitewithsmallblack: 0x25A3,
  30542. srsquare: 0x33DB,
  30543. ssabengali: 0x09B7,
  30544. ssadeva: 0x0937,
  30545. ssagujarati: 0x0AB7,
  30546. ssangcieuckorean: 0x3149,
  30547. ssanghieuhkorean: 0x3185,
  30548. ssangieungkorean: 0x3180,
  30549. ssangkiyeokkorean: 0x3132,
  30550. ssangnieunkorean: 0x3165,
  30551. ssangpieupkorean: 0x3143,
  30552. ssangsioskorean: 0x3146,
  30553. ssangtikeutkorean: 0x3138,
  30554. ssuperior: 0xF6F2,
  30555. sterling: 0x00A3,
  30556. sterlingmonospace: 0xFFE1,
  30557. strokelongoverlaycmb: 0x0336,
  30558. strokeshortoverlaycmb: 0x0335,
  30559. subset: 0x2282,
  30560. subsetnotequal: 0x228A,
  30561. subsetorequal: 0x2286,
  30562. succeeds: 0x227B,
  30563. suchthat: 0x220B,
  30564. suhiragana: 0x3059,
  30565. sukatakana: 0x30B9,
  30566. sukatakanahalfwidth: 0xFF7D,
  30567. sukunarabic: 0x0652,
  30568. summation: 0x2211,
  30569. sun: 0x263C,
  30570. superset: 0x2283,
  30571. supersetnotequal: 0x228B,
  30572. supersetorequal: 0x2287,
  30573. svsquare: 0x33DC,
  30574. syouwaerasquare: 0x337C,
  30575. t: 0x0074,
  30576. tabengali: 0x09A4,
  30577. tackdown: 0x22A4,
  30578. tackleft: 0x22A3,
  30579. tadeva: 0x0924,
  30580. tagujarati: 0x0AA4,
  30581. tagurmukhi: 0x0A24,
  30582. taharabic: 0x0637,
  30583. tahfinalarabic: 0xFEC2,
  30584. tahinitialarabic: 0xFEC3,
  30585. tahiragana: 0x305F,
  30586. tahmedialarabic: 0xFEC4,
  30587. taisyouerasquare: 0x337D,
  30588. takatakana: 0x30BF,
  30589. takatakanahalfwidth: 0xFF80,
  30590. tatweelarabic: 0x0640,
  30591. tau: 0x03C4,
  30592. tav: 0x05EA,
  30593. tavdages: 0xFB4A,
  30594. tavdagesh: 0xFB4A,
  30595. tavdageshhebrew: 0xFB4A,
  30596. tavhebrew: 0x05EA,
  30597. tbar: 0x0167,
  30598. tbopomofo: 0x310A,
  30599. tcaron: 0x0165,
  30600. tccurl: 0x02A8,
  30601. tcedilla: 0x0163,
  30602. tcheharabic: 0x0686,
  30603. tchehfinalarabic: 0xFB7B,
  30604. tchehinitialarabic: 0xFB7C,
  30605. tchehmedialarabic: 0xFB7D,
  30606. tcircle: 0x24E3,
  30607. tcircumflexbelow: 0x1E71,
  30608. tcommaaccent: 0x0163,
  30609. tdieresis: 0x1E97,
  30610. tdotaccent: 0x1E6B,
  30611. tdotbelow: 0x1E6D,
  30612. tecyrillic: 0x0442,
  30613. tedescendercyrillic: 0x04AD,
  30614. teharabic: 0x062A,
  30615. tehfinalarabic: 0xFE96,
  30616. tehhahinitialarabic: 0xFCA2,
  30617. tehhahisolatedarabic: 0xFC0C,
  30618. tehinitialarabic: 0xFE97,
  30619. tehiragana: 0x3066,
  30620. tehjeeminitialarabic: 0xFCA1,
  30621. tehjeemisolatedarabic: 0xFC0B,
  30622. tehmarbutaarabic: 0x0629,
  30623. tehmarbutafinalarabic: 0xFE94,
  30624. tehmedialarabic: 0xFE98,
  30625. tehmeeminitialarabic: 0xFCA4,
  30626. tehmeemisolatedarabic: 0xFC0E,
  30627. tehnoonfinalarabic: 0xFC73,
  30628. tekatakana: 0x30C6,
  30629. tekatakanahalfwidth: 0xFF83,
  30630. telephone: 0x2121,
  30631. telephoneblack: 0x260E,
  30632. telishagedolahebrew: 0x05A0,
  30633. telishaqetanahebrew: 0x05A9,
  30634. tencircle: 0x2469,
  30635. tenideographicparen: 0x3229,
  30636. tenparen: 0x247D,
  30637. tenperiod: 0x2491,
  30638. tenroman: 0x2179,
  30639. tesh: 0x02A7,
  30640. tet: 0x05D8,
  30641. tetdagesh: 0xFB38,
  30642. tetdageshhebrew: 0xFB38,
  30643. tethebrew: 0x05D8,
  30644. tetsecyrillic: 0x04B5,
  30645. tevirhebrew: 0x059B,
  30646. tevirlefthebrew: 0x059B,
  30647. thabengali: 0x09A5,
  30648. thadeva: 0x0925,
  30649. thagujarati: 0x0AA5,
  30650. thagurmukhi: 0x0A25,
  30651. thalarabic: 0x0630,
  30652. thalfinalarabic: 0xFEAC,
  30653. thanthakhatlowleftthai: 0xF898,
  30654. thanthakhatlowrightthai: 0xF897,
  30655. thanthakhatthai: 0x0E4C,
  30656. thanthakhatupperleftthai: 0xF896,
  30657. theharabic: 0x062B,
  30658. thehfinalarabic: 0xFE9A,
  30659. thehinitialarabic: 0xFE9B,
  30660. thehmedialarabic: 0xFE9C,
  30661. thereexists: 0x2203,
  30662. therefore: 0x2234,
  30663. theta: 0x03B8,
  30664. theta1: 0x03D1,
  30665. thetasymbolgreek: 0x03D1,
  30666. thieuthacirclekorean: 0x3279,
  30667. thieuthaparenkorean: 0x3219,
  30668. thieuthcirclekorean: 0x326B,
  30669. thieuthkorean: 0x314C,
  30670. thieuthparenkorean: 0x320B,
  30671. thirteencircle: 0x246C,
  30672. thirteenparen: 0x2480,
  30673. thirteenperiod: 0x2494,
  30674. thonangmonthothai: 0x0E11,
  30675. thook: 0x01AD,
  30676. thophuthaothai: 0x0E12,
  30677. thorn: 0x00FE,
  30678. thothahanthai: 0x0E17,
  30679. thothanthai: 0x0E10,
  30680. thothongthai: 0x0E18,
  30681. thothungthai: 0x0E16,
  30682. thousandcyrillic: 0x0482,
  30683. thousandsseparatorarabic: 0x066C,
  30684. thousandsseparatorpersian: 0x066C,
  30685. three: 0x0033,
  30686. threearabic: 0x0663,
  30687. threebengali: 0x09E9,
  30688. threecircle: 0x2462,
  30689. threecircleinversesansserif: 0x278C,
  30690. threedeva: 0x0969,
  30691. threeeighths: 0x215C,
  30692. threegujarati: 0x0AE9,
  30693. threegurmukhi: 0x0A69,
  30694. threehackarabic: 0x0663,
  30695. threehangzhou: 0x3023,
  30696. threeideographicparen: 0x3222,
  30697. threeinferior: 0x2083,
  30698. threemonospace: 0xFF13,
  30699. threenumeratorbengali: 0x09F6,
  30700. threeoldstyle: 0xF733,
  30701. threeparen: 0x2476,
  30702. threeperiod: 0x248A,
  30703. threepersian: 0x06F3,
  30704. threequarters: 0x00BE,
  30705. threequartersemdash: 0xF6DE,
  30706. threeroman: 0x2172,
  30707. threesuperior: 0x00B3,
  30708. threethai: 0x0E53,
  30709. thzsquare: 0x3394,
  30710. tihiragana: 0x3061,
  30711. tikatakana: 0x30C1,
  30712. tikatakanahalfwidth: 0xFF81,
  30713. tikeutacirclekorean: 0x3270,
  30714. tikeutaparenkorean: 0x3210,
  30715. tikeutcirclekorean: 0x3262,
  30716. tikeutkorean: 0x3137,
  30717. tikeutparenkorean: 0x3202,
  30718. tilde: 0x02DC,
  30719. tildebelowcmb: 0x0330,
  30720. tildecmb: 0x0303,
  30721. tildecomb: 0x0303,
  30722. tildedoublecmb: 0x0360,
  30723. tildeoperator: 0x223C,
  30724. tildeoverlaycmb: 0x0334,
  30725. tildeverticalcmb: 0x033E,
  30726. timescircle: 0x2297,
  30727. tipehahebrew: 0x0596,
  30728. tipehalefthebrew: 0x0596,
  30729. tippigurmukhi: 0x0A70,
  30730. titlocyrilliccmb: 0x0483,
  30731. tiwnarmenian: 0x057F,
  30732. tlinebelow: 0x1E6F,
  30733. tmonospace: 0xFF54,
  30734. toarmenian: 0x0569,
  30735. tohiragana: 0x3068,
  30736. tokatakana: 0x30C8,
  30737. tokatakanahalfwidth: 0xFF84,
  30738. tonebarextrahighmod: 0x02E5,
  30739. tonebarextralowmod: 0x02E9,
  30740. tonebarhighmod: 0x02E6,
  30741. tonebarlowmod: 0x02E8,
  30742. tonebarmidmod: 0x02E7,
  30743. tonefive: 0x01BD,
  30744. tonesix: 0x0185,
  30745. tonetwo: 0x01A8,
  30746. tonos: 0x0384,
  30747. tonsquare: 0x3327,
  30748. topatakthai: 0x0E0F,
  30749. tortoiseshellbracketleft: 0x3014,
  30750. tortoiseshellbracketleftsmall: 0xFE5D,
  30751. tortoiseshellbracketleftvertical: 0xFE39,
  30752. tortoiseshellbracketright: 0x3015,
  30753. tortoiseshellbracketrightsmall: 0xFE5E,
  30754. tortoiseshellbracketrightvertical: 0xFE3A,
  30755. totaothai: 0x0E15,
  30756. tpalatalhook: 0x01AB,
  30757. tparen: 0x24AF,
  30758. trademark: 0x2122,
  30759. trademarksans: 0xF8EA,
  30760. trademarkserif: 0xF6DB,
  30761. tretroflexhook: 0x0288,
  30762. triagdn: 0x25BC,
  30763. triaglf: 0x25C4,
  30764. triagrt: 0x25BA,
  30765. triagup: 0x25B2,
  30766. ts: 0x02A6,
  30767. tsadi: 0x05E6,
  30768. tsadidagesh: 0xFB46,
  30769. tsadidageshhebrew: 0xFB46,
  30770. tsadihebrew: 0x05E6,
  30771. tsecyrillic: 0x0446,
  30772. tsere: 0x05B5,
  30773. tsere12: 0x05B5,
  30774. tsere1e: 0x05B5,
  30775. tsere2b: 0x05B5,
  30776. tserehebrew: 0x05B5,
  30777. tserenarrowhebrew: 0x05B5,
  30778. tserequarterhebrew: 0x05B5,
  30779. tserewidehebrew: 0x05B5,
  30780. tshecyrillic: 0x045B,
  30781. tsuperior: 0xF6F3,
  30782. ttabengali: 0x099F,
  30783. ttadeva: 0x091F,
  30784. ttagujarati: 0x0A9F,
  30785. ttagurmukhi: 0x0A1F,
  30786. tteharabic: 0x0679,
  30787. ttehfinalarabic: 0xFB67,
  30788. ttehinitialarabic: 0xFB68,
  30789. ttehmedialarabic: 0xFB69,
  30790. tthabengali: 0x09A0,
  30791. tthadeva: 0x0920,
  30792. tthagujarati: 0x0AA0,
  30793. tthagurmukhi: 0x0A20,
  30794. tturned: 0x0287,
  30795. tuhiragana: 0x3064,
  30796. tukatakana: 0x30C4,
  30797. tukatakanahalfwidth: 0xFF82,
  30798. tusmallhiragana: 0x3063,
  30799. tusmallkatakana: 0x30C3,
  30800. tusmallkatakanahalfwidth: 0xFF6F,
  30801. twelvecircle: 0x246B,
  30802. twelveparen: 0x247F,
  30803. twelveperiod: 0x2493,
  30804. twelveroman: 0x217B,
  30805. twentycircle: 0x2473,
  30806. twentyhangzhou: 0x5344,
  30807. twentyparen: 0x2487,
  30808. twentyperiod: 0x249B,
  30809. two: 0x0032,
  30810. twoarabic: 0x0662,
  30811. twobengali: 0x09E8,
  30812. twocircle: 0x2461,
  30813. twocircleinversesansserif: 0x278B,
  30814. twodeva: 0x0968,
  30815. twodotenleader: 0x2025,
  30816. twodotleader: 0x2025,
  30817. twodotleadervertical: 0xFE30,
  30818. twogujarati: 0x0AE8,
  30819. twogurmukhi: 0x0A68,
  30820. twohackarabic: 0x0662,
  30821. twohangzhou: 0x3022,
  30822. twoideographicparen: 0x3221,
  30823. twoinferior: 0x2082,
  30824. twomonospace: 0xFF12,
  30825. twonumeratorbengali: 0x09F5,
  30826. twooldstyle: 0xF732,
  30827. twoparen: 0x2475,
  30828. twoperiod: 0x2489,
  30829. twopersian: 0x06F2,
  30830. tworoman: 0x2171,
  30831. twostroke: 0x01BB,
  30832. twosuperior: 0x00B2,
  30833. twothai: 0x0E52,
  30834. twothirds: 0x2154,
  30835. u: 0x0075,
  30836. uacute: 0x00FA,
  30837. ubar: 0x0289,
  30838. ubengali: 0x0989,
  30839. ubopomofo: 0x3128,
  30840. ubreve: 0x016D,
  30841. ucaron: 0x01D4,
  30842. ucircle: 0x24E4,
  30843. ucircumflex: 0x00FB,
  30844. ucircumflexbelow: 0x1E77,
  30845. ucyrillic: 0x0443,
  30846. udattadeva: 0x0951,
  30847. udblacute: 0x0171,
  30848. udblgrave: 0x0215,
  30849. udeva: 0x0909,
  30850. udieresis: 0x00FC,
  30851. udieresisacute: 0x01D8,
  30852. udieresisbelow: 0x1E73,
  30853. udieresiscaron: 0x01DA,
  30854. udieresiscyrillic: 0x04F1,
  30855. udieresisgrave: 0x01DC,
  30856. udieresismacron: 0x01D6,
  30857. udotbelow: 0x1EE5,
  30858. ugrave: 0x00F9,
  30859. ugujarati: 0x0A89,
  30860. ugurmukhi: 0x0A09,
  30861. uhiragana: 0x3046,
  30862. uhookabove: 0x1EE7,
  30863. uhorn: 0x01B0,
  30864. uhornacute: 0x1EE9,
  30865. uhorndotbelow: 0x1EF1,
  30866. uhorngrave: 0x1EEB,
  30867. uhornhookabove: 0x1EED,
  30868. uhorntilde: 0x1EEF,
  30869. uhungarumlaut: 0x0171,
  30870. uhungarumlautcyrillic: 0x04F3,
  30871. uinvertedbreve: 0x0217,
  30872. ukatakana: 0x30A6,
  30873. ukatakanahalfwidth: 0xFF73,
  30874. ukcyrillic: 0x0479,
  30875. ukorean: 0x315C,
  30876. umacron: 0x016B,
  30877. umacroncyrillic: 0x04EF,
  30878. umacrondieresis: 0x1E7B,
  30879. umatragurmukhi: 0x0A41,
  30880. umonospace: 0xFF55,
  30881. underscore: 0x005F,
  30882. underscoredbl: 0x2017,
  30883. underscoremonospace: 0xFF3F,
  30884. underscorevertical: 0xFE33,
  30885. underscorewavy: 0xFE4F,
  30886. union: 0x222A,
  30887. universal: 0x2200,
  30888. uogonek: 0x0173,
  30889. uparen: 0x24B0,
  30890. upblock: 0x2580,
  30891. upperdothebrew: 0x05C4,
  30892. upsilon: 0x03C5,
  30893. upsilondieresis: 0x03CB,
  30894. upsilondieresistonos: 0x03B0,
  30895. upsilonlatin: 0x028A,
  30896. upsilontonos: 0x03CD,
  30897. uptackbelowcmb: 0x031D,
  30898. uptackmod: 0x02D4,
  30899. uragurmukhi: 0x0A73,
  30900. uring: 0x016F,
  30901. ushortcyrillic: 0x045E,
  30902. usmallhiragana: 0x3045,
  30903. usmallkatakana: 0x30A5,
  30904. usmallkatakanahalfwidth: 0xFF69,
  30905. ustraightcyrillic: 0x04AF,
  30906. ustraightstrokecyrillic: 0x04B1,
  30907. utilde: 0x0169,
  30908. utildeacute: 0x1E79,
  30909. utildebelow: 0x1E75,
  30910. uubengali: 0x098A,
  30911. uudeva: 0x090A,
  30912. uugujarati: 0x0A8A,
  30913. uugurmukhi: 0x0A0A,
  30914. uumatragurmukhi: 0x0A42,
  30915. uuvowelsignbengali: 0x09C2,
  30916. uuvowelsigndeva: 0x0942,
  30917. uuvowelsigngujarati: 0x0AC2,
  30918. uvowelsignbengali: 0x09C1,
  30919. uvowelsigndeva: 0x0941,
  30920. uvowelsigngujarati: 0x0AC1,
  30921. v: 0x0076,
  30922. vadeva: 0x0935,
  30923. vagujarati: 0x0AB5,
  30924. vagurmukhi: 0x0A35,
  30925. vakatakana: 0x30F7,
  30926. vav: 0x05D5,
  30927. vavdagesh: 0xFB35,
  30928. vavdagesh65: 0xFB35,
  30929. vavdageshhebrew: 0xFB35,
  30930. vavhebrew: 0x05D5,
  30931. vavholam: 0xFB4B,
  30932. vavholamhebrew: 0xFB4B,
  30933. vavvavhebrew: 0x05F0,
  30934. vavyodhebrew: 0x05F1,
  30935. vcircle: 0x24E5,
  30936. vdotbelow: 0x1E7F,
  30937. vecyrillic: 0x0432,
  30938. veharabic: 0x06A4,
  30939. vehfinalarabic: 0xFB6B,
  30940. vehinitialarabic: 0xFB6C,
  30941. vehmedialarabic: 0xFB6D,
  30942. vekatakana: 0x30F9,
  30943. venus: 0x2640,
  30944. verticalbar: 0x007C,
  30945. verticallineabovecmb: 0x030D,
  30946. verticallinebelowcmb: 0x0329,
  30947. verticallinelowmod: 0x02CC,
  30948. verticallinemod: 0x02C8,
  30949. vewarmenian: 0x057E,
  30950. vhook: 0x028B,
  30951. vikatakana: 0x30F8,
  30952. viramabengali: 0x09CD,
  30953. viramadeva: 0x094D,
  30954. viramagujarati: 0x0ACD,
  30955. visargabengali: 0x0983,
  30956. visargadeva: 0x0903,
  30957. visargagujarati: 0x0A83,
  30958. vmonospace: 0xFF56,
  30959. voarmenian: 0x0578,
  30960. voicediterationhiragana: 0x309E,
  30961. voicediterationkatakana: 0x30FE,
  30962. voicedmarkkana: 0x309B,
  30963. voicedmarkkanahalfwidth: 0xFF9E,
  30964. vokatakana: 0x30FA,
  30965. vparen: 0x24B1,
  30966. vtilde: 0x1E7D,
  30967. vturned: 0x028C,
  30968. vuhiragana: 0x3094,
  30969. vukatakana: 0x30F4,
  30970. w: 0x0077,
  30971. wacute: 0x1E83,
  30972. waekorean: 0x3159,
  30973. wahiragana: 0x308F,
  30974. wakatakana: 0x30EF,
  30975. wakatakanahalfwidth: 0xFF9C,
  30976. wakorean: 0x3158,
  30977. wasmallhiragana: 0x308E,
  30978. wasmallkatakana: 0x30EE,
  30979. wattosquare: 0x3357,
  30980. wavedash: 0x301C,
  30981. wavyunderscorevertical: 0xFE34,
  30982. wawarabic: 0x0648,
  30983. wawfinalarabic: 0xFEEE,
  30984. wawhamzaabovearabic: 0x0624,
  30985. wawhamzaabovefinalarabic: 0xFE86,
  30986. wbsquare: 0x33DD,
  30987. wcircle: 0x24E6,
  30988. wcircumflex: 0x0175,
  30989. wdieresis: 0x1E85,
  30990. wdotaccent: 0x1E87,
  30991. wdotbelow: 0x1E89,
  30992. wehiragana: 0x3091,
  30993. weierstrass: 0x2118,
  30994. wekatakana: 0x30F1,
  30995. wekorean: 0x315E,
  30996. weokorean: 0x315D,
  30997. wgrave: 0x1E81,
  30998. whitebullet: 0x25E6,
  30999. whitecircle: 0x25CB,
  31000. whitecircleinverse: 0x25D9,
  31001. whitecornerbracketleft: 0x300E,
  31002. whitecornerbracketleftvertical: 0xFE43,
  31003. whitecornerbracketright: 0x300F,
  31004. whitecornerbracketrightvertical: 0xFE44,
  31005. whitediamond: 0x25C7,
  31006. whitediamondcontainingblacksmalldiamond: 0x25C8,
  31007. whitedownpointingsmalltriangle: 0x25BF,
  31008. whitedownpointingtriangle: 0x25BD,
  31009. whiteleftpointingsmalltriangle: 0x25C3,
  31010. whiteleftpointingtriangle: 0x25C1,
  31011. whitelenticularbracketleft: 0x3016,
  31012. whitelenticularbracketright: 0x3017,
  31013. whiterightpointingsmalltriangle: 0x25B9,
  31014. whiterightpointingtriangle: 0x25B7,
  31015. whitesmallsquare: 0x25AB,
  31016. whitesmilingface: 0x263A,
  31017. whitesquare: 0x25A1,
  31018. whitestar: 0x2606,
  31019. whitetelephone: 0x260F,
  31020. whitetortoiseshellbracketleft: 0x3018,
  31021. whitetortoiseshellbracketright: 0x3019,
  31022. whiteuppointingsmalltriangle: 0x25B5,
  31023. whiteuppointingtriangle: 0x25B3,
  31024. wihiragana: 0x3090,
  31025. wikatakana: 0x30F0,
  31026. wikorean: 0x315F,
  31027. wmonospace: 0xFF57,
  31028. wohiragana: 0x3092,
  31029. wokatakana: 0x30F2,
  31030. wokatakanahalfwidth: 0xFF66,
  31031. won: 0x20A9,
  31032. wonmonospace: 0xFFE6,
  31033. wowaenthai: 0x0E27,
  31034. wparen: 0x24B2,
  31035. wring: 0x1E98,
  31036. wsuperior: 0x02B7,
  31037. wturned: 0x028D,
  31038. wynn: 0x01BF,
  31039. x: 0x0078,
  31040. xabovecmb: 0x033D,
  31041. xbopomofo: 0x3112,
  31042. xcircle: 0x24E7,
  31043. xdieresis: 0x1E8D,
  31044. xdotaccent: 0x1E8B,
  31045. xeharmenian: 0x056D,
  31046. xi: 0x03BE,
  31047. xmonospace: 0xFF58,
  31048. xparen: 0x24B3,
  31049. xsuperior: 0x02E3,
  31050. y: 0x0079,
  31051. yaadosquare: 0x334E,
  31052. yabengali: 0x09AF,
  31053. yacute: 0x00FD,
  31054. yadeva: 0x092F,
  31055. yaekorean: 0x3152,
  31056. yagujarati: 0x0AAF,
  31057. yagurmukhi: 0x0A2F,
  31058. yahiragana: 0x3084,
  31059. yakatakana: 0x30E4,
  31060. yakatakanahalfwidth: 0xFF94,
  31061. yakorean: 0x3151,
  31062. yamakkanthai: 0x0E4E,
  31063. yasmallhiragana: 0x3083,
  31064. yasmallkatakana: 0x30E3,
  31065. yasmallkatakanahalfwidth: 0xFF6C,
  31066. yatcyrillic: 0x0463,
  31067. ycircle: 0x24E8,
  31068. ycircumflex: 0x0177,
  31069. ydieresis: 0x00FF,
  31070. ydotaccent: 0x1E8F,
  31071. ydotbelow: 0x1EF5,
  31072. yeharabic: 0x064A,
  31073. yehbarreearabic: 0x06D2,
  31074. yehbarreefinalarabic: 0xFBAF,
  31075. yehfinalarabic: 0xFEF2,
  31076. yehhamzaabovearabic: 0x0626,
  31077. yehhamzaabovefinalarabic: 0xFE8A,
  31078. yehhamzaaboveinitialarabic: 0xFE8B,
  31079. yehhamzaabovemedialarabic: 0xFE8C,
  31080. yehinitialarabic: 0xFEF3,
  31081. yehmedialarabic: 0xFEF4,
  31082. yehmeeminitialarabic: 0xFCDD,
  31083. yehmeemisolatedarabic: 0xFC58,
  31084. yehnoonfinalarabic: 0xFC94,
  31085. yehthreedotsbelowarabic: 0x06D1,
  31086. yekorean: 0x3156,
  31087. yen: 0x00A5,
  31088. yenmonospace: 0xFFE5,
  31089. yeokorean: 0x3155,
  31090. yeorinhieuhkorean: 0x3186,
  31091. yerahbenyomohebrew: 0x05AA,
  31092. yerahbenyomolefthebrew: 0x05AA,
  31093. yericyrillic: 0x044B,
  31094. yerudieresiscyrillic: 0x04F9,
  31095. yesieungkorean: 0x3181,
  31096. yesieungpansioskorean: 0x3183,
  31097. yesieungsioskorean: 0x3182,
  31098. yetivhebrew: 0x059A,
  31099. ygrave: 0x1EF3,
  31100. yhook: 0x01B4,
  31101. yhookabove: 0x1EF7,
  31102. yiarmenian: 0x0575,
  31103. yicyrillic: 0x0457,
  31104. yikorean: 0x3162,
  31105. yinyang: 0x262F,
  31106. yiwnarmenian: 0x0582,
  31107. ymonospace: 0xFF59,
  31108. yod: 0x05D9,
  31109. yoddagesh: 0xFB39,
  31110. yoddageshhebrew: 0xFB39,
  31111. yodhebrew: 0x05D9,
  31112. yodyodhebrew: 0x05F2,
  31113. yodyodpatahhebrew: 0xFB1F,
  31114. yohiragana: 0x3088,
  31115. yoikorean: 0x3189,
  31116. yokatakana: 0x30E8,
  31117. yokatakanahalfwidth: 0xFF96,
  31118. yokorean: 0x315B,
  31119. yosmallhiragana: 0x3087,
  31120. yosmallkatakana: 0x30E7,
  31121. yosmallkatakanahalfwidth: 0xFF6E,
  31122. yotgreek: 0x03F3,
  31123. yoyaekorean: 0x3188,
  31124. yoyakorean: 0x3187,
  31125. yoyakthai: 0x0E22,
  31126. yoyingthai: 0x0E0D,
  31127. yparen: 0x24B4,
  31128. ypogegrammeni: 0x037A,
  31129. ypogegrammenigreekcmb: 0x0345,
  31130. yr: 0x01A6,
  31131. yring: 0x1E99,
  31132. ysuperior: 0x02B8,
  31133. ytilde: 0x1EF9,
  31134. yturned: 0x028E,
  31135. yuhiragana: 0x3086,
  31136. yuikorean: 0x318C,
  31137. yukatakana: 0x30E6,
  31138. yukatakanahalfwidth: 0xFF95,
  31139. yukorean: 0x3160,
  31140. yusbigcyrillic: 0x046B,
  31141. yusbigiotifiedcyrillic: 0x046D,
  31142. yuslittlecyrillic: 0x0467,
  31143. yuslittleiotifiedcyrillic: 0x0469,
  31144. yusmallhiragana: 0x3085,
  31145. yusmallkatakana: 0x30E5,
  31146. yusmallkatakanahalfwidth: 0xFF6D,
  31147. yuyekorean: 0x318B,
  31148. yuyeokorean: 0x318A,
  31149. yyabengali: 0x09DF,
  31150. yyadeva: 0x095F,
  31151. z: 0x007A,
  31152. zaarmenian: 0x0566,
  31153. zacute: 0x017A,
  31154. zadeva: 0x095B,
  31155. zagurmukhi: 0x0A5B,
  31156. zaharabic: 0x0638,
  31157. zahfinalarabic: 0xFEC6,
  31158. zahinitialarabic: 0xFEC7,
  31159. zahiragana: 0x3056,
  31160. zahmedialarabic: 0xFEC8,
  31161. zainarabic: 0x0632,
  31162. zainfinalarabic: 0xFEB0,
  31163. zakatakana: 0x30B6,
  31164. zaqefgadolhebrew: 0x0595,
  31165. zaqefqatanhebrew: 0x0594,
  31166. zarqahebrew: 0x0598,
  31167. zayin: 0x05D6,
  31168. zayindagesh: 0xFB36,
  31169. zayindageshhebrew: 0xFB36,
  31170. zayinhebrew: 0x05D6,
  31171. zbopomofo: 0x3117,
  31172. zcaron: 0x017E,
  31173. zcircle: 0x24E9,
  31174. zcircumflex: 0x1E91,
  31175. zcurl: 0x0291,
  31176. zdot: 0x017C,
  31177. zdotaccent: 0x017C,
  31178. zdotbelow: 0x1E93,
  31179. zecyrillic: 0x0437,
  31180. zedescendercyrillic: 0x0499,
  31181. zedieresiscyrillic: 0x04DF,
  31182. zehiragana: 0x305C,
  31183. zekatakana: 0x30BC,
  31184. zero: 0x0030,
  31185. zeroarabic: 0x0660,
  31186. zerobengali: 0x09E6,
  31187. zerodeva: 0x0966,
  31188. zerogujarati: 0x0AE6,
  31189. zerogurmukhi: 0x0A66,
  31190. zerohackarabic: 0x0660,
  31191. zeroinferior: 0x2080,
  31192. zeromonospace: 0xFF10,
  31193. zerooldstyle: 0xF730,
  31194. zeropersian: 0x06F0,
  31195. zerosuperior: 0x2070,
  31196. zerothai: 0x0E50,
  31197. zerowidthjoiner: 0xFEFF,
  31198. zerowidthnonjoiner: 0x200C,
  31199. zerowidthspace: 0x200B,
  31200. zeta: 0x03B6,
  31201. zhbopomofo: 0x3113,
  31202. zhearmenian: 0x056A,
  31203. zhebrevecyrillic: 0x04C2,
  31204. zhecyrillic: 0x0436,
  31205. zhedescendercyrillic: 0x0497,
  31206. zhedieresiscyrillic: 0x04DD,
  31207. zihiragana: 0x3058,
  31208. zikatakana: 0x30B8,
  31209. zinorhebrew: 0x05AE,
  31210. zlinebelow: 0x1E95,
  31211. zmonospace: 0xFF5A,
  31212. zohiragana: 0x305E,
  31213. zokatakana: 0x30BE,
  31214. zparen: 0x24B5,
  31215. zretroflexhook: 0x0290,
  31216. zstroke: 0x01B6,
  31217. zuhiragana: 0x305A,
  31218. zukatakana: 0x30BA,
  31219. '.notdef': 0x0000
  31220. };
  31221. var DingbatsGlyphsUnicode = {
  31222. space: 0x0020,
  31223. a1: 0x2701,
  31224. a2: 0x2702,
  31225. a202: 0x2703,
  31226. a3: 0x2704,
  31227. a4: 0x260E,
  31228. a5: 0x2706,
  31229. a119: 0x2707,
  31230. a118: 0x2708,
  31231. a117: 0x2709,
  31232. a11: 0x261B,
  31233. a12: 0x261E,
  31234. a13: 0x270C,
  31235. a14: 0x270D,
  31236. a15: 0x270E,
  31237. a16: 0x270F,
  31238. a105: 0x2710,
  31239. a17: 0x2711,
  31240. a18: 0x2712,
  31241. a19: 0x2713,
  31242. a20: 0x2714,
  31243. a21: 0x2715,
  31244. a22: 0x2716,
  31245. a23: 0x2717,
  31246. a24: 0x2718,
  31247. a25: 0x2719,
  31248. a26: 0x271A,
  31249. a27: 0x271B,
  31250. a28: 0x271C,
  31251. a6: 0x271D,
  31252. a7: 0x271E,
  31253. a8: 0x271F,
  31254. a9: 0x2720,
  31255. a10: 0x2721,
  31256. a29: 0x2722,
  31257. a30: 0x2723,
  31258. a31: 0x2724,
  31259. a32: 0x2725,
  31260. a33: 0x2726,
  31261. a34: 0x2727,
  31262. a35: 0x2605,
  31263. a36: 0x2729,
  31264. a37: 0x272A,
  31265. a38: 0x272B,
  31266. a39: 0x272C,
  31267. a40: 0x272D,
  31268. a41: 0x272E,
  31269. a42: 0x272F,
  31270. a43: 0x2730,
  31271. a44: 0x2731,
  31272. a45: 0x2732,
  31273. a46: 0x2733,
  31274. a47: 0x2734,
  31275. a48: 0x2735,
  31276. a49: 0x2736,
  31277. a50: 0x2737,
  31278. a51: 0x2738,
  31279. a52: 0x2739,
  31280. a53: 0x273A,
  31281. a54: 0x273B,
  31282. a55: 0x273C,
  31283. a56: 0x273D,
  31284. a57: 0x273E,
  31285. a58: 0x273F,
  31286. a59: 0x2740,
  31287. a60: 0x2741,
  31288. a61: 0x2742,
  31289. a62: 0x2743,
  31290. a63: 0x2744,
  31291. a64: 0x2745,
  31292. a65: 0x2746,
  31293. a66: 0x2747,
  31294. a67: 0x2748,
  31295. a68: 0x2749,
  31296. a69: 0x274A,
  31297. a70: 0x274B,
  31298. a71: 0x25CF,
  31299. a72: 0x274D,
  31300. a73: 0x25A0,
  31301. a74: 0x274F,
  31302. a203: 0x2750,
  31303. a75: 0x2751,
  31304. a204: 0x2752,
  31305. a76: 0x25B2,
  31306. a77: 0x25BC,
  31307. a78: 0x25C6,
  31308. a79: 0x2756,
  31309. a81: 0x25D7,
  31310. a82: 0x2758,
  31311. a83: 0x2759,
  31312. a84: 0x275A,
  31313. a97: 0x275B,
  31314. a98: 0x275C,
  31315. a99: 0x275D,
  31316. a100: 0x275E,
  31317. a101: 0x2761,
  31318. a102: 0x2762,
  31319. a103: 0x2763,
  31320. a104: 0x2764,
  31321. a106: 0x2765,
  31322. a107: 0x2766,
  31323. a108: 0x2767,
  31324. a112: 0x2663,
  31325. a111: 0x2666,
  31326. a110: 0x2665,
  31327. a109: 0x2660,
  31328. a120: 0x2460,
  31329. a121: 0x2461,
  31330. a122: 0x2462,
  31331. a123: 0x2463,
  31332. a124: 0x2464,
  31333. a125: 0x2465,
  31334. a126: 0x2466,
  31335. a127: 0x2467,
  31336. a128: 0x2468,
  31337. a129: 0x2469,
  31338. a130: 0x2776,
  31339. a131: 0x2777,
  31340. a132: 0x2778,
  31341. a133: 0x2779,
  31342. a134: 0x277A,
  31343. a135: 0x277B,
  31344. a136: 0x277C,
  31345. a137: 0x277D,
  31346. a138: 0x277E,
  31347. a139: 0x277F,
  31348. a140: 0x2780,
  31349. a141: 0x2781,
  31350. a142: 0x2782,
  31351. a143: 0x2783,
  31352. a144: 0x2784,
  31353. a145: 0x2785,
  31354. a146: 0x2786,
  31355. a147: 0x2787,
  31356. a148: 0x2788,
  31357. a149: 0x2789,
  31358. a150: 0x278A,
  31359. a151: 0x278B,
  31360. a152: 0x278C,
  31361. a153: 0x278D,
  31362. a154: 0x278E,
  31363. a155: 0x278F,
  31364. a156: 0x2790,
  31365. a157: 0x2791,
  31366. a158: 0x2792,
  31367. a159: 0x2793,
  31368. a160: 0x2794,
  31369. a161: 0x2192,
  31370. a163: 0x2194,
  31371. a164: 0x2195,
  31372. a196: 0x2798,
  31373. a165: 0x2799,
  31374. a192: 0x279A,
  31375. a166: 0x279B,
  31376. a167: 0x279C,
  31377. a168: 0x279D,
  31378. a169: 0x279E,
  31379. a170: 0x279F,
  31380. a171: 0x27A0,
  31381. a172: 0x27A1,
  31382. a173: 0x27A2,
  31383. a162: 0x27A3,
  31384. a174: 0x27A4,
  31385. a175: 0x27A5,
  31386. a176: 0x27A6,
  31387. a177: 0x27A7,
  31388. a178: 0x27A8,
  31389. a179: 0x27A9,
  31390. a193: 0x27AA,
  31391. a180: 0x27AB,
  31392. a199: 0x27AC,
  31393. a181: 0x27AD,
  31394. a200: 0x27AE,
  31395. a182: 0x27AF,
  31396. a201: 0x27B1,
  31397. a183: 0x27B2,
  31398. a184: 0x27B3,
  31399. a197: 0x27B4,
  31400. a185: 0x27B5,
  31401. a194: 0x27B6,
  31402. a198: 0x27B7,
  31403. a186: 0x27B8,
  31404. a195: 0x27B9,
  31405. a187: 0x27BA,
  31406. a188: 0x27BB,
  31407. a189: 0x27BC,
  31408. a190: 0x27BD,
  31409. a191: 0x27BE,
  31410. a89: 0x2768, // 0xF8D7
  31411. a90: 0x2769, // 0xF8D8
  31412. a93: 0x276A, // 0xF8D9
  31413. a94: 0x276B, // 0xF8DA
  31414. a91: 0x276C, // 0xF8DB
  31415. a92: 0x276D, // 0xF8DC
  31416. a205: 0x276E, // 0xF8DD
  31417. a85: 0x276F, // 0xF8DE
  31418. a206: 0x2770, // 0xF8DF
  31419. a86: 0x2771, // 0xF8E0
  31420. a87: 0x2772, // 0xF8E1
  31421. a88: 0x2773, // 0xF8E2
  31422. a95: 0x2774, // 0xF8E3
  31423. a96: 0x2775, // 0xF8E4
  31424. '.notdef': 0x0000
  31425. };
  31426. var PDFImage = (function PDFImageClosure() {
  31427. /**
  31428. * Decode the image in the main thread if it supported. Resovles the promise
  31429. * when the image data is ready.
  31430. */
  31431. function handleImageData(handler, xref, res, image) {
  31432. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  31433. // For natively supported jpegs send them to the main thread for decoding.
  31434. var dict = image.dict;
  31435. var colorSpace = dict.get('ColorSpace', 'CS');
  31436. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  31437. var numComps = colorSpace.numComps;
  31438. var decodePromise = handler.sendWithPromise('JpegDecode',
  31439. [image.getIR(), numComps]);
  31440. return decodePromise.then(function (message) {
  31441. var data = message.data;
  31442. return new Stream(data, 0, data.length, image.dict);
  31443. });
  31444. } else {
  31445. return Promise.resolve(image);
  31446. }
  31447. }
  31448. /**
  31449. * Decode and clamp a value. The formula is different from the spec because we
  31450. * don't decode to float range [0,1], we decode it in the [0,max] range.
  31451. */
  31452. function decodeAndClamp(value, addend, coefficient, max) {
  31453. value = addend + value * coefficient;
  31454. // Clamp the value to the range
  31455. return (value < 0 ? 0 : (value > max ? max : value));
  31456. }
  31457. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  31458. this.image = image;
  31459. var dict = image.dict;
  31460. if (dict.has('Filter')) {
  31461. var filter = dict.get('Filter').name;
  31462. if (filter === 'JPXDecode') {
  31463. var jpxImage = new JpxImage();
  31464. jpxImage.parseImageProperties(image.stream);
  31465. image.stream.reset();
  31466. image.bitsPerComponent = jpxImage.bitsPerComponent;
  31467. image.numComps = jpxImage.componentsCount;
  31468. } else if (filter === 'JBIG2Decode') {
  31469. image.bitsPerComponent = 1;
  31470. image.numComps = 1;
  31471. }
  31472. }
  31473. // TODO cache rendered images?
  31474. this.width = dict.get('Width', 'W');
  31475. this.height = dict.get('Height', 'H');
  31476. if (this.width < 1 || this.height < 1) {
  31477. error('Invalid image width: ' + this.width + ' or height: ' +
  31478. this.height);
  31479. }
  31480. this.interpolate = dict.get('Interpolate', 'I') || false;
  31481. this.imageMask = dict.get('ImageMask', 'IM') || false;
  31482. this.matte = dict.get('Matte') || false;
  31483. var bitsPerComponent = image.bitsPerComponent;
  31484. if (!bitsPerComponent) {
  31485. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  31486. if (!bitsPerComponent) {
  31487. if (this.imageMask) {
  31488. bitsPerComponent = 1;
  31489. } else {
  31490. error('Bits per component missing in image: ' + this.imageMask);
  31491. }
  31492. }
  31493. }
  31494. this.bpc = bitsPerComponent;
  31495. if (!this.imageMask) {
  31496. var colorSpace = dict.get('ColorSpace', 'CS');
  31497. if (!colorSpace) {
  31498. info('JPX images (which do not require color spaces)');
  31499. switch (image.numComps) {
  31500. case 1:
  31501. colorSpace = Name.get('DeviceGray');
  31502. break;
  31503. case 3:
  31504. colorSpace = Name.get('DeviceRGB');
  31505. break;
  31506. case 4:
  31507. colorSpace = Name.get('DeviceCMYK');
  31508. break;
  31509. default:
  31510. error('JPX images with ' + this.numComps +
  31511. ' color components not supported.');
  31512. }
  31513. }
  31514. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  31515. this.numComps = this.colorSpace.numComps;
  31516. }
  31517. this.decode = dict.get('Decode', 'D');
  31518. this.needsDecode = false;
  31519. if (this.decode &&
  31520. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  31521. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  31522. this.needsDecode = true;
  31523. // Do some preprocessing to avoid more math.
  31524. var max = (1 << bitsPerComponent) - 1;
  31525. this.decodeCoefficients = [];
  31526. this.decodeAddends = [];
  31527. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  31528. var dmin = this.decode[i];
  31529. var dmax = this.decode[i + 1];
  31530. this.decodeCoefficients[j] = dmax - dmin;
  31531. this.decodeAddends[j] = max * dmin;
  31532. }
  31533. }
  31534. if (smask) {
  31535. this.smask = new PDFImage(xref, res, smask, false);
  31536. } else if (mask) {
  31537. if (isStream(mask)) {
  31538. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  31539. if (!imageMask) {
  31540. warn('Ignoring /Mask in image without /ImageMask.');
  31541. } else {
  31542. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  31543. }
  31544. } else {
  31545. // Color key mask (just an array).
  31546. this.mask = mask;
  31547. }
  31548. }
  31549. }
  31550. /**
  31551. * Handles processing of image data and returns the Promise that is resolved
  31552. * with a PDFImage when the image is ready to be used.
  31553. */
  31554. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  31555. res, image, inline) {
  31556. var imagePromise = handleImageData(handler, xref, res, image);
  31557. var smaskPromise;
  31558. var maskPromise;
  31559. var smask = image.dict.get('SMask');
  31560. var mask = image.dict.get('Mask');
  31561. if (smask) {
  31562. smaskPromise = handleImageData(handler, xref, res, smask);
  31563. maskPromise = Promise.resolve(null);
  31564. } else {
  31565. smaskPromise = Promise.resolve(null);
  31566. if (mask) {
  31567. if (isStream(mask)) {
  31568. maskPromise = handleImageData(handler, xref, res, mask);
  31569. } else if (isArray(mask)) {
  31570. maskPromise = Promise.resolve(mask);
  31571. } else {
  31572. warn('Unsupported mask format.');
  31573. maskPromise = Promise.resolve(null);
  31574. }
  31575. } else {
  31576. maskPromise = Promise.resolve(null);
  31577. }
  31578. }
  31579. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  31580. function(results) {
  31581. var imageData = results[0];
  31582. var smaskData = results[1];
  31583. var maskData = results[2];
  31584. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  31585. });
  31586. };
  31587. /**
  31588. * Resize an image using the nearest neighbor algorithm. Currently only
  31589. * supports one and three component images.
  31590. * @param {TypedArray} pixels The original image with one component.
  31591. * @param {Number} bpc Number of bits per component.
  31592. * @param {Number} components Number of color components, 1 or 3 is supported.
  31593. * @param {Number} w1 Original width.
  31594. * @param {Number} h1 Original height.
  31595. * @param {Number} w2 New width.
  31596. * @param {Number} h2 New height.
  31597. * @param {TypedArray} dest (Optional) The destination buffer.
  31598. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  31599. * @return {TypedArray} Resized image data.
  31600. */
  31601. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  31602. w1, h1, w2, h2, dest, alpha01) {
  31603. if (components !== 1 && components !== 3) {
  31604. error('Unsupported component count for resizing.');
  31605. }
  31606. var length = w2 * h2 * components;
  31607. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  31608. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  31609. var xRatio = w1 / w2;
  31610. var yRatio = h1 / h2;
  31611. var i, j, py, newIndex = 0, oldIndex;
  31612. var xScaled = new Uint16Array(w2);
  31613. var w1Scanline = w1 * components;
  31614. if (alpha01 !== 1) {
  31615. alpha01 = 0;
  31616. }
  31617. for (j = 0; j < w2; j++) {
  31618. xScaled[j] = Math.floor(j * xRatio) * components;
  31619. }
  31620. if (components === 1) {
  31621. for (i = 0; i < h2; i++) {
  31622. py = Math.floor(i * yRatio) * w1Scanline;
  31623. for (j = 0; j < w2; j++) {
  31624. oldIndex = py + xScaled[j];
  31625. temp[newIndex++] = pixels[oldIndex];
  31626. }
  31627. }
  31628. } else if (components === 3) {
  31629. for (i = 0; i < h2; i++) {
  31630. py = Math.floor(i * yRatio) * w1Scanline;
  31631. for (j = 0; j < w2; j++) {
  31632. oldIndex = py + xScaled[j];
  31633. temp[newIndex++] = pixels[oldIndex++];
  31634. temp[newIndex++] = pixels[oldIndex++];
  31635. temp[newIndex++] = pixels[oldIndex++];
  31636. newIndex += alpha01;
  31637. }
  31638. }
  31639. }
  31640. return temp;
  31641. };
  31642. PDFImage.createMask =
  31643. function PDFImage_createMask(imgArray, width, height,
  31644. imageIsFromDecodeStream, inverseDecode) {
  31645. // |imgArray| might not contain full data for every pixel of the mask, so
  31646. // we need to distinguish between |computedLength| and |actualLength|.
  31647. // In particular, if inverseDecode is true, then the array we return must
  31648. // have a length of |computedLength|.
  31649. var computedLength = ((width + 7) >> 3) * height;
  31650. var actualLength = imgArray.byteLength;
  31651. var haveFullData = computedLength === actualLength;
  31652. var data, i;
  31653. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  31654. // imgArray came from a DecodeStream and its data is in an appropriate
  31655. // form, so we can just transfer it.
  31656. data = imgArray;
  31657. } else if (!inverseDecode) {
  31658. data = new Uint8Array(actualLength);
  31659. data.set(imgArray);
  31660. } else {
  31661. data = new Uint8Array(computedLength);
  31662. data.set(imgArray);
  31663. for (i = actualLength; i < computedLength; i++) {
  31664. data[i] = 0xff;
  31665. }
  31666. }
  31667. // If necessary, invert the original mask data (but not any extra we might
  31668. // have added above). It's safe to modify the array -- whether it's the
  31669. // original or a copy, we're about to transfer it anyway, so nothing else
  31670. // in this thread can be relying on its contents.
  31671. if (inverseDecode) {
  31672. for (i = 0; i < actualLength; i++) {
  31673. data[i] = ~data[i];
  31674. }
  31675. }
  31676. return {data: data, width: width, height: height};
  31677. };
  31678. PDFImage.prototype = {
  31679. get drawWidth() {
  31680. return Math.max(this.width,
  31681. this.smask && this.smask.width || 0,
  31682. this.mask && this.mask.width || 0);
  31683. },
  31684. get drawHeight() {
  31685. return Math.max(this.height,
  31686. this.smask && this.smask.height || 0,
  31687. this.mask && this.mask.height || 0);
  31688. },
  31689. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  31690. var bpc = this.bpc;
  31691. var numComps = this.numComps;
  31692. var decodeAddends = this.decodeAddends;
  31693. var decodeCoefficients = this.decodeCoefficients;
  31694. var max = (1 << bpc) - 1;
  31695. var i, ii;
  31696. if (bpc === 1) {
  31697. // If the buffer needed decode that means it just needs to be inverted.
  31698. for (i = 0, ii = buffer.length; i < ii; i++) {
  31699. buffer[i] = +!(buffer[i]);
  31700. }
  31701. return;
  31702. }
  31703. var index = 0;
  31704. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  31705. for (var j = 0; j < numComps; j++) {
  31706. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  31707. decodeCoefficients[j], max);
  31708. index++;
  31709. }
  31710. }
  31711. },
  31712. getComponents: function PDFImage_getComponents(buffer) {
  31713. var bpc = this.bpc;
  31714. // This image doesn't require any extra work.
  31715. if (bpc === 8) {
  31716. return buffer;
  31717. }
  31718. var width = this.width;
  31719. var height = this.height;
  31720. var numComps = this.numComps;
  31721. var length = width * height * numComps;
  31722. var bufferPos = 0;
  31723. var output = (bpc <= 8 ? new Uint8Array(length) :
  31724. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  31725. var rowComps = width * numComps;
  31726. var max = (1 << bpc) - 1;
  31727. var i = 0, ii, buf;
  31728. if (bpc === 1) {
  31729. // Optimization for reading 1 bpc images.
  31730. var mask, loop1End, loop2End;
  31731. for (var j = 0; j < height; j++) {
  31732. loop1End = i + (rowComps & ~7);
  31733. loop2End = i + rowComps;
  31734. // unroll loop for all full bytes
  31735. while (i < loop1End) {
  31736. buf = buffer[bufferPos++];
  31737. output[i] = (buf >> 7) & 1;
  31738. output[i + 1] = (buf >> 6) & 1;
  31739. output[i + 2] = (buf >> 5) & 1;
  31740. output[i + 3] = (buf >> 4) & 1;
  31741. output[i + 4] = (buf >> 3) & 1;
  31742. output[i + 5] = (buf >> 2) & 1;
  31743. output[i + 6] = (buf >> 1) & 1;
  31744. output[i + 7] = buf & 1;
  31745. i += 8;
  31746. }
  31747. // handle remaing bits
  31748. if (i < loop2End) {
  31749. buf = buffer[bufferPos++];
  31750. mask = 128;
  31751. while (i < loop2End) {
  31752. output[i++] = +!!(buf & mask);
  31753. mask >>= 1;
  31754. }
  31755. }
  31756. }
  31757. } else {
  31758. // The general case that handles all other bpc values.
  31759. var bits = 0;
  31760. buf = 0;
  31761. for (i = 0, ii = length; i < ii; ++i) {
  31762. if (i % rowComps === 0) {
  31763. buf = 0;
  31764. bits = 0;
  31765. }
  31766. while (bits < bpc) {
  31767. buf = (buf << 8) | buffer[bufferPos++];
  31768. bits += 8;
  31769. }
  31770. var remainingBits = bits - bpc;
  31771. var value = buf >> remainingBits;
  31772. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  31773. buf = buf & ((1 << remainingBits) - 1);
  31774. bits = remainingBits;
  31775. }
  31776. }
  31777. return output;
  31778. },
  31779. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  31780. actualHeight, image) {
  31781. var smask = this.smask;
  31782. var mask = this.mask;
  31783. var alphaBuf, sw, sh, i, ii, j;
  31784. if (smask) {
  31785. sw = smask.width;
  31786. sh = smask.height;
  31787. alphaBuf = new Uint8Array(sw * sh);
  31788. smask.fillGrayBuffer(alphaBuf);
  31789. if (sw !== width || sh !== height) {
  31790. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  31791. height);
  31792. }
  31793. } else if (mask) {
  31794. if (mask instanceof PDFImage) {
  31795. sw = mask.width;
  31796. sh = mask.height;
  31797. alphaBuf = new Uint8Array(sw * sh);
  31798. mask.numComps = 1;
  31799. mask.fillGrayBuffer(alphaBuf);
  31800. // Need to invert values in rgbaBuf
  31801. for (i = 0, ii = sw * sh; i < ii; ++i) {
  31802. alphaBuf[i] = 255 - alphaBuf[i];
  31803. }
  31804. if (sw !== width || sh !== height) {
  31805. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  31806. height);
  31807. }
  31808. } else if (isArray(mask)) {
  31809. // Color key mask: if any of the compontents are outside the range
  31810. // then they should be painted.
  31811. alphaBuf = new Uint8Array(width * height);
  31812. var numComps = this.numComps;
  31813. for (i = 0, ii = width * height; i < ii; ++i) {
  31814. var opacity = 0;
  31815. var imageOffset = i * numComps;
  31816. for (j = 0; j < numComps; ++j) {
  31817. var color = image[imageOffset + j];
  31818. var maskOffset = j * 2;
  31819. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  31820. opacity = 255;
  31821. break;
  31822. }
  31823. }
  31824. alphaBuf[i] = opacity;
  31825. }
  31826. } else {
  31827. error('Unknown mask format.');
  31828. }
  31829. }
  31830. if (alphaBuf) {
  31831. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  31832. rgbaBuf[j] = alphaBuf[i];
  31833. }
  31834. } else {
  31835. // No mask.
  31836. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  31837. rgbaBuf[j] = 255;
  31838. }
  31839. }
  31840. },
  31841. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  31842. var matte = this.smask && this.smask.matte;
  31843. if (!matte) {
  31844. return;
  31845. }
  31846. var matteRgb = this.colorSpace.getRgb(matte, 0);
  31847. var matteR = matteRgb[0];
  31848. var matteG = matteRgb[1];
  31849. var matteB = matteRgb[2];
  31850. var length = width * height * 4;
  31851. var r, g, b;
  31852. for (var i = 0; i < length; i += 4) {
  31853. var alpha = buffer[i + 3];
  31854. if (alpha === 0) {
  31855. // according formula we have to get Infinity in all components
  31856. // making it white (typical paper color) should be okay
  31857. buffer[i] = 255;
  31858. buffer[i + 1] = 255;
  31859. buffer[i + 2] = 255;
  31860. continue;
  31861. }
  31862. var k = 255 / alpha;
  31863. r = (buffer[i] - matteR) * k + matteR;
  31864. g = (buffer[i + 1] - matteG) * k + matteG;
  31865. b = (buffer[i + 2] - matteB) * k + matteB;
  31866. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  31867. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  31868. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  31869. }
  31870. },
  31871. createImageData: function PDFImage_createImageData(forceRGBA) {
  31872. var drawWidth = this.drawWidth;
  31873. var drawHeight = this.drawHeight;
  31874. var imgData = { // other fields are filled in below
  31875. width: drawWidth,
  31876. height: drawHeight
  31877. };
  31878. var numComps = this.numComps;
  31879. var originalWidth = this.width;
  31880. var originalHeight = this.height;
  31881. var bpc = this.bpc;
  31882. // Rows start at byte boundary.
  31883. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  31884. var imgArray;
  31885. if (!forceRGBA) {
  31886. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  31887. // without any complications, we pass a same-sized copy to the main
  31888. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  31889. // of memory for many scanned documents. It's also much faster.
  31890. //
  31891. // Similarly, if it is a 24-bit-per pixel RGB image without any
  31892. // complications, we avoid expanding by 1.333x to RGBA form.
  31893. var kind;
  31894. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  31895. kind = ImageKind.GRAYSCALE_1BPP;
  31896. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  31897. !this.needsDecode) {
  31898. kind = ImageKind.RGB_24BPP;
  31899. }
  31900. if (kind && !this.smask && !this.mask &&
  31901. drawWidth === originalWidth && drawHeight === originalHeight) {
  31902. imgData.kind = kind;
  31903. imgArray = this.getImageBytes(originalHeight * rowBytes);
  31904. // If imgArray came from a DecodeStream, we're safe to transfer it
  31905. // (and thus neuter it) because it will constitute the entire
  31906. // DecodeStream's data. But if it came from a Stream, we need to
  31907. // copy it because it'll only be a portion of the Stream's data, and
  31908. // the rest will be read later on.
  31909. if (this.image instanceof DecodeStream) {
  31910. imgData.data = imgArray;
  31911. } else {
  31912. var newArray = new Uint8Array(imgArray.length);
  31913. newArray.set(imgArray);
  31914. imgData.data = newArray;
  31915. }
  31916. if (this.needsDecode) {
  31917. // Invert the buffer (which must be grayscale if we reached here).
  31918. assert(kind === ImageKind.GRAYSCALE_1BPP);
  31919. var buffer = imgData.data;
  31920. for (var i = 0, ii = buffer.length; i < ii; i++) {
  31921. buffer[i] ^= 0xff;
  31922. }
  31923. }
  31924. return imgData;
  31925. }
  31926. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  31927. (this.colorSpace.name === 'DeviceGray' ||
  31928. this.colorSpace.name === 'DeviceRGB' ||
  31929. this.colorSpace.name === 'DeviceCMYK')) {
  31930. imgData.kind = ImageKind.RGB_24BPP;
  31931. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  31932. drawWidth, drawHeight, true);
  31933. return imgData;
  31934. }
  31935. }
  31936. imgArray = this.getImageBytes(originalHeight * rowBytes);
  31937. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  31938. var actualHeight = 0 | (imgArray.length / rowBytes *
  31939. drawHeight / originalHeight);
  31940. var comps = this.getComponents(imgArray);
  31941. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  31942. // more compact RGB_24BPP form if allowable.
  31943. var alpha01, maybeUndoPreblend;
  31944. if (!forceRGBA && !this.smask && !this.mask) {
  31945. imgData.kind = ImageKind.RGB_24BPP;
  31946. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  31947. alpha01 = 0;
  31948. maybeUndoPreblend = false;
  31949. } else {
  31950. imgData.kind = ImageKind.RGBA_32BPP;
  31951. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  31952. alpha01 = 1;
  31953. maybeUndoPreblend = true;
  31954. // Color key masking (opacity) must be performed before decoding.
  31955. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  31956. comps);
  31957. }
  31958. if (this.needsDecode) {
  31959. this.decodeBuffer(comps);
  31960. }
  31961. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  31962. drawWidth, drawHeight, actualHeight, bpc, comps,
  31963. alpha01);
  31964. if (maybeUndoPreblend) {
  31965. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  31966. }
  31967. return imgData;
  31968. },
  31969. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  31970. var numComps = this.numComps;
  31971. if (numComps !== 1) {
  31972. error('Reading gray scale from a color image: ' + numComps);
  31973. }
  31974. var width = this.width;
  31975. var height = this.height;
  31976. var bpc = this.bpc;
  31977. // rows start at byte boundary
  31978. var rowBytes = (width * numComps * bpc + 7) >> 3;
  31979. var imgArray = this.getImageBytes(height * rowBytes);
  31980. var comps = this.getComponents(imgArray);
  31981. var i, length;
  31982. if (bpc === 1) {
  31983. // inline decoding (= inversion) for 1 bpc images
  31984. length = width * height;
  31985. if (this.needsDecode) {
  31986. // invert and scale to {0, 255}
  31987. for (i = 0; i < length; ++i) {
  31988. buffer[i] = (comps[i] - 1) & 255;
  31989. }
  31990. } else {
  31991. // scale to {0, 255}
  31992. for (i = 0; i < length; ++i) {
  31993. buffer[i] = (-comps[i]) & 255;
  31994. }
  31995. }
  31996. return;
  31997. }
  31998. if (this.needsDecode) {
  31999. this.decodeBuffer(comps);
  32000. }
  32001. length = width * height;
  32002. // we aren't using a colorspace so we need to scale the value
  32003. var scale = 255 / ((1 << bpc) - 1);
  32004. for (i = 0; i < length; ++i) {
  32005. buffer[i] = (scale * comps[i]) | 0;
  32006. }
  32007. },
  32008. getImageBytes: function PDFImage_getImageBytes(length,
  32009. drawWidth, drawHeight,
  32010. forceRGB) {
  32011. this.image.reset();
  32012. this.image.drawWidth = drawWidth || this.width;
  32013. this.image.drawHeight = drawHeight || this.height;
  32014. this.image.forceRGB = !!forceRGB;
  32015. return this.image.getBytes(length);
  32016. }
  32017. };
  32018. return PDFImage;
  32019. })();
  32020. // The Metrics object contains glyph widths (in glyph space units).
  32021. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  32022. // space unit corresponds to 1/1000th of text space unit.
  32023. var Metrics = {
  32024. 'Courier': 600,
  32025. 'Courier-Bold': 600,
  32026. 'Courier-BoldOblique': 600,
  32027. 'Courier-Oblique': 600,
  32028. 'Helvetica' : {
  32029. 'space': 278,
  32030. 'exclam': 278,
  32031. 'quotedbl': 355,
  32032. 'numbersign': 556,
  32033. 'dollar': 556,
  32034. 'percent': 889,
  32035. 'ampersand': 667,
  32036. 'quoteright': 222,
  32037. 'parenleft': 333,
  32038. 'parenright': 333,
  32039. 'asterisk': 389,
  32040. 'plus': 584,
  32041. 'comma': 278,
  32042. 'hyphen': 333,
  32043. 'period': 278,
  32044. 'slash': 278,
  32045. 'zero': 556,
  32046. 'one': 556,
  32047. 'two': 556,
  32048. 'three': 556,
  32049. 'four': 556,
  32050. 'five': 556,
  32051. 'six': 556,
  32052. 'seven': 556,
  32053. 'eight': 556,
  32054. 'nine': 556,
  32055. 'colon': 278,
  32056. 'semicolon': 278,
  32057. 'less': 584,
  32058. 'equal': 584,
  32059. 'greater': 584,
  32060. 'question': 556,
  32061. 'at': 1015,
  32062. 'A': 667,
  32063. 'B': 667,
  32064. 'C': 722,
  32065. 'D': 722,
  32066. 'E': 667,
  32067. 'F': 611,
  32068. 'G': 778,
  32069. 'H': 722,
  32070. 'I': 278,
  32071. 'J': 500,
  32072. 'K': 667,
  32073. 'L': 556,
  32074. 'M': 833,
  32075. 'N': 722,
  32076. 'O': 778,
  32077. 'P': 667,
  32078. 'Q': 778,
  32079. 'R': 722,
  32080. 'S': 667,
  32081. 'T': 611,
  32082. 'U': 722,
  32083. 'V': 667,
  32084. 'W': 944,
  32085. 'X': 667,
  32086. 'Y': 667,
  32087. 'Z': 611,
  32088. 'bracketleft': 278,
  32089. 'backslash': 278,
  32090. 'bracketright': 278,
  32091. 'asciicircum': 469,
  32092. 'underscore': 556,
  32093. 'quoteleft': 222,
  32094. 'a': 556,
  32095. 'b': 556,
  32096. 'c': 500,
  32097. 'd': 556,
  32098. 'e': 556,
  32099. 'f': 278,
  32100. 'g': 556,
  32101. 'h': 556,
  32102. 'i': 222,
  32103. 'j': 222,
  32104. 'k': 500,
  32105. 'l': 222,
  32106. 'm': 833,
  32107. 'n': 556,
  32108. 'o': 556,
  32109. 'p': 556,
  32110. 'q': 556,
  32111. 'r': 333,
  32112. 's': 500,
  32113. 't': 278,
  32114. 'u': 556,
  32115. 'v': 500,
  32116. 'w': 722,
  32117. 'x': 500,
  32118. 'y': 500,
  32119. 'z': 500,
  32120. 'braceleft': 334,
  32121. 'bar': 260,
  32122. 'braceright': 334,
  32123. 'asciitilde': 584,
  32124. 'exclamdown': 333,
  32125. 'cent': 556,
  32126. 'sterling': 556,
  32127. 'fraction': 167,
  32128. 'yen': 556,
  32129. 'florin': 556,
  32130. 'section': 556,
  32131. 'currency': 556,
  32132. 'quotesingle': 191,
  32133. 'quotedblleft': 333,
  32134. 'guillemotleft': 556,
  32135. 'guilsinglleft': 333,
  32136. 'guilsinglright': 333,
  32137. 'fi': 500,
  32138. 'fl': 500,
  32139. 'endash': 556,
  32140. 'dagger': 556,
  32141. 'daggerdbl': 556,
  32142. 'periodcentered': 278,
  32143. 'paragraph': 537,
  32144. 'bullet': 350,
  32145. 'quotesinglbase': 222,
  32146. 'quotedblbase': 333,
  32147. 'quotedblright': 333,
  32148. 'guillemotright': 556,
  32149. 'ellipsis': 1000,
  32150. 'perthousand': 1000,
  32151. 'questiondown': 611,
  32152. 'grave': 333,
  32153. 'acute': 333,
  32154. 'circumflex': 333,
  32155. 'tilde': 333,
  32156. 'macron': 333,
  32157. 'breve': 333,
  32158. 'dotaccent': 333,
  32159. 'dieresis': 333,
  32160. 'ring': 333,
  32161. 'cedilla': 333,
  32162. 'hungarumlaut': 333,
  32163. 'ogonek': 333,
  32164. 'caron': 333,
  32165. 'emdash': 1000,
  32166. 'AE': 1000,
  32167. 'ordfeminine': 370,
  32168. 'Lslash': 556,
  32169. 'Oslash': 778,
  32170. 'OE': 1000,
  32171. 'ordmasculine': 365,
  32172. 'ae': 889,
  32173. 'dotlessi': 278,
  32174. 'lslash': 222,
  32175. 'oslash': 611,
  32176. 'oe': 944,
  32177. 'germandbls': 611,
  32178. 'Idieresis': 278,
  32179. 'eacute': 556,
  32180. 'abreve': 556,
  32181. 'uhungarumlaut': 556,
  32182. 'ecaron': 556,
  32183. 'Ydieresis': 667,
  32184. 'divide': 584,
  32185. 'Yacute': 667,
  32186. 'Acircumflex': 667,
  32187. 'aacute': 556,
  32188. 'Ucircumflex': 722,
  32189. 'yacute': 500,
  32190. 'scommaaccent': 500,
  32191. 'ecircumflex': 556,
  32192. 'Uring': 722,
  32193. 'Udieresis': 722,
  32194. 'aogonek': 556,
  32195. 'Uacute': 722,
  32196. 'uogonek': 556,
  32197. 'Edieresis': 667,
  32198. 'Dcroat': 722,
  32199. 'commaaccent': 250,
  32200. 'copyright': 737,
  32201. 'Emacron': 667,
  32202. 'ccaron': 500,
  32203. 'aring': 556,
  32204. 'Ncommaaccent': 722,
  32205. 'lacute': 222,
  32206. 'agrave': 556,
  32207. 'Tcommaaccent': 611,
  32208. 'Cacute': 722,
  32209. 'atilde': 556,
  32210. 'Edotaccent': 667,
  32211. 'scaron': 500,
  32212. 'scedilla': 500,
  32213. 'iacute': 278,
  32214. 'lozenge': 471,
  32215. 'Rcaron': 722,
  32216. 'Gcommaaccent': 778,
  32217. 'ucircumflex': 556,
  32218. 'acircumflex': 556,
  32219. 'Amacron': 667,
  32220. 'rcaron': 333,
  32221. 'ccedilla': 500,
  32222. 'Zdotaccent': 611,
  32223. 'Thorn': 667,
  32224. 'Omacron': 778,
  32225. 'Racute': 722,
  32226. 'Sacute': 667,
  32227. 'dcaron': 643,
  32228. 'Umacron': 722,
  32229. 'uring': 556,
  32230. 'threesuperior': 333,
  32231. 'Ograve': 778,
  32232. 'Agrave': 667,
  32233. 'Abreve': 667,
  32234. 'multiply': 584,
  32235. 'uacute': 556,
  32236. 'Tcaron': 611,
  32237. 'partialdiff': 476,
  32238. 'ydieresis': 500,
  32239. 'Nacute': 722,
  32240. 'icircumflex': 278,
  32241. 'Ecircumflex': 667,
  32242. 'adieresis': 556,
  32243. 'edieresis': 556,
  32244. 'cacute': 500,
  32245. 'nacute': 556,
  32246. 'umacron': 556,
  32247. 'Ncaron': 722,
  32248. 'Iacute': 278,
  32249. 'plusminus': 584,
  32250. 'brokenbar': 260,
  32251. 'registered': 737,
  32252. 'Gbreve': 778,
  32253. 'Idotaccent': 278,
  32254. 'summation': 600,
  32255. 'Egrave': 667,
  32256. 'racute': 333,
  32257. 'omacron': 556,
  32258. 'Zacute': 611,
  32259. 'Zcaron': 611,
  32260. 'greaterequal': 549,
  32261. 'Eth': 722,
  32262. 'Ccedilla': 722,
  32263. 'lcommaaccent': 222,
  32264. 'tcaron': 317,
  32265. 'eogonek': 556,
  32266. 'Uogonek': 722,
  32267. 'Aacute': 667,
  32268. 'Adieresis': 667,
  32269. 'egrave': 556,
  32270. 'zacute': 500,
  32271. 'iogonek': 222,
  32272. 'Oacute': 778,
  32273. 'oacute': 556,
  32274. 'amacron': 556,
  32275. 'sacute': 500,
  32276. 'idieresis': 278,
  32277. 'Ocircumflex': 778,
  32278. 'Ugrave': 722,
  32279. 'Delta': 612,
  32280. 'thorn': 556,
  32281. 'twosuperior': 333,
  32282. 'Odieresis': 778,
  32283. 'mu': 556,
  32284. 'igrave': 278,
  32285. 'ohungarumlaut': 556,
  32286. 'Eogonek': 667,
  32287. 'dcroat': 556,
  32288. 'threequarters': 834,
  32289. 'Scedilla': 667,
  32290. 'lcaron': 299,
  32291. 'Kcommaaccent': 667,
  32292. 'Lacute': 556,
  32293. 'trademark': 1000,
  32294. 'edotaccent': 556,
  32295. 'Igrave': 278,
  32296. 'Imacron': 278,
  32297. 'Lcaron': 556,
  32298. 'onehalf': 834,
  32299. 'lessequal': 549,
  32300. 'ocircumflex': 556,
  32301. 'ntilde': 556,
  32302. 'Uhungarumlaut': 722,
  32303. 'Eacute': 667,
  32304. 'emacron': 556,
  32305. 'gbreve': 556,
  32306. 'onequarter': 834,
  32307. 'Scaron': 667,
  32308. 'Scommaaccent': 667,
  32309. 'Ohungarumlaut': 778,
  32310. 'degree': 400,
  32311. 'ograve': 556,
  32312. 'Ccaron': 722,
  32313. 'ugrave': 556,
  32314. 'radical': 453,
  32315. 'Dcaron': 722,
  32316. 'rcommaaccent': 333,
  32317. 'Ntilde': 722,
  32318. 'otilde': 556,
  32319. 'Rcommaaccent': 722,
  32320. 'Lcommaaccent': 556,
  32321. 'Atilde': 667,
  32322. 'Aogonek': 667,
  32323. 'Aring': 667,
  32324. 'Otilde': 778,
  32325. 'zdotaccent': 500,
  32326. 'Ecaron': 667,
  32327. 'Iogonek': 278,
  32328. 'kcommaaccent': 500,
  32329. 'minus': 584,
  32330. 'Icircumflex': 278,
  32331. 'ncaron': 556,
  32332. 'tcommaaccent': 278,
  32333. 'logicalnot': 584,
  32334. 'odieresis': 556,
  32335. 'udieresis': 556,
  32336. 'notequal': 549,
  32337. 'gcommaaccent': 556,
  32338. 'eth': 556,
  32339. 'zcaron': 500,
  32340. 'ncommaaccent': 556,
  32341. 'onesuperior': 333,
  32342. 'imacron': 278,
  32343. 'Euro': 556
  32344. },
  32345. 'Helvetica-Bold': {
  32346. 'space': 278,
  32347. 'exclam': 333,
  32348. 'quotedbl': 474,
  32349. 'numbersign': 556,
  32350. 'dollar': 556,
  32351. 'percent': 889,
  32352. 'ampersand': 722,
  32353. 'quoteright': 278,
  32354. 'parenleft': 333,
  32355. 'parenright': 333,
  32356. 'asterisk': 389,
  32357. 'plus': 584,
  32358. 'comma': 278,
  32359. 'hyphen': 333,
  32360. 'period': 278,
  32361. 'slash': 278,
  32362. 'zero': 556,
  32363. 'one': 556,
  32364. 'two': 556,
  32365. 'three': 556,
  32366. 'four': 556,
  32367. 'five': 556,
  32368. 'six': 556,
  32369. 'seven': 556,
  32370. 'eight': 556,
  32371. 'nine': 556,
  32372. 'colon': 333,
  32373. 'semicolon': 333,
  32374. 'less': 584,
  32375. 'equal': 584,
  32376. 'greater': 584,
  32377. 'question': 611,
  32378. 'at': 975,
  32379. 'A': 722,
  32380. 'B': 722,
  32381. 'C': 722,
  32382. 'D': 722,
  32383. 'E': 667,
  32384. 'F': 611,
  32385. 'G': 778,
  32386. 'H': 722,
  32387. 'I': 278,
  32388. 'J': 556,
  32389. 'K': 722,
  32390. 'L': 611,
  32391. 'M': 833,
  32392. 'N': 722,
  32393. 'O': 778,
  32394. 'P': 667,
  32395. 'Q': 778,
  32396. 'R': 722,
  32397. 'S': 667,
  32398. 'T': 611,
  32399. 'U': 722,
  32400. 'V': 667,
  32401. 'W': 944,
  32402. 'X': 667,
  32403. 'Y': 667,
  32404. 'Z': 611,
  32405. 'bracketleft': 333,
  32406. 'backslash': 278,
  32407. 'bracketright': 333,
  32408. 'asciicircum': 584,
  32409. 'underscore': 556,
  32410. 'quoteleft': 278,
  32411. 'a': 556,
  32412. 'b': 611,
  32413. 'c': 556,
  32414. 'd': 611,
  32415. 'e': 556,
  32416. 'f': 333,
  32417. 'g': 611,
  32418. 'h': 611,
  32419. 'i': 278,
  32420. 'j': 278,
  32421. 'k': 556,
  32422. 'l': 278,
  32423. 'm': 889,
  32424. 'n': 611,
  32425. 'o': 611,
  32426. 'p': 611,
  32427. 'q': 611,
  32428. 'r': 389,
  32429. 's': 556,
  32430. 't': 333,
  32431. 'u': 611,
  32432. 'v': 556,
  32433. 'w': 778,
  32434. 'x': 556,
  32435. 'y': 556,
  32436. 'z': 500,
  32437. 'braceleft': 389,
  32438. 'bar': 280,
  32439. 'braceright': 389,
  32440. 'asciitilde': 584,
  32441. 'exclamdown': 333,
  32442. 'cent': 556,
  32443. 'sterling': 556,
  32444. 'fraction': 167,
  32445. 'yen': 556,
  32446. 'florin': 556,
  32447. 'section': 556,
  32448. 'currency': 556,
  32449. 'quotesingle': 238,
  32450. 'quotedblleft': 500,
  32451. 'guillemotleft': 556,
  32452. 'guilsinglleft': 333,
  32453. 'guilsinglright': 333,
  32454. 'fi': 611,
  32455. 'fl': 611,
  32456. 'endash': 556,
  32457. 'dagger': 556,
  32458. 'daggerdbl': 556,
  32459. 'periodcentered': 278,
  32460. 'paragraph': 556,
  32461. 'bullet': 350,
  32462. 'quotesinglbase': 278,
  32463. 'quotedblbase': 500,
  32464. 'quotedblright': 500,
  32465. 'guillemotright': 556,
  32466. 'ellipsis': 1000,
  32467. 'perthousand': 1000,
  32468. 'questiondown': 611,
  32469. 'grave': 333,
  32470. 'acute': 333,
  32471. 'circumflex': 333,
  32472. 'tilde': 333,
  32473. 'macron': 333,
  32474. 'breve': 333,
  32475. 'dotaccent': 333,
  32476. 'dieresis': 333,
  32477. 'ring': 333,
  32478. 'cedilla': 333,
  32479. 'hungarumlaut': 333,
  32480. 'ogonek': 333,
  32481. 'caron': 333,
  32482. 'emdash': 1000,
  32483. 'AE': 1000,
  32484. 'ordfeminine': 370,
  32485. 'Lslash': 611,
  32486. 'Oslash': 778,
  32487. 'OE': 1000,
  32488. 'ordmasculine': 365,
  32489. 'ae': 889,
  32490. 'dotlessi': 278,
  32491. 'lslash': 278,
  32492. 'oslash': 611,
  32493. 'oe': 944,
  32494. 'germandbls': 611,
  32495. 'Idieresis': 278,
  32496. 'eacute': 556,
  32497. 'abreve': 556,
  32498. 'uhungarumlaut': 611,
  32499. 'ecaron': 556,
  32500. 'Ydieresis': 667,
  32501. 'divide': 584,
  32502. 'Yacute': 667,
  32503. 'Acircumflex': 722,
  32504. 'aacute': 556,
  32505. 'Ucircumflex': 722,
  32506. 'yacute': 556,
  32507. 'scommaaccent': 556,
  32508. 'ecircumflex': 556,
  32509. 'Uring': 722,
  32510. 'Udieresis': 722,
  32511. 'aogonek': 556,
  32512. 'Uacute': 722,
  32513. 'uogonek': 611,
  32514. 'Edieresis': 667,
  32515. 'Dcroat': 722,
  32516. 'commaaccent': 250,
  32517. 'copyright': 737,
  32518. 'Emacron': 667,
  32519. 'ccaron': 556,
  32520. 'aring': 556,
  32521. 'Ncommaaccent': 722,
  32522. 'lacute': 278,
  32523. 'agrave': 556,
  32524. 'Tcommaaccent': 611,
  32525. 'Cacute': 722,
  32526. 'atilde': 556,
  32527. 'Edotaccent': 667,
  32528. 'scaron': 556,
  32529. 'scedilla': 556,
  32530. 'iacute': 278,
  32531. 'lozenge': 494,
  32532. 'Rcaron': 722,
  32533. 'Gcommaaccent': 778,
  32534. 'ucircumflex': 611,
  32535. 'acircumflex': 556,
  32536. 'Amacron': 722,
  32537. 'rcaron': 389,
  32538. 'ccedilla': 556,
  32539. 'Zdotaccent': 611,
  32540. 'Thorn': 667,
  32541. 'Omacron': 778,
  32542. 'Racute': 722,
  32543. 'Sacute': 667,
  32544. 'dcaron': 743,
  32545. 'Umacron': 722,
  32546. 'uring': 611,
  32547. 'threesuperior': 333,
  32548. 'Ograve': 778,
  32549. 'Agrave': 722,
  32550. 'Abreve': 722,
  32551. 'multiply': 584,
  32552. 'uacute': 611,
  32553. 'Tcaron': 611,
  32554. 'partialdiff': 494,
  32555. 'ydieresis': 556,
  32556. 'Nacute': 722,
  32557. 'icircumflex': 278,
  32558. 'Ecircumflex': 667,
  32559. 'adieresis': 556,
  32560. 'edieresis': 556,
  32561. 'cacute': 556,
  32562. 'nacute': 611,
  32563. 'umacron': 611,
  32564. 'Ncaron': 722,
  32565. 'Iacute': 278,
  32566. 'plusminus': 584,
  32567. 'brokenbar': 280,
  32568. 'registered': 737,
  32569. 'Gbreve': 778,
  32570. 'Idotaccent': 278,
  32571. 'summation': 600,
  32572. 'Egrave': 667,
  32573. 'racute': 389,
  32574. 'omacron': 611,
  32575. 'Zacute': 611,
  32576. 'Zcaron': 611,
  32577. 'greaterequal': 549,
  32578. 'Eth': 722,
  32579. 'Ccedilla': 722,
  32580. 'lcommaaccent': 278,
  32581. 'tcaron': 389,
  32582. 'eogonek': 556,
  32583. 'Uogonek': 722,
  32584. 'Aacute': 722,
  32585. 'Adieresis': 722,
  32586. 'egrave': 556,
  32587. 'zacute': 500,
  32588. 'iogonek': 278,
  32589. 'Oacute': 778,
  32590. 'oacute': 611,
  32591. 'amacron': 556,
  32592. 'sacute': 556,
  32593. 'idieresis': 278,
  32594. 'Ocircumflex': 778,
  32595. 'Ugrave': 722,
  32596. 'Delta': 612,
  32597. 'thorn': 611,
  32598. 'twosuperior': 333,
  32599. 'Odieresis': 778,
  32600. 'mu': 611,
  32601. 'igrave': 278,
  32602. 'ohungarumlaut': 611,
  32603. 'Eogonek': 667,
  32604. 'dcroat': 611,
  32605. 'threequarters': 834,
  32606. 'Scedilla': 667,
  32607. 'lcaron': 400,
  32608. 'Kcommaaccent': 722,
  32609. 'Lacute': 611,
  32610. 'trademark': 1000,
  32611. 'edotaccent': 556,
  32612. 'Igrave': 278,
  32613. 'Imacron': 278,
  32614. 'Lcaron': 611,
  32615. 'onehalf': 834,
  32616. 'lessequal': 549,
  32617. 'ocircumflex': 611,
  32618. 'ntilde': 611,
  32619. 'Uhungarumlaut': 722,
  32620. 'Eacute': 667,
  32621. 'emacron': 556,
  32622. 'gbreve': 611,
  32623. 'onequarter': 834,
  32624. 'Scaron': 667,
  32625. 'Scommaaccent': 667,
  32626. 'Ohungarumlaut': 778,
  32627. 'degree': 400,
  32628. 'ograve': 611,
  32629. 'Ccaron': 722,
  32630. 'ugrave': 611,
  32631. 'radical': 549,
  32632. 'Dcaron': 722,
  32633. 'rcommaaccent': 389,
  32634. 'Ntilde': 722,
  32635. 'otilde': 611,
  32636. 'Rcommaaccent': 722,
  32637. 'Lcommaaccent': 611,
  32638. 'Atilde': 722,
  32639. 'Aogonek': 722,
  32640. 'Aring': 722,
  32641. 'Otilde': 778,
  32642. 'zdotaccent': 500,
  32643. 'Ecaron': 667,
  32644. 'Iogonek': 278,
  32645. 'kcommaaccent': 556,
  32646. 'minus': 584,
  32647. 'Icircumflex': 278,
  32648. 'ncaron': 611,
  32649. 'tcommaaccent': 333,
  32650. 'logicalnot': 584,
  32651. 'odieresis': 611,
  32652. 'udieresis': 611,
  32653. 'notequal': 549,
  32654. 'gcommaaccent': 611,
  32655. 'eth': 611,
  32656. 'zcaron': 500,
  32657. 'ncommaaccent': 611,
  32658. 'onesuperior': 333,
  32659. 'imacron': 278,
  32660. 'Euro': 556
  32661. },
  32662. 'Helvetica-BoldOblique': {
  32663. 'space': 278,
  32664. 'exclam': 333,
  32665. 'quotedbl': 474,
  32666. 'numbersign': 556,
  32667. 'dollar': 556,
  32668. 'percent': 889,
  32669. 'ampersand': 722,
  32670. 'quoteright': 278,
  32671. 'parenleft': 333,
  32672. 'parenright': 333,
  32673. 'asterisk': 389,
  32674. 'plus': 584,
  32675. 'comma': 278,
  32676. 'hyphen': 333,
  32677. 'period': 278,
  32678. 'slash': 278,
  32679. 'zero': 556,
  32680. 'one': 556,
  32681. 'two': 556,
  32682. 'three': 556,
  32683. 'four': 556,
  32684. 'five': 556,
  32685. 'six': 556,
  32686. 'seven': 556,
  32687. 'eight': 556,
  32688. 'nine': 556,
  32689. 'colon': 333,
  32690. 'semicolon': 333,
  32691. 'less': 584,
  32692. 'equal': 584,
  32693. 'greater': 584,
  32694. 'question': 611,
  32695. 'at': 975,
  32696. 'A': 722,
  32697. 'B': 722,
  32698. 'C': 722,
  32699. 'D': 722,
  32700. 'E': 667,
  32701. 'F': 611,
  32702. 'G': 778,
  32703. 'H': 722,
  32704. 'I': 278,
  32705. 'J': 556,
  32706. 'K': 722,
  32707. 'L': 611,
  32708. 'M': 833,
  32709. 'N': 722,
  32710. 'O': 778,
  32711. 'P': 667,
  32712. 'Q': 778,
  32713. 'R': 722,
  32714. 'S': 667,
  32715. 'T': 611,
  32716. 'U': 722,
  32717. 'V': 667,
  32718. 'W': 944,
  32719. 'X': 667,
  32720. 'Y': 667,
  32721. 'Z': 611,
  32722. 'bracketleft': 333,
  32723. 'backslash': 278,
  32724. 'bracketright': 333,
  32725. 'asciicircum': 584,
  32726. 'underscore': 556,
  32727. 'quoteleft': 278,
  32728. 'a': 556,
  32729. 'b': 611,
  32730. 'c': 556,
  32731. 'd': 611,
  32732. 'e': 556,
  32733. 'f': 333,
  32734. 'g': 611,
  32735. 'h': 611,
  32736. 'i': 278,
  32737. 'j': 278,
  32738. 'k': 556,
  32739. 'l': 278,
  32740. 'm': 889,
  32741. 'n': 611,
  32742. 'o': 611,
  32743. 'p': 611,
  32744. 'q': 611,
  32745. 'r': 389,
  32746. 's': 556,
  32747. 't': 333,
  32748. 'u': 611,
  32749. 'v': 556,
  32750. 'w': 778,
  32751. 'x': 556,
  32752. 'y': 556,
  32753. 'z': 500,
  32754. 'braceleft': 389,
  32755. 'bar': 280,
  32756. 'braceright': 389,
  32757. 'asciitilde': 584,
  32758. 'exclamdown': 333,
  32759. 'cent': 556,
  32760. 'sterling': 556,
  32761. 'fraction': 167,
  32762. 'yen': 556,
  32763. 'florin': 556,
  32764. 'section': 556,
  32765. 'currency': 556,
  32766. 'quotesingle': 238,
  32767. 'quotedblleft': 500,
  32768. 'guillemotleft': 556,
  32769. 'guilsinglleft': 333,
  32770. 'guilsinglright': 333,
  32771. 'fi': 611,
  32772. 'fl': 611,
  32773. 'endash': 556,
  32774. 'dagger': 556,
  32775. 'daggerdbl': 556,
  32776. 'periodcentered': 278,
  32777. 'paragraph': 556,
  32778. 'bullet': 350,
  32779. 'quotesinglbase': 278,
  32780. 'quotedblbase': 500,
  32781. 'quotedblright': 500,
  32782. 'guillemotright': 556,
  32783. 'ellipsis': 1000,
  32784. 'perthousand': 1000,
  32785. 'questiondown': 611,
  32786. 'grave': 333,
  32787. 'acute': 333,
  32788. 'circumflex': 333,
  32789. 'tilde': 333,
  32790. 'macron': 333,
  32791. 'breve': 333,
  32792. 'dotaccent': 333,
  32793. 'dieresis': 333,
  32794. 'ring': 333,
  32795. 'cedilla': 333,
  32796. 'hungarumlaut': 333,
  32797. 'ogonek': 333,
  32798. 'caron': 333,
  32799. 'emdash': 1000,
  32800. 'AE': 1000,
  32801. 'ordfeminine': 370,
  32802. 'Lslash': 611,
  32803. 'Oslash': 778,
  32804. 'OE': 1000,
  32805. 'ordmasculine': 365,
  32806. 'ae': 889,
  32807. 'dotlessi': 278,
  32808. 'lslash': 278,
  32809. 'oslash': 611,
  32810. 'oe': 944,
  32811. 'germandbls': 611,
  32812. 'Idieresis': 278,
  32813. 'eacute': 556,
  32814. 'abreve': 556,
  32815. 'uhungarumlaut': 611,
  32816. 'ecaron': 556,
  32817. 'Ydieresis': 667,
  32818. 'divide': 584,
  32819. 'Yacute': 667,
  32820. 'Acircumflex': 722,
  32821. 'aacute': 556,
  32822. 'Ucircumflex': 722,
  32823. 'yacute': 556,
  32824. 'scommaaccent': 556,
  32825. 'ecircumflex': 556,
  32826. 'Uring': 722,
  32827. 'Udieresis': 722,
  32828. 'aogonek': 556,
  32829. 'Uacute': 722,
  32830. 'uogonek': 611,
  32831. 'Edieresis': 667,
  32832. 'Dcroat': 722,
  32833. 'commaaccent': 250,
  32834. 'copyright': 737,
  32835. 'Emacron': 667,
  32836. 'ccaron': 556,
  32837. 'aring': 556,
  32838. 'Ncommaaccent': 722,
  32839. 'lacute': 278,
  32840. 'agrave': 556,
  32841. 'Tcommaaccent': 611,
  32842. 'Cacute': 722,
  32843. 'atilde': 556,
  32844. 'Edotaccent': 667,
  32845. 'scaron': 556,
  32846. 'scedilla': 556,
  32847. 'iacute': 278,
  32848. 'lozenge': 494,
  32849. 'Rcaron': 722,
  32850. 'Gcommaaccent': 778,
  32851. 'ucircumflex': 611,
  32852. 'acircumflex': 556,
  32853. 'Amacron': 722,
  32854. 'rcaron': 389,
  32855. 'ccedilla': 556,
  32856. 'Zdotaccent': 611,
  32857. 'Thorn': 667,
  32858. 'Omacron': 778,
  32859. 'Racute': 722,
  32860. 'Sacute': 667,
  32861. 'dcaron': 743,
  32862. 'Umacron': 722,
  32863. 'uring': 611,
  32864. 'threesuperior': 333,
  32865. 'Ograve': 778,
  32866. 'Agrave': 722,
  32867. 'Abreve': 722,
  32868. 'multiply': 584,
  32869. 'uacute': 611,
  32870. 'Tcaron': 611,
  32871. 'partialdiff': 494,
  32872. 'ydieresis': 556,
  32873. 'Nacute': 722,
  32874. 'icircumflex': 278,
  32875. 'Ecircumflex': 667,
  32876. 'adieresis': 556,
  32877. 'edieresis': 556,
  32878. 'cacute': 556,
  32879. 'nacute': 611,
  32880. 'umacron': 611,
  32881. 'Ncaron': 722,
  32882. 'Iacute': 278,
  32883. 'plusminus': 584,
  32884. 'brokenbar': 280,
  32885. 'registered': 737,
  32886. 'Gbreve': 778,
  32887. 'Idotaccent': 278,
  32888. 'summation': 600,
  32889. 'Egrave': 667,
  32890. 'racute': 389,
  32891. 'omacron': 611,
  32892. 'Zacute': 611,
  32893. 'Zcaron': 611,
  32894. 'greaterequal': 549,
  32895. 'Eth': 722,
  32896. 'Ccedilla': 722,
  32897. 'lcommaaccent': 278,
  32898. 'tcaron': 389,
  32899. 'eogonek': 556,
  32900. 'Uogonek': 722,
  32901. 'Aacute': 722,
  32902. 'Adieresis': 722,
  32903. 'egrave': 556,
  32904. 'zacute': 500,
  32905. 'iogonek': 278,
  32906. 'Oacute': 778,
  32907. 'oacute': 611,
  32908. 'amacron': 556,
  32909. 'sacute': 556,
  32910. 'idieresis': 278,
  32911. 'Ocircumflex': 778,
  32912. 'Ugrave': 722,
  32913. 'Delta': 612,
  32914. 'thorn': 611,
  32915. 'twosuperior': 333,
  32916. 'Odieresis': 778,
  32917. 'mu': 611,
  32918. 'igrave': 278,
  32919. 'ohungarumlaut': 611,
  32920. 'Eogonek': 667,
  32921. 'dcroat': 611,
  32922. 'threequarters': 834,
  32923. 'Scedilla': 667,
  32924. 'lcaron': 400,
  32925. 'Kcommaaccent': 722,
  32926. 'Lacute': 611,
  32927. 'trademark': 1000,
  32928. 'edotaccent': 556,
  32929. 'Igrave': 278,
  32930. 'Imacron': 278,
  32931. 'Lcaron': 611,
  32932. 'onehalf': 834,
  32933. 'lessequal': 549,
  32934. 'ocircumflex': 611,
  32935. 'ntilde': 611,
  32936. 'Uhungarumlaut': 722,
  32937. 'Eacute': 667,
  32938. 'emacron': 556,
  32939. 'gbreve': 611,
  32940. 'onequarter': 834,
  32941. 'Scaron': 667,
  32942. 'Scommaaccent': 667,
  32943. 'Ohungarumlaut': 778,
  32944. 'degree': 400,
  32945. 'ograve': 611,
  32946. 'Ccaron': 722,
  32947. 'ugrave': 611,
  32948. 'radical': 549,
  32949. 'Dcaron': 722,
  32950. 'rcommaaccent': 389,
  32951. 'Ntilde': 722,
  32952. 'otilde': 611,
  32953. 'Rcommaaccent': 722,
  32954. 'Lcommaaccent': 611,
  32955. 'Atilde': 722,
  32956. 'Aogonek': 722,
  32957. 'Aring': 722,
  32958. 'Otilde': 778,
  32959. 'zdotaccent': 500,
  32960. 'Ecaron': 667,
  32961. 'Iogonek': 278,
  32962. 'kcommaaccent': 556,
  32963. 'minus': 584,
  32964. 'Icircumflex': 278,
  32965. 'ncaron': 611,
  32966. 'tcommaaccent': 333,
  32967. 'logicalnot': 584,
  32968. 'odieresis': 611,
  32969. 'udieresis': 611,
  32970. 'notequal': 549,
  32971. 'gcommaaccent': 611,
  32972. 'eth': 611,
  32973. 'zcaron': 500,
  32974. 'ncommaaccent': 611,
  32975. 'onesuperior': 333,
  32976. 'imacron': 278,
  32977. 'Euro': 556
  32978. },
  32979. 'Helvetica-Oblique' : {
  32980. 'space': 278,
  32981. 'exclam': 278,
  32982. 'quotedbl': 355,
  32983. 'numbersign': 556,
  32984. 'dollar': 556,
  32985. 'percent': 889,
  32986. 'ampersand': 667,
  32987. 'quoteright': 222,
  32988. 'parenleft': 333,
  32989. 'parenright': 333,
  32990. 'asterisk': 389,
  32991. 'plus': 584,
  32992. 'comma': 278,
  32993. 'hyphen': 333,
  32994. 'period': 278,
  32995. 'slash': 278,
  32996. 'zero': 556,
  32997. 'one': 556,
  32998. 'two': 556,
  32999. 'three': 556,
  33000. 'four': 556,
  33001. 'five': 556,
  33002. 'six': 556,
  33003. 'seven': 556,
  33004. 'eight': 556,
  33005. 'nine': 556,
  33006. 'colon': 278,
  33007. 'semicolon': 278,
  33008. 'less': 584,
  33009. 'equal': 584,
  33010. 'greater': 584,
  33011. 'question': 556,
  33012. 'at': 1015,
  33013. 'A': 667,
  33014. 'B': 667,
  33015. 'C': 722,
  33016. 'D': 722,
  33017. 'E': 667,
  33018. 'F': 611,
  33019. 'G': 778,
  33020. 'H': 722,
  33021. 'I': 278,
  33022. 'J': 500,
  33023. 'K': 667,
  33024. 'L': 556,
  33025. 'M': 833,
  33026. 'N': 722,
  33027. 'O': 778,
  33028. 'P': 667,
  33029. 'Q': 778,
  33030. 'R': 722,
  33031. 'S': 667,
  33032. 'T': 611,
  33033. 'U': 722,
  33034. 'V': 667,
  33035. 'W': 944,
  33036. 'X': 667,
  33037. 'Y': 667,
  33038. 'Z': 611,
  33039. 'bracketleft': 278,
  33040. 'backslash': 278,
  33041. 'bracketright': 278,
  33042. 'asciicircum': 469,
  33043. 'underscore': 556,
  33044. 'quoteleft': 222,
  33045. 'a': 556,
  33046. 'b': 556,
  33047. 'c': 500,
  33048. 'd': 556,
  33049. 'e': 556,
  33050. 'f': 278,
  33051. 'g': 556,
  33052. 'h': 556,
  33053. 'i': 222,
  33054. 'j': 222,
  33055. 'k': 500,
  33056. 'l': 222,
  33057. 'm': 833,
  33058. 'n': 556,
  33059. 'o': 556,
  33060. 'p': 556,
  33061. 'q': 556,
  33062. 'r': 333,
  33063. 's': 500,
  33064. 't': 278,
  33065. 'u': 556,
  33066. 'v': 500,
  33067. 'w': 722,
  33068. 'x': 500,
  33069. 'y': 500,
  33070. 'z': 500,
  33071. 'braceleft': 334,
  33072. 'bar': 260,
  33073. 'braceright': 334,
  33074. 'asciitilde': 584,
  33075. 'exclamdown': 333,
  33076. 'cent': 556,
  33077. 'sterling': 556,
  33078. 'fraction': 167,
  33079. 'yen': 556,
  33080. 'florin': 556,
  33081. 'section': 556,
  33082. 'currency': 556,
  33083. 'quotesingle': 191,
  33084. 'quotedblleft': 333,
  33085. 'guillemotleft': 556,
  33086. 'guilsinglleft': 333,
  33087. 'guilsinglright': 333,
  33088. 'fi': 500,
  33089. 'fl': 500,
  33090. 'endash': 556,
  33091. 'dagger': 556,
  33092. 'daggerdbl': 556,
  33093. 'periodcentered': 278,
  33094. 'paragraph': 537,
  33095. 'bullet': 350,
  33096. 'quotesinglbase': 222,
  33097. 'quotedblbase': 333,
  33098. 'quotedblright': 333,
  33099. 'guillemotright': 556,
  33100. 'ellipsis': 1000,
  33101. 'perthousand': 1000,
  33102. 'questiondown': 611,
  33103. 'grave': 333,
  33104. 'acute': 333,
  33105. 'circumflex': 333,
  33106. 'tilde': 333,
  33107. 'macron': 333,
  33108. 'breve': 333,
  33109. 'dotaccent': 333,
  33110. 'dieresis': 333,
  33111. 'ring': 333,
  33112. 'cedilla': 333,
  33113. 'hungarumlaut': 333,
  33114. 'ogonek': 333,
  33115. 'caron': 333,
  33116. 'emdash': 1000,
  33117. 'AE': 1000,
  33118. 'ordfeminine': 370,
  33119. 'Lslash': 556,
  33120. 'Oslash': 778,
  33121. 'OE': 1000,
  33122. 'ordmasculine': 365,
  33123. 'ae': 889,
  33124. 'dotlessi': 278,
  33125. 'lslash': 222,
  33126. 'oslash': 611,
  33127. 'oe': 944,
  33128. 'germandbls': 611,
  33129. 'Idieresis': 278,
  33130. 'eacute': 556,
  33131. 'abreve': 556,
  33132. 'uhungarumlaut': 556,
  33133. 'ecaron': 556,
  33134. 'Ydieresis': 667,
  33135. 'divide': 584,
  33136. 'Yacute': 667,
  33137. 'Acircumflex': 667,
  33138. 'aacute': 556,
  33139. 'Ucircumflex': 722,
  33140. 'yacute': 500,
  33141. 'scommaaccent': 500,
  33142. 'ecircumflex': 556,
  33143. 'Uring': 722,
  33144. 'Udieresis': 722,
  33145. 'aogonek': 556,
  33146. 'Uacute': 722,
  33147. 'uogonek': 556,
  33148. 'Edieresis': 667,
  33149. 'Dcroat': 722,
  33150. 'commaaccent': 250,
  33151. 'copyright': 737,
  33152. 'Emacron': 667,
  33153. 'ccaron': 500,
  33154. 'aring': 556,
  33155. 'Ncommaaccent': 722,
  33156. 'lacute': 222,
  33157. 'agrave': 556,
  33158. 'Tcommaaccent': 611,
  33159. 'Cacute': 722,
  33160. 'atilde': 556,
  33161. 'Edotaccent': 667,
  33162. 'scaron': 500,
  33163. 'scedilla': 500,
  33164. 'iacute': 278,
  33165. 'lozenge': 471,
  33166. 'Rcaron': 722,
  33167. 'Gcommaaccent': 778,
  33168. 'ucircumflex': 556,
  33169. 'acircumflex': 556,
  33170. 'Amacron': 667,
  33171. 'rcaron': 333,
  33172. 'ccedilla': 500,
  33173. 'Zdotaccent': 611,
  33174. 'Thorn': 667,
  33175. 'Omacron': 778,
  33176. 'Racute': 722,
  33177. 'Sacute': 667,
  33178. 'dcaron': 643,
  33179. 'Umacron': 722,
  33180. 'uring': 556,
  33181. 'threesuperior': 333,
  33182. 'Ograve': 778,
  33183. 'Agrave': 667,
  33184. 'Abreve': 667,
  33185. 'multiply': 584,
  33186. 'uacute': 556,
  33187. 'Tcaron': 611,
  33188. 'partialdiff': 476,
  33189. 'ydieresis': 500,
  33190. 'Nacute': 722,
  33191. 'icircumflex': 278,
  33192. 'Ecircumflex': 667,
  33193. 'adieresis': 556,
  33194. 'edieresis': 556,
  33195. 'cacute': 500,
  33196. 'nacute': 556,
  33197. 'umacron': 556,
  33198. 'Ncaron': 722,
  33199. 'Iacute': 278,
  33200. 'plusminus': 584,
  33201. 'brokenbar': 260,
  33202. 'registered': 737,
  33203. 'Gbreve': 778,
  33204. 'Idotaccent': 278,
  33205. 'summation': 600,
  33206. 'Egrave': 667,
  33207. 'racute': 333,
  33208. 'omacron': 556,
  33209. 'Zacute': 611,
  33210. 'Zcaron': 611,
  33211. 'greaterequal': 549,
  33212. 'Eth': 722,
  33213. 'Ccedilla': 722,
  33214. 'lcommaaccent': 222,
  33215. 'tcaron': 317,
  33216. 'eogonek': 556,
  33217. 'Uogonek': 722,
  33218. 'Aacute': 667,
  33219. 'Adieresis': 667,
  33220. 'egrave': 556,
  33221. 'zacute': 500,
  33222. 'iogonek': 222,
  33223. 'Oacute': 778,
  33224. 'oacute': 556,
  33225. 'amacron': 556,
  33226. 'sacute': 500,
  33227. 'idieresis': 278,
  33228. 'Ocircumflex': 778,
  33229. 'Ugrave': 722,
  33230. 'Delta': 612,
  33231. 'thorn': 556,
  33232. 'twosuperior': 333,
  33233. 'Odieresis': 778,
  33234. 'mu': 556,
  33235. 'igrave': 278,
  33236. 'ohungarumlaut': 556,
  33237. 'Eogonek': 667,
  33238. 'dcroat': 556,
  33239. 'threequarters': 834,
  33240. 'Scedilla': 667,
  33241. 'lcaron': 299,
  33242. 'Kcommaaccent': 667,
  33243. 'Lacute': 556,
  33244. 'trademark': 1000,
  33245. 'edotaccent': 556,
  33246. 'Igrave': 278,
  33247. 'Imacron': 278,
  33248. 'Lcaron': 556,
  33249. 'onehalf': 834,
  33250. 'lessequal': 549,
  33251. 'ocircumflex': 556,
  33252. 'ntilde': 556,
  33253. 'Uhungarumlaut': 722,
  33254. 'Eacute': 667,
  33255. 'emacron': 556,
  33256. 'gbreve': 556,
  33257. 'onequarter': 834,
  33258. 'Scaron': 667,
  33259. 'Scommaaccent': 667,
  33260. 'Ohungarumlaut': 778,
  33261. 'degree': 400,
  33262. 'ograve': 556,
  33263. 'Ccaron': 722,
  33264. 'ugrave': 556,
  33265. 'radical': 453,
  33266. 'Dcaron': 722,
  33267. 'rcommaaccent': 333,
  33268. 'Ntilde': 722,
  33269. 'otilde': 556,
  33270. 'Rcommaaccent': 722,
  33271. 'Lcommaaccent': 556,
  33272. 'Atilde': 667,
  33273. 'Aogonek': 667,
  33274. 'Aring': 667,
  33275. 'Otilde': 778,
  33276. 'zdotaccent': 500,
  33277. 'Ecaron': 667,
  33278. 'Iogonek': 278,
  33279. 'kcommaaccent': 500,
  33280. 'minus': 584,
  33281. 'Icircumflex': 278,
  33282. 'ncaron': 556,
  33283. 'tcommaaccent': 278,
  33284. 'logicalnot': 584,
  33285. 'odieresis': 556,
  33286. 'udieresis': 556,
  33287. 'notequal': 549,
  33288. 'gcommaaccent': 556,
  33289. 'eth': 556,
  33290. 'zcaron': 500,
  33291. 'ncommaaccent': 556,
  33292. 'onesuperior': 333,
  33293. 'imacron': 278,
  33294. 'Euro': 556
  33295. },
  33296. 'Symbol': {
  33297. 'space': 250,
  33298. 'exclam': 333,
  33299. 'universal': 713,
  33300. 'numbersign': 500,
  33301. 'existential': 549,
  33302. 'percent': 833,
  33303. 'ampersand': 778,
  33304. 'suchthat': 439,
  33305. 'parenleft': 333,
  33306. 'parenright': 333,
  33307. 'asteriskmath': 500,
  33308. 'plus': 549,
  33309. 'comma': 250,
  33310. 'minus': 549,
  33311. 'period': 250,
  33312. 'slash': 278,
  33313. 'zero': 500,
  33314. 'one': 500,
  33315. 'two': 500,
  33316. 'three': 500,
  33317. 'four': 500,
  33318. 'five': 500,
  33319. 'six': 500,
  33320. 'seven': 500,
  33321. 'eight': 500,
  33322. 'nine': 500,
  33323. 'colon': 278,
  33324. 'semicolon': 278,
  33325. 'less': 549,
  33326. 'equal': 549,
  33327. 'greater': 549,
  33328. 'question': 444,
  33329. 'congruent': 549,
  33330. 'Alpha': 722,
  33331. 'Beta': 667,
  33332. 'Chi': 722,
  33333. 'Delta': 612,
  33334. 'Epsilon': 611,
  33335. 'Phi': 763,
  33336. 'Gamma': 603,
  33337. 'Eta': 722,
  33338. 'Iota': 333,
  33339. 'theta1': 631,
  33340. 'Kappa': 722,
  33341. 'Lambda': 686,
  33342. 'Mu': 889,
  33343. 'Nu': 722,
  33344. 'Omicron': 722,
  33345. 'Pi': 768,
  33346. 'Theta': 741,
  33347. 'Rho': 556,
  33348. 'Sigma': 592,
  33349. 'Tau': 611,
  33350. 'Upsilon': 690,
  33351. 'sigma1': 439,
  33352. 'Omega': 768,
  33353. 'Xi': 645,
  33354. 'Psi': 795,
  33355. 'Zeta': 611,
  33356. 'bracketleft': 333,
  33357. 'therefore': 863,
  33358. 'bracketright': 333,
  33359. 'perpendicular': 658,
  33360. 'underscore': 500,
  33361. 'radicalex': 500,
  33362. 'alpha': 631,
  33363. 'beta': 549,
  33364. 'chi': 549,
  33365. 'delta': 494,
  33366. 'epsilon': 439,
  33367. 'phi': 521,
  33368. 'gamma': 411,
  33369. 'eta': 603,
  33370. 'iota': 329,
  33371. 'phi1': 603,
  33372. 'kappa': 549,
  33373. 'lambda': 549,
  33374. 'mu': 576,
  33375. 'nu': 521,
  33376. 'omicron': 549,
  33377. 'pi': 549,
  33378. 'theta': 521,
  33379. 'rho': 549,
  33380. 'sigma': 603,
  33381. 'tau': 439,
  33382. 'upsilon': 576,
  33383. 'omega1': 713,
  33384. 'omega': 686,
  33385. 'xi': 493,
  33386. 'psi': 686,
  33387. 'zeta': 494,
  33388. 'braceleft': 480,
  33389. 'bar': 200,
  33390. 'braceright': 480,
  33391. 'similar': 549,
  33392. 'Euro': 750,
  33393. 'Upsilon1': 620,
  33394. 'minute': 247,
  33395. 'lessequal': 549,
  33396. 'fraction': 167,
  33397. 'infinity': 713,
  33398. 'florin': 500,
  33399. 'club': 753,
  33400. 'diamond': 753,
  33401. 'heart': 753,
  33402. 'spade': 753,
  33403. 'arrowboth': 1042,
  33404. 'arrowleft': 987,
  33405. 'arrowup': 603,
  33406. 'arrowright': 987,
  33407. 'arrowdown': 603,
  33408. 'degree': 400,
  33409. 'plusminus': 549,
  33410. 'second': 411,
  33411. 'greaterequal': 549,
  33412. 'multiply': 549,
  33413. 'proportional': 713,
  33414. 'partialdiff': 494,
  33415. 'bullet': 460,
  33416. 'divide': 549,
  33417. 'notequal': 549,
  33418. 'equivalence': 549,
  33419. 'approxequal': 549,
  33420. 'ellipsis': 1000,
  33421. 'arrowvertex': 603,
  33422. 'arrowhorizex': 1000,
  33423. 'carriagereturn': 658,
  33424. 'aleph': 823,
  33425. 'Ifraktur': 686,
  33426. 'Rfraktur': 795,
  33427. 'weierstrass': 987,
  33428. 'circlemultiply': 768,
  33429. 'circleplus': 768,
  33430. 'emptyset': 823,
  33431. 'intersection': 768,
  33432. 'union': 768,
  33433. 'propersuperset': 713,
  33434. 'reflexsuperset': 713,
  33435. 'notsubset': 713,
  33436. 'propersubset': 713,
  33437. 'reflexsubset': 713,
  33438. 'element': 713,
  33439. 'notelement': 713,
  33440. 'angle': 768,
  33441. 'gradient': 713,
  33442. 'registerserif': 790,
  33443. 'copyrightserif': 790,
  33444. 'trademarkserif': 890,
  33445. 'product': 823,
  33446. 'radical': 549,
  33447. 'dotmath': 250,
  33448. 'logicalnot': 713,
  33449. 'logicaland': 603,
  33450. 'logicalor': 603,
  33451. 'arrowdblboth': 1042,
  33452. 'arrowdblleft': 987,
  33453. 'arrowdblup': 603,
  33454. 'arrowdblright': 987,
  33455. 'arrowdbldown': 603,
  33456. 'lozenge': 494,
  33457. 'angleleft': 329,
  33458. 'registersans': 790,
  33459. 'copyrightsans': 790,
  33460. 'trademarksans': 786,
  33461. 'summation': 713,
  33462. 'parenlefttp': 384,
  33463. 'parenleftex': 384,
  33464. 'parenleftbt': 384,
  33465. 'bracketlefttp': 384,
  33466. 'bracketleftex': 384,
  33467. 'bracketleftbt': 384,
  33468. 'bracelefttp': 494,
  33469. 'braceleftmid': 494,
  33470. 'braceleftbt': 494,
  33471. 'braceex': 494,
  33472. 'angleright': 329,
  33473. 'integral': 274,
  33474. 'integraltp': 686,
  33475. 'integralex': 686,
  33476. 'integralbt': 686,
  33477. 'parenrighttp': 384,
  33478. 'parenrightex': 384,
  33479. 'parenrightbt': 384,
  33480. 'bracketrighttp': 384,
  33481. 'bracketrightex': 384,
  33482. 'bracketrightbt': 384,
  33483. 'bracerighttp': 494,
  33484. 'bracerightmid': 494,
  33485. 'bracerightbt': 494,
  33486. 'apple': 790
  33487. },
  33488. 'Times-Roman': {
  33489. 'space': 250,
  33490. 'exclam': 333,
  33491. 'quotedbl': 408,
  33492. 'numbersign': 500,
  33493. 'dollar': 500,
  33494. 'percent': 833,
  33495. 'ampersand': 778,
  33496. 'quoteright': 333,
  33497. 'parenleft': 333,
  33498. 'parenright': 333,
  33499. 'asterisk': 500,
  33500. 'plus': 564,
  33501. 'comma': 250,
  33502. 'hyphen': 333,
  33503. 'period': 250,
  33504. 'slash': 278,
  33505. 'zero': 500,
  33506. 'one': 500,
  33507. 'two': 500,
  33508. 'three': 500,
  33509. 'four': 500,
  33510. 'five': 500,
  33511. 'six': 500,
  33512. 'seven': 500,
  33513. 'eight': 500,
  33514. 'nine': 500,
  33515. 'colon': 278,
  33516. 'semicolon': 278,
  33517. 'less': 564,
  33518. 'equal': 564,
  33519. 'greater': 564,
  33520. 'question': 444,
  33521. 'at': 921,
  33522. 'A': 722,
  33523. 'B': 667,
  33524. 'C': 667,
  33525. 'D': 722,
  33526. 'E': 611,
  33527. 'F': 556,
  33528. 'G': 722,
  33529. 'H': 722,
  33530. 'I': 333,
  33531. 'J': 389,
  33532. 'K': 722,
  33533. 'L': 611,
  33534. 'M': 889,
  33535. 'N': 722,
  33536. 'O': 722,
  33537. 'P': 556,
  33538. 'Q': 722,
  33539. 'R': 667,
  33540. 'S': 556,
  33541. 'T': 611,
  33542. 'U': 722,
  33543. 'V': 722,
  33544. 'W': 944,
  33545. 'X': 722,
  33546. 'Y': 722,
  33547. 'Z': 611,
  33548. 'bracketleft': 333,
  33549. 'backslash': 278,
  33550. 'bracketright': 333,
  33551. 'asciicircum': 469,
  33552. 'underscore': 500,
  33553. 'quoteleft': 333,
  33554. 'a': 444,
  33555. 'b': 500,
  33556. 'c': 444,
  33557. 'd': 500,
  33558. 'e': 444,
  33559. 'f': 333,
  33560. 'g': 500,
  33561. 'h': 500,
  33562. 'i': 278,
  33563. 'j': 278,
  33564. 'k': 500,
  33565. 'l': 278,
  33566. 'm': 778,
  33567. 'n': 500,
  33568. 'o': 500,
  33569. 'p': 500,
  33570. 'q': 500,
  33571. 'r': 333,
  33572. 's': 389,
  33573. 't': 278,
  33574. 'u': 500,
  33575. 'v': 500,
  33576. 'w': 722,
  33577. 'x': 500,
  33578. 'y': 500,
  33579. 'z': 444,
  33580. 'braceleft': 480,
  33581. 'bar': 200,
  33582. 'braceright': 480,
  33583. 'asciitilde': 541,
  33584. 'exclamdown': 333,
  33585. 'cent': 500,
  33586. 'sterling': 500,
  33587. 'fraction': 167,
  33588. 'yen': 500,
  33589. 'florin': 500,
  33590. 'section': 500,
  33591. 'currency': 500,
  33592. 'quotesingle': 180,
  33593. 'quotedblleft': 444,
  33594. 'guillemotleft': 500,
  33595. 'guilsinglleft': 333,
  33596. 'guilsinglright': 333,
  33597. 'fi': 556,
  33598. 'fl': 556,
  33599. 'endash': 500,
  33600. 'dagger': 500,
  33601. 'daggerdbl': 500,
  33602. 'periodcentered': 250,
  33603. 'paragraph': 453,
  33604. 'bullet': 350,
  33605. 'quotesinglbase': 333,
  33606. 'quotedblbase': 444,
  33607. 'quotedblright': 444,
  33608. 'guillemotright': 500,
  33609. 'ellipsis': 1000,
  33610. 'perthousand': 1000,
  33611. 'questiondown': 444,
  33612. 'grave': 333,
  33613. 'acute': 333,
  33614. 'circumflex': 333,
  33615. 'tilde': 333,
  33616. 'macron': 333,
  33617. 'breve': 333,
  33618. 'dotaccent': 333,
  33619. 'dieresis': 333,
  33620. 'ring': 333,
  33621. 'cedilla': 333,
  33622. 'hungarumlaut': 333,
  33623. 'ogonek': 333,
  33624. 'caron': 333,
  33625. 'emdash': 1000,
  33626. 'AE': 889,
  33627. 'ordfeminine': 276,
  33628. 'Lslash': 611,
  33629. 'Oslash': 722,
  33630. 'OE': 889,
  33631. 'ordmasculine': 310,
  33632. 'ae': 667,
  33633. 'dotlessi': 278,
  33634. 'lslash': 278,
  33635. 'oslash': 500,
  33636. 'oe': 722,
  33637. 'germandbls': 500,
  33638. 'Idieresis': 333,
  33639. 'eacute': 444,
  33640. 'abreve': 444,
  33641. 'uhungarumlaut': 500,
  33642. 'ecaron': 444,
  33643. 'Ydieresis': 722,
  33644. 'divide': 564,
  33645. 'Yacute': 722,
  33646. 'Acircumflex': 722,
  33647. 'aacute': 444,
  33648. 'Ucircumflex': 722,
  33649. 'yacute': 500,
  33650. 'scommaaccent': 389,
  33651. 'ecircumflex': 444,
  33652. 'Uring': 722,
  33653. 'Udieresis': 722,
  33654. 'aogonek': 444,
  33655. 'Uacute': 722,
  33656. 'uogonek': 500,
  33657. 'Edieresis': 611,
  33658. 'Dcroat': 722,
  33659. 'commaaccent': 250,
  33660. 'copyright': 760,
  33661. 'Emacron': 611,
  33662. 'ccaron': 444,
  33663. 'aring': 444,
  33664. 'Ncommaaccent': 722,
  33665. 'lacute': 278,
  33666. 'agrave': 444,
  33667. 'Tcommaaccent': 611,
  33668. 'Cacute': 667,
  33669. 'atilde': 444,
  33670. 'Edotaccent': 611,
  33671. 'scaron': 389,
  33672. 'scedilla': 389,
  33673. 'iacute': 278,
  33674. 'lozenge': 471,
  33675. 'Rcaron': 667,
  33676. 'Gcommaaccent': 722,
  33677. 'ucircumflex': 500,
  33678. 'acircumflex': 444,
  33679. 'Amacron': 722,
  33680. 'rcaron': 333,
  33681. 'ccedilla': 444,
  33682. 'Zdotaccent': 611,
  33683. 'Thorn': 556,
  33684. 'Omacron': 722,
  33685. 'Racute': 667,
  33686. 'Sacute': 556,
  33687. 'dcaron': 588,
  33688. 'Umacron': 722,
  33689. 'uring': 500,
  33690. 'threesuperior': 300,
  33691. 'Ograve': 722,
  33692. 'Agrave': 722,
  33693. 'Abreve': 722,
  33694. 'multiply': 564,
  33695. 'uacute': 500,
  33696. 'Tcaron': 611,
  33697. 'partialdiff': 476,
  33698. 'ydieresis': 500,
  33699. 'Nacute': 722,
  33700. 'icircumflex': 278,
  33701. 'Ecircumflex': 611,
  33702. 'adieresis': 444,
  33703. 'edieresis': 444,
  33704. 'cacute': 444,
  33705. 'nacute': 500,
  33706. 'umacron': 500,
  33707. 'Ncaron': 722,
  33708. 'Iacute': 333,
  33709. 'plusminus': 564,
  33710. 'brokenbar': 200,
  33711. 'registered': 760,
  33712. 'Gbreve': 722,
  33713. 'Idotaccent': 333,
  33714. 'summation': 600,
  33715. 'Egrave': 611,
  33716. 'racute': 333,
  33717. 'omacron': 500,
  33718. 'Zacute': 611,
  33719. 'Zcaron': 611,
  33720. 'greaterequal': 549,
  33721. 'Eth': 722,
  33722. 'Ccedilla': 667,
  33723. 'lcommaaccent': 278,
  33724. 'tcaron': 326,
  33725. 'eogonek': 444,
  33726. 'Uogonek': 722,
  33727. 'Aacute': 722,
  33728. 'Adieresis': 722,
  33729. 'egrave': 444,
  33730. 'zacute': 444,
  33731. 'iogonek': 278,
  33732. 'Oacute': 722,
  33733. 'oacute': 500,
  33734. 'amacron': 444,
  33735. 'sacute': 389,
  33736. 'idieresis': 278,
  33737. 'Ocircumflex': 722,
  33738. 'Ugrave': 722,
  33739. 'Delta': 612,
  33740. 'thorn': 500,
  33741. 'twosuperior': 300,
  33742. 'Odieresis': 722,
  33743. 'mu': 500,
  33744. 'igrave': 278,
  33745. 'ohungarumlaut': 500,
  33746. 'Eogonek': 611,
  33747. 'dcroat': 500,
  33748. 'threequarters': 750,
  33749. 'Scedilla': 556,
  33750. 'lcaron': 344,
  33751. 'Kcommaaccent': 722,
  33752. 'Lacute': 611,
  33753. 'trademark': 980,
  33754. 'edotaccent': 444,
  33755. 'Igrave': 333,
  33756. 'Imacron': 333,
  33757. 'Lcaron': 611,
  33758. 'onehalf': 750,
  33759. 'lessequal': 549,
  33760. 'ocircumflex': 500,
  33761. 'ntilde': 500,
  33762. 'Uhungarumlaut': 722,
  33763. 'Eacute': 611,
  33764. 'emacron': 444,
  33765. 'gbreve': 500,
  33766. 'onequarter': 750,
  33767. 'Scaron': 556,
  33768. 'Scommaaccent': 556,
  33769. 'Ohungarumlaut': 722,
  33770. 'degree': 400,
  33771. 'ograve': 500,
  33772. 'Ccaron': 667,
  33773. 'ugrave': 500,
  33774. 'radical': 453,
  33775. 'Dcaron': 722,
  33776. 'rcommaaccent': 333,
  33777. 'Ntilde': 722,
  33778. 'otilde': 500,
  33779. 'Rcommaaccent': 667,
  33780. 'Lcommaaccent': 611,
  33781. 'Atilde': 722,
  33782. 'Aogonek': 722,
  33783. 'Aring': 722,
  33784. 'Otilde': 722,
  33785. 'zdotaccent': 444,
  33786. 'Ecaron': 611,
  33787. 'Iogonek': 333,
  33788. 'kcommaaccent': 500,
  33789. 'minus': 564,
  33790. 'Icircumflex': 333,
  33791. 'ncaron': 500,
  33792. 'tcommaaccent': 278,
  33793. 'logicalnot': 564,
  33794. 'odieresis': 500,
  33795. 'udieresis': 500,
  33796. 'notequal': 549,
  33797. 'gcommaaccent': 500,
  33798. 'eth': 500,
  33799. 'zcaron': 444,
  33800. 'ncommaaccent': 500,
  33801. 'onesuperior': 300,
  33802. 'imacron': 278,
  33803. 'Euro': 500
  33804. },
  33805. 'Times-Bold': {
  33806. 'space': 250,
  33807. 'exclam': 333,
  33808. 'quotedbl': 555,
  33809. 'numbersign': 500,
  33810. 'dollar': 500,
  33811. 'percent': 1000,
  33812. 'ampersand': 833,
  33813. 'quoteright': 333,
  33814. 'parenleft': 333,
  33815. 'parenright': 333,
  33816. 'asterisk': 500,
  33817. 'plus': 570,
  33818. 'comma': 250,
  33819. 'hyphen': 333,
  33820. 'period': 250,
  33821. 'slash': 278,
  33822. 'zero': 500,
  33823. 'one': 500,
  33824. 'two': 500,
  33825. 'three': 500,
  33826. 'four': 500,
  33827. 'five': 500,
  33828. 'six': 500,
  33829. 'seven': 500,
  33830. 'eight': 500,
  33831. 'nine': 500,
  33832. 'colon': 333,
  33833. 'semicolon': 333,
  33834. 'less': 570,
  33835. 'equal': 570,
  33836. 'greater': 570,
  33837. 'question': 500,
  33838. 'at': 930,
  33839. 'A': 722,
  33840. 'B': 667,
  33841. 'C': 722,
  33842. 'D': 722,
  33843. 'E': 667,
  33844. 'F': 611,
  33845. 'G': 778,
  33846. 'H': 778,
  33847. 'I': 389,
  33848. 'J': 500,
  33849. 'K': 778,
  33850. 'L': 667,
  33851. 'M': 944,
  33852. 'N': 722,
  33853. 'O': 778,
  33854. 'P': 611,
  33855. 'Q': 778,
  33856. 'R': 722,
  33857. 'S': 556,
  33858. 'T': 667,
  33859. 'U': 722,
  33860. 'V': 722,
  33861. 'W': 1000,
  33862. 'X': 722,
  33863. 'Y': 722,
  33864. 'Z': 667,
  33865. 'bracketleft': 333,
  33866. 'backslash': 278,
  33867. 'bracketright': 333,
  33868. 'asciicircum': 581,
  33869. 'underscore': 500,
  33870. 'quoteleft': 333,
  33871. 'a': 500,
  33872. 'b': 556,
  33873. 'c': 444,
  33874. 'd': 556,
  33875. 'e': 444,
  33876. 'f': 333,
  33877. 'g': 500,
  33878. 'h': 556,
  33879. 'i': 278,
  33880. 'j': 333,
  33881. 'k': 556,
  33882. 'l': 278,
  33883. 'm': 833,
  33884. 'n': 556,
  33885. 'o': 500,
  33886. 'p': 556,
  33887. 'q': 556,
  33888. 'r': 444,
  33889. 's': 389,
  33890. 't': 333,
  33891. 'u': 556,
  33892. 'v': 500,
  33893. 'w': 722,
  33894. 'x': 500,
  33895. 'y': 500,
  33896. 'z': 444,
  33897. 'braceleft': 394,
  33898. 'bar': 220,
  33899. 'braceright': 394,
  33900. 'asciitilde': 520,
  33901. 'exclamdown': 333,
  33902. 'cent': 500,
  33903. 'sterling': 500,
  33904. 'fraction': 167,
  33905. 'yen': 500,
  33906. 'florin': 500,
  33907. 'section': 500,
  33908. 'currency': 500,
  33909. 'quotesingle': 278,
  33910. 'quotedblleft': 500,
  33911. 'guillemotleft': 500,
  33912. 'guilsinglleft': 333,
  33913. 'guilsinglright': 333,
  33914. 'fi': 556,
  33915. 'fl': 556,
  33916. 'endash': 500,
  33917. 'dagger': 500,
  33918. 'daggerdbl': 500,
  33919. 'periodcentered': 250,
  33920. 'paragraph': 540,
  33921. 'bullet': 350,
  33922. 'quotesinglbase': 333,
  33923. 'quotedblbase': 500,
  33924. 'quotedblright': 500,
  33925. 'guillemotright': 500,
  33926. 'ellipsis': 1000,
  33927. 'perthousand': 1000,
  33928. 'questiondown': 500,
  33929. 'grave': 333,
  33930. 'acute': 333,
  33931. 'circumflex': 333,
  33932. 'tilde': 333,
  33933. 'macron': 333,
  33934. 'breve': 333,
  33935. 'dotaccent': 333,
  33936. 'dieresis': 333,
  33937. 'ring': 333,
  33938. 'cedilla': 333,
  33939. 'hungarumlaut': 333,
  33940. 'ogonek': 333,
  33941. 'caron': 333,
  33942. 'emdash': 1000,
  33943. 'AE': 1000,
  33944. 'ordfeminine': 300,
  33945. 'Lslash': 667,
  33946. 'Oslash': 778,
  33947. 'OE': 1000,
  33948. 'ordmasculine': 330,
  33949. 'ae': 722,
  33950. 'dotlessi': 278,
  33951. 'lslash': 278,
  33952. 'oslash': 500,
  33953. 'oe': 722,
  33954. 'germandbls': 556,
  33955. 'Idieresis': 389,
  33956. 'eacute': 444,
  33957. 'abreve': 500,
  33958. 'uhungarumlaut': 556,
  33959. 'ecaron': 444,
  33960. 'Ydieresis': 722,
  33961. 'divide': 570,
  33962. 'Yacute': 722,
  33963. 'Acircumflex': 722,
  33964. 'aacute': 500,
  33965. 'Ucircumflex': 722,
  33966. 'yacute': 500,
  33967. 'scommaaccent': 389,
  33968. 'ecircumflex': 444,
  33969. 'Uring': 722,
  33970. 'Udieresis': 722,
  33971. 'aogonek': 500,
  33972. 'Uacute': 722,
  33973. 'uogonek': 556,
  33974. 'Edieresis': 667,
  33975. 'Dcroat': 722,
  33976. 'commaaccent': 250,
  33977. 'copyright': 747,
  33978. 'Emacron': 667,
  33979. 'ccaron': 444,
  33980. 'aring': 500,
  33981. 'Ncommaaccent': 722,
  33982. 'lacute': 278,
  33983. 'agrave': 500,
  33984. 'Tcommaaccent': 667,
  33985. 'Cacute': 722,
  33986. 'atilde': 500,
  33987. 'Edotaccent': 667,
  33988. 'scaron': 389,
  33989. 'scedilla': 389,
  33990. 'iacute': 278,
  33991. 'lozenge': 494,
  33992. 'Rcaron': 722,
  33993. 'Gcommaaccent': 778,
  33994. 'ucircumflex': 556,
  33995. 'acircumflex': 500,
  33996. 'Amacron': 722,
  33997. 'rcaron': 444,
  33998. 'ccedilla': 444,
  33999. 'Zdotaccent': 667,
  34000. 'Thorn': 611,
  34001. 'Omacron': 778,
  34002. 'Racute': 722,
  34003. 'Sacute': 556,
  34004. 'dcaron': 672,
  34005. 'Umacron': 722,
  34006. 'uring': 556,
  34007. 'threesuperior': 300,
  34008. 'Ograve': 778,
  34009. 'Agrave': 722,
  34010. 'Abreve': 722,
  34011. 'multiply': 570,
  34012. 'uacute': 556,
  34013. 'Tcaron': 667,
  34014. 'partialdiff': 494,
  34015. 'ydieresis': 500,
  34016. 'Nacute': 722,
  34017. 'icircumflex': 278,
  34018. 'Ecircumflex': 667,
  34019. 'adieresis': 500,
  34020. 'edieresis': 444,
  34021. 'cacute': 444,
  34022. 'nacute': 556,
  34023. 'umacron': 556,
  34024. 'Ncaron': 722,
  34025. 'Iacute': 389,
  34026. 'plusminus': 570,
  34027. 'brokenbar': 220,
  34028. 'registered': 747,
  34029. 'Gbreve': 778,
  34030. 'Idotaccent': 389,
  34031. 'summation': 600,
  34032. 'Egrave': 667,
  34033. 'racute': 444,
  34034. 'omacron': 500,
  34035. 'Zacute': 667,
  34036. 'Zcaron': 667,
  34037. 'greaterequal': 549,
  34038. 'Eth': 722,
  34039. 'Ccedilla': 722,
  34040. 'lcommaaccent': 278,
  34041. 'tcaron': 416,
  34042. 'eogonek': 444,
  34043. 'Uogonek': 722,
  34044. 'Aacute': 722,
  34045. 'Adieresis': 722,
  34046. 'egrave': 444,
  34047. 'zacute': 444,
  34048. 'iogonek': 278,
  34049. 'Oacute': 778,
  34050. 'oacute': 500,
  34051. 'amacron': 500,
  34052. 'sacute': 389,
  34053. 'idieresis': 278,
  34054. 'Ocircumflex': 778,
  34055. 'Ugrave': 722,
  34056. 'Delta': 612,
  34057. 'thorn': 556,
  34058. 'twosuperior': 300,
  34059. 'Odieresis': 778,
  34060. 'mu': 556,
  34061. 'igrave': 278,
  34062. 'ohungarumlaut': 500,
  34063. 'Eogonek': 667,
  34064. 'dcroat': 556,
  34065. 'threequarters': 750,
  34066. 'Scedilla': 556,
  34067. 'lcaron': 394,
  34068. 'Kcommaaccent': 778,
  34069. 'Lacute': 667,
  34070. 'trademark': 1000,
  34071. 'edotaccent': 444,
  34072. 'Igrave': 389,
  34073. 'Imacron': 389,
  34074. 'Lcaron': 667,
  34075. 'onehalf': 750,
  34076. 'lessequal': 549,
  34077. 'ocircumflex': 500,
  34078. 'ntilde': 556,
  34079. 'Uhungarumlaut': 722,
  34080. 'Eacute': 667,
  34081. 'emacron': 444,
  34082. 'gbreve': 500,
  34083. 'onequarter': 750,
  34084. 'Scaron': 556,
  34085. 'Scommaaccent': 556,
  34086. 'Ohungarumlaut': 778,
  34087. 'degree': 400,
  34088. 'ograve': 500,
  34089. 'Ccaron': 722,
  34090. 'ugrave': 556,
  34091. 'radical': 549,
  34092. 'Dcaron': 722,
  34093. 'rcommaaccent': 444,
  34094. 'Ntilde': 722,
  34095. 'otilde': 500,
  34096. 'Rcommaaccent': 722,
  34097. 'Lcommaaccent': 667,
  34098. 'Atilde': 722,
  34099. 'Aogonek': 722,
  34100. 'Aring': 722,
  34101. 'Otilde': 778,
  34102. 'zdotaccent': 444,
  34103. 'Ecaron': 667,
  34104. 'Iogonek': 389,
  34105. 'kcommaaccent': 556,
  34106. 'minus': 570,
  34107. 'Icircumflex': 389,
  34108. 'ncaron': 556,
  34109. 'tcommaaccent': 333,
  34110. 'logicalnot': 570,
  34111. 'odieresis': 500,
  34112. 'udieresis': 556,
  34113. 'notequal': 549,
  34114. 'gcommaaccent': 500,
  34115. 'eth': 500,
  34116. 'zcaron': 444,
  34117. 'ncommaaccent': 556,
  34118. 'onesuperior': 300,
  34119. 'imacron': 278,
  34120. 'Euro': 500
  34121. },
  34122. 'Times-BoldItalic': {
  34123. 'space': 250,
  34124. 'exclam': 389,
  34125. 'quotedbl': 555,
  34126. 'numbersign': 500,
  34127. 'dollar': 500,
  34128. 'percent': 833,
  34129. 'ampersand': 778,
  34130. 'quoteright': 333,
  34131. 'parenleft': 333,
  34132. 'parenright': 333,
  34133. 'asterisk': 500,
  34134. 'plus': 570,
  34135. 'comma': 250,
  34136. 'hyphen': 333,
  34137. 'period': 250,
  34138. 'slash': 278,
  34139. 'zero': 500,
  34140. 'one': 500,
  34141. 'two': 500,
  34142. 'three': 500,
  34143. 'four': 500,
  34144. 'five': 500,
  34145. 'six': 500,
  34146. 'seven': 500,
  34147. 'eight': 500,
  34148. 'nine': 500,
  34149. 'colon': 333,
  34150. 'semicolon': 333,
  34151. 'less': 570,
  34152. 'equal': 570,
  34153. 'greater': 570,
  34154. 'question': 500,
  34155. 'at': 832,
  34156. 'A': 667,
  34157. 'B': 667,
  34158. 'C': 667,
  34159. 'D': 722,
  34160. 'E': 667,
  34161. 'F': 667,
  34162. 'G': 722,
  34163. 'H': 778,
  34164. 'I': 389,
  34165. 'J': 500,
  34166. 'K': 667,
  34167. 'L': 611,
  34168. 'M': 889,
  34169. 'N': 722,
  34170. 'O': 722,
  34171. 'P': 611,
  34172. 'Q': 722,
  34173. 'R': 667,
  34174. 'S': 556,
  34175. 'T': 611,
  34176. 'U': 722,
  34177. 'V': 667,
  34178. 'W': 889,
  34179. 'X': 667,
  34180. 'Y': 611,
  34181. 'Z': 611,
  34182. 'bracketleft': 333,
  34183. 'backslash': 278,
  34184. 'bracketright': 333,
  34185. 'asciicircum': 570,
  34186. 'underscore': 500,
  34187. 'quoteleft': 333,
  34188. 'a': 500,
  34189. 'b': 500,
  34190. 'c': 444,
  34191. 'd': 500,
  34192. 'e': 444,
  34193. 'f': 333,
  34194. 'g': 500,
  34195. 'h': 556,
  34196. 'i': 278,
  34197. 'j': 278,
  34198. 'k': 500,
  34199. 'l': 278,
  34200. 'm': 778,
  34201. 'n': 556,
  34202. 'o': 500,
  34203. 'p': 500,
  34204. 'q': 500,
  34205. 'r': 389,
  34206. 's': 389,
  34207. 't': 278,
  34208. 'u': 556,
  34209. 'v': 444,
  34210. 'w': 667,
  34211. 'x': 500,
  34212. 'y': 444,
  34213. 'z': 389,
  34214. 'braceleft': 348,
  34215. 'bar': 220,
  34216. 'braceright': 348,
  34217. 'asciitilde': 570,
  34218. 'exclamdown': 389,
  34219. 'cent': 500,
  34220. 'sterling': 500,
  34221. 'fraction': 167,
  34222. 'yen': 500,
  34223. 'florin': 500,
  34224. 'section': 500,
  34225. 'currency': 500,
  34226. 'quotesingle': 278,
  34227. 'quotedblleft': 500,
  34228. 'guillemotleft': 500,
  34229. 'guilsinglleft': 333,
  34230. 'guilsinglright': 333,
  34231. 'fi': 556,
  34232. 'fl': 556,
  34233. 'endash': 500,
  34234. 'dagger': 500,
  34235. 'daggerdbl': 500,
  34236. 'periodcentered': 250,
  34237. 'paragraph': 500,
  34238. 'bullet': 350,
  34239. 'quotesinglbase': 333,
  34240. 'quotedblbase': 500,
  34241. 'quotedblright': 500,
  34242. 'guillemotright': 500,
  34243. 'ellipsis': 1000,
  34244. 'perthousand': 1000,
  34245. 'questiondown': 500,
  34246. 'grave': 333,
  34247. 'acute': 333,
  34248. 'circumflex': 333,
  34249. 'tilde': 333,
  34250. 'macron': 333,
  34251. 'breve': 333,
  34252. 'dotaccent': 333,
  34253. 'dieresis': 333,
  34254. 'ring': 333,
  34255. 'cedilla': 333,
  34256. 'hungarumlaut': 333,
  34257. 'ogonek': 333,
  34258. 'caron': 333,
  34259. 'emdash': 1000,
  34260. 'AE': 944,
  34261. 'ordfeminine': 266,
  34262. 'Lslash': 611,
  34263. 'Oslash': 722,
  34264. 'OE': 944,
  34265. 'ordmasculine': 300,
  34266. 'ae': 722,
  34267. 'dotlessi': 278,
  34268. 'lslash': 278,
  34269. 'oslash': 500,
  34270. 'oe': 722,
  34271. 'germandbls': 500,
  34272. 'Idieresis': 389,
  34273. 'eacute': 444,
  34274. 'abreve': 500,
  34275. 'uhungarumlaut': 556,
  34276. 'ecaron': 444,
  34277. 'Ydieresis': 611,
  34278. 'divide': 570,
  34279. 'Yacute': 611,
  34280. 'Acircumflex': 667,
  34281. 'aacute': 500,
  34282. 'Ucircumflex': 722,
  34283. 'yacute': 444,
  34284. 'scommaaccent': 389,
  34285. 'ecircumflex': 444,
  34286. 'Uring': 722,
  34287. 'Udieresis': 722,
  34288. 'aogonek': 500,
  34289. 'Uacute': 722,
  34290. 'uogonek': 556,
  34291. 'Edieresis': 667,
  34292. 'Dcroat': 722,
  34293. 'commaaccent': 250,
  34294. 'copyright': 747,
  34295. 'Emacron': 667,
  34296. 'ccaron': 444,
  34297. 'aring': 500,
  34298. 'Ncommaaccent': 722,
  34299. 'lacute': 278,
  34300. 'agrave': 500,
  34301. 'Tcommaaccent': 611,
  34302. 'Cacute': 667,
  34303. 'atilde': 500,
  34304. 'Edotaccent': 667,
  34305. 'scaron': 389,
  34306. 'scedilla': 389,
  34307. 'iacute': 278,
  34308. 'lozenge': 494,
  34309. 'Rcaron': 667,
  34310. 'Gcommaaccent': 722,
  34311. 'ucircumflex': 556,
  34312. 'acircumflex': 500,
  34313. 'Amacron': 667,
  34314. 'rcaron': 389,
  34315. 'ccedilla': 444,
  34316. 'Zdotaccent': 611,
  34317. 'Thorn': 611,
  34318. 'Omacron': 722,
  34319. 'Racute': 667,
  34320. 'Sacute': 556,
  34321. 'dcaron': 608,
  34322. 'Umacron': 722,
  34323. 'uring': 556,
  34324. 'threesuperior': 300,
  34325. 'Ograve': 722,
  34326. 'Agrave': 667,
  34327. 'Abreve': 667,
  34328. 'multiply': 570,
  34329. 'uacute': 556,
  34330. 'Tcaron': 611,
  34331. 'partialdiff': 494,
  34332. 'ydieresis': 444,
  34333. 'Nacute': 722,
  34334. 'icircumflex': 278,
  34335. 'Ecircumflex': 667,
  34336. 'adieresis': 500,
  34337. 'edieresis': 444,
  34338. 'cacute': 444,
  34339. 'nacute': 556,
  34340. 'umacron': 556,
  34341. 'Ncaron': 722,
  34342. 'Iacute': 389,
  34343. 'plusminus': 570,
  34344. 'brokenbar': 220,
  34345. 'registered': 747,
  34346. 'Gbreve': 722,
  34347. 'Idotaccent': 389,
  34348. 'summation': 600,
  34349. 'Egrave': 667,
  34350. 'racute': 389,
  34351. 'omacron': 500,
  34352. 'Zacute': 611,
  34353. 'Zcaron': 611,
  34354. 'greaterequal': 549,
  34355. 'Eth': 722,
  34356. 'Ccedilla': 667,
  34357. 'lcommaaccent': 278,
  34358. 'tcaron': 366,
  34359. 'eogonek': 444,
  34360. 'Uogonek': 722,
  34361. 'Aacute': 667,
  34362. 'Adieresis': 667,
  34363. 'egrave': 444,
  34364. 'zacute': 389,
  34365. 'iogonek': 278,
  34366. 'Oacute': 722,
  34367. 'oacute': 500,
  34368. 'amacron': 500,
  34369. 'sacute': 389,
  34370. 'idieresis': 278,
  34371. 'Ocircumflex': 722,
  34372. 'Ugrave': 722,
  34373. 'Delta': 612,
  34374. 'thorn': 500,
  34375. 'twosuperior': 300,
  34376. 'Odieresis': 722,
  34377. 'mu': 576,
  34378. 'igrave': 278,
  34379. 'ohungarumlaut': 500,
  34380. 'Eogonek': 667,
  34381. 'dcroat': 500,
  34382. 'threequarters': 750,
  34383. 'Scedilla': 556,
  34384. 'lcaron': 382,
  34385. 'Kcommaaccent': 667,
  34386. 'Lacute': 611,
  34387. 'trademark': 1000,
  34388. 'edotaccent': 444,
  34389. 'Igrave': 389,
  34390. 'Imacron': 389,
  34391. 'Lcaron': 611,
  34392. 'onehalf': 750,
  34393. 'lessequal': 549,
  34394. 'ocircumflex': 500,
  34395. 'ntilde': 556,
  34396. 'Uhungarumlaut': 722,
  34397. 'Eacute': 667,
  34398. 'emacron': 444,
  34399. 'gbreve': 500,
  34400. 'onequarter': 750,
  34401. 'Scaron': 556,
  34402. 'Scommaaccent': 556,
  34403. 'Ohungarumlaut': 722,
  34404. 'degree': 400,
  34405. 'ograve': 500,
  34406. 'Ccaron': 667,
  34407. 'ugrave': 556,
  34408. 'radical': 549,
  34409. 'Dcaron': 722,
  34410. 'rcommaaccent': 389,
  34411. 'Ntilde': 722,
  34412. 'otilde': 500,
  34413. 'Rcommaaccent': 667,
  34414. 'Lcommaaccent': 611,
  34415. 'Atilde': 667,
  34416. 'Aogonek': 667,
  34417. 'Aring': 667,
  34418. 'Otilde': 722,
  34419. 'zdotaccent': 389,
  34420. 'Ecaron': 667,
  34421. 'Iogonek': 389,
  34422. 'kcommaaccent': 500,
  34423. 'minus': 606,
  34424. 'Icircumflex': 389,
  34425. 'ncaron': 556,
  34426. 'tcommaaccent': 278,
  34427. 'logicalnot': 606,
  34428. 'odieresis': 500,
  34429. 'udieresis': 556,
  34430. 'notequal': 549,
  34431. 'gcommaaccent': 500,
  34432. 'eth': 500,
  34433. 'zcaron': 389,
  34434. 'ncommaaccent': 556,
  34435. 'onesuperior': 300,
  34436. 'imacron': 278,
  34437. 'Euro': 500
  34438. },
  34439. 'Times-Italic': {
  34440. 'space': 250,
  34441. 'exclam': 333,
  34442. 'quotedbl': 420,
  34443. 'numbersign': 500,
  34444. 'dollar': 500,
  34445. 'percent': 833,
  34446. 'ampersand': 778,
  34447. 'quoteright': 333,
  34448. 'parenleft': 333,
  34449. 'parenright': 333,
  34450. 'asterisk': 500,
  34451. 'plus': 675,
  34452. 'comma': 250,
  34453. 'hyphen': 333,
  34454. 'period': 250,
  34455. 'slash': 278,
  34456. 'zero': 500,
  34457. 'one': 500,
  34458. 'two': 500,
  34459. 'three': 500,
  34460. 'four': 500,
  34461. 'five': 500,
  34462. 'six': 500,
  34463. 'seven': 500,
  34464. 'eight': 500,
  34465. 'nine': 500,
  34466. 'colon': 333,
  34467. 'semicolon': 333,
  34468. 'less': 675,
  34469. 'equal': 675,
  34470. 'greater': 675,
  34471. 'question': 500,
  34472. 'at': 920,
  34473. 'A': 611,
  34474. 'B': 611,
  34475. 'C': 667,
  34476. 'D': 722,
  34477. 'E': 611,
  34478. 'F': 611,
  34479. 'G': 722,
  34480. 'H': 722,
  34481. 'I': 333,
  34482. 'J': 444,
  34483. 'K': 667,
  34484. 'L': 556,
  34485. 'M': 833,
  34486. 'N': 667,
  34487. 'O': 722,
  34488. 'P': 611,
  34489. 'Q': 722,
  34490. 'R': 611,
  34491. 'S': 500,
  34492. 'T': 556,
  34493. 'U': 722,
  34494. 'V': 611,
  34495. 'W': 833,
  34496. 'X': 611,
  34497. 'Y': 556,
  34498. 'Z': 556,
  34499. 'bracketleft': 389,
  34500. 'backslash': 278,
  34501. 'bracketright': 389,
  34502. 'asciicircum': 422,
  34503. 'underscore': 500,
  34504. 'quoteleft': 333,
  34505. 'a': 500,
  34506. 'b': 500,
  34507. 'c': 444,
  34508. 'd': 500,
  34509. 'e': 444,
  34510. 'f': 278,
  34511. 'g': 500,
  34512. 'h': 500,
  34513. 'i': 278,
  34514. 'j': 278,
  34515. 'k': 444,
  34516. 'l': 278,
  34517. 'm': 722,
  34518. 'n': 500,
  34519. 'o': 500,
  34520. 'p': 500,
  34521. 'q': 500,
  34522. 'r': 389,
  34523. 's': 389,
  34524. 't': 278,
  34525. 'u': 500,
  34526. 'v': 444,
  34527. 'w': 667,
  34528. 'x': 444,
  34529. 'y': 444,
  34530. 'z': 389,
  34531. 'braceleft': 400,
  34532. 'bar': 275,
  34533. 'braceright': 400,
  34534. 'asciitilde': 541,
  34535. 'exclamdown': 389,
  34536. 'cent': 500,
  34537. 'sterling': 500,
  34538. 'fraction': 167,
  34539. 'yen': 500,
  34540. 'florin': 500,
  34541. 'section': 500,
  34542. 'currency': 500,
  34543. 'quotesingle': 214,
  34544. 'quotedblleft': 556,
  34545. 'guillemotleft': 500,
  34546. 'guilsinglleft': 333,
  34547. 'guilsinglright': 333,
  34548. 'fi': 500,
  34549. 'fl': 500,
  34550. 'endash': 500,
  34551. 'dagger': 500,
  34552. 'daggerdbl': 500,
  34553. 'periodcentered': 250,
  34554. 'paragraph': 523,
  34555. 'bullet': 350,
  34556. 'quotesinglbase': 333,
  34557. 'quotedblbase': 556,
  34558. 'quotedblright': 556,
  34559. 'guillemotright': 500,
  34560. 'ellipsis': 889,
  34561. 'perthousand': 1000,
  34562. 'questiondown': 500,
  34563. 'grave': 333,
  34564. 'acute': 333,
  34565. 'circumflex': 333,
  34566. 'tilde': 333,
  34567. 'macron': 333,
  34568. 'breve': 333,
  34569. 'dotaccent': 333,
  34570. 'dieresis': 333,
  34571. 'ring': 333,
  34572. 'cedilla': 333,
  34573. 'hungarumlaut': 333,
  34574. 'ogonek': 333,
  34575. 'caron': 333,
  34576. 'emdash': 889,
  34577. 'AE': 889,
  34578. 'ordfeminine': 276,
  34579. 'Lslash': 556,
  34580. 'Oslash': 722,
  34581. 'OE': 944,
  34582. 'ordmasculine': 310,
  34583. 'ae': 667,
  34584. 'dotlessi': 278,
  34585. 'lslash': 278,
  34586. 'oslash': 500,
  34587. 'oe': 667,
  34588. 'germandbls': 500,
  34589. 'Idieresis': 333,
  34590. 'eacute': 444,
  34591. 'abreve': 500,
  34592. 'uhungarumlaut': 500,
  34593. 'ecaron': 444,
  34594. 'Ydieresis': 556,
  34595. 'divide': 675,
  34596. 'Yacute': 556,
  34597. 'Acircumflex': 611,
  34598. 'aacute': 500,
  34599. 'Ucircumflex': 722,
  34600. 'yacute': 444,
  34601. 'scommaaccent': 389,
  34602. 'ecircumflex': 444,
  34603. 'Uring': 722,
  34604. 'Udieresis': 722,
  34605. 'aogonek': 500,
  34606. 'Uacute': 722,
  34607. 'uogonek': 500,
  34608. 'Edieresis': 611,
  34609. 'Dcroat': 722,
  34610. 'commaaccent': 250,
  34611. 'copyright': 760,
  34612. 'Emacron': 611,
  34613. 'ccaron': 444,
  34614. 'aring': 500,
  34615. 'Ncommaaccent': 667,
  34616. 'lacute': 278,
  34617. 'agrave': 500,
  34618. 'Tcommaaccent': 556,
  34619. 'Cacute': 667,
  34620. 'atilde': 500,
  34621. 'Edotaccent': 611,
  34622. 'scaron': 389,
  34623. 'scedilla': 389,
  34624. 'iacute': 278,
  34625. 'lozenge': 471,
  34626. 'Rcaron': 611,
  34627. 'Gcommaaccent': 722,
  34628. 'ucircumflex': 500,
  34629. 'acircumflex': 500,
  34630. 'Amacron': 611,
  34631. 'rcaron': 389,
  34632. 'ccedilla': 444,
  34633. 'Zdotaccent': 556,
  34634. 'Thorn': 611,
  34635. 'Omacron': 722,
  34636. 'Racute': 611,
  34637. 'Sacute': 500,
  34638. 'dcaron': 544,
  34639. 'Umacron': 722,
  34640. 'uring': 500,
  34641. 'threesuperior': 300,
  34642. 'Ograve': 722,
  34643. 'Agrave': 611,
  34644. 'Abreve': 611,
  34645. 'multiply': 675,
  34646. 'uacute': 500,
  34647. 'Tcaron': 556,
  34648. 'partialdiff': 476,
  34649. 'ydieresis': 444,
  34650. 'Nacute': 667,
  34651. 'icircumflex': 278,
  34652. 'Ecircumflex': 611,
  34653. 'adieresis': 500,
  34654. 'edieresis': 444,
  34655. 'cacute': 444,
  34656. 'nacute': 500,
  34657. 'umacron': 500,
  34658. 'Ncaron': 667,
  34659. 'Iacute': 333,
  34660. 'plusminus': 675,
  34661. 'brokenbar': 275,
  34662. 'registered': 760,
  34663. 'Gbreve': 722,
  34664. 'Idotaccent': 333,
  34665. 'summation': 600,
  34666. 'Egrave': 611,
  34667. 'racute': 389,
  34668. 'omacron': 500,
  34669. 'Zacute': 556,
  34670. 'Zcaron': 556,
  34671. 'greaterequal': 549,
  34672. 'Eth': 722,
  34673. 'Ccedilla': 667,
  34674. 'lcommaaccent': 278,
  34675. 'tcaron': 300,
  34676. 'eogonek': 444,
  34677. 'Uogonek': 722,
  34678. 'Aacute': 611,
  34679. 'Adieresis': 611,
  34680. 'egrave': 444,
  34681. 'zacute': 389,
  34682. 'iogonek': 278,
  34683. 'Oacute': 722,
  34684. 'oacute': 500,
  34685. 'amacron': 500,
  34686. 'sacute': 389,
  34687. 'idieresis': 278,
  34688. 'Ocircumflex': 722,
  34689. 'Ugrave': 722,
  34690. 'Delta': 612,
  34691. 'thorn': 500,
  34692. 'twosuperior': 300,
  34693. 'Odieresis': 722,
  34694. 'mu': 500,
  34695. 'igrave': 278,
  34696. 'ohungarumlaut': 500,
  34697. 'Eogonek': 611,
  34698. 'dcroat': 500,
  34699. 'threequarters': 750,
  34700. 'Scedilla': 500,
  34701. 'lcaron': 300,
  34702. 'Kcommaaccent': 667,
  34703. 'Lacute': 556,
  34704. 'trademark': 980,
  34705. 'edotaccent': 444,
  34706. 'Igrave': 333,
  34707. 'Imacron': 333,
  34708. 'Lcaron': 611,
  34709. 'onehalf': 750,
  34710. 'lessequal': 549,
  34711. 'ocircumflex': 500,
  34712. 'ntilde': 500,
  34713. 'Uhungarumlaut': 722,
  34714. 'Eacute': 611,
  34715. 'emacron': 444,
  34716. 'gbreve': 500,
  34717. 'onequarter': 750,
  34718. 'Scaron': 500,
  34719. 'Scommaaccent': 500,
  34720. 'Ohungarumlaut': 722,
  34721. 'degree': 400,
  34722. 'ograve': 500,
  34723. 'Ccaron': 667,
  34724. 'ugrave': 500,
  34725. 'radical': 453,
  34726. 'Dcaron': 722,
  34727. 'rcommaaccent': 389,
  34728. 'Ntilde': 667,
  34729. 'otilde': 500,
  34730. 'Rcommaaccent': 611,
  34731. 'Lcommaaccent': 556,
  34732. 'Atilde': 611,
  34733. 'Aogonek': 611,
  34734. 'Aring': 611,
  34735. 'Otilde': 722,
  34736. 'zdotaccent': 389,
  34737. 'Ecaron': 611,
  34738. 'Iogonek': 333,
  34739. 'kcommaaccent': 444,
  34740. 'minus': 675,
  34741. 'Icircumflex': 333,
  34742. 'ncaron': 500,
  34743. 'tcommaaccent': 278,
  34744. 'logicalnot': 675,
  34745. 'odieresis': 500,
  34746. 'udieresis': 500,
  34747. 'notequal': 549,
  34748. 'gcommaaccent': 500,
  34749. 'eth': 500,
  34750. 'zcaron': 389,
  34751. 'ncommaaccent': 500,
  34752. 'onesuperior': 300,
  34753. 'imacron': 278,
  34754. 'Euro': 500
  34755. },
  34756. 'ZapfDingbats': {
  34757. 'space': 278,
  34758. 'a1': 974,
  34759. 'a2': 961,
  34760. 'a202': 974,
  34761. 'a3': 980,
  34762. 'a4': 719,
  34763. 'a5': 789,
  34764. 'a119': 790,
  34765. 'a118': 791,
  34766. 'a117': 690,
  34767. 'a11': 960,
  34768. 'a12': 939,
  34769. 'a13': 549,
  34770. 'a14': 855,
  34771. 'a15': 911,
  34772. 'a16': 933,
  34773. 'a105': 911,
  34774. 'a17': 945,
  34775. 'a18': 974,
  34776. 'a19': 755,
  34777. 'a20': 846,
  34778. 'a21': 762,
  34779. 'a22': 761,
  34780. 'a23': 571,
  34781. 'a24': 677,
  34782. 'a25': 763,
  34783. 'a26': 760,
  34784. 'a27': 759,
  34785. 'a28': 754,
  34786. 'a6': 494,
  34787. 'a7': 552,
  34788. 'a8': 537,
  34789. 'a9': 577,
  34790. 'a10': 692,
  34791. 'a29': 786,
  34792. 'a30': 788,
  34793. 'a31': 788,
  34794. 'a32': 790,
  34795. 'a33': 793,
  34796. 'a34': 794,
  34797. 'a35': 816,
  34798. 'a36': 823,
  34799. 'a37': 789,
  34800. 'a38': 841,
  34801. 'a39': 823,
  34802. 'a40': 833,
  34803. 'a41': 816,
  34804. 'a42': 831,
  34805. 'a43': 923,
  34806. 'a44': 744,
  34807. 'a45': 723,
  34808. 'a46': 749,
  34809. 'a47': 790,
  34810. 'a48': 792,
  34811. 'a49': 695,
  34812. 'a50': 776,
  34813. 'a51': 768,
  34814. 'a52': 792,
  34815. 'a53': 759,
  34816. 'a54': 707,
  34817. 'a55': 708,
  34818. 'a56': 682,
  34819. 'a57': 701,
  34820. 'a58': 826,
  34821. 'a59': 815,
  34822. 'a60': 789,
  34823. 'a61': 789,
  34824. 'a62': 707,
  34825. 'a63': 687,
  34826. 'a64': 696,
  34827. 'a65': 689,
  34828. 'a66': 786,
  34829. 'a67': 787,
  34830. 'a68': 713,
  34831. 'a69': 791,
  34832. 'a70': 785,
  34833. 'a71': 791,
  34834. 'a72': 873,
  34835. 'a73': 761,
  34836. 'a74': 762,
  34837. 'a203': 762,
  34838. 'a75': 759,
  34839. 'a204': 759,
  34840. 'a76': 892,
  34841. 'a77': 892,
  34842. 'a78': 788,
  34843. 'a79': 784,
  34844. 'a81': 438,
  34845. 'a82': 138,
  34846. 'a83': 277,
  34847. 'a84': 415,
  34848. 'a97': 392,
  34849. 'a98': 392,
  34850. 'a99': 668,
  34851. 'a100': 668,
  34852. 'a89': 390,
  34853. 'a90': 390,
  34854. 'a93': 317,
  34855. 'a94': 317,
  34856. 'a91': 276,
  34857. 'a92': 276,
  34858. 'a205': 509,
  34859. 'a85': 509,
  34860. 'a206': 410,
  34861. 'a86': 410,
  34862. 'a87': 234,
  34863. 'a88': 234,
  34864. 'a95': 334,
  34865. 'a96': 334,
  34866. 'a101': 732,
  34867. 'a102': 544,
  34868. 'a103': 544,
  34869. 'a104': 910,
  34870. 'a106': 667,
  34871. 'a107': 760,
  34872. 'a108': 760,
  34873. 'a112': 776,
  34874. 'a111': 595,
  34875. 'a110': 694,
  34876. 'a109': 626,
  34877. 'a120': 788,
  34878. 'a121': 788,
  34879. 'a122': 788,
  34880. 'a123': 788,
  34881. 'a124': 788,
  34882. 'a125': 788,
  34883. 'a126': 788,
  34884. 'a127': 788,
  34885. 'a128': 788,
  34886. 'a129': 788,
  34887. 'a130': 788,
  34888. 'a131': 788,
  34889. 'a132': 788,
  34890. 'a133': 788,
  34891. 'a134': 788,
  34892. 'a135': 788,
  34893. 'a136': 788,
  34894. 'a137': 788,
  34895. 'a138': 788,
  34896. 'a139': 788,
  34897. 'a140': 788,
  34898. 'a141': 788,
  34899. 'a142': 788,
  34900. 'a143': 788,
  34901. 'a144': 788,
  34902. 'a145': 788,
  34903. 'a146': 788,
  34904. 'a147': 788,
  34905. 'a148': 788,
  34906. 'a149': 788,
  34907. 'a150': 788,
  34908. 'a151': 788,
  34909. 'a152': 788,
  34910. 'a153': 788,
  34911. 'a154': 788,
  34912. 'a155': 788,
  34913. 'a156': 788,
  34914. 'a157': 788,
  34915. 'a158': 788,
  34916. 'a159': 788,
  34917. 'a160': 894,
  34918. 'a161': 838,
  34919. 'a163': 1016,
  34920. 'a164': 458,
  34921. 'a196': 748,
  34922. 'a165': 924,
  34923. 'a192': 748,
  34924. 'a166': 918,
  34925. 'a167': 927,
  34926. 'a168': 928,
  34927. 'a169': 928,
  34928. 'a170': 834,
  34929. 'a171': 873,
  34930. 'a172': 828,
  34931. 'a173': 924,
  34932. 'a162': 924,
  34933. 'a174': 917,
  34934. 'a175': 930,
  34935. 'a176': 931,
  34936. 'a177': 463,
  34937. 'a178': 883,
  34938. 'a179': 836,
  34939. 'a193': 836,
  34940. 'a180': 867,
  34941. 'a199': 867,
  34942. 'a181': 696,
  34943. 'a200': 696,
  34944. 'a182': 874,
  34945. 'a201': 874,
  34946. 'a183': 760,
  34947. 'a184': 946,
  34948. 'a197': 771,
  34949. 'a185': 865,
  34950. 'a194': 771,
  34951. 'a198': 888,
  34952. 'a186': 967,
  34953. 'a195': 888,
  34954. 'a187': 831,
  34955. 'a188': 873,
  34956. 'a189': 927,
  34957. 'a190': 970,
  34958. 'a191': 918
  34959. }
  34960. };
  34961. var EOF = {};
  34962. function isEOF(v) {
  34963. return (v === EOF);
  34964. }
  34965. var MAX_LENGTH_TO_CACHE = 1000;
  34966. var Parser = (function ParserClosure() {
  34967. function Parser(lexer, allowStreams, xref) {
  34968. this.lexer = lexer;
  34969. this.allowStreams = allowStreams;
  34970. this.xref = xref;
  34971. this.imageCache = {};
  34972. this.refill();
  34973. }
  34974. Parser.prototype = {
  34975. refill: function Parser_refill() {
  34976. this.buf1 = this.lexer.getObj();
  34977. this.buf2 = this.lexer.getObj();
  34978. },
  34979. shift: function Parser_shift() {
  34980. if (isCmd(this.buf2, 'ID')) {
  34981. this.buf1 = this.buf2;
  34982. this.buf2 = null;
  34983. } else {
  34984. this.buf1 = this.buf2;
  34985. this.buf2 = this.lexer.getObj();
  34986. }
  34987. },
  34988. tryShift: function Parser_tryShift() {
  34989. try {
  34990. this.shift();
  34991. return true;
  34992. } catch (e) {
  34993. if (e instanceof MissingDataException) {
  34994. throw e;
  34995. }
  34996. // Upon failure, the caller should reset this.lexer.pos to a known good
  34997. // state and call this.shift() twice to reset the buffers.
  34998. return false;
  34999. }
  35000. },
  35001. getObj: function Parser_getObj(cipherTransform) {
  35002. var buf1 = this.buf1;
  35003. this.shift();
  35004. if (buf1 instanceof Cmd) {
  35005. switch (buf1.cmd) {
  35006. case 'BI': // inline image
  35007. return this.makeInlineImage(cipherTransform);
  35008. case '[': // array
  35009. var array = [];
  35010. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  35011. array.push(this.getObj(cipherTransform));
  35012. }
  35013. if (isEOF(this.buf1)) {
  35014. error('End of file inside array');
  35015. }
  35016. this.shift();
  35017. return array;
  35018. case '<<': // dictionary or stream
  35019. var dict = new Dict(this.xref);
  35020. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  35021. if (!isName(this.buf1)) {
  35022. info('Malformed dictionary: key must be a name object');
  35023. this.shift();
  35024. continue;
  35025. }
  35026. var key = this.buf1.name;
  35027. this.shift();
  35028. if (isEOF(this.buf1)) {
  35029. break;
  35030. }
  35031. dict.set(key, this.getObj(cipherTransform));
  35032. }
  35033. if (isEOF(this.buf1)) {
  35034. error('End of file inside dictionary');
  35035. }
  35036. // Stream objects are not allowed inside content streams or
  35037. // object streams.
  35038. if (isCmd(this.buf2, 'stream')) {
  35039. return (this.allowStreams ?
  35040. this.makeStream(dict, cipherTransform) : dict);
  35041. }
  35042. this.shift();
  35043. return dict;
  35044. default: // simple object
  35045. return buf1;
  35046. }
  35047. }
  35048. if (isInt(buf1)) { // indirect reference or integer
  35049. var num = buf1;
  35050. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  35051. var ref = new Ref(num, this.buf1);
  35052. this.shift();
  35053. this.shift();
  35054. return ref;
  35055. }
  35056. return num;
  35057. }
  35058. if (isString(buf1)) { // string
  35059. var str = buf1;
  35060. if (cipherTransform) {
  35061. str = cipherTransform.decryptString(str);
  35062. }
  35063. return str;
  35064. }
  35065. // simple object
  35066. return buf1;
  35067. },
  35068. /**
  35069. * Find the end of the stream by searching for the /EI\s/.
  35070. * @returns {number} The inline stream length.
  35071. */
  35072. findDefaultInlineStreamEnd:
  35073. function Parser_findDefaultInlineStreamEnd(stream) {
  35074. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  35075. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  35076. while ((ch = stream.getByte()) !== -1) {
  35077. if (state === 0) {
  35078. state = (ch === E) ? 1 : 0;
  35079. } else if (state === 1) {
  35080. state = (ch === I) ? 2 : 0;
  35081. } else {
  35082. assert(state === 2);
  35083. if (ch === SPACE || ch === LF || ch === CR) {
  35084. // Let's check the next five bytes are ASCII... just be sure.
  35085. n = 5;
  35086. followingBytes = stream.peekBytes(n);
  35087. for (i = 0; i < n; i++) {
  35088. ch = followingBytes[i];
  35089. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  35090. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  35091. // it's binary stuff. Resetting the state.
  35092. state = 0;
  35093. break;
  35094. }
  35095. }
  35096. if (state === 2) {
  35097. break; // Finished!
  35098. }
  35099. } else {
  35100. state = 0;
  35101. }
  35102. }
  35103. }
  35104. return ((stream.pos - 4) - startPos);
  35105. },
  35106. /**
  35107. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  35108. * @returns {number} The inline stream length.
  35109. */
  35110. findDCTDecodeInlineStreamEnd:
  35111. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  35112. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  35113. while ((b = stream.getByte()) !== -1) {
  35114. if (b !== 0xFF) { // Not a valid marker.
  35115. continue;
  35116. }
  35117. switch (stream.getByte()) {
  35118. case 0x00: // Byte stuffing.
  35119. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  35120. break;
  35121. case 0xFF: // Fill byte.
  35122. // Avoid skipping a valid marker, resetting the stream position.
  35123. stream.skip(-1);
  35124. break;
  35125. case 0xD9: // EOI
  35126. foundEOI = true;
  35127. break;
  35128. case 0xC0: // SOF0
  35129. case 0xC1: // SOF1
  35130. case 0xC2: // SOF2
  35131. case 0xC3: // SOF3
  35132. case 0xC5: // SOF5
  35133. case 0xC6: // SOF6
  35134. case 0xC7: // SOF7
  35135. case 0xC9: // SOF9
  35136. case 0xCA: // SOF10
  35137. case 0xCB: // SOF11
  35138. case 0xCD: // SOF13
  35139. case 0xCE: // SOF14
  35140. case 0xCF: // SOF15
  35141. case 0xC4: // DHT
  35142. case 0xCC: // DAC
  35143. case 0xDA: // SOS
  35144. case 0xDB: // DQT
  35145. case 0xDC: // DNL
  35146. case 0xDD: // DRI
  35147. case 0xDE: // DHP
  35148. case 0xDF: // EXP
  35149. case 0xE0: // APP0
  35150. case 0xE1: // APP1
  35151. case 0xE2: // APP2
  35152. case 0xE3: // APP3
  35153. case 0xE4: // APP4
  35154. case 0xE5: // APP5
  35155. case 0xE6: // APP6
  35156. case 0xE7: // APP7
  35157. case 0xE8: // APP8
  35158. case 0xE9: // APP9
  35159. case 0xEA: // APP10
  35160. case 0xEB: // APP11
  35161. case 0xEC: // APP12
  35162. case 0xED: // APP13
  35163. case 0xEE: // APP14
  35164. case 0xEF: // APP15
  35165. case 0xFE: // COM
  35166. // The marker should be followed by the length of the segment.
  35167. markerLength = stream.getUint16();
  35168. if (markerLength > 2) {
  35169. // |markerLength| contains the byte length of the marker segment,
  35170. // including its own length (2 bytes) and excluding the marker.
  35171. stream.skip(markerLength - 2); // Jump to the next marker.
  35172. } else {
  35173. // The marker length is invalid, resetting the stream position.
  35174. stream.skip(-2);
  35175. }
  35176. break;
  35177. }
  35178. if (foundEOI) {
  35179. break;
  35180. }
  35181. }
  35182. length = stream.pos - startPos;
  35183. if (b === -1) {
  35184. warn('Inline DCTDecode image stream: ' +
  35185. 'EOI marker not found, searching for /EI/ instead.');
  35186. stream.skip(-length); // Reset the stream position.
  35187. return this.findDefaultInlineStreamEnd(stream);
  35188. }
  35189. this.inlineStreamSkipEI(stream);
  35190. return length;
  35191. },
  35192. /**
  35193. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  35194. * @returns {number} The inline stream length.
  35195. */
  35196. findASCII85DecodeInlineStreamEnd:
  35197. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  35198. var TILDE = 0x7E, GT = 0x3E;
  35199. var startPos = stream.pos, ch, length;
  35200. while ((ch = stream.getByte()) !== -1) {
  35201. if (ch === TILDE && stream.peekByte() === GT) {
  35202. stream.skip();
  35203. break;
  35204. }
  35205. }
  35206. length = stream.pos - startPos;
  35207. if (ch === -1) {
  35208. warn('Inline ASCII85Decode image stream: ' +
  35209. 'EOD marker not found, searching for /EI/ instead.');
  35210. stream.skip(-length); // Reset the stream position.
  35211. return this.findDefaultInlineStreamEnd(stream);
  35212. }
  35213. this.inlineStreamSkipEI(stream);
  35214. return length;
  35215. },
  35216. /**
  35217. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  35218. * @returns {number} The inline stream length.
  35219. */
  35220. findASCIIHexDecodeInlineStreamEnd:
  35221. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  35222. var GT = 0x3E;
  35223. var startPos = stream.pos, ch, length;
  35224. while ((ch = stream.getByte()) !== -1) {
  35225. if (ch === GT) {
  35226. break;
  35227. }
  35228. }
  35229. length = stream.pos - startPos;
  35230. if (ch === -1) {
  35231. warn('Inline ASCIIHexDecode image stream: ' +
  35232. 'EOD marker not found, searching for /EI/ instead.');
  35233. stream.skip(-length); // Reset the stream position.
  35234. return this.findDefaultInlineStreamEnd(stream);
  35235. }
  35236. this.inlineStreamSkipEI(stream);
  35237. return length;
  35238. },
  35239. /**
  35240. * Skip over the /EI/ for streams where we search for an EOD marker.
  35241. */
  35242. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  35243. var E = 0x45, I = 0x49;
  35244. var state = 0, ch;
  35245. while ((ch = stream.getByte()) !== -1) {
  35246. if (state === 0) {
  35247. state = (ch === E) ? 1 : 0;
  35248. } else if (state === 1) {
  35249. state = (ch === I) ? 2 : 0;
  35250. } else if (state === 2) {
  35251. break;
  35252. }
  35253. }
  35254. },
  35255. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  35256. var lexer = this.lexer;
  35257. var stream = lexer.stream;
  35258. // Parse dictionary.
  35259. var dict = new Dict(this.xref);
  35260. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  35261. if (!isName(this.buf1)) {
  35262. error('Dictionary key must be a name object');
  35263. }
  35264. var key = this.buf1.name;
  35265. this.shift();
  35266. if (isEOF(this.buf1)) {
  35267. break;
  35268. }
  35269. dict.set(key, this.getObj(cipherTransform));
  35270. }
  35271. // Extract the name of the first (i.e. the current) image filter.
  35272. var filter = dict.get('Filter', 'F'), filterName;
  35273. if (isName(filter)) {
  35274. filterName = filter.name;
  35275. } else if (isArray(filter) && isName(filter[0])) {
  35276. filterName = filter[0].name;
  35277. }
  35278. // Parse image stream.
  35279. var startPos = stream.pos, length, i, ii;
  35280. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  35281. length = this.findDCTDecodeInlineStreamEnd(stream);
  35282. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  35283. length = this.findASCII85DecodeInlineStreamEnd(stream);
  35284. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  35285. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  35286. } else {
  35287. length = this.findDefaultInlineStreamEnd(stream);
  35288. }
  35289. var imageStream = stream.makeSubStream(startPos, length, dict);
  35290. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  35291. // adler32 checksum.
  35292. var adler32;
  35293. if (length < MAX_LENGTH_TO_CACHE) {
  35294. var imageBytes = imageStream.getBytes();
  35295. imageStream.reset();
  35296. var a = 1;
  35297. var b = 0;
  35298. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  35299. // No modulo required in the loop if imageBytes.length < 5552.
  35300. a += imageBytes[i] & 0xff;
  35301. b += a;
  35302. }
  35303. adler32 = ((b % 65521) << 16) | (a % 65521);
  35304. if (this.imageCache.adler32 === adler32) {
  35305. this.buf2 = Cmd.get('EI');
  35306. this.shift();
  35307. this.imageCache[adler32].reset();
  35308. return this.imageCache[adler32];
  35309. }
  35310. }
  35311. if (cipherTransform) {
  35312. imageStream = cipherTransform.createStream(imageStream, length);
  35313. }
  35314. imageStream = this.filter(imageStream, dict, length);
  35315. imageStream.dict = dict;
  35316. if (adler32 !== undefined) {
  35317. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  35318. this.imageCache[adler32] = imageStream;
  35319. }
  35320. this.buf2 = Cmd.get('EI');
  35321. this.shift();
  35322. return imageStream;
  35323. },
  35324. makeStream: function Parser_makeStream(dict, cipherTransform) {
  35325. var lexer = this.lexer;
  35326. var stream = lexer.stream;
  35327. // get stream start position
  35328. lexer.skipToNextLine();
  35329. var pos = stream.pos - 1;
  35330. // get length
  35331. var length = dict.get('Length');
  35332. if (!isInt(length)) {
  35333. info('Bad ' + length + ' attribute in stream');
  35334. length = 0;
  35335. }
  35336. // skip over the stream data
  35337. stream.pos = pos + length;
  35338. lexer.nextChar();
  35339. // Shift '>>' and check whether the new object marks the end of the stream
  35340. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  35341. this.shift(); // 'stream'
  35342. } else {
  35343. // bad stream length, scanning for endstream
  35344. stream.pos = pos;
  35345. var SCAN_BLOCK_SIZE = 2048;
  35346. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  35347. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  35348. 0x61, 0x6D];
  35349. var skipped = 0, found = false, i, j;
  35350. while (stream.pos < stream.end) {
  35351. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  35352. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  35353. if (scanLength <= 0) {
  35354. break;
  35355. }
  35356. found = false;
  35357. for (i = 0, j = 0; i < scanLength; i++) {
  35358. var b = scanBytes[i];
  35359. if (b !== ENDSTREAM_SIGNATURE[j]) {
  35360. i -= j;
  35361. j = 0;
  35362. } else {
  35363. j++;
  35364. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  35365. i++;
  35366. found = true;
  35367. break;
  35368. }
  35369. }
  35370. }
  35371. if (found) {
  35372. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  35373. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  35374. break;
  35375. }
  35376. skipped += scanLength;
  35377. stream.pos += scanLength;
  35378. }
  35379. if (!found) {
  35380. error('Missing endstream');
  35381. }
  35382. length = skipped;
  35383. lexer.nextChar();
  35384. this.shift();
  35385. this.shift();
  35386. }
  35387. this.shift(); // 'endstream'
  35388. stream = stream.makeSubStream(pos, length, dict);
  35389. if (cipherTransform) {
  35390. stream = cipherTransform.createStream(stream, length);
  35391. }
  35392. stream = this.filter(stream, dict, length);
  35393. stream.dict = dict;
  35394. return stream;
  35395. },
  35396. filter: function Parser_filter(stream, dict, length) {
  35397. var filter = dict.get('Filter', 'F');
  35398. var params = dict.get('DecodeParms', 'DP');
  35399. if (isName(filter)) {
  35400. return this.makeFilter(stream, filter.name, length, params);
  35401. }
  35402. var maybeLength = length;
  35403. if (isArray(filter)) {
  35404. var filterArray = filter;
  35405. var paramsArray = params;
  35406. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  35407. filter = filterArray[i];
  35408. if (!isName(filter)) {
  35409. error('Bad filter name: ' + filter);
  35410. }
  35411. params = null;
  35412. if (isArray(paramsArray) && (i in paramsArray)) {
  35413. params = paramsArray[i];
  35414. }
  35415. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  35416. // after the first stream the length variable is invalid
  35417. maybeLength = null;
  35418. }
  35419. }
  35420. return stream;
  35421. },
  35422. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  35423. if (stream.dict.get('Length') === 0 && !maybeLength) {
  35424. warn('Empty "' + name + '" stream.');
  35425. return new NullStream(stream);
  35426. }
  35427. try {
  35428. if (params && this.xref) {
  35429. params = this.xref.fetchIfRef(params);
  35430. }
  35431. var xrefStreamStats = this.xref.stats.streamTypes;
  35432. if (name === 'FlateDecode' || name === 'Fl') {
  35433. xrefStreamStats[StreamType.FLATE] = true;
  35434. if (params) {
  35435. return new PredictorStream(new FlateStream(stream, maybeLength),
  35436. maybeLength, params);
  35437. }
  35438. return new FlateStream(stream, maybeLength);
  35439. }
  35440. if (name === 'LZWDecode' || name === 'LZW') {
  35441. xrefStreamStats[StreamType.LZW] = true;
  35442. var earlyChange = 1;
  35443. if (params) {
  35444. if (params.has('EarlyChange')) {
  35445. earlyChange = params.get('EarlyChange');
  35446. }
  35447. return new PredictorStream(
  35448. new LZWStream(stream, maybeLength, earlyChange),
  35449. maybeLength, params);
  35450. }
  35451. return new LZWStream(stream, maybeLength, earlyChange);
  35452. }
  35453. if (name === 'DCTDecode' || name === 'DCT') {
  35454. xrefStreamStats[StreamType.DCT] = true;
  35455. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  35456. }
  35457. if (name === 'JPXDecode' || name === 'JPX') {
  35458. xrefStreamStats[StreamType.JPX] = true;
  35459. return new JpxStream(stream, maybeLength, stream.dict);
  35460. }
  35461. if (name === 'ASCII85Decode' || name === 'A85') {
  35462. xrefStreamStats[StreamType.A85] = true;
  35463. return new Ascii85Stream(stream, maybeLength);
  35464. }
  35465. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  35466. xrefStreamStats[StreamType.AHX] = true;
  35467. return new AsciiHexStream(stream, maybeLength);
  35468. }
  35469. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  35470. xrefStreamStats[StreamType.CCF] = true;
  35471. return new CCITTFaxStream(stream, maybeLength, params);
  35472. }
  35473. if (name === 'RunLengthDecode' || name === 'RL') {
  35474. xrefStreamStats[StreamType.RL] = true;
  35475. return new RunLengthStream(stream, maybeLength);
  35476. }
  35477. if (name === 'JBIG2Decode') {
  35478. xrefStreamStats[StreamType.JBIG] = true;
  35479. return new Jbig2Stream(stream, maybeLength, stream.dict);
  35480. }
  35481. warn('filter "' + name + '" not supported yet');
  35482. return stream;
  35483. } catch (ex) {
  35484. if (ex instanceof MissingDataException) {
  35485. throw ex;
  35486. }
  35487. warn('Invalid stream: \"' + ex + '\"');
  35488. return new NullStream(stream);
  35489. }
  35490. }
  35491. };
  35492. return Parser;
  35493. })();
  35494. var Lexer = (function LexerClosure() {
  35495. function Lexer(stream, knownCommands) {
  35496. this.stream = stream;
  35497. this.nextChar();
  35498. // While lexing, we build up many strings one char at a time. Using += for
  35499. // this can result in lots of garbage strings. It's better to build an
  35500. // array of single-char strings and then join() them together at the end.
  35501. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  35502. // purpose uses less memory than using a new array for each string.
  35503. this.strBuf = [];
  35504. // The PDFs might have "glued" commands with other commands, operands or
  35505. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  35506. // commands and their prefixes. The prefixes are built the following way:
  35507. // if there a command that is a prefix of the other valid command or
  35508. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  35509. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  35510. // other commands or literals as a prefix. The knowCommands is optional.
  35511. this.knownCommands = knownCommands;
  35512. }
  35513. Lexer.isSpace = function Lexer_isSpace(ch) {
  35514. // Space is one of the following characters: SPACE, TAB, CR or LF.
  35515. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  35516. };
  35517. // A '1' in this array means the character is white space. A '1' or
  35518. // '2' means the character ends a name or command.
  35519. var specialChars = [
  35520. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  35521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  35522. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  35523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  35524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  35525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  35526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  35527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  35528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  35529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  35530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  35531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  35532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  35533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  35534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  35535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  35536. ];
  35537. function toHexDigit(ch) {
  35538. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  35539. return ch & 0x0F;
  35540. }
  35541. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  35542. // 'A'-'F', 'a'-'f'
  35543. return (ch & 0x0F) + 9;
  35544. }
  35545. return -1;
  35546. }
  35547. Lexer.prototype = {
  35548. nextChar: function Lexer_nextChar() {
  35549. return (this.currentChar = this.stream.getByte());
  35550. },
  35551. peekChar: function Lexer_peekChar() {
  35552. return this.stream.peekByte();
  35553. },
  35554. getNumber: function Lexer_getNumber() {
  35555. var ch = this.currentChar;
  35556. var eNotation = false;
  35557. var divideBy = 0; // different from 0 if it's a floating point value
  35558. var sign = 1;
  35559. if (ch === 0x2D) { // '-'
  35560. sign = -1;
  35561. ch = this.nextChar();
  35562. if (ch === 0x2D) { // '-'
  35563. // Ignore double negative (this is consistent with Adobe Reader).
  35564. ch = this.nextChar();
  35565. }
  35566. } else if (ch === 0x2B) { // '+'
  35567. ch = this.nextChar();
  35568. }
  35569. if (ch === 0x2E) { // '.'
  35570. divideBy = 10;
  35571. ch = this.nextChar();
  35572. }
  35573. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  35574. error('Invalid number: ' + String.fromCharCode(ch));
  35575. return 0;
  35576. }
  35577. var baseValue = ch - 0x30; // '0'
  35578. var powerValue = 0;
  35579. var powerValueSign = 1;
  35580. while ((ch = this.nextChar()) >= 0) {
  35581. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  35582. var currentDigit = ch - 0x30; // '0'
  35583. if (eNotation) { // We are after an 'e' or 'E'
  35584. powerValue = powerValue * 10 + currentDigit;
  35585. } else {
  35586. if (divideBy !== 0) { // We are after a point
  35587. divideBy *= 10;
  35588. }
  35589. baseValue = baseValue * 10 + currentDigit;
  35590. }
  35591. } else if (ch === 0x2E) { // '.'
  35592. if (divideBy === 0) {
  35593. divideBy = 1;
  35594. } else {
  35595. // A number can have only one '.'
  35596. break;
  35597. }
  35598. } else if (ch === 0x2D) { // '-'
  35599. // ignore minus signs in the middle of numbers to match
  35600. // Adobe's behavior
  35601. warn('Badly formated number');
  35602. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  35603. // 'E' can be either a scientific notation or the beginning of a new
  35604. // operator
  35605. ch = this.peekChar();
  35606. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  35607. powerValueSign = (ch === 0x2D) ? -1 : 1;
  35608. this.nextChar(); // Consume the sign character
  35609. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  35610. // The 'E' must be the beginning of a new operator
  35611. break;
  35612. }
  35613. eNotation = true;
  35614. } else {
  35615. // the last character doesn't belong to us
  35616. break;
  35617. }
  35618. }
  35619. if (divideBy !== 0) {
  35620. baseValue /= divideBy;
  35621. }
  35622. if (eNotation) {
  35623. baseValue *= Math.pow(10, powerValueSign * powerValue);
  35624. }
  35625. return sign * baseValue;
  35626. },
  35627. getString: function Lexer_getString() {
  35628. var numParen = 1;
  35629. var done = false;
  35630. var strBuf = this.strBuf;
  35631. strBuf.length = 0;
  35632. var ch = this.nextChar();
  35633. while (true) {
  35634. var charBuffered = false;
  35635. switch (ch | 0) {
  35636. case -1:
  35637. warn('Unterminated string');
  35638. done = true;
  35639. break;
  35640. case 0x28: // '('
  35641. ++numParen;
  35642. strBuf.push('(');
  35643. break;
  35644. case 0x29: // ')'
  35645. if (--numParen === 0) {
  35646. this.nextChar(); // consume strings ')'
  35647. done = true;
  35648. } else {
  35649. strBuf.push(')');
  35650. }
  35651. break;
  35652. case 0x5C: // '\\'
  35653. ch = this.nextChar();
  35654. switch (ch) {
  35655. case -1:
  35656. warn('Unterminated string');
  35657. done = true;
  35658. break;
  35659. case 0x6E: // 'n'
  35660. strBuf.push('\n');
  35661. break;
  35662. case 0x72: // 'r'
  35663. strBuf.push('\r');
  35664. break;
  35665. case 0x74: // 't'
  35666. strBuf.push('\t');
  35667. break;
  35668. case 0x62: // 'b'
  35669. strBuf.push('\b');
  35670. break;
  35671. case 0x66: // 'f'
  35672. strBuf.push('\f');
  35673. break;
  35674. case 0x5C: // '\'
  35675. case 0x28: // '('
  35676. case 0x29: // ')'
  35677. strBuf.push(String.fromCharCode(ch));
  35678. break;
  35679. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  35680. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  35681. var x = ch & 0x0F;
  35682. ch = this.nextChar();
  35683. charBuffered = true;
  35684. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  35685. x = (x << 3) + (ch & 0x0F);
  35686. ch = this.nextChar();
  35687. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  35688. charBuffered = false;
  35689. x = (x << 3) + (ch & 0x0F);
  35690. }
  35691. }
  35692. strBuf.push(String.fromCharCode(x));
  35693. break;
  35694. case 0x0D: // CR
  35695. if (this.peekChar() === 0x0A) { // LF
  35696. this.nextChar();
  35697. }
  35698. break;
  35699. case 0x0A: // LF
  35700. break;
  35701. default:
  35702. strBuf.push(String.fromCharCode(ch));
  35703. break;
  35704. }
  35705. break;
  35706. default:
  35707. strBuf.push(String.fromCharCode(ch));
  35708. break;
  35709. }
  35710. if (done) {
  35711. break;
  35712. }
  35713. if (!charBuffered) {
  35714. ch = this.nextChar();
  35715. }
  35716. }
  35717. return strBuf.join('');
  35718. },
  35719. getName: function Lexer_getName() {
  35720. var ch;
  35721. var strBuf = this.strBuf;
  35722. strBuf.length = 0;
  35723. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  35724. if (ch === 0x23) { // '#'
  35725. ch = this.nextChar();
  35726. var x = toHexDigit(ch);
  35727. if (x !== -1) {
  35728. var x2 = toHexDigit(this.nextChar());
  35729. if (x2 === -1) {
  35730. error('Illegal digit in hex char in name: ' + x2);
  35731. }
  35732. strBuf.push(String.fromCharCode((x << 4) | x2));
  35733. } else {
  35734. strBuf.push('#', String.fromCharCode(ch));
  35735. }
  35736. } else {
  35737. strBuf.push(String.fromCharCode(ch));
  35738. }
  35739. }
  35740. if (strBuf.length > 127) {
  35741. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  35742. }
  35743. return Name.get(strBuf.join(''));
  35744. },
  35745. getHexString: function Lexer_getHexString() {
  35746. var strBuf = this.strBuf;
  35747. strBuf.length = 0;
  35748. var ch = this.currentChar;
  35749. var isFirstHex = true;
  35750. var firstDigit;
  35751. var secondDigit;
  35752. while (true) {
  35753. if (ch < 0) {
  35754. warn('Unterminated hex string');
  35755. break;
  35756. } else if (ch === 0x3E) { // '>'
  35757. this.nextChar();
  35758. break;
  35759. } else if (specialChars[ch] === 1) {
  35760. ch = this.nextChar();
  35761. continue;
  35762. } else {
  35763. if (isFirstHex) {
  35764. firstDigit = toHexDigit(ch);
  35765. if (firstDigit === -1) {
  35766. warn('Ignoring invalid character "' + ch + '" in hex string');
  35767. ch = this.nextChar();
  35768. continue;
  35769. }
  35770. } else {
  35771. secondDigit = toHexDigit(ch);
  35772. if (secondDigit === -1) {
  35773. warn('Ignoring invalid character "' + ch + '" in hex string');
  35774. ch = this.nextChar();
  35775. continue;
  35776. }
  35777. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  35778. }
  35779. isFirstHex = !isFirstHex;
  35780. ch = this.nextChar();
  35781. }
  35782. }
  35783. return strBuf.join('');
  35784. },
  35785. getObj: function Lexer_getObj() {
  35786. // skip whitespace and comments
  35787. var comment = false;
  35788. var ch = this.currentChar;
  35789. while (true) {
  35790. if (ch < 0) {
  35791. return EOF;
  35792. }
  35793. if (comment) {
  35794. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  35795. comment = false;
  35796. }
  35797. } else if (ch === 0x25) { // '%'
  35798. comment = true;
  35799. } else if (specialChars[ch] !== 1) {
  35800. break;
  35801. }
  35802. ch = this.nextChar();
  35803. }
  35804. // start reading token
  35805. switch (ch | 0) {
  35806. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  35807. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  35808. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  35809. return this.getNumber();
  35810. case 0x28: // '('
  35811. return this.getString();
  35812. case 0x2F: // '/'
  35813. return this.getName();
  35814. // array punctuation
  35815. case 0x5B: // '['
  35816. this.nextChar();
  35817. return Cmd.get('[');
  35818. case 0x5D: // ']'
  35819. this.nextChar();
  35820. return Cmd.get(']');
  35821. // hex string or dict punctuation
  35822. case 0x3C: // '<'
  35823. ch = this.nextChar();
  35824. if (ch === 0x3C) {
  35825. // dict punctuation
  35826. this.nextChar();
  35827. return Cmd.get('<<');
  35828. }
  35829. return this.getHexString();
  35830. // dict punctuation
  35831. case 0x3E: // '>'
  35832. ch = this.nextChar();
  35833. if (ch === 0x3E) {
  35834. this.nextChar();
  35835. return Cmd.get('>>');
  35836. }
  35837. return Cmd.get('>');
  35838. case 0x7B: // '{'
  35839. this.nextChar();
  35840. return Cmd.get('{');
  35841. case 0x7D: // '}'
  35842. this.nextChar();
  35843. return Cmd.get('}');
  35844. case 0x29: // ')'
  35845. error('Illegal character: ' + ch);
  35846. break;
  35847. }
  35848. // command
  35849. var str = String.fromCharCode(ch);
  35850. var knownCommands = this.knownCommands;
  35851. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  35852. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  35853. // stop if known command is found and next character does not make
  35854. // the str a command
  35855. var possibleCommand = str + String.fromCharCode(ch);
  35856. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  35857. break;
  35858. }
  35859. if (str.length === 128) {
  35860. error('Command token too long: ' + str.length);
  35861. }
  35862. str = possibleCommand;
  35863. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  35864. }
  35865. if (str === 'true') {
  35866. return true;
  35867. }
  35868. if (str === 'false') {
  35869. return false;
  35870. }
  35871. if (str === 'null') {
  35872. return null;
  35873. }
  35874. return Cmd.get(str);
  35875. },
  35876. skipToNextLine: function Lexer_skipToNextLine() {
  35877. var ch = this.currentChar;
  35878. while (ch >= 0) {
  35879. if (ch === 0x0D) { // CR
  35880. ch = this.nextChar();
  35881. if (ch === 0x0A) { // LF
  35882. this.nextChar();
  35883. }
  35884. break;
  35885. } else if (ch === 0x0A) { // LF
  35886. this.nextChar();
  35887. break;
  35888. }
  35889. ch = this.nextChar();
  35890. }
  35891. }
  35892. };
  35893. return Lexer;
  35894. })();
  35895. var Linearization = {
  35896. create: function LinearizationCreate(stream) {
  35897. function getInt(name, allowZeroValue) {
  35898. var obj = linDict.get(name);
  35899. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  35900. return obj;
  35901. }
  35902. throw new Error('The "' + name + '" parameter in the linearization ' +
  35903. 'dictionary is invalid.');
  35904. }
  35905. function getHints() {
  35906. var hints = linDict.get('H'), hintsLength, item;
  35907. if (isArray(hints) &&
  35908. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  35909. for (var index = 0; index < hintsLength; index++) {
  35910. if (!(isInt(item = hints[index]) && item > 0)) {
  35911. throw new Error('Hint (' + index +
  35912. ') in the linearization dictionary is invalid.');
  35913. }
  35914. }
  35915. return hints;
  35916. }
  35917. throw new Error('Hint array in the linearization dictionary is invalid.');
  35918. }
  35919. var parser = new Parser(new Lexer(stream), false, null);
  35920. var obj1 = parser.getObj();
  35921. var obj2 = parser.getObj();
  35922. var obj3 = parser.getObj();
  35923. var linDict = parser.getObj();
  35924. var obj, length;
  35925. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  35926. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  35927. return null; // No valid linearization dictionary found.
  35928. } else if ((length = getInt('L')) !== stream.length) {
  35929. throw new Error('The "L" parameter in the linearization dictionary ' +
  35930. 'does not equal the stream length.');
  35931. }
  35932. return {
  35933. length: length,
  35934. hints: getHints(),
  35935. objectNumberFirst: getInt('O'),
  35936. endFirst: getInt('E'),
  35937. numPages: getInt('N'),
  35938. mainXRefEntriesOffset: getInt('T'),
  35939. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  35940. };
  35941. }
  35942. };
  35943. var PostScriptParser = (function PostScriptParserClosure() {
  35944. function PostScriptParser(lexer) {
  35945. this.lexer = lexer;
  35946. this.operators = [];
  35947. this.token = null;
  35948. this.prev = null;
  35949. }
  35950. PostScriptParser.prototype = {
  35951. nextToken: function PostScriptParser_nextToken() {
  35952. this.prev = this.token;
  35953. this.token = this.lexer.getToken();
  35954. },
  35955. accept: function PostScriptParser_accept(type) {
  35956. if (this.token.type === type) {
  35957. this.nextToken();
  35958. return true;
  35959. }
  35960. return false;
  35961. },
  35962. expect: function PostScriptParser_expect(type) {
  35963. if (this.accept(type)) {
  35964. return true;
  35965. }
  35966. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  35967. type + '.');
  35968. },
  35969. parse: function PostScriptParser_parse() {
  35970. this.nextToken();
  35971. this.expect(PostScriptTokenTypes.LBRACE);
  35972. this.parseBlock();
  35973. this.expect(PostScriptTokenTypes.RBRACE);
  35974. return this.operators;
  35975. },
  35976. parseBlock: function PostScriptParser_parseBlock() {
  35977. while (true) {
  35978. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  35979. this.operators.push(this.prev.value);
  35980. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  35981. this.operators.push(this.prev.value);
  35982. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  35983. this.parseCondition();
  35984. } else {
  35985. return;
  35986. }
  35987. }
  35988. },
  35989. parseCondition: function PostScriptParser_parseCondition() {
  35990. // Add two place holders that will be updated later
  35991. var conditionLocation = this.operators.length;
  35992. this.operators.push(null, null);
  35993. this.parseBlock();
  35994. this.expect(PostScriptTokenTypes.RBRACE);
  35995. if (this.accept(PostScriptTokenTypes.IF)) {
  35996. // The true block is right after the 'if' so it just falls through on
  35997. // true else it jumps and skips the true block.
  35998. this.operators[conditionLocation] = this.operators.length;
  35999. this.operators[conditionLocation + 1] = 'jz';
  36000. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  36001. var jumpLocation = this.operators.length;
  36002. this.operators.push(null, null);
  36003. var endOfTrue = this.operators.length;
  36004. this.parseBlock();
  36005. this.expect(PostScriptTokenTypes.RBRACE);
  36006. this.expect(PostScriptTokenTypes.IFELSE);
  36007. // The jump is added at the end of the true block to skip the false
  36008. // block.
  36009. this.operators[jumpLocation] = this.operators.length;
  36010. this.operators[jumpLocation + 1] = 'j';
  36011. this.operators[conditionLocation] = endOfTrue;
  36012. this.operators[conditionLocation + 1] = 'jz';
  36013. } else {
  36014. error('PS Function: error parsing conditional.');
  36015. }
  36016. }
  36017. };
  36018. return PostScriptParser;
  36019. })();
  36020. var PostScriptTokenTypes = {
  36021. LBRACE: 0,
  36022. RBRACE: 1,
  36023. NUMBER: 2,
  36024. OPERATOR: 3,
  36025. IF: 4,
  36026. IFELSE: 5
  36027. };
  36028. var PostScriptToken = (function PostScriptTokenClosure() {
  36029. function PostScriptToken(type, value) {
  36030. this.type = type;
  36031. this.value = value;
  36032. }
  36033. var opCache = {};
  36034. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  36035. var opValue = opCache[op];
  36036. if (opValue) {
  36037. return opValue;
  36038. }
  36039. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  36040. };
  36041. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  36042. '{');
  36043. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  36044. '}');
  36045. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  36046. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  36047. 'IFELSE');
  36048. return PostScriptToken;
  36049. })();
  36050. var PostScriptLexer = (function PostScriptLexerClosure() {
  36051. function PostScriptLexer(stream) {
  36052. this.stream = stream;
  36053. this.nextChar();
  36054. this.strBuf = [];
  36055. }
  36056. PostScriptLexer.prototype = {
  36057. nextChar: function PostScriptLexer_nextChar() {
  36058. return (this.currentChar = this.stream.getByte());
  36059. },
  36060. getToken: function PostScriptLexer_getToken() {
  36061. var comment = false;
  36062. var ch = this.currentChar;
  36063. // skip comments
  36064. while (true) {
  36065. if (ch < 0) {
  36066. return EOF;
  36067. }
  36068. if (comment) {
  36069. if (ch === 0x0A || ch === 0x0D) {
  36070. comment = false;
  36071. }
  36072. } else if (ch === 0x25) { // '%'
  36073. comment = true;
  36074. } else if (!Lexer.isSpace(ch)) {
  36075. break;
  36076. }
  36077. ch = this.nextChar();
  36078. }
  36079. switch (ch | 0) {
  36080. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  36081. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  36082. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  36083. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  36084. this.getNumber());
  36085. case 0x7B: // '{'
  36086. this.nextChar();
  36087. return PostScriptToken.LBRACE;
  36088. case 0x7D: // '}'
  36089. this.nextChar();
  36090. return PostScriptToken.RBRACE;
  36091. }
  36092. // operator
  36093. var strBuf = this.strBuf;
  36094. strBuf.length = 0;
  36095. strBuf[0] = String.fromCharCode(ch);
  36096. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  36097. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  36098. strBuf.push(String.fromCharCode(ch));
  36099. }
  36100. var str = strBuf.join('');
  36101. switch (str.toLowerCase()) {
  36102. case 'if':
  36103. return PostScriptToken.IF;
  36104. case 'ifelse':
  36105. return PostScriptToken.IFELSE;
  36106. default:
  36107. return PostScriptToken.getOperator(str);
  36108. }
  36109. },
  36110. getNumber: function PostScriptLexer_getNumber() {
  36111. var ch = this.currentChar;
  36112. var strBuf = this.strBuf;
  36113. strBuf.length = 0;
  36114. strBuf[0] = String.fromCharCode(ch);
  36115. while ((ch = this.nextChar()) >= 0) {
  36116. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  36117. ch === 0x2D || ch === 0x2E) { // '-', '.'
  36118. strBuf.push(String.fromCharCode(ch));
  36119. } else {
  36120. break;
  36121. }
  36122. }
  36123. var value = parseFloat(strBuf.join(''));
  36124. if (isNaN(value)) {
  36125. error('Invalid floating point number: ' + value);
  36126. }
  36127. return value;
  36128. }
  36129. };
  36130. return PostScriptLexer;
  36131. })();
  36132. var Stream = (function StreamClosure() {
  36133. function Stream(arrayBuffer, start, length, dict) {
  36134. this.bytes = (arrayBuffer instanceof Uint8Array ?
  36135. arrayBuffer : new Uint8Array(arrayBuffer));
  36136. this.start = start || 0;
  36137. this.pos = this.start;
  36138. this.end = (start + length) || this.bytes.length;
  36139. this.dict = dict;
  36140. }
  36141. // required methods for a stream. if a particular stream does not
  36142. // implement these, an error should be thrown
  36143. Stream.prototype = {
  36144. get length() {
  36145. return this.end - this.start;
  36146. },
  36147. get isEmpty() {
  36148. return this.length === 0;
  36149. },
  36150. getByte: function Stream_getByte() {
  36151. if (this.pos >= this.end) {
  36152. return -1;
  36153. }
  36154. return this.bytes[this.pos++];
  36155. },
  36156. getUint16: function Stream_getUint16() {
  36157. var b0 = this.getByte();
  36158. var b1 = this.getByte();
  36159. if (b0 === -1 || b1 === -1) {
  36160. return -1;
  36161. }
  36162. return (b0 << 8) + b1;
  36163. },
  36164. getInt32: function Stream_getInt32() {
  36165. var b0 = this.getByte();
  36166. var b1 = this.getByte();
  36167. var b2 = this.getByte();
  36168. var b3 = this.getByte();
  36169. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  36170. },
  36171. // returns subarray of original buffer
  36172. // should only be read
  36173. getBytes: function Stream_getBytes(length) {
  36174. var bytes = this.bytes;
  36175. var pos = this.pos;
  36176. var strEnd = this.end;
  36177. if (!length) {
  36178. return bytes.subarray(pos, strEnd);
  36179. }
  36180. var end = pos + length;
  36181. if (end > strEnd) {
  36182. end = strEnd;
  36183. }
  36184. this.pos = end;
  36185. return bytes.subarray(pos, end);
  36186. },
  36187. peekByte: function Stream_peekByte() {
  36188. var peekedByte = this.getByte();
  36189. this.pos--;
  36190. return peekedByte;
  36191. },
  36192. peekBytes: function Stream_peekBytes(length) {
  36193. var bytes = this.getBytes(length);
  36194. this.pos -= bytes.length;
  36195. return bytes;
  36196. },
  36197. skip: function Stream_skip(n) {
  36198. if (!n) {
  36199. n = 1;
  36200. }
  36201. this.pos += n;
  36202. },
  36203. reset: function Stream_reset() {
  36204. this.pos = this.start;
  36205. },
  36206. moveStart: function Stream_moveStart() {
  36207. this.start = this.pos;
  36208. },
  36209. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  36210. return new Stream(this.bytes.buffer, start, length, dict);
  36211. },
  36212. isStream: true
  36213. };
  36214. return Stream;
  36215. })();
  36216. var StringStream = (function StringStreamClosure() {
  36217. function StringStream(str) {
  36218. var length = str.length;
  36219. var bytes = new Uint8Array(length);
  36220. for (var n = 0; n < length; ++n) {
  36221. bytes[n] = str.charCodeAt(n);
  36222. }
  36223. Stream.call(this, bytes);
  36224. }
  36225. StringStream.prototype = Stream.prototype;
  36226. return StringStream;
  36227. })();
  36228. // super class for the decoding streams
  36229. var DecodeStream = (function DecodeStreamClosure() {
  36230. // Lots of DecodeStreams are created whose buffers are never used. For these
  36231. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  36232. // having special cases that would be required if we used |null| for an empty
  36233. // buffer.
  36234. var emptyBuffer = new Uint8Array(0);
  36235. function DecodeStream(maybeMinBufferLength) {
  36236. this.pos = 0;
  36237. this.bufferLength = 0;
  36238. this.eof = false;
  36239. this.buffer = emptyBuffer;
  36240. this.minBufferLength = 512;
  36241. if (maybeMinBufferLength) {
  36242. // Compute the first power of two that is as big as maybeMinBufferLength.
  36243. while (this.minBufferLength < maybeMinBufferLength) {
  36244. this.minBufferLength *= 2;
  36245. }
  36246. }
  36247. }
  36248. DecodeStream.prototype = {
  36249. get isEmpty() {
  36250. while (!this.eof && this.bufferLength === 0) {
  36251. this.readBlock();
  36252. }
  36253. return this.bufferLength === 0;
  36254. },
  36255. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  36256. var buffer = this.buffer;
  36257. if (requested <= buffer.byteLength) {
  36258. return buffer;
  36259. }
  36260. var size = this.minBufferLength;
  36261. while (size < requested) {
  36262. size *= 2;
  36263. }
  36264. var buffer2 = new Uint8Array(size);
  36265. buffer2.set(buffer);
  36266. return (this.buffer = buffer2);
  36267. },
  36268. getByte: function DecodeStream_getByte() {
  36269. var pos = this.pos;
  36270. while (this.bufferLength <= pos) {
  36271. if (this.eof) {
  36272. return -1;
  36273. }
  36274. this.readBlock();
  36275. }
  36276. return this.buffer[this.pos++];
  36277. },
  36278. getUint16: function DecodeStream_getUint16() {
  36279. var b0 = this.getByte();
  36280. var b1 = this.getByte();
  36281. if (b0 === -1 || b1 === -1) {
  36282. return -1;
  36283. }
  36284. return (b0 << 8) + b1;
  36285. },
  36286. getInt32: function DecodeStream_getInt32() {
  36287. var b0 = this.getByte();
  36288. var b1 = this.getByte();
  36289. var b2 = this.getByte();
  36290. var b3 = this.getByte();
  36291. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  36292. },
  36293. getBytes: function DecodeStream_getBytes(length) {
  36294. var end, pos = this.pos;
  36295. if (length) {
  36296. this.ensureBuffer(pos + length);
  36297. end = pos + length;
  36298. while (!this.eof && this.bufferLength < end) {
  36299. this.readBlock();
  36300. }
  36301. var bufEnd = this.bufferLength;
  36302. if (end > bufEnd) {
  36303. end = bufEnd;
  36304. }
  36305. } else {
  36306. while (!this.eof) {
  36307. this.readBlock();
  36308. }
  36309. end = this.bufferLength;
  36310. }
  36311. this.pos = end;
  36312. return this.buffer.subarray(pos, end);
  36313. },
  36314. peekByte: function DecodeStream_peekByte() {
  36315. var peekedByte = this.getByte();
  36316. this.pos--;
  36317. return peekedByte;
  36318. },
  36319. peekBytes: function DecodeStream_peekBytes(length) {
  36320. var bytes = this.getBytes(length);
  36321. this.pos -= bytes.length;
  36322. return bytes;
  36323. },
  36324. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  36325. var end = start + length;
  36326. while (this.bufferLength <= end && !this.eof) {
  36327. this.readBlock();
  36328. }
  36329. return new Stream(this.buffer, start, length, dict);
  36330. },
  36331. skip: function DecodeStream_skip(n) {
  36332. if (!n) {
  36333. n = 1;
  36334. }
  36335. this.pos += n;
  36336. },
  36337. reset: function DecodeStream_reset() {
  36338. this.pos = 0;
  36339. },
  36340. getBaseStreams: function DecodeStream_getBaseStreams() {
  36341. if (this.str && this.str.getBaseStreams) {
  36342. return this.str.getBaseStreams();
  36343. }
  36344. return [];
  36345. }
  36346. };
  36347. return DecodeStream;
  36348. })();
  36349. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  36350. function StreamsSequenceStream(streams) {
  36351. this.streams = streams;
  36352. DecodeStream.call(this, /* maybeLength = */ null);
  36353. }
  36354. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  36355. StreamsSequenceStream.prototype.readBlock =
  36356. function streamSequenceStreamReadBlock() {
  36357. var streams = this.streams;
  36358. if (streams.length === 0) {
  36359. this.eof = true;
  36360. return;
  36361. }
  36362. var stream = streams.shift();
  36363. var chunk = stream.getBytes();
  36364. var bufferLength = this.bufferLength;
  36365. var newLength = bufferLength + chunk.length;
  36366. var buffer = this.ensureBuffer(newLength);
  36367. buffer.set(chunk, bufferLength);
  36368. this.bufferLength = newLength;
  36369. };
  36370. StreamsSequenceStream.prototype.getBaseStreams =
  36371. function StreamsSequenceStream_getBaseStreams() {
  36372. var baseStreams = [];
  36373. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  36374. var stream = this.streams[i];
  36375. if (stream.getBaseStreams) {
  36376. Util.appendToArray(baseStreams, stream.getBaseStreams());
  36377. }
  36378. }
  36379. return baseStreams;
  36380. };
  36381. return StreamsSequenceStream;
  36382. })();
  36383. var FlateStream = (function FlateStreamClosure() {
  36384. var codeLenCodeMap = new Int32Array([
  36385. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  36386. ]);
  36387. var lengthDecode = new Int32Array([
  36388. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  36389. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  36390. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  36391. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  36392. ]);
  36393. var distDecode = new Int32Array([
  36394. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  36395. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  36396. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  36397. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  36398. ]);
  36399. var fixedLitCodeTab = [new Int32Array([
  36400. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  36401. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  36402. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  36403. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  36404. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  36405. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  36406. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  36407. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  36408. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  36409. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  36410. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  36411. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  36412. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  36413. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  36414. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  36415. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  36416. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  36417. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  36418. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  36419. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  36420. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  36421. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  36422. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  36423. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  36424. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  36425. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  36426. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  36427. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  36428. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  36429. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  36430. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  36431. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  36432. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  36433. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  36434. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  36435. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  36436. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  36437. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  36438. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  36439. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  36440. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  36441. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  36442. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  36443. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  36444. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  36445. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  36446. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  36447. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  36448. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  36449. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  36450. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  36451. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  36452. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  36453. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  36454. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  36455. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  36456. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  36457. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  36458. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  36459. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  36460. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  36461. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  36462. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  36463. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  36464. ]), 9];
  36465. var fixedDistCodeTab = [new Int32Array([
  36466. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  36467. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  36468. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  36469. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  36470. ]), 5];
  36471. function FlateStream(str, maybeLength) {
  36472. this.str = str;
  36473. this.dict = str.dict;
  36474. var cmf = str.getByte();
  36475. var flg = str.getByte();
  36476. if (cmf === -1 || flg === -1) {
  36477. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  36478. }
  36479. if ((cmf & 0x0f) !== 0x08) {
  36480. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  36481. }
  36482. if ((((cmf << 8) + flg) % 31) !== 0) {
  36483. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  36484. }
  36485. if (flg & 0x20) {
  36486. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  36487. }
  36488. this.codeSize = 0;
  36489. this.codeBuf = 0;
  36490. DecodeStream.call(this, maybeLength);
  36491. }
  36492. FlateStream.prototype = Object.create(DecodeStream.prototype);
  36493. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  36494. var str = this.str;
  36495. var codeSize = this.codeSize;
  36496. var codeBuf = this.codeBuf;
  36497. var b;
  36498. while (codeSize < bits) {
  36499. if ((b = str.getByte()) === -1) {
  36500. error('Bad encoding in flate stream');
  36501. }
  36502. codeBuf |= b << codeSize;
  36503. codeSize += 8;
  36504. }
  36505. b = codeBuf & ((1 << bits) - 1);
  36506. this.codeBuf = codeBuf >> bits;
  36507. this.codeSize = codeSize -= bits;
  36508. return b;
  36509. };
  36510. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  36511. var str = this.str;
  36512. var codes = table[0];
  36513. var maxLen = table[1];
  36514. var codeSize = this.codeSize;
  36515. var codeBuf = this.codeBuf;
  36516. var b;
  36517. while (codeSize < maxLen) {
  36518. if ((b = str.getByte()) === -1) {
  36519. // premature end of stream. code might however still be valid.
  36520. // codeSize < codeLen check below guards against incomplete codeVal.
  36521. break;
  36522. }
  36523. codeBuf |= (b << codeSize);
  36524. codeSize += 8;
  36525. }
  36526. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  36527. var codeLen = code >> 16;
  36528. var codeVal = code & 0xffff;
  36529. if (codeLen < 1 || codeSize < codeLen) {
  36530. error('Bad encoding in flate stream');
  36531. }
  36532. this.codeBuf = (codeBuf >> codeLen);
  36533. this.codeSize = (codeSize - codeLen);
  36534. return codeVal;
  36535. };
  36536. FlateStream.prototype.generateHuffmanTable =
  36537. function flateStreamGenerateHuffmanTable(lengths) {
  36538. var n = lengths.length;
  36539. // find max code length
  36540. var maxLen = 0;
  36541. var i;
  36542. for (i = 0; i < n; ++i) {
  36543. if (lengths[i] > maxLen) {
  36544. maxLen = lengths[i];
  36545. }
  36546. }
  36547. // build the table
  36548. var size = 1 << maxLen;
  36549. var codes = new Int32Array(size);
  36550. for (var len = 1, code = 0, skip = 2;
  36551. len <= maxLen;
  36552. ++len, code <<= 1, skip <<= 1) {
  36553. for (var val = 0; val < n; ++val) {
  36554. if (lengths[val] === len) {
  36555. // bit-reverse the code
  36556. var code2 = 0;
  36557. var t = code;
  36558. for (i = 0; i < len; ++i) {
  36559. code2 = (code2 << 1) | (t & 1);
  36560. t >>= 1;
  36561. }
  36562. // fill the table entries
  36563. for (i = code2; i < size; i += skip) {
  36564. codes[i] = (len << 16) | val;
  36565. }
  36566. ++code;
  36567. }
  36568. }
  36569. }
  36570. return [codes, maxLen];
  36571. };
  36572. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  36573. var buffer, len;
  36574. var str = this.str;
  36575. // read block header
  36576. var hdr = this.getBits(3);
  36577. if (hdr & 1) {
  36578. this.eof = true;
  36579. }
  36580. hdr >>= 1;
  36581. if (hdr === 0) { // uncompressed block
  36582. var b;
  36583. if ((b = str.getByte()) === -1) {
  36584. error('Bad block header in flate stream');
  36585. }
  36586. var blockLen = b;
  36587. if ((b = str.getByte()) === -1) {
  36588. error('Bad block header in flate stream');
  36589. }
  36590. blockLen |= (b << 8);
  36591. if ((b = str.getByte()) === -1) {
  36592. error('Bad block header in flate stream');
  36593. }
  36594. var check = b;
  36595. if ((b = str.getByte()) === -1) {
  36596. error('Bad block header in flate stream');
  36597. }
  36598. check |= (b << 8);
  36599. if (check !== (~blockLen & 0xffff) &&
  36600. (blockLen !== 0 || check !== 0)) {
  36601. // Ignoring error for bad "empty" block (see issue 1277)
  36602. error('Bad uncompressed block length in flate stream');
  36603. }
  36604. this.codeBuf = 0;
  36605. this.codeSize = 0;
  36606. var bufferLength = this.bufferLength;
  36607. buffer = this.ensureBuffer(bufferLength + blockLen);
  36608. var end = bufferLength + blockLen;
  36609. this.bufferLength = end;
  36610. if (blockLen === 0) {
  36611. if (str.peekByte() === -1) {
  36612. this.eof = true;
  36613. }
  36614. } else {
  36615. for (var n = bufferLength; n < end; ++n) {
  36616. if ((b = str.getByte()) === -1) {
  36617. this.eof = true;
  36618. break;
  36619. }
  36620. buffer[n] = b;
  36621. }
  36622. }
  36623. return;
  36624. }
  36625. var litCodeTable;
  36626. var distCodeTable;
  36627. if (hdr === 1) { // compressed block, fixed codes
  36628. litCodeTable = fixedLitCodeTab;
  36629. distCodeTable = fixedDistCodeTab;
  36630. } else if (hdr === 2) { // compressed block, dynamic codes
  36631. var numLitCodes = this.getBits(5) + 257;
  36632. var numDistCodes = this.getBits(5) + 1;
  36633. var numCodeLenCodes = this.getBits(4) + 4;
  36634. // build the code lengths code table
  36635. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  36636. var i;
  36637. for (i = 0; i < numCodeLenCodes; ++i) {
  36638. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  36639. }
  36640. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  36641. // build the literal and distance code tables
  36642. len = 0;
  36643. i = 0;
  36644. var codes = numLitCodes + numDistCodes;
  36645. var codeLengths = new Uint8Array(codes);
  36646. var bitsLength, bitsOffset, what;
  36647. while (i < codes) {
  36648. var code = this.getCode(codeLenCodeTab);
  36649. if (code === 16) {
  36650. bitsLength = 2; bitsOffset = 3; what = len;
  36651. } else if (code === 17) {
  36652. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  36653. } else if (code === 18) {
  36654. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  36655. } else {
  36656. codeLengths[i++] = len = code;
  36657. continue;
  36658. }
  36659. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  36660. while (repeatLength-- > 0) {
  36661. codeLengths[i++] = what;
  36662. }
  36663. }
  36664. litCodeTable =
  36665. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  36666. distCodeTable =
  36667. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  36668. } else {
  36669. error('Unknown block type in flate stream');
  36670. }
  36671. buffer = this.buffer;
  36672. var limit = buffer ? buffer.length : 0;
  36673. var pos = this.bufferLength;
  36674. while (true) {
  36675. var code1 = this.getCode(litCodeTable);
  36676. if (code1 < 256) {
  36677. if (pos + 1 >= limit) {
  36678. buffer = this.ensureBuffer(pos + 1);
  36679. limit = buffer.length;
  36680. }
  36681. buffer[pos++] = code1;
  36682. continue;
  36683. }
  36684. if (code1 === 256) {
  36685. this.bufferLength = pos;
  36686. return;
  36687. }
  36688. code1 -= 257;
  36689. code1 = lengthDecode[code1];
  36690. var code2 = code1 >> 16;
  36691. if (code2 > 0) {
  36692. code2 = this.getBits(code2);
  36693. }
  36694. len = (code1 & 0xffff) + code2;
  36695. code1 = this.getCode(distCodeTable);
  36696. code1 = distDecode[code1];
  36697. code2 = code1 >> 16;
  36698. if (code2 > 0) {
  36699. code2 = this.getBits(code2);
  36700. }
  36701. var dist = (code1 & 0xffff) + code2;
  36702. if (pos + len >= limit) {
  36703. buffer = this.ensureBuffer(pos + len);
  36704. limit = buffer.length;
  36705. }
  36706. for (var k = 0; k < len; ++k, ++pos) {
  36707. buffer[pos] = buffer[pos - dist];
  36708. }
  36709. }
  36710. };
  36711. return FlateStream;
  36712. })();
  36713. var PredictorStream = (function PredictorStreamClosure() {
  36714. function PredictorStream(str, maybeLength, params) {
  36715. var predictor = this.predictor = params.get('Predictor') || 1;
  36716. if (predictor <= 1) {
  36717. return str; // no prediction
  36718. }
  36719. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  36720. error('Unsupported predictor: ' + predictor);
  36721. }
  36722. if (predictor === 2) {
  36723. this.readBlock = this.readBlockTiff;
  36724. } else {
  36725. this.readBlock = this.readBlockPng;
  36726. }
  36727. this.str = str;
  36728. this.dict = str.dict;
  36729. var colors = this.colors = params.get('Colors') || 1;
  36730. var bits = this.bits = params.get('BitsPerComponent') || 8;
  36731. var columns = this.columns = params.get('Columns') || 1;
  36732. this.pixBytes = (colors * bits + 7) >> 3;
  36733. this.rowBytes = (columns * colors * bits + 7) >> 3;
  36734. DecodeStream.call(this, maybeLength);
  36735. return this;
  36736. }
  36737. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  36738. PredictorStream.prototype.readBlockTiff =
  36739. function predictorStreamReadBlockTiff() {
  36740. var rowBytes = this.rowBytes;
  36741. var bufferLength = this.bufferLength;
  36742. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  36743. var bits = this.bits;
  36744. var colors = this.colors;
  36745. var rawBytes = this.str.getBytes(rowBytes);
  36746. this.eof = !rawBytes.length;
  36747. if (this.eof) {
  36748. return;
  36749. }
  36750. var inbuf = 0, outbuf = 0;
  36751. var inbits = 0, outbits = 0;
  36752. var pos = bufferLength;
  36753. var i;
  36754. if (bits === 1) {
  36755. for (i = 0; i < rowBytes; ++i) {
  36756. var c = rawBytes[i];
  36757. inbuf = (inbuf << 8) | c;
  36758. // bitwise addition is exclusive or
  36759. // first shift inbuf and then add
  36760. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  36761. // truncate inbuf (assumes colors < 16)
  36762. inbuf &= 0xFFFF;
  36763. }
  36764. } else if (bits === 8) {
  36765. for (i = 0; i < colors; ++i) {
  36766. buffer[pos++] = rawBytes[i];
  36767. }
  36768. for (; i < rowBytes; ++i) {
  36769. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  36770. pos++;
  36771. }
  36772. } else {
  36773. var compArray = new Uint8Array(colors + 1);
  36774. var bitMask = (1 << bits) - 1;
  36775. var j = 0, k = bufferLength;
  36776. var columns = this.columns;
  36777. for (i = 0; i < columns; ++i) {
  36778. for (var kk = 0; kk < colors; ++kk) {
  36779. if (inbits < bits) {
  36780. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  36781. inbits += 8;
  36782. }
  36783. compArray[kk] = (compArray[kk] +
  36784. (inbuf >> (inbits - bits))) & bitMask;
  36785. inbits -= bits;
  36786. outbuf = (outbuf << bits) | compArray[kk];
  36787. outbits += bits;
  36788. if (outbits >= 8) {
  36789. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  36790. outbits -= 8;
  36791. }
  36792. }
  36793. }
  36794. if (outbits > 0) {
  36795. buffer[k++] = (outbuf << (8 - outbits)) +
  36796. (inbuf & ((1 << (8 - outbits)) - 1));
  36797. }
  36798. }
  36799. this.bufferLength += rowBytes;
  36800. };
  36801. PredictorStream.prototype.readBlockPng =
  36802. function predictorStreamReadBlockPng() {
  36803. var rowBytes = this.rowBytes;
  36804. var pixBytes = this.pixBytes;
  36805. var predictor = this.str.getByte();
  36806. var rawBytes = this.str.getBytes(rowBytes);
  36807. this.eof = !rawBytes.length;
  36808. if (this.eof) {
  36809. return;
  36810. }
  36811. var bufferLength = this.bufferLength;
  36812. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  36813. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  36814. if (prevRow.length === 0) {
  36815. prevRow = new Uint8Array(rowBytes);
  36816. }
  36817. var i, j = bufferLength, up, c;
  36818. switch (predictor) {
  36819. case 0:
  36820. for (i = 0; i < rowBytes; ++i) {
  36821. buffer[j++] = rawBytes[i];
  36822. }
  36823. break;
  36824. case 1:
  36825. for (i = 0; i < pixBytes; ++i) {
  36826. buffer[j++] = rawBytes[i];
  36827. }
  36828. for (; i < rowBytes; ++i) {
  36829. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  36830. j++;
  36831. }
  36832. break;
  36833. case 2:
  36834. for (i = 0; i < rowBytes; ++i) {
  36835. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  36836. }
  36837. break;
  36838. case 3:
  36839. for (i = 0; i < pixBytes; ++i) {
  36840. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  36841. }
  36842. for (; i < rowBytes; ++i) {
  36843. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  36844. rawBytes[i]) & 0xFF;
  36845. j++;
  36846. }
  36847. break;
  36848. case 4:
  36849. // we need to save the up left pixels values. the simplest way
  36850. // is to create a new buffer
  36851. for (i = 0; i < pixBytes; ++i) {
  36852. up = prevRow[i];
  36853. c = rawBytes[i];
  36854. buffer[j++] = up + c;
  36855. }
  36856. for (; i < rowBytes; ++i) {
  36857. up = prevRow[i];
  36858. var upLeft = prevRow[i - pixBytes];
  36859. var left = buffer[j - pixBytes];
  36860. var p = left + up - upLeft;
  36861. var pa = p - left;
  36862. if (pa < 0) {
  36863. pa = -pa;
  36864. }
  36865. var pb = p - up;
  36866. if (pb < 0) {
  36867. pb = -pb;
  36868. }
  36869. var pc = p - upLeft;
  36870. if (pc < 0) {
  36871. pc = -pc;
  36872. }
  36873. c = rawBytes[i];
  36874. if (pa <= pb && pa <= pc) {
  36875. buffer[j++] = left + c;
  36876. } else if (pb <= pc) {
  36877. buffer[j++] = up + c;
  36878. } else {
  36879. buffer[j++] = upLeft + c;
  36880. }
  36881. }
  36882. break;
  36883. default:
  36884. error('Unsupported predictor: ' + predictor);
  36885. }
  36886. this.bufferLength += rowBytes;
  36887. };
  36888. return PredictorStream;
  36889. })();
  36890. /**
  36891. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  36892. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  36893. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  36894. * a library to decode these images and the stream behaves like all the other
  36895. * DecodeStreams.
  36896. */
  36897. var JpegStream = (function JpegStreamClosure() {
  36898. function JpegStream(stream, maybeLength, dict, xref) {
  36899. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  36900. // Note: this seems to mainly affect inline images.
  36901. var ch;
  36902. while ((ch = stream.getByte()) !== -1) {
  36903. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  36904. stream.skip(-1); // Reset the stream position to the SOI.
  36905. break;
  36906. }
  36907. }
  36908. this.stream = stream;
  36909. this.maybeLength = maybeLength;
  36910. this.dict = dict;
  36911. DecodeStream.call(this, maybeLength);
  36912. }
  36913. JpegStream.prototype = Object.create(DecodeStream.prototype);
  36914. Object.defineProperty(JpegStream.prototype, 'bytes', {
  36915. get: function JpegStream_bytes() {
  36916. // If this.maybeLength is null, we'll get the entire stream.
  36917. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  36918. },
  36919. configurable: true
  36920. });
  36921. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  36922. if (this.bufferLength) {
  36923. return;
  36924. }
  36925. try {
  36926. var jpegImage = new JpegImage();
  36927. // checking if values needs to be transformed before conversion
  36928. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  36929. var decodeArr = this.dict.get('Decode');
  36930. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  36931. var decodeArrLength = decodeArr.length;
  36932. var transform = new Int32Array(decodeArrLength);
  36933. var transformNeeded = false;
  36934. var maxValue = (1 << bitsPerComponent) - 1;
  36935. for (var i = 0; i < decodeArrLength; i += 2) {
  36936. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  36937. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  36938. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  36939. transformNeeded = true;
  36940. }
  36941. }
  36942. if (transformNeeded) {
  36943. jpegImage.decodeTransform = transform;
  36944. }
  36945. }
  36946. jpegImage.parse(this.bytes);
  36947. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  36948. this.forceRGB);
  36949. this.buffer = data;
  36950. this.bufferLength = data.length;
  36951. this.eof = true;
  36952. } catch (e) {
  36953. error('JPEG error: ' + e);
  36954. }
  36955. };
  36956. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  36957. this.ensureBuffer();
  36958. return this.buffer;
  36959. };
  36960. JpegStream.prototype.getIR = function JpegStream_getIR() {
  36961. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  36962. };
  36963. /**
  36964. * Checks if the image can be decoded and displayed by the browser without any
  36965. * further processing such as color space conversions.
  36966. */
  36967. JpegStream.prototype.isNativelySupported =
  36968. function JpegStream_isNativelySupported(xref, res) {
  36969. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  36970. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  36971. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  36972. };
  36973. /**
  36974. * Checks if the image can be decoded by the browser.
  36975. */
  36976. JpegStream.prototype.isNativelyDecodable =
  36977. function JpegStream_isNativelyDecodable(xref, res) {
  36978. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  36979. return (cs.numComps === 1 || cs.numComps === 3) &&
  36980. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  36981. };
  36982. return JpegStream;
  36983. })();
  36984. /**
  36985. * For JPEG 2000's we use a library to decode these images and
  36986. * the stream behaves like all the other DecodeStreams.
  36987. */
  36988. var JpxStream = (function JpxStreamClosure() {
  36989. function JpxStream(stream, maybeLength, dict) {
  36990. this.stream = stream;
  36991. this.maybeLength = maybeLength;
  36992. this.dict = dict;
  36993. DecodeStream.call(this, maybeLength);
  36994. }
  36995. JpxStream.prototype = Object.create(DecodeStream.prototype);
  36996. Object.defineProperty(JpxStream.prototype, 'bytes', {
  36997. get: function JpxStream_bytes() {
  36998. // If this.maybeLength is null, we'll get the entire stream.
  36999. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  37000. },
  37001. configurable: true
  37002. });
  37003. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  37004. if (this.bufferLength) {
  37005. return;
  37006. }
  37007. var jpxImage = new JpxImage();
  37008. jpxImage.parse(this.bytes);
  37009. var width = jpxImage.width;
  37010. var height = jpxImage.height;
  37011. var componentsCount = jpxImage.componentsCount;
  37012. var tileCount = jpxImage.tiles.length;
  37013. if (tileCount === 1) {
  37014. this.buffer = jpxImage.tiles[0].items;
  37015. } else {
  37016. var data = new Uint8Array(width * height * componentsCount);
  37017. for (var k = 0; k < tileCount; k++) {
  37018. var tileComponents = jpxImage.tiles[k];
  37019. var tileWidth = tileComponents.width;
  37020. var tileHeight = tileComponents.height;
  37021. var tileLeft = tileComponents.left;
  37022. var tileTop = tileComponents.top;
  37023. var src = tileComponents.items;
  37024. var srcPosition = 0;
  37025. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  37026. var imgRowSize = width * componentsCount;
  37027. var tileRowSize = tileWidth * componentsCount;
  37028. for (var j = 0; j < tileHeight; j++) {
  37029. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  37030. data.set(rowBytes, dataPosition);
  37031. srcPosition += tileRowSize;
  37032. dataPosition += imgRowSize;
  37033. }
  37034. }
  37035. this.buffer = data;
  37036. }
  37037. this.bufferLength = this.buffer.length;
  37038. this.eof = true;
  37039. };
  37040. return JpxStream;
  37041. })();
  37042. /**
  37043. * For JBIG2's we use a library to decode these images and
  37044. * the stream behaves like all the other DecodeStreams.
  37045. */
  37046. var Jbig2Stream = (function Jbig2StreamClosure() {
  37047. function Jbig2Stream(stream, maybeLength, dict) {
  37048. this.stream = stream;
  37049. this.maybeLength = maybeLength;
  37050. this.dict = dict;
  37051. DecodeStream.call(this, maybeLength);
  37052. }
  37053. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  37054. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  37055. get: function Jbig2Stream_bytes() {
  37056. // If this.maybeLength is null, we'll get the entire stream.
  37057. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  37058. },
  37059. configurable: true
  37060. });
  37061. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  37062. if (this.bufferLength) {
  37063. return;
  37064. }
  37065. var jbig2Image = new Jbig2Image();
  37066. var chunks = [], xref = this.dict.xref;
  37067. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  37068. // According to the PDF specification, DecodeParms can be either
  37069. // a dictionary, or an array whose elements are dictionaries.
  37070. if (isArray(decodeParams)) {
  37071. if (decodeParams.length > 1) {
  37072. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  37073. 'not supported.');
  37074. }
  37075. decodeParams = xref.fetchIfRef(decodeParams[0]);
  37076. }
  37077. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  37078. var globalsStream = decodeParams.get('JBIG2Globals');
  37079. var globals = globalsStream.getBytes();
  37080. chunks.push({data: globals, start: 0, end: globals.length});
  37081. }
  37082. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  37083. var data = jbig2Image.parseChunks(chunks);
  37084. var dataLength = data.length;
  37085. // JBIG2 had black as 1 and white as 0, inverting the colors
  37086. for (var i = 0; i < dataLength; i++) {
  37087. data[i] ^= 0xFF;
  37088. }
  37089. this.buffer = data;
  37090. this.bufferLength = dataLength;
  37091. this.eof = true;
  37092. };
  37093. return Jbig2Stream;
  37094. })();
  37095. var DecryptStream = (function DecryptStreamClosure() {
  37096. function DecryptStream(str, maybeLength, decrypt) {
  37097. this.str = str;
  37098. this.dict = str.dict;
  37099. this.decrypt = decrypt;
  37100. this.nextChunk = null;
  37101. this.initialized = false;
  37102. DecodeStream.call(this, maybeLength);
  37103. }
  37104. var chunkSize = 512;
  37105. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  37106. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  37107. var chunk;
  37108. if (this.initialized) {
  37109. chunk = this.nextChunk;
  37110. } else {
  37111. chunk = this.str.getBytes(chunkSize);
  37112. this.initialized = true;
  37113. }
  37114. if (!chunk || chunk.length === 0) {
  37115. this.eof = true;
  37116. return;
  37117. }
  37118. this.nextChunk = this.str.getBytes(chunkSize);
  37119. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  37120. var decrypt = this.decrypt;
  37121. chunk = decrypt(chunk, !hasMoreData);
  37122. var bufferLength = this.bufferLength;
  37123. var i, n = chunk.length;
  37124. var buffer = this.ensureBuffer(bufferLength + n);
  37125. for (i = 0; i < n; i++) {
  37126. buffer[bufferLength++] = chunk[i];
  37127. }
  37128. this.bufferLength = bufferLength;
  37129. };
  37130. return DecryptStream;
  37131. })();
  37132. var Ascii85Stream = (function Ascii85StreamClosure() {
  37133. function Ascii85Stream(str, maybeLength) {
  37134. this.str = str;
  37135. this.dict = str.dict;
  37136. this.input = new Uint8Array(5);
  37137. // Most streams increase in size when decoded, but Ascii85 streams
  37138. // typically shrink by ~20%.
  37139. if (maybeLength) {
  37140. maybeLength = 0.8 * maybeLength;
  37141. }
  37142. DecodeStream.call(this, maybeLength);
  37143. }
  37144. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  37145. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  37146. var TILDA_CHAR = 0x7E; // '~'
  37147. var Z_LOWER_CHAR = 0x7A; // 'z'
  37148. var EOF = -1;
  37149. var str = this.str;
  37150. var c = str.getByte();
  37151. while (Lexer.isSpace(c)) {
  37152. c = str.getByte();
  37153. }
  37154. if (c === EOF || c === TILDA_CHAR) {
  37155. this.eof = true;
  37156. return;
  37157. }
  37158. var bufferLength = this.bufferLength, buffer;
  37159. var i;
  37160. // special code for z
  37161. if (c === Z_LOWER_CHAR) {
  37162. buffer = this.ensureBuffer(bufferLength + 4);
  37163. for (i = 0; i < 4; ++i) {
  37164. buffer[bufferLength + i] = 0;
  37165. }
  37166. this.bufferLength += 4;
  37167. } else {
  37168. var input = this.input;
  37169. input[0] = c;
  37170. for (i = 1; i < 5; ++i) {
  37171. c = str.getByte();
  37172. while (Lexer.isSpace(c)) {
  37173. c = str.getByte();
  37174. }
  37175. input[i] = c;
  37176. if (c === EOF || c === TILDA_CHAR) {
  37177. break;
  37178. }
  37179. }
  37180. buffer = this.ensureBuffer(bufferLength + i - 1);
  37181. this.bufferLength += i - 1;
  37182. // partial ending;
  37183. if (i < 5) {
  37184. for (; i < 5; ++i) {
  37185. input[i] = 0x21 + 84;
  37186. }
  37187. this.eof = true;
  37188. }
  37189. var t = 0;
  37190. for (i = 0; i < 5; ++i) {
  37191. t = t * 85 + (input[i] - 0x21);
  37192. }
  37193. for (i = 3; i >= 0; --i) {
  37194. buffer[bufferLength + i] = t & 0xFF;
  37195. t >>= 8;
  37196. }
  37197. }
  37198. };
  37199. return Ascii85Stream;
  37200. })();
  37201. var AsciiHexStream = (function AsciiHexStreamClosure() {
  37202. function AsciiHexStream(str, maybeLength) {
  37203. this.str = str;
  37204. this.dict = str.dict;
  37205. this.firstDigit = -1;
  37206. // Most streams increase in size when decoded, but AsciiHex streams shrink
  37207. // by 50%.
  37208. if (maybeLength) {
  37209. maybeLength = 0.5 * maybeLength;
  37210. }
  37211. DecodeStream.call(this, maybeLength);
  37212. }
  37213. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  37214. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  37215. var UPSTREAM_BLOCK_SIZE = 8000;
  37216. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  37217. if (!bytes.length) {
  37218. this.eof = true;
  37219. return;
  37220. }
  37221. var maxDecodeLength = (bytes.length + 1) >> 1;
  37222. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  37223. var bufferLength = this.bufferLength;
  37224. var firstDigit = this.firstDigit;
  37225. for (var i = 0, ii = bytes.length; i < ii; i++) {
  37226. var ch = bytes[i], digit;
  37227. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  37228. digit = ch & 0x0F;
  37229. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  37230. // 'A'-'Z', 'a'-'z'
  37231. digit = (ch & 0x0F) + 9;
  37232. } else if (ch === 0x3E) { // '>'
  37233. this.eof = true;
  37234. break;
  37235. } else { // probably whitespace
  37236. continue; // ignoring
  37237. }
  37238. if (firstDigit < 0) {
  37239. firstDigit = digit;
  37240. } else {
  37241. buffer[bufferLength++] = (firstDigit << 4) | digit;
  37242. firstDigit = -1;
  37243. }
  37244. }
  37245. if (firstDigit >= 0 && this.eof) {
  37246. // incomplete byte
  37247. buffer[bufferLength++] = (firstDigit << 4);
  37248. firstDigit = -1;
  37249. }
  37250. this.firstDigit = firstDigit;
  37251. this.bufferLength = bufferLength;
  37252. };
  37253. return AsciiHexStream;
  37254. })();
  37255. var RunLengthStream = (function RunLengthStreamClosure() {
  37256. function RunLengthStream(str, maybeLength) {
  37257. this.str = str;
  37258. this.dict = str.dict;
  37259. DecodeStream.call(this, maybeLength);
  37260. }
  37261. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  37262. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  37263. // The repeatHeader has following format. The first byte defines type of run
  37264. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  37265. // (in addition to the second byte from the header), n = 129 through 255 -
  37266. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  37267. var repeatHeader = this.str.getBytes(2);
  37268. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  37269. this.eof = true;
  37270. return;
  37271. }
  37272. var buffer;
  37273. var bufferLength = this.bufferLength;
  37274. var n = repeatHeader[0];
  37275. if (n < 128) {
  37276. // copy n bytes
  37277. buffer = this.ensureBuffer(bufferLength + n + 1);
  37278. buffer[bufferLength++] = repeatHeader[1];
  37279. if (n > 0) {
  37280. var source = this.str.getBytes(n);
  37281. buffer.set(source, bufferLength);
  37282. bufferLength += n;
  37283. }
  37284. } else {
  37285. n = 257 - n;
  37286. var b = repeatHeader[1];
  37287. buffer = this.ensureBuffer(bufferLength + n + 1);
  37288. for (var i = 0; i < n; i++) {
  37289. buffer[bufferLength++] = b;
  37290. }
  37291. }
  37292. this.bufferLength = bufferLength;
  37293. };
  37294. return RunLengthStream;
  37295. })();
  37296. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  37297. var ccittEOL = -2;
  37298. var twoDimPass = 0;
  37299. var twoDimHoriz = 1;
  37300. var twoDimVert0 = 2;
  37301. var twoDimVertR1 = 3;
  37302. var twoDimVertL1 = 4;
  37303. var twoDimVertR2 = 5;
  37304. var twoDimVertL2 = 6;
  37305. var twoDimVertR3 = 7;
  37306. var twoDimVertL3 = 8;
  37307. var twoDimTable = [
  37308. [-1, -1], [-1, -1], // 000000x
  37309. [7, twoDimVertL3], // 0000010
  37310. [7, twoDimVertR3], // 0000011
  37311. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  37312. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  37313. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  37314. [4, twoDimPass], [4, twoDimPass],
  37315. [4, twoDimPass], [4, twoDimPass],
  37316. [4, twoDimPass], [4, twoDimPass],
  37317. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  37318. [3, twoDimHoriz], [3, twoDimHoriz],
  37319. [3, twoDimHoriz], [3, twoDimHoriz],
  37320. [3, twoDimHoriz], [3, twoDimHoriz],
  37321. [3, twoDimHoriz], [3, twoDimHoriz],
  37322. [3, twoDimHoriz], [3, twoDimHoriz],
  37323. [3, twoDimHoriz], [3, twoDimHoriz],
  37324. [3, twoDimHoriz], [3, twoDimHoriz],
  37325. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  37326. [3, twoDimVertL1], [3, twoDimVertL1],
  37327. [3, twoDimVertL1], [3, twoDimVertL1],
  37328. [3, twoDimVertL1], [3, twoDimVertL1],
  37329. [3, twoDimVertL1], [3, twoDimVertL1],
  37330. [3, twoDimVertL1], [3, twoDimVertL1],
  37331. [3, twoDimVertL1], [3, twoDimVertL1],
  37332. [3, twoDimVertL1], [3, twoDimVertL1],
  37333. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  37334. [3, twoDimVertR1], [3, twoDimVertR1],
  37335. [3, twoDimVertR1], [3, twoDimVertR1],
  37336. [3, twoDimVertR1], [3, twoDimVertR1],
  37337. [3, twoDimVertR1], [3, twoDimVertR1],
  37338. [3, twoDimVertR1], [3, twoDimVertR1],
  37339. [3, twoDimVertR1], [3, twoDimVertR1],
  37340. [3, twoDimVertR1], [3, twoDimVertR1],
  37341. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  37342. [1, twoDimVert0], [1, twoDimVert0],
  37343. [1, twoDimVert0], [1, twoDimVert0],
  37344. [1, twoDimVert0], [1, twoDimVert0],
  37345. [1, twoDimVert0], [1, twoDimVert0],
  37346. [1, twoDimVert0], [1, twoDimVert0],
  37347. [1, twoDimVert0], [1, twoDimVert0],
  37348. [1, twoDimVert0], [1, twoDimVert0],
  37349. [1, twoDimVert0], [1, twoDimVert0],
  37350. [1, twoDimVert0], [1, twoDimVert0],
  37351. [1, twoDimVert0], [1, twoDimVert0],
  37352. [1, twoDimVert0], [1, twoDimVert0],
  37353. [1, twoDimVert0], [1, twoDimVert0],
  37354. [1, twoDimVert0], [1, twoDimVert0],
  37355. [1, twoDimVert0], [1, twoDimVert0],
  37356. [1, twoDimVert0], [1, twoDimVert0],
  37357. [1, twoDimVert0], [1, twoDimVert0],
  37358. [1, twoDimVert0], [1, twoDimVert0],
  37359. [1, twoDimVert0], [1, twoDimVert0],
  37360. [1, twoDimVert0], [1, twoDimVert0],
  37361. [1, twoDimVert0], [1, twoDimVert0],
  37362. [1, twoDimVert0], [1, twoDimVert0],
  37363. [1, twoDimVert0], [1, twoDimVert0],
  37364. [1, twoDimVert0], [1, twoDimVert0],
  37365. [1, twoDimVert0], [1, twoDimVert0],
  37366. [1, twoDimVert0], [1, twoDimVert0],
  37367. [1, twoDimVert0], [1, twoDimVert0],
  37368. [1, twoDimVert0], [1, twoDimVert0],
  37369. [1, twoDimVert0], [1, twoDimVert0],
  37370. [1, twoDimVert0], [1, twoDimVert0],
  37371. [1, twoDimVert0], [1, twoDimVert0],
  37372. [1, twoDimVert0], [1, twoDimVert0]
  37373. ];
  37374. var whiteTable1 = [
  37375. [-1, -1], // 00000
  37376. [12, ccittEOL], // 00001
  37377. [-1, -1], [-1, -1], // 0001x
  37378. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  37379. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  37380. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  37381. [11, 1792], [11, 1792], // 1000x
  37382. [12, 1984], // 10010
  37383. [12, 2048], // 10011
  37384. [12, 2112], // 10100
  37385. [12, 2176], // 10101
  37386. [12, 2240], // 10110
  37387. [12, 2304], // 10111
  37388. [11, 1856], [11, 1856], // 1100x
  37389. [11, 1920], [11, 1920], // 1101x
  37390. [12, 2368], // 11100
  37391. [12, 2432], // 11101
  37392. [12, 2496], // 11110
  37393. [12, 2560] // 11111
  37394. ];
  37395. var whiteTable2 = [
  37396. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  37397. [8, 29], [8, 29], // 00000010x
  37398. [8, 30], [8, 30], // 00000011x
  37399. [8, 45], [8, 45], // 00000100x
  37400. [8, 46], [8, 46], // 00000101x
  37401. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  37402. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  37403. [8, 47], [8, 47], // 00001010x
  37404. [8, 48], [8, 48], // 00001011x
  37405. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  37406. [6, 13], [6, 13], [6, 13], [6, 13],
  37407. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  37408. [8, 33], [8, 33], // 00010010x
  37409. [8, 34], [8, 34], // 00010011x
  37410. [8, 35], [8, 35], // 00010100x
  37411. [8, 36], [8, 36], // 00010101x
  37412. [8, 37], [8, 37], // 00010110x
  37413. [8, 38], [8, 38], // 00010111x
  37414. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  37415. [8, 31], [8, 31], // 00011010x
  37416. [8, 32], [8, 32], // 00011011x
  37417. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  37418. [6, 1], [6, 1], [6, 1], [6, 1],
  37419. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  37420. [6, 12], [6, 12], [6, 12], [6, 12],
  37421. [8, 53], [8, 53], // 00100100x
  37422. [8, 54], [8, 54], // 00100101x
  37423. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  37424. [8, 39], [8, 39], // 00101000x
  37425. [8, 40], [8, 40], // 00101001x
  37426. [8, 41], [8, 41], // 00101010x
  37427. [8, 42], [8, 42], // 00101011x
  37428. [8, 43], [8, 43], // 00101100x
  37429. [8, 44], [8, 44], // 00101101x
  37430. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  37431. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  37432. [8, 61], [8, 61], // 00110010x
  37433. [8, 62], [8, 62], // 00110011x
  37434. [8, 63], [8, 63], // 00110100x
  37435. [8, 0], [8, 0], // 00110101x
  37436. [8, 320], [8, 320], // 00110110x
  37437. [8, 384], [8, 384], // 00110111x
  37438. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  37439. [5, 10], [5, 10], [5, 10], [5, 10],
  37440. [5, 10], [5, 10], [5, 10], [5, 10],
  37441. [5, 10], [5, 10], [5, 10], [5, 10],
  37442. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  37443. [5, 11], [5, 11], [5, 11], [5, 11],
  37444. [5, 11], [5, 11], [5, 11], [5, 11],
  37445. [5, 11], [5, 11], [5, 11], [5, 11],
  37446. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  37447. [8, 59], [8, 59], // 01001010x
  37448. [8, 60], [8, 60], // 01001011x
  37449. [9, 1472], // 010011000
  37450. [9, 1536], // 010011001
  37451. [9, 1600], // 010011010
  37452. [9, 1728], // 010011011
  37453. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  37454. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  37455. [8, 49], [8, 49], // 01010010x
  37456. [8, 50], [8, 50], // 01010011x
  37457. [8, 51], [8, 51], // 01010100x
  37458. [8, 52], [8, 52], // 01010101x
  37459. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  37460. [8, 55], [8, 55], // 01011000x
  37461. [8, 56], [8, 56], // 01011001x
  37462. [8, 57], [8, 57], // 01011010x
  37463. [8, 58], [8, 58], // 01011011x
  37464. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  37465. [6, 192], [6, 192], [6, 192], [6, 192],
  37466. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  37467. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  37468. [8, 448], [8, 448], // 01100100x
  37469. [8, 512], [8, 512], // 01100101x
  37470. [9, 704], // 011001100
  37471. [9, 768], // 011001101
  37472. [8, 640], [8, 640], // 01100111x
  37473. [8, 576], [8, 576], // 01101000x
  37474. [9, 832], // 011010010
  37475. [9, 896], // 011010011
  37476. [9, 960], // 011010100
  37477. [9, 1024], // 011010101
  37478. [9, 1088], // 011010110
  37479. [9, 1152], // 011010111
  37480. [9, 1216], // 011011000
  37481. [9, 1280], // 011011001
  37482. [9, 1344], // 011011010
  37483. [9, 1408], // 011011011
  37484. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  37485. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  37486. [4, 2], [4, 2], [4, 2], [4, 2],
  37487. [4, 2], [4, 2], [4, 2], [4, 2],
  37488. [4, 2], [4, 2], [4, 2], [4, 2],
  37489. [4, 2], [4, 2], [4, 2], [4, 2],
  37490. [4, 2], [4, 2], [4, 2], [4, 2],
  37491. [4, 2], [4, 2], [4, 2], [4, 2],
  37492. [4, 2], [4, 2], [4, 2], [4, 2],
  37493. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  37494. [4, 3], [4, 3], [4, 3], [4, 3],
  37495. [4, 3], [4, 3], [4, 3], [4, 3],
  37496. [4, 3], [4, 3], [4, 3], [4, 3],
  37497. [4, 3], [4, 3], [4, 3], [4, 3],
  37498. [4, 3], [4, 3], [4, 3], [4, 3],
  37499. [4, 3], [4, 3], [4, 3], [4, 3],
  37500. [4, 3], [4, 3], [4, 3], [4, 3],
  37501. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  37502. [5, 128], [5, 128], [5, 128], [5, 128],
  37503. [5, 128], [5, 128], [5, 128], [5, 128],
  37504. [5, 128], [5, 128], [5, 128], [5, 128],
  37505. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  37506. [5, 8], [5, 8], [5, 8], [5, 8],
  37507. [5, 8], [5, 8], [5, 8], [5, 8],
  37508. [5, 8], [5, 8], [5, 8], [5, 8],
  37509. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  37510. [5, 9], [5, 9], [5, 9], [5, 9],
  37511. [5, 9], [5, 9], [5, 9], [5, 9],
  37512. [5, 9], [5, 9], [5, 9], [5, 9],
  37513. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  37514. [6, 16], [6, 16], [6, 16], [6, 16],
  37515. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  37516. [6, 17], [6, 17], [6, 17], [6, 17],
  37517. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  37518. [4, 4], [4, 4], [4, 4], [4, 4],
  37519. [4, 4], [4, 4], [4, 4], [4, 4],
  37520. [4, 4], [4, 4], [4, 4], [4, 4],
  37521. [4, 4], [4, 4], [4, 4], [4, 4],
  37522. [4, 4], [4, 4], [4, 4], [4, 4],
  37523. [4, 4], [4, 4], [4, 4], [4, 4],
  37524. [4, 4], [4, 4], [4, 4], [4, 4],
  37525. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  37526. [4, 5], [4, 5], [4, 5], [4, 5],
  37527. [4, 5], [4, 5], [4, 5], [4, 5],
  37528. [4, 5], [4, 5], [4, 5], [4, 5],
  37529. [4, 5], [4, 5], [4, 5], [4, 5],
  37530. [4, 5], [4, 5], [4, 5], [4, 5],
  37531. [4, 5], [4, 5], [4, 5], [4, 5],
  37532. [4, 5], [4, 5], [4, 5], [4, 5],
  37533. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  37534. [6, 14], [6, 14], [6, 14], [6, 14],
  37535. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  37536. [6, 15], [6, 15], [6, 15], [6, 15],
  37537. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  37538. [5, 64], [5, 64], [5, 64], [5, 64],
  37539. [5, 64], [5, 64], [5, 64], [5, 64],
  37540. [5, 64], [5, 64], [5, 64], [5, 64],
  37541. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  37542. [4, 6], [4, 6], [4, 6], [4, 6],
  37543. [4, 6], [4, 6], [4, 6], [4, 6],
  37544. [4, 6], [4, 6], [4, 6], [4, 6],
  37545. [4, 6], [4, 6], [4, 6], [4, 6],
  37546. [4, 6], [4, 6], [4, 6], [4, 6],
  37547. [4, 6], [4, 6], [4, 6], [4, 6],
  37548. [4, 6], [4, 6], [4, 6], [4, 6],
  37549. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  37550. [4, 7], [4, 7], [4, 7], [4, 7],
  37551. [4, 7], [4, 7], [4, 7], [4, 7],
  37552. [4, 7], [4, 7], [4, 7], [4, 7],
  37553. [4, 7], [4, 7], [4, 7], [4, 7],
  37554. [4, 7], [4, 7], [4, 7], [4, 7],
  37555. [4, 7], [4, 7], [4, 7], [4, 7],
  37556. [4, 7], [4, 7], [4, 7], [4, 7]
  37557. ];
  37558. var blackTable1 = [
  37559. [-1, -1], [-1, -1], // 000000000000x
  37560. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  37561. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  37562. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  37563. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  37564. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  37565. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  37566. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  37567. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  37568. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  37569. [12, 1984], [12, 1984], // 000000010010x
  37570. [12, 2048], [12, 2048], // 000000010011x
  37571. [12, 2112], [12, 2112], // 000000010100x
  37572. [12, 2176], [12, 2176], // 000000010101x
  37573. [12, 2240], [12, 2240], // 000000010110x
  37574. [12, 2304], [12, 2304], // 000000010111x
  37575. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  37576. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  37577. [12, 2368], [12, 2368], // 000000011100x
  37578. [12, 2432], [12, 2432], // 000000011101x
  37579. [12, 2496], [12, 2496], // 000000011110x
  37580. [12, 2560], [12, 2560], // 000000011111x
  37581. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  37582. [10, 18], [10, 18], [10, 18], [10, 18],
  37583. [12, 52], [12, 52], // 000000100100x
  37584. [13, 640], // 0000001001010
  37585. [13, 704], // 0000001001011
  37586. [13, 768], // 0000001001100
  37587. [13, 832], // 0000001001101
  37588. [12, 55], [12, 55], // 000000100111x
  37589. [12, 56], [12, 56], // 000000101000x
  37590. [13, 1280], // 0000001010010
  37591. [13, 1344], // 0000001010011
  37592. [13, 1408], // 0000001010100
  37593. [13, 1472], // 0000001010101
  37594. [12, 59], [12, 59], // 000000101011x
  37595. [12, 60], [12, 60], // 000000101100x
  37596. [13, 1536], // 0000001011010
  37597. [13, 1600], // 0000001011011
  37598. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  37599. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  37600. [13, 1664], // 0000001100100
  37601. [13, 1728], // 0000001100101
  37602. [12, 320], [12, 320], // 000000110011x
  37603. [12, 384], [12, 384], // 000000110100x
  37604. [12, 448], [12, 448], // 000000110101x
  37605. [13, 512], // 0000001101100
  37606. [13, 576], // 0000001101101
  37607. [12, 53], [12, 53], // 000000110111x
  37608. [12, 54], [12, 54], // 000000111000x
  37609. [13, 896], // 0000001110010
  37610. [13, 960], // 0000001110011
  37611. [13, 1024], // 0000001110100
  37612. [13, 1088], // 0000001110101
  37613. [13, 1152], // 0000001110110
  37614. [13, 1216], // 0000001110111
  37615. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  37616. [10, 64], [10, 64], [10, 64], [10, 64]
  37617. ];
  37618. var blackTable2 = [
  37619. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  37620. [8, 13], [8, 13], [8, 13], [8, 13],
  37621. [8, 13], [8, 13], [8, 13], [8, 13],
  37622. [8, 13], [8, 13], [8, 13], [8, 13],
  37623. [11, 23], [11, 23], // 00000101000x
  37624. [12, 50], // 000001010010
  37625. [12, 51], // 000001010011
  37626. [12, 44], // 000001010100
  37627. [12, 45], // 000001010101
  37628. [12, 46], // 000001010110
  37629. [12, 47], // 000001010111
  37630. [12, 57], // 000001011000
  37631. [12, 58], // 000001011001
  37632. [12, 61], // 000001011010
  37633. [12, 256], // 000001011011
  37634. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  37635. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  37636. [12, 48], // 000001100100
  37637. [12, 49], // 000001100101
  37638. [12, 62], // 000001100110
  37639. [12, 63], // 000001100111
  37640. [12, 30], // 000001101000
  37641. [12, 31], // 000001101001
  37642. [12, 32], // 000001101010
  37643. [12, 33], // 000001101011
  37644. [12, 40], // 000001101100
  37645. [12, 41], // 000001101101
  37646. [11, 22], [11, 22], // 00000110111x
  37647. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  37648. [8, 14], [8, 14], [8, 14], [8, 14],
  37649. [8, 14], [8, 14], [8, 14], [8, 14],
  37650. [8, 14], [8, 14], [8, 14], [8, 14],
  37651. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  37652. [7, 10], [7, 10], [7, 10], [7, 10],
  37653. [7, 10], [7, 10], [7, 10], [7, 10],
  37654. [7, 10], [7, 10], [7, 10], [7, 10],
  37655. [7, 10], [7, 10], [7, 10], [7, 10],
  37656. [7, 10], [7, 10], [7, 10], [7, 10],
  37657. [7, 10], [7, 10], [7, 10], [7, 10],
  37658. [7, 10], [7, 10], [7, 10], [7, 10],
  37659. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  37660. [7, 11], [7, 11], [7, 11], [7, 11],
  37661. [7, 11], [7, 11], [7, 11], [7, 11],
  37662. [7, 11], [7, 11], [7, 11], [7, 11],
  37663. [7, 11], [7, 11], [7, 11], [7, 11],
  37664. [7, 11], [7, 11], [7, 11], [7, 11],
  37665. [7, 11], [7, 11], [7, 11], [7, 11],
  37666. [7, 11], [7, 11], [7, 11], [7, 11],
  37667. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  37668. [9, 15], [9, 15], [9, 15], [9, 15],
  37669. [12, 128], // 000011001000
  37670. [12, 192], // 000011001001
  37671. [12, 26], // 000011001010
  37672. [12, 27], // 000011001011
  37673. [12, 28], // 000011001100
  37674. [12, 29], // 000011001101
  37675. [11, 19], [11, 19], // 00001100111x
  37676. [11, 20], [11, 20], // 00001101000x
  37677. [12, 34], // 000011010010
  37678. [12, 35], // 000011010011
  37679. [12, 36], // 000011010100
  37680. [12, 37], // 000011010101
  37681. [12, 38], // 000011010110
  37682. [12, 39], // 000011010111
  37683. [11, 21], [11, 21], // 00001101100x
  37684. [12, 42], // 000011011010
  37685. [12, 43], // 000011011011
  37686. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  37687. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  37688. [7, 12], [7, 12], [7, 12], [7, 12],
  37689. [7, 12], [7, 12], [7, 12], [7, 12],
  37690. [7, 12], [7, 12], [7, 12], [7, 12],
  37691. [7, 12], [7, 12], [7, 12], [7, 12],
  37692. [7, 12], [7, 12], [7, 12], [7, 12],
  37693. [7, 12], [7, 12], [7, 12], [7, 12],
  37694. [7, 12], [7, 12], [7, 12], [7, 12]
  37695. ];
  37696. var blackTable3 = [
  37697. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  37698. [6, 9], // 000100
  37699. [6, 8], // 000101
  37700. [5, 7], [5, 7], // 00011x
  37701. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  37702. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  37703. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  37704. [3, 1], [3, 1], [3, 1], [3, 1],
  37705. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  37706. [3, 4], [3, 4], [3, 4], [3, 4],
  37707. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  37708. [2, 3], [2, 3], [2, 3], [2, 3],
  37709. [2, 3], [2, 3], [2, 3], [2, 3],
  37710. [2, 3], [2, 3], [2, 3], [2, 3],
  37711. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  37712. [2, 2], [2, 2], [2, 2], [2, 2],
  37713. [2, 2], [2, 2], [2, 2], [2, 2],
  37714. [2, 2], [2, 2], [2, 2], [2, 2]
  37715. ];
  37716. function CCITTFaxStream(str, maybeLength, params) {
  37717. this.str = str;
  37718. this.dict = str.dict;
  37719. params = params || Dict.empty;
  37720. this.encoding = params.get('K') || 0;
  37721. this.eoline = params.get('EndOfLine') || false;
  37722. this.byteAlign = params.get('EncodedByteAlign') || false;
  37723. this.columns = params.get('Columns') || 1728;
  37724. this.rows = params.get('Rows') || 0;
  37725. var eoblock = params.get('EndOfBlock');
  37726. if (eoblock === null || eoblock === undefined) {
  37727. eoblock = true;
  37728. }
  37729. this.eoblock = eoblock;
  37730. this.black = params.get('BlackIs1') || false;
  37731. this.codingLine = new Uint32Array(this.columns + 1);
  37732. this.refLine = new Uint32Array(this.columns + 2);
  37733. this.codingLine[0] = this.columns;
  37734. this.codingPos = 0;
  37735. this.row = 0;
  37736. this.nextLine2D = this.encoding < 0;
  37737. this.inputBits = 0;
  37738. this.inputBuf = 0;
  37739. this.outputBits = 0;
  37740. var code1;
  37741. while ((code1 = this.lookBits(12)) === 0) {
  37742. this.eatBits(1);
  37743. }
  37744. if (code1 === 1) {
  37745. this.eatBits(12);
  37746. }
  37747. if (this.encoding > 0) {
  37748. this.nextLine2D = !this.lookBits(1);
  37749. this.eatBits(1);
  37750. }
  37751. DecodeStream.call(this, maybeLength);
  37752. }
  37753. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  37754. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  37755. while (!this.eof) {
  37756. var c = this.lookChar();
  37757. this.ensureBuffer(this.bufferLength + 1);
  37758. this.buffer[this.bufferLength++] = c;
  37759. }
  37760. };
  37761. CCITTFaxStream.prototype.addPixels =
  37762. function ccittFaxStreamAddPixels(a1, blackPixels) {
  37763. var codingLine = this.codingLine;
  37764. var codingPos = this.codingPos;
  37765. if (a1 > codingLine[codingPos]) {
  37766. if (a1 > this.columns) {
  37767. info('row is wrong length');
  37768. this.err = true;
  37769. a1 = this.columns;
  37770. }
  37771. if ((codingPos & 1) ^ blackPixels) {
  37772. ++codingPos;
  37773. }
  37774. codingLine[codingPos] = a1;
  37775. }
  37776. this.codingPos = codingPos;
  37777. };
  37778. CCITTFaxStream.prototype.addPixelsNeg =
  37779. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  37780. var codingLine = this.codingLine;
  37781. var codingPos = this.codingPos;
  37782. if (a1 > codingLine[codingPos]) {
  37783. if (a1 > this.columns) {
  37784. info('row is wrong length');
  37785. this.err = true;
  37786. a1 = this.columns;
  37787. }
  37788. if ((codingPos & 1) ^ blackPixels) {
  37789. ++codingPos;
  37790. }
  37791. codingLine[codingPos] = a1;
  37792. } else if (a1 < codingLine[codingPos]) {
  37793. if (a1 < 0) {
  37794. info('invalid code');
  37795. this.err = true;
  37796. a1 = 0;
  37797. }
  37798. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  37799. --codingPos;
  37800. }
  37801. codingLine[codingPos] = a1;
  37802. }
  37803. this.codingPos = codingPos;
  37804. };
  37805. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  37806. var refLine = this.refLine;
  37807. var codingLine = this.codingLine;
  37808. var columns = this.columns;
  37809. var refPos, blackPixels, bits, i;
  37810. if (this.outputBits === 0) {
  37811. if (this.eof) {
  37812. return null;
  37813. }
  37814. this.err = false;
  37815. var code1, code2, code3;
  37816. if (this.nextLine2D) {
  37817. for (i = 0; codingLine[i] < columns; ++i) {
  37818. refLine[i] = codingLine[i];
  37819. }
  37820. refLine[i++] = columns;
  37821. refLine[i] = columns;
  37822. codingLine[0] = 0;
  37823. this.codingPos = 0;
  37824. refPos = 0;
  37825. blackPixels = 0;
  37826. while (codingLine[this.codingPos] < columns) {
  37827. code1 = this.getTwoDimCode();
  37828. switch (code1) {
  37829. case twoDimPass:
  37830. this.addPixels(refLine[refPos + 1], blackPixels);
  37831. if (refLine[refPos + 1] < columns) {
  37832. refPos += 2;
  37833. }
  37834. break;
  37835. case twoDimHoriz:
  37836. code1 = code2 = 0;
  37837. if (blackPixels) {
  37838. do {
  37839. code1 += (code3 = this.getBlackCode());
  37840. } while (code3 >= 64);
  37841. do {
  37842. code2 += (code3 = this.getWhiteCode());
  37843. } while (code3 >= 64);
  37844. } else {
  37845. do {
  37846. code1 += (code3 = this.getWhiteCode());
  37847. } while (code3 >= 64);
  37848. do {
  37849. code2 += (code3 = this.getBlackCode());
  37850. } while (code3 >= 64);
  37851. }
  37852. this.addPixels(codingLine[this.codingPos] +
  37853. code1, blackPixels);
  37854. if (codingLine[this.codingPos] < columns) {
  37855. this.addPixels(codingLine[this.codingPos] + code2,
  37856. blackPixels ^ 1);
  37857. }
  37858. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37859. refLine[refPos] < columns) {
  37860. refPos += 2;
  37861. }
  37862. break;
  37863. case twoDimVertR3:
  37864. this.addPixels(refLine[refPos] + 3, blackPixels);
  37865. blackPixels ^= 1;
  37866. if (codingLine[this.codingPos] < columns) {
  37867. ++refPos;
  37868. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37869. refLine[refPos] < columns) {
  37870. refPos += 2;
  37871. }
  37872. }
  37873. break;
  37874. case twoDimVertR2:
  37875. this.addPixels(refLine[refPos] + 2, blackPixels);
  37876. blackPixels ^= 1;
  37877. if (codingLine[this.codingPos] < columns) {
  37878. ++refPos;
  37879. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37880. refLine[refPos] < columns) {
  37881. refPos += 2;
  37882. }
  37883. }
  37884. break;
  37885. case twoDimVertR1:
  37886. this.addPixels(refLine[refPos] + 1, blackPixels);
  37887. blackPixels ^= 1;
  37888. if (codingLine[this.codingPos] < columns) {
  37889. ++refPos;
  37890. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37891. refLine[refPos] < columns) {
  37892. refPos += 2;
  37893. }
  37894. }
  37895. break;
  37896. case twoDimVert0:
  37897. this.addPixels(refLine[refPos], blackPixels);
  37898. blackPixels ^= 1;
  37899. if (codingLine[this.codingPos] < columns) {
  37900. ++refPos;
  37901. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37902. refLine[refPos] < columns) {
  37903. refPos += 2;
  37904. }
  37905. }
  37906. break;
  37907. case twoDimVertL3:
  37908. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  37909. blackPixels ^= 1;
  37910. if (codingLine[this.codingPos] < columns) {
  37911. if (refPos > 0) {
  37912. --refPos;
  37913. } else {
  37914. ++refPos;
  37915. }
  37916. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37917. refLine[refPos] < columns) {
  37918. refPos += 2;
  37919. }
  37920. }
  37921. break;
  37922. case twoDimVertL2:
  37923. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  37924. blackPixels ^= 1;
  37925. if (codingLine[this.codingPos] < columns) {
  37926. if (refPos > 0) {
  37927. --refPos;
  37928. } else {
  37929. ++refPos;
  37930. }
  37931. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37932. refLine[refPos] < columns) {
  37933. refPos += 2;
  37934. }
  37935. }
  37936. break;
  37937. case twoDimVertL1:
  37938. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  37939. blackPixels ^= 1;
  37940. if (codingLine[this.codingPos] < columns) {
  37941. if (refPos > 0) {
  37942. --refPos;
  37943. } else {
  37944. ++refPos;
  37945. }
  37946. while (refLine[refPos] <= codingLine[this.codingPos] &&
  37947. refLine[refPos] < columns) {
  37948. refPos += 2;
  37949. }
  37950. }
  37951. break;
  37952. case EOF:
  37953. this.addPixels(columns, 0);
  37954. this.eof = true;
  37955. break;
  37956. default:
  37957. info('bad 2d code');
  37958. this.addPixels(columns, 0);
  37959. this.err = true;
  37960. }
  37961. }
  37962. } else {
  37963. codingLine[0] = 0;
  37964. this.codingPos = 0;
  37965. blackPixels = 0;
  37966. while (codingLine[this.codingPos] < columns) {
  37967. code1 = 0;
  37968. if (blackPixels) {
  37969. do {
  37970. code1 += (code3 = this.getBlackCode());
  37971. } while (code3 >= 64);
  37972. } else {
  37973. do {
  37974. code1 += (code3 = this.getWhiteCode());
  37975. } while (code3 >= 64);
  37976. }
  37977. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  37978. blackPixels ^= 1;
  37979. }
  37980. }
  37981. var gotEOL = false;
  37982. if (this.byteAlign) {
  37983. this.inputBits &= ~7;
  37984. }
  37985. if (!this.eoblock && this.row === this.rows - 1) {
  37986. this.eof = true;
  37987. } else {
  37988. code1 = this.lookBits(12);
  37989. if (this.eoline) {
  37990. while (code1 !== EOF && code1 !== 1) {
  37991. this.eatBits(1);
  37992. code1 = this.lookBits(12);
  37993. }
  37994. } else {
  37995. while (code1 === 0) {
  37996. this.eatBits(1);
  37997. code1 = this.lookBits(12);
  37998. }
  37999. }
  38000. if (code1 === 1) {
  38001. this.eatBits(12);
  38002. gotEOL = true;
  38003. } else if (code1 === EOF) {
  38004. this.eof = true;
  38005. }
  38006. }
  38007. if (!this.eof && this.encoding > 0) {
  38008. this.nextLine2D = !this.lookBits(1);
  38009. this.eatBits(1);
  38010. }
  38011. if (this.eoblock && gotEOL && this.byteAlign) {
  38012. code1 = this.lookBits(12);
  38013. if (code1 === 1) {
  38014. this.eatBits(12);
  38015. if (this.encoding > 0) {
  38016. this.lookBits(1);
  38017. this.eatBits(1);
  38018. }
  38019. if (this.encoding >= 0) {
  38020. for (i = 0; i < 4; ++i) {
  38021. code1 = this.lookBits(12);
  38022. if (code1 !== 1) {
  38023. info('bad rtc code: ' + code1);
  38024. }
  38025. this.eatBits(12);
  38026. if (this.encoding > 0) {
  38027. this.lookBits(1);
  38028. this.eatBits(1);
  38029. }
  38030. }
  38031. }
  38032. this.eof = true;
  38033. }
  38034. } else if (this.err && this.eoline) {
  38035. while (true) {
  38036. code1 = this.lookBits(13);
  38037. if (code1 === EOF) {
  38038. this.eof = true;
  38039. return null;
  38040. }
  38041. if ((code1 >> 1) === 1) {
  38042. break;
  38043. }
  38044. this.eatBits(1);
  38045. }
  38046. this.eatBits(12);
  38047. if (this.encoding > 0) {
  38048. this.eatBits(1);
  38049. this.nextLine2D = !(code1 & 1);
  38050. }
  38051. }
  38052. if (codingLine[0] > 0) {
  38053. this.outputBits = codingLine[this.codingPos = 0];
  38054. } else {
  38055. this.outputBits = codingLine[this.codingPos = 1];
  38056. }
  38057. this.row++;
  38058. }
  38059. var c;
  38060. if (this.outputBits >= 8) {
  38061. c = (this.codingPos & 1) ? 0 : 0xFF;
  38062. this.outputBits -= 8;
  38063. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  38064. this.codingPos++;
  38065. this.outputBits = (codingLine[this.codingPos] -
  38066. codingLine[this.codingPos - 1]);
  38067. }
  38068. } else {
  38069. bits = 8;
  38070. c = 0;
  38071. do {
  38072. if (this.outputBits > bits) {
  38073. c <<= bits;
  38074. if (!(this.codingPos & 1)) {
  38075. c |= 0xFF >> (8 - bits);
  38076. }
  38077. this.outputBits -= bits;
  38078. bits = 0;
  38079. } else {
  38080. c <<= this.outputBits;
  38081. if (!(this.codingPos & 1)) {
  38082. c |= 0xFF >> (8 - this.outputBits);
  38083. }
  38084. bits -= this.outputBits;
  38085. this.outputBits = 0;
  38086. if (codingLine[this.codingPos] < columns) {
  38087. this.codingPos++;
  38088. this.outputBits = (codingLine[this.codingPos] -
  38089. codingLine[this.codingPos - 1]);
  38090. } else if (bits > 0) {
  38091. c <<= bits;
  38092. bits = 0;
  38093. }
  38094. }
  38095. } while (bits);
  38096. }
  38097. if (this.black) {
  38098. c ^= 0xFF;
  38099. }
  38100. return c;
  38101. };
  38102. // This functions returns the code found from the table.
  38103. // The start and end parameters set the boundaries for searching the table.
  38104. // The limit parameter is optional. Function returns an array with three
  38105. // values. The first array element indicates whether a valid code is being
  38106. // returned. The second array element is the actual code. The third array
  38107. // element indicates whether EOF was reached.
  38108. CCITTFaxStream.prototype.findTableCode =
  38109. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  38110. var limitValue = limit || 0;
  38111. for (var i = start; i <= end; ++i) {
  38112. var code = this.lookBits(i);
  38113. if (code === EOF) {
  38114. return [true, 1, false];
  38115. }
  38116. if (i < end) {
  38117. code <<= end - i;
  38118. }
  38119. if (!limitValue || code >= limitValue) {
  38120. var p = table[code - limitValue];
  38121. if (p[0] === i) {
  38122. this.eatBits(i);
  38123. return [true, p[1], true];
  38124. }
  38125. }
  38126. }
  38127. return [false, 0, false];
  38128. };
  38129. CCITTFaxStream.prototype.getTwoDimCode =
  38130. function ccittFaxStreamGetTwoDimCode() {
  38131. var code = 0;
  38132. var p;
  38133. if (this.eoblock) {
  38134. code = this.lookBits(7);
  38135. p = twoDimTable[code];
  38136. if (p && p[0] > 0) {
  38137. this.eatBits(p[0]);
  38138. return p[1];
  38139. }
  38140. } else {
  38141. var result = this.findTableCode(1, 7, twoDimTable);
  38142. if (result[0] && result[2]) {
  38143. return result[1];
  38144. }
  38145. }
  38146. info('Bad two dim code');
  38147. return EOF;
  38148. };
  38149. CCITTFaxStream.prototype.getWhiteCode =
  38150. function ccittFaxStreamGetWhiteCode() {
  38151. var code = 0;
  38152. var p;
  38153. if (this.eoblock) {
  38154. code = this.lookBits(12);
  38155. if (code === EOF) {
  38156. return 1;
  38157. }
  38158. if ((code >> 5) === 0) {
  38159. p = whiteTable1[code];
  38160. } else {
  38161. p = whiteTable2[code >> 3];
  38162. }
  38163. if (p[0] > 0) {
  38164. this.eatBits(p[0]);
  38165. return p[1];
  38166. }
  38167. } else {
  38168. var result = this.findTableCode(1, 9, whiteTable2);
  38169. if (result[0]) {
  38170. return result[1];
  38171. }
  38172. result = this.findTableCode(11, 12, whiteTable1);
  38173. if (result[0]) {
  38174. return result[1];
  38175. }
  38176. }
  38177. info('bad white code');
  38178. this.eatBits(1);
  38179. return 1;
  38180. };
  38181. CCITTFaxStream.prototype.getBlackCode =
  38182. function ccittFaxStreamGetBlackCode() {
  38183. var code, p;
  38184. if (this.eoblock) {
  38185. code = this.lookBits(13);
  38186. if (code === EOF) {
  38187. return 1;
  38188. }
  38189. if ((code >> 7) === 0) {
  38190. p = blackTable1[code];
  38191. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  38192. p = blackTable2[(code >> 1) - 64];
  38193. } else {
  38194. p = blackTable3[code >> 7];
  38195. }
  38196. if (p[0] > 0) {
  38197. this.eatBits(p[0]);
  38198. return p[1];
  38199. }
  38200. } else {
  38201. var result = this.findTableCode(2, 6, blackTable3);
  38202. if (result[0]) {
  38203. return result[1];
  38204. }
  38205. result = this.findTableCode(7, 12, blackTable2, 64);
  38206. if (result[0]) {
  38207. return result[1];
  38208. }
  38209. result = this.findTableCode(10, 13, blackTable1);
  38210. if (result[0]) {
  38211. return result[1];
  38212. }
  38213. }
  38214. info('bad black code');
  38215. this.eatBits(1);
  38216. return 1;
  38217. };
  38218. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  38219. var c;
  38220. while (this.inputBits < n) {
  38221. if ((c = this.str.getByte()) === -1) {
  38222. if (this.inputBits === 0) {
  38223. return EOF;
  38224. }
  38225. return ((this.inputBuf << (n - this.inputBits)) &
  38226. (0xFFFF >> (16 - n)));
  38227. }
  38228. this.inputBuf = (this.inputBuf << 8) + c;
  38229. this.inputBits += 8;
  38230. }
  38231. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  38232. };
  38233. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  38234. if ((this.inputBits -= n) < 0) {
  38235. this.inputBits = 0;
  38236. }
  38237. };
  38238. return CCITTFaxStream;
  38239. })();
  38240. var LZWStream = (function LZWStreamClosure() {
  38241. function LZWStream(str, maybeLength, earlyChange) {
  38242. this.str = str;
  38243. this.dict = str.dict;
  38244. this.cachedData = 0;
  38245. this.bitsCached = 0;
  38246. var maxLzwDictionarySize = 4096;
  38247. var lzwState = {
  38248. earlyChange: earlyChange,
  38249. codeLength: 9,
  38250. nextCode: 258,
  38251. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  38252. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  38253. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  38254. currentSequence: new Uint8Array(maxLzwDictionarySize),
  38255. currentSequenceLength: 0
  38256. };
  38257. for (var i = 0; i < 256; ++i) {
  38258. lzwState.dictionaryValues[i] = i;
  38259. lzwState.dictionaryLengths[i] = 1;
  38260. }
  38261. this.lzwState = lzwState;
  38262. DecodeStream.call(this, maybeLength);
  38263. }
  38264. LZWStream.prototype = Object.create(DecodeStream.prototype);
  38265. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  38266. var bitsCached = this.bitsCached;
  38267. var cachedData = this.cachedData;
  38268. while (bitsCached < n) {
  38269. var c = this.str.getByte();
  38270. if (c === -1) {
  38271. this.eof = true;
  38272. return null;
  38273. }
  38274. cachedData = (cachedData << 8) | c;
  38275. bitsCached += 8;
  38276. }
  38277. this.bitsCached = (bitsCached -= n);
  38278. this.cachedData = cachedData;
  38279. this.lastCode = null;
  38280. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  38281. };
  38282. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  38283. var blockSize = 512;
  38284. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  38285. var i, j, q;
  38286. var lzwState = this.lzwState;
  38287. if (!lzwState) {
  38288. return; // eof was found
  38289. }
  38290. var earlyChange = lzwState.earlyChange;
  38291. var nextCode = lzwState.nextCode;
  38292. var dictionaryValues = lzwState.dictionaryValues;
  38293. var dictionaryLengths = lzwState.dictionaryLengths;
  38294. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  38295. var codeLength = lzwState.codeLength;
  38296. var prevCode = lzwState.prevCode;
  38297. var currentSequence = lzwState.currentSequence;
  38298. var currentSequenceLength = lzwState.currentSequenceLength;
  38299. var decodedLength = 0;
  38300. var currentBufferLength = this.bufferLength;
  38301. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  38302. for (i = 0; i < blockSize; i++) {
  38303. var code = this.readBits(codeLength);
  38304. var hasPrev = currentSequenceLength > 0;
  38305. if (code < 256) {
  38306. currentSequence[0] = code;
  38307. currentSequenceLength = 1;
  38308. } else if (code >= 258) {
  38309. if (code < nextCode) {
  38310. currentSequenceLength = dictionaryLengths[code];
  38311. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  38312. currentSequence[j] = dictionaryValues[q];
  38313. q = dictionaryPrevCodes[q];
  38314. }
  38315. } else {
  38316. currentSequence[currentSequenceLength++] = currentSequence[0];
  38317. }
  38318. } else if (code === 256) {
  38319. codeLength = 9;
  38320. nextCode = 258;
  38321. currentSequenceLength = 0;
  38322. continue;
  38323. } else {
  38324. this.eof = true;
  38325. delete this.lzwState;
  38326. break;
  38327. }
  38328. if (hasPrev) {
  38329. dictionaryPrevCodes[nextCode] = prevCode;
  38330. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  38331. dictionaryValues[nextCode] = currentSequence[0];
  38332. nextCode++;
  38333. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  38334. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  38335. 0.6931471805599453 + 1, 12) | 0;
  38336. }
  38337. prevCode = code;
  38338. decodedLength += currentSequenceLength;
  38339. if (estimatedDecodedSize < decodedLength) {
  38340. do {
  38341. estimatedDecodedSize += decodedSizeDelta;
  38342. } while (estimatedDecodedSize < decodedLength);
  38343. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  38344. }
  38345. for (j = 0; j < currentSequenceLength; j++) {
  38346. buffer[currentBufferLength++] = currentSequence[j];
  38347. }
  38348. }
  38349. lzwState.nextCode = nextCode;
  38350. lzwState.codeLength = codeLength;
  38351. lzwState.prevCode = prevCode;
  38352. lzwState.currentSequenceLength = currentSequenceLength;
  38353. this.bufferLength = currentBufferLength;
  38354. };
  38355. return LZWStream;
  38356. })();
  38357. var NullStream = (function NullStreamClosure() {
  38358. function NullStream() {
  38359. Stream.call(this, new Uint8Array(0));
  38360. }
  38361. NullStream.prototype = Stream.prototype;
  38362. return NullStream;
  38363. })();
  38364. var WorkerTask = (function WorkerTaskClosure() {
  38365. function WorkerTask(name) {
  38366. this.name = name;
  38367. this.terminated = false;
  38368. this._capability = createPromiseCapability();
  38369. }
  38370. WorkerTask.prototype = {
  38371. get finished() {
  38372. return this._capability.promise;
  38373. },
  38374. finish: function () {
  38375. this._capability.resolve();
  38376. },
  38377. terminate: function () {
  38378. this.terminated = true;
  38379. },
  38380. ensureNotTerminated: function () {
  38381. if (this.terminated) {
  38382. throw new Error('Worker task was terminated');
  38383. }
  38384. }
  38385. };
  38386. return WorkerTask;
  38387. })();
  38388. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  38389. setup: function wphSetup(handler) {
  38390. var pdfManager;
  38391. var terminated = false;
  38392. var cancelXHRs = null;
  38393. var WorkerTasks = [];
  38394. function ensureNotTerminated() {
  38395. if (terminated) {
  38396. throw new Error('Worker was terminated');
  38397. }
  38398. }
  38399. function startWorkerTask(task) {
  38400. WorkerTasks.push(task);
  38401. }
  38402. function finishWorkerTask(task) {
  38403. task.finish();
  38404. var i = WorkerTasks.indexOf(task);
  38405. WorkerTasks.splice(i, 1);
  38406. }
  38407. function loadDocument(recoveryMode) {
  38408. var loadDocumentCapability = createPromiseCapability();
  38409. var parseSuccess = function parseSuccess() {
  38410. var numPagesPromise = pdfManager.ensureDoc('numPages');
  38411. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  38412. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  38413. Promise.all([numPagesPromise, fingerprintPromise,
  38414. encryptedPromise]).then(function onDocReady(results) {
  38415. var doc = {
  38416. numPages: results[0],
  38417. fingerprint: results[1],
  38418. encrypted: !!results[2],
  38419. };
  38420. loadDocumentCapability.resolve(doc);
  38421. },
  38422. parseFailure);
  38423. };
  38424. var parseFailure = function parseFailure(e) {
  38425. loadDocumentCapability.reject(e);
  38426. };
  38427. pdfManager.ensureDoc('checkHeader', []).then(function() {
  38428. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  38429. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  38430. parseSuccess, parseFailure);
  38431. }, parseFailure);
  38432. }, parseFailure);
  38433. return loadDocumentCapability.promise;
  38434. }
  38435. function getPdfManager(data) {
  38436. var pdfManagerCapability = createPromiseCapability();
  38437. var pdfManager;
  38438. var source = data.source;
  38439. var disableRange = data.disableRange;
  38440. if (source.data) {
  38441. try {
  38442. pdfManager = new LocalPdfManager(source.data, source.password);
  38443. pdfManagerCapability.resolve(pdfManager);
  38444. } catch (ex) {
  38445. pdfManagerCapability.reject(ex);
  38446. }
  38447. return pdfManagerCapability.promise;
  38448. } else if (source.chunkedViewerLoading) {
  38449. try {
  38450. pdfManager = new NetworkPdfManager(source, handler);
  38451. pdfManagerCapability.resolve(pdfManager);
  38452. } catch (ex) {
  38453. pdfManagerCapability.reject(ex);
  38454. }
  38455. return pdfManagerCapability.promise;
  38456. }
  38457. var networkManager = new NetworkManager(source.url, {
  38458. httpHeaders: source.httpHeaders,
  38459. withCredentials: source.withCredentials
  38460. });
  38461. var cachedChunks = [];
  38462. var fullRequestXhrId = networkManager.requestFull({
  38463. onHeadersReceived: function onHeadersReceived() {
  38464. if (disableRange) {
  38465. return;
  38466. }
  38467. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  38468. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  38469. return;
  38470. }
  38471. var contentEncoding =
  38472. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  38473. if (contentEncoding !== 'identity') {
  38474. return;
  38475. }
  38476. var length = fullRequestXhr.getResponseHeader('Content-Length');
  38477. length = parseInt(length, 10);
  38478. if (!isInt(length)) {
  38479. return;
  38480. }
  38481. source.length = length;
  38482. if (length <= 2 * source.rangeChunkSize) {
  38483. // The file size is smaller than the size of two chunks, so it does
  38484. // not make any sense to abort the request and retry with a range
  38485. // request.
  38486. return;
  38487. }
  38488. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  38489. // We can continue fetching when progressive loading is enabled,
  38490. // and we don't need the autoFetch feature.
  38491. source.disableAutoFetch = true;
  38492. } else {
  38493. // NOTE: by cancelling the full request, and then issuing range
  38494. // requests, there will be an issue for sites where you can only
  38495. // request the pdf once. However, if this is the case, then the
  38496. // server should not be returning that it can support range
  38497. // requests.
  38498. networkManager.abortRequest(fullRequestXhrId);
  38499. }
  38500. try {
  38501. pdfManager = new NetworkPdfManager(source, handler);
  38502. pdfManagerCapability.resolve(pdfManager);
  38503. } catch (ex) {
  38504. pdfManagerCapability.reject(ex);
  38505. }
  38506. cancelXHRs = null;
  38507. },
  38508. onProgressiveData: source.disableStream ? null :
  38509. function onProgressiveData(chunk) {
  38510. if (!pdfManager) {
  38511. cachedChunks.push(chunk);
  38512. return;
  38513. }
  38514. pdfManager.sendProgressiveData(chunk);
  38515. },
  38516. onDone: function onDone(args) {
  38517. if (pdfManager) {
  38518. return; // already processed
  38519. }
  38520. var pdfFile;
  38521. if (args === null) {
  38522. // TODO add some streaming manager, e.g. for unknown length files.
  38523. // The data was returned in the onProgressiveData, combining...
  38524. var pdfFileLength = 0, pos = 0;
  38525. cachedChunks.forEach(function (chunk) {
  38526. pdfFileLength += chunk.byteLength;
  38527. });
  38528. if (source.length && pdfFileLength !== source.length) {
  38529. warn('reported HTTP length is different from actual');
  38530. }
  38531. var pdfFileArray = new Uint8Array(pdfFileLength);
  38532. cachedChunks.forEach(function (chunk) {
  38533. pdfFileArray.set(new Uint8Array(chunk), pos);
  38534. pos += chunk.byteLength;
  38535. });
  38536. pdfFile = pdfFileArray.buffer;
  38537. } else {
  38538. pdfFile = args.chunk;
  38539. }
  38540. // the data is array, instantiating directly from it
  38541. try {
  38542. pdfManager = new LocalPdfManager(pdfFile, source.password);
  38543. pdfManagerCapability.resolve(pdfManager);
  38544. } catch (ex) {
  38545. pdfManagerCapability.reject(ex);
  38546. }
  38547. cancelXHRs = null;
  38548. },
  38549. onError: function onError(status) {
  38550. var exception;
  38551. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  38552. exception = new MissingPDFException('Missing PDF "' +
  38553. source.url + '".');
  38554. handler.send('MissingPDF', exception);
  38555. } else {
  38556. exception = new UnexpectedResponseException(
  38557. 'Unexpected server response (' + status +
  38558. ') while retrieving PDF "' + source.url + '".', status);
  38559. handler.send('UnexpectedResponse', exception);
  38560. }
  38561. cancelXHRs = null;
  38562. },
  38563. onProgress: function onProgress(evt) {
  38564. handler.send('DocProgress', {
  38565. loaded: evt.loaded,
  38566. total: evt.lengthComputable ? evt.total : source.length
  38567. });
  38568. }
  38569. });
  38570. cancelXHRs = function () {
  38571. networkManager.abortRequest(fullRequestXhrId);
  38572. };
  38573. return pdfManagerCapability.promise;
  38574. }
  38575. handler.on('test', function wphSetupTest(data) {
  38576. // check if Uint8Array can be sent to worker
  38577. if (!(data instanceof Uint8Array)) {
  38578. handler.send('test', false);
  38579. return;
  38580. }
  38581. // making sure postMessage transfers are working
  38582. var supportTransfers = data[0] === 255;
  38583. handler.postMessageTransfers = supportTransfers;
  38584. // check if the response property is supported by xhr
  38585. var xhr = new XMLHttpRequest();
  38586. var responseExists = 'response' in xhr;
  38587. // check if the property is actually implemented
  38588. try {
  38589. var dummy = xhr.responseType;
  38590. } catch (e) {
  38591. responseExists = false;
  38592. }
  38593. if (!responseExists) {
  38594. handler.send('test', false);
  38595. return;
  38596. }
  38597. handler.send('test', {
  38598. supportTypedArray: true,
  38599. supportTransfers: supportTransfers
  38600. });
  38601. });
  38602. handler.on('GetDocRequest', function wphSetupDoc(data) {
  38603. var onSuccess = function(doc) {
  38604. ensureNotTerminated();
  38605. handler.send('GetDoc', { pdfInfo: doc });
  38606. };
  38607. var onFailure = function(e) {
  38608. if (e instanceof PasswordException) {
  38609. if (e.code === PasswordResponses.NEED_PASSWORD) {
  38610. handler.send('NeedPassword', e);
  38611. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  38612. handler.send('IncorrectPassword', e);
  38613. }
  38614. } else if (e instanceof InvalidPDFException) {
  38615. handler.send('InvalidPDF', e);
  38616. } else if (e instanceof MissingPDFException) {
  38617. handler.send('MissingPDF', e);
  38618. } else if (e instanceof UnexpectedResponseException) {
  38619. handler.send('UnexpectedResponse', e);
  38620. } else {
  38621. handler.send('UnknownError',
  38622. new UnknownErrorException(e.message, e.toString()));
  38623. }
  38624. };
  38625. ensureNotTerminated();
  38626. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  38627. -1 : data.maxImageSize;
  38628. PDFJS.disableFontFace = data.disableFontFace;
  38629. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  38630. PDFJS.verbosity = data.verbosity;
  38631. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  38632. null : data.cMapUrl;
  38633. PDFJS.cMapPacked = data.cMapPacked === true;
  38634. getPdfManager(data).then(function (newPdfManager) {
  38635. if (terminated) {
  38636. // We were in a process of setting up the manager, but it got
  38637. // terminated in the middle.
  38638. newPdfManager.terminate();
  38639. throw new Error('Worker was terminated');
  38640. }
  38641. pdfManager = newPdfManager;
  38642. handler.send('PDFManagerReady', null);
  38643. pdfManager.onLoadedStream().then(function(stream) {
  38644. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  38645. });
  38646. }).then(function pdfManagerReady() {
  38647. ensureNotTerminated();
  38648. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  38649. ensureNotTerminated();
  38650. // Try again with recoveryMode == true
  38651. if (!(ex instanceof XRefParseException)) {
  38652. if (ex instanceof PasswordException) {
  38653. // after password exception prepare to receive a new password
  38654. // to repeat loading
  38655. pdfManager.passwordChanged().then(pdfManagerReady);
  38656. }
  38657. onFailure(ex);
  38658. return;
  38659. }
  38660. pdfManager.requestLoadedStream();
  38661. pdfManager.onLoadedStream().then(function() {
  38662. ensureNotTerminated();
  38663. loadDocument(true).then(onSuccess, onFailure);
  38664. });
  38665. }, onFailure);
  38666. }, onFailure);
  38667. });
  38668. handler.on('GetPage', function wphSetupGetPage(data) {
  38669. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38670. var rotatePromise = pdfManager.ensure(page, 'rotate');
  38671. var refPromise = pdfManager.ensure(page, 'ref');
  38672. var viewPromise = pdfManager.ensure(page, 'view');
  38673. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  38674. function(results) {
  38675. return {
  38676. rotate: results[0],
  38677. ref: results[1],
  38678. view: results[2]
  38679. };
  38680. });
  38681. });
  38682. });
  38683. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  38684. var ref = new Ref(data.ref.num, data.ref.gen);
  38685. var catalog = pdfManager.pdfDocument.catalog;
  38686. return catalog.getPageIndex(ref);
  38687. });
  38688. handler.on('GetDestinations',
  38689. function wphSetupGetDestinations(data) {
  38690. return pdfManager.ensureCatalog('destinations');
  38691. }
  38692. );
  38693. handler.on('GetDestination',
  38694. function wphSetupGetDestination(data) {
  38695. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  38696. }
  38697. );
  38698. handler.on('GetAttachments',
  38699. function wphSetupGetAttachments(data) {
  38700. return pdfManager.ensureCatalog('attachments');
  38701. }
  38702. );
  38703. handler.on('GetJavaScript',
  38704. function wphSetupGetJavaScript(data) {
  38705. return pdfManager.ensureCatalog('javaScript');
  38706. }
  38707. );
  38708. handler.on('GetOutline',
  38709. function wphSetupGetOutline(data) {
  38710. return pdfManager.ensureCatalog('documentOutline');
  38711. }
  38712. );
  38713. handler.on('GetMetadata',
  38714. function wphSetupGetMetadata(data) {
  38715. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  38716. pdfManager.ensureCatalog('metadata')]);
  38717. }
  38718. );
  38719. handler.on('GetData', function wphSetupGetData(data) {
  38720. pdfManager.requestLoadedStream();
  38721. return pdfManager.onLoadedStream().then(function(stream) {
  38722. return stream.bytes;
  38723. });
  38724. });
  38725. handler.on('GetStats',
  38726. function wphSetupGetStats(data) {
  38727. return pdfManager.pdfDocument.xref.stats;
  38728. }
  38729. );
  38730. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  38731. pdfManager.updatePassword(data);
  38732. });
  38733. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  38734. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38735. return pdfManager.ensure(page, 'getAnnotationsData', []);
  38736. });
  38737. });
  38738. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  38739. var pageIndex = data.pageIndex;
  38740. pdfManager.getPage(pageIndex).then(function(page) {
  38741. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  38742. startWorkerTask(task);
  38743. var pageNum = pageIndex + 1;
  38744. var start = Date.now();
  38745. // Pre compile the pdf page and fetch the fonts/images.
  38746. page.getOperatorList(handler, task, data.intent).then(
  38747. function(operatorList) {
  38748. finishWorkerTask(task);
  38749. info('page=' + pageNum + ' - getOperatorList: time=' +
  38750. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  38751. }, function(e) {
  38752. finishWorkerTask(task);
  38753. if (task.terminated) {
  38754. return; // ignoring errors from the terminated thread
  38755. }
  38756. var minimumStackMessage =
  38757. 'worker.js: while trying to getPage() and getOperatorList()';
  38758. var wrappedException;
  38759. // Turn the error into an obj that can be serialized
  38760. if (typeof e === 'string') {
  38761. wrappedException = {
  38762. message: e,
  38763. stack: minimumStackMessage
  38764. };
  38765. } else if (typeof e === 'object') {
  38766. wrappedException = {
  38767. message: e.message || e.toString(),
  38768. stack: e.stack || minimumStackMessage
  38769. };
  38770. } else {
  38771. wrappedException = {
  38772. message: 'Unknown exception type: ' + (typeof e),
  38773. stack: minimumStackMessage
  38774. };
  38775. }
  38776. handler.send('PageError', {
  38777. pageNum: pageNum,
  38778. error: wrappedException,
  38779. intent: data.intent
  38780. });
  38781. });
  38782. });
  38783. }, this);
  38784. handler.on('GetTextContent', function wphExtractText(data) {
  38785. var pageIndex = data.pageIndex;
  38786. return pdfManager.getPage(pageIndex).then(function(page) {
  38787. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  38788. startWorkerTask(task);
  38789. var pageNum = pageIndex + 1;
  38790. var start = Date.now();
  38791. return page.extractTextContent(task).then(function(textContent) {
  38792. finishWorkerTask(task);
  38793. info('text indexing: page=' + pageNum + ' - time=' +
  38794. (Date.now() - start) + 'ms');
  38795. return textContent;
  38796. }, function (reason) {
  38797. finishWorkerTask(task);
  38798. if (task.terminated) {
  38799. return; // ignoring errors from the terminated thread
  38800. }
  38801. throw reason;
  38802. });
  38803. });
  38804. });
  38805. handler.on('Cleanup', function wphCleanup(data) {
  38806. return pdfManager.cleanup();
  38807. });
  38808. handler.on('Terminate', function wphTerminate(data) {
  38809. terminated = true;
  38810. if (pdfManager) {
  38811. pdfManager.terminate();
  38812. pdfManager = null;
  38813. }
  38814. if (cancelXHRs) {
  38815. cancelXHRs();
  38816. }
  38817. var waitOn = [];
  38818. WorkerTasks.forEach(function (task) {
  38819. waitOn.push(task.finished);
  38820. task.terminate();
  38821. });
  38822. return Promise.all(waitOn).then(function () {});
  38823. });
  38824. }
  38825. };
  38826. var consoleTimer = {};
  38827. var workerConsole = {
  38828. log: function log() {
  38829. var args = Array.prototype.slice.call(arguments);
  38830. globalScope.postMessage({
  38831. action: 'console_log',
  38832. data: args
  38833. });
  38834. },
  38835. error: function error() {
  38836. var args = Array.prototype.slice.call(arguments);
  38837. globalScope.postMessage({
  38838. action: 'console_error',
  38839. data: args
  38840. });
  38841. throw 'pdf.js execution error';
  38842. },
  38843. time: function time(name) {
  38844. consoleTimer[name] = Date.now();
  38845. },
  38846. timeEnd: function timeEnd(name) {
  38847. var time = consoleTimer[name];
  38848. if (!time) {
  38849. error('Unknown timer name ' + name);
  38850. }
  38851. this.log('Timer:', name, Date.now() - time);
  38852. }
  38853. };
  38854. // Worker thread?
  38855. if (typeof window === 'undefined') {
  38856. if (!('console' in globalScope)) {
  38857. globalScope.console = workerConsole;
  38858. }
  38859. // Listen for unsupported features so we can pass them on to the main thread.
  38860. PDFJS.UnsupportedManager.listen(function (msg) {
  38861. globalScope.postMessage({
  38862. action: '_unsupported_feature',
  38863. data: msg
  38864. });
  38865. });
  38866. var handler = new MessageHandler('worker_processor', this);
  38867. WorkerMessageHandler.setup(handler);
  38868. }
  38869. /* This class implements the QM Coder decoding as defined in
  38870. * JPEG 2000 Part I Final Committee Draft Version 1.0
  38871. * Annex C.3 Arithmetic decoding procedure
  38872. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  38873. *
  38874. * The arithmetic decoder is used in conjunction with context models to decode
  38875. * JPEG2000 and JBIG2 streams.
  38876. */
  38877. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  38878. // Table C-2
  38879. var QeTable = [
  38880. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  38881. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  38882. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  38883. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  38884. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  38885. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  38886. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  38887. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  38888. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  38889. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  38890. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  38891. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  38892. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  38893. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  38894. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  38895. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  38896. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  38897. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  38898. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  38899. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  38900. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  38901. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  38902. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  38903. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  38904. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  38905. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  38906. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  38907. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  38908. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  38909. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  38910. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  38911. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  38912. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  38913. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  38914. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  38915. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  38916. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  38917. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  38918. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  38919. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  38920. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  38921. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  38922. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  38923. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  38924. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  38925. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  38926. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  38927. ];
  38928. // C.3.5 Initialisation of the decoder (INITDEC)
  38929. function ArithmeticDecoder(data, start, end) {
  38930. this.data = data;
  38931. this.bp = start;
  38932. this.dataEnd = end;
  38933. this.chigh = data[start];
  38934. this.clow = 0;
  38935. this.byteIn();
  38936. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  38937. this.clow = (this.clow << 7) & 0xFFFF;
  38938. this.ct -= 7;
  38939. this.a = 0x8000;
  38940. }
  38941. ArithmeticDecoder.prototype = {
  38942. // C.3.4 Compressed data input (BYTEIN)
  38943. byteIn: function ArithmeticDecoder_byteIn() {
  38944. var data = this.data;
  38945. var bp = this.bp;
  38946. if (data[bp] === 0xFF) {
  38947. var b1 = data[bp + 1];
  38948. if (b1 > 0x8F) {
  38949. this.clow += 0xFF00;
  38950. this.ct = 8;
  38951. } else {
  38952. bp++;
  38953. this.clow += (data[bp] << 9);
  38954. this.ct = 7;
  38955. this.bp = bp;
  38956. }
  38957. } else {
  38958. bp++;
  38959. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  38960. this.ct = 8;
  38961. this.bp = bp;
  38962. }
  38963. if (this.clow > 0xFFFF) {
  38964. this.chigh += (this.clow >> 16);
  38965. this.clow &= 0xFFFF;
  38966. }
  38967. },
  38968. // C.3.2 Decoding a decision (DECODE)
  38969. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  38970. // contexts are packed into 1 byte:
  38971. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  38972. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  38973. var qeTableIcx = QeTable[cx_index];
  38974. var qeIcx = qeTableIcx.qe;
  38975. var d;
  38976. var a = this.a - qeIcx;
  38977. if (this.chigh < qeIcx) {
  38978. // exchangeLps
  38979. if (a < qeIcx) {
  38980. a = qeIcx;
  38981. d = cx_mps;
  38982. cx_index = qeTableIcx.nmps;
  38983. } else {
  38984. a = qeIcx;
  38985. d = 1 ^ cx_mps;
  38986. if (qeTableIcx.switchFlag === 1) {
  38987. cx_mps = d;
  38988. }
  38989. cx_index = qeTableIcx.nlps;
  38990. }
  38991. } else {
  38992. this.chigh -= qeIcx;
  38993. if ((a & 0x8000) !== 0) {
  38994. this.a = a;
  38995. return cx_mps;
  38996. }
  38997. // exchangeMps
  38998. if (a < qeIcx) {
  38999. d = 1 ^ cx_mps;
  39000. if (qeTableIcx.switchFlag === 1) {
  39001. cx_mps = d;
  39002. }
  39003. cx_index = qeTableIcx.nlps;
  39004. } else {
  39005. d = cx_mps;
  39006. cx_index = qeTableIcx.nmps;
  39007. }
  39008. }
  39009. // C.3.3 renormD;
  39010. do {
  39011. if (this.ct === 0) {
  39012. this.byteIn();
  39013. }
  39014. a <<= 1;
  39015. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  39016. this.clow = (this.clow << 1) & 0xFFFF;
  39017. this.ct--;
  39018. } while ((a & 0x8000) === 0);
  39019. this.a = a;
  39020. contexts[pos] = cx_index << 1 | cx_mps;
  39021. return d;
  39022. }
  39023. };
  39024. return ArithmeticDecoder;
  39025. })();
  39026. var JpegImage = (function jpegImage() {
  39027. var dctZigZag = new Uint8Array([
  39028. 0,
  39029. 1, 8,
  39030. 16, 9, 2,
  39031. 3, 10, 17, 24,
  39032. 32, 25, 18, 11, 4,
  39033. 5, 12, 19, 26, 33, 40,
  39034. 48, 41, 34, 27, 20, 13, 6,
  39035. 7, 14, 21, 28, 35, 42, 49, 56,
  39036. 57, 50, 43, 36, 29, 22, 15,
  39037. 23, 30, 37, 44, 51, 58,
  39038. 59, 52, 45, 38, 31,
  39039. 39, 46, 53, 60,
  39040. 61, 54, 47,
  39041. 55, 62,
  39042. 63
  39043. ]);
  39044. var dctCos1 = 4017; // cos(pi/16)
  39045. var dctSin1 = 799; // sin(pi/16)
  39046. var dctCos3 = 3406; // cos(3*pi/16)
  39047. var dctSin3 = 2276; // sin(3*pi/16)
  39048. var dctCos6 = 1567; // cos(6*pi/16)
  39049. var dctSin6 = 3784; // sin(6*pi/16)
  39050. var dctSqrt2 = 5793; // sqrt(2)
  39051. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  39052. function constructor() {
  39053. }
  39054. function buildHuffmanTable(codeLengths, values) {
  39055. var k = 0, code = [], i, j, length = 16;
  39056. while (length > 0 && !codeLengths[length - 1]) {
  39057. length--;
  39058. }
  39059. code.push({children: [], index: 0});
  39060. var p = code[0], q;
  39061. for (i = 0; i < length; i++) {
  39062. for (j = 0; j < codeLengths[i]; j++) {
  39063. p = code.pop();
  39064. p.children[p.index] = values[k];
  39065. while (p.index > 0) {
  39066. p = code.pop();
  39067. }
  39068. p.index++;
  39069. code.push(p);
  39070. while (code.length <= i) {
  39071. code.push(q = {children: [], index: 0});
  39072. p.children[p.index] = q.children;
  39073. p = q;
  39074. }
  39075. k++;
  39076. }
  39077. if (i + 1 < length) {
  39078. // p here points to last code
  39079. code.push(q = {children: [], index: 0});
  39080. p.children[p.index] = q.children;
  39081. p = q;
  39082. }
  39083. }
  39084. return code[0].children;
  39085. }
  39086. function getBlockBufferOffset(component, row, col) {
  39087. return 64 * ((component.blocksPerLine + 1) * row + col);
  39088. }
  39089. function decodeScan(data, offset, frame, components, resetInterval,
  39090. spectralStart, spectralEnd, successivePrev, successive) {
  39091. var precision = frame.precision;
  39092. var samplesPerLine = frame.samplesPerLine;
  39093. var scanLines = frame.scanLines;
  39094. var mcusPerLine = frame.mcusPerLine;
  39095. var progressive = frame.progressive;
  39096. var maxH = frame.maxH, maxV = frame.maxV;
  39097. var startOffset = offset, bitsData = 0, bitsCount = 0;
  39098. function readBit() {
  39099. if (bitsCount > 0) {
  39100. bitsCount--;
  39101. return (bitsData >> bitsCount) & 1;
  39102. }
  39103. bitsData = data[offset++];
  39104. if (bitsData === 0xFF) {
  39105. var nextByte = data[offset++];
  39106. if (nextByte) {
  39107. throw 'unexpected marker: ' +
  39108. ((bitsData << 8) | nextByte).toString(16);
  39109. }
  39110. // unstuff 0
  39111. }
  39112. bitsCount = 7;
  39113. return bitsData >>> 7;
  39114. }
  39115. function decodeHuffman(tree) {
  39116. var node = tree;
  39117. while (true) {
  39118. node = node[readBit()];
  39119. if (typeof node === 'number') {
  39120. return node;
  39121. }
  39122. if (typeof node !== 'object') {
  39123. throw 'invalid huffman sequence';
  39124. }
  39125. }
  39126. }
  39127. function receive(length) {
  39128. var n = 0;
  39129. while (length > 0) {
  39130. n = (n << 1) | readBit();
  39131. length--;
  39132. }
  39133. return n;
  39134. }
  39135. function receiveAndExtend(length) {
  39136. if (length === 1) {
  39137. return readBit() === 1 ? 1 : -1;
  39138. }
  39139. var n = receive(length);
  39140. if (n >= 1 << (length - 1)) {
  39141. return n;
  39142. }
  39143. return n + (-1 << length) + 1;
  39144. }
  39145. function decodeBaseline(component, offset) {
  39146. var t = decodeHuffman(component.huffmanTableDC);
  39147. var diff = t === 0 ? 0 : receiveAndExtend(t);
  39148. component.blockData[offset] = (component.pred += diff);
  39149. var k = 1;
  39150. while (k < 64) {
  39151. var rs = decodeHuffman(component.huffmanTableAC);
  39152. var s = rs & 15, r = rs >> 4;
  39153. if (s === 0) {
  39154. if (r < 15) {
  39155. break;
  39156. }
  39157. k += 16;
  39158. continue;
  39159. }
  39160. k += r;
  39161. var z = dctZigZag[k];
  39162. component.blockData[offset + z] = receiveAndExtend(s);
  39163. k++;
  39164. }
  39165. }
  39166. function decodeDCFirst(component, offset) {
  39167. var t = decodeHuffman(component.huffmanTableDC);
  39168. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  39169. component.blockData[offset] = (component.pred += diff);
  39170. }
  39171. function decodeDCSuccessive(component, offset) {
  39172. component.blockData[offset] |= readBit() << successive;
  39173. }
  39174. var eobrun = 0;
  39175. function decodeACFirst(component, offset) {
  39176. if (eobrun > 0) {
  39177. eobrun--;
  39178. return;
  39179. }
  39180. var k = spectralStart, e = spectralEnd;
  39181. while (k <= e) {
  39182. var rs = decodeHuffman(component.huffmanTableAC);
  39183. var s = rs & 15, r = rs >> 4;
  39184. if (s === 0) {
  39185. if (r < 15) {
  39186. eobrun = receive(r) + (1 << r) - 1;
  39187. break;
  39188. }
  39189. k += 16;
  39190. continue;
  39191. }
  39192. k += r;
  39193. var z = dctZigZag[k];
  39194. component.blockData[offset + z] =
  39195. receiveAndExtend(s) * (1 << successive);
  39196. k++;
  39197. }
  39198. }
  39199. var successiveACState = 0, successiveACNextValue;
  39200. function decodeACSuccessive(component, offset) {
  39201. var k = spectralStart;
  39202. var e = spectralEnd;
  39203. var r = 0;
  39204. var s;
  39205. var rs;
  39206. while (k <= e) {
  39207. var z = dctZigZag[k];
  39208. switch (successiveACState) {
  39209. case 0: // initial state
  39210. rs = decodeHuffman(component.huffmanTableAC);
  39211. s = rs & 15;
  39212. r = rs >> 4;
  39213. if (s === 0) {
  39214. if (r < 15) {
  39215. eobrun = receive(r) + (1 << r);
  39216. successiveACState = 4;
  39217. } else {
  39218. r = 16;
  39219. successiveACState = 1;
  39220. }
  39221. } else {
  39222. if (s !== 1) {
  39223. throw 'invalid ACn encoding';
  39224. }
  39225. successiveACNextValue = receiveAndExtend(s);
  39226. successiveACState = r ? 2 : 3;
  39227. }
  39228. continue;
  39229. case 1: // skipping r zero items
  39230. case 2:
  39231. if (component.blockData[offset + z]) {
  39232. component.blockData[offset + z] += (readBit() << successive);
  39233. } else {
  39234. r--;
  39235. if (r === 0) {
  39236. successiveACState = successiveACState === 2 ? 3 : 0;
  39237. }
  39238. }
  39239. break;
  39240. case 3: // set value for a zero item
  39241. if (component.blockData[offset + z]) {
  39242. component.blockData[offset + z] += (readBit() << successive);
  39243. } else {
  39244. component.blockData[offset + z] =
  39245. successiveACNextValue << successive;
  39246. successiveACState = 0;
  39247. }
  39248. break;
  39249. case 4: // eob
  39250. if (component.blockData[offset + z]) {
  39251. component.blockData[offset + z] += (readBit() << successive);
  39252. }
  39253. break;
  39254. }
  39255. k++;
  39256. }
  39257. if (successiveACState === 4) {
  39258. eobrun--;
  39259. if (eobrun === 0) {
  39260. successiveACState = 0;
  39261. }
  39262. }
  39263. }
  39264. function decodeMcu(component, decode, mcu, row, col) {
  39265. var mcuRow = (mcu / mcusPerLine) | 0;
  39266. var mcuCol = mcu % mcusPerLine;
  39267. var blockRow = mcuRow * component.v + row;
  39268. var blockCol = mcuCol * component.h + col;
  39269. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  39270. decode(component, offset);
  39271. }
  39272. function decodeBlock(component, decode, mcu) {
  39273. var blockRow = (mcu / component.blocksPerLine) | 0;
  39274. var blockCol = mcu % component.blocksPerLine;
  39275. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  39276. decode(component, offset);
  39277. }
  39278. var componentsLength = components.length;
  39279. var component, i, j, k, n;
  39280. var decodeFn;
  39281. if (progressive) {
  39282. if (spectralStart === 0) {
  39283. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  39284. } else {
  39285. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  39286. }
  39287. } else {
  39288. decodeFn = decodeBaseline;
  39289. }
  39290. var mcu = 0, marker;
  39291. var mcuExpected;
  39292. if (componentsLength === 1) {
  39293. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  39294. } else {
  39295. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  39296. }
  39297. if (!resetInterval) {
  39298. resetInterval = mcuExpected;
  39299. }
  39300. var h, v;
  39301. while (mcu < mcuExpected) {
  39302. // reset interval stuff
  39303. for (i = 0; i < componentsLength; i++) {
  39304. components[i].pred = 0;
  39305. }
  39306. eobrun = 0;
  39307. if (componentsLength === 1) {
  39308. component = components[0];
  39309. for (n = 0; n < resetInterval; n++) {
  39310. decodeBlock(component, decodeFn, mcu);
  39311. mcu++;
  39312. }
  39313. } else {
  39314. for (n = 0; n < resetInterval; n++) {
  39315. for (i = 0; i < componentsLength; i++) {
  39316. component = components[i];
  39317. h = component.h;
  39318. v = component.v;
  39319. for (j = 0; j < v; j++) {
  39320. for (k = 0; k < h; k++) {
  39321. decodeMcu(component, decodeFn, mcu, j, k);
  39322. }
  39323. }
  39324. }
  39325. mcu++;
  39326. }
  39327. }
  39328. // find marker
  39329. bitsCount = 0;
  39330. marker = (data[offset] << 8) | data[offset + 1];
  39331. if (marker <= 0xFF00) {
  39332. throw 'marker was not found';
  39333. }
  39334. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  39335. offset += 2;
  39336. } else {
  39337. break;
  39338. }
  39339. }
  39340. return offset - startOffset;
  39341. }
  39342. // A port of poppler's IDCT method which in turn is taken from:
  39343. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  39344. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  39345. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  39346. // 988-991.
  39347. function quantizeAndInverse(component, blockBufferOffset, p) {
  39348. var qt = component.quantizationTable, blockData = component.blockData;
  39349. var v0, v1, v2, v3, v4, v5, v6, v7;
  39350. var p0, p1, p2, p3, p4, p5, p6, p7;
  39351. var t;
  39352. // inverse DCT on rows
  39353. for (var row = 0; row < 64; row += 8) {
  39354. // gather block data
  39355. p0 = blockData[blockBufferOffset + row];
  39356. p1 = blockData[blockBufferOffset + row + 1];
  39357. p2 = blockData[blockBufferOffset + row + 2];
  39358. p3 = blockData[blockBufferOffset + row + 3];
  39359. p4 = blockData[blockBufferOffset + row + 4];
  39360. p5 = blockData[blockBufferOffset + row + 5];
  39361. p6 = blockData[blockBufferOffset + row + 6];
  39362. p7 = blockData[blockBufferOffset + row + 7];
  39363. // dequant p0
  39364. p0 *= qt[row];
  39365. // check for all-zero AC coefficients
  39366. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  39367. t = (dctSqrt2 * p0 + 512) >> 10;
  39368. p[row] = t;
  39369. p[row + 1] = t;
  39370. p[row + 2] = t;
  39371. p[row + 3] = t;
  39372. p[row + 4] = t;
  39373. p[row + 5] = t;
  39374. p[row + 6] = t;
  39375. p[row + 7] = t;
  39376. continue;
  39377. }
  39378. // dequant p1 ... p7
  39379. p1 *= qt[row + 1];
  39380. p2 *= qt[row + 2];
  39381. p3 *= qt[row + 3];
  39382. p4 *= qt[row + 4];
  39383. p5 *= qt[row + 5];
  39384. p6 *= qt[row + 6];
  39385. p7 *= qt[row + 7];
  39386. // stage 4
  39387. v0 = (dctSqrt2 * p0 + 128) >> 8;
  39388. v1 = (dctSqrt2 * p4 + 128) >> 8;
  39389. v2 = p2;
  39390. v3 = p6;
  39391. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  39392. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  39393. v5 = p3 << 4;
  39394. v6 = p5 << 4;
  39395. // stage 3
  39396. v0 = (v0 + v1 + 1) >> 1;
  39397. v1 = v0 - v1;
  39398. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  39399. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  39400. v3 = t;
  39401. v4 = (v4 + v6 + 1) >> 1;
  39402. v6 = v4 - v6;
  39403. v7 = (v7 + v5 + 1) >> 1;
  39404. v5 = v7 - v5;
  39405. // stage 2
  39406. v0 = (v0 + v3 + 1) >> 1;
  39407. v3 = v0 - v3;
  39408. v1 = (v1 + v2 + 1) >> 1;
  39409. v2 = v1 - v2;
  39410. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  39411. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  39412. v7 = t;
  39413. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  39414. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  39415. v6 = t;
  39416. // stage 1
  39417. p[row] = v0 + v7;
  39418. p[row + 7] = v0 - v7;
  39419. p[row + 1] = v1 + v6;
  39420. p[row + 6] = v1 - v6;
  39421. p[row + 2] = v2 + v5;
  39422. p[row + 5] = v2 - v5;
  39423. p[row + 3] = v3 + v4;
  39424. p[row + 4] = v3 - v4;
  39425. }
  39426. // inverse DCT on columns
  39427. for (var col = 0; col < 8; ++col) {
  39428. p0 = p[col];
  39429. p1 = p[col + 8];
  39430. p2 = p[col + 16];
  39431. p3 = p[col + 24];
  39432. p4 = p[col + 32];
  39433. p5 = p[col + 40];
  39434. p6 = p[col + 48];
  39435. p7 = p[col + 56];
  39436. // check for all-zero AC coefficients
  39437. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  39438. t = (dctSqrt2 * p0 + 8192) >> 14;
  39439. // convert to 8 bit
  39440. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  39441. blockData[blockBufferOffset + col] = t;
  39442. blockData[blockBufferOffset + col + 8] = t;
  39443. blockData[blockBufferOffset + col + 16] = t;
  39444. blockData[blockBufferOffset + col + 24] = t;
  39445. blockData[blockBufferOffset + col + 32] = t;
  39446. blockData[blockBufferOffset + col + 40] = t;
  39447. blockData[blockBufferOffset + col + 48] = t;
  39448. blockData[blockBufferOffset + col + 56] = t;
  39449. continue;
  39450. }
  39451. // stage 4
  39452. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  39453. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  39454. v2 = p2;
  39455. v3 = p6;
  39456. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  39457. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  39458. v5 = p3;
  39459. v6 = p5;
  39460. // stage 3
  39461. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  39462. // converting to UInt8 range later.
  39463. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  39464. v1 = v0 - v1;
  39465. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  39466. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  39467. v3 = t;
  39468. v4 = (v4 + v6 + 1) >> 1;
  39469. v6 = v4 - v6;
  39470. v7 = (v7 + v5 + 1) >> 1;
  39471. v5 = v7 - v5;
  39472. // stage 2
  39473. v0 = (v0 + v3 + 1) >> 1;
  39474. v3 = v0 - v3;
  39475. v1 = (v1 + v2 + 1) >> 1;
  39476. v2 = v1 - v2;
  39477. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  39478. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  39479. v7 = t;
  39480. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  39481. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  39482. v6 = t;
  39483. // stage 1
  39484. p0 = v0 + v7;
  39485. p7 = v0 - v7;
  39486. p1 = v1 + v6;
  39487. p6 = v1 - v6;
  39488. p2 = v2 + v5;
  39489. p5 = v2 - v5;
  39490. p3 = v3 + v4;
  39491. p4 = v3 - v4;
  39492. // convert to 8-bit integers
  39493. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  39494. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  39495. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  39496. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  39497. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  39498. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  39499. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  39500. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  39501. // store block data
  39502. blockData[blockBufferOffset + col] = p0;
  39503. blockData[blockBufferOffset + col + 8] = p1;
  39504. blockData[blockBufferOffset + col + 16] = p2;
  39505. blockData[blockBufferOffset + col + 24] = p3;
  39506. blockData[blockBufferOffset + col + 32] = p4;
  39507. blockData[blockBufferOffset + col + 40] = p5;
  39508. blockData[blockBufferOffset + col + 48] = p6;
  39509. blockData[blockBufferOffset + col + 56] = p7;
  39510. }
  39511. }
  39512. function buildComponentData(frame, component) {
  39513. var blocksPerLine = component.blocksPerLine;
  39514. var blocksPerColumn = component.blocksPerColumn;
  39515. var computationBuffer = new Int16Array(64);
  39516. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  39517. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  39518. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  39519. quantizeAndInverse(component, offset, computationBuffer);
  39520. }
  39521. }
  39522. return component.blockData;
  39523. }
  39524. function clamp0to255(a) {
  39525. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  39526. }
  39527. constructor.prototype = {
  39528. parse: function parse(data) {
  39529. function readUint16() {
  39530. var value = (data[offset] << 8) | data[offset + 1];
  39531. offset += 2;
  39532. return value;
  39533. }
  39534. function readDataBlock() {
  39535. var length = readUint16();
  39536. var array = data.subarray(offset, offset + length - 2);
  39537. offset += array.length;
  39538. return array;
  39539. }
  39540. function prepareComponents(frame) {
  39541. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  39542. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  39543. for (var i = 0; i < frame.components.length; i++) {
  39544. component = frame.components[i];
  39545. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  39546. component.h / frame.maxH);
  39547. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  39548. component.v / frame.maxV);
  39549. var blocksPerLineForMcu = mcusPerLine * component.h;
  39550. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  39551. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  39552. (blocksPerLineForMcu + 1);
  39553. component.blockData = new Int16Array(blocksBufferSize);
  39554. component.blocksPerLine = blocksPerLine;
  39555. component.blocksPerColumn = blocksPerColumn;
  39556. }
  39557. frame.mcusPerLine = mcusPerLine;
  39558. frame.mcusPerColumn = mcusPerColumn;
  39559. }
  39560. var offset = 0, length = data.length;
  39561. var jfif = null;
  39562. var adobe = null;
  39563. var pixels = null;
  39564. var frame, resetInterval;
  39565. var quantizationTables = [];
  39566. var huffmanTablesAC = [], huffmanTablesDC = [];
  39567. var fileMarker = readUint16();
  39568. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  39569. throw 'SOI not found';
  39570. }
  39571. fileMarker = readUint16();
  39572. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  39573. var i, j, l;
  39574. switch(fileMarker) {
  39575. case 0xFFE0: // APP0 (Application Specific)
  39576. case 0xFFE1: // APP1
  39577. case 0xFFE2: // APP2
  39578. case 0xFFE3: // APP3
  39579. case 0xFFE4: // APP4
  39580. case 0xFFE5: // APP5
  39581. case 0xFFE6: // APP6
  39582. case 0xFFE7: // APP7
  39583. case 0xFFE8: // APP8
  39584. case 0xFFE9: // APP9
  39585. case 0xFFEA: // APP10
  39586. case 0xFFEB: // APP11
  39587. case 0xFFEC: // APP12
  39588. case 0xFFED: // APP13
  39589. case 0xFFEE: // APP14
  39590. case 0xFFEF: // APP15
  39591. case 0xFFFE: // COM (Comment)
  39592. var appData = readDataBlock();
  39593. if (fileMarker === 0xFFE0) {
  39594. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  39595. appData[2] === 0x49 && appData[3] === 0x46 &&
  39596. appData[4] === 0) { // 'JFIF\x00'
  39597. jfif = {
  39598. version: { major: appData[5], minor: appData[6] },
  39599. densityUnits: appData[7],
  39600. xDensity: (appData[8] << 8) | appData[9],
  39601. yDensity: (appData[10] << 8) | appData[11],
  39602. thumbWidth: appData[12],
  39603. thumbHeight: appData[13],
  39604. thumbData: appData.subarray(14, 14 +
  39605. 3 * appData[12] * appData[13])
  39606. };
  39607. }
  39608. }
  39609. // TODO APP1 - Exif
  39610. if (fileMarker === 0xFFEE) {
  39611. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  39612. appData[2] === 0x6F && appData[3] === 0x62 &&
  39613. appData[4] === 0x65) { // 'Adobe'
  39614. adobe = {
  39615. version: (appData[5] << 8) | appData[6],
  39616. flags0: (appData[7] << 8) | appData[8],
  39617. flags1: (appData[9] << 8) | appData[10],
  39618. transformCode: appData[11]
  39619. };
  39620. }
  39621. }
  39622. break;
  39623. case 0xFFDB: // DQT (Define Quantization Tables)
  39624. var quantizationTablesLength = readUint16();
  39625. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  39626. var z;
  39627. while (offset < quantizationTablesEnd) {
  39628. var quantizationTableSpec = data[offset++];
  39629. var tableData = new Uint16Array(64);
  39630. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  39631. for (j = 0; j < 64; j++) {
  39632. z = dctZigZag[j];
  39633. tableData[z] = data[offset++];
  39634. }
  39635. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  39636. for (j = 0; j < 64; j++) {
  39637. z = dctZigZag[j];
  39638. tableData[z] = readUint16();
  39639. }
  39640. } else {
  39641. throw 'DQT: invalid table spec';
  39642. }
  39643. quantizationTables[quantizationTableSpec & 15] = tableData;
  39644. }
  39645. break;
  39646. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  39647. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  39648. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  39649. if (frame) {
  39650. throw 'Only single frame JPEGs supported';
  39651. }
  39652. readUint16(); // skip data length
  39653. frame = {};
  39654. frame.extended = (fileMarker === 0xFFC1);
  39655. frame.progressive = (fileMarker === 0xFFC2);
  39656. frame.precision = data[offset++];
  39657. frame.scanLines = readUint16();
  39658. frame.samplesPerLine = readUint16();
  39659. frame.components = [];
  39660. frame.componentIds = {};
  39661. var componentsCount = data[offset++], componentId;
  39662. var maxH = 0, maxV = 0;
  39663. for (i = 0; i < componentsCount; i++) {
  39664. componentId = data[offset];
  39665. var h = data[offset + 1] >> 4;
  39666. var v = data[offset + 1] & 15;
  39667. if (maxH < h) {
  39668. maxH = h;
  39669. }
  39670. if (maxV < v) {
  39671. maxV = v;
  39672. }
  39673. var qId = data[offset + 2];
  39674. l = frame.components.push({
  39675. h: h,
  39676. v: v,
  39677. quantizationTable: quantizationTables[qId]
  39678. });
  39679. frame.componentIds[componentId] = l - 1;
  39680. offset += 3;
  39681. }
  39682. frame.maxH = maxH;
  39683. frame.maxV = maxV;
  39684. prepareComponents(frame);
  39685. break;
  39686. case 0xFFC4: // DHT (Define Huffman Tables)
  39687. var huffmanLength = readUint16();
  39688. for (i = 2; i < huffmanLength;) {
  39689. var huffmanTableSpec = data[offset++];
  39690. var codeLengths = new Uint8Array(16);
  39691. var codeLengthSum = 0;
  39692. for (j = 0; j < 16; j++, offset++) {
  39693. codeLengthSum += (codeLengths[j] = data[offset]);
  39694. }
  39695. var huffmanValues = new Uint8Array(codeLengthSum);
  39696. for (j = 0; j < codeLengthSum; j++, offset++) {
  39697. huffmanValues[j] = data[offset];
  39698. }
  39699. i += 17 + codeLengthSum;
  39700. ((huffmanTableSpec >> 4) === 0 ?
  39701. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  39702. buildHuffmanTable(codeLengths, huffmanValues);
  39703. }
  39704. break;
  39705. case 0xFFDD: // DRI (Define Restart Interval)
  39706. readUint16(); // skip data length
  39707. resetInterval = readUint16();
  39708. break;
  39709. case 0xFFDA: // SOS (Start of Scan)
  39710. var scanLength = readUint16();
  39711. var selectorsCount = data[offset++];
  39712. var components = [], component;
  39713. for (i = 0; i < selectorsCount; i++) {
  39714. var componentIndex = frame.componentIds[data[offset++]];
  39715. component = frame.components[componentIndex];
  39716. var tableSpec = data[offset++];
  39717. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  39718. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  39719. components.push(component);
  39720. }
  39721. var spectralStart = data[offset++];
  39722. var spectralEnd = data[offset++];
  39723. var successiveApproximation = data[offset++];
  39724. var processed = decodeScan(data, offset,
  39725. frame, components, resetInterval,
  39726. spectralStart, spectralEnd,
  39727. successiveApproximation >> 4, successiveApproximation & 15);
  39728. offset += processed;
  39729. break;
  39730. case 0xFFFF: // Fill bytes
  39731. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  39732. offset--;
  39733. }
  39734. break;
  39735. default:
  39736. if (data[offset - 3] === 0xFF &&
  39737. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  39738. // could be incorrect encoding -- last 0xFF byte of the previous
  39739. // block was eaten by the encoder
  39740. offset -= 3;
  39741. break;
  39742. }
  39743. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  39744. }
  39745. fileMarker = readUint16();
  39746. }
  39747. this.width = frame.samplesPerLine;
  39748. this.height = frame.scanLines;
  39749. this.jfif = jfif;
  39750. this.adobe = adobe;
  39751. this.components = [];
  39752. for (i = 0; i < frame.components.length; i++) {
  39753. component = frame.components[i];
  39754. this.components.push({
  39755. output: buildComponentData(frame, component),
  39756. scaleX: component.h / frame.maxH,
  39757. scaleY: component.v / frame.maxV,
  39758. blocksPerLine: component.blocksPerLine,
  39759. blocksPerColumn: component.blocksPerColumn
  39760. });
  39761. }
  39762. this.numComponents = this.components.length;
  39763. },
  39764. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  39765. var scaleX = this.width / width, scaleY = this.height / height;
  39766. var component, componentScaleX, componentScaleY, blocksPerScanline;
  39767. var x, y, i, j, k;
  39768. var index;
  39769. var offset = 0;
  39770. var output;
  39771. var numComponents = this.components.length;
  39772. var dataLength = width * height * numComponents;
  39773. var data = new Uint8Array(dataLength);
  39774. var xScaleBlockOffset = new Uint32Array(width);
  39775. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  39776. for (i = 0; i < numComponents; i++) {
  39777. component = this.components[i];
  39778. componentScaleX = component.scaleX * scaleX;
  39779. componentScaleY = component.scaleY * scaleY;
  39780. offset = i;
  39781. output = component.output;
  39782. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  39783. // precalculate the xScaleBlockOffset
  39784. for (x = 0; x < width; x++) {
  39785. j = 0 | (x * componentScaleX);
  39786. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  39787. }
  39788. // linearize the blocks of the component
  39789. for (y = 0; y < height; y++) {
  39790. j = 0 | (y * componentScaleY);
  39791. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  39792. for (x = 0; x < width; x++) {
  39793. data[offset] = output[index + xScaleBlockOffset[x]];
  39794. offset += numComponents;
  39795. }
  39796. }
  39797. }
  39798. // decodeTransform contains pairs of multiplier (-256..256) and additive
  39799. var transform = this.decodeTransform;
  39800. if (transform) {
  39801. for (i = 0; i < dataLength;) {
  39802. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  39803. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  39804. }
  39805. }
  39806. }
  39807. return data;
  39808. },
  39809. _isColorConversionNeeded: function isColorConversionNeeded() {
  39810. if (this.adobe && this.adobe.transformCode) {
  39811. // The adobe transform marker overrides any previous setting
  39812. return true;
  39813. } else if (this.numComponents === 3) {
  39814. return true;
  39815. } else {
  39816. return false;
  39817. }
  39818. },
  39819. _convertYccToRgb: function convertYccToRgb(data) {
  39820. var Y, Cb, Cr;
  39821. for (var i = 0, length = data.length; i < length; i += 3) {
  39822. Y = data[i ];
  39823. Cb = data[i + 1];
  39824. Cr = data[i + 2];
  39825. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  39826. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  39827. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  39828. }
  39829. return data;
  39830. },
  39831. _convertYcckToRgb: function convertYcckToRgb(data) {
  39832. var Y, Cb, Cr, k;
  39833. var offset = 0;
  39834. for (var i = 0, length = data.length; i < length; i += 4) {
  39835. Y = data[i];
  39836. Cb = data[i + 1];
  39837. Cr = data[i + 2];
  39838. k = data[i + 3];
  39839. var r = -122.67195406894 +
  39840. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  39841. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  39842. 0.154362151871126) +
  39843. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  39844. 0.00477271405408747 * k + 1.53380253221734) +
  39845. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  39846. 0.48357088451265) +
  39847. k * (-0.000336197177618394 * k + 0.484791561490776);
  39848. var g = 107.268039397724 +
  39849. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  39850. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  39851. 0.176491792462875) +
  39852. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  39853. 0.000770482631801132 * k - 0.151051492775562) +
  39854. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  39855. 0.25802910206845) +
  39856. k * (-0.000318913117588328 * k - 0.213742400323665);
  39857. var b = -20.810012546947 +
  39858. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  39859. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  39860. 0.814272968359295) +
  39861. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  39862. 0.000560833691242812 * k - 0.195152027534049) +
  39863. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  39864. 0.116935020465145) +
  39865. k * (-0.000343531996510555 * k + 0.24165260232407);
  39866. data[offset++] = clamp0to255(r);
  39867. data[offset++] = clamp0to255(g);
  39868. data[offset++] = clamp0to255(b);
  39869. }
  39870. return data;
  39871. },
  39872. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  39873. var Y, Cb, Cr;
  39874. for (var i = 0, length = data.length; i < length; i += 4) {
  39875. Y = data[i];
  39876. Cb = data[i + 1];
  39877. Cr = data[i + 2];
  39878. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  39879. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  39880. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  39881. // K in data[i + 3] is unchanged
  39882. }
  39883. return data;
  39884. },
  39885. _convertCmykToRgb: function convertCmykToRgb(data) {
  39886. var c, m, y, k;
  39887. var offset = 0;
  39888. var min = -255 * 255 * 255;
  39889. var scale = 1 / 255 / 255;
  39890. for (var i = 0, length = data.length; i < length; i += 4) {
  39891. c = data[i];
  39892. m = data[i + 1];
  39893. y = data[i + 2];
  39894. k = data[i + 3];
  39895. var r =
  39896. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  39897. 18.82290502165302 * y + 212.25662451639585 * k -
  39898. 72734.4411664936) +
  39899. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  39900. 17.873870861415444 * k - 1401.7366389350734) +
  39901. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  39902. 4465.541406466231) -
  39903. k * (21.86122147463605 * k + 48317.86113160301);
  39904. var g =
  39905. c * (8.841041422036149 * c + 60.118027045597366 * m +
  39906. 6.871425592049007 * y + 31.159100130055922 * k -
  39907. 20220.756542821975) +
  39908. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  39909. 131.35250912493976 * k - 48691.05921601825) +
  39910. y * (4.444339102852739 * y + 9.8632861493405 * k -
  39911. 6341.191035517494) -
  39912. k * (20.737325471181034 * k + 47890.15695978492);
  39913. var b =
  39914. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  39915. 30.89978309703729 * y - 0.23883238689178934 * k -
  39916. 3616.812083916688) +
  39917. m * (10.49593273432072 * m + 63.02378494754052 * y +
  39918. 50.606957656360734 * k - 28620.90484698408) +
  39919. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  39920. 49363.43385999684) -
  39921. k * (22.33816807309886 * k + 45932.16563550634);
  39922. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  39923. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  39924. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  39925. }
  39926. return data;
  39927. },
  39928. getData: function getData(width, height, forceRGBoutput) {
  39929. if (this.numComponents > 4) {
  39930. throw 'Unsupported color mode';
  39931. }
  39932. // type of data: Uint8Array(width * height * numComponents)
  39933. var data = this._getLinearizedBlockData(width, height);
  39934. if (this.numComponents === 3) {
  39935. return this._convertYccToRgb(data);
  39936. } else if (this.numComponents === 4) {
  39937. if (this._isColorConversionNeeded()) {
  39938. if (forceRGBoutput) {
  39939. return this._convertYcckToRgb(data);
  39940. } else {
  39941. return this._convertYcckToCmyk(data);
  39942. }
  39943. } else if (forceRGBoutput) {
  39944. return this._convertCmykToRgb(data);
  39945. }
  39946. }
  39947. return data;
  39948. }
  39949. };
  39950. return constructor;
  39951. })();
  39952. var JpxImage = (function JpxImageClosure() {
  39953. // Table E.1
  39954. var SubbandsGainLog2 = {
  39955. 'LL': 0,
  39956. 'LH': 1,
  39957. 'HL': 1,
  39958. 'HH': 2
  39959. };
  39960. function JpxImage() {
  39961. this.failOnCorruptedImage = false;
  39962. }
  39963. JpxImage.prototype = {
  39964. parse: function JpxImage_parse(data) {
  39965. var head = readUint16(data, 0);
  39966. // No box header, immediate start of codestream (SOC)
  39967. if (head === 0xFF4F) {
  39968. this.parseCodestream(data, 0, data.length);
  39969. return;
  39970. }
  39971. var position = 0, length = data.length;
  39972. while (position < length) {
  39973. var headerSize = 8;
  39974. var lbox = readUint32(data, position);
  39975. var tbox = readUint32(data, position + 4);
  39976. position += headerSize;
  39977. if (lbox === 1) {
  39978. // XLBox: read UInt64 according to spec.
  39979. // JavaScript's int precision of 53 bit should be sufficient here.
  39980. lbox = readUint32(data, position) * 4294967296 +
  39981. readUint32(data, position + 4);
  39982. position += 8;
  39983. headerSize += 8;
  39984. }
  39985. if (lbox === 0) {
  39986. lbox = length - position + headerSize;
  39987. }
  39988. if (lbox < headerSize) {
  39989. throw new Error('JPX Error: Invalid box field size');
  39990. }
  39991. var dataLength = lbox - headerSize;
  39992. var jumpDataLength = true;
  39993. switch (tbox) {
  39994. case 0x6A703268: // 'jp2h'
  39995. jumpDataLength = false; // parsing child boxes
  39996. break;
  39997. case 0x636F6C72: // 'colr'
  39998. // Colorspaces are not used, the CS from the PDF is used.
  39999. var method = data[position];
  40000. var precedence = data[position + 1];
  40001. var approximation = data[position + 2];
  40002. if (method === 1) {
  40003. // enumerated colorspace
  40004. var colorspace = readUint32(data, position + 3);
  40005. switch (colorspace) {
  40006. case 16: // this indicates a sRGB colorspace
  40007. case 17: // this indicates a grayscale colorspace
  40008. case 18: // this indicates a YUV colorspace
  40009. break;
  40010. default:
  40011. warn('Unknown colorspace ' + colorspace);
  40012. break;
  40013. }
  40014. } else if (method === 2) {
  40015. info('ICC profile not supported');
  40016. }
  40017. break;
  40018. case 0x6A703263: // 'jp2c'
  40019. this.parseCodestream(data, position, position + dataLength);
  40020. break;
  40021. case 0x6A502020: // 'jP\024\024'
  40022. if (0x0d0a870a !== readUint32(data, position)) {
  40023. warn('Invalid JP2 signature');
  40024. }
  40025. break;
  40026. // The following header types are valid but currently not used:
  40027. case 0x6A501A1A: // 'jP\032\032'
  40028. case 0x66747970: // 'ftyp'
  40029. case 0x72726571: // 'rreq'
  40030. case 0x72657320: // 'res '
  40031. case 0x69686472: // 'ihdr'
  40032. break;
  40033. default:
  40034. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  40035. (tbox >> 16) & 0xFF,
  40036. (tbox >> 8) & 0xFF,
  40037. tbox & 0xFF);
  40038. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  40039. break;
  40040. }
  40041. if (jumpDataLength) {
  40042. position += dataLength;
  40043. }
  40044. }
  40045. },
  40046. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  40047. var newByte = stream.getByte();
  40048. while (newByte >= 0) {
  40049. var oldByte = newByte;
  40050. newByte = stream.getByte();
  40051. var code = (oldByte << 8) | newByte;
  40052. // Image and tile size (SIZ)
  40053. if (code === 0xFF51) {
  40054. stream.skip(4);
  40055. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  40056. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  40057. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  40058. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  40059. stream.skip(16);
  40060. var Csiz = stream.getUint16(); // Byte 36
  40061. this.width = Xsiz - XOsiz;
  40062. this.height = Ysiz - YOsiz;
  40063. this.componentsCount = Csiz;
  40064. // Results are always returned as Uint8Arrays
  40065. this.bitsPerComponent = 8;
  40066. return;
  40067. }
  40068. }
  40069. throw new Error('JPX Error: No size marker found in JPX stream');
  40070. },
  40071. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  40072. var context = {};
  40073. try {
  40074. var doNotRecover = false;
  40075. var position = start;
  40076. while (position + 1 < end) {
  40077. var code = readUint16(data, position);
  40078. position += 2;
  40079. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  40080. switch (code) {
  40081. case 0xFF4F: // Start of codestream (SOC)
  40082. context.mainHeader = true;
  40083. break;
  40084. case 0xFFD9: // End of codestream (EOC)
  40085. break;
  40086. case 0xFF51: // Image and tile size (SIZ)
  40087. length = readUint16(data, position);
  40088. var siz = {};
  40089. siz.Xsiz = readUint32(data, position + 4);
  40090. siz.Ysiz = readUint32(data, position + 8);
  40091. siz.XOsiz = readUint32(data, position + 12);
  40092. siz.YOsiz = readUint32(data, position + 16);
  40093. siz.XTsiz = readUint32(data, position + 20);
  40094. siz.YTsiz = readUint32(data, position + 24);
  40095. siz.XTOsiz = readUint32(data, position + 28);
  40096. siz.YTOsiz = readUint32(data, position + 32);
  40097. var componentsCount = readUint16(data, position + 36);
  40098. siz.Csiz = componentsCount;
  40099. var components = [];
  40100. j = position + 38;
  40101. for (var i = 0; i < componentsCount; i++) {
  40102. var component = {
  40103. precision: (data[j] & 0x7F) + 1,
  40104. isSigned: !!(data[j] & 0x80),
  40105. XRsiz: data[j + 1],
  40106. YRsiz: data[j + 1]
  40107. };
  40108. calculateComponentDimensions(component, siz);
  40109. components.push(component);
  40110. }
  40111. context.SIZ = siz;
  40112. context.components = components;
  40113. calculateTileGrids(context, components);
  40114. context.QCC = [];
  40115. context.COC = [];
  40116. break;
  40117. case 0xFF5C: // Quantization default (QCD)
  40118. length = readUint16(data, position);
  40119. var qcd = {};
  40120. j = position + 2;
  40121. sqcd = data[j++];
  40122. switch (sqcd & 0x1F) {
  40123. case 0:
  40124. spqcdSize = 8;
  40125. scalarExpounded = true;
  40126. break;
  40127. case 1:
  40128. spqcdSize = 16;
  40129. scalarExpounded = false;
  40130. break;
  40131. case 2:
  40132. spqcdSize = 16;
  40133. scalarExpounded = true;
  40134. break;
  40135. default:
  40136. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  40137. }
  40138. qcd.noQuantization = (spqcdSize === 8);
  40139. qcd.scalarExpounded = scalarExpounded;
  40140. qcd.guardBits = sqcd >> 5;
  40141. spqcds = [];
  40142. while (j < length + position) {
  40143. var spqcd = {};
  40144. if (spqcdSize === 8) {
  40145. spqcd.epsilon = data[j++] >> 3;
  40146. spqcd.mu = 0;
  40147. } else {
  40148. spqcd.epsilon = data[j] >> 3;
  40149. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  40150. j += 2;
  40151. }
  40152. spqcds.push(spqcd);
  40153. }
  40154. qcd.SPqcds = spqcds;
  40155. if (context.mainHeader) {
  40156. context.QCD = qcd;
  40157. } else {
  40158. context.currentTile.QCD = qcd;
  40159. context.currentTile.QCC = [];
  40160. }
  40161. break;
  40162. case 0xFF5D: // Quantization component (QCC)
  40163. length = readUint16(data, position);
  40164. var qcc = {};
  40165. j = position + 2;
  40166. var cqcc;
  40167. if (context.SIZ.Csiz < 257) {
  40168. cqcc = data[j++];
  40169. } else {
  40170. cqcc = readUint16(data, j);
  40171. j += 2;
  40172. }
  40173. sqcd = data[j++];
  40174. switch (sqcd & 0x1F) {
  40175. case 0:
  40176. spqcdSize = 8;
  40177. scalarExpounded = true;
  40178. break;
  40179. case 1:
  40180. spqcdSize = 16;
  40181. scalarExpounded = false;
  40182. break;
  40183. case 2:
  40184. spqcdSize = 16;
  40185. scalarExpounded = true;
  40186. break;
  40187. default:
  40188. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  40189. }
  40190. qcc.noQuantization = (spqcdSize === 8);
  40191. qcc.scalarExpounded = scalarExpounded;
  40192. qcc.guardBits = sqcd >> 5;
  40193. spqcds = [];
  40194. while (j < (length + position)) {
  40195. spqcd = {};
  40196. if (spqcdSize === 8) {
  40197. spqcd.epsilon = data[j++] >> 3;
  40198. spqcd.mu = 0;
  40199. } else {
  40200. spqcd.epsilon = data[j] >> 3;
  40201. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  40202. j += 2;
  40203. }
  40204. spqcds.push(spqcd);
  40205. }
  40206. qcc.SPqcds = spqcds;
  40207. if (context.mainHeader) {
  40208. context.QCC[cqcc] = qcc;
  40209. } else {
  40210. context.currentTile.QCC[cqcc] = qcc;
  40211. }
  40212. break;
  40213. case 0xFF52: // Coding style default (COD)
  40214. length = readUint16(data, position);
  40215. var cod = {};
  40216. j = position + 2;
  40217. var scod = data[j++];
  40218. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  40219. cod.sopMarkerUsed = !!(scod & 2);
  40220. cod.ephMarkerUsed = !!(scod & 4);
  40221. cod.progressionOrder = data[j++];
  40222. cod.layersCount = readUint16(data, j);
  40223. j += 2;
  40224. cod.multipleComponentTransform = data[j++];
  40225. cod.decompositionLevelsCount = data[j++];
  40226. cod.xcb = (data[j++] & 0xF) + 2;
  40227. cod.ycb = (data[j++] & 0xF) + 2;
  40228. var blockStyle = data[j++];
  40229. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  40230. cod.resetContextProbabilities = !!(blockStyle & 2);
  40231. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  40232. cod.verticalyStripe = !!(blockStyle & 8);
  40233. cod.predictableTermination = !!(blockStyle & 16);
  40234. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  40235. cod.reversibleTransformation = data[j++];
  40236. if (cod.entropyCoderWithCustomPrecincts) {
  40237. var precinctsSizes = [];
  40238. while (j < length + position) {
  40239. var precinctsSize = data[j++];
  40240. precinctsSizes.push({
  40241. PPx: precinctsSize & 0xF,
  40242. PPy: precinctsSize >> 4
  40243. });
  40244. }
  40245. cod.precinctsSizes = precinctsSizes;
  40246. }
  40247. var unsupported = [];
  40248. if (cod.selectiveArithmeticCodingBypass) {
  40249. unsupported.push('selectiveArithmeticCodingBypass');
  40250. }
  40251. if (cod.resetContextProbabilities) {
  40252. unsupported.push('resetContextProbabilities');
  40253. }
  40254. if (cod.terminationOnEachCodingPass) {
  40255. unsupported.push('terminationOnEachCodingPass');
  40256. }
  40257. if (cod.verticalyStripe) {
  40258. unsupported.push('verticalyStripe');
  40259. }
  40260. if (cod.predictableTermination) {
  40261. unsupported.push('predictableTermination');
  40262. }
  40263. if (unsupported.length > 0) {
  40264. doNotRecover = true;
  40265. throw new Error('JPX Error: Unsupported COD options (' +
  40266. unsupported.join(', ') + ')');
  40267. }
  40268. if (context.mainHeader) {
  40269. context.COD = cod;
  40270. } else {
  40271. context.currentTile.COD = cod;
  40272. context.currentTile.COC = [];
  40273. }
  40274. break;
  40275. case 0xFF90: // Start of tile-part (SOT)
  40276. length = readUint16(data, position);
  40277. tile = {};
  40278. tile.index = readUint16(data, position + 2);
  40279. tile.length = readUint32(data, position + 4);
  40280. tile.dataEnd = tile.length + position - 2;
  40281. tile.partIndex = data[position + 8];
  40282. tile.partsCount = data[position + 9];
  40283. context.mainHeader = false;
  40284. if (tile.partIndex === 0) {
  40285. // reset component specific settings
  40286. tile.COD = context.COD;
  40287. tile.COC = context.COC.slice(0); // clone of the global COC
  40288. tile.QCD = context.QCD;
  40289. tile.QCC = context.QCC.slice(0); // clone of the global COC
  40290. }
  40291. context.currentTile = tile;
  40292. break;
  40293. case 0xFF93: // Start of data (SOD)
  40294. tile = context.currentTile;
  40295. if (tile.partIndex === 0) {
  40296. initializeTile(context, tile.index);
  40297. buildPackets(context);
  40298. }
  40299. // moving to the end of the data
  40300. length = tile.dataEnd - position;
  40301. parseTilePackets(context, data, position, length);
  40302. break;
  40303. case 0xFF55: // Tile-part lengths, main header (TLM)
  40304. case 0xFF57: // Packet length, main header (PLM)
  40305. case 0xFF58: // Packet length, tile-part header (PLT)
  40306. case 0xFF64: // Comment (COM)
  40307. length = readUint16(data, position);
  40308. // skipping content
  40309. break;
  40310. case 0xFF53: // Coding style component (COC)
  40311. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  40312. 'not implemented');
  40313. default:
  40314. throw new Error('JPX Error: Unknown codestream code: ' +
  40315. code.toString(16));
  40316. }
  40317. position += length;
  40318. }
  40319. } catch (e) {
  40320. if (doNotRecover || this.failOnCorruptedImage) {
  40321. throw e;
  40322. } else {
  40323. warn('Trying to recover from ' + e.message);
  40324. }
  40325. }
  40326. this.tiles = transformComponents(context);
  40327. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  40328. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  40329. this.componentsCount = context.SIZ.Csiz;
  40330. }
  40331. };
  40332. function calculateComponentDimensions(component, siz) {
  40333. // Section B.2 Component mapping
  40334. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  40335. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  40336. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  40337. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  40338. component.width = component.x1 - component.x0;
  40339. component.height = component.y1 - component.y0;
  40340. }
  40341. function calculateTileGrids(context, components) {
  40342. var siz = context.SIZ;
  40343. // Section B.3 Division into tile and tile-components
  40344. var tile, tiles = [];
  40345. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  40346. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  40347. for (var q = 0; q < numYtiles; q++) {
  40348. for (var p = 0; p < numXtiles; p++) {
  40349. tile = {};
  40350. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  40351. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  40352. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  40353. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  40354. tile.width = tile.tx1 - tile.tx0;
  40355. tile.height = tile.ty1 - tile.ty0;
  40356. tile.components = [];
  40357. tiles.push(tile);
  40358. }
  40359. }
  40360. context.tiles = tiles;
  40361. var componentsCount = siz.Csiz;
  40362. for (var i = 0, ii = componentsCount; i < ii; i++) {
  40363. var component = components[i];
  40364. for (var j = 0, jj = tiles.length; j < jj; j++) {
  40365. var tileComponent = {};
  40366. tile = tiles[j];
  40367. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  40368. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  40369. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  40370. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  40371. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  40372. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  40373. tile.components[i] = tileComponent;
  40374. }
  40375. }
  40376. }
  40377. function getBlocksDimensions(context, component, r) {
  40378. var codOrCoc = component.codingStyleParameters;
  40379. var result = {};
  40380. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  40381. result.PPx = 15;
  40382. result.PPy = 15;
  40383. } else {
  40384. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  40385. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  40386. }
  40387. // calculate codeblock size as described in section B.7
  40388. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  40389. Math.min(codOrCoc.xcb, result.PPx));
  40390. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  40391. Math.min(codOrCoc.ycb, result.PPy));
  40392. return result;
  40393. }
  40394. function buildPrecincts(context, resolution, dimensions) {
  40395. // Section B.6 Division resolution to precincts
  40396. var precinctWidth = 1 << dimensions.PPx;
  40397. var precinctHeight = 1 << dimensions.PPy;
  40398. // Jasper introduces codeblock groups for mapping each subband codeblocks
  40399. // to precincts. Precinct partition divides a resolution according to width
  40400. // and height parameters. The subband that belongs to the resolution level
  40401. // has a different size than the level, unless it is the zero resolution.
  40402. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  40403. // The precinct partitioning for a particular subband is derived from a
  40404. // partitioning of its parent LL band (i.e., the LL band at the next higher
  40405. // resolution level)... The LL band associated with each resolution level is
  40406. // divided into precincts... Each of the resulting precinct regions is then
  40407. // mapped into its child subbands (if any) at the next lower resolution
  40408. // level. This is accomplished by using the coordinate transformation
  40409. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  40410. // coordinates of a point in the LL band and child subband, respectively.
  40411. var isZeroRes = resolution.resLevel === 0;
  40412. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  40413. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  40414. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  40415. Math.ceil(resolution.trx1 / precinctWidth) -
  40416. Math.floor(resolution.trx0 / precinctWidth) : 0);
  40417. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  40418. Math.ceil(resolution.try1 / precinctHeight) -
  40419. Math.floor(resolution.try0 / precinctHeight) : 0);
  40420. var numprecincts = numprecinctswide * numprecinctshigh;
  40421. resolution.precinctParameters = {
  40422. precinctWidth: precinctWidth,
  40423. precinctHeight: precinctHeight,
  40424. numprecinctswide: numprecinctswide,
  40425. numprecinctshigh: numprecinctshigh,
  40426. numprecincts: numprecincts,
  40427. precinctWidthInSubband: precinctWidthInSubband,
  40428. precinctHeightInSubband: precinctHeightInSubband
  40429. };
  40430. }
  40431. function buildCodeblocks(context, subband, dimensions) {
  40432. // Section B.7 Division sub-band into code-blocks
  40433. var xcb_ = dimensions.xcb_;
  40434. var ycb_ = dimensions.ycb_;
  40435. var codeblockWidth = 1 << xcb_;
  40436. var codeblockHeight = 1 << ycb_;
  40437. var cbx0 = subband.tbx0 >> xcb_;
  40438. var cby0 = subband.tby0 >> ycb_;
  40439. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  40440. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  40441. var precinctParameters = subband.resolution.precinctParameters;
  40442. var codeblocks = [];
  40443. var precincts = [];
  40444. var i, j, codeblock, precinctNumber;
  40445. for (j = cby0; j < cby1; j++) {
  40446. for (i = cbx0; i < cbx1; i++) {
  40447. codeblock = {
  40448. cbx: i,
  40449. cby: j,
  40450. tbx0: codeblockWidth * i,
  40451. tby0: codeblockHeight * j,
  40452. tbx1: codeblockWidth * (i + 1),
  40453. tby1: codeblockHeight * (j + 1)
  40454. };
  40455. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  40456. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  40457. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  40458. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  40459. // Calculate precinct number for this codeblock, codeblock position
  40460. // should be relative to its subband, use actual dimension and position
  40461. // See comment about codeblock group width and height
  40462. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  40463. precinctParameters.precinctWidthInSubband);
  40464. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  40465. precinctParameters.precinctHeightInSubband);
  40466. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  40467. codeblock.precinctNumber = precinctNumber;
  40468. codeblock.subbandType = subband.type;
  40469. codeblock.Lblock = 3;
  40470. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  40471. codeblock.tby1_ <= codeblock.tby0_) {
  40472. continue;
  40473. }
  40474. codeblocks.push(codeblock);
  40475. // building precinct for the sub-band
  40476. var precinct = precincts[precinctNumber];
  40477. if (precinct !== undefined) {
  40478. if (i < precinct.cbxMin) {
  40479. precinct.cbxMin = i;
  40480. } else if (i > precinct.cbxMax) {
  40481. precinct.cbxMax = i;
  40482. }
  40483. if (j < precinct.cbyMin) {
  40484. precinct.cbxMin = j;
  40485. } else if (j > precinct.cbyMax) {
  40486. precinct.cbyMax = j;
  40487. }
  40488. } else {
  40489. precincts[precinctNumber] = precinct = {
  40490. cbxMin: i,
  40491. cbyMin: j,
  40492. cbxMax: i,
  40493. cbyMax: j
  40494. };
  40495. }
  40496. codeblock.precinct = precinct;
  40497. }
  40498. }
  40499. subband.codeblockParameters = {
  40500. codeblockWidth: xcb_,
  40501. codeblockHeight: ycb_,
  40502. numcodeblockwide: cbx1 - cbx0 + 1,
  40503. numcodeblockhigh: cby1 - cby0 + 1
  40504. };
  40505. subband.codeblocks = codeblocks;
  40506. subband.precincts = precincts;
  40507. }
  40508. function createPacket(resolution, precinctNumber, layerNumber) {
  40509. var precinctCodeblocks = [];
  40510. // Section B.10.8 Order of info in packet
  40511. var subbands = resolution.subbands;
  40512. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  40513. for (var i = 0, ii = subbands.length; i < ii; i++) {
  40514. var subband = subbands[i];
  40515. var codeblocks = subband.codeblocks;
  40516. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  40517. var codeblock = codeblocks[j];
  40518. if (codeblock.precinctNumber !== precinctNumber) {
  40519. continue;
  40520. }
  40521. precinctCodeblocks.push(codeblock);
  40522. }
  40523. }
  40524. return {
  40525. layerNumber: layerNumber,
  40526. codeblocks: precinctCodeblocks
  40527. };
  40528. }
  40529. function LayerResolutionComponentPositionIterator(context) {
  40530. var siz = context.SIZ;
  40531. var tileIndex = context.currentTile.index;
  40532. var tile = context.tiles[tileIndex];
  40533. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  40534. var componentsCount = siz.Csiz;
  40535. var maxDecompositionLevelsCount = 0;
  40536. for (var q = 0; q < componentsCount; q++) {
  40537. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  40538. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  40539. }
  40540. var l = 0, r = 0, i = 0, k = 0;
  40541. this.nextPacket = function JpxImage_nextPacket() {
  40542. // Section B.12.1.1 Layer-resolution-component-position
  40543. for (; l < layersCount; l++) {
  40544. for (; r <= maxDecompositionLevelsCount; r++) {
  40545. for (; i < componentsCount; i++) {
  40546. var component = tile.components[i];
  40547. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  40548. continue;
  40549. }
  40550. var resolution = component.resolutions[r];
  40551. var numprecincts = resolution.precinctParameters.numprecincts;
  40552. for (; k < numprecincts;) {
  40553. var packet = createPacket(resolution, k, l);
  40554. k++;
  40555. return packet;
  40556. }
  40557. k = 0;
  40558. }
  40559. i = 0;
  40560. }
  40561. r = 0;
  40562. }
  40563. throw new Error('JPX Error: Out of packets');
  40564. };
  40565. }
  40566. function ResolutionLayerComponentPositionIterator(context) {
  40567. var siz = context.SIZ;
  40568. var tileIndex = context.currentTile.index;
  40569. var tile = context.tiles[tileIndex];
  40570. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  40571. var componentsCount = siz.Csiz;
  40572. var maxDecompositionLevelsCount = 0;
  40573. for (var q = 0; q < componentsCount; q++) {
  40574. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  40575. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  40576. }
  40577. var r = 0, l = 0, i = 0, k = 0;
  40578. this.nextPacket = function JpxImage_nextPacket() {
  40579. // Section B.12.1.2 Resolution-layer-component-position
  40580. for (; r <= maxDecompositionLevelsCount; r++) {
  40581. for (; l < layersCount; l++) {
  40582. for (; i < componentsCount; i++) {
  40583. var component = tile.components[i];
  40584. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  40585. continue;
  40586. }
  40587. var resolution = component.resolutions[r];
  40588. var numprecincts = resolution.precinctParameters.numprecincts;
  40589. for (; k < numprecincts;) {
  40590. var packet = createPacket(resolution, k, l);
  40591. k++;
  40592. return packet;
  40593. }
  40594. k = 0;
  40595. }
  40596. i = 0;
  40597. }
  40598. l = 0;
  40599. }
  40600. throw new Error('JPX Error: Out of packets');
  40601. };
  40602. }
  40603. function ResolutionPositionComponentLayerIterator(context) {
  40604. var siz = context.SIZ;
  40605. var tileIndex = context.currentTile.index;
  40606. var tile = context.tiles[tileIndex];
  40607. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  40608. var componentsCount = siz.Csiz;
  40609. var l, r, c, p;
  40610. var maxDecompositionLevelsCount = 0;
  40611. for (c = 0; c < componentsCount; c++) {
  40612. var component = tile.components[c];
  40613. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  40614. component.codingStyleParameters.decompositionLevelsCount);
  40615. }
  40616. var maxNumPrecinctsInLevel = new Int32Array(
  40617. maxDecompositionLevelsCount + 1);
  40618. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  40619. var maxNumPrecincts = 0;
  40620. for (c = 0; c < componentsCount; ++c) {
  40621. var resolutions = tile.components[c].resolutions;
  40622. if (r < resolutions.length) {
  40623. maxNumPrecincts = Math.max(maxNumPrecincts,
  40624. resolutions[r].precinctParameters.numprecincts);
  40625. }
  40626. }
  40627. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  40628. }
  40629. l = 0;
  40630. r = 0;
  40631. c = 0;
  40632. p = 0;
  40633. this.nextPacket = function JpxImage_nextPacket() {
  40634. // Section B.12.1.3 Resolution-position-component-layer
  40635. for (; r <= maxDecompositionLevelsCount; r++) {
  40636. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  40637. for (; c < componentsCount; c++) {
  40638. var component = tile.components[c];
  40639. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  40640. continue;
  40641. }
  40642. var resolution = component.resolutions[r];
  40643. var numprecincts = resolution.precinctParameters.numprecincts;
  40644. if (p >= numprecincts) {
  40645. continue;
  40646. }
  40647. for (; l < layersCount;) {
  40648. var packet = createPacket(resolution, p, l);
  40649. l++;
  40650. return packet;
  40651. }
  40652. l = 0;
  40653. }
  40654. c = 0;
  40655. }
  40656. p = 0;
  40657. }
  40658. throw new Error('JPX Error: Out of packets');
  40659. };
  40660. }
  40661. function PositionComponentResolutionLayerIterator(context) {
  40662. var siz = context.SIZ;
  40663. var tileIndex = context.currentTile.index;
  40664. var tile = context.tiles[tileIndex];
  40665. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  40666. var componentsCount = siz.Csiz;
  40667. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  40668. var precinctsIterationSizes = precinctsSizes;
  40669. var l = 0, r = 0, c = 0, px = 0, py = 0;
  40670. this.nextPacket = function JpxImage_nextPacket() {
  40671. // Section B.12.1.4 Position-component-resolution-layer
  40672. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  40673. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  40674. for (; c < componentsCount; c++) {
  40675. var component = tile.components[c];
  40676. var decompositionLevelsCount =
  40677. component.codingStyleParameters.decompositionLevelsCount;
  40678. for (; r <= decompositionLevelsCount; r++) {
  40679. var resolution = component.resolutions[r];
  40680. var sizeInImageScale =
  40681. precinctsSizes.components[c].resolutions[r];
  40682. var k = getPrecinctIndexIfExist(
  40683. px,
  40684. py,
  40685. sizeInImageScale,
  40686. precinctsIterationSizes,
  40687. resolution);
  40688. if (k === null) {
  40689. continue;
  40690. }
  40691. for (; l < layersCount;) {
  40692. var packet = createPacket(resolution, k, l);
  40693. l++;
  40694. return packet;
  40695. }
  40696. l = 0;
  40697. }
  40698. r = 0;
  40699. }
  40700. c = 0;
  40701. }
  40702. px = 0;
  40703. }
  40704. throw new Error('JPX Error: Out of packets');
  40705. };
  40706. }
  40707. function ComponentPositionResolutionLayerIterator(context) {
  40708. var siz = context.SIZ;
  40709. var tileIndex = context.currentTile.index;
  40710. var tile = context.tiles[tileIndex];
  40711. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  40712. var componentsCount = siz.Csiz;
  40713. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  40714. var l = 0, r = 0, c = 0, px = 0, py = 0;
  40715. this.nextPacket = function JpxImage_nextPacket() {
  40716. // Section B.12.1.5 Component-position-resolution-layer
  40717. for (; c < componentsCount; ++c) {
  40718. var component = tile.components[c];
  40719. var precinctsIterationSizes = precinctsSizes.components[c];
  40720. var decompositionLevelsCount =
  40721. component.codingStyleParameters.decompositionLevelsCount;
  40722. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  40723. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  40724. for (; r <= decompositionLevelsCount; r++) {
  40725. var resolution = component.resolutions[r];
  40726. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  40727. var k = getPrecinctIndexIfExist(
  40728. px,
  40729. py,
  40730. sizeInImageScale,
  40731. precinctsIterationSizes,
  40732. resolution);
  40733. if (k === null) {
  40734. continue;
  40735. }
  40736. for (; l < layersCount;) {
  40737. var packet = createPacket(resolution, k, l);
  40738. l++;
  40739. return packet;
  40740. }
  40741. l = 0;
  40742. }
  40743. r = 0;
  40744. }
  40745. px = 0;
  40746. }
  40747. py = 0;
  40748. }
  40749. throw new Error('JPX Error: Out of packets');
  40750. };
  40751. }
  40752. function getPrecinctIndexIfExist(
  40753. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  40754. var posX = pxIndex * precinctIterationSizes.minWidth;
  40755. var posY = pyIndex * precinctIterationSizes.minHeight;
  40756. if (posX % sizeInImageScale.width !== 0 ||
  40757. posY % sizeInImageScale.height !== 0) {
  40758. return null;
  40759. }
  40760. var startPrecinctRowIndex =
  40761. (posY / sizeInImageScale.width) *
  40762. resolution.precinctParameters.numprecinctswide;
  40763. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  40764. }
  40765. function getPrecinctSizesInImageScale(tile) {
  40766. var componentsCount = tile.components.length;
  40767. var minWidth = Number.MAX_VALUE;
  40768. var minHeight = Number.MAX_VALUE;
  40769. var maxNumWide = 0;
  40770. var maxNumHigh = 0;
  40771. var sizePerComponent = new Array(componentsCount);
  40772. for (var c = 0; c < componentsCount; c++) {
  40773. var component = tile.components[c];
  40774. var decompositionLevelsCount =
  40775. component.codingStyleParameters.decompositionLevelsCount;
  40776. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  40777. var minWidthCurrentComponent = Number.MAX_VALUE;
  40778. var minHeightCurrentComponent = Number.MAX_VALUE;
  40779. var maxNumWideCurrentComponent = 0;
  40780. var maxNumHighCurrentComponent = 0;
  40781. var scale = 1;
  40782. for (var r = decompositionLevelsCount; r >= 0; --r) {
  40783. var resolution = component.resolutions[r];
  40784. var widthCurrentResolution =
  40785. scale * resolution.precinctParameters.precinctWidth;
  40786. var heightCurrentResolution =
  40787. scale * resolution.precinctParameters.precinctHeight;
  40788. minWidthCurrentComponent = Math.min(
  40789. minWidthCurrentComponent,
  40790. widthCurrentResolution);
  40791. minHeightCurrentComponent = Math.min(
  40792. minHeightCurrentComponent,
  40793. heightCurrentResolution);
  40794. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  40795. resolution.precinctParameters.numprecinctswide);
  40796. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  40797. resolution.precinctParameters.numprecinctshigh);
  40798. sizePerResolution[r] = {
  40799. width: widthCurrentResolution,
  40800. height: heightCurrentResolution
  40801. };
  40802. scale <<= 1;
  40803. }
  40804. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  40805. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  40806. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  40807. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  40808. sizePerComponent[c] = {
  40809. resolutions: sizePerResolution,
  40810. minWidth: minWidthCurrentComponent,
  40811. minHeight: minHeightCurrentComponent,
  40812. maxNumWide: maxNumWideCurrentComponent,
  40813. maxNumHigh: maxNumHighCurrentComponent
  40814. };
  40815. }
  40816. return {
  40817. components: sizePerComponent,
  40818. minWidth: minWidth,
  40819. minHeight: minHeight,
  40820. maxNumWide: maxNumWide,
  40821. maxNumHigh: maxNumHigh
  40822. };
  40823. }
  40824. function buildPackets(context) {
  40825. var siz = context.SIZ;
  40826. var tileIndex = context.currentTile.index;
  40827. var tile = context.tiles[tileIndex];
  40828. var componentsCount = siz.Csiz;
  40829. // Creating resolutions and sub-bands for each component
  40830. for (var c = 0; c < componentsCount; c++) {
  40831. var component = tile.components[c];
  40832. var decompositionLevelsCount =
  40833. component.codingStyleParameters.decompositionLevelsCount;
  40834. // Section B.5 Resolution levels and sub-bands
  40835. var resolutions = [];
  40836. var subbands = [];
  40837. for (var r = 0; r <= decompositionLevelsCount; r++) {
  40838. var blocksDimensions = getBlocksDimensions(context, component, r);
  40839. var resolution = {};
  40840. var scale = 1 << (decompositionLevelsCount - r);
  40841. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  40842. resolution.try0 = Math.ceil(component.tcy0 / scale);
  40843. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  40844. resolution.try1 = Math.ceil(component.tcy1 / scale);
  40845. resolution.resLevel = r;
  40846. buildPrecincts(context, resolution, blocksDimensions);
  40847. resolutions.push(resolution);
  40848. var subband;
  40849. if (r === 0) {
  40850. // one sub-band (LL) with last decomposition
  40851. subband = {};
  40852. subband.type = 'LL';
  40853. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  40854. subband.tby0 = Math.ceil(component.tcy0 / scale);
  40855. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  40856. subband.tby1 = Math.ceil(component.tcy1 / scale);
  40857. subband.resolution = resolution;
  40858. buildCodeblocks(context, subband, blocksDimensions);
  40859. subbands.push(subband);
  40860. resolution.subbands = [subband];
  40861. } else {
  40862. var bscale = 1 << (decompositionLevelsCount - r + 1);
  40863. var resolutionSubbands = [];
  40864. // three sub-bands (HL, LH and HH) with rest of decompositions
  40865. subband = {};
  40866. subband.type = 'HL';
  40867. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  40868. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  40869. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  40870. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  40871. subband.resolution = resolution;
  40872. buildCodeblocks(context, subband, blocksDimensions);
  40873. subbands.push(subband);
  40874. resolutionSubbands.push(subband);
  40875. subband = {};
  40876. subband.type = 'LH';
  40877. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  40878. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  40879. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  40880. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  40881. subband.resolution = resolution;
  40882. buildCodeblocks(context, subband, blocksDimensions);
  40883. subbands.push(subband);
  40884. resolutionSubbands.push(subband);
  40885. subband = {};
  40886. subband.type = 'HH';
  40887. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  40888. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  40889. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  40890. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  40891. subband.resolution = resolution;
  40892. buildCodeblocks(context, subband, blocksDimensions);
  40893. subbands.push(subband);
  40894. resolutionSubbands.push(subband);
  40895. resolution.subbands = resolutionSubbands;
  40896. }
  40897. }
  40898. component.resolutions = resolutions;
  40899. component.subbands = subbands;
  40900. }
  40901. // Generate the packets sequence
  40902. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  40903. switch (progressionOrder) {
  40904. case 0:
  40905. tile.packetsIterator =
  40906. new LayerResolutionComponentPositionIterator(context);
  40907. break;
  40908. case 1:
  40909. tile.packetsIterator =
  40910. new ResolutionLayerComponentPositionIterator(context);
  40911. break;
  40912. case 2:
  40913. tile.packetsIterator =
  40914. new ResolutionPositionComponentLayerIterator(context);
  40915. break;
  40916. case 3:
  40917. tile.packetsIterator =
  40918. new PositionComponentResolutionLayerIterator(context);
  40919. break;
  40920. case 4:
  40921. tile.packetsIterator =
  40922. new ComponentPositionResolutionLayerIterator(context);
  40923. break;
  40924. default:
  40925. throw new Error('JPX Error: Unsupported progression order ' +
  40926. progressionOrder);
  40927. }
  40928. }
  40929. function parseTilePackets(context, data, offset, dataLength) {
  40930. var position = 0;
  40931. var buffer, bufferSize = 0, skipNextBit = false;
  40932. function readBits(count) {
  40933. while (bufferSize < count) {
  40934. var b = data[offset + position];
  40935. position++;
  40936. if (skipNextBit) {
  40937. buffer = (buffer << 7) | b;
  40938. bufferSize += 7;
  40939. skipNextBit = false;
  40940. } else {
  40941. buffer = (buffer << 8) | b;
  40942. bufferSize += 8;
  40943. }
  40944. if (b === 0xFF) {
  40945. skipNextBit = true;
  40946. }
  40947. }
  40948. bufferSize -= count;
  40949. return (buffer >>> bufferSize) & ((1 << count) - 1);
  40950. }
  40951. function skipMarkerIfEqual(value) {
  40952. if (data[offset + position - 1] === 0xFF &&
  40953. data[offset + position] === value) {
  40954. skipBytes(1);
  40955. return true;
  40956. } else if (data[offset + position] === 0xFF &&
  40957. data[offset + position + 1] === value) {
  40958. skipBytes(2);
  40959. return true;
  40960. }
  40961. return false;
  40962. }
  40963. function skipBytes(count) {
  40964. position += count;
  40965. }
  40966. function alignToByte() {
  40967. bufferSize = 0;
  40968. if (skipNextBit) {
  40969. position++;
  40970. skipNextBit = false;
  40971. }
  40972. }
  40973. function readCodingpasses() {
  40974. if (readBits(1) === 0) {
  40975. return 1;
  40976. }
  40977. if (readBits(1) === 0) {
  40978. return 2;
  40979. }
  40980. var value = readBits(2);
  40981. if (value < 3) {
  40982. return value + 3;
  40983. }
  40984. value = readBits(5);
  40985. if (value < 31) {
  40986. return value + 6;
  40987. }
  40988. value = readBits(7);
  40989. return value + 37;
  40990. }
  40991. var tileIndex = context.currentTile.index;
  40992. var tile = context.tiles[tileIndex];
  40993. var sopMarkerUsed = context.COD.sopMarkerUsed;
  40994. var ephMarkerUsed = context.COD.ephMarkerUsed;
  40995. var packetsIterator = tile.packetsIterator;
  40996. while (position < dataLength) {
  40997. alignToByte();
  40998. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  40999. // Skip also marker segment length and packet sequence ID
  41000. skipBytes(4);
  41001. }
  41002. var packet = packetsIterator.nextPacket();
  41003. if (!readBits(1)) {
  41004. continue;
  41005. }
  41006. var layerNumber = packet.layerNumber;
  41007. var queue = [], codeblock;
  41008. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  41009. codeblock = packet.codeblocks[i];
  41010. var precinct = codeblock.precinct;
  41011. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  41012. var codeblockRow = codeblock.cby - precinct.cbyMin;
  41013. var codeblockIncluded = false;
  41014. var firstTimeInclusion = false;
  41015. var valueReady;
  41016. if (codeblock['included'] !== undefined) {
  41017. codeblockIncluded = !!readBits(1);
  41018. } else {
  41019. // reading inclusion tree
  41020. precinct = codeblock.precinct;
  41021. var inclusionTree, zeroBitPlanesTree;
  41022. if (precinct['inclusionTree'] !== undefined) {
  41023. inclusionTree = precinct.inclusionTree;
  41024. } else {
  41025. // building inclusion and zero bit-planes trees
  41026. var width = precinct.cbxMax - precinct.cbxMin + 1;
  41027. var height = precinct.cbyMax - precinct.cbyMin + 1;
  41028. inclusionTree = new InclusionTree(width, height, layerNumber);
  41029. zeroBitPlanesTree = new TagTree(width, height);
  41030. precinct.inclusionTree = inclusionTree;
  41031. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  41032. }
  41033. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  41034. while (true) {
  41035. if (readBits(1)) {
  41036. valueReady = !inclusionTree.nextLevel();
  41037. if (valueReady) {
  41038. codeblock.included = true;
  41039. codeblockIncluded = firstTimeInclusion = true;
  41040. break;
  41041. }
  41042. } else {
  41043. inclusionTree.incrementValue(layerNumber);
  41044. break;
  41045. }
  41046. }
  41047. }
  41048. }
  41049. if (!codeblockIncluded) {
  41050. continue;
  41051. }
  41052. if (firstTimeInclusion) {
  41053. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  41054. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  41055. while (true) {
  41056. if (readBits(1)) {
  41057. valueReady = !zeroBitPlanesTree.nextLevel();
  41058. if (valueReady) {
  41059. break;
  41060. }
  41061. } else {
  41062. zeroBitPlanesTree.incrementValue();
  41063. }
  41064. }
  41065. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  41066. }
  41067. var codingpasses = readCodingpasses();
  41068. while (readBits(1)) {
  41069. codeblock.Lblock++;
  41070. }
  41071. var codingpassesLog2 = log2(codingpasses);
  41072. // rounding down log2
  41073. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  41074. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  41075. var codedDataLength = readBits(bits);
  41076. queue.push({
  41077. codeblock: codeblock,
  41078. codingpasses: codingpasses,
  41079. dataLength: codedDataLength
  41080. });
  41081. }
  41082. alignToByte();
  41083. if (ephMarkerUsed) {
  41084. skipMarkerIfEqual(0x92);
  41085. }
  41086. while (queue.length > 0) {
  41087. var packetItem = queue.shift();
  41088. codeblock = packetItem.codeblock;
  41089. if (codeblock['data'] === undefined) {
  41090. codeblock.data = [];
  41091. }
  41092. codeblock.data.push({
  41093. data: data,
  41094. start: offset + position,
  41095. end: offset + position + packetItem.dataLength,
  41096. codingpasses: packetItem.codingpasses
  41097. });
  41098. position += packetItem.dataLength;
  41099. }
  41100. }
  41101. return position;
  41102. }
  41103. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  41104. delta, mb, reversible, segmentationSymbolUsed) {
  41105. var x0 = subband.tbx0;
  41106. var y0 = subband.tby0;
  41107. var width = subband.tbx1 - subband.tbx0;
  41108. var codeblocks = subband.codeblocks;
  41109. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  41110. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  41111. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  41112. var codeblock = codeblocks[i];
  41113. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  41114. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  41115. if (blockWidth === 0 || blockHeight === 0) {
  41116. continue;
  41117. }
  41118. if (codeblock['data'] === undefined) {
  41119. continue;
  41120. }
  41121. var bitModel, currentCodingpassType;
  41122. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  41123. codeblock.zeroBitPlanes, mb);
  41124. currentCodingpassType = 2; // first bit plane starts from cleanup
  41125. // collect data
  41126. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  41127. var j, jj, dataItem;
  41128. for (j = 0, jj = data.length; j < jj; j++) {
  41129. dataItem = data[j];
  41130. totalLength += dataItem.end - dataItem.start;
  41131. codingpasses += dataItem.codingpasses;
  41132. }
  41133. var encodedData = new Uint8Array(totalLength);
  41134. var position = 0;
  41135. for (j = 0, jj = data.length; j < jj; j++) {
  41136. dataItem = data[j];
  41137. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  41138. encodedData.set(chunk, position);
  41139. position += chunk.length;
  41140. }
  41141. // decoding the item
  41142. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  41143. bitModel.setDecoder(decoder);
  41144. for (j = 0; j < codingpasses; j++) {
  41145. switch (currentCodingpassType) {
  41146. case 0:
  41147. bitModel.runSignificancePropogationPass();
  41148. break;
  41149. case 1:
  41150. bitModel.runMagnitudeRefinementPass();
  41151. break;
  41152. case 2:
  41153. bitModel.runCleanupPass();
  41154. if (segmentationSymbolUsed) {
  41155. bitModel.checkSegmentationSymbol();
  41156. }
  41157. break;
  41158. }
  41159. currentCodingpassType = (currentCodingpassType + 1) % 3;
  41160. }
  41161. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  41162. var sign = bitModel.coefficentsSign;
  41163. var magnitude = bitModel.coefficentsMagnitude;
  41164. var bitsDecoded = bitModel.bitsDecoded;
  41165. var magnitudeCorrection = reversible ? 0 : 0.5;
  41166. var k, n, nb;
  41167. position = 0;
  41168. // Do the interleaving of Section F.3.3 here, so we do not need
  41169. // to copy later. LL level is not interleaved, just copied.
  41170. var interleave = (subband.type !== 'LL');
  41171. for (j = 0; j < blockHeight; j++) {
  41172. var row = (offset / width) | 0; // row in the non-interleaved subband
  41173. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  41174. for (k = 0; k < blockWidth; k++) {
  41175. n = magnitude[position];
  41176. if (n !== 0) {
  41177. n = (n + magnitudeCorrection) * delta;
  41178. if (sign[position] !== 0) {
  41179. n = -n;
  41180. }
  41181. nb = bitsDecoded[position];
  41182. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  41183. if (reversible && (nb >= mb)) {
  41184. coefficients[pos] = n;
  41185. } else {
  41186. coefficients[pos] = n * (1 << (mb - nb));
  41187. }
  41188. }
  41189. offset++;
  41190. position++;
  41191. }
  41192. offset += width - blockWidth;
  41193. }
  41194. }
  41195. }
  41196. function transformTile(context, tile, c) {
  41197. var component = tile.components[c];
  41198. var codingStyleParameters = component.codingStyleParameters;
  41199. var quantizationParameters = component.quantizationParameters;
  41200. var decompositionLevelsCount =
  41201. codingStyleParameters.decompositionLevelsCount;
  41202. var spqcds = quantizationParameters.SPqcds;
  41203. var scalarExpounded = quantizationParameters.scalarExpounded;
  41204. var guardBits = quantizationParameters.guardBits;
  41205. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  41206. var precision = context.components[c].precision;
  41207. var reversible = codingStyleParameters.reversibleTransformation;
  41208. var transform = (reversible ? new ReversibleTransform() :
  41209. new IrreversibleTransform());
  41210. var subbandCoefficients = [];
  41211. var b = 0;
  41212. for (var i = 0; i <= decompositionLevelsCount; i++) {
  41213. var resolution = component.resolutions[i];
  41214. var width = resolution.trx1 - resolution.trx0;
  41215. var height = resolution.try1 - resolution.try0;
  41216. // Allocate space for the whole sublevel.
  41217. var coefficients = new Float32Array(width * height);
  41218. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  41219. var mu, epsilon;
  41220. if (!scalarExpounded) {
  41221. // formula E-5
  41222. mu = spqcds[0].mu;
  41223. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  41224. } else {
  41225. mu = spqcds[b].mu;
  41226. epsilon = spqcds[b].epsilon;
  41227. b++;
  41228. }
  41229. var subband = resolution.subbands[j];
  41230. var gainLog2 = SubbandsGainLog2[subband.type];
  41231. // calulate quantization coefficient (Section E.1.1.1)
  41232. var delta = (reversible ? 1 :
  41233. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  41234. var mb = (guardBits + epsilon - 1);
  41235. // In the first resolution level, copyCoefficients will fill the
  41236. // whole array with coefficients. In the succeding passes,
  41237. // copyCoefficients will consecutively fill in the values that belong
  41238. // to the interleaved positions of the HL, LH, and HH coefficients.
  41239. // The LL coefficients will then be interleaved in Transform.iterate().
  41240. copyCoefficients(coefficients, width, height, subband, delta, mb,
  41241. reversible, segmentationSymbolUsed);
  41242. }
  41243. subbandCoefficients.push({
  41244. width: width,
  41245. height: height,
  41246. items: coefficients
  41247. });
  41248. }
  41249. var result = transform.calculate(subbandCoefficients,
  41250. component.tcx0, component.tcy0);
  41251. return {
  41252. left: component.tcx0,
  41253. top: component.tcy0,
  41254. width: result.width,
  41255. height: result.height,
  41256. items: result.items
  41257. };
  41258. }
  41259. function transformComponents(context) {
  41260. var siz = context.SIZ;
  41261. var components = context.components;
  41262. var componentsCount = siz.Csiz;
  41263. var resultImages = [];
  41264. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  41265. var tile = context.tiles[i];
  41266. var transformedTiles = [];
  41267. var c;
  41268. for (c = 0; c < componentsCount; c++) {
  41269. transformedTiles[c] = transformTile(context, tile, c);
  41270. }
  41271. var tile0 = transformedTiles[0];
  41272. var out = new Uint8Array(tile0.items.length * componentsCount);
  41273. var result = {
  41274. left: tile0.left,
  41275. top: tile0.top,
  41276. width: tile0.width,
  41277. height: tile0.height,
  41278. items: out
  41279. };
  41280. // Section G.2.2 Inverse multi component transform
  41281. var shift, offset, max, min, maxK;
  41282. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  41283. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  41284. var fourComponents = componentsCount === 4;
  41285. var y0items = transformedTiles[0].items;
  41286. var y1items = transformedTiles[1].items;
  41287. var y2items = transformedTiles[2].items;
  41288. var y3items = fourComponents ? transformedTiles[3].items : null;
  41289. // HACK: The multiple component transform formulas below assume that
  41290. // all components have the same precision. With this in mind, we
  41291. // compute shift and offset only once.
  41292. shift = components[0].precision - 8;
  41293. offset = (128 << shift) + 0.5;
  41294. max = 255 * (1 << shift);
  41295. maxK = max * 0.5;
  41296. min = -maxK;
  41297. var component0 = tile.components[0];
  41298. var alpha01 = componentsCount - 3;
  41299. jj = y0items.length;
  41300. if (!component0.codingStyleParameters.reversibleTransformation) {
  41301. // inverse irreversible multiple component transform
  41302. for (j = 0; j < jj; j++, pos += alpha01) {
  41303. y0 = y0items[j] + offset;
  41304. y1 = y1items[j];
  41305. y2 = y2items[j];
  41306. r = y0 + 1.402 * y2;
  41307. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  41308. b = y0 + 1.772 * y1;
  41309. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  41310. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  41311. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  41312. }
  41313. } else {
  41314. // inverse reversible multiple component transform
  41315. for (j = 0; j < jj; j++, pos += alpha01) {
  41316. y0 = y0items[j] + offset;
  41317. y1 = y1items[j];
  41318. y2 = y2items[j];
  41319. g = y0 - ((y2 + y1) >> 2);
  41320. r = g + y2;
  41321. b = g + y1;
  41322. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  41323. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  41324. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  41325. }
  41326. }
  41327. if (fourComponents) {
  41328. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  41329. k = y3items[j];
  41330. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  41331. }
  41332. }
  41333. } else { // no multi-component transform
  41334. for (c = 0; c < componentsCount; c++) {
  41335. var items = transformedTiles[c].items;
  41336. shift = components[c].precision - 8;
  41337. offset = (128 << shift) + 0.5;
  41338. max = (127.5 * (1 << shift));
  41339. min = -max;
  41340. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  41341. val = items[j];
  41342. out[pos] = val <= min ? 0 :
  41343. val >= max ? 255 : (val + offset) >> shift;
  41344. pos += componentsCount;
  41345. }
  41346. }
  41347. }
  41348. resultImages.push(result);
  41349. }
  41350. return resultImages;
  41351. }
  41352. function initializeTile(context, tileIndex) {
  41353. var siz = context.SIZ;
  41354. var componentsCount = siz.Csiz;
  41355. var tile = context.tiles[tileIndex];
  41356. for (var c = 0; c < componentsCount; c++) {
  41357. var component = tile.components[c];
  41358. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  41359. context.currentTile.QCC[c] : context.currentTile.QCD);
  41360. component.quantizationParameters = qcdOrQcc;
  41361. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  41362. context.currentTile.COC[c] : context.currentTile.COD);
  41363. component.codingStyleParameters = codOrCoc;
  41364. }
  41365. tile.codingStyleDefaultParameters = context.currentTile.COD;
  41366. }
  41367. // Section B.10.2 Tag trees
  41368. var TagTree = (function TagTreeClosure() {
  41369. function TagTree(width, height) {
  41370. var levelsLength = log2(Math.max(width, height)) + 1;
  41371. this.levels = [];
  41372. for (var i = 0; i < levelsLength; i++) {
  41373. var level = {
  41374. width: width,
  41375. height: height,
  41376. items: []
  41377. };
  41378. this.levels.push(level);
  41379. width = Math.ceil(width / 2);
  41380. height = Math.ceil(height / 2);
  41381. }
  41382. }
  41383. TagTree.prototype = {
  41384. reset: function TagTree_reset(i, j) {
  41385. var currentLevel = 0, value = 0, level;
  41386. while (currentLevel < this.levels.length) {
  41387. level = this.levels[currentLevel];
  41388. var index = i + j * level.width;
  41389. if (level.items[index] !== undefined) {
  41390. value = level.items[index];
  41391. break;
  41392. }
  41393. level.index = index;
  41394. i >>= 1;
  41395. j >>= 1;
  41396. currentLevel++;
  41397. }
  41398. currentLevel--;
  41399. level = this.levels[currentLevel];
  41400. level.items[level.index] = value;
  41401. this.currentLevel = currentLevel;
  41402. delete this.value;
  41403. },
  41404. incrementValue: function TagTree_incrementValue() {
  41405. var level = this.levels[this.currentLevel];
  41406. level.items[level.index]++;
  41407. },
  41408. nextLevel: function TagTree_nextLevel() {
  41409. var currentLevel = this.currentLevel;
  41410. var level = this.levels[currentLevel];
  41411. var value = level.items[level.index];
  41412. currentLevel--;
  41413. if (currentLevel < 0) {
  41414. this.value = value;
  41415. return false;
  41416. }
  41417. this.currentLevel = currentLevel;
  41418. level = this.levels[currentLevel];
  41419. level.items[level.index] = value;
  41420. return true;
  41421. }
  41422. };
  41423. return TagTree;
  41424. })();
  41425. var InclusionTree = (function InclusionTreeClosure() {
  41426. function InclusionTree(width, height, defaultValue) {
  41427. var levelsLength = log2(Math.max(width, height)) + 1;
  41428. this.levels = [];
  41429. for (var i = 0; i < levelsLength; i++) {
  41430. var items = new Uint8Array(width * height);
  41431. for (var j = 0, jj = items.length; j < jj; j++) {
  41432. items[j] = defaultValue;
  41433. }
  41434. var level = {
  41435. width: width,
  41436. height: height,
  41437. items: items
  41438. };
  41439. this.levels.push(level);
  41440. width = Math.ceil(width / 2);
  41441. height = Math.ceil(height / 2);
  41442. }
  41443. }
  41444. InclusionTree.prototype = {
  41445. reset: function InclusionTree_reset(i, j, stopValue) {
  41446. var currentLevel = 0;
  41447. while (currentLevel < this.levels.length) {
  41448. var level = this.levels[currentLevel];
  41449. var index = i + j * level.width;
  41450. level.index = index;
  41451. var value = level.items[index];
  41452. if (value === 0xFF) {
  41453. break;
  41454. }
  41455. if (value > stopValue) {
  41456. this.currentLevel = currentLevel;
  41457. // already know about this one, propagating the value to top levels
  41458. this.propagateValues();
  41459. return false;
  41460. }
  41461. i >>= 1;
  41462. j >>= 1;
  41463. currentLevel++;
  41464. }
  41465. this.currentLevel = currentLevel - 1;
  41466. return true;
  41467. },
  41468. incrementValue: function InclusionTree_incrementValue(stopValue) {
  41469. var level = this.levels[this.currentLevel];
  41470. level.items[level.index] = stopValue + 1;
  41471. this.propagateValues();
  41472. },
  41473. propagateValues: function InclusionTree_propagateValues() {
  41474. var levelIndex = this.currentLevel;
  41475. var level = this.levels[levelIndex];
  41476. var currentValue = level.items[level.index];
  41477. while (--levelIndex >= 0) {
  41478. level = this.levels[levelIndex];
  41479. level.items[level.index] = currentValue;
  41480. }
  41481. },
  41482. nextLevel: function InclusionTree_nextLevel() {
  41483. var currentLevel = this.currentLevel;
  41484. var level = this.levels[currentLevel];
  41485. var value = level.items[level.index];
  41486. level.items[level.index] = 0xFF;
  41487. currentLevel--;
  41488. if (currentLevel < 0) {
  41489. return false;
  41490. }
  41491. this.currentLevel = currentLevel;
  41492. level = this.levels[currentLevel];
  41493. level.items[level.index] = value;
  41494. return true;
  41495. }
  41496. };
  41497. return InclusionTree;
  41498. })();
  41499. // Section D. Coefficient bit modeling
  41500. var BitModel = (function BitModelClosure() {
  41501. var UNIFORM_CONTEXT = 17;
  41502. var RUNLENGTH_CONTEXT = 18;
  41503. // Table D-1
  41504. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  41505. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  41506. var LLAndLHContextsLabel = new Uint8Array([
  41507. 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,
  41508. 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,
  41509. 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
  41510. ]);
  41511. var HLContextLabel = new Uint8Array([
  41512. 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,
  41513. 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,
  41514. 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
  41515. ]);
  41516. var HHContextLabel = new Uint8Array([
  41517. 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,
  41518. 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,
  41519. 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
  41520. ]);
  41521. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  41522. this.width = width;
  41523. this.height = height;
  41524. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  41525. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  41526. var coefficientCount = width * height;
  41527. // coefficients outside the encoding region treated as insignificant
  41528. // add border state cells for significanceState
  41529. this.neighborsSignificance = new Uint8Array(coefficientCount);
  41530. this.coefficentsSign = new Uint8Array(coefficientCount);
  41531. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  41532. mb > 6 ? new Uint16Array(coefficientCount) :
  41533. new Uint8Array(coefficientCount);
  41534. this.processingFlags = new Uint8Array(coefficientCount);
  41535. var bitsDecoded = new Uint8Array(coefficientCount);
  41536. if (zeroBitPlanes !== 0) {
  41537. for (var i = 0; i < coefficientCount; i++) {
  41538. bitsDecoded[i] = zeroBitPlanes;
  41539. }
  41540. }
  41541. this.bitsDecoded = bitsDecoded;
  41542. this.reset();
  41543. }
  41544. BitModel.prototype = {
  41545. setDecoder: function BitModel_setDecoder(decoder) {
  41546. this.decoder = decoder;
  41547. },
  41548. reset: function BitModel_reset() {
  41549. // We have 17 contexts that are accessed via context labels,
  41550. // plus the uniform and runlength context.
  41551. this.contexts = new Int8Array(19);
  41552. // Contexts are packed into 1 byte:
  41553. // highest 7 bits carry the index, lowest bit carries mps
  41554. this.contexts[0] = (4 << 1) | 0;
  41555. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  41556. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  41557. },
  41558. setNeighborsSignificance:
  41559. function BitModel_setNeighborsSignificance(row, column, index) {
  41560. var neighborsSignificance = this.neighborsSignificance;
  41561. var width = this.width, height = this.height;
  41562. var left = (column > 0);
  41563. var right = (column + 1 < width);
  41564. var i;
  41565. if (row > 0) {
  41566. i = index - width;
  41567. if (left) {
  41568. neighborsSignificance[i - 1] += 0x10;
  41569. }
  41570. if (right) {
  41571. neighborsSignificance[i + 1] += 0x10;
  41572. }
  41573. neighborsSignificance[i] += 0x04;
  41574. }
  41575. if (row + 1 < height) {
  41576. i = index + width;
  41577. if (left) {
  41578. neighborsSignificance[i - 1] += 0x10;
  41579. }
  41580. if (right) {
  41581. neighborsSignificance[i + 1] += 0x10;
  41582. }
  41583. neighborsSignificance[i] += 0x04;
  41584. }
  41585. if (left) {
  41586. neighborsSignificance[index - 1] += 0x01;
  41587. }
  41588. if (right) {
  41589. neighborsSignificance[index + 1] += 0x01;
  41590. }
  41591. neighborsSignificance[index] |= 0x80;
  41592. },
  41593. runSignificancePropogationPass:
  41594. function BitModel_runSignificancePropogationPass() {
  41595. var decoder = this.decoder;
  41596. var width = this.width, height = this.height;
  41597. var coefficentsMagnitude = this.coefficentsMagnitude;
  41598. var coefficentsSign = this.coefficentsSign;
  41599. var neighborsSignificance = this.neighborsSignificance;
  41600. var processingFlags = this.processingFlags;
  41601. var contexts = this.contexts;
  41602. var labels = this.contextLabelTable;
  41603. var bitsDecoded = this.bitsDecoded;
  41604. var processedInverseMask = ~1;
  41605. var processedMask = 1;
  41606. var firstMagnitudeBitMask = 2;
  41607. for (var i0 = 0; i0 < height; i0 += 4) {
  41608. for (var j = 0; j < width; j++) {
  41609. var index = i0 * width + j;
  41610. for (var i1 = 0; i1 < 4; i1++, index += width) {
  41611. var i = i0 + i1;
  41612. if (i >= height) {
  41613. break;
  41614. }
  41615. // clear processed flag first
  41616. processingFlags[index] &= processedInverseMask;
  41617. if (coefficentsMagnitude[index] ||
  41618. !neighborsSignificance[index]) {
  41619. continue;
  41620. }
  41621. var contextLabel = labels[neighborsSignificance[index]];
  41622. var decision = decoder.readBit(contexts, contextLabel);
  41623. if (decision) {
  41624. var sign = this.decodeSignBit(i, j, index);
  41625. coefficentsSign[index] = sign;
  41626. coefficentsMagnitude[index] = 1;
  41627. this.setNeighborsSignificance(i, j, index);
  41628. processingFlags[index] |= firstMagnitudeBitMask;
  41629. }
  41630. bitsDecoded[index]++;
  41631. processingFlags[index] |= processedMask;
  41632. }
  41633. }
  41634. }
  41635. },
  41636. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  41637. var width = this.width, height = this.height;
  41638. var coefficentsMagnitude = this.coefficentsMagnitude;
  41639. var coefficentsSign = this.coefficentsSign;
  41640. var contribution, sign0, sign1, significance1;
  41641. var contextLabel, decoded;
  41642. // calculate horizontal contribution
  41643. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  41644. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  41645. sign1 = coefficentsSign[index + 1];
  41646. if (significance1) {
  41647. sign0 = coefficentsSign[index - 1];
  41648. contribution = 1 - sign1 - sign0;
  41649. } else {
  41650. contribution = 1 - sign1 - sign1;
  41651. }
  41652. } else if (significance1) {
  41653. sign0 = coefficentsSign[index - 1];
  41654. contribution = 1 - sign0 - sign0;
  41655. } else {
  41656. contribution = 0;
  41657. }
  41658. var horizontalContribution = 3 * contribution;
  41659. // calculate vertical contribution and combine with the horizontal
  41660. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  41661. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  41662. sign1 = coefficentsSign[index + width];
  41663. if (significance1) {
  41664. sign0 = coefficentsSign[index - width];
  41665. contribution = 1 - sign1 - sign0 + horizontalContribution;
  41666. } else {
  41667. contribution = 1 - sign1 - sign1 + horizontalContribution;
  41668. }
  41669. } else if (significance1) {
  41670. sign0 = coefficentsSign[index - width];
  41671. contribution = 1 - sign0 - sign0 + horizontalContribution;
  41672. } else {
  41673. contribution = horizontalContribution;
  41674. }
  41675. if (contribution >= 0) {
  41676. contextLabel = 9 + contribution;
  41677. decoded = this.decoder.readBit(this.contexts, contextLabel);
  41678. } else {
  41679. contextLabel = 9 - contribution;
  41680. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  41681. }
  41682. return decoded;
  41683. },
  41684. runMagnitudeRefinementPass:
  41685. function BitModel_runMagnitudeRefinementPass() {
  41686. var decoder = this.decoder;
  41687. var width = this.width, height = this.height;
  41688. var coefficentsMagnitude = this.coefficentsMagnitude;
  41689. var neighborsSignificance = this.neighborsSignificance;
  41690. var contexts = this.contexts;
  41691. var bitsDecoded = this.bitsDecoded;
  41692. var processingFlags = this.processingFlags;
  41693. var processedMask = 1;
  41694. var firstMagnitudeBitMask = 2;
  41695. var length = width * height;
  41696. var width4 = width * 4;
  41697. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  41698. indexNext = Math.min(length, index0 + width4);
  41699. for (var j = 0; j < width; j++) {
  41700. for (var index = index0 + j; index < indexNext; index += width) {
  41701. // significant but not those that have just become
  41702. if (!coefficentsMagnitude[index] ||
  41703. (processingFlags[index] & processedMask) !== 0) {
  41704. continue;
  41705. }
  41706. var contextLabel = 16;
  41707. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  41708. processingFlags[index] ^= firstMagnitudeBitMask;
  41709. // first refinement
  41710. var significance = neighborsSignificance[index] & 127;
  41711. contextLabel = significance === 0 ? 15 : 14;
  41712. }
  41713. var bit = decoder.readBit(contexts, contextLabel);
  41714. coefficentsMagnitude[index] =
  41715. (coefficentsMagnitude[index] << 1) | bit;
  41716. bitsDecoded[index]++;
  41717. processingFlags[index] |= processedMask;
  41718. }
  41719. }
  41720. }
  41721. },
  41722. runCleanupPass: function BitModel_runCleanupPass() {
  41723. var decoder = this.decoder;
  41724. var width = this.width, height = this.height;
  41725. var neighborsSignificance = this.neighborsSignificance;
  41726. var coefficentsMagnitude = this.coefficentsMagnitude;
  41727. var coefficentsSign = this.coefficentsSign;
  41728. var contexts = this.contexts;
  41729. var labels = this.contextLabelTable;
  41730. var bitsDecoded = this.bitsDecoded;
  41731. var processingFlags = this.processingFlags;
  41732. var processedMask = 1;
  41733. var firstMagnitudeBitMask = 2;
  41734. var oneRowDown = width;
  41735. var twoRowsDown = width * 2;
  41736. var threeRowsDown = width * 3;
  41737. var iNext;
  41738. for (var i0 = 0; i0 < height; i0 = iNext) {
  41739. iNext = Math.min(i0 + 4, height);
  41740. var indexBase = i0 * width;
  41741. var checkAllEmpty = i0 + 3 < height;
  41742. for (var j = 0; j < width; j++) {
  41743. var index0 = indexBase + j;
  41744. // using the property: labels[neighborsSignificance[index]] === 0
  41745. // when neighborsSignificance[index] === 0
  41746. var allEmpty = (checkAllEmpty &&
  41747. processingFlags[index0] === 0 &&
  41748. processingFlags[index0 + oneRowDown] === 0 &&
  41749. processingFlags[index0 + twoRowsDown] === 0 &&
  41750. processingFlags[index0 + threeRowsDown] === 0 &&
  41751. neighborsSignificance[index0] === 0 &&
  41752. neighborsSignificance[index0 + oneRowDown] === 0 &&
  41753. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  41754. neighborsSignificance[index0 + threeRowsDown] === 0);
  41755. var i1 = 0, index = index0;
  41756. var i = i0, sign;
  41757. if (allEmpty) {
  41758. var hasSignificantCoefficent =
  41759. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  41760. if (!hasSignificantCoefficent) {
  41761. bitsDecoded[index0]++;
  41762. bitsDecoded[index0 + oneRowDown]++;
  41763. bitsDecoded[index0 + twoRowsDown]++;
  41764. bitsDecoded[index0 + threeRowsDown]++;
  41765. continue; // next column
  41766. }
  41767. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  41768. decoder.readBit(contexts, UNIFORM_CONTEXT);
  41769. if (i1 !== 0) {
  41770. i = i0 + i1;
  41771. index += i1 * width;
  41772. }
  41773. sign = this.decodeSignBit(i, j, index);
  41774. coefficentsSign[index] = sign;
  41775. coefficentsMagnitude[index] = 1;
  41776. this.setNeighborsSignificance(i, j, index);
  41777. processingFlags[index] |= firstMagnitudeBitMask;
  41778. index = index0;
  41779. for (var i2 = i0; i2 <= i; i2++, index += width) {
  41780. bitsDecoded[index]++;
  41781. }
  41782. i1++;
  41783. }
  41784. for (i = i0 + i1; i < iNext; i++, index += width) {
  41785. if (coefficentsMagnitude[index] ||
  41786. (processingFlags[index] & processedMask) !== 0) {
  41787. continue;
  41788. }
  41789. var contextLabel = labels[neighborsSignificance[index]];
  41790. var decision = decoder.readBit(contexts, contextLabel);
  41791. if (decision === 1) {
  41792. sign = this.decodeSignBit(i, j, index);
  41793. coefficentsSign[index] = sign;
  41794. coefficentsMagnitude[index] = 1;
  41795. this.setNeighborsSignificance(i, j, index);
  41796. processingFlags[index] |= firstMagnitudeBitMask;
  41797. }
  41798. bitsDecoded[index]++;
  41799. }
  41800. }
  41801. }
  41802. },
  41803. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  41804. var decoder = this.decoder;
  41805. var contexts = this.contexts;
  41806. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  41807. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  41808. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  41809. decoder.readBit(contexts, UNIFORM_CONTEXT);
  41810. if (symbol !== 0xA) {
  41811. throw new Error('JPX Error: Invalid segmentation symbol');
  41812. }
  41813. }
  41814. };
  41815. return BitModel;
  41816. })();
  41817. // Section F, Discrete wavelet transformation
  41818. var Transform = (function TransformClosure() {
  41819. function Transform() {}
  41820. Transform.prototype.calculate =
  41821. function transformCalculate(subbands, u0, v0) {
  41822. var ll = subbands[0];
  41823. for (var i = 1, ii = subbands.length; i < ii; i++) {
  41824. ll = this.iterate(ll, subbands[i], u0, v0);
  41825. }
  41826. return ll;
  41827. };
  41828. Transform.prototype.extend = function extend(buffer, offset, size) {
  41829. // Section F.3.7 extending... using max extension of 4
  41830. var i1 = offset - 1, j1 = offset + 1;
  41831. var i2 = offset + size - 2, j2 = offset + size;
  41832. buffer[i1--] = buffer[j1++];
  41833. buffer[j2++] = buffer[i2--];
  41834. buffer[i1--] = buffer[j1++];
  41835. buffer[j2++] = buffer[i2--];
  41836. buffer[i1--] = buffer[j1++];
  41837. buffer[j2++] = buffer[i2--];
  41838. buffer[i1] = buffer[j1];
  41839. buffer[j2] = buffer[i2];
  41840. };
  41841. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  41842. u0, v0) {
  41843. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  41844. var width = hl_lh_hh.width;
  41845. var height = hl_lh_hh.height;
  41846. var items = hl_lh_hh.items;
  41847. var i, j, k, l, u, v;
  41848. // Interleave LL according to Section F.3.3
  41849. for (k = 0, i = 0; i < llHeight; i++) {
  41850. l = i * 2 * width;
  41851. for (j = 0; j < llWidth; j++, k++, l += 2) {
  41852. items[l] = llItems[k];
  41853. }
  41854. }
  41855. // The LL band is not needed anymore.
  41856. llItems = ll.items = null;
  41857. var bufferPadding = 4;
  41858. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  41859. // Section F.3.4 HOR_SR
  41860. if (width === 1) {
  41861. // if width = 1, when u0 even keep items as is, when odd divide by 2
  41862. if ((u0 & 1) !== 0) {
  41863. for (v = 0, k = 0; v < height; v++, k += width) {
  41864. items[k] *= 0.5;
  41865. }
  41866. }
  41867. } else {
  41868. for (v = 0, k = 0; v < height; v++, k += width) {
  41869. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  41870. this.extend(rowBuffer, bufferPadding, width);
  41871. this.filter(rowBuffer, bufferPadding, width);
  41872. items.set(
  41873. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  41874. k);
  41875. }
  41876. }
  41877. // Accesses to the items array can take long, because it may not fit into
  41878. // CPU cache and has to be fetched from main memory. Since subsequent
  41879. // accesses to the items array are not local when reading columns, we
  41880. // have a cache miss every time. To reduce cache misses, get up to
  41881. // 'numBuffers' items at a time and store them into the individual
  41882. // buffers. The colBuffers should be small enough to fit into CPU cache.
  41883. var numBuffers = 16;
  41884. var colBuffers = [];
  41885. for (i = 0; i < numBuffers; i++) {
  41886. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  41887. }
  41888. var b, currentBuffer = 0;
  41889. ll = bufferPadding + height;
  41890. // Section F.3.5 VER_SR
  41891. if (height === 1) {
  41892. // if height = 1, when v0 even keep items as is, when odd divide by 2
  41893. if ((v0 & 1) !== 0) {
  41894. for (u = 0; u < width; u++) {
  41895. items[u] *= 0.5;
  41896. }
  41897. }
  41898. } else {
  41899. for (u = 0; u < width; u++) {
  41900. // if we ran out of buffers, copy several image columns at once
  41901. if (currentBuffer === 0) {
  41902. numBuffers = Math.min(width - u, numBuffers);
  41903. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  41904. for (b = 0; b < numBuffers; b++) {
  41905. colBuffers[b][l] = items[k + b];
  41906. }
  41907. }
  41908. currentBuffer = numBuffers;
  41909. }
  41910. currentBuffer--;
  41911. var buffer = colBuffers[currentBuffer];
  41912. this.extend(buffer, bufferPadding, height);
  41913. this.filter(buffer, bufferPadding, height);
  41914. // If this is last buffer in this group of buffers, flush all buffers.
  41915. if (currentBuffer === 0) {
  41916. k = u - numBuffers + 1;
  41917. for (l = bufferPadding; l < ll; k += width, l++) {
  41918. for (b = 0; b < numBuffers; b++) {
  41919. items[k + b] = colBuffers[b][l];
  41920. }
  41921. }
  41922. }
  41923. }
  41924. }
  41925. return {
  41926. width: width,
  41927. height: height,
  41928. items: items
  41929. };
  41930. };
  41931. return Transform;
  41932. })();
  41933. // Section 3.8.2 Irreversible 9-7 filter
  41934. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  41935. function IrreversibleTransform() {
  41936. Transform.call(this);
  41937. }
  41938. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  41939. IrreversibleTransform.prototype.filter =
  41940. function irreversibleTransformFilter(x, offset, length) {
  41941. var len = length >> 1;
  41942. offset = offset | 0;
  41943. var j, n, current, next;
  41944. var alpha = -1.586134342059924;
  41945. var beta = -0.052980118572961;
  41946. var gamma = 0.882911075530934;
  41947. var delta = 0.443506852043971;
  41948. var K = 1.230174104914001;
  41949. var K_ = 1 / K;
  41950. // step 1 is combined with step 3
  41951. // step 2
  41952. j = offset - 3;
  41953. for (n = len + 4; n--; j += 2) {
  41954. x[j] *= K_;
  41955. }
  41956. // step 1 & 3
  41957. j = offset - 2;
  41958. current = delta * x[j -1];
  41959. for (n = len + 3; n--; j += 2) {
  41960. next = delta * x[j + 1];
  41961. x[j] = K * x[j] - current - next;
  41962. if (n--) {
  41963. j += 2;
  41964. current = delta * x[j + 1];
  41965. x[j] = K * x[j] - current - next;
  41966. } else {
  41967. break;
  41968. }
  41969. }
  41970. // step 4
  41971. j = offset - 1;
  41972. current = gamma * x[j - 1];
  41973. for (n = len + 2; n--; j += 2) {
  41974. next = gamma * x[j + 1];
  41975. x[j] -= current + next;
  41976. if (n--) {
  41977. j += 2;
  41978. current = gamma * x[j + 1];
  41979. x[j] -= current + next;
  41980. } else {
  41981. break;
  41982. }
  41983. }
  41984. // step 5
  41985. j = offset;
  41986. current = beta * x[j - 1];
  41987. for (n = len + 1; n--; j += 2) {
  41988. next = beta * x[j + 1];
  41989. x[j] -= current + next;
  41990. if (n--) {
  41991. j += 2;
  41992. current = beta * x[j + 1];
  41993. x[j] -= current + next;
  41994. } else {
  41995. break;
  41996. }
  41997. }
  41998. // step 6
  41999. if (len !== 0) {
  42000. j = offset + 1;
  42001. current = alpha * x[j - 1];
  42002. for (n = len; n--; j += 2) {
  42003. next = alpha * x[j + 1];
  42004. x[j] -= current + next;
  42005. if (n--) {
  42006. j += 2;
  42007. current = alpha * x[j + 1];
  42008. x[j] -= current + next;
  42009. } else {
  42010. break;
  42011. }
  42012. }
  42013. }
  42014. };
  42015. return IrreversibleTransform;
  42016. })();
  42017. // Section 3.8.1 Reversible 5-3 filter
  42018. var ReversibleTransform = (function ReversibleTransformClosure() {
  42019. function ReversibleTransform() {
  42020. Transform.call(this);
  42021. }
  42022. ReversibleTransform.prototype = Object.create(Transform.prototype);
  42023. ReversibleTransform.prototype.filter =
  42024. function reversibleTransformFilter(x, offset, length) {
  42025. var len = length >> 1;
  42026. offset = offset | 0;
  42027. var j, n;
  42028. for (j = offset, n = len + 1; n--; j += 2) {
  42029. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  42030. }
  42031. for (j = offset + 1, n = len; n--; j += 2) {
  42032. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  42033. }
  42034. };
  42035. return ReversibleTransform;
  42036. })();
  42037. return JpxImage;
  42038. })();
  42039. var Jbig2Image = (function Jbig2ImageClosure() {
  42040. // Utility data structures
  42041. function ContextCache() {}
  42042. ContextCache.prototype = {
  42043. getContexts: function(id) {
  42044. if (id in this) {
  42045. return this[id];
  42046. }
  42047. return (this[id] = new Int8Array(1 << 16));
  42048. }
  42049. };
  42050. function DecodingContext(data, start, end) {
  42051. this.data = data;
  42052. this.start = start;
  42053. this.end = end;
  42054. }
  42055. DecodingContext.prototype = {
  42056. get decoder() {
  42057. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  42058. return shadow(this, 'decoder', decoder);
  42059. },
  42060. get contextCache() {
  42061. var cache = new ContextCache();
  42062. return shadow(this, 'contextCache', cache);
  42063. }
  42064. };
  42065. // Annex A. Arithmetic Integer Decoding Procedure
  42066. // A.2 Procedure for decoding values
  42067. function decodeInteger(contextCache, procedure, decoder) {
  42068. var contexts = contextCache.getContexts(procedure);
  42069. var prev = 1;
  42070. function readBits(length) {
  42071. var v = 0;
  42072. for (var i = 0; i < length; i++) {
  42073. var bit = decoder.readBit(contexts, prev);
  42074. prev = (prev < 256 ? (prev << 1) | bit :
  42075. (((prev << 1) | bit) & 511) | 256);
  42076. v = (v << 1) | bit;
  42077. }
  42078. return v >>> 0;
  42079. }
  42080. var sign = readBits(1);
  42081. var value = readBits(1) ?
  42082. (readBits(1) ?
  42083. (readBits(1) ?
  42084. (readBits(1) ?
  42085. (readBits(1) ?
  42086. (readBits(32) + 4436) :
  42087. readBits(12) + 340) :
  42088. readBits(8) + 84) :
  42089. readBits(6) + 20) :
  42090. readBits(4) + 4) :
  42091. readBits(2);
  42092. return (sign === 0 ? value : (value > 0 ? -value : null));
  42093. }
  42094. // A.3 The IAID decoding procedure
  42095. function decodeIAID(contextCache, decoder, codeLength) {
  42096. var contexts = contextCache.getContexts('IAID');
  42097. var prev = 1;
  42098. for (var i = 0; i < codeLength; i++) {
  42099. var bit = decoder.readBit(contexts, prev);
  42100. prev = (prev << 1) | bit;
  42101. }
  42102. if (codeLength < 31) {
  42103. return prev & ((1 << codeLength) - 1);
  42104. }
  42105. return prev & 0x7FFFFFFF;
  42106. }
  42107. // 7.3 Segment types
  42108. var SegmentTypes = [
  42109. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  42110. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  42111. null, null, null, null, null, 'patternDictionary', null, null, null,
  42112. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  42113. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  42114. null, null, null, null, null, 'IntermediateGenericRegion', null,
  42115. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  42116. 'IntermediateGenericRefinementRegion', null,
  42117. 'ImmediateGenericRefinementRegion',
  42118. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  42119. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  42120. 'Tables', null, null, null, null, null, null, null, null,
  42121. 'Extension'
  42122. ];
  42123. var CodingTemplates = [
  42124. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  42125. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  42126. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  42127. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  42128. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  42129. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  42130. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  42131. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  42132. {x: -1, y: 0}],
  42133. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  42134. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  42135. ];
  42136. var RefinementTemplates = [
  42137. {
  42138. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  42139. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  42140. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  42141. },
  42142. {
  42143. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  42144. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  42145. {x: 0, y: 1}, {x: 1, y: 1}]
  42146. }
  42147. ];
  42148. // See 6.2.5.7 Decoding the bitmap.
  42149. var ReusedContexts = [
  42150. 0x9B25, // 10011 0110010 0101
  42151. 0x0795, // 0011 110010 101
  42152. 0x00E5, // 001 11001 01
  42153. 0x0195 // 011001 0101
  42154. ];
  42155. var RefinementReusedContexts = [
  42156. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  42157. 0x0008 // '0000' + '001000'
  42158. ];
  42159. function decodeBitmapTemplate0(width, height, decodingContext) {
  42160. var decoder = decodingContext.decoder;
  42161. var contexts = decodingContext.contextCache.getContexts('GB');
  42162. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  42163. // ...ooooo....
  42164. // ..ooooooo... Context template for current pixel (X)
  42165. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  42166. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  42167. for (i = 0; i < height; i++) {
  42168. row = bitmap[i] = new Uint8Array(width);
  42169. row1 = (i < 1) ? row : bitmap[i - 1];
  42170. row2 = (i < 2) ? row : bitmap[i - 2];
  42171. // At the beginning of each row:
  42172. // Fill contextLabel with pixels that are above/right of (X)
  42173. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  42174. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  42175. (row1[3] << 4);
  42176. for (j = 0; j < width; j++) {
  42177. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  42178. // At each pixel: Clear contextLabel pixels that are shifted
  42179. // out of the context, then add new ones.
  42180. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  42181. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  42182. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  42183. }
  42184. }
  42185. return bitmap;
  42186. }
  42187. // 6.2 Generic Region Decoding Procedure
  42188. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  42189. decodingContext) {
  42190. if (mmr) {
  42191. error('JBIG2 error: MMR encoding is not supported');
  42192. }
  42193. // Use optimized version for the most common case
  42194. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  42195. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  42196. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  42197. return decodeBitmapTemplate0(width, height, decodingContext);
  42198. }
  42199. var useskip = !!skip;
  42200. var template = CodingTemplates[templateIndex].concat(at);
  42201. // Sorting is non-standard, and it is not required. But sorting increases
  42202. // the number of template bits that can be reused from the previous
  42203. // contextLabel in the main loop.
  42204. template.sort(function (a, b) {
  42205. return (a.y - b.y) || (a.x - b.x);
  42206. });
  42207. var templateLength = template.length;
  42208. var templateX = new Int8Array(templateLength);
  42209. var templateY = new Int8Array(templateLength);
  42210. var changingTemplateEntries = [];
  42211. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  42212. var c, k;
  42213. for (k = 0; k < templateLength; k++) {
  42214. templateX[k] = template[k].x;
  42215. templateY[k] = template[k].y;
  42216. minX = Math.min(minX, template[k].x);
  42217. maxX = Math.max(maxX, template[k].x);
  42218. minY = Math.min(minY, template[k].y);
  42219. // Check if the template pixel appears in two consecutive context labels,
  42220. // so it can be reused. Otherwise, we add it to the list of changing
  42221. // template entries.
  42222. if (k < templateLength - 1 &&
  42223. template[k].y === template[k + 1].y &&
  42224. template[k].x === template[k + 1].x - 1) {
  42225. reuseMask |= 1 << (templateLength - 1 - k);
  42226. } else {
  42227. changingTemplateEntries.push(k);
  42228. }
  42229. }
  42230. var changingEntriesLength = changingTemplateEntries.length;
  42231. var changingTemplateX = new Int8Array(changingEntriesLength);
  42232. var changingTemplateY = new Int8Array(changingEntriesLength);
  42233. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  42234. for (c = 0; c < changingEntriesLength; c++) {
  42235. k = changingTemplateEntries[c];
  42236. changingTemplateX[c] = template[k].x;
  42237. changingTemplateY[c] = template[k].y;
  42238. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  42239. }
  42240. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  42241. var sbb_left = -minX;
  42242. var sbb_top = -minY;
  42243. var sbb_right = width - maxX;
  42244. var pseudoPixelContext = ReusedContexts[templateIndex];
  42245. var row = new Uint8Array(width);
  42246. var bitmap = [];
  42247. var decoder = decodingContext.decoder;
  42248. var contexts = decodingContext.contextCache.getContexts('GB');
  42249. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  42250. for (var i = 0; i < height; i++) {
  42251. if (prediction) {
  42252. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  42253. ltp ^= sltp;
  42254. if (ltp) {
  42255. bitmap.push(row); // duplicate previous row
  42256. continue;
  42257. }
  42258. }
  42259. row = new Uint8Array(row);
  42260. bitmap.push(row);
  42261. for (j = 0; j < width; j++) {
  42262. if (useskip && skip[i][j]) {
  42263. row[j] = 0;
  42264. continue;
  42265. }
  42266. // Are we in the middle of a scanline, so we can reuse contextLabel
  42267. // bits?
  42268. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  42269. // If yes, we can just shift the bits that are reusable and only
  42270. // fetch the remaining ones.
  42271. contextLabel = (contextLabel << 1) & reuseMask;
  42272. for (k = 0; k < changingEntriesLength; k++) {
  42273. i0 = i + changingTemplateY[k];
  42274. j0 = j + changingTemplateX[k];
  42275. bit = bitmap[i0][j0];
  42276. if (bit) {
  42277. bit = changingTemplateBit[k];
  42278. contextLabel |= bit;
  42279. }
  42280. }
  42281. } else {
  42282. // compute the contextLabel from scratch
  42283. contextLabel = 0;
  42284. shift = templateLength - 1;
  42285. for (k = 0; k < templateLength; k++, shift--) {
  42286. j0 = j + templateX[k];
  42287. if (j0 >= 0 && j0 < width) {
  42288. i0 = i + templateY[k];
  42289. if (i0 >= 0) {
  42290. bit = bitmap[i0][j0];
  42291. if (bit) {
  42292. contextLabel |= bit << shift;
  42293. }
  42294. }
  42295. }
  42296. }
  42297. }
  42298. var pixel = decoder.readBit(contexts, contextLabel);
  42299. row[j] = pixel;
  42300. }
  42301. }
  42302. return bitmap;
  42303. }
  42304. // 6.3.2 Generic Refinement Region Decoding Procedure
  42305. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  42306. offsetX, offsetY, prediction, at,
  42307. decodingContext) {
  42308. var codingTemplate = RefinementTemplates[templateIndex].coding;
  42309. if (templateIndex === 0) {
  42310. codingTemplate = codingTemplate.concat([at[0]]);
  42311. }
  42312. var codingTemplateLength = codingTemplate.length;
  42313. var codingTemplateX = new Int32Array(codingTemplateLength);
  42314. var codingTemplateY = new Int32Array(codingTemplateLength);
  42315. var k;
  42316. for (k = 0; k < codingTemplateLength; k++) {
  42317. codingTemplateX[k] = codingTemplate[k].x;
  42318. codingTemplateY[k] = codingTemplate[k].y;
  42319. }
  42320. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  42321. if (templateIndex === 0) {
  42322. referenceTemplate = referenceTemplate.concat([at[1]]);
  42323. }
  42324. var referenceTemplateLength = referenceTemplate.length;
  42325. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  42326. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  42327. for (k = 0; k < referenceTemplateLength; k++) {
  42328. referenceTemplateX[k] = referenceTemplate[k].x;
  42329. referenceTemplateY[k] = referenceTemplate[k].y;
  42330. }
  42331. var referenceWidth = referenceBitmap[0].length;
  42332. var referenceHeight = referenceBitmap.length;
  42333. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  42334. var bitmap = [];
  42335. var decoder = decodingContext.decoder;
  42336. var contexts = decodingContext.contextCache.getContexts('GR');
  42337. var ltp = 0;
  42338. for (var i = 0; i < height; i++) {
  42339. if (prediction) {
  42340. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  42341. ltp ^= sltp;
  42342. if (ltp) {
  42343. error('JBIG2 error: prediction is not supported');
  42344. }
  42345. }
  42346. var row = new Uint8Array(width);
  42347. bitmap.push(row);
  42348. for (var j = 0; j < width; j++) {
  42349. var i0, j0;
  42350. var contextLabel = 0;
  42351. for (k = 0; k < codingTemplateLength; k++) {
  42352. i0 = i + codingTemplateY[k];
  42353. j0 = j + codingTemplateX[k];
  42354. if (i0 < 0 || j0 < 0 || j0 >= width) {
  42355. contextLabel <<= 1; // out of bound pixel
  42356. } else {
  42357. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  42358. }
  42359. }
  42360. for (k = 0; k < referenceTemplateLength; k++) {
  42361. i0 = i + referenceTemplateY[k] + offsetY;
  42362. j0 = j + referenceTemplateX[k] + offsetX;
  42363. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  42364. j0 >= referenceWidth) {
  42365. contextLabel <<= 1; // out of bound pixel
  42366. } else {
  42367. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  42368. }
  42369. }
  42370. var pixel = decoder.readBit(contexts, contextLabel);
  42371. row[j] = pixel;
  42372. }
  42373. }
  42374. return bitmap;
  42375. }
  42376. // 6.5.5 Decoding the symbol dictionary
  42377. function decodeSymbolDictionary(huffman, refinement, symbols,
  42378. numberOfNewSymbols, numberOfExportedSymbols,
  42379. huffmanTables, templateIndex, at,
  42380. refinementTemplateIndex, refinementAt,
  42381. decodingContext) {
  42382. if (huffman) {
  42383. error('JBIG2 error: huffman is not supported');
  42384. }
  42385. var newSymbols = [];
  42386. var currentHeight = 0;
  42387. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  42388. var decoder = decodingContext.decoder;
  42389. var contextCache = decodingContext.contextCache;
  42390. while (newSymbols.length < numberOfNewSymbols) {
  42391. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  42392. currentHeight += deltaHeight;
  42393. var currentWidth = 0;
  42394. var totalWidth = 0;
  42395. while (true) {
  42396. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  42397. if (deltaWidth === null) {
  42398. break; // OOB
  42399. }
  42400. currentWidth += deltaWidth;
  42401. totalWidth += currentWidth;
  42402. var bitmap;
  42403. if (refinement) {
  42404. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  42405. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  42406. if (numberOfInstances > 1) {
  42407. bitmap = decodeTextRegion(huffman, refinement,
  42408. currentWidth, currentHeight, 0,
  42409. numberOfInstances, 1, //strip size
  42410. symbols.concat(newSymbols),
  42411. symbolCodeLength,
  42412. 0, //transposed
  42413. 0, //ds offset
  42414. 1, //top left 7.4.3.1.1
  42415. 0, //OR operator
  42416. huffmanTables,
  42417. refinementTemplateIndex, refinementAt,
  42418. decodingContext);
  42419. } else {
  42420. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  42421. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  42422. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  42423. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  42424. newSymbols[symbolId - symbols.length]);
  42425. bitmap = decodeRefinement(currentWidth, currentHeight,
  42426. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  42427. decodingContext);
  42428. }
  42429. } else {
  42430. // 6.5.8.1 Direct-coded symbol bitmap
  42431. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  42432. templateIndex, false, null, at, decodingContext);
  42433. }
  42434. newSymbols.push(bitmap);
  42435. }
  42436. }
  42437. // 6.5.10 Exported symbols
  42438. var exportedSymbols = [];
  42439. var flags = [], currentFlag = false;
  42440. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  42441. while (flags.length < totalSymbolsLength) {
  42442. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  42443. while (runLength--) {
  42444. flags.push(currentFlag);
  42445. }
  42446. currentFlag = !currentFlag;
  42447. }
  42448. for (var i = 0, ii = symbols.length; i < ii; i++) {
  42449. if (flags[i]) {
  42450. exportedSymbols.push(symbols[i]);
  42451. }
  42452. }
  42453. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  42454. if (flags[i]) {
  42455. exportedSymbols.push(newSymbols[j]);
  42456. }
  42457. }
  42458. return exportedSymbols;
  42459. }
  42460. function decodeTextRegion(huffman, refinement, width, height,
  42461. defaultPixelValue, numberOfSymbolInstances,
  42462. stripSize, inputSymbols, symbolCodeLength,
  42463. transposed, dsOffset, referenceCorner,
  42464. combinationOperator, huffmanTables,
  42465. refinementTemplateIndex, refinementAt,
  42466. decodingContext) {
  42467. if (huffman) {
  42468. error('JBIG2 error: huffman is not supported');
  42469. }
  42470. // Prepare bitmap
  42471. var bitmap = [];
  42472. var i, row;
  42473. for (i = 0; i < height; i++) {
  42474. row = new Uint8Array(width);
  42475. if (defaultPixelValue) {
  42476. for (var j = 0; j < width; j++) {
  42477. row[j] = defaultPixelValue;
  42478. }
  42479. }
  42480. bitmap.push(row);
  42481. }
  42482. var decoder = decodingContext.decoder;
  42483. var contextCache = decodingContext.contextCache;
  42484. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  42485. var firstS = 0;
  42486. i = 0;
  42487. while (i < numberOfSymbolInstances) {
  42488. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  42489. stripT += deltaT;
  42490. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  42491. firstS += deltaFirstS;
  42492. var currentS = firstS;
  42493. do {
  42494. var currentT = (stripSize === 1 ? 0 :
  42495. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  42496. var t = stripSize * stripT + currentT;
  42497. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  42498. var applyRefinement = (refinement &&
  42499. decodeInteger(contextCache, 'IARI', decoder));
  42500. var symbolBitmap = inputSymbols[symbolId];
  42501. var symbolWidth = symbolBitmap[0].length;
  42502. var symbolHeight = symbolBitmap.length;
  42503. if (applyRefinement) {
  42504. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  42505. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  42506. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  42507. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  42508. symbolWidth += rdw;
  42509. symbolHeight += rdh;
  42510. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  42511. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  42512. (rdh >> 1) + rdy, false, refinementAt,
  42513. decodingContext);
  42514. }
  42515. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  42516. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  42517. var s2, t2, symbolRow;
  42518. if (transposed) {
  42519. // Place Symbol Bitmap from T1,S1
  42520. for (s2 = 0; s2 < symbolHeight; s2++) {
  42521. row = bitmap[offsetS + s2];
  42522. if (!row) {
  42523. continue;
  42524. }
  42525. symbolRow = symbolBitmap[s2];
  42526. // To ignore Parts of Symbol bitmap which goes
  42527. // outside bitmap region
  42528. var maxWidth = Math.min(width - offsetT, symbolWidth);
  42529. switch (combinationOperator) {
  42530. case 0: // OR
  42531. for (t2 = 0; t2 < maxWidth; t2++) {
  42532. row[offsetT + t2] |= symbolRow[t2];
  42533. }
  42534. break;
  42535. case 2: // XOR
  42536. for (t2 = 0; t2 < maxWidth; t2++) {
  42537. row[offsetT + t2] ^= symbolRow[t2];
  42538. }
  42539. break;
  42540. default:
  42541. error('JBIG2 error: operator ' + combinationOperator +
  42542. ' is not supported');
  42543. }
  42544. }
  42545. currentS += symbolHeight - 1;
  42546. } else {
  42547. for (t2 = 0; t2 < symbolHeight; t2++) {
  42548. row = bitmap[offsetT + t2];
  42549. if (!row) {
  42550. continue;
  42551. }
  42552. symbolRow = symbolBitmap[t2];
  42553. switch (combinationOperator) {
  42554. case 0: // OR
  42555. for (s2 = 0; s2 < symbolWidth; s2++) {
  42556. row[offsetS + s2] |= symbolRow[s2];
  42557. }
  42558. break;
  42559. case 2: // XOR
  42560. for (s2 = 0; s2 < symbolWidth; s2++) {
  42561. row[offsetS + s2] ^= symbolRow[s2];
  42562. }
  42563. break;
  42564. default:
  42565. error('JBIG2 error: operator ' + combinationOperator +
  42566. ' is not supported');
  42567. }
  42568. }
  42569. currentS += symbolWidth - 1;
  42570. }
  42571. i++;
  42572. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  42573. if (deltaS === null) {
  42574. break; // OOB
  42575. }
  42576. currentS += deltaS + dsOffset;
  42577. } while (true);
  42578. }
  42579. return bitmap;
  42580. }
  42581. function readSegmentHeader(data, start) {
  42582. var segmentHeader = {};
  42583. segmentHeader.number = readUint32(data, start);
  42584. var flags = data[start + 4];
  42585. var segmentType = flags & 0x3F;
  42586. if (!SegmentTypes[segmentType]) {
  42587. error('JBIG2 error: invalid segment type: ' + segmentType);
  42588. }
  42589. segmentHeader.type = segmentType;
  42590. segmentHeader.typeName = SegmentTypes[segmentType];
  42591. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  42592. var pageAssociationFieldSize = !!(flags & 0x40);
  42593. var referredFlags = data[start + 5];
  42594. var referredToCount = (referredFlags >> 5) & 7;
  42595. var retainBits = [referredFlags & 31];
  42596. var position = start + 6;
  42597. if (referredFlags === 7) {
  42598. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  42599. position += 3;
  42600. var bytes = (referredToCount + 7) >> 3;
  42601. retainBits[0] = data[position++];
  42602. while (--bytes > 0) {
  42603. retainBits.push(data[position++]);
  42604. }
  42605. } else if (referredFlags === 5 || referredFlags === 6) {
  42606. error('JBIG2 error: invalid referred-to flags');
  42607. }
  42608. segmentHeader.retainBits = retainBits;
  42609. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  42610. (segmentHeader.number <= 65536 ? 2 : 4));
  42611. var referredTo = [];
  42612. var i, ii;
  42613. for (i = 0; i < referredToCount; i++) {
  42614. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  42615. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  42616. readUint32(data, position)));
  42617. referredTo.push(number);
  42618. position += referredToSegmentNumberSize;
  42619. }
  42620. segmentHeader.referredTo = referredTo;
  42621. if (!pageAssociationFieldSize) {
  42622. segmentHeader.pageAssociation = data[position++];
  42623. } else {
  42624. segmentHeader.pageAssociation = readUint32(data, position);
  42625. position += 4;
  42626. }
  42627. segmentHeader.length = readUint32(data, position);
  42628. position += 4;
  42629. if (segmentHeader.length === 0xFFFFFFFF) {
  42630. // 7.2.7 Segment data length, unknown segment length
  42631. if (segmentType === 38) { // ImmediateGenericRegion
  42632. var genericRegionInfo = readRegionSegmentInformation(data, position);
  42633. var genericRegionSegmentFlags = data[position +
  42634. RegionSegmentInformationFieldLength];
  42635. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  42636. // searching for the segment end
  42637. var searchPatternLength = 6;
  42638. var searchPattern = new Uint8Array(searchPatternLength);
  42639. if (!genericRegionMmr) {
  42640. searchPattern[0] = 0xFF;
  42641. searchPattern[1] = 0xAC;
  42642. }
  42643. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  42644. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  42645. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  42646. searchPattern[5] = genericRegionInfo.height & 0xFF;
  42647. for (i = position, ii = data.length; i < ii; i++) {
  42648. var j = 0;
  42649. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  42650. j++;
  42651. }
  42652. if (j === searchPatternLength) {
  42653. segmentHeader.length = i + searchPatternLength;
  42654. break;
  42655. }
  42656. }
  42657. if (segmentHeader.length === 0xFFFFFFFF) {
  42658. error('JBIG2 error: segment end was not found');
  42659. }
  42660. } else {
  42661. error('JBIG2 error: invalid unknown segment length');
  42662. }
  42663. }
  42664. segmentHeader.headerEnd = position;
  42665. return segmentHeader;
  42666. }
  42667. function readSegments(header, data, start, end) {
  42668. var segments = [];
  42669. var position = start;
  42670. while (position < end) {
  42671. var segmentHeader = readSegmentHeader(data, position);
  42672. position = segmentHeader.headerEnd;
  42673. var segment = {
  42674. header: segmentHeader,
  42675. data: data
  42676. };
  42677. if (!header.randomAccess) {
  42678. segment.start = position;
  42679. position += segmentHeader.length;
  42680. segment.end = position;
  42681. }
  42682. segments.push(segment);
  42683. if (segmentHeader.type === 51) {
  42684. break; // end of file is found
  42685. }
  42686. }
  42687. if (header.randomAccess) {
  42688. for (var i = 0, ii = segments.length; i < ii; i++) {
  42689. segments[i].start = position;
  42690. position += segments[i].header.length;
  42691. segments[i].end = position;
  42692. }
  42693. }
  42694. return segments;
  42695. }
  42696. // 7.4.1 Region segment information field
  42697. function readRegionSegmentInformation(data, start) {
  42698. return {
  42699. width: readUint32(data, start),
  42700. height: readUint32(data, start + 4),
  42701. x: readUint32(data, start + 8),
  42702. y: readUint32(data, start + 12),
  42703. combinationOperator: data[start + 16] & 7
  42704. };
  42705. }
  42706. var RegionSegmentInformationFieldLength = 17;
  42707. function processSegment(segment, visitor) {
  42708. var header = segment.header;
  42709. var data = segment.data, position = segment.start, end = segment.end;
  42710. var args, at, i, atLength;
  42711. switch (header.type) {
  42712. case 0: // SymbolDictionary
  42713. // 7.4.2 Symbol dictionary segment syntax
  42714. var dictionary = {};
  42715. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  42716. dictionary.huffman = !!(dictionaryFlags & 1);
  42717. dictionary.refinement = !!(dictionaryFlags & 2);
  42718. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  42719. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  42720. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  42721. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  42722. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  42723. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  42724. dictionary.template = (dictionaryFlags >> 10) & 3;
  42725. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  42726. position += 2;
  42727. if (!dictionary.huffman) {
  42728. atLength = dictionary.template === 0 ? 4 : 1;
  42729. at = [];
  42730. for (i = 0; i < atLength; i++) {
  42731. at.push({
  42732. x: readInt8(data, position),
  42733. y: readInt8(data, position + 1)
  42734. });
  42735. position += 2;
  42736. }
  42737. dictionary.at = at;
  42738. }
  42739. if (dictionary.refinement && !dictionary.refinementTemplate) {
  42740. at = [];
  42741. for (i = 0; i < 2; i++) {
  42742. at.push({
  42743. x: readInt8(data, position),
  42744. y: readInt8(data, position + 1)
  42745. });
  42746. position += 2;
  42747. }
  42748. dictionary.refinementAt = at;
  42749. }
  42750. dictionary.numberOfExportedSymbols = readUint32(data, position);
  42751. position += 4;
  42752. dictionary.numberOfNewSymbols = readUint32(data, position);
  42753. position += 4;
  42754. args = [dictionary, header.number, header.referredTo,
  42755. data, position, end];
  42756. break;
  42757. case 6: // ImmediateTextRegion
  42758. case 7: // ImmediateLosslessTextRegion
  42759. var textRegion = {};
  42760. textRegion.info = readRegionSegmentInformation(data, position);
  42761. position += RegionSegmentInformationFieldLength;
  42762. var textRegionSegmentFlags = readUint16(data, position);
  42763. position += 2;
  42764. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  42765. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  42766. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  42767. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  42768. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  42769. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  42770. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  42771. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  42772. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  42773. if (textRegion.huffman) {
  42774. var textRegionHuffmanFlags = readUint16(data, position);
  42775. position += 2;
  42776. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  42777. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  42778. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  42779. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  42780. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  42781. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  42782. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  42783. textRegion.huffmanRefinementSizeSelector =
  42784. !!(textRegionHuffmanFlags & 14);
  42785. }
  42786. if (textRegion.refinement && !textRegion.refinementTemplate) {
  42787. at = [];
  42788. for (i = 0; i < 2; i++) {
  42789. at.push({
  42790. x: readInt8(data, position),
  42791. y: readInt8(data, position + 1)
  42792. });
  42793. position += 2;
  42794. }
  42795. textRegion.refinementAt = at;
  42796. }
  42797. textRegion.numberOfSymbolInstances = readUint32(data, position);
  42798. position += 4;
  42799. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  42800. if (textRegion.huffman) {
  42801. error('JBIG2 error: huffman is not supported');
  42802. }
  42803. args = [textRegion, header.referredTo, data, position, end];
  42804. break;
  42805. case 38: // ImmediateGenericRegion
  42806. case 39: // ImmediateLosslessGenericRegion
  42807. var genericRegion = {};
  42808. genericRegion.info = readRegionSegmentInformation(data, position);
  42809. position += RegionSegmentInformationFieldLength;
  42810. var genericRegionSegmentFlags = data[position++];
  42811. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  42812. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  42813. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  42814. if (!genericRegion.mmr) {
  42815. atLength = genericRegion.template === 0 ? 4 : 1;
  42816. at = [];
  42817. for (i = 0; i < atLength; i++) {
  42818. at.push({
  42819. x: readInt8(data, position),
  42820. y: readInt8(data, position + 1)
  42821. });
  42822. position += 2;
  42823. }
  42824. genericRegion.at = at;
  42825. }
  42826. args = [genericRegion, data, position, end];
  42827. break;
  42828. case 48: // PageInformation
  42829. var pageInfo = {
  42830. width: readUint32(data, position),
  42831. height: readUint32(data, position + 4),
  42832. resolutionX: readUint32(data, position + 8),
  42833. resolutionY: readUint32(data, position + 12)
  42834. };
  42835. if (pageInfo.height === 0xFFFFFFFF) {
  42836. delete pageInfo.height;
  42837. }
  42838. var pageSegmentFlags = data[position + 16];
  42839. var pageStripingInformatiom = readUint16(data, position + 17);
  42840. pageInfo.lossless = !!(pageSegmentFlags & 1);
  42841. pageInfo.refinement = !!(pageSegmentFlags & 2);
  42842. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  42843. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  42844. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  42845. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  42846. args = [pageInfo];
  42847. break;
  42848. case 49: // EndOfPage
  42849. break;
  42850. case 50: // EndOfStripe
  42851. break;
  42852. case 51: // EndOfFile
  42853. break;
  42854. case 62: // 7.4.15 defines 2 extension types which
  42855. // are comments and can be ignored.
  42856. break;
  42857. default:
  42858. error('JBIG2 error: segment type ' + header.typeName + '(' +
  42859. header.type + ') is not implemented');
  42860. }
  42861. var callbackName = 'on' + header.typeName;
  42862. if (callbackName in visitor) {
  42863. visitor[callbackName].apply(visitor, args);
  42864. }
  42865. }
  42866. function processSegments(segments, visitor) {
  42867. for (var i = 0, ii = segments.length; i < ii; i++) {
  42868. processSegment(segments[i], visitor);
  42869. }
  42870. }
  42871. function parseJbig2(data, start, end) {
  42872. var position = start;
  42873. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  42874. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  42875. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  42876. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  42877. error('JBIG2 error: invalid header');
  42878. }
  42879. var header = {};
  42880. position += 8;
  42881. var flags = data[position++];
  42882. header.randomAccess = !(flags & 1);
  42883. if (!(flags & 2)) {
  42884. header.numberOfPages = readUint32(data, position);
  42885. position += 4;
  42886. }
  42887. var segments = readSegments(header, data, position, end);
  42888. error('Not implemented');
  42889. // processSegments(segments, new SimpleSegmentVisitor());
  42890. }
  42891. function parseJbig2Chunks(chunks) {
  42892. var visitor = new SimpleSegmentVisitor();
  42893. for (var i = 0, ii = chunks.length; i < ii; i++) {
  42894. var chunk = chunks[i];
  42895. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  42896. processSegments(segments, visitor);
  42897. }
  42898. return visitor.buffer;
  42899. }
  42900. function SimpleSegmentVisitor() {}
  42901. SimpleSegmentVisitor.prototype = {
  42902. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  42903. this.currentPageInfo = info;
  42904. var rowSize = (info.width + 7) >> 3;
  42905. var buffer = new Uint8Array(rowSize * info.height);
  42906. // The contents of ArrayBuffers are initialized to 0.
  42907. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  42908. if (info.defaultPixelValue) {
  42909. for (var i = 0, ii = buffer.length; i < ii; i++) {
  42910. buffer[i] = 0xFF;
  42911. }
  42912. }
  42913. this.buffer = buffer;
  42914. },
  42915. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  42916. var pageInfo = this.currentPageInfo;
  42917. var width = regionInfo.width, height = regionInfo.height;
  42918. var rowSize = (pageInfo.width + 7) >> 3;
  42919. var combinationOperator = pageInfo.combinationOperatorOverride ?
  42920. regionInfo.combinationOperator : pageInfo.combinationOperator;
  42921. var buffer = this.buffer;
  42922. var mask0 = 128 >> (regionInfo.x & 7);
  42923. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  42924. var i, j, mask, offset;
  42925. switch (combinationOperator) {
  42926. case 0: // OR
  42927. for (i = 0; i < height; i++) {
  42928. mask = mask0;
  42929. offset = offset0;
  42930. for (j = 0; j < width; j++) {
  42931. if (bitmap[i][j]) {
  42932. buffer[offset] |= mask;
  42933. }
  42934. mask >>= 1;
  42935. if (!mask) {
  42936. mask = 128;
  42937. offset++;
  42938. }
  42939. }
  42940. offset0 += rowSize;
  42941. }
  42942. break;
  42943. case 2: // XOR
  42944. for (i = 0; i < height; i++) {
  42945. mask = mask0;
  42946. offset = offset0;
  42947. for (j = 0; j < width; j++) {
  42948. if (bitmap[i][j]) {
  42949. buffer[offset] ^= mask;
  42950. }
  42951. mask >>= 1;
  42952. if (!mask) {
  42953. mask = 128;
  42954. offset++;
  42955. }
  42956. }
  42957. offset0 += rowSize;
  42958. }
  42959. break;
  42960. default:
  42961. error('JBIG2 error: operator ' + combinationOperator +
  42962. ' is not supported');
  42963. }
  42964. },
  42965. onImmediateGenericRegion:
  42966. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  42967. start, end) {
  42968. var regionInfo = region.info;
  42969. var decodingContext = new DecodingContext(data, start, end);
  42970. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  42971. region.template, region.prediction, null,
  42972. region.at, decodingContext);
  42973. this.drawBitmap(regionInfo, bitmap);
  42974. },
  42975. onImmediateLosslessGenericRegion:
  42976. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  42977. this.onImmediateGenericRegion.apply(this, arguments);
  42978. },
  42979. onSymbolDictionary:
  42980. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  42981. currentSegment,
  42982. referredSegments,
  42983. data, start, end) {
  42984. var huffmanTables;
  42985. if (dictionary.huffman) {
  42986. error('JBIG2 error: huffman is not supported');
  42987. }
  42988. // Combines exported symbols from all referred segments
  42989. var symbols = this.symbols;
  42990. if (!symbols) {
  42991. this.symbols = symbols = {};
  42992. }
  42993. var inputSymbols = [];
  42994. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  42995. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  42996. }
  42997. var decodingContext = new DecodingContext(data, start, end);
  42998. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  42999. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  43000. dictionary.numberOfExportedSymbols, huffmanTables,
  43001. dictionary.template, dictionary.at,
  43002. dictionary.refinementTemplate, dictionary.refinementAt,
  43003. decodingContext);
  43004. },
  43005. onImmediateTextRegion:
  43006. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  43007. referredSegments,
  43008. data, start, end) {
  43009. var regionInfo = region.info;
  43010. var huffmanTables;
  43011. // Combines exported symbols from all referred segments
  43012. var symbols = this.symbols;
  43013. var inputSymbols = [];
  43014. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  43015. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  43016. }
  43017. var symbolCodeLength = log2(inputSymbols.length);
  43018. var decodingContext = new DecodingContext(data, start, end);
  43019. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  43020. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  43021. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  43022. symbolCodeLength, region.transposed, region.dsOffset,
  43023. region.referenceCorner, region.combinationOperator, huffmanTables,
  43024. region.refinementTemplate, region.refinementAt, decodingContext);
  43025. this.drawBitmap(regionInfo, bitmap);
  43026. },
  43027. onImmediateLosslessTextRegion:
  43028. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  43029. this.onImmediateTextRegion.apply(this, arguments);
  43030. }
  43031. };
  43032. function Jbig2Image() {}
  43033. Jbig2Image.prototype = {
  43034. parseChunks: function Jbig2Image_parseChunks(chunks) {
  43035. return parseJbig2Chunks(chunks);
  43036. }
  43037. };
  43038. return Jbig2Image;
  43039. })();
  43040. var bidi = PDFJS.bidi = (function bidiClosure() {
  43041. // Character types for symbols from 0000 to 00FF.
  43042. var baseTypes = [
  43043. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  43044. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  43045. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  43046. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  43047. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  43048. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  43049. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  43050. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  43051. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  43052. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  43053. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  43054. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  43055. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  43056. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  43057. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  43058. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  43059. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  43060. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  43061. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  43062. ];
  43063. // Character types for symbols from 0600 to 06FF
  43064. var arabicTypes = [
  43065. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43066. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  43067. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43068. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43069. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43070. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43071. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  43072. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  43073. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  43074. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  43075. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43076. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43077. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43078. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43079. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43080. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43081. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43082. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43083. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  43084. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  43085. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  43086. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  43087. ];
  43088. function isOdd(i) {
  43089. return (i & 1) !== 0;
  43090. }
  43091. function isEven(i) {
  43092. return (i & 1) === 0;
  43093. }
  43094. function findUnequal(arr, start, value) {
  43095. for (var j = start, jj = arr.length; j < jj; ++j) {
  43096. if (arr[j] !== value) {
  43097. return j;
  43098. }
  43099. }
  43100. return j;
  43101. }
  43102. function setValues(arr, start, end, value) {
  43103. for (var j = start; j < end; ++j) {
  43104. arr[j] = value;
  43105. }
  43106. }
  43107. function reverseValues(arr, start, end) {
  43108. for (var i = start, j = end - 1; i < j; ++i, --j) {
  43109. var temp = arr[i];
  43110. arr[i] = arr[j];
  43111. arr[j] = temp;
  43112. }
  43113. }
  43114. function createBidiText(str, isLTR, vertical) {
  43115. return {
  43116. str: str,
  43117. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  43118. };
  43119. }
  43120. // These are used in bidi(), which is called frequently. We re-use them on
  43121. // each call to avoid unnecessary allocations.
  43122. var chars = [];
  43123. var types = [];
  43124. function bidi(str, startLevel, vertical) {
  43125. var isLTR = true;
  43126. var strLength = str.length;
  43127. if (strLength === 0 || vertical) {
  43128. return createBidiText(str, isLTR, vertical);
  43129. }
  43130. // Get types and fill arrays
  43131. chars.length = strLength;
  43132. types.length = strLength;
  43133. var numBidi = 0;
  43134. var i, ii;
  43135. for (i = 0; i < strLength; ++i) {
  43136. chars[i] = str.charAt(i);
  43137. var charCode = str.charCodeAt(i);
  43138. var charType = 'L';
  43139. if (charCode <= 0x00ff) {
  43140. charType = baseTypes[charCode];
  43141. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  43142. charType = 'R';
  43143. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  43144. charType = arabicTypes[charCode & 0xff];
  43145. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  43146. charType = 'AL';
  43147. }
  43148. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  43149. numBidi++;
  43150. }
  43151. types[i] = charType;
  43152. }
  43153. // Detect the bidi method
  43154. // - If there are no rtl characters then no bidi needed
  43155. // - If less than 30% chars are rtl then string is primarily ltr
  43156. // - If more than 30% chars are rtl then string is primarily rtl
  43157. if (numBidi === 0) {
  43158. isLTR = true;
  43159. return createBidiText(str, isLTR);
  43160. }
  43161. if (startLevel === -1) {
  43162. if ((strLength / numBidi) < 0.3) {
  43163. isLTR = true;
  43164. startLevel = 0;
  43165. } else {
  43166. isLTR = false;
  43167. startLevel = 1;
  43168. }
  43169. }
  43170. var levels = [];
  43171. for (i = 0; i < strLength; ++i) {
  43172. levels[i] = startLevel;
  43173. }
  43174. /*
  43175. X1-X10: skip most of this, since we are NOT doing the embeddings.
  43176. */
  43177. var e = (isOdd(startLevel) ? 'R' : 'L');
  43178. var sor = e;
  43179. var eor = sor;
  43180. /*
  43181. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  43182. type of the NSM to the type of the previous character. If the NSM is at the
  43183. start of the level run, it will get the type of sor.
  43184. */
  43185. var lastType = sor;
  43186. for (i = 0; i < strLength; ++i) {
  43187. if (types[i] === 'NSM') {
  43188. types[i] = lastType;
  43189. } else {
  43190. lastType = types[i];
  43191. }
  43192. }
  43193. /*
  43194. W2. Search backwards from each instance of a European number until the
  43195. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  43196. the type of the European number to Arabic number.
  43197. */
  43198. lastType = sor;
  43199. var t;
  43200. for (i = 0; i < strLength; ++i) {
  43201. t = types[i];
  43202. if (t === 'EN') {
  43203. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  43204. } else if (t === 'R' || t === 'L' || t === 'AL') {
  43205. lastType = t;
  43206. }
  43207. }
  43208. /*
  43209. W3. Change all ALs to R.
  43210. */
  43211. for (i = 0; i < strLength; ++i) {
  43212. t = types[i];
  43213. if (t === 'AL') {
  43214. types[i] = 'R';
  43215. }
  43216. }
  43217. /*
  43218. W4. A single European separator between two European numbers changes to a
  43219. European number. A single common separator between two numbers of the same
  43220. type changes to that type:
  43221. */
  43222. for (i = 1; i < strLength - 1; ++i) {
  43223. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  43224. types[i] = 'EN';
  43225. }
  43226. if (types[i] === 'CS' &&
  43227. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  43228. types[i + 1] === types[i - 1]) {
  43229. types[i] = types[i - 1];
  43230. }
  43231. }
  43232. /*
  43233. W5. A sequence of European terminators adjacent to European numbers changes
  43234. to all European numbers:
  43235. */
  43236. for (i = 0; i < strLength; ++i) {
  43237. if (types[i] === 'EN') {
  43238. // do before
  43239. var j;
  43240. for (j = i - 1; j >= 0; --j) {
  43241. if (types[j] !== 'ET') {
  43242. break;
  43243. }
  43244. types[j] = 'EN';
  43245. }
  43246. // do after
  43247. for (j = i + 1; j < strLength; --j) {
  43248. if (types[j] !== 'ET') {
  43249. break;
  43250. }
  43251. types[j] = 'EN';
  43252. }
  43253. }
  43254. }
  43255. /*
  43256. W6. Otherwise, separators and terminators change to Other Neutral:
  43257. */
  43258. for (i = 0; i < strLength; ++i) {
  43259. t = types[i];
  43260. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  43261. types[i] = 'ON';
  43262. }
  43263. }
  43264. /*
  43265. W7. Search backwards from each instance of a European number until the
  43266. first strong type (R, L, or sor) is found. If an L is found, then change
  43267. the type of the European number to L.
  43268. */
  43269. lastType = sor;
  43270. for (i = 0; i < strLength; ++i) {
  43271. t = types[i];
  43272. if (t === 'EN') {
  43273. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  43274. } else if (t === 'R' || t === 'L') {
  43275. lastType = t;
  43276. }
  43277. }
  43278. /*
  43279. N1. A sequence of neutrals takes the direction of the surrounding strong
  43280. text if the text on both sides has the same direction. European and Arabic
  43281. numbers are treated as though they were R. Start-of-level-run (sor) and
  43282. end-of-level-run (eor) are used at level run boundaries.
  43283. */
  43284. for (i = 0; i < strLength; ++i) {
  43285. if (types[i] === 'ON') {
  43286. var end = findUnequal(types, i + 1, 'ON');
  43287. var before = sor;
  43288. if (i > 0) {
  43289. before = types[i - 1];
  43290. }
  43291. var after = eor;
  43292. if (end + 1 < strLength) {
  43293. after = types[end + 1];
  43294. }
  43295. if (before !== 'L') {
  43296. before = 'R';
  43297. }
  43298. if (after !== 'L') {
  43299. after = 'R';
  43300. }
  43301. if (before === after) {
  43302. setValues(types, i, end, before);
  43303. }
  43304. i = end - 1; // reset to end (-1 so next iteration is ok)
  43305. }
  43306. }
  43307. /*
  43308. N2. Any remaining neutrals take the embedding direction.
  43309. */
  43310. for (i = 0; i < strLength; ++i) {
  43311. if (types[i] === 'ON') {
  43312. types[i] = e;
  43313. }
  43314. }
  43315. /*
  43316. I1. For all characters with an even (left-to-right) embedding direction,
  43317. those of type R go up one level and those of type AN or EN go up two
  43318. levels.
  43319. I2. For all characters with an odd (right-to-left) embedding direction,
  43320. those of type L, EN or AN go up one level.
  43321. */
  43322. for (i = 0; i < strLength; ++i) {
  43323. t = types[i];
  43324. if (isEven(levels[i])) {
  43325. if (t === 'R') {
  43326. levels[i] += 1;
  43327. } else if (t === 'AN' || t === 'EN') {
  43328. levels[i] += 2;
  43329. }
  43330. } else { // isOdd
  43331. if (t === 'L' || t === 'AN' || t === 'EN') {
  43332. levels[i] += 1;
  43333. }
  43334. }
  43335. }
  43336. /*
  43337. L1. On each line, reset the embedding level of the following characters to
  43338. the paragraph embedding level:
  43339. segment separators,
  43340. paragraph separators,
  43341. any sequence of whitespace characters preceding a segment separator or
  43342. paragraph separator, and any sequence of white space characters at the end
  43343. of the line.
  43344. */
  43345. // don't bother as text is only single line
  43346. /*
  43347. L2. From the highest level found in the text to the lowest odd level on
  43348. each line, reverse any contiguous sequence of characters that are at that
  43349. level or higher.
  43350. */
  43351. // find highest level & lowest odd level
  43352. var highestLevel = -1;
  43353. var lowestOddLevel = 99;
  43354. var level;
  43355. for (i = 0, ii = levels.length; i < ii; ++i) {
  43356. level = levels[i];
  43357. if (highestLevel < level) {
  43358. highestLevel = level;
  43359. }
  43360. if (lowestOddLevel > level && isOdd(level)) {
  43361. lowestOddLevel = level;
  43362. }
  43363. }
  43364. // now reverse between those limits
  43365. for (level = highestLevel; level >= lowestOddLevel; --level) {
  43366. // find segments to reverse
  43367. var start = -1;
  43368. for (i = 0, ii = levels.length; i < ii; ++i) {
  43369. if (levels[i] < level) {
  43370. if (start >= 0) {
  43371. reverseValues(chars, start, i);
  43372. start = -1;
  43373. }
  43374. } else if (start < 0) {
  43375. start = i;
  43376. }
  43377. }
  43378. if (start >= 0) {
  43379. reverseValues(chars, start, levels.length);
  43380. }
  43381. }
  43382. /*
  43383. L3. Combining marks applied to a right-to-left base character will at this
  43384. point precede their base character. If the rendering engine expects them to
  43385. follow the base characters in the final display process, then the ordering
  43386. of the marks and the base character must be reversed.
  43387. */
  43388. // don't bother for now
  43389. /*
  43390. L4. A character that possesses the mirrored property as specified by
  43391. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  43392. directionality of that character is R.
  43393. */
  43394. // don't mirror as characters are already mirrored in the pdf
  43395. // Finally, return string
  43396. for (i = 0, ii = chars.length; i < ii; ++i) {
  43397. var ch = chars[i];
  43398. if (ch === '<' || ch === '>') {
  43399. chars[i] = '';
  43400. }
  43401. }
  43402. return createBidiText(chars.join(''), isLTR);
  43403. }
  43404. return bidi;
  43405. })();
  43406. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  43407. // Workaround for missing math precison in JS.
  43408. var MASK_HIGH = 0xffff0000;
  43409. var MASK_LOW = 0xffff;
  43410. function MurmurHash3_64 (seed) {
  43411. var SEED = 0xc3d2e1f0;
  43412. this.h1 = seed ? seed & 0xffffffff : SEED;
  43413. this.h2 = seed ? seed & 0xffffffff : SEED;
  43414. }
  43415. var alwaysUseUint32ArrayView = false;
  43416. // old webkits have issues with non-aligned arrays
  43417. try {
  43418. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  43419. } catch (e) {
  43420. alwaysUseUint32ArrayView = true;
  43421. }
  43422. MurmurHash3_64.prototype = {
  43423. update: function MurmurHash3_64_update(input) {
  43424. var useUint32ArrayView = alwaysUseUint32ArrayView;
  43425. var i;
  43426. if (typeof input === 'string') {
  43427. var data = new Uint8Array(input.length * 2);
  43428. var length = 0;
  43429. for (i = 0; i < input.length; i++) {
  43430. var code = input.charCodeAt(i);
  43431. if (code <= 0xff) {
  43432. data[length++] = code;
  43433. }
  43434. else {
  43435. data[length++] = code >>> 8;
  43436. data[length++] = code & 0xff;
  43437. }
  43438. }
  43439. } else if (input instanceof Uint8Array) {
  43440. data = input;
  43441. length = data.length;
  43442. } else if (typeof input === 'object' && ('length' in input)) {
  43443. // processing regular arrays as well, e.g. for IE9
  43444. data = input;
  43445. length = data.length;
  43446. useUint32ArrayView = true;
  43447. } else {
  43448. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  43449. 'Input must be a string or array.');
  43450. }
  43451. var blockCounts = length >> 2;
  43452. var tailLength = length - blockCounts * 4;
  43453. // we don't care about endianness here
  43454. var dataUint32 = useUint32ArrayView ?
  43455. new Uint32ArrayView(data, blockCounts) :
  43456. new Uint32Array(data.buffer, 0, blockCounts);
  43457. var k1 = 0;
  43458. var k2 = 0;
  43459. var h1 = this.h1;
  43460. var h2 = this.h2;
  43461. var C1 = 0xcc9e2d51;
  43462. var C2 = 0x1b873593;
  43463. var C1_LOW = C1 & MASK_LOW;
  43464. var C2_LOW = C2 & MASK_LOW;
  43465. for (i = 0; i < blockCounts; i++) {
  43466. if (i & 1) {
  43467. k1 = dataUint32[i];
  43468. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  43469. k1 = k1 << 15 | k1 >>> 17;
  43470. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  43471. h1 ^= k1;
  43472. h1 = h1 << 13 | h1 >>> 19;
  43473. h1 = h1 * 5 + 0xe6546b64;
  43474. } else {
  43475. k2 = dataUint32[i];
  43476. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  43477. k2 = k2 << 15 | k2 >>> 17;
  43478. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  43479. h2 ^= k2;
  43480. h2 = h2 << 13 | h2 >>> 19;
  43481. h2 = h2 * 5 + 0xe6546b64;
  43482. }
  43483. }
  43484. k1 = 0;
  43485. switch (tailLength) {
  43486. case 3:
  43487. k1 ^= data[blockCounts * 4 + 2] << 16;
  43488. /* falls through */
  43489. case 2:
  43490. k1 ^= data[blockCounts * 4 + 1] << 8;
  43491. /* falls through */
  43492. case 1:
  43493. k1 ^= data[blockCounts * 4];
  43494. /* falls through */
  43495. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  43496. k1 = k1 << 15 | k1 >>> 17;
  43497. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  43498. if (blockCounts & 1) {
  43499. h1 ^= k1;
  43500. } else {
  43501. h2 ^= k1;
  43502. }
  43503. }
  43504. this.h1 = h1;
  43505. this.h2 = h2;
  43506. return this;
  43507. },
  43508. hexdigest: function MurmurHash3_64_hexdigest () {
  43509. var h1 = this.h1;
  43510. var h2 = this.h2;
  43511. h1 ^= h2 >>> 1;
  43512. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  43513. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  43514. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  43515. h1 ^= h2 >>> 1;
  43516. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  43517. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  43518. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  43519. h1 ^= h2 >>> 1;
  43520. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  43521. var hex = (arr[i] >>> 0).toString(16);
  43522. while (hex.length < 8) {
  43523. hex = '0' + hex;
  43524. }
  43525. str += hex;
  43526. }
  43527. return str;
  43528. }
  43529. };
  43530. return MurmurHash3_64;
  43531. })();
  43532. }).call((typeof window === 'undefined') ? this : window);
  43533. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  43534. // workerSrc is not set -- using last script url to define default location
  43535. PDFJS.workerSrc = (function () {
  43536. 'use strict';
  43537. var pdfJsSrc = document.currentScript.src;
  43538. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  43539. })();
  43540. }